FileOpen
This global function opens a file and returns a new CFile object for accessing the file. This function is not a class member but it provides an alternative to using CFile:new followed by the class Open method. This method creates and returns the CFile object for the file.
CFile = FileOpen( sFileName, sMode )
sFileName is the full path name for the file to be opened.
sMode is the file mode (see Remarks, below).
CFile is a new CFile object returned by this function. On failure, nil is returned.
This function can open the file in either text or binary mode for reading, writing, or appending. The modes and how to specify them are described under CFile Access Modes.
When the script is finished with the file, the CFile object created by this function should closed using either the Close or delete destructor.
The script below provides a complete function to save a 1-dimensional array to a raw binary file as 16-bit real numbers. The array has indices [1] through [ nCols x nRows ].
The nCols and nRows parameters are written individually as "long" integers (32-bit). Following that is a numeric Pixel Type code to indicate the table contains 64-bit real numbers. Then the entire table is saved. When using Write for a table, the output pixel type defaults to 64-bit real values if it is not specified. For the file to have the correct length, it is assumed that the number of table elements is nCols x nRows. The values sName and F are declared as local inside the function to avoid a collision with the same name outside the function.
|
|
|
-- bail out if a table was not passed |
|
-- open a file using the FileOpen dialog |
|
-- check that a file name was selected |
|
-- Open the file for writing binary data |
|
-- if the file was opened |
|
-- number of columns as a long integer |
|
-- number of rows as a long integer |
|
-- 6 = code for 64-bit real number data |
|
-- write the table as 64-bit real values. |
|
-- remember to close the file when done |
|
-- success |
|
|
|
|
|
-- failure |
|
|
Mira Pro x64 Script User's Guide, Copyright Ⓒ 2023 Mirametrics,
Inc. All Rights Reserved.