LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Binary to ascii conversion

Hi All,
 
At the moment I'm acquiring data from a NI DAQ at 1 kHz per channel for up to 16 channels. Because of the required speed, I'm saving the data in a binary format. To be able to process the data, I'd like to convert is to e.g. ASCII. At first I tried using the FileToArray and ArrayToFile functions to read binary and write ASCII, untille I noticed that ArrayToFile only supports up to 6 digits output. I the dicided to write my own conversion, but I'm having some problems with the data arrangement. In the piece of code below the way I read my binary file is shown. This is working fine:
 
GetFileInfo (filename_read, &size);
points = (int)size/sizeof(double);
strcpy(temp,filename_read);
temp[strlen(temp)-4]='\0';
sprintf(filename_read_cfg,"%s.cfg",temp);
   
result = cfg_file_read_int(filename_read_cfg, "Number of channels", &columns);
data = malloc(points*sizeof(float64));
    
FileToArray (filename_read, data, VAL_DOUBLE, points, columns, VAL_DATA_MULTIPLEXED,
        VAL_GROUPS_AS_COLUMNS, VAL_BINARY);
 
For the ASCII part I tried using something like this:
 
i=0;
do
{
      ProcessSystemEvents();
      transfer = cluster*columns;
      if (cluster*columns*(i+1)>points) transfer = points - cluster*columns*i;
      file_wr = fopen (filename_write, "a");
      for (j=0; j<transfer; j++) r=fprintf(file_wr,"%e,", (double) data[cluster*columns*i+j]);
      fclose(file_wr);
      // r = ArrayToFile (filename_write, &data[cluster*columns*i], VAL_DOUBLE, transfer, columns,
      //    VAL_DATA_MULTIPLEXED, VAL_GROUPS_AS_COLUMNS,
      //    VAL_SEP_BY_COMMA, 10, VAL_ASCII, VAL_APPEND);
      ProcessSystemEvents();
      SetCtrlVal(panelProgressHandle,PANEL4_PROGRESS_BAR,((double)(cluster*columns*i)/(double)points*100.0));
      if(r<0) break;
      i++;
      if((cluster*columns*i)>=points) break;
}
while (!r && !ProgressCancel);
 
as you can see, I was first using ArrayToFile, with  VAL_DATA_MULTIPLEXED and VAL_GROUPS_AS_COLUMNS options. I don't know how to incorporate these options in the fprintf part, and without them the output is a complete mess. If someone could give me a pointer, I would appreciate that very much...
 
Greeting,
Ward

Message Edited by Ward on 11-28-2005 02:59 AM

Message Edited by Ward on 11-28-2005 03:00 AM

0 Kudos
Message 1 of 3
(3,714 Views)
what about:



for (i=0;i lt points;i++) {

...

for (j=0;j lt columns;j++) {

fprintf(file_wr,"%e,", (double) data[cluster*columns*i+j]);

}

fprintf(file_wr,"\n");

}

fclose(file_wr);



should give a text file with 'points' lines,

each 'columns' width. (replace 'lt' appropriately, as original code got mangeled by board software 🙂

Message Edited by josswern on 11-28-2005 10:17 AM

--
Once the game is over, the king and the pawn go back into the same box.
0 Kudos
Message 2 of 3
(3,698 Views)

Thank you for your help!

I changed points in the first loop to nr_lines = points/columns, because in my case points was the total amount of samples, for all channels combined. It's working fine now 🙂

Best regards,

Ward

0 Kudos
Message 3 of 3
(3,665 Views)