FileToArray

int FileToArray (char *fileName, void *array, int dataType, int numberOfElements, int numberOfGroups, int arrayDataOrder, int fileLayout, int fileType);

Purpose

Reads data from a file into an array. You can use FileToArray with files you create using ArrayToFile. FileToArray opens, reads, and closes the file.

Parameters

Input
Name Type Description
fileName string Name of the file to read.

fileName can be an absolute pathname or a relative filename. If you use a relative filename, FileToArray locates the file relative to the current working directory.
dataType integer Data type of the array. The data in the file should match this data type.

dataType must be one of the following data types:
character VAL_CHAR
short integer VAL_SHORT_INTEGER
integer VAL_INTEGER
floating point VAL_FLOAT
double precision VAL_DOUBLE
unsigned character VAL_UNSIGNED_CHAR
unsigned short integer VAL_UNSIGNED_SHORT_INTEGER
unsigned integer VAL_UNSIGNED_INTEGER
numberOfElements integer Number of data points to read from the file.
numberOfGroups integer If the file is in ASCII format, numberOfGroups specifies the number of groups into which the data in the file is divided. FileToArray can read groups as columns or rows. If you do not want to read your data as groups, use 1.
arrayDataOrder integer If you divide your data into groups, arrayDataOrder specifies how to store the data from different groups in the array. The choices are as follows:
  • VAL_GROUPS_TOGETHERFileToArray stores all elements from one data group followed by all elements from the next data group.
  • VAL_DATA_MULTIPLEXEDFileToArray stores the first elements of all data groups consecutively, followed by the second elements from each group and so on.
fileLayout integer If the file is in ASCII format, fileLayout specifies how the data is arranged in the file. The choices are as follows:
  • VAL_GROUPS_AS_COLUMNS
  • VAL_GROUPS_AS_ROWS
If there is only one group, VAL_GROUPS_AS_COLUMNS specifies that each value in the file is on a separate line.
fileType integer Specifies whether the file is in ASCII or binary format. The choices are as follows:
  • VAL_ASCII
  • VAL_BINARY
Output
Name Type Description
array void * Numeric array in which to store the data read from the file.

Return Value

Name Type Description
status integer Indicates whether the function succeeded or failed.

If the value is –1, –2, or –3, you can use GetFmtIOError to get more information about the type of error that occurred.

Code Description
0 Success.
–1 Error attempting to open the file.
–2 Error attempting to close the file.
–3 An I/O error occurred.
–4 Invalid dataType parameter.
–5 Invalid numberOfElements parameter.
–6 Invalid numberOfGroups parameter.
–7 Invalid arrayDataOrder parameter.
–8 Invalid fileLayout parameter.
–9 Invalid fileType parameter.