COD Files


Next: Other Stack-Oriented Languages Up: COD Previous: Colon Definitions

COD Files

COD provides a way to read commands from a disk file. These files contain the same commands that you would enter via the interactive mode. Commands not contained in a colon definition will execute as the file is read. In order to use a COD file as a model component in PLT, it is necessary that the file contain at least one colon definition and it is the last colon definition that will be called when the component is evaluated. As an example of a COD file, assume the file LINE.COD contains the following lines:

 ! COD program to calculate a line.
 ! P1 + P2*X
 : LINE  P1 X P2 * + ;
All lines that begin with `!' are considered comment lines and are ignored by COD. The third line contains the program itself. P1 and P2 refer to the parameters that will be adjusted to minimize c2. When these words execute, they will load the value of the corresponding parameter into the stack. When writing COD programs that use parameters, you must use consecutive numbers starting with one - i.e., do not leave any holes in the sequence. The keyword X is used to push the current value of x into the stack.

It is also possible to use the COD program to read and test the code found in a COD file. The following example demonstrates how this can be done:

COD> GET LINE  ! Read the test file, note comment lines are echoed.
 ! COD program to calculate a line.
 ! P1 + P2*X
 NTERMS= 2
COD> NEW 1 2.  ! Set parameter 1 to 2.0

COD> NEW 2 1.  ! Set parameter 2 to 1.0

COD> 5         ! Place the number 5.0 in the stack
 5.0
COD> RUN       ! Run the program with an X value of 5.0
 7.0           ! The final result
The RUN command reads the top number on the stack, makes it the x value, clears the stack, and then runs the last program in memory. All these steps ensure that COD is in the same state as it will be when called from the PLT routine.

The Single step command can be used to debug a COD function. In the above example, instead of typing RUN, you could have entered Single Init. This would have read the top number in the stack, made it the x value, cleared the stack, and then executed the first step in the LINE colon definition. When using Single step, COD echos a line that contains three columns of information. The first column is the memory location that is about to be executed. The second column contains the encoded command which can be ignored. The third column is the decoded command that is to be executed. When taking single steps, the stack is still be printed just before the COD prompt appears. Hence, you can watch each step and its effect on the stack.

Code not contained in a colon definition will execute as the COD file is being read. Assume the FUNC.COD file contains the following lines:

 VAR 2PI
 2 PI * 2PI STO
 : FUNC X 2PI RCL * P1 / COS ;
While this file is being read, the variable 2PI is created and loaded with the value of 2p. The function FUNC can now access and use this variable.



next up previous contents
Next: Other Stack-Oriented Languages Up: COD Previous: Colon Definitions



Web Page Maintained by: Dr. Lawrence E. Brown elwin@redshift.gsfc.nasa.gov