#include #include #include #include /* Simplistic code to read short int binary file and write text file of same */ #define TRUE 1 #define FALSE 0 #define MIN(x,y) (x < y ? x : y) #define MAX(x,y) (x > y ? x : y) int ReadShort(FILE *,short *,int); short *data = NULL; int ndata = 0; int main(int argc,char **argv) { int i,n=0; short val,themin=0,themax=0; FILE *fptr; // Check args if (argc < 2) { fprintf(stderr,"Usage: %s datfile\n",argv[0]); exit(-1); } // Open file if ((fptr = fopen(argv[argc-1],"rb")) == NULL) { fprintf(stderr,"Failed to open file \"%s\"\n",argv[argc-1]); exit(-1); } // While there is binary data to read, do so while (ReadShort(fptr,&val,FALSE)) { if (ndata == 0) { themin = val; themax = val; } else { themin = MIN(themin,val); themax = MAX(themax,val); } data = realloc(data,(ndata+1)*sizeof(short)); data[ndata] = val; ndata++; } fprintf(stderr,"Read %d items\n",ndata); fprintf(stderr,"Range: %d -> %d\n",themin,themax); fclose(fptr); // Write as plain text for (i=0;i