Skip to content

Commit 0982ecf

Browse files
committed
SF: Add operation extract to retrieve a single dataset from a multi ds result
The API is: extract(multi_dataset, index) extract returns a single dataset. Added test
1 parent 7d217c9 commit 0982ecf

File tree

5 files changed

+76
-1
lines changed

5 files changed

+76
-1
lines changed

Packages/MIES/MIES_Constants.ipf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,6 +2522,7 @@ StrConstant SF_OP_TPSS = "tpss"
25222522
StrConstant SF_OP_TPINST = "tpinst"
25232523
StrConstant SF_OP_TPBASE = "tpbase"
25242524
StrConstant SF_OP_TPFIT = "tpfit"
2525+
StrConstant SF_OP_EXTRACT = "extract"
25252526
///@}
25262527

25272528
/// @name SF operations shorts

Packages/MIES/MIES_SweepFormula.ipf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Function/WAVE SF_GetNamedOperations()
7070
SF_OP_MERGE, SF_OP_FIT, SF_OP_FITLINE, SF_OP_DATASET, SF_OP_SELECTVIS, SF_OP_SELECTCM, SF_OP_SELECTSTIMSET, \
7171
SF_OP_SELECTIVSCCSWEEPQC, SF_OP_SELECTIVSCCSETQC, SF_OP_SELECTRANGE, SF_OP_SELECTEXP, SF_OP_SELECTDEV, \
7272
SF_OP_SELECTEXPANDSCI, SF_OP_SELECTEXPANDRAC, SF_OP_SELECTSETCYCLECOUNT, SF_OP_SELECTSETSWEEPCOUNT, \
73-
SF_OP_SELECTSCIINDEX, SF_OP_SELECTRACINDEX, SF_OP_ANAFUNCPARAM, SF_OP_CONCAT}
73+
SF_OP_SELECTSCIINDEX, SF_OP_SELECTRACINDEX, SF_OP_ANAFUNCPARAM, SF_OP_CONCAT, SF_OP_EXTRACT}
7474

7575
return wt
7676
End

Packages/MIES/MIES_SweepFormula_Executor.ipf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,9 @@ Function/WAVE SFE_FormulaExecutor(STRUCT SF_ExecutionData &exd, [variable srcLoc
469469
case SF_OP_DATASET:
470470
WAVE out = SFO_OperationDataset(exdop)
471471
break
472+
case SF_OP_EXTRACT:
473+
WAVE out = SFO_OperationExtract(exdop)
474+
break
472475
case SF_OP_SELECTVIS:
473476
WAVE out = SFOS_OperationSelectVis(exdop)
474477
break

Packages/MIES/MIES_SweepFormula_Operations.ipf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,24 @@ Function/WAVE SFO_OperationDataset(STRUCT SF_ExecutionData &exd)
742742
return SFH_GetOutputForExecutor(output, exd.graph, SF_OP_DATASET)
743743
End
744744

745+
// extract(<dataset>, index)
746+
Function/WAVE SFO_OperationExtract(STRUCT SF_ExecutionData &exd)
747+
748+
variable idx
749+
string opShort = SF_OP_EXTRACT
750+
751+
SFH_CheckArgumentCount(exd, opShort, 2, maxArgs = 2)
752+
753+
WAVE/WAVE datasets = SFH_GetArgumentAsWave(exd, opShort, 0)
754+
idx = SFH_GetArgumentAsNumeric(exd, opShort, 1)
755+
SFH_ASSERT(idx < DimSize(datasets, ROWS), "index out of range")
756+
757+
WAVE/WAVE output = SFH_CreateSFRefWave(exd.graph, opShort, 1)
758+
output[0] = datasets[idx]
759+
760+
return SFH_GetOutputForExecutor(output, exd.graph, opShort)
761+
End
762+
745763
Function/WAVE SFO_OperationDerivative(STRUCT SF_ExecutionData &exd)
746764

747765
variable numArgs

Packages/tests/Basic/UTF_SweepFormula_Operations.ipf

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3631,3 +3631,56 @@ static Function TestOperationAnaFuncParam()
36313631
idx += 1
36323632
endfor
36333633
End
3634+
3635+
static Function TestOperationExtract()
3636+
3637+
string str, wavePath
3638+
string win
3639+
3640+
win = GetDataBrowserWithData()
3641+
3642+
str = "extract(1)"
3643+
try
3644+
WAVE data = SFE_ExecuteFormula(str, win, singleResult = 1, useVariables = 0)
3645+
FAIL()
3646+
catch
3647+
PASS()
3648+
endtry
3649+
3650+
str = "extract(1,1,1)"
3651+
try
3652+
WAVE data = SFE_ExecuteFormula(str, win, singleResult = 1, useVariables = 0)
3653+
FAIL()
3654+
catch
3655+
PASS()
3656+
endtry
3657+
3658+
str = "extract(1,a)"
3659+
try
3660+
WAVE data = SFE_ExecuteFormula(str, win, singleResult = 1, useVariables = 0)
3661+
FAIL()
3662+
catch
3663+
PASS()
3664+
endtry
3665+
3666+
str = "extract(1,0)"
3667+
WAVE data = SFE_ExecuteFormula(str, win, singleResult = 1, useVariables = 0)
3668+
CHECK_EQUAL_WAVES(data, {1}, mode = WAVE_DATA)
3669+
3670+
str = "extract(a,0)"
3671+
WAVE data = SFE_ExecuteFormula(str, win, singleResult = 1, useVariables = 0)
3672+
Make/FREE/T ref = {"a"}
3673+
CHECK_EQUAL_WAVES(data, ref, mode = WAVE_DATA)
3674+
3675+
str = "extract([1,2],0)"
3676+
WAVE data = SFE_ExecuteFormula(str, win, singleResult = 1, useVariables = 0)
3677+
CHECK_EQUAL_WAVES(data, {1, 2}, mode = WAVE_DATA)
3678+
3679+
str = "extract(dataset(1,2),0)"
3680+
WAVE data = SFE_ExecuteFormula(str, win, singleResult = 1, useVariables = 0)
3681+
CHECK_EQUAL_WAVES(data, {1}, mode = WAVE_DATA)
3682+
3683+
str = "extract(dataset(1,2),1)"
3684+
WAVE data = SFE_ExecuteFormula(str, win, singleResult = 1, useVariables = 0)
3685+
CHECK_EQUAL_WAVES(data, {2}, mode = WAVE_DATA)
3686+
End

0 commit comments

Comments
 (0)