GETARG argNumber resultVariable

GETARG is used only within a subroutine definition that has optional arguments. Optional arguments are those introduced in the NEWCMD command with the '#' sign. GETARG assigns the optional argument whose number is argNumber to the resultVariable. It will usually be used in a loop to process each of the optional arguments. See the example at right.

The first optional argument is argument number one, the second is number two, etc. Any dummy arguments are not included in the count. For example if you had the following definition of a subroutine,

NEWCMD MYCMD dummy1 dummy2 #
...
END

and you invoke it with the line

MYCMD vec1 vec2 vec3 vec4

then vec1 and vec2 are assigned to dummy1 and dummy2 and a command like this one:

GETARG 1 anArg

will assign vec3 to anArg and

GETARG 2 anotherArg

will assign vec4 to anotherArg.

GETARG may not be used outside of a subroutine.

ArgNumber must be be less than or equal to the number of optional arguments that are in the subroutine's invocation. You can determine the number of optional arguments using the ARGCOUNT command.

See also: ARGCOUNT, NEWCMD.

The following program illustrates the use of the GETARG command.

'Subroutine to do an ascending coordinated sort, in place, of two or more vectors
'based on the first vector (keyVariable) as the key. All vectors must be the same length.
NEWCMD SORTCOORD keyVariable #"variable {variable}"  ?"Coordinated sort, in place, of two or more vectors"
   ARGCOUNT numberOfArgs
   IF numberOfArgs > 0
      TAGSORT keyVariable tags
      TAKE keyVariable tags keyVariable
      FOREACH argNum 1,numberOfArgs
         GETARG argNum arg
         TAKE arg tags arg
      END
   ELSE
      DEBUG "ERROR: Incorrect number of arguments in SORTCOORD."
   END
END