示例#1
0
文件: Mfbank2.c 项目: 1014511134/src
int main(int argc, char*argv[])
{
	sf_file in, out;
	int nf, n1, n2, n3, m, n;
	int i3;
	float **wav, ****fb;
	char *interp;

	sf_init(argc, argv);

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

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

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

	sf_shiftdim2(in,out,2);

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

	nf = m+n+1;

	wav = sf_floatalloc2(n1,n2);
	fb  = sf_floatalloc4(n1, n2, nf, nf);

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


	fbank_init(m, n, interp);


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

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

        float   f0, t, t0, dx, dz, dxf, dzf,dt, dkx, dkz, dt2;
        int     mm, nvx, nvz, ns;
        int     hnkx, hnkz, nkx, nkz, nxz, nkxz;
        int     hnkx1, hnkz1, 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 **apx, **apz, **apxx, **apzz;        /* polarization operator of P-wave for a location */
        float **apxs, **apzs, **apxxs, **apzzs;    /* polarization operator of SV-wave for a location */

        float ****ex, ****ez;                      /* operator for whole model for P-wave*/
        float ****exs, ****ezs;                    /* operator for whole model for SV-wave*/
        float **exx, **ezz;                        /* operator for constant model for P-wave*/
        float **exxs, **ezzs;                      /* operator for constant model for SV-wave*/

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

        float *kx, *kz, *kkx, *kkz, *kx2, *kz2, **taper;

        clock_t t1, t2, t3, t4;
        float   timespent; 
        float   A, fx, fz;

        int     isep=1;
        int     ihomo=1;

        char    *tapertype;

	double  vp2, vs2, ep2, de2, the;

        sf_init(argc,argv);

        sf_file Fo1, Fo2, Fo3, Fo4, Fo5, Fo6, Fo7, Fo8, Fo9, Fo10, Fo11, Fo12;
       
        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 */
        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);	

        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] *= PI/180.0;

        t2=clock();

        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);

        /*****************************************************************************
         *  Calculating polarization operator for wave-mode separation
         * ***************************************************************************/
        if(isep==1)
        {
           sf_warning("==================================================");
           sf_warning("==      Calculating Polarization Operator       ==");
           sf_warning("==================================================");
           /* 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*PI/dx/nkx;
           dkz=2*PI/dz/nkz;
	   kxmax=PI/dx;
	   kzmax=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);

           nkxz=nkx*nkz;

           /* truncation of spatial filter */
           if(ihomo==1)
           {
              exx=sf_floatalloc2(nkz1, nkx1);
              ezz=sf_floatalloc2(nkz1, nkx1);
              exxs=sf_floatalloc2(nkz1, nkx1);
              ezzs=sf_floatalloc2(nkz1, nkx1);
           }else{
	      ex=sf_floatalloc4(nkz1, nkx1, nz, nx);
	      ez=sf_floatalloc4(nkz1, nkx1, nz, nx);
	      exs=sf_floatalloc4(nkz1, nkx1, nz, nx);
	      ezs=sf_floatalloc4(nkz1, nkx1, nz, nx);
           }
           /*****************************************************************************
           *  Calculating polarization operator for wave-mode separation
           * ***************************************************************************/
	    apx=sf_floatalloc2(nkz, nkx);
	    apz=sf_floatalloc2(nkz, nkx);

	    apxs=sf_floatalloc2(nkz, nkx);
	    apzs=sf_floatalloc2(nkz, nkx);

	    apxx=sf_floatalloc2(nkz, nkx);
	    apzz=sf_floatalloc2(nkz, nkx);

	    apxxs=sf_floatalloc2(nkz, nkx);
	    apzzs=sf_floatalloc2(nkz, nkx);

            /* setup I/O files for wavenumber-domain operators */
            Fo3 = sf_output("apx"); /*  P-wave's polarization x-comp */
            Fo4 = sf_output("apz"); /*  P-wave's polarization z-comp */
            Fo5 = sf_output("apxs"); /*  SV-wave's polarization x-comp */
            Fo6 = sf_output("apzs"); /*  SV-wave's polarization z-comp */

            puthead1(Fo3, nkz, nkx, dkz, -kzmax, dkx, -kxmax);
            puthead1(Fo4, nkz, nkx, dkz, -kzmax, dkx, -kxmax);
            puthead1(Fo5, nkz, nkx, dkz, -kzmax, dkx, -kxmax);
            puthead1(Fo6, nkz, nkx, dkz, -kzmax, dkx, -kxmax);
 
            /* setup I/O files for space-domain operators */
            Fo7 = sf_output("apxx");  /* P-wave's polarization x-comp in (x,z) domain */
            Fo8 = sf_output("apzz");  /* P-wave's polarization z-comp in (x,z) domain */
            Fo9 = sf_output("apxxs"); /* SV-wave's polarization x-comp in (x,z) domain */
            Fo10 = sf_output("apzzs"); /* SV-wave's polarization z-comp in (x,z) domain */

            puthead2(Fo7, nkz, nkx, dz/1000.0, 0.0, dx/1000.0, 0.0);
            puthead2(Fo8, nkz, nkx, dz/1000.0, 0.0, dx/1000.0, 0.0);
            puthead2(Fo9, nkz, nkx, dz/1000.0, 0.0, dx/1000.0, 0.0);
            puthead2(Fo10, 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 operrate with tapering **********/
                zero2float(apx, nkz, nkx);
                zero2float(apz, nkz, nkx);
                zero2float(apxs, nkz, nkx);
                zero2float(apzs, nkz, nkx);
               
                /* polvtipsv: P- and SV-wave polarization operators in VTI media  */
                itaper=1;
                polttipsv(apx,apz,apxs,apzs,kx,kz,kkx,kkz,taper,hnkx,hnkz,dkx,dkz,
                          vp2,vs2,ep2,de2,the,itaper);

                ikxkz2xz(apx, apxx, hnkx, hnkz, nkx, nkz);
                ikxkz2xz(apz, apzz, hnkx, hnkz, nkx, nkz);
                ikxkz2xz(apxs, apxxs, hnkx, hnkz, nkx, nkz);
                ikxkz2xz(apzs, apzzs, 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]=apxx[ixx][izz]; 
                     ezz[jx+hnkx1][jz+hnkz1]=apzz[ixx][izz]; 
                     exxs[jx+hnkx1][jz+hnkz1]=apxxs[ixx][izz]; 
                     ezzs[jx+hnkx1][jz+hnkz1]=apzzs[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]=apxx[ixx][izz]; 
                     ez[ixf][izf][jx+hnkx1][jz+hnkz1]=apzz[ixx][izz]; 
                     exs[ixf][izf][jx+hnkx1][jz+hnkz1]=apxxs[ixx][izz]; 
                     ezs[ixf][izf][jx+hnkx1][jz+hnkz1]=apzzs[ixx][izz]; 
                   }
                }
                
                if((ixf==nxf/2&&izf==nzf/2&&ihomo==0)||ihomo==1)
                {
                   //write-disk operators in kx-kz domain
	           sf_floatwrite(apx[0], nkxz, Fo3);
	           sf_floatwrite(apz[0], nkxz, Fo4);
	           sf_floatwrite(apxs[0], nkxz, Fo5);
	           sf_floatwrite(apzs[0], nkxz, Fo6);

                   //write-disk operators in x-z domain
	           sf_floatwrite(apxx[0], nkxz, Fo7);
	           sf_floatwrite(apzz[0], nkxz, Fo8);
	           sf_floatwrite(apxxs[0], nkxz, Fo9);
	           sf_floatwrite(apzzs[0], nkxz, Fo10);
                }
                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(*apx);
           free(*apz);
           free(*apxs);
           free(*apzs);
           free(*apxx);
           free(*apzz);
           free(*apxxs);
           free(*apzzs);
        }// isep loop
	/****************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****************/
	/****************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);

        if(isep==1)
        {
            Fo11 = sf_output("ElasticSepP"); /*  scalar wavefield using P-wave's polarization projection oprtator*/
            Fo12 = sf_output("ElasticSepSV"); /*  scalar wavefield using SV-wave's polarization projection oprtator*/

            puthead3(Fo11, nz, nx, 1, dz/1000.0, dx/1000.0, dt, fz/1000.0, fx/1000.0, 0.0);
            puthead3(Fo12, nz, nx, 1, dz/1000.0, dx/1000.0, dt, fz/1000.0, fx/1000.0, 0.0);

	   p3c=sf_floatalloc2(nz,nx);
	   q3c=sf_floatalloc2(nz,nx);
           sum=sf_floatalloc2(nz,nx);

        }

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

                       
                     if(isep==1)
                     {
                        //////////////////////////////////////////////////////////////////////////////////////////
                        /* applying P-wave polarization projection operator in spatial domain */
	                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, Fo11);
          
                        //////////////////////////////////////////////////////////////////////////////////////////
                        /* applying SV-wave polarization projection operator in spatial domain */
	                zero2float(p3c,nz,nx);
	                zero2float(q3c,nz,nx);
                        zero2float(sum, nz, nx);

                        if(ihomo==1)
                            filter2dsepglobal(p3, q3, p3c, q3c, exxs, ezzs, nx, nz, hnkx1, hnkz1);
                        else
                            filter2dsep(p3, q3, p3c, q3c, exs, ezs, 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, Fo12);
                     }// isep==1

                }/* (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 */
        t4=clock();
        timespent=(float)(t4-t3)/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);
              free(*exxs);
              free(*ezzs);
          }else{
              free(***ex);
              free(***ez);
              free(***exs);
              free(***ezs);
          }
        }

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

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

	exit(0);
}
示例#3
0
文件: Mhic2ang.c 项目: 1014511134/src
int main(int argc, char* argv[])
{
    bool verb;
    bool  adj;
    bool anis;
    sf_file Fcip=NULL;	/*   lag-domain CIPs */
    sf_file Fang=NULL;	/* angle-domain CIPs */
    sf_file Fvel=NULL;  /*   velocity @ CIPs */
    sf_file Fnor=NULL;	/*    normals @ CIPs */
    sf_file Ftlt=NULL;	/*       tilt @ CIPs */
    sf_file Fani=NULL;  /* anisotropy @ CIPs */

    sf_axis ahx,ahy,ahz,aht,ac,ath,aph,aps,aj;
    int     ihx,ihy,ihz,iht,ic,ith,iph;

    
    /* angle parameters */
    int   nth,nph,nps,nhx,nhy,nhz,nht;
    float oth,oph,ops,ohx,ohy,ohz,oht;
    float dth,dph,dps,dhx,dhy,dhz,dht;
    float phi;
    float tht;
    float psi;
    float v_s,v_r;
    float cosum,codif,sitovel;

    /*  arrays                  1   2   3   4  */
    float     ****cip;      /* nhx-nhy-nhz-nht */
    float       **ang;      /* nph-nth         */
    float        *vep;      /* nc              */
    float        *ves;      /* nc              */
    float        *eps=NULL; /* nc              */
    float        *dlt=NULL; /* nc              */

    vc3d           vv;      /* azimuth reference vector */
    vc3d          *nn;      /* normal vectors  */
    vc3d          *tt=NULL; /*   tilt vectors  */
    vc3d          *aa;      /* in-plane reference vector */
    vc3d           qq;
    vc3d           jk;      /* temp vector */
    float    hx,hy,hz;

    float tau; /* time lag */
    int   jht; /* tau axis index */
    float fht; /* tau axis weight */

    float ssn; /* slant-stack normalization */

    float *ttipar;
    /*-----------------------------------------------------------------*/
    /* init RSF */
    sf_init(argc,argv);    
    
#ifdef _OPENMP
    omp_init(); /* OMP parameters */
#endif

    if(! sf_getbool("verb",&verb)) verb=false;	/* verbosity flag */
    if(! sf_getbool("anis",&anis)) anis=false;	/* anisotropy flag */
    if(! sf_getbool("adj", &adj))   adj=true;	/* adj flag */    
    /* 
     * ADJ: cip to ang
     * FOR: ang to cip
     */

    sf_warning("verb=%d",verb);
    sf_warning("anis=%d",anis);

    /* select anisotropy model */
    if(anis) sf_warning("ANI model");
    else     sf_warning("ISO model");

    if(adj) {
	Fcip=sf_input ( "in"); /* CIP file */
	Fang=sf_output("out"); /* ANG file */
    } else {
	Fcip=sf_output("out"); /* CIP file */
	Fang=sf_input ("in");  /* ANG file */
    }
    Fvel=sf_input ("vel");     /* velocity file  */
    Fnor=sf_input ("nor");     /* normal vectors */
    if(anis) {
	Ftlt=sf_input ("tlt"); /*   tilt vectors */
	Fani=sf_input ("ani"); /*     anisotropy */
    }

    aj  = sf_maxa(1,0,1);

    if(adj) {
	/* input axes */
	ahx = sf_iaxa(Fcip,1); sf_setlabel(ahx,"hx");
	ahy = sf_iaxa(Fcip,2); sf_setlabel(ahy,"hy");
	ahz = sf_iaxa(Fcip,3); sf_setlabel(ahz,"hz");
	aht = sf_iaxa(Fcip,4); sf_setlabel(aht,"ht");

	/* CIP axis */
	ac  = sf_iaxa(Fcip,5); sf_setlabel(ac ,"c ");
		
	/* reflection angle */
	if(! sf_getint  ("nth",&nth)) nth=90;
	if(! sf_getfloat("oth",&oth)) oth=0;
	if(! sf_getfloat("dth",&dth)) dth=1.;
	ath = sf_maxa(nth,oth,dth);
	sf_setlabel(ath,"th");
	sf_setunit (ath,"deg");
	
	/* azimuth angle */
	if(! sf_getint  ("nph",&nph)) nph=360;
	if(! sf_getfloat("oph",&oph)) oph=-180;
	if(! sf_getfloat("dph",&dph)) dph=1.;
	aph = sf_maxa(nph,oph,dph);
	sf_setlabel(aph,"ph");
	sf_setunit (aph,"deg");

	/* output axes */
	sf_oaxa(Fang,ath,1);
	sf_oaxa(Fang,aph,2);
	sf_oaxa(Fang,ac ,3);
	sf_oaxa(Fang,aj ,4);
	sf_oaxa(Fang,aj ,5);

    } else {

	/* lag in x */
	if(! sf_getint  ("nhx",&nhx)) nhx=1;
	if(! sf_getfloat("ohx",&ohx)) ohx=0;
	if(! sf_getfloat("dhx",&dhx)) dhx=1.;
	ahx = sf_maxa(nhx,ohx,dhx);
	sf_setlabel(ahx,"hx");
	sf_setunit (ahx,"");

	/* lag in y */
	if(! sf_getint  ("nhy",&nhy)) nhy=1;
	if(! sf_getfloat("ohy",&ohy)) ohy=0;
	if(! sf_getfloat("dhy",&dhy)) dhy=1.;
	ahy = sf_maxa(nhy,ohy,dhy);
	sf_setlabel(ahy,"hy");
	sf_setunit (ahy,"");

	/* lag in z */
	nhz=1;
	ohz=0.;
	dhz=1.;
	ahz = sf_maxa(nhz,ohz,dhz);
	sf_setlabel(ahz,"hz");
	sf_setunit (ahz,"");

	/* lag in t */
	if(! sf_getint  ("nht",&nht)) nht=1;
	if(! sf_getfloat("oht",&oht)) oht=0.;
	if(! sf_getfloat("dht",&dht)) dht=1.;
	aht = sf_maxa(nht,oht,dht);
	sf_setlabel(aht,"ht");
	sf_setunit (aht,"");

	/* reflection angle */
	ath = sf_iaxa(Fang,1); sf_setlabel(ath,"th");
	/* azimuth angle */
	aph = sf_iaxa(Fang,2); sf_setlabel(aph,"ph");
	/* CIP axis */
	ac  = sf_iaxa(Fang,3); sf_setlabel(ac ,"c ");

	/* output axes */
	sf_oaxa(Fcip,ahx,1);
	sf_oaxa(Fcip,ahy,2);
	sf_oaxa(Fcip,ahz,3);
	sf_oaxa(Fcip,aht,4);
	sf_oaxa(Fcip,ac ,5);
    }

    if (verb){
	sf_raxa(ahx);
	sf_raxa(ahy);
	sf_raxa(ahz);
	sf_raxa(aht);
	sf_raxa(ac);
	sf_raxa(ath);
	sf_raxa(aph);
    }

    if(anis) {
	/* deviation angle */
	if(! sf_getint  ("nps",&nps)) nps=251;
	if(! sf_getfloat("ops",&ops)) ops=-25;
	if(! sf_getfloat("dps",&dps)) dps=0.2;
	aps = sf_maxa(nps,ops,dps);
	sf_setlabel(aps,"ps");
	sf_setunit (aps,"deg");

	if(verb) sf_raxa(aps);
    } else {
	aps = NULL;
    }

    /*------------------------------------------------------------*/
    /* allocate arrays */
    cip = sf_floatalloc4  (sf_n(ahx),sf_n(ahy),sf_n(ahz),sf_n(aht));
    ang = sf_floatalloc2  (sf_n(ath),sf_n(aph));

    /* read velocity */
    vep = sf_floatalloc  (sf_n(ac));    
    sf_floatread(vep,sf_n(ac),Fvel);

    ves = sf_floatalloc  (sf_n(ac));    
    sf_floatread(ves,sf_n(ac),Fvel);
	
    /*------------------------------------------------------------*/
    /* read normals */
    nn  = (vc3d*) sf_alloc(sf_n(ac),sizeof(*nn)); /* normals  */
    vc3dread1(Fnor,nn,sf_n(ac));

    if(anis) {
	/* read anisotropy */
	eps = sf_floatalloc   (sf_n(ac));
	sf_floatread(eps,sf_n(ac),Fani);

	dlt = sf_floatalloc   (sf_n(ac));
	sf_floatread(dlt,sf_n(ac),Fani);

	/* read tilts */	
	tt  = (vc3d*) sf_alloc(sf_n(ac),sizeof(*tt));
	vc3dread1(Ftlt,tt,sf_n(ac));
    }

    /*------------------------------------------------------------*/
    /* in-plane azimuth reference */
    vv.dx=1;
    vv.dy=0;
    vv.dz=0;

    aa  = (vc3d*) sf_alloc(sf_n(ac),sizeof(*aa));
    for(ic=0;ic<sf_n(ac);ic++) {
	jk    =vcp3d(&nn[ic],&vv);
	aa[ic]=vcp3d(&jk,&nn[ic]);
    }

    /*------------------------------------------------------------*/
    ssn = 1./sqrt(sf_n(ahx)*sf_n(ahy)*sf_n(ahz));

    /*------------------------------------------------------------*/
    /* loop over CIPs */
/*    if(verb) fprintf(stderr,"ic\n");*/
    for(ic=0;ic<sf_n(ac);ic++) {
/*	if(verb) fprintf(stderr,"\b\b\b\b\b%d",ic);*/

	if(adj) {

	    /* read CIP */
	    sf_floatread(cip[0][0][0],sf_n(ahx)*sf_n(ahy)*sf_n(ahz)*sf_n(aht),Fcip);
	    
	    /* init ANG */
	    for    (iph=0;iph<sf_n(aph);iph++) {
		for(ith=0;ith<sf_n(ath);ith++) {
		    ang[iph][ith]=0;
		}
	    }
	} else {
	    
	    /* init CIP */
	    for            (iht=0;iht<sf_n(aht);iht++) {
		for        (ihz=0;ihz<sf_n(ahz);ihz++) {
		    for    (ihy=0;ihy<sf_n(ahy);ihy++) {
			for(ihx=0;ihx<sf_n(ahx);ihx++) {
			    cip[iht][ihz][ihy][ihx]=0;
			}
		    }
		}
	    }

	    /* read ANG */
	    sf_floatread(ang[0],sf_n(ath)*sf_n(aph),Fang);
	}

	/* phi loop */

	nph = sf_n(aph);

#ifdef _OPENMP
#pragma omp parallel for schedule(static)				\
    private(iph,phi,jk,qq,						\
	    ith,tht,							\
	    ihy,ihx,hy,hx,hz,						\
	    tau,jht,fht,cosum,codif,v_s,v_r,psi,sitovel)	\
    shared( nph,aph,ath,aps,ahy,ahx,aht,cip,ang,vep,ves,eps,dlt)
#endif
	for(iph=0;iph<nph;iph++) {
	    phi=(180+sf_o(aph)+iph*sf_d(aph))/180.*SF_PI;
	    /* use '180' to reverse illumination direction: */
	    /* at a CIP, look toward the source */

	    /* reflection azimuth vector */
	    jk = rot3d(nn,aa,phi);
	    qq = nor3d(&jk);
	    
	    /* theta loop */
	    for(ith=0;ith<sf_n(ath);ith++) {
		tht=(sf_o(ath)+ith*sf_d(ath))/180.*SF_PI;
		
		if(anis) {

		    ttipar = psitti(nn,&qq,tt,aa,
				    tht,phi,aps,
				    vep[ic],ves[ic],eps[ic],dlt[ic]);
		    psi = ttipar[0];
		    v_s = ttipar[1];
		    v_r = ttipar[2];

		    psi *= SF_PI/180.;
                    cosum = cosf(tht+psi);
                    codif = cosf(tht-psi);

                    sitovel = sinf(2*tht)/(v_s*cosum + v_r*codif);
		} else {
		    sitovel = sinf(tht)/vep[ic];
		}

		/* lag loops */
		if(adj) {
		    for    (ihy=0;ihy<sf_n(ahy);ihy++) { hy=sf_o(ahy)+ihy*sf_d(ahy);
			for(ihx=0;ihx<sf_n(ahx);ihx++) { hx=sf_o(ahx)+ihx*sf_d(ahx);
 
			    hz = -(hx*(nn[ic].dx)+hy*(nn[ic].dy))/(nn[ic].dz);
			    tau = -((qq.dx)*hx+(qq.dy)*hy+(qq.dz)*hz)*sitovel;			    
			    jht=0.5+(tau-sf_o(aht))/sf_d(aht);

			    if(jht>=0 && jht<sf_n(aht)-1) {
				fht= (tau-sf_o(aht))/sf_d(aht)-jht;
				ang[iph][ith] += (1-fht)*ssn*cip[jht  ][0][ihy][ihx]
				    +               fht *ssn*cip[jht+1][0][ihy][ihx]; 
			    }
			    
			} /* hx */
		    } /* hy */
		} else {
		    for    (ihy=0;ihy<sf_n(ahy);ihy++) { hy=sf_o(ahy)+ihy*sf_d(ahy);
			for(ihx=0;ihx<sf_n(ahx);ihx++) { hx=sf_o(ahx)+ihx*sf_d(ahx);
		    
			    hz = -(hx*(nn[ic].dx)+hy*(nn[ic].dx))/(nn[ic].dz);
			    tau = -((qq.dx)*hx+(qq.dy)*hy+(qq.dz)*hz)*sitovel; 		    
			    jht=0.5+(tau-sf_o(aht))/sf_d(aht);

			    if(jht>=0 && jht<sf_n(aht)-1) {
				fht= (tau-sf_o(aht))/sf_d(aht)-jht;
				cip[jht  ][0][ihy][ihx] += (1-fht)*ssn*ang[iph][ith];
				cip[jht+1][0][ihy][ihx] +=    fht *ssn*ang[iph][ith];
			    }
			    
			} /* hx */
		    } /* hy */
		}

	    } /* th */
	} /* ph */
	
	if(adj) {
	    /* write ANG */
	    sf_floatwrite(ang[0],sf_n(ath)*sf_n(aph),Fang);
	} else {
	    /* write CIP */
	    sf_floatwrite(cip[0][0][0],sf_n(ahx)*sf_n(ahy)*sf_n(ahz)*sf_n(aht),Fcip);
	}

    }
    if(verb) fprintf(stderr,"\n");
    /*------------------------------------------------------------*/
 
    /*------------------------------------------------------------*/
    if(verb) fprintf(stderr,"free memory...");
    free(***cip);free(**cip);free(*cip);free(cip);
    ;                        free(*ang);free(ang);
    ;                                   free(vep);
    ;                                   free (nn);
    ;                                   free (aa);
    if(anis) {
	free(ves);
	free(eps);
	free(dlt);
	free(tt);
    }
    if(verb) fprintf(stderr,"OK\n");
    /*------------------------------------------------------------*/

    exit(0);
}		
示例#4
0
文件: cam3.c 项目: 1014511134/src
/*------------------------------------------------------------*/
cam3d cam3_init(cub3d cub,
		int pmx,
		int pmy,
		int phx,
		int tmx,
		int tmy,
		int thx,
		float dsmax
    )
/*< initialize >*/
{
    int   imy, imx, ihx;
    float      kmx, khx;
    int        jmx, jhx;

    int   ilx, ily;

    float  my,  mx,  hx,    k;

    /*------------------------------------------------------------*/
    cam3d cam;
    cam = (cam3d) sf_alloc(1,sizeof(*cam));

    X2K(cub->amx,cam->bmx,pmx);
    X2K(cub->amy,cam->bmy,pmy);
    X2K(cub->ahx,cam->bhx,phx);

    /* allocate K-domain storage */
    cam->wk = sf_complexalloc4 (cam->bmx.n,cam->bmy.n,cam->bhx.n,cub->ompnth);
    cam->pk = sf_complexalloc4 (cam->bmx.n,cam->bmy.n,cam->bhx.n,cub->ompnth);

    /* allocate X-domain storage */
    cam->wt = sf_floatalloc4   (cub->amx.n,cub->amy.n,cub->ahx.n,cub->ompnth);

    cam->ksx = sf_floatalloc2(cam->bmx.n,cam->bhx.n);
    cam->krx = sf_floatalloc2(cam->bmx.n,cam->bhx.n);
    for (imx=0; imx<cam->bmx.n; imx++) {
	jmx = KMAP(imx,cam->bmx.n);
	kmx = cam->bmx.o + jmx*cam->bmx.d;
	
	for (ihx=0; ihx<cam->bhx.n; ihx++) {
	    jhx = KMAP(ihx,cam->bhx.n);
	    khx = cam->bhx.o + jhx*cam->bhx.d;
	    
	    k = 0.5*(kmx-khx);
	    cam->ksx[ihx][imx] = k*k; /* ksx^2 */
	    
	    k = 0.5*(kmx+khx);
	    cam->krx[ihx][imx] = k*k; /* krx^2 */
	}
    }

    /* precompute indices */
    cam->jx = sf_intalloc(cub->amx.n);
    cam->jy = sf_intalloc(cub->amy.n);
    cam->is = sf_intalloc2(cub->amx.n,cub->ahx.n);  /* source   index */
    cam->ir = sf_intalloc2(cub->amx.n,cub->ahx.n);  /* receiver index */

    for (imy=0; imy<cub->amy.n; imy++) {
	my = cub->amy.o + imy*cub->amy.d;
	ily          = INDEX( my,cub->aly);
	cam->jy[imy] = BOUND(ily,cub->aly.n);            /* x-line index */
    }
    for (imx=0; imx<cub->amx.n; imx++) {
	mx = cub->amx.o + imx*cub->amx.d;
	ilx          = INDEX( mx,cub->alx);
	cam->jx[imx] = BOUND(ilx,cub->alx.n);            /* i-line index */
	
	for (ihx=0; ihx<cub->ahx.n; ihx++) {
	    hx = cub->ahx.o + ihx*cub->ahx.d;
	    
	    ilx               = INDEX(mx-hx,cub->alx);
	    cam->is[ihx][imx] = BOUND(  ilx,cub->alx.n); /* source index */
	    
	    ilx               = INDEX(mx+hx,cub->alx);
	    cam->ir[ihx][imx] = BOUND(  ilx,cub->alx.n); /* receiver index */
	}
    }

    /* initialize FFT */
    cam->f3d = ompfft3_init(cub,cam->bmx.n,cam->bmy.n,cam->bhx.n);
    
    cam->dsmax2 = dsmax*dsmax;
    cam->dsmax2*= cam->dsmax2;

    return cam;
}
示例#5
0
文件: Mescrt3.c 项目: 1014511134/src
int main (int argc, char* argv[]) {
    int nz, nx, ny, nb, na, ib, ia, iz, ix, iy, i, it, nt, ic, nc = 1, fz, lz, itr = 0;
    float dz, oz, dx, ox, dy, oy, db, ob, da, oa, z, x, y, a, dt, df, md, aper;
    float ****e;
    sf_file spdom, vspline = NULL, out, traj = NULL;
    sf_escrt3_traj_cbud *tdata = NULL; 
    char *ext = NULL;
    bool verb, parab;
    sf_esc_slowness3 esc_slow;
    sf_esc_tracer3 *esc_tracers;
    sf_esc_point3 *esc_points;
    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");
    }
    ext = sf_escrt3_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;

    if (!sf_getfloat ("df", &df)) df = 0.1;
    /*< Maximum distance to travel per step (fraction of the cell size) >*/

    if (!sf_getfloat ("md", &md)) md = SF_HUGE;
    /* Maximum distance for a ray to travel (default - up to model boundaries) */
    if (md != SF_HUGE)
        md = fabsf (md);

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

#ifdef _OPENMP
    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 ());
#endif

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

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

    if (sf_getstring ("traj")) {
        /* Trajectory output */
        traj = sf_output ("traj");
        if (!sf_getint ("nt", &nt)) nt = 1001;
        /* Number of time samples for each trajectory */
        if (!sf_getfloat ("dt", &dt)) dt = 0.001;
        /* Time sampling */
        tdata = (sf_escrt3_traj_cbud*)sf_alloc (nc*na*nb, sizeof(sf_escrt3_traj_cbud));
        for (itr = 0; itr < nc*na*nb; itr++) {
            tdata[itr].it = 0;
            tdata[itr].nt = nt;
            tdata[itr].dt = dt;
            tdata[itr].pnts = sf_floatalloc2 (TRAJ3_COMPS - 1, nt);
        }
    }

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

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

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

    if (traj) {
        if (spdom)
            sf_shiftdimn (spdom, traj, 1, 4);
        sf_putint (traj, "n1", TRAJ3_COMPS - 1);
        sf_putfloat (traj, "o1", 0.0);
        sf_putfloat (traj, "d1", 1.0);
        sf_putstring (traj, "label1", "Escape variable");
        sf_putstring (traj, "unit1", "");
        sf_putint (traj, "n2", nt);
        sf_putfloat (traj, "o2", 0.0);
        sf_putfloat (traj, "d2", dt);
        sf_putstring (traj, "label2", "Time");
        sf_putstring (traj, "unit2", "s");
        sf_putint (traj, "n3", nb);
        sf_putfloat (traj, "d3", db*180.0/SF_PI);
        sf_putfloat (traj, "o3", ob*180.0/SF_PI);
        sf_putstring (traj, "label3", "Inclination");
        sf_putstring (traj, "unit3", "Degrees");
        sf_putint (traj, "n4", na);
        sf_putfloat (traj, "d4", da*180.0/SF_PI);
        sf_putfloat (traj, "o4", oa*180.0/SF_PI);
        sf_putstring (traj, "label4", "Azimuth");
        sf_putstring (traj, "unit4", "Degrees");
        
        sf_putint (traj, "n5", nz);
        sf_putfloat (traj, "o5", oz);
        sf_putfloat (traj, "d5", dz);
        if (!spdom) {
            sf_putstring (traj, "label5", "Depth");
            sf_putstring (traj, "unit5", "");
        }
        sf_putint (traj, "n6", nx);
        sf_putfloat (traj, "o6", ox);
        sf_putfloat (traj, "d6", dx);
        if (!spdom) {
            sf_putstring (traj, "label6", "X");
            sf_putstring (traj, "unit6", "");
        }
        sf_putint (traj, "n7", ny);
        sf_putfloat (traj, "o7", oy);
        sf_putfloat (traj, "d7", dy);
        if (!spdom) {
            sf_putstring (traj, "label7", "Y");
            sf_putstring (traj, "unit7", "");
        }
    }

    esc_tracers = (sf_esc_tracer3*)sf_alloc (nc, sizeof(sf_esc_tracer3));
    esc_points = (sf_esc_point3*)sf_alloc (nc, sizeof(sf_esc_point3));
    for (ic = 0; ic < nc; ic++) {
        esc_tracers[ic] = sf_esc_tracer3_init (esc_slow);
        sf_esc_tracer3_set_parab (esc_tracers[ic], parab);
        if (md != SF_HUGE)
            sf_esc_tracer3_set_mdist (esc_tracers[ic], md);
        sf_esc_tracer3_set_df (esc_tracers[ic], df);
        esc_points[ic] = sf_esc_point3_init ();
    }

    timer = sf_timer_init ();
    /* Ray tracing loop */
    for (iy = 0; iy < ny; iy++) {
        y = oy + iy*dy;
        /* Set aperture */
        if (aper != SF_HUGE) {
            for (ic = 0; ic < nc; ic++) {
                sf_esc_tracer3_set_ymin (esc_tracers[ic], y - aper);
                sf_esc_tracer3_set_ymax (esc_tracers[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_tracer3_set_xmin (esc_tracers[ic], x - aper);
                    sf_esc_tracer3_set_xmax (esc_tracers[ic], x + aper);
                }
            }
            if (verb)
                sf_warning ("%s Shooting 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/nc + ((nz % nc) != 0)); ic++) {
                fz = ic*nc;
                lz = (ic + 1)*nc - 1;
                if (lz >= nz)
                    lz = nz - 1;
                sf_timer_start (timer);
#ifdef _OPENMP
#pragma omp parallel for                       \
                schedule(static,1)             \
                private(iz,ia,ib,a,z,it,i,itr) \
                shared(fz,lz,iy,ix,nb,na,nz,nx,ny,ob,oa,oz,ox,oy,db,da,dz,dx,dy,x,y,tdata,esc_tracers,esc_points,e,out,traj)
#endif
                for (iz = fz; iz <= lz; iz++) {
                    z = oz + iz*dz;
                    for (ia = 0; ia < na; ia++) {
                        a = oa + ia*da;
                        for (ib = 0; ib < nb; ib++) {
                            if (traj) {
                                itr = (iz - fz)*na*nb + ia*nb + ib;
                                sf_esc_tracer3_set_trajcb (esc_tracers[iz - fz], sf_escrt3_traj, dt,
                                                           (void*)&tdata[itr]);
                            }
                            sf_esc_tracer3_compute (esc_tracers[iz - fz], z, x, y, ob + ib*db, a,
                                                    0.0, 0.0, esc_points[iz - fz], NULL, NULL);
                            /* Copy escape values to the output buffer */
                            for (i = 0; i < ESC3_NUM; i++)
                                e[iz - fz][ia][ib][i] = sf_esc_point3_get_esc_var (esc_points[iz - fz], i);
                            if (traj) {
                                /* Fill the rest of the trajectory with the last point */
                                for (it = tdata[itr].it + 1; it < tdata[itr].nt; it++) {
                                    for (i = 0; i < TRAJ3_COMPS - 1; i++)
                                        tdata[itr].pnts[it][i] = tdata[itr].pnts[tdata[itr].it][i];
                                }
                            }
                        } /* Loop over b */
                    } /* Loop over a */
                } /* 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);
                if (tdata) {
                    for (itr = 0; itr < (lz - fz + 1)*na*nb; itr++) {
                        sf_floatwrite (tdata[itr].pnts[0],
                                       (size_t)tdata[itr].nt*(size_t)(TRAJ3_COMPS - 1), traj);
                    }
                }
            } /* 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_point3_close (esc_points[ic]);
        sf_esc_tracer3_close (esc_tracers[ic]);
    }
    free (esc_points);
    free (esc_tracers);
    if (traj) {
        for (itr = 0; itr < nc*na*nb; itr++) {
            free (tdata[itr].pnts[0]);
            free (tdata[itr].pnts);
        }
        free (tdata);
    }
    sf_esc_slowness3_close (esc_slow);

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

    sf_fileclose (vspline);
    if (traj)
        sf_fileclose (traj);

    return 0;
}
示例#6
0
文件: Mescst3.c 项目: 1014511134/src
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;
}
示例#7
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);
}
示例#8
0
int main(int argc, char* argv[])
{
    bool verb,isreversed;

    sf_file Fs,Fr,Fi,Fc;        /* I/O files */
    sf_axis az,ax,at,ac,aa;     /* cube axes */
    int     nz,nx,nt, nhx,  nhz, nht,nc;
    int           it, ihx,  ihz, iht,ic;
    int               nhx2,nhz2,nht2;
    off_t iseek;

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

    pt2d *cc=NULL;
    bool *ccin=NULL;
    float cxmin,czmin;
    float cxmax,czmax;
    int  icx, icz;
    int  mcx, mcz, mct;
    int  pcx, pcz, pct;

    int **mcxall, **pcxall;
    int **mczall, **pczall;
    int  *mctall,  *pctall;
    int lht;

    float scale;

    /* gaussian taper */
    bool gaus;
    float gsx,gsz,gst; /* std dev */
    float  gx, gz, gt;

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

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

    if(! sf_getbool("verb",&verb)) verb=false; /* verbosity flag */
    if(! sf_getbool("isreversed",&isreversed)) isreversed=false; /* reversed rec wfld? */
    
    Fs = sf_input ("in" ); /*   source wavefield */
    Fr = sf_input ("ur" ); /* receiver wavefield */
    Fc = sf_input ("cc" ); /* CIP coordinates    */
    Fi = sf_output("out"); /* image */

    /*------------------------------------------------------------*/
    /* read axes */
    az=sf_iaxa(Fs,1); nz = sf_n(az);
    ax=sf_iaxa(Fs,2); nx = sf_n(ax);
    at=sf_iaxa(Fs,3); nt = sf_n(at);

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

    if(! sf_getint("nhz",&nhz)) nhz=0; nhz2=2*nhz+1; /* z lags */
    if(! sf_getint("nhx",&nhx)) nhx=0; nhx2=2*nhx+1; /* x lags */
    if(! sf_getint("nht",&nht)) nht=0; nht2=2*nht+1; /* t lags */

    lht=2*nht;

    if(verb) {
	sf_warning("nhx=%3d nhz=%3d nht=%3d",nhx2,nhz2,nht2);

	sf_raxa(az);
	sf_raxa(ax);
	sf_raxa(at);
	sf_raxa(ac);
    }

    /* set output axes */
    aa=sf_maxa(nhz2,-nhz*sf_d(az),sf_d(az));
    sf_setlabel(aa,"hz"); sf_setunit(aa,"");
    if(verb) sf_raxa(aa);
    sf_oaxa(Fi,aa,1);
    
    aa=sf_maxa(nhx2,-nhx*sf_d(ax),sf_d(ax)); 
    sf_setlabel(aa,"hx"); sf_setunit(aa,"");
    if(verb) sf_raxa(aa);
    sf_oaxa(Fi,aa,2);

    aa=sf_maxa(nht2,-nht*sf_d(at),sf_d(at));
    sf_setlabel(aa,"ht"); sf_setunit(aa,"");
    if(verb) sf_raxa(aa);
    sf_oaxa(Fi,aa,3);

    sf_oaxa(Fi,ac,4);

    if(! sf_getbool("gaus",&gaus)) gaus=false; /* Gaussian taper flag */
    if(gaus) {
	if(! sf_getfloat("gsx",&gsx)) gsx=nhx*sf_d(ax); gsx=1./(2*gsx*gsx);
	if(! sf_getfloat("gsz",&gsz)) gsz=nhz*sf_d(az); gsz=1./(2*gsz*gsz);
	if(! sf_getfloat("gst",&gst)) gst=nht*sf_d(at); gst=1./(2*gst*gst);
    }

    /*------------------------------------------------------------*/
    /* allocate work arrays */
    us=sf_floatalloc3(nz,nx,nht2);
    ur=sf_floatalloc3(nz,nx,nht2);
    ii=sf_floatalloc4(nhz2,nhx2,nht2,nc);
    /* zero output */
    for(ic=0; ic<nc; ic++) {
	for        (iht=0; iht<nht2; iht++) {
	    for    (ihx=0; ihx<nhx2; ihx++) {
		for(ihz=0; ihz<nhz2; ihz++) {
		    ii[ic][iht][ihx][ihz] = 0;
		}
	    }
	}
    }

    /*------------------------------------------------------------*/
    /* CIP coordinates */
    cc= (pt2d*) sf_alloc(nc,sizeof(*cc));
    pt2dread1(Fc,cc,nc,2);

    mcxall=sf_intalloc2(nhx2,nc);
    pcxall=sf_intalloc2(nhx2,nc);
    mczall=sf_intalloc2(nhz2,nc);
    pczall=sf_intalloc2(nhz2,nc);

    ccin=sf_boolalloc(nc);

    cxmin = sf_o(ax) +             nhx *sf_d(ax);
    cxmax = sf_o(ax) + (sf_n(ax)-1-nhx)*sf_d(ax);
    czmin = sf_o(az) +             nhz *sf_d(az);
    czmax = sf_o(az) + (sf_n(az)-1-nhz)*sf_d(az);
    if(verb) {
	sf_warning("cxmin=%f,cxmax=%f",cxmin,cxmax);
	sf_warning("czmin=%f,czmax=%f",czmin,czmax);
    }

    for(ic=0; ic<nc; ic++) {
	ccin[ic]=(cc[ic].x>=cxmin && cc[ic].x<=cxmax &&
		  cc[ic].z>=czmin && cc[ic].z<=czmax)?true:false;
	
	if(ccin[ic]) {

	    icx = 0.5+(cc[ic].x-sf_o(ax))/sf_d(ax);
	    for(ihx=-nhx; ihx<nhx+1; ihx++) {
		mcxall[ic][nhx+ihx] = icx-ihx;
		pcxall[ic][nhx+ihx] = icx+ihx;
	    }

	    icz = 0.5+(cc[ic].z-sf_o(az))/sf_d(az);
	    for(ihz=-nhz; ihz<nhz+1; ihz++) {
		mczall[ic][nhz+ihz] = icz-ihz;
		pczall[ic][nhz+ihz] = icz+ihz;
	    }

	}
    }
       
    mctall=sf_intalloc(nht2);
    pctall=sf_intalloc(nht2);
    for (iht=0; iht<nht2; iht++) { 
	mctall[iht]=iht;
	pctall[iht]=2*nht-iht;
    }
    
    /*------------------------------------------------------------*/
    if(isreversed) { /* receiver wavefield is reversed */

	/* read wavefield @ [0...2nht-1]*/
	for(iht=0;iht<2*nht;iht++) {
	    sf_floatread(us[iht][0],nz*nx,Fs);
	    sf_floatread(ur[iht][0],nz*nx,Fr);
	}

	if(verb) fprintf(stderr,"nt\n");
	for(it=nht;it<nt-nht;it++) {
	    if(verb) fprintf(stderr,"\b\b\b\b\b\b\b\b\b\b%04d",it);
	    
	    /* read wavefield @ [2nht]*/
	    sf_floatread(us[ lht ][0],nz*nx,Fs);
	    sf_floatread(ur[ lht ][0],nz*nx,Fr);
	    
#ifdef _OPENMP
#pragma omp parallel for schedule(dynamic)				\
    private(ic,								\
	    ihx,ihz,iht,						\
	    mcx,mcz,mct,						\
	    pcx,pcz,pct) 						\
    shared (nc,ii,us,ur,						\
	    nhx2,  nhz2,  nht2,						\
	    mcxall,mczall,mctall,					\
	    pcxall,pczall,pctall,ccin)
#endif
	    for(ic=0; ic<nc; ic++) {
		if(ccin[ic]) {
		    
		    for        (iht=0; iht<nht2; iht++) { mct=mctall    [iht]; pct=pctall    [iht];
			for    (ihx=0; ihx<nhx2; ihx++) { mcx=mcxall[ic][ihx]; pcx=pcxall[ic][ihx];
			    for(ihz=0; ihz<nhz2; ihz++) { mcz=mczall[ic][ihz]; pcz=pczall[ic][ihz];
				
				ii[ic][iht][ihx][ihz] += us[mct][mcx][mcz]*ur[pct][pcx][pcz];
				
			    } /* ihz */
			}     /* ihx */
		    }         /* iht */
		    
		}
	    } /* ic */
	    
	    /* update wavefield index (cycle) */
	    for(iht=0;iht<nht2;iht++) {
		mctall[iht] = (mctall[iht]+1) % nht2;
		pctall[iht] = (pctall[iht]+1) % nht2;
	    }
	    lht = (lht+1) % nht2;
	    
	} /* it */
	if(verb) fprintf(stderr,"\n");

    } else { /* receiver wavefield is NOT reversed */

	/* read wavefield @ [0...2nht-1]*/
	for(iht=0;iht<2*nht;iht++) {
	    sf_floatread(us[iht][0],nz*nx,Fs);
	    iseek = (off_t)(nt-1-iht)*nz*nx*sizeof(float);
	    sf_seek(Fr,iseek,SEEK_SET);
	    sf_floatread(ur[iht][0],nz*nx,Fr);
	}

	if(verb) fprintf(stderr,"nt\n");
	for(it=nht;it<nt-nht;it++) {
	    if(verb) fprintf(stderr,"\b\b\b\b\b\b\b\b\b\b%04d",nt-nht-1-it);
	   
	    /* read wavefield @ [2nht]*/
	    sf_floatread(us[ lht ][0],nz*nx,Fs);
	    iseek=(off_t)(nt-nht-1-it)*nz*nx*sizeof(float);
	    sf_seek(Fr,iseek,SEEK_SET);
	    sf_floatread(ur[ lht ][0],nz*nx,Fr);
	    
#ifdef _OPENMP
#pragma omp parallel for schedule(dynamic)				\
    private(ic,								\
	    ihx,ihz,iht,						\
	    mcx,mcz,mct,						\
	    pcx,pcz,pct) 						\
    shared (nc,ii,us,ur,						\
	    nhx2,  nhz2,  nht2,						\
	    mcxall,mczall,mctall,					\
	    pcxall,pczall,pctall,ccin)
#endif
	    for(ic=0; ic<nc; ic++) {
		if(ccin[ic]) {
		    
		    for        (iht=0; iht<nht2; iht++) { mct=mctall    [iht]; pct=pctall    [iht];
			for    (ihx=0; ihx<nhx2; ihx++) { mcx=mcxall[ic][ihx]; pcx=pcxall[ic][ihx];
			    for(ihz=0; ihz<nhz2; ihz++) { mcz=mczall[ic][ihz]; pcz=pczall[ic][ihz];
				
				ii[ic][iht][ihx][ihz] += us[mct][mcx][mcz]*ur[pct][pcx][pcz];
				
			    } /* ihz */
			}     /* ihx */
		    }         /* iht */
		    
		}
	    } /* ic */
	    
	    /* update wavefield index (cycle) */
	    for(iht=0;iht<nht2;iht++) {
		mctall[iht] = (mctall[iht]+1) % nht2;
		pctall[iht] = (pctall[iht]+1) % nht2;
	    }
	    lht = (lht+1) % nht2;

	} /* it */
	if(verb) fprintf(stderr,"\n");

    } /* end "is reversed" */
    /*------------------------------------------------------------*/

    /*------------------------------------------------------------*/
    /* scale image */
    scale = 1./nt;
    for(ic=0; ic<nc; ic++) {
	for        (iht=0; iht<nht2; iht++) {
	    for    (ihx=0; ihx<nhx2; ihx++) {
		for(ihz=0; ihz<nhz2; ihz++) {
		    ii[ic][iht][ihx][ihz] *= scale;
		}
	    }
	}
    }

    /*------------------------------------------------------------*/
    /* apply Gaussian taper */
    if(gaus) {
	for(ic=0; ic<nc; ic++) {
	    for        (iht=0;iht<nht2;iht++) { gt=(iht-nht)*sf_d(at); gt*=gt;
		for    (ihx=0;ihx<nhx2;ihx++) { gx=(ihx-nhx)*sf_d(ax); gx*=gx;
		    for(ihz=0;ihz<nhz2;ihz++) { gz=(ihz-nhz)*sf_d(az); gz*=gz;
			ii[ic][iht][ihx][ihz] *= exp(-gt*gst - gx*gsx - gz*gsz);
		    }
		}
	    }
	}
    }

    /*------------------------------------------------------------*/
    /* write image */
    sf_floatwrite(ii[0][0][0],nc*(nhx2)*(nhz2)*(nht2),Fi);
    
    /*------------------------------------------------------------*/
    /* deallocate arrays */
    free(***ii); free(**ii); free(*ii); free(ii);
    free(*us); free(us);
    free(*ur); free(ur);
 
    free(cc);
    free(ccin);
    
    free(*mcxall); free(mcxall);
    free(*pcxall); free(pcxall);
    free(*mczall); free(mczall);
    free(*pczall); free(pczall);
    /*------------------------------------------------------------*/   

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

    float ***data, ****data_out;

    int ix, nx, iy, ny, it, nt, nfft, nw, iw;
    /*
     * @ Setup the parameters of the dimensions of the DATASETS
     * @ the Output Parameters also be setup
     */
    sf_file Fi=NULL, Fo=NULL;
    /*
     * @ Setup the FILE POINT of Input Data and Output Frequency Dependent Trace
     */
    sf_axis at, ax, ay, aw;
    /*
     * @ Setup the AXISes of DataSETS
     */
    float var;
    /*
     * @ Variance of the Window Function in FT
     */
    int dim, num_dim[SF_MAX_DIM];

    float dt, dw, nw_s, fre;

    if(!sf_getint  ( "nw" , &nw ))         sf_error( "Missing nw!\n" );
    /* Input Parameter: the Number of Slicing in FD */
    if(!sf_getfloat( "nw_s" , &nw_s))      sf_error( "Missing nw_s!\n" );
    /* Input Parameter: the starting number of frequency */
    if(!sf_getfloat( "dw" , &dw ))         sf_error( "Missing dw!\n" );
    /* Input Parameter: the interval of OUTPUT frequency */
    if(!sf_getint( "nfft" , &nfft ))       sf_error( "Missing nfft!\n" );
    /* Input Parameter: the length of FFT */
    if(!sf_getfloat( "variance" , &var ))  sf_error( "Missing variance!\n" );
    /* the variance of the window */

    Fi = sf_input ( "data_in" );
    Fo = sf_output( "data_out" );

    dim = sf_filedims( Fi , num_dim );

    if( dim==1 )
    {
        at = sf_iaxa( Fi , 1 );
        nt = sf_n( at );
        dt = sf_d( at );

        nx = 1;
        ny = 1;
    }
    else if( dim==2 )
    {
        at = sf_iaxa( Fi , 1 );
        nt = sf_n( at );
        dt = sf_d( at );

        ax = sf_iaxa( Fi , 2 );
        nx = sf_n( ax );

        ny = 1;
    }
    else if( dim==3 )
    {
        at = sf_iaxa( Fi , 1 );
        nt = sf_n( at );
        dt = sf_d( at );

        ax = sf_iaxa( Fi , 2 );
        nx = sf_n( ax );

        ay = sf_iaxa( Fi , 3 );
        ny = sf_n( ay );
    }
    else
    {
        sf_error( "DIMENSION WRONG!\n" );
    }

    data        = sf_floatalloc3( nt , nx , ny );
    data_out    = sf_floatalloc4( nt , nw , nx , ny );

    sf_floatread( &data[0][0][0] , nt*nx*ny , Fi );

    for( iy=0 ; iy<ny ; iy++ )
    for( ix=0 ; ix<nx ; ix++ )
    for( iw=0 ; iw<nw ; iw++ )
    {
        fre = nw_s+dw*iw;
        winft( &data[iy][ix][0] , &data_out[iy][ix][iw][0] , nt , nfft , dt , fre , var );
    }

    aw = sf_maxa( nw , nw_s , dw );

    sf_oaxa( Fo , at , 1 );
    sf_oaxa( Fo , aw , 2 );
    if( dim==2 )
    {
        sf_oaxa( Fo , ax , 3 );
    }
    if( dim==3 )
    {
        sf_oaxa( Fo , ax , 3 );
        sf_oaxa( Fo , ay , 4 );
    }

    sf_floatwrite( &data_out[0][0][0][0] , ny*nx*nw*nt , Fo );

    free( data );
    free( data_out );

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

    sf_axis at, ax, ay, aw, at_wave, aw_wave;
    /*
     * @Define AXIS for DATASETS
     */
    sf_file FD1, FD2, FD3, FD4, FW1, FW2, FW3, FW4, FPR1, FPR2, FPR3, FPR4, FPR5, FPO1, FPO2, FPO3, FPO4, FPO5;
    /*
     * @Define File Interfaces for Datasets
     */
    int ix, nx, nx_s, NX, iy, ny, ny_s, NY, iw, nw, nw_s, NW, it, jt, nt, nt_s, NT, nwave;
    /*
     * @Define the Dimension of the Input Data & Inversion
     * @it  : index of time axis
     * @nx  : Dimension of Inversion in Inline Direction
     * @nx_s: Starting place of Inline Direction
     * @NX  : Dimension of Input Data
     * @NY,ny,ny_s: Parameters in Crossline Direction
     * @NT,nt,nt_s: Parameters in time direction
     * @nwave: length of the wavelet
     */
    float sita1, sita2, sita3, sita4;
    /*
     * @ Angle Values of NearOffset, Mid1, Mid2 and TeleOffset, respectively!
     */
    float w0, crange, corder, var_e;
    int wsft;
    /*
     * @ Parameters of Inversion, w0 is the reference frequency of the Q model
     * @ crange and corder are the parameters of Gaussian Shaped Window function
     * @ var_e is the level of noise estimated
     * @ wsft is the wave shift of the wavelet to the original point
     */
    int dim, num_dim[SF_MAX_DIM];
    /*
     * @ Detect the Dimension of the DATASETS Using the Interior Function
     */
    float dt, ot, dw, ow;
    /*
     * @ PARAMETER of the DATASETS
     * @ dt is the time interval, ot is the starting time value
     */
    float **NearWave, **Mid1Wave, **Mid2Wave, **TeleWave;
    /*
     * @ Input Wavelet file in different frequency and Offset
     */
    float *d, *M_prior, **Cm, **Cn, **A, **W, **D, **WA, **G, *M_post, ****MPOST;
    /*
     * @
     * @
     * @Cm is the covariance matrix of the model
     * @Cn is the covariance matrix of the noise
     */
    int ipara, jpara;
    float vpvsratio;
    /*
     * @auxiliary variable in calculating the coefficient in AKI-RICHARD formulae
     */

    if(!sf_getint( "nw_start" , &nw_s ))             sf_error( "Missing Frequency Start!\n" );
    /* Input Parameter: the starting frequency in inversion */
    if(!sf_getint( "nw_inv" , &nw ))                 sf_error( "Missing the Number of Frequency used!\n" );
    /* Input Parameter: the number of frequency in inversion */
    if(!sf_getint( "ninline_start" , &nx_s ))        sf_error( "Missing inline Direction Starting Value !\n" );
    /* Input Parameter: the Starting value in inline direction in Inversion */
    if(!sf_getint( "ninline_inv" , &nx ))            sf_error( "Missing Number of CDPS in inline direction!\n" );
    /* Input Parameter: the number of CDPS in inline direction */
    if(!sf_getint( "ncrossline_start" , &ny_s ))     sf_error( "Missing crossline Direction Starting Value!\n" );
    /* Input Paramter: the starting Value in crossline direction in Inversion */
    if(!sf_getint( "ncrossline_inv" , &ny ))         sf_error( "Missing Number of inlines in Crossline direction!\n" );
    /* Input Parameter: the number of INLINES in crossline direction */
    if(!sf_getfloat( "nearsita" , &sita1 ))          sf_error( "Missing the Near Offset angle Value!\n" );
    /* Input Parameter: the Angle Value of Near Offset Trace Gather */
    if(!sf_getfloat( "mid1sita" , &sita2 ))          sf_error( "Missing the Mid1 Offset angle Value!\n" );
    /* Input Parameter: the Angle Value of Mid1 Offset Trace Gather */
    if(!sf_getfloat( "mid2sita" , &sita3 ))          sf_error( "Missing the Mid2 Offset angle Value!\n" );
    /* Input Parameter: the Angle Value of Mid2 Offset Trace Gather */
    if(!sf_getfloat( "telesita" , &sita4 ))          sf_error( "Missing the Tele Offset angle Value!\n" );
    /* Input Parameter: the Angle Value of Tele Offset Trace Gather */
    if(!sf_getfloat( "w0" , &w0 ))                   sf_error( "Missing w0!\n" );
    /* Input Parameter: Reference Frequency in Inversion */
    if(!sf_getint( "wave_shift" , &wsft ))           sf_error( "Missing the Shift of Wavelet!\n" );
    /* Input Parameter: Wave Shift in Inversion */
    if(!sf_getfloat( "correlation_range" , &crange ))sf_error( "Missing the Correlation Range in Inversion!\n" );
    /* Input Parameter: COrrelation range in Inversion */
    if(!sf_getfloat( "correlation_order" , &corder ))sf_error( "Missing the Correlation Order in Inversion!\n" );
    /* Input Parameter: Correlation Order in Inversion */
    if(!sf_getfloat( "variance_noise" , &var_e ))    sf_error( "Missing the Variance of Noise in Inversion!\n" );
    /* Input Parameter: Variance of Noise in Inversion */

    FD1 = sf_input( "NearOffsetGather" );
    FD2 = sf_input( "Mid1OffsetGather" );
    FD3 = sf_input( "Mid2OffsetGather" );
    FD4 = sf_input( "TeleOffsetGather" );
    /*
     * @ Input DATASETs
     */
    FW1 = sf_input( "NearWavelet" );
    FW2 = sf_input( "Mid1Wavelet" );
    FW3 = sf_input( "Mid2Wavelet" );
    FW4 = sf_input( "TeleWavelet" );
    /*
     * @ Input WAVELETs
     */
    FPR1= sf_input( "vp_prior" );
    FPR2= sf_input( "vs_prior" );
    FPR3= sf_input( "ro_prior" );
    FPR4= sf_input( "qp_prior" );
    FPR5= sf_input( "qs_prior" );
    /*
     * @ Input a Prior Models
     */
    FPO1= sf_output( "vp_post" );
    FPO2= sf_output( "vs_post" );
    FPO3= sf_output( "ro_post" );
    FPO4= sf_output( "qp_post" );
    FPO5= sf_output( "qs_post" );
    /*
     * @ Output Post MODELs by Bayesian Inversion
     */

    dim = sf_filedims( FD1 , num_dim );

    if( dim==3 )
    {
        at = sf_iaxa( FD1 , 1 );
        NT = sf_n( at );
        dt = sf_d( at );
        ot = sf_o( at );

        aw = sf_iaxa( FD1 , 2 );
        NW = sf_n( aw );
        dw = sf_d( aw );
        ow = sf_o( aw );

        ax = sf_iaxa( FD1 , 3 );
        NX = sf_n( ax );

        NY = 1;
    }
    else if( dim==4 )
    {
        at = sf_iaxa( FD1 , 1 );
        NT = sf_n( at );
        dt = sf_d( at );
        ot = sf_o( at );

        aw = sf_iaxa( FD1 , 2 );
        NW = sf_n( aw );
        dw = sf_d( aw );
        ow = sf_o( aw );

        ax = sf_iaxa( FD1 , 3 );
        NX = sf_n( ax );

        ay = sf_iaxa( FD1 , 4 );
        NY = sf_n( ay );
    }
    else
        sf_error( "DATA DIMENSION FAULT!\n" );
    /*
     * @ Only Handle the problem owns at least an inline section
     * @ dimension of the data MUST be 3 or 4!
     */

    at_wave = sf_iaxa( FW1 , 1 );
    aw_wave = sf_iaxa( FW1 , 2 );
    nwave   = sf_n( at_wave );

    if( sf_n(aw_wave)!=NW )                 sf_error( "The NW dimension of wavelet should equal to the one of the DATASETS!\n" );
    if( sf_n(sf_iaxa( FPR1 , 1 ))!=NT+1 )  sf_error( "DATASETS UNMATCHED!\n" );
    if( sf_n(sf_iaxa( FPR1 , 2 ))!=NX )    sf_error( "DATASETS UNMATCHED!\n" );
    if( nw_s<0 || nw_s>=NW )                sf_error( "The nw_start is inappropriate!\n" );
    if( nx_s<0 || nx_s>=NX )                sf_error( "The ninline start is inappropriate!\n" );
    if( ny_s<0 || ny_s>=NY )                sf_error( "The ncrossline start is inappropriate!\n" );
    if( nw_s+nw>NW )                        sf_error( "The nw inversion is inappropriate!\n" );
    if( nx_s+nx>NX )                        sf_error( "The nx inversion is inappropriate!\n" );
    if( ny_s+ny>NY )                        sf_error( "The ny inversion is inappropriate!\n" );

    /*
     * @Read Parameter of Wavelet & Check Parameters 
     * @if occurs inappropriate parameter, the program breaks immediately
     */

    NearWave = sf_floatalloc2( nwave , nw );
    Mid1Wave = sf_floatalloc2( nwave , nw );
    Mid2Wave = sf_floatalloc2( nwave , nw );
    TeleWave = sf_floatalloc2( nwave , nw );

    sf_seek( FW1 , sizeof(float)*nwave*nw_s , SEEK_SET );
    sf_seek( FW2 , sizeof(float)*nwave*nw_s , SEEK_SET );
    sf_seek( FW3 , sizeof(float)*nwave*nw_s , SEEK_SET );
    sf_seek( FW4 , sizeof(float)*nwave*nw_s , SEEK_SET );

    sf_floatread( &NearWave[0][0] , nwave*nw , FW1 );
    sf_floatread( &Mid1Wave[0][0] , nwave*nw , FW2 );
    sf_floatread( &Mid2Wave[0][0] , nwave*nw , FW3 );
    sf_floatread( &TeleWave[0][0] , nwave*nw , FW4 );

    /*
     * @Clip the WAVELET DATASETS and Read Needed Wavelet
     */
    MPOST   = sf_floatalloc4( NT+1 , NX , NY , 5 );

    zero4float( MPOST , NT+1 , NX , NY , 5 );
    /*
     * @ The MAP solution of all the PARAMETERS
     */

    for( iy=0 ; iy<ny ; iy++ )
    for( ix=0 ; ix<nx ; ix++ )
    {
        printf( "ix=%d\n" , ix );
        nt = NT;
        nt_s=0;

        d       = sf_floatalloc( 4*nw*nt );
        M_prior = sf_floatalloc ( 5*(nt+1) );
        M_post  = sf_floatalloc ( 5*(nt+1) );
        Cm      = sf_floatalloc2( 5*(nt+1) , 5*(nt+1) );
        Cn      = sf_floatalloc2( 4*nw*nt , 4*nw*nt );
        A       = sf_floatalloc2( 5*nt , 4*nw*nt );
        W       = sf_floatalloc2( 4*nw*nt , 4*nw*nt );
        D       = sf_floatalloc2( 5*(nt+1) , 5*nt );
        WA      = sf_floatalloc2( 5*nt , 4*nw*nt );
        G       = sf_floatalloc2( 5*(nt+1) , 4*nw*nt );
        /*
         * @4 means 4 angle gather
         * @5 means 5 parameter,
         * @4 &5 could be set up in the parameter list if it's needed!
         * @To keep simplicity, the two parameters are given explicitly
         */
        
        for( iw=0 ; iw<nw ; iw++ )
        {
            sf_seek( FD1 , sizeof(float)*((ny_s+iy)*NX*NW*NT+(nx_s+ix)*NW*NT+(nw_s+iw)*NT+nt_s) , SEEK_SET );
            sf_seek( FD2 , sizeof(float)*((ny_s+iy)*NX*NW*NT+(nx_s+ix)*NW*NT+(nw_s+iw)*NT+nt_s) , SEEK_SET );
            sf_seek( FD3 , sizeof(float)*((ny_s+iy)*NX*NW*NT+(nx_s+ix)*NW*NT+(nw_s+iw)*NT+nt_s) , SEEK_SET );
            sf_seek( FD4 , sizeof(float)*((ny_s+iy)*NX*NW*NT+(nx_s+ix)*NW*NT+(nw_s+iw)*NT+nt_s) , SEEK_SET );

            sf_floatread( &d[(0*nw+iw)*nt] , nt , FD1 );
            sf_floatread( &d[(1*nw+iw)*nt] , nt , FD2 );
            sf_floatread( &d[(2*nw+iw)*nt] , nt , FD3 );
            sf_floatread( &d[(3*nw+iw)*nt] , nt , FD4 );
        }

        sf_seek( FPR1 , sizeof(float)*((ny_s+iy)*NX*(NT+1)+(nx_s+ix)*(NT+1)+nt_s) , SEEK_SET );
        sf_seek( FPR2 , sizeof(float)*((ny_s+iy)*NX*(NT+1)+(nx_s+ix)*(NT+1)+nt_s) , SEEK_SET );
        sf_seek( FPR3 , sizeof(float)*((ny_s+iy)*NX*(NT+1)+(nx_s+ix)*(NT+1)+nt_s) , SEEK_SET );
        sf_seek( FPR4 , sizeof(float)*((ny_s+iy)*NX*(NT+1)+(nx_s+ix)*(NT+1)+nt_s) , SEEK_SET );
        sf_seek( FPR5 , sizeof(float)*((ny_s+iy)*NX*(NT+1)+(nx_s+ix)*(NT+1)+nt_s) , SEEK_SET );

        sf_floatread( &M_prior[0*(nt+1)] , nt+1 , FPR1 );
        sf_floatread( &M_prior[1*(nt+1)] , nt+1 , FPR2 );
        sf_floatread( &M_prior[2*(nt+1)] , nt+1 , FPR3 );
        sf_floatread( &M_prior[3*(nt+1)] , nt+1 , FPR4 );
        sf_floatread( &M_prior[4*(nt+1)] , nt+1 , FPR5 );
        /*
         * @Read Angle freuquency Gather use FILE SEEK function
         * @Read a Prior MODEL
         */

        for( iw=0 ; iw<nw ; iw++ )
        for( it=0 ; it<nt ; it++ )
        {
            vpvsratio = (M_prior[nt+1+it]+M_prior[nt+1+it+1])/(M_prior[it]+M_prior[it+1]);

            A[0*nw*nt+iw*nt+it][it]      = 0.5*(1.+tan(sita1*SF_PI/180.)*tan(sita1*SF_PI/180.));
            A[0*nw*nt+iw*nt+it][nt+it]   = -4.*sin(sita1*SF_PI/180.)*sin(sita1*SF_PI/180.)*pow(vpvsratio,2.);
            A[0*nw*nt+iw*nt+it][2*nt+it] = 0.5*(1.-4.*sin(sita1*SF_PI/180.)*sin(sita1*SF_PI/180.)*pow(vpvsratio,2.));
            A[0*nw*nt+iw*nt+it][3*nt+it] = A[0*nw*nt+iw*nt+it][it]*((1./SF_PI)*log((dw*(nw_s+iw)+ow)/w0));
            A[0*nw*nt+iw*nt+it][4*nt+it] = A[0*nw*nt+iw*nt+it][nt+it]*((1./SF_PI)*log((dw*(nw_s+iw)+ow)/w0));

            A[1*nw*nt+iw*nt+it][it]      = 0.5*(1.+tan(sita2*SF_PI/180.)*tan(sita2*SF_PI/180.));
            A[1*nw*nt+iw*nt+it][nt+it]   = -4.*sin(sita2*SF_PI/180.)*sin(sita2*SF_PI/180.)*pow(vpvsratio,2.);
            A[1*nw*nt+iw*nt+it][2*nt+it] = 0.5*(1.-4.*sin(sita2*SF_PI/180.)*sin(sita2*SF_PI/180.)*pow(vpvsratio,2.));
            A[1*nw*nt+iw*nt+it][3*nt+it] = A[1*nw*nt+iw*nt+it][it]*((1./SF_PI)*log((dw*(nw_s+iw)+ow)/w0));
            A[1*nw*nt+iw*nt+it][4*nt+it] = A[1*nw*nt+iw*nt+it][nt+it]*((1./SF_PI)*log((dw*(nw_s+iw)+ow)/w0));

            A[2*nw*nt+iw*nt+it][it]      = 0.5*(1.+tan(sita3*SF_PI/180.)*tan(sita3*SF_PI/180.));
            A[2*nw*nt+iw*nt+it][nt+it]   = -4.*sin(sita3*SF_PI/180.)*sin(sita3*SF_PI/180.)*pow(vpvsratio,2.);
            A[2*nw*nt+iw*nt+it][2*nt+it] = 0.5*(1.-4.*sin(sita3*SF_PI/180.)*sin(sita3*SF_PI/180.)*pow(vpvsratio,2.));
            A[2*nw*nt+iw*nt+it][3*nt+it] = A[2*nw*nt+iw*nt+it][it]*((1./SF_PI)*log((dw*(nw_s+iw)+ow)/w0));
            A[2*nw*nt+iw*nt+it][4*nt+it] = A[2*nw*nt+iw*nt+it][nt+it]*((1./SF_PI)*log((dw*(nw_s+iw)+ow)/w0));

            A[3*nw*nt+iw*nt+it][it]      = 0.5*(1.+tan(sita4*SF_PI/180.)*tan(sita4*SF_PI/180.));
            A[3*nw*nt+iw*nt+it][nt+it]   = -4.*sin(sita4*SF_PI/180.)*sin(sita4*SF_PI/180.)*pow(vpvsratio,2.);
            A[3*nw*nt+iw*nt+it][2*nt+it] = 0.5*(1.-4.*sin(sita4*SF_PI/180.)*sin(sita4*SF_PI/180.)*pow(vpvsratio,2.));
            A[3*nw*nt+iw*nt+it][3*nt+it] = A[3*nw*nt+iw*nt+it][it]*((1./SF_PI)*log((dw*(nw_s+iw)+ow)/w0));
            A[3*nw*nt+iw*nt+it][4*nt+it] = A[3*nw*nt+iw*nt+it][nt+it]*((1./SF_PI)*log((dw*(nw_s+iw)+ow)/w0));
        }

        for( iw=0; iw<nw; iw++ )
        for( it=0; it<nt; it++ )
        for( jt=0; jt<nt; jt++ )
        {
            if ( (it-jt)<=nwave-1-wsft && (it-jt)>=-wsft )
            {
                W[0*nw*nt+iw*nt+it][0*nw*nt+iw*nt+jt]= NearWave[iw][it-jt+wsft];
                W[1*nw*nt+iw*nt+it][1*nw*nt+iw*nt+jt]= Mid1Wave[iw][it-jt+wsft];
                W[2*nw*nt+iw*nt+it][2*nw*nt+iw*nt+jt]= Mid2Wave[iw][it-jt+wsft];
                W[3*nw*nt+iw*nt+it][3*nw*nt+iw*nt+jt]= TeleWave[iw][it-jt+wsft];
            }
            else
            {
                W[0*nw*nt+iw*nt+it][0*nw*nt+iw*nt+jt]=0.;
                W[1*nw*nt+iw*nt+it][1*nw*nt+iw*nt+jt]=0.;
                W[2*nw*nt+iw*nt+it][2*nw*nt+iw*nt+jt]=0.;
                W[3*nw*nt+iw*nt+it][3*nw*nt+iw*nt+jt]=0.;
            }
        }

        for( ipara=0 ; ipara<5 ; ipara++ )
        for( it=0    ; it<nt   ; it++ )
        {
            D[ipara*nt+it][ipara*(nt+1)+it]   = -1;
            D[ipara*nt+it][ipara*(nt+1)+it+1] = 1;
        }
        /*
         * @Build three essential Matrix, A,W,D
         * @A is the coefficient Matrix in multiple angle(4) and multiple frequency form
         * @W is the wavelet matrix
         * @D is the difference matrix
         * @the forward operator is G=WAD
         */
        lh_matrix_mu_matrix( W , A , WA , 4*nw*nt , 4*nw*nt , 5*nt );
        lh_matrix_mu_matrix( WA , D , G , 4*nw*nt , 5*nt , 5*(nt+1));
        /*
         * @ Build forward operator G, using W,A,D
         */
        for( it=0 ; it<3*(nt+1) ; it++ )
        {
            M_prior[it] = log(M_prior[it]);
        }
        for( it=3*(nt+1) ; it<5*(nt+1) ; it++ )
        {
            M_prior[it] = 1./M_prior[it];
        }
        /*
         * @ Revise the A Prior Model Into the expectation value of True Value
         */

        for( it=0 ; it<nt+1 ; it++ )
        for( jt=0 ; jt<nt+1 ; jt++ )
        for( ipara=0 ; ipara<5 ; ipara++ )
        for( jpara=0 ; jpara<5 ; jpara++ )
        {
            if( ipara==jpara )
                Cm[ipara*(nt+1)+it][jpara*(nt+1)+jt] = lh_float_variance( &M_prior[ipara*(nt+1)] , nt+1 )
                                                        *exp(-1.*pow(fabs((it-jt)*dt/crange),corder));
            else
                Cm[ipara*(nt+1)+it][jpara*(nt+1)+jt] = lh_float_covariance( &M_prior[ipara*(nt+1)] , &M_prior[jpara*(nt+1)] , nt+1 )
                                                        *exp(-1.*pow(fabs((it-jt)*dt/crange),corder));

        }
        for( it=0 ; it<4*nw*nt ; it++ )
        for( jt=0 ; jt<4*nw*nt ; jt++ )
        {
            if( it==jt )
                Cn[it][jt] = var_e;
            else
                Cn[it][jt] = 0.;
        }
        /*
         * @ Transfer the ELASTIC parameters into LOG value
         * @ Transfer the ANELASTIC parameters into RECIPROCAL value
         * @ Setup the variance of the MODEL and the NOISE,
         * @ Cm Usually comes from welldata, here is given from MODELS
         */
        lh_direct_LS( G , 4*nw*nt , 5*(nt+1) , Cn , Cm , d, M_prior, M_post );
        /*
         * @ Inversion Under Bayesian Framework, the formulae comes from Tarantola(2005) directly
         */
        if( ix==0 )
        {
            lh_write_1d_float_bin( M_post , 5*(nt+1) , "M_post.bin" );
            lh_write_1d_float_bin( M_prior, 5*(nt+1) , "M_prior.bin");
        }

        for( it=0 ; it<nt+1 ; it++ )
        {
            MPOST[0][iy+ny_s][ix+nx_s][nt_s+it] = exp(M_post[0*(nt+1)+it]);
            MPOST[1][iy+ny_s][ix+nx_s][nt_s+it] = exp(M_post[1*(nt+1)+it]);
            MPOST[2][iy+ny_s][ix+nx_s][nt_s+it] = exp(M_post[2*(nt+1)+it]);
            MPOST[3][iy+ny_s][ix+nx_s][nt_s+it] = 1.0/M_post[3*(nt+1)+it];
            MPOST[4][iy+ny_s][ix+nx_s][nt_s+it] = 1.0/M_post[4*(nt+1)+it];
        }

        free1float( d );
        free1float( M_prior );
        free1float( M_post );
        free2float( Cm );
        free2float( Cn );
        free2float( A );
        free2float( W );
        free2float( D );
        free2float( WA );
        free2float( G );
    }
    if( dim==3 )
    {
        sf_oaxa( FPO1 , sf_maxa( NT+1 , 0., dt ) , 1 );
        sf_oaxa( FPO2 , sf_maxa( NT+1 , 0., dt ) , 1 );
        sf_oaxa( FPO3 , sf_maxa( NT+1 , 0., dt ) , 1 );
        sf_oaxa( FPO4 , sf_maxa( NT+1 , 0., dt ) , 1 );
        sf_oaxa( FPO5 , sf_maxa( NT+1 , 0., dt ) , 1 );

        sf_oaxa( FPO1 , sf_maxa( NX , 0., 1 ) , 2 );
        sf_oaxa( FPO2 , sf_maxa( NX , 0., 1 ) , 2 );
        sf_oaxa( FPO3 , sf_maxa( NX , 0., 1 ) , 2 );
        sf_oaxa( FPO4 , sf_maxa( NX , 0., 1 ) , 2 );
        sf_oaxa( FPO5 , sf_maxa( NX , 0., 1 ) , 2 );
    }
    if( dim==4 )
    {
        sf_oaxa( FPO1 , sf_maxa( NT+1 , 0., dt ) , 1 );
        sf_oaxa( FPO2 , sf_maxa( NT+1 , 0., dt ) , 1 );
        sf_oaxa( FPO3 , sf_maxa( NT+1 , 0., dt ) , 1 );
        sf_oaxa( FPO4 , sf_maxa( NT+1 , 0., dt ) , 1 );
        sf_oaxa( FPO5 , sf_maxa( NT+1 , 0., dt ) , 1 );

        sf_oaxa( FPO1 , sf_maxa( NX , 0., 1 ) , 2 );
        sf_oaxa( FPO2 , sf_maxa( NX , 0., 1 ) , 2 );
        sf_oaxa( FPO3 , sf_maxa( NX , 0., 1 ) , 2 );
        sf_oaxa( FPO4 , sf_maxa( NX , 0., 1 ) , 2 );
        sf_oaxa( FPO5 , sf_maxa( NX , 0., 1 ) , 2 );

        sf_oaxa( FPO1 , sf_maxa( NY , 0., 1 ) , 3 );
        sf_oaxa( FPO2 , sf_maxa( NY , 0., 1 ) , 3 );
        sf_oaxa( FPO3 , sf_maxa( NY , 0., 1 ) , 3 );
        sf_oaxa( FPO4 , sf_maxa( NY , 0., 1 ) , 3 );
        sf_oaxa( FPO5 , sf_maxa( NY , 0., 1 ) , 3 );
    }
    sf_floatwrite( &MPOST[0][0][0][0] , (NT+1)*NX*NY , FPO1 );
    sf_floatwrite( &MPOST[1][0][0][0] , (NT+1)*NX*NY , FPO2 );
    sf_floatwrite( &MPOST[2][0][0][0] , (NT+1)*NX*NY , FPO3 );
    sf_floatwrite( &MPOST[3][0][0][0] , (NT+1)*NX*NY , FPO4 );
    sf_floatwrite( &MPOST[4][0][0][0] , (NT+1)*NX*NY , FPO5 );

    free( MPOST );

    exit( 0 );
}
示例#11
0
/* for passive source and fwi */
void gradient_pas_init(sf_file Fdat, sf_file Fsrc, sf_file Fmwt, sf_mpi *mpipar, sf_sou soupar, sf_acqui acpar, sf_vec array, sf_fwi fwipar, sf_pas paspar, bool verb1)
/*< initialize >*/
{
        float **dwt=NULL,***mwt,***wwt;
        int it,ix,iz,iturn,is,rdn;
        char filename[20]="tempbin",srdn[10];
        FILE *temp;

	verb=verb1;
	first=true; // only at the first iteration, need to calculate the gradient scaling parameter

	cpuid=mpipar->cpuid;
	numprocs=mpipar->numprocs;

	nz=acpar->nz;
	nx=acpar->nx;
	nzx=nz*nx;
	padnz=acpar->padnz;
	padnx=acpar->padnx;
	padnzx=padnz*padnx;
	nb=acpar->nb;
	nt=acpar->nt;

	ns=acpar->ns;
	nr=acpar->nr;
	dr_v=acpar->dr_v;
	r0_v=acpar->r0_v;
	rz=acpar->rz;

	grectx=fwipar->rectx;
	grectz=fwipar->rectz;
	interval=acpar->interval;
	wnt=(nt-1)/interval+1;

	dt=acpar->dt;
	idt=1./dt;
	dt2=dt*dt;
	wdt=dt*interval;
	wdt2=wdt*wdt;
	dx2=acpar->dx*acpar->dx;
	dz2=acpar->dz*acpar->dz;

	wt1=fwipar->wt1;
	wt2=fwipar->wt2;
	woff1=fwipar->woff1;
	woff2=fwipar->woff2;
	waterz=fwipar->waterz;
	waterzb=fwipar->waterzb;

	bc=acpar->bc;

        if (cpuid==0) {
            srand(time(NULL));
            rdn = rand()%1000000000;
            sprintf(srdn,"%d",rdn);
            strcat(filename,srdn);
        }
	MPI_Bcast(filename, 20, MPI_CHAR, 0, comm);
        if(verb && cpuid==0) sf_warning("filename=%s",filename);

        temp=fopen(filename, "wb+");

	if(ns%numprocs==0) nturn=ns/numprocs;
	else nturn=ns/numprocs+1;

        /* allocate data/source/weight */
        dd  = sf_floatalloc3(nt, nx, nturn);
        ww3 = sf_floatalloc4(nz, nx, nt, nturn);
        gwt = sf_floatalloc4(nz, nx, nt, nturn);
        wwt = sf_floatalloc3(nz, nx, nt); /* temporary output var */
        if (!paspar->onlyvel) {
            mwt = sf_floatalloc3(nz, nx, nt); /* src model weight */
            /*
            dwt = sf_floatalloc2(acpar->nt, acpar->nx);

            wtn1=(fwipar->wt1-acpar->t0)/acpar->dt+0.5;
            wtn2=(fwipar->wt2-acpar->t0)/acpar->dt+0.5;
            woffn1=(fwipar->woff1-acpar->r0)/acpar->dr+0.5;
            woffn2=(fwipar->woff2-acpar->r0)/acpar->dr+0.5;
            residual_weighting(dwt, acpar->nt, acpar->nx, wtn1, wtn2, woffn1, woffn2, !fwipar->oreo);
            */
        } else {
            mwt=NULL;
            dwt=NULL;
        }

        /* read data/source */
        for(iturn=0; iturn<nturn; iturn++){
            is=iturn*numprocs+cpuid;
            if(is<ns){
                /* read data */
                sf_seek(Fdat, is*nt*nx*sizeof(float), SEEK_SET);
                sf_floatread(dd[iturn][0], nt*nx, Fdat);
                if (paspar->onlyvel) {
                    /* read source */
                    sf_seek(Fsrc, is*nz*nx*nt*sizeof(float), SEEK_SET);
                    sf_floatread(ww3[iturn][0][0], nz*nx*nt, Fsrc);
                } else {
                    /* linear inversion of source */
                    lstri_op(dd[iturn], dwt, ww3[iturn], mwt, acpar, array, paspar, verb);
                    /* write source */
                    fseeko(temp, is*nz*nx*nt*sizeof(float), SEEK_SET);
                    fwrite(ww3[iturn][0][0], sizeof(float), nz*nx*nt, temp);
                    if (NULL!=Fmwt && is==0) sf_floatwrite(mwt[0][0], nz*nx*nt, Fmwt);
                }

                /* calculate gradient mask */
                if (!paspar->onlyvel && paspar->prec && paspar->hidesrc) {
#ifdef _OPENMP
#pragma omp parallel for default(shared) private(it,ix,iz)
#endif
                    for         (it=0; it<nt; it++)
                        for     (ix=0; ix<nx; ix++)
                            for (iz=0; iz<nz; iz++)
                                gwt[iturn][it][ix][iz] = mwt[it][ix][iz];
                    threshold(true, nz*nx*nt, paspar->hard, gwt[iturn][0][0]);
#ifdef _OPENMP
#pragma omp parallel for default(shared) private(it,ix,iz)
#endif
                    for         (it=0; it<nt; it++)
                        for     (ix=0; ix<nx; ix++)
                            for (iz=0; iz<nz; iz++)
                                gwt[iturn][it][ix][iz] = 1.-gwt[iturn][it][ix][iz];
                } else {
#ifdef _OPENMP
#pragma omp parallel for default(shared) private(it,ix,iz)
#endif
                    for         (it=0; it<nt; it++)
                        for     (ix=0; ix<nx; ix++)
                            for (iz=0; iz<nz; iz++)
                                gwt[iturn][it][ix][iz] = 1.;
                }
            } /* if is<ns */
        }
        fclose(temp);
        MPI_Barrier(comm);

        if(!paspar->onlyvel && cpuid==0) {
            temp=fopen(filename, "rb");
            for(is=0; is<ns; is++){
                fseeko(temp, is*nz*nx*nt*sizeof(float), SEEK_SET);
                fread(wwt[0][0], sizeof(float), nz*nx*nt, temp);
                sf_floatwrite(wwt[0][0], nz*nx*nt, Fsrc);
            }
            fclose(temp);
            remove(filename);
        }
        MPI_Barrier(comm);

	/* data residual weights */
	wtn1=(wt1-acpar->t0)/dt+0.5;
	wtn2=(wt2-acpar->t0)/dt+0.5;
	woffn1=(woff1-acpar->r0)/acpar->dr+0.5;
	woffn2=(woff2-acpar->r0)/acpar->dr+0.5;
	weight=sf_floatalloc2(nt, nr);
	residual_weighting(weight, nt, nr, wtn1, wtn2, woffn1, woffn2, fwipar->oreo);

	/* padding and convert vector to 2-d array */
	vv = sf_floatalloc2(padnz, padnx);
	tau= sf_floatalloc2(padnz, padnx);
	taus=sf_floatalloc2(padnz, padnx);
	pad2d(array->vv, vv, nz, nx, nb);
	pad2d(array->tau, tau, nz, nx, nb);
	pad2d(array->taus, taus, nz, nx, nb);

        /* multiscale gradient */
	if(soupar->flo > 0.0001) blo=sf_butter_init(false, soupar->flo, 3);
	if(soupar->fhi < 0.5-0.0001) bhi=sf_butter_init(true, soupar->fhi, 3);

        free(**wwt); free(*wwt); free(wwt);
        if (NULL!=mwt) { free(**mwt); free(*mwt); free(mwt); }
	return;
}
示例#12
0
文件: Meicop3d.c 项目: 1014511134/src
/*------------------------------------------------------------*/
int main(int argc, char* argv[])
{
    bool verb;     /* verbosity flag */
    bool pos; /* direction of spraying */
    bool adj;      /* adjoint operator flag */
    bool wflcausal, oprcausal; /* causal wfl?, opr? */

    sf_file    Fopr,        Fwfl,         Fimg,     Fcip; /* I/O files */
    float   ****opr=NULL,****wfl=NULL,*****img=NULL; 
    int     itO,itW;
    
    sf_axis az,ax,ay,at,ac,aa; /* wfld axes */
    int     nz,nx,ny,nt,nc;
    int     iz,ix,iy,it,ic;

    sf_axis ahx, ahy, ahz, aht; /* EIC axes */
    int     nhx, nhy, nhz, nht;
    int     ihx, ihy, ihz, iht;
    float   dhx, dhy, dhz, dht;

    pt3d *cc=NULL;
    bool *ccin=NULL;
    float cxmin,czmin,cymin;
    float cxmax,czmax,cymax;
    int  icx, icz, icy;
    int  mcx, mcz, mcy, mct;
    int  pcx, pcz, pcy, pct;
    int **mcxall, **pcxall;
    int **mcyall, **pcyall;
    int **mczall, **pczall;
    int  *mctall,  *pctall;
    int lht,fht; /* last buffer index */

    float scale; /* time summation scaling */
    int nslice;  /* wavefield slice size */

    bool gaus;         /* gaussian taper */
    float gsx,gsy,gsz,gst; /* std dev */

    /*------------------------------------------------------------*/
    sf_init(argc,argv);
#ifdef _OPENMP
    omp_init();
#endif

    if(! sf_getbool(    "verb",&verb    ))        verb=false; /* verbosity flag */
    if(! sf_getbool(    "positive",&pos ))        pos=true; /* if positive sprays opr to positive shits, else, sprays to negative shifts */
    if(! sf_getbool(     "adj",&adj     ))         adj=false; /* adjoint flag */
    if(! sf_getbool("wflcausal",&wflcausal)) wflcausal=false; /* causal wfl? */
    if(! sf_getbool("oprcausal",&oprcausal)) oprcausal=false; /* causal opr? */

    /*------------------------------------------------------------*/
    Fopr = sf_input ("opr" ); /* operator */
    az=sf_iaxa(Fopr,1); if(verb) sf_raxa(az); nz = sf_n(az);
    ax=sf_iaxa(Fopr,2); if(verb) sf_raxa(ax); nx = sf_n(ax);
    ay=sf_iaxa(Fopr,3); if(verb) sf_raxa(ay); ny = sf_n(ay);
    at=sf_iaxa(Fopr,4); if(verb) sf_raxa(at); nt = sf_n(at);

    scale = 1./nt;                /* time summation scaling */
    nslice = nz*nx*ny*sizeof(float); /* wavefield slice */

    Fcip = sf_input ("cip" ); /* CIP coordinates    */
    ac = sf_iaxa(Fcip,2); 
    sf_setlabel(ac,"c"); sf_setunit(ac,""); if(verb) sf_raxa(ac); nc = sf_n(ac); 
    
    /*------------------------------------------------------------*/
    /* setup output */
    if(adj) {
	Fimg = sf_input ("in");  /*  read img */
	ahz=sf_iaxa(Fimg,1); nhz=(sf_n(ahz)-1)/2; if(verb) sf_raxa(ahz); 
	ahx=sf_iaxa(Fimg,2); nhx=(sf_n(ahx)-1)/2; if(verb) sf_raxa(ahx);
	ahy=sf_iaxa(Fimg,3); nhy=(sf_n(ahy)-1)/2; if(verb) sf_raxa(ahy);
	aht=sf_iaxa(Fimg,4); nht=(sf_n(aht)-1)/2; if(verb) sf_raxa(aht); 

	aa=sf_maxa(1,0,1); sf_setlabel(aa,""); sf_setunit(aa,""); 

	/* set output axes */
	Fwfl = sf_output("out"); /* write wfl */
	sf_oaxa(Fwfl,az,1);
	sf_oaxa(Fwfl,ax,2);
	sf_oaxa(Fwfl,ay,3);
	sf_oaxa(Fwfl,at,4);
	sf_oaxa(Fwfl,aa,5);

    } else {
	Fwfl = sf_input ( "in"); /*  read wfl */
	
	if(! sf_getint("nhz",&nhz)) nhz=0; /* z lags */
	dhz=2*sf_d(az);
	ahz=sf_maxa(2*nhz+1,-nhz*dhz,dhz); sf_setlabel(ahz,"hz"); sf_setunit(ahz,""); 
	if(verb) sf_raxa(ahz);
	
	if(! sf_getint("nhx",&nhx)) nhx=0; /* x lags */
	dhx=2*sf_d(ax);
	ahx=sf_maxa(2*nhx+1,-nhx*dhx,dhx); sf_setlabel(ahx,"hx"); sf_setunit(ahx,""); 
	if(verb) sf_raxa(ahx);

	if(! sf_getint("nhy",&nhy)) nhy=0; /* y lags */
	dhy=2*sf_d(ay);
	ahy=sf_maxa(2*nhy+1,-nhy*dhy,dhy); sf_setlabel(ahy,"hy"); sf_setunit(ahy,""); 
	if(verb) sf_raxa(ahy);

	if(! sf_getint("nht",&nht)) nht=0; /* t lags */
	dht=2*sf_d(at);
	aht=sf_maxa(2*nht+1,-nht*dht,dht); sf_setlabel(aht,"ht"); sf_setunit(aht,""); 
	if(verb) sf_raxa(aht);

	Fimg = sf_output("out"); /* write img */
	sf_oaxa(Fimg,ahz,1);
	sf_oaxa(Fimg,ahx,2);
	sf_oaxa(Fimg,ahy,3);
	sf_oaxa(Fimg,aht,4);
	sf_oaxa(Fimg, ac,5);
    }

    /*------------------------------------------------------------*/
    if(! sf_getbool("gaus",&gaus)) gaus=false; /* Gaussian taper */
    if(gaus) {
	if(! sf_getfloat("gsx",&gsx)) gsx=0.25*sf_n(ahx)*sf_d(ahx); gsx=(nhx==0)?1:1./(2*gsx*gsx);
	if(! sf_getfloat("gsy",&gsy)) gsy=0.25*sf_n(ahy)*sf_d(ahy); gsy=(nhy==0)?1:1./(2*gsy*gsy);
        if(! sf_getfloat("gsz",&gsz)) gsz=0.25*sf_n(ahz)*sf_d(ahz); gsz=(nhz==0)?1:1./(2*gsz*gsz);
        if(! sf_getfloat("gst",&gst)) gst=0.25*sf_n(aht)*sf_d(aht); gst=(nht==0)?1:1./(2*gst*gst);
    }
    
    /*------------------------------------------------------------*/
    /* allocate arrays */
    opr=sf_floatalloc4(nz,nx,ny,sf_n(aht));
    wfl=sf_floatalloc4(nz,nx,ny,sf_n(aht));
    img=sf_floatalloc5(sf_n(ahz),sf_n(ahx),sf_n(ahy),sf_n(aht),sf_n(ac));

    /*------------------------------------------------------------*/
    /* CIP coordinates */
    cc= (pt3d*) sf_alloc(nc,sizeof(*cc));
    pt3dread1(Fcip,cc,nc,3);

    mcxall=sf_intalloc2(sf_n(ahx),sf_n(ac));
    pcxall=sf_intalloc2(sf_n(ahx),sf_n(ac));
    mcyall=sf_intalloc2(sf_n(ahy),sf_n(ac));
    pcyall=sf_intalloc2(sf_n(ahy),sf_n(ac));
    mczall=sf_intalloc2(sf_n(ahz),sf_n(ac));
    pczall=sf_intalloc2(sf_n(ahz),sf_n(ac));
    ccin=sf_boolalloc(sf_n(ac));

    cxmin = sf_o(ax) +             nhx *sf_d(ax);
    cxmax = sf_o(ax) + (sf_n(ax)-1-nhx)*sf_d(ax);
    cymin = sf_o(ay) +             nhy *sf_d(ay);
    cymax = sf_o(ay) + (sf_n(ay)-1-nhy)*sf_d(ay);
    czmin = sf_o(az) +             nhz *sf_d(az);
    czmax = sf_o(az) + (sf_n(az)-1-nhz)*sf_d(az);

    for(ic=0;ic<nc;ic++) {
	ccin[ic]=(cc[ic].x>=cxmin && cc[ic].x<=cxmax &&
		  cc[ic].y>=cymin && cc[ic].y<=cymax &&
		  cc[ic].z>=czmin && cc[ic].z<=czmax)?true:false;
	
	if(ccin[ic]) {

	    icx = 0.5+(cc[ic].x-sf_o(ax))/sf_d(ax);
	    for(ihx=-nhx; ihx<nhx+1; ihx++) {
		mcxall[ic][nhx+ihx] = icx-ihx;
		pcxall[ic][nhx+ihx] = icx+ihx;
	    }

	    icy = 0.5+(cc[ic].y-sf_o(ay))/sf_d(ay);
	    for(ihy=-nhy; ihy<nhy+1; ihy++) {
		mcyall[ic][nhy+ihy] = icy-ihy;
		pcyall[ic][nhy+ihy] = icy+ihy;
	    }

	    icz = 0.5+(cc[ic].z-sf_o(az))/sf_d(az);
	    for(ihz=-nhz; ihz<nhz+1; ihz++) {
		mczall[ic][nhz+ihz] = icz-ihz;
		pczall[ic][nhz+ihz] = icz+ihz;
	    }

	}
    }
       
    mctall=sf_intalloc(sf_n(aht));
    pctall=sf_intalloc(sf_n(aht));
    for (iht=0; iht<sf_n(aht); iht++) { 
	mctall[iht]=            iht;
	pctall[iht]=sf_n(aht)-1-iht;
    }
    
    if(adj) { /* ADJIONT OPERATOR */

	for(iht=0;iht<sf_n(aht);iht++)
	    CICLOOP( wfl[iht][iy][ix][iz]=0; );                         /* zero wfl */
	for(it=0;it<nt;it++) sf_floatwrite(wfl[0][0][0],nz*nx*ny,Fwfl); /* reserve wfl */ 
	sf_seek(Fwfl,0,SEEK_SET);                                       /* seek back */

	sf_floatread(img[0][0][0][0],sf_n(ac)*sf_n(ahy)*sf_n(ahx)*sf_n(ahz)*sf_n(aht),Fimg); /* read img */
	;        applyScaling (img,ac,aht,ahx,ahy,ahz,scale);                       /* scaling  */
	if(gaus) applyGaussian(img,ac,aht,ahx,ahy,ahz,gst,gsx,gsy,gsz);             /* Gaussian */

	lht=0; itO=-999999; itW=-999999;
	for(it=-nht;it<nt+nht;it++) { if(verb) fprintf(stderr,"\b\b\b\b\b\b%04d",it);
	    fht=(lht+1) % sf_n(aht);

	    if(it<nt-nht) {
		itO = it + nht;
		if( !oprcausal ) sf_seek(Fopr,(off_t)(nt-1-itO)*nslice,SEEK_SET);
		else             sf_seek(Fopr,(off_t)      itO *nslice,SEEK_SET);
		sf_floatread(opr[ lht ][0][0],nz*nx*ny,Fopr);
	    }
            for(iht=0;iht<sf_n(aht);iht++) {
                mctall[iht] = (mctall[iht]+1) % sf_n(aht); /* cycle iht index */
                pctall[iht] = (pctall[iht]+1) % sf_n(aht);
            }


	    if(it>=0+nht && 
	       it<nt-nht) { 

#ifdef _OPENMP
#pragma omp parallel for schedule(dynamic)				\
    private(ic,     ihx,ihy,ihz,iht,mcx,   mcy,   mcz,   mct,   pcx,   pcy,   pcz,   pct) \
    shared (nc,ccin,ahx,ahy,ahz,aht,mcxall,mcyall,mczall,mctall,pcxall,pcyall,pczall,pctall)
#endif
		for(ic=0;ic<nc;ic++){ if(ccin[ic]) { /* sum over c only! */
      if(pos){

			EICLOOP( wfl    [mct][mcy][mcx][mcz] +=
				 opr    [pct][pcy][pcx][pcz] *
				 img[ic][iht][ihy][ihx][ihz]; );
      }else{
			EICLOOP( wfl    [pct][pcy][pcx][pcz] +=
				 opr    [mct][mcy][mcx][mcz] *
				 img[ic][iht][ihy][ihx][ihz]; );


      }
		    }
		}