Annotation of researchv10no/cmd/view2d/rks.c, revision 1.1.1.1

1.1       root        1: #include <stdio.h>
                      2: #include <math.h>
                      3: #include "view2d.h"
                      4: 
                      5: char *progname;
                      6: int fd;
                      7: int verbose;
                      8: 
                      9: main(argc, argv)
                     10:   char **argv;
                     11: {
                     12:   int i, j;
                     13:   int npts;
                     14:   int nx, ny;
                     15:   float f, v2;
                     16:   short u, v;
                     17:   float fmin, fmax, frange, grange, gmax, gmin;
                     18:   char buf[512];
                     19:   int hi, lo;
                     20:   double time;
                     21:   int firstime = 1;
                     22:   short *data, *d;
                     23:   int rmax, rmin, r;
                     24:   char *errfil;
                     25:   char *Malloc();
                     26:   double pow2();
                     27:   progname = argv[0];
                     28:   verbose = 0;
                     29:   if((argv[1][0]=='-')&&(argv[1][1]=='v')) verbose = 1;
                     30: 
                     31:   /* open error message file */
                     32:   umask(0);
                     33:   errfil="/tmp/rks.err";
                     34:   if(access(errfil,2)!=0) close(Creat(errfil,0666));
                     35:   freopen(errfil,"a",stderr);
                     36: 
                     37:   /* open output file */
                     38:   fd = Creat(argv[1+verbose],0666);
                     39: 
                     40:   while( gets(buf) != NULL ){
                     41:     if(buf[0]==0) continue;
                     42: 
                     43:     i = sscanf(buf, "%E %d %d %f %f\n", &time, &nx, &ny, &fmin, &fmax);
                     44:     if( i != 5 ) error("file scrambled. %d items in:%s\n",i,buf);
                     45:     if(verbose) fprintf(stderr, "\n%g %d %d %g %g\n", time, nx, ny, fmin, fmax);
                     46:     npts = nx*ny;
                     47:     if(firstime){
                     48:       data = (short *)Malloc(npts*sizeof(short));
                     49:       firstime = 0;
                     50:     }
                     51: 
                     52:     gmax = (fmax<0)?0:fmax;
                     53:     gmin = (fmin>0)?0:fmin;
                     54:     grange = gmax - gmin;
                     55:     frange = fmax - fmin;
                     56:     if(grange<=0){ v=0; u=0; v2=1;}
                     57:     else{
                     58:       f = 2*BIG-2;
                     59:       v = log(grange)/log(2.)-14;
                     60:       v2 = pow2(v);
                     61:       while( 2*grange < f*v2 ){ v--; v2 /= 2; }
                     62:       f = -(gmin+gmax)/(2*v2);
                     63:       u = f;
                     64:       if( (f<-BIG)||(f>BIG) ){
                     65:         fprintf(stderr,"fmin=%g fmax=%g u=%d v=%d\n",fmin,fmax,u,v);
                     66:         error("u out of bounds f=%g",f);
                     67:       }
                     68:     }
                     69: 
                     70:     rmax = -9999;
                     71:     rmin = 9999;
                     72:     for(d = data, i = 0; i < npts; i++, d++){
                     73:       hi = getchar()-33;
                     74:       if(hi < 0) hi = getchar()-33;  /* discard newline */
                     75:       lo = getchar()-33;
                     76:       if( (hi=='~'-33) && (lo=='~'-33) ){
                     77:         *d = -BIG-1;  /* out of bounds */
                     78:       }else{
                     79:         r = hi*64+lo;
                     80:         if(r>rmax) rmax=r;
                     81:         if(r<rmin) rmin=r;
                     82:         *d = u + (short)((fmin + (hi*64+lo)*frange/4095)/v2);
                     83:       }
                     84:     }
                     85:     if(verbose) fprintf(stderr,"rmin=%d rmax=%d\n",rmin,rmax);
                     86:     view2d(fd,nx,ny,time,u,v,0,0,0,data);
                     87:   }
                     88:   exit(0);
                     89: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.