Example #1
0
main()
{
	int ik,ix,itest;
	float dx=1.413,knyq=PI/dx,dk=knyq/NK,fk=dk,xout=0.0;
	float fx,yin[NX],err[NK],x,k,yout,errnow;

	/* loop over k */
	for (ik=0,k=fk; ik<NK; ik++,k+=dk) {

		/* loop over tests */
		for (itest=0; itest<NTEST; itest++) {

			/* determine random first x */
			fx = (-NX/2+franuni())*dx;

			/* fill array with sine wave */
			for (ix=0,x=fx; ix<NX; ix++,x+=dx)
				yin[ix] = sin(k*x);

			/* interpolate (correct yout is 0.0 = sin(k*0.0) */
			ints8r(NX,dx,fx,yin,0.0,0.0,1,&xout,&yout);

			/* store percentage error */
			errnow = fabs(yout)*100.0;
			err[ik] = MAX(errnow,err[ik]);
		}
	}
	pp1d(stdout,"percentage error",NK,0,err);
}
Example #2
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());
}
Example #3
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());
}
Example #4
0
int
main(int argc, char **argv)
{
	int nt;		/* number of time samples per trace */
	float dt;	/* time sampling interval */
	float ft;	/* time of first sample */
	int it;		/* time sample index */
	int ncdp;	/* number of cdps specified */
	float *cdp;	/* array[ncdp] of cdps */
	int icdp;	/* index into cdp array */
	int jcdp;	/* index into cdp array */
	int nvnmo;	/* number of vnmos specified */
	float *vnmo;	/* array[nvnmo] of vnmos */
	int ntnmo;	/* number of tnmos specified */
	float *tnmo;	/* array[ntnmo] of tnmos */
	float **ovv;	/* array[ncdp][nt] of sloth (1/velocity^2) functions */
	float *ovvt;	/* array[nt] of sloth for a particular trace */
	int nanis1;	/* number of anis1's specified */
	int nanis2;	/* number of anis2's specified */
	float *anis1;	/* array[nanis1] of anis1's */
	float *anis2;	/* array[nanis2] of anis2's */
	float **oa1;	/* array[ncdp][nt] of anis1 functions */
	float **oa2;	/* array[ncdp][nt] of anis2 functions */
	float *oa1t;	/* array[nt] of anis1 for a particular trace */
	float *oa2t;	/* array[nt] of anis2 for a particular trace */
	float smute;	/* zero samples with NMO stretch exceeding smute */
	float osmute;	/* 1/smute */
	int lmute;	/* length in samples of linear ramp for mute */
	int itmute=0;	/* zero samples with indices less than itmute */
	int sscale;	/* if non-zero, apply NMO stretch scaling */
	int invert;	/* if non-zero, do inverse NMO */
	float sy;	/* cross-line offset component */
	int ixoffset;	/* indes for cross-line offset component */
	long oldoffset;	/* offset of previous trace */
	long oldcdp;	/* cdp of previous trace */
	int newsloth;	/* if non-zero, new sloth function was computed */
	float tn;	/* NMO time (time after NMO correction) */
	float v;	/* velocity */
	float *qtn;	/* NMO-corrected trace q(tn) */
	float *ttn;	/* time t(tn) for NMO */
	float *atn;	/* amplitude a(tn) for NMO */
	float *qt;	/* inverse NMO-corrected trace q(t) */
	float *tnt;	/* time tn(t) for inverse NMO */
	float *at;	/* amplitude a(t) for inverse NMO */
	float acdp;	/* temporary used to sort cdp array */
	float *aovv;	/* temporary used to sort ovv array */
	float *aoa1;	/* temporary used to sort oa1 array */
	float *aoa2;	/* temporary used to sort oa2 array */
	float temp;	/* temporary float */
	float tsq;	/* temporary float */
	int i;		/* index used in loop */
	int upward;	/* scans upward if it's nonzero. */

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

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

	/* get velocity functions, linearly interpolated in time */
	ncdp = countparval("cdp");
	if (ncdp>0) {
		if (countparname("vnmo")!=ncdp)
			err("a vnmo array must be specified for each cdp");
		if (countparname("tnmo")!=ncdp)
			err("a tnmo array must be specified for each cdp");
		if (countparname("anis1")!=ncdp &&
		    countparname("anis1")!=0)
			err("an anis1 array must be specified for each cdp, "
			    "or omitted at all");
		if (countparname("anis2")!=ncdp &&
		    countparname("anis2")!=0)
			err("an anis2 array must be specified for each cdp, "
			    "or omitted at all");
	} else {
		ncdp = 1;
		if (countparname("vnmo")>1)
			err("only one (or no) vnmo array must be specified");
		if (countparname("tnmo")>1)
			err("only one (or no) tnmo array must be specified");
		if (countparname("anis1")>1)
			err("only one (or no) anis1 array must be specified");
		if (countparname("anis2")>1)
			err("only one (or no) anis2 array must be specified");
	}
	cdp = ealloc1float(ncdp);
	if (!getparfloat("cdp",cdp)) cdp[0] = tr.cdp;
	ovv = ealloc2float(nt,ncdp);
	oa1 = ealloc2float(nt,ncdp);
	oa2 = ealloc2float(nt,ncdp);
	for (icdp=0; icdp<ncdp; ++icdp) {
		nvnmo = countnparval(icdp+1,"vnmo");
		ntnmo = countnparval(icdp+1,"tnmo");
		nanis1 = countnparval(icdp+1,"anis1");
		nanis2 = countnparval(icdp+1,"anis2");
		if (nvnmo!=ntnmo && !(ncdp==1 && nvnmo==1 && ntnmo==0))
			err("number of vnmo and tnmo values must be equal");
		if (nanis1!=nvnmo && nanis1 != 0)
			err("number of vnmo and anis1 values must be equal");
		if (nanis2!=nvnmo && nanis2 != 0)
			err("number of vnmo and anis2 values must be equal");
		if (nvnmo==0) nvnmo = 1;
		if (ntnmo==0) ntnmo = nvnmo;
		if (nanis1==0) nanis1 = nvnmo;
		if (nanis2==0) nanis2 = nvnmo;
		/* equal numbers of parameters vnmo, tnmo, anis1, anis2 */
		vnmo = ealloc1float(nvnmo);
		tnmo = ealloc1float(nvnmo);
		anis1 = ealloc1float(nvnmo);
		anis2 = ealloc1float(nvnmo);
		if (!getnparfloat(icdp+1,"vnmo",vnmo)) vnmo[0] = 1500.0;
		if (!getnparfloat(icdp+1,"tnmo",tnmo)) tnmo[0] = 0.0;
		if (!getnparfloat(icdp+1,"anis1",anis1)) 
			for (i=0; i<nvnmo; i++) anis1[i] = 0.0;
		if (!getnparfloat(icdp+1,"anis2",anis2))
			for (i=0; i<nvnmo; i++) anis2[i] = 0.0;
		for (it=1; it<ntnmo; ++it)
			if (tnmo[it]<=tnmo[it-1])
				err("tnmo values must increase monotonically");
		for (it=0,tn=ft; it<nt; ++it,tn+=dt) {
			intlin(ntnmo,tnmo,vnmo,vnmo[0],vnmo[nvnmo-1],1,&tn,&v);
			ovv[icdp][it] = 1.0/(v*v);
		}
		for (it=0,tn=ft; it<nt; ++it,tn+=dt) {
			intlin(ntnmo,tnmo,anis1,anis1[0],anis1[nanis1-1],1,&tn,
			       &oa1[icdp][it]);
		}
		for (it=0,tn=ft; it<nt; ++it,tn+=dt) {
			intlin(ntnmo,tnmo,anis2,anis2[0],anis2[nanis2-1],1,&tn,
			       &oa2[icdp][it]);
		}
		free1float(vnmo);
		free1float(tnmo);
		free1float(anis1);
		free1float(anis2);
	}

	/* sort (by insertion) sloth and anis functions by increasing cdp */
	for (jcdp=1; jcdp<ncdp; ++jcdp) {
		acdp = cdp[jcdp];
		aovv = ovv[jcdp];
		aoa1 = oa1[jcdp];
		aoa2 = oa2[jcdp];
		for (icdp=jcdp-1; icdp>=0 && cdp[icdp]>acdp; --icdp) {
			cdp[icdp+1] = cdp[icdp];
			ovv[icdp+1] = ovv[icdp];
			oa1[icdp+1] = oa1[icdp];
			oa2[icdp+1] = oa2[icdp];
		}
		cdp[icdp+1] = acdp;
		ovv[icdp+1] = aovv;
		oa1[icdp+1] = aoa1;
		oa2[icdp+1] = aoa2;
	}

	/* get other optional parameters */
	if (!getparfloat("smute",&smute)) smute = 1.5;
	if (!getparint("ixoffset",&ixoffset)) ixoffset=0; 
	  if (ixoffset==0) sy = 0.0;
	if (smute<=0.0) err("smute must be greater than 0.0");
	if (!getparint("lmute",&lmute)) lmute = 25;
	if (!getparint("sscale",&sscale)) sscale = 1;
	if (!getparint("invert",&invert)) invert = 0;
	if (!getparint("upward",&upward)) upward = 0;

	/* allocate workspace */
	ovvt = ealloc1float(nt);
	oa1t = ealloc1float(nt);
	oa2t = ealloc1float(nt);
	ttn = ealloc1float(nt);
	atn = ealloc1float(nt);
	qtn = ealloc1float(nt);
	tnt = ealloc1float(nt);
	at = ealloc1float(nt);
	qt = ealloc1float(nt);

	/* interpolate sloth and anis function for first trace */
	interpovv(nt,ncdp,cdp,ovv,oa1,oa2,(float)tr.cdp,ovvt,oa1t,oa2t);

	/* set old cdp and old offset for first trace */
	oldcdp = tr.cdp;
	oldoffset = tr.offset-1;

	warn("sy = %f",sy);

	/* loop over traces */
	do {
		/* if necessary, compute new sloth and anis function */
		if (tr.cdp!=oldcdp && ncdp>1) {
			interpovv(nt,ncdp,cdp,ovv,oa1,oa2,(float)tr.cdp,
				  ovvt,oa1t,oa2t);
			newsloth = 1;
		} else {
			newsloth = 0;
		}

		/* if sloth and anis function or offset has changed */
		if (newsloth || tr.offset!=oldoffset) {
			/* compute time t(tn) (normalized) */
			temp = ((float) tr.offset*(float) tr.offset + sy*sy)/(dt*dt);
			for (it=0,tn=ft/dt; it<nt; ++it,tn+=1.0) {
				tsq = temp*ovvt[it] + \
				      oa1t[it]*temp*temp / (1.0+oa2t[it]*temp);
				if (tsq<0.0)
					err("negative moveout; check anis1, "
					    "anis2, or suwind far-offset "
					    "traces");
				if ((1.0+oa2t[it]*temp)<=0.0)
					err("anis2 negative and too small; "
					    "check anis2, or suwind far-offset"
					    " traces");
				ttn[it] = sqrt (tn*tn + tsq);
				}
			/* compute inverse of stretch factor a(tn) */
			atn[0] = ttn[1]-ttn[0];
			for (it=1; it<nt; ++it)
				atn[it] = ttn[it]-ttn[it-1];
			
			/* determine index of first sample to survive mute */
			osmute = 1.0/smute;
			if( !upward ) {
				for (it=0; it<nt-1 && atn[it]<osmute; ++it)
					;
			} else {
				/* scan samples from bottom to top */
				for (it=nt-1; it>0 && atn[it]>=osmute; --it)
					;
			}
			itmute = it;

			/* if inverse NMO will be performed */
			if (invert) {
							
				/* compute tn(t) from t(tn) */
				yxtoxy(nt-itmute,1.0,ft/dt+itmute,&ttn[itmute],
					nt-itmute,1.0,ft/dt+itmute,
					ft/dt-nt,ft/dt+nt,&tnt[itmute]);
			
				/* adjust mute time */
				itmute = 1.0+ttn[itmute]-ft/dt;
				itmute = MIN(nt-2,itmute);
								
				/* compute a(t) */
				if (sscale) {
					for (it=itmute+1; it<nt; ++it)
						at[it] = tnt[it]-tnt[it-1];
					at[itmute] = at[itmute+1];
				}
			}
		}
		
		/* if forward (not inverse) nmo */
		if (!invert) {
	
			/* do nmo via 8-point sinc interpolation */
			ints8r(nt,1.0,ft/dt,tr.data,0.0,0.0,
				nt-itmute,&ttn[itmute],&qtn[itmute]);
			
			/* apply mute */
			for (it=0; it<itmute; ++it)
				qtn[it] = 0.0;
			
			/* apply linear ramp */
			for (it=itmute; it<itmute+lmute && it<nt; ++it)
				qtn[it] *= (float)(it-itmute+1)/(float)lmute;
			
			/* if specified, scale by the NMO stretch factor */
			if (sscale)
				for (it=itmute; it<nt; ++it)
					qtn[it] *= atn[it];
			
			/* copy NMO corrected trace to output trace */
			memcpy( (void *) tr.data,
					(const void *) qtn, nt*sizeof(float));
		
		/* else inverse nmo */
		} else {
	
			/* do inverse nmo via 8-point sinc interpolation */
			ints8r(nt,1.0,ft/dt,tr.data,0.0,0.0,
				nt-itmute,&tnt[itmute],&qt[itmute]);
			
			/* apply mute */
			for (it=0; it<itmute; ++it)
				qt[it] = 0.0;
			
			/* if specified, undo NMO stretch factor scaling */
			if (sscale)
				for (it=itmute; it<nt; ++it)
					qt[it] *= at[it];
			
			/* copy inverse NMO corrected trace to output trace */
			memcpy( (void *) tr.data,
					(const void *) qt,nt*sizeof(float));
		}

		/* write output trace */
		puttr(&tr);

		/* remember offset and cdp */
		oldoffset = tr.offset;
		oldcdp = tr.cdp;

	} while (gettr(&tr));

	return(CWP_Exit());
}
Example #5
0
main(int argc, char **argv)
{
    string ggfile;
    FILE *infp=stdin,*outfp=stdout,*gfp;
    int idz, nz, rsampz;
    int nzg, jz;
    float dz, dzint,z; 	
    float fzg, dzg; 
    float *gamgrid, *g2m1, *mout2, *dataint, *zint, *zx , *mute;
    float *g2;
    int oldcdp, oldoffset,ncdpg;
    float cdpming, dcdpg;
    float smute, osmute, odz, odz2, z0, fz;
    int mutes, newgamma ;
    int indz, indx, nzint, iz;
    float temp, res, zzint, odzint, str;
    int ierr;


    /* get parameters */
    initargs(argc,argv);
    askdoc(1);
/* read in first trace */
    if (!fgettr(infp,&tr)) err("can't get first trace");
    idz = tr.dt;
    if ( idz > 1000 ) idz = idz/1000;
    dz = idz;
    fz = tr.delrt/dz;
    if ( fz >1000. ) fz=fz/1000.;

    /* if dz defined in segy trace header, get it */
    if ( tr.dz != 0. ) {
	dz = tr.dz;
	fz = tr.fz;
    }

    nz = tr.ns;
    if ( !getparstring("ggfile",&ggfile)) err("ggfile must be given ! \n");
    if ( !getparfloat("smute",&smute)) smute=1.5;
    /* open ggfile and read header */
    gfp = efopen(ggfile,"r");
    ierr = fgetghdr(gfp,&gh);

	if(ierr!=0) warn(" grid header error \n");

    if ( !getparfloat("cdpming",&cdpming) ) {
	if(ierr==0) {
		getgval(&gh,"ocdp2",&cdpming);
		if(cdpming==0.) 
	      err(" grid file gh.ocdp2=0.; update gh.ocdp2 or spicify cdpming");
	} else {
		cdpming = tr.cdp;
	}
    }
    if ( !getparfloat("dcdpg",&dcdpg) ) {
	if(ierr==0) {
		getgval(&gh,"dcdp2",&dcdpg);
		if(dcdpg==0.) 
		err(" grid file gh.dcdp2=0.; update gh.dcdp2 or spicify dcdpg");
	} else {
		dcdpg = 1;
	}
    }
    if ( !getparfloat("fzg",&fzg) ) {
	if(ierr==0) {
		getgval(&gh,"o1",&fzg);
	} else {
		fzg = fz;
	}
    }
    if ( !getparfloat("dzg",&dzg) ) {
	if(ierr==0) {
		getgval(&gh,"d1",&dzg);
	} else {
		dzg = dz;
	} 
    }	

    if ( !getparint("nzg",&nzg) ) {
	if(ierr==0) {
		nzg = (int) (float)( gh.n1/gh.scale + 0.00001);
	} else {
		nzg = nz;
	}
    }
    if ( !getparint("ncdpg",&ncdpg) ) {
	if(ierr==0) {
		ncdpg = (int) (float)( gh.n2/gh.scale + 0.00001);
	} else {
    		fseek(gfp,0L,2);
    		ncdpg = ftell(gfp)/sizeof(float)/nzg;
        	fseek(gfp,0L,0);
	}
    }
    /* error checking */
    if (ierr==0) {
		if(ncdpg!=(int) (float)( gh.n2/gh.scale + 0.00001))
			err(" check gh.n2 ");
		if(nzg!=(int) (float)( gh.n1/gh.scale + 0.00001))
			err(" check gh.n1 ");
		if(dzg!=gh.d1/gh.scale)
			warn("dzg=%g not the same as gh.d1 = %g ", dzg, gh.d1/gh.scale);
		if(fzg!=gh.o1/gh.scale)
			warn("fzg not the same as gh.o1");
		if(dcdpg!=gh.dcdp2/gh.scale)
			warn("dcdpg not the same as gh.dcdp2");
		if(cdpming!=gh.ocdp2/gh.scale)
			warn("cdpming not the same as gh.ocdp2");
    } else {
                warn(" input ggfile non-standard, defaults used ");
    }

    if(dcdpg==0.) err(" dcdpg must not be 0"); 

    gamgrid = (float*)malloc(nzg*sizeof(float));

    /* sinc interpolate input traces before gmo for better accuracy */
    rsampz = 4.;
    nzint = nz * rsampz;
    dzint = 1./rsampz;
    odzint = rsampz;

    /* memory allocation */
    g2m1 = (float*)malloc(nz*sizeof(float));
    g2 = (float*)malloc(nz*sizeof(float));
    dataint = (float*)malloc(nzint*sizeof(float));
    zint = (float*)malloc(nzint*sizeof(float));
    mout2 = (float*)malloc(nz*sizeof(float));
    zx = (float*)malloc(nz*sizeof(float));
    mute = (float*)malloc(nz*sizeof(float));

    /* main loop over input traces */
    oldcdp = tr.cdp - 1;
    oldoffset=tr.offset - 1;
    odz = 1./dz;
    odz2 = odz*odz;

    for(iz=0;iz<nzint;iz++) zint[iz] = fz + iz*dzint;
    osmute = 1./smute;


    do { 

	/* find cdp index in gamma grid */
	if(tr.cdp!=oldcdp) {
	   newgamma = 1;
	   indx = (tr.cdp-cdpming)/dcdpg;
	   if(indx <0) {
	      indx = 0;
	   }
	   else if (indx >ncdpg-1) {
	      indx = ncdpg - 1;
	   }
           fseek(gfp,indx*nzg*sizeof(float),0);
    	   fread(gamgrid,sizeof(float),nzg,gfp);
	   /* compute (gamma^2-1) */
	   for(iz=0;iz<nz;iz++) { 
		z = fz + iz * dz;
		/* interpolate input ggrid */
		z = (z-fzg)/dzg;
		jz = z;
		if(jz<1) {
			jz = 1;
		} else if (jz>nzg-1) {
			jz = nzg - 1; 
		}
		/* store as 1./g2 */
		g2[iz] = 1./(gamgrid[jz]*gamgrid[jz]);
		g2m1[iz] = g2[iz]-1.;
	   }		
	} else {
	   newgamma = 0;
	}
	if (newgamma || tr.offset!=oldoffset) {
	   /* compute 0.25*offset^2/dz^2*(gamma^2-1)  */
	   temp = (tr.offset*tr.offset)*odz2*0.25;
	   for(iz=0;iz<nz;iz++) mout2[iz] = temp*g2m1[iz];
	}

	/* sinc interpolate the input trace */
	if(nzint>nz) {
	   ints8r(nz,1.0,fz,tr.data,0.0,0.0,nzint,zint,dataint);
	} else {
	   for(iz=0;iz<nz;iz++) dataint[iz]=tr.data[iz];
	}

	/* compute depth z(z0) (in sample) */
	for(iz=0,z0=fz; iz<nz; ++iz, z0+=1.0) { 
	   temp = z0*z0 + mout2[iz];
	   if (temp >= 0.) {
	      zx[iz] = sqrt(temp);
	      mute[iz] = 1.;
	   }
	   else {
	      zx[iz] = fz - 1.;
	      mute[iz] = 0.;
	   }
	}
	/* gmo */
	/* determine if stretch mute is needed */
	str = zx[1]-zx[0];
	if (g2m1[0]>=0.&& str < smute) {
	   mutes = 0;
	} else if(g2m1[0]<0.&& str > osmute) {
	   mutes = 0;
	} else {
	   mutes = 1;
	}
	if(mutes!=1){
	   zzint = (zx[0] - fz)*odzint;
	   indz = zzint;
	   res = zzint - indz;
	   if(indz>0 && indz<nzint-1) {
	      tr.data[0] = dataint[indz]+res*(dataint[indz+1]-dataint[indz]);	
	   } else {
	      tr.data[0] = 0.;	
	   }		
	} else {
	      tr.data[0] = 0.;
	}
	for(iz=1;iz<nz;iz++) {
	   str = zx[iz]-zx[iz-1];
	   if (g2m1[iz]>=0.&& str < smute) {
	      mutes = 0;
	   } else if(g2m1[iz]<0.&& str > osmute) {
	      mutes = 0;
	   } else {
	      mutes = 1;
	   }
	   if(mutes!=1) {
	      zzint = (zx[iz] - fz)*odzint;
	      indz = zzint;
	      res = zzint - indz;
	      if(indz>0 && indz<nzint-1) {
	         tr.data[iz]=dataint[indz]+res*(dataint[indz+1]-dataint[indz]);	
	      } else {
	         tr.data[iz]=0.;	
	      }
	   } else {
	         tr.data[iz]=0.;	
	   }
	}
	/* zero out those with negative inside sqrt */
	for(iz=0;iz<nz;iz++)tr.data[iz]=tr.data[iz]*mute[iz];
	   
	/* output */
	fputtr(outfp,&tr);
	/* update offset and cdp */
	oldcdp = tr.cdp;
	oldoffset = tr.offset;

    }while(fgettr(infp,&tr));

    free(gamgrid);
    free(g2m1);
    free(mout2);
    free(dataint);
    free(mute);
    free(zx);
    free(zint);

    fclose(outfp);
    

    return EXIT_SUCCESS;
}
Example #6
0
int
main(int argc, char **argv)
{
    float c;			/* speed			*/
    float dt;			/* sampling rate		*/
    int nt;				/* number of samples		*/
    size_t ntsize;			/* ... in bytes			*/
    int nshot;			/* number of shots		*/
    int nrec;			/* number of receivers		*/
    float x0, y0, z0;		/* point scatterer location	*/
    float sxmin, symin, szmin;	/* first shot location		*/
    float gxmin, gymin, gzmin;	/* first receiver location	*/
    float dsx, dsy, dsz;		/* step in shot location	*/
    float dgx, dgy, dgz;		/* step in receiver location	*/

    float sx, sy, sz;		/* shot location		*/
    float gx, gy, gz;		/* receiver location		*/
    float rs;			/* distance to shot		*/
    float rg;			/* distance to receiver		*/
    float d;			/* rs + rg			*/
    float t;			/* total travel time		*/
    float k;			/* constant part of response	*/

    register float *rt;		/* real trace			*/
    register complex *ct;		/* complex transformed trace	*/
    int nfft;			/* size of fft 			*/
    int nfby2;			/* nfft/2			*/
    int nfby2p1;			/* nfft/2 + 1			*/
    size_t nzeros;			/* padded zeroes in bytes	*/
    float spread;			/* 3-D spreading factor		*/

    register int i;			/* counter			*/
    register int s;			/* shot counter			*/
    register int g;			/* receiver counter		*/
    register int tracl;		/* trace counter		*/

    float amplitude[1];	/* amplitude 			*/
    float *tout;		/* times[nt] for interpolation	*/


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


    /* Get parameters */
    if (!getparint("nshot", &nshot))	nshot = 1;
    if (!getparint("nrec", &nrec))		nrec  = 1;
    if (!getparint("nt", &nt))		nt    = 256;
    if (!getparfloat("c", &c))		c     = 5000.0;
    if (!getparfloat("dt", &dt))		dt    = 0.004;
    if (!getparfloat("x0", &x0))		x0    = 1000.0;
    if (!getparfloat("y0", &y0))		y0    = 0.0;
    if (!getparfloat("z0", &z0))		z0    = 1000.0;
    if (!getparfloat("sxmin", &sxmin))	sxmin = 0.0;
    if (!getparfloat("symin", &symin))	symin = 0.0;
    if (!getparfloat("szmin", &szmin))	szmin = 0.0;
    if (!getparfloat("gxmin", &gxmin))	gxmin = 0.0;
    if (!getparfloat("gymin", &gymin))	gymin = 0.0;
    if (!getparfloat("gzmin", &gzmin))	gzmin = 0.0;
    if (!getparfloat("dsx", &dsx))		dsx   = 100.0;
    if (!getparfloat("dsy", &dsy))		dsy   = 0.0;
    if (!getparfloat("dsz", &dsz))		dsz   = 0.0;
    if (!getparfloat("dgx", &dgx))		dgx   = 100.0;
    if (!getparfloat("dgy", &dgy))		dgy   = 0.0;
    if (!getparfloat("dgz", &dgz))		dgz   = 0.0;


    /* Set the constant header fields */
    tr.ns = nt;
    tr.dt = dt * 1000000.0;
    ntsize = nt * FSIZE;


    /* Set up for fft */
    nfft = npfaro(nt, LOOKFAC * nt);
    if (nfft >= SU_NFLTS || nfft >= PFA_MAX)
        err("Padded nt=%d -- too big", nfft);

    nfby2 = nfft / 2;
    nfby2p1 = nfby2 + 1;
    nzeros = (nfft - nt) * FSIZE;


    /* Allocate fft arrays */
    rt   = ealloc1float(nfft);
    ct   = ealloc1complex(nfby2p1);


    /* Set the constant in the response amplitude
       including scale for inverse fft below      */
    k = 1.0 / (4.0 * c * c * dt * dt * dt * nfft * nfft * nfft);

    /* Compute output times for interpolation */
    tout = ealloc1float(nt);
    for (i=0; i<nt; i++) tout[i]=i*dt;

    /* Create the traces */
    tracl = 0;
    for (s = 0; s < nshot; ++s) {	/* loop over shots */
        sx = sxmin + s * dsx;
        sy = symin + s * dsy;
        sz = szmin + s * dsz;
        rs = sqrt((sx - x0)*(sx - x0) + (sy - y0)*(sy - y0) +
                  (sz - z0)*(sz - z0));

        for (g = 0; g < nrec; ++g) {	/* loop over receivers */
            memset( (void *) tr.data, 0, ntsize);
            gx = gxmin + g * dgx;
            gy = gymin + g * dgy;
            gz = gzmin + g * dgz;
            rg = sqrt((gx - x0)*(gx - x0) + (gy - y0)*(gy - y0) +
                      (gz - z0)*(gz - z0));
            d = rs + rg;
            t = d/c;
            spread = rs*rg;
            amplitude[0] = k/spread;

            /* Distribute response over full trace */
            ints8r(1,dt,t,amplitude,0,0,nt,tout,tr.data);

            /* Load trace into rt (zero-padded) */
            memcpy( (void *) rt, (const void *) tr.data, ntsize);
            memset( (void *) (rt + nt), 0, nzeros);

            /* FFT */
            pfarc(1, nfft, rt, ct);

            /* Multiply by omega^2 */
            for (i = 0; i < nfby2p1; ++i)
                ct[i] = crmul(ct[i], i*i);

            /* Invert and take real part */
            pfacr(-1, nfft, ct, rt);

            /* Load traces back in */
            memcpy( (void *) tr.data, (const void *) rt, ntsize);

            /* Set header fields---shot fields set above */
            tr.tracl = tr.tracr = ++tracl;
            tr.fldr = 1 + s;
            tr.tracf = 1 + g;
            tr.sx = NINT(sx);
            tr.sy = NINT(sy);
            tr.selev = -NINT(sz); /* above sea level > 0 */
            tr.gx = NINT(gx);
            tr.gy = NINT(gy);
            tr.gelev = -NINT(gz); /* above sea level > 0 */

            /* If along a coordinate axis, use a signed offset */
            tr.offset = sqrt((sx - gx)*(sx - gx) +
                             (sy - gy)*(sy - gy) +
                             (sz - gz)*(sz - gz));
            if (dgy == 0 && dgz == 0)
                tr.offset = NINT(dsx > 0 ? gx - sx : sx - gx);
            if (dgx == 0 && dgz == 0)
                tr.offset = NINT(dsy > 0 ? gy - sy : sy - gy);
            if (dgx == 0 && dgy == 0)
                tr.offset = NINT(dsz > 0 ? gz - sz : sz - gz);

            puttr(&tr);
        } /* end loop on receivers */
    } /* end loop on shots */

    return(CWP_Exit());
}
Example #7
0
int
main(int argc, char **argv)
{
	int nt;		/* number of samples on output trace	*/
	float dt;	/* sample rate on outpu trace		*/
	int itime;	/* counter          			*/
	float tmin;	/* first time sample on output trace	*/
	float tsd=0.0;	/* time to move source to datum         */
	float trd=0.0;	/* time to move 0 offset receiver       */
	float v0;	/* weathering velocity			*/
	float v1;	/* subweathering velocity		*/
	int hdrs; 	/* flag to read statics from headers	*/ 
	float *t;	/* array of output times		*/
	float tstat;	/* total (source and receiver) statics	*/
	int sign;	/* to add (+) or subtract (-) statics	*/
	int no;		/* number of offsets per shot 		*/
	int io;		/* offset counter 			*/
	int is;		/* source counter 			*/
	int ir;		/* receiver counter 			*/
	int ns;		/* number of sources = number of source statics */
	int nr;		/* number of receiver = number of rec. statics	*/
	float *sou_statics=NULL;	/* array of source statics	*/
	float *rec_statics=NULL;	/* array of receiver statics	*/
	FILE *fps, *fpr;	/* file pointers for statics input 	*/
	cwp_String sou_file, rec_file; /* statics filenames 		*/

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

	/* Get information from first trace */
	if (!gettr(&intrace)) err("can't get first trace");
	nt   = intrace.ns;
	tmin = intrace.delrt/1000.0;
	dt   = ((double) intrace.dt)/1000000.0;
	
	/* Get parameters */
	if (!getparfloat("v1", &v1))          v1 = (float) intrace.swevel;
	if (!getparfloat("v0", &v0))
                v0 = (float) ((intrace.wevel) ? intrace.wevel : v1);
	if (!getparint("hdrs", &hdrs))        hdrs = 0;
	if (!getparint("sign", &sign))        sign = 1;

	/* Allocate vector of output times */
	t = ealloc1float(nt);

	/* reading source and receiver statics from files */
	if ((hdrs == 2) || (hdrs == 3)){

		/* getpar statics file related parameters */
		if (!getparint("ns", &ns))        ns = 240;
		if (!getparint("nr", &nr))        nr = 335;
		if (!getparint("no", &no))        no = 96;

		/* getpar statics file names */
        	getparstring("sou_file",&sou_file);
        	getparstring("rec_file",&rec_file);

		/* allocate space */
		rec_statics = alloc1float(nr);
        	sou_statics = alloc1float(ns);

		/* open and read from receiver statics file */
        	if((fpr=efopen(rec_file,"rb"))==NULL)
                	err("cannot open stat_file=%s\n",rec_file);
        	efread(rec_statics, sizeof(float),nr,fpr);
        	efclose(fpr);

		/* open and read from source statics file */
        	if((fps=efopen(sou_file,"rb"))==NULL)
                	err("cannot open stat_file=%s\n",sou_file);
        	efread(sou_statics, sizeof(float),ns,fps);
        	efclose(fps);
	}

	/* Initialize tstat */
	tstat = 0.0;

	/* Loop on traces */	
	io = 0; is = 0;
	do {
		int temp = SGN(intrace.scalel)*log10(abs((int) intrace.scalel));
		float scale;
                scale = pow(10., (float)temp);
		
		/* copy and adjust header */
		memcpy( (void *) &outtrace, (const void *) &intrace, HDRBYTES);
	
		/* compute static correction if necessary */
		if(!hdrs) {
		    	tsd = scale *
			(-intrace.selev + intrace.sdel + intrace.sdepth)/v1;
			trd = tsd - intrace.sut/1000.0;
			tstat = tsd + trd +
				scale * (intrace.selev - intrace.gelev)/v0;

		/* else, read statics from headers */
		} else { 
			/* Initialize header field for output trace */
			outtrace.sstat = intrace.sstat;
			outtrace.gstat = intrace.gstat;
			outtrace.tstat = intrace.sstat+intrace.gstat;
			if (hdrs == 1) {
				tstat = outtrace.tstat/1000.0;
			}
			if (hdrs == 2) {
				ir = is + io;
				if (is <= ns) tsd = sou_statics[is]/1000.0;
				if (ir > 0 && ir <= nr)
					trd = rec_statics[ir]/1000.0;

				tstat = tsd + trd;
				io ++;
				if (io > no-1) {
					io = 0; is++;
				}
			}
			if (hdrs == 3) {
				tsd = sou_statics[intrace.fldr]/1000.0;
				trd = rec_statics[intrace.tracf]/1000.0;

				tstat = tsd + trd;
			}
		}
		
		/* Compute output times */
		for (itime=0; itime<nt; ++itime)
			t[itime] = tmin + itime*dt + sign*tstat;

		/* sinc interpolate new data */
		ints8r(nt, dt, tmin, intrace.data, 
				0.0, 0.0, nt, t, outtrace.data);
		
		/* set header field for output trace */
		if(hdrs == 0 || hdrs == 2 || hdrs == 3){

			/* value is added to existing header values */
			/* this permits multiple static corrections */
			outtrace.sstat += (1000.0 * tsd);
			outtrace.gstat += (1000.0 * trd);
			outtrace.tstat += (1000.0 * tstat);
		} 
		
		puttr(&outtrace);
	} while (gettr(&intrace));


	return(CWP_Exit());
}
Example #8
0
static void cvstack(VND *vnda, VND *vnd, int icmp, int noff, float *off,
		float *mute, int lmute, int nv, float *p2,
		float dt, float dtout)
/************************************************************************
	compute constant velocity stacks for this cmp and
	load out to disk
*************************************************************************
vnda	VND file with input cmp gather
vnd	VND file for output constant velocity stacks
icmp	cmp number (zero based)
noff	number of offsets for this cmp
off[]	list of offsets for this cmp
mute[]	list of mute times for this cmp
lmute	length of mute taper
nv	number of velocities at which to compute stacks
p2[]	list of 1/(v*v) at which to compute stacks
dt	input sample rate
dtout 	output sample rate
***************************************************************************
Author: John Anderson (visitor to CSM from Mobil) Spring 1993
***************************************************************************/
{
	int iv;
	int it;
	int itmute;
	long ioff;
	long nt;
	long ntout;
	long key[2];	
	float *rt;
	float *buf;
	float *ttn;
	float *qtn;
	float *fold;
	float *big;
	float factor;
	float t;
	char *ccrt;

	nt=vnda->N[0];
	ntout=vnd->N[1]/nv;
	rt=(float *)VNDemalloc(ntout*sizeof(float),"sutifowler:cvstack: rt");
	buf=(float *)VNDemalloc(MAX(nt,ntout)*sizeof(float),"sutifowler:cvstack: buf");
	ttn=(float *)VNDemalloc(ntout*sizeof(float),"sutifowler:cvstack: ttn");
	qtn=(float *)VNDemalloc(ntout*sizeof(float),"sutifowler:cvstack: qtn");
	fold=(float *)VNDemalloc(ntout*sizeof(float),"sutifowler:cvstack: fold");
	big=(float *)VNDemalloc(noff*sizeof(float),"sutifowler:cvstack: big");
	ccrt=(char *)rt;
	
	/* check for completely dead traces so can skip them */
	for(ioff=0;ioff<noff;ioff++) {
		big[ioff]=0.;
		V2Dr0(vnda,ioff,(char *)buf,3);
		for(it=0;it<nt;it++)
			big[ioff]=MAX( big[ioff], fabs(buf[it]) );	
	}

	for(iv=0;iv<nv;iv++) {
		for(it=0;it<ntout;it++) rt[it]=0.;
		for(it=0;it<ntout;it++) fold[it]=0.;
		for(ioff=0;ioff<noff;ioff++) {
		    if(big[ioff]>0.) {
			V2Dr0(vnda,ioff,(char *)buf,4);

			factor=off[ioff]*off[ioff]*p2[iv];
			itmute=mute[ioff]/dtout;
			
			for(it=itmute;it<ntout;it++) {
				t=it*dtout;
				ttn[it]=sqrt(t*t+factor);
				}

			/* do nmo via 8-point sinc interpolation */
			ints8r(nt,dt,0.,buf,0.0,0.0,
				ntout-itmute,&ttn[itmute],&qtn[itmute]);
			
			/* apply linear ramp to taper mute */
			for (it=itmute; it<(itmute+lmute) && it<ntout; ++it)
				qtn[it] *= (float)(it-itmute+1)/(float)lmute;

			/* sum NMO corrected trace to stacked trace  */
			for(it=itmute;it<ntout;it++) rt[it]+=qtn[it];

			/* count fold information */
			for(it=itmute;it<ntout;it++) fold[it]+=1.;
		    }
		}
		for(it=0;it<ntout;it++) {
			if(fold[it]==0.) fold[it]=1.;
		}
		for(it=0;it<ntout;it++) rt[it]/=fold[it]; 
		key[0]=icmp;
		key[1]=0;
		VNDrw('w',0,vnd,1,key,0,ccrt,iv*ntout,1,ntout,1,"cv stacking");
	}

	VNDfree(rt,"cvstack: freeing rt");
	VNDfree(buf,"cvstack: freeing buf");
	VNDfree(ttn,"cvstack: freeing ttn");
	VNDfree(qtn,"cvstack: freeing qtn");
	VNDfree(fold,"cvstack: freeing fold");
	VNDfree(big,"cvstack: freeing big");
	if(icmp==20*(icmp/20)){
		fprintf(fpl,
		"sutifowler: completed stacking velocity analysis for cmp %d\n",icmp);
	}
	return;
}
Example #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());	
}
Example #10
0
void knmo(float *ind, float *outd,int nt, float *vrms, 
          float t0,float offset,float dt,int imt,int sph)
{
/* This routine applies the moveout corection, obliquity factor and 
	spherical divergence factor to the gather. The phase shift filter has to be
	applied to the stacked trace */
/* imt index of first live sample in input trace */
	register int i;
	float tx;
	float txa;	/* amplitude of interpolated tx */
	float of2;
	float r;
	float z;
	float t;
	float tmax;
	float tm;
		
	
	tm=imt*dt;
	if (offset==0.0) {
		for(i=0;i<nt;i++) {
			t=t0+i*dt;
			if(sph) { z=vrms[i]/2.0*t;
				  outd[i] = ind[i]*(vrms[i]*z);
			} else 
			outd[i] = ind[i];
		}
	} else {	
		memset( (void *) outd, (int) '\0',nt*FSIZE);
		of2=4.0*SQR(offset);
		tmax=t0+(nt-1)*dt;
		for(i=imt;i<nt;i++) {
			t=t0+i*dt;
			
			/* knmo moveout */
			tx = sqrt(SQR(t) + of2/SQR(vrms[i]));
			if(tx<tmax && tx>tm) { 
				ints8r(nt,dt,t0,ind,0,0,1,&tx,&txa);
				
				/* obliquity factor */
				txa *=tx/t;
				
				if(sph) { /* 3D spherical divergence */
					z=vrms[i]/2.0*(t);
					r=sqrt(SQR(offset)+SQR(z));
					txa *=vrms[i]*r;
				}
					
				outd[i]=txa;
			}
		}
	}
	/* tapering and zeroing above the apperture */
	{ register int si,ei,it;
		si=MAX(imt,0);
		ei=MIN(imt+30,nt);
 		memset( (void *) &outd[0], (int) '\0',si*FSIZE);
		for(it=si;it<ei;it++) outd[it]
			*=(float)sin((double)((it-si)*1.57/30.0));
	}
	return;
}
Example #11
0
int main(int argc, char* argv[])
{
  int verbose;
  sf_file in=NULL, out=NULL;
  int n1_traces;
  int n1_headers;

  char* header_format=NULL;
  sf_datatype typehead;
  /* kls do I need to add this?  sf_datatype typein; */
  float* fheader=NULL;
  float* intrace=NULL;
  float o1;
  float d1;
  int indx_offset;
  float* local_sloth=NULL;
  float v0;
  int indx_time;
  float offset;
  float offset2;
  float* r_index_tx_of_it0=NULL;
  float* r_index_t0_of_itx=NULL;
  int start_indx_nmo;
  int start_indx_nmo_tx;
  float* outtrace=NULL;
  float itrace=0;
  float nmostretch;
  char* offsetname;
  float lmute;
  bool inv;
  /******************************************************/
  /* code block for standard tah Trace And Header setup */
  /******************************************************/

  sf_init (argc,argv);

  /*****************************/
  /* initialize verbose switch */
  /*****************************/
  if(!sf_getint("verbose",&verbose))verbose=1;
  /* \n
     flag to control amount of print
     0 terse, 1 informative, 2 chatty, 3 debug
  */
  sf_warning("verbose=%d",verbose);
 
  /******************************************/
  /* input and output data are stdin/stdout */
  /******************************************/

  if(verbose>0)fprintf(stderr,"read in file name\n");  
  in = sf_input ("in");

  if(verbose>0)fprintf(stderr,"read out file name\n");
  out = sf_output ("out");

  if (!sf_histint(in,"n1_traces",&n1_traces))
    sf_error("input data not define n1_traces");
  if (!sf_histint(in,"n1_headers",&n1_headers)) 
    sf_error("input data does not define n1_headers");

  header_format=sf_histstring(in,"header_format");
  if(strcmp (header_format,"native_int")==0) typehead=SF_INT;
  else                                       typehead=SF_FLOAT;

  if(verbose>0)fprintf(stderr,"allocate headers.  n1_headers=%d\n",n1_headers);
  fheader = sf_floatalloc(n1_headers);
 
  if(verbose>0)fprintf(stderr,"allocate intrace.  n1_traces=%d\n",n1_traces);
  intrace= sf_floatalloc(n1_traces);

  /* maybe I should add some validation that n1== n1_traces+n1_headers+2
     and the record length read in the second word is consistent with 
     n1.  */
  /**********************************************************/
  /* end code block for standard tah Trace And Header setup */
  /* continue with any sf_puthist this tah program calls to */
  /* add to the history file                                */
  /**********************************************************/

  /* put the history from the input file to the output */
  sf_fileflush(out,in);


  /********************************************************/
  /* continue initialization specific to this tah program */
  /********************************************************/
  if (!sf_histfloat(in,"d1",&d1))
    sf_error("input data does not define d1");
  if (!sf_histfloat(in,"o1",&o1))
    sf_error("input data does not define o1");
  /* Kls should read label1 and verify it is time  
  if (!sf_histstring(in,"label1",&label1))
    sf_error("input data not define label1");
  */

  /* segy_init gets the list header keys required by segykey function  */
  segy_init(n1_headers,in);
  /* get index to keys I will be using */
  if(NULL==(offsetname=sf_getstring("offset")))offsetname="offset";
  /* name of the header key to use for offset (usually just offset) */
  indx_offset=segykey(offsetname);
  /* kls what other header keys do I use?  inline? xline? cdp? */

  /* get the parameter for the maximum nmo stretch. */
  if (!sf_getfloat("str",&nmostretch)) nmostretch=0.5;
  /* maximum stretch allowed */

  if (!sf_getfloat("lmute",&lmute)) lmute=12.*d1; 
  /* length of the mute zone in seconds */
  if(verbose>0)  fprintf(stderr,"lmute=%f seconds.\n",lmute);
  lmute/=d1;
  if(!sf_getbool("inv",&inv)) inv=false;
  /* if y, do inverse nmo.  Otherwise forward nmo */ 
   
  if(verbose>0){
    if(inv)fprintf(stderr,"inv=true\n");
    else fprintf(stderr,"inv=false\n");
  }
   
  /* set up velocity function ( really (1/v)**2, sloth */
  local_sloth=sf_floatalloc(n1_traces);
  /* just constant velocity today */
  if(1==1){
    char** list_of_floats;
    float* vnmo;
    float* tnmo;
    int numvnmo;
    int numtnmo;
    float t0;

    if(verbose>1)fprintf(stderr,"read vnmo/tnmo\n");
    /* use this fundtion to find out number of velocities and time 
       input in vnmo and tnmo */
    list_of_floats=sf_getnstring("vnmo",&numvnmo);
    /* list of NMO velocities for the time in tnmo */
    if(verbose>1){
      int i;
      fprintf(stderr,"numvnmo=%d\n",numvnmo);
      for (i=0; i<numvnmo; i++){
	fprintf(stderr,"velocities=%s\n",list_of_floats[i]);
      }
    }
    /* should free this list of strings, but that is only a little memory */\
    list_of_floats=sf_getnstring("tnmo",&numtnmo);
    /* NMO times for the vnmo velocities. */
    if(verbose>1){
      int i;
      for (i=0; i<numtnmo; i++){
	fprintf(stderr,"times=%s\n",list_of_floats[i]);
      }
    }
    if(numvnmo!=numtnmo){
      sf_error("number vnmo floats=%d != number tnmo floats=%d",
	       numvnmo,numtnmo);
    }
    if(numvnmo==0)sf_error("vnmo parameter is required");
    vnmo=sf_floatalloc(numvnmo);
    tnmo=sf_floatalloc(numtnmo);
    if(verbose>1)fprintf(stderr,"sf_getfloats(vnmo)");
    if (!sf_getfloats("vnmo",vnmo,numvnmo))
      sf_error("unable to read vnmo");
    /* list of NMO velocities for the tnmo times. */
    if(verbose>1)fprintf(stderr,"sf_getfloats(tnmo)");
    if (!sf_getfloats("tnmo",tnmo,numtnmo))
      sf_error("unable to read tnmo");
    /* list of NMO times for the vnmo velocities. */
    if(verbose>1){
      for(indx_time=0; indx_time<numvnmo; indx_time++){
	fprintf(stderr,"indx=%d, vnmo=%f, tnmo=%f\n",
		indx_time,vnmo[indx_time],tnmo[indx_time]);
      }
    }
    if(verbose>1)fprintf(stderr,"interpolate the velocity\n");
    for(indx_time=0; indx_time<n1_traces; indx_time++){
      t0=indx_time*d1+o1;
      intlin(numtnmo,tnmo,vnmo,vnmo[0],vnmo[numvnmo-1],1,&t0,&v0);
      local_sloth[indx_time]=1.0/(v0*v0);
    }    
  } 
  /* kls
     previous if(1==1) clause if for it no input velocity file
     need to add else { set up the input velocity file (ie open the file(
     inside the trace loop need to get iline and xline form trace heder
     and use that to read the velocity at (iline,xline) into local_sloth
     then compute local_sloth as 1/(v*v)

     will need to get input velocity shape:
       if (!sf_histint(invelocity,"n1",&n1_velocity))
          sf_error("input velocity file does not define n1");
     test n1_velocity!=n1_trace error
     and do the same for d1, o2, d2, etc 
   */

  if(verbose>0)fprintf(stderr,"allocate arrays for the trace loop\n");
  r_index_tx_of_it0=sf_floatalloc(n1_traces);
  r_index_t0_of_itx=sf_floatalloc(n1_traces);
  outtrace         =sf_floatalloc(n1_traces);
  

  /***************************/
  /* start trace loop        */
  /***************************/
  if(verbose>0)fprintf(stderr,"start trace loop\n");
  while (0==get_tah(intrace, fheader, n1_traces, n1_headers, in)){
    if(verbose>1)fprintf(stderr,"process the tah in sftahnmo\n");
    /********************/
    /* process the tah. */
    /********************/
    /* this program applies moveout */
    /* kls this should be only be done when velocity (local_sloth) 
       or offset changes */
    if(typehead == SF_INT){   
      /* just cast the header to int so the print works */
      offset=((int*)fheader)[indx_offset];
    } else {
      offset=       fheader [indx_offset];
    }
    offset2=offset*offset;
    for(indx_time=0; indx_time<n1_traces; indx_time++){
      float tx, t0;
      t0=indx_time*d1+o1;
      tx=sqrt(t0*t0+offset2*local_sloth[indx_time]);
      r_index_tx_of_it0[indx_time]=(tx-o1)/d1;
      if(itrace==0 && verbose>4){
	fprintf(stderr,"indx_time=%d, tx=%f, sloth=%g, offset=%f, t0=%f\n",
		        indx_time   , tx   , local_sloth[indx_time]  ,
                                                       offset   , t0);
      }
    }
    /* kls nmo start time should depend on the nmo stretch limit.
       Find the excessive stretch closest to the bottom of the trace.  This 
       is the last time nmstrewtch is violated.  It is OK to apply nmo
       to the rest of the trace. */
    for (start_indx_nmo=n1_traces-1; start_indx_nmo>1; start_indx_nmo--){
      /* pfrintf(stderr,"r_indx[it]=%f, rindx */
      if((r_index_tx_of_it0[start_indx_nmo  ]-
	  r_index_tx_of_it0[start_indx_nmo-1])  <nmostretch) break;
    }
    if(inv){
      start_indx_nmo_tx = 1.0+r_index_tx_of_it0[start_indx_nmo];
      if(start_indx_nmo_tx>n1_traces-2)start_indx_nmo_tx = n1_traces-2;
      /* compute r_index_t0_of_itx from r_index_tx_of_it0 */
      yxtoxy(n1_traces-start_indx_nmo,1.0, start_indx_nmo,
	     &r_index_tx_of_it0[start_indx_nmo],
 
	     n1_traces-start_indx_nmo_tx,1.0, start_indx_nmo_tx,
	     -1,n1_traces,&r_index_t0_of_itx[start_indx_nmo_tx]);
    }
    /* kls inverse nmo? will need more code */
    /* do nmo via 8-point sinc interpolation */
    /* void ints8r (int nxin, float dxin, float fxin,      
                    float yin[], float yinl, float yinr, 
		    int nxout, float xout[], 
		    float yout[]) */
    if(!inv){
      ints8r(n1_traces,1.0,0,
	     intrace,0.0,0.0,
	     n1_traces-start_indx_nmo,&r_index_tx_of_it0[start_indx_nmo],
	     &outtrace[start_indx_nmo]);
      /* zero above the start time */
      for(indx_time=0; indx_time<start_indx_nmo; indx_time++){
	outtrace[indx_time]=0.0;
      }
      /* apply linear ramp kls */
      for (indx_time=start_indx_nmo; 
	   indx_time<start_indx_nmo+lmute && indx_time<n1_traces;
	   indx_time++){
	outtrace[indx_time] *= (float)(indx_time-start_indx_nmo+1)/(float)lmute;
      }
    }else{
      ints8r(n1_traces,1.0,0,
	     intrace,0.0,0.0,
	     n1_traces-start_indx_nmo_tx,&r_index_t0_of_itx[start_indx_nmo_tx],
	     &outtrace[start_indx_nmo_tx]);      
      /* zero above the start time */
      for(indx_time=0; indx_time<start_indx_nmo_tx; indx_time++){
	outtrace[indx_time]=0.0;
      }
    }
    /***************************/
    /* write trace and headers */
    /***************************/
    put_tah(outtrace, fheader, n1_traces, n1_headers, out);
    itrace++;
  }
  
  exit(0);
}
Example #12
0
int main(int argc, char *argv[]) {
    int opt;
    char *optstring="dhs:";

    int sfd, fdmax, ret;
    fd_set  readfds, rfds;
    struct timeval timeout;
    struct tm *gmp, *locp;

    int i, numRead;
    char buf[BUF_SIZE];
    
    struct param_st theParams;
    struct gps_st   gpsStat;

    int sampleRate = 4000;

    /* 
     * command-line processing
     */
    debug=opterr=0;
    while((opt=getopt(argc,argv,optstring)) != -1) {
	switch(opt) {
	case 's': 
	    sampleRate = atoi(optarg);
	    break;
	case 'd':
	    debug++;
	    break;
	case '?':
	case 'h':
	default:
	    fprintf(stderr, "Usage: %s\n", "gp_store TODO");
	    exit(-1);
	}
    }

    if(debug)
	printf("gp_qc: sampRate=%d\n", sampleRate);

    struct sigaction sa;
    // sigterm
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0;
    sa.sa_handler = sig_handler;
    if(sigaction(SIGTERM, &sa, NULL) == -1)
	errExit("sched: sigaction");

    /* connect to the udp socket */
    int ufd;
    //    char udp_path[128];
    //    snprintf(udp_path, 128, "%s.%d", UDP_SOCK_PATH, (long) getpid())
	//    ufd = unixBind(udp_path, SOCK_DGRAM);
    ufd = unixConnect(UDP_SOCK_PATH, SOCK_DGRAM);
    if(ufd < 0)
	errMsg("gp_store: udp bind");

    float dt_in = 1. / (float)sampleRate;
    int resampleRate = 500;
    float fpasshi, fstophi, apasshi, astophi;
    int npoleshi;
    float f3dbhi;
    fpasshi = (float) resampleRate / (float) sampleRate;
    fstophi = 1.2 * fpasshi;
    apasshi = 0.95;
    astophi = 0.05;

    if(debug)
	printf("f = %f %f a =%f %f\n", fpasshi, fstophi, apasshi, astophi);
    bfdesign(fpasshi, apasshi, fstophi, astophi, &npoleshi, &f3dbhi);
    if(debug)
	printf("npoles = %d f3db = %f\n", npoleshi, f3dbhi); 

    int n=sampleRate / 10; // operate on 1 s at a time
    float *p, *q;
    if((p=(float *)malloc(n*sizeof(float))) == NULL)
	errExit("qc: malloc");
    if((q=(float *)malloc(n*sizeof(float))) == NULL)
	errExit("qc: malloc");

    int dec = sampleRate / resampleRate;
    int nDec = n / dec;
    float *r, *t, dt_out = dt_in * dec;
    if((r=(float *)malloc(nDec*sizeof(float))) == NULL)
	errExit("qc: malloc");
    if((t=(float *)malloc(nDec*sizeof(float))) == NULL)
	errExit("qc: malloc");
    for(i=0; i<nDec; i++)
	t[i] = i * dt_out;
    if(debug)
	printf("samp %d resamp %d dt %f dtout %f n %d nDec %d\n",
	       sampleRate, resampleRate, dt_in, dt_out, n, nDec);
    
    /* allocate the space for the udppkt.  The zero length array is
       allocated here */
    struct udppkt_st *u;
    int nWrt, pktSize = sizeof(struct udppkt_st) + nDec * sizeof(float);
    if((u=malloc(pktSize)) == NULL)
	errExit("qc: malloc");
    
    while(STOP == FALSE) {
	/* n samples are collected from DMA here... */
	/* copy into p */
	/* antialias filter */
	if(dec > 1) {
	    bflowpass(npoleshi, f3dbhi, n, p, q);
	    ints8r(n, dt_in, 0., q, 0., 0., nDec, t, r);
	    if(ufd>0) { // send the data to base station
		u->dt = dt_out;
		u->ns = nDec;
		// u.t0.tv_sec = ; u.t0.tv_usec =
		memcpy(u->d, r, nDec * sizeof(float));
		if((nWrt = write(ufd, u, pktSize)) != pktSize)
		    errMsg("qc: write");
	    }
	}
    }
}