comparison saitools/saiinfo.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
comparison
equal deleted inserted replaced
-1:000000000000 0:5242703e91d3
1 /*
2 Copyright (c) Applied Psychology Unit, Medical Research Council. 1993
3 ===========================================================================
4
5 Permission to use, copy, modify, and distribute this software without fee
6 is hereby granted for research purposes, provided that this copyright
7 notice appears in all copies and in all supporting documentation, and that
8 the software is not redistributed for any fee (except for a nominal
9 shipping charge). Anyone wanting to incorporate all or part of this
10 software in a commercial product must obtain a license from the Medical
11 Research Council.
12
13 The MRC makes no representations about the suitability of this
14 software for any purpose. It is provided "as is" without express or
15 implied warranty.
16
17 THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
18 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
19 THE A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
20 OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
21 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
22 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
23 SOFTWARE.
24 */
25 /* saiinfo.c
26 * --------------
27 *
28 * Outputs some useful info from the header of a .sai file
29 * Copied from trmaxpeaks.
30 * No output
31 *
32 *
33 * M. Akeroyd. May 1993. 2.00 Revised Winter 1994.
34 *
35 *
36 */
37
38
39 #include <stdio.h>
40 #include <string.h>
41 #include <math.h>
42
43 #include "tip.h"
44
45
46 /* Function declarations */
47 /*---------------------------------------------------------------------------*/
48
49 void parsecommandline(int argc, char *argv[], char inputfn[], char outputfn[]);
50
51 int readheader(FILE *inputfp);
52 void checkheader();
53 void writeheader(FILE *outputfp);
54
55 void writedata_output (FILE *outputfp, int samples_to_write);
56 void writedata_output_fg (FILE *figurefp, FILE *groundfp, int samples_to_write);
57 FILE *open_file (char filefn[], FILE *dir_default, int streamtype);
58
59
60 /* Data arrays: global */
61 /*---------------------------------------------------------------------------*/
62
63 short outputdata[MAX_DATA]; /* output */
64 short outputfiguredata[MAX_DATA]; /* output figure.sai: a single channel */
65 short outputgrounddata[MAX_DATA]; /* output ground.sai: a single channel */
66
67
68
69 /* variables read from header */
70 /*---------------------------------------------------------------------------*/
71
72
73 char progname[MAX_STRING_LENGTH];
74 char header[MAX_LINES_HEADER][MAX_LINE_LENGTH];
75 int header_lines;
76
77 /* .sai parameters */
78
79 int no_frames;
80 int frameheight; /* number of channels */
81 int framewidth_samples; /* pwidth + nwidth * samplerate */
82 int frameshift_samples; /* frstep_aid * samplerate */
83 int pwidth; /* in msecs */
84 int nwidth; /* in msecs: NEGATIVE */
85 int width_win; /* pixels */
86 int height_win; /* pixels */
87 long samplerate; /* samples per sec */
88 int mincf; /* Hz */
89 int maxcf; /* Hz */
90
91 int oppositearchflag = OFF; /* -oparch : see saigraph.c for info */
92 int verboseflag = OFF;
93
94
95 /*........ Main ........................................*/
96 /* ..................................................................*/
97 /* ..................................................................*/
98
99
100
101
102 void main (int argc, char *argv[])
103 {
104
105 int sample;
106 int n;
107
108 int frame, channel;
109 int header_bytes = 0;
110
111 char inputfn[MAX_STRING_LENGTH],
112 outputbasefn[MAX_STRING_LENGTH];
113
114 FILE *inputfp;
115
116
117
118 strcpy(progname, argv[0]);
119 strcpy(outputbasefn, "");
120 strcpy(inputfn, "");
121
122 /* parse command line */
123 parsecommandline(argc, argv, inputfn, outputbasefn);
124
125
126 /* open input files
127 * default: stdin
128 */
129 inputfp = open_file(inputfn, stdin, READ);
130
131 /* read Header */
132 header_bytes = readheader(inputfp);
133
134 /* do some error-checking on the header, and set the fread pointer to the
135 right place */
136 checkheader();
137
138
139 /* print important bits */
140
141 fprintf(stdout, "\n");
142 fprintf(stdout, " header_lines ... : %5i header_bytes ... : %5i\n", header_lines, header_bytes);
143 fprintf(stdout, "\n");
144 fprintf(stdout, " frames ... ... : %5i channels ... ... : %5i\n", no_frames, frameheight);
145 fprintf(stdout, " framewidth_samples : %5i frameshift_samples : %5i\n", framewidth_samples, frameshift_samples);
146 fprintf(stdout, " pwidth ... ... : %5i nwidth ... ... : %5i\n", pwidth, nwidth);
147 fprintf(stdout, " mincf ... ... : %5i maxcf ... ... : %5i\n", mincf, maxcf);
148 fprintf(stdout, "\n");
149 fprintf(stdout, " window width ... : %5i window height ... : %5i\n", width_win, height_win);
150 fprintf(stdout, " sampling rate .. : %i\n", samplerate);
151 fprintf(stdout, "\n");
152
153
154
155 /* Tidy up and exit */
156
157 fclose(inputfp);
158
159 if ( ferror(inputfp) != 0) {
160 fprintf(stderr, " %s : error closing input file.\n", progname);
161 exit(-1);}
162
163 exit(0);
164
165 } /* Main */
166
167
168
169
170 /* ....................................................................*/
171 /* ....................................................................*/
172 /* ....................................................................*/
173 /* ....................................................................*/
174
175
176
177
178
179
180
181 void parsecommandline(int argc, char *argv[], char inputfn[], char outputfn[])
182 {
183 int x=1, helpflag = OFF;
184
185
186 while (x < argc){
187 if (!strcmp(argv[x], "-i")) {strcpy(inputfn, argv[x+1]); x+=2;}
188 else if (!strcmp(argv[x], "-input")) {strcpy(inputfn, argv[x+1]); x+=2;}
189 else if (!strcmp(argv[x], "-help")) {helpflag = ON; x+=1;}
190 else if (!strcmp(argv[x], "-h")) {helpflag = ON; x+=1;}
191 else if (!strcmp(argv[x], "-oparch")) {oppositearchflag = ON; x+=1;}
192 /* this next is special ... */
193 else if (argc==2) { strcpy(inputfn, argv[2-1]);x=argc;}
194 else {fprintf(stderr, "%s: unknown option %s\n", progname, argv[x]);
195 exit(-1);}
196 }
197
198 if (helpflag == ON)
199 {
200 fprintf(stderr, "\n");
201 fprintf(stderr, " %s\n", progname);
202 fprintf(stderr, " -----------------------------------------------------------\n");
203 fprintf(stderr, " prints some useful information from the header of a .sai file \n");
204 fprintf(stderr, "\n");
205 fprintf(stderr, " The -oparch option is REQUIRED if reading a Sun .sai files \n");
206 fprintf(stderr, " on a DEC cpu or vice-versa.\n");
207 fprintf(stderr, " Add .sai to both input and output filenames.\n");
208
209 fprintf(stderr, " -----------------------------------------------------------\n");
210 fprintf(stderr, " -i <.sai file> input file default = stdin\n");
211 fprintf(stderr, " -oparch assume input was generated on an opposing architecture cpu\n");
212 fprintf(stderr, "\n");
213 exit(-1);}
214 }
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232