Exemplo n.º 1
0
int main(int argc, char* argv[])
{
    int n1, is, ns, nf, esize, pad;
    off_t i2, n2;
    char *trace, *zero;
    sf_file in, shift;

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

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

    if (!sf_histint(in,"esize",&esize)) {
	esize=sf_esize(in);
    } else if (0>=esize) {
	sf_error("cannot handle esize=%d",esize);
    }

    if (!sf_getint("ns",&ns)) sf_error("Need ns=");
    /* number of shifts */

    if (!sf_getint("nf",&nf)) nf = 1;
    /* offset of first shift */

    if ((nf+ns-1) >= n1) sf_error("(nf+ns-1)=%d is too large",nf+ns-1);

    sf_putint(shift,"n2",ns);
    sf_shiftdim(in, shift, 2);

    sf_fileflush(shift,in);
    sf_setform(in,SF_NATIVE);
    sf_setform(shift,SF_NATIVE);

    n1 *= esize;

    trace = sf_charalloc(n1);
    zero = sf_charalloc(n1);
    memset(zero,0,n1);

    for (i2=0; i2 < n2; i2++) {
	sf_charread(trace,n1,in);
	for (is=nf; is <= (nf+ns-1); is++) {
	    pad = is*esize;
	    sf_charwrite(zero,pad,shift);
	    sf_charwrite(trace,n1-pad,shift);
	}
    }

    exit(0);
}
Exemplo n.º 2
0
int main(int argc, char*argv[])
{
	sf_file in, out;
	int nf, n1, n2, m, n;
	int i2;
	float *wav, **fb;
	char *interp;

	sf_init(argc, argv);

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

	if (SF_FLOAT != sf_gettype(in)) sf_error("Need float type");

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

	sf_shiftdim(in,out,1);

	if(!sf_getint("m", &m)) m=1;
	/* b[-m, ... ,n] */
	if(!sf_getint("n", &n)) n=1;
	/* b[-m, ... ,n] */
	if ((interp=sf_getstring("interp"))==NULL) interp="maxflat";
	/* interpolation method: maxflat lagrange bspline */

	nf = m+n+1;

	wav = sf_floatalloc(n1);
	fb  = sf_floatalloc2(n1, nf);

	sf_putint(out, "n2", nf);
	sf_putfloat(out, "o2", 0);
	sf_putfloat(out, "d2", 1);


	fbank_init(m, n, interp);


	for(i2=0; i2<n2; i2++)
	{
		sf_floatread(wav, n1, in);
		fbank1(n1, wav, fb);
		sf_floatwrite(fb[0], n1*nf, out);
	}

	fbank_close();
	return 0;
}
Exemplo n.º 3
0
Arquivo: Mss.c Projeto: krushev36/src
int main(int argc, char*argv[])
{
    sf_file in, out ;
    int i1, i2, n1, n2, *v;
    float o1, d1, **u;
    char *l1, *u1;
    sf_axis ax;

    sf_init(argc, argv);

    in  = sf_input("in");  /* delay file (int) */
    out = sf_output("out");

    if(!sf_histint(in, "n1", &n2)) sf_error("n1 needed");
    sf_shiftdim(in, out, 1);


    if(!sf_getint("n1", &n1)) n1=1000; /* samples */
    if(!sf_getfloat("o1", &o1)) o1=0.0; /* sampling interval */
    if(!sf_getfloat("d1", &d1)) d1=0.004; /* original  */
    if((l1=sf_getstring("l1")) == NULL) l1="Time"; /* label "Time" */
    if((u1=sf_getstring("u1")) == NULL) u1="s"; /* unit "s" */

    ax = sf_maxa(n1, o1, d1);
    sf_setlabel(ax, l1);
    sf_setunit(ax, u1);
    sf_oaxa(out, ax, 1);
    sf_putint(out, "n2", n2);
    sf_settype(out, SF_FLOAT);

    v = sf_intalloc(n2);
    u = sf_floatalloc2(n1, n2);
    sf_intread(v, n2, in);

    for(i2=0; i2<n2; i2++)
        for(i1=0; i1<n1; i1++)
            if(i1==v[i2])	u[i2][i1] = 1;
            else u[i2][i1] = 0;

    sf_floatwrite(u[0], n1*n2, out);

    free(v);
    free(u[0]);
    free(u);

    return 0;

}
Exemplo n.º 4
0
int main (int argc, char *argv[])
{
    bool verb, up2, up3;
    unsigned char update;
    int n1,n2,n3, i1,i2,i3, ns2, ns3, ip, np2, np3, n23;
    int order, np, i4, n4, k2, k3, j2, j3, i, jp, j;
    float eps, ***u, **p1, **p2, **cost, *trace, *q2=NULL, *q3=NULL;
    sf_file inp, out, dip;

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

    if (!sf_histint(inp,"n1",&n1)) sf_error("No n1= in input");
    if (!sf_histint(inp,"n2",&n2)) sf_error("No n2= in input");
    if (!sf_histint(inp,"n3",&n3)) sf_error("No n3= in input");
    n23 = n2*n3;
    n4 = sf_leftsize(inp,3);

    if (!sf_getbool("verb",&verb)) verb=false;
    /* verbosity */
    if (!sf_getfloat("eps",&eps)) eps=0.01;
    /* regularization */
    
    if (!sf_getint("order",&order)) order=1;
    /* accuracy order */

    if (!sf_getint("ns2",&ns2)) sf_error("Need ns1=");
    if (!sf_getint("ns3",&ns3)) sf_error("Need ns2=");
    /* spray radius */
    np2 = 2*ns2+1;
    np3 = 2*ns3+1;
    np = np2*np3;

    sf_putint(out,"n2",np);
    sf_shiftdim(inp, out, 2);

    cost = sf_floatalloc2(np2,np3);
    for (i3=0; i3 < np3; i3++) {
	for (i2=0; i2 < np2; i2++) {
	    cost[i3][i2] = hypotf(i2-ns2,i3-ns3);
	}
    }

    predict_init (n1, n2, eps*eps, order, 1, true);
    update_init(np2,np3,*cost);

    u = sf_floatalloc3(n1,np,n23);
    for (i3=0; i3 < n23; i3++) {
	for (ip=0; ip < np; ip++) {
	    for (i1=0; i1 < n1; i1++) {
		u[i3][ip][i1] = 0.;
	    }
	}
    }

    p1 = sf_floatalloc2(n1,n23);
    p2 = sf_floatalloc2(n1,n23);

    for (i=0; i < n23; i++) { 
	sf_floatread(p1[i],n1,dip);
    }

    for (i=0; i < n23; i++) { 
	sf_floatread(p2[i],n1,dip);
    }

    for (i4=0; i4 < n4; i4++) {
	for (i=0; i < n23; i++) { 
	    sf_floatread(u[i][ns3*np2+ns2],n1,inp);
	    
	    i2 = i%n2;
	    i3 = i/n2;

	    for (ip=0; ip < np; ip++) {
		update = get_update(ip,&up2,&up3,&jp);
		
		/* from jp to j */
		k2 = jp%np2;
		k3 = jp/np2;
		
		j2 = i2+k2-ns2;
		j3 = i3+k3-ns3;

		if (j2 < 0 || j2 >= n2 || 
		    j3 < 0 || j3 >= n3) continue;

		j = j2+j3*n2;
		trace = u[j][jp];

		if (update & 1) {		
		    if (up2) {
			if (j2==0) continue;
			j2 = j-1;
			q2 = p1[j2];
			k2 = jp-1;
		    } else {
			if (j2==n2-1) continue;
			j2 = j+1;
			q2 = p1[j];
			k2 = jp+1;
		    }
		}
		if (update & 2) {
		    if (up3) {
			if (j3==0) continue;
			j3 = j-n2;
			q3 = p2[j3];
			k3 = jp-np2;
		    } else {
			if (j3==n3-1) continue;
			j3 = j+n2;
			q3 = p2[j];
			k3 = jp+np2;
		    }
		}

		switch(update) {
		    case 0:			
			break;
		    case 1:
			predict1_step(up2,u[j2][k2],q2,trace);
			break;
		    case 2:
			predict1_step(up3,u[j3][k3],q3,trace);
			break;
		    case 3:
			predict2_step(up2,up3,u[j2][k2],u[j3][k3],
				      q2,q3,trace);
			break;
		}
	    }
	}

	for (i=0; i < n23; i++) {
	    for (ip=0; ip < np; ip++) {
		sf_floatwrite(u[i][ip],n1,out);
	    }
	}
    }

    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
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.º 7
0
int main(int argc, char* argv[])
{
    int j, n1, n2, i2, ni, axis, esize;
    float f;
    off_t i3, n3;
    size_t n;
    sf_file in, out;
    char key1[7], key2[7], *val, *trace;

    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_histint(in,"esize",&esize)) sf_error("No esize= in input");

    if (!sf_getint("axis",&axis)) axis=2;
    /* which axis to spray */

    n = (size_t) esize;
    for (j=0; j < axis-1; j++) {
	sprintf(key2,"n%d",j+1);
	if (!sf_histint(in,key2,&ni)) break;
	n *= ni;
    }

    if (!sf_getint("n",&n2)) sf_error("Need n=");
    /* Size of the newly created dimension */    
    sprintf(key1,"n%d",axis);
    sf_putint(out,key1,n2);

    if (sf_getfloat("d",&f)) {
	/* Sampling of the newly created dimension */ 
	sprintf(key1,"d%d",axis);
	sf_putfloat(out,key1,f);
    }
    
    if (sf_getfloat("o",&f)) {
	/* Origin of the newly created dimension */
	sprintf(key1,"o%d",axis);
	sf_putfloat(out,key1,f);
    }

    if (NULL != (val = sf_getstring("label"))) {
	/* Label of the newly created dimension */
	sprintf(key1,"label%d",axis);
	sf_putstring(out,key1,val);
    }

    if (NULL != (val = sf_getstring("unit"))) {
	/* Units of the newly created dimension */
	sprintf(key1,"unit%d",axis);
	sf_putstring(out,key1,val);
    }

    n3 = sf_shiftdim(in, out, axis);
    
    sf_fileflush(out,in);
    sf_setform(in,SF_NATIVE);
    sf_setform(out,SF_NATIVE);

    trace = sf_charalloc (n);
    
    for (i3=0; i3 < n3; i3++) {
	sf_charread (trace, n, in);
	for (i2=0; i2 < n2; i2++) {
	    sf_charwrite(trace, n, out);
	} 
    }


    exit (0);
}
Exemplo n.º 8
0
int main (int argc, char *argv[])
{
    int n123, niter, order, i,j, liter, dim;
    int n[SF_MAX_DIM], rect[2], nr, ir; 
    float a0, *u, *p;
    bool verb;
    sf_file in, out, sn, cs;

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

    if (SF_FLOAT != sf_gettype(in)) sf_error("Need float type");

    dim = sf_filedims(in,n);
    if (dim < 2) n[1]=1;
    n123 = n[0]*n[1];
    nr = 1;
    for (j=2; j < dim; j++) {
	nr *= n[j];
    }
    
    if (!sf_getint("niter",&niter)) niter=5;
    /* number of iterations */
    if (!sf_getint("liter",&liter)) liter=50;
    /* number of linear iterations */

    if (!sf_getint("rect1",&rect[0])) rect[0]=1;
    /* dip smoothness on 1st axis */
    if (!sf_getint("rect2",&rect[1])) rect[1]=1;
    /* dip smoothness on 2nd axis */

    if (!sf_getfloat("a0",&a0)) a0=0.;
    /* initial dip */

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

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

    sf_shiftdim(in, out, 3);
    sf_putint(out,"n3",2);
    
    /* initialize dip estimation */
    odip2_init(n[0], n[1], rect, liter, verb);

    u = sf_floatalloc(n123);
    p = sf_floatalloc(2*n123);

    if (NULL != sf_getstring("sin")) {
	/* initial dip (sine) */
	sn = sf_input("sin");
    } else {
	sn = NULL;
    }

    if (NULL != sf_getstring("cos")) {
	/* initial dip (cosine) */
	cs = sf_input("cos");
    } else {
	cs = NULL;
    }

    for (ir=0; ir < nr; ir++) {	

	/* initialize t-x dip */
	if (NULL != sn) {
	    sf_floatread(p,n123,sn);
	} else {
	    for(i=0; i < n123; i++) {
		p[i] = 0.0f;
	    }
	}
	if (NULL != cs) {
	    sf_floatread(p+n123,n123,cs);
	} else {
	    for(i=0; i < n123; i++) {
		p[n123+i] = 1.0f;
	    }
	}

	/* read data */
	sf_floatread(u,n123,in);
	
	/* estimate dip */
	odip2(niter, order, u, p);
		
	/* write dip */
	sf_floatwrite(p,2*n123,out);
    }
    
    exit (0);
}
Exemplo n.º 9
0
int main(int argc, char* argv[])
{
    bool verb;
    int n[SF_MAX_DIM], n0[SF_MAX_DIM], rect[SF_MAX_DIM];
    int a[SF_MAX_DIM], center[SF_MAX_DIM], gap[SF_MAX_DIM];
    int ndim, dim, n123, n123s, i, ia, ns, i1, niter, na, i4, n4, *kk;
    float *d, *f, *dd;
    double mean;
    char *lagfile, key[6];
    sf_filter aa;
    sf_file in, filt, lag;
 
    sf_init(argc,argv);

    in = sf_input("in");
    filt = sf_output("out");

    if (NULL == (lagfile = sf_getstring("lag"))) sf_error("Need lag=");
    /* output file for filter lags */

    lag = sf_output(lagfile);
    sf_settype(lag,SF_INT);

    sf_putstring(filt,"lag",lagfile);

    ndim = sf_filedims(in,n);

    if (!sf_getint("dim",&dim)) dim=ndim; /* number of dimensions */

    n4 = sf_leftsize(in,dim);
    
    sf_putints (lag,"n",n,dim);

    if (!sf_getints("a",a,dim)) sf_error("Need a=");

    if (!sf_getints("center",center,dim)) {
	for (i=0; i < dim; i++) {
	    center[i] = (i+1 < dim && a[i+1] > 1)? a[i]/2: 0;
	}
    }

    if (!sf_getint("na",&na)) na=0;
    /* filter size */

    if (0 == na) {
	if (!sf_getints("gap",gap,dim)) {
	    for (i=0; i < dim; i++) {
		gap[i] = 0;
	    }
	}
	
	aa = createhelix(dim, n, center, gap, a); /* allocate PEF */
	
	for (i=0; i < dim; i++) {	    
	    n0[i] = n[i];
	}
    } else {
	aa =  sf_allocatehelix (na);
	if (!sf_getints ("lags", aa->lag, na)) sf_error("Need lags=");
	if (!sf_getints ("n", n0, dim)) {
	    for (i=0; i < dim; i++) {	    
		n0[i] = n[i];
	    }
	}
    }

    n123 = 1;
    for (i=0; i < dim; i++) {
	n123 *= n[i];
	
	snprintf(key,6,"rect%d",i+1);
	if (!sf_getint(key,rect+i)) rect[i]=1;
    }

    dd = sf_floatalloc(n123);
    kk = sf_intalloc(n123);

    for (i1=0; i1 < n123; i1++) {
	kk[i1] = 1;
    }

    bound (dim, n0, n, a, aa);
    find_mask(n123, kk, aa);

    na = aa->nh;

    snprintf(key,3,"n%d",dim+1);
    sf_putint(filt,key,na);
    sf_shiftdim(in, filt, dim+1);    
    
    if (!sf_getint("niter",&niter)) niter=100;
    /* number of iterations */

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

    n123s = n123*na;
    
    d = sf_floatalloc(n123s);
    f = sf_floatalloc(n123s);
    
    sf_multidivn_init(na, dim, n123, n, rect, d, NULL, verb); 

    for (i4=0; i4 < n4; i4++) {

	sf_floatread(dd,n123,in);
	
	/* apply shifts: dd -> d */

	mean = 0.;
	for (i=ia=0; ia < na; ia++) {
	    ns = aa->lag[ia];
	    for (i1=0; i1 < n123; i1++,i++) {
		if (i1 < ns) {
		    d[i] = 0.0f;
		} else {
		    d[i] = dd[i1-ns];
		    mean += d[i]*d[i];
		}
	    }
	}

	if (mean == 0.) {
	    sf_floatwrite(d,n123s,filt);
	    continue;
	}
	
	mean = sqrt (n123s/mean);

	/* -> apply mask */
	
	for(i=0; i < n123s; i++) {
	    d[i] *= mean;
	}
	for(i1=0; i1 < n123; i1++) {
	    dd[i1] *= mean;
	}

	sf_multidivn (dd,f,niter);
	sf_floatwrite(f,n123s,filt);
	
    }
    
    exit(0);
}
Exemplo n.º 10
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);
}
Exemplo n.º 11
0
int main(int argc, char* argv[])
{
    sf_map4 mo;
    int n1, i2, n2, iw, nw, ns;
    float o1, d1, t, eps;
    float *trace, *move, *str, *amp;
    sf_file out, warp;

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

    if (!sf_getint("n1",&n1)) sf_error("Need n1="); /* time samples */
    if (!sf_getfloat("d1",&d1)) d1=1.; /* time sampling */
    if (!sf_getfloat("o1",&o1)) o1=0.; /* time origin */

    sf_shiftdim(warp, out, 1);
	
    sf_putint(out,"n1",n1);
    sf_putfloat(out,"d1",d1);
    sf_putfloat(out,"o1",o1);
    sf_putstring(out,"label1","Time");
    sf_putstring(out,"unit1","s");

    n2 = sf_filesize(warp);

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

    if (!sf_getint("nw",&nw)) nw=10;
    /* wavelet length */
    ns = 2*nw+1;

    move = sf_floatalloc(n2);
    sf_floatread(move,n2,warp);

    trace = sf_floatalloc(n1);
    str = sf_floatalloc(ns);
    amp = sf_floatalloc(ns);

    mo = sf_stretch4_init (n1, o1, d1, ns, eps);

    for (i2=0; i2 < n2; i2++) {
	t = move[i2];
	str[nw] = t;
	amp[nw] = 1.0;

	for (iw=0; iw < nw; iw++) {
	    str[iw] = t - (nw-iw)*d1;
	    amp[iw] = 0.0;

	    str[nw+iw+1] = t+iw*d1;
	    amp[nw+iw+1] = 0.0;
	}

	sf_stretch4_define (mo,str);
	sf_stretch4_apply (false,mo,amp,trace);
	sf_floatwrite (trace,n1,out);
    }

    exit(0);
}
Exemplo n.º 12
0
int main(int argc, char* argv[])
{
    map4 str;
    bool verb;
    int i1,i2, n1,n2,n3, nw, nx,ny,nv, ix,iy,iv;
    float d1,o1,d2,o2, eps, w,x,y, v0,v2,v,dv, dx,dy, t, x0,y0, dw;
    float *trace, *strace, *t2;
    sf_complex *ctrace, *ctrace2, shift;
    sf_file in, out;

#ifdef SF_HAS_FFTW
    fftwf_plan forw, invs;
#else
    kiss_fftr_cfg forw, invs;
#endif

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

    if (SF_FLOAT != sf_gettype(in)) sf_error("Need float input");
    if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input");
    if (!sf_histint(in,"n2",&nx)) sf_error("No n2= in input");
    if (!sf_histint(in,"n3",&ny)) sf_error("No n3= in input");

    if (!sf_getfloat("eps",&eps)) eps=0.01; /* regularization */
    if (!sf_getint("pad",&n2)) n2=n1; /* padding for stretch */
    if (!sf_getint("pad2",&n3)) n3=2*kiss_fft_next_fast_size((n2+1)/2);
    /* padding for FFT */

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

    nw = n3/2+1;

    strace = sf_floatalloc(n3);
    ctrace  = sf_complexalloc(nw);
    ctrace2 = sf_complexalloc(nw);

#ifdef SF_HAS_FFTW
    forw = fftwf_plan_dft_r2c_1d(n3, strace, (fftwf_complex *) ctrace,
				 FFTW_ESTIMATE);
    invs = fftwf_plan_dft_c2r_1d(n3, (fftwf_complex *) ctrace2, strace,
				 FFTW_ESTIMATE);
#else
    forw = kiss_fftr_alloc(n3,0,NULL,NULL);
    invs = kiss_fftr_alloc(n3,1,NULL,NULL);
#endif
    if (NULL == forw || NULL == invs) sf_error("FFT allocation error");

    if (!sf_histfloat(in,"o1",&o1)) o1=0.;  
    o2 = o1*o1;

    if(!sf_histfloat(in,"d1",&d1)) sf_error("No d1= in input");
    d2 = o1+(n1-1)*d1;
    d2 = (d2*d2 - o2)/(n2-1);
    dw = 16*SF_PI/(d2*n3); /* 2pi * 8 */

    if (!sf_getint("nv",&nv)) sf_error("Need nv=");
    /* velocity steps */
    if (!sf_getfloat("dv",&dv)) sf_error("Need dv=");
    /* velocity step size */
    if (!sf_getfloat("v0",&v0) && 
	!sf_histfloat(in,"v0",&v0)) sf_error("Need v0=");
    /*( v0 starting velocity )*/

    if(!sf_histfloat(in,"d2",&dx)) sf_error("No d2= in input");
    if(!sf_histfloat(in,"o2",&x0)) x0=0.;

    if(!sf_histfloat(in,"d3",&dy)) sf_error("No d3= in input");
    if(!sf_histfloat(in,"o3",&y0)) y0=0.;

    sf_putfloat(out,"o2",v0+dv);
    sf_putfloat(out,"d2",dv);
    sf_putint(out,"n2",nv);

    sf_putstring(out,"label2","Velocity");

    sf_shiftdim(in, out, 2);

    dx *= 2.*SF_PI;
    x0 *= 2.*SF_PI;

    dy *= 2.*SF_PI;
    y0 *= 2.*SF_PI;

    trace = sf_floatalloc(n1);
    t2 = sf_floatalloc(n2);

    str = stretch4_init (n1, o1, d1, n2, eps);

    for (i2=0; i2 < n2; i2++) {
	t = o2+i2*d2;
	t2[i2] = sqrtf(t);
    }    

    stretch4_define (str,t2);

    for (iy=0; iy < ny; iy++) {
	if (verb) sf_warning("wavenumber %d of %d;", iy+1,ny);

	y = y0+iy*dy; 
	y *= y * 0.5;

	for (ix=0; ix < nx; ix++) {
	    x = x0+ix*dx; 
	    x *= x * 0.5;

	    x += y;

	    sf_floatread(trace,n1,in);
	    for (i1=0; i1 < n1; i1++) {
		trace[i1] /= n1;
	    }
	    stretch4_invert (false,str,strace,trace);
	    for (i2=n2; i2 < n3; i2++) {
		strace[i2] = 0.;
	    }

#ifdef SF_HAS_FFTW
	    fftwf_execute(forw);
#else
	    kiss_fftr(forw,strace, (kiss_fft_cpx *) ctrace);
#endif

	    for (iv=0; iv < nv; iv++) {
		v = v0 + (iv+1)*dv;
		v2 = x * ((v0*v0) - (v*v));
		
		ctrace2[0] = sf_cmplx(0.0f,0.0f); /* dc */
		
		for (i2=1; i2 < nw; i2++) {
		    w = i2*dw;
		    w = v2/w;
		    
		    shift = sf_cmplx(cosf(w),sinf(w));
		    
#ifdef SF_HAS_COMPLEX_H
		    ctrace2[i2] = ctrace[i2] * shift;
#else
		    ctrace2[i2] = sf_cmul(ctrace[i2],shift);
#endif
		} /* w */

#ifdef SF_HAS_FFTW
		fftwf_execute(invs);
#else
		kiss_fftri(invs,(const kiss_fft_cpx *) ctrace2, strace);
#endif
		stretch4_apply(false,str,strace,trace);
		sf_floatwrite (trace,n1,out);
	    } /* v  */
	} /* x */
    } /* y */
    if (verb) sf_warning(".");

    exit (0);
}
Exemplo n.º 13
0
int main (int argc, char* argv[]) {
    int i, j, n, nn, nt;
    float *trace;
    sf_file data, out;

    bool absoff, filter, kmah, diff, verb;

    sf_init (argc, argv);

    data = sf_input ("in");
    /* Common-shot 2-D data */
    out = sf_output ("out");

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

    if (!sf_getbool ("absoff", &absoff)) absoff = false;
    /* y - absolute offset (default - relative to shot axis) */
    if (!sf_getbool ("filter", &filter)) filter = true;
    /* y - antialiasing filter for data */
    if (!sf_getbool ("KMAH", &kmah)) kmah = true;
    /* y - account for phase shifts due to KMAH index */
    if (!sf_getbool ("diff", &diff)) diff = true;
    /* y - apply half-order differentiation */

    /* Data dimensions */
    if (!sf_histint (data, "n1", &nt)) sf_error ("No n1= in data");
    n = sf_leftsize (data, 1);

    /* Next suitable size for the differentiator */
    nn = 2*kiss_fft_next_fast_size ((nt + 1)/2);
    trace = sf_floatalloc (nn*2);

    if (kmah) { /* Make room for phase-shifted traces */
        sf_shiftdim (data, out, 2);
        sf_putint (out, "n2", 2);
        sf_putfloat (out, "o2", 0.0);
        sf_putfloat (out, "d2", 1.0);
        sf_putstring (out, "label1", "");
        sf_putstring (out, "unit1", "");
    }
    sf_putstring (out, "absoff", absoff ? "y" : "n");
    sf_putstring (out, "filter", filter ? "y" : "n");
    sf_putstring (out, "KMAH", kmah ? "y" : "n");

    /* Half-order differentiation object */
    if (diff)
        sf_halfint_init (true, nn, 1.-1./nt);

    for (i = 0; i < n; i++) { /* Loop over traces */
        if (verb && !(i % 10000LU))
            sf_warning ("Processing trace %lu of %lu (%g %%);",
                        i + 1LU, n, 100.0*(float)i/(float)n);
        sf_floatread (trace, nt, data);
        for (j = nt; j < nn; j++) {
            trace[j] = 0.;
        }
        /* Differentiate */
        if (diff)
            sf_halfint (true, trace);
        /* pi/2 phase shift */
        if (kmah)
            sf_cram_trace_hilbert (nt, trace, &trace[nn]);
        /* Causal and anti-causal integration for anti-aliasing filter */
        if (filter) {
            sf_cram_trace_cint (trace, nt);
            sf_cram_trace_acint (trace, nt);
            if (kmah) {
                sf_cram_trace_cint (&trace[nn], nt);
                sf_cram_trace_acint (&trace[nn], nt);
            }
        }
        sf_floatwrite (trace, nt, out);
        if (kmah)
            sf_floatwrite (&trace[nn], nt, out);
    }
    if (verb)
        sf_warning (".");

    free (trace);

    return 0;
}
Exemplo n.º 14
0
int main(int argc, char* argv[])
{
    fint1 nmo;
    bool sembl, half, slow, dsembl, asembl, weight, squared, trend, ratio;
    int it,ih,ix,iv, nt,nh,nx,nv, ib,ie,nb,i, nw, is, ns, CDPtype, mute, *mask;
    float amp, amp2, dt, dh, t0, h0, v0, dv, ds, smax, num, den, dy, str, sh=0., sh2=0.;
    float *trace, ***stack, ***stack2, ***stack2h, ***stackh, *hh, **bb;
    char *time, *space, *unit;
    const char *type;
    size_t len;
    sf_file cmp, scan, offset, msk, grd;
    mapfunc nmofunc;

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

    if (!sf_histint(cmp,"n1",&nt)) sf_error("No n1= in input");
    if (!sf_histint(cmp,"n2",&nh)) sf_error("No n2= in input");
    nx = sf_leftsize(cmp,2);

    if (!sf_getbool("semblance",&sembl)) sembl=false;
    /* if y, compute semblance; if n, stack */
    if (sembl || !sf_getbool("diffsemblance",&dsembl)) dsembl=false;
    /* if y, compute differential semblance */
    if (sembl || dsembl || !sf_getbool("avosemblance",&asembl)) asembl=false;
    /* if y, compute AVO-friendly semblance */

    if (NULL == (type = sf_getstring("type"))) {
	/* type of semblance (avo,diff,sembl,power,weighted) */
	if (asembl) {
	    type="avo";
	} else if (dsembl) {
	    type="diff";
	} else if (sembl) {
	    type="sembl";
	} else {
	    type="power";
	}
    }

    trend = (bool) ('a' == type[0] || 'w' == type[0]);
    ratio = (bool) ('p' != type[0] && 'd' != type[0]);

    if (!sf_getint("nb",&nb)) nb=2;
    /* semblance averaging */
    if (!sf_getbool("weight",&weight)) weight=true;
    /* if y, apply pseudo-unitary weighting */

    if (!sf_histfloat(cmp,"o1",&t0)) sf_error("No o1= in input");
    if (!sf_histfloat(cmp,"d1",&dt)) sf_error("No d1= in input");

    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");
	hh = sf_floatalloc(nh);

	h0 = dh = 0.;
    } else {
	if (!sf_histfloat(cmp,"o2",&h0)) sf_error("No o2= in input");
	if (!sf_histfloat(cmp,"d2",&dh)) sf_error("No d2= in input");
	
	sf_putfloat(scan,"h0",h0);
	sf_putfloat(scan,"dh",dh);
	sf_putint(scan,"nh",nh);

	if (sf_histfloat(cmp,"d3",&dy)) {
	    CDPtype=half? 0.5+dh/dy: 0.5+0.5*dh/dy;
	    if (0 == CDPtype) CDPtype=1;
	    if (1 != CDPtype) {
		sf_histint(cmp,"CDPtype",&CDPtype);
		sf_warning("CDPtype=%d",CDPtype);
	    }
	}

	offset = NULL;
	hh = NULL;
    }

    if (NULL != sf_getstring("mask")) {
	/* optional mask file */ 
	msk = sf_input("mask");
	mask = sf_intalloc(nh);
    } else {
	msk = NULL;
	mask = NULL;
    }

    if (!sf_getfloat("v0",&v0) && !sf_histfloat(cmp,"v0",&v0)) 
	sf_error("Need v0=");
    /*(v0 first scanned velocity )*/
    if (!sf_getfloat("dv",&dv) && !sf_histfloat(cmp,"dv",&dv)) 
	sf_error("Need dv=");
    /*(dv step in velocity )*/
    if (!sf_getint("nv",&nv) && !sf_histint(cmp,"nv",&nv)) 
	sf_error("Need nv=");
    /*(nv number of scanned velocities )*/

    sf_putfloat(scan,"o2",v0);
    sf_putfloat(scan,"d2",dv);
    sf_putint(scan,"n2",nv);

    if (!sf_getfloat("smax",&smax)) smax=2.0;
    /* maximum heterogeneity */
    if (!sf_getint("ns",&ns)) ns=1;
    /* number of heterogeneity scans */ 
    ds = ns>1? (smax-1.0)/(ns-1): 0.;

    if (ns > 1) {
	sf_putfloat(scan,"o3",1.0);
	sf_putfloat(scan,"d3",ds);
	sf_putint(scan,"n3",ns);

	sf_shiftdim(cmp, scan, 3);
    }

    if (!sf_getbool("slowness",&slow)) slow=false;
    /* if y, use slowness instead of velocity */
    sf_putstring(scan,"label2",slow? "Slowness": "Velocity");

    if (!sf_getbool("squared",&squared)) squared=false;
    /* if y, the slowness or velocity is squared */

    if (!sf_getfloat("v1",&v1)) {
	/*( v1 reference velocity )*/
	if (ns > 1) {
	    nmofunc = squared? noncurved: nonhyperb;
	} else {
	    nmofunc = squared? curved: hyperb;
	}
    } else {
	if (ns > 1) {
	    nmofunc = squared? noncurved1: nonhyperb1;
	} else {
	    nmofunc = squared? curved1: hyperb1;
	}
	if (!slow) v1 = 1./v1;
    }

    if (NULL != (time = sf_histstring(cmp,"unit1")) &&
	NULL != (space = sf_histstring(cmp,"unit2"))) {
	len = strlen(time)+strlen(space)+2;
	unit = sf_charalloc(len);
	if (slow) {
	    snprintf(unit,len,"%s/%s",time,space);
	} else {
	    snprintf(unit,len,"%s/%s",space,time);
	}
	sf_putstring(scan,"unit2",unit);
    }

    if (NULL != sf_getstring("grad")) {
	grd = sf_input("grad");

	bb = sf_floatalloc2(nt,nv);
	sf_floatread(bb[0],nt*nv,grd);

	sf_fileclose(grd);
    } else {
	bb = NULL;
    }

    stack =  sf_floatalloc3(nt,nv,ns);
    stack2 = ('p' != type[0])? sf_floatalloc3(nt,nv,ns): NULL;
    stackh = trend? sf_floatalloc3(nt,nv,ns): NULL;
    stack2h = ('w' == type[0])? sf_floatalloc3(nt,nv,ns): NULL;

    if (!sf_getint("extend",&nw)) nw=4;
    /* trace extension */

    if (!sf_getint("mute",&mute)) mute=12;
    /* mute zone */

    if (!sf_getfloat("str",&str)) str=0.5;
    /* maximum stretch allowed */

    trace = sf_floatalloc(nt);
    nmo = fint1_init(nw,nt,mute);

    for (ix=0; ix < nx; ix++) {
	sf_warning("cmp %d of %d;",ix+1,nx);

	for (it=0; it < nt*nv*ns; it++) {
	    stack[0][0][it] = 0.;
	    if (ratio) stack2[0][0][it] = 0.;
	    if (trend) stackh[0][0][it] = 0.;
	}

	if (NULL != offset) sf_floatread(hh,nh,offset);
	if (NULL != msk) sf_intread(mask,nh,msk);

	if (trend) sh = sh2 = 0.;

	for (ih=0; ih < nh; ih++) {
	    sf_floatread(trace,nt,cmp); 
	    if (NULL != msk && 0==mask[ih]) continue;

	    h = (NULL != offset)? hh[ih]: 
		h0 + ih * dh + (dh/CDPtype)*(ix%CDPtype);
	    if (half) h *= 2.;

	    if (trend) {
		sh  += h;    /* sf  */
		sh2 += h*h;  /* sf2 */
	    }

	    for (it=0; it < nt; it++) {
		trace[it] /= nt*nh;
	    }
	    fint1_set(nmo,trace);

	    for (is=0; is < ns; is++) {
		s = 1.0 + is*ds;

		for (iv=0; iv < nv; iv++) {
		    v = v0 + iv * dv;
		    v = slow? h*v: h/v;

		    stretch(nmo,nmofunc,nt,dt,t0,nt,dt,t0,trace,str);

		    for (it=0; it < nt; it++) {
			amp = weight? fabsf(v)*trace[it]: trace[it];
			if (NULL != bb) amp *= (1.0-bb[iv][it]*h);
			
			switch(type[0]) {
			    case 'd':
				if (ih > 0) {
				    amp2 = amp - stack2[is][iv][it];
				    stack[is][iv][it] += amp2*amp2;
				}
				stack2[is][iv][it] = amp;
				break;
			    case 's':
				stack2[is][iv][it] += amp*amp;
				stack[is][iv][it] += amp;
				break;
			    case 'a': 
				stackh[is][iv][it] += amp*h;    /* saf */
				stack2[is][iv][it] += amp*amp;  /* sa2 */
				stack[is][iv][it] += amp;       /* sa1 */
				break;
			    case 'w':
				stackh[is][iv][it] += amp*h;       /* saf */
				stack2h[is][iv][it] += amp*amp*h;  /* sfa2 */
				stack2[is][iv][it] += amp*amp;     /* sa2 */
				stack[is][iv][it] += amp;          /* sa1 */
				break;
			    case 'p':
			    default:
				stack[is][iv][it] += amp;
				break;				
			} 
		    } /* t */
		} /* v */
	    } /* s */
	} /* h */
	
	if (ratio) {
	    for (is=0; is < ns; is++) {
		for (iv=0; iv < nv; iv++) {
		    for (it=0; it < nt; it++) {
			ib = it-nb;
			ie = it+nb+1;
			if (ib < 0) ib=0;
			if (ie > nt) ie=nt;
			num = 0.;
			den = 0.;
			for (i=ib; i < ie; i++) {
			    switch(type[0]) {
				case 'a':
				    /* (N*saf^2 + sa1^2*sf2 - 2*sa1*saf*sf)/((N*sf2 - sf^2)*sa2) */

				    num += nh*stackh[is][iv][i]*stackh[is][iv][i] + 
					sh2*stack[is][iv][i]*stack[is][iv][i] - 
					2.*sh*stack[is][iv][i]*stackh[is][iv][i];
				    den += stack2[is][iv][i];
				    break;
				case 'w':
				    /* 4*(sa1*sfa2 - sa2*saf)*(N*saf - sa1*sf)/(N*sfa2 - sa2*sf)^2 */

				    num += 
					(stack[is][iv][i]*stack2h[is][iv][i]-
					 stack2[is][iv][i]*stackh[is][iv][i])*
					(nh*stackh[is][iv][i]-stack[is][iv][i]*sh);
				    den += 
					(nh*stack2h[is][iv][i]-stack2[is][iv][i]*sh)*
					(nh*stack2h[is][iv][i]-stack2[is][iv][i]*sh);
				    break;
				case 's':
				default:
				    num += stack[is][iv][i]*stack[is][iv][i];
				den += stack2[is][iv][i];
				break;
			    }
			}
			    
			switch(type[0]) {
			    case 'a':
				den *= (nh*sh2-sh*sh);
				break;
			    case 'w':
				num *= 4.0f;
				break;
			    case 's':
				den *= nh;
				break;
			}

			trace[it] = (den > 0.)? num/den: 0.;
		    }
		    sf_floatwrite(trace,nt,scan);
		} /* v */
	    } /* s */
	} else {
	    sf_floatwrite (stack[0][0],nt*nv*ns,scan);
	}
    } /* x */
    sf_warning(".");
    
    exit(0);
}
Exemplo n.º 15
0
int main(int argc, char* argv[])
{
    const char *type;
    int np, ip, nc, i2, n2, nc2;
    float dp, p0, p;
    float *c, *t, **dt;
    sf_file in, coef, fit, out;

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

    if (!sf_histint(in,"n1",&np)) sf_error("No n1= in input");
    if (!sf_histfloat(in,"d1",&dp)) sf_error("No d1= in input");
    if (!sf_histfloat(in,"o1",&p0)) p0=0.;
    n2 = sf_leftsize(in,1);

    if (NULL == (type=sf_getstring("type"))) type="iso";
    /* Type of approximation (iso,vti) */

    nc2 = (type[0]=='i')? 2:3;

    if (!sf_histint(coef,"n1",&nc) || nc != nc2) 
	sf_error("Need n1=%d in coef",nc2);

    c = sf_floatalloc(nc);

    sf_putint(fit,"n2",nc);
    sf_shiftdim(in, fit, 2);

    t = sf_floatalloc(np);
    dt = sf_floatalloc2(np,nc);

    for (i2=0; i2 < n2; i2++) {
	sf_floatread(c,nc,coef);

	for (ip=0; ip < np; ip++) {
	    p = p0 + ip*dp;
	    p *= p;
	    
	    switch (type[0]) {
		case 'i': 
		    dt[0][ip] = 1;
		    dt[1][ip] = -p;
		    t[ip] = c[0]-p*c[1];
		    break;
		case 'v':
		    dt[0][ip] = (1-p*c[1])/(1-p*c[2]);
		    t[ip] = c[0]*dt[0][ip];
		    dt[1][ip] = -p*c[0]/(1-p*c[2]);
		    dt[2][ip] = p*t[ip]/(1-p*c[2]);
		    break;
		default:
		    sf_error("Unknown type \"%s\"",type); 
		    break;
	    }
	}

	sf_floatwrite(t,np,out);
	sf_floatwrite(dt[0],np*nc,fit);
    }

    exit(0);
}
Exemplo n.º 16
0
int main(int argc, char* argv[])
{
    int i1, n1, i2, n2, i3, n3, ip, np, it;
    float **dat=NULL, *trace=NULL, dp, p0, p, t;
    vint1 str;
    sf_file inp=NULL, out=NULL;

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

    if (!sf_histint(inp,"n1",&n1)) sf_error("No n1= in input");
    if (!sf_histint(inp,"n2",&n2) || n2 < 2) sf_error("No n2= in input");
    n3 = sf_leftsize(inp,2);

    if (!sf_getint("np",&np)) sf_error("Need np=");
    /* number of slopes */
    if (!sf_getfloat("dp",&dp)) sf_error("Need dp=");
    /* slope sampling */
    if (!sf_getfloat("p0",&p0)) sf_error("Need p0=");
    /* first slope */

    sf_putint(out,"n3",np);
    sf_putfloat(out,"d3",dp);
    sf_putfloat(out,"o3",p0);

    sf_shiftdim(inp,out,3);

    dat = sf_floatalloc2(n1,n2);
    trace = sf_floatalloc(n2);
    trace[n2-1] = 0.;

    str = vint1_init (4,n1,n2-1);

    for (i3=0; i3 < n3; i3++) {
	sf_floatread(dat[0],n1*n2,inp);
	vint1_set(str,dat+1);

	for (ip=0; ip < np; ip++) {
	    p = p0 + ip*dp;

	    for (i1=0; i1 < n1; i1++) {
		t = i1+p;
		it = floorf(t);

		if (it < -1 || it > n1) {
		    for (i2=0; i2 < n2-1; i2++) {
			trace[i2]=0.;
		    }
		} else {
		    vint1_apply(str,it,t-it,false,trace);
		}

		for (i2=0; i2 < n2; i2++) {
		    dat[i2][i1] = trace[i2];
		}
	    }
	    sf_floatwrite(dat[0],n1*n2,out);
	}
    }

    exit(0);
}
Exemplo n.º 17
0
int main(int argc, char* argv[])
{
  int nx, ny, nt, npara, nc;
  float x, y, dx, dy, dt, x0, y0, tini, t0;
  float **t0sq,**time, *coeff, ***dtime; 
  float w1,w2,w3,A1,A2,A3,A4,A5,B1,B2,B3,C1,C2,C3,C4,C5,A,B,C;
  int i,j,k,test;
  int count = 0;
  bool verb;

  sf_file inp, out, fit ,inicoef;

  sf_init(argc, argv);
    inp = sf_input("in");
    inicoef = sf_input("coef");
    out = sf_output("out");
    fit = sf_output("fit");

    /* input vector t0^2' */
    if (!sf_histint(inp,"n1",&nx)) sf_error("No n1=");
    if (!sf_histint(inp,"n2",&ny)) sf_error("No n2=");
    if (!sf_histint(inp,"n3",&nt)) sf_error("No n3=");
    if (!sf_histfloat(inp,"d1",&dx)) sf_error("No d1=");
    if (!sf_histfloat(inp,"d2",&dy)) sf_error("No d2=");
    if (!sf_histfloat(inp,"d3",&dt)) sf_error("No d3=");
    if (!sf_histfloat(inp,"o1",&x0)) sf_error("No o1=");
    if (!sf_histfloat(inp,"o2",&y0)) sf_error("No o2=");
    if (!sf_histfloat(inp,"o3",&tini)) sf_error("No o2=");

    /*Number of fitting parameters*/
    npara=16;
    
    /*Verbal flag*/
    if (!sf_getbool("verb",&verb)) verb=false;
    
    /*Memory allocation*/
    coeff = sf_floatalloc(npara);
    t0sq = sf_floatalloc2(nx,ny);
    time = sf_floatalloc2(nx,ny);
    dtime = sf_floatalloc3(nx,ny,npara);
    
    /*Output dimension*/
    if (!sf_histint(inicoef,"n1",&nc) || nc != npara) 
	sf_error("Need n1=%d in inicoef",npara);
    
    /*Shift the third dimension to 4th to insert coefficients*/
     sf_shiftdim(inp, fit, 3);
     sf_putint(fit,"n3",npara);
     sf_putint(fit,"d3",1);
     sf_putint(fit,"o3",0);
    
    /* Loop over time slices */
      for(k=0; k < nt; k++) {
        /*Read intial parameters*/
        sf_floatread(coeff,npara,inicoef);
        w1 = coeff[0];w2 = coeff[1];w3 = coeff[2];
        A1 = coeff[3];A2 = coeff[4];A3 = coeff[5];A4 = coeff[6];A5 = coeff[7];
        B1 = coeff[8];B2 = coeff[9];B3 = coeff[10];
        C1 = coeff[11];C2 = coeff[12];C3 = coeff[13];C4 = coeff[14];C5 = coeff[15];
        sf_floatread(t0sq[0],nx*ny,inp);
        

        /* Loops for each x and y*/
            for(j=0;j<ny;j++){
                y = y0 + j*dy;
                
                for(i=0;i<nx;i++){
                    x = x0 + i*dx;
                    t0 = sqrt(t0sq[j][i]);
                    
                    /* Avoid dividing by zero*/
                    if (x!=0 || y!=0 || t0!=0) {
                    
                    A = A1*pow(x,4) + A2*pow(x,3)*y + A3*pow(x,2)*pow(y,2) + A4*x*pow(y,3) + A5*pow(y,4);
                    B = B1*pow(x,2) + B2*x*y + B3*pow(y,2);
                    C = C1*pow(x,4) + C2*pow(x,3)*y + C3*pow(x,2)*pow(y,2) + C4*x*pow(y,3) + C5*pow(y,4);
                    
                    /* Compute traveltime (t^2)*/
                    time[j][i] = pow(t0,2) + w1*pow(x,2) + w2*x*y + w3*pow(y,2) + A/(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B));
                    /* Compute Derivatives */
                    dtime[0][j][i] = pow(x,2); // Wx
                    dtime[1][j][i] = x*y; // Wxy
                    dtime[2][j][i] = pow(y,2); //Wy

                    dtime[3][j][i] = pow(x,4)/(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B)); // A1

                    dtime[4][j][i] = (pow(x,3)*y)/(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B)); // A2

                    dtime[5][j][i] = (pow(x,2)*pow(y,2))/(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B)); // A3

                    dtime[6][j][i] = (x*pow(y,3))/(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B)); // A4

                    dtime[7][j][i] = pow(y,4)/(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B)); // A5

                    dtime[8][j][i] = (-A*x*x*(1+pow(t0,2)/(sqrt(pow(t0,4) + C + 2*pow(t0,2)*B))))/pow(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B),2); // B1

                    dtime[9][j][i] = (-A*x*y*(1+pow(t0,2)/(sqrt(pow(t0,4) + C + 2*pow(t0,2)*B))))/pow(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B),2); // B2

                    dtime[10][j][i] = (-A*y*y*(1+pow(t0,2)/(sqrt(pow(t0,4) + C + 2*pow(t0,2)*B))))/pow(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B),2); // B3
                    
                    dtime[11][j][i] = (-pow(x,4)*A)/(2*sqrt(pow(t0,4) + C + 2*pow(t0,2)*B)*pow(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B),2)); // C1

                    dtime[12][j][i] = (-pow(x,3)*y*A)/(2*sqrt(pow(t0,4) + C + 2*pow(t0,2)*B)*pow(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B),2)); // C2

                    dtime[13][j][i] = (-pow(x,2)*pow(y,2)*A)/(2*sqrt(pow(t0,4) + C + 2*pow(t0,2)*B)*pow(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B),2)); // C3

                    dtime[14][j][i] = (-x*pow(y,3)*A)/(2*sqrt(pow(t0,4) + C + 2*pow(t0,2)*B)*pow(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B),2)); // C4

                    dtime[15][j][i] = (-pow(y,4)*A)/(2*sqrt(pow(t0,4) + C + 2*pow(t0,2)*B)*pow(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B),2)); // C5
                    
                    for (test=0;test<16;test++) {
                    
                            if(verb && isnan(dtime[test][j][i]) != 0) {
                                sf_warning("The sqrt is NaN at dtime %d k %d j %d i %d",test,k+1,j,i);
                                sf_warning("x %f y %f B %f %f %f C %f %f %f %f %f",x,y,B1,B2,B3,C1,C2,C3,C4,C5);
                                sf_warning("pow(t0,4) + C + 2*pow(t0,2)*B : %f \n",pow(t0,4) + C + 2*pow(t0,2)*B);
                            }
                    }
                    
                    } else {
                    
                    time[j][i] = 0;
                    dtime[0][j][i] = 0;
                    dtime[1][j][i] = 0;
                    dtime[2][j][i] = 0;
                    dtime[3][j][i] = 0;
                    dtime[4][j][i] = 0;
                    dtime[5][j][i] = 0;
                    dtime[6][j][i] = 0;
                    dtime[7][j][i] = 0;
                    dtime[8][j][i] = 0;
                    dtime[9][j][i] = 0;
                    dtime[10][j][i] = 0;
                    dtime[11][j][i] = 0;
                    dtime[12][j][i] = 0;
                    dtime[13][j][i] = 0;
                    dtime[14][j][i] = 0;
                    dtime[15][j][i] = 0;
                    
                    }
                    
                    count++;
    /*                sf_warning("%d of %d surface locations ;",count,nx*ny);*/
            }
        }
        
        sf_warning(" Time step: %d; of %d;",k+1,nt);
        sf_floatwrite(time[0],nx*ny,out);
        sf_floatwrite(dtime[0][0],nx*ny*npara,fit);
    
    }

  exit(0);
}
Exemplo n.º 18
0
int main(int argc, char *argv[])
{
    int nw, n1, n2, n4, iw, i1, i2, i4, s1, x1, s2, x2, m, fold;
    int jumpo, jumps, newn1, newn2, tn;
    float d1, d2, newd1, newd2;
    bool verb, stack, both;

    sf_complex *dd, *ref=NULL, *mm=NULL, *mtemp=NULL;
    sf_file in, out, mul=NULL;

    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_histint(in,"n2",&n2)) sf_error("No n2= in input");
    if (!sf_histint(in,"n3",&nw)) sf_error("No n3= in input");

    if (!sf_histfloat(in,"d1",&d1)) sf_error("No d1= in input");
    if (!sf_histfloat(in,"d2",&d2)) sf_error("No d2= in input");
    
    if (d1!=d2) sf_error("Need d1==d2");

    n4 = sf_leftsize(in,3);
    fold = 0;

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

    if (!sf_getbool("stack",&stack)) stack=true;
    /* stack flag, if y, no common pseudoprimary gather */

    if (!sf_getbool("both",&both)) both=false;
    /* receiver flag, if y, receiver with both sides */

    if (!stack) {
	if (!sf_getint("jumpo",&jumpo)) jumpo=1;
	/* jump in offset dimension, only for stack=n */
	
	if (!sf_getint("jumps",&jumps)) jumps=1;
	/* jump in shot dimension, only for stack=n  */
    }
    newn1 = n1;
    newn2 = n2;
    if (!stack) {
	if (!both) {
	    sf_putint(out,"n1",(2*n1-1));
	    sf_putfloat(out,"d1",d1);
	    sf_putfloat(out,"o1",(1-n1)*d1);
	} else {
	    sf_putint(out,"n1",n1);
	    sf_putfloat(out,"d1",d1);
	    sf_putfloat(out,"o1",(-1*n1/2)*d1);
	}
	(void) sf_shiftdim(in, out, 1);
	if (n1%jumpo == 0) {
	    newn1 = n1 / jumpo;
	} else {
	    newn1 = n1 / jumpo +1;
	}
	if (n2%jumps == 0) {
	    newn2 = n2 / jumps;
	} else {
	    newn2 = n2 / jumps +1;
	}
	newd1 = (float) (d1 * jumpo);
	newd2 = (float) (d2 * jumps);
	sf_putint(out,"n2",newn1);
	sf_putfloat(out,"d2",newd1);
	sf_putint(out,"n3",newn2);
	sf_putfloat(out,"d3",newd2);
    }

    if (NULL != sf_getstring ("mul")) {
	mul = sf_input("mul");
	ref = sf_complexalloc(n1*n2);
    } else {
	mul = NULL;
    }	
    
    dd = sf_complexalloc(n1*n2);

    if (stack) {
	mm = sf_complexalloc(n1*n2);
    } else {
	if (!both) {
	    mm = sf_complexalloc((2*n1-1)*n1*n2);
	    mtemp = sf_complexalloc((2*n1-1)*newn1*newn2);
	} else {
	    mm = sf_complexalloc(n1*n1*n2);
	    mtemp = sf_complexalloc(n1*newn1*newn2);
	}
    }

    /* loop over n4 */
    for (i4=0; i4 < n4; i4++) {
	if (verb) sf_warning("slice %d of %d",i4+1,n4);
	for (iw=0; iw < nw; iw++) { /* loop over frequency */
	    if (verb) sf_warning("frequency %d of %d;",iw+1,nw);
	    sf_complexread(dd,n1*n2,in);
	    if (NULL != mul) {
		sf_complexread(ref,n1*n2,mul);
	    }
	    if (!both) {
		for (i2=0; i2 < n2; i2++) {
		    for (i1=0; i1 < n1; i1++) {
			mm[i2*n1+i1] = sf_cmplx(0.,0.);
			fold = 0;
			for (m=(-1*n1+1); m < n1; m++) {
			    if (m < 0) {
				x1 = -1*m;
				s1 = i2 + m;
				x2 = i1 - m;
				s2 = m + i2;
			    } else if ((i1-m) < 0) {
				x1 = m;
				s1 = i2;
				x2 = m - i1;
				s2 = i2 + i1;
			    } else {
				x1 = m;
				s1 = i2;
				x2 = i1 - m;
				s2 = m + i2;
			    }
			    if (stack) {
				if (s1 >= 0 && s1 < n2 && x1 >= 0 && x1 < n1 && 
				    s2 >= 0 && s2 < n2 && x2 >= 0 && x2 < n1 ) {
#ifdef SF_HAS_COMPLEX_H
				    if(NULL != mul) {
					mm[i2*n1+i1] += conjf(dd[s1*n1+x1])*ref[s2*n1+x2];
				    } else {
					mm[i2*n1+i1] += conjf(dd[s1*n1+x1])*dd[s2*n1+x2];
				    }
#else
				    if(NULL != mul) {
					mm[i2*n1+i1] = sf_cadd(mm[i2*n1+i1],sf_cmul(sf_conjf(dd[s1*n1+x1]),ref[s2*n1+x2]));
				    } else {
					mm[i2*n1+i1] = sf_cadd(mm[i2*n1+i1],sf_cmul(sf_conjf(dd[s1*n1+x1]),dd[s2*n1+x2]));
				    }
#endif
				} else {
				    mm[i2*n1+i1] = sf_cmplx(0.,0.);
				}
				if (0.0 != cabsf(mm[i2*n1+i1])) fold++;	
			    } else {
				if (s1 >= 0 && s1 < n2 && x1 >= 0 && x1 < n1 && 
				    s2 >= 0 && s2 < n2 && x2 >= 0 && x2 < n1 ) {
#ifdef SF_HAS_COMPLEX_H
				    if(NULL != mul) {
					mm[i2*(2*n1-1)*n1+i1*(2*n1-1)+m+n1-1] = dd[s1*n1+x1]*ref[s2*n1+x2];
				    } else {
					mm[i2*(2*n1-1)*n1+i1*(2*n1-1)+m+n1-1] = dd[s1*n1+x1]*dd[s2*n1+x2];
				    }
#else
				    if(NULL != mul) {
					mm[i2*(2*n1-1)*n1+i1*(2*n1-1)+m+n1-1] = sf_cmul(dd[s1*n1+x1],ref[s2*n1+x2]);
				    } else {
					mm[i2*(2*n1-1)*n1+i1*(2*n1-1)+m+n1-1] = sf_cmul(dd[s1*n1+x1],dd[s2*n1+x2]);
				    }
#endif
				} else {
				    mm[i2*(2*n1-1)*n1+i1*(2*n1-1)+m+n1-1] = sf_cmplx(0.,0.);
				}
			    }
			}

			if (stack) {
#ifdef SF_HAS_COMPLEX_H
			    mm[i2*n1+i1] = mm[i2*n1+i1]/(fold+SF_EPS);
#else
			    mm[i2*n1+i1] = sf_crmul(mm[i2*n1+i1],1.0/(fold+SF_EPS));
#endif
			}

		    }
		}
		
		if (!stack) {
		    tn = 0;
		    for (i2=0; i2 < n2; i2++) {
			for (i1=0; i1 < n1; i1++) {
			    if ((i2 % jumps == 0) && (i1 % jumpo == 0)) {
				for (m=(-1*n1+1); m < n1; m++) {
				    mtemp[tn] = mm[i2*(2*n1-1)*n1+i1*(2*n1-1)+m+n1-1];
				    tn ++;
				}
			    }
			}
		    }
		    if (tn!=(2*n1-1)*newn1*newn2) sf_error("jump error!");		    
		    sf_complexwrite(mtemp,tn,out);
		} else {
		    sf_complexwrite(mm,n1*n2,out);
		}
	    } else {
		for (i2=0; i2 < n2; i2++) {
		    for (i1=0; i1 < n1; i1++) {
			mm[i2*n1+i1] = sf_cmplx(0.,0.);
			fold = 0;
			for (m=0; m < n1; m++) {
			    x1 = m;
			    s1 = i2;
			    x2 = i1 - m + n1/2;
			    s2 = m + i2 - n1/2;
			    if (stack) {
				if (s1 >= 0 && s1 < n2 && x1 >= 0 && x1 < n1 && 
				    s2 >= 0 && s2 < n2 && x2 >= 0 && x2 < n1 ) {
#ifdef SF_HAS_COMPLEX_H
				    if(NULL != mul) {			
					mm[i2*n1+i1] += dd[s1*n1+x1]*ref[s2*n1+x2];
				    } else {
					mm[i2*n1+i1] += dd[s1*n1+x1]*dd[s2*n1+x2];
				    }
#else
				    if(NULL != mul) {	
					mm[i2*n1+i1] = sf_cadd(mm[i2*n1+i1],sf_cmul(dd[s1*n1+x1],ref[s2*n1+x2]));
				    } else {
					mm[i2*n1+i1] = sf_cadd(mm[i2*n1+i1],sf_cmul(dd[s1*n1+x1],dd[s2*n1+x2]));
				    }
#endif
				} else {
				    mm[i2*n1+i1] = sf_cmplx(0.,0.);
				}
				if (0.0 != cabsf(mm[i2*n1+i1])) fold++;				
			    } else {
				if (s1 >= 0 && s1 < n2 && x1 >= 0 && x1 < n1 && 
				    s2 >= 0 && s2 < n2 && x2 >= 0 && x2 < n1 ) {
#ifdef SF_HAS_COMPLEX_H
				    if(NULL != mul) {			
					mm[i2*n1*n1+i1*n1+m] = dd[s1*n1+x1]*ref[s2*n1+x2];
				    } else {
					mm[i2*n1*n1+i1*n1+m] = dd[s1*n1+x1]*dd[s2*n1+x2];
				    }
#else
				    if(NULL != mul) {	
					mm[i2*n1*n1+i1*n1+m] = sf_cmul(dd[s1*n1+x1],ref[s2*n1+x2]);
				    } else {
					mm[i2*n1*n1+i1*n1+m] = sf_cmul(dd[s1*n1+x1],dd[s2*n1+x2]);
				    }
#endif
				} else {
				    mm[i2*n1*n1+i1*n1+m] = sf_cmplx(0.,0.);
				}
			    }
			}
			if (stack) {
#ifdef SF_HAS_COMPLEX_H
			    mm[i2*n1+i1] = mm[i2*n1+i1]/(fold+SF_EPS);
#else
			    mm[i2*n1+i1] = sf_crmul(mm[i2*n1+i1],1.0/(fold+SF_EPS));
#endif
			}

		    }
		}
		if (!stack) {
		    tn = 0;
		    for (i2=0; i2 < n2; i2++) {
			for (i1=0; i1 < n1; i1++) {
			    if (i2 % jumps == 0 && i1 % jumpo == 0) {
				for (m=0; m < n1; m++) {
				    mtemp[tn] = mm[i2*n1*n1+i1*n1+m];
				    tn ++;
				}
			    }
			}
		    }	
		    if (tn!=n1*newn1*newn2) sf_error("jump error!");
		    sf_complexwrite(mtemp,tn,out);
		} else {
		    sf_complexwrite(mm,n1*n2,out);
		}
	    }		
	}   
	if (verb) sf_warning(".");
    
    }

    exit(0);
}
Exemplo n.º 19
0
int main(int argc, char **argv)
{
    int n1, n2, ninf, i1, i2, i, *inter2;
    char *label, *unit;
    float o1, d1, o2, d2, x, z;
    float *v0, *dvdx, *dvdz, *x0, *z0, *trace, **inter;
    sf_file model, surface;

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

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

    if (!sf_histint(surface,"n1",&n2))   sf_error("No n1= in input");
    if (!sf_histfloat(surface,"d1",&d2)) sf_error("No d1= in input");
    if (!sf_histfloat(surface,"o1",&o2)) o2=0.;

    sf_shiftdim(surface, model, 1);
    sf_putint(model,"n3",1);

    if (!sf_histint(surface,"n2",&ninf)) ninf=1; 

    if (!sf_getint("n1",&n1)) sf_error("Need n1=");
    /* Number of samples on the depth axis */
    if (!sf_getfloat("d1",&d1)) sf_error("Need d1=");
    /* Sampling of the depth axis */
    if (!sf_getfloat("o1",&o1)) o1=0.;
    /* Origin of the depth axis */

    sf_putint(model,"n1",n1);
    sf_putfloat(model,"d1",d1);
    sf_putfloat(model,"o1",o1);

    if (NULL == (label = sf_getstring("label1"))) label="Depth";
    /* depth axis label */
    sf_putstring(model,"label1",label);

    if (NULL != (unit = sf_getstring("unit1"))) /* depth axis unit */
	sf_putstring(model,"unit1",unit);

    inter = sf_floatalloc2(n2,ninf);
    inter2 = sf_intalloc(ninf);
    sf_floatread(inter[0],n2*ninf,surface);

    ninf++; /* more layers than interfaces */
    v0 = sf_floatalloc(ninf);
    x0 = sf_floatalloc(ninf);
    z0 = sf_floatalloc(ninf);
    dvdx = sf_floatalloc(ninf);
    dvdz = sf_floatalloc(ninf);

    /* Input layer velocities and velocity derivatives */
    if (!sf_getfloats("x0",x0,ninf)) 
	for(i=0;i< ninf;i++) x0[i] = 0.;
    if (!sf_getfloats("z0",z0,ninf))
	for(i=0;i< ninf;i++) z0[i] = 0.;
    if (!sf_getfloats("v00",v0,ninf))
	for(i=0;i< ninf;i++) v0[i] = 1500.+ 500*i;
    if (!sf_getfloats("dvdx",dvdx,ninf)) 
	for(i=0;i< ninf;i++) dvdx[i] = 0.;
    if (!sf_getfloats("dvdz",dvdz,ninf)) 
	for(i=0;i< ninf;i++) dvdz[i] = 0.;

    trace = sf_floatalloc(n1);

    /* compute linear velocity */
    for(i2=0; i2 < n2; i2++) { 
	x = o2+i2*d2;
	for (i=0; i < ninf-1; i++) {
	    inter2[i] = floorf(0.5+(inter[i][i2]-o1)/d1);
	}
	for(i1=0; i1 < n1; i1++) {
	    z = o1+i1*d1;
	    for (i=0; i < ninf-1; i++) {
		if (i1 < inter2[i]) break;
	    }
	    trace[i1] = v0[i] + (x-x0[i])*dvdx[i] + (z-z0[i])*dvdz[i];
	}
	sf_floatwrite(trace,n1,model);
    }

    exit(0);
}
Exemplo n.º 20
0
int main (int argc, char* argv[]) {
    int nz, nx, na, nc;
    int iz, ix, ia;
    float dz, oz, dx, ox, da, oa, a;
    float savg = 0.0, smin = SF_HUGE, smax = -SF_HUGE;
    float corr_nterm = 0.0, corr = 0.0, new_savg = 0.0;
    float **s;
    bool verb;
    sf_file spdom, vspline = NULL, out;
    sf_esc_slowness2 esc_slow;

    sf_init (argc, argv);

    if (!sf_stdin ()) {
        spdom = NULL;
    } else {
        spdom = sf_input ("in");
        /* Spatial (z,x) domain */
    }

    out = sf_output ("out");
    /* Slowness values */

    /* Spatial dimensions */
    if (spdom) {
        if (!sf_histint (spdom, "n1", &nz)) sf_error ("No n1= in input");
        if (!sf_histint (spdom, "n2", &nx)) sf_error ("No n2= in input");
        if (!sf_histfloat (spdom, "d1", &dz)) sf_error ("No d1= in input");
        if (!sf_histfloat (spdom, "o1", &oz)) sf_error ("No o1= in input");
        if (!sf_histfloat (spdom, "d2", &dx)) sf_error ("No d2= in input");
        if (!sf_histfloat (spdom, "o2", &ox)) sf_error ("No o2= in input");
    }
    if (!sf_getint ("nz", &nz) && !spdom) sf_error ("Need nz=");
    /* Number of samples in z axis */
    if (!sf_getfloat ("oz", &oz) && !spdom) sf_error ("Need oz=");
    /* Beginning of z axis */
    if (!sf_getfloat ("dz", &dz) && !spdom) sf_error ("Need oz=");
    /* Sampling of z axis */
    if (!sf_getint ("nx", &nx) && !spdom) sf_error ("Need nx=");
    /* Number of samples in x axis */
    if (!sf_getfloat ("ox", &ox) && !spdom) sf_error ("Need ox=");
    /* Beginning of x axis */
    if (!sf_getfloat ("dx", &dx) && !spdom) sf_error ("Need ox=");
    /* Sampling of x axis */

    if (!sf_getint ("na", &na)) na = 360;
    /* Number of phase angles */

    da = 2.0*SF_PI/(float)na;
    oa = -SF_PI + 0.5*da;

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

    if (spdom)
        sf_shiftdim (spdom, out, 1);

    /* Set up output */
    sf_putint (out, "n1", 4);
    sf_putfloat (out, "o1", 0.0);
    sf_putfloat (out, "d1", 1.0);
    sf_putstring (out, "label1", "Slowness components");
    sf_putstring (out, "unit1", "");
    sf_putint (out, "n2", nz);
    sf_putfloat (out, "o2", oz);
    sf_putfloat (out, "d2", dz);
    if (!spdom) {
        sf_putstring (out, "label2", "Depth");
        sf_putstring (out, "unit2", "");
    }
    sf_putint (out, "n3", nx);
    sf_putfloat (out, "o3", ox);
    sf_putfloat (out, "d3", dx);
    if (!spdom) {
        sf_putstring (out, "label3", "Lateral");
        sf_putstring (out, "unit3", "");
    }
    sf_putint (out, "n4", na);
    sf_putfloat (out, "d4", da*180.0/SF_PI);
    sf_putfloat (out, "o4", oa*180.0/SF_PI);
    sf_putstring (out, "label4", "Angle");
    sf_putstring (out, "unit4", "Degrees");

    if (!sf_getstring ("vspl")) sf_error ("Need vspl=");
    /* Spline coefficients for velocity model */
    vspline = sf_input ("vspl");

    if (!sf_histint (vspline, "Nc", &nc)) sf_error ("No Nc= in vspl");

    /* Slowness components module [(an)isotropic] */
    esc_slow = sf_esc_slowness2_init (vspline, verb);

    s = sf_floatalloc2 (4, nz);

    for (ia = 0; ia < na; ia++) {
        a = oa + ia*da;
        if (verb)
            sf_warning ("Computing angle plane %g;", a*180.0/SF_PI);
        for (ix = 0; ix < nx; ix++) {
            for (iz = 0; iz < nz; iz++) {
                 sf_esc_slowness2_get_components (esc_slow,
                                                  oz + iz*dz, ox + ix*dx, a,
                                                  &s[iz][0], &s[iz][3],
                                                  &s[iz][1], &s[iz][2]);
                if (s[iz][0] < smin)
                    smin = s[iz][0];
                if (s[iz][0] > smax)
                    smax = s[iz][0];
                /* Kahan summation algorithm to avoid roundoff errors
                   while accumulating the total sum */
                corr_nterm = s[iz][0] - corr;
                new_savg = savg + corr_nterm;
                corr = (new_savg - savg) - corr_nterm;
                savg = new_savg;
            }
            sf_floatwrite (&s[0][0], 4*nz, out);
        }
    }
    if (verb) {
        sf_warning (".");
        sf_warning ("Average velocity: %g [min=%g, max=%g]",
                    1.0/(savg/(float)((size_t)na*(size_t)nx*(size_t)nz)),
                    1.0/smax, 1.0/smin);
    }

    sf_esc_slowness2_close (esc_slow);

    free (s[0]);
    free (s);

    sf_fileclose (vspline);

    return 0;
}
Exemplo n.º 21
0
int main (int argc, char* argv[])
{
    int n1, n2, xn, i, j, k, m, nr;
    float o1, d1, xd, xo, *vel, *dip, t, t1,tt, x2,*ani;
    float t0=0., tp=0., slope0=0., slopep=0., x=0., x1=0., v0=0., *data=NULL;
    bool abs, half, inner, hyper, mute;
    sf_file in, out, heterog;
  
    sf_init (argc, argv);

    in = sf_input("in");
    out = sf_output("out");
    
   
    heterog = sf_input("heterog"); 
    /* heterogeneity */
   
    if (!sf_histint(heterog,"n1",&nr)) sf_error("No n1= in heterog");
  
    if (!sf_histfloat(in,"o1",&o1)) sf_error("No o1= in input");
    if (!sf_histfloat(in,"d1",&d1)) sf_error("No d1= in input");
    if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input");
    n2 = sf_leftsize(in,1);

    if (!sf_getint("n",&xn)) xn = 32;
    /* offset number */
    if (!sf_getfloat("d",&xd)) xd = 12.5;
    /* offset interval */
    if (!sf_getfloat("o",&xo)) xo = 0.;
    /* offset origin */
    
    if (!sf_getbool("mute",&mute)) mute=false;
    /* if y, use mutter */

    if (!sf_getbool("half",&half)) half=false;
    /* if y, half-offset instead of full offset */

    if (half) {
	xd *= 2.;
	xo *= 2.;
    }
   
    vel = sf_floatalloc(n1);
    dip = sf_floatalloc(n1*xn);
    
    sf_shiftdim(in, out, 1);
    sf_putint(out,"n2",xn);
    sf_putfloat(out,"d2",xd);
    sf_putfloat(out,"o2",xo);

    if (mute) {
	
	if (!sf_getfloat("tp",&tp)) tp=0.150; 
        /* end time (available when mute=y) */

	if (!sf_getfloat("t0",&t0)) t0=0.; 
	/* starting time (available when mute=y) */

	if (!sf_getfloat("v0",&v0)) v0=10000;  
        /* velocity (available when mute=y) */
	
	if (!sf_getfloat("x0",&x1)) x1=0.;
	/* starting space (available when mute=y) */
	
	if (!sf_getbool("abs",&abs)) abs=true;
	/* if y, use absolute value |x-x0| (available when mute=y) */
	
	if (!sf_getbool("inner",&inner)) inner=false;
	/* if y, do inner muter (available when mute=y) */
	
	if (!sf_getbool("hyper",&hyper)) hyper=false;
	/* if y, do hyperbolic mute (available when mute=y) */
	
	slope0=1./v0;
	slopep=slope0;
	
	if (hyper) {
	    slope0 *= slope0;
	    slopep *= slopep;
	}
	
	data = sf_floatalloc(n1);
	mutter_init(n1,o1-t0,d1,abs,inner,hyper);
    }   
   
    for (k=0; k < n2; k++) {
	sf_warning("slice %d of %d;",k+1,n2);
	sf_floatread(vel,n1,in);

	ani = sf_floatalloc(nr);
	sf_floatread(ani,nr,heterog);

	for (j=0; j < xn; j++) {
	    for (i=0; i < n1; i++)  {
		t = o1+i*d1;
		x2 = xo+j*xd;
		
		m = 0;
		t1 = o1 + m*d1;
		while(t>(t1*(1-1/ani[m])+
			 sqrt(t1*t1+ani[m]*x2*x2/(vel[m]*vel[m]+FLT_EPSILON))/
			 ani[m])) {
		    m++;
		    t1 = o1 + m*d1;
		}

		tt = (o1+i*d1)*(1-1/ani[m])+
		    sqrt((o1+i*d1)*(o1+i*d1)+ani[m]*x2*xd*xd*x2/
			 (vel[m]*vel[m]+FLT_EPSILON))/ani[m];

		dip[j*n1+i] = x2*xd/(FLT_EPSILON+d1*vel[m]*vel[m]*
				     (ani[m]*tt-(o1+i*d1)*(ani[m]-1)));
	    }
	}

	if (mute) {
	    for (j=0; j < xn; j++) { 
		x = xo + j*xd;	    
		x -= x1;
		if (hyper) x *= x;
		
		for (i=0; i < n1; i++) {
		    data[i] = dip[j*n1+i];
		}
		mutter (tp,slope0,slopep, x, data, false);
		for (i=0; i < n1; i++) {
		    dip[j*n1+i] = data[i];
		}
	    }
	}
	sf_floatwrite(dip,n1*xn,out);
    }
 
    sf_warning(".");
    exit (0);
}
Exemplo n.º 22
0
int main(int argc, char* argv[])
{
    bool phase;
    char *label;
    int i1, n1, iw, nt, nw, i2, n2, rect, niter;
    float t, d1, w, w0, dw, *trace, *bs, *bc, *ss, *cc, *mm;
    sf_file time, timefreq, mask;
    
    sf_init(argc,argv);
    time = sf_input("in");
    timefreq = sf_output("out");

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

    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)) {
			/* f	requency step */
			nt =	2*kiss_fft_next_fast_size((n1+1)/2);
			dw =	1./(nt*d1);
		}
		if (!sf_getfloat("w0",&w0)) w0=0.;
		/* first frequency */
    }

    sf_shiftdim(time, timefreq, 2);
    
    sf_putint(timefreq,"n2",nw);
    sf_putfloat(timefreq,"d2",dw);
    sf_putfloat(timefreq,"o2",w0);

    if (NULL != (label = sf_histstring(time,"label1")) && !sf_fft_label(2,label,timefreq)) 
		sf_putstring(timefreq,"label2","Wavenumber");
    sf_fft_unit(2,sf_histstring(time,"unit1"),timefreq);

    dw *= 2.*SF_PI;
    w0 *= 2.*SF_PI;

    trace = sf_floatalloc(n1);
    bs    = sf_floatalloc(n1);
    bc    = sf_floatalloc(n1);
    ss    = sf_floatalloc(n1);
    cc    = sf_floatalloc(n1);
    
    if (!sf_getint("rect",&rect)) rect=10;
    /* smoothing radius */
    if (!sf_getint("niter",&niter)) niter=100;
    /* number of inversion iterations */

    if (!sf_getbool("phase",&phase)) phase=false;
    /* output phase instead of amplitude */

    sf_divn_init(1,n1,&n1,&rect,niter,false);

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

    for (i2=0; i2 < n2; i2++) {
		sf_floatread(trace,n1,time);
		if (NULL != mm) {
			sf_floatread(mm,n1,mask);
			for (i1=0; i1 < n1; i1++) {
				trace[i1] *= mm[i1];
			}
		}

		for (iw=0; iw < nw; iw++) {
			w = w0 + iw*dw;

			if (0.==w) { /* zero frequency */
				for (i1=0; i1 < n1; i1++) {
					ss[i1] = 0.;
					bc[i1] = 0.5;
					if (NULL != mm) bc[i1] *= mm[i1];
				}
				sf_divn(trace,bc,cc);
			} else {
				for (i1=0; i1 < n1; i1++) {
					t = i1*d1;
					bs[i1] = sinf(w*t);
					bc[i1] = cosf(w*t);
					if (NULL != mm) {
						bs[i1] *= mm[i1];
						bc[i1] *= mm[i1];
					}
				}
				sf_divn(trace,bs,ss);
				sf_divn(trace,bc,cc);
			}

			for (i1=0; i1 < n1; i1++) {
				ss[i1] = phase? atan2f(ss[i1],cc[i1]): hypotf(ss[i1],cc[i1]);
			}

			sf_floatwrite(ss,n1,timefreq);
		}
    }
    

    exit(0);
}