02-07-2013 09:54 AM
I have a 3D matrix ratio{i}{j}{k} I want to save to a file and later opet with Origin.
Tried using:
ArrayToFile ("C:\\deposit\\", ratio, VAL_FLOAT, (800)*(280)*(280), 1, VAL_GROUPS_TOGETHER,
VAL_GROUPS_AS_COLUMNS, VAL_CONST_WIDTH, 10, VAL_BINARY, VAL_TRUNCATE);
but I am getting that the type of argument does not match type specified.
I realize its a large file, but there is no other way to do it.
02-08-2013 05:02 AM
HI,
I guess you specified a double array in the parameters of the "ArrayToFile" function.
But in fact you have a 3D array, that's why you have this error.
As you have a large file, you should try to separetely save your data into your file.
Regards,
Celine
National Instruments France
02-08-2013 06:00 AM
Since you are saving in binary format, I was wondering if something like that could be of help:
WRITING FUNCTION
#include <ansi_c.h>
// Define variables
static int i;
static double m[3][3][3];
static FILE *fH = NULL;
// Fill in some value
for (i = 0; i < 3; i++) {
m[0][0][i] = i;
m[0][1][i] = i + 3;
m[0][2][i] = i + 6;
m[1][0][i] = 10 + i;
m[1][1][i] = 10 + i + 3;
m[1][2][i] = 10 + i + 6;
}
// Save to file
fH = fopen ("c:\\Temp\\tmp.dat", "wb");
if (errno) {
// Add proper error handling code
}
fwrite ((char *)m, sizeof(double) * 9, 3, fH);
if (errno) {
// Add proper error handling code
}
if (fH) fclose (fH);
READING FUNCTION
#include <ansi_c.h>
// Define variables
static double m[3][3][3];
static FILE *fH = NULL;
// Read data from disk
fH = fopen ("c:\\Temp\\tmp.dat", "rb");
if (errno) {
// Add proper error handling code
}
fread ((char *)m, sizeof(double) * 9, 3, fH);
if (errno) {
// Add proper error handling code
}
// Close file
if (fH) fclose (fH);
02-08-2013 10:41 AM
First, thank you for your replies.
I can save in ASCII, but I assume binary is faster.
So, the code should look something like this?
fH = fopen ("C:\\deposit\\tmp.dat", "wb");
fwrite ((char *)ratio, sizeof(double) * 280*280*800, 3, fH);
if (fH) fclose (fH);
Since this is inside a loop creating multiple "ratio" files, it writes inside the same .dat file?
02-08-2013 12:13 PM - edited 02-08-2013 12:19 PM
Look at options for fopen: "wb" rewrites old content, while "wb+" appends data to the file. You must be sure how to read them back in this case: this way of reading/writing has no control over data structure and if you use different indexes you read back wrong data.
Also, following my example you should use fwrite ((char *)ratio, sizeof(double) * 280*280, 800, fH); otherwise you are trying to write a 4-dimensions matrix (something like an array of 3 3-dimensions matrices).
02-12-2013 06:32 AM
"wb" rewrites old content, while "wb+" appends data to the file
No, "ab" opens a binary in append mode (file pointer positioned at the end, ready to write more). "wb+" truncates, so it deletes the content of the file.