new_fileopen
This global function opens a file and returns a new CFile object for accessing the file.In contrast, the new_file function simply creates a new CFile object.
CFile_obj = new_fileopen( sPathName, sMode )
sPathName
is the full path name for the file to be opened.
sMode is
the file mode (see Remarks, below).
CFile_obj
is a new CFile object
returned by this function. On failure, nil is returned.
This function can open the file in either binary or text mode for reading, writing, or appending file data. The modes are described under File Access Modes. Also see the functions in the lua I/O library.
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 data array (lua indexed table) to a binary file. The data 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. FInally, the data array is saved. When using Write for a table, the output pixel type defaults to 64-bit real values if it is not specified. 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 |
|
-- get the full path name |
|
-- check that a file name was selected |
|
-- Open the file and create a CFile object |
|
-- if the file was opened, write values: |
|
-- number of columns as a long integer |
|
-- number of rows as a long integer |
|
-- 6 = the code for 64-bit real number data |
|
-- write the data array |
|
-- close the file when done |
|
-- return success |
|
|
|
|
|
-- reurn failure |
|
|
GetFileName
Mira Pro x64 Script User's Guide, v.8.77 Copyright Ⓒ 2024
Mirametrics, Inc. All Rights Reserved.