Exemplo n.º 1
0
int main(int argc, char*argv[])
{
	int n1, n2, n3,n4, i2, i3, i4, m2, m3;
	sf_file in, hor, out;
	float **u, **v, **h, o1, d1;
	char *interp;
	sinterp intp;

	sf_init(argc, argv);

	in = sf_input("in");
	hor = sf_input("horizon");
	out = sf_output("out");

	if(!sf_histint(in, "n1", &n1)) sf_error("n1 needed in input");
	if(!sf_histfloat(in, "o1", &o1)) o1=0.0;
	if(!sf_histfloat(in, "d1", &d1)) d1=1.0;
	if(!sf_histint(in, "n2", &n2)) sf_error("n2 needed in input");
	if(!sf_histint(in, "n3", &n3)) n3=1; 
	if(!sf_histint(in, "n4", &n4)) n4=1; 
	if(!sf_histint(hor, "n1", &m2)) sf_error("n1 needed in horizon file");
	if(!sf_histint(hor, "n2", &m3)) m3=1; 

	if((interp=sf_getstring("interp")) ==NULL ) interp="linear";
	/*< interpolation method: nearest, linear >*/

	intp = sinterp_c2f(interp);
	if(n2!=m2 || n3!= m3) sf_error("horizon file not match");

	sf_unshiftdim(in,out,1);
	u = sf_floatalloc2(n1, n2);
	v = sf_floatalloc2(n2, n3);
	h = sf_floatalloc2(n2, n3);

	sf_floatread(h[0], n3*n2, hor);
	for(i4=0; i4<n4; i4++)
	{
		for(i3=0; i3<n3; i3++)
		{
			sf_floatread(u[0], n1*n2, in);
			for(i2=0; i2<n2; i2++)
			v[i3][i2] = intp(u[i2], (h[i3][i2]-o1)/d1, n1);
		}
		sf_floatwrite(*v, n2*n3, out);
	}

	free(*u);
	free(u);
	free(*v);
	free(v);
	free(*h);
	free(h);
}
Exemplo n.º 2
0
int main(int argc, char* argv[])
{
    int nt, ns, nx, ix, is, it;
    float *trace=NULL, *picks=NULL, **semb=NULL, s0, ds, s;
    sf_file in=NULL, out=NULL, pick=NULL;

    sf_init(argc,argv);
    in = sf_input("in");
    pick = sf_input("pick");
    out = sf_output("out");

    if (!sf_histint(in,"n1",&nt)) sf_error("No n1= in input");

    if (!sf_histint(in,"n2",&ns)) sf_error("No n2= in input");
    if (!sf_histfloat(in,"o2",&s0)) sf_error("No o2= in input");
    if (!sf_histfloat(in,"d2",&ds)) sf_error("No d2= in input");

    nx = sf_unshiftdim(in,out,2);

    semb = sf_floatalloc2(nt,ns);
    picks = sf_floatalloc (nt);
    trace = sf_floatalloc (nt);

    for (ix=0; ix < nx; ix++) {
	sf_floatread (semb[0],nt*ns,in);
	sf_floatread (picks,nt,pick);

	for (it=0; it < nt; it++) {
	    s = (picks[it] - s0)/ds;
	    is = floorf(s); s -= is;
	    if (is >= 0 && is < ns-1) {
		trace[it] = s * semb[is+1][it] + (1.-s) * semb[is][it];
	    } else {
		trace[it] = 0.;
	    }
	}

	sf_floatwrite (trace,nt,out);
    }

    exit (0);
}
Exemplo n.º 3
0
int main (int argc, char* argv[])
{
    bool half, slow;
    int ih,ix,it,nt,nx,nd,nh, CDPtype, jump, niter, restart, nplo, nphi, ni, axis,lim,j;
    off_t n;
    float dt, t0, h0, dh, eps, dy, tol, flo, fhi;
    float *trace, *trace2, *vel, *off, **gather, **dense;
    char key1[7];
    sf_file cmp, stack, velocity, offset;

    sf_init (argc,argv);
    cmp = sf_input("in");
    velocity = sf_input("velocity");
    stack = sf_output("out");
    
    axis = 2; 
    lim = axis-1;
  
    n = 1;
    for (j=0; j < lim; j++) {
      sprintf(key1,"n%d",j+1);
	    if (!sf_histint(cmp,key1,&ni)) break;
	    n *= ni;
    }
  
    (void) sf_unshiftdim(cmp,stack,axis);
 
    if (SF_FLOAT != sf_gettype(cmp)) sf_error("Need float input");
    if (!sf_histint(cmp,"n1",&nt)) sf_error("No n1= in input");
    if (!sf_histfloat(cmp,"d1",&dt)) sf_error("No d1= in input");
    if (!sf_histfloat(cmp,"o1",&t0)) sf_error("No o1= in input");

    if (!sf_histint(cmp,"n2",&nh)) sf_error("No n2= in input");

    off = sf_floatalloc(nh);

    if (!sf_getbool("half",&half)) half=true;
    /* if y, the second axis is half-offset instead of full offset */

    CDPtype=1;
    if (NULL != sf_getstring("offset")) {
	offset = sf_input("offset");
	sf_floatread (off,nh,offset);
	sf_fileclose(offset);
    } else {
	if (!sf_histfloat(cmp,"d2",&dh)) sf_error("No d2= in input");
	if (!sf_histfloat(cmp,"o2",&h0)) sf_error("No o2= in input");
	
	if (sf_histfloat(cmp,"d3",&dy)) {
	    CDPtype=half? 0.5+dh/dy : 0.5+0.5*dh/dy;
	    if (CDPtype < 1) {
		CDPtype=1;
	    } else if (1 != CDPtype) {
		sf_histint(cmp,"CDPtype",&CDPtype);
	    	sf_warning("CDPtype=%d",CDPtype);
	    }
	} 

	for (ih = 0; ih < nh; ih++) {
	    off[ih] = h0 + ih*dh; 
	}
    }

    if (!sf_getbool("slowness",&slow)) slow=false;
    /* if y, use slowness instead of velocity */

    nx = sf_leftsize(cmp,2);

    if (!sf_getfloat ("h0",&h0)) h0=0.;
    /* reference offset */
    if (half) h0 *= 2.;
    if (!sf_getfloat("eps",&eps)) eps=0.01;
    /* stretch regularization */

    if (!sf_getint("jump",&jump)) jump=1;
    /* subsampling */

    if (!sf_getint("niter",&niter)) niter=10;
    /* number of iterations */

    if (!sf_getint("restart",&restart)) restart=niter;
    /* GMRES memory */

    if (!sf_getfloat("tol",&tol)) tol=1e-5;
    /* GMRES tolerance */

    if (!sf_getfloat("flo",&flo)) {
	/* Low frequency in band, default is 0 */
	flo=0.;
    } else if (0. > flo) {
	sf_error("Negative flo=%g",flo);
    } else {
	flo *= (dt/jump);
    }

    if (!sf_getfloat("fhi",&fhi)) {
	/* High frequency in band, default is Nyquist */	
	fhi=0.5;
    } else {
	fhi *= (dt/jump);	
	if (flo > fhi) 
	    sf_error("Need flo < fhi, "
		     "got flo=%g, fhi=%g",flo/(dt/jump),fhi/(dt/jump));
	if (0.5 < fhi)
	    sf_error("Need fhi < Nyquist, "
		     "got fhi=%g, Nyquist=%g",fhi/(dt/jump),0.5/(dt/jump));
    }

    if (!sf_getint("nplo",&nplo)) nplo = 6;
    /* number of poles for low cutoff */
    if (nplo < 1)  nplo = 1;
    if (nplo > 1)  nplo /= 2; 

    if (!sf_getint("nphi",&nphi)) nphi = 6;
    /* number of poles for high cutoff */
    if (nphi < 1)  nphi = 1;
    if (nphi > 1)  nphi /= 2;
  
    nd = (nt-1)*jump+1;
  
    bandpass_init(nd,flo,fhi,nplo,nphi);
    
    sf_putint(stack,"n1",nd);
    sf_putfloat(stack,"d1",dt/jump);

    trace = sf_floatalloc(nd);
    trace2 = sf_floatalloc(nd);
    gather = sf_floatalloc2(nt,nh);
    dense = sf_floatalloc2(nd,nh);

    vel = sf_floatalloc(nd);

    for (ix = 0; ix < nx; ix++) { /* loop over midpoint nx*/
	sf_floatread (vel,nd,velocity);	
	
	inmo_init(vel, off, nh, 
		  h0, dh, CDPtype, ix,
		  nt, slow,
		  t0, dt, eps, half,
		  jump);

	sf_floatread (gather[0],nt*nh,cmp);

	/* apply backward operator */
	interpolate(gather, dense);
	nmostack(dense,trace);
	/* apply shaping */
	bandpass(trace);
	
	sf_gmres_init(nd,restart);

	for (it=0; it < nd; it++) {
	    trace2[it] = 0.0f;
	}

	/* run GMRES */
	sf_gmres(trace,trace2,inmo_oper,NULL,niter,tol,true);

	sf_floatwrite (trace2,nd,stack);

	sf_gmres_close();

	inmo_close();
    }


    exit (0);
}
Exemplo n.º 4
0
int main (int argc, char* argv[])
{
    int n1,n2,i3,i2,n4,j,n12,fold,ndim, mdim;
    int n[SF_MAX_DIM], m[SF_MAX_DIM], *mk;
    float *d, *sht, *x, mean, std, sum, amp=0.0;
    bool verb;
    sf_file in, out, msk, scl;

    sf_init (argc,argv);
    in  = sf_input("in");
    out = sf_output("out");
    
    if (SF_FLOAT != sf_gettype(in)) sf_error("Need float");
    
    if (!sf_histint(in,"n1",&n1)) sf_error("Need n1=");
    if (!sf_histint(in,"n2",&n2)) sf_error("Need n2=");
    n4 = sf_leftsize(in,2);
    n12=n1*n2;

    if (!sf_getbool("verb",&verb)) verb=false;
    /* verbosity flag */

    /* input file*/
    if (! (sf_getstring("mask") || 
               sf_histstring(in,"mask")))
         sf_error("Need mask=");

    msk = sf_input("mask");
    if (SF_INT != sf_gettype(msk)) sf_error("Need integer mask");

    sf_getfloat("amp",&amp);
    /*Exclude amplitudes greater than amp && less than -amp for statistics computations*/

    ndim = sf_filedims(in,n);
    mdim = sf_filedims(msk,m);

    if (mdim != ndim) 
	sf_error("Wrong dimensions: %d != %d",mdim,ndim);
    
    for (j=0; j < ndim; j++) {
	if (m[j] != n[j])
            sf_error("Size mismatch [n%d]: %d != %d",
		     j+1,m[j],n[j]);
    }

    /* output file*/
    if (NULL != sf_getstring("scaler")){
        scl = sf_output("scaler");
        sf_unshiftdim(in, scl, 2);
        sf_putint(scl,"n1",2);
    } else {
	scl = NULL;
    }
    
    d   = sf_floatalloc(n12*n4);
    x   = sf_floatalloc(2*n4);
    sht = sf_floatalloc(n12);
    mk  = sf_intalloc(n12);
    
    /* loop through time samples */
    for (i3=0; i3 < n4; i3++) {
        mean=0.0;
        fold=0;
        std =0.0;
        sum=0.0;
	sf_floatread(sht,n12,in);
        sf_intread(mk,n12,msk);
        /* compute mean */
	for (i2=0; i2 < n12; i2++) {
           if (sht[i2]!=0.0 && mk[i2]!=0 ) {
                if ( amp==0.0 || fabsf(sht[i2]) < fabsf(amp) ){        
                    sum  +=sht[i2];
                    fold +=1;
                }
           }     
        }
        if (fold > 0) mean=sum/fold;
        
        /* compute standard deviation */
        for (i2=0; i2 < n12; i2++) {
           if (sht[i2]!=0.0 && mk[i2]!=0 ) {
               //if (!(amp && fabsf(sht[i2]) < fabsf(amp)))
               //     continue;
               if ( amp==0.0 || fabsf(sht[i2]) < fabsf(amp) )
                  std += (sht[i2]-mean)*(sht[i2]-mean);
           }     
        }
        if (fold > 0) std =sqrtf(std/(fold-1));
        
        /* scale time samples*/
        for (i2=0; i2 < n12; i2++) 
            if (sht[i2]!=0.0 && mean!=0.0 && std!=0.0)
                d[i2+i3*n12]=(sht[i2]-mean)/std;
            else
                d[i2+i3*n12]=sht[i2];
        x[0+i3*2]=mean;
        x[1+i3*2]=std;

        if (verb) sf_warning("shot %8d-> mean:%8g std:%8g, fold:%8d\n;",i3+1,mean,std,fold);
    }
    sf_floatwrite (d,n4*n12,out);
    if (scl)
       sf_floatwrite (x,n4*2,scl);
    exit(0);
}
Exemplo n.º 5
0
int main(int argc, char* argv[])
{
    bool inv, verb;
    int i1, n1, iw, nt, nw, i2, n2, rect0, niter, n12, n1w;
    int m[SF_MAX_DIM], *rect;
    float t, d1, w, w0, dw, mean=0.0f, alpha;
    float *trace, *kbsc, *mkbsc, *sscc, *mm, *ww;
    sf_complex *outp, *cbsc;
    sf_file in, out, mask, weight, basis;

    sf_init(argc,argv);
    in = sf_input("in");
    out = sf_output("out");

    if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input");
    if (!sf_histfloat(in,"d1",&d1)) d1=1.;

    if (!sf_getbool("inv",&inv)) inv=false;
    /* if y, do inverse transform */

    if (!sf_getbool("verb",&verb)) verb = false;
    /* verbosity flag */

    if (NULL != sf_getstring("basis")) {
        basis = sf_output("basis");
        sf_settype(basis,SF_COMPLEX);
    } else {
        basis = NULL;
    }

    if (!inv) {
        if (!sf_getint("nw",&nw)) { /* number of frequencies */
            nt = 2*kiss_fft_next_fast_size((n1+1)/2);
            nw = nt/2+1;
            dw = 1./(nt*d1);
            w0 = 0.;
        } else {
            if (!sf_getfloat("dw",&dw)) {
                /* frequency step */
                nt = 2*kiss_fft_next_fast_size((n1+1)/2);
                dw = 1./(nt*d1);
            }
            if (!sf_getfloat("w0",&w0)) w0=0.;
            /* first frequency */
        }
        n2 = sf_leftsize(in,1);
        sf_shiftdim(in, out, 2);
        sf_putint(out,"n2",nw);
        sf_putfloat(out,"d2",dw);
        sf_putfloat(out,"o2",w0);
        sf_putstring(out,"label2","Frequency");
        sf_putstring(out,"unit2","Hz");
        sf_settype(out,SF_COMPLEX);

        if (!sf_getint("rect",&rect0)) rect0=10;
        /* smoothing radius (in time, samples) */
        if (!sf_getint("niter",&niter)) niter=100;
        /* number of inversion iterations */
        if (!sf_getfloat("alpha",&alpha)) alpha=0.;
        /* frequency adaptivity */

        for(i2=0; i2 < SF_MAX_DIM; i2 ++) {
            m[i2] = 1;
        }
        m[0] = n1;
    } else {
        n2 = sf_leftsize(in,2);
        if (!sf_histint(in,"n2",&nw)) sf_error("No n2= in input");
        if (!sf_histfloat(in,"d2",&dw)) sf_error("No d2= in input");
        if (!sf_histfloat(in,"o2",&w0)) sf_error("No o2= in input");
        sf_unshiftdim(in, out, 2);
        sf_settype(out,SF_FLOAT);
    }

    if (NULL != basis) {
        sf_shiftdim(in, basis, 2);
        sf_putint(basis,"n2",nw);
        sf_putfloat(basis,"d2",dw);
        sf_putfloat(basis,"o2",w0);
        sf_putstring(basis,"label2","Frequency");
        sf_putstring(basis,"unit2","Hz");
    }

    n1w = n1*nw;
    n12 = 2*n1w;
    dw *= 2.*SF_PI;
    w0 *= 2.*SF_PI;

    trace = sf_floatalloc(n1);
    kbsc    = sf_floatalloc(n12);
    outp = sf_complexalloc(n1w);
    cbsc = sf_complexalloc(n1w);

    rect = sf_intalloc(2*nw);
    for (iw=0; iw < nw; iw++) {
        rect[iw+nw] = rect[iw] = SF_MAX(1, (int) rect0/(1.0+alpha*iw/nw));
    }

    if (!inv) {
        sscc = sf_floatalloc(n12);
        nmultidivn_init(2*nw, 1, n1, m, rect, kbsc,
                        (bool) (verb && (n2 < 500)));
    } else {
        sscc = NULL;
    }

    if (NULL != sf_getstring("mask")) { /* data weight */
        mask = sf_input("mask");
        mm = sf_floatalloc(n1);
    } else {
        mask = NULL;
        mm = NULL;
    }

    if (NULL != sf_getstring("weight")) { /* model weight */
        weight = sf_input("weight");
        ww = sf_floatalloc(n1w);
    } else {
        weight = NULL;
        ww = NULL;
    }

    /* sin and cos basis */
    for (iw=0; iw < nw; iw++) {
        w = w0 + iw*dw;
        for (i1=0; i1 < n1; i1++) {
            if (0.==w) { /* zero frequency */
                kbsc[iw*n1+i1] = 0.;
            } else {
                t = i1*d1;
                kbsc[iw*n1+i1] = sinf(w*t);
            }
        }
    }
    for (iw=0; iw < nw; iw++) {
        w = w0 + iw*dw;
        for (i1=0; i1 < n1; i1++) {
            if (0.==w) { /* zero frequency */
                kbsc[(iw+nw)*n1+i1] = 0.5;
            } else {
                t = i1*d1;
                kbsc[(iw+nw)*n1+i1] = cosf(w*t);
            }

            cbsc[iw*n1+i1] = sf_cmplx(kbsc[(iw+nw)*n1+i1],
                                      kbsc[iw*n1+i1]);
        }
    }


    if (NULL != mm || NULL != ww) {
        mkbsc = sf_floatalloc(n12);
        for (i1=0; i1 < n12; i1++) {
            mkbsc[i1] = kbsc[i1];
        }
    } else {
        mkbsc = NULL;

        mean = 0.;
        for (i1=0; i1 < n12; i1++) {
            mean += kbsc[i1]*kbsc[i1];
        }
        mean = sqrtf (mean/(n12));
        for (i1=0; i1 < n12; i1++) {
            kbsc[i1] /= mean;
        }
    }

    for (i2=0; i2 < n2; i2++) {
        sf_warning("slice %d of %d;",i2+1,n2);

        if (NULL != basis) sf_complexwrite(cbsc,n1w,basis);

        if (NULL != mm || NULL != ww) {
            for (i1=0; i1 < n12; i1++) {
                kbsc[i1] = mkbsc[i1];
            }

            if (NULL != mm) {
                sf_floatread(mm,n1,mask);
                for (iw=0; iw < 2*nw; iw++) {
                    for (i1=0; i1 < n1; i1++) {
                        kbsc[iw*n1+i1] *= mm[i1];
                    }
                }
            }

            if (NULL != ww) {
                sf_floatread(ww,n1w,weight);
                for (iw=0; iw < nw; iw++) {
                    for (i1=0; i1 < n1; i1++) {
                        kbsc[iw*n1+i1]      *= ww[iw*n1+i1];
                        kbsc[(iw+nw)*n1+i1] *= ww[iw*n1+i1];
                    }
                }
            }

            mean = 0.;
            for (i1=0; i1 < n12; i1++) {
                mean += kbsc[i1]*kbsc[i1];
            }
            mean = sqrtf (mean/(n12));
            for (i1=0; i1 < n12; i1++) {
                kbsc[i1] /= mean;
            }
        }

        if (!inv) {
            sf_floatread(trace,n1,in);
            if (NULL != mm) {
                for (i1=0; i1 < n1; i1++) {
                    trace[i1] *= mm[i1];
                }
            }

            for(i1=0; i1 < n1; i1++) {
                trace[i1] /= mean;
            }
            nmultidivn (trace,sscc,niter);
            for (iw=0; iw < nw; iw++) {
                for (i1=0; i1 < n1; i1++) {
                    outp[iw*n1+i1] = sf_cmplx(sscc[(iw+nw)*n1+i1],
                                              sscc[iw*n1+i1]);
                }
            }

            if (NULL != ww) {
                for (i1=0; i1 < n1w; i1++) {
#ifdef SF_HAS_COMPLEX_H
                    outp[i1] *= ww[i1];
#else
                    outp[i1] = sf_crmul(outp[i1],ww[i1]);
#endif
                }
            }

            sf_complexwrite(outp,n1w,out);
        } else {
            for (i1=0; i1 < n1; i1++) {
                trace[i1] = 0.;
            }
            sf_complexread(outp,n1w,in);
            for (iw=0; iw < nw; iw++) {
                for (i1=0; i1 < n1; i1++) {
                    trace[i1] += crealf(outp[iw*n1+i1])*kbsc[(iw+nw)*n1+i1]
                                 *mean+cimagf(outp[iw*n1+i1])*kbsc[iw*n1+i1]*mean;
                    if (NULL != mm) trace[i1] *= mm[i1];
                }
            }
            sf_floatwrite(trace,n1,out);
        }
    }
    sf_warning(".");

    exit(0);
}
Exemplo n.º 6
0
Arquivo: Mpick2.c Projeto: Seislet/src
int main(int argc, char* argv[])
{
    int it, niter, nm, n1, n2, n3, i3, i2, i1, i, gate, i0, rect1, rect2, n123, n[2], rect[2];
    float **scan, **weight, *pick, *ampl, *pick2, o2, d2, an, asum, a, ct, vel0;
    char *label;
    sf_file scn, pik;

    sf_init(argc,argv);
    scn = sf_input("in");
    pik = sf_output("out");

    if (SF_FLOAT != sf_gettype(scn)) sf_error("Need float input");

    if (!sf_histint(scn,"n1",&n1)) sf_error("No n1= in input");
    if (!sf_histint(scn,"n2",&n2)) sf_error("No n2= in input");
    if (!sf_histint(scn,"n3",&n3)) sf_error("No n3= in input");

    nm = n1*n3;
    n123 = nm*n2;
    n[0]=n1;
    n[1]=n3;

    if (!sf_histfloat(scn,"o2",&o2)) o2=0.;
    if (!sf_histfloat(scn,"d2",&d2)) d2=1.;
 
    if (!sf_getfloat("vel0",&vel0)) vel0=o2;
    /* surface velocity */
    i0 = 0.5 + (vel0-o2)/d2;
    if (i0 < 0) i0=0;
    if (i0 >= n2) i0=n2-1;

    sf_unshiftdim(scn,pik,2);

    if (NULL != (label = sf_histstring(scn,"label2"))) 
		sf_putstring(pik,"label",label);
    if (NULL != (label = sf_histstring(scn,"unit2"))) 
		sf_putstring(pik,"unit",label);

    if (!sf_getint("rect1",&rect1)) rect1=1;
    /* smoothing radius on the first axis */ 
    if (!sf_getint("rect2",&rect2)) rect2=1;
    /* smoothing radius on the second axis */ 
    rect[0]=rect1;
    rect[1]=rect2;

    if (!sf_getint("niter",&niter)) niter=100;
    /* number of iterations */

    if (!sf_getfloat("an",&an)) an=1.; 
    /* axes anisotropy */
    if (!sf_getint("gate",&gate)) gate=3; 
    /* picking gate */

    scan = sf_floatalloc2(n1,n2);
    weight = sf_floatalloc2(n2,n1);

    (void) dynprog_init(n1,n2,gate,an,false);

    pick = sf_floatalloc(nm);
    pick2 = sf_floatalloc(nm);	
    ampl = sf_floatalloc(nm);
    
    sf_divn_init(2,nm,n,rect,niter,true);

    for (i3=0; i3 < n3; i3++) {
	sf_warning("cmp %d of %d;",i3+1,n3);
	sf_floatread(scan[0],n1*n2,scn);

	/* transpose and reverse */
	for (i2=0; i2 < n2; i2++) {
	    for (i1=0; i1 < n1; i1++) {
		weight[i1][i2] = expf(-scan[i2][i1]);
	    }
	}

	dynprog(i0, weight);
	dynprog_traj(pick2);

	for (i1=0; i1 < n1; i1++) {
	    i = i1 + i3*n1;
	    ct = pick2[i1];
	    pick[i] = ct;
	    it = floorf(ct);
	    ct -= it;
	    if (it >= n2-1) {
		ampl[i]=scan[n2-1][i1];
	    } else if (it < 0) {
		ampl[i]=scan[0][i1];
	    } else {
		ampl[i]=scan[it][i1]*(1.-ct)+scan[it+1][i1]*ct;
	    }
	}
    }
    sf_warning(".");
    
    /* normalize amplitudes */
    asum = 0.;
    for (i = 0; i < nm; i++) {
	a = ampl[i];
	asum += a*a;
    }
    asum = sqrtf (asum/nm);
    for(i=0; i < nm; i++) {
	ampl[i] /= asum;
	pick[i] = (o2+pick[i]*d2-vel0)*ampl[i];
    }
    
    sf_divn(pick,ampl,pick2);

    for(i=0; i < nm; i++) {
	pick2[i] += vel0;
    }

    sf_floatwrite(pick2,nm,pik);

    exit(0);
}
Exemplo n.º 7
0
int main(int argc, char* argv[])
{
    bool inv, dip, verb, time, decomp;
    int i, i1, n1, iw, nw, i2, n2, rect, niter, n12, nt, ip, np;
    char *label;
    float t, d1, w, w0, dw, p0, dp, p;
    sf_complex *trace, *kbsc, *sscc=NULL;
    sf_file in, out, basis;
	
    sf_init(argc,argv);
    in = sf_input("in");
    out = sf_output("out");
	
    if (SF_COMPLEX != sf_gettype(in)) sf_error("Need complex input");
	
    if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input");
    if (!sf_histfloat(in,"d1",&d1)) d1=1.;
    label = sf_histstring(in,"label1");
	
    if (!sf_getbool("inv",&inv)) inv=false;
    /* if y, do inverse transform */
	
    if (!sf_getbool("verb",&verb)) verb = false;
    /* verbosity flag */
	
    if (!sf_getbool("dip",&dip)) dip = false;
    /* if y, do dip decomposition */

    if (!sf_getbool("time",&time)) time = false;
    /* if y, decompose in time */

    if (!sf_getbool("decompose",&decomp)) decomp = false;
    /* if y, output decomposition */
	
    if (NULL != sf_getstring("basis")) {
	basis = sf_output("basis");
    } else {
	basis = NULL;
    }
	
    if (!inv) {
	n2 = sf_leftsize(in,1);
	sf_shiftdim(in, out, 2);
		
	if (!sf_getint("rect",&rect)) rect=10;
	/* smoothing radius (in time, samples) */
	if (!sf_getint("niter",&niter)) niter=100;
	/* number of inversion iterations */
		
	if (dip) {
	    if (!sf_getint("np",&np)) sf_error("Need np=");
	    /* number of slopes */
			
	    if (!sf_getfloat("dp",&dp)) sf_error("Need dp=");
	    /* slope step */
			
	    if (!sf_getfloat("p0",&p0)) sf_error("Need p0=");
	    /* first slope */
			
	    sf_putint(out,"n2",np);
	    sf_putfloat(out,"d2",dp);
	    sf_putfloat(out,"o2",p0);
	    sf_putstring(out,"label2","Slope");
	    sf_putstring(out,"unit2","");
			
            if (!sf_histint(in,"n2",&nw)) nw=1;
	    if (!sf_histfloat(in,"d2",&dw)) dw=1.;
	    if (!sf_histfloat(in,"o2",&w0)) w0=0.;
	} else {
	    if (time) {
		if (!sf_histint  (in,"n1",&nw)) sf_error("No n1= in input");
		if (!sf_histfloat(in,"d1",&dw)) sf_error("No d1= in input");

		nw = 2*(nw-1);
		dw = 1./(nw*dw);

		if (!sf_histint  (in,"fft_n1",&nw)) sf_error("No fft_n1= in input");
		if (!sf_histfloat(in,"fft_o1",&w0)) sf_error("No fft_o1= in input");

		/* fix label */
		if (NULL != (label = sf_histstring(in,"fft_label1"))) {
		    sf_putstring(out,"label1",label);
		} else if (NULL != (label = sf_histstring(in,"label1"))) {
		    (void) sf_fft_label(1,label,out);
		}
	    } else {
		if (!sf_getint("nw",&nw)) nw = kiss_fft_next_fast_size(n1);
		/* number of frequencies */
		
		if (!sf_getfloat("dw",&dw)) dw = 1./(nw*d1);
		/* frequency step */
		
		if (!sf_getfloat("w0",&w0)) w0=-0.5/d1;
		/* first frequency */
			
		if (NULL != label && !sf_fft_label(2,label,out)) 
		    sf_putstring(out,"label2","Wavenumber");
	    }

	    sf_fft_unit(2,sf_histstring(in,"unit1"),out);

	    sf_putint(out,"n2",nw);
	    sf_putfloat(out,"d2",dw);
	    sf_putfloat(out,"o2",w0);

	    if (time) {
		dw = -dw;
		w0 = -w0;
	    }
	}
    } else {
	n2 = sf_leftsize(in,2);
		
	if (dip) {
	    if (!sf_histint(in,"n2",&np)) sf_error("No n2= in input");
	    if (!sf_histfloat(in,"d2",&dp)) sf_error("No d2= in input");
	    if (!sf_histfloat(in,"o2",&p0)) sf_error("No o2= in input");
			
            if (!sf_histint(in,"n2",&nw)) nw=1;
	    if (!sf_histfloat(in,"d3",&dw)) dw=1.;
	    if (!sf_histfloat(in,"o3",&w0)) w0=0.;
	} else {
	    if (!sf_histint(in,"n2",&nw)) sf_error("No n2= in input");
	    if (!sf_histfloat(in,"d2",&dw)) sf_error("No d2= in input");
	    if (!sf_histfloat(in,"o2",&w0)) sf_error("No o2= in input");
	}
		
	sf_unshiftdim(in, out, 2);
    }
	
    if (NULL != basis) {
	sf_shiftdim(in, basis, 2);
	if (dip) {
	    sf_putint(basis,"n2",np);
	    sf_putfloat(basis,"d2",dp);
	    sf_putfloat(basis,"o2",p0);
	    sf_putstring(basis,"label2","Slope");
	    sf_putstring(basis,"unit2","");
	} else {
	    sf_putint(basis,"n2",nw);
	    sf_putfloat(basis,"d2",dw);
	    sf_putfloat(basis,"o2",w0);
	    if (NULL != label && !sf_fft_label(2,label,basis)) 
		sf_putstring(basis,"label2","Wavenumber");
	    sf_fft_unit(2,sf_histstring(in,"unit1"),out);
	}
    }
    
    nt = dip? np:nw;
	
    n12 = nt*n1;
    dw *= 2.*SF_PI;
    w0 *= 2.*SF_PI;
	
    trace = sf_complexalloc(n1);
    kbsc = sf_complexalloc(n12);
    sscc = sf_complexalloc(n12);
    
    if (!dip) {
	/* basis functions */
	for (iw=0; iw < nw; iw++) {
	    w = w0 + iw*dw;
			
	    for (i1=0; i1 < n1; i1++) {
		t = i1*d1;
				
		kbsc[iw*n1+i1] = sf_cmplx(cosf(w*t),sinf(w*t));
	    }
	}
		
	if (NULL != basis) {
	    sf_complexwrite(kbsc,n12,basis);
	}
    }
	
    if (!inv) cmultidivn_init(nt, 1, n1, &n1, &rect, kbsc, (bool) (verb && (n2 < 500)));
	
    for (i2=0; i2 < n2; i2++) {
	sf_warning("slice %d of %d;",i2+1,n2);
		
	if (dip) {
	    w = w0 + (i2 % nw)*dw;
	    for (ip=0; ip < np; ip++) {
		p = -w*(p0 + ip*dp);
				
		for (i1=0; i1 < n1; i1++) {
		    t = i1*d1;
					
		    kbsc[ip*n1+i1] = sf_cmplx(cosf(p*t),sinf(p*t));
		}
	    }
			
	    if (NULL != basis) {
		sf_complexwrite(kbsc,n12,basis);
	    }
	}
		
	if (!inv) {
	    sf_complexread(trace,n1,in);
	    cmultidivn (trace,sscc,niter);

	    if (decomp) {
		for (iw=0; iw < nt; iw++) {
		    for (i1=0; i1 < n1; i1++) {
			i = iw*n1+i1;
					
#ifdef SF_HAS_COMPLEX_H
			sscc[i] *= kbsc[i];
#else
			sscc[i1] = sf_cmul(sscc[i],kbsc[i]);
#endif
		    }
		}
	    }

	    sf_complexwrite(sscc,n12,out);
	} else {
	    for (i1=0; i1 < n1; i1++) {
		trace[i1] = sf_cmplx(0.,0.);
	    }
	    sf_complexread(sscc,n12,in);
	    for (iw=0; iw < nt; iw++) {
		for (i1=0; i1 < n1; i1++) {
		    i = iw*n1+i1;
					
#ifdef SF_HAS_COMPLEX_H
		    trace[i1] += sscc[i]*kbsc[i];
#else
		    trace[i1] = sf_cadd(trace[i1],sf_cmul(sscc[i],kbsc[i]));
#endif
		}
	    }
	    sf_complexwrite(trace,n1,out);
	}
    }
    sf_warning(".");
	
    exit(0);
}
Exemplo n.º 8
0
int main(int argc, char *argv[])
{
    int n1, n2, i3, n3, n12, ip, np, n12p, ncycle, niter, order;
    bool inv, verb, decomp, twhole;
    char *type;
    float *pp, *qq, ***dd, ***mm, eps, perc, scale;
    sf_file in, out, dip, mask;

    sf_init(argc,argv);

    in = sf_input("in");
    out = sf_output("out");
    dip = sf_input("dips");

    if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input");
    if (!sf_histint(in,"n2",&n2)) sf_error("No n2= in input");
    n12 = n1*n2;

    if (!sf_histint(dip,"n3",&np)) np=1;
    n12p = n12*np;
    scale = 1./np;

    pp = sf_floatalloc(n12);
    qq = sf_floatalloc(n12p);
    dd = sf_floatalloc3(n1,n2,np);

    if (!sf_getbool("inv",&inv)) inv=false;
    /* if y, do inverse transform */

    if (!sf_getfloat("eps",&eps)) eps=0.01;
    /* regularization */

    if (!sf_getbool("verb",&verb)) verb=true;
    /* verbosity flag */

    if (!sf_getbool("twhole",&twhole)) twhole=true;
    /* threshold flag, if y, whole model, otherwise, each component */

    if (!sf_getbool("decomp",&decomp)) decomp=false;
    /* do decomposition */

    if (!sf_getint("ncycle",&ncycle)) ncycle=0;
    /* number of iterations */

    if (!sf_getint("niter",&niter)) niter=1;
    /* number of Bregman iterations */

    if (!sf_getfloat("perc",&perc)) perc=50.0;
    /* percentage for sharpening */

    if (NULL != sf_getstring("mask")) { /* (optional) data mask file */
	mask = sf_input("mask");
	mm = sf_floatalloc3(n1,n2,np);
    } else {
	mask = NULL;
	mm = NULL;
    }

    if (inv) {
	n3 = sf_leftsize(in,3);
	if (!decomp) sf_unshiftdim(in, out, 3);
    } else {
	n3 = sf_leftsize(in,2);
	sf_putint(out,"n3",np);
	(void) sf_shiftdim(in, out, 3);
    } 

    if (!sf_getint("order",&order)) order=1;
    /* accuracy order */

    if (NULL == (type=sf_getstring("type"))) type="linear";
    /* wavelet type (haar,linear,biorthogonal), default is linear */
    
    diplet_init(n1,n2,decomp? 1: np, dd,mm,true,eps,order,type[0]);
 
    for (i3=0; i3 < n3; i3++) {
	sf_floatread(dd[0][0],n12p,dip);
	if (NULL != mask) sf_floatread(mm[0][0],n12p,mask);
	
	if (inv) {
	    sf_floatread(qq,n12p,in);

	    if (decomp) {
		for (ip=0; ip < np; ip++) {
		    seislet_set(dd[ip]);
		    seislet_lop(false,false, n12, n12,qq+ip*n12, pp);
		    datawrite(n12,1.,pp,out);
		}
	    } else {
		diplet_lop(false,false, n12p, n12,qq, pp);
		datawrite(n12,scale,pp,out);
	    }
	} else {
    	    sf_floatread(pp,n12,in);
	    sf_sharpinv(diplet_lop,
			scale,niter,ncycle,perc,verb,n12p,n12,qq,pp,twhole); 
	    sf_floatwrite(qq,n12p,out);
	} 
    }

    exit(0);
}