05-05-2023 11:24 AM
Hello,
the task is to read data from a file with "binary read". The binary data structure is
0. value type double // time
1st value Y1 result type single
2nd value Y2 result type single
....
n Value Yn Result type single
normally I would define a structure now
struct data
double *xval
float *yval
and move the data pointer and address yval as array, this works very well in C
But when I define an array in Labview the first bytes are always the array size and the data structure is not correct, Labview always adds something of its own.
With a custer I can't change it dynamically at runtime, since the value for n can be a few hundred , a solution with case distinctions is not in useful.
How can I define a structure with full user control like in C, the binary data structure of the file cannot be adapted, it is predefined.
thanks in advance
Lutz
Solved! Go to Solution.
05-05-2023 01:20 PM
You cannot create or modify clusters dynamically during runtime. Since the structure is a double followed by N singles and I assume that you know the value of N, you can first read 8 bytes for the double, then N*4 bytes for the singles. And repeat the two Read VI in a loop.
05-05-2023 07:51 PM
the problem is not the cluster but the array in the cluster, this contains additional data. If I have a cluster with a double value and an array with 10 single values I would expect 1x8byte + 10 x 4 byte, so in total 48 byte, so in C, but in Labview it is 52 byte, because the array is given additional info about the size, if I give this defined data type to the block "read binary" it reads too much data and assigns them wrong. In C it is my task not to work beyond the limit, Labview wants to be more comfortable and does the check itself with the help of the additional data, but in this case it is not a help but a handicap.
Of course I know that I can read in a loop first the double and then n single values. With my test file with 25 MByte this takes 2 minutes in Labview, in C <<1s. But usual file sizes I have to work with are up to 4 GByte, takes in C 20s to read, so would take in Labview estimated 5h, instead of 20s.
Therefore I would like to define the structure, in order to read in then in larger blocks, the number can be given with the Block "read binary".
05-06-2023 07:21 AM - edited 05-06-2023 07:22 AM
If your array has a fixed size that is known at compile time, you can do this:
Otherwise, read N x <struct size> bytes (48) and unflatten the data in a loop:
05-06-2023 09:11 AM
Out of curiosity, I did some benchmarking, The dynamic unflatten from string approach has the fastest performance,
05-08-2023 04:25 AM
Thanks for the solution, still had to define the byte order and now it goes very fast.
I was not clear that you have to go via String, had searched in the Variant area because I had expected it rather there, but clear, without success. Now it works