FreeFlyer provides a variety of interfaces for interacting with external files. For information on working with JSON data, please see the JSON-Formatted Data page.
The following Sample Mission Plans (included with your FreeFlyer installation) demonstrate the use of the FileInterface object:
For information on saving the state of a FreeFlyer object to an external file, see the Put command. See the Get command for information on retrieving states from a file. The Object.PutToFile(), Object.PutToString(), Object.GetFromFile(), and Object.GetFromString() methods can also be used in place of the Put and Get commands.
Note: The Save and Restore commands provide similar functionality to the Put and Get commands, while saving object data to internal memory instead of external files.
Determining Information about External Files and Directories
The FileSystem object can be used to gather information about files and directories, such as whether a file exists in a directory or when a file was last modified. The FileSystem object cannot be created and is only accessible via FreeForm script.
This example shows how the FileSystem object can be used to create a copy of a file:
Spacecraft Spacecraft1;
ReportInterface ReportInterface1;
ReportInterface1.Filename = "temp.txt";
While (Spacecraft1.ElapsedTime < TS(1 days));
Report Spacecraft1.EpochText, Spacecraft1.Position, Spacecraft1.Velocity to ReportInterface1;
Step Spacecraft1;
End;
Close ReportInterface1; // Close the file to allow the FileSystem object to control
FileSystem.Copy(ReportInterface1.Filename, "temp2.txt"); // Create a copy of the file in the same directory
The FileSystem object can be used to delete a file:
FileSystem.Delete("temp2.txt"); // Delete file
The FileSystem object can be used to create a directory:
FileSystem.CreateDirectory("./destination"); // Create a directory
The FileSystem object can be used to move and rename a file:
FileSystem.Move(ReportInterface1.Filename, "./destination/file.txt"); // Move the file and rename it
Reading Arbitrary File Formats
Two mechanisms are available to open and parse input files. The first mechanism is the simple StringArray.ReadFromFile method. The second mechanism is the more generic and more functional FileInterface object.
Using these functionalities, you can:
1.Examine iput and output files.
2.Read arbitrary ephemeris file formats.
3.Integrate into other systems by reading their relative formats.
The StringArray.ReadFromFile method is a convenient way to read small ASCII files without having to worry about the details of the format of the file. In this example, a data file is read into a StringArray called fileContents, and then each line is parsed into individual data elements in the lineContents StringArray.
Input File: myFile.txt
Spacecraft1.A Variable1
km
7088.4366419 0.0000000
7088.1359928 2.0000000
7087.8048512 4.0000000
7087.4445534 6.0000000
7087.0565503 8.0000000
7086.6424014 10.0000000
Mission Plan
StringArray fileContents[0];
StringArray lineContents[0];
Variable numLines;
Variable i = 0;
//Read the entire contents of the file and place each line into an element of "fileContents"
//Split each line into entries, using spaces as the delimiter
fileContents[i].Split(" ",lineContents);
//Ignore the first two lines of the file (Headers) and report the parsed data
If (i > 1);
Report lineContents[0], lineContents[1];
End;
i++;
End;
Output Report
lineContents[0]
lineContents[1]
7088.4366419
0.0000000
7088.1359928
2.0000000
7087.8048512
4.0000000
7087.4445534
6.0000000
7087.0565503
8.0000000
7086.6424014
10.0000000
Note: The StringArray object also has a StringArray.WriteToFile method, which writes the elements of a StringArray to a file. Each element becomes a new line in the file.
Example 2: The FileInterface Object
The FileInterface object has many options that provide the ability to read and write ASCII and binary files. The image below shows an example of the FileInterface object editor, which allows the user to configure a FileInterface's filename, read/write modes, format flags, and other properties.
FileInterface Object Editor
In this example, additional acceleration data is retrieved from a randomly formatted external file called "UnmodAccel.txt", and this data is assigned to a Spacecraft ForceModel's "Other Accelerations" properties.