Exemplo n.º 1
0
void cstretch4_apply (map4 str, 
		      const sf_complex* ord /* [nd] */, 
		      sf_complex* mod       /* [n1] */)
/*< complex transform ordinates to model >*/
{    
    int id, it;
    float *real, *imag, *ford;
    
    real = sf_floatalloc(str->nt);
    imag = sf_floatalloc(str->nt);
    ford = sf_floatalloc(str->nd);

    for (id=0; id < str->nd; id++) {
	ford[id] = crealf(ord[id]);
    }

    stretch4_apply (false,str,ford,real);

    for (id=0; id < str->nd; id++) {
	ford[id] = cimagf(ord[id]);
    }

    stretch4_apply (false,str,ford,imag);

    for (it=0; it < str->nt; it++) {
	mod[it] = sf_cmplx(real[it],imag[it]);
    }

    free(real);
    free(imag);
    free(ford);
}
Exemplo n.º 2
0
void fwarp3(float ***slice2 /* [n3][n2][n1] input */,
	    float ***coord1 /* [nx][ny][nt] coordinates */,
	    float ***coord2 /* [nx][ny][nt] coordinates */,
	    float ***coord3 /* [nx][ny][nt] coordinates */,
	    float ***slice  /* [nx][ny][nt] output */)
/*< apply forward warping >*/
{
    int i1, i2, i3;

    for (i3=0; i3 < nx; i3++) {
	for (i2=0; i2 < ny; i2++) {
	    stretch4_define (map1,coord1[i3][i2]);	    
	
	    stretch4_apply  (false,map1,coord2[i3][i2],trace1);
	    for (i1=0; i1 < n1; i1++) {
		str2[i1][i3][i2] = trace1[i1];
	    }

	    stretch4_apply  (false,map1,coord3[i3][i2],trace1);
	    for (i1=0; i1 < n1; i1++) {
		str3[i1][i3][i2] = trace1[i1];
	    }
	}
    }

    for (i1=0; i1 < n1; i1++) {
	for (i3=0; i3 < n3; i3++) {
	    for (i2=0; i2 < n2; i2++) {
		trace2[i3][i2] = slice2[i3][i2][i1];
	    }
	}

	fwarp2(trace2,str2[i1],str3[i1],slice1[i1]);
    }
    
    for (i3=0; i3 < nx; i3++) {
	for (i2=0; i2 < ny; i2++) {
	    for (i1=0; i1 < n1; i1++) {
		trace1[i1] = slice1[i1][i3][i2];
	    }
	    
	    stretch4_define (map1,coord1[i3][i2]);	    	
	    stretch4_invert  (false,map1,slice[i3][i2],trace1);
	}
    }
}
Exemplo n.º 3
0
Arquivo: inmo.c Projeto: krushev36/src
void inmo(const float *trace   /* input trace [nt] */,
	  float **gather /* output CMP gather [nt][nh] */)
/*< apply inverse nmo >*/
{
    int ih;

    for (ih = 0; ih < nh; ih++) {
	stretch4_apply (false,nmo[ih],(float*)trace,gather[ih]);
    }
}
Exemplo n.º 4
0
int main(int argc, char* argv[])
{
    map4 mo;
    bool inv;
    int n1, i2, n2, i3, n3;
    float o1, d1, o2, d2, eps, t, t0;
    float *trace, *t2, *trace2;
    sf_file in, out;

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

    if (!sf_getbool("inv",&inv)) inv=false;
    /* inversion flag */

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

	if (!sf_histint(in,"n1_logwarp",&n1)) n1=n2;

	if (!sf_getfloat("t0",&t0) && 
	    !sf_histfloat(in,"t0_logwarp",&t0)) sf_error("Need t0=");

	o1 = t0*expf(o2);
	d1 = o2+(n2-1)*d2;
	d1 = (t0*expf(d1)-o1)/(n1-1);
	
	sf_putint(out,"n1",n1);
	sf_putfloat(out,"d1",d1);
	sf_putfloat(out,"o1",o1);
    } else {
	if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input");
	if (!sf_getint("pad",&n2)) n2=n1; /* output time samples */

	if (!sf_histfloat(in,"d1",&d1)) d1=1.;
	if (!sf_histfloat(in,"o1",&o1)) o1=0.;

	if (!sf_getfloat("t0",&t0)) t0=o1;
	sf_putfloat(out,"t0_logwarp",t0);

	o2 = logf(o1/t0);
	d2 = o1+(n1-1)*d1;
	d2 = (logf(d2/t0) - o2)/(n2-1);

	sf_putint(out,"n1",n2);
	sf_putfloat(out,"d1",d2);
	sf_putfloat(out,"o1",o2);

	sf_putint(out,"n1_t2warp",n1);
    } 

    n3 = sf_leftsize(in,1);

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

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

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

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

    stretch4_define (mo,t2);
    
    for (i3=0; i3 < n3; i3++) {
	if (inv) {
	    sf_floatread(trace,n2,in);
	    stretch4_apply (false,mo,trace,trace2);
	    sf_floatwrite (trace2,n1,out);
	} else {
	    sf_floatread(trace2,n1,in);
	    stretch4_invert (false,mo,trace,trace2);
	    sf_floatwrite (trace,n2,out);
	}
    }

    exit(0);
}
Exemplo n.º 5
0
int main (int argc, char* argv[])
{
    bool interval;
    map4 nmo; /* using cubic spline interpolation */
    int it,ix,ip, nt,nx, np;
    float dt, t0, p, p0, f, ft, dp, eps, at;
    float *trace=NULL, *vel=NULL, *str=NULL, *out=NULL, *n=NULL;
    sf_file cmp=NULL, nmod=NULL, velocity=NULL, eta=NULL;

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

    if (!sf_getbool("interval",&interval)) interval=true;
    /* use interval velocity */

    if (NULL == sf_getstring("eta")) {
	eta = NULL;
    } else {
	eta = sf_input("eta");
    }

    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",&np)) sf_error("No n2= in input");
    if (!sf_histfloat(cmp,"d2",&dp)) sf_error("No d2= in input");
    if (!sf_histfloat(cmp,"o2",&p0)) sf_error("No o2= in input");

    nx = sf_leftsize(cmp,2);

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

    trace = sf_floatalloc(nt);
    vel = sf_floatalloc(nt);
    str = sf_floatalloc(nt);
    out = sf_floatalloc(nt);

    n = (NULL == eta)? NULL: sf_floatalloc(nt);

    nmo = stretch4_init (nt, t0, dt, nt, eps);

    for (ix = 0; ix < nx; ix++) {
	sf_floatread (vel,nt,velocity);	
	if (NULL != eta) sf_floatread (n,nt,eta);	

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

	    sf_floatread (trace,nt,cmp);
	    
	    f = 0.;
	    for (it=0; it < nt; it++) {
		ft = vel[it];
		ft *= ft;
		
		if (NULL == n) {
		    ft = 1.-p*ft;
		} else {
		    at = n[it];
		    ft = (1.-(1.+2.*at)*p*ft)/(1.-2.*at*p*ft);
		}

		if (ft < 0.) {
		    for (; it < nt; it++) {
			str[it]=t0-10.*dt;
		    }
		    break;
		}

		if (interval) {
		    if (it==0) f = sqrtf(ft)*t0/dt;
		    str[it] = f*dt;
		    f += sqrtf(ft);
		} else {		    
		    f = sqrtf(ft);
		    str[it] = f*(t0+it*dt);
		}
	    }

	    stretch4_define (nmo,str);
	    stretch4_apply (nmo,trace,out);

	    sf_floatwrite (out,nt,nmod);
	}
    }

    exit (0);
}
Exemplo n.º 6
0
int main (int argc, char* argv[])
{
    map4 nmo; /* using cubic spline interpolation */
    bool half;
    int it,ix,iy, nt, nx, ny, nw, i4, n4, n;
    float dt, t0, x, y, x0, y0, f, dx, dy, eps;
    float *trace=NULL, *vx=NULL, *vy=NULL, *vxy=NULL, *str=NULL, *out=NULL;
    sf_file cmp=NULL, nmod=NULL, vel=NULL;

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

    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",&nx)) sf_error("No n2= in input");
    if (!sf_histint(cmp,"n3",&ny)) sf_error("No n3= in input");
    n4 = sf_leftsize(cmp,3);

    vel = sf_input("velocity");
    if (SF_FLOAT != sf_gettype(vel)) sf_error("Need float velocity");
    if (!sf_histint(vel,"n1",&n) || nt != n) sf_error("Need n1=%d in velocity",nt);
    if (!sf_histint(vel,"n2",&n) || 3 != n) sf_error("Need n2=3 in velocity",nt);
    if (n4 != sf_leftsize(vel,2)) sf_error("Wrong dimensions in velocity");

    if (!sf_histfloat(cmp,"d2",&dx)) sf_error("No d2= in input");
    if (!sf_histfloat(cmp,"o2",&x0)) sf_error("No o2= in input");
    if (!sf_histfloat(cmp,"d3",&dy)) sf_error("No d3= in input");
    if (!sf_histfloat(cmp,"o3",&y0)) sf_error("No o3= in input");

    if (!sf_getbool("half",&half)) half=true;
    /* if y, the second and third axes are half-offset instead of full offset */

    if (half) { /* get full offset - multiply by 2 */
      dx *= 2.;
      dy *= 2.;
      x0 *= 2.;
      y0 *= 2.;
      sf_warning("Since half=y, offsets were doubled.");
    }else{
      sf_warning("Since half=n, offsets not doubled.");
    }

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

    trace = sf_floatalloc(nt);
    vx = sf_floatalloc(nt);
    vy = sf_floatalloc(nt);
    vxy = sf_floatalloc(nt);

    str = sf_floatalloc(nt);
    out = sf_floatalloc(nt);

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

    nmo = stretch4_init (nt, t0, dt, nt, eps);

    for (i4=0; i4 < n4; i4++) { /* loop over cmps */
      sf_floatread (vx,nt,vel);
      sf_floatread (vy,nt,vel);
      sf_floatread (vxy,nt,vel);

      for (iy = 0; iy < ny; iy++) {
	y = y0+iy*dy;

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

	  sf_floatread (trace,nt,cmp);

	  for (it=0; it < nt; it++) {
	    f = t0 + it*dt;
	    f = f*f + x*x*vx[it]+y*y*vy[it]+2*x*y*vxy[it];

	    if (f < 0.) {
	      str[it]=t0-10.*dt;
	    } else {
	      str[it] = sqrtf(f);
	    }
	  }

	  stretch4_define (nmo,str);
	  stretch4_apply (nmo,trace,out);

	  sf_floatwrite (out,nt,nmod);
	} /* ix */
      } /* iy */
    } /* i4 */

    exit (0);
}
Exemplo n.º 7
0
int main (int argc, char* argv[])
{
    map4 nmo; /* using cubic spline interpolation */
    bool half, slow;
    int it,ix,ih, nt,nx, nh, CDPtype;
    float dt, t0, h, h0, f, dh, eps, dy;
    float *trace, *vel, *off, *str, *out;
    sf_file cmp, nmod, velocity, offset;

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

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

    trace = sf_floatalloc(nt);
    vel = sf_floatalloc(nt);
    str = sf_floatalloc(nt);
    out = sf_floatalloc(nt);

    nmo = stretch4_init (nt, t0, dt, nt, eps);
    
    for (ix = 0; ix < nx; ix++) {
	sf_floatread (vel,nt,velocity);	

	for (ih = 0; ih < nh; ih++) {
	    sf_floatread (trace,nt,cmp);
	    
	    h = off[ih] + (dh/CDPtype)*(ix%CDPtype); 
	    if (half) h *= 2;
	    h = h*h - h0*h0;
	    
	    for (it=0; it < nt; it++) {
		f = t0 + it*dt;
		if (slow) {
		    f = f*f + h*vel[it]*vel[it];
		} else {
		    f = f*f + h/(vel[it]*vel[it]);
		}
		if (f < 0.) {
		    str[it]=t0-10.*dt;
		} else {
		    str[it] = sqrtf(f);
		}
	    }

	    stretch4_define (nmo,str);
	    stretch4_apply (false,nmo,trace,out);
	    
	    sf_floatwrite (out,nt,nmod);
	}
    }


    exit (0);
}
Exemplo n.º 8
0
int main(int argc, char* argv[])
{
    bool moveout;
    int nt, n1, i1, i2, n2, ns, n1s, ip, np, three;
    float *a=NULL, *b=NULL, *r=NULL, *tpp=NULL, *tps=NULL, *app=NULL, *aps=NULL, **pp=NULL, **ps=NULL;
    float dt, tp,ts, a1,a2, b1,b2, r1,r2, eps, rc[4], ang[4];
    float d1, p0, dp, p, as, bs, ad1, bd1; 
    map4 map;
    sf_file in, out;

    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,"n2",&three) || three != 3)
	sf_error("Need n2=3 in input");
    n2 = sf_leftsize(in,2);

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

    if (!sf_getint("sparse",&ns)) ns=10;
    /* sparseness of reflectivity */

    if (!sf_getbool("moveout",&moveout)) moveout=true;
    /* if apply moveout */

    if (!sf_getint("nt",&nt)) sf_error("Need nt=");
    /* time samples */
    if (!sf_getfloat("dt",&dt)) sf_error("Need dt=");
    /* time sampling */

    if (!sf_getint("np",&np)) sf_error("Need np=");
    /* slope samples */
    if (!sf_getfloat("dp",&dp)) sf_error("Need dp=");
    /* slope sampling */
    if (!sf_getfloat("p0",&p0)) sf_error("Need p0=");
    /* slope origin */

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

    sf_putint(out,"n1",nt);
    sf_putfloat(out,"d1",dt);
    sf_putfloat(out,"o1",0.);
    sf_putstring(out,"label1","Time");
    sf_putstring(out,"unit1","s");

    sf_putint(out,"n2",np);
    sf_putfloat(out,"d2",dp);
    sf_putfloat(out,"o2",p0);

    sf_putint(out,"n3",2);
    sf_putint(out,"n4",n2);    

    a = sf_floatalloc(n1);
    b = sf_floatalloc(n1);
    r = sf_floatalloc(n1);

    n1s = (n1-1)*ns;
    d1 /= ns;

    tpp = sf_floatalloc(n1s);
    tps = sf_floatalloc(n1s);
    app = sf_floatalloc(n1s);
    aps = sf_floatalloc(n1s);

    pp = sf_floatalloc2(nt,np);
    ps = sf_floatalloc2(nt,np);

    map = stretch4_init (nt, 0., dt, n1s, eps);

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

	sf_floatread(a,n1,in); /* Vp */
	sf_floatread(b,n1,in); /* Vs */
	sf_floatread(r,n1,in); /* rho */

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

	    tp = ts = 0.;
	    a2 = a[0];
	    b2 = b[0];
	    r2 = r[0];
	    for (i1=1; i1 <= n1s; i1++) {
		as = a2*p;
		if (fabsf(as) > 1.) 
		    sf_error("p=%g is postcritical (vp=%g)",p,a2);

		bs = b2*p; 
		if (fabsf(bs) > 1.) 
		    sf_error("p=%g is postcritical (vs=%g)",p,b2);
		
		ad1 = d1*sqrtf(1.-as*as)/a2;
		bd1 = d1*sqrtf(1.-bs*bs)/b2;

		if (moveout) {
		    tp += 2.*ad1;
		    ts += ad1 + bd1;
		} else {
		    tp += 2.*d1/a2;
		    ts += d1/a2+d1/b2;
		}

		tpp[i1-1] = tp;
		tps[i1-1] = ts;
	
		a1 = a2;
		b1 = b2;
		r1 = r2;

		if (0==i1%ns) {
		    a2 = a[i1/ns];
		    b2 = b[i1/ns];
		    r2 = r[i1/ns];
		    zoeppritz (4,a1,a2,b1,b2,r1,r2,true,p,rc,ang);
		} else {
		    rc[0] = rc[1] = 0.;
		}

		app[i1-1] = rc[0];
		aps[i1-1] = rc[1];
	    }

	    stretch4_define (map,tpp);
	    stretch4_apply (false,map,app,pp[ip]);

	    stretch4_define (map,tps);
	    stretch4_apply (false,map,aps,ps[ip]);
	}

	sf_floatwrite(pp[0],nt*np,out);
	sf_floatwrite(ps[0],nt*np,out);
    }

    exit(0);
}
Exemplo n.º 9
0
int main(int argc, char* argv[])
{
    int nt, ns, nx, n2, it, nstr, ifix;
    float dt, t0, eps, v0, *v=NULL, *trace=NULL, *out=NULL, *ww=NULL, wsum;
    char buffer[20];
    map4 stolt;
    fint1 istolt;
    bool inv;
    sf_file in=NULL, st=NULL, vel=NULL;

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

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

    if (!sf_getint("nstretch",&nstr)) nstr=1;
    /* number of steps */

    if (inv) {
        if (!sf_histint(in,"n1",&ns)) sf_error("No n1= in input");
        if (!sf_histint(vel,"n1",&nt)) sf_error("No n1= in velocity");
        sf_putint(st,"n1",nt);
    } else {
        if (!sf_histint(in,"n1",&nt)) sf_error("No n1= in input");
        if (!sf_getint("pad",&ns)) ns=nt;
        /* time axis padding */
        sf_putint(st,"n1",ns);
        sf_putint(st,"nstretch", nstr);
    }
    nx = sf_leftsize(in,1);
    n2 = sf_leftsize(vel,1);

    if (n2 != 1 && n2 != nx) sf_error("Wrong number of traces in velocity");

    if (!sf_histfloat(in,"d1",&dt)) sf_error("No d1= in input");
    if (!sf_histfloat(in,"o1",&t0) || 0. != t0) sf_error("Need o1=0 in input");
    if (!sf_getfloat("eps",&eps)) eps=0.01;
    /* stretch regularization */
    if (!sf_getfloat("vel",&v0)) sf_error("Need vel=");
    /* reference velocity */

    trace = sf_floatalloc(nt);
    v = sf_floatalloc(nt);
    str = sf_floatalloc2(nt,nx);
    out = sf_floatalloc(ns);
    ww = sf_floatalloc(nx);

    if (inv) {
        stolt = NULL;
        istolt = fint1_init(4,ns,0);
    } else {
        stolt =  stretch4_init (ns,t0,dt,nt,eps);
        istolt = NULL;
    }

    wsum = 0.;
    for (ix=0; ix < nx; ix++) {
        if (0==ix || n2 > 1) {
            sf_floatread(v,nt,vel);
            ww[ix] = vt2w (nt,v,str[ix]);
        } else if (1 == n2) {
            ww[ix] = ww[0];
            for (it=0; it < nt; it++) {
                str[ix][it] = str[0][it];
            }
        }
        wsum += ww[ix];
    }

    sf_warning("%d traces processed",nx);

    if (1==nstr) {
        sf_putfloat(st,"stretch", wsum/nx);
    } else {
        for (ix=0; ix < nstr; ix++) {
            ifix=SF_MAX(1,(int) (nx*ix/(nstr-1)));
            sf_warning("%d %d",ix,ifix);

            snprintf(buffer,20,"stretch%d",ix);
            sf_putfloat (st,buffer,ww[ifix]);

            snprintf(buffer,20,"node%d",ix);
            sf_putint (st,buffer,ifix);
        }
    }

    for (ix=0; ix < nx; ix++) {
        for (it=0; it < nt; it++) {
            str[ix][it] *= dt/v0;
        }
        if (inv) {
            sf_floatread(out,ns,in);
            fint1_set(istolt,out);
            stretch(istolt, map, ns, dt, t0, nt, dt, t0, trace, 0.);
            sf_floatwrite (trace,nt,st);
        } else {
            sf_floatread (trace,nt,in);
            stretch4_define (stolt, str[ix]);
            stretch4_apply (false,stolt, trace, out);
            sf_floatwrite (out,ns,st);
        }
    }

    exit(0);
}
Exemplo n.º 10
0
int main(int argc, char* argv[])
{
    map4 mo;
    bool inv, each=true;
    int i, nt, n1, i2, n2, nw;
    float o1, d1, t0, dt, eps;
    sf_complex *ctrace, *ctrace2;
    float *trace, *str, *trace2;
    sf_file in, out, warp;

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

    if (!sf_getbool("inv",&inv)) inv=true;
    /* inversion flag */

    if (inv) {
	if (!sf_histint(in,"n1",&nt)) sf_error("No n1= in input");
	
	if (!sf_getint("n1",&n1)) n1=nt; /* output samples - for inv=y */
	if (!sf_getfloat("d1",&d1) && !sf_histfloat(in,"d1",&d1)) d1=1.;
	/*( d1=1 output sampling - for inv=y )*/
	if (!sf_getfloat("o1",&o1) && !sf_histfloat(in,"o1",&o1)) o1=0.;
	/*( o1=0 output origin - for inv=y )*/ 

	sf_putint(out,"n1",n1);
	sf_putfloat(out,"d1",d1);
	sf_putfloat(out,"o1",o1);
    } else {
	if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input");
	if (!sf_histfloat(in,"d1",&d1)) d1=1.;
	if (!sf_histfloat(in,"o1",&o1)) o1=0.;

	if (!sf_histint(warp,"n1",&nt)) sf_error("No n1= in warp");
	if (!sf_histfloat(warp,"d1",&dt)) dt=d1;
	if (!sf_histfloat(warp,"o1",&t0)) t0=o1;
	
	sf_putint(out,"n1",nt);
	sf_putfloat(out,"d1",dt);
	sf_putfloat(out,"o1",t0);
    }

    n2 = sf_leftsize(in,1);
    nw = sf_leftsize(warp,1);
    if (1 == nw) {
	each = false;
    } else if (n2 != nw) {
	sf_error("Need %d traces in warp, got %d",n2,nw);
    } 
    
    if (!sf_getfloat("eps",&eps)) eps=0.01;
    /* stretch regularization */

    trace = sf_floatalloc(nt);
    str = sf_floatalloc(nt);
    trace2 = sf_floatalloc(n1);

    mo = stretch4_init (n1, o1, d1, nt, eps);

    if (SF_COMPLEX == sf_gettype(in)) {
	ctrace = sf_complexalloc(nt);
	ctrace2 = sf_complexalloc(n1);
    } else {
	ctrace = ctrace2 = NULL;
    }

    for (i2=0; i2 < n2; i2++) {
	if (each || 0==i2) {
	    sf_floatread(str,nt,warp);
	    stretch4_define (mo,str);
	}

	if (inv) {
	    if (SF_COMPLEX == sf_gettype(in)) {
		sf_complexread(ctrace,nt,in);
		for (i=0; i < nt; i++) {
		    trace[i] = crealf(ctrace[i]);
		}
		stretch4_apply (false,mo,trace,trace2);
		for (i=0; i < n1; i++) {
		    ctrace2[i] = sf_cmplx(trace2[i],0.0f);
		}
		for (i=0; i < nt; i++) {
		    trace[i] = cimagf(ctrace[i]);
		}
		stretch4_apply (false,mo,trace,trace2);
		for (i=0; i < n1; i++) {
#ifdef SF_HAS_COMPLEX_H
		    ctrace2[i] += sf_cmplx(0.0f,trace2[i]);
#else
		    ctrace2[i] = sf_cadd(ctrace2[i],sf_cmplx(0.0f,trace2[i]));
#endif
		}
		sf_complexwrite (ctrace2,n1,out);
	    } else {
		sf_floatread(trace,nt,in);
		stretch4_apply (false,mo,trace,trace2);
		sf_floatwrite (trace2,n1,out);
	    }
	} else {
	    if (SF_COMPLEX == sf_gettype(in)) {
		sf_complexread (ctrace2,n1,out);
		for (i=0; i < n1; i++) {
		    trace2[i] = crealf(ctrace2[i]);
		}
		stretch4_invert (false,mo,trace,trace2);
		for (i=0; i < nt; i++) {
		    ctrace[i] = sf_cmplx(trace[i],0.0f);
		}
		for (i=0; i < n1; i++) {
		    trace2[i] = cimagf(ctrace2[i]);
		}
		stretch4_invert (false,mo,trace,trace2);
		for (i=0; i < nt; i++) {
#ifdef SF_HAS_COMPLEX_H
		    ctrace[i] += sf_cmplx(0.0f,trace[i]);
#else
		    ctrace[i] = sf_cadd(ctrace[i],sf_cmplx(0.0f,trace[i]));
#endif
		}
		sf_complexwrite(ctrace,nt,in);
	    } else {
		sf_floatread(trace2,n1,in);
		stretch4_invert (false,mo,trace,trace2);
		sf_floatwrite (trace,nt,out);
	    }
	}
    }

    exit(0);
}
Exemplo n.º 11
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.º 12
0
int main(int argc, char* argv[])
{
    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 = 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;
	}

	stretch4_define (mo,str);
	stretch4_apply (mo,amp,trace);
	sf_floatwrite (trace,n1,out);
    }

    exit(0);
}