01-28-2012 04:55 PM
I think I understand your problem, now. The Data (with a capital D) is a two-dimensional array of some size (say, 10 rows and 3 columns) and some data type (say a 4-byte integer). If you ask how many bytes does this Data take in memory, the answer is 10*3*4 = 120 bytes.
The problem comes when you try to write out this data to a file, and ask "How many bytes are there in the file?". The answer depends on several things, but one very significant one is what kind of file is it? In your example, your data seem to be read from a text file, so the numbers are represented as strings. Thus a file with 100 values of 1 would be much smaller than a file with 100 values of 1000000, as you'd only need a single character to represent the number "1", but would need 7 characters to represent a million. You are using the Spreadsheet String to Array function, which may have additional "padding" rules, but the bottom line is that text representation of numeric data need not bear any fixed relationship (in size) to the number of data elements.
If you read and write your data using the "binary" read and write functions, you should create a file of 120 bytes (in the example above), and could easily pick out a single element from the file using the file positioning function. It is also likely that the file will be smaller, and file i/o faster, though you'd absolutely need to know the format of the file to make sense out of it (for example, if you tried to read it assuming it consisted of DBLs instead of I32, you'd get values, alright, but they wouldn't make much sense!).
01-28-2012 08:14 PM
Also some of the functions use a few header bytes to record the lengths of strings or arrays, I think. No time to look it up for confirmation now.
Lynn
01-29-2012 07:13 AM
Hi Bob,
That is a nice summery of my problem! I think in deed the main issue is to find out how big a file with e.g. 100 values of 1(or 1000000) would be (so that I can use later the “Set File Position.vi” correctly). Since my file has different numbers (Integers and Doubles (?)) a calculation similar to your example seems to be difficult. And, as you recognized, my file is a text file which can’t be changed. If it was a binary file some things would perhaps be easier.
Anyway, I played a bit with the program I have posted in my 10 message. It seems to work except of the difference of 2. But as long as I know that the difference is always 2, I can add this number to my length of my string, so that I can set later the file position correctly.
Perhaps Lynn (Thanks for your comment too) is right and the reason for the difference comes from some header bytes.
I also recognized that I get for the file size the same number as for the string length (193 bytes) if I start a new, empty line in the file. Perhaps the line break takes 2 bytes in memory.
At least, I know that I am not too sensitive for the correct byte size in my main program. It is not so bad if one line of my file is not read in correctly. But the byte size should be known more or less well for the “Set File Position.vi”.
Well, now all I want to know is if there is a better way to get the size of my array (of the corresponding string) in bytes as I am calculating it in my ByteSizeOfArraySubsetLV2011_3.vi.