tomwalters@0: /* tomwalters@0: Copyright (c) Applied Psychology Unit, Medical Research Council. 1993 tomwalters@0: =========================================================================== tomwalters@0: tomwalters@0: Permission to use, copy, modify, and distribute this software without fee tomwalters@0: is hereby granted for research purposes, provided that this copyright tomwalters@0: notice appears in all copies and in all supporting documentation, and that tomwalters@0: the software is not redistributed for any fee (except for a nominal tomwalters@0: shipping charge). Anyone wanting to incorporate all or part of this tomwalters@0: software in a commercial product must obtain a license from the Medical tomwalters@0: Research Council. tomwalters@0: tomwalters@0: The MRC makes no representations about the suitability of this tomwalters@0: software for any purpose. It is provided "as is" without express or tomwalters@0: implied warranty. tomwalters@0: tomwalters@0: THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING tomwalters@0: ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL tomwalters@0: THE A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES tomwalters@0: OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, tomwalters@0: WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, tomwalters@0: ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS tomwalters@0: SOFTWARE. tomwalters@0: */ tomwalters@0: /* saiinfo.c tomwalters@0: * -------------- tomwalters@0: * tomwalters@0: * Outputs some useful info from the header of a .sai file tomwalters@0: * Copied from trmaxpeaks. tomwalters@0: * No output tomwalters@0: * tomwalters@0: * tomwalters@0: * M. Akeroyd. May 1993. 2.00 Revised Winter 1994. tomwalters@0: * tomwalters@0: * tomwalters@0: */ tomwalters@0: tomwalters@0: tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include tomwalters@0: tomwalters@0: #include "tip.h" tomwalters@0: tomwalters@0: tomwalters@0: /* Function declarations */ tomwalters@0: /*---------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: void parsecommandline(int argc, char *argv[], char inputfn[], char outputfn[]); tomwalters@0: tomwalters@0: int readheader(FILE *inputfp); tomwalters@0: void checkheader(); tomwalters@0: void writeheader(FILE *outputfp); tomwalters@0: tomwalters@0: void writedata_output (FILE *outputfp, int samples_to_write); tomwalters@0: void writedata_output_fg (FILE *figurefp, FILE *groundfp, int samples_to_write); tomwalters@0: FILE *open_file (char filefn[], FILE *dir_default, int streamtype); tomwalters@0: tomwalters@0: tomwalters@0: /* Data arrays: global */ tomwalters@0: /*---------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: short outputdata[MAX_DATA]; /* output */ tomwalters@0: short outputfiguredata[MAX_DATA]; /* output figure.sai: a single channel */ tomwalters@0: short outputgrounddata[MAX_DATA]; /* output ground.sai: a single channel */ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /* variables read from header */ tomwalters@0: /*---------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: tomwalters@0: char progname[MAX_STRING_LENGTH]; tomwalters@0: char header[MAX_LINES_HEADER][MAX_LINE_LENGTH]; tomwalters@0: int header_lines; tomwalters@0: tomwalters@0: /* .sai parameters */ tomwalters@0: tomwalters@0: int no_frames; tomwalters@0: int frameheight; /* number of channels */ tomwalters@0: int framewidth_samples; /* pwidth + nwidth * samplerate */ tomwalters@0: int frameshift_samples; /* frstep_aid * samplerate */ tomwalters@0: int pwidth; /* in msecs */ tomwalters@0: int nwidth; /* in msecs: NEGATIVE */ tomwalters@0: int width_win; /* pixels */ tomwalters@0: int height_win; /* pixels */ tomwalters@0: long samplerate; /* samples per sec */ tomwalters@0: int mincf; /* Hz */ tomwalters@0: int maxcf; /* Hz */ tomwalters@0: tomwalters@0: int oppositearchflag = OFF; /* -oparch : see saigraph.c for info */ tomwalters@0: int verboseflag = OFF; tomwalters@0: tomwalters@0: tomwalters@0: /*........ Main ........................................*/ tomwalters@0: /* ..................................................................*/ tomwalters@0: /* ..................................................................*/ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: void main (int argc, char *argv[]) tomwalters@0: { tomwalters@0: tomwalters@0: int sample; tomwalters@0: int n; tomwalters@0: tomwalters@0: int frame, channel; tomwalters@0: int header_bytes = 0; tomwalters@0: tomwalters@0: char inputfn[MAX_STRING_LENGTH], tomwalters@0: outputbasefn[MAX_STRING_LENGTH]; tomwalters@0: tomwalters@0: FILE *inputfp; tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: strcpy(progname, argv[0]); tomwalters@0: strcpy(outputbasefn, ""); tomwalters@0: strcpy(inputfn, ""); tomwalters@0: tomwalters@0: /* parse command line */ tomwalters@0: parsecommandline(argc, argv, inputfn, outputbasefn); tomwalters@0: tomwalters@0: tomwalters@0: /* open input files tomwalters@0: * default: stdin tomwalters@0: */ tomwalters@0: inputfp = open_file(inputfn, stdin, READ); tomwalters@0: tomwalters@0: /* read Header */ tomwalters@0: header_bytes = readheader(inputfp); tomwalters@0: tomwalters@0: /* do some error-checking on the header, and set the fread pointer to the tomwalters@0: right place */ tomwalters@0: checkheader(); tomwalters@0: tomwalters@0: tomwalters@0: /* print important bits */ tomwalters@0: tomwalters@0: fprintf(stdout, "\n"); tomwalters@0: fprintf(stdout, " header_lines ... : %5i header_bytes ... : %5i\n", header_lines, header_bytes); tomwalters@0: fprintf(stdout, "\n"); tomwalters@0: fprintf(stdout, " frames ... ... : %5i channels ... ... : %5i\n", no_frames, frameheight); tomwalters@0: fprintf(stdout, " framewidth_samples : %5i frameshift_samples : %5i\n", framewidth_samples, frameshift_samples); tomwalters@0: fprintf(stdout, " pwidth ... ... : %5i nwidth ... ... : %5i\n", pwidth, nwidth); tomwalters@0: fprintf(stdout, " mincf ... ... : %5i maxcf ... ... : %5i\n", mincf, maxcf); tomwalters@0: fprintf(stdout, "\n"); tomwalters@0: fprintf(stdout, " window width ... : %5i window height ... : %5i\n", width_win, height_win); tomwalters@0: fprintf(stdout, " sampling rate .. : %i\n", samplerate); tomwalters@0: fprintf(stdout, "\n"); tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /* Tidy up and exit */ tomwalters@0: tomwalters@0: fclose(inputfp); tomwalters@0: tomwalters@0: if ( ferror(inputfp) != 0) { tomwalters@0: fprintf(stderr, " %s : error closing input file.\n", progname); tomwalters@0: exit(-1);} tomwalters@0: tomwalters@0: exit(0); tomwalters@0: tomwalters@0: } /* Main */ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /* ....................................................................*/ tomwalters@0: /* ....................................................................*/ tomwalters@0: /* ....................................................................*/ tomwalters@0: /* ....................................................................*/ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: void parsecommandline(int argc, char *argv[], char inputfn[], char outputfn[]) tomwalters@0: { tomwalters@0: int x=1, helpflag = OFF; tomwalters@0: tomwalters@0: tomwalters@0: while (x < argc){ tomwalters@0: if (!strcmp(argv[x], "-i")) {strcpy(inputfn, argv[x+1]); x+=2;} tomwalters@0: else if (!strcmp(argv[x], "-input")) {strcpy(inputfn, argv[x+1]); x+=2;} tomwalters@0: else if (!strcmp(argv[x], "-help")) {helpflag = ON; x+=1;} tomwalters@0: else if (!strcmp(argv[x], "-h")) {helpflag = ON; x+=1;} tomwalters@0: else if (!strcmp(argv[x], "-oparch")) {oppositearchflag = ON; x+=1;} tomwalters@0: /* this next is special ... */ tomwalters@0: else if (argc==2) { strcpy(inputfn, argv[2-1]);x=argc;} tomwalters@0: else {fprintf(stderr, "%s: unknown option %s\n", progname, argv[x]); tomwalters@0: exit(-1);} tomwalters@0: } tomwalters@0: tomwalters@0: if (helpflag == ON) tomwalters@0: { tomwalters@0: fprintf(stderr, "\n"); tomwalters@0: fprintf(stderr, " %s\n", progname); tomwalters@0: fprintf(stderr, " -----------------------------------------------------------\n"); tomwalters@0: fprintf(stderr, " prints some useful information from the header of a .sai file \n"); tomwalters@0: fprintf(stderr, "\n"); tomwalters@0: fprintf(stderr, " The -oparch option is REQUIRED if reading a Sun .sai files \n"); tomwalters@0: fprintf(stderr, " on a DEC cpu or vice-versa.\n"); tomwalters@0: fprintf(stderr, " Add .sai to both input and output filenames.\n"); tomwalters@0: tomwalters@0: fprintf(stderr, " -----------------------------------------------------------\n"); tomwalters@0: fprintf(stderr, " -i <.sai file> input file default = stdin\n"); tomwalters@0: fprintf(stderr, " -oparch assume input was generated on an opposing architecture cpu\n"); tomwalters@0: fprintf(stderr, "\n"); tomwalters@0: exit(-1);} tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: