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
|
tomwalters@0
|
28 /* saigraph.c
|
tomwalters@0
|
29 * --------------
|
tomwalters@0
|
30 *
|
tomwalters@0
|
31 * Works out the (first-order) temporal intervals between peaks in a .sai file,
|
tomwalters@0
|
32 * and saves them in a SINGLE-FRAME .sai
|
tomwalters@0
|
33 * In essence, a histogram.
|
tomwalters@0
|
34 *
|
tomwalters@0
|
35 * Uses ALL peaks: if you just want the locallly maxima peaks, then use
|
tomwalters@0
|
36 * trbigpeak first.
|
tomwalters@0
|
37 *
|
tomwalters@0
|
38 * Output is another .sai file: but only a single frame. The header is
|
tomwalters@0
|
39 * modified accordingly.
|
tomwalters@0
|
40 *
|
tomwalters@0
|
41 *
|
tomwalters@0
|
42 *
|
tomwalters@0
|
43 * M. Akeroyd. May 1993. Version 2.0
|
tomwalters@0
|
44 *
|
tomwalters@0
|
45 * Autumn 1993: added grayscaleflag
|
tomwalters@0
|
46 * Winter 1994: allowed weighting, and other general revisions.
|
tomwalters@0
|
47 */
|
tomwalters@0
|
48
|
tomwalters@0
|
49
|
tomwalters@0
|
50
|
tomwalters@0
|
51 #include <stdio.h>
|
tomwalters@0
|
52 #include <string.h>
|
tomwalters@0
|
53 #include <stdlib.h>
|
tomwalters@0
|
54
|
tomwalters@0
|
55 #include "tip.h"
|
tomwalters@0
|
56
|
tomwalters@0
|
57
|
tomwalters@0
|
58 /* Function declarations */
|
tomwalters@0
|
59 /*------------------------------------------------------------*/
|
tomwalters@0
|
60
|
tomwalters@0
|
61 void parsecommandline (int argc, char *argv[], char inputfn[], char outputfn[]);
|
tomwalters@0
|
62
|
tomwalters@0
|
63 int readheader(FILE *inputfp);
|
tomwalters@0
|
64 void checkheader();
|
tomwalters@0
|
65 void writeheader(FILE *outputfp);
|
tomwalters@0
|
66
|
tomwalters@0
|
67 void changeheader(int no_frames, int new_pwidth, int new_nwidth, int framewidth_samples_output);
|
tomwalters@0
|
68
|
tomwalters@0
|
69 int findpeaksreverse ();
|
tomwalters@0
|
70 void find_intervals(int total_peaks, int channel, int max_interval);
|
tomwalters@0
|
71
|
tomwalters@0
|
72 void writedata_output (FILE *outputfp, int samples_to_write);
|
tomwalters@0
|
73 void writedata_output_fg (FILE *figurefp, FILE *groundfp, int samples_to_write);
|
tomwalters@0
|
74 FILE *open_file (char filefn[], FILE *dir_default, int streamtype);
|
tomwalters@0
|
75
|
tomwalters@0
|
76 void copytooutput_fg_single (int total_peaks, int frame, int channel, int trigger_peak);
|
tomwalters@0
|
77
|
tomwalters@0
|
78 void write_matrix_hori_time(int framewidth, FILE *outputfigurefp);
|
tomwalters@0
|
79 void write_matrix_hori_freq(int framewidth, FILE *outputfigurefp);
|
tomwalters@0
|
80
|
tomwalters@0
|
81
|
tomwalters@0
|
82
|
tomwalters@0
|
83
|
tomwalters@0
|
84 /* Data arrays: global */
|
tomwalters@0
|
85 /*-----------------------------------------------------------------*/
|
tomwalters@0
|
86
|
tomwalters@0
|
87
|
tomwalters@0
|
88 short inputdata[MAX_DATA]; /* input .sai: a single channel of a frame */
|
tomwalters@0
|
89 short outputdata[MAX_DATA]; /* output .sai: a single channel */
|
tomwalters@0
|
90 short outputfiguredata[MAX_DATA]; /* output figure.sai: a single channel */
|
tomwalters@0
|
91 short outputgrounddata[MAX_DATA]; /* output ground.sai: a single channel */
|
tomwalters@0
|
92 short clip[MAX_CHANNELS];
|
tomwalters@0
|
93
|
tomwalters@0
|
94 short interval[MAX_CHANNELS][MAX_DATA]; /* histogram */
|
tomwalters@0
|
95 short summation[MAX_CHANNELS];
|
tomwalters@0
|
96
|
tomwalters@0
|
97
|
tomwalters@0
|
98
|
tomwalters@0
|
99 /* other variables */
|
tomwalters@0
|
100 /*----------------------------------------------------------------*/
|
tomwalters@0
|
101
|
tomwalters@0
|
102 struct Peak peak[MAX_PEAKS]; /* used in findpeaksreverse():
|
tomwalters@0
|
103 * single channel */
|
tomwalters@0
|
104 struct NextEvent nextevent[MAX_NEXTEVENTS]; /* used in findpeaksreverse():
|
tomwalters@0
|
105 * single channel */
|
tomwalters@0
|
106
|
tomwalters@0
|
107
|
tomwalters@0
|
108
|
tomwalters@0
|
109 /* variables read from header */
|
tomwalters@0
|
110 /*---------------------------------------------------------------*/
|
tomwalters@0
|
111
|
tomwalters@0
|
112 char header[MAX_LINES_HEADER][MAX_LINE_LENGTH];
|
tomwalters@0
|
113 int header_lines;
|
tomwalters@0
|
114
|
tomwalters@0
|
115 int no_frames;
|
tomwalters@0
|
116 int frameheight; /* number of channels */
|
tomwalters@0
|
117 int framewidth_samples; /* pwidth + nwidth * samplerate */
|
tomwalters@0
|
118 int frameshift_samples; /* frstep_aid * samplerate */
|
tomwalters@0
|
119 int pwidth; /* in msecs */
|
tomwalters@0
|
120 int nwidth; /* in msecs: NEGATIVE */
|
tomwalters@0
|
121 int width_win; /* pixels */
|
tomwalters@0
|
122 int height_win; /* pixels */
|
tomwalters@0
|
123 long samplerate; /* samples per sec */
|
tomwalters@0
|
124 int mincf; /* Hz */
|
tomwalters@0
|
125 int maxcf; /* Hz */
|
tomwalters@0
|
126
|
tomwalters@0
|
127
|
tomwalters@0
|
128
|
tomwalters@0
|
129
|
tomwalters@0
|
130 /* misc */
|
tomwalters@0
|
131 /*-----------------------------------------------------------*/
|
tomwalters@0
|
132
|
tomwalters@0
|
133 char progname[MAX_STRING_LENGTH];
|
tomwalters@0
|
134 char outputfigurefn[MAX_STRING_LENGTH];
|
tomwalters@0
|
135
|
tomwalters@0
|
136
|
tomwalters@0
|
137 int verboseflag = OFF; /* -v */
|
tomwalters@0
|
138 int removeflag = OFF; /* -r */
|
tomwalters@0
|
139 double removevalue = 0.1;
|
tomwalters@0
|
140 int widthflag = OFF; /* -width : if OFF, copy pwdith/nwidth
|
tomwalters@0
|
141 * off Input .sai */
|
tomwalters@0
|
142 int total_width; /* -width : total width of new .sai */
|
tomwalters@0
|
143 int asciiflag = OFF; /* -a */
|
tomwalters@0
|
144 int asciireverseflag = OFF; /* -ar */
|
tomwalters@0
|
145 int summationflag = OFF; /* -s */
|
tomwalters@0
|
146 int greyscaleflag = OFF; /* -g */
|
tomwalters@0
|
147 int weightflag = OFF; /* -weight */
|
tomwalters@0
|
148 int oppositearchflag = OFF; /* -oparch: if ON, then the header-reading
|
tomwalters@0
|
149 * code will load one (1) extra byte. This
|
tomwalters@0
|
150 * is so that Sun .sai/.nap can be read
|
tomwalters@0
|
151 * on a DEC, and equally the reverse.
|
tomwalters@0
|
152 * It is NOT required if reading Sun on
|
tomwalters@0
|
153 * Sun, or DEC on DEC. */
|
tomwalters@0
|
154
|
tomwalters@0
|
155
|
tomwalters@0
|
156
|
tomwalters@0
|
157 /*............... Main ................................*/
|
tomwalters@0
|
158 /*.........................................................................*/
|
tomwalters@0
|
159 /*.........................................................................*/
|
tomwalters@0
|
160
|
tomwalters@0
|
161
|
tomwalters@0
|
162
|
tomwalters@0
|
163 void main (int argc, char *argv[])
|
tomwalters@0
|
164 {
|
tomwalters@0
|
165 int sample;
|
tomwalters@0
|
166 int n;
|
tomwalters@0
|
167
|
tomwalters@0
|
168 int frame, channel;
|
tomwalters@0
|
169 int trigger_peak = 0;
|
tomwalters@0
|
170 int no_peak = 0, total_peaks =0, total_peaks_2;
|
tomwalters@0
|
171 int framewidth_samples_input,
|
tomwalters@0
|
172 framewidth_samples_output;
|
tomwalters@0
|
173 int new_pwidth,
|
tomwalters@0
|
174 new_nwidth;
|
tomwalters@0
|
175 int header_bytes = 0;
|
tomwalters@0
|
176
|
tomwalters@0
|
177 char inputfn[MAX_STRING_LENGTH],
|
tomwalters@0
|
178 outputbasefn[MAX_STRING_LENGTH];
|
tomwalters@0
|
179
|
tomwalters@0
|
180 FILE *inputfp, *outputfigurefp;
|
tomwalters@0
|
181
|
tomwalters@0
|
182 int clipflag = OFF;
|
tomwalters@0
|
183
|
tomwalters@0
|
184 /*-----------------------------------------*/
|
tomwalters@0
|
185
|
tomwalters@0
|
186 strcpy(progname, argv[0]);
|
tomwalters@0
|
187 strcpy(inputfn, "");
|
tomwalters@0
|
188 strcpy(outputbasefn, "");
|
tomwalters@0
|
189 strcpy(outputfigurefn, "");
|
tomwalters@0
|
190
|
tomwalters@0
|
191 /* parse command line */
|
tomwalters@0
|
192 parsecommandline(argc, argv, inputfn, outputbasefn);
|
tomwalters@0
|
193
|
tomwalters@0
|
194 if (strcmp(outputbasefn, "") == 0)
|
tomwalters@0
|
195 strcpy(outputfigurefn, "");
|
tomwalters@0
|
196 else
|
tomwalters@0
|
197 strcpy(outputfigurefn, outputbasefn);
|
tomwalters@0
|
198
|
tomwalters@0
|
199
|
tomwalters@0
|
200 /* open files */
|
tomwalters@0
|
201 /* default directions are:
|
tomwalters@0
|
202 * input = stdin
|
tomwalters@0
|
203 * figure = stdout
|
tomwalters@0
|
204 */
|
tomwalters@0
|
205
|
tomwalters@0
|
206 inputfp = open_file(inputfn, stdin, READ);
|
tomwalters@0
|
207 outputfigurefp = open_file(outputfigurefn, stdout, WRITE);
|
tomwalters@0
|
208
|
tomwalters@0
|
209 /* read Header */
|
tomwalters@0
|
210 header_bytes = readheader(inputfp);
|
tomwalters@0
|
211 checkheader();
|
tomwalters@0
|
212
|
tomwalters@0
|
213
|
tomwalters@0
|
214 /* reset the variables */
|
tomwalters@0
|
215 framewidth_samples_input = framewidth_samples;
|
tomwalters@0
|
216 if (widthflag == OFF) {
|
tomwalters@0
|
217 new_pwidth = + pwidth;
|
tomwalters@0
|
218 new_nwidth = -nwidth;
|
tomwalters@0
|
219 framewidth_samples_output = framewidth_samples_input;}
|
tomwalters@0
|
220 else {
|
tomwalters@0
|
221 new_pwidth = + NEW_PWIDTH;
|
tomwalters@0
|
222 new_nwidth = (new_pwidth + total_width);
|
tomwalters@0
|
223 framewidth_samples_output = (int) ((int) (abs(new_pwidth) + abs (new_nwidth)) * samplerate ) / 1000;}
|
tomwalters@0
|
224
|
tomwalters@0
|
225 if (framewidth_samples_output >= MAX_DATA) {
|
tomwalters@0
|
226 fprintf(stderr, "%s: new frame is too wide at %i: only allowed %i samples\n", progname, framewidth_samples_output, MAX_DATA);
|
tomwalters@0
|
227 exit(-1); }
|
tomwalters@0
|
228
|
tomwalters@0
|
229
|
tomwalters@0
|
230 /* change header */
|
tomwalters@0
|
231 changeheader(1, new_pwidth, new_nwidth, framewidth_samples_output);
|
tomwalters@0
|
232
|
tomwalters@0
|
233 /* write header */
|
tomwalters@0
|
234 if (asciiflag == OFF)
|
tomwalters@0
|
235 writeheader(outputfigurefp);
|
tomwalters@0
|
236 else {
|
tomwalters@0
|
237 /* begining of ascii header. The rest depends on the matrix format ... */
|
tomwalters@0
|
238 fprintf(outputfigurefp, "# saigraph output. %s\n", inputfn);
|
tomwalters@0
|
239 fprintf(outputfigurefp, "# \n");
|
tomwalters@0
|
240 fprintf(outputfigurefp, "# samplerate=%i pwidth=%d nwidth=%d frames=%i ", samplerate, pwidth, nwidth, no_frames);
|
tomwalters@0
|
241 fprintf(outputfigurefp, " mincf=%i maxcf=%i channels=%i \n", mincf, maxcf, frameheight);
|
tomwalters@0
|
242 fprintf(outputfigurefp, "# \n");
|
tomwalters@0
|
243 }
|
tomwalters@0
|
244
|
tomwalters@0
|
245 /*------------------------------------------*/
|
tomwalters@0
|
246
|
tomwalters@0
|
247 /* Main loop */
|
tomwalters@0
|
248
|
tomwalters@0
|
249 if (verboseflag == ON) {
|
tomwalters@0
|
250 fprintf(stderr, " frames ");
|
tomwalters@0
|
251 fflush(stderr);}
|
tomwalters@0
|
252
|
tomwalters@0
|
253
|
tomwalters@0
|
254 /* clear arrays */
|
tomwalters@0
|
255
|
tomwalters@0
|
256 for (channel=0; channel<MAX_CHANNELS; channel++) {
|
tomwalters@0
|
257 for(sample=0; sample<MAX_DATA; sample++)
|
tomwalters@0
|
258 interval[channel][sample] = 0;
|
tomwalters@0
|
259 clip[channel]=OFF;
|
tomwalters@0
|
260 }
|
tomwalters@0
|
261
|
tomwalters@0
|
262
|
tomwalters@0
|
263 /* reset this, so everything still works */
|
tomwalters@0
|
264 framewidth_samples = framewidth_samples_input;
|
tomwalters@0
|
265
|
tomwalters@0
|
266
|
tomwalters@0
|
267 for (frame=1; frame<=no_frames; frame++) {
|
tomwalters@0
|
268
|
tomwalters@0
|
269 if (verboseflag == ON) {
|
tomwalters@0
|
270 fprintf(stderr, " %i ", frame);
|
tomwalters@0
|
271 fflush(stderr);}
|
tomwalters@0
|
272
|
tomwalters@0
|
273 /*--------------------------------------------*/
|
tomwalters@0
|
274
|
tomwalters@0
|
275 /* load the whole frame's worth of data first */
|
tomwalters@0
|
276
|
tomwalters@0
|
277 for (channel=1; channel <=frameheight; channel ++) {
|
tomwalters@0
|
278
|
tomwalters@0
|
279 /* clear arrays */
|
tomwalters@0
|
280 for(sample=0; sample<framewidth_samples; sample++)
|
tomwalters@0
|
281 inputdata[sample] = outputdata[sample] = 0;
|
tomwalters@0
|
282 for(n=0; n < MAX_PEAKS; n++){
|
tomwalters@0
|
283 peak[n].tent = UNSET;
|
tomwalters@0
|
284 peak[n].sample=0;}
|
tomwalters@0
|
285
|
tomwalters@0
|
286 /* Nextevents are unnecessary */
|
tomwalters@0
|
287
|
tomwalters@0
|
288 /* load a single channel's worth of 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: if any numbers < 0, then say so */
|
tomwalters@0
|
292 for(sample=0; sample<framewidth_samples; sample++)
|
tomwalters@0
|
293 if (inputdata[sample] < 0 ) {
|
tomwalters@0
|
294 fprintf(stderr, "%s: something's gone wrong: the data is negative.\n", progname);
|
tomwalters@0
|
295 exit(-1); }
|
tomwalters@0
|
296
|
tomwalters@0
|
297 /* find peaks. WARNING: in reverse */
|
tomwalters@0
|
298 total_peaks = findpeaksreverse();
|
tomwalters@0
|
299
|
tomwalters@0
|
300 /* bin any small peaks ... */
|
tomwalters@0
|
301 if ((removeflag == ON) && (total_peaks !=0 ) ) {
|
tomwalters@0
|
302 total_peaks_2 = removepeaks(total_peaks);
|
tomwalters@0
|
303 for(n=0; n < MAX_PEAKS; n++) {
|
tomwalters@0
|
304 peak[n].tent = UNSET;
|
tomwalters@0
|
305 peak[n].sample = 0;}
|
tomwalters@0
|
306 total_peaks = findpeaksreverse();}
|
tomwalters@0
|
307
|
tomwalters@0
|
308 /* get intervals */
|
tomwalters@0
|
309 find_intervals(total_peaks, channel, framewidth_samples_output);
|
tomwalters@0
|
310
|
tomwalters@0
|
311 } /* channel */
|
tomwalters@0
|
312
|
tomwalters@0
|
313 } /* frame */
|
tomwalters@0
|
314
|
tomwalters@0
|
315
|
tomwalters@0
|
316 /*------------------------------------------*/
|
tomwalters@0
|
317 /*------------------------------------------*/
|
tomwalters@0
|
318
|
tomwalters@0
|
319
|
tomwalters@0
|
320 fflush(stdout);
|
tomwalters@0
|
321
|
tomwalters@0
|
322
|
tomwalters@0
|
323 /* If required, sum the values */
|
tomwalters@0
|
324 if (summationflag==ON) {
|
tomwalters@0
|
325
|
tomwalters@0
|
326 for (channel = 1; channel <= frameheight; channel ++)
|
tomwalters@0
|
327 summation[channel] = 0;
|
tomwalters@0
|
328
|
tomwalters@0
|
329 for (channel = 1; channel <= frameheight; channel ++) {
|
tomwalters@0
|
330 clipflag = OFF;
|
tomwalters@0
|
331 for (sample = 0; sample < framewidth_samples_output; sample++)
|
tomwalters@0
|
332 summation[channel] += interval[channel][sample];
|
tomwalters@0
|
333
|
tomwalters@0
|
334 /* clip check */
|
tomwalters@0
|
335 if ((summation[channel] > 32765) ||
|
tomwalters@0
|
336 (summation[channel] < 0)){
|
tomwalters@0
|
337 if (clipflag == OFF) {
|
tomwalters@0
|
338 fprintf(stderr, " \nclipping: channel %i, summations.\n ", channel);
|
tomwalters@0
|
339 clipflag = ON;}
|
tomwalters@0
|
340 summation[channel] = 32765;
|
tomwalters@0
|
341 }
|
tomwalters@0
|
342 }
|
tomwalters@0
|
343 }
|
tomwalters@0
|
344
|
tomwalters@0
|
345 /*-------------------------------------------*/
|
tomwalters@0
|
346
|
tomwalters@0
|
347 /* write output */
|
tomwalters@0
|
348
|
tomwalters@0
|
349 if (asciiflag == OFF) {
|
tomwalters@0
|
350 for (channel = 1; channel <= frameheight; channel ++){
|
tomwalters@0
|
351 for (sample = 0; sample < framewidth_samples_output; sample++)
|
tomwalters@0
|
352 outputfiguredata[sample] = interval[channel][sample];
|
tomwalters@0
|
353 writedata_output(outputfigurefp, framewidth_samples_output);
|
tomwalters@0
|
354 }
|
tomwalters@0
|
355 }
|
tomwalters@0
|
356 else {
|
tomwalters@0
|
357 if (asciireverseflag == OFF)
|
tomwalters@0
|
358 write_matrix_hori_freq(framewidth_samples_output, outputfigurefp);
|
tomwalters@0
|
359 else
|
tomwalters@0
|
360 write_matrix_hori_time(framewidth_samples_output, outputfigurefp);
|
tomwalters@0
|
361 }
|
tomwalters@0
|
362
|
tomwalters@0
|
363 /*-------------------------------------------*/
|
tomwalters@0
|
364
|
tomwalters@0
|
365 /* Tidy up and exit */
|
tomwalters@0
|
366
|
tomwalters@0
|
367 if (verboseflag == ON)
|
tomwalters@0
|
368 fprintf(stderr, "\n");
|
tomwalters@0
|
369 fclose(inputfp);
|
tomwalters@0
|
370 fclose(outputfigurefp);
|
tomwalters@0
|
371
|
tomwalters@0
|
372 if ( ferror(inputfp) != 0) {
|
tomwalters@0
|
373 fprintf(stderr, " %s : error closing input file.\n", progname);
|
tomwalters@0
|
374 exit(-1);}
|
tomwalters@0
|
375
|
tomwalters@0
|
376 if ( ferror(outputfigurefp) != 0) {
|
tomwalters@0
|
377 fprintf(stderr, " %s : error closing figure file.\n", progname);
|
tomwalters@0
|
378 exit(-1);}
|
tomwalters@0
|
379
|
tomwalters@0
|
380 exit(0);
|
tomwalters@0
|
381
|
tomwalters@0
|
382 } /* Main */
|
tomwalters@0
|
383
|
tomwalters@0
|
384
|
tomwalters@0
|
385
|
tomwalters@0
|
386
|
tomwalters@0
|
387
|
tomwalters@0
|
388
|
tomwalters@0
|
389 /*---------------------------------------------------------------------------*/
|
tomwalters@0
|
390 /*---------------------------------------------------------------------------*/
|
tomwalters@0
|
391
|
tomwalters@0
|
392
|
tomwalters@0
|
393
|
tomwalters@0
|
394
|
tomwalters@0
|
395
|
tomwalters@0
|
396 void parsecommandline(int argc, char *argv[], char inputfn[], char outputbasefn[])
|
tomwalters@0
|
397 {
|
tomwalters@0
|
398 int x=1, helpflag = OFF;
|
tomwalters@0
|
399
|
tomwalters@0
|
400 while (x < argc){
|
tomwalters@0
|
401 if (!strcmp(argv[x], "-o")) {strcpy(outputbasefn, argv[x+1]); x+=2;}
|
tomwalters@0
|
402 else if (!strcmp(argv[x], "-output")) {strcpy(outputbasefn, argv[x+1]); x+=2;}
|
tomwalters@0
|
403 else if (!strcmp(argv[x], "-i")) {strcpy(inputfn, argv[x+1]); x+=2;}
|
tomwalters@0
|
404 else if (!strcmp(argv[x], "-input")) {strcpy(inputfn, argv[x+1]); x+=2;}
|
tomwalters@0
|
405 else if (!strcmp(argv[x], "-help")) {helpflag = ON; x+=1;}
|
tomwalters@0
|
406 else if (!strcmp(argv[x], "-h")) {helpflag = ON; x+=1;}
|
tomwalters@0
|
407 else if (!strcmp(argv[x], "-verbose")) {verboseflag = ON; x+=1;}
|
tomwalters@0
|
408 else if (!strcmp(argv[x], "-v")) {verboseflag = ON; x+=1;}
|
tomwalters@0
|
409 else if (!strcmp(argv[x], "-weight")) {weightflag = NORMAL_WEIGHTING; x+=1;}
|
tomwalters@0
|
410 else if (!strcmp(argv[x], "-weightlog")) {weightflag = LOG_WEIGHTING; x+=1;}
|
tomwalters@0
|
411 else if (!strcmp(argv[x], "-width")) {widthflag = ON; total_width=atoi(argv[x+1]); x+=2;}
|
tomwalters@0
|
412 else if (!strcmp(argv[x], "-r")) { removeflag = ON; removevalue = atof(argv[x+1]); x+=2;}
|
tomwalters@0
|
413 else if (!strcmp(argv[x], "-a")) { asciiflag = ON;x+=1;}
|
tomwalters@0
|
414 else if (!strcmp(argv[x], "-ar")) { asciiflag = ON; asciireverseflag=ON; x+=1;}
|
tomwalters@0
|
415 else if (!strcmp(argv[x], "-s")) { summationflag=ON; x+=1;}
|
tomwalters@0
|
416 else if (!strcmp(argv[x], "-g")) { greyscaleflag=ON; x+=1;}
|
tomwalters@0
|
417 else if (!strcmp(argv[x], "-grey")) { greyscaleflag=ON; x+=1;}
|
tomwalters@0
|
418 else if (!strcmp(argv[x], "-gray")) { greyscaleflag=ON; x+=1;}
|
tomwalters@0
|
419 else if (!strcmp(argv[x], "-oparch")) { oppositearchflag=ON; x+=1;}
|
tomwalters@0
|
420 else {fprintf(stderr, "%s: unknown option %s\n", progname, argv[x]);
|
tomwalters@0
|
421 exit(-1);}
|
tomwalters@0
|
422 }
|
tomwalters@0
|
423
|
tomwalters@0
|
424 if (helpflag == ON)
|
tomwalters@0
|
425 {
|
tomwalters@0
|
426 fprintf(stderr, "\n");
|
tomwalters@0
|
427 fprintf(stderr, " %s\n", progname);
|
tomwalters@0
|
428 fprintf(stderr, " -----------------------------------------------------------------------------\n");
|
tomwalters@0
|
429 fprintf(stderr, " Works out a histogram of peak intervals, from a .sai\n");
|
tomwalters@0
|
430 fprintf(stderr, " Default output is a .sai file: if -a or -ar specified,\n");
|
tomwalters@0
|
431
|
tomwalters@0
|
432 fprintf(stderr, " then output is a ASCII matrix.\n");
|
tomwalters@0
|
433 fprintf(stderr, "\n");
|
tomwalters@0
|
434 fprintf(stderr, " The -oparch option is REQUIRED if reading a Sun .sai files \n");
|
tomwalters@0
|
435 fprintf(stderr, " on a DEC cpu or vice-versa.\n");
|
tomwalters@0
|
436 fprintf(stderr, " Add .sai to both input and output filenames.\n");
|
tomwalters@0
|
437
|
tomwalters@0
|
438 fprintf(stderr, " -----------------------------------------------------------------------------\n");
|
tomwalters@0
|
439 fprintf(stderr, "\n");
|
tomwalters@0
|
440 fprintf(stderr, " -i <.sai file> input file default = stdin\n");
|
tomwalters@0
|
441 fprintf(stderr, " -o <.sai file> output file default = stdout\n");
|
tomwalters@0
|
442 fprintf(stderr, " -oparch assume input was generated on an opposing architecture\n");
|
tomwalters@0
|
443 fprintf(stderr, "\n");
|
tomwalters@0
|
444 fprintf(stderr, " -a ASCII output: rows = channels\n");
|
tomwalters@0
|
445 fprintf(stderr, " -ar ASCII output: rows = time intervals\n");
|
tomwalters@0
|
446 fprintf(stderr, " -s include summations over time intervals (ASCII options only)\n");
|
tomwalters@0
|
447 fprintf(stderr, "\n");
|
tomwalters@0
|
448 fprintf(stderr, " -width <int> width of graph.sai (msecs).\n");
|
tomwalters@0
|
449 fprintf(stderr, " -r <fraction> remove any peaks F(n) < F(n+1) & F(n-1) * fract \n");
|
tomwalters@0
|
450 fprintf(stderr, " default = %.3f\n", removevalue);
|
tomwalters@0
|
451 fprintf(stderr, " -weight weight histogram entries by mean height of peaks\n");
|
tomwalters@0
|
452 fprintf(stderr, " -weightlog as per -weight, but use 10log(mean height)\n");
|
tomwalters@0
|
453 fprintf(stderr, "\n");
|
tomwalters@0
|
454 fprintf(stderr, " -v verbose output (to stderr)\n");
|
tomwalters@0
|
455 fprintf(stderr, " -g change .sai 'view' format to 'grayscale'.\n");
|
tomwalters@0
|
456 fprintf(stderr, "\n\n");
|
tomwalters@0
|
457 exit(-1);}
|
tomwalters@0
|
458
|
tomwalters@0
|
459 }
|
tomwalters@0
|
460
|
tomwalters@0
|
461
|
tomwalters@0
|
462
|
tomwalters@0
|
463
|
tomwalters@0
|
464 /* The End */
|
tomwalters@0
|
465 /*---------------------------------------------------------------------------*/
|