annotate tools/ftgram.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 ftgram.c Row-wise fft program by Michael Allerhand.
tomwalters@0 3 ----------
tomwalters@0 4
tomwalters@0 5 Short-time Fourier transform applied to each row of input frames.
tomwalters@0 6 Output frames consist of row-wise magnitude spectra, computed using fft.
tomwalters@0 7
tomwalters@0 8 Input/output:
tomwalters@0 9 Read a header and frame in NAP format.
tomwalters@0 10 Write a header, (constructed from the original input header), and a
tomwalters@0 11 succession of frames in SAI format.
tomwalters@0 12
tomwalters@0 13 The input file is interpreted as one large frame in NAP format to be
tomwalters@0 14 divided into input frames, each to be processed and output in SAI format.
tomwalters@0 15
tomwalters@0 16 The options "start" and "length" specify the input file.
tomwalters@0 17 The special option value length=max specifies all the input file from
tomwalters@0 18 the given start to its end.
tomwalters@0 19
tomwalters@0 20 The options "width" and "frstep" specify the input frames.
tomwalters@0 21 The width option is the framewidth of each input frame) and the frstep
tomwalters@0 22 option is the frameshift between input frames in the input file.
tomwalters@0 23 The special option value width=max specifies the input framewidth as equal
tomwalters@0 24 to the given input file length, (and if this is also "max", then the
tomwalters@0 25 input framewidth is the remainder of the input file).
tomwalters@0 26
tomwalters@0 27 Most options in the input header are copied to the output header.
tomwalters@0 28 This enables options which are needed for the eventual display
tomwalters@0 29 to pass straight through. Some options are set so that they can override
tomwalters@0 30 the input header. For example, the display option is set on to enable
tomwalters@0 31 display even when input has display=off. The animate option can be set on
tomwalters@0 32 even when the input has animate=off.
tomwalters@0 33 Parts of the header are changed for the new sai format:
tomwalters@0 34 (frames, frameshift, framewidth, frameheight, framebytes).
tomwalters@0 35
tomwalters@0 36 Padding:
tomwalters@0 37 The output framewidth is the next power-of-2 above twice the input
tomwalters@0 38 framewidth.
tomwalters@0 39 The rows of each input frame are padded with zeroes so that the input
tomwalters@0 40 framewidth is at least twice its original size, and also a power of 2.
tomwalters@0 41 This is because the fft method is "radix-2", and because each output
tomwalters@0 42 spectrum is symmetrical so that just half the points are unique.
tomwalters@0 43 It is advisable to pad input frames for the additional reason that
tomwalters@0 44 padding counters frame end-effects.
tomwalters@0 45
tomwalters@0 46 Therefore each row of each input frame is padded with zeroes to the next
tomwalters@0 47 power of 2 larger than the original input framewidth.
tomwalters@0 48 If necessary, extra padding can be enforced using the padding option to
tomwalters@0 49 add extra zeroes, padding to a larger power of 2.
tomwalters@0 50 The amount of extra padding is "exponential" since if the basic padded
tomwalters@0 51 framesize is N, and the padding option is n, then extra padding is to:
tomwalters@0 52 N * 2**n.
tomwalters@0 53 (n=0 by default, so that N is not changed. When n=1 then N is doubled, and
tomwalters@0 54 when n=2 then N is quadrupled, etc.).
tomwalters@0 55
tomwalters@0 56 The output framewidth (and hence the frequency resolution) depends upon the
tomwalters@0 57 input framewidth and the padding.
tomwalters@0 58
tomwalters@0 59 Examples:
tomwalters@0 60
tomwalters@0 61 1. ftgram of a NAP, animated, with framewidth 16ms
tomwalters@0 62
tomwalters@0 63 gennap len=128ms output=stdout display=off file | ftgram width=16ms anim=on > file.sai
tomwalters@0 64 gensai useprev=on headr=5 top=1000 file -(for landscape plot)
tomwalters@0 65 genspl useprev=on headr=5 top=1000 pensize=2 file -(for spiral plot)
tomwalters@0 66
tomwalters@0 67 2. ftgram of an SAI:
tomwalters@0 68 (Note that gensai removes file.sai, so you must use some other name, eg foo.sai).
tomwalters@0 69
tomwalters@0 70 gensai len=64 pwidth=64 nwidth=0 output=stdout display=off file | \
tomwalters@0 71 saitonap frame=3 | ftgram width=32ms frame=1 > foo.sai
tomwalters@0 72 gensai useprev=on top=1000 headr=5 mag=2 foo
tomwalters@0 73
tomwalters@0 74
tomwalters@0 75 */
tomwalters@0 76
tomwalters@0 77 #include <stdio.h>
tomwalters@0 78 #include <math.h>
tomwalters@0 79 #include "header.h"
tomwalters@0 80 #include "options.h"
tomwalters@0 81 #include "units.h"
tomwalters@0 82 #include "strmatch.h"
tomwalters@0 83 #include "sigproc.h"
tomwalters@0 84
tomwalters@0 85 char applic[] = "Autocorrelogram auditory image." ;
tomwalters@0 86
tomwalters@0 87 static char *helpstr , *debugstr, *dispstr , *anistr , *startstr ;
tomwalters@0 88 static char *lengthstr, *widthstr, *shiftstr, *headerstr, *framestr ;
tomwalters@0 89 static char *wstr , *scalestr, *padstr ;
tomwalters@0 90
tomwalters@0 91 static Options option[] = {
tomwalters@0 92 { "help" , "off" , &helpstr , "help" , DEBUG },
tomwalters@0 93 { "debug" , "off" , &debugstr , "debugging switch" , DEBUG },
tomwalters@0 94 { "display" , "on" , &dispstr , "Display output image." , SETFLAG },
tomwalters@0 95 { "animate" , "off" , &anistr , "Animate cartoon." , SETFLAG },
tomwalters@0 96 { "frames" , "1-max" , &framestr , "Select frames inclusively" , VAL },
tomwalters@0 97 { "header" , "on" , &headerstr , "Header (for gensai useprevious=on)." , VAL },
tomwalters@0 98 { "start" , "0" , &startstr , "Start point in i/p file." , VAL },
tomwalters@0 99 { "length" , "max" , &lengthstr , "Length of i/p file to process." , VAL },
tomwalters@0 100 { "frstep" , "16ms" , &shiftstr , "Step between input frames." , VAL },
tomwalters@0 101 { "width" , "32ms" , &widthstr , "Width of input frames." , VAL },
tomwalters@0 102 { "padding" , "0" , &padstr , "Exponential frame padding" , SVAL },
tomwalters@0 103 { "window" , "on" , &wstr , "Hamming window" , SETFLAG },
tomwalters@0 104 { "scale" , "0.08" , &scalestr , "Scale factor for output" , SVAL },
tomwalters@0 105 ( char * ) 0 } ;
tomwalters@0 106
tomwalters@0 107
tomwalters@0 108 int samplerate ;
tomwalters@0 109
tomwalters@0 110 int frameheight, framewidth ;
tomwalters@0 111 int frames, framebytes ;
tomwalters@0 112 int frameshift ;
tomwalters@0 113
tomwalters@0 114 int Newframeheight, Newframewidth ;
tomwalters@0 115 int Newframes, Newframebytes ;
tomwalters@0 116 int Newframeshift ;
tomwalters@0 117
tomwalters@0 118 int start, length ; /* Size of input file (num cols) */
tomwalters@0 119 int frameslength ; /* Length (num cols) of input file to process */
tomwalters@0 120
tomwalters@0 121 int zeroes ;
tomwalters@0 122 int window ; /* Flag for Hamming window */
tomwalters@0 123 float scale ; /* Scale factor for output */
tomwalters@0 124
tomwalters@0 125 short *file ; /* Input file (NAP format) */
tomwalters@0 126 float *W ; /* Hamming window for fft */
tomwalters@0 127 float *buf ; /* fft working space */
tomwalters@0 128
tomwalters@0 129
tomwalters@0 130 main(argc, argv)
tomwalters@0 131 int argc ;
tomwalters@0 132 char *argv[] ;
tomwalters@0 133 {
tomwalters@0 134 FILE *fp ;
tomwalters@0 135 char *header, *SaiHeader();
tomwalters@0 136 char *versionstr, c ;
tomwalters@0 137 int startbytes, framebyteshift ;
tomwalters@0 138 short *frame, *endframe ;
tomwalters@0 139 int i, a, b ;
tomwalters@0 140
tomwalters@0 141 fp = openopts( option,argc,argv ) ;
tomwalters@0 142 if ( !isoff( helpstr ) )
tomwalters@0 143 helpopts( helpstr, argv[0], applic, option ) ;
tomwalters@0 144
tomwalters@0 145 window = ison( wstr ) ;
tomwalters@0 146
tomwalters@0 147
tomwalters@0 148 /**** parse bounds on number of frames ****/
tomwalters@0 149
tomwalters@0 150 if ( selector( framestr, &a, &b ) == 0 ) {
tomwalters@0 151 fprintf(stderr,"ftgram: bad frame selector [%s]\n", framestr ) ;
tomwalters@0 152 exit( 1 ) ;
tomwalters@0 153 }
tomwalters@0 154
tomwalters@0 155
tomwalters@0 156 /**** Input frame dimensions (from header and options) ****/
tomwalters@0 157
tomwalters@0 158 if ((header = ReadHeader(fp)) == (char *) 0 ) {
tomwalters@0 159 fprintf(stderr,"ftgram: header not found\n");
tomwalters@0 160 exit(1);
tomwalters@0 161 }
tomwalters@0 162
tomwalters@0 163 if ( (versionstr = HeaderString( header, "Version" )) == (char *)0 ) {
tomwalters@0 164 fprintf(stderr,"ftgram: model version-number not found in header\n");
tomwalters@0 165 exit(1);
tomwalters@0 166 }
tomwalters@0 167
tomwalters@0 168 samplerate = HeaderSamplerate( header );
tomwalters@0 169
tomwalters@0 170 /* In NAP format, the size of the 2-D image is given by: */
tomwalters@0 171 /* frameheight = number of rows (filterbank channels) */
tomwalters@0 172 /* frames = number of columns (sample points) */
tomwalters@0 173
tomwalters@0 174 frameheight = HeaderInt( header, "frameheight" );
tomwalters@0 175 frames = HeaderInt( header, "frames" );
tomwalters@0 176
tomwalters@0 177 if ( ( frameshift = to_p( shiftstr, samplerate ) ) <= 0 ) {
tomwalters@0 178 fprintf(stderr,"ftgram: non-positive frstep [%d]\n", frameshift);
tomwalters@0 179 exit(1);
tomwalters@0 180 }
tomwalters@0 181
tomwalters@0 182 /* calculate start of first frame (in cols) */
tomwalters@0 183
tomwalters@0 184 if ( ( start = to_p( startstr, samplerate ) + ( a-1 ) * frameshift ) >= frames ) {
tomwalters@0 185 fprintf(stderr,"ftgram: input file too small (%dms) for given framing parameters\n", frames * 1000 / samplerate );
tomwalters@0 186 exit(1);
tomwalters@0 187 }
tomwalters@0 188
tomwalters@0 189 /* get length of input file (in cols) and framewidth of input frames */
tomwalters@0 190
tomwalters@0 191 if ( ismax( lengthstr ) ) length = frames - start ;
tomwalters@0 192 else length = to_p( lengthstr, samplerate ) - start ;
tomwalters@0 193
tomwalters@0 194 if ( ismax( widthstr ) ) framewidth = length ;
tomwalters@0 195 else framewidth = to_p( widthstr, samplerate ) ;
tomwalters@0 196
tomwalters@0 197 if ( length < framewidth ) {
tomwalters@0 198 fprintf(stderr,"ftgram: input file too small (%dms) for given framing parameters\n", frames * 1000 / samplerate );
tomwalters@0 199 exit(1);
tomwalters@0 200 }
tomwalters@0 201
tomwalters@0 202 /* calculate length (num cols) to process, and the number of frames */
tomwalters@0 203
tomwalters@0 204 if ( b==0 ) {
tomwalters@0 205 frameslength = length ;
tomwalters@0 206 Newframes = 1 + ( length - framewidth ) / frameshift ;
tomwalters@0 207 }
tomwalters@0 208 else {
tomwalters@0 209 frameslength = framewidth + ( b-a ) * frameshift ;
tomwalters@0 210 Newframes = b - ( a-1 ) ;
tomwalters@0 211 }
tomwalters@0 212
tomwalters@0 213 if ( start + frameslength > frames ) {
tomwalters@0 214 fprintf(stderr,"ftgram: input file too small (%dms) for requested start and length \n", frames * 1000 / samplerate );
tomwalters@0 215 exit(1);
tomwalters@0 216 }
tomwalters@0 217
tomwalters@0 218 framebytes = frameheight * frameslength * sizeof(short) ;
tomwalters@0 219 startbytes = frameheight * start * sizeof(short) ;
tomwalters@0 220
tomwalters@0 221
tomwalters@0 222 /**** Output frame dimensions ****/
tomwalters@0 223
tomwalters@0 224 Newframeheight = frameheight ;
tomwalters@0 225 Newframewidth = ( framewidth + zeroes ) >> 1 ; /* spectral bins */
tomwalters@0 226 Newframeshift = frameshift ;
tomwalters@0 227 Newframebytes = Newframeheight * Newframewidth * sizeof(short) ;
tomwalters@0 228
tomwalters@0 229
tomwalters@0 230 /**** Padding and output scale factor ****/
tomwalters@0 231
tomwalters@0 232 zeroes = ( getpower( framewidth << 1 ) << atoi( padstr ) ) - framewidth ;
tomwalters@0 233 scale = atof( scalestr ) ;
tomwalters@0 234
tomwalters@0 235
tomwalters@0 236 /**** Debug ****/
tomwalters@0 237
tomwalters@0 238 if ( ison( debugstr ) ) {
tomwalters@0 239 fprintf(stderr, "Input: frames=%d frameheight=%d frameshift=%d\n", frames, frameheight, frameshift ) ;
tomwalters@0 240 fprintf(stderr, "Sizes: start=%d length=%d framewidth=%d frameslength=%d\n", start, length, framewidth, frameslength ) ;
tomwalters@0 241 fprintf(stderr, "Output: zeroes=%d Newframewidth=%d Newframes=%d \n", zeroes, Newframewidth, Newframes ) ;
tomwalters@0 242 exit( 1 ) ;
tomwalters@0 243 }
tomwalters@0 244
tomwalters@0 245
tomwalters@0 246 /**** Allocate space (input file, window coeffs, and fft working space) ****/
tomwalters@0 247
tomwalters@0 248 if ( ( file = (short *)malloc( framebytes ) ) == NULL ) {
tomwalters@0 249 fprintf(stderr,"ftgram: malloc out of space\n");
tomwalters@0 250 exit(1);
tomwalters@0 251 }
tomwalters@0 252
tomwalters@0 253 if ( window )
tomwalters@0 254 W = hamming( framewidth ) ;
tomwalters@0 255
tomwalters@0 256 buf = (float *)malloc( ( framewidth + zeroes ) * sizeof(float) );
tomwalters@0 257
tomwalters@0 258
tomwalters@0 259 /**** Write new sai header ****/
tomwalters@0 260
tomwalters@0 261 if ( ison( headerstr ) )
tomwalters@0 262 WriteHeader( SaiHeader(header), stdout );
tomwalters@0 263
tomwalters@0 264
tomwalters@0 265 /**** Seek to start of input file in blocks of framebytes ****/
tomwalters@0 266
tomwalters@0 267 for (i=framebytes ; i < startbytes ; i += framebytes)
tomwalters@0 268 if ( fread( file, framebytes, 1, fp ) == NULL ) {
tomwalters@0 269 fprintf(stderr,"ftgram: missing data after header\n");
tomwalters@0 270 exit(1);
tomwalters@0 271 }
tomwalters@0 272 if ( (startbytes -= (i - framebytes)) > 0 )
tomwalters@0 273 if ( fread( file, startbytes, 1, fp ) == NULL ) {
tomwalters@0 274 fprintf(stderr,"ftgram: missing data after header\n");
tomwalters@0 275 exit(1);
tomwalters@0 276 }
tomwalters@0 277
tomwalters@0 278
tomwalters@0 279 /**** Read framebytes of i/p file ****/
tomwalters@0 280
tomwalters@0 281 if ( fread( file, framebytes, 1, fp ) == NULL ) {
tomwalters@0 282 fprintf(stderr,"ftgram: missing data after header\n");
tomwalters@0 283 exit(1);
tomwalters@0 284 }
tomwalters@0 285
tomwalters@0 286
tomwalters@0 287 /**** Process frames ****/
tomwalters@0 288
tomwalters@0 289 framebyteshift = frameshift * frameheight ;
tomwalters@0 290 endframe = file + Newframes * framebyteshift ;
tomwalters@0 291
tomwalters@0 292 for ( frame = file, i=1 ; frame < endframe ; frame += framebyteshift, i++ ) {
tomwalters@0 293 fprintf(stderr,"ftgram: %d / %d [%dms]\n", i, Newframes, start*1000/samplerate );
tomwalters@0 294 ftgram( frame ) ;
tomwalters@0 295 start += frameshift ;
tomwalters@0 296 }
tomwalters@0 297
tomwalters@0 298 fclose(fp);
tomwalters@0 299 fprintf(stderr,"ftgram: done\n" ) ;
tomwalters@0 300 }
tomwalters@0 301
tomwalters@0 302
tomwalters@0 303
tomwalters@0 304 /********************************** FFT ************************************/
tomwalters@0 305
tomwalters@0 306 /* Call fft and magnitude spectrum for each row in auditory image */
tomwalters@0 307
tomwalters@0 308 ftgram( frame )
tomwalters@0 309 short *frame ;
tomwalters@0 310 {
tomwalters@0 311 register int i, j, row, col ;
tomwalters@0 312
tomwalters@0 313 for ( row=0 ; row < frameheight ; row++ ) {
tomwalters@0 314
tomwalters@0 315 if ( window )
tomwalters@0 316 for ( col=0 , i=row ; col < framewidth ; col++, i+=frameheight )
tomwalters@0 317 buf[col] = frame[i] * W[col] ;
tomwalters@0 318 else
tomwalters@0 319 for ( col=0 , i=row ; col < framewidth ; col++, i+=frameheight )
tomwalters@0 320 buf[col] = frame[i] ;
tomwalters@0 321
tomwalters@0 322 for ( j=0 ; j<zeroes ; j++ ) /* padding */
tomwalters@0 323 buf[col++] = 0 ;
tomwalters@0 324
tomwalters@0 325 fft( buf, framewidth+zeroes, 1 ) ;
tomwalters@0 326 mag( buf, framewidth+zeroes ) ;
tomwalters@0 327
tomwalters@0 328 writebuf( buf, Newframewidth, scale ) ;
tomwalters@0 329 }
tomwalters@0 330 }
tomwalters@0 331
tomwalters@0 332
tomwalters@0 333 /********************** Write o/p ****************************************/
tomwalters@0 334
tomwalters@0 335 writebuf( buf, n, scale ) /* write buffer as scaled shorts */
tomwalters@0 336 float *buf ;
tomwalters@0 337 int n ;
tomwalters@0 338 float scale ;
tomwalters@0 339 {
tomwalters@0 340 register int i ;
tomwalters@0 341 short p ;
tomwalters@0 342
tomwalters@0 343 for (i=0 ; i < n ; i++) {
tomwalters@0 344 p = (short)( buf[i] * scale ) ;
tomwalters@0 345 fwrite( &p, sizeof(short), 1, stdout ) ;
tomwalters@0 346 }
tomwalters@0 347 }
tomwalters@0 348
tomwalters@0 349
tomwalters@0 350 /************************ Output header ************************************/
tomwalters@0 351 /*
tomwalters@0 352 Copy the original nap header to a new sai header, changing in order:
tomwalters@0 353 frames
tomwalters@0 354 frameshift
tomwalters@0 355 framewidth
tomwalters@0 356 frameheight
tomwalters@0 357 framebytes
tomwalters@0 358 animate
tomwalters@0 359 display
tomwalters@0 360 Finally, update the new header_bytes, and return the new header.
tomwalters@0 361 */
tomwalters@0 362
tomwalters@0 363 char *SaiHeader( napheader )
tomwalters@0 364 char *napheader ;
tomwalters@0 365 {
tomwalters@0 366 char *saiheader;
tomwalters@0 367 char *p0, *p1, *p2, *s, str[64];
tomwalters@0 368
tomwalters@0 369 saiheader = (char *)malloc( strlen(napheader) + 64 ) ;
tomwalters@0 370
tomwalters@0 371 p0 = saiheader ;
tomwalters@0 372 p1 = napheader ;
tomwalters@0 373
tomwalters@0 374
tomwalters@0 375 /** copy up to frames **/
tomwalters@0 376
tomwalters@0 377 p2 = HeaderString( napheader , "frames" ) ;
tomwalters@0 378 while( p1 < p2 )
tomwalters@0 379 *p0++ = *p1++ ;
tomwalters@0 380
tomwalters@0 381 sprintf(str,"%d\n", Newframes);
tomwalters@0 382 for (s = str ; *s != '\n' ; )
tomwalters@0 383 *p0++ = *s++;
tomwalters@0 384 *p0++ = *s;
tomwalters@0 385 while (*p1 != '\n')
tomwalters@0 386 *p1++;
tomwalters@0 387 *p1++;
tomwalters@0 388
tomwalters@0 389
tomwalters@0 390 /** copy up to frameshift **/
tomwalters@0 391
tomwalters@0 392 p2 = HeaderString( napheader , "frameshift" ) ;
tomwalters@0 393 while ( p1 < p2 )
tomwalters@0 394 *p0++ = *p1++ ;
tomwalters@0 395
tomwalters@0 396 sprintf(str,"%d\n", Newframeshift);
tomwalters@0 397 for (s = str ; *s != '\n' ; )
tomwalters@0 398 *p0++ = *s++;
tomwalters@0 399 *p0++ = *s;
tomwalters@0 400 while (*p1 != '\n')
tomwalters@0 401 *p1++;
tomwalters@0 402 *p1++;
tomwalters@0 403
tomwalters@0 404
tomwalters@0 405 /** copy up to framewidth **/
tomwalters@0 406
tomwalters@0 407 p2 = HeaderString( napheader , "framewidth" ) ;
tomwalters@0 408 while ( p1 < p2 )
tomwalters@0 409 *p0++ = *p1++ ;
tomwalters@0 410
tomwalters@0 411 sprintf(str,"%d\n", Newframewidth);
tomwalters@0 412 for (s = str ; *s != '\n' ; )
tomwalters@0 413 *p0++ = *s++;
tomwalters@0 414 *p0++ = *s;
tomwalters@0 415 while (*p1 != '\n')
tomwalters@0 416 *p1++;
tomwalters@0 417 *p1++;
tomwalters@0 418
tomwalters@0 419
tomwalters@0 420 /** copy up to frameheight **/
tomwalters@0 421
tomwalters@0 422 p2 = HeaderString( napheader , "frameheight" ) ;
tomwalters@0 423 while ( p1 < p2 )
tomwalters@0 424 *p0++ = *p1++ ;
tomwalters@0 425
tomwalters@0 426 sprintf(str,"%d\n", Newframeheight);
tomwalters@0 427 for (s = str ; *s != '\n' ; )
tomwalters@0 428 *p0++ = *s++;
tomwalters@0 429 *p0++ = *s;
tomwalters@0 430 while (*p1 != '\n')
tomwalters@0 431 *p1++;
tomwalters@0 432 *p1++;
tomwalters@0 433
tomwalters@0 434
tomwalters@0 435 /** copy up to framebytes **/
tomwalters@0 436
tomwalters@0 437 p2 = HeaderString( napheader , "framebytes" ) ;
tomwalters@0 438 while ( p1 < p2 )
tomwalters@0 439 *p0++ = *p1++ ;
tomwalters@0 440
tomwalters@0 441 sprintf(str,"%d\n", Newframebytes);
tomwalters@0 442 for (s = str ; *s != '\n' ; )
tomwalters@0 443 *p0++ = *s++;
tomwalters@0 444 *p0++ = *s;
tomwalters@0 445 while (*p1 != '\n')
tomwalters@0 446 *p1++;
tomwalters@0 447 *p1++;
tomwalters@0 448
tomwalters@0 449
tomwalters@0 450 /** copy up to animate_ctn **/
tomwalters@0 451
tomwalters@0 452 p2 = HeaderString( napheader , "animate_ctn" ) ;
tomwalters@0 453 while ( p1 < p2 )
tomwalters@0 454 *p0++ = *p1++ ;
tomwalters@0 455
tomwalters@0 456 sprintf(str,"%s\n", anistr );
tomwalters@0 457 for (s = str ; *s != '\n' ; )
tomwalters@0 458 *p0++ = *s++;
tomwalters@0 459 *p0++ = *s;
tomwalters@0 460 while (*p1 != '\n')
tomwalters@0 461 *p1++;
tomwalters@0 462 *p1++;
tomwalters@0 463
tomwalters@0 464
tomwalters@0 465 /** copy up to display **/
tomwalters@0 466
tomwalters@0 467 p2 = HeaderString( napheader , "display" ) ;
tomwalters@0 468 while ( p1 < p2 )
tomwalters@0 469 *p0++ = *p1++ ;
tomwalters@0 470
tomwalters@0 471 sprintf(str,"%s\n", dispstr );
tomwalters@0 472 for (s = str ; *s != '\n' ; )
tomwalters@0 473 *p0++ = *s++;
tomwalters@0 474 *p0++ = *s;
tomwalters@0 475 while (*p1 != '\n')
tomwalters@0 476 *p1++;
tomwalters@0 477 *p1++;
tomwalters@0 478
tomwalters@0 479
tomwalters@0 480 /** copy rest of header **/
tomwalters@0 481
tomwalters@0 482 p2 = HeaderString( napheader , "Version" ) ;
tomwalters@0 483 while ( p1 < p2 )
tomwalters@0 484 *p0++ = *p1++ ;
tomwalters@0 485
tomwalters@0 486 while (*p1 != '\n')
tomwalters@0 487 *p0++ = *p1++ ;
tomwalters@0 488 *p0++ = *p1++ ;
tomwalters@0 489
tomwalters@0 490
tomwalters@0 491 /** update header_bytes **/
tomwalters@0 492
tomwalters@0 493 sprintf(str, "%0*d", 7, p0-saiheader);
tomwalters@0 494 p0 = HeaderString( saiheader , "header_bytes" ) ;
tomwalters@0 495 s = str;
tomwalters@0 496 while(*p0 != '\n')
tomwalters@0 497 *p0++ = *s++ ;
tomwalters@0 498
tomwalters@0 499
tomwalters@0 500 return saiheader;
tomwalters@0 501 }
tomwalters@0 502
tomwalters@0 503