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: /* sairotate.c tomwalters@0: * ------------ tomwalters@0: * tomwalters@0: * 'Rotates' a .sai frame by 90degrees clockwise, so the horizontal tomwalters@0: * scale is frequency, vertical image-time. tomwalters@0: * tomwalters@0: * If -R is specified, then put the trigger at the top, so ImageTime goes tomwalters@0: * down. This is equiv to a 270degree rotation pluse tomwalters@0: * a refelction about x=midpoint axis. tomwalters@0: * tomwalters@0: * If -T is specified, then start drawing from the "beginning" of the tomwalters@0: * TriggerPeak (defined as the right nextevent). tomwalters@0: * tomwalters@0: * tomwalters@0: * M Akeroyd. June 1993. v1.00 Revised Spring 1994. tomwalters@0: */ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include "tip.h" tomwalters@0: tomwalters@0: 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: int readheader(FILE *inputfp); tomwalters@0: void checkheader(); tomwalters@0: void writeheader(FILE *outputfp); tomwalters@0: void changeheader(int no_frames, int new_pwidth, int new_nwidth, int framewidthsamples_output); tomwalters@0: void changeheader_B(int new_mincf, int new_maxcf, int new_channels); tomwalters@0: tomwalters@0: void writedata_output (FILE *outputfp, int samples_to_write); tomwalters@0: FILE *open_file (char filefn[], FILE *dir_default, int streamtype); tomwalters@0: tomwalters@0: int findpeaksreverse (); tomwalters@0: int find_trigger(int frame, int channel, int total_peaks); tomwalters@0: tomwalters@0: tomwalters@0: /* Data Arrays */ tomwalters@0: /* ------------------------------------------------------------------------*/ tomwalters@0: short inputdata[MAX_DATA]; tomwalters@0: short inputbychannel[MAX_CHANNELS][MAX_DATA]; tomwalters@0: short outputfiguredata[MAX_DATA]; tomwalters@0: short outputgrounddata[MAX_DATA]; tomwalters@0: tomwalters@0: tomwalters@0: /* other variables */ tomwalters@0: /*-------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: struct Peak peak[MAX_PEAKS]; tomwalters@0: struct NextEvent nextevent[MAX_NEXTEVENTS]; tomwalters@0: tomwalters@0: tomwalters@0: /* variables read from header */ tomwalters@0: /*-------------------------------------------------------------------------*/ tomwalters@0: char header[MAX_LINES_HEADER][MAX_LINE_LENGTH]; tomwalters@0: int header_lines; tomwalters@0: tomwalters@0: /* .sai parameters */ 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: /* parameters read from command line*/ tomwalters@0: int framestart; tomwalters@0: int frameend; tomwalters@0: int minchannel; tomwalters@0: int maxchannel; tomwalters@0: tomwalters@0: tomwalters@0: /* misc */ tomwalters@0: /*-----------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: char progname[MAX_STRING_LENGTH]; tomwalters@0: char outputfigurefn[MAX_STRING_LENGTH]; tomwalters@0: tomwalters@0: int verboseflag = OFF; /* -v */ tomwalters@0: int trigger_bottomflag = ON; /* -R ("lots of rotation" */ tomwalters@0: int triggerflag = OFF; /* -T */ tomwalters@0: int greyscaleflag = OFF; /* Not used: required for compilation */ tomwalters@0: int oppositearchflag = OFF; /* -oparch : see saigraph.c for info */ tomwalters@0: tomwalters@0: /* ................... Main ................................*/ tomwalters@0: /* .........................................................................*/ tomwalters@0: /* .........................................................................*/ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: void main (int argc, char *argv[]) tomwalters@0: { tomwalters@0: int n, sample; tomwalters@0: int frame, channel; tomwalters@0: int trigger_peak = 0; tomwalters@0: int header_bytes = 0; tomwalters@0: int cut_framestart, cut_frameend, cut_no_frames; tomwalters@0: int cut_minchannel, cut_maxchannel, cut_frameheight; tomwalters@0: char inputfn[MAX_STRING_LENGTH], outputbasefn[MAX_STRING_LENGTH]; tomwalters@0: FILE *inputfp, *outputfigurefp; tomwalters@0: int total_peaks; tomwalters@0: tomwalters@0: tomwalters@0: /*-------------------------------------*/ tomwalters@0: strcpy(progname, argv[0]); tomwalters@0: strcpy(inputfn, ""); tomwalters@0: strcpy(outputbasefn, ""); tomwalters@0: strcpy(outputfigurefn, ""); tomwalters@0: tomwalters@0: parsecommandline(argc, argv, inputfn, outputbasefn); tomwalters@0: tomwalters@0: if (strcmp(outputbasefn, "") == 0) tomwalters@0: strcpy(outputfigurefn, ""); tomwalters@0: else { tomwalters@0: strcpy(outputfigurefn, outputbasefn); tomwalters@0: /* strcat(outputfigurefn, OUTPUT_EXT);*/ tomwalters@0: } tomwalters@0: tomwalters@0: /*--------------------------------------*/ tomwalters@0: /* open files, read and check header */ tomwalters@0: inputfp = open_file(inputfn, stdin, READ); tomwalters@0: outputfigurefp = open_file(outputfigurefn, stdout, WRITE); tomwalters@0: header_bytes = readheader(inputfp); tomwalters@0: checkheader(); tomwalters@0: tomwalters@0: /*--------------------------------------*/ tomwalters@0: tomwalters@0: /* reset the frame/channel counters tomwalters@0: * framewidth -> frameheight tomwalters@0: * framehieght -> framewidth tomwalters@0: * (it seems that onlr framewidth has an affect on 'gensai -use': tomwalters@0: * pwidth/nwidth, nor mincf/maxcf don't do anything) tomwalters@0: */ tomwalters@0: tomwalters@0: changeheader(no_frames, pwidth, nwidth, frameheight); tomwalters@0: changeheader_B(mincf, maxcf, framewidth_samples); tomwalters@0: tomwalters@0: writeheader(outputfigurefp); tomwalters@0: tomwalters@0: /*--------------------------------------*/ tomwalters@0: tomwalters@0: if (verboseflag==ON) { tomwalters@0: fprintf(stderr, " frames "); tomwalters@0: fflush(stderr);} tomwalters@0: tomwalters@0: /*------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: for (frame=1; frame<=no_frames; frame++) { tomwalters@0: if (verboseflag==ON) { tomwalters@0: fprintf(stderr, " %i ", frame); fflush(stderr);} tomwalters@0: tomwalters@0: /*--------------------------------------*/ tomwalters@0: tomwalters@0: for (channel=1; channel <=frameheight; channel ++) { tomwalters@0: tomwalters@0: for(n=0; n < MAX_PEAKS; n++) { tomwalters@0: peak[n].tent = UNSET; tomwalters@0: nextevent[n].type = UNSET;} tomwalters@0: tomwalters@0: for(sample=0; sample= 0; sample--) { tomwalters@0: for(channel = 1; channel <= frameheight; channel++) tomwalters@0: outputfiguredata[(channel-1)] = inputbychannel[channel][sample]; tomwalters@0: writedata_output(outputfigurefp, frameheight); } } tomwalters@0: else { tomwalters@0: /* write this frame, rotated through 270 degrees (but with a mirror on tomwalters@0: * centre freq as well) tomwalters@0: * Trigger goes at bottom */ tomwalters@0: for(sample=0; sample input file default = stdin\n"); tomwalters@0: fprintf(stderr, " -o <.sai file> output file default = stdout\n"); tomwalters@0: fprintf(stderr, " -oparch assume input was generated on an opposing architecture cpu\n"); tomwalters@0: fprintf(stderr, "\n"); tomwalters@0: fprintf(stderr, " -T start at the TriggerPeak\n"); tomwalters@0: fprintf(stderr, " -R put Trigger at top (270 deg)\n"); tomwalters@0: fprintf(stderr, "\n"); tomwalters@0: fprintf(stderr, " -v verbose output (to stderr)\n"); tomwalters@0: fprintf(stderr, "\n\n" ); tomwalters@0: exit(-1);} tomwalters@0: tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: