Tutorial: Development of a script

This tutorial shows how to add functionalities to a script. As an example, the Trajectory script is developed in order to analyse the results of the trajectories performed by the script and plot the RMS error for the different pixel timings.

For this purpose two new function are created. The AnalyzeTrajectory function and the Setup function.

Setup Function

Static Function Setup()
    DFREF dfr=NFGetUserScriptDFR(ksUserScriptName)

    MAKE/O/N=(kNumRuns) dfr:TrajectoryRMSs=0

    WAVE TrajectoryRMSs=dfr:TrajectoryRMSs
    Display TrajectoryRMSs

    return 0
End

Setup creates and displays the Wave that stores the results.

MAKE/O/N=(kNumRuns) dfr:TrajectoryRMSs=0

Creates the wave to store the results.

WAVE TrajectoryRMSs=dfr:TrajectoryRMSs

Creates a wave reference to the wave containing the results.

Display TrajectoryRMSs

Displays the results.

AnalyzeTrajectory function

Static Function AnalyzeTrajectory()
    DFREF dfr=NFGetUserScriptDFR(ksUserScriptName)

    Variable sessionId=NFGetSessionId()

    DFREF trajectoryDFR=NanoFrazorDFR#GetTrajectoryDFR(sessionId)

    WAVE TrajectoryX=trajectoryDFR:scanGrid_XX_error_nm

    WaveStats TrajectoryX

    Variable currentRunIndex=NFGetMAOCurrentRunIndex()
    WAVE TrajectoryRMSs=dfr:TrajectoryRMSs
    TrajectoryRMSs[currentRunIndex]=V_rms

    NFMAOMoveRelativeToOperation(1)

    return 0
End

AnalyzeTrajectory calculates the rms error of the trajectory and stores it.

DFREF dfr=NFGetUserScriptDFR(ksUserScriptName)

Gets Data Folder Reference (DFR) of the user script folder.

WAVE TrajectoryX=trajectoryDFR:scanGrid_XX_error_nm

Creates reference to the wave where the NanoFrazor stores the trajectory error.

WaveStats TrajectoryX

Calculates statistic values for the wave.

Variable currentRunIndex=NFGetMAOCurrentRunIndex()

Calls API function to get the RunIndex.

WAVE TrajectoryRMSs=dfr:TrajectoryRMSs

Creates wave reference to the wave storing the results.

TrajectoryRMSs[currentRunIndex]=V_rms

Copies the RMS error value into the wave storing the results.

Start Function

Static Function Start()

    //
    // Setup
    //

    Setup()

    //
    // Main task
    //

    NFMAOInit(numRuns=kNumRuns)
    Variable operationCounter=0
    NFMAOAdd(0,operationCounter,"NFScriptTrajectory#SetTrajectory")
    operationCounter+=1

    NFMAOAdd(0,operationCounter,"NanoFrazorMAO#StartTrajectory")
    operationCounter+=1

    NFMAOAdd(0,operationCounter,"NanoFrazorMAO#WaitTrajectory")
    operationCounter+=1

    NFMAOAdd(0,operationCounter,"NFScriptTrajectory#AnalyzeTrajectory")
    operationCounter+=1

    NFMAOAdd(0,operationCounter,"NanoFrazorMAO#Exit")
    operationCounter+=1
    //
    // Start
    //

    NFMAOStart()
End

Two new calls to function are added to the Start function.

Setup()

Setup is called directly to initialize data structures. This function is called only once when the script is initialized.

NFMAOAdd(0,operationCounter,"NFScriptTrajectory#AnalyzeTrajectory")

Inserts the AnalyzeTrajectory function to the list of operations. AnalyzeTrajectory runs at every iteration of the script.