Skip to content

Commit

Permalink
GetRowIndex: Add textOp optional parameter
Browse files Browse the repository at this point in the history
This allows to choose /TXOP for textwaves.
  • Loading branch information
t-b committed Dec 19, 2024
1 parent 8c0b7b9 commit 6cc5fd2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Packages/MIES/MIES_Utilities_Algorithm.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ End
/// @brief Return the row index of the given value, string converted to a variable, or wv
///
/// Assumes wv being one dimensional and does not use any tolerance for numerical values.
threadsafe Function GetRowIndex(WAVE wv, [variable val, string str, WAVE/Z refWave, variable reverseSearch])
threadsafe Function GetRowIndex(WAVE wv, [variable val, string str, WAVE/Z refWave, variable reverseSearch, variable textOp])

variable numEntries, i

Expand All @@ -271,6 +271,10 @@ threadsafe Function GetRowIndex(WAVE wv, [variable val, string str, WAVE/Z refWa
reverseSearch = !!reverseSearch
endif

if(ParamIsDefault(textOp))
textOp = 4
endif

if(!ParamIsDefault(refWave))
ASSERT_TS(IsWaveRefWave(wv), "wv must be a wave holding wave references")
numEntries = DimSize(wv, ROWS)
Expand Down Expand Up @@ -336,9 +340,9 @@ threadsafe Function GetRowIndex(WAVE wv, [variable val, string str, WAVE/Z refWa
endif

if(!reverseSearch)
FindValue/TEXT=(str)/TXOP=4 wv
FindValue/TEXT=(str)/TXOP=(textOp) wv
else
FindValue/TEXT=(str)/TXOP=4/R wv
FindValue/TEXT=(str)/TXOP=(textOp)/R wv
endif

if(V_Value >= 0)
Expand Down
9 changes: 9 additions & 0 deletions Packages/tests/Basic/UTF_Utils_Algorithm.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ static Function TestGetRowIndex()
CHECK_EQUAL_VAR(GetRowIndex(textWave, str = "b"), 1)
CHECK_EQUAL_VAR(GetRowIndex(textWave, val = 123), NaN)

// text waves with textOp
Make/FREE/T textWave = {"a1", "b2", "c", "d", "1", "2"}
CHECK_EQUAL_VAR(GetRowIndex(textWave, val = 1), 4)
CHECK_EQUAL_VAR(GetRowIndex(textWave, val = 1, textOp = 4), 4)
CHECK_EQUAL_VAR(GetRowIndex(textWave, val = 1, textOp = 0), 0)
CHECK_EQUAL_VAR(GetRowIndex(textWave, str = "2"), 5)
CHECK_EQUAL_VAR(GetRowIndex(textWave, str = "2", textOp = 4), 5)
CHECK_EQUAL_VAR(GetRowIndex(textWave, str = "2", textOp = 0), 1)

// wave ref waves
Make/FREE/WAVE/N=2 waveRefWave
Make/FREE content
Expand Down

0 comments on commit 6cc5fd2

Please sign in to comment.