#include "stdio.h" #include "stdlib.h" #include "math.h" #include "sethead.h" #include #include /* Minimal conversion program for Neuroscan average files The output file is as follows First line: nchannels adcrate nevents nsamples Second line: "sample event elec_1 elec_2 .... elec_nchannels" Rest of file: sample event# sample_1 sample_2 .... sample_nchannels */ #define TRUE 1 #define FALSE 0 #define MIN(x,y) (x < y ? x : y) #define MAX(x,y) (x > y ? x : y) int main(argc,argv) int argc; char **argv; { int i,j,readok,foundevent; float sample,scale; float themin=1e32,themax=-1e32; short unsigned nchannels; short unsigned adc; short unsigned nsamples; long c,filesize=0; char ename[16]; FILE *fptr; float **data; /* Do we have enough arguments */ if (argc < 2) { fprintf(stderr,"Usage: %s avgfile scale\n",argv[0]); exit(0); } /* Attempt to open the average EEG file */ if ((fptr = fopen(argv[1],"r")) == NULL) { fprintf(stderr,"Unable to open file <%s>\n",argv[1]); exit(0); } /* Calculate the file size */ while ((c = fgetc(fptr)) != EOF) filesize++; fseek(fptr,0L,SEEK_SET); /* Read the number of channels */ fseek(fptr,370L,SEEK_SET); readok = ReadUShort(fptr,&nchannels,TRUE); if (!readok || nchannels < 1 || nchannels > 64) { fprintf(stderr,"Unexpected number of channels <%d>\n",nchannels); exit(0); } printf("%d ",nchannels); /* Read the ADC rate */ fseek(fptr,376L,SEEK_SET); readok = ReadUShort(fptr,&adc,TRUE); if (!readok || adc < 1) { fprintf(stderr,"Unexpected error reading adc rate\n",adc); exit(0); } printf("%d 0 ",adc); /* Calculate the number of expected samples */ nsamples = ((filesize - 900 - nchannels*75) / nchannels - 5) / 4; if (nsamples < 1) { fprintf(stderr,"Unexpected number of samples <%ld>\n",nsamples); exit(0); } printf("%ld\n",(long)nsamples); /* Read the electrode names */ printf("sample event "); for (i=0;i