Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include "plxstructs.h"
- FILE *plxfile = NULL; //Global file pointer is ok for now...
- struct PL_FileHeader fileheader; //we'll slurp in the file header to fileheader
- struct PL_ChanHeader channelheader[128]; //This is max channels in any system right now
- struct PL_SlowChannelHeader continuousheader[384]; //this is max (128 * 3) continuous channels right now
- struct PL_EventHeader eventheader[64]; //Not sure what the max is, this is an overshoot
- struct PL_DataBlockHeader blockheader;
- int main(void)
- {
- //Set up the file pointer and a little error checking
- const char *filename = "64chWB-LargeFile.plx";
- plxfile = fopen(filename, "rb");
- if (plxfile == NULL)
- {
- printf ("error opening file\n");
- return 0;
- }
- //First read in the file header
- fread(&fileheader, sizeof(struct PL_FileHeader), 1, plxfile);
- printf("Number of DSP (AKA ""spike"") channels: %i\n", fileheader.NumDSPChannels);
- printf("Number of continuous (""wideband, spike, FP"") channels: %i\n", fileheader.NumSlowChannels);
- printf("Number of event channels %i\n", fileheader.NumEventChannels);
- //Second read in the spike channel headers
- int x;
- fread(&channelheader, sizeof(struct PL_ChanHeader) * fileheader.NumDSPChannels, 1, plxfile);
- for (x = 0; x < fileheader.NumDSPChannels; x++)
- {
- printf("Spike Channel Name: %s\n", channelheader[x].Name);
- }
- //Third read in the event headers
- int z;
- fread(&eventheader, sizeof(struct PL_EventHeader) * fileheader.NumEventChannels, 1, plxfile);
- for (z = 0; z < fileheader.NumEventChannels; z++)
- {
- printf("Event Channel Name: %s\n", eventheader[z].Name);
- }
- //Fourth resad in the continuous (AKA slow) channel headers
- int y;
- fread(&continuousheader, sizeof(struct PL_SlowChannelHeader) * fileheader.NumSlowChannels, 1, plxfile);
- for (y = 0; y < fileheader.NumSlowChannels; y++)
- {
- printf("Continuous Channel Name: %s\n", continuousheader[y].Name);
- }
- //Fifth read in and handle uniquely each type of data block
- int loop = 0; //might use this later
- //I'll start it off manually before going into the loop
- //This makes it easier for me to use feof later.
- fread(&blockheader, sizeof(struct PL_DataBlockHeader), 1, plxfile);
- //Now we check out what was brought into the block header and repeat
- while(loop == 0)
- {
- if (blockheader.Type == 1)
- {
- //Print out some info on the spike
- //printf("Spike Ch %i Unit %i\n", blockheader.Channel, blockheader.Unit);
- //Skip past the spike waveform data (not checking for files with TS only!)
- fseek(plxfile, (blockheader.NumberOfWordsInWaveform * sizeof(short int)), SEEK_CUR);
- }
- else if (blockheader.Type == 4)
- {
- //Print out info on the unit
- printf("Event %i\n", blockheader.Channel);
- }
- else if (blockheader.Type == 5)
- {
- //Print out info on continuous block
- //printf("Continuous data for Ch %i\n", blockheader.Channel);
- //Skip past continuous data in block
- fseek(plxfile, (blockheader.NumberOfWordsInWaveform * sizeof(short int)), SEEK_CUR);
- }
- //read in the next data block header
- fread(&blockheader, sizeof(struct PL_DataBlockHeader), 1, plxfile);
- //feof is only true if fread reads past the last point - NOT when it's AT the last point.
- if (feof(plxfile)) {break;}
- }
- fclose(plxfile);
- printf("End of data.\n\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement