File MIES_SweepFormula.ipf

SF Sweep formula allows to do analysis on sweeps with a dedicated formula language

Functions

variable SF_BringBrowserToFront()
wave SF_GetNamedOperations()
wave SF_GetFormulaKeywords()
string SF_EscapeJsonPath(string str)

add escape characters to a path element

variable SF_FormulaWaveScaleTransfer(wave source, wave dest, variable dimSource, variable dimDest)

transfer the wave scaling from one wave to another

Note: wave scale transfer requires wave units for the first wave or second wave

Parameters:
  • source – Wave whos scaling should get transferred

  • dest – Wave that accepts the new scaling

  • dimSource – dimension of the source wave, if SF_TRANSFER_ALL_DIMS is used then all scales and units are transferred on the same dimensions, dimDest is ignored in that case, no unit check is applied in that case

  • dimDest – dimension of the destination wave

static std::tuple<WaveRefWave, SF_PlotMetaData> SF_GatherFormulaResults(string xFormula, string yFormula, string graph, variable lineNr, variable offset)
static string SF_FormatUnit(string unit)
static string SF_GetAnnotationPrefix(string dataType)
static string SF_GetTraceAnnotationText(SF_PlotMetaData *plotMetaData, wave data)
static string SF_GetMetaDataAnnotationText(SF_PlotMetaData *plotMetaData, wave data, string traceName)
static wave SF_GenerateTraceColors(wave colorGroups)
static wave SF_GetColorGroups(WaveRefWave formulaResults, WaveOrNull colorGroups)

Add the color groups from the formulaResults to colorGroups and return it.

std::tuple<RGBColor> SF_GetTraceColor(string graph, string opStack, wave data, WaveOrNull colorGroups)
static std::tuple<WaveText, variable> SF_CreateTraceNames(variable numTraces, variable dataNum, SF_PlotMetaData *plotMetaData, wave data)

Generate numTraces trace names for the given input.

Generates the trace names required for a single formula in the plotter and therefore the trace names range from traceCnt to traceCnt + numTraces - 1.

Return values:
  • traces – generated trace names

  • traceCnt – total count of all traces (input and output)

static string SF_ShrinkLegend(string annotation)

Reduces a multi line legend to a single line if only the sweep number changes. Returns the original annotation if more changes or the legend text does not follow the exected format

static std::tuple<WaveText, WaveRefWave> SF_PreparePlotter(string winNameTemplate, string graph, variable winDisplayMode, variable numGraphs)
static variable SF_CommonWindowSetup(string win, string graph)
static variable SF_GatherAxisLabels(WaveRefWave formulaResults, string explicitLbl, string formulaLabel, WaveText axisLabels)
static string SF_CombineAxisLabels(WaveText axisLabels)
static variable SF_CheckNumTraces(string graph, variable numTraces)
static variable SF_CleanUpPlotWindowsOnFail(WaveText plotGraphs)
static variable SF_KillWorkingDF(string graph)
static wave GetSweepFormula(dfref dfr, variable graphNr, variable forAxis)

Return the X or Y wave for the sweep formula.

static wave SF_PrepareResultWaveForPlotting(dfref dfr, wave wvResult, variable dataCnt, variable forAxis)
static variable SF_FormulaPlotter(string graph, string formula, variable dmMode = defaultValue, variable lineVars = defaultValue)

Plot the formula using the data from graph.

Parameters:
  • graph – graph to pass to SF_FormulaExecutor

  • formula – formula to plot

  • dmMode – [optional, default DM_SUBWINDOWS] display mode that defines how multiple sweepformula graphs are arranged

  • lineVars – [optional, default NaN] number of lines in the SF notebook with variable assignments in front of the formula

static variable SF_DeriveTraceDisplayMode(WaveOrNull wvX, wave wvY)
static variable SF_GetShowLegend(wave wv)
static variable SF_SplitPlotting(wave wv, variable dim, variable i, variable split)

utility function for SF_FormulaPlotter

split dimension dim of wave wv into slices of size split and get the starting index i

string SF_PreprocessInput(string formula)

Pre process code entered into the notebook.

  • unify line endings to CR

  • remove comments at line ending

  • cut off last CR from back conversion with TextWaveToList

variable SF_button_sweepFormula_check(WMButtonAction *ba)
static variable SF_ClearSFOutputState()
variable SF_DisplayOutputStateInGUI(string databrowser)
std::tuple<WaveText, string> SF_GetVariableAssignments(string preProcCode)
static string SF_CheckVariableAssignments(string preProcCode, variable jsonId)
static variable SF_GetLineNumberOfRemainingCode(string all, string endPart)

When preprocessing the SF notebook content there are occurances where a part at the front is split off for further processing. For the source location tracking it is important to track the current line number. Thus, the number of <CR> in the split off part need to be counted. This helper function counts these <CR>s.

Parameters:
  • all – full string content

  • endPart – remaining string content (where all == split_off_part + endPart)

static variable SF_CheckInputCode(string code, string graph)

Checks input code, sets globals for jsonId and error string.

static variable SF_AddSourceInfoToJSON(variable jsonId, string jsonPath, string subPath, variable srcLocId, string formula, variable line, variable offset)

Helper function to add base source location information to a JSON created for “check” The full path is build from: jsonPath + “/source_location” + subPath + <internalPathForElement> Internal paths are (path : content): /source : formula /line : line number /start_offset : offset /source_map : here JSON form srcLocId is added.

srcLocId is created and returned by SFP_ParseFormulaToJSON

Parameters:
  • jsonId – JSON created for “check”

  • jsonPath – the base JSON path for the specific formula set (from graph/pair) or variable

  • subPath – the sub JSON path for the specific formula or variable name

  • srcLocId – the JSON with the source location information, it is released after adding it to the main JSON from jsonid

  • formula – formula string

  • line – line in the SF notebook where the formula is

  • offset – character offset of the formula in the line in the SF notebook

variable SF_Update(string graph)
variable SF_IsActive(string win)

checks if SweepFormula (SF) is active.

std::tuple<string, string> SF_GetCode(string win)

Return the sweep formula code in raw and with all necessary preprocesssing.

variable SF_button_sweepFormula_display(WMButtonAction *ba)
variable SF_TabProc_Formula(WMTabControlAction *tca)
variable SF_SetSweepXAxisTickLabels(wave output, WaveOrNull selectDataPlainOrArray)
static wave SF_SplitCodeToGraphs(string code)
static std::tuple<string, string, variable> SF_SplitGraphsToFormula(string graphCode)
static string SF_GetFormulaWinNameTemplate(string mainWindow)
variable SF_button_sweepFormula_tofront(WMButtonAction *ba)
wave SF_GetAllOldCodeForGUI(string win)
static wave SF_GetAllOldCode()
variable SF_PopMenuProc_OldCode(WMPopupAction *pa)
static std::tuple<RGBColor> SF_GetErrorColorsFromSeverity(variable severity)
variable SF_SetOutputState(string error, variable severity)
variable SF_SetFormula(string databrowser, string formula)
static variable SF_ConvertAllReturnDataToPermanent(WaveRefWave output, string win, string opShort)
wave SF_GetArgumentTop(SF_ExecutionData *exd, string opShort)

Executes the complete arguments of the JSON and parses the resulting data to a waveRef type.

Deprecated:

: executing all arguments e.g. as array in the executor poses issues as soon as data types get mixed. e.g. operation(0, A, [1, 2, 3]) fails as [0, A, [1, 2, 3]] can not be converted to an Igor wave. Thus, it is strongly recommended to parse each argument separately.

static wave SF_CreatePlotFormulaDataWave()
static variable SF_CollectTraceData(variable *index, WaveRefWave graphData, string traceName, WaveOrNull wx, wave wy)
static std::tuple<string, string> SF_SplitVariableAssignment(string line)
dfref SF_GetBrowserDF(string graph)
wave SF_ResolveDatasetFromJSON(SF_ExecutionData *exd, variable argNum, variable copy = defaultValue)

Executes the part of the argument part of the JSON and parses the resulting data to a waveRef type.

wave SF_ResolveDataset(wave input)
string SF_GetDefaultFormula()
static variable SF_FormulaPlotterExtendResultsIfCompatible(WaveRefWave formulaResults)

This function extends formulaResults if possible. For each result from a Y formula it is attempted to move datasets from inside an array outside in the form [dataset(1, 2), dataset(3, 4)] -> dataset([1, 3], [3, 4]) because the plotter can iterate over datasets only at the outermost occurrence. As result the inside elements may be plottable after this transformation. algorithm details: Each Y formula result is ‘repackaged’ in an array and attempted to be transformed Case 1: On a failed transformation the initial array is returned. Case 2: On a successful transformation a dataset with one or more elements is returned Regarding the plotter the array of case 1 is treated as a single dataset. All the results from case 1 and case 2 are gathered in a waveref wave collectY. The X formula results are associated multiple times for case 2 if multiple datasets were returned and are gathered in a waveref wave collectX that grows identical to collectY. The formulaResults wave gets modified to store the new transformed results.

variable TraceValueDisplayHook(WMTooltipHookStruct *s)
static string SF_IsExecutionErrorInVariable(string win)

Utility function that is called in the process of calculating the error location in the SF notebook. If the current error location points to a variable then the variable should be marked too. Generally errors in variables can only happen in the execution phase. This function checks if the last execution path pointed to a variable. If it does it returns the variable name, an empty string otherwise.

static std::tuple<variable, variable> SF_CalculateErrorLocationInNotebook(string win)

calculate the error position within the sf notebook In notebooks every paragraph ends with a CR. It is possible to navigate through paragraphs and character offsets in these paragraphs. As formula code can contain CR, these have to be accounted for in counting paragraphs. Also the effective character offset in the NB paragraph needs to be calculated.

static variable SF_MarkErrorLocationInNotebook(string win)

Mark the error location in red in the SF notebook.

Variables

static const string SF_SWEEPFORMULA_REGEXP = "^(.+?)(?:\\bvs\\b(.+))?$"

Regular expression which extracts both formulas from $a vs $b

static const string SF_SWEEPFORMULA_GRAPHS_REGEXP = "^(.+?)(?:\\r[ \t]*and[ \t]*\\r(.*))?$"

Regular expression which extracts formulas pairs from $a vs $b\rand\r$c vs $d\rand\r...

static const string SF_SWEEPFORMULA_WITH_REGEXP = "^(.+?)(?:\\r[ \t]*with[ \t]*\\r(.*))?$"

Regular expression which extracts y-formulas from $a\rwith\r$b\rwith\r$c\r...

static const double SF_MAX_NUMPOINTS_FOR_MARKERS = 1000
static const string SF_CHAR_COMMENT = "#"
static const string SF_CHAR_CR = "\r"
static const string SF_CHAR_NEWLINE = "\n"
static const string SF_PLOTTER_GUIDENAME = "HOR"
static const string SF_XLABEL_USER = ""
static const double SF_NUMTRACES_ERROR_THRESHOLD = 10000
static const double SF_NUMTRACES_WARN_THRESHOLD = 1000
static const double SF_SWEEPFORMULA_AXIS_X = 0
static const double SF_SWEEPFORMULA_AXIS_Y = 1