Ejemplo n.º 1
0
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());
}
Ejemplo n.º 2
0
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); 
	}
}