@@ -30,6 +30,10 @@ static StrConstant SF_OP_APFREQUENCY_NONORM = "nonorm"
3030static StrConstant SF_OP_APFREQUENCY_X_COUNT = "count"
3131static StrConstant SF_OP_APFREQUENCY_X_TIME = "time"
3232
33+ static StrConstant SF_OP_IVSCCAPFREQUENCY_MIN = "min"
34+ static StrConstant SF_OP_IVSCCAPFREQUENCY_MAX = "max"
35+ static StrConstant SF_OP_IVSCCAPFREQUENCY_NONE = "none"
36+
3337static StrConstant SF_OP_AVG_INSWEEPS = "in"
3438static StrConstant SF_OP_AVG_OVERSWEEPS = "over"
3539static StrConstant SF_OP_AVG_GROUPS = "group"
@@ -2503,3 +2507,136 @@ Function/WAVE SFO_OperationTable(STRUCT SF_ExecutionData &exd)
25032507
25042508 return SFH_GetOutputForExecutor ( output, exd. graph, SF_OP_TABLE)
25052509End
2510+
2511+ /// @brief Sets the plot meta data for the ivscc_apfrequency operation
2512+ static Function SFO_OperationIVSCCApFrequencySetPlotProperties ( WAVE wvY, variable xAxisPercentage, variable yAxisPercentage)
2513+
2514+ JWN_SetNumberInWaveNote ( wvY, SF_META_XAXISPERCENT, xAxisPercentage)
2515+ JWN_SetNumberInWaveNote ( wvY, SF_META_YAXISPERCENT, yAxisPercentage)
2516+ End
2517+
2518+ // ivscc_apfrequency([xaxisOffset, yaxisOffset, xAxisPercentage, yAxisPercentage])
2519+ Function /WAVE SFO_OperationIVSCCApFrequency ( STRUCT SF_ExecutionData &exd)
2520+
2521+ string opShort = SF_OP_IVSCCAPFREQUENCY
2522+ variable numArgsMin = 0
2523+ variable numArgsMax = 4
2524+ string formula, expr, exprPart
2525+ variable i , numArgs, col, size, numExp
2526+ variable xAxisPercentage, yAxisPercentage
2527+ string xaxisOffset, yaxisOffset
2528+
2529+ SFH_ASSERT ( BSP_IsSweepBrowser ( exd. graph) , "ivscc_apfrequency only works with sweepbrowser" )
2530+
2531+ numArgs = SFH_GetNumberOfArguments ( exd)
2532+ SFH_ASSERT ( numArgs <= numArgsMax, "ivscc_apfrequency has " + num2istr ( numArgsMax) + " arguments at most." )
2533+ SFH_ASSERT ( numArgs >= numArgsMin, "ivscc_apfrequency needs at least " + num2istr ( numArgsMin) + " argument(s)." )
2534+
2535+ xaxisOffset = SFH_GetArgumentAsText ( exd, opShort, 0, defValue = SF_OP_IVSCCAPFREQUENCY_MIN, allowedValues = { SF_OP_IVSCCAPFREQUENCY_MIN, SF_OP_IVSCCAPFREQUENCY_MAX, SF_OP_IVSCCAPFREQUENCY_NONE})
2536+ yaxisOffset = SFH_GetArgumentAsText ( exd, opShort, 1, defValue = SF_OP_IVSCCAPFREQUENCY_MIN, allowedValues = { SF_OP_IVSCCAPFREQUENCY_MIN, SF_OP_IVSCCAPFREQUENCY_MAX, SF_OP_IVSCCAPFREQUENCY_NONE})
2537+ xAxisPercentage = SFH_GetArgumentAsNumeric ( exd, opShort, 2, defValue = 100, checkFunc = BetweenZeroAndOneHoundred)
2538+ yAxisPercentage = SFH_GetArgumentAsNumeric ( exd, opShort, 3, defValue = 100, checkFunc = BetweenZeroAndOneHoundred)
2539+
2540+ WAVE /T sweepMap = SB_GetSweepMap ( exd. graph)
2541+ col = FindDimlabel ( sweepMap, COLS, "FileName" )
2542+ size = GetNumberFromWaveNote ( sweepMap, NOTE_INDEX)
2543+ Duplicate / FREE/ RMD= [ 0, size - 1 ][ col] sweepMap, fileNames
2544+ WAVE /T uniqueFiles = GetUniqueEntries ( fileNames, dontDuplicate = 1 )
2545+ numExp = DimSize ( uniqueFiles, ROWS)
2546+ SFH_ASSERT ( numExp > 0, "ivscc_apfrequency: data from at least one experiment has to be loaded" )
2547+
2548+ Make / FREE/ T/ N= ( numExp) elems
2549+
2550+ formula = "sel = select(selsweeps(), selstimset(\" *rheo*\" , \" *supra*\" ), selvis(all))\r "
2551+ for ( i = 0; i < numExp; i += 1 )
2552+ sprintf expr, "selexpAD%d = select(selexp(\" %s\" ), $sel, selchannels(AD0), selrange(E1))" , i , uniqueFiles[ i ]
2553+ formula = SF_AddExpressionToFormula ( formula, expr)
2554+ sprintf expr, "selexpDA%d = select(selexp(\" %s\" ), $sel, selchannels(DA0), selrange(E1))" , i , uniqueFiles[ i ]
2555+ formula = SF_AddExpressionToFormula ( formula, expr)
2556+ sprintf expr, "freq%d = apfrequency(data($selexpAD%d))" , i , i
2557+ formula = SF_AddExpressionToFormula ( formula, expr)
2558+ sprintf expr, "current%d = max(data($selexpDA%d))" , i , i
2559+ formula = SF_AddExpressionToFormula ( formula, expr)
2560+ if ( ! CmpStr ( xaxisOffset, SF_OP_IVSCCAPFREQUENCY_MIN))
2561+ sprintf expr, "currentNorm%d = $current%d - extract($current%d, 0)" , i , i , i
2562+ elseif ( ! CmpStr ( xaxisOffset, SF_OP_IVSCCAPFREQUENCY_MAX))
2563+ sprintf expr, "currentNorm%d = $current%d - max(flatten($current%d))" , i , i , i
2564+ elseif ( ! CmpStr ( xaxisOffset, SF_OP_IVSCCAPFREQUENCY_NONE))
2565+ sprintf expr, "currentNorm%d = $current%d" , i , i
2566+ else
2567+ FATAL_ERROR ( "Unknown xaxisOffset specification" )
2568+ endif
2569+ formula = SF_AddExpressionToFormula ( formula, expr)
2570+ endfor
2571+
2572+ elems[] = "$freq" + num2istr ( p)
2573+ expr = "ivsccavg = avg([" + TextWaveToList ( elems, "," , trailSep = 0 ) + "], group)"
2574+ formula = SF_AddExpressionToFormula ( formula, expr)
2575+
2576+ elems[] = "$currentNorm" + num2istr ( p)
2577+ expr = "ivscccurrentavg = avg([" + TextWaveToList ( elems, "," , trailSep = 0 ) + "], group)"
2578+ formula = SF_AddExpressionToFormula ( formula, expr)
2579+
2580+ elems[] = "\" " + uniqueFiles[ p] + "\" "
2581+ expr = "ivscc_apfrequency_explist = [" + TextWaveToList ( elems, "," , trailSep = 0 ) + "]"
2582+ formula = SF_AddExpressionToFormula ( formula, expr)
2583+
2584+ WAVE /WAVE varStorage = GetSFVarStorage ( exd. graph)
2585+ Duplicate / FREE varStorage, varBackup
2586+ SFE_ExecuteVariableAssignments ( exd. graph, formula)
2587+
2588+ WAVE /WAVE varStorageOp = GetSFVarStorage ( exd. graph)
2589+ WAVE wvResult = varStorageOp[ % ivscc_apfrequency_explist]
2590+
2591+ WAVE /WAVE plotAND = SFH_CreateSFRefWave ( exd. graph, opShort, 1 )
2592+ Make / FREE/ WAVE /N= ( numExp + 1, 2 ) plotWITH
2593+ SetDimlabel COLS, 0, FORMULAX, plotWITH
2594+ SetDimlabel COLS, 1, FORMULAY, plotWITH
2595+ plotAND[ 0 ] = plotWITH
2596+
2597+ for ( i = 0; i < numExp; i += 1 )
2598+ if ( ! CmpStr ( yaxisOffset, SF_OP_IVSCCAPFREQUENCY_MIN))
2599+ sprintf formula, "$freq%d - extract($freq%d, 0)" , i , i
2600+ elseif ( ! CmpStr ( yaxisOffset, SF_OP_IVSCCAPFREQUENCY_MAX))
2601+ sprintf formula, "$freq%d - max(flatten($freq%d))" , i , i
2602+ elseif ( ! CmpStr ( yaxisOffset, SF_OP_IVSCCAPFREQUENCY_NONE))
2603+ sprintf formula, "$freq%d" , i
2604+ else
2605+ FATAL_ERROR ( "Unknown xaxisOffset specification" )
2606+ endif
2607+ plotWITH[ i ][ % FORMULAY] = SFH_ExecuteFormulaInternal ( exd. graph, formula)
2608+ SFO_OperationIVSCCApFrequencySetPlotProperties ( plotWITH[ i ][ % FORMULAY] , xAxisPercentage, yAxisPercentage)
2609+ sprintf formula, "$currentNorm%d" , i
2610+ plotWITH[ i ][ % FORMULAX] = SFH_ExecuteFormulaInternal ( exd. graph, formula)
2611+ endfor
2612+
2613+ if ( ! CmpStr ( yaxisOffset, SF_OP_IVSCCAPFREQUENCY_MIN))
2614+ formula = "$ivsccavg - extract($ivsccavg, 0)"
2615+ elseif ( ! CmpStr ( yaxisOffset, SF_OP_IVSCCAPFREQUENCY_MAX))
2616+ formula = "$ivsccavg - max(flatten($ivsccavg))"
2617+ elseif ( ! CmpStr ( yaxisOffset, SF_OP_IVSCCAPFREQUENCY_NONE))
2618+ formula = "$ivsccavg"
2619+ else
2620+ FATAL_ERROR ( "Unknown yaxisOffset specification" )
2621+ endif
2622+ plotWITH[ i ][ % FORMULAY] = SFH_ExecuteFormulaInternal ( exd. graph, formula)
2623+ SFO_OperationIVSCCApFrequencySetPlotProperties ( plotWITH[ i ][ % FORMULAY] , xAxisPercentage, yAxisPercentage)
2624+
2625+ if ( ! CmpStr ( xaxisOffset, SF_OP_IVSCCAPFREQUENCY_MIN))
2626+ formula = "$ivscccurrentavg - extract($ivscccurrentavg, 0)"
2627+ elseif ( ! CmpStr ( xaxisOffset, SF_OP_IVSCCAPFREQUENCY_MAX))
2628+ formula = "$ivscccurrentavg - max(flatten($ivscccurrentavg))"
2629+ elseif ( ! CmpStr ( xaxisOffset, SF_OP_IVSCCAPFREQUENCY_NONE))
2630+ formula = "$ivscccurrentavg"
2631+ else
2632+ FATAL_ERROR ( "Unknown xaxisOffset specification" )
2633+ endif
2634+ plotWITH[ i ][ % FORMULAX] = SFH_ExecuteFormulaInternal ( exd. graph, formula)
2635+
2636+ Duplicate / O varBackup, varStorage
2637+ SFH_AddVariableToStorage ( exd. graph, "ivscc_apfrequency_explist" , wvResult)
2638+
2639+ JWN_SetNumberInWaveNote ( plotAND, SF_META_PLOT, 1 )
2640+
2641+ return SFH_GetOutputForExecutor ( plotAND, exd. graph, opShort)
2642+ End
0 commit comments