Exemple #1
0
void sfFloatWrite1d(const char *fn, const float *dat, int n1, float d1, float o1) {
  sf_file f = sf_output(fn);
  sf_putint(f, "n1", n1);
  sf_putfloat(f, "d1", d1);
  sf_putfloat(f, "o1", o1);
  sf_floatwrite(const_cast<float *>(dat), n1, f);
}
Exemple #2
0
int main(int argc, char* argv[])
{
    int nd, m1, na, nr, niter;
    float *rr, *dd, *coord, o1, d1, eps;
    char *header;
    sf_file in, out, head;

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

    /* create model */
    if (!sf_getint ("nx",&m1)) sf_error("Need n1=");
    /* number of bins */
    sf_putint(out,"n1",m1);

    if (!sf_getfloat("x0",&o1)) sf_error("Need o1=");
    /* grid origin */
    sf_putfloat (out,"o1",o1);

    if (!sf_getfloat("dx",&d1)) sf_error("Need d1=");
    /* grid sampling */
    sf_putfloat (out,"d1",d1);

    if (!sf_getint("niter",&niter)) niter=1+m1*3/2; niter *= 2;
    /* number of conjugate-gradient iterations */
    if (!sf_getfloat("eps",&eps)) eps=0.2;
    /* regularization parameter */

    /* create filter */
    if (!sf_getint("na",&na)) na=3;
    nr = m1 + na;

    rr = sf_floatalloc(nr);

    if (!sf_histint(in,"n1",&nd)) nd=1;
    coord = sf_floatalloc(nd);
    dd = sf_floatalloc(nd);

    header = sf_getstring("head");
    if (NULL == header) { 
	header = sf_histstring(in,"head");
	if (NULL == header) sf_error("Need head=");
    }

    head = sf_input(header);
    if (SF_FLOAT != sf_gettype(head)) sf_error("Need float head");
    sf_floatread (coord,nd,head);
    sf_fileclose (head);

    sf_floatread (dd,nd,in);

    levint1 (niter, m1, nr, nd, coord, dd, o1, d1, rr, eps);
    
    sf_floatwrite (rr,m1,out);


    exit(0);
}
Exemple #3
0
int main(int argc, char* argv[])
{
    int n1,n2,n12;
    bool adj;
    float d1,d2,o1,o2,v, *model=NULL, *dat=NULL;
    sf_file in=NULL, out=NULL;

    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)) sf_error("No d1= in input");
    if (!sf_histfloat(in,"o1",&o1)) o1=0.;

    if (!sf_getbool("adj",&adj)) adj=false;
    /* adjoint flag */

    if (adj) {
	if (!sf_histint(in,"n2",&n2)) sf_error("No n2= in input");
	if (!sf_histfloat(in,"d2",&d2)) sf_error("No d2= in input");
	if (!sf_histfloat(in,"o2",&o2)) sf_error("No o2= in input");

	sf_putint(out,"n2",1);
    } else {
	if (!sf_getint("n2",&n2)) n2=20;
	/* number of offsets (if inv=n) */
	if (!sf_getfloat("d2",&d2)) d2=200.;
	/* offset sampling (if inv=n) */
	if (!sf_getfloat("o2",&o2)) o2=0.;
	/* offset origin (if inv=n) */

	sf_putint(out,"n2",n2);
	sf_putfloat(out,"d2",d2);
	sf_putfloat(out,"o2",o2);
    }
    n12 = n1*n2;

    if (!sf_getfloat ("v",&v)) v=1000.;
    /* velocity */

    dat = sf_floatalloc(n12);
    model =  sf_floatalloc(n1);

    imospray_init (1./v, o2,d2, o1,d1, n1,n2);

    if (adj) {
	sf_floatread(dat,n12,in);
	imospray_lop (true,false,n1,n12,model,dat);
	sf_floatwrite(model,n1,out);
    } else {	
	sf_floatread(model,n1,in);
	imospray_lop (false,false,n1,n12,model,dat);
	sf_floatwrite(dat,n12,out);
    }

    exit(0);
}
Exemple #4
0
int main(int argc, char* argv[])
{
   int j, nx, nt, n;
   float dt, dx, lambda; /* dt corresponds to k, dx corresponds to h */
   float *uo, *up, *u_true, *dif, *t; /*uo->u(n), up->u(n+1)*/
   sf_file out;
   sf_init(argc,argv);
   out=sf_output("out");
   
  if(!sf_getint("nt",&nt)) sf_error("No nt in command line!");
  /* number of temporal points */
  if(!sf_getfloat("dt",&dt)) sf_error("No dt in command line!");
  /* temporal sampling */

  if(!sf_getint("nx",&nx)) sf_error("No nx in command line!");
  /* number of spatial points */
  if(!sf_getfloat("dx",&dx)) sf_error("No dx in command line!");
  /* spatial sampling */
   
  sf_putint(out,"n1",nx);
  sf_putfloat(out,"d1",dx);
  sf_putfloat(out,"o1",0);
 
   lambda=dt/(dx*dx); /* correpsonding to a^2k/h^2 */

   uo=sf_floatalloc(nx);
   up=sf_floatalloc(nx);
   u_true=sf_floatalloc(nx);
   dif=sf_floatalloc(nx);

/* initialize it=0 */
   for(j=0;j<nx;j++)
	uo[j]=f(dx*j);

/* loop over it until finish computing up[nt-1] */
   for(n=0;n<nt-1;n++)  /* (nt-1) iterations */
	{
	up[0]=0;up[nx-1]=0;
	for(j=1;j<nx-1;j++)
		up[j]=lambda*uo[j-1]+(1-2*lambda)*uo[j]+lambda*uo[j+1];
	t=uo;
	uo=up;
	up=t;
	}
   for(j=0;j<nx;j++)
	{u_true[j]=f_true(j*dx,(nt-1)*dt); dif[j]=fabs(u_true[j]-uo[j]);}

   for(j=0;j<nx;j++)
   {
	sf_warning("%.1f   %.8f   %.8f   %.3e",j*dx, u_true[j], uo[j], dif[j]);
   }

   /* Here uo refers to the final result. */
   sf_floatwrite(uo, nx, out);
   exit(0);
}
Exemple #5
0
int main(int argc, char* argv[])
{
    int nz, nx, ix, iz;
    float *trace, x0, z0, x, z, dx, dz, v0, g, v, a, d;
    sf_file mod;

    sf_init (argc,argv);
    mod = sf_output("out");

    if (!sf_getint("nz",&nz)) nz=601; 
    /* vertical dimension */
    if (!sf_getint("nx",&nx)) nx=401; 
    /* horizontal dimension */

    dz = 4./(nz-1);
    dx = 6./(nx-1);
    
    sf_putint   (mod,"n1",nz); 
    sf_putfloat (mod,"d1",dz); 
    sf_putfloat (mod,"o1",0.);
    sf_putint   (mod,"n2",nx); 
    sf_putfloat (mod,"d2",dx); 
    sf_putfloat (mod,"o2",0.);
    sf_setformat (mod,"native_float");

    if(!sf_getfloat ("x0",&x0)) x0=4.;
    /* anomaly center in x */
    if(!sf_getfloat ("z0",&z0)) z0=1.5;
    /* anomaly center in z */
    if(!sf_getfloat ("v0",&v0)) v0=1.5;
    /* surface velocity */
    if(!sf_getfloat ("g",&g)) g=0.6;
    /* velocity gradient */
    if(!sf_getfloat ("a",&a)) a=1.;
    /* anomaly magnitude */
    if(!sf_getfloat ("d",&d)) d=1.;
    /* anomaly radius */
    d *= d;

    trace = sf_floatalloc(nz);

    for (ix=0; ix <  nx; ix++) {
	x = ix*dx - x0;
	x *= x;
	for (iz=0; iz < nz; iz++) {
	    z = iz*dz;
	    v = v0 + g*z;
	    z = z - z0;
	    z = z*z + x;
	    trace[iz] = v + a*exp(-z/d);
	}
	sf_floatwrite (trace,nz,mod);
    }

    exit (0);
}
Exemple #6
0
int main(int argc, char* argv[])
{
	int i3, n3, ix, nx, iz, nz;
	int nx2, nz2, scalex, scalez;
	float dx, dz;
	float **a, **b;
	sf_file in, out;

	sf_init(argc, argv);

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

	if(!sf_getint("scalex", &scalex)) sf_error("Need scalex=");
	if(!sf_getint("scalez", &scalez)) sf_error("Need scalez=");

	if(!sf_histint(in, "n1", &nz)) sf_error("No n1= in input");
	if(!sf_histfloat(in, "d1", &dz)) sf_error("No d1= in input");
	if(!sf_histint(in, "n2", &nx)) sf_error("No n2= in input");
	if(!sf_histfloat(in, "d2", &dx)) sf_error("No d2= in input");

	nx2=(nx-1)*scalex+1;
	nz2=(nz-1)*scalez+1;
	n3=sf_leftsize(in, 2);

	sf_putint(out, "n1", nz2);
	sf_putfloat(out, "d1", dz/scalez);
	sf_putint(out, "n2", nx2);
	sf_putfloat(out, "d2", dx/scalex);

	a=sf_floatalloc2(nz, nx);
	b=sf_floatalloc2(nz2, nx2);

	for (i3=0; i3<n3; i3++){
		sf_floatread(a[0], nz*nx, in);

#pragma omp parallel for private(ix, iz)
		for(ix=0; ix<nx2; ix++){
			for(iz=0; iz<nz2; iz++){
				b[ix][iz]=0.;
			}
		}

#pragma omp parallel for private(ix, iz)
		for(ix=0; ix<nx; ix++){
			for(iz=0; iz<nz; iz++){
				b[ix*scalex][iz*scalez]=a[ix][iz];
			}
		}

		sf_floatwrite(b[0], nz2*nx2, out);
	}

	exit(0);
}
Exemple #7
0
int main(int argc, char*argv[])
{
	sf_file in, out;
	int nf, n1, n2, n3, m, n;
	int i3;
	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");
	if (!sf_histint(in, "n2", &n2)) sf_error("No n2= in input");
	n3 = sf_leftsize(in, 2);

	sf_shiftdim2(in,out,2);

	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_floatalloc2(n1,n2);
	fb  = sf_floatalloc4(n1, n2, nf, nf);

	sf_putint(out, "n3", nf);
	sf_putint(out, "n4", nf);
	sf_putfloat(out, "o3", 0);
	sf_putfloat(out, "d3", 1);
	sf_putfloat(out, "o4", 0);
	sf_putfloat(out, "d4", 1);


	fbank_init(m, n, interp);


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

	fbank_close();
	return 0;
}
Exemple #8
0
void sfFloatWrite2d(const char *fn, const float *dat, int n1, int n2,
    float d1, float d2, float o1, float o2) {
  sf_file f = sf_output(fn);
  sf_putint(f, "n1", n1);
  sf_putint(f, "n2", n2);
  sf_putfloat(f, "d1", d1);
  sf_putfloat(f, "d2", d2);
  sf_putfloat(f, "o1", o1);
  sf_putfloat(f, "o2", o2);
  sf_floatwrite(const_cast<float *>(dat), n1 * n2, f);
}
Exemple #9
0
int main(int argc, char* argv[])
{
    int ix, iy, nx, ny;
    float dx, dy, zx, zy, x, y, *trace;
    sf_file angle;
    
    sf_init(argc,argv);
    angle=sf_output("out");
    sf_setformat(angle,"native_float");

    if (!sf_getint("nx",&nx)) nx=451;
    if (!sf_getint("ny",&ny)) ny=451;

    if (!sf_getfloat("dx",&dx)) dx=0.1;
    if (!sf_getfloat("dy",&dy)) dy=0.1;

    if (!sf_getfloat("zx",&zx)) zx=0.;
    if (!sf_getfloat("zy",&zy)) zy=0.;

    zx = tanf(SF_PI*zx/180.);
    zy = tanf(SF_PI*zy/180.);

    sf_putint(angle,"n1",2*nx-1);
    sf_putfloat(angle,"o1",-(nx-1)*dx);
    sf_putfloat(angle,"d1",dx);
    sf_putstring(angle,"label1","In-line Offset Slope");
    sf_putstring(angle,"unit1","degrees");

    sf_putint(angle,"n2",2*ny-1);
    sf_putfloat(angle,"o2",-(ny-1)*dy);
    sf_putfloat(angle,"d2",dy);
    sf_putstring(angle,"label2","Cross-line Offset Slope");
    sf_putstring(angle,"unit2","degrees");

    trace = sf_floatalloc(2*nx-1);
    
    for (iy=-ny+1; iy < ny; iy++) {
	y = tanf(iy*dy*SF_PI/180.);
	for (ix=-nx+1; ix < nx; ix++) {
	    x = tanf(ix*dx*SF_PI/180.);
	    x = x*x*(1.+zx*zx) + 2.*x*y*zx*zy + y*y*(1.+zy*zy);
	    x /= (1.+zx*zx+zy*zy);
	    if (x > 0.) {
		trace[ix+nx-1] = atanf(sqrtf(x)) * 180./SF_PI;
	    } else {
		trace[ix+nx-1] = -1.;
	    }
	}
	sf_floatwrite(trace,2*nx-1,angle);
    }

    exit(0);
}
Exemple #10
0
void sfDoubleWrite2d(const char *fn, const double *dat, int n1, int n2,
    float d1, float d2, float o1, float o2) {
  sf_file f = sf_output(fn);
  sf_putint(f, "n1", n1);
  sf_putint(f, "n2", n2);
  sf_putfloat(f, "d1", d1);
  sf_putfloat(f, "d2", d2);
  sf_putfloat(f, "o1", o1);
  sf_putfloat(f, "o2", o2);

  std::vector<float> tmp(dat, dat + n1 * n2);
  sf_floatwrite(&tmp[0], n1 * n2, f);
}
Exemple #11
0
void puthead4x(sf_file Fo, int n1, int n2, int n3, int n4, float d1, float d2, float d3, float d4, float o1, float o2, float o3, float o4)
/*<  put head for (y,x,z,t) domain float-type 3D data sets>*/
{
        /* Read/Write axes */
        sf_putint(Fo,"n1",n1);
        sf_putint(Fo,"n2",n2);
        sf_putint(Fo,"n3",n3);
        sf_putint(Fo,"n4",n4);
        sf_putfloat(Fo,"d1",d1);
        sf_putfloat(Fo,"d2",d2);
        sf_putfloat(Fo,"d3",d3);
        sf_putfloat(Fo,"d4",d4);
        sf_putfloat(Fo,"o1",o1);
        sf_putfloat(Fo,"o2",o2);
        sf_putfloat(Fo,"o3",o3);
        sf_putfloat(Fo,"o4",o4);
        sf_putstring(Fo,"label1","z");
        sf_putstring(Fo,"label2","x");
        sf_putstring(Fo,"label3","y");
        sf_putstring(Fo,"label4","t");
        sf_putstring(Fo,"unit1","km");
        sf_putstring(Fo,"unit2","km");
        sf_putstring(Fo,"unit3","km");
        sf_putstring(Fo,"unit4","s");
}
Exemple #12
0
void FwiParams::putOutputParams() {
  sf_putint(vupdates, "n1", nz);
  sf_putint(vupdates, "n2", nx);
  sf_putfloat(vupdates, "d1", dz);
  sf_putfloat(vupdates, "d2", dx);
  sf_putstring(vupdates, "label1", "Depth");
  sf_putstring(vupdates, "label2", "Distance");
  sf_putstring(vupdates, "label3", "Iteration");
  sf_putint(vupdates, "n3", niter);
  sf_putint(vupdates, "d3", 1);
  sf_putint(vupdates, "o3", 1);
  sf_putint(grads, "n1", nz);
  sf_putint(grads, "n2", nx);
  sf_putint(grads, "n3", niter);
  sf_putfloat(grads, "d1", dz);
  sf_putfloat(grads, "d2", dx);
  sf_putint(grads, "d3", 1);
  sf_putint(grads, "o3", 1);
  sf_putstring(grads, "label1", "Depth");
  sf_putstring(grads, "label2", "Distance");
  sf_putstring(grads, "label3", "Iteration");
  sf_putint(illums, "n1", nz);
  sf_putint(illums, "n2", nx);
  sf_putfloat(illums, "d1", dz);
  sf_putfloat(illums, "d2", dx);
  sf_putint(illums, "n3", niter);
  sf_putint(illums, "d3", 1);
  sf_putint(illums, "o3", 1);
  sf_putint(objs, "n1", niter);
  sf_putint(objs, "n2", 1);
  sf_putfloat(objs, "d1", 1);
  sf_putfloat(objs, "o1", 1);
}
Exemple #13
0
int main(int argc, char* argv[])
{
    int n1, ia, na, ib, nb;
    float a0, b0, a1, b1, da, db, a, b, *trace, *filt;
    sf_file inp, out;
    
    sf_init(argc,argv);
    inp = sf_input("in");
    out = sf_output("out");

    if (!sf_histint(inp,"n1",&n1)) sf_error("No n1= in input");
    
    trace = sf_floatalloc(n1);
    filt = sf_floatalloc(n1);

    if (!sf_getint("na",&na)) na=1;
    if (!sf_getint("nb",&nb)) nb=1;
    if (!sf_getfloat("a0",&a0)) sf_error("Need a0=");
    if (!sf_getfloat("b0",&b0)) sf_error("Need b0=");
    if (!sf_getfloat("a1",&a1)) a1=a0;
    if (!sf_getfloat("b1",&b1)) b1=b0;

    da = (1 >= na)?0.: (a1-a0)/(na-1);
    db = (1 >= nb)?0.: (b1-b0)/(nb-1);

    sf_putint(out,"n2",na);
    sf_putint(out,"n3",nb);

    sf_putfloat(out,"o2",a0);
    sf_putfloat(out,"o3",b0);

    sf_putfloat(out,"d2",da);
    sf_putfloat(out,"d3",db);

    sf_floatread(trace,n1,inp);

    for (ib=0; ib < nb; ib++) {
	b = b0 + ib*db;
	for (ia=0; ia < na; ia++) {
	    a = a0 + ia*da;
	    locov_init(a,b);
	    locov_filt(n1,trace,filt);

	    sf_floatwrite(filt,n1,out);
	}
    }

    exit(0);
}
Exemple #14
0
int main(int argc, char* argv[])
{
    float x;	    /* trace value       */
    int ns=512;	    /* number of samples */
    int ntr=8;	    /* number of traces  */
    int dtime=16;   /* one way time in samples through "ocean" layer */
    float rbot=0.8; /* reflection strength of "ocean" bottom         */
    int h=100;	    /* location in samples of two way reverb train 	 */
    float amp=0.2;  /* strength of reflector */
    int loc=170;    /* location of reflector on trace 1 in time samples */
    int dip=12;	    /* dip of reflector in time samples */
    int i, j, k, sgn;
    float *trace;
    sf_file traces;

    sf_init(argc,argv);
    traces = sf_output("out");
    sf_setformat(traces,"native_float");
    sf_putint(traces,"n1",ns);
    sf_putint(traces,"n2",ntr);

    sf_putfloat(traces,"o1",0);
    sf_putfloat(traces,"d1",0.004);
    sf_putfloat(traces,"o2",1);
    sf_putfloat(traces,"d2",1);

    sf_putstring(traces,"label1","Time");
    sf_putstring(traces,"unit1","s");
    sf_putstring(traces,"label2","Trace");

    trace = sf_floatalloc(ns);

    for (j = 0; j < ntr; j++) {
        for (i = 0; i < ns; i++) {
            if (i >= h && ((i-h) % dtime == 0)) {
                k = (i-h)/dtime;
                sgn = (ISODD(k) ? -1 : 1);
                x = sgn * (k+1) * powf(rbot, k);
            } else {
                x = 0.0f;
            }
            if (i == loc + j*dip) x += amp;
            trace[i] = x;
        }
        sf_floatwrite(trace,ns,traces);
    }

    exit(0);
}
Exemple #15
0
void puthead2kx(sf_file Fo, int n1, int n2, float d1, float d2, float o1, float o2)
/*<  put head for (kx,kz) domain float-type 2D data sets>*/
{
        /* Read/Write axes */
        sf_putint(Fo,"n1",n1);
        sf_putint(Fo,"n2",n2);
        sf_putfloat(Fo,"d1",d1);
        sf_putfloat(Fo,"d2",d2);
        sf_putfloat(Fo,"o1",o1);
        sf_putfloat(Fo,"o2",o2);
        sf_putstring(Fo,"label1","kz");
        sf_putstring(Fo,"label2","kx");
        sf_putstring(Fo,"unit1","2*pi/m");
        sf_putstring(Fo,"unit2","2*pi/m");
}
Exemple #16
0
int main(int argc, char* argv[])
{
    int  i1, i2, n1,n2,n3,n12;
    float  s=0, *pp1, *pp2;
    sf_file inp1, inp2,  dif;

    sf_init(argc,argv);
    inp1 = sf_input("in");
    inp2 = sf_input("match");
    dif = sf_output("out");
    
    sf_putfloat(dif,"o2",0);
    sf_putfloat(dif,"o1",0);
    sf_putint(dif,"n1",1);  
    sf_putint(dif,"n2",1);    
	
    if (!sf_histint(inp1,"n1",&n1)) sf_error("No n1= in input");
    if (!sf_histint(inp1,"n2",&n2)) sf_error("No n2= in input");
    if (!sf_histint(inp1,"n3",&n3)) n3=1;

    n2 = sf_leftsize(inp1,1); /* left dimensions after the first one */
    n12 = n1*n2;
    
    if (n3!=1) {sf_putint(dif,"n3",1); sf_putint(dif,"d3",1); }
    
    pp1 = sf_floatalloc(n12);
    pp2 = sf_floatalloc(n12);
    sf_floatread(pp1,n12,inp1);
    sf_floatread(pp2,n12,inp2);

    for (i2=0; i2 < n2; i2++) {
	for (i1=0; i1 < n1; i1++) {
	    s = s + pow((pp1[i2*n1+i1]-pp2[i2*n1+i1]),2);
	}
    }
    
    sf_warning("The difference is %f", s );
    sf_floatwrite(&s,1,dif);
    exit(0);
}
Exemple #17
0
int main(int argc,char*argv[])
{
	sf_file in, out;
	int i1, i2, j2, i3, n1, n2, n3, nf;
	float **u1, **u2, sigma, d2;

	sf_init(argc,argv);

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

	n3 = sf_leftsize(in, 2);

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

	if (!sf_getfloat("sigma", &sigma)) sigma=1.0;
	/* sigma */
	if (!sf_getint("nf", &nf)) nf=100;
	/* frequency samples [0, 0.5] */

	d2 = SF_PI/(nf-1);

	sf_putint(out, "n2", nf);
	sf_putfloat(out, "d2", 0.5/(nf-1));
	dgauss_init(n1, 1.0/sigma);

	u1 = sf_floatalloc2(n1, n2);
	u2 = sf_floatalloc2(n1, nf);

	for (i3=0; i3<n3; i3++)
	{
		sf_floatread(u1[0], n1*n2, in);
		for(i1=0; i1<n1; i1++)
		{
			for (j2=0; j2<nf; j2++)
			for (i2=0; i2<n2; i2++)
			{
				u2[j2][i1] = u1[i2][i1] * dgauss_val(i2, d2*j2) 
					* powf(0.5/SF_PI, i2);
			}
		}
		sf_floatwrite(u2[0], n1*nf, out);
	}

	free(u1[0]);
	free(u2[0]);
	free(u1);
	free(u2);
	dgauss_close();
	exit(0);
}
Exemple #18
0
int main(int argc, char* argv[])
{
    int nx, nz, ix, iz;
    float* trace;
    float dx, dz, x[2];
    sf_file mod;

    sf_init (argc,argv);
    mod = sf_output("out");

    if (!sf_getint("nx",&nx)) nx=400; 
    /* horizontal dimension */
    if (!sf_getint("nz",&nz)) nz=800; 
    /* vertical dimension */

    dx = 1./(nx-1);
    dz = 2./(nz-1);

    sf_putint   (mod,"n1",nz); 
    sf_putfloat (mod,"d1",dz); 
    sf_putfloat (mod,"o1",0.);
    sf_putint   (mod,"n2",nx); 
    sf_putfloat (mod,"d2",dx); 
    sf_putfloat (mod,"o2",0.);
    sf_setformat (mod,"native_float");

    trace = sf_floatalloc(nz);

    for (ix = 0; ix < nx; ix++) {
	x[1] = ix*dx;
	for (iz = 0; iz < nz; iz++) {
	    x[0] = iz*dz;
	    trace[iz] = 1./sqrtf(symes_vel(NULL,x));
	}
	sf_floatwrite(trace,nz,mod);
    }

    exit (0);
}
Exemple #19
0
void write3dfdm(const char *file, float ***dat, fdm3d fdm) 
{
  sf_file f = sf_output(file);
  sf_putint(f, "n1", fdm->nzpad); sf_putfloat(f, "o1", fdm->ozpad); sf_putfloat(f, "d1", fdm->dz);
  sf_putint(f, "n2", fdm->nxpad); sf_putfloat(f, "o2", fdm->oxpad); sf_putfloat(f, "d2", fdm->dx);
  sf_putint(f, "n3", fdm->nypad); sf_putfloat(f, "o3", fdm->oypad); sf_putfloat(f, "d3", fdm->dy);
  sf_floatwrite(dat[0][0], fdm->nzpad*fdm->nxpad*fdm->nypad, f);
}
Exemple #20
0
void write3df(const char *file, float ***dat, int n1, int n2, int n3) 
{
  sf_file f = sf_output(file);
  sf_putint(f, "n1", n1); sf_putfloat(f, "o1", 0); sf_putfloat(f, "d1", 0);
  sf_putint(f, "n2", n2); sf_putfloat(f, "o2", 0); sf_putfloat(f, "d2", 0);
  sf_putint(f, "n3", n3); sf_putfloat(f, "o3", 0); sf_putfloat(f, "d3", 0);
  sf_floatwrite(dat[0][0], n1*n2*n3, f);
}
Exemple #21
0
void putf(sf_file so1, int nx, int nz, float dx, float dz)
{
    sf_putint (so1, "n3", 1);
    sf_putint (so1, "n2", nx);
    sf_putint (so1, "n1", nz);
    sf_putfloat (so1, "d3", 0);
    sf_putfloat (so1, "d2", dx);
    sf_putfloat (so1, "d1", dz);
    sf_putfloat (so1, "o3", 0);
    sf_putfloat (so1, "o2", 0);
    sf_putfloat (so1, "o1", 0);
}
Exemple #22
0
void puthead2dcommonshot(sf_file Fo, int n1, int n2, int n3, float d1, float d2, float d3, float o1, float o2, float o3)
/*<  put head for 2D (x,t) domain common-shot data sets>*/
{
        /* Read/Write axes */
        sf_putint(Fo,"n1",n1);
        sf_putint(Fo,"n2",n2);
        sf_putint(Fo,"n3",n3);
        sf_putfloat(Fo,"d1",d1);
        sf_putfloat(Fo,"d2",d2);
        sf_putfloat(Fo,"d3",d3);
        sf_putfloat(Fo,"o1",o1);
        sf_putfloat(Fo,"o2",o2);
        sf_putfloat(Fo,"o3",o3);
        sf_putstring(Fo,"label1","z");
        sf_putstring(Fo,"label2","x");
        sf_putstring(Fo,"label3","y");
        sf_putstring(Fo,"unit1","km");
        sf_putstring(Fo,"unit2","km");
        sf_putstring(Fo,"unit3","km");
}
Exemple #23
0
void puthead3kx(sf_file Fo, int n1, int n2, int n3, float d1, float d2, float d3, float o1, float o2, float o3)
/*<  put head for (ky,kx,kz) domain float-type 3D data sets>*/
{
        /* Read/Write axes */
        sf_putint(Fo,"n1",n1);
        sf_putint(Fo,"n2",n2);
        sf_putint(Fo,"n3",n3);
        sf_putfloat(Fo,"d1",d1);
        sf_putfloat(Fo,"d2",d2);
        sf_putfloat(Fo,"d3",d3);
        sf_putfloat(Fo,"o1",o1);
        sf_putfloat(Fo,"o2",o2);
        sf_putfloat(Fo,"o3",o3);
        sf_putstring(Fo,"label1","kz");
        sf_putstring(Fo,"label2","kx");
        sf_putstring(Fo,"label3","ky");
        sf_putstring(Fo,"unit1","2*pi/m");
        sf_putstring(Fo,"unit2","2*pi/m");
        sf_putstring(Fo,"unit3","2*pi/m");
}
Exemple #24
0
int main(int argc, char* argv[])
{
    bool inv;
    int nt, ny, nx, n1, n2, n3, i4, n4, ntxy;
    float o1, d1, o2, d2, o3, d3, eps;
    float ***slice, ***tstr, ***ystr, ***xstr, ***slice2;
    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_histint(in,"n2",&ny)) sf_error("No n2= in input");
       if (!sf_histint(in,"n3",&nx)) sf_error("No n3= in input");
    } else {
       if (!sf_histint(warp,"n1",&nt)) sf_error("No n1= in input");
       if (!sf_histint(warp,"n2",&ny)) sf_error("No n2= in input");
       if (!sf_histint(warp,"n3",&nx)) sf_error("No n3= in 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",&n3)) sf_error("No n3= in input");
    }
    n4 = sf_leftsize(in,3);

    ntxy= nt*ny*nx;

    if (inv && !sf_getint("n1",&n1)) n1=nt;
    if (!sf_getfloat("d1",&d1) && !sf_histfloat(in,"d1",&d1)) d1=1.;
    if (!sf_getfloat("o1",&o1) && !sf_histfloat(in,"o1",&o1)) o1=0.;
    
    if (inv && !sf_getint("n2",&n2)) n2=ny;
    if (!sf_getfloat("d2",&d2) && !sf_histfloat(in,"d2",&d2)) d2=1.;
    if (!sf_getfloat("o2",&o2) && !sf_histfloat(in,"o2",&o2)) o2=0.;

    if (inv && !sf_getint("n3",&n3)) n3=nx;
    /* output samples - for inv=y */
    if (!sf_getfloat("d3",&d3) && !sf_histfloat(in,"d3",&d3)) d3=1.;
    /*( d1=1 output sampling - for inv=y )*/
    if (!sf_getfloat("o3",&o3) && !sf_histfloat(in,"o3",&o3)) o3=0.;
    /*( o1=0 output origin - for inv=y )*/ 

    if (inv) {
       sf_putint(out,"n1",n1);
       sf_putfloat(out,"d1",d1);
       sf_putfloat(out,"o1",o1);

       sf_putint(out,"n2",n2);
       sf_putfloat(out,"d2",d2);
       sf_putfloat(out,"o2",o2);

       sf_putint(out,"n3",n3);
       sf_putfloat(out,"d3",d3);
       sf_putfloat(out,"o3",o3);
    } else {
       sf_putint(out,"n1",nt);
       sf_putint(out,"n2",ny);
       sf_putint(out,"n3",nx);
    }

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

    slice  = sf_floatalloc3(nt,ny,nx);
    tstr   = sf_floatalloc3(nt,ny,nx);
    xstr   = sf_floatalloc3(nt,ny,nx);
    ystr   = sf_floatalloc3(nt,ny,nx); 
    slice2 = sf_floatalloc3(n1,n2,n3);

    warp3_init(n1, o1, d1,
	       n2, o2, d2,
               n3, o3, d3,
	       nt, ny, nx, eps); 

    for (i4=0; i4 < n4; i4++) {
	sf_floatread(tstr[0][0],ntxy,warp);
        sf_floatread(ystr[0][0],ntxy,warp);
	sf_floatread(xstr[0][0],ntxy,warp);

        if (inv) {
            sf_floatread(slice[0][0],ntxy,in);
	    warp3(slice,tstr,ystr,xstr,slice2);
	    sf_floatwrite (slice2[0][0],n1*n2*n3,out);
        } else {	    
            sf_floatread(slice2[0][0],n1*n2*n3,in);
	    fwarp3(slice2,tstr,ystr,xstr,slice); 
	    sf_floatwrite (slice[0][0],ntxy,out);
        }
    }

    exit(0);
}
Exemple #25
0
int main(int argc, char* argv[])
{
    int n1, n2, n3, gainstep, panel, it, nreserve, i1, i2, i3, j, orient;
    float o1, o2, o3, d1, d2, d3, gpow, clip, pclip, phalf, bias=0., minmax[2];
    float pbias, gain=0., x1, y1, x2, y2, **data=NULL, f, barmin, barmax, dat;
    bool transp, yreverse, xreverse, allpos, polarity, symcp, verb;
    bool eclip=false, egpow=false, barreverse, mean=false;
    bool scalebar, nomin=true, nomax=true, framenum, sfbyte, sfbar, charin;
    char *gainpanel, *color, *barfile;
    unsigned char tbl[TSIZE+1], **buf, tmp, *barbuf[1];
    enum {GAIN_EACH=-3,GAIN_ALL=-2,NO_GAIN=-1};
    off_t pos;
    sf_file in, out=NULL, bar=NULL;
    
    sf_init(argc,argv);
    in = sf_input("in");

    sfbyte = (bool) (NULL != strstr (sf_getprog(),"byte"));
    sfbar = (bool) (NULL != strstr (sf_getprog(),"bar"));

    if (sfbyte) {
	out = sf_output("out");
	sf_settype(out,SF_UCHAR);
    } else if (sfbar) {
	bar = sf_output("out");
	sf_settype(bar,SF_UCHAR);
    } else {
	vp_init();
    }

    charin = (bool) (SF_UCHAR == sf_gettype(in));

    if (charin && sfbyte) sf_error("Cannot input uchar to byte");

    if (!charin && 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",&n2)) n2=1;
    n3 = sf_leftsize(in,2);

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

    if (!sf_histfloat(in,"d1",&d1)) d1=1.;
    if (!sf_histfloat(in,"d2",&d2)) d2=1.;
    if (!sf_histfloat(in,"d3",&d3)) d3=1.;

    if (!sf_getbool("transp",&transp)) transp=true;
    /* if y, transpose the display axes */
    if (!sf_getbool("yreverse",&yreverse)) yreverse=true;
    /* if y, reverse the vertical axis */
    if (!sf_getbool("xreverse",&xreverse)) xreverse=false;
    /* if y, reverse the horizontal axis */

    if (transp) {
	orient = 3;
    } else {	
	orient = (xreverse==yreverse)? 0:2;
    }

    if (!charin) {
	panel = NO_GAIN; /* no need for gain */
	
	phalf=85.;
	egpow = false;
	if (!sf_getfloat("gpow",&gpow)) {
	    gpow=1.;
	    /*( gpow=1 raise data to gpow power for display )*/
	} else if (gpow <= 0.) {
	    gpow=0.;
	    egpow = true;
	    sf_getfloat("phalf",&phalf);
	    /* percentage for estimating gpow */
	    if (phalf <=0. || phalf > 100.)
		sf_error("phalf=%g should be > 0 and <= 100",phalf);
	    panel = 0;
	}
	
	pclip=99.;
	eclip = (bool) (!sf_getfloat("clip",&clip));
	/* data clip */
	if (eclip) {	    
	    clip = 0.;
	    sf_getfloat("pclip",&pclip);
	    /* data clip percentile (default is 99) */
	    if (pclip <=0. || pclip > 100.)
		sf_error("pclip=%g should be > 0 and <= 100",pclip);
	    panel = 0;
	} else if (clip <= 0.) {
	    sf_warning("clip=%g <= 0",clip);
	    clip = FLT_EPSILON;
	}

	if (0==panel) {
	    if (!sf_getint("gainstep",&gainstep)) gainstep=0.5+n1/256.;
	    /* subsampling for gpow and clip estimation */
	    if (gainstep <= 0) gainstep=1;

	    gainpanel = sf_getstring("gainpanel");
	    /* gain reference: 'a' for all, 'e' for each, or number */
	    if (NULL != gainpanel) {
		switch (gainpanel[0]) {
		    case 'a': 
			panel=GAIN_ALL; 
			break;
		    case 'e': 
			panel=GAIN_EACH;
			break;
		    default:
			if (0 ==sscanf(gainpanel,"%d",&panel) || 
			    panel < 1 || panel > n3) 
			    sf_error("gainpanel= should be all,"
				     " each, or a number"
				     " between 1 and %d",n3);
			panel--;
			break;
		}
		free (gainpanel); 
	    } 

	    sf_unpipe(in,sf_filesize(in)*sizeof(float));
	} 

	if (!sf_getbool("allpos",&allpos)) allpos=false;
	/* if y, assume positive data */
	if (!sf_getbool("mean",&mean)) mean=false;
	/* if y, bias on the mean value */
	if (!sf_getfloat("bias",&pbias)) pbias=0.;
	/* value mapped to the center of the color table */
	if (!sf_getbool("polarity",&polarity)) polarity=false;
	/* if y, reverse polarity (white is high by default) */
	if (!sf_getbool("symcp",&symcp)) symcp=false;
	/* if y, assume symmetric color palette of 255 colors */
	if (!sf_getbool("verb",&verb)) verb=false;
	/* verbosity flag */
    } /* if !charin */

    barfile = sf_getstring("bar");
    /* file for scalebar data */

    if (sfbyte) {
	scalebar = (bool) (NULL != barfile);
	if (scalebar) sf_putstring(out,"bar",barfile);
    } else if (sfbar) {
	scalebar = true;
    } else {
	if (!sf_getbool ("wantscalebar",&scalebar) && 
	    !sf_getbool ("scalebar",&scalebar)) scalebar = false;
	/* if y, draw scalebar */	
    }
    if (scalebar) {
	nomin = (bool) (!sf_getfloat("minval",&barmin));
	/* minimum value for scalebar (default is the data minimum) */
	nomax = (bool) (!sf_getfloat("maxval",&barmax));
	/* maximum value for scalebar (default is the data maximum) */
	
	barbuf[0] = sf_ucharalloc(VP_BSIZE);

	if (!sf_getbool("barreverse",&barreverse)) barreverse=false;
	/* if y, go from small to large on the bar scale */

	if (sfbyte || sfbar) {
	    if (sfbyte) {
		bar = sf_output("bar");
		sf_settype(bar,SF_UCHAR);
	    }
	    sf_putint(bar,"n1",VP_BSIZE+2*sizeof(float));
	    sf_putint(bar,"n2",1);
	    sf_putint(bar,"n3",n3);

	    if (!nomin) sf_putfloat(bar,"minval",barmin);
	    if (!nomax) sf_putfloat(bar,"maxval",barmax);
	} else if (charin) {
	    if (NULL == barfile) {
		barfile=sf_histstring(in,"bar");
		if (NULL == barfile) sf_error("Need bar=");
	    }

	    bar = sf_input(barfile);
	    if (SF_UCHAR != sf_gettype(bar)) sf_error("Need uchar in bar");

	    if (nomin) nomin = (bool) (!sf_histfloat(bar,"minval",&barmin));
	    if (nomax) nomax = (bool) (!sf_histfloat(bar,"maxval",&barmax));
	}
    }

    if (!sf_getbool("wantframenum",&framenum)) framenum = (bool) (n3 > 1);
    /* if y, display third axis position in the corner */

    x1 = o1-0.5*d1;
    x2 = o1+(n1-1)*d1+0.5*d1;
    y1 = o2-0.5*d2;
    y2 = o2+(n2-1)*d2+0.5*d2;

    if (!sfbyte && !sfbar) {
	vp_stdplot_init (x1, x2, y1, y2, transp, false, yreverse, false);
	vp_frame_init(in,"tlb",false);
/*	if (scalebar && !nomin && !nomax) 
	vp_barframe_init (in,barmin,barmax); */
    }

    if (transp) {
	f=x1; x1=y1; y1=f;
	f=x2; x2=y2; y2=f;
    }

    if (yreverse) {
	f=y1; y1=y2; y2=f;
    }

    if (xreverse) {
	f=x1; x1=x2; x2=f;
    }

    buf = sf_ucharalloc2(n1,n2);

    if (!charin) {
	data = sf_floatalloc2(n1,n2);

	if (GAIN_ALL==panel || panel >= 0) {
	    pos = sf_tell(in);
	    if (panel > 0) sf_seek(in,
				   pos+panel*n1*n2*sizeof(float),
				   SEEK_SET);
	    vp_gainpar (in,data,n1,n2,gainstep,
			pclip,phalf,&clip,&gpow,mean,&pbias,
			n3,panel,panel);
	    if (verb) sf_warning("panel=%d bias=%g clip=%g gpow=%g",
				 panel,pbias,clip,gpow);
	    if (sfbyte) sf_putfloat(out,"clip",clip);
	    sf_seek(in,pos,SEEK_SET); /* rewind */
	}
    }

    if (!sfbyte && !sfbar) {
	/* initialize color table */
	if (NULL == (color = sf_getstring("color"))) color="i";
	/* color scheme (default is i) */
	if (!sf_getint ("nreserve",&nreserve)) nreserve = 8;
	/* reserved colors */
	vp_rascoltab (nreserve, color);
    }

    for (i3=0; i3 < n3; i3++) {	
	if (!charin) {
	    if (GAIN_EACH == panel) {
		if (eclip) clip=0.;
		if (egpow) gpow=0.;
		vp_gainpar (in,data,n1,n2,gainstep,
			    pclip,phalf,&clip,&gpow,
			    mean,&pbias,n3,0,n3);
		if (verb) sf_warning("bias=%g clip=%g gpow=%g",pbias,clip,gpow);
	    } else {
		sf_floatread(data[0],n1*n2,in);
	    }
	    
	    if (1 == panel || GAIN_EACH == panel || 0==i3) { 
		/* initialize the conversion table */
		if(!allpos) { /* negative and positive values */
		    for (it=1; it<=TSIZE/2; it++) {
		        if (symcp) {
			    tbl[TSIZE-it] = (gpow != 1.)?
			        254*(pow(((TSIZE-2.0*it)/TSIZE),gpow)+1.)/2.+1.:
			        254*(    ((TSIZE-2.0*it)/TSIZE)      +1.)/2.+1.;
			    tbl[it] = 255 - tbl[TSIZE-it] + 1.0;
			} else {
			    tbl[TSIZE-it] = (gpow != 1.)?
			        252*(pow(((TSIZE-2.0*it)/TSIZE),gpow)+1.)/2.+3.:
			        252*(    ((TSIZE-2.0*it)/TSIZE)      +1.)/2.+3.;
			    tbl[it] = 255 - tbl[TSIZE-it] + 2.0;
			}
		    }
		    bias = TSIZE/2.;
		    gain = TSIZE/(2.*clip);
		} else { /* all positive */
		    if (symcp) {
			for (it=1; it < TSIZE ; it++) {
			    tbl[it] = 255*((it-1.0)/TSIZE) + 1.0;
			}
		    } else {
			for (it=1; it < TSIZE ; it++) {
			    tbl[it] = 256*((it-1.0)/TSIZE);
			}
		    }
		    bias = 0.;
		    gain = TSIZE/clip;		
		}
		tbl[0] = tbl[1];
		tbl[TSIZE] = tbl[TSIZE-1];
		if (polarity) { /* switch polarity */
		    for (it=0; it<=TSIZE; it++) {
			tbl[it]=255-tbl[it];
		    }
		}
	    }
	    
	    /* convert to bytes */
	    for (i2=0; i2 < n2; i2++) {
		for (i1=0; i1 < n1; i1++) {
		    j = (data[i2][i1]-pbias)*gain + bias;
		    if      (j < 0) j=0;
		    else if (j > TSIZE) j=TSIZE;
		    buf[i2][i1] = tbl[j];
		}
	    }
	} else {
	    sf_ucharread(buf[0],n1*n2,in);
	}

	if (!sfbyte && !sfbar) {
	    if (yreverse) {
		for (i2=0; i2 < n2; i2++) {
		    for (i1=0; i1 < n1/2; i1++) {			
			tmp = buf[i2][i1];
			buf[i2][i1] = buf[i2][n1-1-i1];
			buf[i2][n1-1-i1] = tmp;
		    }
		}
	    } 
	    
	    if ((xreverse && transp) || (!xreverse && !transp)) {
		for (i2=0; i2 < n2/2; i2++) {
		    for (i1=0; i1 < n1; i1++) {
			tmp = buf[i2][i1];
			buf[i2][i1] = buf[n2-1-i2][i1];
			buf[n2-1-i2][i1] = tmp;
		    }
		}
	    }
	
	    if (i3 > 0) vp_erase (); 	

	    if (framenum) vp_framenum(o3+i3*d3);
	    vp_frame(); 
	    vp_uraster (buf, false, 256, n1, n2, 
			x1, y1, x2, y2, orient);
	    vp_simpleframe();
	}
	
	if (scalebar) {
	    if (!charin) {
		if (nomin) barmin = data[0][0];
		if (nomax) barmax = data[0][0];
		if (nomin || nomax) {
		    for (i2=0; i2 < n2; i2++) {
			for (i1=0; i1 < n1; i1++) {
			    dat = data[i2][i1];
			    if (nomin && barmin > dat) barmin = dat;
			    if (nomax && barmax < dat) barmax = dat;
			}
		    }
		}
		
		for (it=0; it < VP_BSIZE; it++) {
		    if (barreverse) {
			dat = (barmin*it + barmax*(VP_BSIZE-1-it))/(VP_BSIZE-1);
		    } else {
			dat = (barmax*it + barmin*(VP_BSIZE-1-it))/(VP_BSIZE-1);
		    }
		    j = (dat-pbias)*gain + bias;
		    if      (j < 0) j=0;
		    else if (j > TSIZE) j=TSIZE;
		    barbuf[0][it] = tbl[j];
		} 
	    } else {
		sf_floatread(minmax,2,bar);
		sf_ucharread(barbuf[0],VP_BSIZE,bar);

		if (nomin) barmin=minmax[0];
		if (nomax) barmax=minmax[1];
	    }

	    if (sfbyte || sfbar) {
		sf_floatwrite(&barmin,1,bar);
		sf_floatwrite(&barmax,1,bar);
		sf_ucharwrite(barbuf[0],VP_BSIZE,bar);
	    } else {
		if (barreverse) {
		    vp_barframe_init (in,barmax,barmin);
		} else {
		    vp_barframe_init (in,barmin,barmax);
		}
		vp_barraster(VP_BSIZE, barbuf);
	    }
	} /* if scalebar */

	if (sfbyte) {
	    sf_ucharwrite(buf[0],n1*n2,out);
	} else if (!sfbar) {
	    vp_purge();
	} 
    } /* i3 loop */


    exit (0);
}
Exemple #26
0
int main(int argc, char* argv[])
{
    int nt, nh, ncmp, it, icmp, ih, iw, w, zero, shift;
    float *indata, *outdata, *stack, *win1, *win2, *outweight;
    float dt,var, maxwin1, maxwin2, ee, esp, dh, dcmp,cmp0, t0, h0, /* sumab, sumwin1, sumwin2, */ sumweight, sft;

    sf_file in, out; 
    
    /* initialization */
    sf_init(argc,argv);
    in = sf_input("in");
    out = sf_output("out");
    
    
    /* get rsf_file parameters */
    if (!sf_histint(in,"n1",&nt)) sf_error("Need n1=");
    if (!sf_histfloat(in,"d1",&dt)) dt=1.;
    if (!sf_histfloat(in,"o1",&t0)) t0=0.;
    
    if (!sf_histint(in,"n2",&nh)) sf_error("Need n2=");
    if (!sf_histfloat(in,"d2",&dh)) dh=1.;
    if (!sf_histfloat(in,"o2",&h0)) h0=0.;

    if (!sf_histint(in,"n3",&ncmp)) ncmp=1;
    if (!sf_histfloat(in,"d3",&dcmp)) dcmp=1.;
    if (!sf_histfloat(in,"o3",&cmp0)) cmp0=0.;

    /* get other parameters */
    if (!sf_getint("w",&w)) w=50;  
    /* sliding window size*/    
    if (!sf_getfloat("sft",&sft)) sft=1;  
    /*weight shift*/
    if (!sf_getfloat("ee",&ee)) ee=1.0;      
    if (!sf_getfloat("esp",&esp)) esp=1.0;       
    
    sf_putint(out,"n1",nt);
    sf_putint(out,"n2",ncmp);

    sf_putfloat(out,"d1",dt);
    sf_putfloat(out,"o1",t0);
    sf_putfloat(out,"d2",dcmp);
    sf_putfloat(out,"o2",cmp0);
    sf_putint(out,"n3",1);
    
    
                  
    indata = sf_floatalloc(nt*nh);
    outdata = sf_floatalloc(nt);
    outweight = sf_floatalloc(nt*nh);
    stack = sf_floatalloc(nt);
    win1 = sf_floatalloc(w);
    win2 = sf_floatalloc(w);
 
    for (icmp=0; icmp < ncmp; icmp++){ 
        
         sf_floatread(indata,nt*nh,in);

         for (it=0; it < nt; it++){
              stack[it] = 0;
              outdata[it] = 0;
	      for (ih=0;ih<nh;ih++){
	           outweight[nt*ih+it]=0;
	      }
         }
	 
	 
         /* computer the directly stack trace */
         for (it=0; it < nt; it++){
              zero=0;
              for(ih=0; ih < nh; ih++){
                 if (indata[ih*nt+it]!=0)
                     zero++;
                 
                 stack[it]+= indata[ih*nt+it];
              }
              if (zero==0)
              stack[it]=stack[it];
              else 
              stack[it]=stack[it]/zero;
         }         
         /* estimate the noise variances */
         for (it=0; it < nt; it++){ 
              zero = 0;
	       sumweight=0;
              for (ih=0; ih < nh; ih++){
		  /* sumwin1 = 0;
                    sumwin2 = 0;
                    sumab = 0; */
                   shift = SF_MAX(0,SF_MIN(nt-w, it-w/2-1));
		   /* weight=0; */
		   var=0;
		   maxwin1=0;
		   maxwin2=0;
                   for (iw=0; iw <w; iw++){
                        win1[iw] = indata[ih*nt+iw+shift];
                        win2[iw] = stack[iw+shift];
			if (fabs(win1[iw])>fabs(maxwin1))
			     maxwin1 = fabs(win1[iw]);
			if (fabs(win2[iw])>fabs(maxwin2))
			     maxwin2 = fabs(win2[iw]);
	           }
		   for (iw=0; iw <w; iw++){		     
			var += fabs(win1[iw]/maxwin1-win2[iw]/maxwin2)*fabs(win1[iw]/maxwin1-win2[iw]/maxwin2);    
                   }
                   outweight[nt*ih+it] =1./(var+ee); 
                   
                   if (indata[ih*nt+it]!=0){
                     zero++;
                     outdata[it] += pow(1./(var+ee),1)*indata[ih*nt+it];
                     sumweight +=  pow(1./(var+ee),1);
		   }
              }
              if (zero==0)
                  outdata[it]=0;              
              else     
                  outdata[it] = outdata[it]/(zero*sumweight+esp);
              
         }
	 
         sf_floatwrite(outdata,nt,out);
         sf_warning("running cmp is = %d of %d",icmp, ncmp); 
     }

    exit(0);
}
Exemple #27
0
void shot_image_init(float dx,float dy,float dz,int nz,struct shot_image_par_type *image_par)
/*< initialize image >*/
{
    sf_file imagex, imagez;
    float *tmpimg;
    float ohx,ohy;
    int i; 

    tmpimg=sf_floatalloc(nz);
 
    vector_value_f(tmpimg,0.0,nz);
    image_par->dx=dx; image_par->dy=dy; image_par->dz=dz;
    image_par->nx=(image_par->max_x-image_par->min_x)/(image_par->dx)+1;
    image_par->ny=(image_par->max_y-image_par->min_y)/(image_par->dy)+1;
    image_par->nz=nz;
    if (!sf_getfloat("imageohx",&ohx)) ohx=-image_par->dx*image_par->nhx/2;
    if (!sf_getfloat("imageohy",&ohy)) ohy=-image_par->dy*image_par->nhy/2;
    image_par->ohx=ohx;   image_par->ohy=ohy;
    
    imagex = sf_output("Image_hx");
    imagez = sf_output("Image_hz");

    sf_putfloat(imagex,"o1",0.0);              sf_putfloat(imagex,"d1",image_par->dz); sf_putint(imagex,"n1",image_par->nz);
    sf_putfloat(imagex,"o2",image_par->ohx);   sf_putfloat(imagex,"d2",image_par->dx); sf_putint(imagex,"n2",image_par->nhx);
    sf_putfloat(imagex,"o3",image_par->ohy);   sf_putfloat(imagex,"d3",image_par->dy); sf_putint(imagex,"n3",image_par->nhy);
    sf_putfloat(imagex,"o4",image_par->min_x); sf_putfloat(imagex,"d4",image_par->dx); sf_putint(imagex,"n4",image_par->nx);
    sf_putfloat(imagex,"o5",image_par->min_y); sf_putfloat(imagex,"d5",image_par->dy); sf_putint(imagex,"n5",image_par->ny);

    sf_putfloat(imagez,"o1",0.0);              sf_putfloat(imagez,"d1",image_par->dz); sf_putint(imagez,"n1",image_par->nz);
    sf_putfloat(imagez,"o2",image_par->ohx);   sf_putfloat(imagez,"d2",image_par->dx); sf_putint(imagez,"n2",image_par->nhx);
    sf_putfloat(imagez,"o3",image_par->ohy);   sf_putfloat(imagez,"d3",image_par->dy); sf_putint(imagez,"n3",image_par->nhy);
    sf_putfloat(imagez,"o4",image_par->min_x); sf_putfloat(imagez,"d4",image_par->dx); sf_putint(imagez,"n4",image_par->nx);
    sf_putfloat(imagez,"o5",image_par->min_y); sf_putfloat(imagez,"d5",image_par->dy); sf_putint(imagez,"n5",image_par->ny);

    for(i=0;i<image_par->ny*image_par->nx*image_par->nhy*image_par->nhx;i++) {
	sf_floatwrite(tmpimg,image_par->nz,imagex);
	sf_floatwrite(tmpimg,image_par->nz,imagez);
    }
    free(tmpimg);

    image_par->imagex = imagex;
    image_par->imagez = imagez;
}
Exemple #28
0
int main(int argc, char* argv[]) 
{
    int nx, nz, nt, ix, iz, it, nbt, nbb, nxl, nxr,  nxb, nyb, nzb, isx, isz;
    float dt, dx, dy, dz, o1, o2, o3;
    float **old,  **cur,  **tmp, *wav;
    float  **v, **vtmp, v0, **sigma, **delta, **seta;
    float ***aa, w, g1, g2, czt, czb, cxl, cxr; /* top, bottom, left, right */
    float ax, az, factor;
    sf_file out, vel, source, fsigma, fdelta, fseta;
    int opt, snap, nsnap;    /* optimal padding */
     
    sf_init(argc,argv);
    out = sf_output("out");
    vel = sf_input("vel");   /* velocity */
    fsigma = sf_input("sigma");   /* velocity */
    fdelta = sf_input("delta");   /* velocity */
    fseta  = sf_input("seta");   /* velocity */
    source = sf_input("in");   /* source wavlet*/

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

	if (!sf_histint(vel,"n1",&nz)) sf_error("No n1= in input");
	if (!sf_histfloat(vel,"d1",&dz)) sf_error("No d1= in input");
    if (!sf_histint(vel,"n2",&nx)) sf_error("No n2= in input");
    if (!sf_histfloat(vel,"d2",&dx)) sf_error("No d2= in input");
    if (!sf_histfloat(vel,"o1",&o1)) o1=0.0;
    if (!sf_histfloat(vel,"o2",&o2)) o2=0.0;

    
	if (!sf_getint("opt",&opt)) opt=1;
    /* if y, determine optimal size for efficiency */

    if (!sf_getfloat("dt",&dt)) sf_error("Need dt input");
    if (!sf_getint("nt",&nt)) sf_error("Need nt input");
    if (!sf_getint("isx",&isx)) sf_error("Need isx input");
    if (!sf_getint("isz",&isz)) sf_error("Need isz input");

    if (!sf_getint("nbt",&nbt)) nbt=44;
    if (!sf_getint("nbb",&nbb)) nbb=44;
    if (!sf_getint("nxl",&nxl)) nxl=44;
    if (!sf_getint("nxr",&nxr)) nxr=44;
	
	/* assume ABC pars are the same */
	if (nbt != nbb || nxl != nxr || nbt!=nxl) 
		sf_error("ABC pars are not the same");

    if (!sf_getfloat("czt",&czt))  czt = 0.01; /*decaying parameter*/
    if (!sf_getfloat("czb",&czb))  czb = 0.01; /*decaying parameter*/
    if (!sf_getfloat("cxl",&cxl)) cxl = 0.01; /*decaying parameter*/
    if (!sf_getfloat("cxr",&cxr)) cxr = 0.01; /*decaying parameter*/
	 if (!sf_getint("snap",&snap)) snap=1;
	 nsnap=0;
	 for (it=0; it < nt; it++) {
			if (it%snap == 0) nsnap++;
	  }

    sf_putfloat(out,"d1",dz);
    sf_putfloat(out,"d2",dx);
    sf_putfloat(out,"d3",dt*snap);
    sf_putfloat(out,"o1",o1); 
    sf_putfloat(out,"o2",o2); 
    sf_putfloat(out,"o3",0.0); 

    nxb = nx + nxl + nxr;
    nzb = nz + nbt + nbb;
    
	sf_putint(out,"n1",nzb);
    sf_putint(out,"n2",nxb);
    sf_putint(out,"n3",nsnap);


    wav    =  sf_floatalloc(nt);
    sf_floatread(wav,nt,source);

    old    =  sf_floatalloc2(nzb,nxb);
    cur    =  sf_floatalloc2(nzb,nxb);
    aa     =  sf_floatalloc3(nzb,nxb,3);
    

    bd2_init(nx,nz,nxl,nxr,nbt,nbb,cxl,cxr,czt,czb);

    /*input & extend velocity model*/
    v = sf_floatalloc2(nzb,nxb);
    vtmp = sf_floatalloc2(nz,nx);
    sf_floatread(vtmp[0],nx*nz,vel);
	v = extmodel(vtmp, nz, nx, nbt);

    sigma = sf_floatalloc2(nzb,nxb);
    sf_floatread(vtmp[0],nx*nz,fsigma);
	sigma = extmodel(vtmp, nz, nx, nbt);

    delta = sf_floatalloc2(nzb,nxb);
    sf_floatread(vtmp[0],nx*nz,fdelta);
	delta = extmodel(vtmp, nz, nx, nbt);
    
    seta = sf_floatalloc2(nzb,nxb);
    sf_floatread(vtmp[0],nx*nz,fseta);
	seta = extmodel(vtmp, nz, nx, nbt);

    v0 =0.0;
    for (ix=0; ix < nxb; ix++) {
        for (iz=0; iz < nzb; iz++) {
            v0 += v[ix][iz]*v[ix][iz];
         }
    }

    v0 = sqrtf(v0/(nxb*nzb));

	fprintf(stderr, "v0=%f\n\n", v0);


    for (ix=0; ix < nxb; ix++) {
        for (iz=0; iz < nzb; iz++) {
            cur[ix][iz] = 0.0;
            old[ix][iz] = 0.0; 
        }
    }

    /* propagation in time */
    pamstep2_init(nzb,nxb,dz,dx,opt);

    for (it=0; it < nt; it++) {
		fprintf(stderr, "\b\b\b\b\b%d", it);

        pamstep2(old, cur, nzb, nxb, dz, dx, v0, v, sigma, delta, seta, dt); 
        old[isx+nxl][isz+nbt] += wav[it];
     
		bd2_decay(old); 
        bd2_decay(cur); 
        tmp = old;
        old = cur;
        cur = tmp;

		if (it%nsnap==0)
		sf_floatwrite(cur[0], nxb*nzb, out);

    }

    pamstep2_close();
    bd2_close();

    free(**aa);
    free(*aa);
    free(aa);
    free(*v);     
    free(*sigma);     
    free(*delta);     
    free(*seta);     
	free(*vtmp);
    free(*cur);     
    free(*old);     
    free(v);     
    free(sigma);     
    free(delta);     
    free(seta);     
	free(vtmp);
    free(cur);     
    free(old);     
    exit(0); 
}           
Exemple #29
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);
}
Exemple #30
0
int main(int argc, char* argv[])
{
    const int nt=300, nx=64, nz=300, nb=50; 
    int it, ib, iz, ix;
    float v=1.,t,z,x,x0, theta, *b, **tdat, **zdat;
    float top=3.2, c1=.9, c2=6.8, d1=0.02, d2=0.12, r;
    sf_file c, d;

    sf_init(argc,argv);
    
    b = sf_floatalloc(nb);
    tdat = sf_floatalloc2(nt,nx);
    zdat = sf_floatalloc2(nz,nx);

    if (!sf_getfloat("top",&top)) top=5.;
    if (!sf_getfloat("c1",&c1)) c1=0.5;
    if (!sf_getfloat("c2",&c2)) c2=5.;

    vp_init();

    vp_uorig (-c1,-.5);
    vp_uclip (0.,top-3.,4.,top);
    vp_umove (0.,top-0.);  
    vp_udraw (0.,top-4.);
    vp_umove (0.,top-0.);  
    vp_udraw (4.,top-0.);

    for (z=.4; z < 4.; z += .4) {
	vp_penup ();
	x0 = z * tanf( SF_PI*45./180.);
	for (x=0.; x < 4.; x += .01) {
	    t = hypotf(z,x-x0)/v;
	    vp_upendn (x,top-t);
	}
    }

    	
    for (ib=0; ib < nb; ib++) {
	b[ib] = expf(-3.*(ib+1.)/20.) * sinf(SF_PI*(ib+1.)/10.);
    }
    
    if (NULL != sf_getstring("c")) {
	c = sf_output("c");
	sf_setformat(c,"native_float");
	sf_putint(c,"n1",nt);
	sf_putint(c,"n2",nx);
	sf_putfloat(c,"d1",d1);
	sf_putfloat(c,"d2",d2);
	
	for (ix=0; ix < nx; ix++) {
	    for (it=0; it < nt; it++) {
		tdat[ix][it] = 0.;
	    }
	}
	
	for (iz=0; iz < 12; iz++) {
	    z = (iz+1.)*nt/12.;
	    x0 = z * tanf( SF_PI*45./180.);
	    for (ix=0; ix < nx; ix++) {
		x = (ix+1.) * d2/d1;
		t = hypotf(z,x-x0)/v;
		for (ib=0; ib < nb; ib++) {
		    it = t+ib-1;
		    if (it < nt) tdat[ix][it] += b[ib];
		}
	    }
	}

	sf_floatwrite(tdat[0],nt*nx,c);
    }

    vp_uorig (-c2,-.5);
    vp_uclip (0.,top-3.,4.,top);
    vp_umove (0.,top-0.);  
    vp_udraw (0.,top-4.);
    vp_umove (0.,top-0.);   
    vp_udraw (4.,top-0.);

    for(t=.4; t<6.; t += .4) {
	vp_penup ();
	x0 = t / sinf( SF_PI*45./180.);
	for (theta=-89.5; theta<89.5; theta += 1.) {
	    z =      t * cosf (SF_PI*theta/180.);
	    x = x0 + t * sinf (SF_PI*theta/180.);
	    vp_upendn (x,top-z);
	}
    }

    if (NULL != sf_getstring("d")) {
	d = sf_output("d");
	sf_setformat(d,"native_float");
	sf_putint(d,"n1",nz);
	sf_putint(d,"n2",nx);
	sf_putfloat(d,"d1",d1);
	sf_putfloat(d,"d1",d2);
	
	for (ix=0; ix < nx; ix++) {
	    for (iz=0; iz < nz; iz++) {
	    zdat[ix][iz] = 0.;
	    }
	}
	
	for (it=0; it < 20; it++) {
	    t = (it+1.)*nz/20.;
	    x0 = t / sinf( SF_PI*45./180.);
	    for (theta=-89.5; theta<89.5; theta += 1.) {
		z =      t * cosf (SF_PI*theta/180.);
		x = x0 + t * sinf (SF_PI*theta/180.);
		ix = x * d1/d2;
		r = hypotf(z,x-x0);
		for (ib=0; ib < nb; ib++) {
		    iz = z + ib-1;
		    if (iz >= 0 && iz < nz && ix >=0 && ix < nx)
			zdat[ix][iz] += b[ib]*r;
		}
	    }
	}
	
	sf_floatwrite(zdat[0],nz*nx,d);
    }

    exit(0);
}