view saitools/matrix.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 source
/*
    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.
*/

/*-------------------------------------------------------------------------*/

/*  matrix.c
*  ----------
*
* Writes an interal histogram matrix in two pretty (ascii) formats.
*
* M. Akeroyd.  Summer 1993. Revised Winter 1994.
*/


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "tip.h"

extern char progname[MAX_STRING_LENGTH];
extern int verboseflag;
extern short interval[MAX_CHANNELS][MAX_DATA];      
extern short summation[MAX_CHANNELS];
extern int summationflag;

extern int frameheight;



/*-------------------------------------------------------------------------*/



void write_matrix_hori_freq(int framewidth, FILE *outputfigurefp)
{
  /* Format of matrix:
   *
# (Info on file, inclduing name, pwdith, nwidth, mincf etc goes here)
# Rows = channels. Columns = intervals (samples)
# 
#                               Time Interval (samples)
#                 0  1  2  3  4  5  6  7  8  9   ..... (framewidth-1)
# .......................................................................
 c  frameheight
 h    ...
 a    ...
 n    ...
 n     4
 e     3
 l     2
 s     1
 
# ......................................................................

   * ALL comment lines have '#' in them.
   *
   * The entries are raw numbers: at the moment, no normalisation has taken 
   * place. So the longer the .sai, the bigger the numbers.
   *
   * If the '-s' flag is set, then the row (=channel) sums are printed at 
   * the end of each ROW.
   *
   * This version prints "." instead of zeros.
   */


  int channel, sample;   

  /* rest of header ... */
  fprintf(outputfigurefp,"# Rows = channels  Columns = intervals (samples)\n");
  fprintf(outputfigurefp, "# \n");

  /* Top line */
  fprintf(outputfigurefp, "#    ");
  for (sample=0; sample<framewidth; sample++)
    fprintf(outputfigurefp, "%5i ", sample);
  if (summationflag == ON)
    fprintf(outputfigurefp, " :   Sum");
  fprintf(outputfigurefp, "\n");

  
  /* top tabulation line */
    fprintf(outputfigurefp, "#    ");
  for (sample=0; sample<framewidth; sample++)
    fprintf(outputfigurefp, "......");
  if (summationflag == ON)
    fprintf(outputfigurefp, "........");
  fprintf(outputfigurefp, "\n");
  
  /* Main body: NOTE REVERSE ... */
  for (channel=frameheight; channel >=1; channel --) {
    fprintf(outputfigurefp, " %2i: ", channel);
    for (sample = 0; sample < framewidth; sample++){
      if (interval[channel][sample] == 0) 
	fprintf(outputfigurefp, "    . ");
      else 
	fprintf(outputfigurefp, "%5i ", interval[channel][sample]);
    }

    if (summationflag == ON)
      fprintf(outputfigurefp, " : %5i", summation[channel]);

    fprintf(outputfigurefp, "\n");
  }
  
  /* bottom tabulation line */
  fprintf(outputfigurefp, "#    ");
  for (sample=0; sample<framewidth; sample++)
    fprintf(outputfigurefp, "......");
  if (summationflag == ON)
    fprintf(outputfigurefp, "........");
  fprintf(outputfigurefp, "\n");

}




/*-------------------------------------------------------------------------*/




void write_matrix_hori_time(int framewidth, FILE *outputfigurefp)
{
  int channel, sample;

  /* Format of matrix:
   *
# (Info on file, inclduing name, pwdith, nwidth, mincf etc goes here)
# Rows = intervals. Columns = channels
#
#                               Channels   
#                     1  2  3  4  5  6  7  8  ... .... (frameheight)
# ..................................................................
 T 
 i      0
 m  (   1
 e  s   2
    a   3
 I  m  
 n  p  ...
 t  l 
 e  e  ... 
 r  s
 v  )  ...
 a      
 l   (framewidth-1)
# .................................................................

   * ALL comment lines have '#' in them.
   *
   * The entries are raw numbers: at the moment, no normalisation has taken 
   * place. So the longer the .sai, the bigger the numbers.
   *
   * If the '-s' flag is set, then the row (=channel) sums are printed at 
   * the end of each ROW.
   *
   * This version prints "." instead of zeros.
   */


  /* rest of Header ... */
  fprintf(outputfigurefp, "# Rows = intervals (samples) Columns = channels\n");
  fprintf(outputfigurefp, "# \n");
   

  /* Top line */
  fprintf(outputfigurefp, "#     ");
  for (channel=1; channel<=frameheight; channel++)
    fprintf(outputfigurefp, "%5i ", channel);
  fprintf(outputfigurefp, "\n");
  
  /* top tabulation line */
  fprintf(outputfigurefp, "#    ");
  for (channel=1; channel<=frameheight; channel++)
    fprintf(outputfigurefp, "......");
  fprintf(outputfigurefp, "\n");
  
  /* Main body: NOTE forward ... */
  for (sample = 0; sample < framewidth; sample++) {
    fprintf(outputfigurefp, " %4i: ", sample);
    for (channel=1; channel<=frameheight; channel++)
      if (interval[channel][sample] == 0) 
	fprintf(outputfigurefp, "    . ");
      else 
	fprintf(outputfigurefp, "%5i ", interval[channel][sample]);
    fprintf(outputfigurefp, "\n");
  }
  
  /* bottom tabulation line */
  fprintf(outputfigurefp, "#    ");
  for (channel=1; channel<=frameheight; channel++)
    fprintf(outputfigurefp, "......");
  fprintf(outputfigurefp, "\n");

  if (summationflag == ON) {
    fprintf(outputfigurefp, "#\n");
    fprintf(outputfigurefp, "# Sum: ");
    for (channel=1; channel<=frameheight; channel++)
      fprintf(outputfigurefp, "%5i ", summation[channel]);
    fprintf(outputfigurefp, "\n");    
  }
}    




/* The End */
/*-------------------------------------------------------------------------*/