예제 #1
0
파일: parallel.c 프로젝트: housian0724/src
void sf_out(sf_file out        /* output file */, 
	    int axis           /* join axis */,
	    const char *iname  /* name of the input file */)
/*< prepare output >*/
{
    char *oname, cmdline[SF_CMDLEN];
    int ndim;
    off_t n[SF_MAX_DIM];
    sf_file inp;
    FILE *ofile=NULL;

    ofile = sf_tempfile(&oname,"w+b");
    fclose(ofile);

    snprintf(cmdline,SF_CMDLEN,"%s %s --dryrun=y < %s > %s",
	     command,splitcommand,iname,oname);
    sf_system(cmdline);
    
    inp = sf_input(oname);
    ndim = sf_largefiledims (inp,n);
    
    if (axis > ndim) axis=ndim;

    snprintf(nkey,5,"n%d",axis);
    axis--;
    sizes(inp,axis,ndim,n,&size1,&size2);
    
    sf_setformat(out,sf_histstring(inp,"data_format"));
    sf_fileflush(out,inp);
    
    sf_setform(out,SF_NATIVE);
    sf_rm(oname,true,false,false);
}
예제 #2
0
파일: Mhale.c 프로젝트: 1014511134/src
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);
}
예제 #3
0
파일: Mangle2.c 프로젝트: 1014511134/src
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);
}
예제 #4
0
파일: traces.c 프로젝트: krushev36/src
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);
}
예제 #5
0
파일: Msymes.c 프로젝트: 1014511134/src
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);
}
예제 #6
0
파일: Msag.c 프로젝트: 1014511134/src
int main(int argc, char* argv[])
{
    int nt, nx, it,ix;
    float t,t0,dt, x,x0,dx, z; 
    float tmax,xmax,delx, dxdz,v0,alpha;
    float** datr;
    sf_file sag;

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

    if (!sf_getint ("nt",&nt)) nt = 200;
    /* Number of samples in time */
    if (!sf_getint ("nx",&nx)) nx = 200;
    /* Number of samples in distance */

    if (!sf_getfloat ("tmax",&tmax)) tmax = 4.;
    /* Maximum time */
    if (!sf_getfloat ("xmax",&xmax)) xmax = 4.;
    /* Maximum distance */
    if (!sf_getfloat ("delx",&delx)) delx = .5;
    /* Increment in x */
    if (!sf_getfloat ("dxdz",&dxdz)) dxdz = 1.;
    /* Slope for the line of diffractors */
    if (!sf_getfloat ("v0",&v0)) v0 = 1.5;
    /* Initial velocity */
    if (!sf_getfloat ("alpha",&alpha)) alpha = 0.;
    /* Velocity gradient */

    t0 = 0;		
    x0 = 0.;
    dt = tmax / nt;
    dx = xmax / nx;

    sf_setformat(sag,"native_float");    
    sf_putint (sag,"n1",nt); 
    sf_putfloat (sag,"o1",t0); 
    sf_putfloat (sag,"d1",dt);
    sf_putint (sag,"n2",nx); 
    sf_putfloat (sag,"o2",x0); 
    sf_putfloat (sag,"d2",dx);
    sf_putstring (sag,"label1","Pseudo-depth (s)");
    sf_putstring (sag,"label2","Lateral (km)");

    datr = sf_floatalloc2(nt,nx);
    for (ix=0; ix < nx; ix++) {
	for (it=0; it < nt; it++) {
	    datr[ix][it] = 0.;
	}
    }

    for (x = delx/2; x <= xmax; x+= delx) {
	z = x / dxdz;
	if( alpha != 0.) {
	    t = 2. * log( 1. + alpha * z / v0) / alpha;
	} else {		 
	    t = 2. * z / v0;
	}
	it = 0.5 + t/dt;
	ix = 0.5 + x/dx;
	if(ix < nx && it < nt) datr[ix][it] += 1.;
    }

    sf_floatwrite (datr[0],nt*nx,sag);

    exit (0);
}
예제 #7
0
파일: spike.c 프로젝트: 1014511134/src
int main(int argc, char* argv[])
{ 
    int i, j, is, ip, dim, n[SF_MAX_DIM], ii[SF_MAX_DIM];
    int nsp, **k=NULL, **l=NULL, n1, n2, i1, i2, kk, ll;
    char key[7];
    const char *label, *unit;
    float f, *trace, *mag=NULL, **p=NULL, pp;
    sf_file in, spike;

    sf_init (argc,argv);

    if (!sf_stdin()) { /* no input file in stdin */
	in = NULL;
    } else {
	in = sf_input("in");
    }

    spike = sf_output("out");
    
    if (NULL == in) {
	sf_setformat(spike,"native_float");
    } else if (SF_FLOAT != sf_gettype(in)) {
	sf_error("Need float input");
    }
    
    /* dimensions */
    for (i=0; i < SF_MAX_DIM; i++) {
	snprintf(key,3,"n%d",i+1);
	if (!sf_getint(key,n+i) && 
	    (NULL == in || !sf_histint(in,key,n+i))) break;
	/*( n# size of #-th axis )*/  
	sf_putint(spike,key,n[i]);
    }

    if (0==i) sf_error("Need n1=");
    dim=i;
    
    /* basic parameters */
    for (i=0; i < dim; i++) {
	snprintf(key,3,"o%d",i+1);
	if (!sf_getfloat(key,&f) && 
	    (NULL == in || !sf_histfloat(in,key,&f))) f=0.;
	/*( o#=[0,0,...] origin on #-th axis )*/  
	sf_putfloat(spike,key,f);

	snprintf(key,3,"d%d",i+1);
	if (!sf_getfloat(key,&f) &&
	    (NULL == in || !sf_histfloat(in,key,&f))) f = (i==0)? 0.004: 0.1;
	/*( d#=[0.004,0.1,0.1,...] sampling on #-th axis )*/  
	sf_putfloat(spike,key,f);

	snprintf(key,7,"label%d",i+1);
	if (NULL == (label = sf_getstring(key)) &&
	    (NULL == in || NULL == (label = sf_histstring(in,key))))
	    label = (i==0)? "Time":"Distance";
	/*( label#=[Time,Distance,Distance,...] label on #-th axis )*/  
	if (*label != '\0' && (*label != ' ' || *(label+1) != '\0')) 	
	    sf_putstring(spike,key,label);

	snprintf(key,6,"unit%d",i+1);
	if (NULL == (unit = sf_getstring(key)) &&
	    (NULL == in || NULL == (unit = sf_histstring(in,key))))
	    unit = (i==0)? "s":"km";
        /*( unit#=[s,km,km,...] unit on #-th axis )*/  
	if (*unit != '\0' && (*unit != ' ' || *(unit+1) != '\0')) 	
	    sf_putstring(spike,key,unit);
    }
	
    if (NULL != (label = sf_getstring("title")))
	sf_putstring(spike,"title",label);
    /* title for plots */

    if (!sf_getint("nsp",&nsp)) nsp=1;
    /* Number of spikes */

    if (nsp >= 1) { 
	mag = sf_floatalloc (nsp);
	k = sf_intalloc2 (nsp,dim);
	l = sf_intalloc2 (nsp,dim);
	p = sf_floatalloc2 (nsp,dim);
    
	for (i=0; i < dim; i++) {
	    snprintf(key,3,"k%d",i+1);
	    if ( !sf_getints(key,k[i],nsp)) {
		/*( k#=[0,...] spike starting position )*/
		for (is=0; is < nsp; is++) {
		    k[i][is]=-1;
		}
	    } else {
		for (is=0; is < nsp; is++) {
		    if (k[i][is] > n[i]) 
			sf_error("Invalid k%d[%d]=%d > n%d=%d",
				 i+1,is+1,k[i][is],i+1,n[i]);
		    k[i][is]--; /* C notation */
		}
	    }
	    snprintf(key,3,"l%d",i+1);
	    if (!sf_getints(key,l[i],nsp)) {
		/*( l#=[k1,k2,...] spike ending position )*/
		for (is=0; is < nsp; is++) {
		    l[i][is]=k[i][is];
		}
	    } else {
		for (is=0; is < nsp; is++) {
		    if (l[i][is] > n[i]) 
			sf_error("Invalid l%d[%d]=%d > n%d=%d",
				 i+1,is+1,l[i][is],i+1,n[i]);
		    l[i][is]--; /* C notation */
		}
	    }	
	    snprintf(key,3,"p%d",i+1);
	    if (!sf_getfloats(key,p[i],nsp)) {
		/*( p#=[0,...] spike inclination (in samples) )*/
		for (is=0; is < nsp; is++) {
		    p[i][is]=0.;
		}
	    }
	}
	
	if (!sf_getfloats("mag",mag,nsp)) {
	    /* spike magnitudes */
	    for (is=0; is < nsp; is++) {
		mag[is]=1.;
	    }
	}
    }

    n1 = n[0];
    n2 = sf_leftsize(spike,1);

    trace = sf_floatalloc (n[0]);

    for (i2=0; i2 < n2; i2++) { /* loop over traces */
	sf_line2cart(dim-1, n+1, i2, ii+1);
	/* zero trace */
	for (i1=0; i1 < n1; i1++) trace[i1]=0.;
	/* put spikes in it */
	for (is=0; is < nsp; is++) { /* loop over spikes */
	    pp = 0.;
	    for (i=1; i < dim; i++) {
		kk = k[i][is];
		ll = l[i][is];
		if ((kk < -1 && ll < -1) || 
		    (kk >= 0 && ll >= 0 && 
		     (kk > ii[i] || ll < ii[i]))) break;
		pp += p[i][is]*(ii[i]-k[i][is]-1);
	    }
	    if (i < dim) continue; /* skip this spike */

	    /* linear interpolation */
	    ip = floorf(pp);
	    pp = 1.-(pp-ip);

	    kk = k[0][is];
	    ll = l[0][is];
	    if (kk >= 0) { /* one segment per trace */
		kk = SF_MAX(kk+ip,0);
		ll = SF_MIN(ll+ip,n1-1);
	    } else {
		kk = SF_MAX(ip,0);
		ll = SF_MIN(n1-1+ip,n1-1);
	    }

	    for (j=kk; j <= ll; j++) {
		trace[j] += pp*mag[is];
		if (j+1 < n1) trace[j+1] += (1.-pp)*mag[is];
	    }
	}
	sf_floatwrite(trace,n1,spike);
    }

    exit (0);
}
예제 #8
0
파일: Mwavemovie.c 프로젝트: 1014511134/src
int main(int argc, char* argv[])
{
    bool impresp;
    int nt,nx,nz,nw,init,i,padfactor,nfilt,nkol,it,ix,iz,iw;
    float v,dx,dz,lambda,sixth,gamma,epsdamp,pi2,dw,dt, w,wov;
    sf_complex wov2, a, b, c, d, cshift;
    float ***ppp;
    sf_complex *pp, *qq;
    cfilter aa, fac1, fac2;
    sf_file out, imp=NULL;

    sf_init(argc,argv);
    out = sf_output("out");
    sf_setformat(out,"native_float");

    if (!sf_getint("nz",&nz)) nz=96;
    if (!sf_getint("nx",&nx)) nx=48;
    if (!sf_getint("nt",&nt)) nt=12;
    if (!sf_getint("nw",&nw)) nw=2;
    if (!sf_getint("init",&init)) init=1;

    if (!sf_getfloat("v",&v)) v=1.;
    if (!sf_getfloat("dz",&dz)) dz=1.;
    if (!sf_getfloat("dx",&dx)) dx=2.;
    if (!sf_getfloat("lambda",&lambda)) lambda=nz*dz/4.;

    sf_putint(out,"n1",nz);
    sf_putint(out,"n2",nx);
    sf_putint(out,"n3",nt);

    aa = allocatechelix(9);

    if (!sf_getfloat("sixth",&sixth)) sixth=0.0833;
    if (!sf_getfloat("gamma",&gamma)) gamma=0.667;
    if (!sf_getfloat("epsdamp",&epsdamp)) epsdamp=0.01;
    if (!sf_getint("padfactor",&padfactor)) padfactor=1024;
    if (!sf_getint("nfilt",&nfilt)) nfilt=nx+2;
    if (!sf_getbool("impresp",&impresp)) impresp=false;

    if (impresp) {
	imp = sf_output("imp");
	sf_setformat(imp,"native_complex");
	sf_putint(imp,"n1",2*nx);
	sf_putint(imp,"n2",2);
    }

    ppp = sf_floatalloc3(nz,nx,nt);
    pp = sf_complexalloc(nx*nz);
    qq = sf_complexalloc(nx*nz);

    pi2 = 2.*SF_PI;
    dw = v*pi2/lambda;
    dt =   pi2/(nt*dw);

    nkol=pad2(padfactor*nx);
    /* dkol=pi2/nkol; */

    for (it=0; it < nt; it++) {
	for (ix=0; ix < nx; ix++) {
	    for (iz=0; iz < nz; iz++) {
		ppp[it][ix][iz] = 0.;
	    }
	}
    }

    fac1 = allocatechelix(nfilt);
    fac2 = allocatechelix(nfilt);
    helimakelag(fac1,nx,nz);
    helimakelag(fac2,nx,nz);

    xkolmog_init(nkol);

    for (iw=0; iw < nw; iw++) { /* frequency loop */
	w = (iw+1)*dw;

	if (impresp) w=dw*nw/2;

	wov = w/v;
	wov2 = sf_cmplx(epsdamp,wov);
#ifdef SF_HAS_COMPLEX_H
	wov2 = -wov2*wov2;
#else
	wov2 = sf_cneg(sf_cmul(wov2,wov2));
#endif

	sf_warning("%g %g (%d of %d)",crealf(wov2),cimagf(wov2),iw,nw);

	init_wave(init,nx,dx,nz,dz,pp,wov,nw,iw);

	for (iz=0; iz < nx*nz; iz++) {
	    qq[iz]=sf_cmplx(0.,0.);
	}

	/* isotropic laplacian = 5-point laplacian */
	a= sf_cmplx(0.,0.);
#ifdef SF_HAS_COMPLEX_H
	b= gamma*(1+sixth*wov2)* (-1./(dz*dz));
	c= gamma*(1+sixth*wov2)* (-1./(dx*dx));
	d= gamma*(1+sixth*wov2)* (2/(dx*dx) + 2/(dz*dz))  -wov2;
#else
	b = sf_crmul(sf_cadd(sf_cmplx(1.,0.),sf_crmul(wov2,sixth)),
		     gamma*(-1./(dz*dz)));
	c = sf_crmul(sf_cadd(sf_cmplx(1.,0.),sf_crmul(wov2,sixth)),
		     gamma*(-1./(dx*dx)));
	d = sf_cadd(sf_crmul(sf_cadd(sf_cmplx(1.,0.),sf_crmul(wov2,sixth)),
			     gamma*(2/(dx*dx) + 2/(dz*dz))),sf_cneg(wov2));
#endif

	/* + rotated 5-point laplacian */
#ifdef SF_HAS_COMPLEX_H
	a += (1-gamma)*(1+sixth*wov2)* (-0.5/(dx*dz));
	b += (1-gamma)*(1+sixth*wov2)*0.;
	c += (1-gamma)*(1+sixth*wov2)*0.;
	d += (1-gamma)*(1+sixth*wov2)* 2.0/(dx*dz);
#else
	a = sf_cadd(a,sf_crmul(sf_cadd(sf_cmplx(1.0,0.0),
				       sf_crmul(wov2,sixth)),
			       (1-gamma)*(-0.5/(dx*dz))));
	d = sf_cadd(d,sf_crmul(sf_cadd(sf_cmplx(1.0,0.0),
				       sf_crmul(wov2,sixth)),
			       (1-gamma)*(2.0/(dx*dz))));
#endif

	aa->flt[0] = a; aa->lag[0] = -nx-1;
	aa->flt[1] = b; aa->lag[1] = -nx;
	aa->flt[2] = a; aa->lag[2] = -nx+1;

	aa->flt[3] = c; aa->lag[3] = -1;
	aa->flt[4] = d; aa->lag[4] = 0;
	aa->flt[5] = c; aa->lag[5] = 1;

	aa->flt[6] = a; aa->lag[6] = nx-1;
	aa->flt[7] = b; aa->lag[7] = nx;
	aa->flt[8] = a; aa->lag[8] = nx+1;

	xkolmog_helix(aa,fac1,fac2);

	for (i=0; i < nfilt; i++) {
#ifdef SF_HAS_COMPLEX_H
	    fac1->flt[i]=0.5*(fac2->flt[i]+conjf(fac1->flt[i]));
#else
	    fac1->flt[i]=sf_crmul(sf_cadd(fac2->flt[i],conjf(fac1->flt[i])),
				  0.5);
#endif
	}

	if (impresp) {
	    for (iz=0; iz < nx*nz; iz++) {
		pp[iz]=sf_cmplx(0.,0.);
	    }	    
	    pp[nx/2-1]=sf_cmplx(1.,0.);
	    sf_complexwrite(pp,2*nx,imp);
	}

	
	cpolydiv_init(nx*nz,fac2);
	cpolydiv_lop(false,false,nx*nz,nx*nz,pp,qq);

	if (impresp) {
	    sf_complexwrite(qq,2*nx,imp);
	    break;
	}

	/* back to time domain */
	for (it=0; it < nt; it++) {
	    cshift = cexpf(sf_cmplx( 0.,-w*it*dt));
	    for (ix=0; ix < nx; ix++) {
		for (iz=0; iz < nz; iz++) {
#ifdef SF_HAS_COMPLEX_H
		    ppp[it][ix][iz] += crealf(qq[ix+iz*nx]*cshift);
#else
		    ppp[it][ix][iz] += crealf(sf_cmul(qq[ix+iz*nx],cshift));
#endif
		}
	    }
	}

    } /* end frequency loop */

    sf_floatwrite(ppp[0][0],nt*nx*nz,out);

    exit(0);
}
예제 #9
0
파일: real.c 프로젝트: 1014511134/src
int main(int argc, char* argv[])
{
    int esize, shift;
    off_t size;
    size_t i, nleft, nbuf, e_size, len, bufsiz;
    sf_file real, cmplx;
    char *rbuf, *cbuf, *rformat, *cformat, *prog;

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

    if (SF_COMPLEX != sf_gettype(cmplx))
      {
	
	sf_error("wrong input type");
      }
    
    cformat = sf_histstring(cmplx,"data_format");
    len = strlen(cformat)+1;
    rformat = sf_charalloc(len);
    memcpy(rformat,cformat,len);
    strcpy(strstr(rformat,"complex"),"float");
    sf_setformat(real,rformat);

    if (!sf_histint(real,"esize",&esize)) esize=4;
    if (esize <= 0) sf_error("wrong esize=%d",esize);
    e_size = (size_t) esize;

    size = sf_filesize (cmplx);
    
    sf_fileflush(real,cmplx);
    sf_setform(real ,SF_NATIVE);
    sf_setform(cmplx,SF_NATIVE);
    
    prog = sf_getprog();
    if (       NULL != strstr(prog,"real")) {
	shift=0;
    } else if (NULL != strstr(prog,"imag")) {
	shift=esize;
    } else {
	sf_warning("neither real nor imag, assume real");
	shift=0;
    }

    bufsiz = sf_bufsiz(cmplx);
    rbuf = sf_charalloc(bufsiz);
    cbuf = sf_charalloc(2*bufsiz);
    
    for (nleft=size*e_size; nleft > 0; nleft -= nbuf) {
	nbuf = (bufsiz < nleft)? bufsiz: nleft;
	sf_charread(cbuf,2*nbuf,cmplx);
	for (i=0; i < nbuf; i += e_size) {
	    memcpy(rbuf+i,cbuf+2*i+shift,e_size);
	}
	sf_charwrite(rbuf,nbuf,real);
    }
    

    exit (0);
}
예제 #10
0
파일: Ms2plane.c 프로젝트: 1014511134/src
int main (int argc, char* argv[])
{
    int n1, n2, i1, i2;
    float a, z0, y, d2, d1, t, z, s, g, s0, w;
    float sina, cosa, sin2a, sina2, sina4, cosa2;
    float *trace;
    sf_file out;

    /* plane reflector: z = z0 + (x-x0)*tan(a) */
    /* slowness: s = sqrt(s0^2 + 2*g*z) */

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

    if (!sf_getint("n1",&n1)) sf_error("Need n1=");
    if (!sf_getint("n2",&n2)) sf_error("Need n2=");

    if (!sf_getfloat("d1",&d1)) sf_error("Need d1=");
    if (!sf_getfloat("d2",&d2)) sf_error("Need d2=");

    sf_putint(out,"n1",n1); sf_putfloat(out,"d1",d1); sf_putfloat(out,"o1",0.);
    sf_putint(out,"n2",n2); sf_putfloat(out,"d2",d2); sf_putfloat(out,"o2",0.);
    sf_setformat(out,"native_float");

    if (!sf_getfloat("s0",&s0)) sf_error("Need s0=");
    s0 *= s0;
    if (!sf_getfloat("g",&g)) g=0;

    if (!sf_getfloat("z0",&z0)) sf_error("Need z0=");
    if (!sf_getfloat("a",&a)) a=0.;
    a *= SF_PI/180.; /* degrees to radians */

    sina = sinf(a);
    cosa = cosf(a);
    sin2a = 2.*sina*cosa;
    sina2 = sina*sina;
    sina4 = sin2a*sin2a;
    cosa2 = cosa*cosa;
    
    trace = sf_floatalloc(n1);

    for (i2=0; i2 < n2; i2++) {
	for (i1=0; i1 < n1; i1++) {
	    trace[i1] = 0.;
	}

	if (sina==0.) {
	    z = z0;
	} else {
	    y = z0*cosa/sina + i2*d2;

	    z = s0*sin2a - 4.*g*y*sina4;

	    if (s0*s0+g*y*z < 0.) {
		sf_floatwrite(trace,n1,out);
		continue;
	    }
	    
	    z = y*sina/(1.+3.*sina2)*
		(cosa*(1.+2.*sina2) + sina*z/(s0+sqrtf(s0*s0+g*y*z)));
	}

	s = sqrtf(s0+2.*g*z);

	sf_warning("depth=%g slowness=%g",z,s);

	if (z < z0) {
	    sf_floatwrite(trace,n1,out);
	    continue;
	}

	if (s*s*cosa2 - 2.*g*z < 0.) {
	    sf_floatwrite(trace,n1,out);
	    continue;
	}

	t = sqrtf(s*s*cosa2 - 2.*g*z);

	t = 2.*z*(2.*(s*s - g*z) - (s*cosa - t)*(s*cosa - t)/3.)/(s*cosa + t);

	w = t/d1;
	i1 = w;
	w -= i1;

	if (i1>=0 && i1 < n1-1) {
	    trace[i1] = (1.-w)/t;
	    trace[i1+1] = w/t;
	}

	sf_floatwrite(trace,n1,out);
    }

    exit(0);
}
예제 #11
0
파일: file.c 프로젝트: liumch/src
sf_file sf_output (/*@null@*/ const char* tag)
/*< Create an output file structure.
  ---
  Should do output after the first call to sf_input. >*/
{
    sf_file file;
    char *headname, *dataname, *path, *name, *format;
    size_t namelen;
    extern int mkstemp (char *tmpl);
    extern off_t ftello (FILE *stream);
	
    file = (sf_file) sf_alloc(1,sizeof(*file));
	
    if (NULL == tag || 0 == strcmp(tag,"out")) {
	file->stream = stdout;
	headname = NULL;
    } else {
	headname = sf_getstring (tag);
	if (NULL == headname) {
	    namelen = strlen(tag)+1;
	    headname = sf_charalloc (namelen);
	    memcpy(headname,tag,namelen);
	}
		
	file->stream = fopen(headname,"w");
	if (NULL == file->stream) 
        {
            free(file);
	    sf_error ("%s: Cannot write to header file %s:",__FILE__,headname);
        }
    }
	
    file->buf = NULL;
    /*    setbuf(file->stream,file->buf); */
	
    file->pars = sf_simtab_init (tabsize);
    file->head = NULL;
    file->headname = NULL;
	
    file->pipe = (bool) (-1 == ftello(file->stream));
    if (file->pipe && ESPIPE != errno) 
    {
        free(file);
	sf_error ("%s: pipe problem:",__FILE__);
    }
 
    dataname = sf_getstring("out");
    if (NULL == dataname)
	dataname = sf_getstring("--out");
	
    if (file->pipe) {
	file->dataname = sf_charalloc (7);
	memcpy(file->dataname,"stdout",7);
    } else if (NULL == dataname) {
	path = getdatapath();
	file->dataname = sf_charalloc (PATH_MAX+NAME_MAX+1);
	strcpy (file->dataname,path);
	name = file->dataname+strlen(path);
	free (path);
	if (getfilename (file->stream,name)) {
	  if(0==strcmp(name,"/dev/null")){
	      file->dataname = sf_charalloc (7);
	      memcpy(file->dataname,"stdout",7);
	    } else {
	      namelen = strlen(file->dataname);
	      file->dataname[namelen]='@';
	      file->dataname[namelen+1]='\0';
	    }
	} else { /* Invent a name */
	  /* stdout is not a pipe, not /dev/null, not a file in this 
	     directory. 
	     One way to get here is to redirect io to a file not in this 
	     directory.  For example >../myfile.rsf.  In this case getfilename
	     cannot find the file from file->stream by looking in the current 
	     directory.  The function mkstemp is used to create a unique name 
	     to contain the binary data. */
	    sprintf(name,"%sXXXXXX",sf_getprog());
	    (void) close(mkstemp(file->dataname));
	    /* (void) unlink(file->dataname); */
	    /* old code for named pipes below */
	    /*
	      if (NULL == headname &&
	      -1L == fseek(file->stream,0L,SEEK_CUR) &&
	      ESPIPE == errno && 
	      0 != mkfifo (file->dataname, S_IRUSR | S_IWUSR))
	      sf_error ("%s: Cannot make a pipe %s:",
	      __FILE__,file->dataname);
	    */
	}  
    } else {
	namelen = strlen(dataname)+1;
	file->dataname = sf_charalloc (namelen);
	memcpy(file->dataname,dataname,namelen);
	free (dataname);
    }
	
    sf_putstring(file,"in",file->dataname);    
	
    file->op = XDR_ENCODE;
	
    if (NULL == infiles) {
	infiles = (sf_file *) sf_alloc(1,sizeof(sf_file));
	infiles[0] = NULL;
	nfile=1;
    } 
	
    if (NULL != infiles[0]) { 
	if (NULL == infiles[0]->pars) sf_error("The input file was closed prematurely.");
	if (NULL != (format = sf_histstring(infiles[0],"data_format"))) {
	    sf_setformat(file,format);
	    free (format);
	}
    } else {
	sf_setformat(file,"native_float");
    }
	
    if (NULL != headname) free(headname);
	
    if (!sf_getbool("--readwrite",&(file->rw))) file->rw=false;
    if (!sf_getbool("--dryrun",&(file->dryrun))) file->dryrun=false;
	
    return file;
}
예제 #12
0
파일: file.c 프로젝트: liumch/src
sf_file sf_input (/*@null@*/ const char* tag)
/*< Create an input file structure >*/
{
    int esize;
    sf_file file;
    char *filename, *format;
    size_t len;
    extern off_t ftello (FILE *stream);
	
    file = (sf_file) sf_alloc(1,sizeof(*file));
    file->dataname = NULL;
    
    if (NULL == tag || 0 == strcmp(tag,"in")) {
	file->stream = stdin;
	filename = NULL;
    } else {
	filename = sf_getstring (tag);
	if (NULL == filename) {
	    /* this option allows you to call function with 
	       sf_input("mydir/myinput.rsf");  Karl  */
	    len = strlen(tag)+1;
	    filename = sf_charalloc(len);
	    /* should change next line to strcpy or strncpy Karl */
	    memcpy(filename,tag,len);
	}
		
	file->stream = fopen(filename,"r");
	if (NULL == file->stream) {
	    sf_input_error(file,"Cannot read input (header) file",filename);
	    return NULL;
	}
    }
	
    file->buf = NULL;
    /*    setbuf(file->stream,file->buf); */
	
    /* create a parameter table */
    file->pars = sf_simtab_init (tabsize);
    file->head = sf_tempfile(&file->headname,"w+");
	
    /* read the parameter table from the file */
    sf_simtab_input (file->pars,file->stream,file->head);
	
    if (NULL == infiles) {
	infiles = (sf_file *) sf_alloc(1,sizeof(sf_file));
	infiles[0] = NULL;
	nfile=1;
    }
	
    if (NULL == filename) {
	infiles[0] = file;
    } else {
	free (filename);
	ifile++;
	if (ifile >= nfile) {
	    /* grow array */
	    nfile *= 2;
	    infiles = (sf_file *) realloc(infiles, nfile * sizeof(sf_file));
	    if (NULL == infiles) sf_error("%s: reallocation error",__FILE__);
	}
	infiles[ifile] = file;
    }
	
    filename = sf_histstring(file,"in");
    if (NULL == filename) {
    	sf_input_error (file,"No in= in file",tag);
	return NULL;
    }
    len = strlen(filename)+1;
    file->dataname = sf_charalloc(len);
    memcpy(file->dataname,filename,len);
	
    if (0 != strcmp(filename,"stdin")) {
	file->stream = freopen(filename,"rb",file->stream);
	if (NULL == file->stream) {
	    sf_input_error(file,"Cannot read data file",filename);
	    return NULL;
	}
    }
    free (filename);
	
    file->pipe = (bool) (-1 == ftello(file->stream));
    if (file->pipe && ESPIPE != errno) 
	sf_error ("%s: pipe problem:",__FILE__);
	
    file->op = XDR_DECODE;
	
    format = sf_histstring(file,"data_format");
    if (NULL == format) {
	if (!sf_histint(file,"esize",&esize) || 0 != esize) {
	    sf_input_error (file,"Unknown format in",tag);
	    return NULL;
	}
	sf_setformat(file,"ascii_float");
    } else {    
	sf_setformat(file,format);
	free (format);
    }
	
    return file;
}
예제 #13
0
파일: rsf_write.c 프로젝트: 1014511134/src
void mexFunction(int nlhs, mxArray *plhs[], 
		 int nrhs, const mxArray *prhs[])
{
    int taglen, status, argc=2, i, ndim, len;
    const int *dim=NULL;
    size_t nbuf = BUFSIZ, nd, j;
    char *tag=NULL, *argv[] = {"matlab","-"}, *par=NULL, *filename=NULL;
    double *dr=NULL, *di=NULL;
    float *p=NULL;
    sf_complex *c=NULL;
    char buf[BUFSIZ], key[5];
    bool same;
    FILE *file2=NULL;
    sf_file file=NULL;
    
    /* Check for proper number of arguments. */
    if (nrhs < 2 || nrhs > 3) mexErrMsgTxt("Two or three inputs required.");

    /* Second input must be a string. */
    if (!mxIsChar(prhs[1]))
	mexErrMsgTxt("Second input must be a string.");

    /* Second input must be a row vector. */
    if (mxGetM(prhs[1]) != 1)
	mexErrMsgTxt("Second input must be a row vector.");

    /* Get the length of the input string. */
    taglen = mxGetN(prhs[1]) + 1;

    /* Allocate memory for input string. */
    tag = mxCalloc(taglen, sizeof(char));

    /* Copy the string data from prhs[1] into a C string. */
    status = mxGetString(prhs[1], tag, taglen);
    if (status != 0) 
	mexWarnMsgTxt("Not enough space. String is truncated.");

    if (3 == nrhs) {
        /* Input 3 must be a string. */
	if (!mxIsChar(prhs[2]))
	    mexErrMsgTxt("Input 3 must be a string.");

	/* Input 3 must be a row vector. */
	if (mxGetM(prhs[2]) != 1)
	    mexErrMsgTxt("Input 3 must be a row vector.");
	
	/* Get the length of the input string. */
	len = mxGetN(prhs[2]) + 1;
	
	/* Allocate memory for input string. */
	par = mxCalloc(len, sizeof(char));

	/* Copy the string data from prhs[2] into a C string. */
	status = mxGetString(prhs[2], par, len);
	if (status != 0) 
	    mexWarnMsgTxt("Not enough space. String is truncated.");

	same = (0 == (strncmp(par,"same",4)));
    } else {
	same = false;
    }

    sf_init(argc,argv);

    if (same) {
	file = sf_input(tag);
	filename = sf_histstring(file,"in");
	sf_fileclose(file);

	if (NULL == filename) mexErrMsgTxt("No in= in file.");
	file2 = fopen(filename,"ab");
	if (NULL == file2) 
	    mexErrMsgTxt("Could not open binary file for writing.");
    } else {
	file = sf_output(tag);
	file2 = NULL;
    }

    /* Input 1 must be a number. */
    if (!mxIsDouble(prhs[0])) mexErrMsgTxt("First input must be double.");

    /* get data dimensions */
    ndim=mxGetNumberOfDimensions(prhs[0]);
    dim=mxGetDimensions(prhs[0]);

    /* get data size */
    nd = mxGetNumberOfElements(prhs[0]);

    if (!same) {
	sf_setformat(file,mxIsComplex(prhs[0])?"native_complex":"native_float");

	/* Output */
	for (i=0; i < ndim; i++) {
	    sprintf(key,"n%d",i+1);
	    sf_putint(file,key,dim[i]);
	}
    }
    
    if (mxIsComplex(prhs[0])) {
	/* complex data */
	c = (sf_complex*) buf;

	dr = mxGetPr(prhs[0]);

	/* pointer to imaginary part */
	di = mxGetPi(prhs[0]);
	
	for (j=0, nbuf /= sizeof(sf_complex); nd > 0; nd -= nbuf) {
	    if (nbuf > nd) nbuf=nd;
	    
	    for (i=0; i < nbuf; i++, j++) {
		c[i] = sf_cmplx((float) dr[j],(float) di[j]);
	    }
	    
	    if (same) {
		if (nbuf != fwrite(c,sizeof(sf_complex),nbuf,file2)) 
		    mexWarnMsgTxt("Writing problems.");
	    } else {
		sf_complexwrite(c,nbuf,file);
	    }
	}

    } else { 
	/* real data */
	p = (float*) buf;

	dr = mxGetPr(prhs[0]);

	for (j=0, nbuf /= sizeof(float); nd > 0; nd -= nbuf) {
	    if (nbuf > nd) nbuf=nd;
	    
	    for (i=0; i < nbuf; i++, j++) {
		p[i] = (float) dr[j];
	    }
	    
	    if (same) {
		if (nbuf != fwrite(p,sizeof(float),nbuf,file2)) 
		    mexWarnMsgTxt("Writing problems.");
	    } else {
		sf_floatwrite(p,nbuf,file);
	    }
	}
    } 

    if (same) {
	fclose(file2);
    } else {
	sf_fileclose(file);
    }
}
예제 #14
0
파일: Mduffing1.c 프로젝트: 1014511134/src
int main(int argc,char *argv[])
{
    float x0,y0,x00,y00,t0,d1,d2,d3,o1,o2,o3,k11,k21,k31,k41,k12,k22,k32,k42;
    float kxi,gamma,omega,phi;/*parameter define*/
    int i,j,k,n1,n2,n3,sn1,pow1,pow2;
    double h;
    float  *inpsg,*xt,*xt1,*re;
    sf_complex *out1;
    sf_file in, out, restor=NULL;
    bool verb,cosine;
    
    sf_init (argc, argv); 
    in = sf_input("in");
    out = sf_output("out");

    if (NULL != sf_getstring ("restor")) {
        restor = sf_input("restor");
    } else {
	restor = NULL;
	sn1=1;
    }
    
   
    sf_setformat(out,"native_complex");
    
    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)) sf_error("No o1= in input");
    if (!sf_histint(in,"n2",&n2)) n2=1;
    if (!sf_histfloat(in,"d2",&d2)) d2=1;
    if (!sf_histfloat(in,"o2",&o2)) o2=1;
    if (!sf_histint(in,"n3",&n3)) n3=1;
    if (!sf_histfloat(in,"d3",&d3)) d3=1;
    if (!sf_histfloat(in,"o3",&o3)) o3=1;
    
    if(!sf_getfloat("gamma",&gamma)) gamma=0.75;
    /*strength of external force*/
    if(!sf_getfloat("omega",&omega)) omega=1;
    /*angular frequence of external force*/
    if(!sf_getfloat("kxi",&kxi)) kxi=1;
    /*adjustment for input signal*/
    if(!sf_getfloat("x0",&x0)) x0=0;
    /*initial value of x0*/
    if(!sf_getfloat("y0",&y0)) y0=0;
    /*initial value of y0*/
    if(!sf_getint("pow1",&pow1)) pow1=1;
    /*power of first non-linear restitution term*/
    if(!sf_getint("pow2",&pow2)) pow2=3;
    /*power of second non-linear restitution term*/
    if(!sf_getfloat("phi",&phi)) phi=0.;
    /*phase of cosine signal unit=pi*/
    if(!sf_getbool("verb",&verb)) verb = false;
    /* verbosity flag */
    if(!sf_getbool("cosine",&cosine)) cosine = true;
    /* if n need extenal input for periodic restoring force */
    
    if (NULL != restor){
	
	if (!sf_histint(restor,"n1",&sn1)) sf_error("No n1= in s");
	if (n1>sn1) sf_error("insufficient lenth of external force");
    }
    
    
    h=d1;
    /*step lenth of R-K4*/
    
    re = sf_floatalloc(sn1);
    inpsg = sf_floatalloc(n1*n2);
    xt = sf_floatalloc(n1*n2);
    xt1 = sf_floatalloc(n1*n2);
    out1 = sf_complexalloc(n1*n2);
    
    
    if (NULL != restor) {
	sf_floatread(re,sn1,restor);
    }else {
	for (i=0;i<sn1; i++)
	    re[i] = 0;
    }

    
    if(cosine) {
	for(k = 0; k < n3 ; k++) {
	    sf_floatread(inpsg,n1*n2,in);
	    x00=x0,y00=y0;
	    t0=0;
	    if(verb) sf_warning("step %d of %d;",k,n3);
	    for(j = 0;j < n2;j++) {
		x00=x0,y00=y0;
		t0=0;
		for(i = 0;i < n1;i++){
		    
		    k11 = function1(t0,x00,y00,omega);
		    k12 = function2(t0,x00,y00,inpsg[i+j*n1],kxi,
				    gamma,omega,pow1,pow2,phi);
		    k21 = function1(t0+h/2,x00+k11*h/2,y00+k12*h/2,omega);
		    k22 = function2(t0+h/2,x00+k11*h/2,
				    y00+k12*h/2,inpsg[i+j*n1],kxi,
				    gamma,omega,pow1,pow2,phi);
		    k31 = function1(t0+h/2,x00+k21*h/2,y00+k22*h/2,omega);
		    k32 = function2(t0+h/2,x00+k21*h/2,
				    y00+k22*h/2,inpsg[i+j*n1],kxi,
				    gamma,omega,pow1,pow2,phi);
		    k41 = function1(t0+h,x00+k31*h,y00+k32*h,omega);
		    k42 = function2(t0+h,x00+k31*h,y00+k32*h,inpsg[i+j*n1],
				    kxi,gamma,omega,pow1,pow2,phi);
		    
		    x00+= h*(k11+2*k21+2*k31+k41)/6;
		    y00+= h*(k12+2*k22+2*k32+k42)/6;
		    t0+= h;
		    
		    xt[i+j*n1]=x00,xt1[i+j*n1]=y00;
		}	
	    }
	    for(i=0;i < n1*n2;i++) {
		out1[i] = sf_cmplx(xt[i],xt1[i]);
	    }
	    sf_complexwrite(out1,n1*n2,out);
	}
    }else {
	for(k = 0; k < n3 ; k++) {
	    sf_floatread(inpsg,n1*n2,in);
	    x00=x0,y00=y0;
	    t0=0;
	    if(verb) sf_warning("step %d of %d;",k,n3);
	    for(j = 0;j < n2;j++) {
		x00=x0,y00=y0;
		t0=0;
		for(i = 0;i < n1;i++) {
		    	    
		    k11 = function1(t0,x00,y00,omega);
		    k12 = function3(t0,x00,y00,inpsg[i+j*n1],kxi,
				    gamma,omega,pow1,pow2,re[i]);
		    k21 = function1(t0+h/2,x00+k11*h/2,y00+k12*h/2,omega);
		    k22 = function3(t0+h/2,x00+k11*h/2,
				    y00+k12*h/2,inpsg[i+j*n1],kxi,
				    gamma,omega,pow1,pow2,re[i]);
		    k31 = function1(t0+h/2,x00+k21*h/2,y00+k22*h/2,omega);
		    k32 = function3(t0+h/2,x00+k21*h/2,
				    y00+k22*h/2,inpsg[i+j*n1],kxi,
				    gamma,omega,pow1,pow2,re[i]);
		    k41 = function1(t0+h,x00+k31*h,y00+k32*h,omega);
		    k42 = function3(t0+h,x00+k31*h,y00+k32*h,inpsg[i+j*n1],
				    kxi,gamma,omega,pow1,pow2,re[i]);
		    
		    x00+= h*(k11+2*k21+2*k31+k41)/6;
		    y00+= h*(k12+2*k22+2*k32+k42)/6;
		    t0+= h;
		    
		    
		    xt[i+j*n1]=x00,xt1[i+j*n1]=y00;
		}
	    }
	    for(i=0;i < n1*n2;i++) {
		out1[i] = sf_cmplx(xt[i],xt1[i]);
	    }
	    sf_complexwrite(out1,n1*n2,out);
	}
    }
    
    exit(0);
}
예제 #15
0
파일: Midempatch.c 프로젝트: krushev36/src
int main(int argc, char* argv[])
{
    int n[2], w[2], k[2], a[2], l[2], n12, w12, i;
    float *wall, *data, *windwt;
    sf_filter aa;
    sf_file wind, out;

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

    sf_setformat(out,"native_float");

    if (!sf_getint("n1",&n[0])) n[0] = 100;
    if (!sf_getint("n2",&n[1])) n[1] = 30;

    sf_putint(out,"n1",n[0]);
    sf_putint(out,"n2",n[1]);

    if (!sf_getint("w1",&w[0])) w[0] = 17;
    if (!sf_getint("w2",&w[1])) w[1] = 6;

    if (!sf_getint("k1",&k[0])) k[0] = 5;
    if (!sf_getint("k2",&k[1])) k[1] = 11;

    if (!sf_getint("a1",&a[0])) a[0] = 1;
    if (!sf_getint("a2",&a[1])) a[1] = 1;

    if (!sf_getint("lag1",&l[0])) l[0] = 1;
    if (!sf_getint("lag2",&l[1])) l[1] = 1;

    n12 = n[0]*n[1];
    w12 = w[0]*w[1];

    wall = sf_floatalloc(n12);
    data = sf_floatalloc(n12);
    windwt = sf_floatalloc(w12);

    for (i=0; i < n12; i++) {
        wall[i] = 1.;
    }

    aa = sf_allocatehelix (1);
    aa->lag[0] = 1;

    tent (2, w, l, a, windwt);

    if (NULL != sf_getstring("wind")) {
        /* optional output file for window weight */
        wind = sf_output("wind");
        sf_setformat(wind,"native_float");
        sf_putint(wind,"n1",w[0]);
        sf_putint(wind,"n2",w[1]);

        sf_floatwrite (windwt,w12,wind);
        sf_fileclose(wind);
    }

    sf_helicon_init (aa);
    patching (sf_helicon_lop, wall, data, 2, k, n, w, windwt);

    for (i=0; i < n12; i+= n[0]) {
        data[i] = 0.;
    }
    for (i=1; i < n12; i+= n[0]) {
        data[i] = 0.;
    }
    for (i=n[0]-2; i < n12; i+= n[0]) {
        data[i] = 0.;
    }
    for (i=n[0]-1; i < n12; i+= n[0]) {
        data[i] = 0.;
    }

    sf_floatwrite(data,n12,out);


    exit (0);
}
예제 #16
0
파일: 7ab.c 프로젝트: 1014511134/src
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);
}
예제 #17
0
파일: Mvofz.c 프로젝트: krushev36/src
int main (int argc, char* argv[])
{
    int n, n1, n2, i1, i2;
    float g, s, v0, v, x, z, a, d1, d2, o1, o2;
    float **vel, **time;
    bool intime;
    sf_file out;

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

    if (!sf_getint("n1",&n1)) {
        /* vertical samples */
        if (!sf_getint("n",&n)) sf_error("Need n=");
        /* number of samples */
        n1 = n+1;
    }
    if (!sf_getint("n2",&n2)) {
        /* horizontal samples */
        if (!sf_getint("n",&n)) sf_error("Need n=");
        /* number of samples */
        n2 = 2*n+1;
    }
    if (!sf_getfloat("g",&g)) g = 1.;
    /* velocity gradient */
    if (!sf_getfloat("v0",&v0)) v0 = 0.5;
    /* initial velocity */
    if (!sf_getfloat("s",&s)) s = 0.5;
    /* shot location at the surface */

    if (!sf_getfloat("d1",&d1)) d1 = 0.5/(n1-1);
    /* vertical sampling */
    if (!sf_getfloat("d2",&d2)) d2 = 1./(n2-1);
    /* horizontal sampling */
    if (!sf_getfloat("o1",&o1)) o1 = 0.;
    /* vertical origin */
    if (!sf_getfloat("o2",&o2)) o2 = 0.;
    /* horizontal origin */

    if (!sf_getbool("intime",&intime)) intime = false;
    /* if in vertical time coordinates */

    a = 0.5*g*g/v0;

    sf_putint(out,"n1",n1);
    sf_putfloat(out,"d1",d1);
    sf_putfloat(out,"o1",0.);
    sf_putint(out,"n2",n2);
    sf_putfloat(out,"d2",d2);
    sf_putfloat(out,"o2",0.);
    sf_putint(out,"n3",2);
    sf_setformat(out,"native_float");

    vel = sf_floatalloc2 (n1,n2);
    time = sf_floatalloc2 (n1,n2);

    for (i2 = 0; i2 < n2; i2++) {
        x = o2+i2*d2 - s;
        x = x*x;
        for (i1 = 0; i1 < n1; i1++) {
            z = o1+i1*d1;
            if (intime) z = v0*(expf(g*z)-1.)/g;

            v = v0 + g*z;
            z = 1. + a*(z*z+x)/v;
            vel[i2][i1] = v;
            time[i2][i1] = fabsf(logf(z + sqrtf(z*z-1.))/g);
        }
    }

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

    exit (0);
}