LabWindows/CVI

Content Type
Programming Language
Current manual

FileToArray

FileToArray

int FileToArray (char fileName[], void *array, int dataType, size_t numberOfElements, size_t 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.

Note   This function cannot convert NaN and Inf in ASCII files to double-precision numbers. This function can convert these special double-precision numbers in binary files. If your data contains these special double-precision numbers, National Instruments recommends using files in binary format with this function.

Parameters

Input
Name Type Description
fileName char [] 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 int 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
long long VAL_64BIT_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
unsigned long long VAL_UNSIGNED_64BIT_INTEGER
size_t VAL_SIZE_T
signed size_t VAL_SSIZE_T
pointer difference VAL_PTRDIFF_T
unsigned pointer-sized integer VAL_UINTPTR_T
pointer-sized integer VAL_INTPTR_T
numberOfElements size_t Number of data points to read from the file.
numberOfGroups size_t 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 int 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 int 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 int 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 int 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.

Additional Information

Library: Formatting and I/O Library

Include file: formatio.h

LabWindows/CVI compatibility: LabWindows/CVI 4.0 and later

Example

Refer to fileio\arrayfile.cws for an example of using the FileToArray function.

Was this information helpful?

Help us improve your future ni.com experience.

Did you find the documentation you were looking for?

Submit