Step 3: Validate Script Inputs

Script input validation does not necessarily need to be implemented for every script.  If validation is not used, a run-time error might be generated based on incorrect input parameters supplied by the user, but EMGworks will handle and report this error to the user (and other series will still be processed if they do not generate an error).  If validation is not desired, this tutorial step may be safely skipped.

In the case that we would like to validate the inputs, we should check that:

To do so, code the Validate function as seen below.

/**
* Data Segment Removal Tutorial Script
* @name Data Segment Removal
* @version 0.0.0.0
* @author Your Name
* @signed 0
* @namespace DSR
*/


DSR = {
Calculate : function()
   {
    // enter the logic for your script here
    // assign outputs to MYS.Output.ExampleOutputA
   },

Input : 5,

OutputTemplate:
           {
              SegmentRemoved: {seq: 1, name: "Data Segment Removed"}
           },

Validate : function()
           {
              if (DSR.Parameter.IntervalStart < DSR.Input.XStart)
                  return "Start cannot be less than the start time of the data series";
              if (DSR.Parameter.IntervalStart >= DSR.Parameter.IntervalStop)
                  return "Start cannot be greater than or equal to stop";
              if ((DSR.Parameter.IntervalStop - DSR.Input.XStart) * DSR.Input.Fs > DSR.Input.NumPoints)
                  return "Stop cannot be greater than the length of the data series";   
   
           },

ParameterTemplate:
           {
              IntervalStart: {seq: 1, name: "Start of interval (sec)", type:"number", initial: 0},
              IntervalStop: {seq: 2, name: "End of interval (sec)", type:"number", initial: 5}
           },
}