Skip to content

Commit

Permalink
Tests: Add ignoreErr argument to ListToNumericWave
Browse files Browse the repository at this point in the history
- setting the flag allow to retrieve NaN for values that could not be converted,
  previously this resulted in an RTE
  • Loading branch information
MichaelHuth committed Mar 19, 2024
1 parent 94e7490 commit 9efd770
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 11 additions & 7 deletions Packages/MIES/MIES_Utilities.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -3238,19 +3238,23 @@ End
/// Counterpart @see NumericWaveToList().
/// @see TextWaveToList
///
/// @param list list with numeric entries
/// @param sep separator
/// @param type [optional, defaults to double precision float (`IGOR_TYPE_64BIT_FLOAT`)] type of the created numeric wave
threadsafe Function/WAVE ListToNumericWave(list, sep, [type])
string list, sep
variable type
/// @param list list with numeric entries
/// @param sep separator
/// @param type [optional, defaults to double precision float (`IGOR_TYPE_64BIT_FLOAT`)] type of the created numeric wave
/// @param ignoreErr [optional, defaults 0] when this flag is set conversion errors are ignored, the value placed is NaN (-9223372036854775808 for int type)
threadsafe Function/WAVE ListToNumericWave(string list, string sep, [variable type, variable ignoreErr])

if(ParamIsDefault(type))
type = IGOR_TYPE_64BIT_FLOAT
endif
ignoreErr = ParamIsDefault(ignoreErr) ? 0 : !!ignoreErr

Make/FREE/Y=(type)/N=(ItemsInList(list, sep)) wv
MultiThread wv = str2num(StringFromList(p, list, sep))
if(ignoreErr)
MultiThread wv = str2numSafe(StringFromList(p, list, sep))
else
MultiThread wv = str2num(StringFromList(p, list, sep))
endif

return wv
End
Expand Down
4 changes: 2 additions & 2 deletions Packages/tests/UTF_DataGenerators.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ static Function/WAVE EpochTestSamplingFrequency_Gen()

string frequencies = DAP_GetSamplingFrequencies()

WAVE wTemp = ListToNumericWave(frequencies, ";")
WAVE wTemp = ListToNumericWave(frequencies, ";", ignoreErr = 1)
WAVE w = ZapNaNs(wTemp)

SetDimensionLabelsFromWaveContents(w, prefix = "f_", suffix = "_kHz")
Expand All @@ -285,7 +285,7 @@ static Function/WAVE EpochTestSamplingFrequencyTTL_Gen()

string frequencies = DAP_GetSamplingFrequencies()

WAVE wTemp = ListToNumericWave(frequencies, ";")
WAVE wTemp = ListToNumericWave(frequencies, ";", ignoreErr = 1)

#ifdef TESTS_WITH_ITC18USB_HARDWARE
wTemp[] = wTemp[p] == 100 ? NaN : wTemp[p]
Expand Down

0 comments on commit 9efd770

Please sign in to comment.