Skip to content

Commit

Permalink
GetUniqueSettings/FFI_QueryLogbookUniqueSetting: Add them
Browse files Browse the repository at this point in the history
  • Loading branch information
t-b committed Sep 3, 2024
1 parent e77db2f commit 15f739c
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 12 deletions.
26 changes: 26 additions & 0 deletions Packages/MIES/MIES_ForeignFunctionInterface.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -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
44 changes: 44 additions & 0 deletions Packages/MIES/MIES_MiesUtilities_Logbook.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
13 changes: 1 addition & 12 deletions Packages/MIES/MIES_SweepFormula.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions Packages/tests/Basic/UTF_ForeignFunctionInterface.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 27 additions & 0 deletions Packages/tests/Basic/UTF_Labnotebook.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 15f739c

Please sign in to comment.