'***************************************************************************
'Galil Motion Control Sample DMC Code
'***************************************************************************
'Description:
'Array fill, copy, print, and compare
'***************************************************************************
#run                            ;'program start label
'define two arrays of equal length. Note that array names are limited
'to 6 characters when they are going to be passed to a subroutine.
DM arr1[10],arr2[10]


JS #fill("arr1", 3.14)          ;'fill arr1 with 3.14
JS #fill("arr2", 1)             ;'fill arr2 with 1
JS #print("arr1", "arr2")       ;'print the two arrays
JS #comp("arr1", "arr2")        ;'compare the two arrays
MG "Compare returned>", _JS     ;'comp returns number of differences

JS #copy("arr1", "arr2")        ;'copy arr1 to arr2
JS #print("arr1", "arr2")       ;'print the two arrays
JS #comp("arr1", "arr2")        ;'compare the copied arrays
MG "Compare returned>", _JS     ;'comp should return 0 for no differences
EN                              ;'end of main program


#fill                           ;'simple subroutine to fill array with values
^c= 0                            ;'use local scope ^c for iterator
#fill_h                         ;'fill loop
^a[^c]= ^b                       ;'set each value of the array
^c= ^c+1
JP #fill_h,(^c<^a[-1])           ;'keep setting array values for length of array
EN


#copy                           ;'simple subroutine copies array ^a to array ^b
JS #chkdims(^a,^b)               ;'first ensure that dimensions match
^c= 0
#copy_h
^b[^c]= ^a[^c]
^c= ^c+1
JP #copy_h,(^c<^a[-1])
EN


#print                          ;'simple subroutine to print arrays ^a and ^b
JS #chkdims(^a,^b)
^c= 0
#print_h
MG ^a[^c], ^b[^c]               ;'MG each array value for length of array ^a
^c= ^c+1
JP #print_h,(^c<^a[-1])
EN

#comp                           ;'simple subroutine to compare arrays
JS #chkdims(^a,^b)
^c= 0
^d= 0                            ;'local scope ^d will be used for return val
#comp_h
IF (^a[^c]<>^b[^c])
^d= ^d+1
ENDIF
^c= ^c+1
JP #comp_h,(^c<^a[-1])
EN ,,^d                          ;'return ^d which is the count of differences

#chkdims
IF (^a[-1] <> ^b[-1])           ;'use TR1 to see which code segment called this
  MG "Dimensions of arrays do not match"
  ZS                            ;'zero stack so EN actually ends program
ENDIF
EN