'***************************************************************************
'Galil Motion Control Sample DMC Code
'***************************************************************************
'Description:
'Record data using RA,RD,RC.  Compute Root Mean Square on data.
'***************************************************************************
#record        ;'label
DM yerror[100] ;'dimension array
RA yerror[]    ;'record mode
RD _TEB        ;'data type for record
RC 4, 100      ;'actual recording
EN             ;'end program

#stat                        ;'label
n = 0                        ;'initial values
max = 0
min = 0
sum = 0

#loop                        ;'label
  e = yerror[n]              ;'read position error
  sum = e * e + sum          ;'compute sum of squares

  IF (yerror[n] > max)       ;'compare with max
    max = e                  ;'redefine max
  ELSE ; IF (yerror[n] < min) ;'compare with min
    min = e                  ;'redefine min
  ENDIF ; ENDIF

  n = n + 1                  ;'increment index
JP #loop, n < 100            ;'repeat 100 times

mean = sum / 100             ;'mean square
root = @SQR[mean]            ;'root mean square (rms)
EN                           ;'end program