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); }
int main (int argc, char *argv[]) { int ir, nr, n1,n2,n3, m1, m2, m3, n12, nw, nj1, nj2, i3; float *u1, *u2, *p, *ani; sf_file in, out, dip, aniso; bool verb; allpass ap; sf_init(argc,argv); in = sf_input ("in"); dip = sf_input ("dip"); out = sf_output ("out"); if (SF_FLOAT != sf_gettype(in) || SF_FLOAT != sf_gettype(dip)) sf_error("Need float type"); if (!sf_histint(in,"n1",&n1)) sf_error("Need n1= in input"); if (!sf_histint(in,"n2",&n2)) n2=1; if (!sf_histint(in,"n3",&n3)) n3=1; n12 = n1*n2; nr = sf_leftsize(in,2); if (!sf_histint(dip,"n1",&m1) || m1 != n1) sf_error("Need n1=%d in dip",n1); if (1 != n2 && (!sf_histint(dip,"n2",&m2) || m2 != n2)) sf_error("Need n2=%d in dip",n2); if (1 != n3 && (!sf_histint(dip,"n3",&m3) || m3 != n3)) sf_error("Need n3=%d in dip",n3); if (NULL != sf_getstring("aniso")) aniso = sf_input("aniso"); /*aniso field */ else aniso = NULL ; if (!sf_getint("order",&nw)) nw=1; /* accuracy */ if (!sf_getbool("verb",&verb)) verb = false; /* verbosity flag */ if (!sf_getint("nj1",&nj1)) nj1=1; /* aliasing */ nj2 = 1; n3 = 1; for (ir=0; ir < nr; ir++) { if (verb) sf_warning("slice %d of %d", ir+1, nr); u1 = sf_floatalloc(n12); u2 = sf_floatalloc(n12); p = sf_floatalloc(n12); ani = sf_floatalloc(n12); for (i3=0; i3 < n3; i3++) { int i12; /* read data */ sf_floatread(u1,n12,in); /* read t-x dip */ sf_floatread(p,n12,dip); if (NULL != aniso) sf_floatread(ani,n12,aniso); else for (i12=0; i12<n12; i12++) { ani[i12]=1; } ap = allpass_init (nw,nj1,n1,n2,1,p,ani); /* apply */ allpass1(false, ap, u1, u2); /* write t-x destruction */ sf_floatwrite(u2,n12,out); } free(u1); free(u2); free(p); } exit (0); }
int main(int argc, char* argv[]) { int n[SF_MAX_DIM], a[SF_MAX_DIM], center[SF_MAX_DIM], gap[SF_MAX_DIM]; int *pch, *nh, dim, n123, nf, i, niter, nbf, nbp, id, ip, ig, np; int *kk, *pp; float *dd, eps, dabs, di; nfilter aa, bb; char varname[6], *lagfile; sf_file in, flt, lag, mask, patch, reg; sf_init(argc,argv); in = sf_input("in"); flt = sf_output("out"); dim = sf_filedims(in,n); if (NULL == (lagfile = sf_getstring("lag"))) sf_error("Need lag="); /* output file for filter lags */ lag = sf_output(lagfile); sf_settype(lag,SF_INT); sf_putstring(flt,"lag",lagfile); sf_putints(lag,"n",n,dim); if (!sf_getints("a",a,dim)) sf_error("Need a="); if (!sf_getints("center",center,dim)) { for (i=0; i < dim; i++) { center[i] = (i+1 < dim && a[i+1] > 1)? a[i]/2: 0; } } if (!sf_getints("gap",gap,dim)) { for (i=0; i < dim; i++) { gap[i] = 0; } } n123 = 1; for (i=0; i < dim; i++) { n123 *= n[i]; } dd = sf_floatalloc(n123); kk = sf_intalloc(n123); if (NULL != sf_getstring("maskin")) { /* optional input mask file */ mask = sf_input("maskin"); switch (sf_gettype(mask)) { case SF_INT: sf_intread (kk,n123,mask); break; case SF_FLOAT: sf_floatread (dd,n123,mask); for (i=0; i < n123; i++) { kk[i] = (dd[i] != 0.); } break; default: sf_error ("Wrong data type in maskin"); break; } sf_fileclose (mask); } else { for (i=0; i < n123; i++) { kk[i] = 1; } } sf_floatread(dd,n123,in); dabs = fabsf(dd[0]); for (i=1; i < n123; i++) { di = fabsf(dd[i]); if (di > dabs) dabs=di; } random_init(2004); for (i=0; i < n123; i++) { dd[i] = dd[i]/dabs+ 100.*FLT_EPSILON*(random0()-0.5);; } pp = sf_intalloc(n123); if (NULL != sf_getstring("pch")) { patch = sf_input("pch"); if (SF_INT != sf_gettype(patch)) sf_error("Need int pch"); sf_intread(pp,n123,patch); np = pp[0]; for (i=1; i < n123; i++) { if (pp[i] > np) np = pp[i]; } sf_fileclose(patch); } else { np = n123; for (i=0; i < n123; i++) { pp[i] = i; } } aa = createnhelix(dim, n, center, gap, a, pp); free (pp); nf = aa->hlx[0]->nh; nfind_mask(n123, kk, aa); if(!sf_getint("niter",&niter)) niter=100; /* number of iterations */ if (!sf_getfloat("epsilon",&eps)) eps=0.01; /* regularization parameter */ sf_putint(flt,"n1",nf); sf_putint(flt,"n2",np); sf_putint(lag,"n1",nf); sf_putint(lag,"n2",np); for (i=2; i < dim; i++) { sprintf(varname,"n%d",i+1); sf_putint(flt,varname,1); sf_putint(lag,varname,1); } for (ip=0; ip < np; ip++) { sf_intwrite(aa->hlx[ip]->lag,nf,lag); } sf_fileclose(lag); if (NULL != sf_getstring("maskout")) { /* optional output mask file */ mask = sf_output("maskout"); for (i=0; i < n123; i++) { kk[i] = aa->mis[i]? 0.: 1.; } sf_settype(mask,SF_INT); sf_intwrite (kk,n123,mask); } reg = sf_input("filt"); if (!sf_histint(reg,"n1",&nbf)) sf_error("No n1= in filt"); if (!sf_histint(reg,"n2",&nbp)) sf_error("No n2= in filt"); if (NULL != sf_getstring("filt_pch")) { patch = sf_input("filt_pch"); if (SF_INT != sf_gettype(patch)) sf_error("Need int filt_pch"); pp = sf_intalloc(np); sf_intread(pp,np,patch); } else { if (nbp != np) sf_error ("Wrong filter size: %d != %d",nbp,np); pp = NULL; } pch = sf_intalloc(nf*np); nh = sf_intalloc(nbp); for (i=0; i < nbp; i++) { nh[i] = nbf; } for (id=ig=0; ig < nf; ig++) { for (ip=0; ip < np; ip++, id++) { pch[id] = (NULL != pp)? pp[ip]: ip; } } bb = nallocate (nbp, nf*np, nh, pch); if (NULL == (lagfile = sf_getstring("filt_lag")) && NULL == (lagfile = sf_histstring(reg,"lag"))) sf_error("Need filt_lag="); /* input file for double-helix filter lags */ lag = sf_input(lagfile); if (SF_INT != sf_gettype(lag)) sf_error("Need int filt_lag"); for (ip=0; ip < nbp; ip++) { sf_intread (kk,nbf,lag); for (i=0; i < nbf; i++) { bb->hlx[ip]->lag[i] = kk[i]*nf; } } for (ip=0; ip < nbp; ip++) { sf_floatread (bb->hlx[ip]->flt,nbf,reg); } nfind_pef (n123, dd, aa, bb, niter, eps, nf); for (ip=0; ip < np; ip++) { sf_floatwrite (aa->hlx[ip]->flt,nf,flt); } exit(0); }
int main(int argc, char* argv[]) { int nt, nx, it, ix, niter, iter, ntfft, nxfft,np, ip, ikt, ikx, iktn, ikxn, ifsnr; /* iktn, ikxn, iNyquist*/ float dt, dx, pmin, pmax, dp, p, cmax, scalar, sembpmax, num, den; float *sembp, *mask, *gy, *fden, *fshift, *SNR; float **fdata, **taup, **odata, **tdata, **odatat, **semb; /* tdata is the true data */ kiss_fft_cpx **cdata, **cdatat; char *type; sf_file inp, outp, m, spec1, spec2, trued, snr; sf_init(argc,argv); inp=sf_input("in"); m=sf_input("mask"); outp=sf_output("out"); if(!sf_histint(inp,"n1",&nt)) sf_warning("No n1 in input"); if(!sf_histint(inp,"n2",&nx)) sf_warning("No n2 in input"); if(!sf_histfloat(inp,"d1",&dt)) sf_warning("No n1 in input"); if(!sf_histfloat(inp,"d2",&dx)) sf_warning("No n2 in input"); ntfft = 2*kiss_fft_next_fast_size((nt+1)/2); nxfft = 2*kiss_fft_next_fast_size((nx+1)/2); scalar = 1./(ntfft*nxfft); iktn=ntfft/2; ikxn=nxfft/2; float dkt = 1.0/(ntfft*dt), fkt = 0.0,kt; float dkx = 1.0/(nxfft*dx), fkx = 0.0,kx; if (NULL == (type=sf_getstring("type"))) type="amplitude"; /* [amplitude, semblance] thresholding type, the default is amplitude thresholding */ if(!sf_getint("niter",&niter)) niter = 10; /* Get the number of iterations */ if(!sf_getint("ifsnr",&ifsnr)) ifsnr = 0; /* If compute SNR during iteration */ if(type[0]=='s') { if(!sf_getfloat("pmin",&pmin)) pmin=-2; /* minimum p */ if(!sf_getfloat("pmax",&pmin)) pmax=2; /* maximum p */ if(!sf_getint("np",&np)) np=nx; /* number of p */ dp=(pmax-pmin)/(np-1); sembp =sf_floatalloc(np); semb =sf_floatalloc2(nt,np); taup =sf_floatalloc2(nt,np); } /* output files */ if (NULL!=sf_getstring("spec2")) { spec2=sf_output("spec2"); sf_putint(spec2, "n1", ntfft); sf_putint(spec2, "n2", nxfft); } if (NULL!=sf_getstring("spec1")) { spec1=sf_output("spec1"); sf_putint(spec1, "n1", ntfft); sf_putint(spec1, "n2", nxfft); } if (ifsnr==1 && (NULL!=sf_getstring("true"))) { snr=sf_output("snr"); trued=sf_input("true"); tdata=sf_floatalloc2(nt,nx); SNR=sf_floatalloc(niter); sf_floatread(tdata[0],nt*nx,trued); sf_putint(snr,"n1",niter); sf_putint(snr,"d1",1); sf_putint(snr,"n2",1); } /* Allocate memory */ cdata =(kiss_fft_cpx**) sf_complexalloc2(ntfft,nxfft); cdatat =(kiss_fft_cpx**) sf_complexalloc2(ntfft,nxfft); /* temporary file */ fshift= sf_floatalloc(ntfft); fden = sf_floatalloc(ntfft); gy = sf_floatalloc(nxfft); mask =sf_floatalloc(nx); odata =sf_floatalloc2(nt,nx); odatat =sf_floatalloc2(ntfft,nxfft); fdata =sf_floatalloc2(ntfft,nxfft); memset(&odata[0][0],0,ntfft*nxfft*sizeof(float)); /* Read data */ sf_floatread(odata[0],nt*nx,inp); sf_floatread(mask,nx,m); if(type[0]=='s') { slant(dt,nt,nx,gy,pmin,dp,np,odata,taup,semb,sembp,&sembpmax,fshift,fden); } for (iter=niter-1; iter>=0; iter--) { tfft(odata, cdatat, nx, ntfft); xfft(cdatat, cdata, ntfft, nxfft); cmax = findmax(nxfft,ntfft,cdata); if (iter==0 || iter==niter-1) { // beginning and ending spectra for (ix=0; ix<nxfft; ix++) for (it=0; it<ntfft; it++) fdata[ix][it] = sf_cabsf(cdata[ix][it]); if (iter==0 && (NULL!=sf_getstring("spec2"))) sf_floatwrite(fdata[0],ntfft*nxfft,spec2); if (iter==niter-1 && (NULL!=sf_getstring("spec1"))) sf_floatwrite(fdata[0],ntfft*nxfft,spec1); } if(type[0]=='a') { for (ix=0; ix<nxfft; ix++) // Abma Kabir FT amplitude thresholding for (it=0; it<ntfft; it++) if (sf_cabsf(cdata[ix][it])<iter*1./niter*cmax) cdata[ix][it] = cmplx(0.,0.); } else { for (ix=0; ix<nxfft; ix++) // Abma Kabir FT amplitude thresholding for (it=0; it<ntfft; it++) if (sf_cabsf(cdata[ix][it])<iter*1./niter*cmax) cdata[ix][it] = cmplx(0.,0.); for (ikx=0,kx=fkx; ikx<=ikxn; ++ikx,kx+=dkx) { for (ikt=0,kt=fkt; ikt<=iktn; ++ikt,kt+=dkt) { if (kx==0) { if (sf_cabsf(cdata[ikx][ikt])<iter*1./niter*cmax) cdata[ikx][ikt] = cmplx(0.,0.); continue; } p = -kx/kt; ip = round((p-pmin)/dp); //if (ip<0 || ip>=np) { cdata[ikx][ikt] = 0.;continue; } if (ip<0 || ip>=np) { } else if (sembp[ip] <iter*1./niter*sembpmax) cdata[ikx][ikt] = cmplx(0.,0.); if (ikx>0 && ikx<(nxfft+1)/2) { // kx>=0, kx<0 p = kx/kt; ip = round((p-pmin)/dp); //if (ip<0 || ip>=np) { cdata[nxfft-ikx][ikt] = 0.;continue; } if (ip<0 || ip>=np) { } else if (sembp[ip] <iter*1./niter*sembpmax) cdata[nxfft-ikx][ikt] = cmplx(0.,0.); } if (ikt>0 && ikt<(ntfft+1)/2) { // kt<0, kx>=0 p = kx/kt; ip = round((p-pmin)/dp); //if (ip<0 || ip>=np) { cdata[ikx][ntfft-ikt] = 0.;continue; } if (ip<0 || ip>=np) { } else if (sembp[ip] <iter*1./niter*sembpmax) cdata[ikx][ntfft-ikt] = cmplx(0.,0.); } if (ikx>0 && ikx<(nxfft+1)/2 && ikt>0 && ikt<(ntfft+1)/2) { // kt<0, kx<0 p = -kx/kt; ip = round((p-pmin)/dp); //if (ip<0 || ip>=np) { cdata[nxfft-ikx][ntfft-ikt] = 0.;continue; } if (ip<0 || ip>=np) { } else if (sembp[ip] <iter*1./niter*sembpmax) cdata[nxfft-ikx][ntfft-ikt] =cmplx(0.,0.); } }} } ixfft(cdata, cdatat, ntfft, nxfft); itfft(cdatat, odatat, nxfft, ntfft); for (ix=0; ix<nx; ix++) { // put in ORIGINAL KNOWN data if (mask[ix]==1) continue; for (it=0; it<nt; it++) odata[ix][it]=odatat[ix][it]; } num=0;den=0; /* If output the SNR file. */ if (ifsnr==1 && (NULL!=sf_getstring("true"))) { for(ix=0;ix<nx;ix++) for(it=0;it<nt;it++) { num+=tdata[ix][it]*tdata[ix][it]; den+=(tdata[ix][it]-odata[ix][it])*(tdata[ix][it]-odata[ix][it]); } SNR[niter-iter-1]=10*logf(num/den); } } if (ifsnr==1 && (NULL!=sf_getstring("true"))) { sf_floatwrite(SNR,niter,snr); } sf_floatwrite(odata[0],nt*nx,outp); exit (0); }
int main(int argc, char* argv[]) { int niter, nd, n1, n2, i1, i2; float **vr, **vi, **wt, **v0, **bk, *tmp, wti, perc; sf_file vrms, vint, weight, vout, block; sf_init(argc,argv); vrms = sf_input("in"); vint = sf_output("out"); weight = sf_input("weight"); block = sf_input("block"); if (!sf_histint(vrms,"n1",&n1)) sf_error("No n1= in input"); n2 = sf_leftsize(vrms,1); nd = n1*n2; vr = sf_floatalloc2(n1,n2); vi = sf_floatalloc2(n1,n2); wt = sf_floatalloc2(n1,n2); v0 = sf_floatalloc2(n1,n2); bk = sf_floatalloc2(n1,n2); tmp = sf_floatalloc(n1); sf_floatread(vr[0],nd,vrms); sf_floatread(wt[0],nd,weight); sf_floatread(bk[0],nd,block); if (!sf_getfloat("perc",&perc)) perc=50.0; /* percentage for sharpening */ blockder_init(n1, n2, perc, bk[0], wt[0]); if (!sf_getint("niter",&niter)) niter=100; /* maximum number of iterations */ wti = 0.; for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1; i1++) { wti += wt[i2][i1]*wt[i2][i1]; } } if (wti > 0.) wti = sqrtf(n1*n2/wti); for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1; i1++) { vr[i2][i1] *= vr[i2][i1]*(i1+1.0f); /* vrms^2*t - data */ wt[i2][i1] *= wti/(i1+1.0f); /* decrease weight with time */ v0[i2][i1] = -vr[i2][0]; } sf_causint_lop(false,true,n1,n1,v0[i2],vr[i2]); } blockder(niter, vr[0], vi[0]); for (i2=0; i2 < n2; i2++) { sf_causint_lop(false,false,n1,n1,vi[i2],tmp); for (i1=0; i1 < n1; i1++) { vi[i2][i1] = tmp[i1] - v0[i2][i1]; } sf_causint_lop(false,false,n1,n1,vi[i2],vr[i2]); } for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1; i1++) { vr[i2][i1] = sqrtf(fabsf(vr[i2][i1]/(i1+1.0f))); vi[i2][i1] = sqrtf(fabsf(vi[i2][i1])); } } sf_floatwrite(vi[0],nd,vint); if (NULL != sf_getstring("vrmsout")) { /* optionally, output predicted vrms */ vout = sf_output("vrmsout"); sf_floatwrite(vr[0],nd,vout); } exit(0); }
int main (int argc,char* argv[]) { int b1, b2, b3, n1, n2, n3, i, nshot, ndim, is,n123, /* **p, */ j; float br1, br2, br3, o1, o2, o3, d1, d2, d3; float **s, **t, **v, **vv,**vs,**q,**a,**sg,**bet; char *sfile, *file; bool plane[3]; sf_file vvf, bv, eta, time, shots; sf_init (argc, argv); bv = sf_input("in"); time = sf_output("out"); if (SF_FLOAT != sf_gettype(bv)) sf_error("Need float input"); if (NULL != (file = sf_getstring("vv"))) { vvf = sf_input(file); free(file); } else { vvf = NULL; } if (NULL != (file = sf_getstring("eta"))) { eta = sf_input(file); free(file); } else { eta = NULL; } if(!sf_histint(bv,"n1",&n1)) sf_error("No n1= in input"); if(!sf_histint(bv,"n2",&n2)) sf_error("No n2= in input"); if(!sf_histint(bv,"n3",&n3)) n3=1; if (n1 <2 || n2<2) sf_error("n1 and n2 muxt be bigger than 1"); if(!sf_histfloat(bv,"d1",&d1)) sf_error("No d1= in input"); if(!sf_histfloat(bv,"d2",&d2)) sf_error("No d2= in input"); if(!sf_histfloat(bv,"d3",&d3)) d3=d2; if(!sf_histfloat(bv,"o1",&o1)) o1=0.; if(!sf_histfloat(bv,"o2",&o2)) o2=0.; if(!sf_histfloat(bv,"o3",&o3)) o3=0.; /* if y, the input is background time; n, Velocity */ /* The value of the constant eta */ if(!sf_getfloat("br1",&br1)) br1=d1; if(!sf_getfloat("br2",&br2)) br2=d2; if(!sf_getfloat("br3",&br3)) br3=d3; /* Constant-velocity box around the source (in physical dimensions) */ if(!sf_getbool("plane1",&plane[2])) plane[2]=false; if(!sf_getbool("plane2",&plane[1])) plane[1]=false; if(!sf_getbool("plane3",&plane[0])) plane[0]=false; /* plane-wave source */ if(!sf_getint("b1",&b1)) b1= plane[2]? n1: (int) (br1/d1+0.5); if(!sf_getint("b2",&b2)) b2= plane[1]? n2: (int) (br2/d2+0.5); if(!sf_getint("b3",&b3)) b3= plane[0]? n3: (int) (br3/d3+0.5); /* Constant-velocity box around the source (in samples) */ if( b1<1 ) b1=1; if( b2<1 ) b2=1; if( b3<1 ) b3=1; sfile = sf_getstring("shotfile"); /* File with shot locations (n2=number of shots, n1=3) */ if(NULL != sfile) { shots = sf_input("shotfile"); if (SF_FLOAT != sf_gettype(shots)) sf_error("Need float shotfile"); if(!sf_histint(shots,"n2",&nshot)) sf_error("No n2= in shotfile"); if(!sf_histint(shots,"n1",&ndim) || ndim != 3) sf_error("Need n1=3 in shotfile"); s = sf_floatalloc2 (ndim,nshot); sf_floatread(s[0],nshot*ndim,shots); sf_fileclose(shots); sf_putint (time,"n4",nshot); free (sfile); } else { nshot = 1; ndim = 3; s = sf_floatalloc2 (ndim,nshot); if(!sf_getfloat("zshot",&s[0][0]) ) s[0][0]=0.; /* Shot location (used if no shotfile) */ if(!sf_getfloat("yshot",&s[0][1])) s[0][1]=o2 + 0.5*(n2-1)*d2; if(!sf_getfloat("xshot",&s[0][2])) s[0][2]=o3 + 0.5*(n3-1)*d3; sf_warning("Shooting from zshot=%g yshot=%g xshot=%g", s[0][0],s[0][1],s[0][2]); } n123 = n1*n2*n3; t = sf_floatalloc2(n1,n2); v = sf_floatalloc2(n1,n2); vv = sf_floatalloc2(n1,n2); vs = sf_floatalloc2(n1,n2); q = sf_floatalloc2(n1,n2); a = sf_floatalloc2(n1,n2); bet = sf_floatalloc2(n1,n2); sg = sf_floatalloc2(n1,n2); /* p = sf_intalloc2(n1,n2); */ sf_floatread(v[0],n123,bv); if (NULL != vvf) { sf_floatread(vv[0],n123,vvf); sf_fileclose(vvf); /* transform velocity to slowness squared */ for(j = 0; j < n2; j++) for(i = 0; i < n1; i++) vv[j][i] = vv[j][i]*vv[j][i]; } else { for(j = 0; j < n2; j++) for(i = 0; i < n1; i++) vv[j][i] = v[j][i]*v[j][i]; } if(NULL != eta) { sf_floatread(q[0],n123,eta); sf_fileclose(eta); /* transform eta to q */ } else { /* assume elliptic anisotropy */ for(j = 0; j < n2; j++) for(i = 0; i < n1; i++) q[j][i] = 0.; } for(j = 0; j < n2; j++) for(i = 0; i < n1; i++){ v[j][i] = v[j][i]*v[j][i]*(1+2*q[j][i]); vs[j][i] = 0.25*vv[j][i]; q[j][i] = vv[j][i]-2*vs[j][i]; }; /* loop over shots and find traveltime for source perturbation*/ for( is = 0; is < nshot; is++) { wkbjti(s[is][1],s[is][0],n1,d1,o1,n2,d2,o2,v,vv,vs,q,t,a,sg,bet); sf_floatwrite (t[0],n123,time); } /* close input */ sf_fileclose(bv); exit (0); }
int main(int argc, char* argv[]) { bool hermite_false, hermite_true; int n1, n2, npml, pad1, pad2, ns, nw; float d1, d2, **v, ds, os, dw, ow; sf_complex ****f, ****obs; sf_file in, out, misfit, source, receiver, record; char *order; int uts, mts, is, i, j, iw, iter, niter; float **recloc; float **m_old, **m_new; float **d_new, **d_old; float **g_old, **g_new; sf_complex ****r_new, ****r_old; sf_complex ****Fg; float alpha, beta, gnorm, rnorm; float *datamisfit; sf_init(argc, argv); in = sf_input("in"); out = sf_output("out"); misfit = sf_output("misfit"); if (!sf_getint("uts",&uts)) uts=0; //#ifdef _OPENMP // mts = omp_get_max_threads(); //#else mts = 1; //#endif uts = (uts < 1)? mts: uts; hermite_false=false; hermite_true=true; /* Hermite operator */ if (!sf_getint("npml",&npml)) npml=20; /* PML width */ if (!sf_getint("niter",&niter)) niter=0; /* Number of iterations */ if (NULL == (order = sf_getstring("order"))) order="c"; /* discretization scheme (default optimal 9-point) */ fdprep_order(order); /* read input dimension */ if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input."); if (!sf_histint(in,"n2",&n2)) sf_error("No n2= in input."); if (!sf_histfloat(in,"d1",&d1)) sf_error("No d1= in input."); if (!sf_histfloat(in,"d2",&d2)) sf_error("No d2= in input."); v = sf_floatalloc2(n1,n2); sf_floatread(v[0],n1*n2,in); /* PML padding */ pad1 = n1+2*npml; pad2 = n2+2*npml; /* read receiver */ if (NULL == sf_getstring("receiver")) sf_error("Need receiver="); receiver = sf_input("receiver"); recloc=sf_floatalloc2(n1,n2); sf_floatread(recloc[0],n1*n2,receiver); /* read source */ if (NULL == sf_getstring("source")) sf_error("Need source="); source = sf_input("source"); if (!sf_histint(source,"n3",&ns)) sf_error("No ns=."); if (!sf_histfloat(source,"d3",&ds)) ds=d2; if (!sf_histfloat(source,"o3",&os)) os=0.; /* read observed data */ if (NULL == sf_getstring("record")) sf_error("Need record="); record = sf_input("record"); if (!sf_histint(record,"n4",&nw)) sf_error("No nw=."); if (!sf_histfloat(record,"d4",&dw)) sf_error("No dw=."); if (!sf_histfloat(record,"o4",&ow)) sf_error("No ow=."); f = sf_complexalloc4(n1,n2,ns,nw); obs = sf_complexalloc4(n1,n2,ns,nw); sf_complexread(f[0][0][0],n1*n2*ns*nw,source); sf_complexread(obs[0][0][0],n1*n2*ns*nw,record); /* allocate variables */ m_old = sf_floatalloc2(n1,n2); m_new = sf_floatalloc2(n1,n2); d_old = sf_floatalloc2(n1,n2); d_new = sf_floatalloc2(n1,n2); g_old = sf_floatalloc2(n1,n2); g_new = sf_floatalloc2(n1,n2); r_old = sf_complexalloc4(n1,n2,ns,nw); r_new = sf_complexalloc4(n1,n2,ns,nw); Fg = sf_complexalloc4(n1,n2,ns,nw); /* set output dimension */ sf_putint(out,"n1",n1); sf_putint(out,"n2",n2); sf_putint(out,"n3",niter); sf_putint(misfit,"n1",niter); sf_putfloat(misfit,"d1",1); sf_putint(misfit,"n2",1); datamisfit = sf_floatalloc(niter); rnorm = 0.0; for ( iw = 0; iw < nw; iw ++ ) { for ( is = 0; is < ns; is ++) { for ( j = 0; j < n2 ; j++ ) { for ( i = 0; i < n1; i++ ) { r_old[iw][is][j][i] = obs[iw][is][j][i]; if ( recloc[j][i] > 0.0 ) { rnorm += cabsf( r_old[iw][is][j][i] * r_old[iw][is][j][i] ); } } } } } sf_warning("rnorm = %g.",rnorm); sf_warning("Adjoint calculation for the first iteration."); /* adjoint calculation */ adjlsm_operator(nw, ow, dw, ns, n1, n2, uts, pad1, pad2, npml, d1, d2, hermite_false, hermite_true, v, f, recloc, r_old, g_old); /* set starting valuables */ for (j = 0; j < n2; j++) { for (i = 0; i < n2; i++ ) { d_old[j][i] = g_old[j][i]; m_old[j][i] = 0.0; } } for ( iter = 0; iter < niter; iter ++ ) { sf_warning("Calculating iteration %d out of %d.",iter,niter); /* born forward operator */ bornsyn_operator(nw, ow, dw, ns, n1, n2, uts, pad1, pad2, npml, d1, d2, hermite_false, v, f, recloc, d_old, Fg); /* calculate alpha value */ alpha = calc_alpha(g_old, Fg, recloc, n1, n2, ns, nw); /* update model */ update_model_lsm(m_old, m_new, d_old, alpha, n1, n2); /* update residual */ update_residual(r_old, r_new, Fg, recloc, alpha, n1, n2, ns, nw); /* adjoint operator */ adjlsm_operator(nw, ow, dw, ns, n1, n2, uts, pad1, pad2, npml, d1, d2, hermite_false, hermite_true, v, f, recloc, r_new, g_new); /* update direction */ beta = direction_cg_fletcher(g_old, d_old, g_new, d_new, n1, n2); sf_warning("alpha = %g, beta = %g.",alpha, beta); /* update vectors */ gnorm = 0.0 ; for (j = 0; j < n2; j++ ) { for (i = 0; i < n1; i++ ) { d_old[j][i] = d_new[j][i]; g_old[j][i] = g_new[j][i]; m_old[j][i] = m_new[j][i]; gnorm += g_old[j][i] * g_old[j][i]; } } rnorm = 0.0 ; for (iw = 0; iw < nw; iw ++ ) { for (is = 0; is < ns; is ++ ) { for (j = 0; j < n2; j ++ ) { for (i = 0; i < n1; i ++ ) { r_old[iw][is][j][i] = r_new[iw][is][j][i]; if ( recloc[j][i] > 0.0 ) { rnorm += cabsf( r_old[iw][is][j][i] * r_old[iw][is][j][i] ); } } } } } sf_warning("gnorm = %g; rnorm = %g.",gnorm, rnorm); datamisfit[iter] = rnorm; sf_floatwrite(m_old[0],n1*n2,out); } /* end iteration */ sf_floatwrite(datamisfit, niter, misfit); exit(0); }
int main(int argc, char* argv[]) { int i, j, is, ip, dim, n[SF_MAX_DIM], ii[SF_MAX_DIM]; int nsp, **k=NULL, **l=NULL, n1, n2, i1, i2, kk, ll; char key[7]; const char *label, *unit; float f, *trace, *mag=NULL, **p=NULL, pp; sf_file in, spike; sf_init (argc,argv); if (!sf_stdin()) { /* no input file in stdin */ in = NULL; } else { in = sf_input("in"); } spike = sf_output("out"); if (NULL == in) { sf_setformat(spike,"native_float"); } else if (SF_FLOAT != sf_gettype(in)) { sf_error("Need float input"); } /* dimensions */ for (i=0; i < SF_MAX_DIM; i++) { snprintf(key,3,"n%d",i+1); if (!sf_getint(key,n+i) && (NULL == in || !sf_histint(in,key,n+i))) break; /*( n# size of #-th axis )*/ sf_putint(spike,key,n[i]); } if (0==i) sf_error("Need n1="); dim=i; /* basic parameters */ for (i=0; i < dim; i++) { snprintf(key,3,"o%d",i+1); if (!sf_getfloat(key,&f) && (NULL == in || !sf_histfloat(in,key,&f))) f=0.; /*( o#=[0,0,...] origin on #-th axis )*/ sf_putfloat(spike,key,f); snprintf(key,3,"d%d",i+1); if (!sf_getfloat(key,&f) && (NULL == in || !sf_histfloat(in,key,&f))) f = (i==0)? 0.004: 0.1; /*( d#=[0.004,0.1,0.1,...] sampling on #-th axis )*/ sf_putfloat(spike,key,f); snprintf(key,7,"label%d",i+1); if (NULL == (label = sf_getstring(key)) && (NULL == in || NULL == (label = sf_histstring(in,key)))) label = (i==0)? "Time":"Distance"; /*( label#=[Time,Distance,Distance,...] label on #-th axis )*/ if (*label != '\0' && (*label != ' ' || *(label+1) != '\0')) sf_putstring(spike,key,label); snprintf(key,6,"unit%d",i+1); if (NULL == (unit = sf_getstring(key)) && (NULL == in || NULL == (unit = sf_histstring(in,key)))) unit = (i==0)? "s":"km"; /*( unit#=[s,km,km,...] unit on #-th axis )*/ if (*unit != '\0' && (*unit != ' ' || *(unit+1) != '\0')) sf_putstring(spike,key,unit); } if (NULL != (label = sf_getstring("title"))) sf_putstring(spike,"title",label); /* title for plots */ if (!sf_getint("nsp",&nsp)) nsp=1; /* Number of spikes */ if (nsp >= 1) { mag = sf_floatalloc (nsp); k = sf_intalloc2 (nsp,dim); l = sf_intalloc2 (nsp,dim); p = sf_floatalloc2 (nsp,dim); for (i=0; i < dim; i++) { snprintf(key,3,"k%d",i+1); if ( !sf_getints(key,k[i],nsp)) { /*( k#=[0,...] spike starting position )*/ for (is=0; is < nsp; is++) { k[i][is]=-1; } } else { for (is=0; is < nsp; is++) { if (k[i][is] > n[i]) sf_error("Invalid k%d[%d]=%d > n%d=%d", i+1,is+1,k[i][is],i+1,n[i]); k[i][is]--; /* C notation */ } } snprintf(key,3,"l%d",i+1); if (!sf_getints(key,l[i],nsp)) { /*( l#=[k1,k2,...] spike ending position )*/ for (is=0; is < nsp; is++) { l[i][is]=k[i][is]; } } else { for (is=0; is < nsp; is++) { if (l[i][is] > n[i]) sf_error("Invalid l%d[%d]=%d > n%d=%d", i+1,is+1,l[i][is],i+1,n[i]); l[i][is]--; /* C notation */ } } snprintf(key,3,"p%d",i+1); if (!sf_getfloats(key,p[i],nsp)) { /*( p#=[0,...] spike inclination (in samples) )*/ for (is=0; is < nsp; is++) { p[i][is]=0.; } } } if (!sf_getfloats("mag",mag,nsp)) { /* spike magnitudes */ for (is=0; is < nsp; is++) { mag[is]=1.; } } } n1 = n[0]; n2 = sf_leftsize(spike,1); trace = sf_floatalloc (n[0]); for (i2=0; i2 < n2; i2++) { /* loop over traces */ sf_line2cart(dim-1, n+1, i2, ii+1); /* zero trace */ for (i1=0; i1 < n1; i1++) trace[i1]=0.; /* put spikes in it */ for (is=0; is < nsp; is++) { /* loop over spikes */ pp = 0.; for (i=1; i < dim; i++) { kk = k[i][is]; ll = l[i][is]; if ((kk < -1 && ll < -1) || (kk >= 0 && ll >= 0 && (kk > ii[i] || ll < ii[i]))) break; pp += p[i][is]*(ii[i]-k[i][is]-1); } if (i < dim) continue; /* skip this spike */ /* linear interpolation */ ip = floorf(pp); pp = 1.-(pp-ip); kk = k[0][is]; ll = l[0][is]; if (kk >= 0) { /* one segment per trace */ kk = SF_MAX(kk+ip,0); ll = SF_MIN(ll+ip,n1-1); } else { kk = SF_MAX(ip,0); ll = SF_MIN(n1-1+ip,n1-1); } for (j=kk; j <= ll; j++) { trace[j] += pp*mag[is]; if (j+1 < n1) trace[j+1] += (1.-pp)*mag[is]; } } sf_floatwrite(trace,n1,spike); } exit (0); }
int main (int argc,char* argv[]) { int i, j, ip, n1, n2, np, ndim, order, n123, *pp, n[2], box[2], **shift, b; float o1, o2, d1, d2, slow, *dd, **pts, *vv, *h, *bin, *vor, d[2], **rect; bool isvel, dist, voro; sf_upgrad upg; sf_file coord, ord, grid, vel; sf_init (argc, argv); ord = sf_input("in"); coord = sf_input("coord"); grid = sf_output("out"); if (NULL != sf_getstring("velocity")) { vel = sf_input("velocity"); if(!sf_histint(vel,"n1",&n1)) sf_error("No n1= in vel"); if(!sf_histint(vel,"n2",&n2)) sf_error("No n2= in vel"); /* dimensions */ if(!sf_histfloat(vel,"d1",&d1)) sf_error("No d1= in vel"); if(!sf_histfloat(vel,"d2",&d2)) sf_error("No d2= in vel"); /* sampling */ if(!sf_histfloat(vel,"o1",&o1)) o1=0.; if(!sf_histfloat(vel,"o2",&o2)) o2=0.; /* origin */ } else { vel = NULL; if(!sf_getint("n1",&n1)) sf_error("Need n1="); if(!sf_getint("n2",&n2)) sf_error("Need n2="); /* dimensions */ if(!sf_getfloat("d1",&d1)) sf_error("Need d1="); if(!sf_getfloat("d2",&d2)) sf_error("Need d2="); /* sampling */ if(!sf_getfloat("o1",&o1)) o1=0.; if(!sf_getfloat("o2",&o2)) o2=0.; /* origin */ } sf_putint(grid,"n1",n1); sf_putint(grid,"n2",n2); sf_putfloat(grid,"d1",d1); sf_putfloat(grid,"d2",d2); sf_putfloat(grid,"o1",o1); sf_putfloat(grid,"o2",o2); n[0]=n1; d[0]=d1; n[1]=n2; d[1]=d2; if(!sf_getint("order",&order)) order=2; /* [1,2] Accuracy order for distance calculation */ if(!sf_getbool("vel",&isvel)) isvel=true; /* if y, the input is velocity; n, slowness squared */ if (SF_FLOAT != sf_gettype(coord)) sf_error("Need float input"); if(!sf_histint(coord,"n2",&np)) sf_error("No n2= in input"); if(!sf_histint(coord,"n1",&ndim) || ndim > 3) sf_error("Need n1 <= 3 in input"); pts = sf_floatalloc2 (3,np); for (ip=0; ip < np; ip++) { sf_floatread(pts[ip],ndim,coord); pts[ip][2] = 0.0f; } n123 = n1*n2; dd = sf_floatalloc (n123); vv = sf_floatalloc (n123); pp = sf_intalloc (n123); if (NULL != vel) { sf_floatread(vv,n123,vel); sf_fileclose(vel); /* transform velocity to slowness squared */ if (isvel) { for(i = 0; i < n123; i++) { slow = vv[i]; vv[i] = 1./(slow*slow); } } } else { for(i = 0; i < n123; i++) { vv[i] = 1.; } } /* 1. find distance */ distance_init (1,n2,n1,np); distance(np,pts,dd,vv,pp, 1,n2,n1, 0.,o2,o1, 1.,d2,d1, order); if (!sf_getbool("dist",&dist)) dist=false; /* if output distance */ if (dist) { sf_floatwrite(dd,n123,grid); exit(0); } /* 2. binning */ sf_int2_init (pts, o1,o2,d1,d2,n1,n2, sf_bin_int, 1, np); h = sf_floatalloc(np); for (ip=0; ip<np; ip++) { h[ip]=1.0f; } sf_int2_lop (true,false,n123,np,vv,h); if (SF_FLOAT != sf_gettype(ord)) sf_error("Need float input"); sf_floatread(h,np,ord); bin = sf_floatalloc(n123); sf_int2_lop (true,false,n123,np,bin,h); for (i=0; i < n123; i++) { /* normalize by the fold */ if (vv[i] > FLT_EPSILON) bin[i] /=vv[i]; vv[i]=0.0f; } /* 3. voronoi interpolation */ vor = sf_floatalloc(n123); upg = sf_upgrad_init(2,n,d); sf_upgrad_set(upg,dd); sf_upgrad_solve(upg,vv,vor,bin); if (!sf_getbool("voro",&voro)) voro=false; /* if output Voronoi diagram */ if (voro) { sf_floatwrite(vor,n123,grid); exit(0); } /* 4. smoothing */ rect = sf_floatalloc2(n123,2); shift = sf_intalloc2(n123,2); for (j=0; j < 2; j++) { box[j] = 1; for (i=0; i < n123; i++) { rect[j][i] = 1.0f+dd[i]/d[j]; b = ceilf(rect[j][i]); if (b > box[j]) box[j] = b; shift[j][i] = 0; } } ntrianglen_init(2,box,n,rect,shift,1); ntrianglen_lop(false,false,n123,n123,vor,bin); sf_floatwrite(bin,n123,grid); exit (0); }
int main(int argc, char* argv[]) { /*survey parameters*/ int nx, nz; float dx, dz; int n_srcs; int *spx, *spz; int gpz, gpx, gpl; int gpz_v, gpx_v, gpl_v; int snap; /*fft related*/ bool cmplx; int pad1; /*absorbing boundary*/ bool abc; int nbt, nbb, nbl, nbr; float ct,cb,cl,cr; /*source parameters*/ int src; /*source type*/ int nt,ntsnap; float dt,*f0,*t0,*A; /*misc*/ bool verb, ps, mig; float vref; pspar par; int nx1, nz1; /*domain of interest*/ int it; float *vel,**dat,**dat_v,**wvfld,*img; /*velocity profile*/ sf_file Fi,Fo,Fd,Fd_v,snaps; /* I/O files */ sf_axis az,ax; /* cube axes */ sf_init(argc,argv); if (!sf_getint("snap",&snap)) snap=0; /* interval for snapshots */ if (!sf_getbool("cmplx",&cmplx)) cmplx=true; /* use complex fft */ if (!sf_getint("pad1",&pad1)) pad1=1; /* padding factor on the first axis */ if(!sf_getbool("abc",&abc)) abc=false; /* absorbing flag */ if (abc) { if(!sf_getint("nbt",&nbt)) sf_error("Need nbt!"); if(!sf_getint("nbb",&nbb)) nbb = nbt; if(!sf_getint("nbl",&nbl)) nbl = nbt; if(!sf_getint("nbr",&nbr)) nbr = nbt; if(!sf_getfloat("ct",&ct)) sf_error("Need ct!"); if(!sf_getfloat("cb",&cb)) cb = ct; if(!sf_getfloat("cl",&cl)) cl = ct; if(!sf_getfloat("cr",&cr)) cr = ct; } else { nbt = 0; nbb = 0; nbl = 0; nbr = 0; ct = 0; cb = 0; cl = 0; cr = 0; } if (!sf_getbool("verb",&verb)) verb=false; /* verbosity */ if (!sf_getbool("ps",&ps)) ps=false; /* use pseudo-spectral */ if (ps) sf_warning("Using pseudo-spectral..."); else sf_warning("Using pseudo-analytical..."); if (!sf_getbool("mig",&mig)) mig=false; /* use pseudo-spectral */ if (mig) sf_warning("Time-reversal propagation"); else sf_warning("Forward modeling"); if (!sf_getfloat("vref",&vref)) vref=1500; /* reference velocity (default using water) */ /* setup I/O files */ Fi = sf_input ("in"); Fo = sf_output("out"); if (mig) { gpl = -1; gpl_v = -1; if (NULL==sf_getstring("dat") && NULL==sf_getstring("dat_v")) sf_error("Need Data!"); if (NULL!=sf_getstring("dat")) { Fd = sf_input("dat"); sf_histint(Fd,"n1",&nt); sf_histfloat(Fd,"d1",&dt); sf_histint(Fd,"n2",&gpl); } else Fd = NULL; if (NULL!=sf_getstring("dat_v")) { Fd_v = sf_input("dat_v"); sf_histint(Fd_v,"n1",&nt); sf_histfloat(Fd_v,"d1",&dt); sf_histint(Fd_v,"n2",&gpl_v); } else Fd_v = NULL; src = -1; n_srcs = -1; spx = NULL; spz = NULL; f0 = NULL; t0 = NULL; A = NULL; } else { Fd = NULL; if (!sf_getint("nt",&nt)) sf_error("Need nt!"); if (!sf_getfloat("dt",&dt)) sf_error("Need dt!"); if (!sf_getint("gpl",&gpl)) gpl = -1; /* geophone length */ if (!sf_getint("gpl_v",&gpl_v)) gpl_v = -1; /* geophone height */ if (!sf_getint("src",&src)) src=0; /* source type */ if (!sf_getint("n_srcs",&n_srcs)) n_srcs=1; /* source type */ spx = sf_intalloc(n_srcs); spz = sf_intalloc(n_srcs); f0 = sf_floatalloc(n_srcs); t0 = sf_floatalloc(n_srcs); A = sf_floatalloc(n_srcs); if (!sf_getints("spx",spx,n_srcs)) sf_error("Need spx!"); /* shot position x */ if (!sf_getints("spz",spz,n_srcs)) sf_error("Need spz!"); /* shot position z */ if (!sf_getfloats("f0",f0,n_srcs)) sf_error("Need f0! (e.g. 30Hz)"); /* wavelet peak freq */ if (!sf_getfloats("t0",t0,n_srcs)) sf_error("Need t0! (e.g. 0.04s)"); /* wavelet time lag */ if (!sf_getfloats("A",A,n_srcs)) sf_error("Need A! (e.g. 1)"); /* wavelet amplitude */ } if (!sf_getint("gpx",&gpx)) gpx = -1; /* geophone position x */ if (!sf_getint("gpz",&gpz)) gpz = -1; /* geophone position z */ if (!sf_getint("gpx_v",&gpx_v)) gpx_v = -1; /* geophone position x */ if (!sf_getint("gpz_v",&gpz_v)) gpz_v = -1; /* geophone position z */ if (SF_FLOAT != sf_gettype(Fi)) sf_error("Need float input"); /* Read/Write axes */ az = sf_iaxa(Fi,1); nz = sf_n(az); dz = sf_d(az); ax = sf_iaxa(Fi,2); nx = sf_n(ax); dx = sf_d(ax); nz1 = nz-nbt-nbb; nx1 = nx-nbl-nbr; if (gpx==-1) gpx = nbl; if (gpz==-1) gpz = nbt; if (gpl==-1) gpl = nx1; if (gpx_v==-1) gpx_v = nbl; if (gpz_v==-1) gpz_v = nbt; if (gpl_v==-1) gpl_v = nz1; ntsnap=0; if (snap) for (it=0;it<nt;it++) if (it%snap==0) ntsnap++; if (mig) { /*output final wavefield*/ sf_setn(az,nz1); sf_setn(ax,nx1); sf_oaxa(Fo,az,1); sf_oaxa(Fo,ax,2); sf_settype(Fo,SF_FLOAT); } else { /*output data*/ sf_setn(ax,gpl); /*output horizontal data is mandatory*/ sf_putint(Fo,"n1",nt); sf_putfloat(Fo,"d1",dt); sf_putfloat(Fo,"o1",0.); sf_putstring(Fo,"label1","Time"); sf_putstring(Fo,"unit1","s"); sf_oaxa(Fo,ax,2); sf_settype(Fo,SF_FLOAT); /*output vertical data is optional*/ if (NULL!=sf_getstring("dat_v")) { Fd_v = sf_output("dat_v"); sf_setn(az,gpl_v); sf_putint(Fd_v,"n1",nt); sf_putfloat(Fd_v,"d1",dt); sf_putfloat(Fd_v,"o1",0.); sf_putstring(Fd_v,"label1","Time"); sf_putstring(Fd_v,"unit1","s"); sf_oaxa(Fd_v,az,2); sf_settype(Fd_v,SF_FLOAT); } else Fd_v = NULL; } if (snap > 0) { snaps = sf_output("snaps"); /* (optional) snapshot file */ sf_setn(az,nz1); sf_setn(ax,nx1); sf_oaxa(snaps,az,1); sf_oaxa(snaps,ax,2); sf_putint(snaps,"n3",ntsnap); sf_putfloat(snaps,"d3",dt*snap); sf_putfloat(snaps,"o3",0.); sf_putstring(snaps,"label3","Time"); sf_putstring(snaps,"unit3","s"); } else snaps = NULL; par = (pspar) sf_alloc(1,sizeof(*par)); vel = sf_floatalloc(nz*nx); if (mig && NULL==Fd) dat = NULL; else dat = sf_floatalloc2(nt,gpl); if (NULL!=Fd_v) dat_v = sf_floatalloc2(nt,gpl_v); else dat_v = NULL; if (mig) img = sf_floatalloc(nz1*nx1); else img = NULL; if (snap>0) wvfld = sf_floatalloc2(nx1*nz1,ntsnap); else wvfld = NULL; sf_floatread(vel,nz*nx,Fi); if (mig) { if (NULL!=Fd) sf_floatread(dat[0],gpl*nt,Fd); if (NULL!=Fd_v) sf_floatread(dat_v[0],gpl_v*nt,Fd_v); } /*passing the parameters*/ par->nx = nx; par->nz = nz; par->dx = dx; par->dz = dz; par->n_srcs= n_srcs; par->spx = spx; par->spz = spz; par->gpz = gpz; par->gpx = gpx; par->gpl = gpl; par->gpz_v = gpz_v; par->gpx_v = gpx_v; par->gpl_v = gpl_v; par->snap = snap; par->cmplx = cmplx; par->pad1 = pad1; par->abc = abc; par->nbt = nbt; par->nbb = nbb; par->nbl = nbl; par->nbr = nbr; par->ct = ct; par->cb = cb; par->cl = cl; par->cr = cr; par->src = src; par->nt = nt; par->dt = dt; par->f0 = f0; par->t0 = t0; par->A = A; par->verb = verb; par->ps = ps; par->vref = vref; /*do the work*/ psp(wvfld, dat, dat_v, img, vel, par, mig); if (mig) { sf_floatwrite(img,nz1*nx1,Fo); } else { sf_floatwrite(dat[0],gpl*nt,Fo); if (NULL!=Fd_v) sf_floatwrite(dat_v[0],gpl_v*nt,Fd_v); } if (snap>0) sf_floatwrite(wvfld[0],nz1*nx1*ntsnap,snaps); exit (0); }
int main (int argc, char* argv[]) { map4 nmo; /* using cubic spline interpolation */ bool half, slow; int it,ix,ih, nt,nx, nh, CDPtype; float dt, t0, h, h0, f, dh, eps, dy; float *trace, *vel, *off, *str, *out; sf_file cmp, nmod, velocity, offset; sf_init (argc,argv); cmp = sf_input("in"); velocity = sf_input("velocity"); nmod = sf_output("out"); if (SF_FLOAT != sf_gettype(cmp)) sf_error("Need float input"); if (!sf_histint(cmp,"n1",&nt)) sf_error("No n1= in input"); if (!sf_histfloat(cmp,"d1",&dt)) sf_error("No d1= in input"); if (!sf_histfloat(cmp,"o1",&t0)) sf_error("No o1= in input"); if (!sf_histint(cmp,"n2",&nh)) sf_error("No n2= in input"); off = sf_floatalloc(nh); if (!sf_getbool("half",&half)) half=true; /* if y, the second axis is half-offset instead of full offset */ CDPtype=1; if (NULL != sf_getstring("offset")) { offset = sf_input("offset"); sf_floatread (off,nh,offset); sf_fileclose(offset); } else { if (!sf_histfloat(cmp,"d2",&dh)) sf_error("No d2= in input"); if (!sf_histfloat(cmp,"o2",&h0)) sf_error("No o2= in input"); if (sf_histfloat(cmp,"d3",&dy)) { CDPtype=half? 0.5+dh/dy : 0.5+0.5*dh/dy; if (CDPtype < 1) { CDPtype=1; } else if (1 != CDPtype) { sf_histint(cmp,"CDPtype",&CDPtype); sf_warning("CDPtype=%d",CDPtype); } } for (ih = 0; ih < nh; ih++) { off[ih] = h0 + ih*dh; } } if (!sf_getbool("slowness",&slow)) slow=false; /* if y, use slowness instead of velocity */ nx = sf_leftsize(cmp,2); if (!sf_getfloat ("h0",&h0)) h0=0.; /* reference offset */ if (half) h0 *= 2.; if (!sf_getfloat("eps",&eps)) eps=0.01; /* stretch regularization */ trace = sf_floatalloc(nt); vel = sf_floatalloc(nt); str = sf_floatalloc(nt); out = sf_floatalloc(nt); nmo = stretch4_init (nt, t0, dt, nt, eps); for (ix = 0; ix < nx; ix++) { sf_floatread (vel,nt,velocity); for (ih = 0; ih < nh; ih++) { sf_floatread (trace,nt,cmp); h = off[ih] + (dh/CDPtype)*(ix%CDPtype); if (half) h *= 2; h = h*h - h0*h0; for (it=0; it < nt; it++) { f = t0 + it*dt; if (slow) { f = f*f + h*vel[it]*vel[it]; } else { f = f*f + h/(vel[it]*vel[it]); } if (f < 0.) { str[it]=t0-10.*dt; } else { str[it] = sqrtf(f); } } stretch4_define (nmo,str); stretch4_apply (false,nmo,trace,out); sf_floatwrite (out,nt,nmod); } } exit (0); }
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", ¶b)) 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; }
int main(int argc, char* argv[]) { bool inv, verb; int i1, n1, iw, nt, nw, i2, n2, rect0, niter, n12, n1w; int m[SF_MAX_DIM], *rect; float t, d1, w, w0, dw, mean=0.0f, alpha; float *trace, *kbsc, *mkbsc, *sscc, *mm, *ww; sf_complex *outp, *cbsc; sf_file in, out, mask, weight, basis; sf_init(argc,argv); in = sf_input("in"); out = sf_output("out"); if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histfloat(in,"d1",&d1)) d1=1.; if (!sf_getbool("inv",&inv)) inv=false; /* if y, do inverse transform */ if (!sf_getbool("verb",&verb)) verb = false; /* verbosity flag */ if (NULL != sf_getstring("basis")) { basis = sf_output("basis"); sf_settype(basis,SF_COMPLEX); } else { basis = NULL; } if (!inv) { if (!sf_getint("nw",&nw)) { /* number of frequencies */ nt = 2*kiss_fft_next_fast_size((n1+1)/2); nw = nt/2+1; dw = 1./(nt*d1); w0 = 0.; } else { if (!sf_getfloat("dw",&dw)) { /* frequency step */ nt = 2*kiss_fft_next_fast_size((n1+1)/2); dw = 1./(nt*d1); } if (!sf_getfloat("w0",&w0)) w0=0.; /* first frequency */ } n2 = sf_leftsize(in,1); sf_shiftdim(in, out, 2); sf_putint(out,"n2",nw); sf_putfloat(out,"d2",dw); sf_putfloat(out,"o2",w0); sf_putstring(out,"label2","Frequency"); sf_putstring(out,"unit2","Hz"); sf_settype(out,SF_COMPLEX); if (!sf_getint("rect",&rect0)) rect0=10; /* smoothing radius (in time, samples) */ if (!sf_getint("niter",&niter)) niter=100; /* number of inversion iterations */ if (!sf_getfloat("alpha",&alpha)) alpha=0.; /* frequency adaptivity */ for(i2=0; i2 < SF_MAX_DIM; i2 ++) { m[i2] = 1; } m[0] = n1; } else { n2 = sf_leftsize(in,2); if (!sf_histint(in,"n2",&nw)) sf_error("No n2= in input"); if (!sf_histfloat(in,"d2",&dw)) sf_error("No d2= in input"); if (!sf_histfloat(in,"o2",&w0)) sf_error("No o2= in input"); sf_unshiftdim(in, out, 2); sf_settype(out,SF_FLOAT); } if (NULL != basis) { sf_shiftdim(in, basis, 2); sf_putint(basis,"n2",nw); sf_putfloat(basis,"d2",dw); sf_putfloat(basis,"o2",w0); sf_putstring(basis,"label2","Frequency"); sf_putstring(basis,"unit2","Hz"); } n1w = n1*nw; n12 = 2*n1w; dw *= 2.*SF_PI; w0 *= 2.*SF_PI; trace = sf_floatalloc(n1); kbsc = sf_floatalloc(n12); outp = sf_complexalloc(n1w); cbsc = sf_complexalloc(n1w); rect = sf_intalloc(2*nw); for (iw=0; iw < nw; iw++) { rect[iw+nw] = rect[iw] = SF_MAX(1, (int) rect0/(1.0+alpha*iw/nw)); } if (!inv) { sscc = sf_floatalloc(n12); nmultidivn_init(2*nw, 1, n1, m, rect, kbsc, (bool) (verb && (n2 < 500))); } else { sscc = NULL; } if (NULL != sf_getstring("mask")) { /* data weight */ mask = sf_input("mask"); mm = sf_floatalloc(n1); } else { mask = NULL; mm = NULL; } if (NULL != sf_getstring("weight")) { /* model weight */ weight = sf_input("weight"); ww = sf_floatalloc(n1w); } else { weight = NULL; ww = NULL; } /* sin and cos basis */ for (iw=0; iw < nw; iw++) { w = w0 + iw*dw; for (i1=0; i1 < n1; i1++) { if (0.==w) { /* zero frequency */ kbsc[iw*n1+i1] = 0.; } else { t = i1*d1; kbsc[iw*n1+i1] = sinf(w*t); } } } for (iw=0; iw < nw; iw++) { w = w0 + iw*dw; for (i1=0; i1 < n1; i1++) { if (0.==w) { /* zero frequency */ kbsc[(iw+nw)*n1+i1] = 0.5; } else { t = i1*d1; kbsc[(iw+nw)*n1+i1] = cosf(w*t); } cbsc[iw*n1+i1] = sf_cmplx(kbsc[(iw+nw)*n1+i1], kbsc[iw*n1+i1]); } } if (NULL != mm || NULL != ww) { mkbsc = sf_floatalloc(n12); for (i1=0; i1 < n12; i1++) { mkbsc[i1] = kbsc[i1]; } } else { mkbsc = NULL; mean = 0.; for (i1=0; i1 < n12; i1++) { mean += kbsc[i1]*kbsc[i1]; } mean = sqrtf (mean/(n12)); for (i1=0; i1 < n12; i1++) { kbsc[i1] /= mean; } } for (i2=0; i2 < n2; i2++) { sf_warning("slice %d of %d;",i2+1,n2); if (NULL != basis) sf_complexwrite(cbsc,n1w,basis); if (NULL != mm || NULL != ww) { for (i1=0; i1 < n12; i1++) { kbsc[i1] = mkbsc[i1]; } if (NULL != mm) { sf_floatread(mm,n1,mask); for (iw=0; iw < 2*nw; iw++) { for (i1=0; i1 < n1; i1++) { kbsc[iw*n1+i1] *= mm[i1]; } } } if (NULL != ww) { sf_floatread(ww,n1w,weight); for (iw=0; iw < nw; iw++) { for (i1=0; i1 < n1; i1++) { kbsc[iw*n1+i1] *= ww[iw*n1+i1]; kbsc[(iw+nw)*n1+i1] *= ww[iw*n1+i1]; } } } mean = 0.; for (i1=0; i1 < n12; i1++) { mean += kbsc[i1]*kbsc[i1]; } mean = sqrtf (mean/(n12)); for (i1=0; i1 < n12; i1++) { kbsc[i1] /= mean; } } if (!inv) { sf_floatread(trace,n1,in); if (NULL != mm) { for (i1=0; i1 < n1; i1++) { trace[i1] *= mm[i1]; } } for(i1=0; i1 < n1; i1++) { trace[i1] /= mean; } nmultidivn (trace,sscc,niter); for (iw=0; iw < nw; iw++) { for (i1=0; i1 < n1; i1++) { outp[iw*n1+i1] = sf_cmplx(sscc[(iw+nw)*n1+i1], sscc[iw*n1+i1]); } } if (NULL != ww) { for (i1=0; i1 < n1w; i1++) { #ifdef SF_HAS_COMPLEX_H outp[i1] *= ww[i1]; #else outp[i1] = sf_crmul(outp[i1],ww[i1]); #endif } } sf_complexwrite(outp,n1w,out); } else { for (i1=0; i1 < n1; i1++) { trace[i1] = 0.; } sf_complexread(outp,n1w,in); for (iw=0; iw < nw; iw++) { for (i1=0; i1 < n1; i1++) { trace[i1] += crealf(outp[iw*n1+i1])*kbsc[(iw+nw)*n1+i1] *mean+cimagf(outp[iw*n1+i1])*kbsc[iw*n1+i1]*mean; if (NULL != mm) trace[i1] *= mm[i1]; } } sf_floatwrite(trace,n1,out); } } sf_warning("."); exit(0); }
int main (int argc,char* argv[]) { int n[3], ns, ns0, nt, is0, s0; float o[3], os, os0, d[3], ds, ds0, **t, **tds, *tempt, ss; char *type; sf_file in, out, deriv, pattern; sf_init (argc, argv); in = sf_input("in"); out = sf_output("out"); /* read input dimensions */ if(!sf_histint(in,"n1",n )) sf_error("No n1= in input"); if(!sf_histint(in,"n2",n+1)) sf_error("No n2= in input"); if(!sf_histint(in,"n3",n+2)) n[2]=1; if(!sf_histint(in,"n4",&ns)) sf_error("No ns= in input"); if (ns <= 1) sf_error("Provide at least two shots"); if(!sf_histfloat(in,"d1",d )) sf_error("No d1= in input"); if(!sf_histfloat(in,"d2",d+1)) sf_error("No d2= in input"); if(!sf_histfloat(in,"d3",d+2)) d[2]=d[1]; if(!sf_histfloat(in,"d4",&ds)) ds=d[1]; if(!sf_histfloat(in,"o1",o )) o[0]=0.; if(!sf_histfloat(in,"o2",o+1)) o[1]=0.; if(!sf_histfloat(in,"o3",o+2)) o[2]=o[1]; if(!sf_histfloat(in,"o4",&os)) os=o[1]; /* read traveltime file */ nt = n[0]*n[1]*n[2]; t = sf_floatalloc2(nt,ns); sf_floatread(t[0],nt*ns,in); if (NULL == (type = sf_getstring("type"))) type="hermit"; /* type of interpolation (default Hermit) */ if (type[0] != 'h') { /* linear interpolation */ deriv = NULL; tds = NULL; } else { /* read derivative file */ if (NULL == sf_getstring("deriv")) sf_error("Need derivative deriv="); deriv = sf_input("deriv"); tds = sf_floatalloc2(nt,ns); sf_floatread(tds[0],nt*ns,deriv); sf_fileclose(deriv); } if (NULL != sf_getstring("pattern")) { pattern = sf_input("pattern"); } else { pattern = NULL; } if (!sf_getint("ns",&ns0) && (NULL==pattern || !sf_histint(pattern,"n4",&ns0))) sf_error("Need ns="); /* Output source size */ if (!sf_getfloat("ds",&ds0) && (NULL==pattern || !sf_histfloat(pattern,"d4",&ds0))) sf_error("Need ds="); /* Output source sampling */ if (!sf_getfloat("os",&os0) && (NULL==pattern || !sf_histfloat(pattern,"o4",&os0))) sf_error("Need os="); /* Output source origin */ sf_putint(out,"n4",ns0); sf_putfloat(out,"d4",ds0); sf_putfloat(out,"o4",os0); /* allocate temporaty memory */ tempt = sf_floatalloc(nt); /* initialization */ tinterp_init(nt,ds); /* loop over sources */ for (is0=0; is0 < ns0; is0++) { s0 = (os0+is0*ds0-os)/ds; ss = os0+is0*ds0-os-s0*ds; if (s0 < 0) { s0 = 0; ss = 0.; } if (s0 >= ns-1) { s0 = ns-2; ss = ds; } /* do interpolation */ switch (type[0]) { case 'l': /* linear */ tinterp_linear(tempt,ss,t[s0],t[s0+1]); break; case 'p': /* partial */ tinterp_partial(tempt,ss,n[0],n[1],d[1],t[s0],t[s0+1]); break; case 'h': /* hermite */ tinterp_hermite(tempt,ss,t[s0],t[s0+1],tds[s0],tds[s0+1]); break; } sf_floatwrite(tempt,nt,out); } exit (0); }
int main(int argc, char* argv[]) { int verbose; sf_file in=NULL, out=NULL; int n1_traces; int n1_headers; char* header_format=NULL; sf_datatype typehead; /* kls do I need to add this? sf_datatype typein; */ float* fheader=NULL; float* intrace=NULL; float* fprevheader=NULL; int numkeys; int ikey; char** list_of_keys; int *indx_of_keys; char* skey; int indx_of_skey; int skeyvalue; bool pkeychanged; int itrace=0; /*****************************/ /* initialize verbose switch */ /*****************************/ sf_init (argc,argv); /* verbose flag controls ammount of print */ /*( verbose=1 0 terse, 1 informative, 2 chatty, 3 debug ) */ /* fprintf(stderr,"read verbose switch. getint reads command line.\n"); */ if(!sf_getint("verbose",&verbose))verbose=1; /* \n flag to control amount of print 0 terse, 1 informative, 2 chatty, 3 debug */ sf_warning("verbose=%d",verbose); /******************************************/ /* input and output data are stdin/stdout */ /******************************************/ if(verbose>0)fprintf(stderr,"read in file name\n"); in = sf_input ("in"); if(verbose>0)fprintf(stderr,"read out file name\n"); out = sf_output ("out"); if (!sf_histint(in,"n1_traces",&n1_traces)) sf_error("input data not define n1_traces"); if (!sf_histint(in,"n1_headers",&n1_headers)) sf_error("input data does not define n1_headers"); header_format=sf_histstring(in,"header_format"); if(strcmp (header_format,"native_int")==0) typehead=SF_INT; else typehead=SF_FLOAT; if(verbose>0)fprintf(stderr,"allocate headers. n1_headers=%d\n",n1_headers); fheader = sf_floatalloc(n1_headers); fprevheader = sf_floatalloc(n1_headers); if(verbose>0)fprintf(stderr,"allocate intrace. n1_traces=%d\n",n1_traces); intrace= sf_floatalloc(n1_traces); if(verbose>0)fprintf(stderr,"call list of keys\n"); /* this sf_getstring will create parameter descrpiton in the self doc */ sf_getstring("pkey"); /* \n A comma seperated list of primary header keys to monitor to determine gathers. The trace number in the gather is counted and put in the skey header location. \n */ list_of_keys=sf_getnstring("pkey",&numkeys); /* List of the primary keys monitored to determine gathers. */ if(list_of_keys==NULL) sf_error("The required parameter \"pkey\" was not found."); /* I wanted to use sf_getstrings, but it seems to want a colon seperated list of keys (eg key=offset:ep:fldr:cdp) and I wanted a comma seperated list of keys (eg key=offset:ep:fldr:cdp). numkeys=sf_getnumpars("pkey"); if(numkeys==0) sf_error("The required parameter \"pkey\" was not found."); fprintf(stderr,"alloc list_of_keys numkeys=%d\n",numkeys); list_of_keys=(char**)sf_alloc(numkeys,sizeof(char*)); sf_getstrings("pkey",list_of_keys,numkeys); */ /* print the list of keys */ if(verbose>1){ fprintf(stderr,"numkeys=%d\n",numkeys); for(ikey=0; ikey<numkeys; ikey++){ fprintf(stderr,"list_of_keys[%d]=%s\n",ikey,list_of_keys[ikey]); } } if(NULL==(skey=sf_getstring("skey"))) sf_error("the required parameter \"skey\" was not found"); /* The name of the secondary key created by the program. */ /* maybe I should add some validation that n1== n1_traces+n1_headers+2 and the record length read in the second word is consistent with n1. */ /**********************************************************/ /* end code block for standard tah Trace And Header setup */ /* continue with any sf_puthist this tah program calls to */ /* add to the history file */ /**********************************************************/ /* put the history from the input file to the output */ sf_fileflush(out,in); /********************************************************/ /* continue initialization specific to this tah program */ /********************************************************/ /* segy_init gets the list header keys required by segykey function */ segy_init(n1_headers,in); indx_of_keys=sf_intalloc(numkeys); for (ikey=0; ikey<numkeys; ikey++){ /* kls need to check each of these key names are in the segy header and make error message for invalid keys. Of does segykey do this? NO, just segmentation fault. */ indx_of_keys[ikey]=segykey(list_of_keys[ikey]); } indx_of_skey=segykey(skey); /***************************/ /* start trace loop */ /***************************/ if(verbose>0)fprintf(stderr,"start trace loop\n"); skeyvalue=0; itrace=0; while (0==get_tah(intrace, fheader, n1_traces, n1_headers, in)){ if(verbose>1)fprintf(stderr,"process the tah in sftahgethw\n"); /********************/ /* process the tah. */ /********************/ /* this program computes a secondary key. If one of the headers in pkey changes, skey is set to 1. Otherwise skey is the previous skey+1 */ pkeychanged=false; if(itrace>0){ for(ikey=0; ikey<numkeys; ikey++){ if(typehead == SF_INT){ if(((int*)fheader )[indx_of_keys[ikey]]!= ((int*)fprevheader)[indx_of_keys[ikey]]){ pkeychanged=true; break; } } else { if(fheader[indx_of_keys[ikey]]!=fprevheader[indx_of_keys[ikey]]){ pkeychanged=true; break; } } } } if(pkeychanged) skeyvalue=1; else skeyvalue++; if(typehead == SF_INT) ((int*)fheader)[indx_of_skey]=skeyvalue; else fheader [indx_of_skey]=skeyvalue; if(skeyvalue==1){ /* this is a new pkey, save the header so you know when it changes */ memcpy(fprevheader,fheader,n1_headers*sizeof(int)); } /***************************/ /* write trace and headers */ /***************************/ put_tah(intrace, fheader, n1_traces, n1_headers, out); itrace++; } exit(0); }
int main(int argc, char* argv[]) { int i, iter, niter, p[6][2], status, *mask; float *buf, *buf2, *wht; double rn, rnp, alpha, beta; pid_t pid[6]={1,1,1,1,1,1}; off_t nm, nd, msiz, dsiz, pos; size_t nbuf, mbuf, dbuf; FILE *xfile, *Rfile, *gfile, *sfile, *Sfile; char *x, *R, *g, *s, *S, *prog; sf_file mod, dat, from, mwt, x0, known; /* input */ sf_file to, out; /* output */ extern int fseeko(FILE *stream, off_t offset, int whence); extern off_t ftello (FILE *stream); sf_init(argc,argv); dat = sf_input("in"); mod = sf_input("mod"); if (SF_FLOAT != sf_gettype(mod) || SF_FLOAT != sf_gettype(dat)) sf_error("Need float type in mod and dat"); for (i=0; i < argc-1; i++) { argv[i]=argv[i+1]; } for (i=0; i < argc-1; i++) { /* find the program to run */ if (NULL == strchr(argv[i],'=')) { /* first one without the '=' */ prog = argv[0]; argv[0] = argv[i]; argv[i] = prog; break; } } argv[argc-1] = sf_charalloc(6); snprintf(argv[argc-1],6,"adj=X"); if (!sf_getint("niter",&niter)) niter=1; /* number of iterations */ Rfile = sf_tempfile(&R,"w+b"); xfile = sf_tempfile(&x,"w+b"); gfile = sf_tempfile(&g,"w+b"); sfile = sf_tempfile(&s,"w+b"); Sfile = sf_tempfile(&S,"w+b"); fclose(Rfile); fclose(xfile); fclose(gfile); fclose(sfile); fclose(Sfile); nm = sf_filesize(mod); nd = sf_filesize(dat); /* I/O buffers */ nbuf = BUFSIZ/sizeof(float); buf = sf_floatalloc(nbuf); buf2 = sf_floatalloc(nbuf); if (NULL != sf_getstring("mwt")) { mwt = sf_input("mwt"); /* model weight */ wht = sf_floatalloc(nbuf); } else { mwt = NULL; wht = NULL; } if (NULL != sf_getstring("known")) { known = sf_input("known"); /* known model mask */ if (SF_INT != sf_gettype(known)) sf_error("Need int type in known"); mask = sf_intalloc(nbuf); } else { known = NULL; mask = NULL; } if (NULL != sf_getstring("x0")) { x0 = sf_input("x0"); /* initial model */ } else { x0 = NULL; } for (i=0; i < 6; i++) { /* make six pipes */ if (pipe(p[i]) < 0) sf_error("pipe error:"); } for (iter=0; iter < niter; iter++) { for (i=0; i < 6; i++) { /* fork six children */ if ((pid[i] = fork()) < 0) sf_error("fork error:"); if (0 == pid[i]) break; } if (0 == pid[0]) { /* feeds rr to p[0] */ close(p[0][0]); close(STDOUT_FILENO); DUP(p[0][1]); to = sf_output("out"); if (0 == iter) { xfile = fopen(x,"wb"); if (NULL == x0) { for (i=0; i < nbuf; i++) { buf[i] = 0.0f; } } MLOOP( if (NULL != x0) sf_floatread(buf,mbuf,x0); MWRITE(xfile); ); fclose(xfile); Rfile = fopen(R,"wb"); DLOOP( sf_floatread(buf,dbuf,dat); for (i=0; i < dbuf; i++) { buf[i] = -buf[i]; } sf_floatwrite(buf,dbuf,to); DWRITE (Rfile); );
int main(int argc, char* argv[]) { bool adj, half, verb, normalize; int nt, nx, nh, nh2, ix, ih, iy, i, nn, it, **fold, apt; float *trace, **image, **v, rho, **stack, *pp, *off; float h, x, t, h0, dh, dx, ti, tx, t0, t1, t2, dt, vi, aal, angle; sf_file inp, out, vel, gather, offset; sf_init (argc,argv); inp = sf_input("in"); vel = sf_input("vel"); out = sf_output("out"); if (!sf_getbool("adj",&adj)) adj=true; /* adjoint flag (y for migration, n for modeling) */ if (!sf_getbool("normalize",&normalize)) normalize=true; /* normalize for the fold */ if (!sf_histint(inp,"n1",&nt)) sf_error("No n1="); if (!sf_histint(inp,"n2",&nx)) sf_error("No n2="); if (!sf_histfloat(inp,"o1",&t0)) sf_error("No o1="); if (!sf_histfloat(inp,"d1",&dt)) sf_error("No d1="); if (!sf_histfloat(inp,"d2",&dx)) sf_error("No d2="); if (adj) { if (!sf_histint(inp,"n3",&nh)) sf_error("No n3="); sf_putint(out,"n3",1); } else { if (!sf_getint("nh",&nh)) sf_error("Need nh="); /* number of offsets (for modeling) */ sf_putint(out,"n3",nh); } if (NULL != sf_getstring("gather")) { gather = sf_output("gather"); } else { gather = NULL; } if (!sf_getfloat("antialias",&aal)) aal = 1.0; /* antialiasing */ if (!sf_getint("apt",&apt)) apt = nx; /* integral aperture */ if (!sf_getfloat("angle",&angle)) angle = 90.0; /* angle aperture */ angle = fabsf(tanf(angle*SF_PI/180.0)); if (!sf_getbool("half",&half)) half = true; /* if y, the third axis is half-offset instead of full offset */ if (!sf_getbool("verb",&verb)) verb = true; /* verbosity flag */ if (!sf_getfloat("rho",&rho)) rho = 1.-1./nt; /* Leaky integration constant */ if (NULL != sf_getstring("offset")) { offset = sf_input("offset"); nh2 = sf_filesize(offset); if (nh2 != nh*nx) sf_error("Wrong dimensions in offset"); off = sf_floatalloc(nh2); sf_floatread (off,nh2,offset); sf_fileclose(offset); } else { if (adj) { if (!sf_histfloat(inp,"o3",&h0)) sf_error("No o3="); if (!sf_histfloat(inp,"d3",&dh)) sf_error("No d3="); sf_putfloat(out,"d3",1.); sf_putfloat(out,"o3",0.); } else { if (!sf_getfloat("dh",&dh)) sf_error("Need dh="); /* offset sampling (for modeling) */ if (!sf_getfloat("h0",&h0)) sf_error("Need h0="); /* first offset (for modeling) */ sf_putfloat(out,"d3",dh); sf_putfloat(out,"o3",h0); } if (!half) dh *= 0.5; off = sf_floatalloc(nh*nx); for (ix = 0; ix < nx; ix++) { for (ih = 0; ih < nh; ih++) { off[ih*nx+ix] = h0 + ih*dh; } } offset = NULL; } v = sf_floatalloc2(nt,nx); sf_floatread(v[0],nt*nx,vel); trace = sf_floatalloc(nt); image = sf_floatalloc2(nt,nx); stack = sf_floatalloc2(nt,nx); if (normalize) { fold = sf_intalloc2(nt,nx); } else { fold = NULL; } nn = 2*kiss_fft_next_fast_size((nt+1)/2); pp = sf_floatalloc(nn); sf_halfint_init (true, nn, rho); if (adj) { for (i=0; i < nt*nx; i++) { stack[0][i] = 0.; } } else { sf_floatread(stack[0],nt*nx,inp); } if (NULL != fold) { for (i=0; i < nt*nx; i++) { fold[0][i] = 0; } } for (ih=0; ih < nh; ih++) { if (verb) sf_warning("offset %d of %d;",ih+1,nh); if (adj) { for (i=0; i < nt*nx; i++) { image[0][i] = 0.; } } else { for (iy=0; iy < nx; iy++) { for (it=0; it < nt; it++) { image[iy][it] = stack[iy][it]; } } } if (!adj) { for (iy=0; iy < nx; iy++) { for (it=0; it < nt; it++) { pp[it] = image[iy][it]; } for (it=nt; it < nn; it++) { pp[it] = 0.; } sf_halfint (false, pp); for (it=0; it < nt; it++) { image[iy][it] = pp[it]; } } } for (iy=0; iy < nx; iy++) { if (adj) { sf_floatread (trace,nt,inp); sf_doubint(true, nt,trace); } else { for (it=0; it < nt; it++) { trace[it]=0.0f; } } h = fabsf(off[ih*nx+iy]); for (ix=0; ix < nx; ix++) { x = (ix-iy)*dx; if (SF_ABS(ix-iy) > apt) continue; for (it=0; it < nt; it++) { t = t0 + it*dt; vi = v[ix][it]; if (fabsf(x) > angle*vi*t) continue; /* hypot(a,b) = sqrt(a*a+b*b) */ t1 = hypotf(0.5*t,(x-h)/vi); t2 = hypotf(0.5*t,(x+h)/vi); ti = t1+t2; /* tx = |dt/dx| */ tx = fabsf(x-h)/(vi*vi*(t1+dt))+ fabsf(x+h)/(vi*vi*(t2+dt)); pick(adj,ti,fabsf(tx*dx*aal),trace,image[ix],it,nt,dt,t0); } } if (!adj) { sf_doubint(true, nt,trace); sf_floatwrite (trace,nt,out); } } if (adj) { for (iy=0; iy < nx; iy++) { for (it=0; it < nt; it++) { pp[it] = image[iy][it]; } for (it=nt; it < nn; it++) { pp[it] = 0.; } sf_halfint (true, pp); for (it=0; it < nt; it++) { image[iy][it] = pp[it]; } } if (NULL != gather) sf_floatwrite(image[0],nt*nx,gather); for (iy=0; iy < nx; iy++) { for (it=0; it < nt; it++) { stack[iy][it] += image[iy][it]; if (NULL != fold && 0.!=image[iy][it]) fold[iy][it]++; } } } } if (verb) sf_warning("."); if (NULL != fold) { for (i=0; i < nt*nx; i++) { stack[0][i] /= (fold[0][i]+FLT_EPSILON); } } if (adj) sf_floatwrite(stack[0],nt*nx,out); exit(0); }
int main(int argc, char* argv[]) { int i, niter, n1, n2, n12, i3, n3, rect1, rect2, order; float *mm, *dd, **pp, lam; bool *known; sf_file in, out, dip, mask; sf_init (argc,argv); in = sf_input("in"); out = sf_output("out"); dip = sf_input("dip"); if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(in,"n2",&n2)) sf_error("No n2= in input"); n12 = n1*n2; n3 = sf_leftsize(in,2); if (!sf_getint("niter",&niter)) niter=100; /* number of iterations */ if (!sf_getint("order",&order)) order=1; /* accuracy order */ pp = sf_floatalloc2(n1,n2); mm = sf_floatalloc(n12); known = sf_boolalloc(n12); if (NULL != sf_getstring ("mask")) { mask = sf_input("mask"); dd = sf_floatalloc(n12); } else { mask = NULL; dd = NULL; } if (!sf_getint("rect1",&rect1)) rect1=3; if (!sf_getint("rect2",&rect2)) rect2=3; /* smoothing radius */ pwdsl_init(n1,n2,order,rect1,rect2,0.01); pwdsl_set(pp); sf_mask_init(known); for (i3=0; i3 < n3; i3++) { sf_warning("slice %d of %d",i3+1,n3); sf_floatread(mm,n12,in); if (NULL != mask) { sf_floatread(dd,n12,mask); } else { dd = mm; } /* figure out scaling and make known data mask */ lam = 0.; for (i=0; i < n12; i++) { if (dd[i] != 0.) { known[i] = true; lam += 1.; } else { known[i] = false; } } lam = sqrtf(lam/n12); /* read dip */ sf_floatread(pp[0],n12,dip); sf_conjgrad_init(n12, n12, n12, n12, lam, 10*FLT_EPSILON, true, true); sf_conjgrad(NULL,sf_mask_lop,pwdsl_lop,dd,mm,mm,niter); sf_conjgrad_close(); sf_floatwrite (mm,n12,out); } exit(0); }
int main (int argc, char* argv[]) { int n1,n2,i3,i2,n4,j,n12,fold,ndim, mdim; int n[SF_MAX_DIM], m[SF_MAX_DIM], *mk; float *d, *sht, *x, mean, std, sum, amp=0.0; bool verb; sf_file in, out, msk, scl; sf_init (argc,argv); in = sf_input("in"); out = sf_output("out"); if (SF_FLOAT != sf_gettype(in)) sf_error("Need float"); if (!sf_histint(in,"n1",&n1)) sf_error("Need n1="); if (!sf_histint(in,"n2",&n2)) sf_error("Need n2="); n4 = sf_leftsize(in,2); n12=n1*n2; if (!sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ /* input file*/ if (! (sf_getstring("mask") || sf_histstring(in,"mask"))) sf_error("Need mask="); msk = sf_input("mask"); if (SF_INT != sf_gettype(msk)) sf_error("Need integer mask"); sf_getfloat("amp",&); /*Exclude amplitudes greater than amp && less than -amp for statistics computations*/ ndim = sf_filedims(in,n); mdim = sf_filedims(msk,m); if (mdim != ndim) sf_error("Wrong dimensions: %d != %d",mdim,ndim); for (j=0; j < ndim; j++) { if (m[j] != n[j]) sf_error("Size mismatch [n%d]: %d != %d", j+1,m[j],n[j]); } /* output file*/ if (NULL != sf_getstring("scaler")){ scl = sf_output("scaler"); sf_unshiftdim(in, scl, 2); sf_putint(scl,"n1",2); } else { scl = NULL; } d = sf_floatalloc(n12*n4); x = sf_floatalloc(2*n4); sht = sf_floatalloc(n12); mk = sf_intalloc(n12); /* loop through time samples */ for (i3=0; i3 < n4; i3++) { mean=0.0; fold=0; std =0.0; sum=0.0; sf_floatread(sht,n12,in); sf_intread(mk,n12,msk); /* compute mean */ for (i2=0; i2 < n12; i2++) { if (sht[i2]!=0.0 && mk[i2]!=0 ) { if ( amp==0.0 || fabsf(sht[i2]) < fabsf(amp) ){ sum +=sht[i2]; fold +=1; } } } if (fold > 0) mean=sum/fold; /* compute standard deviation */ for (i2=0; i2 < n12; i2++) { if (sht[i2]!=0.0 && mk[i2]!=0 ) { //if (!(amp && fabsf(sht[i2]) < fabsf(amp))) // continue; if ( amp==0.0 || fabsf(sht[i2]) < fabsf(amp) ) std += (sht[i2]-mean)*(sht[i2]-mean); } } if (fold > 0) std =sqrtf(std/(fold-1)); /* scale time samples*/ for (i2=0; i2 < n12; i2++) if (sht[i2]!=0.0 && mean!=0.0 && std!=0.0) d[i2+i3*n12]=(sht[i2]-mean)/std; else d[i2+i3*n12]=sht[i2]; x[0+i3*2]=mean; x[1+i3*2]=std; if (verb) sf_warning("shot %8d-> mean:%8g std:%8g, fold:%8d\n;",i3+1,mean,std,fold); } sf_floatwrite (d,n4*n12,out); if (scl) sf_floatwrite (x,n4*2,scl); exit(0); }
int main(int argc, char* argv[]) { bool sym; float o1,d1, o2,d2, tol; int nd, n1, n2, n12, niter, rect1, rect2, nw; float **xy, *z, *m, *m2, *d; sf_file in, out, coord, pattern; sf_init(argc,argv); in = sf_input("in"); out = sf_output("out"); coord = sf_input("coord"); if (SF_FLOAT != sf_gettype(in)) sf_error("Need float input"); if (!sf_histint(in,"n1",&nd)) sf_error("No n1= in input"); if (NULL != sf_getstring("pattern")) { /* pattern file for output dimensions */ pattern = sf_input("pattern"); if (!sf_histint(pattern,"n1",&n1)) sf_error("No n1= in pattern"); if (!sf_histint(pattern,"n2",&n2)) sf_error("No n2= in pattern"); if (!sf_histfloat(pattern,"d1",&d1)) d1=1.; if (!sf_histfloat(pattern,"d2",&d2)) d2=1.; if (!sf_histfloat(pattern,"o1",&o1)) o1=0.; if (!sf_histfloat(pattern,"o2",&o2)) o2=0.; sf_fileclose(pattern); } else { if (!sf_getint("n1",&n1)) sf_error("Need n1="); if (!sf_getint("n2",&n2)) sf_error("Need n2="); if (!sf_getfloat("d1",&d1)) d1=1.; if (!sf_getfloat("d2",&d2)) d2=1.; if (!sf_getfloat("o1",&o1)) o1=0.; if (!sf_getfloat("o2",&o2)) o2=0.; } n12 = n1*n2; sf_putint(out,"n1",n1); sf_putint(out,"n2",n2); sf_putfloat(out,"d1",d1); sf_putfloat(out,"d2",d2); sf_putfloat(out,"o1",o1); sf_putfloat(out,"o2",o2); if (!sf_getint("niter",&niter)) niter=10; /* number of iterations */ xy = sf_floatalloc2(2,nd); sf_floatread(xy[0],nd*2,coord); if (!sf_getint("rect1",&rect1)) rect1=1; if (!sf_getint("rect2",&rect2)) rect2=1; /* smoothing regularization */ if (!sf_getint("nw",&nw)) nw=2; /* interpolator size */ if (!sf_getbool("sym",&sym)) sym=false; /* if y, use symmetric shaping */ if (!sf_getfloat("tol",&tol)) tol=1e-3; /* tolerance for stopping iteration */ nnshape_init(sym,nd, n1,n2, o1,o2, d1,d2, rect1,rect2, nw, 2, xy); sf_gmres_init(n12,niter); z = sf_floatalloc (n12); m = sf_floatalloc (n12); d = sf_floatalloc(nd); sf_floatread(d,nd,in); /* make right-hand side */ nnshape_back(d,z); nnshape_smooth(z); /* invert */ sf_gmres(z,m,nnshape,NULL,niter,tol,true); if (sym) nnshape_smooth(m); sf_floatwrite (m, n12, out); exit(0); }
int main(int argc, char* argv[]) { int i; float *data; char *fn; sf_init(argc,argv); FILE *Fi; sf_file Fo; cjbsegy *tr; tr = calloc(sizeof(cjbsegy), 1); int nx, ny, nazim, nang, ntau; float dazim, dang, dtau, fazim=0.0, fang=0.0, ftau=0; int dx, dy, fx=0, fy=0; if (!sf_getint("nx",&nx)) nx=101; if (!sf_getint("ny",&ny)) ny=101; if (!sf_getint("nazim",&nazim)) nazim=8; if (!sf_getint("nang",&nang)) nang=21; if (!sf_getint("ntau",&ntau)) ntau=101; if (!sf_getint("dx",&dx)) dx=1; if (!sf_getint("dy",&dy)) dy=1; if (!sf_getfloat("dazim",&dazim)) dazim=22.5; if (!sf_getfloat("dang",&dang)) dang=2.0; if (!sf_getfloat("dtau",&dtau)) dtau=0.002; if (!sf_getint("fx",&fx)) fx=1; if (!sf_getint("fy",&fy)) fy=1; if (!sf_getfloat("ftau",&ftau)) ftau=0; if (NULL==(fn=sf_getstring("fn"))) fn="kpstm.ladcig.su.agc"; /* setup I/O files */ Fo = sf_output("out"); if((Fi=fopen(fn,"rb"))==NULL) { printf("File %s open error!\n",fn); exit(0); } fread(tr,sizeof(cjbsegy),1,Fi); int iline0=tr->ep; sf_warning("ns=%d dt=%f iLineNo=%d ",tr->ns, tr->dt,iline0); if(fseek(Fi, 0L, 2) ==-1) printf("input file size unknown; Please specify n2\n"); int nxy=(int) (ftell(Fi)/((60+ntau)*sizeof(float))); sf_warning("nxy=%d nx=%d ny=%d ",nxy, nx,ny); sf_warning("nazim=%d nang=%d ntau=%d",nazim,nang,ntau); sf_warning("dx=%d dy=%d dazim=%f dang=%f dtau=%f",dx,dy,dazim,dang,dtau); sf_warning("fx=%d fy=%d fazim=%f fang=%f ftau=%f",fx,fy,fazim,fang,ftau); if(nxy!=nx*ny*nazim*nang) { sf_warning("nx * ny * nazim * nang != nxy "); exit(0); }; sf_putint(Fo,"n1",ntau); sf_putint(Fo,"n2",nang); sf_putint(Fo,"n3",nazim); sf_putint(Fo,"n4",nx); sf_putint(Fo,"n5",ny); sf_putfloat(Fo,"d1",dtau); sf_putfloat(Fo,"o1",ftau); sf_putfloat(Fo,"d2",dang); sf_putfloat(Fo,"o2",fang); sf_putfloat(Fo,"d3",dazim); sf_putfloat(Fo,"o3",fazim); sf_putfloat(Fo,"d4",dx); sf_putfloat(Fo,"o4",fx); sf_putfloat(Fo,"d5",dy); sf_putfloat(Fo,"o5",fy); sf_putstring(Fo,"label1","z"); sf_putstring(Fo,"label2","angle"); sf_putstring(Fo,"label3","azimuth"); sf_putstring(Fo,"label4","x"); sf_putstring(Fo,"label5","y"); sf_putstring(Fo,"unit1","ms"); sf_putstring(Fo,"unit2","degree"); sf_putstring(Fo,"unit3","degree"); sf_putstring(Fo,"unit4","m"); sf_putstring(Fo,"unit5","m"); data = sf_floatalloc(ntau); rewind(Fi); for(i=0;;i++) { fread(tr,sizeof(cjbsegy),1,Fi); if(tr->ep != iline0){ sf_warning("Read iLineNo=%d finished",iline0); iline0=tr->ep; } fread(data,sizeof(float),ntau,Fi); if(feof(Fi))break; sf_floatwrite(data, ntau, Fo); } sf_warning("Read iLineNo=%d finished",tr->ep); fclose(Fi); free(data); free(tr); exit(0); }
int main(int argc, char* argv[]) { int i, ia, na, nx, ns, dim, n[SF_MAX_DIM], m[SF_MAX_DIM]; float a0, *pp, *qq; bool adj; sf_filter aa; char* lagfile; sf_file in, out, filt, lag; sf_init (argc,argv); in = sf_input("in"); filt = sf_input("filt"); out = sf_output("out"); dim = sf_filedims (in,n); if (!sf_histint(filt,"n1",&na)) sf_error("No n1= in filt"); aa = sf_allocatehelix (na); if (!sf_histfloat(filt,"a0",&a0)) a0=1.; sf_floatread (aa->flt,na,filt); for( ia=0; ia < na; ia++) { aa->flt[ia] /= a0; } if (NULL != (lagfile = sf_getstring("lag")) /* file with filter lags */ || NULL != (lagfile = sf_histstring(filt,"lag"))) { lag = sf_input(lagfile); sf_intread(aa->lag,na,lag); } else { lag = NULL; for( ia=0; ia < na; ia++) { aa->lag[ia] = ia+1; } } sf_fileclose(filt); if (!sf_getints ("n",m,dim) && (NULL == lag || !sf_histints (lag,"n",m,dim))) { for (i=0; i < dim; i++) { m[i] = n[i]; } } if (NULL != lag) sf_fileclose(lag); regrid (dim, m, n, aa); if (!sf_getbool ("adj",&adj)) adj=false; /* if y, do adjoint operation */ if (!sf_getint ("ns",&ns)) sf_error("Need ns="); /* scaling */ nx = 1; for( i=0; i < dim; i++) { nx *= n[i]; } pp = sf_floatalloc (nx); qq = sf_floatalloc (nx); if (adj) { sf_floatread (qq,nx,in); } else { sf_floatread (pp,nx,in); } hshape_init (nx,ns,aa); hshape_lop (adj,false,nx,nx,pp,qq); if (adj) { sf_floatwrite (pp,nx,out); } else { sf_floatwrite (qq,nx,out); } exit (0); }
int main(int argc, char* argv[]) { bool verb; int n[SF_MAX_DIM], n0[SF_MAX_DIM], rect[SF_MAX_DIM]; int a[SF_MAX_DIM], center[SF_MAX_DIM], gap[SF_MAX_DIM]; int ndim, dim, n123, n123s, i, ia, ns, i1, niter, na, i4, n4, *kk; float *d, *f, *dd; double mean; char *lagfile, key[6]; sf_filter aa; sf_file in, filt, lag; sf_init(argc,argv); in = sf_input("in"); filt = sf_output("out"); if (NULL == (lagfile = sf_getstring("lag"))) sf_error("Need lag="); /* output file for filter lags */ lag = sf_output(lagfile); sf_settype(lag,SF_INT); sf_putstring(filt,"lag",lagfile); ndim = sf_filedims(in,n); if (!sf_getint("dim",&dim)) dim=ndim; /* number of dimensions */ n4 = sf_leftsize(in,dim); sf_putints (lag,"n",n,dim); if (!sf_getints("a",a,dim)) sf_error("Need a="); if (!sf_getints("center",center,dim)) { for (i=0; i < dim; i++) { center[i] = (i+1 < dim && a[i+1] > 1)? a[i]/2: 0; } } if (!sf_getint("na",&na)) na=0; /* filter size */ if (0 == na) { if (!sf_getints("gap",gap,dim)) { for (i=0; i < dim; i++) { gap[i] = 0; } } aa = createhelix(dim, n, center, gap, a); /* allocate PEF */ for (i=0; i < dim; i++) { n0[i] = n[i]; } } else { aa = sf_allocatehelix (na); if (!sf_getints ("lags", aa->lag, na)) sf_error("Need lags="); if (!sf_getints ("n", n0, dim)) { for (i=0; i < dim; i++) { n0[i] = n[i]; } } } n123 = 1; for (i=0; i < dim; i++) { n123 *= n[i]; snprintf(key,6,"rect%d",i+1); if (!sf_getint(key,rect+i)) rect[i]=1; } dd = sf_floatalloc(n123); kk = sf_intalloc(n123); for (i1=0; i1 < n123; i1++) { kk[i1] = 1; } bound (dim, n0, n, a, aa); find_mask(n123, kk, aa); na = aa->nh; snprintf(key,3,"n%d",dim+1); sf_putint(filt,key,na); sf_shiftdim(in, filt, dim+1); if (!sf_getint("niter",&niter)) niter=100; /* number of iterations */ if (!sf_getbool("verb",&verb)) verb = true; /* verbosity flag */ n123s = n123*na; d = sf_floatalloc(n123s); f = sf_floatalloc(n123s); sf_multidivn_init(na, dim, n123, n, rect, d, NULL, verb); for (i4=0; i4 < n4; i4++) { sf_floatread(dd,n123,in); /* apply shifts: dd -> d */ mean = 0.; for (i=ia=0; ia < na; ia++) { ns = aa->lag[ia]; for (i1=0; i1 < n123; i1++,i++) { if (i1 < ns) { d[i] = 0.0f; } else { d[i] = dd[i1-ns]; mean += d[i]*d[i]; } } } if (mean == 0.) { sf_floatwrite(d,n123s,filt); continue; } mean = sqrt (n123s/mean); /* -> apply mask */ for(i=0; i < n123s; i++) { d[i] *= mean; } for(i1=0; i1 < n123; i1++) { dd[i1] *= mean; } sf_multidivn (dd,f,niter); sf_floatwrite(f,n123s,filt); } exit(0); }
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", ¶b)) 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; }
int main(int argc, char* argv[]) { int n1, n2, i1, i2, niter; float **b, *h, ***rt, d, maxd; sf_complex **data; sf_file inp, out, bad; sf_init (argc,argv); inp = sf_input("in"); out = sf_output("out"); if (SF_COMPLEX != sf_gettype(inp)) sf_error("Need complex input"); if (!sf_histint(inp,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(inp,"n2",&n2)) sf_error("No n2= in input"); sf_settype(out,SF_FLOAT); if (!sf_getint("niter",&niter)) niter=0; /* number of iterations */ if (NULL != sf_getstring("badness")) { bad = sf_output("badness"); /* (optional) badness attribute file */ sf_settype(bad,SF_FLOAT); } else { bad = NULL; } data = sf_complexalloc2(n1,n2); sf_complexread(data[0],n1*n2,inp); /* normalize */ maxd = 0; for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1; i1++) { d = cabsf(data[i2][i1]); if (maxd < d) maxd=d; } } for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1; i1++) { #ifdef SF_HAS_COMPLEX_H data[i2][i1] = data[i2][i1]/maxd; #else data[i2][i1] = sf_crmul(data[i2][i1],1.0f/maxd); #endif } } if (NULL != bad) { b = sf_floatalloc2(n1,n2); rt = sf_floatalloc3(n1,n2,2); grad2init (n1, n2, data, rt); for (i2=0; i2 < n2; i2++) { b[i2][n1-1] = 0.; b[i2][n1-2] = 0.; } for (i1=0; i1 < n1; i1++) { b[n2-1][i1] = 0.; b[n2-2][i1] = 0.; } for (i2=0; i2 < n2-2; i2++) { for (i1=0; i1 < n1-2; i1++) { b[i2][i1] = (rt[0][i2+1][i1] - rt[0][i2][i1]) - (rt[1][i2][i1+1] - rt[1][i2][i1]); } } sf_floatwrite(b[0],n1*n2,bad); } if (niter > 0) { h = sf_floatalloc(n1*n2); unwraper (n1,n2, data, h, niter); sf_floatwrite(h,n1*n2,out); } exit(0); }
int main(int argc, char* argv[]) { int n2, i2, i1, ic, id, nc, n; double xp; float *roots, *sol, *dat, x, o, d; sf_file inp, coef, out; sf_init(argc,argv); inp = sf_input("in"); out = sf_output("out"); if (!sf_histint(inp,"n1",&nc)) sf_error("No n1= in input"); nc++; n2 = sf_leftsize(inp,1); if (NULL != sf_getstring("coef")) { /* (optional) coefficients */ coef = sf_output("coef"); sf_putint(coef,"n1",nc); } else { coef = NULL; } roots = sf_floatalloc(nc-1); out = sf_output("out"); if (!sf_getint("n1",&n)) sf_error("Need n1="); /* number of samples */ if (!sf_getfloat("d1",&d)) sf_error("Need d1="); /* sampling */ if (!sf_getfloat("o1",&o)) sf_error("Need o1="); /* origin */ sf_putint(out,"n1",n); sf_putfloat(out,"d1",d); sf_putfloat(out,"o1",o); dat = sf_floatalloc(n); sol = sf_floatalloc(nc); sol[0]=1.0; for (i2=0; i2 < n2; i2++) { sf_floatread(roots,nc-1,inp); for (ic=1; ic < nc; ic++) { sol[ic]=0.0; } for (ic=0; ic < nc-1; ic++) { for (id=0; id <= ic; id++) { sol[id+1] -= roots[ic]*sol[id]; } } if (NULL != coef) sf_floatwrite(sol,nc,coef); for (i1=0; i1 < n; i1++) { dat[i1] = 0.; x = o+i1*d; xp = 1.0; for (ic=0; ic < nc; ic++) { dat[i1] += xp*sol[ic]; xp *= x; } } sf_floatwrite(dat,n,out); } exit(0); }
int main(int argc, char **argv) { int n1, n2, ninf, i1, i2, i, *inter2; char *label, *unit; float o1, d1, o2, d2, x, z; float *v0, *dvdx, *dvdz, *x0, *z0, *trace, **inter; sf_file model, surface; sf_init(argc, argv); surface = sf_input("in"); model = sf_output("out"); if (SF_FLOAT != sf_gettype(surface)) sf_error("Need float input"); if (!sf_histint(surface,"n1",&n2)) sf_error("No n1= in input"); if (!sf_histfloat(surface,"d1",&d2)) sf_error("No d1= in input"); if (!sf_histfloat(surface,"o1",&o2)) o2=0.; sf_shiftdim(surface, model, 1); sf_putint(model,"n3",1); if (!sf_histint(surface,"n2",&ninf)) ninf=1; if (!sf_getint("n1",&n1)) sf_error("Need n1="); /* Number of samples on the depth axis */ if (!sf_getfloat("d1",&d1)) sf_error("Need d1="); /* Sampling of the depth axis */ if (!sf_getfloat("o1",&o1)) o1=0.; /* Origin of the depth axis */ sf_putint(model,"n1",n1); sf_putfloat(model,"d1",d1); sf_putfloat(model,"o1",o1); if (NULL == (label = sf_getstring("label1"))) label="Depth"; /* depth axis label */ sf_putstring(model,"label1",label); if (NULL != (unit = sf_getstring("unit1"))) /* depth axis unit */ sf_putstring(model,"unit1",unit); inter = sf_floatalloc2(n2,ninf); inter2 = sf_intalloc(ninf); sf_floatread(inter[0],n2*ninf,surface); ninf++; /* more layers than interfaces */ v0 = sf_floatalloc(ninf); x0 = sf_floatalloc(ninf); z0 = sf_floatalloc(ninf); dvdx = sf_floatalloc(ninf); dvdz = sf_floatalloc(ninf); /* Input layer velocities and velocity derivatives */ if (!sf_getfloats("x0",x0,ninf)) for(i=0;i< ninf;i++) x0[i] = 0.; if (!sf_getfloats("z0",z0,ninf)) for(i=0;i< ninf;i++) z0[i] = 0.; if (!sf_getfloats("v00",v0,ninf)) for(i=0;i< ninf;i++) v0[i] = 1500.+ 500*i; if (!sf_getfloats("dvdx",dvdx,ninf)) for(i=0;i< ninf;i++) dvdx[i] = 0.; if (!sf_getfloats("dvdz",dvdz,ninf)) for(i=0;i< ninf;i++) dvdz[i] = 0.; trace = sf_floatalloc(n1); /* compute linear velocity */ for(i2=0; i2 < n2; i2++) { x = o2+i2*d2; for (i=0; i < ninf-1; i++) { inter2[i] = floorf(0.5+(inter[i][i2]-o1)/d1); } for(i1=0; i1 < n1; i1++) { z = o1+i1*d1; for (i=0; i < ninf-1; i++) { if (i1 < inter2[i]) break; } trace[i1] = v0[i] + (x-x0[i])*dvdx[i] + (z-z0[i])*dvdz[i]; } sf_floatwrite(trace,n1,model); } exit(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; 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; /* 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, t5; float timespent; float fx, fz; int isep=1; int ihomo=1; char *tapertype; double vp2, vs2, ep2, de2; 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; Fvp0 = sf_input ("in"); /* vp0 using standard input */ Fvs0 = sf_input ("vs0"); /* vs0 */ Feps = sf_input ("epsi"); /* epsi */ Fdel = sf_input ("del"); /* delta */ /* 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); 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); 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=155.0/dx; hnkz1=155.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, nzf, nxf); ez=sf_floatalloc4(nkz1, nkx1, nzf, nxf); exs=sf_floatalloc4(nkz1, nkx1, nzf, nxf); ezs=sf_floatalloc4(nkz1, nkx1, nzf, nxf); } /***************************************************************************** * 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]; 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; polvtipsv(apx,apz,apxs,apzs,kx,kz,kkx,kkz,kx2,kz2,taper,hnkx,hnkz,dkx,dkz, vp2,vs2,ep2,de2,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*/ fwpvtielastic(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); /******* 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) { t4=clock(); ////////////////////////////////////////////////////////////////////////////////////////// /* 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); t5=clock(); timespent=(float)(t5-t4)/CLOCKS_PER_SEC; sf_warning("Computation time (separation): %f (second)",timespent); }// 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 */ timespent=(float)(t5-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(coeff_2dx); free(coeff_2dz); free(coeff_1dx); free(coeff_1dz); free(*p1); free(*p2); free(*p3); free(*q1); free(*q2); free(*q3); free(*vp0); free(*vs0); free(*epsi); free(*del); exit(0); }
int main (int argc, char* argv[]) { int nz, nx, ny, ic, nc; float dz, oz, dx, ox, dy, oy; size_t i, n, sz; float *buf = NULL, *buf2 = NULL; #ifdef HAVE_SSE unsigned char pad[64]; #endif sf_file velz, velx = NULL, theta = NULL, phi = NULL, eta = NULL, out; bool verb; Ugrid z_grid, x_grid, y_grid; BCtype_s zBC, xBC, yBC; multi_UBspline_3d_s *velspline = NULL; sf_init (argc, argv); velz = sf_input ("in"); /* Vertical velocity */ out = sf_output ("out"); /* Spline coefficients */ /* Spatial dimensions */ if (!sf_histint (velz, "n1", &nz)) sf_error ("No n1= in input"); if (!sf_histint (velz, "n2", &nx)) sf_error ("No n2= in input"); if (!sf_histint (velz, "n3", &ny)) sf_error ("No n3= in input"); if (!sf_histfloat (velz, "d1", &dz)) sf_error ("No d1= in input"); if (!sf_histfloat (velz, "o1", &oz)) oz = 0.0; if (!sf_histfloat (velz, "d2", &dx)) sf_error ("No d2= in input"); if (!sf_histfloat (velz, "o2", &ox)) ox = 0.0; if (!sf_histfloat (velz, "d3", &dy)) sf_error ("No d3= in input"); if (!sf_histfloat (velz, "o3", &oy)) oy = 0.0; if (!sf_getbool ("verb", &verb)) verb = false; /* verbosity flag */ n = (size_t)nz*(size_t)nx*(size_t)ny; buf = sf_floatalloc (n); nc = 1; if (sf_getstring ("vx")) { /* Horizontal velocity */ velx = sf_input ("vx"); nc++; } if (sf_getstring ("eta")) { /* Anellipticity */ if (NULL == velx) sf_error ("Need vx=, if eta= is given"); eta = sf_input ("eta"); nc++; } else if (velx) sf_error ("Need eta=, if vx= is given"); if (sf_getstring ("theta")) { /* Tilt angle elevation */ if (NULL == velx) sf_error ("Need vx=, if theta= is given"); theta = sf_input ("theta"); nc++; } if (sf_getstring ("phi")) { /* Tilt angle azimuth */ if (NULL == theta) sf_error ("Need theta=, if phi= is given"); phi = sf_input ("phi"); nc++; } z_grid.start = oz; z_grid.end = oz + (nz - 1)*dz; z_grid.num = nz; x_grid.start = ox; x_grid.end = ox + (nx - 1)*dx; x_grid.num = nx; y_grid.start = oy; y_grid.end = oy + (ny - 1)*dy; y_grid.num = ny; zBC.lCode = zBC.rCode = NATURAL; xBC.lCode = xBC.rCode = NATURAL; yBC.lCode = yBC.rCode = NATURAL; velspline = create_multi_UBspline_3d_s (y_grid, x_grid, z_grid, yBC, xBC, zBC, nc); /* Read data and compute spline coefficients */ if (verb) sf_warning ("Processing V_z"); sf_floatread (buf, n, velz); if (1 == nc) { /* Isotropic case - convert velocity to slowness */ if (verb) sf_warning ("Converting to slowness for isotropic case"); for (i = 0; i < n; i++) buf[i] = 1.0/buf[i]; } else { /* Convert to V_z^2 */ for (i = 0; i < n; i++) buf[i] *= buf[i]; } ic = 0; set_multi_UBspline_3d_s (velspline, ic, buf); ic++; if (velx) { if (verb) sf_warning ("Processing V_x"); buf2 = sf_floatalloc (n); sf_floatread (buf2, n, velx); sf_fileclose (velx); /* Convert to V_x^2 */ for (i = 0; i < n; i++) buf2[i] *= buf2[i]; set_multi_UBspline_3d_s (velspline, ic, buf2); ic++; /* Convert to (V_z*V_x)^2 */ for (i = 0; i < n; i++) buf[i] *= buf2[i]; } if (eta) { if (verb) sf_warning ("Processing Eta"); sf_floatread (buf2, n, eta); sf_fileclose (eta); /* Convert to -8*eta/(1 + 2*eta)*(V_z*V_x)^2 */ for (i = 0; i < n; i++) { buf2[i] = -8.0*buf2[i]/(1.0 + 2.0*buf2[i]); buf2[i] *= buf[i]; } set_multi_UBspline_3d_s (velspline, ic, buf2); ic++; } if (theta) { if (verb) sf_warning ("Processing Theta"); sf_floatread (buf, n, theta); sf_fileclose (theta); /* Convert to radians */ for (i = 0; i < n; i++) buf[i] = buf[i]*SF_PI/180.0; set_multi_UBspline_3d_s (velspline, ic, buf); ic++; } if (phi) { if (verb) sf_warning ("Processing Phi"); sf_floatread (buf, n, phi); sf_fileclose (phi); /* Convert to radians */ for (i = 0; i < n; i++) buf[i] = buf[i]*SF_PI/180.0; set_multi_UBspline_3d_s (velspline, ic, buf); ic++; } if (buf2) free (buf2); free (buf); sz = (size_t)sizeof(multi_UBspline_3d_s) + (size_t)velspline->nc; #ifdef HAVE_SSE if (sizeof(multi_UBspline_3d_s) % 64) sz += 64 - (sizeof(multi_UBspline_3d_s) % 64); #endif /* Make output a 1-D file of coefficients */ sf_unshiftdim2 (velz, out, 1); /* Set up output */ sf_settype (out, SF_UCHAR); sf_putlargeint (out, "n1", sz); sf_putfloat (out, "o1", 0.0); sf_putfloat (out, "d1", 1.0); sf_putstring (out, "label1", "Spline coefficients"); sf_putstring (out, "unit1", ""); sf_putstring (out, "label2", ""); sf_putstring (out, "unit2", ""); sf_putint (out, "Nz", nz); sf_putfloat (out, "Oz", oz); sf_putfloat (out, "Dz", dz); sf_putint (out, "Nx", nx); sf_putfloat (out, "Ox", ox); sf_putfloat (out, "Dx", dx); sf_putint (out, "Ny", ny); sf_putfloat (out, "Oy", oy); sf_putfloat (out, "Dy", dy); sf_putint (out, "Nc", nc); sf_putstring (out, "splines", "y"); if (verb) { sf_warning ("Number of spline coefficients: %lu", velspline->nc/(size_t)sizeof(float)); sf_warning ("Writing spline coefficients"); } sf_ucharwrite ((unsigned char*)velspline, (size_t)sizeof(multi_UBspline_3d_s), out); #ifdef HAVE_SSE if (sizeof(multi_UBspline_3d_s) % 64) sf_ucharwrite (pad, (size_t)(64 - (sizeof(multi_UBspline_3d_s) % 64)), out); #endif sf_ucharwrite ((unsigned char*)velspline->coefs, (size_t)velspline->nc, out); destroy_Bspline (velspline); return 0; }
/* initialize the length of axis and the number of tics */ void vp_axis_init (const sf_file in) { float ftmp, num; bool want; char *stmp, *label, *unit; size_t len; struct Axis axis; if (!sf_getint ("axisfat",&axisfat)) axisfat=0; if (!sf_getint ("axiscol",&axiscol)) axiscol=7; if (!sf_getint ("labelfat",&labelfat)) labelfat=0; if (!sf_getfloat ("labelsz",&labelsz)) labelsz=8.; if ((NULL == (label=sf_getstring("label1"))) && (NULL == (label=sf_histstring(in,"label1")))) { axis1.label = blank; } else if ((NULL == (unit=sf_getstring("unit1"))) && (NULL == (unit=sf_histstring(in,"unit1")))) { axis1.label = label; } else { len = strlen(label)+strlen(unit)+4; axis1.label = sf_charalloc(len); snprintf(axis1.label,len,"%s (%s)",label,unit); free(label); free(unit); } if ((NULL == (label=sf_getstring("label2"))) && (NULL == (label=sf_histstring(in,"label2")))) { axis2.label = blank; } else if ((NULL == (unit=sf_getstring("unit2"))) && (NULL == (unit=sf_histstring(in,"unit2")))) { axis2.label = label; } else { len = strlen(label)+strlen(unit)+4; axis2.label = sf_charalloc(len); snprintf(axis2.label,len,"%s (%s)",label,unit); free(label); free(unit); } where1 = (NULL != (stmp = sf_getstring ("wherexlabel")) && 'b' == *stmp); where2 = (NULL != (stmp = sf_getstring ("whereylabel")) && 'r' == *stmp); /* checking to see if wantaxis is fetched */ if (!sf_getbool ("wantaxis", &want)) { /* setting the default to put the axes on the plot */ want = true; axis1.want = true; axis2.want = true; } else if (!want) { axis1.want = false; axis2.want = false; } else { if (!sf_getbool ("wantaxis1",&(axis1.want))) axis1.want = true; if (!sf_getbool ("wantaxis2",&(axis2.want))) axis2.want = true; } /* frame or axis */ wheretics = NULL != (stmp = sf_getstring ("wheretics")) && 'a' == *stmp; if (!sf_getfloat ("axisor1",&(axis1.or))) axis1.or = where1? min2: max2; if (!sf_getfloat ("axisor2",&(axis2.or))) axis2.or = where2? min1: max1; if (!sf_getint ("n1tic",&(axis1.ntic))) axis1.ntic = 1; if (!sf_getint ("n2tic",&(axis2.ntic))) axis2.ntic = 1; if (!sf_getfloat ("d1num", &(axis1.dnum))) getscl (&axis1); if (!sf_getfloat ("d2num", &(axis2.dnum))) getscl (&axis2); if (0. == axis1.dnum) sf_error("%s: zero d1num",__FILE__); if (0. == axis2.dnum) sf_error("%s: zero d2num",__FILE__); if (!sf_getfloat("o1num",&(axis1.num0))) { ftmp = (min1 < max1)? min1: max1; for (num = floorf(ftmp / axis1.dnum) * axis1.dnum - axis1.dnum; num < ftmp; num += axis1.dnum) ; axis1.num0 = num; } if (!sf_getfloat("o2num",&(axis2.num0))) { ftmp = (min2 < max2)? min2: max2; for (num = floorf(ftmp / axis2.dnum) * axis2.dnum - axis2.dnum; num < ftmp; num += axis2.dnum) ; axis2.num0 = num; } axis1.dtic = axis1.dnum / axis1.ntic ; ftmp = (min1 < max1)? min1: max1; for (num = axis1.num0 - axis1.ntic * axis1.dtic; num < ftmp; num += axis1.dtic); axis1.tic0 = num; axis2.dtic = axis2.dnum / axis2.ntic ; ftmp = (min2 < max2)? min2: max2; for (num = axis2.num0 - axis2.ntic * axis2.dtic; num < ftmp; num += axis2.dtic); axis2.tic0 = num; if (transp) { /* swap */ axis = axis1; axis1 = axis2; axis2 = axis; } if(yreverse) axis1.or = (min2+max2)-axis1.or; if(xreverse) axis2.or = (min1+max1)-axis2.or; }