Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Packages/MIES/MIES_GuiUtilities.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1864,13 +1864,15 @@ End
/// @brief Recursively build a list of windows, including all child
/// windows, starting with wName.
///
/// @param wName parent window name to start with, if wName is empty then all graphs, tables, layouts, notebooks and panels
/// @param wName parent window name to start with, if wName is empty then all graphs, tables, layouts, notebooks, panels and gizmo
/// with subwindows (possible for graphs and panels) are returned
/// @return A string containing names of windows. This list is a semicolon separated list. It will include the window
/// wName, if wName was not empty, and all of its children and children of children, etc.
Function/S GetAllWindows(string wName)

string windowList = ""

ASSERT(!IsNull(wName), "Can not work with null string")
[windowList] = GetAllWindowsImpl(wName)

return windowList
Expand All @@ -1889,6 +1891,9 @@ static Function [string windowList] GetAllWindowsImpl(string wName)
[windowList] = GetAllWindowsImpl(win)
endfor
else
if(!WindowExists(wName))
return [windowList]
endif
windowList = AddListItem(wName, windowList, ";", Inf)

if(!WindowTypeCanHaveChildren(wName))
Expand Down
9 changes: 0 additions & 9 deletions Packages/MIES/MIES_Structures.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -630,15 +630,6 @@ Structure CheckParametersStruct
string setName // name of the stimulus set
EndStructure

/// @brief Helper struct for data gathered by SF formula plotter in SF_GatherFormulaResults
Structure SF_PlotMetaData
string dataType // from SF_META_DATATYPE constant
string opStack // from SF_META_OPSTACK constant
string argSetupStack // from SF_META_ARGSETUPSTACK constant
string xAxisLabel // from SF_META_XAXISLABEL constant
string yAxisLabel // from SF_META_YAXISLABEL constant
EndStructure

/// @brief ReadOut Structure for ASYNC
Structure ASYNC_ReadOutStruct
DFREF dfr // dfr with output data
Expand Down
193 changes: 128 additions & 65 deletions Packages/MIES/MIES_SweepFormula.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Function SF_FormulaWaveScaleTransfer(WAVE source, WAVE dest, variable dimSource,
endswitch
End

static Function [WAVE/WAVE formulaResults, STRUCT SF_PlotMetaData plotMetaData] SF_GatherFormulaResults(string xFormula, string yFormula, string graph, variable lineNr, variable offset)
static Function [WAVE/WAVE formulaResults, WAVE/T plotMetaData] SF_GatherFormulaResults(string xFormula, string yFormula, string graph, variable lineNr, variable offset)

variable i, numResultsY, numResultsX
variable useXLabel, addDataUnitsInAnnotation
Expand Down Expand Up @@ -234,11 +234,13 @@ static Function [WAVE/WAVE formulaResults, STRUCT SF_PlotMetaData plotMetaData]
dataUnits = SelectString(addDataUnitsInAnnotation && !IsEmpty(dataUnitCheck), "", SF_FormatUnit(dataUnitCheck))
endif

plotMetaData.dataType = JWN_GetStringFromWaveNote(wvYRef, SF_META_DATATYPE)
plotMetaData.opStack = JWN_GetStringFromWaveNote(wvYRef, SF_META_OPSTACK)
plotMetaData.argSetupStack = JWN_GetStringFromWaveNote(wvYRef, SF_META_ARGSETUPSTACK)
plotMetaData.xAxisLabel = SelectString(useXLabel, SF_XLABEL_USER, JWN_GetStringFromWaveNote(wvYRef, SF_META_XAXISLABEL))
plotMetaData.yAxisLabel = JWN_GetStringFromWaveNote(wvYRef, SF_META_YAXISLABEL) + dataUnits
WAVE/T plotMetaData = GetSFPlotMetaData()

plotMetaData[%DATATYPE] = JWN_GetStringFromWaveNote(wvYRef, SF_META_DATATYPE)
plotMetaData[%OPSTACK] = JWN_GetStringFromWaveNote(wvYRef, SF_META_OPSTACK)
plotMetaData[%ARGSETUPSTACK] = JWN_GetStringFromWaveNote(wvYRef, SF_META_ARGSETUPSTACK)
plotMetaData[%XAXISLABEL] = SelectString(useXLabel, SF_XLABEL_USER, JWN_GetStringFromWaveNote(wvYRef, SF_META_XAXISLABEL))
plotMetaData[%YAXISLABEL] = JWN_GetStringFromWaveNote(wvYRef, SF_META_YAXISLABEL) + dataUnits

return [formulaResults, plotMetaData]
End
Expand Down Expand Up @@ -266,15 +268,15 @@ static Function/S SF_GetAnnotationPrefix(string dataType)
endswitch
End

static Function/S SF_GetTraceAnnotationText(STRUCT SF_PlotMetaData &plotMetaData, WAVE data)
static Function/S SF_GetTraceAnnotationText(WAVE/T plotMetaData, WAVE data)

variable channelNumber, channelType, sweepNo, isAveraged
string channelId, prefix, legendPrefix
string traceAnnotation, annotationPrefix

prefix = RemoveEnding(ReplaceString(";", plotMetaData.opStack, " "), " ")
prefix = RemoveEnding(ReplaceString(";", plotMetaData[%OPSTACK], " "), " ")

strswitch(plotMetaData.dataType)
strswitch(plotMetaData[%DATATYPE])
case SF_DATATYPE_EPOCHS: // fallthrough
case SF_DATATYPE_SWEEP: // fallthrough
case SF_DATATYPE_LABNOTEBOOK: // fallthrough
Expand All @@ -287,7 +289,7 @@ static Function/S SF_GetTraceAnnotationText(STRUCT SF_PlotMetaData &plotMetaData
legendPrefix = " " + legendPrefix + " "
endif

sprintf annotationPrefix, "%s%s", SF_GetAnnotationPrefix(plotMetaData.dataType), legendPrefix
sprintf annotationPrefix, "%s%s", SF_GetAnnotationPrefix(plotMetaData[%DATATYPE]), legendPrefix

if(IsValidSweepNumber(sweepNo))
channelNumber = JWN_GetNumberFromWaveNote(data, SF_META_CHANNELNUMBER)
Expand All @@ -299,7 +301,7 @@ static Function/S SF_GetTraceAnnotationText(STRUCT SF_PlotMetaData &plotMetaData
endif
break
default:
if(WhichListItem(SF_OP_DATA, plotMetaData.opStack) == -1)
if(WhichListItem(SF_OP_DATA, plotMetaData[%OPSTACK]) == -1)
sprintf traceAnnotation, "%s", prefix
else
channelNumber = JWN_GetNumberFromWaveNote(data, SF_META_CHANNELNUMBER)
Expand Down Expand Up @@ -327,7 +329,7 @@ static Function/S SF_GetTraceAnnotationText(STRUCT SF_PlotMetaData &plotMetaData
return traceAnnotation
End

static Function/S SF_GetMetaDataAnnotationText(STRUCT SF_PlotMetaData &plotMetaData, WAVE data, string traceName)
static Function/S SF_GetMetaDataAnnotationText(WAVE/T plotMetaData, WAVE data, string traceName)

return "\\s(" + traceName + ") " + SF_GetTraceAnnotationText(plotMetaData, data) + "\r"
End
Expand Down Expand Up @@ -492,7 +494,7 @@ End
///
/// @retval traces generated trace names
/// @retval traceCnt total count of all traces (input *and* output)
static Function [WAVE/T traces, variable traceCnt] SF_CreateTraceNames(variable numTraces, variable dataNum, STRUCT SF_PlotMetaData &plotMetaData, WAVE data)
static Function [WAVE/T traces, variable traceCnt] SF_CreateTraceNames(variable numTraces, variable dataNum, WAVE/T plotMetaData, WAVE data)

string traceAnnotation

Expand Down Expand Up @@ -829,8 +831,6 @@ End

static Function SF_KillWindowAndParentsIfEmpty(string win)

string subWindows

KillWindow/Z $win
for(;;)
win = RemoveEnding(win, "#" + LastStringFromList(win, sep = "#"))
Expand All @@ -855,7 +855,7 @@ static Function SF_KillEmptyDataWindows(WAVE/T plotGraphs)
endfor
End

/// @brief Tiles the subwindows in the panels acording to existing data, requires SF_DM_SUBWINDOWS mode
/// @brief Tiles the subwindows in the panels according to existing data, requires SF_DM_SUBWINDOWS mode
static Function SF_TileExistingData(WAVE/T plotGraphs)

variable numSubWins, numData, guidePos, subWindowIndex, posIndex, col, numCols
Expand Down Expand Up @@ -939,6 +939,76 @@ static Function SF_IsDataForTableDisplay(WAVE wvY)
return IsNaN(useTable) ? 0 : !!useTable
End

/// @brief Evaluates the formulas and returns results for all successfully evaluated ones
/// Data structure wave tree, rows are filled:
/// WREF indexing over all graphs
/// WREF indexing over all formula results with two columns
/// col %DATA: formularesults
/// col %META: plot meta data
///
/// Formula results are in the format as returned by SF_GatherFormulaResults() from GetFormulaGatherWave()
/// with indexing over the results of a single formula and two columns
/// col %FORMULAX
/// col %FORMULAY
///
/// @param graph graph name of SB/DB
/// @param formula formula to plot
/// @param lineVars number of lines in the SF notebook with variable assignments in front of the formula
///
/// @returns dataInGraphs waveref wave with the structure as explained above
/// @returns err set to 1 if there was an evaluation error, 0 otherwise
static Function [WAVE/WAVE dataInGraphs, variable err] SF_PlotterGetDataFromFormulas(string graph, string formula, variable lineVars)

variable i, numDataInGraph, numGraphs
string formulasRemain, moreFormulas, xFormula, yFormula, yAndXFormula
variable line, lineGraph, lineGraphFormula, xFormulaOffset

err = 0

WAVE/T graphCode = SF_SplitCodeToGraphs(formula)
numGraphs = DimSize(graphCode, ROWS)

Make/FREE/WAVE/N=(numGraphs) dataInGraphs
for(i = 0; i < numGraphs; i += 1)

formulasRemain = graphCode[i][%GRAPHCODE]
lineGraph = str2num(graphCode[i][%LINE])

WAVE/WAVE dataInGraph = GetSFDataInGraph()
numDataInGraph = 0
do
SplitString/E=SF_SWEEPFORMULA_WITH_REGEXP formulasRemain, yAndXFormula, moreFormulas
if(!V_flag)
break
endif
line = lineVars + lineGraph + lineGraphFormula
lineGraphFormula = SF_GetLineNumberOfRemainingCode(formulasRemain, moreFormulas)
formulasRemain = moreFormulas

[xFormula, yFormula, xFormulaOffset] = SF_SplitGraphsToFormula(yAndXFormula)
SFH_ASSERT(!IsEmpty(yFormula), "Could not determine y [vs x] formula pair.")

WAVE/Z/WAVE formulaResults = $""
WAVE/Z/T plotMetaData = $""
try
[formulaResults, plotMetaData] = SF_GatherFormulaResults(xFormula, yFormula, graph, line, xFormulaOffset)
catch
err = 1
continue
endtry
EnsureLargeEnoughWave(dataInGraph, indexShouldExist = numDataInGraph)
dataInGraph[numDataInGraph][%DATA] = formulaResults
dataInGraph[numDataInGraph][%META] = plotMetaData

numDataInGraph += 1
while(1)
Redimension/N=(numDataInGraph, -1) dataInGraph
dataInGraphs[i] = dataInGraph
endfor

return [dataInGraphs, err]
End

/// @brief Plot the formula using the data from graph
///
/// @param graph graph to pass to SF_FormulaExecutor
Expand All @@ -949,34 +1019,44 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode

string trace, customLegend
variable i, j, k, l, numTraces, splitTraces, splitY, splitX, numGraphs, numWins, numData, dataCnt, traceCnt
variable winDisplayMode, showLegend, tagCounter, overrideMarker, line, lineGraph, lineGraphFormula
variable winDisplayMode, showLegend, tagCounter, overrideMarker
variable xMxN, yMxN, xPoints, yPoints, keepUserSelection, numAnnotations, formulasAreDifferent, postPlotPSX
variable formulaCounter, gdIndex, markerCode, lineCode, lineStyle, traceToFront, isCategoryAxis, xFormulaOffset
variable showInTable, numTableFormulas, formulaAddedOncePerDataset
variable formulaCounter, gdIndex, markerCode, lineCode, lineStyle, traceToFront, isCategoryAxis
variable showInTable, numTableFormulas, formulaAddedOncePerDataset, cntDataInGraph, numDataInGraph, evalErr
string win, winTable, wList, winNameTemplate, exWList, wName, annotation, xAxisLabel, yAxisLabel, wvName, info, xAxis
string formulasRemain, moreFormulas, yAndXFormula, xFormula, yFormula, tagText, name, winHook
STRUCT SF_PlotMetaData plotMetaData
STRUCT RGBColor color
string tagText, name, winHook
STRUCT RGBColor color

winDisplayMode = ParamIsDefault(dmMode) ? SF_DM_SUBWINDOWS : dmMode
lineVars = ParamIsDefault(lineVars) ? NaN : lineVars
ASSERT(winDisplaymode == SF_DM_NORMAL || winDisplaymode == SF_DM_SUBWINDOWS, "Invalid display mode.")

DFREF dfr = SF_GetBrowserDF(graph)

WAVE/T graphCode = SF_SplitCodeToGraphs(formula)

SVAR lastCode = $GetLastSweepFormulaCode(dfr)
DFREF dfr = SF_GetBrowserDF(graph)
SVAR lastCode = $GetLastSweepFormulaCode(dfr)
keepUserSelection = !cmpstr(lastCode, formula)

numGraphs = DimSize(graphCode, ROWS)
[WAVE/WAVE evalFormulas, evalErr] = SF_PlotterGetDataFromFormulas(graph, formula, lineVars)

numGraphs = DimSize(evalFormulas, ROWS)
wList = ""
winNameTemplate = SF_GetFormulaWinNameTemplate(graph)

[WAVE/T plotGraphs, WAVE/WAVE infos] = SF_PreparePlotter(winNameTemplate, graph, winDisplayMode, numGraphs)

for(j = 0; j < numGraphs; j += 1)

win = plotGraphs[j][%GRAPH]
winTable = plotGraphs[j][%TABLE]
if(winDisplayMode == SF_DM_NORMAL)
wList = AddListItem(win, wList)
wList = AddListItem(winTable, wList)
endif

WAVE/WAVE graphFormulas = evalFormulas[j]
if(!DimSize(graphFormulas, ROWS))
continue
endif

traceCnt = 0
numAnnotations = 0
postPlotPSX = 0
Expand All @@ -988,49 +1068,28 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode

Make/FREE/T/N=0 xAxisLabels, yAxisLabels

formulasRemain = graphCode[j][%GRAPHCODE]
lineGraph = str2num(graphCode[j][%LINE])

win = plotGraphs[j][%GRAPH]
winTable = plotGraphs[j][%TABLE]
if(winDisplayMode == SF_DM_NORMAL)
wList = AddListItem(win, wList)
wList = AddListItem(winTable, wList)
endif

Make/FREE=1/T/N=(MINIMUM_WAVE_SIZE) wAnnotations, formulaArgSetup, tableFormulas
Make/FREE=1/WAVE/N=(MINIMUM_WAVE_SIZE) collPlotFormData

do
numDataInGraph = DimSize(graphFormulas, ROWS)
for(cntDataInGraph = 0; cntDataInGraph < numDataInGraph; cntDataInGraph += 1)

WAVE/Z/WAVE formulaResults = graphFormulas[cntDataInGraph][%DATA]
if(!WaveExists(formulaResults))
ASSERT(evalErr, "Got null wave as one result for formula, but evaluation returned no error")
continue
endif
WAVE/T plotMetaData = graphFormulas[cntDataInGraph][%META]

WAVE/WAVE plotFormData = SF_CreatePlotFormulaDataWave()
gdIndex = 0
annotation = ""
formulaAddedOncePerDataset = 0

SplitString/E=SF_SWEEPFORMULA_WITH_REGEXP formulasRemain, yAndXFormula, moreFormulas
if(!V_flag)
break
endif
line = lineVars + lineGraph + lineGraphFormula
lineGraphFormula = SF_GetLineNumberOfRemainingCode(formulasRemain, moreFormulas)
formulasRemain = moreFormulas
SF_GatherAxisLabels(formulaResults, plotMetaData[%XAXISLABEL], "FORMULAX", xAxisLabels)
SF_GatherAxisLabels(formulaResults, plotMetaData[%YAXISLABEL], "FORMULAY", yAxisLabels)

[xFormula, yFormula, xFormulaOffset] = SF_SplitGraphsToFormula(yAndXFormula)
SFH_ASSERT(!IsEmpty(yFormula), "Could not determine y [vs x] formula pair.")

WAVE/Z/WAVE formulaResults = $""
try
[formulaResults, plotMetaData] = SF_GatherFormulaResults(xFormula, yFormula, graph, line, xFormulaOffset)
catch
SF_KillEmptyDataWindows(plotGraphs)
Abort
endtry

SF_GatherAxisLabels(formulaResults, plotMetaData.xAxisLabel, "FORMULAX", xAxisLabels)
SF_GatherAxisLabels(formulaResults, plotMetaData.yAxisLabel, "FORMULAY", yAxisLabels)

if(!cmpstr(plotMetaData.dataType, SF_DATATYPE_PSX))
if(!CmpStr(plotMetaData[%DATATYPE], SF_DATATYPE_PSX))
PSX_Plot(win, graph, formulaResults, plotMetaData)
postPlotPSX = 1
continue
Expand Down Expand Up @@ -1060,9 +1119,9 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode

SFH_ASSERT(!(IsTextWave(wvResultY) && WaveDims(wvResultY) > 1), "Plotter got 2d+ text wave as y data.")

[color] = SF_GetTraceColor(graph, plotMetaData.opStack, wvResultY, colorGroups)
[color] = SF_GetTraceColor(graph, plotMetaData[%OPSTACK], wvResultY, colorGroups)

if(!WaveExists(wvResultX) && !IsEmpty(plotMetaData.xAxisLabel))
if(!WaveExists(wvResultX) && !IsEmpty(plotMetaData[%XAXISLABEL]))
WAVE/Z wvResultX = JWN_GetNumericWaveFromWaveNote(wvResultY, SF_META_XVALUES)

if(!WaveExists(wvResultX))
Expand Down Expand Up @@ -1231,7 +1290,7 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
EnsureLargeEnoughWave(wAnnotations, indexShouldExist = numAnnotations)
wAnnotations[numAnnotations] = annotation
EnsureLargeEnoughWave(formulaArgSetup, indexShouldExist = numAnnotations)
formulaArgSetup[numAnnotations] = plotMetaData.argSetupStack
formulaArgSetup[numAnnotations] = plotMetaData[%ARGSETUPSTACK]
numAnnotations += 1
endif

Expand All @@ -1241,7 +1300,7 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
Redimension/N=(gdIndex, -1) tracesInGraph, dataInGraph
collPlotFormData[formulaCounter] = plotFormData
formulaCounter += 1
while(1)
endfor

if(numTableFormulas)
Redimension/N=(numTableFormulas) tableFormulas
Expand Down Expand Up @@ -1442,6 +1501,10 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
endif
endfor
endif

if(evalErr)
Abort
endif
End

static Function SF_DeriveTraceDisplayMode(WAVE/Z wvX, WAVE wvY)
Expand Down
Loading
Loading