LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

FileToArray function with offset?

is there a function like FileToArray() that can start
at some arbitrary offset into a file, e.g. start at line # xx
of an ascii csv file?

it seems FileToArray() can do a variable length, but always
starts at the beginning of the file?

--------------

int status = 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 the ArrayToFile function. FileToArray handles
creating, opening, reading, and closing the file.

Parameters

Input

Name Type Description
fileName string File pathname.
dataType integer Array element data type.
numberOfElements integer
Number of elements in the array.
numberOfGroups integer Number of groups in the array.
arrayDataOrder integer How to order groups in the file.
fileLayout integer Direction to write groups in the file.
fileType integer ASCII/binary mode.
Output

Name Type Description
array void* Numeric array.
Return Value

Name Type Description
status integer Indicates success or failure.
0 Kudos
Message 1 of 5
(3,259 Views)
Hello,
I hope I understand your question correctly. Can't you just use FileToArray function, and advance the void pointer "array" by offset * (sizeof the data type)?

Mika Fukuchi
Application Engineer
National Instruments
0 Kudos
Message 2 of 5
(3,259 Views)
It sounds like you must be using an much older version of CVI. In the current version of CVI (and I think several versions back), the FileToArray function also has a parameter called "File Action" which you did not list. The File Action parameter allows you to start at the first or at the end ("Append") of the file to insert the array. Since you don't have that parameter in the older version, you will probably have to use the ANSI-C file I/O functions and convert the array to ASCII yourself with sprintf or the Fmt function.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 3 of 5
(3,259 Views)
thanks for the info, but sounds like you are referring to ArrayToFile
whereas I was referring to FileToArray, i.e. reading a file into an
array?

I do see the parameter FileAction you are referring to in the
description for ArrayToFile in CVI 5.5.1.

the problem being to selectively read a subset of a very large
ascii file of multi-columnar data.

I suppose it makes sense to just read the whole thing,
but it may be millions of rows, and I was thinking it would
be faster to just skip to row N and start reading if I only
wanted to view e.g. 1000 rows out of a million.


> It sounds like you must be using an much older version of CVI. In the
> current version of CVI (and I think several versions back), the
> FileToArray function also has a parameter called "File
Action" which
> you did not list. The File Action parameter allows you to start at
> the first or at the end ("Append") of the file to insert the array.
> Since you don't have that parameter in the older version, you will
> probably have to use the ANSI-C file I/O functions and convert the
> array to ASCII yourself with sprintf or the Fmt function.
>
> Best Regards,
>
> Chris Matthews
> National Instruments
0 Kudos
Message 4 of 5
(3,259 Views)
You are correct, I was looking at the wrong function. That's a good suggestion for improving FileToArray. There isn't currently a way to do this built into the function or another function that would do this without a custom format string. You would have to use the ScanFile function for this and set up the format string yourself with repeat codes. See the online help for help with the format string.

Chris
0 Kudos
Message 5 of 5
(3,259 Views)