diff --git a/Packages/MIES/MIES_Labnotebook.ipf b/Packages/MIES/MIES_Labnotebook.ipf index e038f2d823..31809d02cf 100644 --- a/Packages/MIES/MIES_Labnotebook.ipf +++ b/Packages/MIES/MIES_Labnotebook.ipf @@ -85,3 +85,36 @@ threadsafe Function/WAVE LBN_GetTextWave([string defValue]) return data End + +/// @brief Return all labnotebook entries which are at least written once +threadsafe Function/WAVE LBV_GetFilledLabnotebookEntries(WAVE/Z values) + + if(!WaveExists(values)) + return $"" + endif + + Make/FREE/N=(DimSize(values, COLS))/T keys + + Multithread keys[] = LBV_IsLabnotebookColumnFilled(values, p) + + RemoveTextWaveEntry1D(keys, "", all = 1) + + if(DimSize(keys, ROWS) == 0) + return $"" + endif + + return keys +End + +/// @brief Return the name of the given labnotebook column if it was written into +/// at least once, an empty string otherwise +threadsafe static Function/S LBV_IsLabnotebookColumnFilled(WAVE values, variable col) + + WAVE/Z indizes = FindIndizes(values, col=col, prop=PROP_NON_EMPTY, startLayer = 0, endLayer = LABNOTEBOOK_LAYER_COUNT - 1) + + if(WaveExists(indizes)) + return GetDimLabel(values, COLS, col) + endif + + return "" +End diff --git a/Packages/MIES/MIES_LogbookViewer.ipf b/Packages/MIES/MIES_LogbookViewer.ipf index 349ae654a5..5809949f47 100644 --- a/Packages/MIES/MIES_LogbookViewer.ipf +++ b/Packages/MIES/MIES_LogbookViewer.ipf @@ -63,10 +63,13 @@ Function/WAVE LBV_PopupExtGetLBKeys(string win) return $"" endif - WAVE/T/Z textualKeys = BSP_GetLogbookWave(win, LBT_LABNOTEBOOK, LBN_TEXTUAL_KEYS, selectedExpDevice = 1) - WAVE/T/Z numericalKeys = BSP_GetLogbookWave(win, LBT_LABNOTEBOOK, LBN_NUMERICAL_KEYS, selectedExpDevice = 1) + WAVE/Z textualValues = BSP_GetLogbookWave(win, LBT_LABNOTEBOOK, LBN_TEXTUAL_VALUES, selectedExpDevice = 1) + WAVE/Z numericalValues = BSP_GetLogbookWave(win, LBT_LABNOTEBOOK, LBN_NUMERICAL_VALUES, selectedExpDevice = 1) + + WAVE/T textualNames = LBV_GetFilledLabnotebookEntries(textualValues) + WAVE/T numericalNames = LBV_GetFilledLabnotebookEntries(numericalValues) - WAVE/Z entries = LBV_GetAllLogbookKeys(textualKeys, numericalKeys) + WAVE/Z entries = LBV_GetAllLogbookParamNames(textualNames, numericalNames) return LBV_PopupExtFormatEntries(entries) End @@ -78,50 +81,62 @@ Function/WAVE LBV_PopupExtGetResultsKeys(string win) return $"" endif - WAVE/T/Z textualKeys = BSP_GetLogbookWave(win, LBT_RESULTS, LBN_TEXTUAL_KEYS, selectedExpDevice = 1) - WAVE/T/Z numericalKeys = BSP_GetLogbookWave(win, LBT_RESULTS, LBN_NUMERICAL_KEYS, selectedExpDevice = 1) + WAVE/Z textualValues = BSP_GetLogbookWave(win, LBT_RESULTS, LBN_TEXTUAL_VALUES, selectedExpDevice = 1) + WAVE/Z numericalValues = BSP_GetLogbookWave(win, LBT_RESULTS, LBN_NUMERICAL_VALUES, selectedExpDevice = 1) + + WAVE/T textualNames = LBV_GetFilledLabnotebookEntries(textualValues) + WAVE/T numericalNames = LBV_GetFilledLabnotebookEntries(numericalValues) - WAVE/Z entries = LBV_GetAllLogbookKeys(textualKeys, numericalKeys) + WAVE/Z entries = LBV_GetAllLogbookParamNames(textualNames, numericalNames) return LBV_PopupExtFormatEntries(entries) End -/// @brief Returns the combined keys from the numerical and textual MD key loogbook waves as 1D text wave -static Function/WAVE LBV_GetAllLogbookKeys(WAVE/T/Z textualKeys, WAVE/T/Z numericalKeys) +/// @brief Returns the combined parameter names from the numerical and textual MD key loogbook waves as 1D text wave +static Function/WAVE LBV_GetAllLogbookParamNames(WAVE/T/Z textualNames, WAVE/T/Z numericalNames) variable existText, existNum - WAVE/Z/T textualKeys1D = LBV_GetLogbookKeys(textualKeys) - WAVE/Z/T numericalKeys1D = LBV_GetLogbookKeys(numericalKeys) + WAVE/Z/T textualNamesClean = LBV_CleanLogbookParamNames(textualNames) + WAVE/Z/T numericalNamesClean = LBV_CleanLogbookParamNames(numericalNames) - existText = WaveExists(textualKeys1D) - existNum = WaveExists(numericalKeys1D) + existText = WaveExists(textualNamesClean) + existNum = WaveExists(numericalNamesClean) if(existText && existNum) - return GetSetUnion(textualKeys1D, numericalKeys1D) + return GetSetUnion(textualNamesClean, numericalNamesClean) elseif(existText && !existNum) - return textualKeys1D + return textualNamesClean elseif(!existText && existNum) - return numericalKeys1D + return numericalNamesClean endif return $"" End -/// @brief Return a wave with all keys in the logbook key wave -static Function/WAVE LBV_GetLogbookKeys(WAVE/Z/T keyWave) +/// @brief Return a wave with all parameter names in the logbook key wave +static Function/WAVE LBV_GetLogbookParamNames(WAVE/Z/T keys) variable row - if(!WaveExists(keyWave)) + if(!WaveExists(keys)) return $"" endif - row = FindDimLabel(keyWave, ROWS, "Parameter") + row = FindDimLabel(keys, ROWS, "Parameter") - Duplicate/FREE/RMD=[row][] keyWave, keys - Redimension/N=(numpnts(keys))/E=1 keys + Duplicate/FREE/RMD=[row][] keys, names + Redimension/N=(numpnts(keys))/E=1 names + + return LBV_CleanLogbookParamNames(names) +End + +static Function/WAVE LBV_CleanLogbookParamNames(WAVE/Z/T names) + + if(!WaveExists(names)) + return $"" + endif WAVE/T hiddenDefaultKeys = ListToTextWave(LABNOTEBOOK_KEYS_INITIAL, ";") - return GetSetDifference(keys, hiddenDefaultKeys) + return GetSetDifference(names, hiddenDefaultKeys) End /// @brief Return a text wave with all entries from all TPStorage waves which are candidates for plotting @@ -1086,7 +1101,7 @@ Function LBV_PlotAllAnalysisFunctionLBNKeys(string browser, variable anaFuncType WAVE/T/Z textualKeys = BSP_GetLogbookWave(browser, LBT_LABNOTEBOOK, LBN_TEXTUAL_KEYS, selectedExpDevice = 1) WAVE/T/Z numericalKeys = BSP_GetLogbookWave(browser, LBT_LABNOTEBOOK, LBN_NUMERICAL_KEYS, selectedExpDevice = 1) - WAVE/T/Z allKeys = LBV_GetAllLogbookKeys(numericalkeys, textualKeys) + WAVE/T/Z allKeys = LBV_GetAllLogbookParamNames(numericalkeys, textualKeys) if(!WaveExists(allKeys)) printf "Could not find any labnotebook keys.\r" diff --git a/Packages/MIES/MIES_Utilities.ipf b/Packages/MIES/MIES_Utilities.ipf index 980e3e5aca..12e68e8c8b 100644 --- a/Packages/MIES/MIES_Utilities.ipf +++ b/Packages/MIES/MIES_Utilities.ipf @@ -5042,8 +5042,8 @@ End /// @param all [optional, defaults to false] removes all entries /// /// @return 0 if at least one entry was found, 1 otherwise -Function RemoveTextWaveEntry1D(WAVE/T w, string entry, [variable options, variable all]) - ASSERT(IsTextWave(w), "Input wave must be a text wave") +threadsafe Function RemoveTextWaveEntry1D(WAVE/T w, string entry, [variable options, variable all]) + ASSERT_TS(IsTextWave(w), "Input wave must be a text wave") variable start, foundOnce diff --git a/Packages/tests/Basic/UTF_Labnotebook.ipf b/Packages/tests/Basic/UTF_Labnotebook.ipf index f8322dd1f8..cc2d43d8aa 100644 --- a/Packages/tests/Basic/UTF_Labnotebook.ipf +++ b/Packages/tests/Basic/UTF_Labnotebook.ipf @@ -1160,3 +1160,37 @@ Function GTW_WorksWithCustomDefault() WAVE/T/Z result = GetUniqueEntries(values) CHECK_EQUAL_TEXTWAVES(result, {"abcd"}) End + +Function GFE_Works() + + string device, key, keyTxt + + device = "ABCD" + + // handles null wave graciously + WAVE/Z null = LBV_GetFilledLabnotebookEntries($"") + CHECK_NO_RTE() + CHECK_WAVE(null, NULL_WAVE) + + // no valid entries by default + WAVE numericalValues = GetLBNumericalValues(device) + CHECK_WAVE(numericalValues, NUMERIC_WAVE) + + WAVE/Z null = LBV_GetFilledLabnotebookEntries(numericalValues) + CHECK_WAVE(null, NULL_WAVE) + + WAVE textualValues = GetLBTextualValues(device) + CHECK_WAVE(textualValues, TEXT_WAVE) + + WAVE/Z null = LBV_GetFilledLabnotebookEntries(textualValues) + CHECK_WAVE(null, NULL_WAVE) + + // our fake LBNs have only valid entries + [key, keyTxt] = PrepareLBN_IGNORE(device) + + WAVE/Z filled = LBV_GetFilledLabnotebookEntries(numericalValues) + CHECK_EQUAL_VAR(DimSize(filled, ROWS), DimSize(numericalValues, COLS)) + + WAVE/Z filled = LBV_GetFilledLabnotebookEntries(textualValues) + CHECK_EQUAL_VAR(DimSize(filled, ROWS), DimSize(textualValues, COLS)) +End diff --git a/Packages/tests/UTF_HardwareHelperFunctions.ipf b/Packages/tests/UTF_HardwareHelperFunctions.ipf index ec2ef5b8c8..244f381eab 100644 --- a/Packages/tests/UTF_HardwareHelperFunctions.ipf +++ b/Packages/tests/UTF_HardwareHelperFunctions.ipf @@ -675,7 +675,10 @@ static Function CheckForOtherUserLBNKeys(string device, variable type) WAVE numericalKeys = GetLBNumericalKeys(device) WAVE textualKeys = GetLBTextualKeys(device) - WAVE/Z entries = MIES_LBV#LBV_GetAllLogbookKeys(textualKeys, numericalKeys) + WAVE/Z numericalNames = MIES_LBV#LBV_GetLogbookParamNames(numericalKeys) + WAVE/Z textualNames = MIES_LBV#LBV_GetLogbookParamNames(textualKeys) + + WAVE/Z entries = MIES_LBV#LBV_GetAllLogbookParamNames(textualNames, numericalNames) CHECK_WAVE(entries, TEXT_WAVE) // check that all user entries are from our analysis function @@ -704,7 +707,10 @@ static Function CheckRangeOfUserLabnotebookKeys(string device, variable type, va WAVE numericalKeys = GetLBNumericalKeys(device) WAVE textualKeys = GetLBTextualKeys(device) - WAVE/Z entries = MIES_LBV#LBV_GetAllLogbookKeys(textualKeys, numericalKeys) + WAVE/Z numericalNames = MIES_LBV#LBV_GetLogbookParamNames(numericalKeys) + WAVE/Z textualNames = MIES_LBV#LBV_GetLogbookParamNames(textualKeys) + + WAVE/Z entries = MIES_LBV#LBV_GetAllLogbookParamNames(textualNames, numericalNames) CHECK_WAVE(entries, TEXT_WAVE) WAVE/T/Z allUserEntries = GrepTextWave(entries, LABNOTEBOOK_USER_PREFIX + ".*")