int main(int argc, char **argv) { char *tmpdir ; /* directory path for tmp files */ cwp_Bool istmpdir=cwp_false ; /* true for user given path */ float *hedr ; /* the headers */ float *data ; /* the data */ int nt ; /* number of trace samples */ float dt ; /* sample interval, sec */ float delrt ; /* delay recording time, sec */ cwp_String key[SU_NKEYS] ; /* array of keywords */ cwp_String type ; /* key string type */ int nkeys ; /* number of keywords */ int ikey,ntr = 0 ; /* counters */ int num ; /* number of traces to dump */ int numtr = 4 ; /* number of traces to dump */ int hpf ; /* header print format */ /* Initialize */ initargs(argc, argv) ; requestdoc(1) ; /* Look for user-supplied tmpdir */ if (!getparstring("tmpdir",&tmpdir) && !(tmpdir = getenv("CWP_TMPDIR"))) tmpdir=""; if (!STREQ(tmpdir, "") && access(tmpdir, WRITE_OK)) err("you can't write in %s (or it doesn't exist)", tmpdir); /* Get values from first trace */ if (!gettr(&tr)) err("can't get first trace"); nt = (int) tr.ns ; /* Get nt */ dt = ((double) tr.dt)/1000000.0 ; /* microsecs to secs */ if (!dt) getparfloat("dt", &dt) ; if (!dt) MUSTGETPARFLOAT("dt", &dt) ; delrt = ((double) tr.delrt)/1000.0 ; /* millisecs to secs */ /* Get parameters */ if (getparint ("num", &num)) numtr = num ; if ((nkeys=countparval("key"))!=0) getparstringarray("key",key) ; hedr = ealloc1float(nkeys*numtr) ; /* make space for headers */ if (!getparint ("hpf", &hpf)) hpf = 0 ; /* Store traces, headers in tempfiles */ if (STREQ(tmpdir,"")) { tracefp = etmpfile(); headerfp = etmpfile(); do { ++ntr; efwrite(&tr, HDRBYTES, 1, headerfp); efwrite(tr.data, FSIZE, nt, tracefp); /* Get header values */ for (ikey=0; ikey<nkeys; ++ikey) { Value val; float fval; gethdval(&tr, key[ikey], &val) ; type = hdtype(key[ikey]) ; fval = vtof(type,val) ; hedr[(ntr-1)*nkeys+ikey] = fval ; } } while (ntr<numtr && gettr(&tr)) ; } else /* user-supplied tmpdir */ { char directory[BUFSIZ]; strcpy(directory, tmpdir); strcpy(tracefile, temporary_filename(directory)); strcpy(headerfile, temporary_filename(directory)); /* Handle user interrupts */ signal(SIGINT, (void (*) (int)) closefiles); signal(SIGQUIT, (void (*) (int)) closefiles); signal(SIGHUP, (void (*) (int)) closefiles); signal(SIGTERM, (void (*) (int)) closefiles); tracefp = efopen(tracefile, "w+"); headerfp = efopen(headerfile, "w+"); istmpdir=cwp_true; do { ++ntr; efwrite(&tr, HDRBYTES, 1, headerfp); efwrite(tr.data, FSIZE, nt, tracefp); /* Get header values */ for (ikey=0; ikey<nkeys; ++ikey) { Value val; float fval; gethdval(&tr, key[ikey], &val) ; type = hdtype(key[ikey]) ; fval = vtof(type,val) ; hedr[(ntr-1)*nkeys+ikey] = fval ; } } while (ntr<numtr && gettr(&tr)) ; } /* Rewind after read, allocate space */ erewind(tracefp); erewind(headerfp); data = ealloc1float(nt*ntr); /* Load traces into data and close tmpfile */ efread(data, FSIZE, nt*ntr, tracefp); efclose(tracefp); if (istmpdir) eremove(tracefile); rewind(headerfp); rewind(tracefp); /* Do trace work */ dump(data, dt, hedr, key, delrt, nkeys, ntr, nt, hpf) ; /* close */ efclose(headerfp); if (istmpdir) eremove(headerfile); free1(hedr) ; free1(data) ; return(CWP_Exit()) ; }
int main( int argc, char *argv[] ) { cwp_String keyg; /* header key word from segy.h */ cwp_String typeg; /* ... its type */ Value valg; cwp_String key[SU_NKEYS]; /* array of keywords */ cwp_String type[SU_NKEYS]; /* array of keywords */ int index[SU_NKEYS]; /* name of type of getparred key */ segy **rec_o; /* trace header+data matrix */ int first=0; /* true when we passed the first gather */ int ng=0; float dt; /* time sampling interval */ int nt; /* number of time samples per trace */ int ntr; /* number of traces per ensemble */ int nfft=0; /* lenghth of padded array */ float snfft; /* scale factor for inverse fft */ int nf=0; /* number of frequencies */ float d1; /* frequency sampling int. */ float *rt; /* real trace */ complex *ctmix; /* complex trace */ complex **fd; /* frequency domain data */ float padd; int nd; /* number of dimensions */ float *dx=NULL; float fac; float vmin; int vf; /* Trimming arrays */ float *itrm=NULL; float *rtrm=NULL; float *wht=NULL; float trimp=15; /* Initialize */ initargs(argc, argv); requestdoc(1); if (!getparstring("keyg", &keyg)) keyg ="ep"; if (!getparint("vf", &vf)) vf = 1; if (!getparfloat("vmin", &vmin)) vmin = 5000; if (!getparfloat("padd", &padd)) padd = 25.0; padd = 1.0+padd/100.0; /* Get "key" values */ nd=countparval("key"); getparstringarray("key",key); /* get types and indexes corresponding to the keys */ { int ikey; for (ikey=0; ikey<nd; ++ikey) { type[ikey]=hdtype(key[ikey]); index[ikey]=getindex(key[ikey]); } } dx = ealloc1float(nd); MUSTGETPARFLOAT("dx",(float *)dx); if (!getparfloat("fac", &fac)) fac = 1.0; fac = MAX(fac,1.0); /* get the first record */ rec_o = get_gather(&keyg,&typeg,&valg,&nt,&ntr,&dt,&first); if(ntr==0) err("Can't get first record\n"); /* set up the fft */ nfft = npfar(nt*padd); if (nfft >= SU_NFLTS || nfft >= PFA_MAX) err("Padded nt=%d--too big", nfft); nf = nfft/2 + 1; snfft=1.0/nfft; d1 = 1.0/(nfft*dt); rt = ealloc1float(nfft); ctmix = ealloc1complex(nf); do { ng++; fd = ealloc2complex(nf,ntr); memset( (void *) ctmix, (int) '\0', nf*sizeof(complex)); itrm = ealloc1float(ntr); rtrm = ealloc1float(ntr); wht = ealloc1float(ntr); /* transform the data into FX domain */ { unsigned int itr; for(itr=0;itr<ntr;itr++) { memcpy( (void *) rt, (const void *) (*rec_o[itr]).data,nt*FSIZE); memset( (void *) &rt[nt], (int) '\0', (nfft - nt)*FSIZE); pfarc(1, nfft, rt, fd[itr]); } } /* Do the mixing */ { unsigned int imx=0,itr,ifr; float dist; /* Find the trace to mix */ for(itr=0;itr<ntr;itr++) if((*rec_o[itr]).mark) { imx = itr; break; } memcpy( (void *) ctmix, (const void *) fd[imx],nf*sizeof(complex)); /* Save the header */ memcpy( (void *) &tr, (const void *) rec_o[imx],HDRBYTES); /* weights */ wht[imx] = 1.0; for(itr=0;itr<imx;itr++) { dist=n_distance(rec_o,index,type,dx,nd,imx,itr); wht[itr] = MIN(1.0/dist,1.0); wht[itr] = 1.0; } for(itr=imx+1;itr<ntr;itr++) { dist=n_distance(rec_o,index,type,dx,nd,imx,itr); wht[itr] = MIN(1.0/dist,1.0); wht[itr] = 1.0; } /* Do the alpha trim for each trace */ for(ifr=0;ifr<nf;ifr++) { for(itr=0;itr<ntr;itr++) { itrm[itr] = fd[itr][ifr].i; rtrm[itr] = fd[itr][ifr].r; } ctmix[ifr].i = alpha_trim_w(itrm,wht,ntr,trimp); ctmix[ifr].r = alpha_trim_w(rtrm,wht,ntr,trimp); } } { unsigned int it; pfacr(-1, nfft, ctmix, rt); for(it=0;it<nt;it++) tr.data[it]=rt[it]*snfft; } free2complex(fd); { unsigned int itr; for(itr=0;itr<ntr;itr++) { free1((void *)rec_o[itr]); } } puttr(&tr); rec_o = get_gather(&keyg,&typeg,&valg,&nt,&ntr,&dt,&first); fprintf(stderr," %d %d\n",ng,ntr); free1float(rtrm); free1float(itrm); free1float(wht); } while(ntr); free1float(rt); warn("Number of gathers %10d\n",ng); return EXIT_SUCCESS; }
int main(int argc, char **argv) { cwp_String key[SU_NKEYS]; /* array of keywords */ cwp_String type[SU_NKEYS]; /* array of keywords */ int index[SU_NKEYS]; /* name of type of getparred key */ int ikey; /* key counter */ int nkeys; /* number of header fields set */ int count=0; /* number of header fields from file */ double i; /* parameters for computing fields */ int itr = 0; /* trace counter */ Value val; /* value of key field */ char *infile=""; /* name of input file of header values */ FILE *infp=NULL; /* pointer to input file */ cwp_Bool from_file=cwp_false; /* is the data from infile? */ float *afile=NULL; /* array of "a" values from file */ double *a=NULL; /* array of "a" values */ double *b=NULL; /* array of "b" values */ double *c=NULL; /* array of "c" values */ double *d=NULL; /* array of "d" values */ double *j=NULL; /* array of "j" values */ int n; /* number of a,b,c,d,j values */ /* Initialize */ initargs(argc, argv); requestdoc(1); /* Get "key" values */ if ((nkeys=countparval("key"))!=0) { getparstringarray("key",key); } else { key[0]="cdp"; } /* get types and indexes corresponding to the keys */ for (ikey=0; ikey<nkeys; ++ikey) { type[ikey]=hdtype(key[ikey]); index[ikey]=getindex(key[ikey]); } /* get name of infile */ getparstring("infile",&infile); /* if infile is specified get specified keys from file */ if (*infile!='\0') { /* open infile */ if((infp=efopen(infile,"r"))==NULL) err("cannot open infile=%s\n",infile); /* set from_file flag */ from_file=cwp_true; } /* If not from file, getpar a,b,c,d,j */ if (!from_file) { /* get "a" values */ if ((n=countparval("a"))!=0) { if (n!=nkeys) err("number of a values not equal to number of keys"); a=ealloc1double(n); getpardouble("a",a); } else { a=ealloc1double(nkeys); for (ikey=0; ikey<nkeys; ++ikey) a[ikey]=0.; } /* get "b" values */ if ((n=countparval("b"))!=0) { if (n!=nkeys) err("number of b values not equal to number of keys"); b=ealloc1double(n); getpardouble("b",b); } else { b=ealloc1double(nkeys); for (ikey=0; ikey<nkeys; ++ikey) b[ikey]=0.; } /* get "c" values */ if ((n=countparval("c"))!=0) { if (n!=nkeys) err("number of c values not equal to number of keys"); c=ealloc1double(n); getpardouble("c",c); } else { c=ealloc1double(nkeys); for (ikey=0; ikey<nkeys; ++ikey) c[ikey]=0.; } /* get "d" values */ if ((n=countparval("d"))!=0) { if (n!=nkeys) err("number of d values not equal to number of keys"); d=ealloc1double(n); getpardouble("d",d); } else { d=ealloc1double(nkeys); for (ikey=0; ikey<nkeys; ++ikey) d[ikey]=0.; } /* get "j" values */ if ((n=countparval("j"))!=0) { if (n!=nkeys) err("number of j values not equal to number of keys"); j=ealloc1double(n); getpardouble("j",j); /* make sure that j!=0 */ for (ikey=0; ikey<nkeys; ++ikey) if(j[ikey]==0) j[ikey]=ULONG_MAX; } else { j=ealloc1double(nkeys); for (ikey=0; ikey<nkeys; ++ikey) j[ikey]=ULONG_MAX; } } else { /* if reading from a file */ /* allocate space for afile */ afile=ealloc1float(nkeys); } checkpars(); /* loop over traces */ while (gettr(&tr)) { if (from_file) { /* use the "a" value from file to trace by trace */ if (efread(afile,FSIZE,nkeys,infp)!=0) { for (ikey=0; ikey<nkeys; ++ikey) { double a_in; a_in=(double) afile[ikey]; setval(type[ikey],&val,a_in, 0,0,0,ULONG_MAX); puthval(&tr,index[ikey],&val); ++count; } } } else { /* use getparred values of a,b,c,d,j */ for (ikey=0; ikey<nkeys; ++ikey) { i = (double) itr + d[ikey]; setval(type[ikey],&val,a[ikey],b[ikey], c[ikey],i,j[ikey]); puthval(&tr,index[ikey],&val); } } ++itr; puttr(&tr); } if (from_file) { efclose(infp); if (count < (int)(itr*nkeys) ) { warn("itr=%d > count=%d %s",(int) itr*count,count); warn("n traces=%d > data count =%d",(itr*nkeys),count); } } return(CWP_Exit()); }
int main(int argc, char **argv) { cwp_String key[SU_NKEYS]; /* array of keywords */ cwp_String type[SU_NKEYS]; /* array of types for key */ int index[SU_NKEYS]; /* array of indexes for key */ int ikey; /* key counter */ int nkeys; /* number of header fields set */ int n; /* number of min,max values */ Value val; /* value of key field */ double fval; /* value of key field */ float *min=NULL; /* array of "min" values */ float *max=NULL; /* array of "max" values */ /* Initialize */ initargs(argc, argv); requestdoc(1); /* Get "key" values */ if ((nkeys=countparval("key"))!=0) { getparstringarray("key",key); } else { key[0]="cdp"; } /* get types and indexes corresponding to the keys */ for (ikey=0; ikey<nkeys; ++ikey) { type[ikey]=hdtype(key[ikey]); index[ikey]=getindex(key[ikey]); } /* get "min" values */ if ((n=countparval("min"))!=0) { if (n!=nkeys) err("number of a values not equal to number of keys"); min=ealloc1float(n); getparfloat("min",min); } else { min=ealloc1float(nkeys); for (ikey=0; ikey<nkeys; ++ikey) min[ikey]=0.; } /* get "max" values */ if ((n=countparval("max"))!=0) { if (n!=nkeys) err("number of a values not equal to number of keys"); max=ealloc1float(n); getparfloat("max",max); } else { max=ealloc1float(nkeys); for (ikey=0; ikey<nkeys; ++ikey) max[ikey]=ULONG_MAX; } /* get types and index values */ for (ikey=0; ikey<nkeys; ++ikey) { type[ikey] = hdtype(key[ikey]); index[ikey] = getindex(key[ikey]); } while (gettr(&tr)) { for (ikey=0; ikey<nkeys; ++ikey) { gethval(&tr, index[ikey], &val); fval = vtof(type[ikey], val); if (fval < min[ikey]) { changeval(type[ikey], &val, min[ikey]); puthval(&tr, index[ikey], &val); } else if (fval > max[ikey]) { changeval(type[ikey], &val, max[ikey]); puthval(&tr, index[ikey], &val); } } puttr(&tr); } return(CWP_Exit()); }
int main (int argc, char **argv) { int n1,n2,n3,nbpe,perm,i1,i2,i3,verbose; char *v=NULL; char *tempstem=NULL, **tempdirs=NULL; int ntempdirs; char tmpstem[] = "foo"; char tmpdir[] = "/tmp"; FILE *infp=stdin,*outfp=stdout; VND *handle; long N[3] ; long key[3] ; /* hook up getpar */ initargs(argc,argv); requestdoc(1); /* get parameters */ if (!getparint("n1",&n1)) err("must specify n1!"); if (!getparint("n2",&n2)) err("must specify n2!"); ntempdirs = countparval("scratchdir"); if(ntempdirs > 0) { tempdirs = (char **) ealloc1(ntempdirs, sizeof(char *)); getparstringarray("scratchdir",tempdirs); } else { ntempdirs = 1; tempdirs = (char **) ealloc1(ntempdirs, sizeof(char *)); strcpy(tempdirs[0],tmpdir); } if (!getparstring("scratchstem",&tempstem)) tempstem = &tmpstem[0]; if (!getparint("nbpe",&nbpe)) nbpe = sizeof(float); if (!getparint("perm",&perm)) perm = 231; /* trace to time slice */ if (!getparint("n3",&n3)) { if (efseeko(infp,(off_t) 0,SEEK_END)==-1) err("input file size unknown; specify n3\n"); n3 = (int) (eftello(infp)/(((off_t)n1)*((off_t)n2)*((off_t)nbpe))); efseeko(infp, (off_t) 0,SEEK_SET); } verbose = 0; getparint("verbose",&verbose); if (verbose) warn("n1=%d n2=%d n3=%d nbpe=%d perm=%d\n",n1,n2,n3,nbpe,perm); /* allocate space for a single vector in any dimension */ v = ealloc1((n1+n2+n3),nbpe); /* allocate big matrix state */ N[0] = n1; N[1] = n2; N[2] = n3; handle = VNDop(2,200000000,3,N,1,nbpe,tempstem,ntempdirs,tempdirs,1); /* put vectors along 1st dimension to big matrix */ if (verbose) warn("Reading input file"); for (i3=0; i3<n3; i3++) { for (i2=0; i2<n2; i2++) { if (fread(v,1,nbpe*n1,infp)!=nbpe*n1) err("Error reading input file: i2=%d\n",i2); key[0] = 0; key[1] = i2; key[2] = i3; VNDrw('w',0,handle,0,key,0,v,0,1,n1,21,NULL); } } /* get vectors along 2nd dimension from big matrix */ if (verbose) warn("Writing output file"); switch(perm) { case 123: for (i3=0; i3<n3; i3++) { for (i2=0; i2<n2; i2++) { key[0] = 0; key[1] = i2; key[2] = i3; VNDrw('r',0,handle,0,key,0,v,0,1,n1,123,NULL); if (fwrite(v,1,nbpe*n1,outfp)!=nbpe*n1) err("Error writing output file: i2=%d i3=%d",i2,i3); } } break; case 132: for (i2=0; i2<n2; i2++) { for (i3=0; i3<n3; i3++) { key[0] = 0; key[1] = i2; key[2] = i3; VNDrw('r',0,handle,0,key,0,v,0,1,n1,132,NULL); if (fwrite(v,1,nbpe*n1,outfp)!=nbpe*n1) err("Error writing output file: i2=%d i3=%d",i2,i3); } } break; case 213: for (i3=0; i3<n3; i3++) { for (i1=0; i1<n1; i1++) { key[0] = i1; key[1] = 0; key[2] = i3; VNDrw('r',0,handle,1,key,0,v,0,1,n2,213,NULL); if (fwrite(v,1,nbpe*n2,outfp)!=nbpe*n2) err("Error writing output file: i1=%d i3=%d",i1,i3); } } break; case 231: for (i1=0; i1<n1; i1++) { for (i3=0; i3<n3; i3++) { key[0] = i1; key[1] = 0; key[2] = i3; VNDrw('r',0,handle,1,key,0,v,0,1,n2,231,NULL); if (fwrite(v,1,nbpe*n2,outfp)!=nbpe*n2) err("Error writing output file: i1=%d i3=%d",i1,i3); } } break; case 312: for (i2=0; i2<n2; i2++) { for (i1=0; i1<n1; i1++) { key[0] = i1; key[1] = i2; key[2] = 0; VNDrw('r',0,handle,2,key,0,v,0,1,n3,312,NULL); if (fwrite(v,1,nbpe*n3,outfp)!=nbpe*n3) err("Error writing output file: i1=%d i2=%d",i1,i2); } } break; case 321: for (i1=0; i1<n1; i1++) { for (i2=0; i2<n2; i2++) { key[0] = i1; key[1] = i2; key[2] = 0; VNDrw('r',0,handle,2,key,0,v,0,1,n3,321,NULL); if (fwrite(v,1,nbpe*n3,outfp)!=nbpe*n3) err("Error writing output file: i1=%d i2=%d",i1,i2); } } break; default: err("Unrecognized transpose permutation %d",perm); } /* free big matrix state */ VNDcl(handle,1); if (verbose) warn("Transpose done!"); return(CWP_Exit()); }
int main (int argc, char **argv) { int n1,n2,n1tic,n2tic,nfloats,bbox[4], i1,i2,grid1,grid2,style, n1c,n2c,n1s,n2s,i1beg,i1end,i2beg,i2end,i1c,i2c, nz,iz,i1step,i2step,verbose,hls,bps, legend,ugrid=SOLID,lstyle=VERTLEFT,lz,lbegsup=0,lendsup=0,ln=256, lbbox[4], threecolor=0; /* BEREND, Schoenfelder */ int lnice; /* c liner */ float labelsize,titlesize,perc,clip,bperc,wperc,bclip,wclip, d1,f1,d2,f2,*z,*temp,zscale,zoffset,zi, xbox,ybox,width,height, x1beg,x1end,x2beg,x2end, x1min,x1max,x2min,x2max, d1num,f1num,d2num,f2num, p1beg,p1end,p2beg,p2end,matrix[6],colors[3][3], /* for 3 color mode */ d1s,d2s, lwidth,lheight,lx,ly,lbeg,lend,lmin=(float) FLT_MAX,lmax=(float) -FLT_MAX, ldnum,lfnum,ld,lf=0,labmatrix[6]; /* BEREND, Schoenfelder */ float axeswidth, ticwidth, gridwidth; unsigned char *cz,*czp,*sz,*data_legend=NULL; char *label1="",*label2="",*title="",*units="", *legendfont="times_roman10", *labelfont="Helvetica",*titlefont="Helvetica-Bold", *styles="seismic",*grid1s="none",*grid2s="none", *titlecolor="black",*axescolor="black",*gridcolor="black", *lstyles="vertleft",*lgrids="none"; FILE *infp=stdin; float **x1curve=NULL,**x2curve=NULL,*curvewidth=NULL; int i,j,curve=0,*npair=NULL,ncurvecolor=0,ncurvewidth=0,ncurvedash=0,*curvedash=NULL; char **curvecolor=NULL,**curvefile=NULL; FILE *curvefp=NULL; cwp_Bool is_curve = cwp_false; /* initialize getpar */ initargs(argc,argv); requestdoc(1); /* get parameters describing 1st dimension sampling */ if (!getparint("n1",&n1)) err("must specify n1!\n"); d1 = 1.0; getparfloat("d1",&d1); f1 = 0.0; getparfloat("f1",&f1); x1min = (d1>0.0)?f1:f1+(n1-1)*d1; x1max = (d1<0.0)?f1:f1+(n1-1)*d1; /* get parameters describing 2nd dimension sampling */ if (!getparint("n2",&n2)) { if (efseeko(infp,(off_t) 0,SEEK_END)!=0) err("must specify n2 if in a pipe!\n"); nfloats = (int) (eftello(infp)/((off_t) sizeof(float))); efseeko(infp,(off_t) 0,SEEK_SET); n2 = nfloats/n1; } d2 = 1.0; getparfloat("d2",&d2); f2 = 0.0; getparfloat("f2",&f2); x2min = (d2>0.0)?f2:f2+(n2-1)*d2; x2max = (d2<0.0)?f2:f2+(n2-1)*d2; /* read color parameters */ if (!getparint("threecolor",&threecolor)) threecolor=1; bps = 8; hls = 0; /* color[][0] is black, color[][2] is white in 2 color mode */ colors[R][0] = colors[G][0] = colors[B][0] = 0.0; colors[R][1] = colors[G][1] = colors[B][1] = 0.5; colors[R][2] = colors[G][2] = colors[B][2] = 1.0; if (countparval("brgb") || countparval("wrgb")) { float brgb[3],grgb[3],wrgb[3]; brgb[R] = brgb[G] = brgb[B] = 0.0; wrgb[R] = wrgb[G] = wrgb[B] = 1.0; getparfloat("brgb",&brgb[0]); getparfloat("wrgb",&wrgb[0]); grgb[R] = (brgb[R] + wrgb[R])/2.; grgb[G] = (brgb[G] + wrgb[G])/2.; grgb[B] = (brgb[B] + wrgb[B])/2.; if (threecolor==1) getparfloat("grgb",&grgb[0]); brgb[R] = MAX(0.0,MIN(1.0,brgb[R])); grgb[R] = MAX(0.0,MIN(1.0,grgb[R])); wrgb[R] = MAX(0.0,MIN(1.0,wrgb[R])); brgb[G] = MAX(0.0,MIN(1.0,brgb[G])); grgb[G] = MAX(0.0,MIN(1.0,grgb[G])); wrgb[G] = MAX(0.0,MIN(1.0,wrgb[G])); brgb[B] = MAX(0.0,MIN(1.0,brgb[B])); grgb[B] = MAX(0.0,MIN(1.0,grgb[B])); wrgb[B] = MAX(0.0,MIN(1.0,wrgb[B])); colors[R][0] = brgb[R]; colors[R][1] = grgb[R]; colors[R][2] = wrgb[R]; colors[G][0] = brgb[G]; colors[G][1] = grgb[G]; colors[G][2] = wrgb[G]; colors[B][0] = brgb[B]; colors[B][1] = grgb[B]; colors[B][2] = wrgb[B]; if (!getparint("bps",&bps)) bps = 12; if (bps!=12 && bps!=24) err("bps must equal 12 or 24 for color plots!\n"); } else if (countparval("bhls") || countparval("whls")) { float bhls[3],ghls[3],whls[3]; hls = 1; bhls[H] = ghls[H] = whls[H] = 0.0; bhls[L] = 0.0; ghls[L] = 0.5; whls[L] = 1.0; bhls[S] = ghls[S] = whls[S] = 0.0; getparfloat("bhls",&bhls[0]); getparfloat("whls",&whls[0]); ghls[H] = (bhls[H] + whls[H])/2.; ghls[L] = (bhls[L] + whls[L])/2.; ghls[S] = (bhls[S] + whls[S])/2.; if (threecolor==1) getparfloat("ghls",&ghls[0]); bhls[L] = MAX(0.0,MIN(1.0,bhls[L])); ghls[L] = MAX(0.0,MIN(1.0,ghls[L])); whls[L] = MAX(0.0,MIN(1.0,whls[L])); bhls[S] = MAX(0.0,MIN(1.0,bhls[S])); ghls[S] = MAX(0.0,MIN(1.0,ghls[S])); whls[S] = MAX(0.0,MIN(1.0,whls[S])); colors[H][0] = bhls[0]; colors[H][1] = ghls[0]; colors[H][2] = whls[0]; colors[L][0] = bhls[1]; colors[L][1] = ghls[1]; colors[L][2] = whls[1]; colors[S][0] = bhls[2]; colors[S][1] = ghls[2]; colors[S][2] = whls[2]; if (!getparint("bps",&bps)) bps = 12; if (bps!=12 && bps!=24) err("bps must equal 12 or 24 for color plots!\n"); } /* get legend specs BEREND, Schoenfelder */ legend = 0; getparint("legend", &legend); /* BEREND, Schoenfelder */ getparstring("units", &units); /* BEREND, Schoenfelder */ getparstring("legendfont", &legendfont); /* BEREND, Schoenfelder */ /* set up curve plotting */ if ((curve=countparval("curve"))!=0) { curvefile=(char**)ealloc1(curve,sizeof(void*)); getparstringarray("curve",curvefile); if ((x1curve=(float**)malloc(curve*sizeof(void*)))==NULL) err("Could not allocate x1curve pointers\n"); if ((x2curve=(float**)malloc(curve*sizeof(void*)))==NULL) err("Could not allocate x2curve pointers\n"); npair=ealloc1int(curve); getparint("npair",npair); is_curve = cwp_true; } else { npair=(int *)NULL; curvefile=(char **)NULL; x1curve=(float **)NULL; x2curve=(float **)NULL; is_curve = cwp_false; } if (is_curve) { if ((ncurvecolor=countparval("curvecolor"))<curve) { curvecolor=(char**)ealloc1(curve,sizeof(void*)); if (!getparstringarray("curvecolor",curvecolor)) { curvecolor[0]=(char *)cwp_strdup("black\0"); ncurvecolor=1; } for (i=ncurvecolor; i<curve; i++) curvecolor[i]=(char *)cwp_strdup(curvecolor[ncurvecolor-1]); } else if (ncurvecolor) { curvecolor=(char**)ealloc1(ncurvecolor,sizeof(void*)); getparstringarray("curvecolor",curvecolor); } for (j=0; j<curve; j++) { curvefp=efopen(curvefile[j],"r"); x1curve[j]=ealloc1float(npair[j]); x2curve[j]=ealloc1float(npair[j]); for (i=0; i<npair[j]; i++) { fscanf(curvefp,"%f",&x1curve[j][i]); fscanf(curvefp,"%f",&x2curve[j][i]); } efclose(curvefp); } } /* read binary data to be plotted */ nz = n1*n2; z = ealloc1float(nz); if (fread(z,sizeof(float),nz,infp)!=nz) err("error reading input file!\n"); /* if necessary, determine clips from percentiles */ if (getparfloat("clip",&clip)) { bclip = clip; wclip = -clip; } if ((!getparfloat("bclip",&bclip) || !getparfloat("wclip",&wclip)) && !getparfloat("clip",&clip)) { perc = 100.0; getparfloat("perc",&perc); temp = ealloc1float(nz); for (iz=0; iz<nz; iz++) temp[iz] = z[iz]; if (!getparfloat("bclip",&bclip)) { bperc = perc; getparfloat("bperc",&bperc); iz = (nz*bperc/100.0); if (iz<0) iz = 0; if (iz>nz-1) iz = nz-1; qkfind(iz,nz,temp); bclip = temp[iz]; } if (!getparfloat("wclip",&wclip)) { wperc = 100.0-perc; getparfloat("wperc",&wperc); iz = (nz*wperc/100.0); if (iz<0) iz = 0; if (iz>nz-1) iz = nz-1; qkfind(iz,nz,temp); wclip = temp[iz]; } free1float(temp); } verbose = 1; getparint("verbose",&verbose); if (verbose) warn("bclip=%g wclip=%g",bclip,wclip); /* get scaled sampling intervals */ d1s = 1.0; getparfloat("d1s",&d1s); d2s = 1.0; getparfloat("d2s",&d2s); d1s = fabs(d1s); d1s *= d1; d2s = fabs(d2s); d2s *= d2; /* get axes parameters */ xbox = 1.5; getparfloat("xbox",&xbox); /* if psimage is called by ximage, it */ ybox = 1.5; getparfloat("ybox",&ybox); /* will xbox=1.166 and ybox=1.167 */ width = 6.0; getparfloat("wbox",&width); getparfloat("width",&width); height = 8.0;getparfloat("hbox",&height);getparfloat("height",&height); /* begin c liner */ lnice = 0; getparint("lnice",&lnice); if (lnice==1) { ybox = 2.2; /* lx=8 is set below, after getpar on lx ... c liner */ width = 5.4; height = 7.2; } /* end c liner */ x1beg = x1min; getparfloat("x1beg",&x1beg); x1end = x1max; getparfloat("x1end",&x1end); d1num = 0.0; getparfloat("d1num",&d1num); f1num = x1min; getparfloat("f1num",&f1num); n1tic = 1; getparint("n1tic",&n1tic); getparstring("grid1",&grid1s); if (STREQ("dot",grid1s)) grid1 = DOT; else if (STREQ("dash",grid1s)) grid1 = DASH; else if (STREQ("solid",grid1s)) grid1 = SOLID; else grid1 = NONE; getparstring("label1",&label1); x2beg = x2min; getparfloat("x2beg",&x2beg); x2end = x2max; getparfloat("x2end",&x2end); d2num = 0.0; getparfloat("d2num",&d2num); f2num = 0.0; getparfloat("f2num",&f2num); n2tic = 1; getparint("n2tic",&n2tic); getparstring("grid2",&grid2s); if (STREQ("dot",grid2s)) grid2 = DOT; else if (STREQ("dash",grid2s)) grid2 = DASH; else if (STREQ("solid",grid2s)) grid2 = SOLID; else grid2 = NONE; getparstring("label2",&label2); getparstring("labelfont",&labelfont); labelsize = 18.0; getparfloat("labelsize",&labelsize); getparstring("title",&title); getparstring("titlefont",&titlefont); titlesize = 24.0; getparfloat("titlesize",&titlesize); getparstring("titlecolor",&titlecolor); getparstring("axescolor",&axescolor); getparstring("gridcolor",&gridcolor); /* axes and tic width */ if(!getparfloat("axeswidth",&axeswidth)) axeswidth=1; if (!getparfloat("ticwidth",&ticwidth)) ticwidth=axeswidth; if(!getparfloat("gridwidth",&gridwidth)) gridwidth =axeswidth; if (is_curve) { if ((ncurvewidth=countparval("curvewidth"))<curve) { curvewidth=ealloc1float(curve); if (!getparfloat("curvewidth",curvewidth)) { curvewidth[0]=axeswidth; ncurvewidth=1; } for (i=ncurvewidth; i<curve; i++) curvewidth[i]=curvewidth[ncurvewidth-1]; } else { curvewidth=ealloc1float(ncurvewidth); getparfloat("curvewidth",curvewidth); } if ((ncurvedash=countparval("curvedash"))<curve) { curvedash=ealloc1int(curve); if (!getparint("curvedash",curvedash)) { curvedash[0]=0; ncurvedash=1; } for (i=ncurvedash; i<curve; i++) curvedash[i]=curvedash[ncurvedash-1]; } else { curvedash=ealloc1int(ncurvedash); getparint("curvedash",curvedash); } } getparstring("style",&styles); if (STREQ("normal",styles)) style = NORMAL; else style = SEISMIC; /* Get or calc legend parameters */ /* Legend min and max: Calc from data read in */ if (legend) { for (lz=0;lz<nz;lz++) { lmin=FMIN(lmin,z[lz]); lmax=FMAX(lmax,z[lz]); } if (verbose==2) warn("lmin=%g lmax=%g",lmin,lmax); } if (legend) { lbeg = lmin; if (getparfloat("lbeg",&lbeg)) lbegsup=1; lend = lmax; if (getparfloat("lend",&lend)) lendsup=1; /* Change wclip,bclip to be inside legend range */ wclip = FMAX(lbeg,wclip); /* [wclip,bclip] has to be in [lbeg,lend] */ bclip = FMIN(lend,bclip); if (lbegsup!=1) { /* Add white and black areas to show possible clipping */ float rangeperc=(bclip-wclip)/20.; lbeg=wclip-rangeperc; } if (lendsup!=1) { float rangeperc=(bclip-wclip)/20.; lend=bclip+rangeperc; } lfnum = lmin; getparfloat("lfnum",&lfnum); getparstring("lstyle",&lstyles); if (STREQ("vertright",lstyles)) lstyle = VERTRIGHT; else if (STREQ("horibottom",lstyles)) lstyle = HORIBOTTOM; /* legend dimensions (BEREND), Schoenfelder */ lwidth = 0.1 ;lheight = height/2; if (lstyle==HORIBOTTOM) { lwidth=width/1.2 ;lheight = 0.24; } getparfloat("lwidth",&lwidth); getparfloat("lheight",&lheight); lx=.8;ly = ybox+(height-lheight)/2; if (lstyle==VERTRIGHT) { lx=xbox+width+0.1; } else if (lstyle==HORIBOTTOM) { lx=xbox+(width-lwidth)/2.0;ly = 1.0; } getparfloat("lx",&lx); if (lnice==1) lx = 8; /* c liner */ getparfloat("ly",&ly); getparstring("lgrid",&lgrids); if (STREQ("dot",lgrids)) ugrid = DOT; else if (STREQ("dash",lgrids)) ugrid = DASH; else if (STREQ("solid",lgrids)) ugrid = SOLID; else ugrid = NONE; } /* adjust x1beg and x1end to fall on sampled values */ /* This will not allow to display an area greater than the data supplied */ i1beg = NINT((x1beg-f1)/d1); i1beg = MAX(0,MIN(n1-1,i1beg)); x1beg = f1+i1beg*d1; i1end = NINT((x1end-f1)/d1); i1end = MAX(0,MIN(n1-1,i1end)); x1end = f1+i1end*d1; /* adjust x2beg and x2end to fall on sampled values */ i2beg = NINT((x2beg-f2)/d2); i2beg = MAX(0,MIN(n2-1,i2beg)); x2beg = f2+i2beg*d2; i2end = NINT((x2end-f2)/d2); i2end = MAX(0,MIN(n2-1,i2end)); x2end = f2+i2end*d2; if (legend) { /* Make legend color values */ int lll=0,lcount,perc5=13,ilbeg,ilend; /* color scale */ if (lbegsup!=1) { ln+=perc5; /* white area */ } if (lendsup!=1) { ln+=perc5; /* black area */ } data_legend = ealloc1(ln,sizeof(char)); if (lbegsup!=1) { for (lll=0;lll<perc5;lll++) data_legend[lll]=(char) 255; /* white area */ } for (lcount=255;lcount>=0;lcount--,lll++) data_legend[lll]=(char) lcount; if (lendsup!=1) { for (;lll<ln;lll++) data_legend[lll]=(char) 0; /* black area */ } lf=lbeg;ld=(lend-lbeg)/(ln-1); if (!(getparfloat("ldnum",&ldnum))) ldnum=0.0; /* adjust lbeg and lend to fall on sampled values */ ilbeg = NINT((lbeg-lf)/ld); ilbeg = MAX(0,MIN(ln-1,ilbeg)); lbeg = lf+ilbeg*ld; ilend = NINT((lend-lf)/ld); ilend = MAX(0,MIN(ln-1,ilend)); lend = lf+ilend*ld; } /* allocate space for image bytes */ n1c = 1+abs(i1end-i1beg); n2c = 1+abs(i2end-i2beg); cz = ealloc1(n1c*n2c,sizeof(char)); /* convert data to be imaged into unsigned characters */ zscale = (wclip!=bclip)?255.0/(wclip-bclip):1.0e10; zoffset = -bclip*zscale; i1step = (i1end>i1beg)?1:-1; i2step = (i2end>i2beg)?1:-1; czp = cz; for (i1c=0,i1=i1beg; i1c<n1c; i1c++,i1+=i1step) { for (i2c=0,i2=i2beg; i2c<n2c; i2c++,i2+=i2step) { zi = zoffset+z[i1+i2*n1]*zscale; if (zi<0.0) zi = 0.0; if (zi>255.0) zi = 255.0; *czp++ = (unsigned char)zi; } } free1float(z); /* determine sampling after scaling */ n1s = MAX(1,NINT(1+(n1c-1)*d1/d1s)); d1s = (n1s>1)?d1*(n1c-1)/(n1s-1):d1; n2s = MAX(1,NINT(1+(n2c-1)*d2/d2s)); d2s = (n2s>1)?d2*(n2c-1)/(n2s-1):d2; /* if necessary, interpolate to scaled sampling intervals */ if (n1s!=n1c || n2s!=n2c) { sz = ealloc1(n1s*n2s,sizeof(char)); intl2b(n2c,d2,0.0,n1c,d1,0.0,cz,n2s,d2s,0.0,n1s,d1s,0.0,sz); /* Interpol array */ free1(cz); } else { sz = cz; } /* determine axes pads */ p1beg = (x1end>x1beg)?-fabs(d1s)/2:fabs(d1s)/2; p1end = (x1end>x1beg)?fabs(d1s)/2:-fabs(d1s)/2; p2beg = (x2end>x2beg)?-fabs(d2s)/2:fabs(d2s)/2; p2end = (x2end>x2beg)?fabs(d2s)/2:-fabs(d2s)/2; /* convert axes box parameters from inches to points */ xbox *= 72.0; ybox *= 72.0; width *= 72.0; height *= 72.0; if (legend) { lx *= 72.0; /* Schoenfelder */ ly *= 72.0; /* Schoenfelder */ lwidth *= 72.0; /* Schoenfelder */ lheight *= 72.0; /* Schoenfelder */ } /* set bounding box */ psAxesBBox( xbox,ybox,width,height, labelfont,labelsize, titlefont,titlesize, style,bbox); if (legend) { psLegendBBox( /* Space for legend Schoenfelder */ lx,ly,lwidth,lheight, labelfont,labelsize, lstyle,lbbox); /* Include space for legend Schoenfelder */ bbox[0]=MIN(bbox[0],lbbox[0]); bbox[1]=MIN(bbox[1],lbbox[1]); bbox[2]=MAX(bbox[2],lbbox[2]); bbox[3]=MAX(bbox[3],lbbox[3]); } boundingbox(bbox[0],bbox[1],bbox[2],bbox[3]); /* begin PostScript */ begineps(); /* save graphics state */ gsave(); /* translate coordinate system by box offset */ translate(xbox,ybox); /* determine image matrix */ if (style==NORMAL) { matrix[0] = 0; matrix[1] = n1s; matrix[2] = n2s; matrix[3] = 0; matrix[4] = 0; matrix[5] = 0; } else { matrix[0] = n2s; matrix[1] = 0; matrix[2] = 0; matrix[3] = -n1s; matrix[4] = 0; matrix[5] = n1s; } scale(width,height); /* draw the image (before axes so grid lines are visible) */ drawimage(hls,colors,n2s,n1s,bps,matrix,sz); /***************************/ /* main image has been drawn, restore graphics state */ grestore(); /* *********************************/ /* draw the colorbar (before axes so grid lines are visible) Schoenfelder*/ if (legend) { gsave(); translate(lx,ly); scale(lwidth,lheight); if ((lstyle==VERTLEFT) || (lstyle==VERTRIGHT)) { labmatrix[0] = 1; labmatrix[1] = 0; labmatrix[2] = 0; labmatrix[3] = ln; labmatrix[4] = 0; labmatrix[5] = 0; drawimage(hls,colors,1,ln,bps,labmatrix,data_legend); } else { labmatrix[0] = -1; labmatrix[1] = 0; labmatrix[2] = 0; labmatrix[3] = ln; labmatrix[4] = 0; labmatrix[5] = 0; rotate(-90); drawimage(hls,colors,1,ln,bps,labmatrix,data_legend); rotate(90); } grestore(); } /* draw curve */ for (i=0; i<curve; i++) { gsave(); psDrawCurve( xbox,ybox,width,height, x1beg,x1end,p1beg,p1end, x2beg,x2end,p2beg,p2end, x1curve[i],x2curve[i],npair[i], curvecolor[i],curvewidth[i],curvedash[i],style); grestore(); } gsave(); /* draw axes and title */ psAxesBox( xbox,ybox,width,height, x1beg,x1end,p1beg,p1end, d1num,f1num,n1tic,grid1,label1, x2beg,x2end,p2beg,p2end, d2num,f2num,n2tic,grid2,label2, labelfont,labelsize, title,titlefont,titlesize, titlecolor,axescolor,gridcolor, ticwidth,axeswidth,gridwidth, style); /* restore graphics state */ grestore(); /* draw axes and title for legend Schoenfelder*/ if (legend) { float lpbeg,lpend; int lntic=1; gsave(); lpbeg = 0.0; /*(lend>lbeg)?-fabs(d1s)/2:fabs(d1s)/2;*/ lpend = 0.0; /*(lend>lbeg)?fabs(d1s)/2:-fabs(d1s)/2;*/ psLegendBox( lx,ly,lwidth,lheight, lbeg,lend,lpbeg,lpend, ldnum,lf,lntic,ugrid,units, labelfont,labelsize, axescolor,gridcolor, lstyle); grestore(); } /* end PostScript */ showpage(); endeps(); if (curve) { free1int(npair); for (i=0; i<curve; i++) { free1float(x1curve[i]); free1float(x2curve[i]); } free1float(curvewidth); free1int(curvedash); free((void**)x1curve); free((void**)x2curve); free((void**)curvefile); free((void**)curvecolor); } return 0; }