RATS 10.1
RATS 10.1

Storing Procedures in External Files

Procedures and functions do not need to be in the same file as the program which uses them. There are several advantages to keeping them on separate files:

If you have a subprogram which can be used by more than one program, you only need to maintain one copy of the subprogram.

Keeping subprograms on separate files means that your main program files will be shorter and easier to edit and debug.

You can call in a subprogram even when you’re working interactively.

 

Before you can execute a subprogram stored on a separate file, RATS needs to execute (or “compile”) the instructions on that file. In many cases, RATS can locate and execute the appropriate file automatically. Otherwise, you can use SOURCE to tell RATS which file to execute. See below(??) for details.

 

Look Up the Syntax!

Descriptions of the most important procedures are included. These describe the syntax in a form similar to that used for instructions. For those that are newly-written (or less heavily used) and thus not covered in those sources, the first thing you should do is to open the file and read through the comments at the top. These are ordinary text files, so you can open them by doing File—Open in RATS, or any other text-editor or word-processor. All of the procedure files that we have written include comments describing the procedure syntax, options available, and, usually, technical details and references as well.

 

If you create a procedure yourself that you wish to share with others, make sure you include similar information, so that the future users will know how to use it, and will know whom to thank.

 

Compiling the Procedure

To use a procedure or function that is stored on an external file, RATS will first need to execute the commands on the file. This “compiles” the procedure or function code. Procedures can then be executed using the EXECUTE command or (more commonly) @procedure. For functions, you simply use the function name (and any parameters) in an expression.

 

For procedures, the easiest approach is to let RATS locate and compile the procedure file automatically, by simply executing the procedure. If the procedure has not already been compiled, RATS will search for a filename matching the name of the procedure, with an extension of .src. For example, if you do @DFUNIT, RATS will search for a file called dfunit.src. It does this in the following order:

1.The first directory it searches is its "parent". If it's a procedure called from another procedure, that will be the directory where the outer procedure is located. If it's a procedure from a program file, that will be the directory with the program.

2.If that fails, it will search the “Procedure Directories” specified in the File—Preferences dialog (in order if you list more than one).

3.If that also fails, it will search the current working directory.

4.If it still fails to find a matching file, you will see a standard operating system file dialog box prompting you to locate the file.

 

If you prefer, you can use an explicit SOURCE instruction to read in and execute the commands on an external file. This is required for FUNCTIONS (RATS won’t search for those), for procedure files where the procedure name does not match the file name, for procedures located in a directory not included in the search paths described above, or for a custom variation of a standard procedure.

 

Suppose you are writing a program that will require the @DISAGGREGATE procedure to interpolate low-frequency data to a higher frequency. If you have a custom version of this saved on a directory called c:\users\myname\documents\my rats\, you can either put the path to your custom procedures above the standard one in the "Procedure Directories" on your Preferences (which might make sense if you have quite a few of these) or use an explicit SOURCE as shown below. Note the “..” around the name, which is required if there are any embedded spaces, and never hurts.

 

source "c:\users\myname\documents\my rats\disaggregate.src"

calendar(m) 1990

open data quarterly.rat

data(format=rats) 1990:1 2023:12 x1 x2

@disaggregate(model=loglin,tsmodel=rw1) x1 / xm

# constant x2

 

Procedure Libraries

Procedure libraries are collections of procedures and functions which are brought in at the start of the program, and also whenever the program is reinitialized, using, for instance, File—Clear Memory. This makes sure the procedures included in the library are always available. There are several ways to specify a procedure file:

1.The RATS instruction ENV PROC=name of procedure library

2.The /PROC=name of procedure library option on the command line.

3.Through setting the "Procedure Library" in the Preferences.

 

You can form the library either by copying the full text of the desired procedures to a single file, or by setting up a file with a group of SOURCE instructions for the procedures you want.          

 


Copyright © 2025 Thomas A. Doan