Files |
Top Previous Next |
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.
FreeFlyer Data FilesFor information on FreeFlyer Data Files and Formats, including Ephemeris Files, see the Data Files reference in the Appendix. See also Working with Ephemerides.
Creating External Object FilesFor 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 DirectoriesThe 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:
The FileSystem object can be used to delete a file:
The FileSystem object can be used to create a directory:
The FileSystem object can be used to move and rename a file:
Reading Arbitrary File FormatsTwo 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:
To help parse data out of each line read, review the StringTokenizer object and the String.Split method. See Parsing Arbitrary String Data for more information.
Note: The StringArray and FileInterface objects also support the creation of arbitrarily formatted output files. Refer to StringArray.WriteToFile, FileInterface.WriteMode, and FileInterface.Write to get started.
Example 1: StringArray ReadFromFile MethodThe 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
Mission Plan
Output Report
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 ObjectThe 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.
Input File: UnmodAccel.txt
Mission Plan
Output Report
See Also
|