|
|
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 = 0; ! 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, fd; ! 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: 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: if(!staticd){ ! 146: j = (4*nx>5*ny) ? (4*nx)/5 : ny; ! 147: if ( j>512 ){ zoom(0); } ! 148: else if( j>256 ){ zoom(1); } ! 149: else if( j>128 ){ zoom(3); } ! 150: else if( j> 64 ){ zoom(7); } ! 151: else { zoom(15); } ! 152: } ! 153: frame=blanking; ! 154: while(rd2di(&frtime,v)){ ! 155: if(verbose) fprintf(stderr,"time=%.9g frame %d\n",frtime,frame); ! 156: if(frame<200) tim[frame]=frtime; ! 157: if(coldstart!=0){ ! 158: fx = frame%wid; ! 159: fy = wid-1 - (frame/wid)%wid; ! 160: if(!(fy&1)) fx = wid-1 - fx; ! 161: fz = frame/(wid*wid); ! 162: if(singstep){ fx=0; fy=0; fz=0; } ! 163: if(fz>0) error("too many frames %d time=%g",frame,frtime); ! 164: p = pict; ! 165: q = v; ! 166: rmin = rd.pmin; ! 167: for(i=0; i<ny; i++){ ! 168: q = v+nx*(ny-1-i); ! 169: qend = q+nx; ! 170: for(; q<qend; q++){ ! 171: r = *q; ! 172: if( r < -BIG ){ *p = black; } ! 173: else{ ! 174: *p = ((r-rmin)*ncolor)/prange; ! 175: if(*p>=ncolor) *p = ncolor-1; ! 176: *p += 1; /* index 0 now is used for background */ ! 177: } ! 178: p++; ! 179: } ! 180: } ! 181: if(!staticd) pan(psx*fx,ps*fy+ny); ! 182: if(verbose>=2){ ! 183: fd = open("dump",1); ! 184: Write(fd,pict,nx*ny); ! 185: close(fd); ! 186: } ! 187: image(pict, psx*fx+(psx-nx)/2, ps*fy, ! 188: psx*fx+(psx-nx)/2 + nx-1, ps*fy + ny-1); ! 189: if(singstep){ ! 190: if(holly){ ! 191: sprintf(junk,"snap %d",holly); ! 192: system(junk); ! 193: }else if(terminal==NULL){ ! 194: fprintf(stderr,"time=%g frame %d\n",frtime,frame); ! 195: }else{ ! 196: fprintf(stderr,"time=%g frame %d GO? ",frtime,frame); ! 197: fgets(junk,100,terminal); ! 198: if((junk[0]=='s')||(junk[0]=='S')){ ! 199: system("snap"); ! 200: junk[0]=' '; ! 201: } ! 202: if(sscanf(junk,"%d",&j)==1){ ! 203: if(verbose) fprintf(stderr," skipping %d.. ",j); ! 204: frame += j-1; ! 205: rd2dj(j-1); ! 206: } ! 207: } ! 208: } ! 209: } ! 210: frame++; ! 211: } ! 212: nframe = frame-blanking; ! 213: if(verbose) fprintf(stderr,"%d frames\n%d colors\n",nframe,ncolor); ! 214: if(singstep||staticd){ exit(0); } ! 215: ! 216: if(nframe>1){ ! 217: if(nframe>200) nframe = 200; ! 218: period *= 1000; /* convert to milliseconds */ ! 219: ttim = (tim[nframe]-tim[blanking]); ! 220: if(ttim<=0){ /* if user gave unreasonable times, fake it */ ! 221: for(i=blanking+1; i<=nframe; i++){ ! 222: tim[i] = tim[i-1]+1; ! 223: } ! 224: } ! 225: if(blanking) tim[0] = 2*tim[1]-tim[2]; ! 226: tim[nframe+1] = 2*tim[nframe]-tim[nframe-1]; ! 227: ttim = (tim[nframe]-tim[1] + (tim[2]-tim[1]+tim[nframe]-tim[nframe-1])/2); ! 228: } ! 229: frame=blanking; ! 230: while(1){ /**** infinite loop ****/ ! 231: fx = frame%wid; ! 232: fy = wid-1 - (frame/wid)%wid; ! 233: if(!(fy&1)) fx = wid-1 - fx; ! 234: fz = frame/(wid*wid); ! 235: pan(psx*fx,ps*fy+ny); ! 236: if(nframe==1) exit(0); ! 237: ring = (frame==0)? 500: (period*(tim[frame+1]-tim[frame-1])) / (2*ttim); ! 238: /* conceptually, display frame i from halfway between (i-1,i) until ! 239: halfway between (i,i+1). ring = delay time in ms. */ ! 240: ring = (ring*60)/1000; /* convert to 1/60 sec ticks */ ! 241: while( ring>=120 ){ ! 242: nap(119); ! 243: ring -= 119; ! 244: } ! 245: nap(ring); ! 246: if(++frame>nframe-1+blanking) frame = 0; ! 247: } ! 248: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.