annotate model/review.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. 1988, 1989
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 shipping
tomwalters@0 9 charge). Anyone wanting to incorporate all or part of this software in a
tomwalters@0 10 commercial product must obtain a license from the Medical Research Council.
tomwalters@0 11
tomwalters@0 12 The MRC makes no representations about the suitability of this
tomwalters@0 13 software for any purpose. It is provided "as is" without express or implied
tomwalters@0 14 warranty.
tomwalters@0 15
tomwalters@0 16 THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
tomwalters@0 17 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE
tomwalters@0 18 A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
tomwalters@0 19 DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
tomwalters@0 20 AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
tomwalters@0 21 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
tomwalters@0 22 */
tomwalters@0 23
tomwalters@0 24 /*
tomwalters@0 25 review.c
tomwalters@0 26 ========
tomwalters@0 27
tomwalters@0 28 formerly known as revsai.c - reviews .ctn screen dump files from disk.
tomwalters@0 29
tomwalters@0 30
tomwalters@0 31 Copyright (c), 1989 The Medical Research Council, Applied Psychology Unit.
tomwalters@0 32
tomwalters@0 33
tomwalters@0 34 Authors : Paul Manson and John Holdsworth.
tomwalters@0 35 Written : 11th March, 1989
tomwalters@0 36
tomwalters@0 37 Edited :
tomwalters@0 38
tomwalters@0 39 03 April 1989 (Paul Manson) -- A new star on the horizon! The all-singing, all-dancing
tomwalters@0 40 new revue emerges from the ashes of last week's version.
tomwalters@0 41
tomwalters@0 42 19 April 1989 (Paul Manson) -- Added the <input> option. Changed the name to revsai.
tomwalters@0 43
tomwalters@0 44 27 April 1989 (Paul Manson) -- The port to the DecStation (and by implication, the VAX)
tomwalters@0 45 has revealed several problems and bugs. All such known
tomwalters@0 46 bugs have been fixed. The <memory> option has been
tomwalters@0 47 introduced (for non-PCs only) to permit rapid reviewing
tomwalters@0 48 on X-windows servers. NOTE THAT THE SCREEN SIZE FOR NON
tomwalters@0 49 PC MACHINES HAS BEEN HARD_CODED! THIS SHOULD CHANGE!
tomwalters@0 50
tomwalters@0 51 05 May 1989 (Paul Manson) -- The above problem has been temporarily rectified by
tomwalters@0 52 using the default width and height options to indicate
tomwalters@0 53 the actual screen size. Also, the options format change
tomwalters@0 54 has been accounted for.
tomwalters@0 55
tomwalters@0 56 11 May 1989 (Paul Manson) -- Altered options to conform to the new(est) r'egime.
tomwalters@0 57
tomwalters@0 58 15 May 1989 (Paul Manson) -- Incorporated the PC-style wildcarding into the Unix version.
tomwalters@0 59 Made display use "NULL" instead of (char *) 0.
tomwalters@0 60
tomwalters@0 61 05 June 1989 (Paul Manson) -- Altered a couple of the option comments to reflect their
tomwalters@0 62 behaviour more accurately. I also encountered the rather
tomwalters@0 63 suspicious "bug" whereby revsai gets a segmentation fault
tomwalters@0 64 whenever it is run on an old "sai" file ... those generated
tomwalters@0 65 by sai now appear to be OK... If this really is a problem,
tomwalters@0 66 it should be tracked down!
tomwalters@0 67
tomwalters@0 68 06 July 1989 (Paul Manson) -- As well as altering revsai to accomodate all of the new
tomwalters@0 69 options names, I note that the abovementioned bug appears
tomwalters@0 70 to have disappeared without trace; hopefully it was just
tomwalters@0 71 due to previous (buggy) files, etc.
tomwalters@0 72
tomwalters@0 73 3 August 1993 (M. Akeroyd) -- Added declarations of "colourstr" and "planemaskstr".
tomwalters@0 74 They aren't used, but are in X.c (and thus libglib.a),
tomwalters@0 75 and are therfore required to fool the linker.
tomwalters@0 76
tomwalters@0 77 25 March 1994 (M. Akeroyd) -- Added colour. mono etc, so that 'review' would actually work.
tomwalters@0 78 (the previuos cahnge just made it compile.)
tomwalters@0 79 */
tomwalters@0 80
tomwalters@0 81 #include <string.h>
tomwalters@0 82 #include <stdio.h>
tomwalters@0 83 #include <math.h>
tomwalters@0 84
tomwalters@0 85 #if defined(THINK_C) || defined(NeXT)
tomwalters@0 86 #include <stdlib.h>
tomwalters@0 87 #else
tomwalters@0 88 #include <malloc.h>
tomwalters@0 89 #endif
tomwalters@0 90
tomwalters@0 91 #include "windows.h"
tomwalters@0 92 #include "options.h"
tomwalters@0 93
tomwalters@0 94
tomwalters@0 95 char *monostr, *colourstr, *planemaskstr; /* MAA 3-8-1993 */
tomwalters@0 96 char *fgcolourstr, *bgcolourstr; /* MAA 19-8-1993 */
tomwalters@0 97 #ifndef lint
tomwalters@0 98 static char *sccs_id = "@(#)review.c 1.13 Paul Manson, John Holdsworth (MRC-APU) 5/31/91";
tomwalters@0 99 #endif
tomwalters@0 100
tomwalters@0 101 #define max(A,B) (((A) > (B)) ? (A) : (B))
tomwalters@0 102 #define LENGTH_STR "remainder"
tomwalters@0 103 #define MAX_LENGTH (9999)
tomwalters@0 104
tomwalters@0 105 #define CENTER_STR "center"
tomwalters@0 106 #define IMAGE_SUFFIX ".ctn"
tomwalters@0 107
tomwalters@0 108 #ifdef PC
tomwalters@0 109 #define READ_BINARY "rb"
tomwalters@0 110 #else
tomwalters@0 111 #define READ_BINARY "r"
tomwalters@0 112 #endif
tomwalters@0 113
tomwalters@0 114 /* configurables */
tomwalters@0 115
tomwalters@0 116 static char *helpstr ;
tomwalters@0 117 static char *speed1str, *speed2str ;
tomwalters@0 118 static char *xstr, *ystr, *widthstr, *heightstr ;
tomwalters@0 119 static char *start1str, *stop1str, *step1str ;
tomwalters@0 120 static char *start2str, *stop2str, *step2str ;
tomwalters@0 121 static char *minstr , *maxstr , *framestr ;
tomwalters@0 122 static char *in1str, *in2str, *downstr ;
tomwalters@0 123
tomwalters@0 124 #if !defined( PC )
tomwalters@0 125 extern void exit();
tomwalters@0 126 static char *memorystr;
tomwalters@0 127 #endif
tomwalters@0 128
tomwalters@0 129 static Option res[] = {
tomwalters@0 130 { "help", "none", &helpstr, "<wave1> [<wave2>]\n\n\
tomwalters@0 131 Redisplays stored images from memory or directly from disk.\n\
tomwalters@0 132 Review responds to various simple commands, viz.\n\n\
tomwalters@0 133 1\t Activate only wave1 (default when only one wave named).\n\
tomwalters@0 134 2\t Activate only wave2.\n\
tomwalters@0 135 b or B\t Activate Both waves (default when two waves named).\n\n\
tomwalters@0 136 a or A\t Animate cartoon wave(s). Hitting space bar is equivalent.\n\
tomwalters@0 137 s or S\t Single-step activated wave(s). Hit space bar to step.\n\
tomwalters@0 138 +\t Animate activated wave(s) faster.\n\
tomwalters@0 139 -\t Animate activated wave(s) slower.\n\n\
tomwalters@0 140 q or Q\t Quit Revue.\n", SilentOption },
tomwalters@0 141 { "input1", NULL_OPTION, &in1str, "Default input file name 1", InputOption},
tomwalters@0 142 { "start1" , "0" , &start1str , "Start point in wave 1 (in ms)", InputOption},
tomwalters@0 143 { "length1", LENGTH_STR, &stop1str , "Length of wave 1 to display (in ms)", InputOption},
tomwalters@0 144 { "step1" , "1" , &step1str , "Display every step-th image of wave 1", InputOption},
tomwalters@0 145 { "speed1", "1" , &speed1str, "Image 1 display speed (1 is fastest)", InputOption},
tomwalters@0 146
tomwalters@0 147 { "input2", NULL_OPTION, &in2str, "Default input file name 2\n", InputOption},
tomwalters@0 148 { "start2" , "0" , &start2str , "Start point in wave 2 (in ms)", InputOption},
tomwalters@0 149 { "length2", LENGTH_STR, &stop2str , "Length of wave 2 to display (in ms)", InputOption},
tomwalters@0 150 { "step2" , "1" , &step2str , "Display every step-th image of wave 2", InputOption},
tomwalters@0 151 { "speed2", "1" , &speed2str, "Image 2 display speed (1 is fastest)", InputOption},
tomwalters@0 152
tomwalters@0 153 { "x0_win", CENTER_STR, &xstr, "Left edge of window (in pixels)" , SilentOption},
tomwalters@0 154 { "y0_win", CENTER_STR, &ystr, "Upper edge of window (in pixels)", SilentOption},
tomwalters@0 155 { "width_screen", "960", &widthstr, "Physical screen width in pixels", SilentOption},
tomwalters@0 156 { "height_screen","750", &heightstr, "Physical screen height in pixels", SilentOption},
tomwalters@0 157
tomwalters@0 158 /* MAA: 25 March 1994
tomwalters@0 159 * These next added because they are used from within X.c (although defined in gen.c), and thus the graphics
tomwalters@0 160 * calls. They are of NO meaning, however; they define how the Model makes the bitmaps.
tomwalters@0 161 * Once made, you cannot edit bitmaps ...
tomwalters@0 162 */
tomwalters@0 163 { "fg_col", "black", &fgcolourstr, "Foreground Colour.\n", SilentOption},
tomwalters@0 164 { "bg_col", "white", &bgcolourstr, "Background Colour.\n", SilentOption},
tomwalters@0 165 { "mono_ctn", ON_OPTION, &monostr, "Force monochrome (single plane) cartoons.", SilentOption},
tomwalters@0 166 { "colour_ctn", OFF_OPTION, &colourstr, "Force colour (multi-plane) cartoons.", SilentOption},
tomwalters@0 167 {"planemask_ctn", "1", &planemaskstr, "Planemask for creating cartoons.\n", SilentOption},
tomwalters@0 168 /* MAA: End of that bit */
tomwalters@0 169
tomwalters@0 170 #if !defined( PC )
tomwalters@0 171 { "memory", ON_OPTION, &memorystr, "Read images into memory for reviewing\n", InputOption},
tomwalters@0 172 #endif
tomwalters@0 173 ( char * ) 0 } ;
tomwalters@0 174
tomwalters@0 175 static Option hiddenRes[] = {
tomwalters@0 176 { "downsample", "20", &downstr, "Image file frame size (in ms)", InputOption},
tomwalters@0 177 { "frstep_aid", "20", &framestr, "Image file frame size (in ms)", InputOption},
tomwalters@0 178 { "mincf_afb", "220", &minstr , "Minimum Center Frequency in Hertz", InputOption},
tomwalters@0 179 { "maxcf_afb", "4400", &maxstr , "Maximum Center Frequency in Hertz", InputOption},
tomwalters@0 180 { "width_win", "900", &widthstr, "Window width (pixels)", InputOption},
tomwalters@0 181 { "height_win", "600", &heightstr, "Window height (pixels)", InputOption},
tomwalters@0 182 ( char * ) 0 } ;
tomwalters@0 183
tomwalters@0 184 #define ONE (1)
tomwalters@0 185 #define TWO (2)
tomwalters@0 186 #define BOTH (0)
tomwalters@0 187
tomwalters@0 188 #define FALSE (0)
tomwalters@0 189 #define TRUE (1)
tomwalters@0 190 #define OVERTHETOP (10000)
tomwalters@0 191 #define AXES_WIDTH (15)
tomwalters@0 192
tomwalters@0 193 static int msToImages(frame, ms)
tomwalters@0 194 double frame;
tomwalters@0 195 double ms ;
tomwalters@0 196 {
tomwalters@0 197 return (((int) (ms / frame)) + 1); /* Round Up */
tomwalters@0 198 }
tomwalters@0 199
tomwalters@0 200 /* File Name Suffix Conversion Parameters */
tomwalters@0 201
tomwalters@0 202 #define BACKSLASH_CHAR '\\'
tomwalters@0 203 #define SLASH_CHARACTER '/'
tomwalters@0 204 #define NULL_CHARACTER '\000'
tomwalters@0 205 #define DOT_CHARACTER '.'
tomwalters@0 206
tomwalters@0 207 /******************************************************************************************/
tomwalters@0 208 /* */
tomwalters@0 209 /* AlterSuffix(). Returns its argument fileName with a newSuffix appended in place of */
tomwalters@0 210 /* any previous suffix it may have had. It should be noted that this */
tomwalters@0 211 /* suffix must include any DOT it wishes to have appended to the name. */
tomwalters@0 212 /* */
tomwalters@0 213 /******************************************************************************************/
tomwalters@0 214
tomwalters@0 215 char *AlterSuffix(fileName, newSuffix)
tomwalters@0 216 char *fileName, *newSuffix;
tomwalters@0 217 {
tomwalters@0 218 char *temp, *temp2, *lastPart;
tomwalters@0 219 int i;
tomwalters@0 220
tomwalters@0 221 temp = malloc((unsigned) (strlen(fileName) + strlen(newSuffix) + 1));
tomwalters@0 222
tomwalters@0 223 temp = strcpy(temp, fileName);
tomwalters@0 224
tomwalters@0 225 #if defined( PC )
tomwalters@0 226 /* Change all backslashes to forward slashes */
tomwalters@0 227 for (i = 0; temp[i] != NULL_CHARACTER; i++)
tomwalters@0 228 if (temp[i] == BACKSLASH_CHAR)
tomwalters@0 229 temp[i] = SLASH_CHARACTER;
tomwalters@0 230 #endif
tomwalters@0 231
tomwalters@0 232 if ((lastPart = strrchr(temp, SLASH_CHARACTER)) == NULL)
tomwalters@0 233 lastPart = temp;
tomwalters@0 234 else
tomwalters@0 235 lastPart++; /* Skip over the actual "/" */
tomwalters@0 236
tomwalters@0 237 /* lastPart points to the tail name of the path */
tomwalters@0 238
tomwalters@0 239 if ((temp2 = strchr(lastPart, DOT_CHARACTER)) == NULL)
tomwalters@0 240 temp = strcat(temp, newSuffix);
tomwalters@0 241 else
tomwalters@0 242 temp2 = strcpy(temp2, newSuffix);
tomwalters@0 243
tomwalters@0 244 return (temp);
tomwalters@0 245 }
tomwalters@0 246
tomwalters@0 247 /* -----------------------------------------------------------------------------------
tomwalters@0 248
tomwalters@0 249 A Routine to extend revsai for in-memory animation. This copies every image from
tomwalters@0 250 <start> to <stop> by <step> into the images buffer for the window <w>. It then
tomwalters@0 251 expects contiguous animation of these images. The integer returned is the number
tomwalters@0 252 of images that were saved; subsequent image Recall() calls should refer to images
tomwalters@0 253 in the range [1 .. this returned value].
tomwalters@0 254
tomwalters@0 255 ----------------------------------------------------------------------------------- */
tomwalters@0 256
tomwalters@0 257 static int readIntoMemory(w, filePtr, start, stop, step)
tomwalters@0 258 WindowObject w;
tomwalters@0 259 FILE *filePtr ;
tomwalters@0 260 int start;
tomwalters@0 261 int stop;
tomwalters@0 262 int step;
tomwalters@0 263 {
tomwalters@0 264 int fileImage, memImage;
tomwalters@0 265
tomwalters@0 266 memImage = 0;
tomwalters@0 267
tomwalters@0 268 fileImage = start;
tomwalters@0 269
tomwalters@0 270 while (fileImage <= stop && Read(w, filePtr, fileImage)) {
tomwalters@0 271 Store(w);
tomwalters@0 272 fileImage += step;
tomwalters@0 273 memImage++;
tomwalters@0 274 }
tomwalters@0 275
tomwalters@0 276 return (memImage);
tomwalters@0 277 }
tomwalters@0 278
tomwalters@0 279 main( argc, argv )
tomwalters@0 280 int argc ;
tomwalters@0 281 char *argv[] ;
tomwalters@0 282 {
tomwalters@0 283 WindowObject w1, w2;
tomwalters@0 284 int screenWidth, screenHeight ;
tomwalters@0 285 int firstWidth , firstHeight ;
tomwalters@0 286 int secondWidth, secondHeight ;
tomwalters@0 287 int firstPixels, secondPixels ;
tomwalters@0 288 FILE *firstWave , *secondWave ;
tomwalters@0 289
tomwalters@0 290 int OneWave, TwoWaves, spareWidth,
tomwalters@0 291 spareHeight ;
tomwalters@0 292
tomwalters@0 293 int waveMode , image1 , image2;
tomwalters@0 294 int count1 , count2;
tomwalters@0 295 int stopFirst, stopSecond ;
tomwalters@0 296 int start1 , stop1 , step1 ;
tomwalters@0 297 int start2 , stop2 , step2 ;
tomwalters@0 298 int speed1 , speed2 ;
tomwalters@0 299
tomwalters@0 300 char command, *firstWaveName,
tomwalters@0 301 *secondWaveName,
tomwalters@0 302 *programName;
tomwalters@0 303
tomwalters@0 304 double mincf1, mincf2, maxcf1, maxcf2, frame1, frame2;
tomwalters@0 305 int inMemory, x, y;
tomwalters@0 306
tomwalters@0 307 programName = argv[0];
tomwalters@0 308
tomwalters@0 309 (void) getopts( res, &argc, &argv );
tomwalters@0 310
tomwalters@0 311 /* Extract any information from the opts which is NECESSARY for the
tomwalters@0 312 operation of revue */
tomwalters@0 313
tomwalters@0 314 screenWidth = atoi( widthstr );
tomwalters@0 315 screenHeight= atoi( heightstr);
tomwalters@0 316
tomwalters@0 317 #if defined( PC )
tomwalters@0 318 inMemory = FALSE;
tomwalters@0 319 #else
tomwalters@0 320 inMemory = isON( memorystr );
tomwalters@0 321 #endif
tomwalters@0 322
tomwalters@0 323 if (argc > 2 || (argc == 0 && isNULL(in1str))) {
tomwalters@0 324 (void) helpopts(res, programName);
tomwalters@0 325 exit(1);
tomwalters@0 326 }
tomwalters@0 327 else {
tomwalters@0 328 OneWave = ((argc == 0 && !isNULL(in1str)) ||
tomwalters@0 329 (argc == 1 && isNULL(in2str)));
tomwalters@0 330 TwoWaves = !OneWave;
tomwalters@0 331 }
tomwalters@0 332
tomwalters@0 333 if (argc == 0)
tomwalters@0 334 firstWaveName = AlterSuffix(in1str, IMAGE_SUFFIX) ;
tomwalters@0 335 else
tomwalters@0 336 firstWaveName = AlterSuffix(argv[0], IMAGE_SUFFIX);
tomwalters@0 337
tomwalters@0 338 if ((firstWave = fopen(firstWaveName, READ_BINARY )) == NULL) {
tomwalters@0 339 (void) fprintf(stderr, "Could not open the image file %s.\n", firstWaveName);
tomwalters@0 340 exit(1);
tomwalters@0 341 }
tomwalters@0 342
tomwalters@0 343 (void) readopts(res, firstWave);
tomwalters@0 344
tomwalters@0 345 if (fseek(firstWave, 0l, 0)) {
tomwalters@0 346 (void) fprintf(stderr, "revsai: Could not re-seek the %s file.\n",
tomwalters@0 347 firstWaveName);
tomwalters@0 348 exit(1);
tomwalters@0 349 }
tomwalters@0 350
tomwalters@0 351 (void) readopts(hiddenRes, firstWave);
tomwalters@0 352
tomwalters@0 353 if( framestr == (char *) 0 )
tomwalters@0 354 if( downstr == (char *) 0 )
tomwalters@0 355 frame1 = 1 ;
tomwalters@0 356 else
tomwalters@0 357 frame1 = atof(downstr);
tomwalters@0 358 else if ((frame1 = atof(framestr)) < 0.0)
tomwalters@0 359 frame1 = 0.0;
tomwalters@0 360
tomwalters@0 361 firstWidth = atoi( widthstr );
tomwalters@0 362 firstHeight = atoi( heightstr);
tomwalters@0 363
tomwalters@0 364 start1 = msToImages(frame1, atof( start1str ));
tomwalters@0 365
tomwalters@0 366 if (strcmp(stop1str, LENGTH_STR) == 0)
tomwalters@0 367 stop1 = MAX_LENGTH;
tomwalters@0 368 else
tomwalters@0 369 stop1 = msToImages(frame1, atof( stop1str )) + start1;
tomwalters@0 370
tomwalters@0 371 step1 = atoi( step1str );
tomwalters@0 372 if (step1 < 1)
tomwalters@0 373 step1 = 1;
tomwalters@0 374
tomwalters@0 375 firstPixels = 1; /* atoi( pixelstr ); */
tomwalters@0 376
tomwalters@0 377 mincf1 = atof( minstr );
tomwalters@0 378 maxcf1 = atof( maxstr );
tomwalters@0 379
tomwalters@0 380 if (TwoWaves) {
tomwalters@0 381
tomwalters@0 382 if (argc == 1)
tomwalters@0 383 secondWaveName = AlterSuffix(in2str, IMAGE_SUFFIX);
tomwalters@0 384 else
tomwalters@0 385 secondWaveName = AlterSuffix(argv[1],IMAGE_SUFFIX);
tomwalters@0 386
tomwalters@0 387 if ((secondWave = fopen(secondWaveName, READ_BINARY )) == NULL) {
tomwalters@0 388 (void) fprintf(stderr, "Could not open the image file %s.\n",
tomwalters@0 389 secondWaveName);
tomwalters@0 390 exit(1);
tomwalters@0 391 }
tomwalters@0 392
tomwalters@0 393 (void) readopts(res, secondWave);
tomwalters@0 394 if (fseek(secondWave, 0l, 0)) {
tomwalters@0 395 (void) fprintf(stderr, "revsai: Could not re-seek the %s file.\n",
tomwalters@0 396 secondWaveName);
tomwalters@0 397 exit(1);
tomwalters@0 398 }
tomwalters@0 399 (void) readopts(hiddenRes, secondWave);
tomwalters@0 400
tomwalters@0 401 if( framestr == (char *) 0 )
tomwalters@0 402 if( downstr == (char *) 0 )
tomwalters@0 403 frame2 = 1. ;
tomwalters@0 404 else
tomwalters@0 405 frame2 = atof(downstr);
tomwalters@0 406 else if ((frame2 = atof(framestr)) < 0.0)
tomwalters@0 407 frame2 = atof(downstr);
tomwalters@0 408
tomwalters@0 409 secondWidth = atoi( widthstr );
tomwalters@0 410 secondHeight = atoi( heightstr);
tomwalters@0 411
tomwalters@0 412 start2 = msToImages(frame2, atof( start2str ));
tomwalters@0 413
tomwalters@0 414 if (strcmp(stop2str, LENGTH_STR) == 0)
tomwalters@0 415 stop2 = MAX_LENGTH;
tomwalters@0 416 else
tomwalters@0 417 stop2 = msToImages(frame2, atof( stop2str )) + start2;
tomwalters@0 418
tomwalters@0 419 step2 = atoi( step2str );
tomwalters@0 420 if (step2 < 1)
tomwalters@0 421 step2 = 1;
tomwalters@0 422
tomwalters@0 423 secondPixels = 1; /* atoi( pixelstr ); */
tomwalters@0 424
tomwalters@0 425 mincf2 = atof( minstr );
tomwalters@0 426 maxcf2 = atof( maxstr );
tomwalters@0 427
tomwalters@0 428 }
tomwalters@0 429
tomwalters@0 430
tomwalters@0 431 /* Open display window(s) */
tomwalters@0 432
tomwalters@0 433 if (TwoWaves) {
tomwalters@0 434 /* Center them both for height, but try to fit them both on the screen
tomwalters@0 435 at once, width-wise. Firstly, get the REAL screen size */
tomwalters@0 436 #if defined( PC )
tomwalters@0 437 w1 = newDisplayWindow(firstWaveName, -1, -1, OVERTHETOP, OVERTHETOP, 1);
tomwalters@0 438 screenWidth = Width(w1);
tomwalters@0 439 screenHeight = Height(w1);
tomwalters@0 440 Close(w1);
tomwalters@0 441 #endif
tomwalters@0 442
tomwalters@0 443 if (screenHeight < firstHeight || screenHeight < secondHeight) {
tomwalters@0 444 (void) fprintf(stderr, "revsai: One (or both) of the waves specified was too\n high for this screen.\n");
tomwalters@0 445 exit(1);
tomwalters@0 446 }
tomwalters@0 447 if (screenWidth < firstWidth + secondWidth) {
tomwalters@0 448 (void) fprintf(stderr, "revsai: These two waves are too wide to be viewed side-by-side.\n Please revue them one at a time, or perhaps generate them smaller.\n");
tomwalters@0 449 exit(1);
tomwalters@0 450 }
tomwalters@0 451
tomwalters@0 452 spareWidth = screenWidth - (firstWidth + secondWidth + (2 * AXES_WIDTH));
tomwalters@0 453 spareHeight = screenHeight - (firstHeight + (2 * AXES_WIDTH));
tomwalters@0 454
tomwalters@0 455 w1 = newDisplayWindow(firstWaveName, spareWidth/6 + AXES_WIDTH, spareHeight/2,
tomwalters@0 456 firstWidth, firstHeight, firstPixels);
tomwalters@0 457 Axes(w1, firstWaveName, 0.0, frame1, "Image Frame Size (in ms)",
tomwalters@0 458 mincf1, maxcf1, "Center Frequency (in Hz)");
tomwalters@0 459
tomwalters@0 460 spareHeight = screenHeight - (secondHeight + (2 * AXES_WIDTH));
tomwalters@0 461
tomwalters@0 462 w2 = newDisplayWindow(secondWaveName, (5 * spareWidth / 6) +
tomwalters@0 463 firstWidth + (2 * AXES_WIDTH),
tomwalters@0 464 spareHeight/2, secondWidth, secondHeight,
tomwalters@0 465 secondPixels);
tomwalters@0 466 Axes(w2, secondWaveName, 0.0, frame2, "Image Frame Size (in ms)",
tomwalters@0 467 mincf2, maxcf2, "Center Frequency (in Hz)");
tomwalters@0 468 }
tomwalters@0 469 else {
tomwalters@0 470 /* Easy .. MetaPC Centers it for us */
tomwalters@0 471 if (OptionStringsEqual(xstr, CENTER_STR))
tomwalters@0 472 x = -1;
tomwalters@0 473 else
tomwalters@0 474 x = atoi(xstr);
tomwalters@0 475
tomwalters@0 476 if (OptionStringsEqual(ystr, CENTER_STR))
tomwalters@0 477 y = -1;
tomwalters@0 478 else
tomwalters@0 479 y = atoi(ystr);
tomwalters@0 480
tomwalters@0 481 w1 = newDisplayWindow(firstWaveName, x, y, firstWidth, firstHeight,
tomwalters@0 482 firstPixels );
tomwalters@0 483 Axes(w1, firstWaveName, 0.0, frame1, "Image Frame Size (in ms)",
tomwalters@0 484 mincf1, maxcf1, "Center Frequency (in Hz)");
tomwalters@0 485
tomwalters@0 486 #if defined( SUN )
tomwalters@0 487 /* Kludge to overcome the window-sizing inconsistency when
tomwalters@0 488 you open a SunView window with a frame */
tomwalters@0 489
tomwalters@0 490 if (Height(w1) > firstHeight || Width(w1) > firstWidth) {
tomwalters@0 491 #else
tomwalters@0 492 if (Height(w1) != firstHeight || Width(w1) != firstWidth) {
tomwalters@0 493 #endif
tomwalters@0 494 (void) fprintf(stderr, "revsai: The wave you wish to view is too large (ie. either too wide\nor too tall) for the current screen.\n");
tomwalters@0 495 exit(1);
tomwalters@0 496 }
tomwalters@0 497 }
tomwalters@0 498
tomwalters@0 499 /* Do the actual reviewing */
tomwalters@0 500
tomwalters@0 501 if (TwoWaves)
tomwalters@0 502 waveMode = BOTH;
tomwalters@0 503 else
tomwalters@0 504 waveMode = ONE ;
tomwalters@0 505
tomwalters@0 506 speed1 = atoi( speed1str );
tomwalters@0 507 if (speed1 < 1)
tomwalters@0 508 speed1 = 1;
tomwalters@0 509 speed2 = atoi( speed2str );
tomwalters@0 510 if (speed2 < 1)
tomwalters@0 511 speed2 = 1;
tomwalters@0 512
tomwalters@0 513 /* Initially, just open the files and display the first frame of each, */
tomwalters@0 514 /* UNLESS the inMemory switch is set, in which case you should read in */
tomwalters@0 515 /* all of the images and adjust start, stop to suit. */
tomwalters@0 516
tomwalters@0 517 if (inMemory) {
tomwalters@0 518 stop1 = readIntoMemory(w1, firstWave, start1, stop1, step1);
tomwalters@0 519 start1 = 1; /* Now runs from 0 to the adjusted stop */
tomwalters@0 520 step1 = 1; /* Now the images are contiguous */
tomwalters@0 521 if (TwoWaves) {
tomwalters@0 522 stop2 = readIntoMemory(w2, secondWave, start2, stop2, step2);
tomwalters@0 523 start2 = 1; /* Now runs from 0 to the adjusted stop */
tomwalters@0 524 step2 = 1; /* Now the images are contiguous */
tomwalters@0 525 }
tomwalters@0 526 }
tomwalters@0 527 else {
tomwalters@0 528 if (!Read(w1, firstWave, start1)) {
tomwalters@0 529 (void) fprintf(stderr, "revsai: Could not read the first image from the first wave.\n");
tomwalters@0 530 exit(1);
tomwalters@0 531 }
tomwalters@0 532
tomwalters@0 533 if (TwoWaves && !Read(w2, secondWave, start2)) {
tomwalters@0 534 (void) fprintf(stderr, "revsai: Couldn't read the first image from the second wave.\n");
tomwalters@0 535 exit(1);
tomwalters@0 536 }
tomwalters@0 537 }
tomwalters@0 538
tomwalters@0 539 /* Sit and take commands */
tomwalters@0 540
tomwalters@0 541 while ((command = Pause(w1)) != 'q' && command != 'Q') {
tomwalters@0 542 switch (command) {
tomwalters@0 543 case '1':
tomwalters@0 544 /* Toggle to Wave number One */
tomwalters@0 545 waveMode = ONE;
tomwalters@0 546 break;
tomwalters@0 547 case '2':
tomwalters@0 548 /* Try to toggle to Wave number Two */
tomwalters@0 549 if (TwoWaves)
tomwalters@0 550 waveMode = TWO;
tomwalters@0 551 break;
tomwalters@0 552 case 'b': case 'B':
tomwalters@0 553 /* Try to toggle to Both Waves */
tomwalters@0 554 if (TwoWaves)
tomwalters@0 555 waveMode = BOTH;
tomwalters@0 556 break;
tomwalters@0 557 case '+':
tomwalters@0 558 /* Speed up current Wave(s) */
tomwalters@0 559 if (waveMode == ONE || waveMode == BOTH)
tomwalters@0 560 speed1 = ((speed1 > 1) ? (speed1 /= 2) : (1));
tomwalters@0 561 if (waveMode == TWO || waveMode == BOTH)
tomwalters@0 562 speed2 = ((speed2 > 1) ? (speed2 /= 2) : (1));
tomwalters@0 563 break;
tomwalters@0 564 case '-':
tomwalters@0 565 /* Slow down current Wave(s) */
tomwalters@0 566 if (waveMode == ONE || waveMode == BOTH)
tomwalters@0 567 speed1 *= 2;
tomwalters@0 568 if (waveMode == TWO || waveMode == BOTH)
tomwalters@0 569 speed2 *= 2;
tomwalters@0 570 break;
tomwalters@0 571 case 's': case 'S':
tomwalters@0 572 stopFirst = (waveMode == TWO);
tomwalters@0 573 stopSecond = (waveMode == ONE);
tomwalters@0 574 image1 = start1;
tomwalters@0 575 image2 = start2;
tomwalters@0 576 while (!(stopFirst && stopSecond) && (Pause(w1) == ' ')) {
tomwalters@0 577 if (!stopFirst) {
tomwalters@0 578 if (inMemory)
tomwalters@0 579 Recall(w1, image1);
tomwalters@0 580 else
tomwalters@0 581 stopFirst = !Read(w1, firstWave , image1);
tomwalters@0 582 if (!stopFirst) {
tomwalters@0 583 image1 += step1;
tomwalters@0 584 stopFirst = (image1 > stop1);
tomwalters@0 585 }
tomwalters@0 586 }
tomwalters@0 587 if (!stopSecond) {
tomwalters@0 588 if (inMemory)
tomwalters@0 589 Recall(w2, image2);
tomwalters@0 590 else
tomwalters@0 591 stopSecond = !Read(w2, secondWave, image2);
tomwalters@0 592 if (!stopSecond) {
tomwalters@0 593 image2 += step2;
tomwalters@0 594 stopSecond = (image2 > stop2);
tomwalters@0 595 }
tomwalters@0 596 }
tomwalters@0 597 }
tomwalters@0 598 break;
tomwalters@0 599 case 'a': case 'A': case ' ':
tomwalters@0 600 stopFirst = (waveMode == TWO);
tomwalters@0 601 stopSecond = (waveMode == ONE);
tomwalters@0 602 image1 = start1;
tomwalters@0 603 image2 = start2;
tomwalters@0 604 count1 = count2 = 0 ;
tomwalters@0 605 while (!(stopFirst && stopSecond)) {
tomwalters@0 606 if (stopFirst || image1 > stop1) {
tomwalters@0 607 if (waveMode == BOTH && !stopSecond && image2 <= stop2 &&
tomwalters@0 608 image1 > start1 && count1 == 0) {
tomwalters@0 609 /* Redisplay the previous image for constant speed */
tomwalters@0 610 if (inMemory)
tomwalters@0 611 Recall(w1, image1-1);
tomwalters@0 612 else
tomwalters@0 613 stopFirst = !Read(w1, firstWave, image1-1);
tomwalters@0 614 }
tomwalters@0 615 stopFirst = TRUE;
tomwalters@0 616 }
tomwalters@0 617 else {
tomwalters@0 618 if (inMemory)
tomwalters@0 619 Recall(w1, image1);
tomwalters@0 620 else
tomwalters@0 621 stopFirst = !Read(w1, firstWave, image1);
tomwalters@0 622 if (!stopFirst)
tomwalters@0 623 if (++count1 >= speed1) {
tomwalters@0 624 image1 += step1;
tomwalters@0 625 count1 = 0 ;
tomwalters@0 626 }
tomwalters@0 627 }
tomwalters@0 628 if (stopSecond || image2 > stop2) {
tomwalters@0 629 if (waveMode == BOTH && !stopFirst && image1 <= stop1 &&
tomwalters@0 630 image2 > start2 && count2 == 0) {
tomwalters@0 631 /* Redisplay the previous image for constant speed */
tomwalters@0 632 if (inMemory)
tomwalters@0 633 Recall(w2, image2-1);
tomwalters@0 634 else
tomwalters@0 635 stopSecond = !Read(w2, secondWave, image2-1);
tomwalters@0 636 }
tomwalters@0 637 stopSecond = TRUE;
tomwalters@0 638 }
tomwalters@0 639 else {
tomwalters@0 640 if (inMemory)
tomwalters@0 641 Recall(w2, image2);
tomwalters@0 642 else
tomwalters@0 643 stopSecond = !Read(w2, secondWave, image2);
tomwalters@0 644 if (!stopSecond)
tomwalters@0 645 if (++count2 >= speed2) {
tomwalters@0 646 image2 += step2;
tomwalters@0 647 count2 = 0 ;
tomwalters@0 648 }
tomwalters@0 649 }
tomwalters@0 650 }
tomwalters@0 651 break;
tomwalters@0 652 default:
tomwalters@0 653 break;
tomwalters@0 654 }
tomwalters@0 655 }
tomwalters@0 656 if (fclose(firstWave)) {
tomwalters@0 657 (void) fprintf(stderr, "revsai: Could not close file % correctly.\n",
tomwalters@0 658 firstWaveName);
tomwalters@0 659 exit(1);
tomwalters@0 660 }
tomwalters@0 661 if (TwoWaves && fclose(secondWave)) {
tomwalters@0 662 (void) fprintf(stderr, "revsai: Could not close file % correctly.\n",
tomwalters@0 663 secondWaveName);
tomwalters@0 664 exit(1);
tomwalters@0 665 }
tomwalters@0 666 }