annotate saitools/saisummary.c @ 0:5242703e91d3 tip

Initial checkin for AIM92 aimR8.2 (last updated May 1997).
author tomwalters
date Fri, 20 May 2011 15:19:45 +0100
parents
children
rev   line source
tomwalters@0 1 /*
tomwalters@0 2 Copyright (c) Applied Psychology Unit, Medical Research Council. 1993
tomwalters@0 3 ===========================================================================
tomwalters@0 4
tomwalters@0 5 Permission to use, copy, modify, and distribute this software without fee
tomwalters@0 6 is hereby granted for research purposes, provided that this copyright
tomwalters@0 7 notice appears in all copies and in all supporting documentation, and that
tomwalters@0 8 the software is not redistributed for any fee (except for a nominal
tomwalters@0 9 shipping charge). Anyone wanting to incorporate all or part of this
tomwalters@0 10 software in a commercial product must obtain a license from the Medical
tomwalters@0 11 Research Council.
tomwalters@0 12
tomwalters@0 13 The MRC makes no representations about the suitability of this
tomwalters@0 14 software for any purpose. It is provided "as is" without express or
tomwalters@0 15 implied warranty.
tomwalters@0 16
tomwalters@0 17 THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
tomwalters@0 18 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
tomwalters@0 19 THE A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
tomwalters@0 20 OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
tomwalters@0 21 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
tomwalters@0 22 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
tomwalters@0 23 SOFTWARE.
tomwalters@0 24 */
tomwalters@0 25 /*---------------------------------------------------------------------------*/
tomwalters@0 26 /*
tomwalters@0 27 * saisummary
tomwalters@0 28 *
tomwalters@0 29 * builds a summary .sai
tomwalters@0 30 * Output is one channel.
tomwalters@0 31 *
tomwalters@0 32 * M. Akeroyd. May 1993. Version 2.0
tomwalters@0 33 * Revised Winter 1994.
tomwalters@0 34 * revised Autumn 1993.
tomwalters@0 35 * variuos fiddles added Summer 1994.
tomwalters@0 36 * (and some new options)
tomwalters@0 37 * and some more Spring 1995.
tomwalters@0 38 * and more Summer 1995.
tomwalters@0 39 */
tomwalters@0 40
tomwalters@0 41
tomwalters@0 42 #include <stdio.h>
tomwalters@0 43 #include <string.h>
tomwalters@0 44 #include <stdlib.h>
tomwalters@0 45
tomwalters@0 46 #include "tip.h"
tomwalters@0 47
tomwalters@0 48
tomwalters@0 49
tomwalters@0 50 /* Function declarations */
tomwalters@0 51 /*---------------------------------------------------------------------------*/
tomwalters@0 52
tomwalters@0 53
tomwalters@0 54 void parsecommandline(int argc, char *argv[], char inputfn[], char outputfn[]);
tomwalters@0 55
tomwalters@0 56 int readheader(FILE *inputfp);
tomwalters@0 57 void checkheader();
tomwalters@0 58 void writeheader(FILE *outputfp);
tomwalters@0 59
tomwalters@0 60 void writedata_output (FILE *outputfp, int samples_to_write);
tomwalters@0 61 FILE *open_file (char filefn[], FILE *dir_default, int streamtype);
tomwalters@0 62 void copytooutput_single(int no_peaks, int frame, int channel, int trigger_peak);
tomwalters@0 63
tomwalters@0 64 int findpeaksreverse();
tomwalters@0 65 int findbigpeaks(int total_peaks);
tomwalters@0 66 void integratebigpeaks(int total_bigpeaks);
tomwalters@0 67
tomwalters@0 68 void changeheader(int no_frames, int new_pwidth, int new_nwidth, int framewidth_samples_output);
tomwalters@0 69 void changeheader_B(int new_mincf, int new_maxcf, int new_channels);
tomwalters@0 70
tomwalters@0 71 void write_matrix_hori_time(int framewidth, FILE *outputfigurefp);
tomwalters@0 72
tomwalters@0 73
tomwalters@0 74
tomwalters@0 75 /* Data arrays: global */
tomwalters@0 76 /*--------------------------------------------------------------------------*/
tomwalters@0 77
tomwalters@0 78
tomwalters@0 79 short inputdata[MAX_DATA];
tomwalters@0 80 short outputdata[MAX_DATA];
tomwalters@0 81 short outputfiguredata[MAX_DATA];
tomwalters@0 82 short outputgrounddata[MAX_DATA];
tomwalters@0 83 float summary[MAX_DATA];
tomwalters@0 84 float framesummary[MAX_DATA];
tomwalters@0 85
tomwalters@0 86 short interval[MAX_CHANNELS][MAX_DATA]; /* required for matrix.c */
tomwalters@0 87 short summation[MAX_CHANNELS]; /* required for matrix.c */
tomwalters@0 88
tomwalters@0 89 int clip[MAX_DATA];
tomwalters@0 90
tomwalters@0 91 /* other variables */
tomwalters@0 92 /*-------------------------------------------------------------------------*/
tomwalters@0 93
tomwalters@0 94
tomwalters@0 95 /* variables read from header */
tomwalters@0 96 /*-------------------------------------------------------------------------*/
tomwalters@0 97
tomwalters@0 98 char header[MAX_LINES_HEADER][MAX_LINE_LENGTH];
tomwalters@0 99 int header_lines;
tomwalters@0 100
tomwalters@0 101
tomwalters@0 102
tomwalters@0 103 /* .sai parameters */
tomwalters@0 104 /*-------------------------------------------------------------------------*/
tomwalters@0 105
tomwalters@0 106 int no_frames;
tomwalters@0 107 int frameheight; /* number of channels */
tomwalters@0 108 int framewidth_samples; /* pwidth + nwidth * samplerate */
tomwalters@0 109 int frameshift_samples; /* frstep_aid * samplerate */
tomwalters@0 110 int pwidth; /* in msecs */
tomwalters@0 111 int nwidth; /* in msecs: NEGATIVE */
tomwalters@0 112 int width_win; /* pixels */
tomwalters@0 113 int height_win; /* pixels */
tomwalters@0 114 long samplerate; /* samples per sec */
tomwalters@0 115 int mincf; /* Hz */
tomwalters@0 116 int maxcf; /* Hz */
tomwalters@0 117
tomwalters@0 118
tomwalters@0 119
tomwalters@0 120
tomwalters@0 121
tomwalters@0 122 /* misc */
tomwalters@0 123 /*---------------- ---------------------------------------------------------*/
tomwalters@0 124
tomwalters@0 125 char progname[MAX_STRING_LENGTH];
tomwalters@0 126 char outputfigurefn[MAX_STRING_LENGTH];
tomwalters@0 127
tomwalters@0 128
tomwalters@0 129 int verboseflag = OFF; /* -v */
tomwalters@0 130 int summationflag = OFF;
tomwalters@0 131 int frameflag = OFF; /* -f */
tomwalters@0 132 int asciiflag = OFF;
tomwalters@0 133 int greyscaleflag = OFF;
tomwalters@0 134 int divideflag = OFF;
tomwalters@0 135
tomwalters@0 136 int oppositearchflag = OFF; /* -oparch : see saigraph.c for info */
tomwalters@0 137
tomwalters@0 138 int nstopflag = ON;
tomwalters@0 139 int nwarnflag = OFF;
tomwalters@0 140 int n32760flag = OFF;
tomwalters@0 141 int n0flag = OFF;
tomwalters@0 142 int headeroutputflag = ON;
tomwalters@0 143 int singleframeflag = OFF;
tomwalters@0 144 int frameaverageflag = ON;
tomwalters@0 145 int specificchannelflag = OFF;
tomwalters@0 146 int cutchannels[MAX_CHANNELS];
tomwalters@0 147 int nchannels=0;
tomwalters@0 148
tomwalters@0 149 int framestart;
tomwalters@0 150 int frameend;
tomwalters@0 151 int cut_framestart;
tomwalters@0 152 int cut_frameend;
tomwalters@0 153
tomwalters@0 154
tomwalters@0 155 /* .............. Main .............................*/
tomwalters@0 156 /* .....................................................................*/
tomwalters@0 157 /* .....................................................................*/
tomwalters@0 158
tomwalters@0 159
tomwalters@0 160
tomwalters@0 161
tomwalters@0 162 void main (int argc, char *argv[])
tomwalters@0 163 {
tomwalters@0 164 int sample;
tomwalters@0 165 int n;
tomwalters@0 166
tomwalters@0 167 int frame, channel;
tomwalters@0 168 int trigger_peak = 0;
tomwalters@0 169 int no_peak = 0, total_peaks =0;
tomwalters@0 170 int total_bigpeaks = 0;
tomwalters@0 171 int trueframeheight = 0;
tomwalters@0 172 int header_bytes = 0;
tomwalters@0 173
tomwalters@0 174 double temp;
tomwalters@0 175
tomwalters@0 176 char inputfn[MAX_STRING_LENGTH],
tomwalters@0 177 outputbasefn[MAX_STRING_LENGTH];
tomwalters@0 178
tomwalters@0 179 FILE *inputfp, *outputfigurefp;
tomwalters@0 180
tomwalters@0 181 strcpy(progname, argv[0]);
tomwalters@0 182 strcpy(inputfn, "");
tomwalters@0 183 strcpy(outputbasefn, "");
tomwalters@0 184 strcpy(outputfigurefn, "");
tomwalters@0 185
tomwalters@0 186 for (n=0; n<MAX_CHANNELS; n++)
tomwalters@0 187 cutchannels[n] = OFF;
tomwalters@0 188
tomwalters@0 189 /* parse command line */
tomwalters@0 190 parsecommandline(argc, argv, inputfn, outputbasefn);
tomwalters@0 191
tomwalters@0 192 /* for (n=0; n<MAX_CHANNELS; n++)
tomwalters@0 193 if (cutchannels[n] == ON)
tomwalters@0 194 fprintf(stderr, "%d\n", n);
tomwalters@0 195 */
tomwalters@0 196 if (specificchannelflag == OFF)
tomwalters@0 197 for (n=0; n<MAX_CHANNELS; n++)
tomwalters@0 198 cutchannels[n] = ON;
tomwalters@0 199
tomwalters@0 200 if (strcmp(outputbasefn, "") == 0)
tomwalters@0 201 strcpy(outputfigurefn, "");
tomwalters@0 202 else {
tomwalters@0 203 strcpy(outputfigurefn, outputbasefn);
tomwalters@0 204 /* strcat(outputfigurefn, OUTPUT_EXT);*/
tomwalters@0 205 }
tomwalters@0 206
tomwalters@0 207 /* open files */
tomwalters@0 208 /* default directions are:
tomwalters@0 209 * input = stdin
tomwalters@0 210 * figure = stdout
tomwalters@0 211 */
tomwalters@0 212
tomwalters@0 213 inputfp = open_file(inputfn, stdin, READ);
tomwalters@0 214 outputfigurefp = open_file(outputfigurefn, stdout, WRITE);
tomwalters@0 215
tomwalters@0 216 /* read Header */
tomwalters@0 217 header_bytes = readheader(inputfp);
tomwalters@0 218
tomwalters@0 219 /* do some error-checking on the header, and set the fread
tomwalters@0 220 * pointer to the right place */
tomwalters@0 221 checkheader();
tomwalters@0 222
tomwalters@0 223 if (frameflag == ON) {
tomwalters@0 224 cut_frameend = frameend;
tomwalters@0 225 cut_framestart = framestart; }
tomwalters@0 226 else {
tomwalters@0 227 cut_frameend = no_frames;
tomwalters@0 228 cut_framestart = 1; }
tomwalters@0 229
tomwalters@0 230 if (frameflag == ON)
tomwalters@0 231 changeheader((cut_frameend - cut_framestart + 1), pwidth, nwidth, framewidth_samples);
tomwalters@0 232
tomwalters@0 233 if (singleframeflag == ON)
tomwalters@0 234 changeheader(1, pwidth, nwidth, framewidth_samples);
tomwalters@0 235
tomwalters@0 236 /* reset the variables */
tomwalters@0 237 /* arguments: mincf maxcf channels */
tomwalters@0 238 changeheader_B(0, 0, 1);
tomwalters@0 239
tomwalters@0 240 /* write header */
tomwalters@0 241 if (singleframeflag == OFF) {
tomwalters@0 242 if ((asciiflag == OFF) && (headeroutputflag == ON))
tomwalters@0 243 writeheader(outputfigurefp);
tomwalters@0 244 else ;}
tomwalters@0 245 else {
tomwalters@0 246 if ((asciiflag == OFF) && (headeroutputflag == ON))
tomwalters@0 247 writeheader(outputfigurefp);
tomwalters@0 248 else if (asciiflag == ON){
tomwalters@0 249 /* begining of ascii header. The rest depends upon the output format. */
tomwalters@0 250 fprintf(outputfigurefp, "# saisummary output. %s\n", inputfn);
tomwalters@0 251 fprintf(outputfigurefp, "# \n");
tomwalters@0 252 fprintf(outputfigurefp, "# samplerate=%i pwidth=%d nwidth=%d frameheight=%i\n", samplerate, pwidth, nwidth, frameheight);
tomwalters@0 253 fprintf(outputfigurefp, "# \n");
tomwalters@0 254 }}
tomwalters@0 255
tomwalters@0 256
tomwalters@0 257 /*---------------------------------------------------------------------------*/
tomwalters@0 258
tomwalters@0 259 /* Main loop */
tomwalters@0 260
tomwalters@0 261
tomwalters@0 262 if (verboseflag==ON) {
tomwalters@0 263 fprintf(stderr, " frames ");
tomwalters@0 264 fflush(stderr);}
tomwalters@0 265
tomwalters@0 266 for(sample=0; sample<framewidth_samples; sample++)
tomwalters@0 267 framesummary[sample] = 0.0;
tomwalters@0 268
tomwalters@0 269 for (frame=1; frame<=no_frames; frame++) {
tomwalters@0 270 if (verboseflag==ON) {
tomwalters@0 271 fprintf(stderr, " %i ", frame);
tomwalters@0 272 fflush(stderr);}
tomwalters@0 273
tomwalters@0 274 for(sample=0; sample<framewidth_samples; sample++) {
tomwalters@0 275 interval[1][sample] = outputfiguredata[sample] = 0;
tomwalters@0 276 summary[sample] = 0.0;
tomwalters@0 277 clip[sample] = OFF;}
tomwalters@0 278
tomwalters@0 279 /*---------------------------------------------------------------------------*/
tomwalters@0 280
tomwalters@0 281 nchannels=0;
tomwalters@0 282 for (channel=1; channel <=frameheight; channel ++) {
tomwalters@0 283
tomwalters@0 284 /* clear arrays */
tomwalters@0 285 for(sample=0; sample<framewidth_samples; sample++)
tomwalters@0 286 inputdata[sample] = 0;
tomwalters@0 287
tomwalters@0 288 /* load data */
tomwalters@0 289 fread (inputdata, 2, (size_t) framewidth_samples, inputfp);
tomwalters@0 290
tomwalters@0 291 /* This next is a simple input check: */
tomwalters@0 292 /* revised for various warnings */
tomwalters@0 293 for(sample=0; sample<framewidth_samples; sample++) {
tomwalters@0 294 /* fprintf(stderr, "data: %i sample: %i channel: %i \n", inputdata[sample], sample, channel);*/
tomwalters@0 295 if (inputdata[sample] < 0 ) {
tomwalters@0 296 if (nstopflag == ON) {
tomwalters@0 297 if (verboseflag == ON) fprintf(stderr, "\n");
tomwalters@0 298 fprintf(stderr, "%s: negative data: ", progname);
tomwalters@0 299 fprintf(stderr, "%i sample: %i channel: %i \n", inputdata[sample], sample, channel);
tomwalters@0 300 fprintf(stderr, "bye.\n");
tomwalters@0 301 exit(-1);}
tomwalters@0 302 if (nwarnflag == ON){
tomwalters@0 303 if (verboseflag == ON) fprintf(stderr, "\n");
tomwalters@0 304 fprintf(stderr, "warning: negative data: %i (sample: %i channel: %i)\n", inputdata[sample], sample, channel);}
tomwalters@0 305 if (n0flag == ON)
tomwalters@0 306 inputdata[sample] = 0;
tomwalters@0 307 else if (n32760flag == ON)
tomwalters@0 308 inputdata[sample] = 32760;}}
tomwalters@0 309
tomwalters@0 310 /* add data to the summary autoco: outputfigurefp */
tomwalters@0 311 if ((frame >= cut_framestart) && (frame <= cut_frameend)){
tomwalters@0 312 if (cutchannels[channel] == ON){
tomwalters@0 313 nchannels ++;
tomwalters@0 314 /*fprintf(stderr, "c%d ", channel);*/
tomwalters@0 315 for(sample=0; sample<framewidth_samples; sample++)
tomwalters@0 316 summary[sample] += (double) inputdata[sample];}
tomwalters@0 317 /*fprintf(stderr, "%d hello\n", channel);*/
tomwalters@0 318 }
tomwalters@0 319 } /* channel */
tomwalters@0 320
tomwalters@0 321 /* fprintf(stderr, "c%d ", nchannels);*/
tomwalters@0 322 /* divide everything by no. of channels */
tomwalters@0 323 if (divideflag == ON) {
tomwalters@0 324 for(sample=0; sample<framewidth_samples; sample++){
tomwalters@0 325 temp = (double) summary[sample] / nchannels;
tomwalters@0 326 if ( ( temp > 32760.0)||( temp < 0)) {
tomwalters@0 327 if (clip[sample] == OFF) {
tomwalters@0 328 fprintf(stderr, "\nclipping: time interval %i\n", sample);
tomwalters@0 329 clip[sample] = ON; }
tomwalters@0 330 temp = 32761.0; }
tomwalters@0 331 interval[1][sample] = outputfiguredata[sample] = (short) temp; }}
tomwalters@0 332 else {
tomwalters@0 333 for(sample=0; sample<framewidth_samples; sample++){
tomwalters@0 334 temp = (double) summary[sample];
tomwalters@0 335 if (( temp > 32760.0) || (temp < 0.0)){
tomwalters@0 336 if (clip[sample] == OFF) {
tomwalters@0 337 fprintf(stderr, "\nclipping: time interval %i\n", sample);
tomwalters@0 338 clip[sample] = ON; }
tomwalters@0 339 temp = 32761.0; }
tomwalters@0 340 interval[1][sample] = outputfiguredata[sample] = (short) temp; }}
tomwalters@0 341
tomwalters@0 342 /* This next is a simple output check: */
tomwalters@0 343 for(sample=0; sample<framewidth_samples; sample++)
tomwalters@0 344 if (outputfiguredata[sample] < 0 ) {
tomwalters@0 345 fprintf(stderr, " %s : something's gone wrong: the output data is negative. \n", progname);
tomwalters@0 346 exit(-1); }
tomwalters@0 347
tomwalters@0 348 /* if required, sum the values */
tomwalters@0 349 if (summationflag == ON) {
tomwalters@0 350 /* clear ... */
tomwalters@0 351 summation[1] = 0;
tomwalters@0 352 clip[0] = OFF;
tomwalters@0 353 /* set ... */
tomwalters@0 354 for (sample=0; sample < framewidth_samples; sample++) {
tomwalters@0 355 summation[1] += interval[1][sample];
tomwalters@0 356 /* clip check */
tomwalters@0 357 if (( summation[1] > 32760 )||(summation[1] < 0 )) {
tomwalters@0 358 if (clip[0] == OFF) {
tomwalters@0 359 fprintf(stderr, "\nclipping: summation\n");
tomwalters@0 360 clip[0] = ON; }
tomwalters@0 361 summation[1] = 32761;}}
tomwalters@0 362
tomwalters@0 363 }
tomwalters@0 364
tomwalters@0 365 /* add to frame average */
tomwalters@0 366 if ((frame >= cut_framestart) && (frame <= cut_frameend)){
tomwalters@0 367 for (sample=0; sample < framewidth_samples; sample++)
tomwalters@0 368 framesummary[sample] += outputfiguredata[sample];
tomwalters@0 369 }
tomwalters@0 370
tomwalters@0 371 /* write output: outputfiguredata[] for the .sai
tomwalters@0 372 * interval[] & summation[] for the ascii
tomwalters@0 373 * Note hack for frameheight
tomwalters@0 374 * BUT: not if only 1 frame is to be output
tomwalters@0 375 */
tomwalters@0 376
tomwalters@0 377 if ((frame >= cut_framestart) && (frame <= cut_frameend)){
tomwalters@0 378 if (singleframeflag == OFF) {
tomwalters@0 379 if (asciiflag == OFF)
tomwalters@0 380 writedata_output(outputfigurefp, framewidth_samples);
tomwalters@0 381 else {
tomwalters@0 382 trueframeheight=frameheight;
tomwalters@0 383 frameheight=1;
tomwalters@0 384 write_matrix_hori_time(framewidth_samples, outputfigurefp);
tomwalters@0 385 frameheight=trueframeheight; }}
tomwalters@0 386 else ;
tomwalters@0 387 }
tomwalters@0 388
tomwalters@0 389 /* -------------------------------------------------------------------------*/
tomwalters@0 390
tomwalters@0 391 } /* frame */
tomwalters@0 392
tomwalters@0 393 if (singleframeflag == ON) {
tomwalters@0 394 if (verboseflag == ON) {
tomwalters@0 395 fprintf(stderr, " averaging ");
tomwalters@0 396 fflush(stderr);}
tomwalters@0 397 clip[0] = OFF;
tomwalters@0 398 for (sample=0; sample < framewidth_samples; sample++) {
tomwalters@0 399 if (frameaverageflag == ON)
tomwalters@0 400 temp = framesummary[sample]/(cut_frameend - cut_framestart + 1);
tomwalters@0 401 else
tomwalters@0 402 temp = framesummary[sample];
tomwalters@0 403 /* clip check */
tomwalters@0 404 if (temp > 32760) {
tomwalters@0 405 if (clip[0] == OFF) {
tomwalters@0 406 fprintf(stderr, "\nclipping: frameaverage at sample %i\n", sample);
tomwalters@0 407 clip[0] = ON; }
tomwalters@0 408 temp = 32760;}
tomwalters@0 409 outputfiguredata[sample]= (short)temp;
tomwalters@0 410 interval[1][sample] = outputfiguredata[sample];}
tomwalters@0 411 if (asciiflag == OFF)
tomwalters@0 412 writedata_output(outputfigurefp, framewidth_samples);
tomwalters@0 413 else {
tomwalters@0 414 trueframeheight=frameheight;
tomwalters@0 415 frameheight=1;
tomwalters@0 416 write_matrix_hori_time(framewidth_samples, outputfigurefp);
tomwalters@0 417 frameheight=trueframeheight; }}
tomwalters@0 418 else ;
tomwalters@0 419
tomwalters@0 420
tomwalters@0 421 /* Tidy up and exit */
tomwalters@0 422 fprintf(stderr, "\n");
tomwalters@0 423 fclose(inputfp);
tomwalters@0 424 fclose(outputfigurefp);
tomwalters@0 425
tomwalters@0 426 if ( ferror(inputfp) != 0) {
tomwalters@0 427 fprintf(stderr, " %s : error closing input file.\n", progname);
tomwalters@0 428 exit(-1);}
tomwalters@0 429
tomwalters@0 430 if ( ferror(outputfigurefp) != 0) {
tomwalters@0 431 fprintf(stderr, " %s : error closing figure file.\n", progname);
tomwalters@0 432 exit(-1);}
tomwalters@0 433
tomwalters@0 434 exit(0);
tomwalters@0 435
tomwalters@0 436 } /* Main */
tomwalters@0 437
tomwalters@0 438
tomwalters@0 439
tomwalters@0 440
tomwalters@0 441
tomwalters@0 442
tomwalters@0 443 /* .....................................................................*/
tomwalters@0 444 /* .....................................................................*/
tomwalters@0 445 /* .....................................................................*/
tomwalters@0 446 /* .....................................................................*/
tomwalters@0 447
tomwalters@0 448
tomwalters@0 449
tomwalters@0 450
tomwalters@0 451
tomwalters@0 452
tomwalters@0 453 void parsecommandline(int argc, char *argv[], char inputfn[], char outputfn[])
tomwalters@0 454 {
tomwalters@0 455 int x=1, helpflag = OFF;
tomwalters@0 456 int group;
tomwalters@0 457
tomwalters@0 458 while (x < argc){
tomwalters@0 459 if (!strcmp(argv[x], "-o")) {strcpy(outputfn, argv[x+1]); x+=2;}
tomwalters@0 460 else if (!strcmp(argv[x], "-output")) {strcpy(outputfn, argv[x+1]); x+=2;}
tomwalters@0 461 else if (!strcmp(argv[x], "-i")) {strcpy(inputfn, argv[x+1]); x+=2;}
tomwalters@0 462 else if (!strcmp(argv[x], "-input")) {strcpy(inputfn, argv[x+1]); x+=2;}
tomwalters@0 463 else if (!strcmp(argv[x], "-help")) {helpflag = ON; x+=1;}
tomwalters@0 464 else if (!strcmp(argv[x], "-h")) {helpflag = ON; x+=1;}
tomwalters@0 465 else if (!strcmp(argv[x], "-verbose")) {verboseflag = ON; x+=1;}
tomwalters@0 466 else if (!strcmp(argv[x], "-v")) {verboseflag = ON; x+=1;}
tomwalters@0 467 else if (!strcmp(argv[x], "-s")) {summationflag = ON; x+=1;}
tomwalters@0 468 else if (!strcmp(argv[x], "-g")) {greyscaleflag = ON; x+=1;}
tomwalters@0 469 else if (!strcmp(argv[x], "-gray")) {greyscaleflag = ON; x+=1;}
tomwalters@0 470 else if (!strcmp(argv[x], "-grey")) {greyscaleflag = ON; x+=1;}
tomwalters@0 471 else if (!strcmp(argv[x], "-ar")) {asciiflag = ON; x+=1;}
tomwalters@0 472 else if (!strcmp(argv[x], "-d")) {divideflag = ON; x+=1;}
tomwalters@0 473 else if (!strcmp(argv[x], "-channels")) {specificchannelflag = ON;
tomwalters@0 474 x+=1;
tomwalters@0 475 while (x<argc){
tomwalters@0 476 if ((int) strspn(argv[x], "-") == 0)
tomwalters@0 477 cutchannels[atoi(argv[x])]=ON;
tomwalters@0 478 else break;
tomwalters@0 479 x++;}}
tomwalters@0 480 else if (!strcmp(argv[x], "-oneframe")) {singleframeflag = ON; frameaverageflag = ON; x+=1;}
tomwalters@0 481 else if (!strcmp(argv[x], "-sumframe")) {singleframeflag = ON; frameaverageflag = OFF; x+=1;}
tomwalters@0 482 else if (!strcmp(argv[x], "-oparch")) {oppositearchflag = ON; x+=1;}
tomwalters@0 483 else if (!strcmp(argv[x], "-nstop")) {nstopflag = ON; x+=1;}
tomwalters@0 484 else if (!strcmp(argv[x], "-header")) {headeroutputflag = ON; x+=1;}
tomwalters@0 485 else if (!strcmp(argv[x], "-noheader")) {headeroutputflag = OFF; x+=1;}
tomwalters@0 486 else if (!strcmp(argv[x], "-nwarn")) {nwarnflag = ON; nstopflag = OFF; x+=1;}
tomwalters@0 487 else if (!strcmp(argv[x], "-nignore")) {nwarnflag = OFF; nstopflag = OFF; x+=1;}
tomwalters@0 488 else if (!strcmp(argv[x], "-n0")) {n0flag = ON; n32760flag = OFF; nstopflag = OFF; x+=1;}
tomwalters@0 489 else if (!strcmp(argv[x], "-n32760")) {n0flag = OFF; n32760flag = ON; nstopflag = OFF; x+=1;}
tomwalters@0 490 else if (!strcmp(argv[x], "-frames")) {frameflag=ON; framestart=atoi(argv[x+1]); frameend=atoi(argv[x+2]); x+=3;}
tomwalters@0 491
tomwalters@0 492 else {fprintf(stderr, "%s: unknown option %s\n", progname, argv[x]);
tomwalters@0 493 exit(-1);}
tomwalters@0 494 }
tomwalters@0 495
tomwalters@0 496 if (helpflag == ON)
tomwalters@0 497 {
tomwalters@0 498 fprintf(stderr, "\n");
tomwalters@0 499 fprintf(stderr, " saisummary\n");
tomwalters@0 500 fprintf(stderr, " -----------------------------------------------------------\n");
tomwalters@0 501 fprintf(stderr, " Works out a summary image (cf a summary autocorrelogram).\n");
tomwalters@0 502 fprintf(stderr, " The -oparch option is REQUIRED if reading a Sun .sai files \n");
tomwalters@0 503 fprintf(stderr, " on a DEC cpu or vice-versa.\n");
tomwalters@0 504 fprintf(stderr, " Add .sai to both input and output filenames.\n");
tomwalters@0 505 fprintf(stderr, "\n");
tomwalters@0 506 fprintf(stderr, " -i <.sai file> input file default = stdin\n");
tomwalters@0 507 fprintf(stderr, " -o <.sai file> output file default = stdout\n");
tomwalters@0 508 fprintf(stderr, " -oparch assume input was generated on an opposing architecture cpu\n");
tomwalters@0 509 fprintf(stderr, "\n");
tomwalters@0 510 fprintf(stderr, " -frames <start> <end> (inclusive) (default=all)\n");
tomwalters@0 511 fprintf(stderr, " -channels <> <> ..... specify channel numbers to be included (1++)\n");
tomwalters@0 512 fprintf(stderr, " -d divide by no. of channels (Warning: precision may be lost).\n");
tomwalters@0 513 fprintf(stderr, " -ar ASCII output: rows=time intervals (requires -oneframe)\n");
tomwalters@0 514 fprintf(stderr, " -s include summations (ascii only)\n");
tomwalters@0 515 fprintf(stderr, "\n");
tomwalters@0 516 fprintf(stderr, " -header include AIM header in output file (default)\n");
tomwalters@0 517 fprintf(stderr, " -noheader don't ... ... ... \n");
tomwalters@0 518 fprintf(stderr, " -v verbose output (to stderr)\n");
tomwalters@0 519 fprintf(stderr, " -g change .sai format to 'grayscale'\n");
tomwalters@0 520 fprintf(stderr, " -oneframe average frames together; one (1) output frame\n");
tomwalters@0 521 fprintf(stderr, " -sumframe sum frames together; one (1) output frame\n");
tomwalters@0 522 fprintf(stderr, "\n");
tomwalters@0 523 fprintf(stderr, " -nstop if negative inputs found, stop processing (default)\n");
tomwalters@0 524 fprintf(stderr, " -nwarn if negative inputs found, continue (but warn user) \n");
tomwalters@0 525 fprintf(stderr, " -nignore if negative inputs found, continue \n");
tomwalters@0 526 fprintf(stderr, " -n0 if negative inputs found, replace with 0 \n");
tomwalters@0 527 fprintf(stderr, " -n32760 if negative inputs found, replace with 32760 \n");
tomwalters@0 528 fprintf(stderr, "\n\n");
tomwalters@0 529 exit(-1);}
tomwalters@0 530 }
tomwalters@0 531
tomwalters@0 532 /* The End. */
tomwalters@0 533 /*------------------------------------------------------------------------------------------------------*/