Beispiel #1
0
int main (int argc, char* argv[])
{
    bool verb, fsrf, snap, expl, dabc; 
    int  jsnap, ntsnap, jdata;

    /* I/O files */
    sf_file Fwav = NULL; /* wavelet   */
    sf_file Fsou = NULL; /* sources   */
    sf_file Frec = NULL; /* receivers */
    sf_file Fvel = NULL; /* velocity  */
    sf_file Fden = NULL; /* density   */
    sf_file Fdat = NULL; /* data      */
    sf_file Fwfl = NULL; /* wavefield */

    /* cube axes */
    sf_axis at, az, ax;
    sf_axis as, ar;

    int cpuid;
    int nt, nz, nx, ns, nr;
    int it, ia;
    float dt, dz, dx;

    /* FDM structure */
    /* Wee keep these structures for compatibility,
       as soon as PETSC version is finished,
       this will be removed */
    fdm2d fdm = NULL;

    /* I/O arrays */
    float *ww = NULL;           /* wavelet   */
    pt2d  *ss = NULL;           /* sources   */
    pt2d  *rr = NULL;           /* receivers */
    float *dd = NULL;           /* data      */

    float **u,**v;

    /* linear interpolation weights/indices */
    lint2d cs,cr;

    /* wavefield cut params */
    sf_axis acz = NULL, acx = NULL;
    int   nqz, nqx;
    float oqz, oqx;
    float dqz, dqx;
    float **uc = NULL;

    sf_petsc_aimplfd2 aimplfd;
    PetscErrorCode ierr;
    /* PETSc Initialization */
    ierr = PetscInitialize (&argc, &argv, 0, 0); CHKERRQ(ierr);
    MPI_Comm_rank (MPI_COMM_WORLD, &cpuid);

    /*------------------------------------------------------------*/
    /* init RSF */
    sf_init (argc, argv);

    /*------------------------------------------------------------*/

    if (!sf_getbool ("verb", &verb)) verb = false; /* verbosity flag */
    if (!sf_getbool ("snap", &snap)) snap = false; /* wavefield snapshots flag */
    if (!sf_getbool ("free", &fsrf)) fsrf = false; /* free surface flag */
    if (!sf_getbool ("expl", &expl)) expl = false; /* "exploding reflector" */
    if (!sf_getbool ("dabc", &dabc)) dabc = false; /* absorbing BC */
    /*------------------------------------------------------------*/

    /*------------------------------------------------------------*/
    /* I/O files */
    Fwav = sf_input ("in" ); /* wavelet   */
    Fvel = sf_input ("vel"); /* velocity  */
    Fsou = sf_input ("sou"); /* sources   */
    Frec = sf_input ("rec"); /* receivers */
    Fwfl = sf_output("wfl"); /* wavefield */
    Fdat = sf_output("out"); /* data      */
    Fden = sf_input ("den"); /* density   */

    /*------------------------------------------------------------*/
    /* axes */
    at = sf_iaxa (Fwav,2); sf_setlabel (at,"t"); if (verb && 0 == cpuid) sf_raxa (at); /* time */
    az = sf_iaxa (Fvel,1); sf_setlabel (az,"z"); if (verb && 0 == cpuid) sf_raxa (az); /* depth */
    ax = sf_iaxa (Fvel,2); sf_setlabel (ax,"x"); if (verb && 0 == cpuid) sf_raxa (ax); /* space */

    as = sf_iaxa (Fsou, 2); sf_setlabel (as, "s"); if (verb && 0 == cpuid) sf_raxa (as); /* sources */
    ar = sf_iaxa (Frec, 2); sf_setlabel (ar, "r"); if (verb && 0 == cpuid) sf_raxa (ar); /* receivers */

    nt = sf_n (at); dt = sf_d (at);
    nz = sf_n (az); dz = sf_d (az);
    nx = sf_n (ax); dx = sf_d (ax);

    ns = sf_n (as);
    nr = sf_n (ar);
    /*------------------------------------------------------------*/

    /*------------------------------------------------------------*/
    /* other execution parameters */
    if (!sf_getint ("jdata", &jdata)) jdata = 1;
    if (snap) {  /* save wavefield every *jsnap* time steps */
        if (!sf_getint ("jsnap", &jsnap)) jsnap = nt;
    }
    /*------------------------------------------------------------*/

    /*------------------------------------------------------------*/
    /* expand domain for FD operators and ABC */
    /*if (!sf_getint("nb",&nb) || nb<NOP) nb=NOP;*/
    fdm = fdutil_init (verb, true, az, ax, 0, 1);

    /*------------------------------------------------------------*/

    if (0 == cpuid) {
        sf_setn (az, fdm->nzpad); sf_seto (az, fdm->ozpad); if(verb) sf_raxa (az);
        sf_setn (ax, fdm->nxpad); sf_seto (ax, fdm->oxpad); if(verb) sf_raxa (ax);
        /*------------------------------------------------------------*/

        /*------------------------------------------------------------*/
        /* setup output data header */
        sf_oaxa (Fdat, ar, 1);

        sf_setn (at, nt/jdata);
        sf_setd (at, dt*jdata);
        sf_oaxa (Fdat, at, 2);
    }

    /* setup output wavefield header */
    if (snap && 0 == cpuid) {
        if (!sf_getint ("nqz", &nqz)) nqz = sf_n (az);
        if (!sf_getint ("nqx", &nqx)) nqx = sf_n (ax);

        if (!sf_getfloat ("oqz", &oqz)) oqz = sf_o (az);
        if (!sf_getfloat ("oqx", &oqx)) oqx = sf_o (ax);

        dqz = sf_d (az);
        dqx = sf_d (ax);

        acz = sf_maxa (nqz, oqz, dqz); sf_raxa (acz);
        acx = sf_maxa (nqx, oqx, dqx); sf_raxa (acx);
        /* check if the imaging window fits in the wavefield domain */

        uc = sf_floatalloc2 (sf_n (acz), sf_n (acx));

        ntsnap = 0;
        for (it = 0; it < nt; it++) {
            if (it % jsnap == 0)
                ntsnap++;
        }
        sf_setn (at, ntsnap);
        sf_setd (at, dt*jsnap);
        if (verb)
            sf_raxa(at);

        sf_oaxa (Fwfl, acz, 1);
        sf_oaxa (Fwfl, acx, 2);
        sf_oaxa (Fwfl, at,  3);
    }

    if (expl) {
        ww = sf_floatalloc (1);
    } else {
        ww = sf_floatalloc (ns);
    }
    dd = sf_floatalloc (nr);

    /*------------------------------------------------------------*/
    /* setup source/receiver coordinates */
    ss = (pt2d*) sf_alloc (ns, sizeof (*ss));
    rr = (pt2d*) sf_alloc (nr, sizeof (*rr));

    pt2dread1 (Fsou, ss, ns, 2); /* read (x,z) coordinates */
    pt2dread1 (Frec, rr, nr, 2); /* read (x,z) coordinates */

    cs = lint2d_make (ns, ss, fdm);
    cr = lint2d_make (nr, rr, fdm);

    v = sf_floatalloc2 (nz, nx);
    u = sf_floatalloc2 (nz, nx);

    /* input velocity */
    sf_floatread (v[0], nz*nx, Fvel);

    /*------------------------------------------------------------*/
    PetscFPrintf (MPI_COMM_WORLD, stderr, "Initializing GMRES solver\n");   
    aimplfd = sf_petsc_aimplfd2_init (nz, nx, dz, dx, dt, &v[0][0], 100, true);

    /*------------------------------------------------------------*/
    /* 
     *  MAIN LOOP
     */
    /*------------------------------------------------------------*/
    for (it = 0; it < nt; it++) {
        PetscFPrintf (MPI_COMM_WORLD, stderr, "Timestep #%d, t=%f\n", it, it*dt);

        sf_petsc_aimplfd2_next_step (aimplfd);

        /* inject acceleration source */
        if (expl) {
            sf_floatread (ww, 1, Fwav);
            for (ia = 0; ia < cs->n; ia++) {
                sf_petsc_aimplfd2_add_source_ut1 (aimplfd, ww[0], cs->jz[ia], cs->jx[ia]);
            }
        } else {
            sf_floatread (ww, ns, Fwav);
            for (ia = 0; ia < cs->n; ia++) {
            /*
                PetscFPrintf (MPI_COMM_WORLD, stderr, "Source #%d [%d, %d], f=%f\n", ia, cs->jz[ia], cs->jx[ia], ww[0]);
                */
                sf_petsc_aimplfd2_add_source_ut1 (aimplfd, ww[ia], cs->jz[ia], cs->jx[ia]);
            }
        }
        sf_petsc_aimplfd2_get_wavefield_ut2 (aimplfd, &u[0][0]);

        /* extract data */
        /*
        lint2d_extract (u, dd, cr);
        */
        for (ia = 0; ia < cr->n; ia++) {
            dd[ia] = u[cr->jx[ia]][cr->jz[ia]];
        }

        if (snap && it % jsnap == 0 && 0 == cpuid) {
            cut2d (u, uc, fdm, acz, acx);
            sf_floatwrite (uc[0], sf_n(acz)*sf_n(acx), Fwfl);
        }
        if (it % jdata == 0 && 0 == cpuid)
            sf_floatwrite (dd, nr, Fdat);
    }

    exit (0);
}
Beispiel #2
0
int main(int argc, char* argv[]) 
{
    int nx, nt, ix, it, isx;
    float dt, dx;
    float *old, *nxt, *cur, *sig, *v;
    sf_file in, out, vel;
    int im,im2,im3,im4,im5,ip,ip2,ip3,ip4,ip5;

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

    if (SF_FLOAT != sf_gettype(in)) sf_error("Need float input");
    if (!sf_histint(vel,"n1",&nx)) sf_error("No n1= in input");
    if (!sf_histfloat(vel,"d1",&dx)) sf_error("No d1= in input");
    if (!sf_getint("isx",&isx)) isx=(int)(nx/2);
    if (!sf_getint("nt",&nt)) sf_error("No nt in input");
    if (!sf_getfloat("dt",&dt)) sf_error("No dt in input");

    sf_putint(out,"n1",nx);
    sf_putfloat(out,"d1",dx);
    sf_putint(out,"n2",nt);
    sf_putfloat(out,"d2",dt);
    sf_putfloat(out,"o2",0.0); 

    sig = sf_floatalloc(nx);
    old = sf_floatalloc(nx);
    nxt = sf_floatalloc(nx);
    cur = sf_floatalloc(nx);
    v   = sf_floatalloc(nx);
    
 
    sf_floatread(v,nx,vel);
    sf_floatread(sig,nx,in);		

	/* initial conditions */
    for (ix=0; ix < nx; ix++){
        cur[ix] =  sig[ix];
        old[ix] =  0.0; 
	nxt[ix] = 0.;
    }

    /* propagation in time */
    for (it=0; it < nt; it++) {
	sf_floatwrite(cur,nx,out);
	/* Stencil */
	for (ix=0; ix < nx; ix++) {
            im  =(ix-1+nx)%nx; 
            im2 =(ix-2+nx)%nx; 
            im3 =(ix-3+nx)%nx; 
            im4 =(ix-4+nx)%nx; 
            im5 =(ix-5+nx)%nx; 
            ip = (ix+1+nx)%nx;
            ip2 =(ix+2+nx)%nx;
            ip3 =(ix+3+nx)%nx;
            ip4 =(ix+4+nx)%nx;
            ip5 =(ix+5+nx)%nx;
	    nxt[ix] = dt*dt/(12.0*dx*dx)*(-30.0*cur[ix] +16.0* (cur[im]+cur[ip]) - (cur[im2]+cur[ip2]))*v[ix]*v[ix] 
                      +2.0*cur[ix]- old[ix];
	}
       for (ix=0; ix < nx; ix++) {
	    old[ix] = cur[ix];
	    cur[ix] = nxt[ix];
	}
    }
    exit(0);
}
Beispiel #3
0
int main (int argc, char *argv[])
{
    bool verb, up2, up3;
    unsigned char update;
    int n1,n2,n3, i1,i2,i3, ns2, ns3, ip, np2, np3, n23;
    int order, np, i4, n4, k2, k3, j2, j3, i, jp, j;
    float eps, ***u, **p1, **p2, **cost, *trace, *q2=NULL, *q3=NULL;
    sf_file inp, out, dip;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    exit (0);
}
Beispiel #4
0
int main (int argc, char* argv[]) 
{
    int n1,n2,n3; /*n1 is trace length, n2 is the number of traces, n3 is the number of 3th axis*/
    int nfw;    /*nfw is the filter-window length*/
    int m;
    int i,j,k,ii;
    bool boundary;
    
    float *trace;
    float *tempt;
    float *temp1;
    float *extendt;
    sf_file in, out;
    
    sf_init (argc, argv); 
    in = sf_input("in");
    out = sf_output("out");
    
    if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input");
    if (!sf_histint(in,"n2",&n2)) sf_error("No n2= in input");
    n3 = sf_leftsize(in,2);
    /* get the trace length (n1) and the number of traces (n2) and n3*/
    
    if (!sf_getint("nfw",&nfw)) sf_error("Need integer input");
    /* filter-window length (positive and odd integer)*/
    
    if (!sf_getbool("boundary",&boundary)) boundary=false;
    /* if y, boundary is data, whereas zero*/
    
    if (nfw < 1)  sf_error("Need positive integer input"); 
    if (nfw%2 == 0) nfw++;
    m=(nfw-1)/2;
    
    trace = sf_floatalloc(n1*n2);
    tempt = sf_floatalloc(n1*n2);
    temp1 = sf_floatalloc(nfw);
    extendt = sf_floatalloc((n1+2*m)*n2);
    
    for(ii=0;ii<n3;ii++){
	sf_floatread(trace,n1*n2,in);
	
	for(i=0;i<n1*n2;i++){
	    tempt[i]=trace[i];
	}
	
	bound1(tempt,extendt,nfw,n1,n2,boundary);
	
	/************1D median filter****************/
	
	for(i=0;i<n2;i++){
	    for(j=0;j<n1;j++){
		for(k=0;k<nfw;k++){
		    temp1[k]=extendt[(n1+2*m)*i+j+k];
		}
		trace[n1*i+j]=sf_quantile(m,nfw,temp1); 
	    }
	}
	
	sf_floatwrite(trace,n1*n2,out);
    }

    exit (0);
}
Beispiel #5
0
int main (int argc, char *argv[])
{
    int  adj;             /* forward or adjoint */
    int  eic;             /* EIC or CIC */
    bool verb;            /* verbosity */
    float eps;            /* dip filter constant */
    int   nrmax;          /* number of reference velocities */
    float dtmax;          /* time error */
    int   pmx,pmy;        /* padding in the k domain */
    int   tmx,tmy;        /* boundary taper size */

    int nhx, nhy, nhz, nht, nc;
    int nhx2,nhy2,nhz2,nht2;
    float dht, oht;

    sf_axis amx,amy,az;
    sf_axis alx,aly;
    sf_axis aw,ae,ac,aa;
    sf_axis ahx,ahy,ahz,aht;         

    /* I/O files */
    sf_file Bws=NULL;   /*  background wavefield file Bws */
    sf_file Bwr=NULL;   /*  background wavefield file Bwr */
    sf_file Bs=NULL;    /*  background slowness file Bs   */
    sf_file Ps=NULL;    /*  slowness perturbation file Ps */
    sf_file Pi=NULL;    /*  image perturbation file Pi    */
    sf_file Fc=NULL;    /*  CIP coordinates               */
    sf_file Pws=NULL;   /*  perturbed wavefield file Pws */
    sf_file Pwr=NULL;   /*  perturbed wavefield file Pwr */
    sf_file Pti=NULL;  

    int ompnth=1;

    wexcub3d cub; /* wavefield hypercube */
    wexcip3d cip; /* CIP gathers */
    wextap3d tap; /* tapering */
    wexssr3d ssr; /* SSR operator */
    wexlsr3d lsr; /* LSR operator */
    wexslo3d slo; /* slowness */

    wexmvaop3d mva;
    float dsmax;

    /*------------------------------------------------------------*/
    sf_init(argc,argv);

    /* OMP parameters */
#ifdef _OPENMP
    ompnth=omp_init();
#endif

    if (!sf_getbool(  "verb",&verb ))  verb =  true; /* verbosity flag */
    if (!sf_getint(   "adj",&adj   ))  sf_error("Specify adjoint!"); /* y=ADJ Back-projection; n=FWD Forward Scattering */
    if (!sf_getint(  "feic",&eic   ))  sf_error("Specify EIC!");     /* extended I.C. flag */
    if (!sf_getfloat(  "eps",&eps  ))   eps =  0.01; /* stability parameter */
    if (!sf_getint(  "nrmax",&nrmax)) nrmax =     1; /* max number of refs */
    if (!sf_getfloat("dtmax",&dtmax)) dtmax = 0.004; /* max time error */
    if (!sf_getint(    "pmx",&pmx  ))   pmx =     0; /* padding on x */
    if (!sf_getint(    "pmy",&pmy  ))   pmy =     0; /* padding on y */
    if (!sf_getint(    "tmx",&tmx  ))   tmx =     0; /* taper on x   */
    if (!sf_getint(    "tmy",&tmy  ))   tmy =     0; /* taper on y   */

    ae  = sf_maxa(1,0,1);
    nhx=nhy=nhz=nht=nc=nhx2=nhy2=nhz2=nht2=0;
    oht = dht = 0.0;
    /*------------------------------------------------------------*/
    /* slowness */

    Bs = sf_input("slo");
    alx = sf_iaxa(Bs,1); sf_setlabel(alx,"lx");
    aly = sf_iaxa(Bs,2); sf_setlabel(aly,"ly");
    az =  sf_iaxa(Bs,3); sf_setlabel(az, "z");

    /*------------------------------------------------------------*/
    /* input file */
    if(adj)
        Pi = sf_input("in");
    else
        Ps = sf_input("in");

    /*------------------------------------------------------------*/
    /* wavefield */
    Bws = sf_input("swfl");
    Bwr = sf_input("rwfl");

    amx = sf_iaxa(Bws,1); sf_setlabel(amx,"mx");
    amy = sf_iaxa(Bws,2); sf_setlabel(amy,"my");
    aw  = sf_iaxa(Bws,4); sf_setlabel(aw ,"w" );

    Pws = sf_tmpfile(NULL); sf_settype(Pws,SF_COMPLEX);
    Pwr = sf_tmpfile(NULL); sf_settype(Pwr,SF_COMPLEX);

    /*------------------------------------------------------------*/
    cub = wex_cube(verb,
                   amx,amy,az,
                   alx,aly,
                   aw,
                   ae,
                   eps,
                   ompnth);
    dsmax = dtmax/cub->az.d;

    /*------------------------------------------------------------*/
    /* init structures */
    tap = wextap_init(cub->amx.n,
                      cub->amy.n,
                      1,
                      SF_MIN(tmx,cub->amx.n-1), /* tmx */
                      SF_MIN(tmy,cub->amy.n-1), /* tmy */
                      0,
                      true,true,false);
    slo = wexslo_init(cub,Bs,nrmax,dsmax);
    ssr = wexssr_init(cub,slo,pmx,pmy,tmx,tmy,dsmax);
    lsr = wexlsr_init(cub,pmx,pmy,dsmax);

    /*------------------------------------------------------------*/
    Pti = sf_tmpfile(NULL); sf_settype(Pti,SF_COMPLEX);

    /*------------------------------------------------------------*/
    /* WEMVA */
    if(adj) {
        sf_warning("adjoint operator...");

        if(eic){
            ahx = sf_iaxa(Pi,1); sf_setlabel(ahx,"hx");
            ahy = sf_iaxa(Pi,2); sf_setlabel(ahy,"hy");
            ahz = sf_iaxa(Pi,3); sf_setlabel(ahz,"hz");
            aht = sf_iaxa(Pi,4); sf_setlabel(aht,"ht");

            dht = sf_d(aht);  oht = sf_o(aht);

            nhx2 = sf_n(ahx); nhx = (nhx2-1)/2;
            nhy2 = sf_n(ahy); nhy = (nhy2-1)/2;
            nhz2 = sf_n(ahz); nhz = (nhz2-1)/2;
            nht2 = sf_n(aht); nht = (nht2-1)/2;

            /* CIP coordinates */
            Fc = sf_input ("cc" );
            ac = sf_iaxa(Fc,2); sf_setlabel(ac,"cc"); sf_setunit(ac,"");
            nc = sf_n(ac);
        }

        cip = wexcip_init(cub,nhx,nhy,nhz,nht,nhx2,nhy2,nhz2,nht2,nc,dht,oht,Fc,eic);
        mva = wexmva_init(cub,cip);

        Ps = sf_output("out"); sf_settype(Ps,SF_COMPLEX);
        sf_oaxa(Ps,amx,1);
        sf_oaxa(Ps,amy,2);
        sf_oaxa(Ps,az, 3);
        if(eic){
        sf_oaxa(Ps,ae, 4);
        sf_oaxa(Ps,ae, 5);}

        /* Adjoint I.C. operator, dI -> dW */
        wexcip_adj(cub,cip,Bwr,Pws,Pi,eic,1,1); /* Ws dR */
        wexcip_adj(cub,cip,Bws,Pwr,Pi,eic,0,0); /* Wr dR */

        sf_filefresh(Pws);
        sf_filefresh(Pwr);

        /* Adjoint WEMVA operator, dW -> dS */
        wexmva(mva,adj,cub,ssr,lsr,tap,slo,Bws,Bwr,Pws,Pwr,Ps);

    } else {
        /* set up the I/O of output CIP gathers */
        Pi = sf_output("out"); sf_settype(Pi,SF_COMPLEX);

        if(eic){
            /* CIP coordinates */
            Fc = sf_input ("cc" );
            ac = sf_iaxa(Fc,2); sf_setlabel(ac,"cc"); sf_setunit(ac,"");
            nc = sf_n(ac);

            if(! sf_getint("nhx",&nhx)) nhx=0; /* number of lags on the x axis */
            if(! sf_getint("nhy",&nhy)) nhy=0; /* number of lags on the y axis */
            if(! sf_getint("nhz",&nhz)) nhz=0; /* number of lags on the z axis */
            if(! sf_getint("nht",&nht)) nht=0; /* number of lags on the t axis */
            if(! sf_getfloat("dht",&dht)) sf_error("need dht");
            oht = -nht*dht;

            nhx2=2*nhx+1; nhy2=2*nhy+1;
            nhz2=2*nhz+1; nht2=2*nht+1;

            aa=sf_maxa(nhx2,-nhx*cub->amx.d,cub->amx.d);
            sf_setlabel(aa,"hx"); sf_setunit(aa,"");
            if(verb) sf_raxa(aa);
            sf_oaxa(Pi,aa,1);

            aa=sf_maxa(nhy2,-nhy*cub->amy.d,cub->amy.d);
            sf_setlabel(aa,"hy"); sf_setunit(aa,"");
            if(verb) sf_raxa(aa);
            sf_oaxa(Pi,aa,2);

            aa=sf_maxa(nhz2,-nhz*cub->az.d,cub->az.d);
            sf_setlabel(aa,"hz"); sf_setunit(aa,"");
            if(verb) sf_raxa(aa);
            sf_oaxa(Pi,aa,3);

            aa=sf_maxa(nht2,-nht*dht,dht);
            sf_setlabel(aa,"ht"); sf_setunit(aa,"s");
            if(verb) sf_raxa(aa);
            sf_oaxa(Pi,aa,4);
 
            sf_oaxa(Pi,ac,5);

        }
        else{
            sf_oaxa(Pi,amx,1);
            sf_oaxa(Pi,amy,2);
            sf_oaxa(Pi,az, 3);
        }

        cip = wexcip_init(cub,nhx,nhy,nhz,nht,nhx2,nhy2,nhz2,nht2,nc,dht,oht,Fc,eic);
        mva = wexmva_init(cub,cip);
 
        /* WEMVA operator, dS -> dW */
        wexmva(mva,adj,cub,ssr,lsr,tap,slo,Bws,Bwr,Pws,Pwr,Ps);
         
        sf_filefresh(Pws);
        sf_filefresh(Pwr);

        /* I.C. operator, dW -> dI */
        wexcip_for(cub,cip,Bws,Pwr,Pti,eic,0,0); /* CONJ( Ws) dWr */
        sf_seek(Pti,(off_t)0,SEEK_SET);
        wexcip_for(cub,cip,Pws,Bwr,Pti,eic,0,1); /* CONJ(dWs)  Wr */

        sf_filefresh(Pti);
        sf_filecopy(Pi,Pti,SF_COMPLEX);
    }

    /*------------------------------------------------------------*/
    /* close structures */
    wexslo_close(slo);
    wexssr_close(cub,ssr);
    wextap2D_close(tap);
    wexmva_close(mva);
    wexcip_close(cip,eic);
    /*------------------------------------------------------------*/

    /*------------------------------------------------------------*/
    /* close files */
    if (Ps!=NULL) sf_fileclose(Ps);
    if (Fc!=NULL) sf_fileclose(Fc);
    if (Pi!=NULL) sf_fileclose(Pi);
    if (Bws!=NULL) sf_fileclose(Bws);
    if (Bwr!=NULL) sf_fileclose(Bwr);
    if (Pws!=NULL) sf_tmpfileclose(Pws);
    if (Pwr!=NULL) sf_tmpfileclose(Pwr);
    if (Pti!=NULL) sf_tmpfileclose(Pti);
    /*------------------------------------------------------------*/

    exit (0);
}
Beispiel #6
0
int main(int argc, char* argv[])
{
    /*------------------------------------------------------------*/
    /* Execution control, I/O files and geometry                  */
    /*------------------------------------------------------------*/
    bool verb,fsrf,snap,back,esou; /* execution flags */
    int  jsnap,ntsnap,jdata; /* jump along axes */
    int  shft; /* time shift for wavefield matching in RTM */

    /* I/O files */
    sf_file Fwav=NULL; /* wavelet   */
    sf_file Fdat=NULL; /* data      */
    sf_file Fsou=NULL; /* sources   */
    sf_file Frec=NULL; /* receivers */
    sf_file Fccc=NULL; /* velocity  */
    sf_file Frkp=NULL; /* app. rank */
    sf_file Fltp=NULL; /* left mat  */
    sf_file Frtp=NULL; /* right mat */
    sf_file Fwfp=NULL; /* wavefield */
    sf_file Frks=NULL; /* app. rank */
    sf_file Flts=NULL; /* left mat  */
    sf_file Frts=NULL; /* right mat */
    sf_file Fwfs=NULL; /* wavefield */

    /* cube axes */
    sf_axis at,ax,ay,az; /* time, x, y, z */ 
    sf_axis asx,asy,arx,ary,ac;    /* sou, rec-x, rec-y, component */ 

    /* dimension, index and interval */
    int     nt,nz,nx,ny,ns,nr,nc,nb;
    int     it,iz,ix,iy;
    float   dt,dz,dx,dy;
    int     nxyz, nk;

    /* FDM and KSP structure */ //!!!JS
    fdm3d    fdm=NULL;
    dft3d    dft=NULL;
    clr3d    clr_p=NULL, clr_s=NULL;

    /* I/O arrays for sou & rec */
    sf_complex***ww=NULL;    /* wavelet   */
    pt3d        *ss=NULL;    /* sources   */
    pt3d        *rr=NULL;    /* receivers */
    sf_complex **dd=NULL;    /* data      */

    /*------------------------------------------------------------*/
    /* displacement: uo = U @ t; up = U @ t+1                     */
    /*------------------------------------------------------------*/
    sf_complex ***uox, ***uoy, ***uoz, **uo;
    sf_complex ***uox_p, ***uoy_p, ***uoz_p, **uo_p;
    sf_complex ***uox_s, ***uoy_s, ***uoz_s, **uo_s;
    /*sf_complex ***upx, ***upy, ***upz, **up;*/

    /*------------------------------------------------------------*/
    /* lowrank decomposition arrays                               */
    /*------------------------------------------------------------*/
    int ntmp, *n2s_p, *n2s_s;
    sf_complex **lt_p, **rt_p, **lt_s, **rt_s;

    /*------------------------------------------------------------*/
    /* linear interpolation weights/indices                       */
    /*------------------------------------------------------------*/
    lint3d cs,cr; /* for injecting source and extracting data */

    /* Gaussian bell */
    int nbell;
    
    /*------------------------------------------------------------*/
    /* wavefield cut params                                       */
    /*------------------------------------------------------------*/
    sf_axis   acz=NULL,acx=NULL,acy=NULL;
    int       nqz,nqx,nqy;
    float     oqz,oqx,oqy;
    float     dqz,dqx,dqy;
    sf_complex***uc=NULL; /* tmp array for output wavefield snaps */

    /*------------------------------------------------------------*/
    /* init RSF                                                   */
    /*------------------------------------------------------------*/
    sf_init(argc,argv);

    /*------------------------------------------------------------*/
    /* OMP parameters                                             */
    /*------------------------------------------------------------*/
#ifdef _OPENMP
    omp_init();
#endif

    /*------------------------------------------------------------*/
    /* read execution flags                                       */
    /*------------------------------------------------------------*/
    if(! sf_getbool("verb",&verb)) verb=false; /* verbosity flag */
    if(! sf_getbool("snap",&snap)) snap=false; /* wavefield snapshots flag */
    if(! sf_getbool("free",&fsrf)) fsrf=false; /* free surface flag */
    if(! sf_getbool("back",&back)) back=false; /* backward extrapolation flag (for rtm) */
    if(! sf_getbool("esou",&esou)) esou=false; /* explosive force source */

    /*------------------------------------------------------------*/
    /* I/O files                                                  */
    /*------------------------------------------------------------*/
    Fwav = sf_input ("in" ); /* wavelet   */
    Fdat = sf_output("out"); /* data      */
    Fsou = sf_input ("sou"); /* sources   */
    Frec = sf_input ("rec"); /* receivers */
    Fccc = sf_input ("ccc"); /* stiffness */
    Frkp = sf_input ("rkp"); /* app. rank */
    Fltp = sf_input ("ltp"); /* left mat  */
    Frtp = sf_input ("rtp"); /* right mat */
    Fwfp = sf_output("wfp"); /* wavefield */
    Frks = sf_input ("rks"); /* app. rank */
    Flts = sf_input ("lts"); /* left mat  */
    Frts = sf_input ("rts"); /* right mat */
    Fwfs = sf_output("wfs"); /* wavefield */

    /*------------------------------------------------------------*/
    /* axes                                                       */
    /*------------------------------------------------------------*/
    at = sf_iaxa(Fwav,4); sf_setlabel(at,"t"); if(verb) sf_raxa(at); /* time */
    az = sf_iaxa(Fccc,1); sf_setlabel(az,"z"); if(verb) sf_raxa(az); /* depth */
    ax = sf_iaxa(Fccc,2); sf_setlabel(ax,"x"); if(verb) sf_raxa(ax); /* space x */
    ay = sf_iaxa(Fccc,3); sf_setlabel(ay,"y"); if(verb) sf_raxa(ay); /* space y */

    asx = sf_iaxa(Fsou,2); sf_setlabel(asx,"sx"); if(verb) sf_raxa(asx); /* sources x */
    asy = sf_iaxa(Fsou,3); sf_setlabel(asy,"sy"); if(verb) sf_raxa(asy); /* sources y */
    arx = sf_iaxa(Frec,2); sf_setlabel(arx,"rx"); if(verb) sf_raxa(arx); /* receivers x */
    ary = sf_iaxa(Frec,3); sf_setlabel(ary,"ry"); if(verb) sf_raxa(ary); /* receivers y */

    nt = sf_n(at); dt = sf_d(at);
    nz = sf_n(az); dz = sf_d(az);
    nx = sf_n(ax); dx = sf_d(ax);
    ny = sf_n(ay); dy = sf_d(ay);

    ns = sf_n(asx)*sf_n(asy);
    nr = sf_n(arx)*sf_n(ary);

    /*------------------------------------------------------------*/
    /* other execution parameters                                 */
    /*------------------------------------------------------------*/
    if(! sf_getint("nbell",&nbell)) nbell=NOP;  /* bell size */
    if(verb) sf_warning("nbell=%d",nbell);
    if(! sf_getint("jdata",&jdata)) jdata=1;
    if(snap) {  /* save wavefield every *jsnap* time steps */
	if(! sf_getint("jsnap",&jsnap)) jsnap=nt;
    }
    if(back) {
        shft = (nt-1)%jsnap;
        sf_warning("For backward extrapolation, make sure nbell(%d)=0",nbell);
    } else shft = 0;

    /*------------------------------------------------------------*/
    /* expand domain for FD operators and ABC                     */
    /*------------------------------------------------------------*/
    if( !sf_getint("nb",&nb)) nb=NOP;

    fdm=fdutil3d_init(verb,fsrf,az,ax,ay,nb,1);
    if(nbell) fdbell3d_init(nbell);

    sf_setn(az,fdm->nzpad); sf_seto(az,fdm->ozpad); if(verb) sf_raxa(az);
    sf_setn(ax,fdm->nxpad); sf_seto(ax,fdm->oxpad); if(verb) sf_raxa(ax);
    sf_setn(ay,fdm->nypad); sf_seto(ay,fdm->oypad); if(verb) sf_raxa(ay);

    /*------------------------------------------------------------*/
    /* 3D vector components                                       */
    /*------------------------------------------------------------*/
    nc=3;
    ac=sf_maxa(nc,0,1); /* output 3 cartesian components */

    /*------------------------------------------------------------*/
    /* setup output data header                                   */
    /*------------------------------------------------------------*/
    sf_settype(Fdat,SF_COMPLEX);
    sf_oaxa(Fdat,arx,1);
    sf_oaxa(Fdat,ary,2);
    sf_oaxa(Fdat,ac,3);

    sf_setn(at,nt/jdata);
    sf_setd(at,dt*jdata);
    sf_oaxa(Fdat,at,4);

    /* setup output wavefield header */
    if(snap) {
	if(!sf_getint  ("nqz",&nqz)) nqz=sf_n(az);
	if(!sf_getint  ("nqx",&nqx)) nqx=sf_n(ax);
	if(!sf_getint  ("nqy",&nqy)) nqy=sf_n(ay);

	if(!sf_getfloat("oqz",&oqz)) oqz=sf_o(az);
	if(!sf_getfloat("oqx",&oqx)) oqx=sf_o(ax);
	if(!sf_getfloat("oqy",&oqy)) oqy=sf_o(ay);

	dqz=sf_d(az);
	dqx=sf_d(ax);
	dqy=sf_d(ay);

	acz = sf_maxa(nqz,oqz,dqz); sf_raxa(acz);
	acx = sf_maxa(nqx,oqx,dqx); sf_raxa(acx);
	acy = sf_maxa(nqy,oqy,dqy); sf_raxa(acy);

	uc=sf_complexalloc3(sf_n(acz),sf_n(acx),sf_n(acy));

	ntsnap=0; /* ntsnap = it/jsnap+1; */
	for(it=0; it<nt; it++) {
	    if(it%jsnap==0) ntsnap++;
	}
	sf_setn(at,  ntsnap);
	sf_setd(at,dt*jsnap);
	if(verb) sf_raxa(at);

        sf_settype(Fwfp,SF_COMPLEX);
	sf_oaxa(Fwfp,acz,1);
	sf_oaxa(Fwfp,acx,2);
	sf_oaxa(Fwfp,acy,3);
	sf_oaxa(Fwfp,ac, 4);
	sf_oaxa(Fwfp,at, 5);

        sf_settype(Fwfs,SF_COMPLEX);
	sf_oaxa(Fwfs,acz,1);
	sf_oaxa(Fwfs,acx,2);
	sf_oaxa(Fwfs,acy,3);
	sf_oaxa(Fwfs,ac, 4);
	sf_oaxa(Fwfs,at, 5);
    }

    /*------------------------------------------------------------*/
    /* source and data array                                      */
    /*------------------------------------------------------------*/
    ww=sf_complexalloc3(ns,nc,nt); /* Fast axis: n_sou > n_comp > n_time */
    sf_complexread(ww[0][0],nt*nc*ns,Fwav);

    dd=sf_complexalloc2(nr,nc);

    /*------------------------------------------------------------*/
    /* setup source/receiver coordinates                          */
    /*------------------------------------------------------------*/
    ss = (pt3d*) sf_alloc(ns,sizeof(*ss)); 
    rr = (pt3d*) sf_alloc(nr,sizeof(*rr)); 

    pt3dread1(Fsou,ss,ns,3); /* read (x,y,z) coordinates */
    pt3dread1(Frec,rr,nr,3); /* read (x,y,z) coordinates */

    /* calculate 3d linear interpolation coef for sou & rec */
    cs = lint3d_make(ns,ss,fdm);
    cr = lint3d_make(nr,rr,fdm);

    /*------------------------------------------------------------*/
    /* allocate and initialize wavefield arrays                   */
    /*------------------------------------------------------------*/
    /* z-component */
    uoz=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad);
    uoz_p=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad);
    uoz_s=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad);
    /*upz=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad);*/

    /* x-component */
    uox=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad);
    uox_p=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad);
    uox_s=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad);
    /*upx=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad);*/

    /* y-component */
    uoy=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad);
    uoy_p=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad);
    uoy_s=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad);
    /*upy=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad);*/

    /* wavefield vector */
    uo = (sf_complex**) sf_alloc(3,sizeof(sf_complex*));
    uo[0] = uox[0][0]; uo[1] = uoy[0][0]; uo[2] = uoz[0][0];
    uo_p = (sf_complex**) sf_alloc(3,sizeof(sf_complex*));
    uo_p[0] = uox_p[0][0]; uo_p[1] = uoy_p[0][0]; uo_p[2] = uoz_p[0][0];
    uo_s = (sf_complex**) sf_alloc(3,sizeof(sf_complex*));
    uo_s[0] = uox_s[0][0]; uo_s[1] = uoy_s[0][0]; uo_s[2] = uoz_s[0][0];
    /*up = (sf_complex**) sf_alloc(3,sizeof(sf_complex*));*/
    /*up[0] = upx[0][0]; up[1] = upy[0][0]; up[2] = upz[0][0];*/

    /* initialize fft and lrk */
    dft = dft3d_init(1,false,false,fdm);
    nxyz= fdm->nypad*fdm->nxpad*fdm->nzpad;
    nk  = dft->nky  *dft->nkx  *dft->nkz;

    /*------------------------------------------------------------*/ 
    /* allocation I/O arrays                                      */
    /*------------------------------------------------------------*/ 
    n2s_p = sf_intalloc(9);
    sf_intread(n2s_p,9,Frkp);
    clr_p = clr3d_make2(n2s_p,fdm);

    n2s_s = sf_intalloc(9);
    sf_intread(n2s_s,9,Frks);
    clr_s = clr3d_make2(n2s_s,fdm);

    if (clr_p->n2_max > clr_s->n2_max) clr3d_init(fdm,dft,clr_p);
    else clr3d_init(fdm,dft,clr_s);

    /* check the dimension */
    if (!sf_histint(Fltp,"n1",&ntmp) || ntmp != nxyz)          sf_error("Need n1=%d in left",nxyz);
    if (!sf_histint(Fltp,"n2",&ntmp) || ntmp != clr_p->n2_sum) sf_error("Need n2=%d in left",clr_p->n2_sum);
    if (!sf_histint(Frtp,"n1",&ntmp) || ntmp != nk)            sf_error("Need n1=%d in right",nk);
    if (!sf_histint(Frtp,"n2",&ntmp) || ntmp != clr_p->n2_sum) sf_error("Need n2=%d in right",clr_p->n2_sum);
  
    lt_p = sf_complexalloc2(nxyz,clr_p->n2_sum); 
    rt_p = sf_complexalloc2(nk  ,clr_p->n2_sum); 
    sf_complexread(lt_p[0],nxyz*clr_p->n2_sum,Fltp);
    sf_complexread(rt_p[0],nk  *clr_p->n2_sum,Frtp);

    if (!sf_histint(Flts,"n1",&ntmp) || ntmp != nxyz)          sf_error("Need n1=%d in left",nxyz);
    if (!sf_histint(Flts,"n2",&ntmp) || ntmp != clr_s->n2_sum) sf_error("Need n2=%d in left",clr_s->n2_sum);
    if (!sf_histint(Frts,"n1",&ntmp) || ntmp != nk)            sf_error("Need n1=%d in right",nk);
    if (!sf_histint(Frts,"n2",&ntmp) || ntmp != clr_s->n2_sum) sf_error("Need n2=%d in right",clr_s->n2_sum);

    lt_s = sf_complexalloc2(nxyz,clr_s->n2_sum); 
    rt_s = sf_complexalloc2(nk  ,clr_s->n2_sum); 
    sf_complexread(lt_s[0],nxyz*clr_s->n2_sum,Flts);
    sf_complexread(rt_s[0],nk  *clr_s->n2_sum,Frts);

    /* initialize to zero */
#ifdef _OPENMP
#pragma omp parallel for              \
    schedule(dynamic,1)               \
    private(iy,ix,iz)                 \
    shared(fdm,uoz,uox,uoy,uoz_p,uox_p,uoy_p,uoz_s,uox_s,uoy_s)
#endif
    for        (iy=0; iy<fdm->nypad; iy++) {
	for    (ix=0; ix<fdm->nxpad; ix++) {
	    for(iz=0; iz<fdm->nzpad; iz++) {
		uoz  [iy][ix][iz]=sf_cmplx(0.,0.); uox  [iy][ix][iz]=sf_cmplx(0.,0.); uoy  [iy][ix][iz]=sf_cmplx(0.,0.);
		uoz_p[iy][ix][iz]=sf_cmplx(0.,0.); uox_p[iy][ix][iz]=sf_cmplx(0.,0.); uoy_p[iy][ix][iz]=sf_cmplx(0.,0.);
		uoz_s[iy][ix][iz]=sf_cmplx(0.,0.); uox_s[iy][ix][iz]=sf_cmplx(0.,0.); uoy_s[iy][ix][iz]=sf_cmplx(0.,0.);
		/*upz[iy][ix][iz]=sf_cmplx(0.,0.); upx[iy][ix][iz]=sf_cmplx(0.,0.); upy[iy][ix][iz]=sf_cmplx(0.,0.);*/
	    }
	}
    }

    /*------------------------------------------------------------*/ 
    /*------------------------ MAIN LOOP -------------------------*/ 
    /*------------------------------------------------------------*/
    if(verb) fprintf(stderr,"\n");
    for (it=0; it<nt; it++) {
        if(verb) sf_warning("it=%d/%d;",it,nt); /*fprintf(stderr,"\b\b\b\b\b%d",it);*/

	/*------------------------------------------------------------*/
	/* apply lowrank matrix to wavefield vector                   */
        /*------------------------------------------------------------*/
        clr3d_apply(uo_p, uo, lt_p, rt_p, fdm, dft, clr_p);
        clr3d_apply(uo_s, uo, lt_s, rt_s, fdm, dft, clr_s);

	/*------------------------------------------------------------*/
        /* combine P and S wave modes                                 */
        /*------------------------------------------------------------*/
#ifdef _OPENMP
#pragma omp parallel for              \
        schedule(dynamic,1)               \
        private(iy,ix,iz)                 \
        shared(fdm,uoz,uox,uoy,uoz_p,uox_p,uoy_p,uoz_s,uox_s,uoy_s)
#endif
        for        (iy=0; iy<fdm->nypad; iy++) {
            for    (ix=0; ix<fdm->nxpad; ix++) {
                for(iz=0; iz<fdm->nzpad; iz++) {
                    uoz[iy][ix][iz] = uoz_p[iy][ix][iz] + uoz_s[iy][ix][iz];
                    uox[iy][ix][iz] = uox_p[iy][ix][iz] + uox_s[iy][ix][iz];
                    uoy[iy][ix][iz] = uoy_p[iy][ix][iz] + uoy_s[iy][ix][iz];
                    /*upz[iy][ix][iz]=sf_cmplx(0.,0.); upx[iy][ix][iz]=sf_cmplx(0.,0.); upy[iy][ix][iz]=sf_cmplx(0.,0.);*/
                }
            }
        }

	/*------------------------------------------------------------*/
	/* free surface */
	/*------------------------------------------------------------*/
	if(fsrf) { /* need to do something here */ }

        /*------------------------------------------------------------*/
	/* inject displacement source                                 */
	/*------------------------------------------------------------*/
        if(esou) {
            /* exploding force source */
            lint3d_expl_complex(uoz,uox,uoy,ww[it],cs);
        } else {
            if(nbell) {
                lint3d_bell_complex(uoz,ww[it][0],cs);
                lint3d_bell_complex(uox,ww[it][1],cs);
                lint3d_bell_complex(uoy,ww[it][2],cs);
            } else {
                lint3d_inject_complex(uoz,ww[it][0],cs);
                lint3d_inject_complex(uox,ww[it][1],cs);
                lint3d_inject_complex(uoy,ww[it][2],cs);
            }
        }

	/*------------------------------------------------------------*/
	/* cut wavefield and save */
	/*------------------------------------------------------------*/
        if(snap && (it-shft)%jsnap==0) {
            /* P wave */
            cut3d_complex(uoz_p,uc,fdm,acz,acx,acy);
            sf_complexwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfp);

            cut3d_complex(uox_p,uc,fdm,acz,acx,acy);
            sf_complexwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfp);

            cut3d_complex(uoy_p,uc,fdm,acz,acx,acy);
            sf_complexwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfp);

            /* S wave */
            cut3d_complex(uoz_s,uc,fdm,acz,acx,acy);
            sf_complexwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfs);

            cut3d_complex(uox_s,uc,fdm,acz,acx,acy);
            sf_complexwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfs);

            cut3d_complex(uoy_s,uc,fdm,acz,acx,acy);
            sf_complexwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfs);
        }

        lint3d_extract_complex(uoz,dd[0],cr);
        lint3d_extract_complex(uox,dd[1],cr);
        lint3d_extract_complex(uoy,dd[2],cr);
        if(it%jdata==0) sf_complexwrite(dd[0],nr*nc,Fdat);

    }
    if(verb) sf_warning(".");
    if(verb) fprintf(stderr,"\n");    
    
    /*------------------------------------------------------------*/
    /* deallocate arrays */
    
    free(dft);
    dft3d_finalize();
    free(clr_p); free(clr_s);
    clr3d_finalize();

    free(**ww); free(*ww); free(ww);
    free(ss);
    free(rr);
    free(*dd);  free(dd);

    free(n2s_p); free(n2s_s);
    free(*lt_p); free(lt_p); free(*rt_p); free(rt_p);
    free(*lt_s); free(lt_s); free(*rt_s); free(rt_s);

    free(**uoz  ); free(*uoz  ); free(uoz)  ;
    free(**uoz_p); free(*uoz_p); free(uoz_p);
    free(**uoz_s); free(*uoz_s); free(uoz_s);
    /*free(**upz); free(*upz); free(upz);*/
    free(uo); free(uo_p); free(uo_s);
    /*free(up);*/

    if (snap) {
       free(**uc);  free(*uc);  free(uc);    
    }

    /*------------------------------------------------------------*/


    exit (0);
}
Beispiel #7
0
int main(int argc, char* argv[])
{

    float *data /*input [nk] */; 
    int nk      /* data length */;
    float dk    /* data sampling */; 
    float k0    /* initial location */;
    bool verb   /* verbosity flag */;
    int niter   /* number of iterations */; 

    int ik, iter;
    float x1, x2, x3, dx1, dx2, dx3, x10, x20, x30, x4, x5;
    float k, f, s, l, r, p, q, s2, y1, y2, y3, sk, s1, s3;
    float a11, a12, a13, a22, a23, a33, a2, a3, a4, a5, a6, d;
    float b11, b12, b13, b22, b23, b33, eps, r2; 
    
    sf_file in, out, prm;

    /* Estimate shape (Caution: data gets corrupted) */ 

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


    if (SF_FLOAT != sf_gettype(in)) sf_error("Need float input");
    if (!sf_histint(in,"n1",&nk)) sf_error("No n1= in input");
    if (!sf_histfloat(in,"d1",&dk)) sf_error("No d1= in input");
    if (!sf_histfloat(in,"o1",&k0)) sf_error("No o1= in input");
 
    if (!sf_getint("niter",&niter)) niter=100;
    /* number of iterations */
    if (!sf_getfloat("x10",&x10)) x10=6.;
    /* initial nonlinear parameter x1 value */
    if (!sf_getfloat("x20",&x20)) x20=-0.5;
    /* initial nonlinear parameter x2 value */
    if (!sf_getfloat("x30",&x30)) x30=200.;
    /* initial nonlinear parameter x3 value */
    if (!sf_getbool("verb",&verb)) verb=false;
    /* verbosity flag */

    sf_putint(prm,"n1",3);
    sf_putint(prm,"nk",nk);
    sf_putfloat(prm,"dk",dk);
    sf_putfloat(prm,"k0",k0);
    sf_fileflush(prm,in);

    data = sf_floatalloc(nk);
    
    sf_floatread(data,nk,in);

    x1 = x10; /* initial x1 */
    x2 = x20; /* initial x2 */
    x3 = x30; /* initial x3 */
    x4 = x3*x3;

    eps = 10.*FLT_EPSILON;
    eps *= eps;
    a11 = (float)nk;

    if (verb) sf_warning("got x10=%g x20=%g x30=%g k0=%g niter=%d nk=%d dk=%g",
			 x10,x20,x30,k0,niter,nk,dk);
	
    /* Gauss iterations */
    for (iter = 0; iter < niter; iter++) {
        x5 = 2.*x2*x3;
        s2 = y1 = y2 = y3 = sk = s1 = s3 = a12 = r2 = 0.;
	for (ik = 0; ik < nk; ik++) {
	    k = ik*dk + k0;
	    k *= k;
            s = 1. + x4*k;
	    l = log(s);
            q = 1./s;
	    p = k*q;
            
            s2 += l*l;
            sk += p;
            a12 += l;

	    f = log(data[ik]);       
	    r = x1 + x2*l - f;

	    y1 += r;
	    y2 += r*l;
	    y3 += r*p;
	    s1 += p*(r + x2*l);
            s3 += p*q*(2.*x2*x4*k + r*(1.-x4*k));

	    r2 += r*r;
	}

        y3 *= x5;

	a13 = x5*sk;
	a22 = s2;
        a23 = 2.*x3*s1;
	a33 = 2.*x2*s3;

	a2 = a12*a12;
	a3 = a12*a13;
	a4 = a13*a13;
        a5 = a23*a23;
        a6 = a22*a33;

        d = 1./(a11*(a6-a5) + 2.*a3*a23 - a33*a2 - a22*a4);

	b11 = a6-a5;
        b12 = a13*a23-a12*a33;
	b13 = a12*a23-a13*a22;
	b22 = a11*a33-a4;
	b23 = a3-a23*a11;
	b33 = a11*a22-a2;

	dx1 = -d*(b11*y1 + b12*y2 + b13*y3);
	dx2 = -d*(b12*y1 + b22*y2 + b23*y3);
	dx3 = -d*(b13*y1 + b23*y2 + b33*y3);

	x1 += dx1;
	x2 += dx2;
	x3 += dx3;
        x4 = x3*x3;
	
        if (verb) sf_warning("iter=%d r2=%g dx1=%g dx2=%g dx3=%g x1=%g x2=%g x3=%g",
			     iter,r2,dx1,dx2,dx3,x1,x2,x3);
	if (r2 < eps || (dx1*dx1+dx2*dx2+dx3*dx3) < eps) break;    
    }
 
    for (ik = 0; ik < nk; ik++) {
	k = ik*dk + k0;
	k *= k;
	data[ik] = exp(x1+x2*log(1.+x4*k));
    }
 
    if (verb) sf_warning ("%d iterations", iter);        
	
    /* Optimized parameters for f = log(data) = log(d0) + a*log(1+b*b*k*k) where a = -(nu/2+1/4) */
    sf_warning ("b=%g nu=%g d0=%g",x3,-2*x2-0.5,exp(x1));

    sf_floatwrite(&x3,1,prm);
    sf_floatwrite(&x2,1,prm);
    sf_floatwrite(&x1,1,prm);

    sf_floatwrite (data,nk,out);

    exit (0);
}
Beispiel #8
0
int main(int argc, char* argv[])
{
    int	ix, iz, jx, jz, ixf, izf, ixx, izz, i,j,im, jm,nx,nz,nxf,nzf,nxpad,nzpad,it,ii,jj;
    float   kxmax,kzmax;

    float   A, f0, t, t0, dx, dz, dxf, dzf, dt, dkx, dkz, dt2, div;
    int     mm, nvx, nvz, ns;
    int     hnkx, hnkz, nkx, nkz, nxz, nkxz;
    int     hnkx1=1, hnkz1=1, nkx1, nkz1;
    int     isx, isz, isxm, iszm; /*source location */
    int     itaper; /* tapering or not for spectrum of oprtator*/

    int     nstep;            /* every nstep in spatial grids to calculate filters sparsely*/

    float   *coeff_1dx, *coeff_1dz, *coeff_2dx, *coeff_2dz; /* finite-difference coefficient */

    float **apvx, **apvz, **apvxx, **apvzz;    /* projection deviation operator of P-wave for a location */

    float ****ex=NULL, ****ez=NULL;                      /* operator for whole model for P-wave*/
    float **exx=NULL, **ezz=NULL;                        /* operator for constant model for P-wave*/

    float **vp0, **vs0, **epsi, **del, **theta;         /* velocity model */
    float **p1, **p2, **p3, **q1, **q2, **q3, **p3c=NULL, **q3c=NULL, **sum=NULL;  /* wavefield array */
    float *kx, *kz, *kkx, *kkz, *kx2, *kz2, **taper;

    clock_t t2, t3, t4, t5;
    float   timespent, fx,fz; 
    char    *tapertype;

    int     isep=1;
    int     ihomo=1;

    double  vp2, vs2, ep2, de2, the;

    sf_file Fo1, Fo2, Fo3, Fo4, Fo5, Fo6, Fo7, Fo8;
    sf_file Fvp0, Fvs0, Feps, Fdel, Fthe;

    sf_axis az, ax;
       
    sf_init(argc,argv);

    /* t1=clock(); */
 
    /*  wavelet parameter for source definition */
    f0=30.0;                  
    t0=0.04;                  
    A=1.0;                  

    /* time samping paramter */
    if (!sf_getint("ns",&ns)) ns=301;
    if (!sf_getfloat("dt",&dt)) dt=0.001;
    if (!sf_getint("isep",&isep)) isep=0;             /* if isep=1, separate wave-modes */
    if (!sf_getint("ihomo",&ihomo)) ihomo=0;          /* if ihomo=1, homogeneous medium */
    if (NULL== (tapertype=sf_getstring("tapertype"))) tapertype="D"; /* taper type*/
    if (!sf_getint("nstep",&nstep)) nstep=1; /* grid step to calculate operators: 1<=nstep<=5 */

    sf_warning("isep=%d",isep);
    sf_warning("ihomo=%d",ihomo);
    sf_warning("tapertype=%s",tapertype);
    sf_warning("nstep=%d",nstep);

    sf_warning("ns=%d dt=%f",ns,dt);
    sf_warning("read velocity model parameters");

    /* setup I/O files */
    Fvp0 = sf_input ("in");  /* vp0 using standard input */
    Fvs0 = sf_input ("vs0");  /* vs0 */
    Feps = sf_input ("epsi");  /* epsi */
    Fdel = sf_input ("del");  /* delta */
    Fthe = sf_input ("the");  /* theta */

    /* Read/Write axes */
    az = sf_iaxa(Fvp0,1); nvz = sf_n(az); dz = sf_d(az)*1000.0;
    ax = sf_iaxa(Fvp0,2); nvx = sf_n(ax); dx = sf_d(ax)*1000.0;
    fx=sf_o(ax);
    fz=sf_o(az);

    /* source definition */
    isx=nvx/2;
    isz=nvz/2;
    /* isz=nvz*2/5; */

    /* wave modeling space */
    nx=nvx;
    nz=nvz;
    nxpad=nx+2*_m;
    nzpad=nz+2*_m;

    sf_warning("dx=%f dz=%f",dx,dz);

    sf_warning("nx=%d nz=%d nxpad=%d nzpad=%d", nx,nz,nxpad,nzpad);

    vp0=sf_floatalloc2(nz,nx);	
    vs0=sf_floatalloc2(nz,nx);	
    epsi=sf_floatalloc2(nz,nx);	
    del=sf_floatalloc2(nz,nx);	
    theta=sf_floatalloc2(nz,nx);	

    nxz=nx*nz;
    mm=2*_m+1;

    dt2=dt*dt;
    isxm=isx+_m;  /* source's x location */
    iszm=isz+_m;  /* source's z-location */

    /* read velocity model */
    sf_floatread(vp0[0],nxz,Fvp0);
    sf_floatread(vs0[0],nxz,Fvs0);
    sf_floatread(epsi[0],nxz,Feps);
    sf_floatread(del[0],nxz,Fdel);
    sf_floatread(theta[0],nxz,Fthe);

    for(i=0;i<nx;i++)
        for(j=0;j<nz;j++)
	    theta[i][j] *= SF_PI/180.0;

    t2=clock();

    /* setup I/O files */
    Fo1 = sf_output("out"); /* pseudo-pure P-wave x-component */
    Fo2 = sf_output("PseudoPurePz"); /* pseudo-pure P-wave z-component */
    Fo3 = sf_output("PseudoPureP"); /* scalar P-wave field using divergence operator */
    puthead3(Fo1, nz, nx, 1, dz/1000.0, dx/1000.0, dt, fz, fx, 0.0);
    puthead3(Fo2, nz, nx, 1, dz/1000.0, dx/1000.0, dt, fz, fx, 0.0);
    puthead3(Fo3, nz, nx, 1, dz/1000.0, dx/1000.0, dt, fz, fx, 0.0);

    /*****************************************************************************
     *  Calculating polarization deviation operator for wave-mode separation
     * ***************************************************************************/
    if(isep==1)
    {
	/* calculate spatial steps for operater in sparsely sampling grid point */
	dxf=dx*nstep;
	dzf=dz*nstep;
	nxf=nx/nstep+1;
	nzf=nz/nstep+1;

	/* operators length for calculation */
	hnkx=400.0/dx;
	hnkz=400.0/dz;
	nkx=2*hnkx+1;   /* operator length in kx-direction */
	nkz=2*hnkz+1;   /* operator length in kz-direction */

	/* truncated spatial operators length for filtering*/
	hnkx1=200.0/dx;
	hnkz1=200.0/dz;
	nkx1=2*hnkx1+1;
	nkz1=2*hnkz1+1;

	sf_warning("nx=%d nz=%d nxf=%d nzf=%d", nx,nz,nxf,nzf);
	sf_warning("dx=%f dz=%f dxf=%f dzf=%f", dx,dz,dxf,dzf);

	sf_warning("hnkx=%d hnkz=%d nkx=%d nkz=%d", hnkx, hnkz, nkx, nkz);
	sf_warning("hnkx1=%d hnkz1=%d nkx1=%d nkz1=%d", hnkx1, hnkz1, nkx1, nkz1);

	dkx=2*SF_PI/dx/nkx;
	dkz=2*SF_PI/dz/nkz;
	kxmax=SF_PI/dx;
	kzmax=SF_PI/dz;

	kx=sf_floatalloc(nkx);
	kz=sf_floatalloc(nkx);
	kkx=sf_floatalloc(nkx);
	kkz=sf_floatalloc(nkx);
	kx2=sf_floatalloc(nkx);
	kz2=sf_floatalloc(nkx);

	taper=sf_floatalloc2(nkz, nkx);

	/* define axis samples and taper in wavenumber domain */
	kxkztaper(kx, kz, kkx, kkz, kx2, kz2, taper, nkx, nkz, hnkx, hnkz, dkx, dkz, kxmax, kzmax, tapertype);
           
	/* truncation of spatial filter */
	p3c=sf_floatalloc2(nz,nx);
	q3c=sf_floatalloc2(nz,nx);
	sum=sf_floatalloc2(nz,nx);

	if(ihomo==1)
	{
	    exx=sf_floatalloc2(nkz1, nkx1);
	    ezz=sf_floatalloc2(nkz1, nkx1);
	}
	else{ /* to store spatail varaied operators */
	    ex=sf_floatalloc4(nkz1, nkx1, nzf, nxf);
	    ez=sf_floatalloc4(nkz1, nkx1, nzf, nxf);
	}
	nkxz=nkx*nkz;

	apvx=sf_floatalloc2(nkz, nkx);
	apvz=sf_floatalloc2(nkz, nkx);
	apvxx=sf_floatalloc2(nkz, nkx);
	apvzz=sf_floatalloc2(nkz, nkx);

	/* setup I/O files */
	Fo4 = sf_output("apvx"); /* P-wave projection deviation x-comp */
	Fo5 = sf_output("apvz"); /* P-wave projection deviation z-comp */
	Fo6 = sf_output("apvxx"); /* P-wave projection deviation x-comp in (x,z) domain */
	Fo7 = sf_output("apvzz"); /* P-wave projection deviation z-comp in (x,z) domain */

	puthead1(Fo4, nkz, nkx, dkz, -kzmax, dkx, -kxmax);
	puthead1(Fo5, nkz, nkx, dkz, -kzmax, dkx, -kxmax);

	puthead2(Fo6, nkz, nkx, dz/1000.0, 0.0, dx/1000.0, 0.0);
	puthead2(Fo7, nkz, nkx, dz/1000.0, 0.0, dx/1000.0, 0.0);

	/*************calculate projection deviation grid-point by grid-point **********/
	for(ix=0,ixf=0;ix<nx;ix+=nstep,ixf++)
	{
	    for(iz=0,izf=0;iz<nz;iz+=nstep,izf++)
	    {
	        vp2=vp0[ix][iz]*vp0[ix][iz];
	        vs2=vs0[ix][iz]*vs0[ix][iz];
	        ep2=1.0+2*epsi[ix][iz];
	        de2=1.0+2*del[ix][iz];
	        the=theta[ix][iz];

                if(ixf%10==0&&izf%100==0) sf_warning("Operator: nxf=%d ixf=%d izf=%d vp2=%f vs2=%f",nxf, ixf,izf,vp2,vs2);

   	        /*************calculate projection deviation without tapering **********/
                itaper=0;
                /* devvtip: projection deviation operators for P-wave in TTI media */
                devttip(apvx,apvz,kx,kz,kkx,kkz,taper,hnkx,hnkz,dkx,dkz,vp2,vs2,ep2,de2,the,itaper);

                /* inverse Fourier transform */
                kxkz2xz(apvx, apvxx, hnkx, hnkz, nkx, nkz);
                kxkz2xz(apvz, apvzz, hnkx, hnkz, nkx, nkz);

                /* truncation and saving of operator in space-domain */
                if(ihomo==1)
                {
		    for(jx=-hnkx1,ixx=hnkx-hnkx1;jx<=hnkx1;jx++,ixx++)
			for(jz=-hnkz1,izz=hnkz-hnkz1;jz<=hnkz1;jz++,izz++)
			{
			    exx[jx+hnkx1][jz+hnkz1]=apvxx[ixx][izz];
			    ezz[jx+hnkx1][jz+hnkz1]=apvzz[ixx][izz];
			}
                }else{
		    for(jx=-hnkx1,ixx=hnkx-hnkx1;jx<=hnkx1;jx++,ixx++)
			for(jz=-hnkz1,izz=hnkz-hnkz1;jz<=hnkz1;jz++,izz++)
			{
			    ex[ixf][izf][jx+hnkx1][jz+hnkz1]=apvxx[ixx][izz];
			    ez[ixf][izf][jx+hnkx1][jz+hnkz1]=apvzz[ixx][izz];
			}
                }
                if((ix==nx/2&&iz==nz/2&&ihomo==0)||ihomo==1)
                {
		    sf_floatwrite(apvx[0], nkxz, Fo4);
		    sf_floatwrite(apvz[0], nkxz, Fo5);

		    sf_floatwrite(apvxx[0], nkxz, Fo6);
		    sf_floatwrite(apvzz[0], nkxz, Fo7);
                }
                if(ihomo==1) goto loop;

	    }/* iz loop */
	}/* ix loop */
    loop:;

	free(kx);
	free(kz);
	free(kx2);
	free(kz2);
	free(kkx);
	free(kkz);

	free(*taper);

	free(*apvx);
	free(*apvz);
	free(*apvxx);
	free(*apvzz);
    }/* isep */
    /****************End of Calculating Projection Deviation Operator****************/
    t3=clock();
    timespent=(float)(t3-t2)/CLOCKS_PER_SEC;
    sf_warning("Computation time (operators): %f (second)",timespent);

    /****************begin to calculate wavefield****************/
    coeff_2dx=sf_floatalloc(mm);
    coeff_2dz=sf_floatalloc(mm);
    coeff_1dx=sf_floatalloc(mm);
    coeff_1dz=sf_floatalloc(mm);

    coeff2d(coeff_2dx,dx);
    coeff2d(coeff_2dz,dz);
    coeff1d(coeff_1dx,dx);
    coeff1d(coeff_1dz,dz);

    p1=sf_floatalloc2(nzpad, nxpad);
    p2=sf_floatalloc2(nzpad, nxpad);
    p3=sf_floatalloc2(nzpad, nxpad);

    q1=sf_floatalloc2(nzpad, nxpad);
    q2=sf_floatalloc2(nzpad, nxpad);
    q3=sf_floatalloc2(nzpad, nxpad);

    zero2float(p1, nzpad, nxpad);
    zero2float(p2, nzpad, nxpad);
    zero2float(p3, nzpad, nxpad);
        
    zero2float(q1, nzpad, nxpad);
    zero2float(q2, nzpad, nxpad);
    zero2float(q3, nzpad, nxpad);
        
    if(isep==1)
    {
        /* setup I/O files */
        Fo8 = sf_output("PseudoPureSepP"); /* scalar P-wave field using polarization projection oprtator*/

        puthead3(Fo8, nz, nx, 1, dz/1000.0, dx/1000.0, dt, fz, fx, 0.0);
    } else {
	Fo8 = NULL;
    }

    sf_warning("==================================================");
    sf_warning("==  Propagation Using Pseudo-Pure P-Wave Eq.    ==");
    sf_warning("==================================================");
    t4=clock();
    for(it=0;it<ns;it++)
    {
	t=it*dt;

	p2[isxm][iszm]+=Ricker(t, f0, t0, A);
	q2[isxm][iszm]+=Ricker(t, f0, t0, A);

	/* fwpttipseudop: forward-propagating in TTI media with pseudo-pure P-wave equation */
	fwpttipseudop(dt2, p1, p2, p3, q1, q2, q3, coeff_2dx, coeff_2dz,
		      dx, dz, nx, nz, nxpad, nzpad, vp0, vs0, epsi, del, theta);

	/******* output wavefields: component and divergence *******/
	if(it==ns-1)
	{
	    for(i=0;i<nx;i++)
	    {
		im=i+_m;
		for(j=0;j<nz;j++)
		{
		    jm=j+_m;
		    sf_floatwrite(&p3[im][jm],1,Fo1);
		    sf_floatwrite(&q3[im][jm],1,Fo2);

		    div=p3[im][jm]+q3[im][jm];

		    sf_floatwrite(&div,1,Fo3);
		}
	    }/* i loop*/

	    /* correct projection error for accurate separate qP wave in spatial domain */
	    if(isep==1)
	    {
		zero2float(p3c,nz,nx);
		zero2float(q3c,nz,nx);
		zero2float(sum, nz, nx);

		if(ihomo==1)
		    filter2dsepglobal(p3, q3, p3c, q3c, exx, ezz, nx, nz, hnkx1, hnkz1);
		else
		    filter2dsep(p3, q3, p3c, q3c, ex, ez, nx, nz, nstep, hnkx1, hnkz1);

		for(i=0;i<nx;i++)
		    for(j=0;j<nz;j++)
			sum[i][j]=p3c[i][j]+q3c[i][j];

		sf_floatwrite(sum[0],nx*nz, Fo8);
	    }
	}/* (it+1)%ntstep==0 */

	/**************************************/
	for(i=0,ii=_m;i<nx;i++,ii++)
	    for(j=0,jj=_m;j<nz;j++,jj++)
	    {
		p1[ii][jj]=p2[ii][jj];	
		p2[ii][jj]=p3[ii][jj];	

		q1[ii][jj]=q2[ii][jj];	
		q2[ii][jj]=q3[ii][jj];	
	    }

	if(it%50==0)
	    sf_warning("Pseudo: it= %d",it);
    }/* it loop */
    t5=clock();
    timespent=(float)(t5-t4)/CLOCKS_PER_SEC;
    sf_warning("Computation time (propagation + separation): %f (second)",timespent);

    if(isep==1)
    {
	free(*p3c);
	free(*q3c);
	free(*sum);

	if(ihomo==1)
	{
	    free(*exx);
	    free(*ezz);
	}else{
	    free(***ex);
	    free(***ez);
	}
    }

    free(*p1);
    free(*p2);
    free(*p3);
    free(*q1);
    free(*q2);
    free(*q3);

    free(*vp0);
    free(*vs0);
    free(*epsi);
    free(*del);
    free(*theta);

    exit(0);
}
Beispiel #9
0
int main (int argc, char *argv[])
{
    bool verb;
    bool rays;

    sf_axis az,ax;  /* Cartesian coordinates */
    sf_axis at,ag;  /* Ray coordinates */
    int it,ig;
    int nz,nx,nt,ng;
    float dt,dg,ot,og;

    float xsou,zsou; /* source coordinates */

    sf_file Fv=NULL; /* velocity file */
    sf_file Fw=NULL; /* wavefronfs file */

    float **vv=NULL; /* velocity       */
    pt2d   *wm=NULL; /* wavefront it-1 */
    pt2d   *wo=NULL; /* wavefront it   */
    pt2d   *wp=NULL; /* wavefront it+1 */

    pt2d    Ro;    /* point  on wft it-1 */
    pt2d Pm,Po,Pp; /* points on wft it   */
    pt2d    Qo;    /* point  on wft it+1 */

    /*------------------------------------------------------------*/
    sf_init(argc,argv);
    if(! sf_getbool("verb",&verb)) verb=false;
    if(! sf_getbool("rays",&rays)) rays=false;

    /* velocity file */
    Fv = sf_input ("in");
    az = sf_iaxa(Fv,1); sf_setlabel(az,"z"); nz=sf_n(az); if(verb) sf_raxa(az);
    ax = sf_iaxa(Fv,2); sf_setlabel(ax,"x"); nx=sf_n(ax); if(verb) sf_raxa(ax);

    vv=sf_floatalloc2(nz,nx); 
    sf_floatread(vv[0],nz*nx,Fv);

    /* source location */
    if(! sf_getfloat("xsou",&xsou)) xsou=sf_o(ax) + nx*sf_d(ax)/2;
    if(! sf_getfloat("zsou",&zsou)) zsou=sf_o(az) + nz*sf_d(az)/2;
    if(verb) fprintf(stderr,"xsou=%f zsou=%f\n",xsou,zsou);

    /* time axis */
    if(! sf_getint  ("nt",&nt)) nt=100;
    if(! sf_getfloat("ot",&ot)) ot=0;
    if(! sf_getfloat("dt",&dt)) dt=0.001;
    at = sf_maxa(nt,ot,dt); sf_setlabel(at,"t");

    /* shooting angle axis */
    if(! sf_getint  ("ng",&ng)) ng= 360;
    if(! sf_getfloat("og",&og)) og=-180;
    if(! sf_getfloat("dg",&dg)) dg= 1;
    ag = sf_maxa(ng,og,dg); sf_setlabel(ag,"g");

    /*------------------------------------------------------------*/
    /* wavefronts file (g,t) */
    Fw = sf_output("out");
    sf_oaxa(Fw,ag,1); if(verb) sf_raxa(ag);
    sf_oaxa(Fw,at,2); if(verb) sf_raxa(at);

    /* set the output to complex */
    sf_putint(Fw,"esize",8);
    sf_settype(Fw,SF_COMPLEX);

    /*------------------------------------------------------------*/
    /* allocate wavefronts */
    wm = pt2dalloc1(ng);
    wo = pt2dalloc1(ng);
    wp = pt2dalloc1(ng);

    /* initialize wavefronts */
    for( ig=0; ig<ng; ig++) {
	wm[ig].x=wo[ig].x=wp[ig].x=0;
	wm[ig].z=wo[ig].z=wp[ig].z=0;
	wm[ig].v=wo[ig].v=wp[ig].v=0;
    }

    /*------------------------------------------------------------*/
    /* init HWT */
    hwt2d_init(vv,az,ax,at,ag);

    /*------------------------------------------------------------*/
    /* construct it=0 wavefront */
    it=0;
    for( ig=0; ig<ng; ig++) {
	wm[ig].x=xsou;
	wm[ig].z=zsou;
	wm[ig].v=hwt2d_getv(wm[ig]);
    }
    pt2dwrite1(Fw,wm,ng,2); /* write wavefront it=0 */

    /*------------------------------------------------------------*/
    /* construct it=1 wavefront */
    it=1;
    for( ig=0; ig<ng; ig++) {
	double d,g;

	d = dt * hwt2d_getv(wm[ig]);
	g = (og+ig*dg) * SF_PI/180;

	wo[ig].x=xsou + d*sin(g);
	wo[ig].z=zsou + d*cos(g);
	wo[ig].v=hwt2d_getv(wo[ig]);
    }
    pt2dwrite1(Fw,wo,ng,2); /* write wavefront it=1 */

    /*------------------------------------------------------------*/
    /* LOOP over time */
    for (it=2; it<nt; it++) {
	if(verb) fprintf(stderr,"it=%d\n",it);
	
	if(ng>3 && !rays) {
	    /* boundaries */
	    ig=0;      wp[ig] = hwt2d_raytr(wm[ig],wo[ig]);
	    ig=ng-1; wp[ig] = hwt2d_raytr(wm[ig],wo[ig]);

	    for (ig=1; ig<ng-1; ig++) {
		
		Pm = wo[ig-1];
		Po = wo[ig  ];  Qo = wm[ig];
		Pp = wo[ig+1];
		
		if(hwt2d_cusp(Qo,Pm,Po,Pp)) {
		    Ro = hwt2d_raytr(Qo,   Po   );
		} else {
		    Ro = hwt2d_wfttr(Qo,Pm,Po,Pp);
		}
		wp[ig] = Ro;
	    }
	} else {
	    for (ig=0; ig<ng; ig++) {
		Po = wo[ig];  
		Qo = wm[ig];
		Ro = hwt2d_raytr(Qo,Po);
		wp[ig] = Ro;
	    }
	}

	/* write wavefront it */
	pt2dwrite1(Fw,wp,ng,2);

	/* step in time */
	for( ig=0; ig<ng; ig++) {
	    wm[ig] = wo[ig];
	    wo[ig] = wp[ig];
	}
    } /* end it */

    /*------------------------------------------------------------*/

    exit (0);
}
Beispiel #10
0
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);
}
Beispiel #11
0
int main(int  argc,char **argv)
{
    sf_init(argc,argv);

    sf_file Fix, Fiy, Fiz;
    sf_file Fi1, Fi2, Fi3;
    sf_file Fo1, Fo2;

    clock_t t1, t2;
    float   timespent;

    t1=clock();

   int isep;

   if (!sf_getint("isep",&isep)) isep=1;

    /* setup I/O files */
    Fix = sf_input("in");
    Fiy = sf_input("apvyy");
    Fiz = sf_input("apvzz");

    Fi1 = sf_input("PseudoPurePx"); /* pseudo-pure P-wave x-component */
    Fi2 = sf_input("PseudoPurePy"); /* pseudo-pure P-wave y-component */
    Fi3 = sf_input("PseudoPurePz"); /* pseudo-pure P-wave z-component */
    Fo1 = sf_output("out");               /* pseudo-pure scalar P-wave */
    Fo2 = sf_output("PseudoPureSepP");    /* separated scalar P-wave */

    int     nx, ny, nz, nxf, nyf, nzf, hnx, hny, hnz, i, j, k;
    float   fx, fy, fz, dx, dy, dz, dxf, dyf, dzf;

    /* Read/Write axes */
    sf_axis az, ax, ay;

    az = sf_iaxa(Fi1,1); nz = sf_n(az); dz = sf_d(az)*1000.0;
    ax = sf_iaxa(Fi1,2); nx = sf_n(ax); dx = sf_d(ax)*1000.0;
    ay = sf_iaxa(Fi1,3); ny = sf_n(ay); dy = sf_d(ay)*1000.0;
    fy=sf_o(ay)*1000.0;
    fx=sf_o(ax)*1000.0;
    fz=sf_o(az)*1000.0;

    sf_warning("nx=%d ny=%d nz=%d dx=%f dy=%f dz=%f",nx,ny,nz,dx,dy,dz);

    puthead3x(Fo1, nz, nx, ny, dz/1000.0, dx/1000.0, dy/1000.0, 0.0, 0.0, 0.0);
    puthead3x(Fo2, nz, nx, ny, dz/1000.0, dx/1000.0, dy/1000.0, 0.0, 0.0, 0.0);

    float*** px=sf_floatalloc3(nz,nx,ny);
    float*** py=sf_floatalloc3(nz,nx,ny);
    float*** pz=sf_floatalloc3(nz,nx,ny);
    float*** p=sf_floatalloc3(nz,nx,ny);

    int iy, ix, iz;

    for(iy=0;iy<ny;iy++)
    for(ix=0;ix<nx;ix++)
    {
      sf_floatread(px[iy][ix],nz,Fi1);
      sf_floatread(py[iy][ix],nz,Fi2);
      sf_floatread(pz[iy][ix],nz,Fi3);
    }

    for(iy=0;iy<ny;iy++)
    for(ix=0;ix<nx;ix++){
       for(iz=0;iz<nz;iz++)
          p[iy][ix][iz] = px[iy][ix][iz] + py[iy][ix][iz] + pz[iy][ix][iz];
       sf_floatwrite(p[iy][ix],nz,Fo1);
    }

if(isep==1){
    /* Read axes */
    sf_axis azf, axf, ayf;
    azf = sf_iaxa(Fix,1); nzf = sf_n(azf); dzf = sf_d(azf)*1000.0;
    axf = sf_iaxa(Fix,2); nxf = sf_n(axf); dxf = sf_d(axf)*1000.0;
    ayf = sf_iaxa(Fix,3); nyf = sf_n(ayf); dyf = sf_d(ayf)*1000.0;

    if(dx!=dxf){
       sf_warning("dx= %f dxf=%f",dx,dxf);
       sf_warning("filter and data spatial sampling don't match in x-axis");
       exit(0);
    }
    if(dy!=dyf){
       sf_warning("dy= %f dyf=%f",dy,dyf);
       sf_warning("filter and data spatial sampling don't match in y-axis");
       exit(0);
    }
    if(dz!=dzf){
       sf_warning("dz= %f dzf=%f",dz,dzf);
       sf_warning("filter and data spatial sampling don't match in z-axis");
       exit(0);
    }

    float*** apvxx=sf_floatalloc3(nzf,nxf,nyf);
    float*** apvyy=sf_floatalloc3(nzf,nxf,nyf);
    float*** apvzz=sf_floatalloc3(nzf,nxf,nyf);

    hnx=nxf/2;
    hny=nyf/2;
    hnz=nzf/2;

    sf_warning("nxf=%d nyf=%d nzf=%d dxf=%f dyf=%f dzf=%f",nxf,nyf,nzf,dxf,dyf,dzf);

    for(iy=0;iy<nyf;iy++)
    for(ix=0;ix<nxf;ix++)
    {
      sf_floatread(apvxx[iy][ix],nzf,Fix);
      sf_floatread(apvyy[iy][ix],nzf,Fiy);
      sf_floatread(apvzz[iy][ix],nzf,Fiz);
    }

    float*** pxc=sf_floatalloc3(nz,nx,ny);
    float*** pyc=sf_floatalloc3(nz,nx,ny);
    float*** pzc=sf_floatalloc3(nz,nx,ny);
    zero3float(pxc, nz,nx,ny);
    zero3float(pyc, nz,nx,ny);
    zero3float(pzc, nz,nx,ny);

    int l, g, h, ll, gg, hh;

    for(j=0;j<ny;j++){
      sf_warning("ny=%d iy=%d",ny,j);
      for(i=0;i<nx;i++)
      for(k=0;k<nz;k++)
      {

        for(g=-hny; g<=hny; g++){
            gg=g+hny;
            for(l=-hnx; l<=hnx; l++){
                ll=l+hnx;
                for(h=-hnz; h<=hnz; h++)
                {
                    hh=h+hnz;
                    if(i+l>=0 && i+l<nx && j+g>=0 && j+g<ny && k+h>=0 && k+h<nz){
                        pyc[i][j][k]+=py[i+l][j+g][k+h]*apvxx[gg][ll][hh];
                        pxc[i][j][k]+=px[i+l][j+g][k+h]*apvyy[gg][ll][hh];
                        pzc[i][j][k]+=pz[i+l][j+g][k+h]*apvzz[gg][ll][hh];
                    }
                } // h loop
             } // g loop
          }// l oop
       }
    }
/*
    int iix, iiy, iiz;

    for(iy=0;iy<ny;iy++)
    for(ix=0;ix<nx;ix++)
       for(iz=0;iz<nz;iz++){
          pxc[iy][ix][iz]=px[iy][ix][iz];
          pyc[iy][ix][iz]=py[iy][ix][iz];
          pzc[iy][ix][iz]=pz[iy][ix][iz];
          iix=ix-nx/2;
          iiy=iy-ny/2;
          iiz=iz-nz/2;
          if(sqrt(1.0*(iix*iix+iiy*iiy+iiz*iiz))<3.0*nx/8)
          {
             pxc[iy][ix][iz] = 0.0;
             pyc[iy][ix][iz] = 0.0;
             pzc[iy][ix][iz] = 0.0;
          }
       }
*/
    for(iy=0;iy<ny;iy++)
    for(ix=0;ix<nx;ix++){
       for(iz=0;iz<nz;iz++)
          p[iy][ix][iz] = pxc[iy][ix][iz] + pyc[iy][ix][iz] + pzc[iy][ix][iz];
       sf_floatwrite(p[iy][ix],nz,Fo2);
    }
    free(**pxc);
    free(**pyc);
    free(**pzc);
    free(**apvxx);
    free(**apvyy);
    free(**apvzz);
}// endif
    t2=clock();
    timespent=(float)(t2-t1)/CLOCKS_PER_SEC;
    sf_warning("Computation time (Filtering): %f (second)",timespent);

    free(**px);
    free(**py);
    free(**pz);

    free(**p);
		
    return 0;
}
Beispiel #12
0
int main(int argc, char* argv[])
{
  int verbose;
  sf_file in=NULL, out=NULL;
  int n1_traces;
  int n1_headers;

  char* header_format=NULL;
  sf_datatype typehead;
  /* kls do I need to add this?  sf_datatype typein; */
  float* fheader=NULL;
  float* intrace=NULL;
  float    sx;
  float    sy;
  float    gx;
  float    gy;
  float    offset;
  float offx, offy, midx, midy;
  float scalco, scale;
  int indx_sx;
  int indx_sy;
  int indx_gx;
  int indx_gy;
  int indx_offset;
  int indx_scalco;

  float v, dx, dy, x0, y0, t0, t0xy, t, off_dotprod_dip;
  int it;
  float d1, o1;
  
 /*****************************/
  /* initialize verbose switch */
  /*****************************/
  sf_init (argc,argv);

  if(!sf_getint("verbose",&verbose))verbose=1;
      /* \n
     flag to control amount of print
     0 terse, 1 informative, 2 chatty, 3 debug
  */
  sf_warning("verbose=%d",verbose);
 
  if(!sf_getfloat("v",&v))sf_error("v, a required parameter not input");
  if(!sf_getfloat("dx",&dx))sf_error("dx, a required parameter not input");
  if(!sf_getfloat("dy",&dy))sf_error("dy, a required parameter not input");
  if(!sf_getfloat("x0",&x0))sf_error("x0, a required parameter not input");
  if(!sf_getfloat("y0",&y0))sf_error("y0, a required parameter not input");
  if(!sf_getfloat("t0",&t0))sf_error("t0, a required parameter not input");

  /******************************************/
  /* input and output data are stdin/stdout */
  /******************************************/

  if(verbose>0)fprintf(stderr,"read in file name\n");  
  in = sf_input ("in");

  if(verbose>0)fprintf(stderr,"read out file name\n");
  out = sf_output ("out");

  if (!sf_histint(in,"n1_traces",&n1_traces))
    sf_error("input data not define n1_traces");
  if (!sf_histint(in,"n1_headers",&n1_headers)) 
    sf_error("input data does not define n1_headers");

  header_format=sf_histstring(in,"header_format");
  if(strcmp (header_format,"native_int")==0) typehead=SF_INT;
  else                                       typehead=SF_FLOAT;

  if(verbose>0)fprintf(stderr,"allocate headers.  n1_headers=%d\n",n1_headers);
  fheader = sf_floatalloc(n1_headers);
 
  if(verbose>0)fprintf(stderr,"allocate intrace.  n1_traces=%d\n",n1_traces);
  intrace= sf_floatalloc(n1_traces);



  /* maybe I should add some validation that n1== n1_traces+n1_headers+2
     and the record length read in the second word is consistent with 
     n1.  */

  /**********************************************************/
  /* end code block for standard tah Trace And Header setup */
  /* continue with any sf_puthist this tah program calls to */
  /* add to the history file                                */
  /**********************************************************/

  /* put the history from the input file to the output */
  sf_fileflush(out,in);

  /********************************************************/
  /* continue initialization specific to this tah program */
  /********************************************************/
  if (!sf_histfloat(in,"d1",&d1))
    sf_error("input data not define d1");
  if (!sf_histfloat(in,"o1",&o1))
    sf_error("input data not define o1");

  /* segy_init gets the list header keys required by segykey function  */
  segy_init(n1_headers,in);

  indx_sx    =segykey("sx"    );
  indx_sy    =segykey("sy"    );
  indx_gx    =segykey("gx"    );
  indx_gy    =segykey("gy"    );
  indx_offset=segykey("offset");
  indx_scalco=segykey("scalco");

  /***************************/
  /* start trace loop        */
  /***************************/
  if(verbose>0)fprintf(stderr,"start trace loop\n");
  while (0==get_tah(intrace, fheader, n1_traces, n1_headers, in)){
    if(verbose>1)fprintf(stderr,"process the tah in sftahgethw\n");
    /********************/
    /* process the tah. */
    /********************/
    if(typehead == SF_INT){
      /* just cast the header to int so the print works */
      scalco=((int*)fheader)[indx_scalco];
      if(scalco==0)scale=1;
      if(scalco<0)scale=-1/scalco;
      else scale=scalco;
      sx    =scale*((int*)fheader)[indx_sx    ];
      sy    =scale*((int*)fheader)[indx_sy    ];
      gx    =scale*((int*)fheader)[indx_gx    ];
      gy    =scale*((int*)fheader)[indx_gy    ];
      offset=((int*)fheader)[indx_offset];
    } else {
      scalco=fheader[indx_scalco];
      if(scalco==0)scale=1;
      if(scalco<0)scale=-1/scalco;
      else scale=scalco;
      sx    =scale*fheader[indx_sx    ];
      sy    =scale*fheader[indx_sy    ];
      gx    =scale*fheader[indx_gx    ];
      gy    =scale*fheader[indx_gy    ];
      offset=fheader[indx_offset];
    }
    offx=sx-gx;
    offy=sy-gy;
    midx=(sx+gx)/2.0;
    midy=(sy+gy)/2.0;
    if(verbose>2){
      fprintf(stderr, "sx    =%e",sx    );
      fprintf(stderr," sy    =%e",sy    );
      fprintf(stderr," gx    =%e",gx    );
      fprintf(stderr," gy    =%e",gy    );
      fprintf(stderr," offset=%e",offset);
      fprintf(stderr," offx=%e",offx);
      fprintf(stderr," offy=%e",offy);
      fprintf(stderr," newoff=%e",sqrt(offx*offx+offy*offy));
      fprintf(stderr," midx=%e",midx);
      fprintf(stderr," midy=%e",midy);
      fprintf(stderr,"\n");
    }
    /* zero the output trace */
    memset(intrace,0,n1_traces*sizeof(float));
    /* compute time of the spike and put it on the trace */
    /* t=t0; */
    t0xy=t0+(midx-x0)*dx+(midy-y0)*dy;
    /* t=t0xy; */
    /* no dmo term t=sqrt(t0xy*t0xy+(offset*offset)/(v*v)); */
    off_dotprod_dip=offx*dx+offy*dy;
    t=sqrt(t0xy*t0xy+(offset*offset)/(v*v)-off_dotprod_dip*off_dotprod_dip/4.0);
    if(t>=o1){
      it=(t-o1)/d1;
      if(it>0 && it<n1_traces){
	intrace[it]=it+1-(t-o1)/d1;
      }
      if(it+1>0 && it+1<n1_traces){
	intrace[it+1]=(t-o1)/d1-it;
      }
    }
    /***************************/
    /* write trace and headers */
    /***************************/
    put_tah(intrace, fheader, n1_traces, n1_headers, out);
  }

  exit(0);
}
Beispiel #13
0
/* initialize the length of axis and the number of tics */
void vp_axis_init (const sf_file in)
{
    float ftmp, num;
    bool want;
    char *stmp, *label, *unit;
    size_t len;
    struct Axis axis;

    if (!sf_getint ("axisfat",&axisfat)) axisfat=0;
    if (!sf_getint ("axiscol",&axiscol)) axiscol=7;
    if (!sf_getint ("labelfat",&labelfat)) labelfat=0;
    if (!sf_getfloat ("labelsz",&labelsz)) labelsz=8.;
    
    if ((NULL == (label=sf_getstring("label1"))) &&
	(NULL == (label=sf_histstring(in,"label1")))) {  
	axis1.label = blank;
    } else if ((NULL == (unit=sf_getstring("unit1"))) &&
	       (NULL == (unit=sf_histstring(in,"unit1")))) {
	axis1.label = label;
    } else {
	len = strlen(label)+strlen(unit)+4;
	axis1.label = sf_charalloc(len);
	snprintf(axis1.label,len,"%s (%s)",label,unit);
	free(label);
	free(unit);
    }

    if ((NULL == (label=sf_getstring("label2"))) &&
	(NULL == (label=sf_histstring(in,"label2")))) {
	axis2.label = blank;
    } else if ((NULL == (unit=sf_getstring("unit2"))) &&
	       (NULL == (unit=sf_histstring(in,"unit2")))) {
	axis2.label = label;           
    } else {
	len = strlen(label)+strlen(unit)+4;
	axis2.label = sf_charalloc(len);
	snprintf(axis2.label,len,"%s (%s)",label,unit);
	free(label);
	free(unit);
    }

    where1 = (NULL != (stmp = sf_getstring ("wherexlabel")) &&
	      'b' == *stmp);
    where2 = (NULL != (stmp = sf_getstring ("whereylabel")) &&
	      'r' == *stmp);
    
    /* checking to see if wantaxis is fetched */
    if (!sf_getbool ("wantaxis", &want)) {
	/* setting the default to put the axes on the plot */
        want = true;
	axis1.want = true;
	axis2.want = true;
    } else if (!want) {
	axis1.want = false;
	axis2.want = false;
    } else {
	if (!sf_getbool ("wantaxis1",&(axis1.want)))
	    axis1.want = true;
	if (!sf_getbool ("wantaxis2",&(axis2.want)))
	    axis2.want = true;
    }

    /* frame or axis */
    wheretics = NULL != (stmp = sf_getstring ("wheretics")) &&
	'a' == *stmp;

    if (!sf_getfloat ("axisor1",&(axis1.or)))
	axis1.or = where1? min2: max2;

    if (!sf_getfloat ("axisor2",&(axis2.or)))
	axis2.or = where2? min1: max1;

    if (!sf_getint ("n1tic",&(axis1.ntic))) axis1.ntic = 1;
    if (!sf_getint ("n2tic",&(axis2.ntic))) axis2.ntic = 1;

    if (!sf_getfloat ("d1num", &(axis1.dnum))) getscl (&axis1);
    if (!sf_getfloat ("d2num", &(axis2.dnum))) getscl (&axis2);

    if (0. == axis1.dnum) sf_error("%s: zero d1num",__FILE__);
    if (0. == axis2.dnum) sf_error("%s: zero d2num",__FILE__);

    if (!sf_getfloat("o1num",&(axis1.num0))) {
	ftmp = (min1 < max1)? min1: max1;
	for (num = floorf(ftmp / axis1.dnum) * axis1.dnum - axis1.dnum; 
	     num < ftmp; num += axis1.dnum) ;
	axis1.num0 = num;
    }

    if (!sf_getfloat("o2num",&(axis2.num0))) {
	ftmp = (min2 < max2)? min2: max2;
	for (num = floorf(ftmp / axis2.dnum) * axis2.dnum - axis2.dnum; 
	     num < ftmp; num += axis2.dnum) ;
	axis2.num0 = num;
    }

    axis1.dtic = axis1.dnum / axis1.ntic ;
    ftmp = (min1 < max1)? min1: max1;
    for (num = axis1.num0 - axis1.ntic * axis1.dtic;
	 num < ftmp; num += axis1.dtic);
    axis1.tic0 = num;

    axis2.dtic = axis2.dnum / axis2.ntic ;
    ftmp = (min2 < max2)? min2: max2;
    for (num = axis2.num0 - axis2.ntic * axis2.dtic;
	 num < ftmp; num += axis2.dtic);
    axis2.tic0 = num;

    if (transp) { /* swap */
	axis = axis1;
	axis1 = axis2;
	axis2 = axis;
    }
    
    if(yreverse) axis1.or = (min2+max2)-axis1.or;    
    if(xreverse) axis2.or = (min1+max1)-axis2.or;
}
Beispiel #14
0
int main(int argc, char* argv[])
{
    bool verb;
    int n[SF_MAX_DIM], m[SF_MAX_DIM], rect[SF_MAX_DIM];
    int ndim, mdim, nd, ns, n12, i, j, niter, na, ia, i4, n4=1;
    float *d, *f, *g, mean, a0;
    char key[6], *peffile, *lagfile;
    sf_filter aa;
    sf_file dat, flt, mat, pre, pef, lag;

    sf_init(argc,argv);

    dat = sf_input("in");
    mat = sf_input("match");
    flt = sf_output("out");

    if (NULL != sf_getstring("pred")) {
	pre = sf_output("pred");
    } else {
	pre = NULL;
    }

    ndim = 3;
    mdim = 2;


    if (!sf_histint(dat,"n1",&n[0])) sf_error("No n1= in input");
    if (!sf_histint(dat,"n2",&n[1])) sf_error("No n2= in input");
    if (!sf_histint(dat,"n3",&n[2])) sf_error("No n3= in input");
    n[3] = sf_leftsize(dat,3);

    if (!sf_histint(mat,"n1",&m[0])) sf_error("No n1= in match");
    if (!sf_histint(mat,"n2",&m[1])) sf_error("No n2= in match");
    m[2] = sf_leftsize(mat,2);

    if (mdim > ndim) 
	sf_error("Wrong dimensions: %d > %d",mdim,ndim);
 
    if (m[2] != n[3]) {
	sf_error("Size mismatch [n%d] : %d != %d",3,m[2],n[3]);
    } else {
	n4 = n[3];
    }

    nd = 1;
    for (j=0; j < mdim; j++) {
	if (m[j] != n[j]) 
	    sf_error("Size mismatch [n%d]: %d != %d",
		     j+1,m[j],n[j]);
	nd *= m[j];
	snprintf(key,6,"rect%d",j+1);
	if (!sf_getint(key,rect+j)) rect[j]=1;
    }
    for (ns = 1; j < ndim; j++) {
	ns *= n[j];
	if (pre) {
	    snprintf(key,6,"n%d",j+1);
	    sf_putint(pre,key,n4);
	    snprintf(key,6,"n%d",j+2);
	    sf_putint(pre,key,1);
	}
    }
    n12 = nd*ns;

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

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

    if (NULL == (peffile = sf_getstring("pef"))) { 
        /* signal PEF file (optional) */
	aa = NULL;
    } else {
	pef = sf_input(peffile);
	if (!sf_histint(pef,"n1",&na)) 
	    sf_error("No n1= in pef");
	aa = sf_allocatehelix (na);
	
	if (!sf_histfloat(pef,"a0",&a0)) a0=1.;
	sf_floatread (aa->flt,na,pef);
	for( ia=0; ia < na; ia++) {
	    aa->flt[ia] /= a0;
	}
	if (NULL != (lagfile = sf_getstring("lag")) 
	    || 
	    NULL != (lagfile = sf_histstring(pef,"lag"))) {
            /* file with PEF lags (optional) */
	    lag = sf_input(lagfile);
	    sf_intread(aa->lag,na,lag);
	    sf_fileclose(lag);
	} else {
	    for( ia=0; ia < na; ia++) {
		aa->lag[ia] = ia+1;
	    }
	}
    }

    d = sf_floatalloc(n12);
    f = sf_floatalloc(n12);
    g = sf_floatalloc(nd);

    for(i4=0; i4 < n4; i4++) {
	fprintf(stderr,"slice %d of %d\n",i4+1,n4);	
	for (i=0; i < n12; i++) {
	    d[i] = 0.;
	}
	sf_multidivn_init(ns, mdim, nd, m, rect, d, aa, verb); 
    
	sf_floatread(d,n12,dat);
	sf_floatread(g,nd,mat);

	mean = 0.;
	for(i=0; i < n12; i++) {
	    mean += d[i]*d[i];
	}
	if (mean == 0.) {
	    sf_floatwrite(d,n12,flt);
	    continue;
	}
	
	mean = sqrtf (mean/n12);
	
	for(i=0; i < n12; i++) {
	    d[i] /= mean;
	}
	for(i=0; i < nd; i++) {
	    g[i] /= mean;
	}
	
	sf_multidivn (g,f,niter);
	sf_floatwrite(f,n12,flt);
	
	if (pre) {
	    for(i=0; i < n12; i++) {
		d[i] *= mean;
	    }
	    
	    sf_weight2_lop(false,false,n12,nd,f,g);
	    sf_floatwrite(g,nd,pre);
	}
    }
    
    exit(0);
}
Beispiel #15
0
int main(int argc, char* argv[])
{
    bool inv, verb;
    int i1, n1, iw, nt, nw, i2, n2, rect0, niter, n12, n1w;
    int m[SF_MAX_DIM], *rect;
    float t, d1, w, w0, dw, mean=0.0f, alpha;
    float *trace, *kbsc, *mkbsc, *sscc, *mm, *ww;
    sf_complex *outp, *cbsc;
    sf_file in, out, mask, weight, basis;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

    exit(0);
}
int main( int argc , char* argv[] )
{
    sf_init( argc , argv );

    sf_file FI1, FI2, FI3, FO1;

    sf_axis aa;

    int dim, num_dim[SF_MAX_DIM], NTRACE, NT, nw, nwave, wsft, itrace, idim;

    float dt, **ref, **Q, *wave, **gather, **TVM;

    if(!sf_getint( "wsft" , &wsft ))  sf_error( "MISSING wave_shift PARAMETER!!\n" );
    /* The wave shift should be set up! */

    FI1 = sf_input( "ref" );
    FI2 = sf_input( "Q" );
    FI3 = sf_input( "wave" );
    FO1 = sf_output( "gather" );

    NTRACE = sf_leftsize( FI1 , 1 );
    dim = sf_filedims( FI1 , num_dim );

    /* define the LEFTSIZE bigger than the first 
     * dimension, so we can treat the data as two
     * dimensional-data, 
     */

    NT = sf_n( sf_iaxa( FI1 , 1 ) );
    dt = sf_d( sf_iaxa( FI1 , 1 ) );
    nw = sf_n( sf_iaxa( FI3 , 1 ) );

    /* extract the information about the first
     * dimension, which is needed by the function
     * of calculating the attenuated wavelet
     */

    nwave = lh_powerof2( nw );

    /* compute the suitable length for the FFT
     */

    ref     = alloc2float( NT , NTRACE );
    Q       = alloc2float( NT , NTRACE );
    gather  = alloc2float( NT , NTRACE );
    wave    = alloc1float( nwave );
    TVM     = alloc2float( NT , NT );

    zero2float( ref   , NT , NTRACE );
    zero2float( Q     , NT , NTRACE );
    zero2float( gather, NT , NTRACE );
    zero1float( wave  , nwave );

    /* alloc and setup */

    sf_floatread( &ref[0][0] , NT*NTRACE , FI1 );
    sf_floatread( &Q[0][0]   , NT*NTRACE , FI2 );
    sf_floatread( &wave[0]   , nw        , FI3 );

    for( itrace=0 ; itrace<NTRACE ; itrace++ )
    {
        zero2float( TVM , NT , NT );
        lh_time_variant_matrix( wave , wsft , nwave , dt , &Q[itrace][0], NT , TVM );
        lh_matrix_mu_vector( TVM , &ref[itrace][0] , &gather[itrace][0], NT , NT );
    }
/*
float **spec_real, **spec_imag, **spec_amp;
int nwave1 = lh_powerof2( NT );

spec_real = alloc2float( nwave1 , NT );
spec_imag = alloc2float( nwave1 , NT );
spec_amp  = alloc2float( 200 , NT );

zero2float( spec_real , nwave1 , NT );
zero2float( spec_imag , nwave1 , NT );
zero2float( spec_amp  , 200   , NT );

int i,j;
for( i=0 ; i<NT ; i++ )
{
    for( j=0 ; j<NT ; j++ )
    spec_real[i][j] = TVM[j][i];

    lh_fft( &spec_real[i][0] , &spec_imag[i][0], nwave1 , 1 );

    for( j=0 ; j<200 ; j++ )
    spec_amp[i][j] = sqrt( spec_real[i][j]*spec_real[i][j]+spec_imag[i][j]*spec_imag[i][j] );
}
lh_write_2d_float_bin_row( spec_amp , NT , 200 , "spec_amp_qwave.bin" );
*/

    for( idim=1 ; idim<=dim ; idim++ )
    {
        aa = sf_iaxa( FI1 , idim );
        sf_oaxa( FO1 , aa , idim );
    }
    sf_floatwrite( &gather[0][0] , NT*NTRACE , FO1 );

    exit( 0 );
}
Beispiel #17
0
int main(int argc, char* argv[])
{
    bool  verb;
    sf_axis  az,ah,ahx,ahy,ahz;
    int  iz,   ihx,ihy,ihz;
    int  nz,   nhx,nhy,nhz;
    float       hx, hy, hz;
    float oh,dh,ohx,dhx,ohy,dhy,ohz,dhz;
    sf_bands spl;

    sf_file Fd; /*  data =   vector offset (hx,hy,hz)-z */
    sf_file Fm; /* model = absolute offset     h     -z */

    int nw;    /* spline order */
    int nd,id; /*  data size (nd=nhx*nhy*nhz) */
    int nh;    /* model size (nm=nh) */

    float *dat=NULL;
    float *mod=NULL;
    float *map=NULL;

    float *mwt=NULL;
    float *dwt=NULL;

    int i;
/*    int im;*/
/*------------------------------------------------------------*/

    sf_init(argc,argv);

    if(! sf_getbool("verb",&verb)) verb=false; /* verbosity flag */
    if(! sf_getint(   "nw",&nw))     nw=4;     /* spline order */

    Fd = sf_input ("in");
    ahx = sf_iaxa(Fd,1); sf_setlabel(ahx,"hx"); if(verb) sf_raxa(ahx);
    ahy = sf_iaxa(Fd,2); sf_setlabel(ahy,"hy"); if(verb) sf_raxa(ahy);
    ahz = sf_iaxa(Fd,3); sf_setlabel(ahz,"hz"); if(verb) sf_raxa(ahz);
    az  = sf_iaxa(Fd,4); sf_setlabel(az,"z");   if(verb) sf_raxa(az);

    nhx = sf_n(ahx); ohx = sf_o(ahx); dhx = sf_d(ahx);
    nhy = sf_n(ahy); ohy = sf_o(ahy); dhy = sf_d(ahy);
    nhz = sf_n(ahz); ohz = sf_o(ahz); dhz = sf_d(ahz);
    nz = sf_n(az);

    if(!sf_getint  ("nh",&nh)) nh=nhx + ohx/dhx;
    if(!sf_getfloat("oh",&oh)) oh=0;
    if(!sf_getfloat("dh",&dh)) dh=dhx;
    ah = sf_maxa(nh,oh,dh); sf_setlabel(ah,"h"); if(verb) sf_raxa(ah);

    Fm = sf_output("out");
    sf_oaxa(Fm,ah,1);
    sf_oaxa(Fm,az,2);
    sf_putint(Fm,"n3",1);
    sf_putint(Fm,"n4",1);

/*------------------------------------------------------------*/
    nd = nhx*nhy*nhz;  /*  data size */

    map = sf_floatalloc(nd); /* mapping */

    mod = sf_floatalloc(nh); /* model vector */
    dat = sf_floatalloc(nd); /*  data vector */

    mwt = sf_floatalloc(nh); /* model weight */
    dwt = sf_floatalloc(nd); /*  data weight */

    spl = sf_spline_init(nw,nd);

    for(ihz=0;ihz<nhz;ihz++) {
	hz = ohz + ihz * dhz;         hz*=hz;
	for(ihy=0;ihy<nhy;ihy++) {
	    hy = ohy + ihy * dhy;     hy*=hy;
	    for(ihx=0;ihx<nhx;ihx++) {
		hx = ohx + ihx * dhx; hx*=hx;
		
		i = ihz * nhx*nhy + 
		    ihy * nhx     +
		    ihx;
		
		map[i] = sqrtf(hx+hy+hz);
	    }
	}
    }

    sf_int1_init( map, 
		  oh, dh, nh, 
		  sf_spline_int, 
		  nw, 
		  nd, 
		  0.0);

    for(id=0;id<nd;id++) {
	dwt[id]=1;
    }
    sf_banded_solve(spl,dwt);  

    for(iz=0;iz<nz;iz++) {
	sf_warning("iz=%d of %d",iz+1,nz);

	sf_floatread(dat,nd,Fd);

	sf_banded_solve(spl,dat);  
	sf_int1_lop( true,   /* adj */
		     false,  /* add */
		     nh,     /* n model */
		     nd,     /* n data */
		     mod,   
		     dat);

	sf_floatwrite(mod,nh,Fm);
    }

/*------------------------------------------------------------*/

    sf_int1_close();

    free(map);
    free(mod);
    free(dat);
    free(mwt);
    free(dwt);

    exit(0);
}
Beispiel #18
0
int main(int argc, char **argv)
{
    int         h, i, j, k, n;
    int         nkernels, id, kcalls=0, fixed_up=0, nfilled=0, nread=0;
    float       stretch_mute=0.0, dxbar=0.0;
    int         amps=0;
    int         input_number_samples=0;
    int         digi=0, ntimes=0, onetwo;
    float       a,b=1.0;
    float       *temp1=NULL, *temp2=NULL, *temp;

    unsigned int delay=1000;
    tpool_t tpool;
    pthread_t *peers;
    pthread_attr_t attr;
    mig_work_order_t *work_order=NULL;

    void   post_work_order(tpool_t tpool, mig_work_order_t *work_order);
    void   peer_mig(tpool_t tpool);

    sf_init(argc,argv);

    if (!sf_getint("kernels",&nkernels)) sf_error("Need kernels=");
    /* Number of kernel threads to create */

    if (!sf_getint("times",&ntimes)) sf_error("Need times=");
    /* Number of SQRT loops to execute */

    tpool = (tpool_t) sf_alloc(1,sizeof(struct tpool));
    tpool->cur_queue_size = 0;
    tpool->max_queue_size = MAX_QUEUE_SIZE;
    tpool->queue_head = NULL;
    tpool->queue_tail = NULL;
    tpool->shutdown = 0;
    pthread_mutex_init(&(tpool->queue_lock), NULL);
    pthread_cond_init(&(tpool->queue_empty), NULL);
    pthread_cond_init(&(tpool->queue_not_empty), NULL);
    pthread_cond_init(&(tpool->queue_not_full), NULL);

    peers = (pthread_t*) sf_alloc(nkernels,sizeof(pthread_t));
    pthread_attr_init(&attr);        /* set default thread attributes */
#ifdef SGI
    pthread_attr_setscope(&attr, PTHREAD_SCOPE_BOUND_NP);  /* allow SGI single process */
    pthread_setconcurrency(nkernels);     /* allow SGI multi kernels */
#else
    pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);  /* allow multi process */
#endif
    temp = temp1; onetwo=1;

/* kickoff the kernels into a wait state */

    tpool->working = sf_intalloc(nkernels);
    tpool->in_nsamps = input_number_samples;    /* never changes */
    tpool->hitarray = sf_intalloc(nkernels);
    tpool->digi = digi;                         /* never changes */
    tpool->stretch_mute = stretch_mute;         /* never changes */
    tpool->ntimes = ntimes;                     /* never changes */
    tpool->amps = amps;                         /* never changes */
    tpool->dxbar = dxbar;                       /* never changes */
    for(k=0; k<nkernels; k++) tpool->working[k] = 0;

    for(id=0; id<nkernels; id++) {
	tpool->id = id;
	n=pthread_create(&(peers[id]), &attr, (void*(*)(void*))peer_mig,
			 (void*)tpool);
	if(n) { sf_warning("\n peer %d kickoff error %d",id,n); exit(0); }
	sf_warning("peer %d kicked off",id);
	usleep(delay);    /* give threads time to retrieve parameters */
    }

    nread = 0;
    for(h=0; h<4; h++) {              /* loop over input traces */
	nread++;

	for(k=0; k<nkernels; k++) tpool->hitarray[k] = 0;
	fixed_up = 0;
	for(i=0; i<3; i++) {            /* loop over lines */
	    for(j=0; j<73; j++) {         /* loop over xlines */

/* any aperture branch-arounds would be here */

		if (fixed_up == 0) {

		    sf_warning("\npreparing trace %d", nread); 
		    for(k=0; k<10000; k++) a=sqrt(b);
     
		    fixed_up = 1;
		    nfilled = 0;
		    kcalls = 0;
		    tpool->cur_queue_size = 0;      /* just to */
		    tpool->queue_head = NULL;         /* be */
		    tpool->queue_tail = NULL;        /* sure */
		}

/* fill out the new work order for this batch */

		k=kcalls%MAX_THREAD_FOLD;

		work_order = (mig_work_order_t*) sf_alloc(1,sizeof(mig_work_order_t));

		if(!k) {
		    work_order->id = (nread-1)*1000+kcalls; 
		    work_order->ntodo = 0; 
		    work_order->next = NULL; 
		} 

/* fill out this entry in the work order */

		work_order->data = temp;         /* all the same for dis work order */
		work_order->xdist2[k] = 0.0;
		work_order->ydist2[k] = 0.0;
		work_order->shot_dist[k] = 0.0;
		work_order->rcvr_dist[k] = 0.0;
		work_order->offsets[k] = 0;
		work_order->lineap[k] = NULL;
		work_order->cdpap[k] = NULL;
		work_order->vrms[k] = NULL;
		work_order->image[k] = NULL;
		work_order->image_fold[k] = NULL;
		work_order->migrated_gathers[k] = 0;
		work_order->gathers[k] = NULL;
		work_order->gathers_fold[k] = NULL;
		(work_order->ntodo)++;                /* one more in dis batch */
		nfilled++;

/* send it off for migration */

		if(nfilled==MAX_THREAD_FOLD) {
		    sf_warning(" main posting filled work order %d with %d vectors for trace %d" ,
			       work_order->id,nfilled,nread);  
		    post_work_order(tpool, work_order);
		    nfilled = 0;
		}
 
		kcalls++;

	    } /* end loop j */
	} /* end loop i */

/* send last unfilled work order off for migration */

	if(nfilled) {
	    sf_warning(" main posting partially-filled work order %d with %d vectors for trace %d" ,
		       work_order->id,nfilled,nread);  
	    post_work_order(tpool, work_order);
	    nfilled = 0;
	}
 
/* wait for queue to empty before migrating next trace */

	pthread_mutex_lock(&(tpool->queue_lock));    /* lock queue */
	while(tpool->cur_queue_size>0) {             /* check flag */
	    sf_warning(" Waiting in main on queue_size= %d",tpool->cur_queue_size);
	    pthread_cond_wait(&(tpool->queue_empty), &(tpool->queue_lock));
	} 
	pthread_mutex_unlock(&(tpool->queue_lock));  /* unlock queue */

/* switch temp array */

	onetwo = 3-onetwo;
	if(onetwo == 1) temp = temp1;
	else            temp = temp2;

    } /* end h loop */

/* wait for kernels to finish last batch of work orders */

    for(k=0; k<nkernels; k++) {while(tpool->working[k]>0) usleep(delay);} 

/* kill kernel threads */

    sf_warning("\n Killing off kernels");
    pthread_mutex_lock(&(tpool->queue_lock));    /* lock queue */
    tpool->shutdown = 1;                         /* request shutdown */
    tpool->cur_queue_size=1;                     /* one in queue */
    pthread_mutex_unlock(&(tpool->queue_lock));  /* unlock queue */
    pthread_cond_broadcast(&(tpool->queue_not_empty)); /* broadcast queue not empty */
    for(id=0; id<nkernels; id++) {
	pthread_join(peers[id], NULL);               /* wait for kernel to flush */
    }


} /* end */
Beispiel #19
0
int main (int argc, char* argv[]) {
    int nz, nx, ny, nb, na, iz, ix, iy, ia, ib, fz, lz;
    int icpu = 0, ncpu = 1, morder = 2, ic, nc = 1, mp = 1, ith = 0, inet = 0, tdel = 0;
    float dz, oz, dx, ox, dy, oy, db, ob, da, oa, aper;
    float z, x, y;
    float ****e;
    sf_file spdom, vspline = NULL, scgrid = NULL, scdaemon = NULL, 
            out;
    char *ext = NULL;
    bool verb, parab, mmaped, rfail;
    sf_esc_slowness3 esc_slow;
    sf_esc_scglstor3 esc_scgrid_lstor;
    sf_esc_tracer3 *esc_tracers;
    sf_esc_scgrid3 *esc_scgrids;
    sf_timer timer;

    sf_init (argc, argv);

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

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

    /* Spatial dimensions */
    if (spdom) {
        if (!sf_histint (spdom, "n1", &nz)) sf_error ("No n1= in input");
        if (!sf_histint (spdom, "n2", &nx)) sf_error ("No n2= in input");
        if (!sf_histint (spdom, "n3", &ny)) sf_error ("No n3= in input");
        if (!sf_histfloat (spdom, "d1", &dz)) sf_error ("No d1= in input");
        if (!sf_histfloat (spdom, "o1", &oz)) sf_error ("No o1= in input");
        if (!sf_histfloat (spdom, "d2", &dx)) sf_error ("No d2= in input");
        if (!sf_histfloat (spdom, "o2", &ox)) sf_error ("No o2= in input");
        if (!sf_histfloat (spdom, "d3", &dy)) sf_error ("No d3= in input");
        if (!sf_histfloat (spdom, "o3", &oy)) sf_error ("No o3= in input");
        if (!sf_histint (spdom, "icpu", &icpu)) icpu = 0;
        /* Current CPU number */
        if (!sf_histint (spdom, "ncpu", &ncpu)) ncpu = 1;
        /* Total number of CPUs */
    }
    ext = sf_escst3_warnext (spdom);
    if (!sf_getint ("nz", &nz) && !spdom) sf_error ("Need nz=");
    /* Number of samples in z axis */
    if (!sf_getfloat ("oz", &oz) && !spdom) sf_error ("Need oz=");
    /* Beginning of z axis */
    if (!sf_getfloat ("dz", &dz) && !spdom) sf_error ("Need dz=");
    /* Sampling of z axis */
    if (!sf_getint ("nx", &nx) && !spdom) sf_error ("Need nx=");
    /* Number of samples in x axis */
    if (!sf_getfloat ("ox", &ox) && !spdom) sf_error ("Need ox=");
    /* Beginning of x axis */
    if (!sf_getfloat ("dx", &dx) && !spdom) sf_error ("Need dx=");
    /* Sampling of x axis */
    if (!sf_getint ("ny", &ny) && !spdom) sf_error ("Need ny=");
    /* Number of samples in y axis */
    if (!sf_getfloat ("oy", &oy) && !spdom) sf_error ("Need oy=");
    /* Beginning of y axis */
    if (!sf_getfloat ("dy", &dy) && !spdom) sf_error ("Need dy=");
    /* Sampling of y axis */

    if (!sf_getint ("na", &na)) na = 360;
    /* Number of azimuth phase angles */
    da = 2.0*SF_PI/(float)na;
    oa = 0.5*da;

    if (!sf_getint ("nb", &nb)) nb = 180;
    /* Number of inclination phase angles */
    db = SF_PI/(float)nb;
    ob = 0.5*db;

#ifdef _OPENMP
    if (!sf_getint ("mp", &mp)) mp = 1;
    /* Bufferization factor for multicore processing (number of points in buffer = mp*nc) */
    if (!sf_getint ("nc", &nc)) nc = 0;
    /* Number of threads to use for ray tracing (OMP_NUM_THREADS by default) */
    if (nc)
        omp_set_num_threads (nc); /* User override */
    else
        nc = omp_get_max_threads (); /* Current default */
    sf_warning ("%s Using %d threads", ext, omp_get_max_threads ());
    sf_warning ("%s Buffering %d points", ext, nc*mp);
#endif

    if (!sf_getfloat ("aper", &aper)) aper = SF_HUGE;
    /* Maximum aperture in x and y directions from current point (default - up to grid boundaries) */
    if (aper != SF_HUGE)
        aper = fabsf (aper);

    if (!sf_getbool ("parab", &parab)) parab = true;
    /* y - use parabolic approximation of trajectories, n - straight line */

    if (!sf_getbool ("mmaped", &mmaped)) mmaped = true;
    /* n - do not use memory mapping for local data access */

    if (!sf_getbool ("rfail", &rfail)) rfail = true;
    /* n - do not quit if remote processing fails, try local processing */

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

    e = sf_floatalloc4 (ESC3_NUM, nb, na, nc*mp);

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

    if (!sf_getstring ("scgrid")) sf_error ("Need scgrid=");
    /* Grid of supercells of local escape solutions */
    scgrid = sf_input ("scgrid");

    if (sf_getstring ("scdaemon")) {
        /* Daemon for distributed computation */
        scdaemon = sf_input ("scdaemon");
    }

    if (!sf_getint ("morder", &morder)) morder = 1;
    /* Order of interpolation accuracy in the angular domain (1-3) */
#ifdef LINUX
    if (!sf_getint ("inet", &inet)) inet = 1;
    /* Network interface index */
#endif
    if (!sf_getint ("tdel", &tdel)) tdel = 0;
    /* Optional delay time before connecting (seconds) */
   
    /* Slowness components module [(an)isotropic] */
    esc_slow = sf_esc_slowness3_init (vspline, verb);

    /* Make room for escape variables in output */
    if (spdom)
        sf_shiftdimn (spdom, out, 1, 3);

    sf_putint (out, "n1", ESC3_NUM);
    sf_putfloat (out, "o1", 0.0);
    sf_putfloat (out, "d1", 1.0);
    sf_putstring (out, "label1", "Escape variable");
    sf_putstring (out, "unit1", "");
    sf_putint (out, "n2", nb);
    sf_putfloat (out, "d2", db*180.0/SF_PI);
    sf_putfloat (out, "o2", ob*180.0/SF_PI);
    sf_putstring (out, "label2", "Inclination");
    sf_putstring (out, "unit2", "Degrees");
    sf_putint (out, "n3", na);
    sf_putfloat (out, "d3", da*180.0/SF_PI);
    sf_putfloat (out, "o3", oa*180.0/SF_PI);
    sf_putstring (out, "label3", "Azimuth");
    sf_putstring (out, "unit3", "Degrees");

    sf_putint (out, "n4", nz);
    sf_putfloat (out, "o4", oz);
    sf_putfloat (out, "d4", dz);
    if (!spdom) {
        sf_putstring (out, "label4", "Depth");
        sf_putstring (out, "unit4", "");
    }
    sf_putint (out, "n5", nx);
    sf_putfloat (out, "o5", ox);
    sf_putfloat (out, "d5", dx);
    if (!spdom) {
        sf_putstring (out, "label5", "X");
        sf_putstring (out, "unit5", "");
    }
    sf_putint (out, "n6", ny);
    sf_putfloat (out, "o6", oy);
    sf_putfloat (out, "d6", dy);
    if (!spdom) {
        sf_putstring (out, "label6", "Y");
        sf_putstring (out, "unit6", "");
    }
    /* Save min/max possible escape values */
    sf_putfloat (out, "Zmin", sf_esc_slowness3_oz (esc_slow));
    sf_putfloat (out, "Zmax", sf_esc_slowness3_oz (esc_slow) +
                              (sf_esc_slowness3_nz (esc_slow) - 1)*
                              sf_esc_slowness3_dz (esc_slow));
    sf_putfloat (out, "Xmin", sf_esc_slowness3_ox (esc_slow));
    sf_putfloat (out, "Xmax", sf_esc_slowness3_ox (esc_slow) +
                              (sf_esc_slowness3_nx (esc_slow) - 1)*
                              sf_esc_slowness3_dx (esc_slow));
    sf_putfloat (out, "Ymin", sf_esc_slowness3_oy (esc_slow));
    sf_putfloat (out, "Ymax", sf_esc_slowness3_oy (esc_slow) +
                              (sf_esc_slowness3_ny (esc_slow) - 1)*
                              sf_esc_slowness3_dy (esc_slow));

    esc_scgrid_lstor = sf_esc_scglstor3_init (scgrid, mmaped, ext, verb);

    esc_tracers = (sf_esc_tracer3*)sf_alloc (nc, sizeof(sf_esc_tracer3));
    esc_scgrids = (sf_esc_scgrid3*)sf_alloc (nc, sizeof(sf_esc_scgrid3));
    sleep (tdel);
    for (ic = 0; ic < nc; ic++) {
        esc_tracers[ic] = sf_esc_tracer3_init (esc_slow);
        sf_esc_tracer3_set_parab (esc_tracers[ic], parab);
        esc_scgrids[ic] = sf_esc_scgrid3_init (scgrid, scdaemon, esc_tracers[ic], esc_scgrid_lstor,
                                               morder, inet, (float)icpu/(float)ncpu, ext, rfail, verb && 0 == ic);
    }

    timer = sf_timer_init ();

    for (iy = 0; iy < ny; iy++) {
        y = oy + iy*dy;
        /* Set aperture */
        if (aper != SF_HUGE) {
            for (ic = 0; ic < nc; ic++) {
                sf_esc_scgrid3_set_ymin (esc_scgrids[ic], y - aper);
                sf_esc_scgrid3_set_ymax (esc_scgrids[ic], y + aper);
            }
        }
        for (ix = 0; ix < nx; ix++) {
            x = ox + ix*dx;
            /* Set aperture */
            if (aper != SF_HUGE) {
                for (ic = 0; ic < nc; ic++) {
                    sf_esc_scgrid3_set_xmin (esc_scgrids[ic], x - aper);
                    sf_esc_scgrid3_set_xmax (esc_scgrids[ic], x + aper);
                }
            }
            if (verb)
                sf_warning ("%s Projecting from lateral location %d of %d at y=%g, x=%g;",
                            ext, iy*nx + ix + 1, ny*nx, y, x);
            /* Loop over chunks */
            for (ic = 0; ic < (nz/(mp*nc) + ((nz % (nc*mp)) != 0)); ic++) {
                fz = ic*nc*mp;
                lz = (ic + 1)*nc*mp - 1;
                if (lz >= nz)
                    lz = nz - 1;
                sf_timer_start (timer);
#ifdef _OPENMP
#pragma omp parallel for            \
                schedule(dynamic,1) \
                private(iz,ia,ib,ith,z) \
                shared(fz,lz,iy,ix,nc,mp,nb,na,nz,nx,ny,ob,oa,oz,ox,oy,db,da,dz,dx,dy,x,y,esc_tracers,esc_scgrids,e,out)
#endif
                for (iz = fz; iz <= lz; iz++) {
#ifdef _OPENMP
                    ith = omp_get_thread_num ();
#endif
                    z = oz + iz*dz;
                    if (sf_esc_tracer3_inside (esc_tracers[ith], &z, &x, &y, false)) {
                        sf_esc_scgrid3_compute (esc_scgrids[ith], z, x, y, oa, da, ob, db, na, nb, e[iz - fz][0][0]);
                    } else {
                        for (ia = 0; ia < na; ia++) {
                            for (ib = 0; ib < nb; ib++) {
                                e[iz - fz][ia][ib][ESC3_Z] = z;
                                e[iz - fz][ia][ib][ESC3_X] = x;
                                e[iz - fz][ia][ib][ESC3_Y] = y;
                                e[iz - fz][ia][ib][ESC3_T] = 0.0;
#ifdef ESC_EQ_WITH_L
                                e[iz - fz][ia][ib][ESC3_L] = 0.0;                            
#endif
                            }
                        }
                    }
                } /* Loop over z */
                sf_timer_stop (timer);
                sf_floatwrite (e[0][0][0], (size_t)(lz - fz + 1)*(size_t)nb*(size_t)na*(size_t)ESC3_NUM,
                               out);
            } /* Loop over z chunks */
        } /* Loop over x */
    } /* Loop over y */
    if (verb) {
        sf_warning (".");
        sf_warning ("%s Total kernel time: %g s, per depth point: %g s",
                    ext, sf_timer_get_total_time (timer)/1000.0,
                    (sf_timer_get_total_time (timer)/(float)((size_t)nx*(size_t)ny*(size_t)nz))/1000.0);
    }
    sf_timer_close (timer);


    for (ic = 0; ic < nc; ic++) {
        sf_esc_tracer3_close (esc_tracers[ic]);
        sf_esc_scgrid3_close (esc_scgrids[ic], verb);
    }
    free (esc_tracers);
    free (esc_scgrids);

    sf_esc_scglstor3_close (esc_scgrid_lstor);
    sf_esc_slowness3_close (esc_slow);

    free (e[0][0][0]);
    free (e[0][0]);
    free (e[0]);
    free (e);
    free (ext);

    if (scdaemon)
        sf_fileclose (scdaemon);

    sf_fileclose (scgrid);
    sf_fileclose (vspline);

    return 0;
}
Beispiel #20
0
int main(int argc, char* argv[])
{
    bool adj,timer,verb;
    int nt, nx, nz, nx2, nz2, nzx, nzx2, ntx, pad1, snap, wfnt;
    int m2, n2, nk, nth=1;
    float dt, dx, dz, ox;
    sf_complex **img, **dat, **lt, **rt, ***wvfld, *ww;
    sf_file data, image, left, right, snaps, src;
    double time=0.,t0=0.,t1=0.;
    geopar geop;

    sf_init(argc,argv);

    if (!sf_getbool("adj",&adj)) adj=false;
    /* if n, modeling; if y, migration */
    if(! sf_getbool("timer",&timer)) timer=false;
    if (!sf_getbool("verb",&verb)) verb=false;
    if (!sf_getint("snap",&snap)) snap=0;
    /* interval for snapshots */
    if (!sf_getint("pad1",&pad1)) pad1=1;
    /* padding factor on the first axis */

    if (adj) { /* migration */
	data = sf_input("in"); // data here is just a refl file
	image = sf_output("out");
	sf_settype(image,SF_COMPLEX);

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

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

	sf_putint(image,"n1",nz);
	sf_putfloat(image,"d1",dz);
	sf_putfloat(image,"o1",0.);
	sf_putstring(image,"label1","Depth");
	sf_putint(image,"n2",nx);
	sf_putfloat(image,"d2",dx);
	sf_putfloat(image,"o2",ox);
	sf_putstring(image,"label2","Distance");
    } else { /* modeling */
	image = sf_input("in");
	data = sf_output("out");
	src = sf_input("src");
	sf_settype(data,SF_COMPLEX);

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

	if (!sf_getint("nt",&nt)) sf_error("Need nt=");
	/* time samples */
	if (!sf_getfloat("dt",&dt)) sf_error("Need dt=");
	/* time sampling */
	if (!sf_histint(src,"n1",&n2) || n2 != nt) sf_error("nt doesn't match!");

	sf_putint(data,"n1",nz);
	sf_putfloat(data,"d1",dz);
	sf_putfloat(data,"o1",0.);
	sf_putstring(data,"label1","Depth");
	sf_putint(data,"n2",nx);
	sf_putfloat(data,"d2",dx);
	sf_putfloat(data,"o2",ox);
	sf_putstring(data,"label2","Distance");
    }

    nz2 = kiss_fft_next_fast_size(nz*pad1);
    nx2 = kiss_fft_next_fast_size(nx);
    nk = nz2*nx2; /*wavenumber*/

    nzx = nz*nx;
    nzx2 = nz2*nx2;
    ntx = nt*nx;
    wfnt = (int)(nt-1)/snap+1;

    if (snap > 0) {
	snaps = sf_output("snaps");
	/* (optional) snapshot file */
	sf_settype(snaps,SF_COMPLEX);
	sf_putint(snaps,"n1",nz);
	sf_putfloat(snaps,"d1",dz);
	sf_putfloat(snaps,"o1",0.);
	sf_putstring(snaps,"label1","Depth");
	sf_putint(snaps,"n2",nx);
	sf_putfloat(snaps,"d2",dx);
	sf_putfloat(snaps,"o2",ox);
	sf_putstring(snaps,"label2","Distance");
	sf_putint(snaps,"n3",wfnt);
	sf_putfloat(snaps,"d3",dt*snap);
	sf_putfloat(snaps,"o3",0.);
	sf_putstring(snaps,"label3","Time");
    } else {
	snaps = NULL;
    }

    /* propagator matrices */
    left = sf_input("left");
    right = sf_input("right");
    
    if (!sf_histint(left,"n1",&n2) || n2 != nzx) sf_error("Need n1=%d in left",nzx);
    if (!sf_histint(left,"n2",&m2))  sf_error("No n2= in left");
    if (!sf_histint(right,"n1",&n2) || n2 != m2) sf_error("Need n1=%d in right",m2);
    if (!sf_histint(right,"n2",&n2) || n2 != nk) sf_error("Need n2=%d in right",nk);
    
    lt = sf_complexalloc2(nzx,m2);
    rt = sf_complexalloc2(m2,nk);
    img = sf_complexalloc2(nz,nx);
    dat = sf_complexalloc2(nz,nx);
    if (snap > 0) wvfld = sf_complexalloc3(nz,nx,wfnt);
    else wvfld = NULL;
    geop = (geopar) sf_alloc(1, sizeof(*geop));
    if (!adj) {
	ww=sf_complexalloc(nt);
	sf_complexread(ww,nt,src);
    } else ww=NULL;
    sf_complexread(lt[0],nzx*m2,left);
    sf_complexread(rt[0],m2*nk,right);
    if (adj) sf_complexread(dat[0],nzx,data);
    else sf_complexread(img[0],nzx,image);

    /*close RSF files*/
    sf_fileclose(left);
    sf_fileclose(right);

#ifdef _OPENMP
#pragma omp parallel
{   
    nth = omp_get_num_threads();
}
    sf_warning(">>>> Using %d threads <<<<<", nth);
#endif

    if (timer) t0 = gtod_timer();

    /*load constant geopar elements*/
    geop->nx  = nx;
    geop->nz  = nz;
    geop->dx  = dx;
    geop->dz  = dz;
    geop->ox  = ox;
    geop->nt  = nt;
    geop->dt  = dt;
    geop->snap= snap;
    geop->nzx2= nzx2;
    geop->nk  = nk;
    geop->m2  = m2;
    geop->wfnt= wfnt;

    lrexp(img, dat, adj, lt, rt, ww, geop, pad1, verb, snap, wvfld);

    if (timer)
      {
        t1 = gtod_timer();
        time = t1-t0;
        sf_warning("Time = %lf\n",time);
      }

    if (adj) {
	sf_complexwrite(img[0],nzx,image);
    } else {
	sf_complexwrite(dat[0],ntx,data);
    }
    
    if (snap > 0 && NULL != snaps) {
	sf_complexwrite(wvfld[0][0],wfnt*nx*nz,snaps);
    }

    exit(0);
}
Beispiel #21
0
wexlsr3d wexlsr_init(wexcub3d cub,
                      int      px,
                      int      py,
                      float  dsmax
    )
/*< initialize >*/
{
    int   ix, iy;
    float kx, ky;
    int   jx, jy;
    float xx, yy;
    int  ilx,ily;
    int  ompith;

    /*------------------------------------------------------------*/
    wexlsr3d lsr;
    lsr = (wexlsr3d) sf_alloc(1,sizeof(*lsr));

    X2K(cub->amx,lsr->bxx,px);
    X2K(cub->amy,lsr->byy,py);

    /* allocate K-domain storage */
    lsr->wk = sf_complexalloc3(lsr->bxx.n,lsr->byy.n,cub->ompnth);
    lsr->wt = sf_complexalloc3(lsr->bxx.n,lsr->byy.n,cub->ompnth);

    /* precompute wavenumbers */
    lsr->kk = sf_floatalloc2(lsr->bxx.n,lsr->byy.n);
    lsr->kw = sf_floatalloc2(lsr->bxx.n,lsr->byy.n);
    for (iy=0; iy<lsr->byy.n; iy++) {
        jy = KMAP(iy,lsr->byy.n);
        ky = lsr->byy.o + jy*lsr->byy.d;
        for (ix=0; ix<lsr->bxx.n; ix++) {
            jx = KMAP(ix,lsr->bxx.n);
            kx = lsr->bxx.o + jx*lsr->bxx.d;
            lsr->kk[iy][ix] = kx*kx+ky*ky;

            lsr->kw[iy][ix] = 1.;
        }
    }

    /* precompute indices */
    lsr->lx = sf_intalloc(cub->amx.n);
    lsr->ly = sf_intalloc(cub->amy.n);

    for (iy=0; iy<cub->amy.n; iy++) {
        yy = cub->amy.o + iy*cub->amy.d;
        ily    = INDEX( yy,cub->aly);
        lsr->ly[iy] = BOUND(ily,cub->aly.n); /* x-line index */
    }
    for (ix=0; ix<cub->amx.n; ix++) {
        xx = cub->amx.o + ix*cub->amx.d;
        ilx    = INDEX( xx,cub->alx);
        lsr->lx[ix] = BOUND(ilx,cub->alx.n); /* i-line index */
    }

    /* square-root expansion coefficients */
    if(!sf_getint("nsc",&lsr->nsc)) lsr->nsc = 0;
    if(lsr->nsc>5) lsr->nsc=5;

    lsr->csc[0]= 1.;
    lsr->csc[1]= 1./  2.;
    lsr->csc[2]= 3./  8.;
    lsr->csc[3]= 5./ 16.;
    lsr->csc[4]=35./128.;

    /* initialize FFT */
    lsr->f2d = (wexfft2d*) sf_alloc(cub->ompnth,sizeof(wexfft2d));
    for(ompith=0;ompith<cub->ompnth;ompith++) {
        lsr->f2d[ompith] = wexfft_init(cub,lsr->bxx.n,lsr->byy.n);
    }

    lsr->dsmax2 = dsmax*dsmax;
    lsr->dsmax2*= lsr->dsmax2;

    return lsr;

}
Beispiel #22
0
int main(int argc, char* argv[])
{
    bool verb;

    sf_file Fi,Fs,Fr;    /* I/O files */
    sf_axis at,az,ax,aa; /* cube axes */

    int     nt,nz,nx, nhz,nhx,nht;
    int     it,iz,ix, ihz,ihx,iht;
    int     jt,jz,jx;
    int     kt,kz,kx;

    float **ii=NULL, ***us=NULL,***ur=NULL; /* arrays */

    int ompchunk; 

    int lox,hix;
    int loz,hiz;
    int lot,hit;

    float ts,tr;

    /*------------------------------------------------------------*/
    /* init RSF */
    sf_init(argc,argv);

    if(! sf_getint("ompchunk",&ompchunk)) ompchunk=1;  /* OpenMP data chunk size */
    if(! sf_getbool("verb",&verb)) verb=false;         /* verbosity flag */

    if(! sf_getint("nhz",&nhz)) nhz=0;
    if(! sf_getint("nhx",&nhx)) nhx=0;
    if(! sf_getint("nht",&nht)) nht=1;
    sf_warning("nht=%d nhx=%d nhz=%d",2*nht+1,2*nhx+1,2*nhz+1);

    Fs = sf_input ("in" ); /*   source wavefield */
    Fr = sf_input ("ur" ); /* receiver wavefield */
    Fi = sf_output("out"); /* image */

    /* read axes */
    az=sf_iaxa(Fs,1); sf_setlabel(az,"z"); if(verb) sf_raxa(az); /* depth */
    ax=sf_iaxa(Fs,2); sf_setlabel(ax,"x"); if(verb) sf_raxa(ax); /* position */
    at=sf_iaxa(Fs,3); sf_setlabel(at,"t"); if(verb) sf_raxa(at); /* time */

    /* set output axes */
    aa=sf_maxa(1,0,1); 
    sf_oaxa(Fi,aa,3);

    nz = sf_n(az);
    nx = sf_n(ax);
    nt = sf_n(at);

    /* allocate work arrays */
    us=sf_floatalloc3(nz,nx,nt);
    ur=sf_floatalloc3(nz,nx,nt);
    ii=sf_floatalloc2(nz,nx);

    /* init output */
    for (iz=0; iz<nz; iz++) {
	for (ix=0; ix<nx; ix++) {
	    ii[ix][iz]=0;
	}
    }

    sf_floatread(us[0][0],nz*nx*nt,Fs);
    sf_floatread(ur[0][0],nz*nx*nt,Fr);

    if(verb) fprintf(stderr,"   t    x\n");
    if(verb) fprintf(stderr,"%4d %4d\n",nt,nx);
    for(        it=nht; it<nt-nht; it++) { lot=-nht; hit=nht+1;
	for(    ix=nhx; ix<nx-nhx; ix++) { lox=-nhx; hix=nhx+1;
	    if(verb) fprintf(stderr,"%4d %4d",it,ix);
#ifdef _OPENMP
#pragma omp parallel for schedule(dynamic,ompchunk) private(iz,iht,ihx,ihz,ts,tr,loz,hiz,jt,kt,jx,kx,jz,kz) shared(ur,nz,nhz,lot,hit,lox,hix)
#endif		
	    for(iz=nhz; iz<nz-nhz; iz++) { loz=-nhz; hiz=nhz+1;
/*		ts = us[it][ix][iz]*us[it][ix][iz];*/
		ts = us[it][ix][iz];
		tr = 0;
		
		for(        iht=lot; iht<hit; iht++) { jt=it-iht; kt=it+iht;
		    for(    ihx=lox; ihx<hix; ihx++) { jx=ix-ihx; kx=ix+ihx;
			for(ihz=loz; ihz<hiz; ihz++) { jz=iz-ihz; kz=iz+ihz;
			    tr += ur[jt][jx][jz]
				* ur[kt][kx][kz];
			} /* nhz */
		    } /* nhx */
		} /* nht */
		ii[ix][iz] += ts * tr;
	    } /* nz */
	    if(verb) fprintf(stderr,"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
	} /* nx */
    } /* nt */
    if(verb) fprintf(stderr,"\n");

    sf_floatwrite(ii[0],nz*nx,Fi);    

    exit (0);
}
Beispiel #23
0
int main(int argc, char* argv[]) 
{
    int nx, nt, ix, it, what;
    float dt, dx, w, g, a0, a1, a2, a3, a4, a5;
    float *old, *nxt, *cur, *sig, *v, *vx, **a; 
    sf_file inp, out, vel, grad;

    sf_init(argc,argv);
    inp = sf_input("in");
    out = sf_output("out");
    vel = sf_input("vel");   /* velocity */
    grad = sf_input("grad"); /* velocity gradient */

    if (SF_FLOAT != sf_gettype(inp)) sf_error("Need float input");
    if (!sf_histint(vel,"n1",&nx)) sf_error("No n1= in input");
    if (!sf_histfloat(vel,"d1",&dx)) sf_error("No d1= in input");
    if (!sf_histint(inp,"n1",&nt)) sf_error("No n2= in input");
    if (!sf_histfloat(inp,"d1",&dt)) sf_error("No d2= in input");

    sf_putint(out,"n1",nx);
    sf_putfloat(out,"d1",dx);
    sf_putint(out,"n2",nt);
    sf_putfloat(out,"d2",dt);

    if (!sf_getint("what",&what)) what=2; /* 2nd or 4th order for FD*/
    sig = sf_floatalloc(nt);
    old = sf_floatalloc(nx);
    nxt = sf_floatalloc(nx);
    cur = sf_floatalloc(nx);
    v = sf_floatalloc(nx);
    vx = sf_floatalloc(nx);

    sf_floatread(v,nx,vel);
    sf_floatread(vx,nx,grad);

    sf_fileclose(vel);
    sf_fileclose(grad);

    sf_floatread(sig,nt,inp);		
    
    switch(what) {
	case 2:
	    /* 2nd order FD*/
	    a = sf_floatalloc2(3,nx);
	    for (ix=0; ix < nx; ix++) {
		/* dimensionless velocity */
		w = v[ix] * dt/dx;
		/* dimensionless gradient */
		g = 0.5 * vx[ix] * dt;

		a1 = w*w * (1.0 + g*g);
		a2= g*w;
	
		a[ix][0] = a1+a2;
		a[ix][1] = -2*a1;
		a[ix][2] = a1-a2;

		/* initial conditions */
		cur[ix] = 0.;
		nxt[ix] = 0.;
	    }

	    free(v);
	    free(vx);

	    /* propagation in time */
	    for (it=0; it < nt; it++) {


		for (ix=0; ix < nx; ix++) {
		    old[ix] = cur[ix];
		    cur[ix] = nxt[ix];
		}   

		/* Stencil */
		nxt[0] = sig[it]; 
		for (ix=1; ix < nx-1; ix++) {
		    nxt[ix] = cur[ix]*a[ix][1] + cur[ix+1]*a[ix][0] + cur[ix-1]*a[ix][2];
		}
		nxt[nx-1] = cur[nx-1]*a[nx-1][1] + cur[nx-1]*a[nx-1][0] + cur[nx-2]*a[nx-1][2];
	
		for (ix=1; ix < nx; ix++) {
		    nxt[ix] += 2*cur[ix] - old[ix];
		} 

		sf_floatwrite(nxt,nx,out);
	    }
	    break;
        
        case 4:
	    /* 4th order FD*/
	    a = sf_floatalloc2(5,nx);
     
	    for (ix=0; ix < nx; ix++) {
		/* dimensionless velocity */
		w = v[ix] * dt/dx;
		/* dimensionless gradient */
		g = vx[ix] * dt;

		a1 = w*w * (4.0 + g*g);
		a2 = w*w*w*w*(16.0+24.0*g*g+g*g*g*g);
		a3 = w*g;
		a4 = w*w*w*g*(12.0+g*g);	
		a[ix][0] = -a1/48.0+a2/192.0-a3/12.0+a4/48.0;
		a[ix][1] = a1/3.0-a2/48.0+2.0*a3/3.0-a4/24.0; 
		a[ix][2] = -5.0*a1/8.0+a2/32.0; 
		a[ix][3] = a1/3.0-a2/48.0-2.0*a3/3.0+a4/24.0; 
		a[ix][4] = -a1/48.0+a2/192.0+a3/12.0-a4/48.0;

		/* initial conditions */
		cur[ix] = 0.;
		nxt[ix] = 0.;
	    }

	    free(v);
	    free(vx);

	    /* propagation in time */
	    for (it=0; it < nt; it++) {

		for (ix=0; ix < nx; ix++) {
		    old[ix] = cur[ix];
		    cur[ix] = nxt[ix];
		}  

		/* Stencil */
		nxt[0] = sig[it]; 
		nxt[1] = cur[0]*a[1][4] +cur[0]*a[1][3] +cur[1]*a[1][2] 
		    + cur[2]*a[1][1] + cur[3]*a[1][0];
		for (ix=2; ix < nx-2; ix++) {
		    nxt[ix] = cur[ix+2]*a[ix][0] + cur[ix+1]*a[ix][1] + cur[ix]*a[ix][2]
			+ cur[ix-1]*a[ix][3] + cur[ix-2]*a[ix][4];

		}
		nxt[nx-2] = cur[nx-4]*a[nx-2][4] + cur[nx-3]*a[nx-2][3] + cur[nx-2]*a[nx-2][2]
	            + cur[nx-1]*a[nx-2][1] + cur[nx-1]*a[nx-2][0];
		nxt[nx-1] = cur[nx-3]*a[nx-1][4] + cur[nx-2]*a[nx-1][3] + cur[nx-1]*a[nx-1][2]
	            + cur[nx-1]*a[nx-1][1] + cur[nx-1]*a[nx-1][0];
		for (ix=1; ix < nx; ix++) {
		    nxt[ix] += 2*cur[ix] - old[ix];
		}  

		sf_floatwrite(nxt,nx,out);
	    } 
	    break;
 
        case 8:
	    /* 4th order FD*/
	    a = sf_floatalloc2(7,nx);
     
	    for (ix=0; ix < nx; ix++) {
		/* dimensionless velocity */
		w = v[ix] * dt/dx;
		/* dimensionless gradient */
		g = vx[ix] * dt;
		a0 = w*g;
		a1 = w*w*(4.0 + g*g);
		a2 = w*w*w*g*(12.0+g*g);	
		a3 = pow(w,4)*(16.0+24.0*g*g+pow(g,4));
		a4 = pow(w,5)*g*(80.0+40.0*g*g+pow(g,4));
		a5 = pow(w,6)*(64.0+240.0*g*g+60.0*pow(g,4)+pow(g,6));

		a[ix][0] = (384.0*a0+64.0*a1-120.0*a2-20.0*a3+6.0*a4+a5)/23040.0;  
		a[ix][1] = -(576.0*a0+144.0*a1-160.0*a2-40.0*a3+4.0*a4+a5)/3840.0;
		a[ix][2] = (1152.0*a0+576.0*a1-104.0*a2-52.0*a3+2.0*a4+a5)/1536.0;
		a[ix][3] = -(784.0*a1-56.0*a3+a5)/1152.0;
		a[ix][4] = (-1152.0*a0+576.0*a1+104.0*a2-52.0*a3-2.0*a4+a5)/1536.0;
		a[ix][5] = -(-576.0*a0+144.0*a1+160.0*a2-40.0*a3-4.0*a4+a5)/3840.0;
		a[ix][6] = (-384.0*a0+64.0*a1+120.0*a2-20.0*a3-6.0*a4+a5)/23040.0;  

		/* initial conditions */
		cur[ix] = 0.;
		nxt[ix] = 0.;
	    }

	    free(v);
	    free(vx);


	    /* propagation in time */
	    for (it=0; it < nt; it++) {

		for (ix=0; ix < nx; ix++) {
		    old[ix] = cur[ix];
		    cur[ix] = nxt[ix];
		}  

		/* Stencil */
		nxt[0] = sig[it]; 
		nxt[1] = cur[0]*a[1][6] +cur[0]*a[1][5] +cur[0]*a[1][4] +cur[1]*a[1][3] +cur[2]*a[1][2] 
		    + cur[3]*a[1][1] + cur[4]*a[1][0];
		nxt[2] = cur[0]*a[1][6] +cur[0]*a[1][5] +cur[1]*a[1][4] +cur[2]*a[1][3] +cur[3]*a[1][2] 
		    + cur[4]*a[1][1] + cur[5]*a[1][0];
		for (ix=3; ix < nx-3; ix++) {
		    nxt[ix] = cur[ix+3]*a[ix][0] +cur[ix+2]*a[ix][1] + cur[ix+1]*a[ix][2] + cur[ix]*a[ix][3]
			+ cur[ix-1]*a[ix][4] + cur[ix-2]*a[ix][5]+ cur[ix-3]*a[ix][6];

		}
		nxt[nx-3] = cur[nx-6]*a[nx-3][6] + cur[nx-5]*a[nx-3][5] + cur[nx-4]*a[nx-3][4] + cur[nx-3]*a[nx-3][3]
	            + cur[nx-2]*a[nx-3][2]+ cur[nx-1]*a[nx-3][1] + cur[nx-1]*a[nx-3][0];
		nxt[nx-2] = cur[nx-5]*a[nx-2][6] + cur[nx-4]*a[nx-2][5] + cur[nx-3]*a[nx-2][4] + cur[nx-2]*a[nx-2][3]
	            + cur[nx-1]*a[nx-2][2] + cur[nx-1]*a[nx-2][1] + cur[nx-1]*a[nx-2][0];
		nxt[nx-1] = cur[nx-4]*a[nx-1][6] + cur[nx-3]*a[nx-1][5] + cur[nx-2]*a[nx-1][4] + cur[nx-1]*a[nx-1][3]
	            + cur[nx-1]*a[nx-1][2] + cur[nx-1]*a[nx-1][1] + cur[nx-1]*a[nx-1][0];
		for (ix=1; ix < nx; ix++) {
		    nxt[ix] += 2*cur[ix] - old[ix];
		}  

		sf_floatwrite(nxt,nx,out);
	    } 



    }         

    exit(0); 
}           
Beispiel #24
0
int main(int argc, char* argv[])
{
     	int	i,j,im,jm,nx,nz,nxpad,nzpad,it,ii,jj;

        float   f0, t, t0, dx, dz,dt, dt2;
        int     mm, nvx, nvz, ns;
        int     isx, isz, isxm, iszm; /*source location */

        float   *coeff_1dx, *coeff_1dz, *coeff_2dx, *coeff_2dz; /* finite-difference coefficient */

        float **vp0, **vs0, **epsi, **del, **theta;         /* velocity model */
        float **p1, **p2, **p3, **q1, **q2, **q3;  /* wavefield array */

        float   A, fx, fz;

        sf_init(argc,argv);

        sf_file Fo1, Fo2;
       
        /*  wavelet parameter for source definition */
        f0=30.0;                  
        t0=0.04;                  
        A=1.0;                  

        /* time samping paramter */
        if (!sf_getint("ns",&ns)) ns=301;
        if (!sf_getfloat("dt",&dt)) dt=0.001;

        sf_warning("ns=%d dt=%f",ns,dt);
        sf_warning("read velocity model parameters");

        /* setup I/O files */
        sf_file Fvp0, Fvs0, Feps, Fdel, Fthe;

        Fvp0 = sf_input ("in");  /* vp0 using standard input */
        Fvs0 = sf_input ("vs0");  /* vs0 */
        Feps = sf_input ("epsi");  /* epsi */
        Fdel = sf_input ("del");  /* delta */
        Fthe = sf_input ("the");  /* theta */

        /* Read/Write axes */
        sf_axis az, ax;
        az = sf_iaxa(Fvp0,1); nvz = sf_n(az); dz = sf_d(az)*1000.0;
        ax = sf_iaxa(Fvp0,2); nvx = sf_n(ax); dx = sf_d(ax)*1000.0;
        fx=sf_o(ax)*1000.0;
        fz=sf_o(az)*1000.0;

        /* source definition */
        isx=nvx/2;
        isz=nvz/2;
        //isz=nvz*2/5;

        /* wave modeling space */
	nx=nvx;
	nz=nvz;
        nxpad=nx+2*_m;
        nzpad=nz+2*_m;

        sf_warning("fx=%f fz=%f dx=%f dz=%f",fx,fz,dx,dz);

        sf_warning("nx=%d nz=%d nxpad=%d nzpad=%d", nx,nz,nxpad,nzpad);

	vp0=sf_floatalloc2(nz,nx);	
	vs0=sf_floatalloc2(nz,nx);	
	epsi=sf_floatalloc2(nz,nx);	
	del=sf_floatalloc2(nz,nx);	
	theta=sf_floatalloc2(nz,nx);	

        int nxz=nx*nz;
        mm=2*_m+1;

        dt2=dt*dt;
        isxm=isx+_m;  /* source's x location */
        iszm=isz+_m;  /* source's z-location */

        /* read velocity model */
        sf_floatread(vp0[0],nxz,Fvp0);
        sf_floatread(vs0[0],nxz,Fvs0);
        sf_floatread(epsi[0],nxz,Feps);
        sf_floatread(del[0],nxz,Fdel);
        sf_floatread(theta[0],nxz,Fthe);

        for(i=0;i<nx;i++)
        for(j=0;j<nz;j++)
           theta[i][j] *= SF_PI/180.0;

        Fo1 = sf_output("out"); /* Elastic-wave x-component */
        Fo2 = sf_output("Elasticz"); /* Elastic-wave z-component */
        /* setup I/O files */
        puthead3(Fo1, nz, nx, 1, dz/1000.0, dx/1000.0, dt, fz/1000.0, fx/1000.0, 0.0);
        puthead3(Fo2, nz, nx, 1, dz/1000.0, dx/1000.0, dt, fz/1000.0, fx/1000.0, 0.0);

	/****************begin to calculate wavefield****************/
	/****************begin to calculate wavefield****************/
        sf_warning("==================================================");
        sf_warning("==      Propagation Using Elastic Wave Eq.      ==");
        sf_warning("==================================================");
       coeff_2dx=sf_floatalloc(mm);
       coeff_2dz=sf_floatalloc(mm);
       coeff_1dx=sf_floatalloc(mm);
       coeff_1dz=sf_floatalloc(mm);

        coeff2d(coeff_2dx,dx);
        coeff2d(coeff_2dz,dz);

	p1=sf_floatalloc2(nzpad, nxpad);
	p2=sf_floatalloc2(nzpad, nxpad);
	p3=sf_floatalloc2(nzpad, nxpad);

	q1=sf_floatalloc2(nzpad, nxpad);
	q2=sf_floatalloc2(nzpad, nxpad);
	q3=sf_floatalloc2(nzpad, nxpad);

        zero2float(p1, nzpad, nxpad);
        zero2float(p2, nzpad, nxpad);
        zero2float(p3, nzpad, nxpad);
      
        zero2float(q1, nzpad, nxpad);
        zero2float(q2, nzpad, nxpad);
        zero2float(q3, nzpad, nxpad);
        
        coeff1dmix(coeff_1dx,dx);
        coeff1dmix(coeff_1dz,dz);

	for(it=0;it<ns;it++)
	{
		t=it*dt;

                // 2D exploding force source (e.g., Wu's PhD
                for(i=-1;i<=1;i++)
                for(j=-1;j<=1;j++)
                {
                     if(fabs(i)+fabs(j)==2)
                     {
                          p2[isxm+i][iszm+j]+=i*Ricker(t, f0, t0, A);
                          q2[isxm+i][iszm+j]+=j*Ricker(t, f0, t0, A);
                     }
                }
        // 2D equil-energy force source (e.g., Wu's PhD)
        /*
        for(i=-1;i<=1;i++)
        for(j=-1;j<=1;j++)
        {
             if(fabs(i)+fabs(j)==2)
             {
                  if(i==-1&&j==1)  
                    q2[isxm+i][iszm+j]+=sqrt(2.0)*Ricker(t, f0, t0, A);
                  if(i==-1&&j==-1) 
                   p2[isxm+i][iszm+j]+=-sqrt(2.0)*Ricker(t, f0, t0, A);
                  if(i==1&&j==1)  
                   p2[isxm+i][iszm+j]+=sqrt(2.0)*Ricker(t, f0, t0, A);
                  if(i==1&&j==-1) 
                    q2[isxm+i][iszm+j]+=-sqrt(2.0)*Ricker(t, f0, t0, A);
             }
        }
        */
                /* fwpvtielastic: forward-propagating using original elastic equation of displacement in VTI media*/
		fwpttielastic(dt2, p1, p2, p3, q1, q2, q3, coeff_2dx, coeff_2dz, coeff_1dx, coeff_1dz,
                              dx, dz, nx, nz, nxpad, nzpad, vp0, vs0, epsi, del, theta);

               /******* output wavefields: component and divergence *******/
	       if(it==ns-1)
		{
		     for(i=0;i<nx;i++)
                     {
                        im=i+_m;
		        for(j=0;j<nz;j++)
		        {
                            jm=j+_m;
	                    sf_floatwrite(&p3[im][jm],1,Fo1);
	                    sf_floatwrite(&q3[im][jm],1,Fo2);
			}
                     }/* i loop*/
                       
                }/* (it+1)%ntstep==0 */

                /**************************************/
 	        for(i=0,ii=_m;i<nx;i++,ii++)
	        for(j=0,jj=_m;j<nz;j++,jj++)
		{
				p1[ii][jj]=p2[ii][jj];	
				p2[ii][jj]=p3[ii][jj];	

				q1[ii][jj]=q2[ii][jj];	
				q2[ii][jj]=q3[ii][jj];	
		}

		if(it%100==0)
			sf_warning("Elastic: it= %d",it);
        }/* it loop */

        free(*p1);
        free(*p2);
        free(*p3);
        free(*q1);
        free(*q2);
        free(*q3);

        free(*vp0);
        free(*vs0);
        free(*epsi);
        free(*del);
        free(*theta);

	exit(0);
}
Beispiel #25
0
int main(int argc, char* argv[])
{

    /*survey parameters*/
    int   nx, nz;
    float dx, dz;
    int   n_srcs;
    int   *spx, *spz;
    int   gpz, gpx, gpl;
    int   gpz_v, gpx_v, gpl_v;
    int   snap;
    /*fft related*/
    bool  cmplx;
    int   pad1;
    /*absorbing boundary*/
    bool abc;
    int nbt, nbb, nbl, nbr;
    float ct,cb,cl,cr;
    /*source parameters*/
    int src; /*source type*/
    int nt,ntsnap;
    float dt,*f0,*t0,*A;
    /*misc*/
    bool verb, ps, mig;
    float vref;

    pspar par;
    int nx1, nz1; /*domain of interest*/
    int it;
    float *vel,**dat,**dat_v,**wvfld,*img; /*velocity profile*/
    sf_file Fi,Fo,Fd,Fd_v,snaps; /* I/O files */
    sf_axis az,ax; /* cube axes */

    sf_init(argc,argv);

    if (!sf_getint("snap",&snap)) snap=0; /* interval for snapshots */
    if (!sf_getbool("cmplx",&cmplx)) cmplx=true; /* use complex fft */
    if (!sf_getint("pad1",&pad1)) pad1=1; /* padding factor on the first axis */
    if(!sf_getbool("abc",&abc)) abc=false; /* absorbing flag */
    if (abc) {
      if(!sf_getint("nbt",&nbt)) sf_error("Need nbt!");
      if(!sf_getint("nbb",&nbb)) nbb = nbt;
      if(!sf_getint("nbl",&nbl)) nbl = nbt;
      if(!sf_getint("nbr",&nbr)) nbr = nbt;
      if(!sf_getfloat("ct",&ct)) sf_error("Need ct!");
      if(!sf_getfloat("cb",&cb)) cb = ct;
      if(!sf_getfloat("cl",&cl)) cl = ct;
      if(!sf_getfloat("cr",&cr)) cr = ct;
    } else {
      nbt = 0; nbb = 0; nbl = 0; nbr = 0;
      ct = 0; cb = 0; cl = 0; cr = 0;
    }
    if (!sf_getbool("verb",&verb)) verb=false; /* verbosity */
    if (!sf_getbool("ps",&ps)) ps=false; /* use pseudo-spectral */
    if (ps) sf_warning("Using pseudo-spectral...");
    else sf_warning("Using pseudo-analytical...");
    if (!sf_getbool("mig",&mig)) mig=false; /* use pseudo-spectral */
    if (mig) sf_warning("Time-reversal propagation");
    else sf_warning("Forward modeling");
    if (!sf_getfloat("vref",&vref)) vref=1500; /* reference velocity (default using water) */

    /* setup I/O files */
    Fi = sf_input ("in");
    Fo = sf_output("out");
    if (mig) {
      gpl = -1;
      gpl_v = -1;
      if (NULL==sf_getstring("dat") && NULL==sf_getstring("dat_v"))
	sf_error("Need Data!");
      if (NULL!=sf_getstring("dat")) {
	Fd = sf_input("dat");
	sf_histint(Fd,"n1",&nt);
	sf_histfloat(Fd,"d1",&dt);
	sf_histint(Fd,"n2",&gpl);
      } else Fd = NULL;
      if (NULL!=sf_getstring("dat_v")) {
	Fd_v = sf_input("dat_v");
	sf_histint(Fd_v,"n1",&nt);
	sf_histfloat(Fd_v,"d1",&dt);
	sf_histint(Fd_v,"n2",&gpl_v);
      } else Fd_v = NULL;
      src = -1; n_srcs = -1;
      spx = NULL; spz = NULL;
      f0 = NULL; t0 = NULL; A = NULL;
    } else {
      Fd = NULL;
      if (!sf_getint("nt",&nt)) sf_error("Need nt!");
      if (!sf_getfloat("dt",&dt)) sf_error("Need dt!");
      if (!sf_getint("gpl",&gpl)) gpl = -1; /* geophone length */
      if (!sf_getint("gpl_v",&gpl_v)) gpl_v = -1; /* geophone height */
      if (!sf_getint("src",&src)) src=0; /* source type */
      if (!sf_getint("n_srcs",&n_srcs)) n_srcs=1; /* source type */
      spx = sf_intalloc(n_srcs);
      spz = sf_intalloc(n_srcs);
      f0  = sf_floatalloc(n_srcs);
      t0  = sf_floatalloc(n_srcs);
      A   = sf_floatalloc(n_srcs);
      if (!sf_getints("spx",spx,n_srcs)) sf_error("Need spx!"); /* shot position x */
      if (!sf_getints("spz",spz,n_srcs)) sf_error("Need spz!"); /* shot position z */
      if (!sf_getfloats("f0",f0,n_srcs)) sf_error("Need f0! (e.g. 30Hz)");   /*  wavelet peak freq */
      if (!sf_getfloats("t0",t0,n_srcs)) sf_error("Need t0! (e.g. 0.04s)");  /*  wavelet time lag */
      if (!sf_getfloats("A",A,n_srcs)) sf_error("Need A! (e.g. 1)");     /*  wavelet amplitude */
    }
    if (!sf_getint("gpx",&gpx)) gpx = -1; /* geophone position x */
    if (!sf_getint("gpz",&gpz)) gpz = -1; /* geophone position z */
    if (!sf_getint("gpx_v",&gpx_v)) gpx_v = -1; /* geophone position x */
    if (!sf_getint("gpz_v",&gpz_v)) gpz_v = -1; /* geophone position z */

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

    /* Read/Write axes */
    az = sf_iaxa(Fi,1); nz = sf_n(az); dz = sf_d(az);
    ax = sf_iaxa(Fi,2); nx = sf_n(ax); dx = sf_d(ax);
    nz1 = nz-nbt-nbb;
    nx1 = nx-nbl-nbr;
    if (gpx==-1) gpx = nbl;
    if (gpz==-1) gpz = nbt;
    if (gpl==-1) gpl = nx1;
    if (gpx_v==-1) gpx_v = nbl;
    if (gpz_v==-1) gpz_v = nbt;
    if (gpl_v==-1) gpl_v = nz1;
    ntsnap=0;
    if (snap)
        for (it=0;it<nt;it++)
            if (it%snap==0) ntsnap++;

    if (mig) { /*output final wavefield*/
      sf_setn(az,nz1);
      sf_setn(ax,nx1);
      sf_oaxa(Fo,az,1);
      sf_oaxa(Fo,ax,2);
      sf_settype(Fo,SF_FLOAT);
    } else { /*output data*/
      sf_setn(ax,gpl);
      /*output horizontal data is mandatory*/
      sf_putint(Fo,"n1",nt);
      sf_putfloat(Fo,"d1",dt);
      sf_putfloat(Fo,"o1",0.);
      sf_putstring(Fo,"label1","Time");
      sf_putstring(Fo,"unit1","s");
      sf_oaxa(Fo,ax,2);
      sf_settype(Fo,SF_FLOAT);
      /*output vertical data is optional*/
      if (NULL!=sf_getstring("dat_v")) {
	Fd_v = sf_output("dat_v");
	sf_setn(az,gpl_v);
	sf_putint(Fd_v,"n1",nt);
	sf_putfloat(Fd_v,"d1",dt);
	sf_putfloat(Fd_v,"o1",0.);
	sf_putstring(Fd_v,"label1","Time");
	sf_putstring(Fd_v,"unit1","s");
	sf_oaxa(Fd_v,az,2);
	sf_settype(Fd_v,SF_FLOAT);	
      } else Fd_v = NULL;
    }

    if (snap > 0) {
	snaps = sf_output("snaps");
	/* (optional) snapshot file */
	sf_setn(az,nz1);
	sf_setn(ax,nx1);
	sf_oaxa(snaps,az,1);
	sf_oaxa(snaps,ax,2);
	sf_putint(snaps,"n3",ntsnap);
	sf_putfloat(snaps,"d3",dt*snap);
	sf_putfloat(snaps,"o3",0.);
	sf_putstring(snaps,"label3","Time");
	sf_putstring(snaps,"unit3","s");
    } else snaps = NULL;
    
    par = (pspar) sf_alloc(1,sizeof(*par));
    vel = sf_floatalloc(nz*nx);
    if (mig && NULL==Fd) dat = NULL;
    else dat = sf_floatalloc2(nt,gpl);
    if (NULL!=Fd_v) dat_v = sf_floatalloc2(nt,gpl_v);
    else dat_v = NULL;
    if (mig) img = sf_floatalloc(nz1*nx1);
    else img = NULL;
    if (snap>0) wvfld = sf_floatalloc2(nx1*nz1,ntsnap);
    else wvfld = NULL;

    sf_floatread(vel,nz*nx,Fi);
    if (mig) {
      if (NULL!=Fd)   sf_floatread(dat[0],gpl*nt,Fd);
      if (NULL!=Fd_v) sf_floatread(dat_v[0],gpl_v*nt,Fd_v);
    }

    /*passing the parameters*/
    par->nx    = nx;  
    par->nz    = nz;
    par->dx    = dx;
    par->dz    = dz;
    par->n_srcs= n_srcs;
    par->spx   = spx;
    par->spz   = spz;
    par->gpz   = gpz;
    par->gpx   = gpx;
    par->gpl   = gpl;
    par->gpz_v = gpz_v;
    par->gpx_v = gpx_v;
    par->gpl_v = gpl_v;
    par->snap  = snap;
    par->cmplx = cmplx;
    par->pad1  = pad1;
    par->abc   = abc;
    par->nbt   = nbt;
    par->nbb   = nbb;
    par->nbl   = nbl;
    par->nbr   = nbr;
    par->ct    = ct;
    par->cb    = cb;
    par->cl    = cl;
    par->cr    = cr;
    par->src   = src;
    par->nt    = nt;
    par->dt    = dt;
    par->f0    = f0;
    par->t0    = t0;
    par->A     = A;
    par->verb  = verb;
    par->ps    = ps;
    par->vref  = vref;

    /*do the work*/
    psp(wvfld, dat, dat_v, img, vel, par, mig);

    if (mig) {
      sf_floatwrite(img,nz1*nx1,Fo);
    } else {
      sf_floatwrite(dat[0],gpl*nt,Fo);
      if (NULL!=Fd_v)
	sf_floatwrite(dat_v[0],gpl_v*nt,Fd_v);
    }

    if (snap>0)
      sf_floatwrite(wvfld[0],nz1*nx1*ntsnap,snaps);
    
    exit (0);
}
Beispiel #26
0
int main (int argc,char* argv[]) 
{
    int n[3], ns, ns0, nt, is0, s0;
    float o[3], os, os0, d[3], ds, ds0, **t, **tds, *tempt, ss;
    char *type;
    sf_file in, out, deriv, pattern;

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

    /* read input dimensions */
    if(!sf_histint(in,"n1",n  )) sf_error("No n1= in input");
    if(!sf_histint(in,"n2",n+1)) sf_error("No n2= in input");
    if(!sf_histint(in,"n3",n+2)) n[2]=1;
    if(!sf_histint(in,"n4",&ns)) sf_error("No ns= in input");

    if (ns <= 1) sf_error("Provide at least two shots");

    if(!sf_histfloat(in,"d1",d  )) sf_error("No d1= in input");
    if(!sf_histfloat(in,"d2",d+1)) sf_error("No d2= in input");
    if(!sf_histfloat(in,"d3",d+2)) d[2]=d[1];
    if(!sf_histfloat(in,"d4",&ds)) ds=d[1];

    if(!sf_histfloat(in,"o1",o  )) o[0]=0.;
    if(!sf_histfloat(in,"o2",o+1)) o[1]=0.;
    if(!sf_histfloat(in,"o3",o+2)) o[2]=o[1];
    if(!sf_histfloat(in,"o4",&os)) os=o[1];

    /* read traveltime file */
    nt = n[0]*n[1]*n[2];
    
    t = sf_floatalloc2(nt,ns);
    sf_floatread(t[0],nt*ns,in);

    if (NULL == (type = sf_getstring("type"))) type="hermit";
    /* type of interpolation (default Hermit) */

    if (type[0] != 'h') {
	/* linear interpolation */
	deriv = NULL;
	tds = NULL;
    } else {
	/* read derivative file */
	if (NULL == sf_getstring("deriv"))
	    sf_error("Need derivative deriv=");
	deriv = sf_input("deriv");

	tds = sf_floatalloc2(nt,ns);
	sf_floatread(tds[0],nt*ns,deriv);
	sf_fileclose(deriv);
    }
    
    if (NULL != sf_getstring("pattern")) {
	pattern = sf_input("pattern");
    } else {
	pattern = NULL;
    }
    
    if (!sf_getint("ns",&ns0) && 
	(NULL==pattern ||
	 !sf_histint(pattern,"n4",&ns0))) sf_error("Need ns=");
    /* Output source size */
    if (!sf_getfloat("ds",&ds0) && 
	(NULL==pattern ||
	 !sf_histfloat(pattern,"d4",&ds0))) sf_error("Need ds=");
    /* Output source sampling */
    if (!sf_getfloat("os",&os0) &&
	(NULL==pattern ||
	 !sf_histfloat(pattern,"o4",&os0))) sf_error("Need os=");
    /* Output source origin */
    
    sf_putint(out,"n4",ns0);
    sf_putfloat(out,"d4",ds0);
    sf_putfloat(out,"o4",os0);

    /* allocate temporaty memory */
    tempt = sf_floatalloc(nt);

    /* initialization */
    tinterp_init(nt,ds);

    /* loop over sources */
    for (is0=0; is0 < ns0; is0++) {
	s0 = (os0+is0*ds0-os)/ds;
	ss = os0+is0*ds0-os-s0*ds;

	if (s0 < 0) {
	    s0 = 0; ss = 0.;
	}
	if (s0 >= ns-1) {
	    s0 = ns-2; ss = ds;
	}

	/* do interpolation */
	switch (type[0]) {
	    case 'l': /* linear */
		tinterp_linear(tempt,ss,t[s0],t[s0+1]);
		break;

	    case 'p': /* partial */
		tinterp_partial(tempt,ss,n[0],n[1],d[1],t[s0],t[s0+1]);
		break;

	    case 'h': /* hermite */
		tinterp_hermite(tempt,ss,t[s0],t[s0+1],tds[s0],tds[s0+1]);
		break;
	}
	
	sf_floatwrite(tempt,nt,out);
    }

    exit (0);
}
Beispiel #27
0
void FwiParams::getInputParams() {
  /* get parameters from velocity model and recorded shots */
   if (!sf_getbool("verb", &verb)) {
     verb = true;  /* vebosity */
   }
   if (!sf_histint(vinit, "n1", &nz)) {
     sf_error("no n1");  /* nz */
   }
   if (!sf_histint(vinit, "n2", &nx)) {
     sf_error("no n2");  /* nx */
   }
   if (!sf_histfloat(vinit, "d1", &dz)) {
     sf_error("no d1");  /* dz */
   }
   if (!sf_histfloat(vinit, "d2", &dx)) {
     sf_error("no d2");  /* dx */
   }
   if (!sf_getbool("precon", &precon)) {
     precon = false;  /* precondition or not */
   }
   if (!sf_getint("niter", &niter)) {
     niter = 100;  /* number of iterations */
   }
   if (!sf_getint("rbell", &rbell)) {
     rbell = 2;  /* radius of bell smooth */
   }

   if (!sf_histint(shots, "n1", &nt)) {
     sf_error("no nt");
   }
   /* total modeling time steps */
   if (!sf_histint(shots, "n2", &ng)) {
     sf_error("no ng");
   }
   /* total receivers in each shot */
   if (!sf_histint(shots, "n3", &ns)) {
     sf_error("no ns");
   }
   /* number of shots */
   if (!sf_histfloat(shots, "d1", &dt)) {
     sf_error("no dt");
   }
   /* time sampling interval */
   if (!sf_histfloat(shots, "amp", &amp)) {
     sf_error("no amp");
   }
   /* maximum amplitude of ricker */
   if (!sf_histfloat(shots, "fm", &fm)) {
     sf_error("no fm");
   }
   /* dominant freq of ricker */
   if (!sf_histint(shots, "sxbeg", &sxbeg)) {
     sf_error("no sxbeg");
   }
   /* x-begining index of sources, starting from 0 */
   if (!sf_histint(shots, "szbeg", &szbeg)) {
     sf_error("no szbeg");
   }
   /* x-begining index of sources, starting from 0 */
   if (!sf_histint(shots, "gxbeg", &gxbeg)) {
     sf_error("no gxbeg");
   }
   /* x-begining index of receivers, starting from 0 */
   if (!sf_histint(shots, "gzbeg", &gzbeg)) {
     sf_error("no gzbeg");
   }
   /* x-begining index of receivers, starting from 0 */
   if (!sf_histint(shots, "jsx", &jsx)) {
     sf_error("no jsx");
   }
   /* source x-axis  jump interval  */
   if (!sf_histint(shots, "jsz", &jsz)) {
     sf_error("no jsz");
   }
   /* source z-axis jump interval  */
   if (!sf_histint(shots, "jgx", &jgx)) {
     sf_error("no jgx");
   }
   /* receiver x-axis jump interval  */
   if (!sf_histint(shots, "jgz", &jgz)) {
     sf_error("no jgz");
   }
   /* receiver z-axis jump interval  */

   /* filename of the shot data */
   if (!(obsDataFileName = sf_histstring(shots, "in"))) {
     sf_error("cannot find observed data file path");
   }

   /* # layer of boundary */
   if (!sf_getint("nb", &nb)) {
     sf_error("nb is not set");
   }
}
Beispiel #28
0
void c2r_sinc(
    bool      adj,
    float      **mapCC,
    float      **mapRC,
    sf_complex **rays)
/*< sinc interpolation >*/
{
    int it,ig,iz,ix;
    int  jx,jz;
    float x, z;

    float xo,zo;
    float dr,r,sincr;
    int   nsz,nsx;
    float  dz,dx;

    dr = sqrtf(az.d*az.d + ax.d*ax.d);
    
    if(! sf_getint("nsz",&nsz)) nsz=1; if(verb) sf_warning("nsz=%d",nsz);
    if(! sf_getint("nsx",&nsx)) nsx=1; if(verb) sf_warning("nsx=%d",nsx);
    
    /* loop over RC */
    for(it=0;it<at.n;it++) {
	if( verb && it%100 == 0 ) sf_warning("SINT %d of %d",it,at.n);
	for(ig=0;ig<ag.n;ig++) {
	    
	    z = cimagf(rays[it][ig]);
	    x = crealf(rays[it][ig]);
	    
	    iz=floor((z-az.o)/az.d);
	    ix=floor((x-ax.o)/ax.d);
	    
	    if(iz>=nsz && iz<=az.n-nsz-1 && ix>=nsx && ix<=ax.n-nsx-1) {
		
		/* sinc */
		for(jz=iz-nsz; jz<=iz+nsz; jz++) {
		    zo=az.o+jz*az.d;
		    dz=zo-z;
		    
		    for(jx=ix-nsx; jx<=ix+nsx; jx++) {
			xo=ax.o+jx*ax.d;
			dx=xo-x;
			
			r=sqrt(dz*dz + dx*dx);
			
			if(SF_ABS(r) < 0.00001*dr) {
			    sincr = 1.0;
			} else {
			    r = r / dr;
			    sincr = sin(r)/r;
			}
			
			if(adj) {
			    mapCC[jz][jx] += mapRC[it][ig] * sincr;
			} else {
			    mapRC[it][ig] += mapCC[jz][jx] * sincr;
			}
		    }
		}
		/* sinc end */
		
	    } /* if iz,ix in bounds */
	    
	} /* ig */
    } /* it */
    
}
Beispiel #29
0
int main(int argc, char* argv[])
{
    bool verb;        
    int it,iz,im,ik,ix,i,j;     /* index variables */
    int nt,nz,nx, m2, nk, nzx, nz2, nx2, nzx2, n2, pad1;
    sf_complex c;

    float  *rr;      /* I/O arrays*/
    sf_complex *ww, *cwave, *cwavem;

    sf_complex **wave, *curr;
    float *rcurr;
    
    sf_file Fw,Fr,Fo;    /* I/O files */
    sf_axis at,az,ax;    /* cube axes */

    sf_complex **lt, **rt;
    sf_file left, right;


    sf_init(argc,argv);
    if(!sf_getbool("verb",&verb)) verb=false; /* verbosity */

    /* setup I/O files */
    Fw = sf_input ("in" );
    Fo = sf_output("out");
    Fr = sf_input ("ref");

    if (SF_COMPLEX != sf_gettype(Fw)) sf_error("Need complex input");
    if (SF_FLOAT != sf_gettype(Fr)) sf_error("Need float ref");

    sf_settype(Fo,SF_FLOAT);

    /* Read/Write axes */
    at = sf_iaxa(Fw,1); nt = sf_n(at); 
    az = sf_iaxa(Fr,1); nz = sf_n(az); 
    ax = sf_iaxa(Fr,2); nx = sf_n(ax); 

    sf_oaxa(Fo,az,1); 
    sf_oaxa(Fo,ax,2); 
    sf_oaxa(Fo,at,3);
    
    if (!sf_getint("pad1",&pad1)) pad1=1; /* padding factor on the first axis */

    nk = cfft2_init(pad1,nz,nx,&nz2,&nx2);

    nzx = nz*nx;
    nzx2 = nz2*nx2;

    /* propagator matrices */
    left = sf_input("left");
    right = sf_input("right");

    if (!sf_histint(left,"n1",&n2) || n2 != nzx) sf_error("Need n1=%d in left",nzx);
    if (!sf_histint(left,"n2",&m2))  sf_error("Need n2= in left");
    
    if (!sf_histint(right,"n1",&n2) || n2 != m2) sf_error("Need n1=%d in right",m2);
    if (!sf_histint(right,"n2",&n2) || n2 != nk) sf_error("Need n2=%d in right",nk);
//    if (!sf_histint(Fw,"n1",&nxx)) sf_error("No n1= in input");
  
    lt = sf_complexalloc2(nzx,m2);
    rt = sf_complexalloc2(m2,nk);

    sf_complexread(lt[0],nzx*m2,left);
    sf_complexread(rt[0],m2*nk,right);

//    sf_fileclose(left);
//    sf_fileclose(right);

    /* read wavelet & reflectivity */
    ww=sf_complexalloc(nt);  
    sf_complexread(ww,nt ,Fw);

    rr=sf_floatalloc(nzx); 
    sf_floatread(rr,nzx,Fr);

    curr   = sf_complexalloc(nzx2);
    rcurr  = sf_floatalloc(nzx2);

    cwave  = sf_complexalloc(nk);
    cwavem = sf_complexalloc(nk);
    wave   = sf_complexalloc2(nzx2,m2);


    for (iz=0; iz < nzx2; iz++) {
	curr[iz] = sf_cmplx(0.,0.);
	rcurr[iz]= 0.;
    }

    /* MAIN LOOP */
    for (it=0; it<nt; it++) {
	if(verb) sf_warning("it=%d;",it);

	/* matrix multiplication */
	cfft2(curr,cwave);

	for (im = 0; im < m2; im++) {
	    for (ik = 0; ik < nk; ik++) {
#ifdef SF_HAS_COMPLEX_H
		cwavem[ik] = cwave[ik]*rt[ik][im];
#else
		cwavem[ik] = sf_cmul(cwave[ik],rt[ik][im]); //complex multiplies complex
#endif
//		sf_warning("realcwave=%g, imagcwave=%g", crealf(cwavem[ik]),cimagf(cwavem[ik]));
	    }
	    icfft2(wave[im],cwavem);
	}

	for (ix = 0; ix < nx; ix++) {
	    for (iz=0; iz < nz; iz++) {
		i = iz+ix*nz;  /* original grid */
		j = iz+ix*nz2; /* padded grid */
#ifdef SF_HAS_COMPLEX_H
		c = ww[it] * rr[i]; // source term
#else
		c = sf_crmul(ww[it], rr[i]); // source term
#endif
		for (im = 0; im < m2; im++) {
#ifdef SF_HAS_COMPLEX_H
		    c += lt[im][i]*wave[im][j];
#else
		    c = sf_cadd(c,sf_cmul(lt[im][i], wave[im][j]));
#endif
		}

		curr[j] = c;
		rcurr[j] = crealf(c);
//		rcurr[j] = cimagf(c);
	    }

	    /* write wavefield to output */
	    sf_floatwrite(rcurr+ix*nz2,nz,Fo);
	}
    }
    if(verb) sf_warning("."); 
    
    exit (0);
}
Beispiel #30
0
int main(int argc, char* argv[])
{
    bool verb,fsrf,snap,expl,dabc; 
    int  jsnap,ntsnap,jdata;

    /* OMP parameters */
#ifdef _OPENMP
    int ompnth;
#endif 

    /* I/O files */
    sf_file Fwav=NULL; /* wavelet   */
    sf_file Fsou=NULL; /* sources   */
    sf_file Frec=NULL; /* receivers */

    sf_file Fmag=NULL; /* magnetic permitivity */
    sf_file Fele=NULL; /* electric susceptibility */
    sf_file Fcdt=NULL; /* conductivity */

    sf_file Fdat=NULL; /* data      */
    sf_file Fwfl=NULL; /* wavefield */
    /*------------------------------------------------------------*/ 	
    /*------------------------------------------------------------*/
    /* cube axes */
    sf_axis at,az,ax;
    sf_axis as,ar;

    int     nt,nz,nx,ns,nr,nb;
    int     it,iz,ix;
    float   dt,dz,dx,idz,idx;

    /* FDM structure */
    fdm2d    fdm=NULL;
    abcone2d abc=NULL;
    sponge   spo=NULL;

    /* I/O arrays */
    float  *ww=NULL;           /* wavelet   */
    pt2d   *ss=NULL;           /* sources   */
    pt2d   *rr=NULL;           /* receivers */
    float  *dd=NULL;           /* data      */

    float **tt=NULL;

    float **vel=NULL;           /* velocity */
    float **mag=NULL;
    float **ele=NULL;
    float **cdt=NULL;

    float **cdtele=NULL;        /* temporary cdt*dt/2*ele */
    float **magele=NULL;	/* temporary dt*dt/mag*ele */
    /*------------------------------------------------------------*/

    /*------------------------------------------------------------*/
    float **um,**uo,**up,**ua,**ut; /* wavefield: um = U @ t-1; uo = U @ t; up = U @ t+1 */

    /* linear interpolation weights/indices */
    lint2d cs,cr;

    /* FD operator size */
    float co,cax,cbx,caz,cbz;

    /* wavefield cut params */
    sf_axis   acz=NULL,acx=NULL;
    int       nqz,nqx;
    float     oqz,oqx;
    float     dqz,dqx;
    float     **uc=NULL;

    /*------------------------------------------------------------*/
    /* init RSF */
    sf_init(argc,argv);

    /*------------------------------------------------------------*/
    /* OMP parameters */
#ifdef _OPENMP
    ompnth=omp_init();
#endif
    /*------------------------------------------------------------*/

    if(! sf_getbool("verb",&verb)) verb=false; /* verbosity flag */
    if(! sf_getbool("snap",&snap)) snap=false; /* wavefield snapshots flag */
    if(! sf_getbool("free",&fsrf)) fsrf=false; /* free surface flag */
    if(! sf_getbool("expl",&expl)) expl=false; /* "exploding reflector" */
    if(! sf_getbool("dabc",&dabc)) dabc=false; /* absorbing BC */
    /*------------------------------------------------------------*/

    /*------------------------------------------------------------*/
    /* I/O files */
    Fwav = sf_input ("in" ); /* wavelet   */
    Fsou = sf_input ("sou"); /* sources   */
    Frec = sf_input ("rec"); /* receivers */

    Fwfl = sf_output("wfl"); /* wavefield */
    Fdat = sf_output("out"); /* data      */

    /*------------------------------------------------------------*/
    Fmag = sf_input ("mag"); /* magnetic permitivity */
    Fele = sf_input ("ele"); /* electric susceptibility */
    Fcdt = sf_input ("cdt"); /* conductivity */
    /*------------------------------------------------------------*/
	    
    /*------------------------------------------------------------*/
    /* axes */
    at = sf_iaxa(Fwav,2); sf_setlabel(at,"t"); if(verb) sf_raxa(at); /* time */
    az = sf_iaxa(Fmag,1); sf_setlabel(az,"z"); if(verb) sf_raxa(az); /* depth */
    ax = sf_iaxa(Fmag,2); sf_setlabel(ax,"x"); if(verb) sf_raxa(ax); /* space */

    as = sf_iaxa(Fsou,2); sf_setlabel(as,"s"); if(verb) sf_raxa(as); /* sources */
    ar = sf_iaxa(Frec,2); sf_setlabel(ar,"r"); if(verb) sf_raxa(ar); /* receivers */

    nt = sf_n(at); dt = sf_d(at);
    nz = sf_n(az); dz = sf_d(az);
    nx = sf_n(ax); dx = sf_d(ax);

    ns = sf_n(as);
    nr = sf_n(ar);
    /*------------------------------------------------------------*/

    /*------------------------------------------------------------*/
    /* other execution parameters */
    if(! sf_getint("jdata",&jdata)) jdata=1;
    if(snap) {  /* save wavefield every *jsnap* time steps */
	if(! sf_getint("jsnap",&jsnap)) jsnap=nt;        
    }
    /*------------------------------------------------------------*/

    /*------------------------------------------------------------*/
    /* expand domain for FD operators and ABC 
       we exclude some of the code to maintain the same size of velocity model*/
    if( !sf_getint("nb",&nb) || nb<NOP) nb=NOP;

    fdm=fdutil_init(verb,fsrf,az,ax,nb,1);

    /*sf_setn(az,fdm->nzpad); sf_seto(az,fdm->ozpad); if(verb) sf_raxa(az);
    sf_setn(ax,fdm->nxpad); sf_seto(ax,fdm->oxpad); if(verb) sf_raxa(ax);*/
    /*------------------------------------------------------------*/

    /*------------------------------------------------------------*/
    /* setup output data header */
    sf_oaxa(Fdat,ar,1);

    sf_setn(at,nt/jdata);
    sf_setd(at,dt*jdata);
    sf_oaxa(Fdat,at,2);

    /* setup output wavefield header */
    if(snap) {
	if(!sf_getint  ("nqz",&nqz)) nqz=sf_n(az);
	if(!sf_getint  ("nqx",&nqx)) nqx=sf_n(ax);

	if(!sf_getfloat("oqz",&oqz)) oqz=sf_o(az);
	if(!sf_getfloat("oqx",&oqx)) oqx=sf_o(ax);

	dqz=sf_d(az);
	dqx=sf_d(ax);

	acz = sf_maxa(nqz,oqz,dqz); sf_raxa(acz);
	acx = sf_maxa(nqx,oqx,dqx); sf_raxa(acx);
	/* check if the imaging window fits in the wavefield domain */

	uc=sf_floatalloc2(sf_n(acz),sf_n(acx));

	ntsnap=0;
	for(it=0; it<nt; it++) {
	    if(it%jsnap==0) ntsnap++;
	}
	sf_setn(at,  ntsnap);
	sf_setd(at,dt*jsnap);
	if(verb) sf_raxa(at);

	sf_oaxa(Fwfl,acz,1);
	sf_oaxa(Fwfl,acx,2);
	sf_oaxa(Fwfl,at, 3);
    }

    if(expl) {
	ww = sf_floatalloc( 1);
    } else {
	ww = sf_floatalloc(ns);
    }
    dd = sf_floatalloc(nr);

    /*------------------------------------------------------------*/
    /* setup source/receiver coordinates */
    ss = (pt2d*) sf_alloc(ns,sizeof(*ss)); 
    rr = (pt2d*) sf_alloc(nr,sizeof(*rr)); 

    pt2dread1(Fsou,ss,ns,2); /* read (x,z) coordinates */
    pt2dread1(Frec,rr,nr,2); /* read (x,z) coordinates */

    cs = lint2d_make(ns,ss,fdm);
    cr = lint2d_make(nr,rr,fdm);

    /*------------------------------------------------------------*/
    /* setup FD coefficients */
    idz = 1/dz;
    idx = 1/dx;

    co = C0 * (idx*idx+idz*idz);
    cax= CA *  idx*idx;
    cbx= CB *  idx*idx;
    caz= CA *  idz*idz;
    cbz= CB *  idz*idz;

    /*------------------------------------------------------------*/ 
    tt = sf_floatalloc2(nz,nx); 

    vel = sf_floatalloc2(fdm->nzpad,fdm->nxpad); 
    mag = sf_floatalloc2(fdm->nzpad,fdm->nxpad);
    ele = sf_floatalloc2(fdm->nzpad,fdm->nxpad);
    cdt = sf_floatalloc2(fdm->nzpad,fdm->nxpad); 

    cdtele =sf_floatalloc2(fdm->nzpad,fdm->nxpad);
    magele =sf_floatalloc2(fdm->nzpad,fdm->nxpad);
    /*------------------------------------------------------------*/

    /*------------------------------------------------------------*/
    /* input magnetic susceptibility*/
    sf_floatread(tt[0],nz*nx,Fmag );    expand(tt,mag,fdm);

    /* input electric susceptibility*/
    sf_floatread(tt[0],nz*nx,Fele );    expand(tt,ele,fdm);
    
    /* input conductivity*/
    sf_floatread(tt[0],nz*nx,Fcdt );    expand(tt,cdt,fdm);

    /*------------------------------------------------------------*/
    /* cdtele = sigma*dt/2*epsilon */
    /* magele = dt*dt/mu*epsilon */
    for    (ix=0; ix<fdm->nxpad; ix++) {
	for(iz=0; iz<fdm->nzpad; iz++) {
	    cdtele[ix][iz] = cdt[ix][iz]*dt/(2*(ele[ix][iz]));
	    magele[ix][iz]  = dt*dt/(mag[ix][iz]*ele[ix][iz]);
	    vel[ix][iz] = 1./(sqrt(mag[ix][iz]*ele[ix][iz]));
	}
    }
    if(fsrf) { /* free surface */
	for    (ix=0; ix<fdm->nxpad; ix++) {
	    for(iz=0; iz<fdm->nb; iz++) {
		cdtele[ix][iz]=0;
		magele[ix][iz]=0;
	    }
	}
    }
    /*------------------------------------------------------------*/

    free(*tt); free(tt);    
    /*------------------------------------------------------------*/

    /*------------------------------------------------------------*/
    /* allocate wavefield arrays */
    um=sf_floatalloc2(fdm->nzpad,fdm->nxpad);
    uo=sf_floatalloc2(fdm->nzpad,fdm->nxpad);
    up=sf_floatalloc2(fdm->nzpad,fdm->nxpad);
    ua=sf_floatalloc2(fdm->nzpad,fdm->nxpad);

    for    (ix=0; ix<fdm->nxpad; ix++) {
	for(iz=0; iz<fdm->nzpad; iz++) {
	    um[ix][iz]=0;
	    uo[ix][iz]=0;
	    up[ix][iz]=0;
	    ua[ix][iz]=0;
	}
    }

    /*------------------------------------------------------------*/
    if(dabc) {
	/* one-way abc setup */
	abc = abcone2d_make(NOP,dt,vel,fsrf,fdm);
	/* sponge abc setup */
	spo = sponge_make(fdm->nb);
    }

    /*------------------------------------------------------------*/
    /* 
     *  MAIN LOOP
     */
    /*------------------------------------------------------------*/
    if(verb) fprintf(stderr,"\n");
    for (it=0; it<nt; it++) {
	if(verb) fprintf(stderr,"\b\b\b\b\b%d",it);

#ifdef _OPENMP
#pragma omp parallel for				\
    schedule(dynamic,fdm->ompchunk)			\
    private(ix,iz)					\
    shared(fdm,ua,uo,co,cax,caz,cbx,cbz,idx,idz)
#endif
	for    (ix=NOP; ix<fdm->nxpad-NOP; ix++) {
	    for(iz=NOP; iz<fdm->nzpad-NOP; iz++) {
		
		/* 4th order Laplacian operator */
		ua[ix][iz] = 
		    co * uo[ix  ][iz  ] + 
		    cax*(uo[ix-1][iz  ] + uo[ix+1][iz  ]) +
		    cbx*(uo[ix-2][iz  ] + uo[ix+2][iz  ]) +
		    caz*(uo[ix  ][iz-1] + uo[ix  ][iz+1]) +
		    cbz*(uo[ix  ][iz-2] + uo[ix  ][iz+2]);
		
	    }
	}   

	/* inject acceleration source */
	if(expl) {
	    sf_floatread(ww, 1,Fwav);
	    lint2d_inject1(ua,ww[0],cs);
	} else {
	    sf_floatread(ww,ns,Fwav);	
	    lint2d_inject(ua,ww,cs);
	}

	/* step forward in time */
#ifdef _OPENMP
#pragma omp parallel for	    \
    schedule(dynamic,fdm->ompchunk) \
    private(ix,iz)		    \
    shared(fdm,ua,uo,um,up,cdtele,magele)
#endif
	for    (ix=0; ix<fdm->nxpad; ix++) {
	    for(iz=0; iz<fdm->nzpad; iz++) {
	   	up[ix][iz] = (2*uo[ix][iz] 
			   - (1-cdtele[ix][iz])*um[ix][iz] 
			   + ua[ix][iz]*(magele[ix][iz]))/(1+cdtele[ix][iz]);
	    }
	}
	/* circulate wavefield arrays */
	ut=um;
	um=uo;
	uo=up;
	up=ut;
	
	if(dabc) {
	    /* one-way abc apply */
	    abcone2d_apply(uo,um,NOP,abc,fdm);
	    sponge2d_apply(um,spo,fdm);
	    sponge2d_apply(uo,spo,fdm);
	    sponge2d_apply(up,spo,fdm);
	}

	/* extract data */
	lint2d_extract(uo,dd,cr);

	if(snap && it%jsnap==0) {
	    cut2d(uo,uc,fdm,acz,acx);
	    sf_floatwrite(uc[0],sf_n(acz)*sf_n(acx),Fwfl);
	}
	if(        it%jdata==0) 
	    sf_floatwrite(dd,nr,Fdat);
    }
    if(verb) fprintf(stderr,"\n");    

    /*------------------------------------------------------------*/
    /* deallocate arrays */
    free(*um); free(um);
    free(*up); free(up);
    free(*uo); free(uo);
    free(*ua); free(ua);
    free(*uc); free(uc);

    free(*mag); free(mag);
    free(*ele); free(ele);
    free(*cdt); free(cdt);
    free(*vel); free(vel);  
    free(*cdtele); free(cdtele);
    free(*magele);  free(magele);

    /*------------------------------------------------------------*/
    free(ww);
    free(ss);
    free(rr);
    free(dd);
    /*------------------------------------------------------------*/

    sf_close();
    exit (0);
}