Ejemplo n.º 1
0
int
main(int argc, char **argv)
{
	int j,nt,flag,ntout;
	float *buf,*ttn,dt,dtout=0.0,tmin,tmax;

	/* Initialize */
	initargs(argc, argv);
	requestdoc(1);

	/* Get information from the first header */
	if (!gettr(&tr)) err("can't get first trace");
	nt = tr.ns;
	dt = (float) tr.dt/1000000.0;

	if (!getparfloat("tmin", &tmin)) tmin=0.1*nt*dt;
	if (!getparint("flag", &flag)) flag=1;
	if(flag==1) {
		dtout=tmin*2.*dt;
		tmax=nt*dt;
		ntout=1+tmax*tmax/dtout; CHECK_NT("ntout",ntout);
		ttn=ealloc1float(ntout);
		for(j=0;j<ntout;j++) ttn[j]=sqrt(j*dtout);
	}else{
		if (!getparfloat("dt", &dt)) dtout=0.004;
		ntout=1+sqrt(nt*dt)/dtout; CHECK_NT("ntout",ntout);
		ttn=ealloc1float(ntout);
		for(j=0;j<ntout;j++) ttn[j]=j*j*dtout*dtout;
	}
	buf = ealloc1float(nt);

	fprintf(stderr,"sutsq: ntin=%d dtin=%f ntout=%d dtout=%f\n",
		nt,dt,ntout,dtout);

	/* Main loop over traces */
	do {
		for(j=0;j<nt;j++) buf[j]=tr.data[j];
		tr.ns = ntout;
		tr.dt = dtout*1000000.;			
		ints8r(nt,dt,0.,buf,0.0,0.0,
			ntout,ttn,tr.data);
		puttr(&tr);
	} while (gettr(&tr));
	
	return(CWP_Exit());
}
Ejemplo n.º 2
0
int
main(int argc, char **argv)
{
	int nt;				/* number of time samples	*/
	int ntr;			/* number of traces		*/
	int itr;			/* trace counter		*/
	int nspk;			/* number of spikes		*/
	int it1;			/* time of 1st spike		*/
	int ix1;			/* position of 1st spike	*/
	int it2;			/* time of 2nd spike		*/
	int ix2;			/* position of 2nd spike	*/
	int ix3;			/* position of 3rd spike	*/
	int it3;			/* time of 3rd spike		*/
	int ix4;			/* position of 4th spike	*/
	int it4;			/* time of 4th spike		*/
	float dt;			/* time sampling interval	*/
	float offset;			/* offset			*/


	/* Initialize */
	initargs(argc, argv);
	requestdoc(0); /* stdin not used */


	nt = 64;	getparint("nt", &nt);
	CHECK_NT("nt",nt);				tr.ns = nt;
	ntr = 32;	getparint("ntr", &ntr);
	dt = 0.004;	getparfloat("dt", &dt);		tr.dt = dt*1000000;
	offset = 400;	getparfloat("offset", &offset);	tr.offset = offset;
	nspk = 4;	getparint("nspk", &nspk);
	ix1 = ntr/4;	getparint("ix1", &ix1); 
	it1 = nt/4;	getparint("it1", &it1);
	ix2 = ntr/4;	getparint("ix2", &ix2);
	it2 = 3*nt/4;	getparint("it2", &it2);
	ix3 = 3*ntr/4;	getparint("ix3", &ix3);
	it3 = nt/4;	getparint("it3", &it3);
	ix4 = 3*ntr/4;	getparint("ix4", &ix4);
	it4 = 3*nt/4;	getparint("it4", &it4);

	for (itr = 0; itr < ntr; itr++) {
		memset( (void *) tr.data, 0, nt * FSIZE);
		if (itr == ix1-1) tr.data[it1-1] = 1.0;  
		if (nspk > 1 && itr == ix2-1) tr.data[it2-1] = 1.0;
		if (nspk > 2 && itr == ix3-1) tr.data[it3-1] = 1.0;
		if (nspk > 3 && itr == ix4-1) tr.data[it4-1] = 1.0;
		tr.tracl = itr + 1;
		puttr(&tr);
	}


	return(CWP_Exit());
}
Ejemplo n.º 3
0
int
main(int argc, char **argv)
{
	int nt,nshot,noff;
        int ishot,ioff,it;
        float dt,dshot,doff,sx,gx,offset,cmp;

	/* Initialize */
	initargs(argc, argv);
	requestdoc(0); /* stdin not used */

	nt = 100;	getparint("nt", &nt);
	CHECK_NT("nt",nt);				tr.ns = nt;
	nshot = 10;	getparint("nshot", &nshot);
	noff  = 24;	getparint("noff", &noff);
	dt = 0.004;	getparfloat("dt", &dt);		tr.dt = dt*1000000;
	dshot = 10;	getparfloat("dshot", &dshot);
	doff = 20;	getparfloat("doff", &doff);

	for (ishot = 0; ishot < nshot; ishot++) {
          sx = ishot*dshot;
	  for (ioff = 0; ioff < noff; ioff++) {
                offset = (ioff+1)*doff;
                gx = sx + offset; 
                cmp = (sx + gx)/2.;
		memset( (void *) tr.data, 0, nt * FSIZE);
                for (it = 0; it < nt/4; it++) {
		  tr.data[it] = sx;  
                }
                for (it = nt/4; it < nt/2; it++) {
		  tr.data[it] = gx;  
                }
                for (it = nt/2; it < 3*nt/4; it++) {
		  tr.data[it] = offset;  
                }
                for (it = 3*nt/4; it < nt; it++) {
		  tr.data[it] = cmp;  
                }
		tr.sx = sx;
		tr.gx = gx;
		tr.offset = offset;
		tr.cdp = cmp;
		tr.tracl = ishot*nshot + ioff + 1;
		puttr(&tr);
          }
        }


	return(CWP_Exit());
}
Ejemplo n.º 4
0
int
main(int argc, char **argv)
{
	int nz;		/* numer of depth samples */
	int iz;		/* counter */
	int nt;		/* number of time samples */

	int nzpar;	/* number of getparred depth values for velocities */
	int nvpar;	/* number of getparred velocity values */
	int izpar;	/* counter */

	int verbose;	/* verbose flag, =0 silent, =1 chatty */

	float dz=0.0;	/* depth sampling interval */
	float fz=0.0;	/* first depth value */
	float dt=0.0;	/* time sampling interval for velocities */
	float ft=0.0;	/* first time value */
	float z=0.0;	/* depth values for times */
	float vmin=0.0;	/* minimum velocity */
	float vmax=0.0;	/* maximum velocity */

	float *zpar=NULL;	/* values of z getparred */
	float *vpar=NULL;	/* values of v getparred */
	float *vz=NULL;		/* v(z) velocity as a function of z */
	float *zt=NULL;		/* z(t) depth as a function of t */
	float *temp=NULL;	/* temporary storage array */
	char *vfile="";		/* name of the velocity file */

	/* hook up getpar */
	initargs(argc,argv);
	requestdoc(1);

	/* get time sampling from first header */
	if (!gettr(&tr)) err("can't get first trace");
	nz = tr.ns;

	/* get depth sampling */
	if (!getparfloat("dz",&dz)) dz = ((float) tr.d1);

	/* determine velocity function v(t) */
	vz = ealloc1float(nz);
	if (!getparstring("vfile",&vfile)) {
		nzpar = countparval("z");
		if (nzpar==0) nzpar = 1;
		zpar = ealloc1float(nzpar);
		if (!getparfloat("z",zpar)) zpar[0] = 0.0;
		nvpar = countparval("v");
		if (nvpar==0) nvpar = 1;
		if (nvpar!=nzpar)err("number of t and v values must be equal");
		vpar = ealloc1float(nvpar);
		if (!getparfloat("v",vpar)) vpar[0] = 1500.0;
		for (izpar=1; izpar<nzpar; ++izpar)
			if (zpar[izpar]<=zpar[izpar-1])
				err("zpar must increase monotonically");
		for (iz=0,z=0.0; iz<nz; ++iz,z+=dz)
			intlin(nzpar,zpar,vpar,vpar[0],vpar[nzpar-1],
				1,&z,&vz[iz]);
	} else { /* read from a file */
		if (fread(vz,sizeof(float),nz,fopen(vfile,"r"))!=nz)
			err("cannot read %d velocities from file %s",nz,vfile);
	}

	/* determine minimum and maximum velocities */
	for (iz=1,vmin=vmax=vz[0]; iz<nz; ++iz) {
		if (vz[iz]<vmin) vmin = vz[iz];
		if (vz[iz]>vmax) vmax = vz[iz];
	}

	/* get parameters */
	if (!getparfloat("dt",&dt)) dt = 2.0*dz/vmin;
	if (!getparfloat("ft",&ft)) ft = 2.0*ft/vz[0];
	if (!getparint("nt",&nt)) nt = 1+(nz-1)*dz*2.0/(dt*vmax);
	if (!getparint("verbose",&verbose)) verbose = 0;
	CHECK_NT("nt",nt);

	/* if requested, print time sampling, etc */
	if (verbose) {
		warn("Input:");
		warn("\tnumber of depth samples = %d",nz);
		warn("\tdepth sampling interval = %g",dz);
		warn("\tfirst depth sample = %g",fz);
		warn("Output:");
		warn("\tnumber of time samples = %d",nt);
		warn("\ttime sampling interval = %g",dt);
		warn("\tfirst time sample = %g",ft);
	}

	/* allocate workspace */
	zt = ealloc1float(nt);
	temp = ealloc1float(nz);

	/* make z(t) function */
	makezt(nz,dz,fz,vz,nt,dt,ft,zt);
	
	/* loop over traces */
	do {
		/* update header fields */
		tr.trid = TREAL;
		tr.ns = nt;
		tr.dt = dt*1000000.0;
		tr.f1 = ft;
		tr.d1 = 0.0;

		/* resample */
		memcpy((void *) temp, (const void *) tr.data,nz*sizeof(float));
		ints8r(nz,dz,fz,temp,0.0,0.0,nt,zt,tr.data);

		/* put this trace before getting another */
		puttr(&tr);

	} while(gettr(&tr));

	return(CWP_Exit());
}
Ejemplo n.º 5
0
int
main (int argc, char **argv)
{
	int 	nr,ir,ls,smooth,ndpfz,ns,ixo,ixm,nxo,nxm,nt,
		nx,nz,nxb,nxd,ixd,i,ix,iz,nx1,nx0,nxd1,
		verbose,tracl,
		*nxz;
	float   tmin,temp,temp1,
		dsmax,fpeak,dx,dz,fx,ex,fx1,ex1,
		dxm,dxo,dt,fxm,fxo,ft,xo,xm,vs0,vg0,
		xs,xg,ez,
		*ar,**xr,**zr,
		**vold,**ts,**as,**sgs,**tg,**ag,**sgg,**bas,**bag,
		**v,**ts1=NULL,**as1=NULL,**sgs1=NULL,
		**tg1=NULL,**ag1=NULL,**sgg1=NULL;
	FILE *vfp=stdin;
	Reflector *r;
	Wavelet *w;

	/* hook up getpar to handle the parameters */
	initargs(argc,argv);
	requestdoc(0);

	/* get required parameters */
	if (!getparint("nx",&nx)) err("must specify nx!\n");
	if (!getparint("nz",&nz)) err("must specify nz!\n");
	
	/* get optional parameters */
	if (!getparint("nxb",&nxb)) nxb = nx;
	if (!getparint("nxd",&nxd)) nxd = 1;
	if (!getparfloat("dx",&dx)) dx = 100;
	if (!getparfloat("fx",&fx)) fx = 0.0;
	if (!getparfloat("dz",&dz)) dz = 100;
	if (!getparint("nt",&nt)) nt = 101; CHECK_NT("nt",nt);
	if (!getparfloat("dt",&dt)) dt = 0.04;
	if (!getparfloat("ft",&ft)) ft = 0.0;
	if (!getparint("nxo",&nxo)) nxo = 1;
	if (!getparfloat("dxo",&dxo)) dxo = 50;
	if (!getparfloat("fxo",&fxo)) fxo = 0.0;
	if (!getparint("nxm",&nxm)) nxm = 101;
	if (!getparfloat("dxm",&dxm)) dxm = 50;
	if (!getparfloat("fxm",&fxm)) fxm = 0.0;
	if (!getparfloat("fpeak",&fpeak)) fpeak = 0.2/dt;
	if (!getparint("ls",&ls)) ls = 0;
	if (!getparfloat("tmin",&tmin)) tmin = 10.0*dt;
	if (!getparint("ndpfz",&ndpfz)) ndpfz = 5;
	if (!getparint("smooth",&smooth)) smooth = 0;
	if (!getparint("verbose",&verbose)) verbose = 0;
	
	/* check the ranges of shots and receivers */
	ex = fx+(nx-1)*dx;
	ez = (nz-1)*dz;
 	for (ixm=0; ixm<nxm; ++ixm) 
		for (ixo=0; ixo<nxo; ++ixo) {
			/* compute source and receiver coordinates */
			xs = fxm+ixm*dxm-0.5*(fxo+ixo*dxo);
			xg = xs+fxo+ixo*dxo;
			if (fx>xs || ex<xs || fx>xg || ex<xg) 
		err("shot or receiver lie outside of specified (x,z) grid\n");
	} 
		
	
	decodeReflectors(&nr,&ar,&nxz,&xr,&zr);
	if (!smooth) breakReflectors(&nr,&ar,&nxz,&xr,&zr);

	/* allocate space */
	vold = ealloc2float(nz,nx);
	/* read velocities */
	if(fread(vold[0],sizeof(float),nx*nz,vfp)!=nx*nz)
		err("cannot read %d velocities from file %s",nx*nz,vfp);
	/* determine maximum reflector segment length */
	tmin = MAX(tmin,MAX(ft,dt));
	dsmax = vold[0][0]/(2*ndpfz)*sqrt(tmin/fpeak);
 	
	/* make reflectors */
	makeref(dsmax,nr,ar,nxz,xr,zr,&r);

	/* count reflector segments */
	for (ir=0,ns=0; ir<nr; ++ir)
		ns += r[ir].ns;

	/* make wavelet */
	makericker(fpeak,dt,&w);
	
	/* if requested, print information */
	if (verbose) {
		warn("\nSUSYNVXZ:");
		warn("Total number of small reflecting segments is %d.\n",ns);
	}
	
	/* set constant segy trace header parameters */
	memset( (void *) &tr, 0, sizeof(segy));
	tr.trid = 1;
	tr.counit = 1;
	tr.ns = nt;
	tr.dt = 1.0e6*dt;
	tr.delrt = 1.0e3*ft;
	
	/* allocate space */
	nx1 = 1+2*nxb;
	ts = ealloc2float(nz,nx1);
	as = ealloc2float(nz,nx1);
	sgs = ealloc2float(nz,nx1);
	tg = ealloc2float(nz,nx1);
	ag = ealloc2float(nz,nx1);
	sgg = ealloc2float(nz,nx1);
	v = ealloc2float(nz,nx1);
	bas = ealloc2float(nz,nx1);
	bag = ealloc2float(nz,nx1);
	if(nxd>1) {
		/* allocate space for interpolation */
		ts1 = ealloc2float(nz,nx1);
		as1 = ealloc2float(nz,nx1);
		sgs1 = ealloc2float(nz,nx1);
		tg1 = ealloc2float(nz,nx1);
		ag1 = ealloc2float(nz,nx1);
		sgg1 = ealloc2float(nz,nx1);
  	}
		

	/* loop over offsets and midpoints */
	for (ixo=0, tracl=0; ixo<nxo; ++ixo){
	    xo = fxo+ixo*dxo;
	    if(ABS(xo)>nxb*dx) err("\t band NXB is too small!\n");
	    nxd1 = nxd;
	    for (ixm=0; ixm<nxm; ixm +=nxd1){
		xm = fxm+ixm*dxm;
   		xs = xm-0.5*xo;
		xg = xs+xo;
		/* set range for traveltimes' calculation */
		fx1 = xm-nxb*dx;
		ex1 = MIN(ex+(nxd1-1)*dxm,xm+nxb*dx);
		nx1 = 1+(ex1-fx1)/dx;	
		nx0 = (fx1-fx)/dx;
		temp = (fx1-fx)/dx-nx0;
		/* transpose velocity such that the first row is at fx1 */
		for(ix=0;ix<nx1;++ix)
		    for(iz=0;iz<nz;++iz){
		    	if(ix<-nx0) 
			   	v[ix][iz] = vold[0][iz];
		    	else if(ix+nx0>nx-2) 
				v[ix][iz]=vold[nx-1][iz];
			else
				v[ix][iz] = vold[ix+nx0][iz]*(1.0-temp)
					+temp*vold[ix+nx0+1][iz];
		    }
			
		if(ixm==0 || nxd1==1){
		/* No interpolation */
	
			/* compute traveltimes, propagation angles, sigmas 
	  		 from shot and receiver respectively	*/
			eiktam(xs,0.,nz,dz,0.,nx1,dx,fx1,v,ts,as,sgs,bas);
			eiktam(xg,0.,nz,dz,0.,nx1,dx,fx1,v,tg,ag,sgg,bag);
			ixd = NINT((xs-fx)/dx);
			vs0 = vold[ixd][0];
			ixd = NINT((xg-fx)/dx);
			vg0 = vold[ixd][0];
				
			/* make one trace */
			ex1 = MIN(ex,xm+nxb*dx);
			makeone(ts,as,sgs,tg,ag,sgg,ex1,ez,dx,dz,fx1,vs0,vg0,
				ls,w,nr,r,nt,dt,ft,tr.data);
			/* set segy trace header parameters */
			tr.tracl = tr.tracr = ++tracl;
			tr.cdp = 1+ixm;
			tr.cdpt = 1+ixo;
			tr.offset = NINT(xo);
			tr.sx = NINT(xs);
			tr.gx = NINT(xg);
			/* write trace */
			puttr(&tr);
		}
		else {
			/* Linear interpolation */
			
			eiktam(xs,0,nz,dz,0,nx1,dx,fx1,v,ts1,as1,sgs1,bas);
			eiktam(xg,0,nz,dz,0,nx1,dx,fx1,v,tg1,ag1,sgg1,bag);
			ixd = NINT((xs-fx)/dx);
			vs0 = vold[ixd][0];
			ixd = NINT((xg-fx)/dx);
			vg0 = vold[ixd][0];
			
		    	xm -= nxd1*dxm;
		    for(i=1; i<=nxd1; ++i) {
		    	xm += dxm;
			xs = xm-0.5*xo;
			xg = xs+xo;
			fx1 = xm-nxb*dx;	
			ex1 = MIN(ex+(nxd1-1)*dxm,xm+nxb*dx);
			nx1 = 1+(ex1-fx1)/dx;	
			temp = nxd1-i;
			temp1 = 1.0/(nxd1-i+1);
			for(ix=0;ix<nx1;++ix)
			    for(iz=0;iz<nz;++iz){
			    if(i==nxd1){
			   	ts[ix][iz] = ts1[ix][iz];
			   	tg[ix][iz] = tg1[ix][iz];
			   	sgs[ix][iz] = sgs1[ix][iz];
			   	ag[ix][iz] = ag1[ix][iz];
			   	sgg[ix][iz] = sgg1[ix][iz];
			   	as[ix][iz] = as1[ix][iz];
				}
			    else{
			   	ts[ix][iz] = (temp*ts[ix][iz]
					+ts1[ix][iz])*temp1;
			   	tg[ix][iz] = (temp*tg[ix][iz]
					+tg1[ix][iz])*temp1;
			    	as[ix][iz] = (temp*as[ix][iz]
					+as1[ix][iz])*temp1;
			   	sgs[ix][iz] = (temp*sgs[ix][iz]
					+sgs1[ix][iz])*temp1;
			   	ag[ix][iz] = (temp*ag[ix][iz]
					+ag1[ix][iz])*temp1;
			   	sgg[ix][iz] = (temp*sgg[ix][iz]
					+sgg1[ix][iz])*temp1;
				}
			}
				
			/* make one trace */
			ex1 = MIN(ex,xm+nxb*dx);
			makeone(ts,as,sgs,tg,ag,sgg,ex1,ez,dx,dz,fx1,vs0,vg0,
				ls,w,nr,r,nt,dt,ft,tr.data);
			/* set segy trace header parameters */
			tr.tracl = tr.tracr = ++tracl;
			tr.cdp = 1+ixm-nxd1+i;
			tr.cdpt = 1+ixo;
			tr.offset = NINT(xo);
			tr.d2=dxm;
			tr.f2=fxm;
			tr.sx = NINT(xs);
			tr.gx = NINT(xg);
			/* write trace */
			puttr(&tr);
		    }
		}
		    /* set skip parameter */
		    if(ixm<nxm-1 && ixm>nxm-1-nxd1) nxd1 = nxm-1-ixm;

	    }
	    warn("\t finish offset %f\n",xo);
	}

	free2float(vold);
	free2float(ts);
	free2float(bas);
	free2float(sgs);
	free2float(as);
	free2float(v);
	free2float(tg);
	free2float(bag);
	free2float(sgg);
	free2float(ag);
	if(nxd>1) {
		free2float(ts1);
		free2float(as1);
		free2float(sgs1);
		free2float(tg1);
		free2float(ag1);
		free2float(sgg1);
  	}
	return(CWP_Exit());
}
Ejemplo n.º 6
0
int
main (int argc, char **argv)
{
	int nt;			/* number of time samples */
	int ntau;		/* number of migrated time samples */
	int nx;			/* number of midpoints 	*/
	int ik,ix,it,itau,itmig;/* loop counters 	*/
	int nxfft;		/* fft size		*/
	int nk;			/* number of wave numbers */	

	int ntmig,nvmig;	

	float dt;		/* time sampling interval 	*/
	float ft;		/* first time sample		*/
	float dtau;		/* migrated time sampling interval */
	float ftau;		/* first migrated time value 	*/
	float dk;		/* wave number sampling interval */
	float fk;		/* first wave number 		*/
	float Q, ceil;		/* quality factor, ceiling of amplitude */
	float t,k;		/* time,wave number		*/
	float *tmig, *vmig;	/* arrays of time, interval velocities */
	float dx;		/* spatial sampling interval	*/
	float *vt;		/* velocity v(t)		*/
	float **p,**q;		/* input, output data		*/

	complex **cp,**cq;	/* complex input,output		*/

	char *vfile="";		/* name of file containing velocities */
	int verbose=0;		/* flag for echoing info		*/
	char *tmpdir;		/* directory path for tmp files		*/
	cwp_Bool istmpdir=cwp_false;/* true for user-given path		*/

	/* hook up getpar to handle the parameters */
	initargs(argc,argv);
	requestdoc(1);

	/* get info from first trace */
	if (!gettr(&tr))  err("can't get first trace");
	nt = tr.ns;

	/* let user give dt and/or dx from command line */
	if (!getparfloat("dt", &dt)) {
		if (tr.dt) { /* is dt field set? */
			dt = ((double) tr.dt)/1000000.0;
		} else { /* dt not set, assume 4 ms */
			dt = 0.004;
			warn("tr.dt not set, assuming dt=0.004");
		}
	}
	if (!getparfloat("dx",&dx)) {
		if (tr.d2) { /* is d2 field set? */
			dx = tr.d2;
		} else {
			dx = 1.0;
			warn("tr.d2 not set, assuming d2=1.0");
		}
	}


	/* get optional parameters */
	if (!getparfloat("ft",&ft)) ft = 0.0;
	if (!getparint("ntau",&ntau)) ntau = nt; CHECK_NT("ntau",ntau);
	if (!getparfloat("dtau",&dtau)) dtau = dt;
	if (!getparfloat("ftau",&ftau)) ftau = ft;
	if (!getparfloat("Q",&Q)) Q = 1.0e6;
	if (!getparfloat("ceil",&ceil)) ceil = 1.0e6; 
		if (verbose)warn("Q=%f ceil=%f",Q,ceil); 

	if (!getparint("verbose", &verbose)) verbose = 0;

	/* 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);


	/* store traces and headers in tempfiles while getting a count */
	if (STREQ(tmpdir,"")) {
		tracefp = etmpfile();
		headerfp = etmpfile();
		if (verbose) warn("using tmpfile() call");
	} else { /* user-supplied tmpdir */
		char directory[BUFSIZ];
		strcpy(directory, tmpdir);
		strcpy(tracefile, temporary_filename(directory));
		strcpy(headerfile, temporary_filename(directory));
		/* Trap signals so can remove temp files */
		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;		
		if (verbose) warn("putting temporary files in %s", directory);
	}

	nx = 0;
	do {
		 ++nx;
		efwrite(&tr,HDRBYTES,1,headerfp);
		efwrite(tr.data, FSIZE, nt, tracefp);
	} while (gettr(&tr));
	erewind(tracefp);
	erewind(headerfp);
	
	/* determine wavenumber sampling (for real to complex FFT) */
	nxfft = npfar(nx);
	nk = nxfft/2+1;
	dk = 2.0*PI/(nxfft*dx);
	fk = 0.0;
	
	/* allocate space */
	p = alloc2float(nt,nxfft);
	q = alloc2float(ntau,nxfft);
	cp = alloc2complex(nt,nk);
	cq = alloc2complex(ntau,nk);

	/* load traces into the zero-offset array and close tmpfile */
	efread(*p, FSIZE, nt*nx, tracefp);
	efclose(tracefp);

	/* determine velocity function v(t) */
	vt = ealloc1float(ntau);
	if (!getparstring("vfile",&vfile)) {
		ntmig = countparval("tmig");
		if (ntmig==0) ntmig = 1;
		tmig = ealloc1float(ntmig);
		if (!getparfloat("tmig",tmig)) tmig[0] = 0.0;
		nvmig = countparval("vmig");
		if (nvmig==0) nvmig = 1;
		if (nvmig!=ntmig) err("number of tmig and vmig must be equal");
		vmig = ealloc1float(nvmig);
		if (!getparfloat("vmig",vmig)) vmig[0] = 1500.0;
		for (itmig=1; itmig<ntmig; ++itmig)
			if (tmig[itmig]<=tmig[itmig-1])
				err("tmig must increase monotonically");
		for (it=0,t=0.0; it<ntau; ++it,t+=dt)
			intlin(ntmig,tmig,vmig,vmig[0],vmig[ntmig-1],
				1,&t,&vt[it]);
	} else {
		if (fread(vt,sizeof(float),nt,fopen(vfile,"r"))!=nt)
			err("cannot read %d velocities from file %s",nt,vfile);
	}
	
        checkpars();

	/* pad with zeros and Fourier transform x to k */
	for (ix=nx; ix<nxfft; ix++)
		for (it=0; it<nt; it++)
			p[ix][it] = 0.0;
	pfa2rc(-1,2,nt,nxfft,p[0],cp[0]);
	
	/* migrate each wavenumber */
	for (ik=0,k=fk; ik<nk; ik++,k+=dk)
		gazdagvt(k,nt,dt,ft,ntau,dtau,ftau,vt,cp[ik],cq[ik], Q, ceil);
	
	/* Fourier transform k to x (including FFT scaling) */
	pfa2cr(1,2,ntau,nxfft,cq[0],q[0]);
	for (ix=0; ix<nx; ix++)
		for (itau=0; itau<ntau; itau++)
			q[ix][itau] /= nxfft;

	/* restore header fields and write output */
	for (ix=0; ix<nx; ++ix) {
		efread(&tr,HDRBYTES,1,headerfp);
		tr.ns = ntau ;
		tr.dt = dtau * 1000000.0 ;
		tr.delrt = ftau * 1000.0 ;
		memcpy( (void *) tr.data, (const void *) q[ix],ntau*FSIZE);
		puttr(&tr);
	}
	
	/* Clean up */
	efclose(headerfp);
	if (istmpdir) eremove(headerfile);
	if (istmpdir) eremove(tracefile);

	return(CWP_Exit());	
}
Ejemplo n.º 7
0
int
main(int argc, char **argv)
{
	int nv;		/* number of velocities */
	float dv;	/* velocity sampling interval */
	float fv;	/* first velocity */
        float anis1;    /* quartic term, or numerator of an extended one */
        float anis2;    /* inside denominator of an extended quartic term */
	int iv;		/* velocity index */
	int dtratio;	/* ratio of output to input sampling intervals */
	int nsmooth;	/* length in samples of num and den smoothing window */
	int nt;		/* number of time samples per input trace */
	float dt;	/* time sampling interval for input traces */
	float ft;	/* time of first sample input and output */
	int ntout;	/* number of output samples */
	float dtout;	/* time sampling interval for output traces */
	int it;		/* input time sample index */
	int itout;	/* output time sample index */
	int is;		/* time sample index for smoothing window */
	int ismin;	/* lower limit on is */
	int ismax;	/* upper limit on is */
	int itmute;	/* time sample index of first sample not muted */
	int iti;	/* time sample index used in linear interpolation */
	float ti;	/* normalized time for linear interpolation */
	float frac;	/* fractional distance from sample in interpolation */
	int gottrace;	/* =1 if an input trace was read */
	int verbose;	/* =1 for diagnostic print */
	long cdp;	/* cdp from current input trace header */
	long cdpprev;	/* cdp from previous input trace header */
	float smute;	/* NMO stretch mute factor */
	float offset;	/* offset from input trace header */
	float offovs;	/* (offset/velocity)^2 */
        float offan=0.0;    /* shift of tnmo due to anisotropy */
	float tn;	/* time after NMO */
	float tnmute;	/* mute time after NMO */
	float nsum;	/* semblance numerator sum */
	float dsum;	/* semblance denominator sum */
	float v;	/* velocity */
	float temp;	/* temporary scalar */
	float *data;	/* array[nt] of input trace */
	float *sem;	/* array[ntout] of semblance */
	float **num;	/* array[nv][nt] of semblance numerators */
	float **den;	/* array[nv][nt] of semblance denominators */
	float **nnz;	/* array[nv][nt] for counting non-zero samples */
	float pwr;      /* power of semblance */

	/* hook up getpar */
	initargs(argc,argv);
	requestdoc(0);

	/* get parameters from the first trace */
	if (!gettr(&tr)) err("can't get first trace");
	nt = tr.ns;
	dt = ((double) tr.dt)/1000000.0;
	ft = tr.delrt/1000.0;
	cdp = tr.cdp;
	offset = tr.offset;

	/* get optional parameters */
	if (!getparint("nv",&nv)) nv = 50;
	if (!getparfloat("dv",&dv)) dv = 50.0;
	if (!getparfloat("fv",&fv)) fv = 1500.0;
	if (!getparfloat("anis1",&anis1)) anis1 = 0.0;
	if (!getparfloat("anis2",&anis2)) anis2 = 0.0;
	if (!getparfloat("smute",&smute)) smute = 1.5;
	if (smute<=1.0) err("smute must be greater than 1.0");
	if (!getparint("dtratio",&dtratio)) dtratio = 5;
	if (!getparint("nsmooth",&nsmooth)) nsmooth = dtratio*2+1;
	if (!getparint("verbose",&verbose)) verbose = 0;
	if (!getparfloat("pwr",&pwr)) pwr = 1.0;
	if (pwr < 0.0)   
	  err("we are not looking for noise: pwr < 0");
	if (pwr == 0.0)   
	  err("we are creating an all-white semblance: pwr = 0");

        checkpars();
	/* determine output sampling */
	ntout = 1+(nt-1)/dtratio;   CHECK_NT("ntout",ntout);
	dtout = dt*dtratio;
	if (verbose) {
		fprintf(stderr,
			"\tnumber of output time samples is %d\n",ntout);
		fprintf(stderr,
			"\toutput time sampling interval is %g\n",dtout);
		fprintf(stderr,
			"\toutput time of first sample is %g\n",ft);
	}

	/* allocate memory */
	data = ealloc1float(nt);
	num = ealloc2float(nt,nv);
	den = ealloc2float(nt,nv);
	nnz = ealloc2float(nt,nv);
	sem = ealloc1float(ntout);

	/* zero accumulators */
	for (iv=0; iv<nv; ++iv) {
		for (it=0; it<nt; ++it) {
			num[iv][it] = 0.0;
			den[iv][it] = 0.0;
			nnz[iv][it] = 0.0;
		}
	}

	/* initialize flag */
	gottrace = 1;

	/* remember previous cdp */
	cdpprev = tr.cdp;

	/* loop over input traces */
	while (gottrace|(~gottrace)/*True*/) { /* middle exit loop */

		/* if got a trace */
		if (gottrace) {

			/* determine offset and cdp */
			offset = tr.offset;
			cdp = tr.cdp;
                        if ((1.0 + offset*offset*anis2) <= 0.0)
                           err ("anis2 too small");
                        offan = (offset*offset*offset*offset*anis1) / 
                                (1.0 + offset*offset*anis2);

			/* get trace samples */
			memcpy( (void *) data,
				(const void *) tr.data,nt*sizeof(float));
		}

		/* if cdp has changed or no more input traces */
		if (cdp!=cdpprev || !gottrace) {

			/* set output trace header fields */
			tr.offset = 0;
			tr.cdp = (int) cdpprev;
			tr.ns = ntout;
			tr.dt = dtout*1000000.0;

			/* loop over velocities */
			for (iv=0; iv<nv; ++iv) {

				/* compute semblance quotients */
				for (itout=0; itout<ntout; ++itout) {
					it = itout*dtratio;
					ismin = it-nsmooth/2;
					ismax = it+nsmooth/2;
					if (ismin<0) ismin = 0;
					if (ismax>nt-1) ismax = nt-1;
					nsum = dsum = 0.0;
					for (is=ismin; is<ismax; ++is) {
						nsum += num[iv][is]*
							num[iv][is];
						dsum += nnz[iv][is]*
							den[iv][is];
					}
					sem[itout] = (dsum!=0.0?nsum/dsum:0.0);
				}

				/* powering the semblance */
				if (pwr != 1.0) {
				  for (itout=0; itout<ntout; ++itout)
				    sem[itout] = pow (sem[itout], pwr);
				};

				/* output semblances */
				memcpy((void *) tr.data,
				       (const void *) sem,ntout*sizeof(float));
				puttr(&tr);

				/* zero accumulators */
				for (it=0; it<nt; ++it) {
					num[iv][it] = 0.0;
					den[iv][it] = 0.0;
					nnz[iv][it] = 0.0;
				}
			}

			/* diagnostic print */
			if (verbose) 
				warn("semblance output for cdp=%d",cdpprev);

			/* if no more input traces, break input trace loop */
			if (!gottrace) break;

			/* remember previous cdp */
			cdpprev = cdp;
		}

		/* loop over velocities */
		for (iv=0,v=fv; iv<nv; ++iv,v+=dv) {
			
			/* compute offset/velocity squared */
			offovs = (offset*offset)/(v*v) + offan;
                        /* decrease of traveltime with distance due to highly
                           increasing velocity cannot be handled yet
                        */
                        if (offovs < 0.0)
                           warn("no moveout; check anis1 and anis2");

			/* determine mute time after nmo */
			tnmute = sqrt(offovs/(smute*smute-1.0));
			if (tnmute > ft) {
				itmute = (tnmute-ft)/dt;
			} else {
				itmute = 0 ;
			}
			
			/* do nmo via quick and dirty linear interpolation
			   (accurate enough for velocity analysis) and
			   accumulate semblance numerator and denominator
			*/

			for (it=itmute,tn=ft+itmute*dt; it<nt; ++it,tn+=dt) {
				ti = (sqrt(tn*tn+offovs)-ft)/dt;
				iti = ti;
				if (iti<nt-1) {
					frac = ti-iti;
					temp = (1.0-frac)*data[iti]+
						frac*data[iti+1];
					if (temp!=0.0) {
						num[iv][it] += temp;
						den[iv][it] += temp*temp;
						nnz[iv][it] += 1.0;
					}
				}
			}
		}

		/* get next trace (if there is one) */
		if (!gettr(&tr)) gottrace = 0;

	}

	return(CWP_Exit());
}
Ejemplo n.º 8
0
int
main (int argc, char **argv)
{
	int nr,er,ob,sp,ir,ixz,ls,smooth,ndpfz,ns,
		ixo,ixsm,nxo,nxs,nxm,nt,nxsm,
		shots,midpoints,verbose,tracl,
		*nxz;
	float x0,z0,v00,gamma,dvdx,dvdz,vmin,tmin,tminr,
		x,z,v,t,dsmax,fpeak,
		dxs,dxm,dxo,dt,fxs,fxm,fxo,ft,dxsm,
		xs,zs,xg,zg,
		*xo,*ar,**xr,**zr;
	Reflector *r;
	Wavelet *w;

	/* hook up getpar to handle the parameters */
	initargs(argc,argv);
	requestdoc(0);

	/* get parameters */
	if (!getparint("nt",&nt)) nt = 101; CHECK_NT("nt",nt);
	if (!getparfloat("dt",&dt)) dt = 0.04;
	if (!getparfloat("ft",&ft)) ft = 0.0;
	if ((nxo=countparval("xo"))!=0) {
		xo = ealloc1float(nxo);
		getparfloat("xo",xo);
	} else {
		if (!getparint("nxo",&nxo)) nxo = 1;
		if (!getparfloat("dxo",&dxo)) dxo = 0.05;
		if (!getparfloat("fxo",&fxo)) fxo = 0.0;
		xo = ealloc1float(nxo);
		for (ixo=0; ixo<nxo; ++ixo)
			xo[ixo] = fxo+ixo*dxo;
	}
	shots = (getparint("nxs",&nxs) || 
		getparfloat("dxs",&dxs) || 
		getparfloat("fxs",&fxs));
	midpoints = (getparint("nxm",&nxm) || 
		getparfloat("dxm",&dxm) || 
		getparfloat("fxm",&fxm)); 
	if (shots && midpoints)
		err("cannot specify both shot and midpoint sampling!\n");
	if (shots) {
		if (!getparint("nxs",&nxs)) nxs = 101;
		if (!getparfloat("dxs",&dxs)) dxs = 0.05;
		if (!getparfloat("fxs",&fxs)) fxs = 0.0;
		nxsm = nxs;
		dxsm = dxs;
	} else {
		midpoints = 1;
		if (!getparint("nxm",&nxm)) nxm = 101;
		if (!getparfloat("dxm",&dxm)) dxm = 0.05;
		if (!getparfloat("fxm",&fxm)) fxm = 0.0;
		nxsm = nxm;
		dxsm = dxm;
	}
	if (!getparint("nxm",&nxm)) nxm = 101;
	if (!getparfloat("dxm",&dxm)) dxm = 0.05;
	if (!getparfloat("fxm",&fxm)) fxm = 0.0;
	if (!getparfloat("x0",&x0)) x0 = 0.0;
	if (!getparfloat("z0",&z0)) z0 = 0.0;
	if (!getparfloat("v00",&v00)) v00 = 2.0;
	if (!getparfloat("gamma",&gamma)) gamma = 1.0;
	if (!getparfloat("dvdx",&dvdx)) dvdx = 0.0;
	if (!getparfloat("dvdz",&dvdz)) dvdz = 0.0;
	if (!getparfloat("fpeak",&fpeak)) fpeak = 0.2/dt;
	if (!getparint("ls",&ls)) ls = 0;
	if (!getparint("er",&er)) er = 0;
	if (!getparint("ob",&ob)) ob = 1;
	if (!getparint("sp",&sp)) sp = 1;
	if (!getparfloat("tmin",&tmin)) tmin = 10.0*dt;
	if (!getparint("ndpfz",&ndpfz)) ndpfz = 5;
	if (!getparint("smooth",&smooth)) smooth = 0;
	if (!getparint("verbose",&verbose)) verbose = 0;
	decodeReflectors(&nr,&ar,&nxz,&xr,&zr);
	if (!smooth) breakReflectors(&nr,&ar,&nxz,&xr,&zr);

	/* convert velocity v(x0,z0) to v(0,0) */
	v00 -= dvdx*x0+dvdz*z0;
	
	/* determine minimum velocity and minimum reflection time */
	for (ir=0,vmin=FLT_MAX,tminr=FLT_MAX; ir<nr; ++ir) {
		for (ixz=0; ixz<nxz[ir]; ++ixz) {
			x = xr[ir][ixz];
			z = zr[ir][ixz];
			v = v00+dvdx*x+dvdz*z;
			if (v<vmin) vmin = v;
			t = 2.0*z/v;
			if (t<tminr) tminr = t;
		}
	}

	/* determine maximum reflector segment length */
	tmin = MAX(tmin,MAX(ft,dt));
	dsmax = vmin/(2*ndpfz)*sqrt(tmin/fpeak);
 	
	/* make reflectors */
	makeref(dsmax,nr,ar,nxz,xr,zr,&r);

	/* count reflector segments */
	for (ir=0,ns=0; ir<nr; ++ir)
		ns += r[ir].ns;

	/* make wavelet */
	makericker(fpeak,dt,&w);
	
	/* if requested, print information */
	if (verbose) {
		warn("\nSYNLVCW:");
		warn(
			"Minimum possible reflection time (assuming sources\n"
			"and receivers are at the surface Z=0) is %g s.\n"
			"You may want to adjust the \"minimum time of \n"
			"interest\" parameter.",tminr);
		warn(
			"Total number of small reflecting\n"
			"segments is %d.",ns);
	}
	
	/* set constant segy trace header parameters */
	memset( (void *) &tr, 0, sizeof(segy));
	tr.trid = 1;
	tr.counit = 1;
	tr.ns = nt;
	tr.dt = 1.0e6*dt;
	tr.delrt = 1.0e3*ft;
	
	/* loop over shots or midpoints */
	for (ixsm=0,tracl=0; ixsm<nxsm; ++ixsm) {
	
		/* loop over offsets */
		for (ixo=0; ixo<nxo; ++ixo) {
		
			/* compute source and receiver coordinates */
			if (shots)
				xs = fxs+ixsm*dxs;
			else
				xs = fxm+ixsm*dxm-0.5*xo[ixo];
			zs = 0.0;
			xg = xs+xo[ixo];
			zg = 0.0;
			
			/* set segy trace header parameters */
			tr.tracl = tr.tracr = ++tracl;
			if (shots) {
				tr.fldr = 1+ixsm;
				tr.tracf = 1+ixo;
			} else {
				tr.cdp = 1+ixsm;
				tr.cdpt = 1+ixo;
			}
			tr.offset = NINT(1000.0*(dxsm>0.0?xo[ixo]:-xo[ixo]));
			tr.sx = NINT(1000.0*xs);
			tr.gx = NINT(1000.0*xg);
				
			/* make one trace */
			makeone(v00,dvdx,dvdz,ls,er,ob,sp,w,gamma,
				xs,zs,xg,zg,
				nr,r,nt,dt,ft,tr.data);
			
			/* write trace */
			puttr(&tr);
		}
	}
	return(CWP_Exit());
}
Ejemplo n.º 9
0
int
main(int argc, char **argv)
{
	int nline;		/* number of (identical) lines		*/
	int ntr;		/* number of traces			*/
	int nt;			/* number of time samples		*/
	int ninf;		/* number of subsurface reflectors	*/
	int itr;		/* trace number index			*/
	int iline;		/* line number index			*/
	int i, j;		/* counters				*/

	float dx;		/* trace interval			*/
	float dt;		/* time interval			*/
	float tdelay;		/* recording time delay			*/
	float x;		/* zero offset position			*/
	float xmin, xmax;	/* min and max horizontal coordinates 	*/

	float *zint;		/* reflector intercepts at x = 0 	*/
	float *dip;		/* reflector dips 			*/
	float *v;		/* speeds in layers 			*/
	float *rho;		/* densities in layers 			*/
	float *xl, *xr;		/* min and max horiz coords in a layer 	*/
	float *meet;		/* horizontal intercept for two adjacent
				 * layers, if layers not parallel */
	float *trcoefs;		/* transmission coefficients		*/
	float *data;		/* temp for holding synthetic trace	*/
	float *tout;		/* times[nt] for interpolation		*/
	float **theta;		/* angle at which the specular ray to
				 * interface j hits interface i */
	float **m;		/* slope for horiz travel calculation	*/
	float **b;		/* intercept for horiz travel calc	*/
	float **d;		/* distance traveled in a layer, if layers
				 * are parallel */
	float **k;		/* factor for finding horizontal distance
				 * in a layer */
	float **w;		/* for spreading factor calculation	*/

	cwp_Bool *dorow;	/* are adjacent reflectors parallel?	*/


	/* hook up getpar */
	initargs(argc, argv);
	requestdoc(0);
	
	
	/* get scalar parameters */
	if (!getparint("nline",&nline))	     nline=1;
	if (!getparint("ntr",&ntr))	     ntr=32;	 tr.ntr = ntr*nline;
	if (!getparfloat("dx",&dx))	     dx=10.0;
	if (!getparint("nt",&nt))	     nt=128;
	CHECK_NT("nt",nt);					 tr.ns = nt;
	if (!getparfloat("dt",&dt))	     dt=0.004;	 tr.dt = dt*1000000;
	if (!getparfloat("tdelay",&tdelay))  tdelay=0.0;
						tr.delrt = tdelay*1000;
	if (!getparint("ninf",&ninf))	ninf=4;
	
	/* allocate space */
	data = ealloc1float(nt);
	v = ealloc1float(ninf+1);
	rho = ealloc1float(ninf+1);
	zint = ealloc1float(ninf+1);
	dip = ealloc1float(ninf+1);
	meet = ealloc1float(ninf+1);
	xl = ealloc1float(ninf+1);
	xr = ealloc1float(ninf+1);
	trcoefs = ealloc1float(ninf+1);
	theta = ealloc2float(ninf+1,ninf+1);
	m = ealloc2float(ninf+1,ninf+1);
	b = ealloc2float(ninf+1,ninf+1);
	d = ealloc2float(ninf+1,ninf+1);
	w = ealloc2float(ninf+1,ninf+1);
	k = ealloc2float(ninf+1,ninf+1);
	dorow = ealloc1(ninf+1,sizeof(cwp_Bool));
	
	/* compute output times for interpolation */
	tout = ealloc1float(nt);
	for (i=0; i<nt; i++) tout[i]=i*dt;

	 	
	/* getpar the reflector intercepts, dips, v's, and rho's */
	zint[0] = 0.0; /* surface hard wired */
	if (!getparfloat("zint", zint+1))
 		for (i = 1; i <= ninf; ++i) zint[i] = 100.0 * i;
	dip[0] = 0.0; /* surface hard wired */
	if (!getparfloat("dip", dip+1))
 		for (i = 1; i <= ninf; ++i) dip[i] = 5.0 * i;
	if (!getparfloat("v", v))
 		for (i = 0; i <= ninf; ++i) v[i] = 1500.+ 500*i;
	if (!getparfloat("rho", rho))
 		for (i = 0; i <= ninf; ++i) rho[i] = 1.0;

	/* check dips and intercepts */
	for (i = 1; i <= ninf; ++i) {
		if (dip[i] < -90.0 || dip[i] > 90.0) err("dips1");
		if (ABS(dip[i] - dip[i-1]) > 90.0) err("dips2");
		dip[i] *= TORADS;
		
		if (zint[i] <= zint[i-1]) err("intercept");
	}
	for (i = 0; i < ninf; ++i) {
		if (v[i] <= 0.0) err("velocities");
		if (rho[i] <= 0.0) err("density");
	}


	/* Table theta[j][i], the angle at which the specular to layer j
	 * leaves interface i. 						*/
	for (j = 1; j < ninf; ++j) {
		theta[j][j-1] = -dip[j];
		for (i = j-1; i > 0; --i) {
		    float temp;
		    
		    temp = v[i-1]*sin(theta[j][i]+dip[i])/v[i];
		    if (ABS(temp) > 1.0) err("specular %d", j);
			
		    theta[j][i-1] = asin(temp) - dip[i];
		}
	}


	/* Table m and b, which are used to find the x coordinate of
	 * the specular at the next interface from its x coordinate at
	 * the previous interface. 					*/
	for (j = 1; j <= ninf; ++j) {
		for (i = 0; i < j; ++i) {
			float s, temp;
			
			s = sin(theta[j][i]);
			temp = 1.0 - tan(dip[i+1])*s;
			m[j][i] = (1.0 - tan(dip[i])*s)/temp;
			b[j][i] = (zint[i+1]-zint[i])*s/temp;
		}
	}

	/* Make the final checks on the substructure specification.
	 * The strategy is to check the x coordinates of the
	 * interface intercepts against x coordinates of
	 * specular-interface intercepts. Only the rays from the
	 * left and right endpoints need to be checked, since they define
	 * the area being "observed". 					*/
	xmin = 0.0;
	xmax = dx * (ntr - 1);
	for (j = 1; j <= ninf; ++j) {
		xl[j] = xmin;  /*** changed Brian's code here! */
		xr[j] = xmax;
	}

	for (j=0; j<ninf; ++j) {
		int j2;
		for (j2=j+1; j2<=ninf; ++j2) {
		    if (dip[j2] != dip[j]) {
			float intercept;
			
			intercept = (zint[j2]-zint[j])/
						(tan(dip[j])-tan(dip[j2]));
			if (intercept > xmin && intercept < xmax) {
				err("intercept");
			}
		    }
		}

		for (j2=j+1; j<=ninf; ++j) {
			xl[j2] = m[j2][j]*xl[j2] + b[j2][j];
			xr[j2] = m[j2][j]*xr[j2] + b[j2][j];

			if (xl[j2] < xmin) xmin = xl[j2];
			if (xr[j2] > xmax) xmax = xr[j2];
		}
	}

	/* Table the arrays meet and k if two adjacent interfaces
	 * intersect, otherwise d if they are parallel.
	 * Meet is the x coordinate of intersection if there is
	 * an intersection, k is a value which will be used to
	 * find the distance travelled in that layer. If there is no
	 * intersection d will be a constant for all j and can be
	 * stored now. */
	for (i = 0; i < ninf; ++i) {
		if (dip[i+1] == dip[i]) {
			dorow[i] = cwp_false;
			for (j = i + 1; j <= ninf; ++j) {
				d[j][i] = (zint[i+1]-zint[i])*cos(dip[i]) /
						cos(theta[j][i] + dip[i]);
			}
		} else {
			dorow[i] = cwp_true;
			meet[i] = (zint[i+1]-zint[i])/
					(tan(dip[i])-tan(dip[i+1]));
			for (j = i + 1; j <= ninf; ++j) {
				k[j][i] = sin(dip[i]-dip[i+1]) /
				      (cos(theta[j][i]+dip[i+1])*cos(dip[i]));
			}
		}
	}

	/* Table t, the transmission coefficients. */
	tabtrcoefs(ninf, rho, v, theta, dip, trcoefs);

	/* Table w, the coefficients for the spreading factor calculation. */
	for (j = 1; j <= ninf; ++j) {
		w[j][0] = 1.0;
		for (i = 1; i < j; ++i) {
			float c1, c2;
			
			c1 = cos(theta[j][i-1] + dip[i]);
			c2 = cos(theta[j][i] + dip[i]);
			w[j][i] = w[j][i-1]*c1*c1/(c2*c2);
		}
	}

	/* Now ready to make synthetic traces. */
	for (iline = 0; iline < nline; ++iline) {
		x = 0.0;
		for (itr = 0; itr < ntr; itr++) {
			float ex, t0, time, tmp, p1, p2, dist, amp[1];
			int itime, it;
			
			memset( (void *) tr.data, 0, nt * FSIZE);
			memset( (void *) data, 0, nt * FSIZE);
	
			for (j = 1; j <= ninf; ++j) {
				ex = x;
				if (dorow[0]) {
					dist = (meet[0]-ex)*k[j][0];
				} else {
					dist = d[j][0];
				}
				t0 = dist/v[0];
				tmp = dist*v[0];
				p1 = tmp;
				p2 = tmp;
				for (i = 1; i < j; ++i) {
					ex = m[j][i-1]*ex + b[j][i-1];
					if (dorow[i]) {
						dist = (meet[i] - ex)*k[j][i];
					} else {
						dist = d[j][i];
					}
	
					t0 += dist/v[i];
					tmp = dist*v[i];
					p1 += tmp;
					p2 += tmp*w[j][i];
				}
	
				/* set strength and time of spike response */
				amp[0] = v[0]*trcoefs[j]/
						(dt*FOURPI*2.0*sqrt(p1*p2));
				time = 2.0*t0 - tdelay;
				itime = NINT(time/dt);
				if (itime >= 0 && itime < nt)
						data[itime] = amp[0];
				
				/* distribute spike response over full trace */
				ints8r(1,dt,time,amp,0,0,nt,tout,data);
				
				/* add distributed spike to segy trace */
				for (it = 0; it < nt; ++it)
					tr.data[it] += data[it];
			}
			
			/* fill tracl header and put trace out */
			tr.tracl = itr + 1;
			tr.gx = x;
			tr.sx = x;
			puttr(&tr);

			/* set horizontal location of next trace */
			x += dx;
	
		}
	}
	
	/**
	* Thats all folks.
	**/

	return(CWP_Exit());	
}