File Handling |
The Default Directory and the OPEN Instruction
When you use the Data Wizard to read a file, RATS includes the full path to the file on the OPEN instruction. However, RATS also maintains a “default” directory setting, which is where it will look for (or create) files if you don’t specify the full path.
You can use the menu operation File—Directory if you want to change the default directory for the current session. If you want to make that change permanent, you can reset that as part of your Preferences. File—Recent Directories has a list of the most recently used directories that's saved automatically, so it remembers where you have been working recently.
So, if you have the directory containing the RATS example files set as the default directory (which it should be when you first install the program), so you can, for instance, simply do
open data ExampleThree.xls
to get one of the example files. This approach (omitting the path) often works better if you will be sharing programs and data with another user who has a different directory structure on their system. Your colleagues just need to make sure that their programs and data files are stored in the same directory, and that they set that as the default directory in RATS.
Blank Spaces? Enclose in Quotes
If your path and filename includes any blank spaces, you need to enclose the entire string in single or double quotes, as in the code generated by the wizard. For example:
open data "C:\My RATS Files\ExampleThree.xls"
or
open data 'C:\My RATS Files\ExampleThree.xls'
For a path or filename that does not include any blank spaces, you don’t need quote marks around the name, although there is no harm in including them.
Data from Multiple Files
You do not have to load all your data with a single instruction. You can use several OPEN DATA and DATA instructions to read from multiple data sources.
While you could use the Data Wizard operation for each file, you would need to make sure to use the same “Target Dates” setting each time. Otherwise, the date mappings specified by the last CALENDAR setting will no longer match up properly with data read in previously. So, if you need to read from multiple files or sources, you may find it easier to just type in the instructions directly (or use the Wizard for the first file, and then type the instructions for the additional files directly).
Can’t Open a File?
If you have created a data file in RATS and are having trouble opening the file in another application, you need to make sure that RATS doesn’t still have the file open. For example, if you are working in interactive mode and do:
open copy test.dat
copy(format=prn,org=columns) / x y z
and then immediately try to open test.dat in another application while RATS is still running, you will probably get an error message. And, if you view a directory listing of test.dat using Windows Explorer or a similar utility, it will appear as a zero-byte file. That’s because RATS still has the file open. In order to access the file in another application, just close the file by issuing the command:
close copy
or else by quitting the RATS application.
Similarly, RATS may not be able to read data from a file that is currently open in another application.
File Units
In RATS, you open a file by associating a file name with an input/output “unit.” For example, the statement:
open data myfile.txt
simply associates the filename myfile.txt with the DATA unit, which is one of the reserved unit names in RATS. Every RATS instruction that can read or write data has a UNIT option which allows you to specify the source or destination unit for that operation.
Fortunately, this business of file unit names is generally transparent to the user, because all of the relevant instructions have default settings for the UNIT option. For example, the DATA instruction accesses the DATA unit by default. So, you can read data from a file by simply doing something like:
open data sample.rat
data(format=rats)
Because DATA is the default unit for the DATA instruction, it will automatically read the data from the sample.rat file, which has been associated with the DATA unit by the OPEN command. If no file has been associated with the DATA unit, RATS will prompt you for a filename.
In some cases, however, you may find it helpful to make use of the UNIT option, particularly when you want to have several data files or output files open simultaneously. This is made easy by the fact that RATS lets you define your own unit names.
For example, suppose you want to read data from two different files in your program. You can either:
•Use an OPEN DATA command to associate the first file with the DATA unit, and then read the data in using DATA. Then, repeat this procedure for the second file:
open data first.rat
data(format=rats) / x
open data second.rat
data(format=rats) / y
•Or, you can define your own custom unit names, and associate one file with each name. You can then read from the files in any order by specifying the appropriate unit name. For example:
open data1 first.rat
open data2 second.rat
data(format=rats,unit=data2) / y
data(format=rats,unit=data1) / x
Because you are using different unit names for each file, both files remain open, so you can go back and read from either one without having to repeat the OPEN command.
Copyright © 2025 Thomas A. Doan