EXECUTE Instruction |
EXECUTE( options ) procname parameters
or
@procname( options ) parameters
EXECUTE invokes a PROCEDURE created (or SOURCE’d in) previously in the program. The two lines below are equivalent, with the second preferred in situations where the procedure is mimicking a RATS instruction.
Parameters
procname |
Name of the procedure invoked. You must use the full name, not an abbreviation. Before RATS can EXECUTE a procedure, it must compile the code for the procedure itself. See “Compiling Procedures” below for details |
parameters |
List of actual parameters. These pass information (series, arrays, scalars, etc.) to matching formal parameters listed on the PROCEDURE instruction which defined the procedure. |
Options
Procedure options (defined with the OPTION instruction) are selected in the same fashion as are options for any standard RATS instruction. You can abbreviate to three or more letters the option name, and the choices for a CHOICE option. For the three option types:
•SWITCH options use option name alone for “On” (translated as 1), and NOoption name for “Off” (translated as 0). That is, if you define an option PRINT, the user would use PRINT or NOPRINT to turn it on or off.
•CHOICE options use option name=keyword for choice. For instance, if you define a CHOICE option TYPE with FLAT and TENT as the choices, the user would select the type by means of TYPE=FLAT or TYPE=TENT.
•Value options use option name=variable or expression. RATS handles value options in the same fashion as procedure parameters of the same type.
Compiling Procedures
Before you can use a procedure, you must execute, or “compile”, the code that defines the procedure. If the procedure code is included in the same file as the program being executed, you just need to make sure the procedure code precedes the EXECUTE command that calls the procedure.
More commonly, the procedure code is stored on a separate file. In that case, you can:
•compile the procedure explicitly, using a SOURCE instruction or by including the file in your “procedure library” using the Preferences menu operation, the ENVIRONMENT instruction, or the /PROC command-line switch , or
•let RATS search for the file. Given a procedure called “PROCNAME”, RATS will search for a file called name PROCNAME.SRC. It will check (in order) the "parent" directory if one procedure calls another, your “Procedure Directories” (defined in the Preferences), the current default directory, and the directory containing the RATS executable file.
Notes
If you have nested procedures, that is, if one procedure contains an EXECUTE for another procedure, RATS needs to compile the code for the inner procedure first.
When control is returned from the procedure by a RETURN or END instruction, execution of the main program continues with the instruction that follows EXECUTE.
Parameters Passed by Value
If a PROCEDURE expects a parameter passed by value, you can use any variable or expression which has the correct type. For
example:
proc foo tvector treal
type vector tvector
type real treal
disp %size(tvector) treal
end
@foo ||6.0,5.0,3.0|| %rss
Parameters Passed by Address
If a PROCEDURE expects a parameter passed by address, you may use a variable or array element or series element which has the expected type, or a new variable name which will be defined as a global variable of the required type. You should only pass by address if you need to set or change the parameter passed.
procedure change intpar matpar
type integer *intpar
type symmetric *matpar
compute intpar=%rows(matpar)
compute matpar=inv(matpar)
end change
*
dec symm s(3,3)
ewise s(i,j)=.9^(i-j)
exec change n s
inverts the matrix S and sets N to 3.
Undefined Parameters/Options
If you either omit a parameter or use * in its place, the procedure will treat it as if you put a * wherever that parameter occurs. If it is used in a calculation, that calculation will be skipped. If certain parameters must be assigned values for your procedure to make sense, you should use the %DEFINED function to check this and exit if it returns 0.
proc quickie matpar
type symmetric *matpar
if .not.%defined(matpar) {
disp "Syntax: @quickie matrix"
return
}
compute matpar=inv(matpar)
end
Example
procedure specfore series start end forecast
type series series
type integer start end
type series *forecast
*
option integer diffs 0
option integer sdiffs 0
option switch const 1
option choice trans 1 none log root
shows the parameters and options for the procedure SPECFORE. The following is an example of this being executed:
@specfore(diffs=1,noconst,trans=root) longrate $
2019:1 2019:12 flong
LONGRATE is the SERIES parameter, 2019:1 and 2019:12 are START and END, and the forecasts are returned to the series FLONG. DIFFS is equal to one, CONST will be zero (the effect of the use of NOCONST), TRANS will be 3—the value for the ROOT choice.
Copyright © 2025 Thomas A. Doan