Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include "plxstructs.h"
  5.  
  6. FILE *plxfile = NULL; //Global file pointer is ok for now...
  7. struct PL_FileHeader fileheader; //we'll slurp in the file header to fileheader
  8. struct PL_ChanHeader channelheader[128]; //This is max channels in any system right now
  9. struct PL_SlowChannelHeader continuousheader[384]; //this is max (128 * 3) continuous channels right now
  10. struct PL_EventHeader eventheader[64]; //Not sure what the max is, this is an overshoot
  11. struct PL_DataBlockHeader blockheader;
  12.  
  13. int main(void)
  14. {
  15.  
  16. //Set up the file pointer and a little error checking
  17.     const char *filename = "64chWB-LargeFile.plx";
  18.     plxfile = fopen(filename, "rb");
  19.     if (plxfile == NULL)
  20.         {
  21.             printf ("error opening file\n");
  22.             return 0;
  23.         }
  24.  
  25. //First read in the file header
  26.     fread(&fileheader, sizeof(struct PL_FileHeader), 1, plxfile);
  27.  
  28.     printf("Number of DSP (AKA ""spike"") channels: %i\n", fileheader.NumDSPChannels);
  29.     printf("Number of continuous (""wideband, spike, FP"") channels: %i\n", fileheader.NumSlowChannels);
  30.     printf("Number of event channels %i\n", fileheader.NumEventChannels);
  31.  
  32. //Second read in the spike channel headers
  33.     int x;
  34.     fread(&channelheader, sizeof(struct PL_ChanHeader) * fileheader.NumDSPChannels, 1, plxfile);
  35.     for (x = 0; x < fileheader.NumDSPChannels; x++)
  36.         {
  37.         printf("Spike Channel Name: %s\n", channelheader[x].Name);
  38.         }
  39.  
  40. //Third read in the event headers
  41.     int z;
  42.     fread(&eventheader, sizeof(struct PL_EventHeader) * fileheader.NumEventChannels, 1, plxfile);
  43.     for (z = 0; z < fileheader.NumEventChannels; z++)
  44.         {
  45.         printf("Event Channel Name: %s\n", eventheader[z].Name);
  46.         }
  47.  
  48. //Fourth resad in the continuous (AKA slow) channel headers
  49.     int y;
  50.     fread(&continuousheader, sizeof(struct PL_SlowChannelHeader) * fileheader.NumSlowChannels, 1, plxfile);
  51.     for (y = 0; y < fileheader.NumSlowChannels; y++)
  52.         {
  53.         printf("Continuous Channel Name: %s\n", continuousheader[y].Name);
  54.         }
  55.  
  56. //Fifth read in and handle uniquely each type of data block
  57.     int loop =  0; //might use this later
  58.  
  59. //I'll start it off manually before going into the loop
  60. //This makes it easier for me to use feof later.
  61.     fread(&blockheader, sizeof(struct PL_DataBlockHeader), 1, plxfile);
  62.  
  63.     //Now we check out what was brought into the block header and repeat
  64.     while(loop == 0)
  65.         {
  66.             if (blockheader.Type == 1)
  67.             {
  68.                 //Print out some info on the spike
  69.                 //printf("Spike Ch %i Unit %i\n", blockheader.Channel, blockheader.Unit);
  70.                 //Skip past the spike waveform data (not checking for files with TS only!)
  71.                 fseek(plxfile, (blockheader.NumberOfWordsInWaveform * sizeof(short int)), SEEK_CUR);
  72.             }
  73.  
  74.             else if (blockheader.Type == 4)
  75.             {
  76.                 //Print out info on the unit
  77.                 printf("Event %i\n", blockheader.Channel);
  78.             }
  79.  
  80.             else if (blockheader.Type == 5)
  81.             {
  82.                 //Print out info on continuous block
  83.                 //printf("Continuous data for Ch %i\n", blockheader.Channel);
  84.                 //Skip past continuous data in block
  85.                 fseek(plxfile, (blockheader.NumberOfWordsInWaveform * sizeof(short int)), SEEK_CUR);
  86.             }
  87.             //read in the next data block header
  88.             fread(&blockheader, sizeof(struct PL_DataBlockHeader), 1, plxfile);
  89.  
  90.             //feof is only true if fread reads past the last point - NOT when it's AT the last point.
  91.             if (feof(plxfile)) {break;}
  92.  
  93.         }
  94.  
  95.     fclose(plxfile);
  96.  
  97.     printf("End of data.\n\n");
  98.  
  99.     return 0;
  100.  
  101. }