diff --git a/Packages/MIES/MIES_ForeignFunctionInterface.ipf b/Packages/MIES/MIES_ForeignFunctionInterface.ipf index ad9ae826b5..f7f8cda5a5 100644 --- a/Packages/MIES/MIES_ForeignFunctionInterface.ipf +++ b/Packages/MIES/MIES_ForeignFunctionInterface.ipf @@ -114,3 +114,29 @@ Function/WAVE FFI_QueryLogbook(string device, variable logbookType, variable swe return settings End + +/// @brief Return all unique logbook entries from devices +/// +/// @param device Name of the hardware device panel, @sa GetLockedDevices() +/// @param logbookType One of #LBT_LABNOTEBOOK or #LBT_RESULTS +/// @param setting Name of the entry +/// +/// @return Numerical/Textual 1D wave or a null wave reference if nothing could be found +Function/WAVE FFI_QueryLogbookUniqueSetting(string device, variable logbookType, string setting) + + ASSERT(logbookType != LBT_TPSTORAGE, "Invalid logbook type") + + WAVE/T numericalValues = GetLogbookWaves(logbookType, LBN_NUMERICAL_VALUES, device = device) + + WAVE/Z settings = GetUniqueSettings(numericalValues, setting) + + if(WaveExists(settings)) + return settings + endif + + WAVE/T textualValues = GetLogbookWaves(logbookType, LBN_TEXTUAL_VALUES, device = device) + + WAVE/Z settings = GetUniqueSettings(textualValues, setting) + + return settings +End diff --git a/Packages/MIES/MIES_MiesUtilities_Logbook.ipf b/Packages/MIES/MIES_MiesUtilities_Logbook.ipf index 055ec628f3..97a0be0182 100644 --- a/Packages/MIES/MIES_MiesUtilities_Logbook.ipf +++ b/Packages/MIES/MIES_MiesUtilities_Logbook.ipf @@ -1534,6 +1534,50 @@ threadsafe Function/WAVE GetSweepsWithSetting(labnotebookValues, setting) return GetUniqueEntries(sweeps) End +/// @brief Return a unique list of labnotebook entries of the given setting +/// +/// @param values numerical logbook wave +/// @param setting name of the value to search +threadsafe Function/WAVE GetUniqueSettings(WAVE values, string setting) + + variable numMatches, settingsCol + + [WAVE indizes, settingsCol] = GetNonEmptyLBNRows(values, setting) + if(!WaveExists(indizes)) + return $"" + endif + + numMatches = DimSize(indizes, ROWS) + + if(IsNumericWave(values)) + Make/D/FREE/N=(numMatches, LABNOTEBOOK_LAYER_COUNT) data + + Multithread data[][] = values[indizes[p]][settingsCol][q] + + Redimension/N=(numMatches * LABNOTEBOOK_LAYER_COUNT)/E=1 data + + WAVE dataUnique = GetUniqueEntries(data) + + return ZapNaNs(dataUnique) + elseif(IsTextWave(values)) + Make/T/FREE/N=(numMatches, LABNOTEBOOK_LAYER_COUNT) dataTxt + + WAVE/T valuesTxt = values + + Multithread dataTxt[][] = valuesTxt[indizes[p]][settingsCol][q] + + Redimension/N=(numMatches * LABNOTEBOOK_LAYER_COUNT)/E=1 dataTxt + + WAVE dataUnique = GetUniqueEntries(dataTxt) + + RemoveTextWaveEntry1D(dataUnique, "") + + return dataUnique + endif + + ASSERT_TS(0, "Unsupported wave type") +End + /// @brief Return the last numerical value of a setting from the labnotebook /// and the sweep it was set. /// diff --git a/Packages/MIES/MIES_SweepFormula.ipf b/Packages/MIES/MIES_SweepFormula.ipf index dd71f9f476..f7126f0612 100644 --- a/Packages/MIES/MIES_SweepFormula.ipf +++ b/Packages/MIES/MIES_SweepFormula.ipf @@ -5081,21 +5081,10 @@ Function/WAVE SF_GetAllOldCodeForGUI(string win) // parameter required for popup End static Function/WAVE SF_GetAllOldCode() - string entry - variable settingsCol WAVE/T textualResultsValues = GetLogbookWaves(LBT_RESULTS, LBN_TEXTUAL_VALUES) - entry = "Sweep Formula code" - [WAVE indizes, settingsCol] = GetNonEmptyLBNRows(textualResultsValues, entry) - - if(!WaveExists(indizes)) - return $"" - endif - - Make/FREE/T/N=(DimSize(indizes, ROWS)) entries = textualResultsValues[indizes[p]][settingsCol][INDEP_HEADSTAGE] - - return GetUniqueEntries(entries) + return GetUniqueSettings(textualResultsValues, "Sweep Formula code") End Function SF_PopMenuProc_OldCode(STRUCT WMPopupAction &pa) : PopupMenuControl diff --git a/Packages/tests/Basic/UTF_ForeignFunctionInterface.ipf b/Packages/tests/Basic/UTF_ForeignFunctionInterface.ipf index d18f4307d3..932a8679bf 100644 --- a/Packages/tests/Basic/UTF_ForeignFunctionInterface.ipf +++ b/Packages/tests/Basic/UTF_ForeignFunctionInterface.ipf @@ -28,3 +28,16 @@ static Function TestLogbookQuery() WAVE/Z settings = FFI_QueryLogbook(device, LBT_LABNOTEBOOK, 0, keyTxt, DATA_ACQUISITION_MODE) CHECK_WAVE(settings, TEXT_WAVE) End + +static Function TestLogbookQueryUnique() + string key, keyTxT, device + + device = "ITC16USB_0_DEV" + [key, keyTxt] = PrepareLBN_IGNORE(device) + + WAVE/Z settings = FFI_QueryLogbookUniqueSetting(device, LBT_LABNOTEBOOK, key) + CHECK_WAVE(settings, NUMERIC_WAVE) + + WAVE/Z settings = FFI_QueryLogbookUniqueSetting(device, LBT_LABNOTEBOOK, keyTxt) + CHECK_WAVE(settings, TEXT_WAVE) +End diff --git a/Packages/tests/Basic/UTF_Labnotebook.ipf b/Packages/tests/Basic/UTF_Labnotebook.ipf index 21b1df9251..bbca058656 100644 --- a/Packages/tests/Basic/UTF_Labnotebook.ipf +++ b/Packages/tests/Basic/UTF_Labnotebook.ipf @@ -1312,3 +1312,30 @@ Function MultipleSameEDAdds() CHECK_EQUAL_VAR(DimSize(indices, ROWS), 1) CHECK_GE_VAR(indices[0], 0) End + +Function GetUniqueSettingsWorks() + string key, keyTxT, device + + device = "ITC16USB_0_DEV" + [key, keyTxt] = PrepareLBN_IGNORE(device) + + WAVE/T numericalValues = GetLogbookWaves(LBT_LABNOTEBOOK, LBN_NUMERICAL_VALUES, device = device) + WAVE/T textualValues = GetLogbookWaves(LBT_LABNOTEBOOK, LBN_TEXTUAL_VALUES, device = device) + + // no matches + WAVE/Z results = GetUniqueSettings(numericalValues, "I_DONT_EXIST") + CHECK_WAVE(results, NULL_WAVE) + + WAVE/Z resultsTxt = GetUniqueSettings(textualValues, "I_DONT_EXIST") + CHECK_WAVE(resultsTxt, NULL_WAVE) + + // matches + WAVE/Z results = GetUniqueSettings(numericalValues, key) + CHECK_WAVE(results, NUMERIC_WAVE) + Make/D/FREE ref = {131415, 192021, 161718, 222324, 252627} + CHECK_EQUAL_WAVES(results, ref) + + WAVE/Z resultsTxt = GetUniqueSettings(textualValues, keyTxt) + CHECK_WAVE(resultsTxt, TEXT_WAVE) + CHECK_EQUAL_TEXTWAVES(resultsTxt, {"131415", "192021", "161718", "222324", "252627"}) +End