@@ -164,7 +164,7 @@ Function SF_FormulaWaveScaleTransfer(WAVE source, WAVE dest, variable dimSource,
164164 endswitch
165165End
166166
167- static Function [WAVE/WAVE formulaResults, STRUCT SF_PlotMetaData plotMetaData] SF_GatherFormulaResults ( string xFormula, string yFormula, string graph, variable lineNr, variable offset)
167+ static Function [WAVE/WAVE formulaResults, WAVE/T plotMetaData] SF_GatherFormulaResults ( string xFormula, string yFormula, string graph, variable lineNr, variable offset)
168168
169169 variable i , numResultsY, numResultsX
170170 variable useXLabel, addDataUnitsInAnnotation
@@ -234,11 +234,13 @@ static Function [WAVE/WAVE formulaResults, STRUCT SF_PlotMetaData plotMetaData]
234234 dataUnits = SelectString ( addDataUnitsInAnnotation && ! IsEmpty ( dataUnitCheck) , "" , SF_FormatUnit ( dataUnitCheck))
235235 endif
236236
237- plotMetaData. dataType = JWN_GetStringFromWaveNote ( wvYRef, SF_META_DATATYPE)
238- plotMetaData. opStack = JWN_GetStringFromWaveNote ( wvYRef, SF_META_OPSTACK)
239- plotMetaData. argSetupStack = JWN_GetStringFromWaveNote ( wvYRef, SF_META_ARGSETUPSTACK)
240- plotMetaData. xAxisLabel = SelectString ( useXLabel, SF_XLABEL_USER, JWN_GetStringFromWaveNote ( wvYRef, SF_META_XAXISLABEL))
241- plotMetaData. yAxisLabel = JWN_GetStringFromWaveNote ( wvYRef, SF_META_YAXISLABEL) + dataUnits
237+ WAVE /T plotMetaData = GetSFPlotMetaData ()
238+
239+ plotMetaData[ % DATATYPE] = JWN_GetStringFromWaveNote ( wvYRef, SF_META_DATATYPE)
240+ plotMetaData[ % OPSTACK] = JWN_GetStringFromWaveNote ( wvYRef, SF_META_OPSTACK)
241+ plotMetaData[ % ARGSETUPSTACK] = JWN_GetStringFromWaveNote ( wvYRef, SF_META_ARGSETUPSTACK)
242+ plotMetaData[ % XAXISLABEL] = SelectString ( useXLabel, SF_XLABEL_USER, JWN_GetStringFromWaveNote ( wvYRef, SF_META_XAXISLABEL))
243+ plotMetaData[ % YAXISLABEL] = JWN_GetStringFromWaveNote ( wvYRef, SF_META_YAXISLABEL) + dataUnits
242244
243245 return [ formulaResults, plotMetaData]
244246End
@@ -266,15 +268,15 @@ static Function/S SF_GetAnnotationPrefix(string dataType)
266268 endswitch
267269End
268270
269- static Function/S SF_GetTraceAnnotationText ( STRUCT SF_PlotMetaData & plotMetaData, WAVE data)
271+ static Function/S SF_GetTraceAnnotationText ( WAVE /T plotMetaData, WAVE data)
270272
271273 variable channelNumber, channelType, sweepNo, isAveraged
272274 string channelId, prefix, legendPrefix
273275 string traceAnnotation, annotationPrefix
274276
275- prefix = RemoveEnding ( ReplaceString ( ";" , plotMetaData. opStack , " " ) , " " )
277+ prefix = RemoveEnding ( ReplaceString ( ";" , plotMetaData[ % OPSTACK ] , " " ) , " " )
276278
277- strswitch ( plotMetaData. dataType )
279+ strswitch ( plotMetaData[ % DATATYPE ] )
278280 case SF_DATATYPE_EPOCHS: // fallthrough
279281 case SF_DATATYPE_SWEEP: // fallthrough
280282 case SF_DATATYPE_LABNOTEBOOK: // fallthrough
@@ -287,7 +289,7 @@ static Function/S SF_GetTraceAnnotationText(STRUCT SF_PlotMetaData &plotMetaData
287289 legendPrefix = " " + legendPrefix + " "
288290 endif
289291
290- sprintf annotationPrefix, "%s%s" , SF_GetAnnotationPrefix ( plotMetaData. dataType ) , legendPrefix
292+ sprintf annotationPrefix, "%s%s" , SF_GetAnnotationPrefix ( plotMetaData[ % DATATYPE ] ), legendPrefix
291293
292294 if ( IsValidSweepNumber ( sweepNo))
293295 channelNumber = JWN_GetNumberFromWaveNote ( data, SF_META_CHANNELNUMBER)
@@ -299,7 +301,7 @@ static Function/S SF_GetTraceAnnotationText(STRUCT SF_PlotMetaData &plotMetaData
299301 endif
300302 break
301303 default :
302- if ( WhichListItem ( SF_OP_DATA, plotMetaData. opStack ) == -1 )
304+ if ( WhichListItem ( SF_OP_DATA, plotMetaData[ % OPSTACK ] ) == -1 )
303305 sprintf traceAnnotation, "%s" , prefix
304306 else
305307 channelNumber = JWN_GetNumberFromWaveNote ( data, SF_META_CHANNELNUMBER)
@@ -327,7 +329,7 @@ static Function/S SF_GetTraceAnnotationText(STRUCT SF_PlotMetaData &plotMetaData
327329 return traceAnnotation
328330End
329331
330- static Function/S SF_GetMetaDataAnnotationText ( STRUCT SF_PlotMetaData & plotMetaData, WAVE data, string traceName)
332+ static Function/S SF_GetMetaDataAnnotationText ( WAVE /T plotMetaData, WAVE data, string traceName)
331333
332334 return "\\ s(" + traceName + ") " + SF_GetTraceAnnotationText ( plotMetaData, data) + "\r "
333335End
492494///
493495/// @retval traces generated trace names
494496/// @retval traceCnt total count of all traces (input *and* output)
495- static Function [WAVE/T traces, variable traceCnt] SF_CreateTraceNames ( variable numTraces, variable dataNum, STRUCT SF_PlotMetaData & plotMetaData, WAVE data)
497+ static Function [WAVE/T traces, variable traceCnt] SF_CreateTraceNames ( variable numTraces, variable dataNum, WAVE /T plotMetaData, WAVE data)
496498
497499 string traceAnnotation
498500
829831
830832static Function SF_KillWindowAndParentsIfEmpty ( string win)
831833
832- string subWindows
833-
834834 KillWindow / Z $ win
835835 for ( ;; )
836836 win = RemoveEnding ( win, "#" + LastStringFromList ( win, sep = "#" ))
@@ -939,6 +939,76 @@ static Function SF_IsDataForTableDisplay(WAVE wvY)
939939 return IsNaN ( useTable) ? 0 : !! useTable
940940End
941941
942+ /// @brief Evaluates the formulas and returns results for all successfully evaluated ones
943+ /// Data structure wave tree, rows are filled:
944+ /// WREF indexing over all graphs
945+ /// WREF indexing over all formula results with two columns
946+ /// col %DATA: formularesults
947+ /// col %META: plot meta data
948+ ///
949+ /// Formula results are in the format as returned by SF_GatherFormulaResults() from GetFormulaGatherWave()
950+ /// with indexing over the results of a single formula and two columns
951+ /// col %FORMULAX
952+ /// col %FORMULAY
953+ ///
954+ /// @param graph graph name of SB/DB
955+ /// @param formula formula to plot
956+ /// @param lineVars number of lines in the SF notebook with variable assignments in front of the formula
957+ ///
958+ /// @returns dataInGraphs waveref wave with the structure as explained above
959+ /// @returns err set to 1 if there was an evaluation error, 0 otherwise
960+ static Function [WAVE/WAVE dataInGraphs, variable err] SF_PlotterGetDataFromFormulas ( string graph, string formula, variable lineVars)
961+
962+ variable i , numDataInGraph, numGraphs
963+ string formulasRemain, moreFormulas, xFormula, yFormula, yAndXFormula
964+ variable line, lineGraph, lineGraphFormula, xFormulaOffset
965+
966+ err = 0
967+
968+ WAVE /T graphCode = SF_SplitCodeToGraphs ( formula)
969+ numGraphs = DimSize ( graphCode, ROWS)
970+
971+ Make / FREE/ WAVE /N= ( numGraphs) dataInGraphs
972+ for ( i = 0; i < numGraphs; i += 1 )
973+
974+ formulasRemain = graphCode[ i ][ % GRAPHCODE]
975+ lineGraph = str2num ( graphCode[ i ][ % LINE])
976+
977+ WAVE /WAVE dataInGraph = GetSFDataInGraph ()
978+ numDataInGraph = 0
979+ do
980+ SplitString / E= SF_SWEEPFORMULA_WITH_REGEXP formulasRemain, yAndXFormula, moreFormulas
981+ if ( ! V_flag)
982+ break
983+ endif
984+ line = lineVars + lineGraph + lineGraphFormula
985+ lineGraphFormula = SF_GetLineNumberOfRemainingCode ( formulasRemain, moreFormulas)
986+ formulasRemain = moreFormulas
987+
988+ [ xFormula, yFormula, xFormulaOffset] = SF_SplitGraphsToFormula ( yAndXFormula)
989+ SFH_ASSERT ( ! IsEmpty ( yFormula) , "Could not determine y [vs x] formula pair." )
990+
991+ WAVE /Z/ WAVE formulaResults = $ ""
992+ WAVE /Z/ T plotMetaData = $ ""
993+ try
994+ [ formulaResults, plotMetaData] = SF_GatherFormulaResults ( xFormula, yFormula, graph, line, xFormulaOffset)
995+ catch
996+ err = 1
997+ continue
998+ endtry
999+ EnsureLargeEnoughWave ( dataInGraph, indexShouldExist = numDataInGraph)
1000+ dataInGraph[ numDataInGraph][ % DATA] = formulaResults
1001+ dataInGraph[ numDataInGraph][ % META] = plotMetaData
1002+
1003+ numDataInGraph += 1
1004+ while ( 1 )
1005+ Redimension / N= ( numDataInGraph, -1 ) dataInGraph
1006+ dataInGraphs[ i ] = dataInGraph
1007+ endfor
1008+
1009+ return [ dataInGraphs, err]
1010+ End
1011+
9421012/// @brief Plot the formula using the data from graph
9431013///
9441014/// @param graph graph to pass to SF_FormulaExecutor
@@ -949,34 +1019,45 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
9491019
9501020 string trace, customLegend
9511021 variable i , j, k, l, numTraces, splitTraces, splitY, splitX, numGraphs, numWins, numData, dataCnt, traceCnt
952- variable winDisplayMode, showLegend, tagCounter, overrideMarker, line , lineGraph , lineGraphFormula
1022+ variable winDisplayMode, showLegend, tagCounter, overrideMarker
9531023 variable xMxN, yMxN, xPoints, yPoints, keepUserSelection, numAnnotations, formulasAreDifferent, postPlotPSX
954- variable formulaCounter, gdIndex, markerCode, lineCode, lineStyle, traceToFront, isCategoryAxis, xFormulaOffset
955- variable showInTable, numTableFormulas, formulaAddedOncePerDataset
1024+ variable formulaCounter, gdIndex, markerCode, lineCode, lineStyle, traceToFront, isCategoryAxis
1025+ variable showInTable, numTableFormulas, formulaAddedOncePerDataset, cntDataInGraph , numDataInGraph , evalErr
9561026 string win, winTable, wList, winNameTemplate, exWList, wName, annotation, xAxisLabel, yAxisLabel, wvName, info, xAxis
957- string formulasRemain, moreFormulas, yAndXFormula, xFormula, yFormula, tagText, name, winHook
958- STRUCT SF_PlotMetaData plotMetaData
959- STRUCT RGBColor color
1027+ string tagText, name, winHook
1028+ STRUCT RGBColor color
9601029
9611030 winDisplayMode = ParamIsDefault ( dmMode) ? SF_DM_SUBWINDOWS : dmMode
9621031 lineVars = ParamIsDefault ( lineVars) ? NaN : lineVars
9631032 ASSERT ( winDisplaymode == SF_DM_NORMAL || winDisplaymode == SF_DM_SUBWINDOWS, "Invalid display mode." )
9641033
965- DFREF dfr = SF_GetBrowserDF ( graph)
966-
967- WAVE /T graphCode = SF_SplitCodeToGraphs ( formula)
968-
969- SVAR lastCode = $ GetLastSweepFormulaCode ( dfr)
1034+ DFREF dfr = SF_GetBrowserDF ( graph)
1035+ SVAR lastCode = $ GetLastSweepFormulaCode ( dfr)
9701036 keepUserSelection = ! cmpstr ( lastCode, formula)
9711037
972- numGraphs = DimSize ( graphCode, ROWS)
1038+ [ WAVE /WAVE evalFormulas, evalErr] = SF_PlotterGetDataFromFormulas ( graph, formula, lineVars)
1039+
1040+ numGraphs = DimSize ( evalFormulas, ROWS)
9731041 wList = ""
9741042 winNameTemplate = SF_GetFormulaWinNameTemplate ( graph)
9751043
9761044 [ WAVE /T plotGraphs, WAVE /WAVE infos] = SF_PreparePlotter ( winNameTemplate, graph, winDisplayMode, numGraphs)
9771045
1046+ numGraphs = DimSize ( evalFormulas, ROWS)
9781047 for ( j = 0; j < numGraphs; j += 1 )
9791048
1049+ win = plotGraphs[ j][ % GRAPH]
1050+ winTable = plotGraphs[ j][ % TABLE]
1051+ if ( winDisplayMode == SF_DM_NORMAL)
1052+ wList = AddListItem ( win, wList)
1053+ wList = AddListItem ( winTable, wList)
1054+ endif
1055+
1056+ WAVE /WAVE graphFormulas = evalFormulas[ j]
1057+ if ( ! DimSize ( graphFormulas, ROWS))
1058+ continue
1059+ endif
1060+
9801061 traceCnt = 0
9811062 numAnnotations = 0
9821063 postPlotPSX = 0
@@ -988,49 +1069,28 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
9881069
9891070 Make / FREE/ T/ N=0 xAxisLabels, yAxisLabels
9901071
991- formulasRemain = graphCode[ j][ % GRAPHCODE]
992- lineGraph = str2num ( graphCode[ j][ % LINE])
993-
994- win = plotGraphs[ j][ % GRAPH]
995- winTable = plotGraphs[ j][ % TABLE]
996- if ( winDisplayMode == SF_DM_NORMAL)
997- wList = AddListItem ( win, wList)
998- wList = AddListItem ( winTable, wList)
999- endif
1000-
10011072 Make / FREE=1/ T/ N= ( MINIMUM_WAVE_SIZE) wAnnotations, formulaArgSetup, tableFormulas
10021073 Make / FREE=1/ WAVE /N= ( MINIMUM_WAVE_SIZE) collPlotFormData
10031074
1004- do
1075+ numDataInGraph = DimSize ( graphFormulas, ROWS)
1076+ for ( cntDataInGraph = 0; cntDataInGraph < numDataInGraph; cntDataInGraph += 1 )
1077+
1078+ WAVE /Z/ WAVE formulaResults = graphFormulas[ cntDataInGraph][ % DATA]
1079+ if ( ! WaveExists ( formulaResults))
1080+ ASSERT ( evalErr, "Got null wave as one result for formula, but evaluation returned no error" )
1081+ continue
1082+ endif
1083+ WAVE /T plotMetaData = graphFormulas[ cntDataInGraph][ % META]
10051084
10061085 WAVE /WAVE plotFormData = SF_CreatePlotFormulaDataWave ()
10071086 gdIndex = 0
10081087 annotation = ""
10091088 formulaAddedOncePerDataset = 0
10101089
1011- SplitString / E= SF_SWEEPFORMULA_WITH_REGEXP formulasRemain, yAndXFormula, moreFormulas
1012- if ( ! V_flag)
1013- break
1014- endif
1015- line = lineVars + lineGraph + lineGraphFormula
1016- lineGraphFormula = SF_GetLineNumberOfRemainingCode ( formulasRemain, moreFormulas)
1017- formulasRemain = moreFormulas
1090+ SF_GatherAxisLabels ( formulaResults, plotMetaData[ % XAXISLABEL] , "FORMULAX" , xAxisLabels)
1091+ SF_GatherAxisLabels ( formulaResults, plotMetaData[ % YAXISLABEL] , "FORMULAY" , yAxisLabels)
10181092
1019- [ xFormula, yFormula, xFormulaOffset] = SF_SplitGraphsToFormula ( yAndXFormula)
1020- SFH_ASSERT ( ! IsEmpty ( yFormula) , "Could not determine y [vs x] formula pair." )
1021-
1022- WAVE /Z/ WAVE formulaResults = $ ""
1023- try
1024- [ formulaResults, plotMetaData] = SF_GatherFormulaResults ( xFormula, yFormula, graph, line, xFormulaOffset)
1025- catch
1026- SF_KillEmptyDataWindows ( plotGraphs)
1027- Abort
1028- endtry
1029-
1030- SF_GatherAxisLabels ( formulaResults, plotMetaData. xAxisLabel, "FORMULAX" , xAxisLabels)
1031- SF_GatherAxisLabels ( formulaResults, plotMetaData. yAxisLabel, "FORMULAY" , yAxisLabels)
1032-
1033- if ( ! cmpstr ( plotMetaData. dataType, SF_DATATYPE_PSX))
1093+ if ( ! CmpStr ( plotMetaData[ % DATATYPE] , SF_DATATYPE_PSX))
10341094 PSX_Plot ( win, graph, formulaResults, plotMetaData)
10351095 postPlotPSX = 1
10361096 continue
@@ -1060,9 +1120,9 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
10601120
10611121 SFH_ASSERT ( ! ( IsTextWave ( wvResultY) && WaveDims ( wvResultY) > 1 ) , "Plotter got 2d+ text wave as y data." )
10621122
1063- [ color] = SF_GetTraceColor ( graph, plotMetaData. opStack , wvResultY, colorGroups)
1123+ [ color] = SF_GetTraceColor ( graph, plotMetaData[ % OPSTACK ] , wvResultY, colorGroups)
10641124
1065- if ( ! WaveExists ( wvResultX) && ! IsEmpty ( plotMetaData. xAxisLabel ))
1125+ if ( ! WaveExists ( wvResultX) && ! IsEmpty ( plotMetaData[ % XAXISLABEL ] ))
10661126 WAVE /Z wvResultX = JWN_GetNumericWaveFromWaveNote ( wvResultY, SF_META_XVALUES)
10671127
10681128 if ( ! WaveExists ( wvResultX))
@@ -1231,7 +1291,7 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
12311291 EnsureLargeEnoughWave ( wAnnotations, indexShouldExist = numAnnotations)
12321292 wAnnotations[ numAnnotations] = annotation
12331293 EnsureLargeEnoughWave ( formulaArgSetup, indexShouldExist = numAnnotations)
1234- formulaArgSetup[ numAnnotations] = plotMetaData. argSetupStack
1294+ formulaArgSetup[ numAnnotations] = plotMetaData[ % ARGSETUPSTACK ]
12351295 numAnnotations += 1
12361296 endif
12371297
@@ -1241,7 +1301,7 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
12411301 Redimension / N= ( gdIndex, -1 ) tracesInGraph, dataInGraph
12421302 collPlotFormData[ formulaCounter] = plotFormData
12431303 formulaCounter += 1
1244- while ( 1 )
1304+ endfor
12451305
12461306 if ( numTableFormulas)
12471307 Redimension / N= ( numTableFormulas) tableFormulas
@@ -1442,6 +1502,10 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
14421502 endif
14431503 endfor
14441504 endif
1505+
1506+ if ( evalErr)
1507+ Abort
1508+ endif
14451509End
14461510
14471511static Function SF_DeriveTraceDisplayMode ( WAVE /Z wvX, WAVE wvY)
0 commit comments