annotate 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
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 /* saiinfo.c
tomwalters@0 26 * --------------
tomwalters@0 27 *
tomwalters@0 28 * Outputs some useful info from the header of a .sai file
tomwalters@0 29 * Copied from trmaxpeaks.
tomwalters@0 30 * No output
tomwalters@0 31 *
tomwalters@0 32 *
tomwalters@0 33 * M. Akeroyd. May 1993. 2.00 Revised Winter 1994.
tomwalters@0 34 *
tomwalters@0 35 *
tomwalters@0 36 */
tomwalters@0 37
tomwalters@0 38
tomwalters@0 39 #include <stdio.h>
tomwalters@0 40 #include <string.h>
tomwalters@0 41 #include <math.h>
tomwalters@0 42
tomwalters@0 43 #include "tip.h"
tomwalters@0 44
tomwalters@0 45
tomwalters@0 46 /* Function declarations */
tomwalters@0 47 /*---------------------------------------------------------------------------*/
tomwalters@0 48
tomwalters@0 49 void parsecommandline(int argc, char *argv[], char inputfn[], char outputfn[]);
tomwalters@0 50
tomwalters@0 51 int readheader(FILE *inputfp);
tomwalters@0 52 void checkheader();
tomwalters@0 53 void writeheader(FILE *outputfp);
tomwalters@0 54
tomwalters@0 55 void writedata_output (FILE *outputfp, int samples_to_write);
tomwalters@0 56 void writedata_output_fg (FILE *figurefp, FILE *groundfp, int samples_to_write);
tomwalters@0 57 FILE *open_file (char filefn[], FILE *dir_default, int streamtype);
tomwalters@0 58
tomwalters@0 59
tomwalters@0 60 /* Data arrays: global */
tomwalters@0 61 /*---------------------------------------------------------------------------*/
tomwalters@0 62
tomwalters@0 63 short outputdata[MAX_DATA]; /* output */
tomwalters@0 64 short outputfiguredata[MAX_DATA]; /* output figure.sai: a single channel */
tomwalters@0 65 short outputgrounddata[MAX_DATA]; /* output ground.sai: a single channel */
tomwalters@0 66
tomwalters@0 67
tomwalters@0 68
tomwalters@0 69 /* variables read from header */
tomwalters@0 70 /*---------------------------------------------------------------------------*/
tomwalters@0 71
tomwalters@0 72
tomwalters@0 73 char progname[MAX_STRING_LENGTH];
tomwalters@0 74 char header[MAX_LINES_HEADER][MAX_LINE_LENGTH];
tomwalters@0 75 int header_lines;
tomwalters@0 76
tomwalters@0 77 /* .sai parameters */
tomwalters@0 78
tomwalters@0 79 int no_frames;
tomwalters@0 80 int frameheight; /* number of channels */
tomwalters@0 81 int framewidth_samples; /* pwidth + nwidth * samplerate */
tomwalters@0 82 int frameshift_samples; /* frstep_aid * samplerate */
tomwalters@0 83 int pwidth; /* in msecs */
tomwalters@0 84 int nwidth; /* in msecs: NEGATIVE */
tomwalters@0 85 int width_win; /* pixels */
tomwalters@0 86 int height_win; /* pixels */
tomwalters@0 87 long samplerate; /* samples per sec */
tomwalters@0 88 int mincf; /* Hz */
tomwalters@0 89 int maxcf; /* Hz */
tomwalters@0 90
tomwalters@0 91 int oppositearchflag = OFF; /* -oparch : see saigraph.c for info */
tomwalters@0 92 int verboseflag = OFF;
tomwalters@0 93
tomwalters@0 94
tomwalters@0 95 /*........ Main ........................................*/
tomwalters@0 96 /* ..................................................................*/
tomwalters@0 97 /* ..................................................................*/
tomwalters@0 98
tomwalters@0 99
tomwalters@0 100
tomwalters@0 101
tomwalters@0 102 void main (int argc, char *argv[])
tomwalters@0 103 {
tomwalters@0 104
tomwalters@0 105 int sample;
tomwalters@0 106 int n;
tomwalters@0 107
tomwalters@0 108 int frame, channel;
tomwalters@0 109 int header_bytes = 0;
tomwalters@0 110
tomwalters@0 111 char inputfn[MAX_STRING_LENGTH],
tomwalters@0 112 outputbasefn[MAX_STRING_LENGTH];
tomwalters@0 113
tomwalters@0 114 FILE *inputfp;
tomwalters@0 115
tomwalters@0 116
tomwalters@0 117
tomwalters@0 118 strcpy(progname, argv[0]);
tomwalters@0 119 strcpy(outputbasefn, "");
tomwalters@0 120 strcpy(inputfn, "");
tomwalters@0 121
tomwalters@0 122 /* parse command line */
tomwalters@0 123 parsecommandline(argc, argv, inputfn, outputbasefn);
tomwalters@0 124
tomwalters@0 125
tomwalters@0 126 /* open input files
tomwalters@0 127 * default: stdin
tomwalters@0 128 */
tomwalters@0 129 inputfp = open_file(inputfn, stdin, READ);
tomwalters@0 130
tomwalters@0 131 /* read Header */
tomwalters@0 132 header_bytes = readheader(inputfp);
tomwalters@0 133
tomwalters@0 134 /* do some error-checking on the header, and set the fread pointer to the
tomwalters@0 135 right place */
tomwalters@0 136 checkheader();
tomwalters@0 137
tomwalters@0 138
tomwalters@0 139 /* print important bits */
tomwalters@0 140
tomwalters@0 141 fprintf(stdout, "\n");
tomwalters@0 142 fprintf(stdout, " header_lines ... : %5i header_bytes ... : %5i\n", header_lines, header_bytes);
tomwalters@0 143 fprintf(stdout, "\n");
tomwalters@0 144 fprintf(stdout, " frames ... ... : %5i channels ... ... : %5i\n", no_frames, frameheight);
tomwalters@0 145 fprintf(stdout, " framewidth_samples : %5i frameshift_samples : %5i\n", framewidth_samples, frameshift_samples);
tomwalters@0 146 fprintf(stdout, " pwidth ... ... : %5i nwidth ... ... : %5i\n", pwidth, nwidth);
tomwalters@0 147 fprintf(stdout, " mincf ... ... : %5i maxcf ... ... : %5i\n", mincf, maxcf);
tomwalters@0 148 fprintf(stdout, "\n");
tomwalters@0 149 fprintf(stdout, " window width ... : %5i window height ... : %5i\n", width_win, height_win);
tomwalters@0 150 fprintf(stdout, " sampling rate .. : %i\n", samplerate);
tomwalters@0 151 fprintf(stdout, "\n");
tomwalters@0 152
tomwalters@0 153
tomwalters@0 154
tomwalters@0 155 /* Tidy up and exit */
tomwalters@0 156
tomwalters@0 157 fclose(inputfp);
tomwalters@0 158
tomwalters@0 159 if ( ferror(inputfp) != 0) {
tomwalters@0 160 fprintf(stderr, " %s : error closing input file.\n", progname);
tomwalters@0 161 exit(-1);}
tomwalters@0 162
tomwalters@0 163 exit(0);
tomwalters@0 164
tomwalters@0 165 } /* Main */
tomwalters@0 166
tomwalters@0 167
tomwalters@0 168
tomwalters@0 169
tomwalters@0 170 /* ....................................................................*/
tomwalters@0 171 /* ....................................................................*/
tomwalters@0 172 /* ....................................................................*/
tomwalters@0 173 /* ....................................................................*/
tomwalters@0 174
tomwalters@0 175
tomwalters@0 176
tomwalters@0 177
tomwalters@0 178
tomwalters@0 179
tomwalters@0 180
tomwalters@0 181 void parsecommandline(int argc, char *argv[], char inputfn[], char outputfn[])
tomwalters@0 182 {
tomwalters@0 183 int x=1, helpflag = OFF;
tomwalters@0 184
tomwalters@0 185
tomwalters@0 186 while (x < argc){
tomwalters@0 187 if (!strcmp(argv[x], "-i")) {strcpy(inputfn, argv[x+1]); x+=2;}
tomwalters@0 188 else if (!strcmp(argv[x], "-input")) {strcpy(inputfn, argv[x+1]); x+=2;}
tomwalters@0 189 else if (!strcmp(argv[x], "-help")) {helpflag = ON; x+=1;}
tomwalters@0 190 else if (!strcmp(argv[x], "-h")) {helpflag = ON; x+=1;}
tomwalters@0 191 else if (!strcmp(argv[x], "-oparch")) {oppositearchflag = ON; x+=1;}
tomwalters@0 192 /* this next is special ... */
tomwalters@0 193 else if (argc==2) { strcpy(inputfn, argv[2-1]);x=argc;}
tomwalters@0 194 else {fprintf(stderr, "%s: unknown option %s\n", progname, argv[x]);
tomwalters@0 195 exit(-1);}
tomwalters@0 196 }
tomwalters@0 197
tomwalters@0 198 if (helpflag == ON)
tomwalters@0 199 {
tomwalters@0 200 fprintf(stderr, "\n");
tomwalters@0 201 fprintf(stderr, " %s\n", progname);
tomwalters@0 202 fprintf(stderr, " -----------------------------------------------------------\n");
tomwalters@0 203 fprintf(stderr, " prints some useful information from the header of a .sai file \n");
tomwalters@0 204 fprintf(stderr, "\n");
tomwalters@0 205 fprintf(stderr, " The -oparch option is REQUIRED if reading a Sun .sai files \n");
tomwalters@0 206 fprintf(stderr, " on a DEC cpu or vice-versa.\n");
tomwalters@0 207 fprintf(stderr, " Add .sai to both input and output filenames.\n");
tomwalters@0 208
tomwalters@0 209 fprintf(stderr, " -----------------------------------------------------------\n");
tomwalters@0 210 fprintf(stderr, " -i <.sai file> input file default = stdin\n");
tomwalters@0 211 fprintf(stderr, " -oparch assume input was generated on an opposing architecture cpu\n");
tomwalters@0 212 fprintf(stderr, "\n");
tomwalters@0 213 exit(-1);}
tomwalters@0 214 }
tomwalters@0 215
tomwalters@0 216
tomwalters@0 217
tomwalters@0 218
tomwalters@0 219
tomwalters@0 220
tomwalters@0 221
tomwalters@0 222
tomwalters@0 223
tomwalters@0 224
tomwalters@0 225
tomwalters@0 226
tomwalters@0 227
tomwalters@0 228
tomwalters@0 229
tomwalters@0 230
tomwalters@0 231
tomwalters@0 232