|
|
1.1 ! root 1: #include <stdio.h> ! 2: #include <math.h> ! 3: #include "view2d.h" ! 4: ! 5: extern Rd2d rd; ! 6: char *progname; ! 7: short timewarp; ! 8: double ts, te; ! 9: int verbose; ! 10: ! 11: main(argc,argv) ! 12: int argc; ! 13: char **argv; ! 14: { ! 15: register char *p; ! 16: register int prange; ! 17: register short *q; ! 18: register int r, rmin; ! 19: short *qend; ! 20: char *pict; ! 21: int ip; ! 22: short *v; ! 23: char *map; ! 24: int black; ! 25: int ncolor = 32; ! 26: int ps, psx; ! 27: int wid; ! 28: int coldstart = 1; ! 29: int blanking = 1; ! 30: int singstep = 0; ! 31: int staticd = 0; ! 32: int holly = 0; ! 33: int i, j; ! 34: short nx, ny, fru, frv; ! 35: int frame, nframe, fx, fy, fz; ! 36: int mapr[256], mapg[256], mapb[256]; ! 37: int period = 5; ! 38: int printcol = 0; ! 39: long ring, ttim; ! 40: int nf; ! 41: double frtime; ! 42: double tim[201]; ! 43: char *Malloc(); ! 44: FILE *terminal = NULL; ! 45: char junk[150]; ! 46: double cleft, cright; ! 47: timewarp = -1; ! 48: verbose = 0; ! 49: progname=argv[0]; ! 50: map = NULL; ! 51: ! 52: for(argc--, argv++; *argv && (**argv == '-' ); argv++){ ! 53: switch(argv[0][1]){ ! 54: case 'S': ! 55: switch(argv[0][2]){ ! 56: case 'a': ! 57: case 'A': singstep = 1; ! 58: terminal=NULL; ! 59: break; ! 60: case 'f': ! 61: case 'F': singstep = 1; ! 62: terminal = fopen("/dev/tty","r"); ! 63: if(terminal==NULL) error("can't open /dev/tty"); ! 64: break; ! 65: case 'M': singstep = 1; ! 66: if(argv[0][3]!='\0') holly = atoi(&argv[0][3]); ! 67: else holly = 1; ! 68: break; ! 69: case 'S': staticd = 1; ! 70: blanking = 1-blanking; ! 71: break; ! 72: } ! 73: break; ! 74: case 'b': ! 75: blanking = 1-blanking; ! 76: break; ! 77: case 'c': ! 78: ncolor = atoi(&argv[0][2]); ! 79: break; ! 80: case 'm': ! 81: map = &argv[0][2]; ! 82: break; ! 83: case 'p': ! 84: sscanf(&argv[0][2], "%d",&period); ! 85: break; ! 86: case 't': ! 87: i = sscanf(&argv[0][2], "%he, %he", &ts, &te); ! 88: if(i<=0) error("bad TS,TE"); ! 89: timewarp = i; ! 90: break; ! 91: case 'v': ! 92: verbose++; ! 93: if(argv[0][2]=='c') printcol++; ! 94: break; ! 95: case 'w': ! 96: coldstart = 0; ! 97: break; ! 98: case 'T': ! 99: case 'g': ! 100: case 's': ! 101: break; ! 102: default: ! 103: err: ! 104: fprintf(stderr,"unrecognized option: %s\n",argv[0]); ! 105: exit(1); ! 106: } ! 107: } ! 108: ! 109: if((timewarp>=0)&&verbose) ! 110: fprintf(stderr,"timewarp=%d ts=%g te=%g\n",timewarp,ts,te); ! 111: rd2dh(0,&nx,&ny); ! 112: if((timewarp>=0)&&verbose) ! 113: fprintf(stderr,"timewarp=%d ts=%g te=%g\n",timewarp,ts,te); ! 114: if(verbose){ ! 115: fprintf(stderr,"nx=%d ny=%d\n",nx,ny); ! 116: fprintf(stderr,"fmin=%g fmax=%g\n",rd.fmin,rd.fmax); ! 117: if(holly) fprintf(stderr,"snap %d\n",holly); ! 118: fprintf(stderr,"blanking=%d\n",blanking); ! 119: } ! 120: if((nx>1280)||(ny>1024)) error("picture too large %d,%d\n",nx,ny); ! 121: v = (short *)Malloc(nx*ny*sizeof(short)); ! 122: pict = (char *)Malloc(nx*ny*sizeof(char)); ! 123: minit(coldstart); ! 124: ! 125: j = (4*nx>5*ny) ? (4*nx)/5 : ny; ! 126: if ( j>512 ){ ps=1024; wid= 1; } ! 127: else if( j>256 ){ ps= 512; wid= 2; } ! 128: else if( j>128 ){ ps= 256; wid= 4; } ! 129: else if( j> 64 ){ ps= 128; wid= 8; } ! 130: else { ps= 64; wid=16; } ! 131: psx = 5*ps/4; ! 132: ! 133: prange = ((int)rd.pmax)-rd.pmin; ! 134: if(prange==0) prange = 1; ! 135: black = cvmap(map,ncolor-1,mapr,mapg,mapb); ! 136: if(printcol){ ! 137: for(j=0; j<=ncolor-1; j++){ ! 138: cleft = rd.fmin + j*(rd.fmax-rd.fmin)/ncolor; ! 139: cright = rd.fmin + (j+1)*(rd.fmax-rd.fmin)/ncolor; ! 140: fprintf(stderr,"color %4d%4d%4d = %g to %g\n", ! 141: mapr[j], mapg[j], mapb[j], cleft, cright ); ! 142: } ! 143: } ! 144: ! 145: frame=blanking; ! 146: while(rd2di(&frtime,v)){ ! 147: if(verbose) fprintf(stderr,"time=%.9g frame %d\n",frtime,frame); ! 148: if(frame<200) tim[frame]=frtime; ! 149: if(coldstart!=0){ ! 150: fx = frame%wid; ! 151: fy = wid-1 - (frame/wid)%wid; ! 152: fz = frame/(wid*wid); ! 153: if(singstep){ fx=1; fy=1; fz=1; } ! 154: if(fz>0) error("too many frames %d time=%g",frame,frtime); ! 155: p = pict; ! 156: q = v; ! 157: rmin = rd.pmin; ! 158: for(i=0; i<ny; i++){ ! 159: q = v+nx*(ny-1-i); ! 160: qend = q+nx; ! 161: for(; q<qend; q++){ ! 162: r = *q; ! 163: if( r < -BIG ){ *p = black; } ! 164: else{ ! 165: *p = ((r-rmin)*ncolor)/prange; ! 166: if(*p>=ncolor) *p = ncolor-1; ! 167: } ! 168: p++; ! 169: } ! 170: } ! 171: image(pict, psx*fx+(psx-nx)/2, ps*fy, psx*fx+(psx-nx)/2 + nx-1, ps*fy + ny-1); ! 172: if(singstep){ ! 173: if(holly){ ! 174: sprintf(junk,"snap %d",holly); ! 175: system(junk); ! 176: }else if(terminal==NULL){ ! 177: fprintf(stderr,"time=%g frame %d\n",frtime,frame); ! 178: }else{ ! 179: fprintf(stderr,"time=%g frame %d GO? ",frtime,frame); ! 180: fgets(junk,100,terminal); ! 181: if((junk[0]=='s')||(junk[0]=='S')){ ! 182: system("snap"); ! 183: junk[0]=' '; ! 184: } ! 185: if(sscanf(junk,"%d",&j)==1){ ! 186: if(verbose) fprintf(stderr," skipping %d.. ",j); ! 187: frame += j-1; ! 188: rd2dj(j-1); ! 189: } ! 190: } ! 191: } ! 192: } ! 193: frame++; ! 194: } ! 195: nframe = frame-blanking; ! 196: if(verbose) fprintf(stderr,"%d frames\n%d colors\n",nframe,ncolor); ! 197: if(singstep||staticd){ exit(0); } ! 198: ! 199: if(!staticd){ ! 200: j = (4*nx>5*ny) ? (4*nx)/5 : ny; ! 201: if ( j>512 ){ zoom(0); } ! 202: else if( j>256 ){ zoom(1); } ! 203: else if( j>128 ){ zoom(3); } ! 204: else if( j> 64 ){ zoom(7); } ! 205: else { zoom(15); } ! 206: } ! 207: if(nframe>1){ ! 208: if(nframe>200) nframe = 200; ! 209: period *= 1000; /* convert to milliseconds */ ! 210: ttim = (tim[nframe]-tim[blanking]); ! 211: if(ttim<=0){ /* if user gave unreasonable times, fake it */ ! 212: for(i=blanking+1; i<=nframe; i++){ ! 213: tim[i] = tim[i-1]+1; ! 214: } ! 215: } ! 216: if(blanking) tim[0] = 2*tim[1]-tim[2]; ! 217: tim[nframe+1] = 2*tim[nframe]-tim[nframe-1]; ! 218: ttim = (tim[nframe]-tim[1] + (tim[2]-tim[1]+tim[nframe]-tim[nframe-1])/2); ! 219: } ! 220: frame=blanking; ! 221: while(1){ /**** infinite loop ****/ ! 222: fx = frame%wid; ! 223: fy = wid-1 - (frame/wid)%wid; ! 224: fz = frame/(wid*wid); ! 225: pan(psx*fx,ps*fy+ny); ! 226: if(nframe==1) exit(0); ! 227: ring = (frame==0)? 500: (period*(tim[frame+1]-tim[frame-1])) / (2*ttim); ! 228: /* conceptually, display frame i from halfway between (i-1,i) until ! 229: halfway between (i,i+1). ring = delay time in ms. */ ! 230: ring = (ring*60)/1000; /* convert to 1/60 sec ticks */ ! 231: while( ring>=120 ){ ! 232: nap(119); ! 233: ring -= 119; ! 234: } ! 235: nap(ring); ! 236: if(++frame>nframe-1+blanking) frame = 0; ! 237: } ! 238: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.