diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/saitools/saiinfo.c	Fri May 20 15:19:45 2011 +0100
@@ -0,0 +1,232 @@
+/*
+    Copyright (c) Applied Psychology Unit, Medical Research Council. 1993
+    ===========================================================================
+
+    Permission to use, copy, modify, and distribute this software without fee 
+    is hereby granted for research purposes, provided that this copyright 
+    notice appears in all copies and in all supporting documentation, and that 
+    the software is not redistributed for any fee (except for a nominal 
+    shipping charge). Anyone wanting to incorporate all or part of this 
+    software in a commercial product must obtain a license from the Medical 
+    Research Council.
+
+    The MRC makes no representations about the suitability of this 
+    software for any purpose.  It is provided "as is" without express or 
+    implied warranty.
+ 
+    THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 
+    ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 
+    THE A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES 
+    OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 
+    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 
+    ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 
+    SOFTWARE.
+*/
+/*  saiinfo.c
+*  --------------
+*  
+* Outputs some useful info from the header of a .sai file
+* Copied from trmaxpeaks.
+* No output
+*
+*
+* M. Akeroyd.   May 1993.  2.00   Revised Winter 1994.
+*
+*
+*/
+
+
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+
+#include "tip.h"
+
+
+/* Function declarations */
+/*---------------------------------------------------------------------------*/
+
+void parsecommandline(int argc, char *argv[], char inputfn[], char outputfn[]);
+
+int readheader(FILE *inputfp);
+void checkheader();
+void writeheader(FILE *outputfp);
+
+void writedata_output (FILE *outputfp, int samples_to_write);
+void writedata_output_fg (FILE *figurefp, FILE *groundfp, int samples_to_write);
+FILE *open_file (char filefn[], FILE *dir_default, int streamtype);
+
+
+/* Data arrays: global */
+/*---------------------------------------------------------------------------*/
+
+short outputdata[MAX_DATA];                 /* output */
+short outputfiguredata[MAX_DATA];                 /* output figure.sai: a single channel */
+short outputgrounddata[MAX_DATA];                 /* output ground.sai: a single channel */
+
+
+
+/* variables read from header */
+/*---------------------------------------------------------------------------*/
+
+
+char progname[MAX_STRING_LENGTH];
+char header[MAX_LINES_HEADER][MAX_LINE_LENGTH];
+int header_lines;
+
+/* .sai parameters */
+
+int no_frames;
+int frameheight;             /* number of channels */
+int framewidth_samples;      /* pwidth + nwidth * samplerate */
+int frameshift_samples;      /* frstep_aid * samplerate */
+int pwidth;                  /* in msecs */
+int nwidth;                  /* in msecs: NEGATIVE */
+int width_win;               /* pixels */
+int height_win;              /* pixels */
+long samplerate;            /* samples per sec */
+int mincf;                   /* Hz */
+int maxcf;                   /* Hz */
+
+int oppositearchflag = OFF;          /* -oparch : see saigraph.c for info */
+int verboseflag = OFF;
+
+
+/*........           Main    ........................................*/
+/* ..................................................................*/
+/* ..................................................................*/
+
+
+
+
+void main (int argc, char *argv[])
+{
+
+  int sample;
+  int n;
+
+  int frame, channel;
+  int header_bytes = 0;
+
+  char inputfn[MAX_STRING_LENGTH],
+       outputbasefn[MAX_STRING_LENGTH];
+
+  FILE *inputfp;
+
+
+
+  strcpy(progname, argv[0]);
+  strcpy(outputbasefn, "");
+  strcpy(inputfn, "");
+
+  /* parse command line */
+  parsecommandline(argc, argv, inputfn, outputbasefn);
+
+
+  /* open input files 
+   * default: stdin
+   */
+  inputfp = open_file(inputfn, stdin, READ);
+
+  /* read Header */
+  header_bytes = readheader(inputfp);
+
+  /* do some error-checking on the header, and set the fread pointer to the 
+     right place */
+  checkheader();
+
+
+  /* print important bits */
+
+  fprintf(stdout, "\n");
+  fprintf(stdout, " header_lines  ...  : %5i     header_bytes   ... : %5i\n", header_lines, header_bytes);
+  fprintf(stdout, "\n");
+  fprintf(stdout, " frames   ...  ...  : %5i     channels  ...  ... : %5i\n", no_frames, frameheight);
+  fprintf(stdout, " framewidth_samples : %5i     frameshift_samples : %5i\n", framewidth_samples, frameshift_samples);
+  fprintf(stdout, " pwidth   ...  ...  : %5i     nwidth    ...  ... : %5i\n", pwidth, nwidth);
+  fprintf(stdout, " mincf    ...  ...  : %5i     maxcf     ...  ... : %5i\n", mincf, maxcf);
+  fprintf(stdout, "\n");
+  fprintf(stdout, " window width  ...  : %5i     window height  ... : %5i\n", width_win, height_win);
+  fprintf(stdout, " sampling rate  ..  : %i\n", samplerate);
+  fprintf(stdout, "\n");
+
+      
+
+  /* Tidy up and exit */
+  
+  fclose(inputfp); 
+  
+  if ( ferror(inputfp) != 0) {
+    fprintf(stderr, " %s : error closing input file.\n", progname);
+    exit(-1);}
+
+  exit(0);
+
+} /* Main */
+
+
+
+
+/*  ....................................................................*/
+/*  ....................................................................*/
+/*  ....................................................................*/
+/*  ....................................................................*/
+
+
+
+
+
+
+
+void parsecommandline(int argc, char *argv[], char inputfn[], char outputfn[])
+{
+  int x=1, helpflag = OFF;
+
+
+  while (x < argc){
+    if      (!strcmp(argv[x], "-i")) {strcpy(inputfn, argv[x+1]); x+=2;}
+    else if (!strcmp(argv[x], "-input")) {strcpy(inputfn, argv[x+1]); x+=2;}
+    else if (!strcmp(argv[x], "-help")) {helpflag = ON; x+=1;}
+    else if (!strcmp(argv[x], "-h")) {helpflag = ON; x+=1;}
+    else if (!strcmp(argv[x], "-oparch")) {oppositearchflag = ON; x+=1;}
+    /* this next is special ... */
+    else if (argc==2) { strcpy(inputfn, argv[2-1]);x=argc;}
+         else {fprintf(stderr, "%s: unknown option %s\n", progname, argv[x]);
+	       exit(-1);}
+  }
+  
+  if (helpflag == ON)
+    {
+      fprintf(stderr, "\n");
+      fprintf(stderr, "                         %s\n", progname);
+      fprintf(stderr, " -----------------------------------------------------------\n");
+      fprintf(stderr, " prints some useful information from the header of a .sai file \n");
+      fprintf(stderr, "\n");
+      fprintf(stderr, " The -oparch option is REQUIRED if reading a Sun .sai files \n");
+      fprintf(stderr, " on a DEC cpu or vice-versa.\n");
+      fprintf(stderr, " Add .sai to both input and output filenames.\n");
+
+      fprintf(stderr, " -----------------------------------------------------------\n");
+      fprintf(stderr, " -i <.sai file>      input file             default = stdin\n");
+      fprintf(stderr, " -oparch          assume input was generated on an opposing architecture cpu\n");
+      fprintf(stderr, "\n");
+      exit(-1);}
+}  
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+