main(int argc, char **argv) { String key; /* header key word from segy.h */ String type; /* ... its type */ int index; /* ... its index in hdr.h */ Value val; /* ... its value */ void absval(String type, Value *valp); /* Initialize */ initargs(argc, argv); askdoc(1); /* Get key parameter */ if (!getparstring("key", &key)) key = KEY; file2g(stdin); file2g(stdout); type = hdtype(key); index = getindex(key); while (gettr(&tr)) { gethval(&tr, index, &val); absval(type, &val); puthval(&tr, index, &val); puttr(&tr); } return EXIT_SUCCESS; }
main(int argc, char **argv) { String key; String type; int index; double a, c, b, d, i, j; int itr = 0; Value val; FILE *infp=stdin, *outfp=stdout; /* Initialize */ initargs(argc, argv); requestdoc(1); /* Get parameters */ if (!getparstring("key", &key)) key = "cdp"; if (!getpardouble("a" , &a)) a = 0; if (!getpardouble("b" , &b)) b = 0; if (!getpardouble("c" , &c)) c = 0; if (!getpardouble("d" , &d)) d = 0; if (!getpardouble("j" , &j)) j = ULONG_MAX; type = hdtype(key); index = getindex(key); file2g(infp); file2g(outfp); while (gettr(&tr)) { i = (double) itr++ + d; setval(type, &val, a, b, c, i, j); puthval(&tr, index, &val); puttr(&tr); } return EXIT_SUCCESS; }
int main(int argc, char **argv) { cwp_String key1,key2,key3; /* panel/trace/flag key */ cwp_String type1,type2,type3; /* type for panel/trace/flag key*/ int index1,index2,index3; /* indexes for key1/2/3 */ Value val1,val2,val3; /* value of key1/2/3 */ double dval1=0.0,dval2=0.0,dval3=0.0; /* value of key1/2/3 */ double c; /* trace key spacing */ double dmin,dmax,dx; /* trace key start/end/spacing */ double panelno=0.0,traceno=0.0; int nt; /* number of samples per trace */ int isgn; /* sort order */ int iflag; /* internal flag: */ /* -1 exit */ /* 0 regular mode */ /* 1 first time */ /* 2 trace out of range */ /* initialize */ initargs(argc, argv); requestdoc(1); /* get parameters */ if (!getparstring("key1", &key1)) key1 = "ep"; if (!getparstring("key2", &key2)) key2 = "tracf"; if (!getparstring("key3", &key3)) key3 = "trid"; if (!getpardouble("val3", &dval3)) dval3 = 2.; if (!getpardouble("d", &dx)) dx = 1.; if (!getpardouble("min", &dmin)) err("need lower panel boundary MIN"); if (!getpardouble("max", &dmax)) err("need upper panel boundary MAX"); checkpars(); /* check parameters */ if (dx==0) err("trace spacing d cannot be zero"); if (dmax<dmin) err("max needs to be greater than min"); if (dx<0) { isgn = -1; } else { isgn = 1; } /* get types and index values */ type1 = hdtype(key1); type2 = hdtype(key2); type3 = hdtype(key3); index1 = getindex(key1); index2 = getindex(key2); index3 = getindex(key3); /* loop over traces */ iflag = 1; while (iflag>=0) { if (gettr(&tr)) { /* get header values */ gethval(&tr, index1, &val1); gethval(&tr, index2, &val2); dval1 = vtod(type1, val1); dval2 = vtod(type2, val2); /* Initialize zero trace */ nt = tr.ns; memset( (void *) nulltr.data, 0, nt*FSIZE); if ( iflag==1 ) { panelno = dval1; traceno = dmin - dx; } iflag = 0; if ( dval2<dmin || dval2>dmax ) iflag = 2; /* fprintf(stderr,"if=%d, dmin=%8.0f, dmax=%8.0f\n",iflag,dmin,dmax);*/ } else { iflag = -1; /* exit flag */ } /* fprintf(stderr,"if=%d, dval1=%8.0f, dval2=%8.0f\n",iflag,dval1,dval2);*/ /* if new panel or last trace --> finish the previous panel */ if ( panelno!=dval1 || iflag==-1 ) { /* fprintf(stderr,"finish previous\n");*/ for (c=traceno+dx; isgn*c<=isgn*dmax; c=c+dx) { assgnval(type2, &val2, c); puthval(&nulltr, index2, &val2); assgnval(type3, &val3, dval3); puthval(&nulltr, index3, &val3); puttr(&nulltr); } traceno = dmin - dx; /* reset to pad present panel */ panelno = dval1; /* added by Ted Stieglitz 28Nov2012*/ } /* if trace within boundaries --> pad the present panel */ if ( iflag==0 ) { /* fprintf(stderr,"pad present, trn=%5.0f,dval2=%5.0f\n",traceno,dval2);*/ memcpy( (void *) &nulltr, (const void *) &tr, 240); for (c=traceno+dx; isgn*c<isgn*dval2; c=c+dx) { assgnval(type2, &val2, c); puthval(&nulltr, index2, &val2); assgnval(type3, &val3, dval3); puthval(&nulltr, index3, &val3); puttr(&nulltr); } } /* write the present trace and save header indices */ if ( iflag==0 ) { puttr(&tr); panelno = dval1; traceno = dval2; } } return(CWP_Exit()); }
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()); }
void intout(float *xi, float *xo, float *yo, char *hdrs, int nxi, int nxo, int nt, FILE *outfp, int extrap, String hdtp, int index) { segytrace tro, tr1, tr2; float tmp, res, ftmp; int one=1, indx, itmp, ix, it; float sx, gx, sy, gy, mx, my, dd, ofo; Value val; /* output interpolated result */ for(ix=0;ix<nxo;ix++) { for(it=0;it<nt;it++) tro.data[it]=yo[it+ix*nt]; tmp = xo[ix]; bisear_(&nxi,&one,xi,&tmp,&indx); if(tmp<=xi[0]) { itmp = 1; bcopy(hdrs,(char*)&tro,HDRBYTES); } else if(tmp>=xi[nxi-1]) { itmp = nxi-1; bcopy(hdrs+(nxi-1)*HDRBYTES, (char*)&tro,HDRBYTES); } else { if(indx==nxi) indx=indx-1; itmp = indx; if(abs(tmp-xi[itmp-1])<abs(tmp-xi[itmp])) { bcopy(hdrs+(itmp-1)*HDRBYTES, (char*)&tro,HDRBYTES); } else { bcopy(hdrs+itmp*HDRBYTES, (char*)&tro,HDRBYTES); } } bcopy(hdrs+(itmp-1)*HDRBYTES,(char*)&tr1, HDRBYTES); bcopy(hdrs+itmp*HDRBYTES,(char*)&tr2, HDRBYTES); res = (tmp-xi[itmp-1])/(xi[itmp]-xi[itmp-1]); ftmp = tr1.cdp + res*(tr2.cdp-tr1.cdp) + .5; tro.cdp = ftmp; ftmp = tr1.mute + res*(tr2.mute-tr1.mute) + .5; tro.mute = ftmp; ftmp = tr1.sx + res*(tr2.sx-tr1.sx) + .5; tro.sx = ftmp; ftmp = tr1.sy + res*(tr2.sy-tr1.sy) + .5; tro.sy = ftmp; ftmp = tr1.gx + res*(tr2.gx-tr1.gx) + .5; tro.gx = ftmp; ftmp = tr1.gy + res*(tr2.gy-tr1.gy) + .5; tro.gy = ftmp; /* if offsets are the same sign, linearly interpolate to get the output offset; otherwise, use the closest trace's offset */ if(tr1.offset*tr2.offset >= 0.) { ftmp = tr1.offset + res*(tr2.offset-tr1.offset) + .5; tro.offset = ftmp; } if(abs(tmp-xi[itmp-1])<0.1 || abs(tmp-xi[itmp])<0.1) { tro.duse = 1; } else { tro.duse = 2; } changeval(hdtp,&val,xo[ix]); puthval(&tro, index, &val); /* need to adjust (x,y) of source and receiver, with the new offset for pre-stack migration */ sx = tro.sx; sy = tro.sy; gx = tro.gx; gy = tro.gy; mx = (sx+gx)/2.; my = (sy+gy)/2.; dd = sqrt((sx-gx)*(sx-gx)+(sy-gy)*(sy-gy)); if(tro.scalco>1) { dd = dd * tro.scalco; } else if(tro.scalco<0) { dd = - dd / tro.scalco; } ofo = tro.offset; if(ofo<0) ofo = - ofo; if (dd>0.) { tro.sx = mx+(tro.sx-mx)*ofo/dd; tro.gx = mx+(tro.gx-mx)*ofo/dd; tro.sy = my+(tro.sy-my)*ofo/dd; tro.gy = my+(tro.gy-my)*ofo/dd; } else { tro.sx = mx-ofo/2; tro.gx = mx-ofo/2; tro.sy = my; tro.gy = my; } if(xi[0]-tmp>0.1 || tmp-xi[nxi-1]>0.1 ) { if(extrap==0) { tro.trid = 2; bzero(tro.data,nt*sizeof(float)); } } fputtr(outfp,&tro); } }