コード例 #1
0
ファイル: modeling.c プロジェクト: JOravetz/SeisUnix
void decodeReflectors (int *nrPtr,
	float **aPtr, int **nxzPtr, float ***xPtr, float ***zPtr)
/*************************************************************************
decodeReflectors - parse reflectors parameter string
**************************************************************************
Output:
nrPtr		pointer to nr an int specifying number of reflectors
aPtr		pointer to a specifying reflector amplitudes
nxzPtr		pointer to nxz specifying number of (x,z) pairs defining the
		reflectors
xPtr		pointer to array[x][nr] of x values for the entire model
zPtr		array[z][nr] of z values for the entire model

***************************************************************************
Author: Dave Hale, Colorado School of Mines, 09/17/91
**************************************************************************/
{
	int nr,*nxz,ir;
	float *a,**x,**z;
	char t[1024],*s;

	/* count reflectors */
	nr = countparname("ref");
	if (nr==0) nr = 1;
	
	/* allocate space */
	a = ealloc1(nr,sizeof(float));
	nxz = ealloc1(nr,sizeof(int));
	x = ealloc1(nr,sizeof(float*));
	z = ealloc1(nr,sizeof(float*));

	/* get reflectors */
	for (ir=0; ir<nr; ++ir) {
		if (!getnparstring(ir+1,"ref",&s)) s = "1:1,2;4,2";
		strcpy(t,s);
		if (!decodeReflector(t,&a[ir],&nxz[ir],&x[ir],&z[ir]))
			err("Reflector number %d specified "
				"incorrectly!\n",ir+1);
	}

	/* set output parameters before returning */
	*nrPtr = nr;
	*aPtr = a;
	*nxzPtr = nxz;
	*xPtr = x;
	*zPtr = z;
}
コード例 #2
0
ファイル: sunmo.c プロジェクト: gwowen/seismicunix
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());
}
コード例 #3
0
ファイル: sudlmo.c プロジェクト: JohnWStockwellJr/SeisUnix
int
main(int argc, char **argv)
{
	float phase;		/* phase shift = phasefac*PI		*/
	float power;		/* phase shift = phasefac*PI		*/
	register float *rt;	/* real trace				*/
	register complex *ct;	/* complex transformed trace		*/
	complex *filt;		/* complex power	 		*/
	int nt;			/* number of points on input trace	*/
	size_t ntsize;		/* nt in bytes				*/
	int ncdp;               /* number of cdps specified */
	int icdp;       	/* index into cdp array */

	long oldoffset;         /* offset of previous trace */
        long oldcdp;    	/* cdp of previous trace */
        int newsloth;   	/* if non-zero, new sloth function was computed */
	int jcdp;       	/* index into cdp array */
	float dt;		/* sample spacing (secs) on input trace	*/
	float tn;		/* sample spacing (secs) on input trace	*/
	float omega;		/* circular frequency			*/
	float domega;		/* circular frequency spacing (from dt)	*/
	int nfft;		/* number of points in nfft		*/
	int ntnmo;      	/* number of tnmos specified            */
	float *cdp;     	/* array[ncdp] of cdps */

	float *vnmo;   		/* array[nvnmo] of vnmos               */
	float *ovvt;   		/* array[nvnmo] of vnmos               */
	int nvnmo;      	/* number of tnmos specified            */
	float *fnmo;   		 /* array[ntnmo] of tnmos               */
	float **ovv;   		 /* array[nf] of fnmos                  */
	float doffs;             /* offset                            */
	float acdp;     	/* temporary used to sort cdp array */
        float *aovv;    	/* temporary used to sort ovv array */

        int invert;              /*  if non-zero, do invers DLMO       */
        int cm;                  /*  if non-zero, the offset in cm     */
        int nf;                 /* number of frequencies (incl Nyq)     */
        int it;                 /* number of frequencies (incl Nyq)     */
	float onfft;		/* 1 / nfft				*/
	float v;                 /* velocity                            */
	size_t nzeros;		/* number of padded zeroes in bytes	*/
	
	
	/* Initialize */
	initargs(argc, argv);
	requestdoc(1);

	/* Set parameters */
	power=0.0;

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

	nt = tr.ns;

	if (!getparfloat("dt", &dt))	dt = ((double) tr.dt)/1000000.0;
	if (!dt)	err("dt field is zero and not getparred");
	ntsize = nt * FSIZE;

        if (!getparint("invert",&invert)) invert = 0;
        if (!getparint("cm",&cm)) cm = 0;

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

        nf = nfft/2 + 1;
        onfft = 1.0 / nfft;
	nzeros = (nfft - nt) * FSIZE;
	domega = TWOPI * onfft / dt;


	/* get velocity functions, linearly interpolated in frequency */

	ncdp = countparval("cdp");

	if (ncdp>0) {
                if (countparname("vnmo")!=ncdp)
                        err("a vnmo array must be specified for each cdp");
                if (countparname("fnmo")!=ncdp)
                        err("a tnmo array must be specified for each cdp");
        } else {
                ncdp = 1;
                if (countparname("vnmo")>1)
                        err("only one (or no) vnmo array must be specified");
                if (countparname("fnmo")>1)
                        err("only one (or no) tnmo array must be specified");
        }

	cdp = ealloc1float(ncdp);
        if (!getparfloat("cdp",cdp)) cdp[0] = tr.cdp;
        ovv = ealloc2float(nf,ncdp);

	for (icdp=0; icdp<ncdp; ++icdp) {
                nvnmo = countnparval(icdp+1,"vnmo");
                ntnmo = countnparval(icdp+1,"fnmo");
                if (nvnmo!=ntnmo && !(ncdp==1 && nvnmo==1 && ntnmo==0))
                        err("number of vnmo and tnmo values must be equal");
                if (nvnmo==0) nvnmo = 1;
                if (ntnmo==0) ntnmo = nvnmo;
                /* equal numbers of parameters vnmo, fnmo  */

                vnmo = ealloc1float(nvnmo);
                fnmo = ealloc1float(nvnmo);

                if (!getnparfloat(icdp+1,"vnmo",vnmo)) vnmo[0] = 400.0;
                if (!getnparfloat(icdp+1,"fnmo",fnmo)) fnmo[0] = 0.0;
		

		for (it=0; it<ntnmo; ++it)
			fnmo[it]*=TWOPI;

                for (it=1; it<ntnmo; ++it)
                        if (fnmo[it]<=fnmo[it-1])
                                err("tnmo values must increase monotonically");

		for (it=0,tn=0; it<nf; ++it,tn+=domega) {
			intlin(ntnmo,fnmo,vnmo,vnmo[0],vnmo[nvnmo-1],1,&tn,&v);
			ovv[icdp][it] = 1.0/(v); 
		}
                free1float(vnmo);
                free1float(fnmo);
        }



/* sort (by insertion) sloth and anis functions by increasing cdp */

        for (jcdp=1; jcdp<ncdp; ++jcdp) {
                acdp = cdp[jcdp];
                aovv = ovv[jcdp];
                for (icdp=jcdp-1; icdp>=0 && cdp[icdp]>acdp; --icdp) {
                        cdp[icdp+1] = cdp[icdp];
                        ovv[icdp+1] = ovv[icdp];
                }
                cdp[icdp+1] = acdp;
                ovv[icdp+1] = aovv;
        }

/* allocate workspace */


        ovvt = ealloc1float(nf);

/* interpolate sloth and anis function for first trace */

        interpovv(nf,ncdp,cdp,ovv,(float)tr.cdp,ovvt);

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



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


		

	/* Loop over traces */
	do {

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

		/* if sloth and anis function or offset has changed */

                if (newsloth || tr.offset!=oldoffset) {

		doffs = (fabs)((float)(tr.offset));
		if (cm==1) doffs/=100;
		/* Load trace into rt (zero-padded) */
		memcpy( (void *) rt, (const void *) tr.data, ntsize);
		memset((void *) (rt + nt), (int) '\0', nzeros);

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


		/* Apply filter */
		{ register int i;
		for (i = 0; i < nf; ++i){
			omega = i * domega;
			if (power < 0 && i == 0) omega = FLT_MAX;
			if (invert==0)
			phase = -1.0*omega*ovvt[i]*doffs;
			else
			phase = 1.0*omega*ovvt[i]*doffs;
			
		/*	filt[i] = cmplx(cos(phase),sin(phase)); */
			filt[i] = cwp_cexp(crmul(I,phase)); 
			filt[i] = crmul(filt[i], onfft);
			ct[i] = cmul(ct[i], filt[i]);
			
			}
		}
	  }
		/* Invert */
		pfacr(-1, nfft, ct, rt);


		/* Load traces back in, recall filter had nfft factor */
		{ register int i;
		for (i = 0; i < nt; ++i)  tr.data[i] = rt[i];
		}


		puttr(&tr);

	} while (gettr(&tr));


	return EXIT_SUCCESS;
}
コード例 #4
0
ファイル: getpars.c プロジェクト: JOravetz/SeisUnix
main(int argc, char **argv)
{
	char *s;
	short h, vh[N];
	unsigned short u, vu[N];
	long l, vl[N];
	unsigned long v, vv[N];
	int i, vi[N], ipar, npar, nval;
	unsigned int p, vp[N];
	float f, vf[N];
	double d, vd[N];

	initargs(argc, argv);

	/* int parameters */
	npar = countparname("i");
	printf("\nnumber of i pars = %d\n",npar);
	for (ipar=1; ipar<=npar; ++ipar) {
		getnparint(ipar,"i",&i);
		printf("occurence %d of i=%d\n",ipar,i);
	}
	if (getparint("i", &i))	
		printf("last occurence of i=%d\n",i);
	npar = countparname("vi");
	printf("number of vi pars = %d\n",npar);
	for (ipar=1; ipar<=npar; ++ipar) {
		nval = countnparval(ipar,"vi");
		printf("occurence %d has %d values\n",ipar,nval);
		nval = getnparint(ipar,"vi",vi);
		printf("vi=");
		for (i=0; i<nval; i++)
			printf("%d%c",vi[i],i==nval-1?'\n':',');
	}
	if (npar>0) {
		nval = countparval("vi");
		printf("last occurence has %d values\n",nval);
		getparint("vi",vi);
		printf("vi=");
		for (i=0; i<nval; i++)
			printf("%d%c",vi[i],i==nval-1?'\n':',');
	}

	/* float parameters */
	npar = countparname("f");
	printf("\nnumber of f pars = %d\n",npar);
	for (ipar=1; ipar<=npar; ++ipar) {
		getnparfloat(ipar,"f",&f);
		printf("occurence %d of f=%g\n",ipar,f);
	}
	if (getparfloat("f", &f))	
		printf("last occurence of f=%g\n",f);
	npar = countparname("vf");
	printf("number of vf pars = %d\n",npar);
	for (ipar=1; ipar<=npar; ++ipar) {
		nval = countnparval(ipar,"vf");
		printf("occurence %d has %d values\n",ipar,nval);
		nval = getnparfloat(ipar,"vf",vf);
		printf("vf=");
		for (i=0; i<nval; i++)
			printf("%g%c",vf[i],i==nval-1?'\n':',');
	}
	if (npar>0) {
		nval = countparval("vf");
		printf("last occurence has %d values\n",nval);
		getparfloat("vf",vf);
		printf("vf=");
		for (i=0; i<nval; i++)
			printf("%g%c",vf[i],i==nval-1?'\n':',');
	}

	/* string parameters */
	npar = countparname("s");
	printf("\nnumber of s pars = %d\n",npar);
	for (ipar=1; ipar<=npar; ++ipar) {
		getnparstring(ipar,"s",&s);
		printf("occurence %d of s=%s\n",ipar,s);
	}
	if (getparstring("s", &s))	
		printf("last occurence of s=%s\n",s);
	
	if( auxgetpar("aux","i","i",&i) ) 
		printf("in aux last occurence of i=%d\n",i);
	if( auxgetpar("aux","f","f",&f) )
		printf("in aux last occurence of f=%f\n",f);
	if( auxgetpar("aux","s","s",&s) ) 
		printf("in aux last occurence of s=%s\n",s);

	if (getparint("i", &i))	
		printf("last occurence of i=%d\n",i);
	if( auxgetpar("aux","junk","s",&s) ) 
		printf("in aux last occurence of junk=%s\n",s);

	return EXIT_SUCCESS;
}
コード例 #5
0
ファイル: suinterpfowler.c プロジェクト: gwowen/seismicunix
/**************** end self doc ********************************/

segy tr;	/* Input and output trace data of length nt */
int main (int argc, char **argv)
{
	int nt;
	int icmp;
	int j;
	int neta;
	int nv;
	int ncdps;
	int nc;
	int ic;
	int ic1=0;
	int ic2=0;
	int it;
	int iv;
	int ie;
	int nvel;
	int nvstack;


	float *c;
	float *v;
	float *t;
	float *e;

	float *time;
	float *eta;
	float *vel;
	float *p;

	float vminstack;
	float dt;
	float vmin;
	float vmax;
	float etamin;
	float etamax;
	float dv;
	float deta;
	float wc=0.0;
	float wv;
	float we;
	float ee;
	float vv;
	float vscale;

	initargs(argc,argv);
	requestdoc(1);

	if (!getparint("nv",&nv)) nv = 21;
	if (!getparint("neta",&neta)) neta=11;
	if (!getparint("ncdps",&ncdps)) ncdps = 1130;
	if (!getparfloat("vmin",&vmin)) vmin = 1500.;
	if (!getparfloat("vmax",&vmax)) vmax = 2500.;
	if (!getparfloat("etamin",&etamin)) etamin = 0.10;
	if (!getparfloat("etamax",&etamax)) etamax = 0.25;
	if (!getparint("nvstack",&nvstack)) nvstack = 0;
	if (!getparfloat("vminstack",&vminstack)) vminstack = 0.25;
	if (!getparfloat("vscale",&vscale)) vscale = 1.0;

	dv=(vmax-vmin)/MAX((nv-1),1);
	deta = (etamax-etamin)/MAX((neta-1),1);
	if(deta==0) {
		deta=1;
		neta=1;
	}
	if(nvstack>5) {
		etamin=0;
		etamax=0.;
		deta=1.;
		vmin=0.;
		nv=nvstack;
		neta=1;
		dv=1./(vminstack*vminstack*(nvstack-5));
	}

	if (!gettr(&tr))  err("can't get first trace");
	nt = tr.ns;
	dt = 0.000001*tr.dt;
	fprintf(stderr,"supaint: sample rate = %f s, number of samples = %d\n",
		dt,nt);
	p = ealloc1float(nv*neta*nt);

	nc = countparname("cdp");
	if(countparname("v")!=nc) err("v array must be specified for each cdp");
	if(countparname("t")!=nc) err("t array must be specified for each cdp");
	if(nvstack<6){
		if(countparname("eta")!=nc) err("eta array must be specified for each cdp");
	}
	vel=ealloc1float(nc*nt);
	eta=ealloc1float(nc*nt);
	time=ealloc1float(nt);
	c=ealloc1float(nc);
	for(it=0;it<nt;it++) time[it]=it*dt;
	if(nvstack>5) {
	    for(ic=0;ic<nc;ic++) {
		getnparfloat(ic+1,"cdp",&c[ic]);
		nvel=countnparval(ic+1,"v");
		fprintf(stderr,"cdp=%f, number of (time,velocity) values = %d\n",c[ic],nvel);
		if(countnparval(ic+1,"t")!=nvel)
			err("For each cdp control point, t and v must have the same number of values");
		v=ealloc1float(nvel);
		t=ealloc1float(nvel);
		getnparfloat(ic+1,"t",t);
		getnparfloat(ic+1,"v",v);
		for(j=0;j<nvel;j++) v[j]*=vscale;
		for(j=0;j<nvel;j++) fprintf(stderr,"	time=%f velocity=%f\n",t[j],v[j]);
		intlin(nvel,t,v,v[0],v[nvel-1],nt,time,&vel[ic*nt]);
		free(v);
		free(t);	
	    }
	    for(j=0;j<nt*nc;j++) {
		vel[j]=1./(vel[j]*vel[j]);
		eta[j]=0.;
	    }
	}else{
	    for(ic=0;ic<nc;ic++) {
		getnparfloat(ic+1,"cdp",&c[ic]);
		nvel=countnparval(ic+1,"v");
		fprintf(stderr,"cdp=%f, number of triplet values = %d\n",c[ic],nvel);
		if(countnparval(ic+1,"t")!=nvel || countnparval(ic+1,"eta")!=nvel ) 
			err("For each cdp control point, t,v,and eta must have the same number of values");
		v=ealloc1float(nvel);
		t=ealloc1float(nvel);
		e=ealloc1float(nvel);
		getnparfloat(ic+1,"t",t);
		getnparfloat(ic+1,"v",v);
		for(j=0;j<nvel;j++) v[j]*=vscale;
		getnparfloat(ic+1,"eta",e);
		for(j=0;j<nvel;j++) {
			fprintf(stderr,"	time=%f velocity=%f eta=%f\n",
				t[j],v[j],e[j]);
		}
		intlin(nvel,t,v,v[0],v[nvel-1],nt,time,&vel[ic*nt]);
		intlin(nvel,t,e,e[0],e[nvel-1],nt,time,&eta[ic*nt]);
		free(v);
		free(t);
		free(e);
	    }
	}
	free(time);
	for(icmp=0;icmp<ncdps;icmp++) {
		for(j=0;j<(nv*neta);j++) {
			if(icmp==0 && j==0 ) {
				/* data already in memory */
			}else{
				if (!gettr(&tr))  
					err("can't get input trace");
			}
			for(it=0;it<nt;it++)
				p[it+j*nt]=tr.data[it];
		}
		if(icmp<=c[0]) {
			ic1=0;
			ic2=0;
			wc=0.;
		}else if(icmp>=c[nc-1]) {
			ic1=nc-1;
			ic2=nc-1;
			wc=0.;
		}else{
			for(ic=1;ic<nc;ic++) {
				ic1=ic-1;
				ic2=ic;
				wc=(c[ic2]-icmp)/(c[ic2]-c[ic1]);
				if(icmp>c[ic1] && icmp<=c[ic2]) break;
			}
		}

		for(it=0;it<nt;it++) {
			ee=(wc*eta[it+ic1*nt]+(1.-wc)*eta[it+ic2*nt]-etamin)/deta;
			vv=(wc*vel[it+ic1*nt]+(1.-wc)*vel[it+ic2*nt]-vmin)/dv;
			ie=ee;
			we=ee-ie;
			iv=vv;
			wv=vv-iv;
			tr.data[it]=0.;
			if(neta==1) {
				if(iv>=0 && iv<nv-1) {
					tr.data[it]=(1-wv)*p[it+iv*nt] + 
							wv*p[it+(iv+1)*nt];	
				}
			}else if(iv>=0 && iv<nv-1 && ie>=0 && ie<neta-1) {
				tr.data[it]=(1-we)*(1-wv)*p[it+(ie*nv+iv)*nt]+
					(1-we)*wv*p[it+(ie*nv+iv+1)*nt]+
					we*(1-wv)*p[it+((ie+1)*nv+iv)*nt]+
					we*wv*p[it+((ie+1)*nv+iv+1)*nt];
				}
		}
		tr.f2=0.;
		tr.d2=1.;
		tr.f1=0.;
		tr.d1=dt;
		tr.offset=0;
		tr.cdp=icmp;
		tr.igc=0;
		tr.igi=0;
		tr.sx=0.5*(tr.sx+tr.gx);
		tr.gx=tr.sx;
		tr.cdpt=0;
		puttr(&tr);
		if(icmp==20*(icmp/20)) fprintf(stderr,"supaint: have output cmp %d\n",icmp);
	}
	free(p);
	free(c);
	free(eta);
	free(vel);
	return EXIT_SUCCESS;
}
コード例 #6
0
ファイル: sucdpnorm.c プロジェクト: JOravetz/SeisUnix
main(int argc, char **argv)
{
	int nt;		/* number of time samples per trace */
	int it;		/* time sample index */
	char *datain, *dataout;
	int cdppre,cdpnow;
	FILE *infp,*outfp;
	float scale;
	int maxfold, ix, nfold; 
	float *data;
	char *header;
	int op;
	int nofo;
	float *fold, *ofo, oofo, dofo;
	int itmp, iofoin;
	int *iofo, one, io;
	float ofol, ofor, tmp;
	int signof;
	
	
	/* hook up getpar */
	initargs(argc, argv);
	askdoc(1);

	/* get required parameters */

	if (!getparstring("datain",&datain)) {
		infp = stdin;
	} else {
		infp = efopen(datain,"r");
	} 
	file2g(infp);

	if (!getparstring("dataout",&dataout)) {
		outfp = stdout;
	} else {
		if(strcmp(dataout,datain)) { 
			outfp = efopen(dataout,"w");
		} else {
			outfp = efopen(dataout,"r+w");
		}
	} 
	file2g(outfp);

	/* get information from the first header */
	if (!fgettr(infp,&tri)) err("can't get first trace");
	nt = tri.ns;
	
	/* get other optional parameters */
	if (!getparint("maxfold",&maxfold)) maxfold = 120;
	if (!getparint("op",&op)) op = 1;
	if (!getparint("nofo",&nofo)) nofo = 1;
	if (!getparfloat("oofo",&oofo)) oofo = 0.;
	if (!getparfloat("dofo",&dofo)) dofo = 999999.;
	if (!getparint("signof",&signof)) signof = 1;
        itmp = countparname("ofo");
        if(itmp>0 && itmp!=nofo) err("number of ofo not match with nofo");
        ofo = (float*) emalloc(nofo*sizeof(float));
        if(itmp>0) {
                getparfloat("ofo",ofo);
                if(nofo>1) {
                        ofol = ofo[0] - 0.5*(ofo[1]-ofo[0]);
                        ofor = ofo[nofo-1] + 0.5*(ofo[nofo-1]-ofo[nofo-2]);
                } else {
                        ofol = ofo[0] - 0.5*dofo;
                        ofor = ofo[nofo-1] + 0.5*dofo;
	                oofo = ofo[0];
                }
        } else {
                for(io=0;io<nofo;io++) ofo[io] = oofo + io*dofo;
        }
        iofoin = itmp;


	data = (float*) malloc(nt*maxfold*sizeof(float));
	header = (char*) malloc(HDRBYTES*maxfold*sizeof(char));
	fold = (float*) malloc(nofo*sizeof(float));
	iofo = (int*) malloc(maxfold*sizeof(int));

	cdppre = tri.cdp;
	bzero(fold,nofo*sizeof(float));

	/* loop over traces */
	do {

		cdpnow = tri.cdp;
		if (cdpnow==cdppre) {
			tmp  = tri.offset;
			if(signof==1 && tmp<0. ) tmp = -tmp;
                	if(iofoin==0 || nofo==1 ) {
                        	tmp = (tmp-oofo)/dofo+.5;
                        	io = tmp;
                	} else {
                        	if(tmp<ofol) {
                                	io = -1;
                        	} else if(tmp>ofor) {
                                	io = nofo;
                        	} else {
                                	bisear_(&nofo,&one,ofo,&tmp,&io);
                                	io = io - 1;
                                	if(io<nofo-1) {
                                        	if(abs(tmp-ofo[io])	
							>abs(tmp-ofo[io+1]))
                                                	io = io + 1;
                                	}
                        	}
                	}
			if(io>=0 && io<nofo) { 
				bcopy((char*)&tri,header+nfold*HDRBYTES,
					HDRBYTES);
				bcopy((char*)tri.data,data+nfold*nt,nt*4);
				fold[io] += 1.0; 
				iofo[nfold] = io;
				nfold = nfold + 1;
			}
		} else {
			for(ix=0;ix<nfold;ix++) {
				if(op==1) {
					scale = 1./fold[iofo[ix]];
				} else {
					scale = fold[iofo[ix]];
				}
				for(it=0;it<nt;it++) 
					tro.data[it] = data[it+ix*nt]*scale; 
				bcopy(header+ix*HDRBYTES,(char*)&tro,
					HDRBYTES);
				fputtr(outfp,&tro);
			}
			nfold = 0;
			bzero(fold,nofo*sizeof(float));
			tmp  = tri.offset;
			if(signof==1 && tmp<0. ) tmp = -tmp;
                        if(iofoin==0 || nofo==1 ) {
                                tmp = (tmp-oofo)/dofo+.5;
                                io = tmp;
                        } else {
                                if(tmp<ofol) {
                                        io = -1;
                                } else if(tmp>ofor) {
                                        io = nofo;
                                } else {
                                        bisear_(&nofo,&one,ofo,&tmp,&io);
                                        io = io - 1;
                                        if(io<nofo-1) {
                                                if(abs(tmp-ofo[io])
                                                        >abs(tmp-ofo[io+1]))
                                                        io = io + 1;
                                        }
                                }
                        }
                        if(io>=0 && io<nofo) {
                                bcopy((char*)&tri,header+nfold*HDRBYTES,
                                        HDRBYTES);
                                bcopy((char*)tri.data,data+nfold*nt,nt*4);
				fold[io] += 1.0; 
				iofo[nfold] = io;
				nfold = nfold + 1;
			}
			cdppre = cdpnow;
		}
		
	} while (fgettr(infp,&tri));

	/* output last gather */
	if(nfold>0) {
		for(ix=0;ix<nfold;ix++) {
			if(op==1) {
				scale = 1./fold[iofo[ix]];
			} else {
				scale = fold[iofo[ix]];
			}
			for(it=0;it<nt;it++) 
				tro.data[it] = data[it+ix*nt]*scale; 
			bcopy(header+ix*HDRBYTES,(char*)&tro,HDRBYTES);
			fputtr(outfp,&tro);
		}
	}
	
	return EXIT_SUCCESS;
}
コード例 #7
0
ファイル: gridsediment.c プロジェクト: JOravetz/SeisUnix
int main(int argc, char **argv)
{
	usghed usghin, usghtop, usghbot, usghlayer;
	usghed usghvtop, usghvbot, usghglayer;
	FILE *infp,*outfp,*topfp,*botfp,*layerfp;
	FILE *vtopfp,*vbotfp,*glayerfp;
	char *infile,*outfile,*layertop, *layerbot;
	char *gtopgrid, *gbotgrid;
	char *layers, *glayers;
	int ibot, itop;
	int ierr;
	int nz, iz;
	float *dzrl, sm2top, sm2bot, sm3top, sm3bot;
	float gabovetop, gbelowbot;
	int igabovetop, igbelowbot;
	float g0, r0;
	int ginterp=0;

	int n1,n2,n3;
	int i1,i2,i3;
	float d1,o1,d2,d3;

	float *grid, *ztop, *zbot, gmin, gmax;
	float *vtop, *vbot;
	float top, bot;
	float tmp;
	int i1top, i1bot, itmp;
	int ivtop, ivbot;

	float *sm2s, *sm3s;
	float *work, *fsmx, *fsmy, *vs, *zs;
	float z, scale, zscale, vscale;
	int ismx, ismy;

	int nlayer, nglayer;


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

	/* get parameters */
	if(getparstring("infile",&infile)) {
		infp = efopen(infile,"r");
	} else {
		infp = stdin;
	}
	ierr = fgetusghdr(infp,&usghin);
    	if(ierr!=0) err(" input grid header error ");
	if(getparstring("outfile",&outfile)) {
		outfp = efopen(outfile,"w");
	} else {
		outfp = stdout;
	}
	file2g(infp);
	file2g(outfp);

	nlayer = 0;
	nglayer = 0;
        nlayer = countparname("layers");
	if(nlayer==1) err(" at least 2 layers are needed \n");
        nglayer = countparname("glayers");

	if(nlayer==0) {
		if (getparstring("layertop",&layertop)) {
			topfp = efopen(layertop,"r");
			ierr = fgetusghdr(topfp,&usghtop);
      			if(ierr!=0) err(" layertop grid header error ");
		} else {
			err(" layertop missing ");
		}
		if (getparstring("layerbot",&layerbot)) {
			botfp = efopen(layerbot,"r");
			ierr = fgetusghdr(botfp,&usghbot);
      			if(ierr!=0) err(" layerbot grid header error ");
		} else {
			err(" layerbot missing ");
		}
	} else {
		if(nlayer!=nglayer && nglayer>0 ) 
		   err(" %d layers not matching %d glayers \n",nlayer,nglayer);
	}

	ivtop = 0;
	if (getparstring("gtopgrid",&gtopgrid)) {
		vtopfp = efopen(gtopgrid,"r");
		ierr = fgetusghdr(vtopfp,&usghvtop);
      		if(ierr!=0) err(" gtopgrid header error ");
		ivtop = 1;
	}
	ivbot = 0;
	if(getparstring("gbotgrid",&gbotgrid) ) {
		vbotfp = efopen(gbotgrid,"r");
		ierr = fgetusghdr(vbotfp,&usghvbot);
      		if(ierr!=0) err(" gbotgrid header error ");
		ivbot = 1;
	}
	if(!getparint("ginterp",&ginterp)) ginterp=0;

	if(ivtop==0 || ivbot==0) {
		if ( getparfloat("g0",&g0) && getparfloat("r0",&r0) ) {
			ivtop = -1; ivbot = -1;
		}
	}

	if( !getparint("nz",&nz) ) nz=10;
	if(nlayer!=0) nz = nlayer - 1;
	dzrl = emalloc(nz*sizeof(float));
	sm2s = emalloc((nz+1)*sizeof(float));
	sm3s = emalloc((nz+1)*sizeof(float));

	if( countparval("dzrl")>0 && nz!=countparval("dzrl") ) {
		err( " number of dzrl elements must match nz=%d \n",nz);
	} else if( countparval("dzrl")==0 ) {
		for(iz=0;iz<nz;iz++) dzrl[iz] = 1.;
	} else if( countparval("dzrl")==nz) {
		getparfloat("dzrl",dzrl);
	}

	if( !getparfloat("sm2top",&sm2top) ) sm2top=0.;
	if( !getparfloat("sm3top",&sm3top) ) sm3top=0.;
	if( !getparfloat("sm2bot",&sm2bot) ) sm2bot=0.;
	if( !getparfloat("sm3bot",&sm3bot) ) sm3bot=0.;

	igabovetop = 1;
	if( !getparfloat("gabovetop",&gabovetop) ) igabovetop=0;
	igbelowbot = 1;
	if( !getparfloat("gbelowbot",&gbelowbot) ) igbelowbot=0;


	n1 = usghin.n1;
	n2 = usghin.n2;
	n3 = usghin.n3;
	o1 = usghin.o1;
	d1 = usghin.d1;
	d2 = usghin.d2;
	d3 = usghin.d3;
	gmin = usghin.gmin;
	gmax = usghin.gmax;

	/* memory allocations */
	ztop = (float*) emalloc(n2*n3*sizeof(float));
	zbot = (float*) emalloc(n2*n3*sizeof(float));
	vtop = (float*) emalloc(n2*n3*sizeof(float));
	vbot = (float*) emalloc(n2*n3*sizeof(float));
	zs = (float*) emalloc(n2*n3*(nz+1)*sizeof(float));
	vs = (float*) emalloc(n2*n3*(nz+1)*sizeof(float));
	work = (float*) emalloc(n2*n3*sizeof(float));
	grid = (float*) emalloc(n1*sizeof(float));
	
	if(nlayer==0) {
		if(usghin.n2!=usghtop.n1) err("check layertop header n1");
		if(usghin.n3!=usghtop.n2) err("check layertop header n2");
		if(usghin.o2!=usghtop.o1) err("check layertop header o1");
		if(usghin.o3!=usghtop.o2) err("check layertop header o2");
		if(usghin.d2!=usghtop.d1) err("check layertop header d1");
		if(usghin.d3!=usghtop.d2) err("check layertop header d2");
		efseek(topfp,0,0);
		efread(ztop,sizeof(float),n2*n3,topfp);

		if(usghin.n2!=usghbot.n1) err("check layerbot header n1");
		if(usghin.n3!=usghbot.n2) err("check layerbot header n2");
		if(usghin.o2!=usghbot.o1) err("check layerbot header o1");
		if(usghin.o3!=usghbot.o2) err("check layerbot header o2");
		if(usghin.d2!=usghbot.d1) err("check layerbot header d1");
		if(usghin.d3!=usghbot.d2) err("check layerbot header d2");
		efseek(botfp,0,0);
		efread(zbot,sizeof(float),n2*n3,botfp);

		if(ivtop==1) {
		if(usghin.n2!=usghvtop.n1) err("check gtopgrid header n1");
		if(usghin.n3!=usghvtop.n2) err("check gtopgrid header n2");
		if(usghin.o2!=usghvtop.o1) err("check gtopgrid header o1");
		if(usghin.o3!=usghvtop.o2) err("check gtopgrid header o2");
		if(usghin.d2!=usghvtop.d1) err("check gtopgrid header d1");
		if(usghin.d3!=usghvtop.d2) err("check gtopgrid header d2");
		efseek(vtopfp,0,0);
		efread(vtop,sizeof(float),n2*n3,vtopfp);
		} 

		if(ivbot==1) {
		if(usghin.n2!=usghvbot.n1) err("check gbotgrid header n1");
		if(usghin.n3!=usghvbot.n2) err("check gbotgrid header n2");
		if(usghin.o2!=usghvbot.o1) err("check gbotgrid header o1");
		if(usghin.o3!=usghvbot.o2) err("check gbotgrid header o2");
		if(usghin.d2!=usghvbot.d1) err("check gbotgrid header d1");
		if(usghin.d3!=usghvbot.d2) err("check gbotgrid header d2");
		efseek(vbotfp,0,0);
		efread(vbot,sizeof(float),n2*n3,vbotfp);
		}
	} else {
		for(iz=0;iz<nlayer;iz++) {
			getnparstring(iz+1,"layers",&layers);
			layerfp=efopen(layers,"r");
			ierr = fgetusghdr(layerfp,&usghlayer);
			if(ierr!=0) err(" error open layers=%s \n",layers);
			if(usghin.n2!=usghlayer.n1) err("check %s header n1",layers);
			if(usghin.n3!=usghlayer.n2) err("check %s header n2",layers);
			if(usghin.o2!=usghlayer.o1) err("check %s header o1",layers);
			if(usghin.o3!=usghlayer.o2) err("check %s header o2",layers);
			if(usghin.d2!=usghlayer.d1) err("check %s header d1",layers);
			if(usghin.d3!=usghlayer.d2) err("check %s header d2",layers);
			efseek(layerfp,0,0);
			efread(zs+iz*n2*n3,sizeof(float),n2*n3,layerfp);
			efclose(layerfp);
		}
		for(iz=0;iz<nglayer;iz++) {
			getnparstring(iz+1,"glayers",&glayers);
			glayerfp=efopen(glayers,"r");
			ierr = fgetusghdr(glayerfp,&usghglayer);
			if(ierr!=0) err(" error open layers=%s \n",layers);
			if(usghin.n2!=usghglayer.n1) err("check %s header n1",glayers);
			if(usghin.n3!=usghglayer.n2) err("check %s header n2",glayers);
			if(usghin.o2!=usghglayer.o1) err("check %s header o1",glayers);
			if(usghin.o3!=usghglayer.o2) err("check %s header o2",glayers);
			if(usghin.d2!=usghglayer.d1) err("check %s header d1",glayers);
			if(usghin.d3!=usghglayer.d2) err("check %s header d2",glayers);
			efseek(glayerfp,0,0);
			efread(vs+iz*n2*n3,sizeof(float),n2*n3,glayerfp);
			efclose(glayerfp);
		}
		nz = nlayer - 1;
	}

/* compute mini layer depth and grid values */
	if(nlayer==0) {
		for(i2=0;i2<n2*n3;i2++) {
			zs[i2] = ztop[i2];
			vs[i2] = vtop[i2];
		}
		tmp = 0.;
		for(iz=0;iz<nz;iz++) tmp = tmp + dzrl[iz];
		vscale = 0.;
		zscale = 0.;
		for(iz=1;iz<nz;iz++) {
			zscale += dzrl[iz-1]/tmp;
			if(ginterp==0) {
				vscale += dzrl[iz-1]/tmp;
			} else {
				vscale = (float)iz / nz;
			}

			for(i2=0;i2<n2*n3;i2++) {
				zs[i2+iz*n2*n3] = ztop[i2] +
					zscale*(zbot[i2]-ztop[i2]);
				vs[i2+iz*n2*n3] = vtop[i2] + 
					vscale*(vbot[i2]-vtop[i2]);
			}
		}
		for(i2=0;i2<n2*n3;i2++) {
			zs[i2+nz*n2*n3] = zbot[i2];
			vs[i2+nz*n2*n3] = vbot[i2];
		}
	}

/* compute smoothing window for mini layers */
	tmp = 0.;
	for(iz=0;iz<nz;iz++) tmp = tmp + dzrl[iz];
	scale = 0.;
	sm2s[0] = sm2top;
	sm3s[0] = sm3top;
	for(iz=1;iz<nz+1;iz++) {
		scale += dzrl[iz-1]/tmp;
		sm2s[iz] = sm2top + scale*(sm2bot-sm2top);
		sm3s[iz] = sm3top + scale*(sm3bot-sm3top);
	} 

/* compute grid values at the mini layers if not specified */
	fseek2g(infp,0,0);
	if( ( (ivtop==0 || ivbot==0) && nlayer==0 ) || (nglayer==0 && nlayer>0) ) {
		for(i3=0;i3<n3;i3++) {
			for(i2=0;i2<n2;i2++) {
				efread(grid,sizeof(float),n1,infp);
				for(iz=0;iz<nz+1;iz++) {
					tmp = (zs[i2+i3*n2+iz*n2*n3] - o1)/d1 + 0.5; 
					i1 = tmp;
					if(i1<0) {
						vs[i2+i3*n2+iz*n2*n3] = grid[0];
					} else if(i1>=n1-1) {
						vs[i2+i3*n2+iz*n2*n3] = grid[n1-1];
					} else {
						vs[i2+i3*n2+iz*n2*n3] = grid[i1]+
								(tmp-i1)*(grid[i1+1]-grid[i1]);
					}
				}
			}
		}
	} else if(ivtop==-1 && ivbot==-1) {
		for(i3=0;i3<n3;i3++) {
			for(i2=0;i2<n2;i2++) {
				for(iz=0;iz<nz+1;iz++) {
					tmp = (zs[i2+i3*n2+iz*n2*n3] - ztop[i3*n2+i2]);
					vs[i2+i3*n2+iz*n2*n3] = g0 + r0 * tmp;
				}	
			}
		}
	}
/* smooth mini layer grids */
	for(iz=0;iz<nz+1;iz++) {
		tmp = sm2s[iz]/d2;
		ismx = tmp + 1.5;
		tmp = sm3s[iz]/d3;
		ismy = tmp + 1.5;
		fsmx = (float*) emalloc(ismx*sizeof(float));
		fsmy = (float*) emalloc(ismy*sizeof(float));
		/* 2d smoothing */
		smth2d_(vs+iz*n2*n3,work,fsmx,fsmy,&n2,&n3,&ismx,&ismy);
		/*
		dump2xplot(vs+iz*n2*n3,n2,n3,0,"vsmoth");
		*/
		free(fsmx);
		free(fsmy);
	}


/* output grid */
	fseek2g(infp,0,0);
	for(i3=0;i3<n3;i3++) {
		for(i2=0;i2<n2;i2++) {

			efread(grid,sizeof(float),n1,infp);
			itmp = i2+i3*n2;
			if(nlayer==0) {
				top = ztop[itmp];
				bot = zbot[itmp];
			} else {
				top = zs[itmp];
				bot = zs[itmp+(nlayer-1)*n2*n3];
			}
			tmp = (top - o1)/d1 + 0.5; 
			i1top = tmp;
			tmp = (bot - o1)/d1 + 0.5; 
			i1bot = tmp;
			if(i1top<0) i1top = 0;
			if(i1bot>n1-1) i1bot = n1-1;
			for(i1=i1top;i1<=i1bot;i1++) {
				z = o1 + i1*d1;
                                if(z>=zs[itmp] && z<=zs[itmp+nz*n2*n3]) {
					for(iz=0;iz<nz;iz++) {
						if( z == zs[itmp+iz*n2*n3] && z == zs[itmp+(iz+1)*n2*n3] ){
							grid[i1] = vs[itmp+iz*n2*n3];

						}else if(z>=zs[itmp+iz*n2*n3] && z<zs[itmp+(iz+1)*n2*n3]) {
							tmp = (z-zs[itmp+iz*n2*n3]) /
					  			(zs[itmp+(iz+1)*n2*n3]-zs[itmp+iz*n2*n3]);
							grid[i1] = vs[itmp+iz*n2*n3] + 
								tmp*(vs[itmp+(iz+1)*n2*n3]-vs[itmp+iz*n2*n3]);
                                                	if( grid[i1] != grid[i1] ){
                                                   		fprintf( stderr ,"NaN at i3=%d " ,i3 );
                                                   		fprintf( stderr ,"i2=%d i1=%d\n" ,i2, i3);
                                                	}
							break;
						}
					}
				}
			}

			if(igabovetop==1) {
				for(i1=0;i1<i1top;i1++) {
					grid[i1] = gabovetop;
				}
			}
			if(igbelowbot==1) {
				for(i1=i1bot;i1<n1;i1++) {
					grid[i1] = gbelowbot;
				}
			}

			if(i2==0 && i3==0) {
				gmin = grid[0];
				gmax = grid[0];
			}
			for(i1=0;i1<n1;i1++) {
				if(gmin>grid[i1]) gmin = grid[i1];
				if(gmax<grid[i1]) gmax = grid[i1];
			}

                        if( grid[0] != grid[0] ){
                           fprintf( stderr ,"NaN\n" );
                        }
			efwrite(grid,sizeof(float),n1,outfp);

		}
	}

	usghin.gmin = gmin;
	usghin.gmax = gmax;

	ierr = fputusghdr(outfp,&usghin);
	
	free(ztop);
	free(zbot);
	free(vtop);
	free(vbot);
	free(zs);
	free(vs);
	free(work);
	free(grid);
	exit(0);
}
コード例 #8
0
ファイル: sutvband.c プロジェクト: JOravetz/SeisUnix
main(int argc, char **argv)
{
        float **filter;         /* filter arrays                        */
        float *tf;              /* times at which filters are centered  */
        int *itf;               /* ... as integers                      */
	int jmin;		/* index of first filter itf value	*/
	int jmax;		/* index of last filter itf value	*/
        int nfft;     	        /* fft sizes in each time gate          */
        int nfreq;     	        /* number of frequencies  	        */
        float **ftrace;         /* filtered sub-traces                  */
        int nfilter;            /* number of filters specified          */
      	float dt;               /* sample spacing                       */
        float tmin;             /* first time on traces                 */
        int nt;                 /* number of points on input trace      */
	float *data;
	FILE *infp=stdin, *outfp=stdout;
        
        /* Initialize */
        initargs(argc, argv);
        requestdoc(1);


        /* Get info from first trace */ 
	file2g(infp);
	file2g(outfp);
        if (!fgettr(infp,&tr))  err("can't get first trace");
        if (tr.trid && tr.trid != TREAL)
                err("input is not seismic data, trid=%d", tr.trid);
        nt = tr.ns;
        if (!getparfloat("dt", &dt))    dt = (float)tr.dt/1000000.0;
        if (!dt) err("dt field is zero and not getparred");
	tmin = tr.delrt/1000.0;


        /* Get number of filters and center times */
        if (!(nfilter = countparval("tf")))  MUSTGETPARFLOAT("tf", tf);
	if (countparname("f") != nfilter)
		err("must give one f 4-tuple for each"
		    " (%d) tf value", nfilter);
		
	/* Leave room for possibly missing filters at endpoints */
	tf = ealloc1float(nfilter+4);  /* never use ist2 or last 2 */
	itf = ealloc1int(nfilter+4);
        getparfloat("tf", tf+2); jmin = 2; jmax = nfilter + 1;
	{ register int j;
          for (j = jmin; j <= jmax; ++j)  itf[j] = NINT((tf[j] - tmin)/dt);
        }

	

        /* Make filters with scale for inverse transform */
	nfft = npfaro(nt, LOOKFAC * nt);
	if (nfft >= MIN(SU_NFLTS, PFA_MAX))
		err("Padded nt=%d -- too big", nfft);
	nfreq = nfft/2 + 1;
	filter = ealloc2float(nfreq, nfilter+4); /* never use 1st & last */
        { register int j;
          for (j = jmin; j <= jmax; ++j) {
                float *f = ealloc1float(4);

                if (getnparfloat(j-jmin+1, "f", f) != 4)
                        err("must give 4 corner frequencies in f=");
        	if (f[0] < 0.0 || f[0] > f[1] ||
				  f[1] >= f[2] || f[2] > f[3])
               		err("Filter #%d has bad frequencies", j - jmin + 1);
                makefilter(f, nfft, nfreq, dt, filter[j]);
          }
        }
	


	/* User may not have given a filter for tmin and/or tmax--	*/
	/* Extend array so can always assume these filters are present.	*/
	/* Note don't really use any of the extra storage in **filter!	*/
	if (itf[jmin] > 0) {
		filter[jmin-1] = filter[jmin]; 
		itf[jmin-1] = 0;
		--jmin;
	}
	if (itf[jmax] < nt - 1) {
		filter[jmax+1] = filter[jmax];
		itf[jmax+1] = nt - 1;
		++jmax;
	}
	
	
	/* Extend array so can always consider time points to be interior */
	itf[jmin-1] = 0;      /* now jmin - 1 is a valid index */
	itf[jmax+1] = nt - 1; /* now jmax + 1 is a valid index */


        /* Main loop over traces */
        ftrace = ealloc2float(nt, nfilter+4); /* never use 1st & last */
	data = ealloc1float(nt);
        do {
                register int i, j;
		
		/* Construct filtered sub-traces */
		for (j = jmin; j <= jmax; ++j) {			
			bzero(data, nt*FSIZE);
			for (i = itf[j-1]; i <= itf[j+1]; ++i)
				data[i] = tr.data[i];
                        bandpass(data,nt,nfft,nfreq,filter[j],ftrace[j]);
                }

               /* Compose filtered trace from sub-traces */
               for (j = jmin; j < jmax; ++j) {
	       		float fitfj;
                        for (fitfj = i = itf[j]; i <= itf[j+1]; ++i) {
                                float a = (i - fitfj)/(itf[j+1] - fitfj);
                                tr.data[i] = (1-a)*ftrace[j][i] +
                                                 a*ftrace[j+1][i];
			}
                }
                
                fputtr(outfp,&tr);
        } while (fgettr(infp,&tr));

        return EXIT_SUCCESS;
}
コード例 #9
0
ファイル: gridmerge.c プロジェクト: JOravetz/SeisUnix
main(int argc,char *argv[]) {
	int mergeaxis, nin, headupdate;
	int i, nread;
	string *datain;
	FILE *outfp = stdout;
	FILE **infp;
	char *grid, *grido;

	usghed usgh, usgh2;
	int ierr;

	int n1, n2, n3, n4, n5;
	int i1, i2, i3, i4, i5;

	int si3, ni3=0, si5, ni5=0;
	int nn3=1, nn5=1, ii5;
	int i50;
	long long lpos;
	int n1out;

	float ddupdate;
	int iddupdate=1;

	int *m5;
	initargs(argc,argv) ;
	askdoc(1);

		
	if( !getparint("mergeaxis",&mergeaxis) ) mergeaxis=5;
	if( !getparint("headupdate",&headupdate) ) headupdate=5;
	if( !getparfloat("ddupdate",&ddupdate) ) {
		iddupdate = 0;
	}
	file2g(outfp);

	nin = countparname("gridin");
	fprintf(stderr," gridmerge with %d input grid files \n",nin);
	datain = (string *) malloc(nin*sizeof(string));
	infp = (FILE**) malloc(nin*sizeof(FILE *));

 	for(i=0;i<nin;i++) { 
		getnparstring(i+1,"gridin",&datain[i]);
		fprintf(stderr,"   Input %d :  gridin=%s \n",i+1,datain[i]);
		/*
		if((infp[i] = fopen(datain[i],"r"))==NULL)
			err(" %s not found ",datain[i]);
		*/
		infp[i] = fopen(datain[i],"r");
		file2g(infp[i]);
	}

	ierr = fgetusghdr(infp[0],&usgh);
	if(ierr!=0) err(" error open gridin=%s \n",datain[0]);

	grid = (char*)malloc(usgh.n1*usgh.dtype);
	m5 = (int*)malloc(nin*sizeof(int));

	if( !getparint("si3",&si3) ) si3=1;
	if( !getparint("si5",&si5) ) si5=1;
	if( !getparint("ni3",&ni3) ) { ni3=0; nn3=0; }
	if( !getparint("ni5",&ni5) ) { ni5=0; nn5=0; }
	si3 = si3 - 1;
	si5 = si5 - 1;

	if(mergeaxis==5) {
			n5 = 0;
			ii5 = 0;
			for(i=0;i<nin;i++) {
				ierr = fgetusghdr(infp[i],&usgh2);
				if(ierr!=0) err(" error open gridin=%s \n",datain[i]);
				if(usgh.n1*usgh.n2*usgh.n3*usgh.n4 
			 	 !=usgh2.n1*usgh2.n2*usgh2.n3*usgh2.n4)
					err(" check gridin=%s \n",datain[i]);
				n5 += usgh2.n5;
				fseek64(infp[i],0,0);
				nread = usgh2.n5 * usgh2.n4 * usgh2.n3 *usgh2.n2;
				if(nn3==0) ni3 = usgh2.n3;
				if(nn5==0) ni5 += usgh2.n5;
				fprintf(stderr," ii5=%d si5=%d ni5=%d \n",ii5+1,si5+1,ni5);
				fprintf(stderr," si3=%d ni3=%d \n",si3+1,ni3);
				if(ii5+usgh2.n5<=si5) {
					ii5 = ii5 + usgh2.n5; 
					fprintf(stderr," skip gridin=%s ... o5=%g n5=%d d5=%g \n",
						datain[i],usgh2.o5,usgh2.n5,usgh2.d5);
				} else {
					if(ii5>=ni5) {
						ii5 = ii5 + usgh2.n5; 
						break;
					}
					i50 = si5 - ii5;
					if(i50>0) {
						lpos = i50*usgh2.n1*usgh2.n2;
						lpos = lpos*usgh2.n3*usgh2.n4*usgh2.dtype;
						fseek64(infp[i],lpos,0);
						ii5 = si5;
					} else {
						i50 = 0;
					}

					for(i5=i50;i5<usgh2.n5;i5++) {
					for(i4=0;i4<usgh2.n4;i4++) {
					if(si3>=0) {
						lpos = si3+(i4+i5*usgh2.n4)*usgh2.n3;
						lpos = lpos*usgh2.n2*usgh2.n1*usgh2.dtype;
						fseek64(infp[i],lpos,0);
					}
					for(i3=si3;i3<ni3;i3++) {
					for(i2=0;i2<usgh2.n2;i2++) {
						fread(grid,usgh.dtype,usgh.n1,infp[i]);
						fwrite(grid,usgh.dtype,usgh.n1,outfp);
					}
					}
					}
					ii5 = ii5 + 1;
					if(ii5>=ni5 && nn5>0) {
						ii5 = ii5 + (usgh2.n5-i5);
						break;
					}

					}
				fprintf(stderr," merge gridin=%s ... o5=%g n5=%d d5=%g \n",
					datain[i],usgh2.o5,usgh2.n5,usgh2.d5);
				}

			}
			usgh.o3 = si3 * usgh.d3 + usgh.o3;
			usgh.n3 = (ni3 - si3);
			usgh.o5 = si5 * usgh.d5 + usgh.o5;
			usgh.n5 = (ni5 - si5);
	} else if(mergeaxis==4) {
			n4 = 0;
			for(i=0;i<nin;i++) {
				ierr = fgetusghdr(infp[i],&usgh2);
				if(ierr!=0) err(" error open gridin=%s \n",datain[i]);
				if(usgh.n1*usgh.n2*usgh.n3*usgh.n5 
			 	 !=usgh2.n1*usgh2.n2*usgh2.n3*usgh2.n5)
					err(" check gridin=%s \n",datain[i]);
				n4 += usgh2.n4;
				m5[i] = usgh2.n4;
				fseek64(infp[i],0,0);
				fprintf(stderr," merge gridin=%s ... o4=%g n4=%d d4=%g \n",
					datain[i],usgh2.o4,usgh2.n4,usgh2.d4);
			}

			for(i5=0;i5<usgh.n5;i5++) {
				for(i=0;i<nin;i++) {
					nread = m5[i] * usgh.n3 * usgh.n2;
					for(i2=0;i2<nread;i2++) {
						fread(grid,usgh.dtype,usgh.n1,infp[i]);
						fwrite(grid,usgh.dtype,usgh.n1,outfp);
					}
				}
			}
			if(headupdate==4) {
				usgh.n4 = n4;
			} else if(headupdate==5) {
				usgh.n5 = n5*nin;
				usgh.d5 = usgh.d5/nin;
			}
	} else if(mergeaxis==3) {
			n3 = 0;
			for(i=0;i<nin;i++) {
				ierr = fgetusghdr(infp[i],&usgh2);
				if(ierr!=0) err(" error open gridin=%s \n",datain[i]);
				if(usgh.n1*usgh.n2*usgh.n4*usgh.n5 
			 	 !=usgh2.n1*usgh2.n2*usgh2.n4*usgh2.n5)
					err(" check gridin=%s \n",datain[i]);
				n3 += usgh2.n3;
				m5[i] = usgh2.n3;
				fseek64(infp[i],0,0);
				fprintf(stderr," merge gridin=%s ... o3=%g n3=%d d3=%g \n",
					datain[i],usgh2.o3,usgh2.n3,usgh2.d3);
			}

			for(i5=0;i5<usgh.n5*usgh.n4;i5++) {
				for(i=0;i<nin;i++) {
					nread = m5[i] * usgh.n2;
					for(i2=0;i2<nread;i2++) {
						fread(grid,usgh.dtype,usgh.n1,infp[i]);
						fwrite(grid,usgh.dtype,usgh.n1,outfp);
					}
				}
			}
			usgh.n3 = n3;
	} else if(mergeaxis==2) {
			n2 = 0;
			for(i=0;i<nin;i++) {
				ierr = fgetusghdr(infp[i],&usgh2);
				if(ierr!=0) err(" error open gridin=%s \n",datain[i]);
				if(usgh.n1*usgh.n3*usgh.n4*usgh.n5 
			 	 !=usgh2.n1*usgh2.n3*usgh2.n4*usgh2.n5)
					err(" check gridin=%s \n",datain[i]);
				n2 += usgh2.n2;
				m5[i] = usgh2.n2;
				fseek64(infp[i],0,0);
				fprintf(stderr," merge gridin=%s ... o2=%g n2=%d d2=%g \n",
					datain[i],usgh2.o2,usgh2.n2,usgh2.d2);
			}

			for(i5=0;i5<usgh.n5*usgh.n4*usgh.n3;i5++) {
				for(i=0;i<nin;i++) {
					nread = m5[i];
					for(i2=0;i2<nread;i2++) {
						fread(grid,usgh.dtype,usgh.n1,infp[i]);
						fwrite(grid,usgh.dtype,usgh.n1,outfp);
					}
				}
			}
			usgh.n2 = n2;
	} else if(mergeaxis==1) {
			for(i=0;i<nin;i++) {
				ierr = fgetusghdr(infp[i],&usgh2);
				if(ierr!=0) err(" error open gridin=%s \n",datain[i]);
				if(usgh.n2*usgh.n3*usgh.n4*usgh.n5 
			 	 !=usgh2.n2*usgh2.n3*usgh2.n4*usgh2.n5)
					err(" check gridin=%s \n",datain[i]);
				n1 += usgh2.n1;
				m5[i] = usgh2.n1;
				fseek64(infp[i],0,0);
				fprintf(stderr," merge gridin=%s ... o1=%g n1=%d d1=%g \n",
					datain[i],usgh2.o1,usgh2.n1,usgh2.d1);
			}
			n1out = 0;
			for(i2=0;i2<nin;i2++) n1out = n1out + m5[i2];
			grido = (char*)malloc(n1out*usgh.dtype);
			for(i5=0;i5<usgh.n5*usgh.n4*usgh.n3*usgh.n2;i5++) {
				i2 = 0;
				for(i=0;i<nin;i++) {
					nread = m5[i];
					fread(grid,usgh.dtype,nread,infp[i]);
					bcopy(grid,grido+i2,nread*usgh.dtype);
					i2 = i2 + nread*usgh.dtype;
				}
				fwrite(grido,usgh.dtype,n1out,outfp);
			}
			usgh.n1 = n1out;
	}

	usgh.scale = 1.0;
	if(iddupdate==1) {
		if(headupdate==1) {
			usgh.d1 = ddupdate;
		} else if(headupdate==2) {
			usgh.d2 = ddupdate;
		} else if(headupdate==3) {
			usgh.d3 = ddupdate;
		} else if(headupdate==4) {
			usgh.d4 = ddupdate;
		} else if(headupdate==5) {
			usgh.d5 = ddupdate;
		}
	}

	ierr = fputusghdr(outfp,&usgh);
	if(ierr!=0) err(" error output ");

	free(grid);
	free(m5);
	if(mergeaxis==1) free(grido);

	exit (0);

}
コード例 #10
0
ファイル: sutifowler.c プロジェクト: gwowen/seismicunix
/**************** end self doc ********************************/


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);
static void vget( float a, float b, float e, float d,
		float theta, float *vel);
VND *ptabledmo(int nv, float *v, float etamin, float deta, int neta,
		float d, float vsvp, int np, float dp, float dp2, char *file);
VND *ptablemig(int nv, float *v, float etamin, float deta,
		int neta, float d, float vsvp, int np, char *file);
static void taper (int lxtaper, int lbtaper,
		int nx, int ix, int nt, float *trace);

segy tr;	/* input and output SEGY data */
FILE *fpl;	/* file pointer for print listing */
int main(int argc, char **argv)
{
	VND *vnd=NULL;	/* big file holding data, all cmps, all etas, all velocities */
	VND *vnda=NULL;	/* holds one input cmp gather */
	VND *vndb=NULL;	/* holds (w,v) for one k component */
	VND *vndvnmo=NULL;	/* holds (vnmo,p) table for ti dmo */
	VND *vndvphase=NULL;	/* holds (vphase,p) table for ti Stolt migration */
	long N[2];	/* holds number of values in each dimension for VND opens */
	long key[2];	/* holds key in each dimension for VND i/o */
	char **dir=NULL; /* could hold list of directories where to put VND temp files */
	char *file;	/* root name for temporary files */
	char *printfile; /* name of file for printout */
	complex *crt;
	complex *ctemp;
	complex czero;
	float *rt;
	char *ccrt;
	char *fname;
	
	float etamin;	/* minimum eta scan to compute */
	float etamax;	/* maximum eta scan to compute */
	float deta;	/* increment in eta to compute for eta scan */
	float dx;	/* cmp spatial sampling interval */
	float dk;	/* wavenumber increment */
	float dv;	/* velocity increment */
	float vmin;	/* minimum output velocity */
	float vmax;	/* maximum output velocity */
	float dt;	/* input sample rate in seconds */
	float dtout;	/* output sample rate in seconds */
	float *mute;	/* array of mute times for this cmp */
	float *off;	/* array of offsets for this cmp */
	float *v;	/* array of output velocities */
	float *p2stack;	/* array of stacking 1/(v*v) */
	float *rindex;	/* array of interpolation indices */
	float dp2=0.0;	/* increment in slowness squared for input cvstacks */
	float scale;	/* used for trace scale factor */
	float p;	/* horizontal slowness */
	float p2;	/* p*p */
	float v2;	/* velocity squared */
	float ak;	/* horizontal wavenumber */
	float dw;	/* angular frequency increment */
	float *w;	/* array holding w values for Fowler */
	float factor;	/* scale factor */
	float d;	/* Thomsen's delta */
	float vsvp;	/* vs/vp ratio */
	float dp;	/* increment of slowness values in vndvnmo table */
	float rp;	/* real valued index in p */
	float wgt;	/* weight for linear interpolation */
	float fmax;	/* maximum frequency to use for antialias mute */
	float salias;	/* fraction of frequencies to be within sloth antialias limit */
	float dpm;	/* slowness increment in TI migration table */
	float fw;	/* first w in Stolt data table */
	float vminstack;/* only used if reading precomputed cvstacks, minimum stacking vel */

	int neta;	/* number of eta scans to compute */
	int ichoose;	/* defines type of processing to do */
	int ncmps;	/* number of input and output cmps */
	int nv;		/* number of output velocity panels to generate */
	int nvstack;	/* number of cvstack panels to generate */
	int ntpad;	/* number of time samples to padd to avoid wraparound */
	int nxpad;	/* number of traces to padd to avoid wraparound */
	int lmute;	/* number of samples to taper mute */
	int lbtaper;	/* length of bottom time taper in ms */
	int lstaper;	/* length of side taper in traces */
	int mxfold;	/* maximum allowed number of input offsets/cmp */
	int icmp;	/* cmp index */
	int ntfft;	/* length of temporal fft for Fowler */
	int ntffts;	/* length of temporal fft for Stolt */
	int nxfft;	/* length of spatial fft */
	int ntfftny;	/* count of freq to nyquist */
	int nxfftny;	/* count of wavenumbers to nyquist */
	int nmax;	/* used to compute max number of samples for array allocation */
	int oldcmp;	/* current cdp header value */
	int noff;	/* number of offsets */
	int k;		/* wavenumber index */
	int iwmin;	/* minimum freq index */
	int TI;		/* 0 for isotropic, 1 for transversely isotropic */
	long it;	/* time index */
	long iw;	/* index for angular frequency */
	long nt;	/* number of input time samples */
	long ntout;	/* number of output time samples */
	long iv;	/* velocity index */
	long ip;	/* slowness index */
	long ieta;
	int nonhyp;	/* flag equals 1 if do mute to avoid non-hyperbolic events */
	int getcvstacks;/* flag equals 1 if input cvstacks precomputed */
	int ngroup;	/* number of traces per vel anal group */
	int ndir;	/* number of user specified directories for temp files */

/******************************************************************************/
/* 	input parameters, allocate buffers, and define reusable constants     */
/******************************************************************************/
	initargs(argc, argv);
	requestdoc(1);

	/* get first trace and extract critical info from header */
	if(!gettr(&tr)) err("Can't get first trace \n");
	nt=tr.ns;
	dt=0.000001*tr.dt;
	oldcmp=tr.cdp;

	if (!getparstring("printfile",&printfile)) printfile=NULL;
	if (printfile==NULL) {
		fpl=stderr;
	}else{
		fpl=fopen(printfile,"w");
	}

	if (!getparfloat("salias",&salias)) salias=0.8;
 	if(salias>1.0) salias=1.0;
	if (!getparfloat("dtout",&dtout)) dtout=1.5*dt;
	ntout=1+nt*dt/dtout;
	if (!getparint("getcvstacks",&getcvstacks)) getcvstacks=0;
	if(getcvstacks) {
		dtout=dt;
		ntout=nt;
	}
	fmax=salias*0.5/dtout;
	fprintf(fpl,"sutifowler: ntin=%ld dtin=%f\n",nt,dt);
	fprintf(fpl,"sutifowler: ntout=%ld dtout=%f\n",ntout,dtout);
	if (!getparstring("file",&file)) file="sutifowler";
	if (!getparfloat("dx",&dx)) dx=25.;
	if (!getparfloat("vmin",&vmin)) vmin=1500.;
	if (!getparfloat("vmax",&vmax)) vmax=8000.;
	if (!getparfloat("vminstack",&vminstack)) vminstack=vmin;
	if (!getparfloat("d",&d)) d=0.0;
	if (!getparfloat("etamin",&etamin)) etamin=0.0;
	if (!getparfloat("etamax",&etamax)) etamax=0.5;
	if (!getparfloat("vsvp",&vsvp)) vsvp=0.5;
	if (!getparint("neta", &neta)) neta = 1;
	if (fabs(etamax-etamin)<1.0e-7) neta = 1;
	if (neta < 1) neta = 1;
	if (!getparint("choose", &ichoose)) ichoose = 1;
	if (!getparint("ncdps", &ncmps)) err("sutifowler: must enter ncdps");
	if (!getparint("nv", &nv)) nv = 75;
	if (!getparint("nvstack", &nvstack)) nvstack = 180;
	if (!getparint("ntpad", &ntpad)) ntpad = 0.1*ntout;
	if (!getparint("nxpad", &nxpad)) nxpad = 0;
	if (!getparint("lmute", &lmute)) lmute = 24;
	lmute=1 + 0.001*lmute/dtout;
	if (!getparint("lbtaper", &lbtaper)) lbtaper = 0;
	if (!getparint("lstaper", &lstaper)) lstaper = 0;
	if (!getparint("mxfold", &mxfold)) mxfold = 120;
	if (!getparint("nonhyp",&nonhyp)) nonhyp=1.;
	if (!getparint("ngroup", &ngroup)) ngroup = 20;
	ndir = countparname("p");
	if(ndir==0) {
		ndir=-1;
	}else{
		dir = (char **)VNDemalloc(ndir*sizeof(char *),"dir");
		for(k=0;k<ndir;k++) {
			it=getnparstring(k+1,"p",&dir[k]);
		}
	}
	lbtaper=lbtaper/(1000.*dt);
	TI=0;
	if(fabs(d)>0. || fabs(etamin)>0 || neta>1 ) TI=1;
	if(TI) fprintf(fpl,"sutifowler: operation in TI mode\n");
	deta = 0.;
	if(neta>1) deta=(etamax-etamin)/(neta-1);
	dp=1./(vmin*(NP-5));
	if(TI) dp=dp*sqrt(1.+2.*fabs(etamin));
	if(ichoose>2) nvstack=nv;
	if(ichoose==1 || ichoose==2 || ichoose==3) {
		ntfft=ntout+ntpad;
	}else{
		ntfft=1;
	}
	if(ichoose==1 || ichoose==3) {
		ntffts=2*ntout/0.6;
	}else{
		ntffts=1;
	}
	ntfft=npfao(ntfft,2*ntfft);
	ntffts=npfao(ntffts,2*ntffts);
	dw=2.*PI/(ntfft*dtout);
	nxfft=npfar(ncmps+nxpad);
	dk=2.*PI/(nxfft*dx);
	fprintf(fpl,"sutifowler: ntfft=%d ntffts=%d nxfft=%d\n",ntfft,ntffts,nxfft);
	czero.r=czero.i=0.;
	scale=1.;
	if(ichoose<5) scale=1./(nxfft);
	if(ichoose==1 || ichoose==2 ) scale*=1./ntfft;
	if(ichoose==1 || ichoose==3 ) scale*=1./ntffts;
	nxfftny = nxfft/2 + 1;
	ntfftny = ntfft/2 + 1;
	nmax = nxfftny;
	if(ntfft > nmax) nmax=ntfft;
	if((NP/2+1)>nmax) nmax=(NP/2+1);
	if(nvstack>nmax) nmax=nvstack;
	if(nv*neta>nmax) nmax=nv*neta;
	ctemp = (complex *)VNDemalloc(nmax*sizeof(complex),"allocating ctemp");
	rindex=(float *)VNDemalloc(nmax*sizeof(float),"allocating rindex");
	if(ntffts > nmax) nmax=ntffts;
	crt = (complex *)VNDemalloc(nmax*sizeof(complex),"allocating crt");
	rt = (float *)crt;
	ccrt = (char *)crt;
	fprintf(fpl,"sutifowler: nv=%d nvstack=%d\n",nv,nvstack);
	v=(float *)VNDemalloc(nv*sizeof(float),"allocating v");
	p2stack=(float *)VNDemalloc(nvstack*sizeof(float),"allocating p2stack");
	mute=(float *)VNDemalloc(mxfold*sizeof(float),"allocating mute");
	off=(float *)VNDemalloc(mxfold*sizeof(float),"allocating off");
	fprintf(fpl,"sutifowler: allocating and filling w array\n");
	w=(float *)VNDemalloc(ntfft*sizeof(float),"allocating w");
	for(iw=0;iw<ntfft;iw++) {
		if(iw<ntfftny){
			w[iw]=iw*dw;
		}else{
			w[iw]=(iw-ntfft)*dw;
		}
		if(iw==0) w[0]=0.1*dw;  	/* fudge for dc component */
	}

/******************************************************************************/
	fprintf(fpl,"sutifowler: building function for stacking velocity analysis\n");
/******************************************************************************/
	dv=(vmax-vmin)/MAX((nv-1),1);
	for(iv=0;iv<nv;iv++) v[iv]=vmin+iv*dv;
	if(ichoose>=3){
	  	for(iv=0;iv<nvstack;iv++) {
			p2stack[iv]=1./(v[iv]*v[iv]);
			fprintf(fpl,"	    stacking velocity %ld %f\n",iv,v[iv]);
		}
	}else{
		if(nvstack<6) err("sutifowler: nvstack must be 6 or more");
		dp2 = 1./(vminstack*vminstack*(nvstack-5));
		for(iv=0;iv<nvstack;iv++) {
			p2stack[iv]=iv*dp2;
			if(iv>0) {
				factor=1./sqrt(p2stack[iv]);
				fprintf(fpl,"	    stacking velocity %ld %f\n",iv,factor);
			}else{
				fprintf(fpl,"	    stacking velocity %ld infinity\n",iv);
			}
		}		
	}

/******************************************************************************/
	fprintf(fpl,"sutifowler: Opening and zeroing large block matrix disk file\n");
	fprintf(fpl,"	    This can take a while, but all is fruitless if the \n");
	fprintf(fpl,"	    necessary disk space is not there...\n");
/******************************************************************************/
	N[0]=nxfft+2;
	N[1]=ntout*MAX(nv*neta,nvstack);
	fname=VNDtempname(file);
	vnd = VNDop(2,0,2,N,1,sizeof(float),fname,ndir,dir,1);
	VNDfree(fname,"main: freeing fname 1");
	fprintf(fpl,"sutifowler: large file RAM mem buf = %ld bytes\n",
		vnd->NumBytesMemBuf);
	fprintf(fpl,"sutifowler: large file disk area = %ld bytes\n",
		vnd->NumBytesPerBlock*vnd->NumBlocksPerPanel*vnd->NumPanels);


	if(getcvstacks) {
/******************************************************************************/
		fprintf(fpl,"sutifowler: reading input cvstacks\n");
/******************************************************************************/
		for(icmp=0;icmp<ncmps;icmp++) {
			key[0]=icmp;
			key[1]=0;
			for(iv=0;iv<nvstack;iv++) {
				VNDrw('w',0,vnd,1,key,0,
					(char *) tr.data,iv*ntout,1,ntout,
					1,"writing cvstacks to disk");
				if( !gettr(&tr) ) {
				    if(icmp==ncmps-1 && iv==nvstack-1 ) {
					/* all ok, read all the input data */
				    }else{
					err("sutifowler: error reading input cvstacks");
				    }
				}
			}
		}
		goto xffts;
	}
/******************************************************************************/
	fprintf(fpl,
	"sutifowler: beginning constant velocity stacks of the input cmp gathers\n");
/******************************************************************************/
	fname=VNDtempname(file);
	vnda = V2Dop(2,1000000,sizeof(float),fname,nt,mxfold);
	VNDfree(fname,"main: freeing fname 2");
	fprintf(fpl,"sutifowler: cmp gather RAM mem buf = %ld bytes\n",
		vnda->NumBytesMemBuf);

	icmp=0;
	noff=0;
	do {
	   if(tr.cdp!=oldcmp) {
		cvstack(vnda,vnd,icmp,noff,off,mute,lmute,
			nvstack,p2stack,dt,dtout);
		icmp++;
		if(icmp==ncmps) {
			fprintf(fpl,"sutifowler: more input cdps than ncdps parameter\n");
			fprintf(fpl,"	    Will only process ncdps gathers.\n");
			goto done_with_input;
			}
		oldcmp=tr.cdp;
		noff=0;
	   }
	   if(lbtaper>0 || lstaper>0) taper (lstaper,lbtaper,ncmps,icmp,nt,tr.data);
	   factor=scale;
	   for(it=0;it<nt;it++) tr.data[it]*=factor;
	   V2Dw0(vnda,noff,(char *)tr.data,1);
	   off[noff]=tr.offset;
 	   if(ichoose==1 || ichoose==2) {
 		mute[noff]=fmax*off[noff]*off[noff]*dp2;
 	   }else{
 		mute[noff]=0.;
 	   }
	   if(nonhyp) mute[noff]=MAX(mute[noff],2*off[noff]/vmin);
	   noff++;
	   if(noff>mxfold) err("tifowler: input cdp has more traces than mxfold");
	} while ( gettr(&tr) );
	cvstack(vnda,vnd,icmp,noff,off,mute,lmute,
		nvstack,p2stack,dt,dtout);
	icmp++;
done_with_input:
	ncmps=icmp;
	fprintf(fpl,"sutifowler: read and stacked %d cmp gathers\n",ncmps);
	VNDcl(vnda,1);
xffts:
	VNDflush(vnd);

	if(ichoose<5){
/******************************************************************************/
	    fprintf(fpl,"sutifowler: doing forward x -> k spatial fft's\n");
/******************************************************************************/
	    for(it=0;it<(ntout*nvstack);it++) {
		V2Dr0(vnd,it,ccrt,21);
		for(k=ncmps;k<nxfft+2;k++) rt[k]=0.;
		pfarc(1,nxfft,rt,crt);
		V2Dw0(vnd,it,ccrt,22);
	    }
	    VNDr2c(vnd);
	}

	if(ichoose<=3) {
	    fprintf(fpl,"sutifowler: looping over k\n");
	    if(TI && (ichoose==1 || ichoose==2)) { /* build ti vnmo(p) table */
		vndvnmo=ptabledmo(nv,v,etamin,deta,neta,d,vsvp,NP,dp,dp2,file);
		fprintf(fpl,"sutifowler: dmo index(p) RAM mem buf = %ld bytes\n",
			vndvnmo->NumBytesMemBuf);
	    }
	    if(TI && (ichoose==1 || ichoose==3)){ /* build ti vphase(p) table */
		vndvphase=ptablemig(nv,v,etamin,deta,neta,d,vsvp,NP,file);
		fprintf(fpl,"sutifowler: migration scaler(p) RAM mem buf = %ld bytes\n",
			vndvphase->NumBytesMemBuf);
	    }
	    if(ichoose==1 || ichoose==2){
	    	iv=MAX(nv*neta,nvstack);
		fname=VNDtempname(file);
	    	vndb = V2Dop(2,750000,sizeof(complex),
			fname,(long)ntfft,iv);
	    		fprintf(fpl,"sutifowler: (w,v) RAM mem buf = %ld bytes\n",
				vndb->NumBytesMemBuf);
		VNDfree(fname,"main: freeing fname 3");
	    }

/******************************************************************************/
	    for(k=0;k<nxfftny;k++){ 	/* loop over spatial wavenumbers */
/******************************************************************************/
		if(k==(20*(k/20))) {
			fprintf(fpl,"sutifowler: k index = %d out of %d\n",
				k,nxfftny);
		}
		ak=k*dk;
		key[0]=k;
		key[1]=0;
/******************************************************************************/
		if(ichoose==1 || ichoose==2) { /* do Fowler DMO */
/******************************************************************************/
			for(iv=0;iv<nvstack;iv++) {	/* loop over input velocities */
				VNDrw('r',0,vnd,1,key,0,ccrt,iv*ntout,1,ntout,
				31,"Fowler DMO t -> w fft read");
				for(it=ntout;it<ntfft;it++) crt[it]=czero;
				pfacc(-1,ntfft,crt);
				V2Dw0(vndb,iv,ccrt,32);
			}

			for(iw=0;iw<ntfft;iw++) {
				p=0.5*ak/fabs(w[iw]);
				if(TI) {	/* anisotropic TI*/
				    ip=p/dp;
				    if(ip<NP) {
					V2Dr0(vndvnmo,ip,(char *)rindex,40);
				    }else{
					for(iv=0;iv<(nv*neta);iv++) rindex[iv]=-1.;
				    }
				}else{			/* isotropic */
				    p2=p*p;
				    for(iv=0;iv<nv;iv++){
					v2=v[iv]*v[iv];
					rindex[iv]=(1-v2*p2)/(v2*dp2);
				    }
				}	
				V2Dr1(vndb,iw,ccrt,41);
				for(iv=0;iv<nvstack;iv++) ctemp[iv]=crt[iv];
				ints8c(nvstack,1.0,0.0,ctemp,czero,czero,nv*neta,rindex,crt);
				V2Dw1(vndb,iw,ccrt,42);
			}
			for(iv=0;iv<(nv*neta);iv++) {	/* loop over output vel */
				V2Dr0(vndb,iv,ccrt,51);
				pfacc(1,ntfft,crt);
				VNDrw('w',0,vnd,1,key,0,ccrt,iv*ntout,1,ntout,
				52,"Fowler DMO w -> t fft write");		
			}
		}
/******************************************************************************/
		if( ichoose==3 && neta>1 ) {  /* fix up disk order if only doing TI migrations */
/******************************************************************************/
			for(iv=0;iv<nv;iv++) {
				VNDrw('r',0,vnd,1,key,0,ccrt,iv*ntout,1,ntout,
				57,"option 3 fixup for multiple eta read");
				for(ieta=1;ieta<neta;ieta++) {
					VNDrw('w',0,vnd,1,key,0,ccrt,
					iv*ntout+ieta*nv*ntout,1,ntout,
					58,"option 3 fixup for multiple eta write");
				}
			}
		}
/******************************************************************************/
		if( (ichoose==1 || ichoose==3 ) ) { 	/* do Stolt migration */
/******************************************************************************/
			for(iv=0;iv<(nv*neta);iv++) {
				if(TI) {	/* anisotropic TI */
				    V2Dr0(vndvphase,iv,ccrt,50);
				    dpm=rt[0];
				    dw=2.*PI/(ntfft*dtout);
				    iwmin=0.5*ak/( (NP-3)*dpm*dw);
				    for(iw=iwmin+1;iw<ntfftny;iw++) {
					p=0.5*ak/fabs(w[iw]);
					rp=1.0+p/dpm;
					ip=rp;
					wgt=rp-ip;
					factor=wgt*rt[ip+1]+(1.-wgt)*rt[ip];
					rindex[iw]=w[iw]*factor;
					rindex[ntfft-iw]=w[ntfft-iw]*factor;
				    }
				    fw=-2.*PI/dtout;
				    rindex[0]=fw;
				    for(iw=1;iw<iwmin+1;iw++) {
					rindex[iw]=fw;
					rindex[ntfft-iw]=fw;
				    }
				}else{			/* isotropic */
					scale=0.5*v[iv]*ak;
				    	for(iw=0;iw<ntfft;iw++) {
					    if(fabs(w[iw])>scale) {
						factor=scale/w[iw];
						factor=sqrt(1+factor*factor);
						rindex[iw]=w[iw]*factor;
					    }else{
						rindex[iw]=-2.*PI/dtout;
					    }
					}
				}

				VNDrw('r',0,vnd,1,key,0,ccrt,iv*ntout,1,ntout,
					61,"Stolt t -> w fft read");
				for(it=1;it<ntout;it+=2){
					crt[it].r=-crt[it].r;
					crt[it].i=-crt[it].i;
				}
				for(it=ntout;it<ntffts;it++) crt[it]=czero;
				pfacc(1,ntffts,crt);
				dw=2.*PI/(ntffts*dtout);
				fw=-PI/dtout;
				ints8c(ntffts,dw,fw,crt,czero,czero,
					ntfft,rindex,ctemp);
				/* obliquity factor code */
 				for(iw=0;iw<ntfft;iw++){
 					factor=fabs(w[iw]/rindex[iw]);
 					crt[iw].r=factor*ctemp[iw].r;
 					crt[iw].i=factor*ctemp[iw].i;
 				}
				pfacc(-1,ntfft,crt);
				VNDrw('w',0,vnd,1,key,0,ccrt,iv*ntout,1,ntout,
					62,"Stolt w->t fft write");		
			}
		}

	    }
	    fprintf(fpl,"sutifowler: completed loop over wavenumbers\n");
	    if(ichoose==1 || ichoose==2) VNDcl(vndb,1);
	    if(TI && (ichoose==1 || ichoose==2)) VNDcl(vndvnmo,1);
	    if(TI && (ichoose==1 || ichoose==3)) VNDcl(vndvphase,1);
	}

	if(ichoose<5) {
/******************************************************************************/
	    fprintf(fpl,"sutifowler: doing inverse spatial fft's k->x\n");
/******************************************************************************/
	    for(it=0;it<(ntout*nv*neta);it++) {
		V2Dr0(vnd,it,ccrt,71);
		pfacr(-1,nxfft,crt,rt);
		V2Dw0(vnd,it,ccrt,72);
	    }
	    VNDc2r(vnd);
	}

/*****************************************************************/
	fprintf(fpl,"sutifowler: outputting results\n");
/******************************************************************/
	it=0;
	for(icmp=0;icmp<ncmps;icmp++) {
		key[0]=icmp;
		key[1]=0;
		for(ieta=0;ieta<neta;ieta++) {
			for(iv=0;iv<nv;iv++) {
				VNDrw('r',0,vnd,1,key,0,(char *)tr.data,
					iv*ntout+ieta*nv*ntout,1,ntout,82,
					"outputting all velocities for each cmp");
				tr.ns=ntout;
				tr.dt=1000000*dtout;
				tr.cdp=icmp;
				tr.tracf=iv;
				tr.offset=v[iv];
				tr.cdpt=iv;
				tr.sx=icmp*dx;
				tr.gx=icmp*dx;
				it++;
				tr.tracl=it;
				tr.tracr=it;
				tr.fldr=icmp/ngroup;
				tr.ep=10+tr.fldr*ngroup;
				tr.igc=ieta;
				tr.igi=100*(etamin+ieta*deta);
				tr.d1=dtout;
				tr.f1=0.;
				tr.d2=1.;
				tr.f2=0.;
				puttr(&tr);
			}
		}
	}

/* close files and return */
	VNDcl(vnd,1);
	VNDfree(crt,"main: freeing crt");
	VNDfree(ctemp,"main: freeing ctemp");
	VNDfree(v,"main: freeing v");
	VNDfree(p2stack,"main: freeing p2stack");
	VNDfree(mute,"main: freeing mute");
	VNDfree(off,"main: freeing off");
	VNDfree(rindex,"main: freeing rindex");
	VNDfree(w,"main: freeing w");
	if(VNDtotalmem()!=0) {
		fprintf(stderr,"total VND memory at end = %ld\n",
		VNDtotalmem());
	}
	return EXIT_SUCCESS;
}
コード例 #11
0
ファイル: makemod.c プロジェクト: whu-pzhang/OpenSource
int main(int argc, char **argv)
{
  FILE *fpint, *fpcp, *fpcs, *fpro;
  int   example, verbose, writeint, nb;
  int	above, diffrwidth, dtype;
  int   Ngp, Ngs, Ngr, Np, Ns, Nr, Ng, Ni, Nv, Nvi, No, Noi;
  int   jint, jcount, j, ix, iz, nx, nz, nxp, nzp, *zp, nmaxx, nminx, optgrad, poly, gradt; 
  int	ncp, nro, ncs, nvel, skip, rayfile, store_int;
	long lseed;
  size_t  nwrite;
  float *data_out, orig[2], cp0, cs0, ro0;
  float	*x, *z, *var, *interface, **inter;
  float back[3], sizex, sizez, dx, dz;
  float **cp ,**cs, **ro, aver, gradlen, gradcp, gradcs, gradro;
  
  /* Gradient unit flag    */
  /* ------------------    */
  /* - 0 Unit : m/s per dz */
  /* - 1 Unit : m/s per m  */
  int gradunit;
  /* Number of Z-reference points (one per layer) */
  int Nzr=0;
  
  float   **gridcp, **gridcs, **gridro;
  segy    *hdrs;
  FILE    *fpout;
  char    *file, intt[10], *file_base, filename[150];
  
  initargs(argc, argv);
  requestdoc(1);
  
  if (!getparint("example", &example)) example=0;
  else { plotexample(); exit(0); }
  
  if(getparstring("file",&file_base)) 
    vwarn("parameters file is changed to file_base");
  else {
    if(!getparstring("file_base",&file_base))
      verr("file_base not specified.");
  }
  if(getparfloat("back", back)) {
    vwarn("parameters back is not used anymore");
    vwarn("it has changed into cp0 (ro0,cs0 are optional)");
    nb = countparval("back");
    if (nb == 1) {
      vwarn("The new call should be cp0=%.1f",back[0]);
      cp0 = back[0];
    }
    if (nb == 2) {
      vwarn("The new call should be cp0=%.1f",back[0]);
      vwarn("                       ro0=%.1f",back[1]);
      cp0 = back[0];
      ro0 = back[1];
    }
    if (nb == 3) {
      vwarn("The new call should be cp0=%.1f",back[0]);
      vwarn("                       cs0=%.1f",back[1]);
      vwarn("                       ro0=%.1f",back[2]);
      cp0 = back[0];
      cs0 = back[1];
      ro0 = back[2];
    }
    vmess("Don't worry everything still works fine");
  }
  else {
    if(!getparfloat("cp0", &cp0)) verr("cp0 not specified.");
    if(!getparfloat("cs0", &cs0)) cs0 = -1;
    if(!getparfloat("ro0", &ro0)) ro0 = -1;
  }
  if(!getparfloat("sizex", &sizex)) verr("x-model size not specified.");
  if(!getparfloat("sizez", &sizez)) verr("z-model size not specified.");
  if(!getparfloat("dx", &dx)) verr("grid distance dx not specified.");
  if(!getparfloat("dz", &dz)) verr("grid distance dz not specified.");
  if(!getparfloat("orig", orig)) orig[0] = orig[1] = 0.0;
  if(!getparint("gradt", &gradt)) gradt = 1;
  if(!getparint("gradunit", &gradunit)) gradunit = 0;
  if(!getparint("writeint", &writeint)) writeint = 0;
  if(!getparint("rayfile", &rayfile)) rayfile = 0;
  if(!getparint("skip", &skip)) skip = 5;
  if(!getparint("above", &above)) above=0;
  if(!getparint("verbose", &verbose)) verbose=0;
  if(!getparint("dtype", &dtype)) dtype = 0;
  
  if ((writeint == 1) || (rayfile == 1)) store_int = 1;
  else store_int = 0;
  
  /*=================== check parameters =================*/
  
  Np = countparname("cp");
  Ns = countparname("cs");
  Nr = countparname("ro");
  Ng = countparname("grad");
  No = countparname("poly");
  Ni = countparname("intt");
  Nv = countparname("var");
  Ngp = countparname("gradcp");
  Ngs = countparname("gradcs");
  Ngr = countparname("gradro");
  
  Nvi = 0;
  for (jint = 1; jint <= Ni; jint++) {
    getnparstring(jint,"intt", &file);
    strcpy(intt, file);
    if (strstr(intt,"sin") != NULL) Nvi++;
    if (strstr(intt,"rough") != NULL) Nvi++;
    if (strstr(intt,"fract") != NULL) Nvi++;
    if (strstr(intt,"elipse") != NULL) Nvi++;
	if (strstr(intt,"random") != NULL) Nvi++;
//	if (strstr(intt,"randdf") != NULL) Nvi++;
    if (strstr(intt,"diffr") != NULL || strstr(intt,"randdf") != NULL) {
	  Nvi++;
//      if (Ng != 0) Ng++; 
//      if (No != 0) No++;
    }
  }
//  fprintf(stderr,"Nvi=%d ng=%d No=%d np=%d,", Nvi,Ng,No,Np);
  
  if (Np != Nr && ro0 > 0) verr("number of cp and ro not equal.");
  if (Np != Ni) verr("number of cp and interfaces not equal.");
  if (Nvi != Nv) verr("number of interface variables(var) not correct.");
  if (Ns == 0 && Nr == 0) if (verbose>=2) vmess("Velocity model.");
  if (Ns == 0) { if (verbose>=2) vmess("Acoustic model."); }
  else {
    if (verbose>=2) vmess("Elastic model.");
    if (Np != Ns) verr("number of cp and cs not equal");
  }
  
  if (Ng == 0) {
    if (verbose>=2) vmess("No boundary gradients are defined.");
  }
  else if (Ng != Np) {
    verr("number of boundary gradients and interfaces are not equal.");
  }
  if (Ngp == 0) {
    if (verbose>=2) vmess("No interface gradients for cp defined.");
  }
  else if (Ngp != Np) {
    verr("gradcp gradients and interfaces are not equal.");
  }
  if (Ngs == 0) {
    if (verbose>=2) vmess("No interface gradients for cs defined.");
  }
  else if (Ngs != Np) {
    verr("gradcs gradients and interfaces are not equal.");
  }
  if (Ngr == 0) {
    if (verbose>=2) vmess("No interface gradients for rho defined.");
  }
  else if (Ngr != Np) {
    verr("gradro gradients and interfaces are not equal.");
  }
  if (No == 0) {
    if (verbose>=2) vmess("All interfaces are linear.");
  }
//  else if (No != Np) {
//    verr("number of poly variables and interfaces are not equal.");
//  }
  
  if (Np > 0) {
    if (countparname("x") != Np)
      verr("a x array must be specified for each interface.");
    if (countparname("z") != Np)
      verr("a z array must be specified for each interface.");
  } 
  else Np = 1;

  if (Nzr != Np && Nzr !=0) {
    verr("number of zref gradients not equal to number of interfaces");
  }
  
  /*=================== initialization of arrays =================*/
  
  nz = NINT(sizez/dz)+1;
  nx = NINT(sizex/dx)+1;
  
  zp = (int *)malloc(nx*sizeof(int));
  interface = (float *)malloc(nx*sizeof(float));
  var = (float *)malloc(8*sizeof(float));
  gridcp = alloc2float(nz, nx);
  if(gridcp == NULL) verr("memory allocation error gridcp");
  if (Ns || (NINT(cs0*1e3) >= 0)) {
    gridcs = alloc2float(nz, nx);
    if(gridcs == NULL) verr("memory allocation error gridcs");
  }
  else gridcs = NULL;
  if (Nr || (NINT(ro0*1e3) >= 0)) {
    gridro = alloc2float(nz, nx);
    if(gridro == NULL) verr("memory allocation error gridro");
  }
  else gridro = NULL;
  
  cp = alloc2float(nx,3);
  cs = alloc2float(nx,3);
  ro = alloc2float(nx,3);
  if (store_int == 1) inter = alloc2float(nx, 2*Np);
  
  if (verbose) {
    vmess("Origin top left (x,z) . = %.1f, %.1f", orig[0], orig[1]);
    vmess("Base name ............. = %s", file_base);
    vmess("Number of interfaces .. = %d", Np);
    vmess("length in x ........... = %f (=%d)", sizex, nx);
    vmess("length in z ........... = %f (=%d)", sizez, nz);
    vmess("delta x ............... = %f", dx);
    vmess("delta z ............... = %f", dz);
    vmess("cp0 ................... = %f", cp0);
    if (Ns) vmess("cs0 ................... = %f", cs0);
    if (Nr) vmess("ro0 ................... = %f", ro0);
    vmess("write interfaces ...... = %d", writeint);
    vmess("store interfaces ...... = %d", store_int);
    if (above) vmess("define model above interface");
    else vmess("define model below interface");
  }

  /*========== initializing for homogeneous background =============*/
  
  nminx = 0;
  nmaxx = nx;
  for (j = nminx; j < nmaxx; j++) {
    cp[0][j] = cp0;
    cs[0][j] = cs0;
    ro[0][j] = ro0;
    zp[j] = 0;
    cp[1][j] = cp0;
    cs[1][j] = cs0;
    ro[1][j] = ro0;
  }
  
  gradlen = 0.0;
  gradcp = gradcs = gradro = 0.0;
  optgrad = 3;
  if (above == 0) {
    Nvi = 1; Noi = 1;
  } else {
    Nvi = Ngp; Noi = Ngp;
  }
  grid(gridcp, gridcs, gridro, zp, cp, cs, ro, nminx, nmaxx, optgrad,
       gradlen, gradcp, gradcs, gradro, dx, dz, nz);
  
  nxp = nzp = 2;
  x = (float *)malloc(nxp*sizeof(float));
  z = (float *)malloc(nzp*sizeof(float));
  
  if (Ni == 0) {
    if (verbose) vmess("No interfaces are defined, Homogeneous model.");
    Np = 0;
  }
  
  /*========== filling gridded model with interfaces =============*/
  
  for (jcount = 1; jcount <= Np; jcount++) {
    
    /* for above interface definition reverse	*/
    /* order of interfaces to scan 			*/
    if (above == 0) jint=jcount;
    else jint=Np+1-jcount;
    
    if (verbose) vmess("***** Interface number %d *****", jint);
    
    getnparstring(jint,"intt", &file);
    strcpy(intt, file);
    
    nxp = countnparval(jint,"x");
    nzp = countnparval(jint,"z");
    if (nxp != nzp) {
      vmess("nxp = %d nzp =%d for interface %d",nxp, nzp, jint);
      verr("Number of x and z values not equal for interface %d",jint);
    }
    ncp = countnparval(jint,"cp");
    nro = countnparval(jint,"ro");
    ncs = countnparval(jint,"cs");
    
    if (ncp == 1) {
      if (verbose>=2) vmess("No lateral gradient in P velocity");
    }
    else if (ncp == 2) {
      if (verbose) vmess("lateral P-gradient from begin to end");
    }
    else if (ncp != nxp) {
      vmess("ncp = %d nxp =%d for interface %d",ncp, nxp, jint);
      verr("Number of cp's and x not equal for interface %d",jint);
    }
    if (nro <= 1) {
      if (verbose>=2) vmess("No lateral gradient in density");
    }
    else if (nro == 2) {
      if (verbose) vmess("lateral Rho-gradient from begin to end");
    }
    else if (nro != nxp) {
      vmess("nro = %d nxp =%d for interface %d",nro, nxp, jint);
      verr("Number of ro's and x not equal for interface %d",jint);
    }
    if (ncs <= 1) {
      if (verbose>=2) vmess("No lateral gradient in S velocity");
    }
    else if (ncs == 2) {
      if (verbose) vmess("lateral S-gradient from begin to end");
    }
    else if (ncs != nxp) {
      vmess("ncs = %d nxp =%d for interface %d",ncs, nxp, jint);
      verr("Number of cs's and x not equal for interface %d",jint);
    }
    
    nvel = MAX(ncp, MAX(nro, ncs));
    
    free(x);
    free(z);
    x = (float *)malloc(nxp*sizeof(float));
    z = (float *)malloc(nzp*sizeof(float));
	memset(interface, 0, nx*sizeof(float));
    
    getnparfloat(jint,"x",x);
    getnparfloat(jint,"z",z);
    getnparfloat(jint,"cp",cp[2]);
    if (Nr == 0) ro[2][0] = 0.0;
    else getnparfloat(jint,"ro", ro[2]);
    if (Ns == 0) cs[2][0] = 0.0;
    else getnparfloat(jint,"cs", cs[2]);
    if (Ng == 0) gradlen = 0.0;
    else getnparfloat(Noi,"grad", &gradlen);
    if (No == 0) poly = 0;
    else getnparint(Noi,"poly", &poly);
    if (Ngp == 0) gradcp = 0.0;
    else getnparfloat(Noi,"gradcp", &gradcp);
    if (Ngs == 0) gradcs = 0.0;
    else getnparfloat(Noi,"gradcs", &gradcs);
    if (Ngr == 0) gradro = 0.0;
    else getnparfloat(Noi,"gradro", &gradro);
    /* if gradunit is in meters, recalculate gradcp,gradcs and gradro */
    if (gradunit > 0) {
      gradcs = gradcs * dz;
      gradcp = gradcp * dz;
      gradro = gradro * dz;
    }
    
    if (nvel != 1) {
      if (ncp == 1) {
	for (j = 1; j < nvel; j++) cp[2][j] = cp[2][0];
      }
      if (ncs == 1) {
	for (j = 1; j < nvel; j++) cs[2][j] = cs[2][0];
      }
      if (nro == 1) {
	for (j = 1; j < nvel; j++) ro[2][j] = ro[2][0];
      }
    }
    
    if (verbose) {
      vmess("Interface type .......... = %s", intt);
      vmess("Boundary gradient ....... = %f", gradlen);
      vmess("Interface gradient cp ... = %f", gradcp);
      if (Ns) vmess("Interface gradient cs ... = %f", gradcs);
      if (Nr) vmess("Interface gradient ro ... = %f", gradro);
      if (verbose>=2) {
	vmess("Polynomal ............... = %d", poly);
	vmess("Number of (x,z) points... = %d", nxp);
	vmess("P-wave velocities ....... = %d", ncp);
	if (Ns) vmess("S-wave velocities ....... = %d", ncs);
	if (Nr) vmess("Densities ............... = %d", nro);
      }
      for (j = 0; j < nxp; j++) {
	vmess("x = %6.1f \t z = %6.1f", x[j], z[j]);
	if (nvel != 1) {
	  vmess("    cp = %f", cp[2][j]);
	  if (Ns) vmess("    cs = %f", cs[2][j]);
	  if (Nr) vmess("   rho = %f", ro[2][j]);
	}
      }
      if (nvel == 1) {
	vmess("    cp = %f", cp[2][0]);
	if (Ns) vmess("    cs = %f", cs[2][0]);
	if (Nr) vmess("    rho = %f", ro[2][0]);
      }
    }
    
    for (j = 0; j < nxp; j++) {
      x[j] -= orig[0];
      z[j] -= orig[1];
    }
    for (j = 0; j < nxp; j++) {
      if(x[j] > sizex) verr("x coordinate bigger than model");
      if(z[j] > sizez) verr("z coordinate bigger than model");
    }
    if (gradlen > 0) optgrad = gradt;
    else optgrad = 3;
    
	if (strstr(intt,"random") != NULL) {
		Nv = countnparval(Nvi,"var");
		if (Nv != 1) verr("Random interface must have 1 variables.");
		getnparfloat(Nvi,"var", var);
		lseed = (long)var[0];
		srand48(lseed);
		gradcp=gradcs=gradro=var[0];
		optgrad = 4;
        if (above == 0) Noi++; else Noi--;
        if (above == 0) Nvi++; else Nvi--;
	}
	  
    if ((strstr(intt,"diffr") == NULL) && (strstr(intt,"randdf") == NULL)) {
      interpolation(x, z, nxp, nx, poly, &nminx, &nmaxx, dx, 
		    cp, cs, ro, nvel, interface);
    }

    if ( (strstr(intt,"def") != NULL) || (strstr(intt,"random") != NULL) ) {
      linearint(zp, nminx, nmaxx, dz, interface);
      if (above == 0) Noi++; else Noi--;
    }

    if (strstr(intt,"sin") != NULL) {
      Nv = countnparval(Nvi,"var");
      if (Nv != 2) verr("Sinus interface must have 2 variables.");
      getnparfloat(Nvi,"var", var);
      sinusint(zp, nminx, nmaxx, dz, interface, dx, var[0], var[1]);
      if (above == 0) Noi++; else Noi--;
      if (above == 0) Nvi++; else Nvi--;
    }
    else if (strstr(intt,"rough") != NULL) {
      Nv = countnparval(Nvi,"var");
      if (Nv != 3) verr("Rough interface must have 3 variables.");
      getnparfloat(Nvi,"var", var);
      roughint(zp, nminx, nmaxx, dz, interface, var[0],var[1],var[2]);
      if (above == 0) Noi++; else Noi--;
      if (above == 0) Nvi++; else Nvi--;
    }
    else if (strstr(intt,"fract") != NULL) {
      Nv = countnparval(Nvi, "var");
      if (Nv != 6) verr("Fractal interface must have 6 variables.");
      getnparfloat(Nvi,"var", var);
      fractint(zp, nminx, nmaxx, dx, dz, interface, var[0], var[1], 
	       var[2], var[3], var[4], var[5]);
      if (above == 0) Noi++; else Noi--;
      if (above == 0) Nvi++; else Nvi--;
    }
   	else if (strstr(intt,"randdf") != NULL) {
		float x0, z0, dsx, dsz;
		int i;
		Nv = countnparval(Nvi, "var");
		if (Nv != 2) verr("randdf interface must have 2 variables: number of points, width.");
		getnparfloat(Nvi,"var", var);
        if(!getparint("dtype", &dtype)) dtype = -1;
        
        randdf(x, z, nxp, dx, dz, gridcp, gridcs, gridro, cp, cs, ro,
              interface, zp, nx, sizex, sizez, var[0], (int)var[1], dtype);

		if (above == 0) Noi++; else Noi--;
		if (above == 0) Nvi++; else Nvi--;
	}
	else if (strstr(intt,"elipse") != NULL) {
		Nv = countnparval(Nvi, "var");
		if (Nv != 2) verr("Elipse interface must have 2 variables.");
		getnparfloat(Nvi,"var", var);
		elipse(x, z, nxp, dx, dz, gridcp, gridcs, gridro, 
			cp, cs, ro, interface, zp, nz, nx, var[0], var[1], gradcp, gradcs, gradro);
		if (above == 0) Noi++; else Noi--;
		if (above == 0) Nvi++; else Nvi--;
	}
	else if ((strstr(intt,"diffr") != NULL)) {
		Nv = countnparval(Nvi, "var");
        if (Nv == 2 || Nv == 1) {
            getnparfloat(Nvi,"var", var);
            diffrwidth=(int)var[0];
            if (Nv==1) {
            	if(!getparint("dtype", &dtype)) dtype = 0;
			}
            else dtype=(int)var[1];
        }
        else {
            verr("diffr interface must have 1 or 2 variables: width,type.");
        }
        
		diffraction(x, z, nxp, dx, dz, gridcp, gridcs, gridro,
			cp, cs, ro, interface, zp, nx, diffrwidth, dtype);
		if (above == 0) Noi++; else Noi--;
		if (above == 0) Nvi++; else Nvi--;
	}
    else {
		if (above == 0) {
			grid(gridcp, gridcs, gridro, zp, cp, cs, ro, nminx, nmaxx, 
				optgrad, gradlen, gradcp, gradcs, gradro, dx, dz, nz);
		} 
		else {
			gridabove(gridcp, gridcs, gridro, zp, cp, cs, ro, nminx, nmaxx, 
				optgrad, gradlen, gradcp, gradcs, gradro, dx, dz, nz);
		}
	}
    
    if (store_int == 1) {
      for(j = 0; j < nminx; j++) inter[jint-1][j] = 0.0;
      for(j = nminx; j < nmaxx; j++) inter[jint-1][j] = interface[j];
      for(j = nmaxx; j < nx; j++) inter[jint-1][j] = 0.0;
      
      for(j = 0; j < nminx; j++) inter[jint-1+Np][j] = 0.0;
      for(j = nminx; j < nmaxx; j++) inter[jint-1+Np][j] = zp[j]*dz;
      for(j = nmaxx; j < nx; j++) inter[jint-1+Np][j] = 0.0;
    }
  } /* end of loop over interfaces */
  
  if (verbose) vmess("Writing data to disk.");
  
  hdrs = (segy *) calloc(nx,sizeof(segy));
  for(j = 0; j < nx; j++) {
	hdrs[j].f1= orig[1];
	hdrs[j].f2= orig[0];
	hdrs[j].d1= dz;
	hdrs[j].d2= dx;
    hdrs[j].ns= nz;
	hdrs[j].trwf= nx;
	hdrs[j].tracl= j;
	hdrs[j].tracf= j;
    hdrs[j].gx = (orig[0] + j*dx)*1000;
    hdrs[j].scalco = -1000;
    hdrs[j].timbas = 25;
    hdrs[j].trid = TRID_DEPTH;
  }

  /* due to bug in SU, int-file has to be opened before other files are closed */
  if (writeint == 1) {
    strcpy(filename, file_base);
    name_ext(filename, "_int");
    fpint = fopen(filename,"w");
    assert(fpint != NULL);
  }
  
  /* write P-velocities in file */
  strcpy(filename, file_base);
  name_ext(filename, "_cp");
  fpcp = fopen(filename,"w");
  assert(fpcp != NULL);
  
  data_out = (float *)malloc(nx*nz*sizeof(float));
  for(ix = 0; ix < nx; ix++) {
    for(iz = 0; iz < nz; iz++) {
      data_out[ix*nz+iz] = gridcp[ix][iz];
	}
    nwrite = fwrite( &hdrs[ix], 1, TRCBYTES, fpcp);
    assert(nwrite == TRCBYTES);
    nwrite = fwrite( &data_out[ix*nz], sizeof(float), nz, fpcp);
    assert(nwrite == nz);
  }
  fclose(fpcp);
  free2float(gridcp);
  
  /* write S-velocities in file */
  if (Ns > 0 || getparfloat("cs0", &cs0)) {
    strcpy(filename, file_base);
    name_ext(filename, "_cs");
    fpcs = fopen(filename,"w");
    assert(fpcs != NULL);
    
    for(ix = 0; ix < nx; ix++) {
      for(iz = 0; iz < nz; iz++) {
	     data_out[ix*nz+iz] = gridcs[ix][iz];
      }
      nwrite = fwrite( &hdrs[ix], 1, TRCBYTES, fpcs);
      assert(nwrite == TRCBYTES);
      nwrite = fwrite( &data_out[ix*nz], sizeof(float), nz, fpcs);
      assert(nwrite == nz);
    }
    fclose(fpcs);
    free2float(gridcs);
    
  } /* end of writing S-velocity file */
  
  /* write densities in file */
  if (Nr > 0 || getparfloat("ro0", &ro0)) {
    strcpy(filename, file_base);
    name_ext(filename, "_ro");
    fpro = fopen(filename,"w");
    assert(fpro != NULL);
    
    for(ix = 0; ix < nx; ix++) {
      for(iz = 0; iz < nz; iz++) {
	     data_out[ix*nz+iz] = gridro[ix][iz];
      }
      nwrite = fwrite( &hdrs[ix], 1, TRCBYTES, fpro);
      assert(nwrite == TRCBYTES);
      nwrite = fwrite( &data_out[ix*nz], sizeof(float), nz, fpro);
      assert(nwrite == nz);
    }
    fclose(fpro);
    free2float(gridro);
  } /* end of writing density file */
  
  /* write depths of the interfaces */
  if (writeint == 1) {
    free(hdrs);
    hdrs = (segy *) calloc(Np,sizeof(segy));
    for(j = 0; j < Np; j++) {
      hdrs[j].fldr = 1;
      hdrs[j].timbas = 25;
	  hdrs[j].f1= orig[0];
	  hdrs[j].f2= 0.0;
	  hdrs[j].d1= dx;
	  hdrs[j].d2= dz;
	  hdrs[j].ns= nx;
	  hdrs[j].trwf= Np;
	  hdrs[j].tracl= j;
	  hdrs[j].tracf= j;
	  hdrs[j].trid= TRID_DEPTH;
    }
    
    /* note that due to bug in SU, interface file ha salready been opened */
    strcpy(filename, file_base);
    name_ext(filename, "_int");

    free(data_out);
    data_out = (float *)malloc(nx*Np*sizeof(float));
    for(jint = 0; jint < Np; jint++) {
      for(j = 0; j < nx; j++) {
	    data_out[jint*nx+j] = inter[jint][j]+orig[1];
      }
      nwrite = fwrite( &hdrs[ix], 1, TRCBYTES, fpint);
      assert(nwrite == TRCBYTES);
      nwrite = fwrite( &data_out[jint*nx], sizeof(float), nx, fpint);
      assert(nwrite == nx);
    }
    
	for(j = 0; j < Np; j++) hdrs[j].fldr = 2;
    for(jint = 0; jint < Np; jint++) {
      for(j = 0; j < nx; j++) {
	     data_out[jint*nx+j] = inter[jint+Np][j]+orig[1];
      }
      nwrite = fwrite( &hdrs[ix], 1, TRCBYTES, fpint);
      assert(nwrite == TRCBYTES);
      nwrite = fwrite( &data_out[jint*nx], sizeof(float), nx, fpint);
      assert(nwrite == nx);
    }
    fclose(fpint);
    
  } /* end of writing interface file */
  
  if (rayfile == 1) {
    strcpy(filename, file_base);
    strcpy(strrchr(filename, '.'), ".mod");
    
    fpout = fopen(filename, "w+");
    fprintf(fpout,"RAYTRACE MODEL FILE\n");
    fprintf(fpout,"# ASCII file for ray-tracer\n\n");
    fprintf(fpout,"# Top interface\n\n");
    fprintf(fpout,"x=0,%.1f\n", sizex);
    fprintf(fpout,"z=0.,0.\n");
    
    /*		for(i = 1; i <= Np; i++) {
		fprintf(fpout,"\n# %d th interface\n\nx=",i);
		nxp = countnparval(i,"x");
		nzp = countnparval(i,"z");
		free(x);
		free(z);
		x = (float *)malloc(nxp*sizeof(float));
		z = (float *)malloc(nzp*sizeof(float));
		getnparfloat(i,"x",x);
		getnparfloat(i,"z",z);
		for(j = 0; j < (nxp-1); j ++) fprintf(fpout,"%.1f,", x[j]);
		fprintf(fpout,"%.1f\nz=", x[nxp-1]);
		for(j = 0; j < (nxp-1); j ++) fprintf(fpout,"%.1f,", z[j]);
		fprintf(fpout,"%.1f\n", z[nxp-1]);
		}
    */
    for(jint = 0; jint < Np; jint++) {
      fprintf(fpout,"\n# %d th interface\n\nx=0",jint+1);
      for(j = skip; j < nx; j += skip) 
	fprintf(fpout,",%.1f", (float)j*dx);
      
      fprintf(fpout,"\nz=%.1f", inter[jint][0]);
      for(j = skip; j < nx; j += skip) 
	fprintf(fpout,",%.1f", inter[jint][j]);
      fprintf(fpout,"\n");
    }
    fprintf(fpout,"\n# %d th interface\n\nx=0",jint+1);
    for(j = skip; j < nx; j += skip) 
      fprintf(fpout,",%.1f", (float)j*dx);
    
    fprintf(fpout,"\nz=%.1f", sizez);
    for(j = skip; j < nx; j += skip) 
      fprintf(fpout,",%.1f", sizez);
    fprintf(fpout,"\n");
    
    /**/
    fprintf(fpout,"\n\n");
    fprintf(fpout,"cp=%.1f,", back[0]);
    for(jint = 1; jint <= Np; jint++) {
      aver = 0.0;
      ncp = countnparval(jint,"cp");
      getnparfloat(jint,"cp",cp[2]);
      for(j = 0; j < ncp; j++) 
	aver += cp[2][j];
      aver = aver/((float)ncp);
      if (jint == Np ) fprintf(fpout,"%.1f", aver);
      else fprintf(fpout,"%.1f,", aver);
    }
    
    fclose(fpout);
    free2float(inter);
  }
  
  free(hdrs);
  
  return 0;
}
コード例 #12
0
ファイル: pslabel.c プロジェクト: JOravetz/SeisUnix
int main (int argc, char **argv)
{
	char **text,**font,*textcolor,*boxcolor;
	float size,labelCD=0.0,labelCA,labelCW=0.0,labelCH,bigx,bigy,eps,eps2;
	float *x;
	int n,j,nsub;
	size_t nchar;

	/* Hook up getpars */
	initargs(argc,argv);
	requestdoc(0);

	/* Get parameters */
	if(!getparint("nsub",&nsub))nsub=0;
	if(!getparfloat("size",&size))size=30;
	if(!getparstring("tcolor",&textcolor))textcolor="black";
	if(!getparstring("bcolor",&boxcolor))boxcolor="white";

        checkpars();

	eps=0.25*size;
	eps2=0.1*size;
	n=countparname("t");
	if(n==0)
 	err("must enter at least one PSTEXT text stream as parameter t");

	if(n!=countparname("f")) 
		warn("suggest specify same number of values for t and f");
	text =(char **)malloc( (n+1)*sizeof(char *) );
	font =(char **)malloc( (n+1)*sizeof(char *) );
	x = (float *)malloc( (n+1)*sizeof(float) );	
	for(bigx=eps,bigy=0.,j=0;j<n;j++){
		x[j]=bigx;
		if(!getnparstring(j+1,"t",&text[j]))text[j]="hello";
		if(!getnparstring(j+1,"f",&font[j]))font[j]="Times-Bold";
		labelCH = fontheight(font[j],size);
		labelCW = fontwidth(font[j],size);
		labelCA = fontascender(font[j],size);
		labelCD = MIN(labelCD,fontdescender(font[j],size));
		nchar = strlen(text[j]);
		bigx+=0.5*(((double) nchar)*labelCW);
		bigy=MAX(bigy,labelCH+eps+0.0*labelCA);
	}
	bigx+=eps;
	bigx-=0.5*nsub*labelCW;

	/* open output eps file */
	boundingbox(-eps2,-eps2,bigx+eps2,bigy+eps2);
	begineps();
	gsave();
	rectclip(0.,0.,bigx,bigy);

	/* fill background box with background color */
	newpath();
	moveto(0.,0.);
	lineto(bigx,0.);
	lineto(bigx,bigy);
	lineto(0.,bigy);
	closepath();
	setcolor(boxcolor);
	fill();
	
	/* write out text strings */
	setcolor(textcolor);
	moveto(eps,eps-labelCD);
	for(j=0;j<n;j++) {
		setfont(font[j],size);
		show(text[j]);
	}

	/* close output stream */
	grestore();
	showpage();
	endeps();

	return EXIT_SUCCESS;
}