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 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 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[]) { 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[]) { bool verb,pas,adj,abc; /* execution flags */ int ix, iz, it; /* index variables */ int nt, nx, nz, depth, nzxpad, nb, n2, snap; float ox, oz, dx, dz, dt, dt2, idz2, idx2, cb; int nxpad, nzpad; float **vvpad; float **dd, **mm, **vv, ***ww; float **u0, **u1, **u2, **tmp; /* temporary arrays */ sf_file in, out, vel, wave; /* I/O files */ /* initialize Madagascar */ sf_init(argc,argv); /* initialize OpenMP support */ #ifdef _OPENMP omp_init(); #endif if(!sf_getbool("verb", &verb)) verb=false; /* verbosity flag */ if(!sf_getbool("adj", &adj)) adj=false; /* adjoint flag, 0: modeling, 1: migration */ if(!sf_getbool("pas", &pas)) pas=false; /* passive flag, 0: exploding reflector rtm, 1: passive seismic imaging */ if(!sf_getbool("abc",&abc)) abc = false; /* absorbing boundary condition */ if(!sf_getint("snap", &snap)) snap=0; /* wavefield snapshot flag */ if(!sf_getint("depth", &depth)) depth=0; /* surface */ /* setup I/O files */ in = sf_input("in"); out = sf_output("out"); vel = sf_input("velocity"); /* velocity model */ /* Dimensions */ if(!sf_histint (vel, "n1", &nz)) sf_error("No n1= in velocity"); if(!sf_histint (vel, "n2", &nx)) sf_error("No n2= in velocity"); if(!sf_histfloat(vel, "o1", &oz)) sf_error("No o1= in velocity"); if(!sf_histfloat(vel, "o2", &ox)) sf_error("No o2= in velocity"); if(!sf_histfloat(vel, "d1", &dz)) sf_error("No d1= in velocity"); if(!sf_histfloat(vel, "d2", &dx)) sf_error("No d2= in velocity"); if(adj){ /* migration */ if(!sf_histint(in, "n1", &nt)) sf_error("No n1= in data"); if(!sf_histfloat(in, "d1", &dt)) sf_error("No d1= in data"); if(!sf_histint(in, "n2", &n2) || n2!=nx) sf_error("Need n2=%d in data", nx); sf_putint (out, "n1", nz); sf_putfloat (out, "o1", oz); sf_putfloat (out, "d1", dz); sf_putstring(out, "label1", "Depth"); sf_putstring(out, "unit1" , "km"); sf_putint (out, "n2", nx); sf_putfloat (out, "o2", ox); sf_putfloat (out, "d2", dx); sf_putstring(out, "label2", "Distance"); sf_putstring(out, "unit2" , "km"); if (pas) { sf_putint (out, "n3", nt); sf_putfloat (out, "d3", dt); sf_putfloat (out, "o3", 0.0f); sf_putstring(out, "label3", "Time"); sf_putstring(out, "unit3" , "s"); } }else{ /* modeling */ if(!sf_getint("nt", &nt)) sf_error("Need nt="); if(!sf_getfloat("dt", &dt)) sf_error("Need dt="); sf_putint (out, "n1", nt); sf_putfloat (out, "d1", dt); sf_putfloat (out, "o1", 0.0); sf_putstring(out, "label1", "Time"); sf_putstring(out, "unit1" , "s"); sf_putint (out, "n2", nx); sf_putfloat (out, "o2", ox); sf_putfloat (out, "d2", dx); sf_putstring(out, "label2", "Distance"); sf_putstring(out, "unit2" , "km"); if (pas) { sf_putint (out, "n3", 1); } } /* dimension of padded boundary */ if(!sf_getint("nb", &nb) || nb<NOP) nb = NOP; if(!sf_getfloat("cb", &cb)) cb = 0.0f; nxpad = nx+2*nb; nzpad = nz+2*nb; nzxpad = nzpad*nxpad; depth = depth+nb; /* set Laplacian coefficients */ idz2 = 1.0f/(dz*dz); idx2 = 1.0f/(dx*dx); /* wavefield snapshot */ if(snap){ wave = sf_output("wave"); sf_putint(wave, "n1", nzpad); sf_putfloat(wave, "d1", dz); sf_putfloat(wave, "o1", oz-nb*dz); sf_putint(wave, "n2", nxpad); sf_putfloat(wave, "d2", dx); sf_putfloat(wave, "o2", ox-nb*dx); sf_putint(wave, "n3", 1+(nt-1)/snap); if(adj){ sf_putfloat(wave, "d3", -snap*dt); sf_putfloat(wave, "o3", (nt-1)*dt); }else{ sf_putfloat(wave, "d3", snap*dt); sf_putfloat(wave, "o3", 0.0f); } } /* allocate arrays */ vv = sf_floatalloc2(nz, nx); dd = sf_floatalloc2(nt, nx); vvpad = sf_floatalloc2(nzpad, nxpad); u0 = sf_floatalloc2(nzpad, nxpad); u1 = sf_floatalloc2(nzpad, nxpad); u2 = sf_floatalloc2(nzpad, nxpad); if (pas) { mm = NULL; ww = sf_floatalloc3(nz, nx, nt); } else { mm = sf_floatalloc2(nz, nx); ww = NULL; } /* read velocity */ sf_floatread(vv[0], nz*nx, vel); /* pad boundary */ dt2 = dt*dt; for (ix=0; ix<nx; ix++) for (iz=0; iz<nz; iz++) vvpad[ix+nb][iz+nb] = vv[ix][iz]*vv[ix][iz]*dt2; for (ix=0; ix<nxpad; ix++){ for (iz=0; iz<nb; iz++){ vvpad[ix][ iz ] = vvpad[ix][ nb ]; vvpad[ix][nzpad-iz-1] = vvpad[ix][nzpad-nb-1]; } } for (ix=0; ix<nb; ix++){ for (iz=0; iz<nzpad; iz++){ vvpad[ ix ][iz]=vvpad[ nb ][iz]; vvpad[nxpad-ix-1][iz]=vvpad[nxpad-nb-1][iz]; } } memset(u0[0], 0.0f, nzxpad*sizeof(float)); memset(u1[0], 0.0f, nzxpad*sizeof(float)); memset(u2[0], 0.0f, nzxpad*sizeof(float)); /* absorbing boundary condition */ if (abc) { if (verb) sf_warning("absorbing boundary condition"); abc_init(nzpad,nxpad,nzpad,nxpad,nb,nb,nb,nb,cb,cb,cb,cb); } if(adj){ /* migration */ /* read data */ sf_floatread(dd[0], nt*nx, in); for (it=nt-1; it>-1; it--){ if (verb) sf_warning("Migration: %d/%d;", it, 0); /* time stepping */ #ifdef _OPENMP #pragma omp parallel for default(shared) private(ix, iz) #endif for (ix=NOP; ix<nxpad-NOP; ix++){ for (iz=NOP; iz<nzpad-NOP; iz++){ u2[ix][iz] = LapT(u1,ix,iz,idx2,idz2,vvpad) + 2.0f*u1[ix][iz] - u0[ix][iz]; } } /* rotate pointers */ tmp=u0; u0=u1; u1=u2; u2=tmp; if (abc) abc_apply(u1[0]); if (abc) abc_apply(u0[0]); /* inject data */ #ifdef _OPENMP #pragma omp parallel for default(shared) private(ix) #endif for (ix=nb; ix<nb+nx; ix++) u1[ix][depth] += dd[ix-nb][it]; if (pas) { /* image source */ #ifdef _OPENMP #pragma omp parallel for default(shared) private(ix, iz) #endif for (ix=0; ix<nx; ix++) for (iz=0; iz<nz; iz++) ww[it][ix][iz] = u1[ix+nb][iz+nb]; } if (snap && it%snap==0) sf_floatwrite(u1[0], nzxpad, wave); } if (verb) sf_warning("."); if (!pas) { /* output image */ #ifdef _OPENMP #pragma omp parallel for default(shared) private(ix, iz) #endif for (ix=0; ix<nx; ix++) for (iz=0; iz<nz; iz++) mm[ix][iz] = u1[ix+nb][iz+nb]; sf_floatwrite(mm[0], nz*nx, out); } else { /* output source */ sf_floatwrite(ww[0][0], nz*nx*nt, out); } }else{/* modeling */ if (pas) { /* read source */ sf_floatread(ww[0][0], nz*nx*nt, in); } else { /* read image */ sf_floatread(mm[0], nz*nx, in); #ifdef _OPENMP #pragma omp parallel for default(shared) private(ix, iz) #endif for (ix=0; ix<nx; ix++) for (iz=0; iz<nz; iz++) u1[ix+nb][iz+nb] = mm[ix][iz]; } for (it=0; it<nt; it++){ if (verb) sf_warning("Modeling: %d/%d;", it, nt-1); if(snap && it%snap==0) sf_floatwrite(u1[0], nzxpad, wave); if (pas){ /* inject source */ #ifdef _OPENMP #pragma omp parallel for default(shared) private(ix, iz) #endif for (ix=0; ix<nx; ix++) for (iz=0; iz<nz; iz++) u1[ix+nb][iz+nb] += ww[it][ix][iz]; } /* record data */ #ifdef _OPENMP #pragma omp parallel for default(shared) private(ix) #endif for (ix=nb; ix<nb+nx; ix++) dd[ix-nb][it] = u1[ix][depth]; if (abc) abc_apply(u0[0]); if (abc) abc_apply(u1[0]); /* time stepping */ #ifdef _OPENMP #pragma omp parallel for default(shared) private(ix, iz) #endif for (ix=NOP; ix<nxpad-NOP; ix++){ for (iz=NOP; iz<nzpad-NOP; iz++){ u2[ix][iz] = Lap (u1,ix,iz,idx2,idz2,vvpad) + 2.0f*u1[ix][iz] - u0[ix][iz]; } } /* rotate pointers */ tmp=u0; u0=u1; u1=u2; u2=tmp; } if (verb) sf_warning("."); /* output data */ sf_floatwrite(dd[0], nt*nx, out); } if(pas) { free(**ww); free(*ww); free(ww); } else { free(*mm); free(mm); } if (abc) abc_close(); free(*vvpad); free(vvpad); free(*vv); free(vv); free(*dd); free(dd); free(*u0); free(u0); free(*u1); free(u1); free(*u2); free(u2); 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 n1, n2, n3, i1, i2, i3, j1, j2, k1, k2, nedge, nold, nmin, nmax, n12; int **edge; float **pp, **ww, **w1, **w2, g1, g2, w, min, max; sf_file in=NULL, out=NULL; sf_init(argc,argv); in = sf_input("in"); out = sf_output("out"); if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(in,"n2",&n2)) sf_error("No n2= in input"); n3 = sf_leftsize(in,2); if (!sf_getfloat("min",&min)) min=5.0; /* minimum threshold */ if (!sf_getfloat("max",&max)) max=95.0; /* maximum threshold */ n12 = n1*n2; nmin = min*0.01*n12; if (nmin < 0) nmin=0; if (nmin >= n12) nmin=n12-1; nmax = max*0.01*n12; if (nmax < 0) nmax=0; if (nmax >= n12) nmax=n12-1; pp = sf_floatalloc2(n1,n2); w1 = sf_floatalloc2(n1,n2); w2 = sf_floatalloc2(n1,n2); ww = sf_floatalloc2(n1,n2); edge = sf_intalloc2(n1,n2); sf_settype(out,SF_INT); for (i3=0; i3 < n3; i3++) { sf_floatread(pp[0],n12,in); /* gradient computation */ sf_sobel(n1,n2,pp,w1,w2); for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1; i1++) { /* gradient norm */ g1 = w1[i2][i1]; g2 = w2[i2][i1]; ww[i2][i1] = g1*g1+g2*g2; } } /* edge thinning */ for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1; i1++) { g1 = w1[i2][i1]; g2 = w2[i2][i1]; if (fabsf(g1) > fabsf(g2)) { j1=1; if (g2/g1 > 0.5) { j2=1; } else if (g2/g1 < - 0.5) { j2=-1; } else { j2=0; } } else if (fabsf(g2) > fabsf(g1)) { j2=1; if (g1/g2 > 0.5) { j1=1; } else if (g1/g2 < - 0.5) { j1=-1; } else { j1=0; } } else { j1=0; j2=0; } k1 = i1+j1; if (j1 && (k1 < 0 || k1 >= n1)) k1=i1; k2 = i2+j2; if (j2 && (k2 < 0 || k2 >= n2)) k2=i2; if (ww[i2][i1] <= ww[k2][k1]) { pp[i2][i1] = 0.; continue; } k1 = i1-j1; if (k1 < 0 || k1 >= n1) k1=i1; k2 = i2-j2; if (k2 < 0 || k2 >= n2) k2=i2; if (ww[i2][i1] <= ww[k2][k1]) { pp[i2][i1] = 0.; continue; } pp[i2][i1] = ww[i2][i1]; } } /* edge selection */ max = sf_quantile(nmax,n12,ww[0]); min = sf_quantile(nmin,n12,ww[0]); nedge=0; for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1; i1++) { w = pp[i2][i1]; if (w > max) { edge[i2][i1] = SF_IN; nedge++; } else if (w < min) { edge[i2][i1] = SF_OUT; } else { edge[i2][i1] = SF_FRONT; } } } nold=0; while (nedge != nold) { nold = nedge; for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1; i1++) { if (SF_FRONT == edge[i2][i1]) { if (i2 > 0) { if (SF_IN == edge[i2-1][i1] || (i1 > 0 && SF_IN == edge[i2-1][i1-1]) || (i1 < n1-1 && SF_IN == edge[i2-1][i1+1])) { edge[i2][i1] = SF_IN; nedge++; continue; } } if (i2 < n2-1) { if (SF_IN == edge[i2+1][i1] || (i1 > 0 && SF_IN == edge[i2+1][i1-1]) || (i1 < n1-1 && SF_IN == edge[i2+1][i1+1])) { edge[i2][i1] = SF_IN; nedge++; continue; } } if ((i1 > 0 && SF_IN == edge[i2][i1-1]) || (i1 < n1-1 && SF_IN == edge[i2][i1+1])) { edge[i2][i1] = SF_IN; nedge++; continue; } } } } } for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1; i1++) { if (SF_FRONT == edge[i2][i1]) edge[i2][i1] = SF_OUT; } } sf_intwrite(edge[0],n12,out); } exit(0); }
int main (int argc, char* argv[]) { map4 nmo; /* using cubic spline interpolation */ bool half; int it,ix,iy, nt, nx, ny, nw, i4, n4, n; float dt, t0, x, y, x0, y0, f, dx, dy, eps; float *trace=NULL, *vx=NULL, *vy=NULL, *vxy=NULL, *str=NULL, *out=NULL; sf_file cmp=NULL, nmod=NULL, vel=NULL; sf_init (argc,argv); cmp = sf_input("in"); 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",&nx)) sf_error("No n2= in input"); if (!sf_histint(cmp,"n3",&ny)) sf_error("No n3= in input"); n4 = sf_leftsize(cmp,3); vel = sf_input("velocity"); if (SF_FLOAT != sf_gettype(vel)) sf_error("Need float velocity"); if (!sf_histint(vel,"n1",&n) || nt != n) sf_error("Need n1=%d in velocity",nt); if (!sf_histint(vel,"n2",&n) || 3 != n) sf_error("Need n2=3 in velocity",nt); if (n4 != sf_leftsize(vel,2)) sf_error("Wrong dimensions in velocity"); if (!sf_histfloat(cmp,"d2",&dx)) sf_error("No d2= in input"); if (!sf_histfloat(cmp,"o2",&x0)) sf_error("No o2= in input"); if (!sf_histfloat(cmp,"d3",&dy)) sf_error("No d3= in input"); if (!sf_histfloat(cmp,"o3",&y0)) sf_error("No o3= in input"); if (!sf_getbool("half",&half)) half=true; /* if y, the second and third axes are half-offset instead of full offset */ if (half) { /* get full offset - multiply by 2 */ dx *= 2.; dy *= 2.; x0 *= 2.; y0 *= 2.; sf_warning("Since half=y, offsets were doubled."); }else{ sf_warning("Since half=n, offsets not doubled."); } if (!sf_getfloat("eps",&eps)) eps=0.01; /* stretch regularization */ trace = sf_floatalloc(nt); vx = sf_floatalloc(nt); vy = sf_floatalloc(nt); vxy = sf_floatalloc(nt); str = sf_floatalloc(nt); out = sf_floatalloc(nt); if (!sf_getint("extend",&nw)) nw=8; /* trace extension */ nmo = stretch4_init (nt, t0, dt, nt, eps); for (i4=0; i4 < n4; i4++) { /* loop over cmps */ sf_floatread (vx,nt,vel); sf_floatread (vy,nt,vel); sf_floatread (vxy,nt,vel); for (iy = 0; iy < ny; iy++) { y = y0+iy*dy; for (ix = 0; ix < nx; ix++) { x = x0 + ix*dx; sf_floatread (trace,nt,cmp); for (it=0; it < nt; it++) { f = t0 + it*dt; f = f*f + x*x*vx[it]+y*y*vy[it]+2*x*y*vxy[it]; if (f < 0.) { str[it]=t0-10.*dt; } else { str[it] = sqrtf(f); } } stretch4_define (nmo,str); stretch4_apply (nmo,trace,out); sf_floatwrite (out,nt,nmod); } /* ix */ } /* iy */ } /* i4 */ exit (0); }
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, n1, n2, n12, nj1, nj2, niter, nw, n3, i3; float eps, *d, *s, *nd, **nn, **ss; bool verb; sf_file in, out, ndip, sdip; sf_init (argc,argv); in = sf_input("in"); ndip = sf_input("ndip"); sdip = sf_input("sdip"); out = sf_output("out"); if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(in,"n2",&n2)) sf_error("No n2= in input"); n12 = n1*n2; n3 = sf_leftsize(in,2); if (1==n3) sf_putint (out,"n3",2); if (!sf_getint ("niter",&niter)) niter=50; /* maximum number of iterations */ if (!sf_getfloat ("eps",&eps)) eps=1.; /* regularization parameter */ if (!sf_getint("order",&nw)) nw=1; /* [1,2,3] accuracy order */ if (nw < 1 || nw > 3) sf_error ("Unsupported nw=%d, choose between 1 and 3",nw); if (!sf_getint("nj1",&nj1)) nj1=1; /* antialiasing for noise dip */ if (!sf_getint("nj2",&nj2)) nj2=1; /* antialiasing for signal dip */ if (!sf_getbool("verb",&verb)) verb = false; /* verbosity flag */ nd = sf_floatalloc(2*n12); s = sf_floatalloc(n12); d = sf_floatalloc(n12); nn = sf_floatalloc2(n1,n2); ss = sf_floatalloc2(n1,n2); for (i=0; i < n12; i++) { nd[n12+i] = 0.; } planesignoi_init (nw, nj1,nj2, n1,n2, nn, ss, eps); for (i3=0; i3 < n3; i3++) { sf_floatread (d,n12,in); sf_floatread (nn[0],n12,ndip); sf_floatread (ss[0],n12,sdip); allpass22_init(allpass2_init(nw,nj1,n1,n2,nn)); allpass21_lop (false,false,n12,n12,d,nd); sf_solver (planesignoi_lop, sf_cgstep, n12, n12*2, s, nd, niter, "verb", verb, "end"); sf_cgstep_close(); sf_floatwrite(s,n12,out); if (1==n3) { for (i=0; i < n12; i++) { d[i] -= s[i]; } sf_floatwrite(d,n12,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 nh, n1,n2, i1,i2, i, n12, niter, dim, n[SF_MAX_DIM], rect[SF_MAX_DIM]; int shrt, lng; float *trace, *hilb, *num, *den, *phase, mean, c; char key[6]; sf_triangle ts, tl; sf_file in, out; sf_init (argc,argv); in = sf_input("in"); out = sf_output("out"); if (SF_FLOAT != sf_gettype(in)) sf_error("Need float input"); dim = sf_filedims (in,n); n1 = n[0]; n12 = 1; for (i=0; i < dim; i++) { snprintf(key,6,"rect%d",i+1); if (!sf_getint(key,rect+i)) rect[i]=1; n12 *= n[i]; } n2 = n12/n1; num = sf_floatalloc(n12); den = sf_floatalloc(n12); phase = sf_floatalloc(n12); if (!sf_getint("niter",&niter)) niter=100; /* number of iterations */ if (!sf_getint("order",&nh)) nh=10; /* Hilbert transformer order */ if (!sf_getfloat("ref",&c)) c=1.; /* Hilbert transformer reference (0.5 < ref <= 1) */ sf_hilbert_init(n1, nh, c); if (!sf_getint("short",&shrt)) shrt=1; /* short smoothing radius */ if (!sf_getint("long",&lng)) lng=10; /* long smoothing radius */ ts = sf_triangle_init(shrt,n1,false); tl = sf_triangle_init(lng,n1,false); mean=0.; for (i2=0; i2 < n2; i2++) { trace = num+n1*i2; hilb = den+n1*i2; sf_floatread(trace,n1,in); sf_hilbert(trace,hilb); for (i1=0; i1 < n1; i1++) { trace[i1] = hypotf(trace[i1],hilb[i1]); hilb[i1] = trace[i1]; } sf_smooth2 (ts, 0, 1, false, trace); sf_smooth2 (tl, 0, 1, false, hilb); for (i1=0; i1 < nh; i1++) { trace[i1] = 0.; hilb[i1] = 0.; } for (i1=nh; i1 < n1-nh; i1++) { mean += hilb[i1]*hilb[i1]; } for (i1=n1-nh; i1 < n1; i1++) { trace[i1] = 0.; hilb[i1] = 0.; } } mean = sqrtf(n12/mean); for (i=0; i < n12; i++) { num[i] *= mean; den[i] *= mean; } sf_divn_init(dim, n12, n, rect, niter, true); sf_divn (num, den, phase); sf_floatwrite(phase,n12,out); 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[]) { sf_map4 mo; bool inv, each=true; int i, nt, n1, i2, n2, nw; float o1, d1, t0, dt, eps; sf_complex *ctrace, *ctrace2; float *trace, *str, *trace2; sf_file in, out, warp; sf_init(argc,argv); in = sf_input("in"); out = sf_output("out"); warp = sf_input("warp"); if (!sf_getbool("inv",&inv)) inv=true; /* inversion flag */ if (inv) { if (!sf_histint(in,"n1",&nt)) sf_error("No n1= in input"); if (!sf_getint("n1",&n1)) n1=nt; /* output samples - for inv=y */ if (!sf_getfloat("d1",&d1) && !sf_histfloat(in,"d1",&d1)) d1=1.; /*( d1=1 output sampling - for inv=y )*/ if (!sf_getfloat("o1",&o1) && !sf_histfloat(in,"o1",&o1)) o1=0.; /*( o1=0 output origin - for inv=y )*/ sf_putint(out,"n1",n1); sf_putfloat(out,"d1",d1); sf_putfloat(out,"o1",o1); } else { if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histfloat(in,"d1",&d1)) d1=1.; if (!sf_histfloat(in,"o1",&o1)) o1=0.; if (!sf_histint(warp,"n1",&nt)) sf_error("No n1= in warp"); if (!sf_histfloat(warp,"d1",&dt)) dt=d1; if (!sf_histfloat(warp,"o1",&t0)) t0=o1; sf_putint(out,"n1",nt); sf_putfloat(out,"d1",dt); sf_putfloat(out,"o1",t0); } n2 = sf_leftsize(in,1); nw = sf_leftsize(warp,1); if (1 == nw) { each = false; } else if (n2 != nw) { sf_error("Need %d traces in warp, got %d",n2,nw); } if (!sf_getfloat("eps",&eps)) eps=0.01; /* stretch regularization */ trace = sf_floatalloc(nt); str = sf_floatalloc(nt); trace2 = sf_floatalloc(n1); mo = sf_stretch4_init (n1, o1, d1, nt, eps); if (SF_COMPLEX == sf_gettype(in)) { ctrace = sf_complexalloc(nt); ctrace2 = sf_complexalloc(n1); } else { ctrace = ctrace2 = NULL; } for (i2=0; i2 < n2; i2++) { if (each || 0==i2) { sf_floatread(str,nt,warp); sf_stretch4_define (mo,str); } if (inv) { if (SF_COMPLEX == sf_gettype(in)) { sf_complexread(ctrace,nt,in); for (i=0; i < nt; i++) { trace[i] = crealf(ctrace[i]); } sf_stretch4_apply (false,mo,trace,trace2); for (i=0; i < n1; i++) { ctrace2[i] = sf_cmplx(trace2[i],0.0f); } for (i=0; i < nt; i++) { trace[i] = cimagf(ctrace[i]); } sf_stretch4_apply (false,mo,trace,trace2); for (i=0; i < n1; i++) { #ifdef SF_HAS_COMPLEX_H ctrace2[i] += sf_cmplx(0.0f,trace2[i]); #else ctrace2[i] = sf_cadd(ctrace2[i],sf_cmplx(0.0f,trace2[i])); #endif } sf_complexwrite (ctrace2,n1,out); } else { sf_floatread(trace,nt,in); sf_stretch4_apply (false,mo,trace,trace2); sf_floatwrite (trace2,n1,out); } } else { if (SF_COMPLEX == sf_gettype(in)) { sf_complexread (ctrace2,n1,out); for (i=0; i < n1; i++) { trace2[i] = crealf(ctrace2[i]); } sf_stretch4_invert (false,mo,trace,trace2); for (i=0; i < nt; i++) { ctrace[i] = sf_cmplx(trace[i],0.0f); } for (i=0; i < n1; i++) { trace2[i] = cimagf(ctrace2[i]); } sf_stretch4_invert (false,mo,trace,trace2); for (i=0; i < nt; i++) { #ifdef SF_HAS_COMPLEX_H ctrace[i] += sf_cmplx(0.0f,trace[i]); #else ctrace[i] = sf_cadd(ctrace[i],sf_cmplx(0.0f,trace[i])); #endif } sf_complexwrite(ctrace,nt,in); } else { sf_floatread(trace2,n1,in); sf_stretch4_invert (false,mo,trace,trace2); sf_floatwrite (trace,nt,out); } } } exit(0); }
int main(int argc, char* argv[]) { bool adj,timer,verb,gmres; int nt, nx, nz, nx2, nz2, nzx, nzx2, ntx, pad1, snap, gpz, wfnt, i; int m2, n2, nk, nth=1; int niter, mem; float dt, dx, dz, ox; sf_complex *img, *imgout, *dat, **lt1, **rt1, **lt2, **rt2, ***wvfld; sf_file data, image, leftf, rightf, leftb, rightb, snaps; double time=0.,t0=0.,t1=0.; geopar geop; sf_init(argc,argv); /* essentially doing imaging */ adj = true; if (!sf_getbool("gmres",&gmres)) gmres=false; if (gmres) { if (!sf_getint("niter",&niter)) niter=10; if (!sf_getint("mem",&mem)) mem=20; } if(! sf_getbool("timer",&timer)) timer=false; if (!sf_getbool("verb",&verb)) verb=false; if (!sf_getint("snap",&snap)) snap=0; /* interval for snapshots */ if (!sf_getint("pad1",&pad1)) pad1=1; /* padding factor on the first axis */ if(!sf_getint("gpz",&gpz)) gpz=0; /* geophone surface */ /* adj */ if (!sf_getint("nz",&nz)) sf_error("Need nz="); /* depth samples */ if (!sf_getfloat("dz",&dz)) sf_error("Need dz="); /* depth sampling */ /* for */ if (!sf_getint("nt",&nt)) sf_error("Need nt="); /* time samples */ if (!sf_getfloat("dt",&dt)) sf_error("Need dt="); /* time sampling */ if (adj) { /* migration */ data = sf_input("in"); image = sf_output("out"); sf_settype(image,SF_COMPLEX); if (!sf_histint(data,"n1",&nt)) sf_error("No n1= in input"); if (!sf_histfloat(data,"d1",&dt)) sf_error("No d1= in input"); if (!sf_histint(data,"n2",&nx)) sf_error("No n2= in input"); if (!sf_histfloat(data,"d2",&dx)) sf_error("No d2= in input"); if (!sf_histfloat(data,"o2",&ox)) ox=0.; sf_putint(image,"n1",nz); sf_putfloat(image,"d1",dz); sf_putfloat(image,"o1",0.); sf_putstring(image,"label1","Depth"); sf_putint(image,"n2",nx); sf_putfloat(image,"d2",dx); sf_putfloat(image,"o2",ox); sf_putstring(image,"label2","Distance"); } else { /* modeling */ image = sf_input("in"); data = sf_output("out"); sf_settype(data,SF_COMPLEX); if (!sf_histint(image,"n1",&nz)) sf_error("No n1= in input"); if (!sf_histfloat(image,"d1",&dz)) sf_error("No d1= in input"); if (!sf_histint(image,"n2",&nx)) sf_error("No n2= in input"); if (!sf_histfloat(image,"d2",&dx)) sf_error("No d2= in input"); if (!sf_histfloat(image,"o2",&ox)) ox=0.; if (!sf_getint("nt",&nt)) sf_error("Need nt="); /* time samples */ if (!sf_getfloat("dt",&dt)) sf_error("Need dt="); /* time sampling */ sf_putint(data,"n1",nt); sf_putfloat(data,"d1",dt); sf_putfloat(data,"o1",0.); sf_putstring(data,"label1","Time"); sf_putstring(data,"unit1","s"); sf_putint(data,"n2",nx); sf_putfloat(data,"d2",dx); sf_putfloat(data,"o2",ox); sf_putstring(data,"label2","Distance"); } nz2 = kiss_fft_next_fast_size(nz*pad1); nx2 = kiss_fft_next_fast_size(nx); nk = nz2*nx2; /*wavenumber*/ nzx = nz*nx; nzx2 = nz2*nx2; ntx = nt*nx; if (snap > 0) { wfnt = (int)(nt-1)/snap+1; snaps = sf_output("snaps"); /* (optional) snapshot file */ sf_settype(snaps,SF_COMPLEX); sf_putint(snaps,"n1",nz); sf_putfloat(snaps,"d1",dz); sf_putfloat(snaps,"o1",0.); sf_putstring(snaps,"label1","Depth"); sf_putint(snaps,"n2",nx); sf_putfloat(snaps,"d2",dx); sf_putfloat(snaps,"o2",ox); sf_putstring(snaps,"label2","Distance"); sf_putint(snaps,"n3",wfnt); sf_putfloat(snaps,"d3",dt*snap); sf_putfloat(snaps,"o3",0.); sf_putstring(snaps,"label3","Time"); } else { wfnt = 0; snaps = NULL; } /* propagator matrices */ leftf = sf_input("leftf"); rightf = sf_input("rightf"); if (!sf_histint(leftf,"n1",&n2) || n2 != nzx) sf_error("Need n1=%d in leftf",nzx); if (!sf_histint(leftf,"n2",&m2)) sf_error("No n2= in leftf"); if (!sf_histint(rightf,"n1",&n2) || n2 != m2) sf_error("Need n1=%d in rightf",m2); if (!sf_histint(rightf,"n2",&n2) || n2 != nk) sf_error("Need n2=%d in rightf",nk); leftb = sf_input("leftb"); rightb = sf_input("rightb"); if (!sf_histint(leftb,"n1",&n2) || n2 != nzx) sf_error("Need n1=%d in leftb",nzx); if (!sf_histint(leftb,"n2",&m2)) sf_error("No n2= in leftb"); if (!sf_histint(rightb,"n1",&n2) || n2 != m2) sf_error("Need n1=%d in rightb",m2); if (!sf_histint(rightb,"n2",&n2) || n2 != nk) sf_error("Need n2=%d in rightb",nk); lt1 = sf_complexalloc2(nzx,m2); /* propagator for forward modeling */ rt1 = sf_complexalloc2(m2,nk); lt2 = sf_complexalloc2(nzx,m2); /* propagator for backward imaging */ rt2 = sf_complexalloc2(m2,nk); img = sf_complexalloc(nz*nx); dat = sf_complexalloc(nt*nx); imgout = sf_complexalloc(nz*nx); if (snap > 0) wvfld = sf_complexalloc3(nz,nx,wfnt); else wvfld = NULL; geop = (geopar) sf_alloc(1, sizeof(*geop)); sf_complexread(lt1[0],nzx*m2,leftf); sf_complexread(rt1[0],m2*nk,rightf); sf_complexread(lt2[0],nzx*m2,leftb); sf_complexread(rt2[0],m2*nk,rightb); if (adj) sf_complexread(dat,ntx,data); else sf_complexread(img,nzx,image); /*close RSF files*/ sf_fileclose(leftf); sf_fileclose(rightf); sf_fileclose(leftb); sf_fileclose(rightb); #ifdef _OPENMP #pragma omp parallel { nth = omp_get_num_threads(); } sf_warning(">>>> Using %d threads <<<<<", nth); #endif if (timer) t0 = gtod_timer(); /*load constant geopar elements*/ geop->nx = nx; geop->nz = nz; geop->dx = dx; geop->dz = dz; geop->ox = ox; geop->gpz = gpz; geop->nt = nt; geop->dt = dt; geop->snap= snap; geop->nzx2= nzx2; geop->nk = nk; geop->m2 = m2; geop->wfnt= wfnt; geop->pad1= pad1; geop->verb= verb; /* first get the Q-compensated image: B[d] */ lrexp(img, dat, adj, lt2, rt2, geop, wvfld); /* performing the least-squares optimization: ||{BF}[m] - B[d]|| */ if (gmres) { /* disabling snapshots */ geop->snap= 0; lrexp_init(lt1,rt1,lt2,rt2); sf_warning(">>>>>> Using GMRES(m) <<<<<<"); cgmres_init(nzx,mem); cgmres( img, imgout, lrexp_op, geop, niter, 0.01*SF_EPS, true); /*lrexp_op(nzx, img, imgout, geop);*/ lrexp_close(); } else { for (i=0; i<nzx; i++) imgout[i] = img[i]; } if (timer) { t1 = gtod_timer(); time = t1-t0; sf_warning("Time = %lf\n",time); } if (adj) { sf_complexwrite(imgout,nzx,image); } else { sf_complexwrite(dat,ntx,data); } if (snap > 0 && NULL != snaps) { sf_complexwrite(wvfld[0][0],wfnt*nx*nz,snaps); } exit(0); }
int main() { char ascii_buffer[17]; char fbyte, inchar; int i, j, k, pagenum, value, start, end; char linebuf[80], *p, *buf, ch; brdInit(); sfspi_init(); if (sf_init()) { printf("Flash init failed\n"); exit(-1); } else { printf("Flash init OK\n"); printf("# of blocks: %d\n", sf_blocks); printf("size of block: %d\n\n", sf_blocksize); } print_command(); while(1) { inchar = getchar(); if(inchar == 'c') { printf("page number to clear?"); pagenum = input_number(); if(pagenum >= 0 && pagenum < sf_blocks) { printf("\nClearing page %d\n", pagenum); memset (flash_buf, 0, sf_blocksize); sf_writeRAM(flash_buf, 0, sf_blocksize); sf_RAMToPage(pagenum); } else { printf("ERROR: invalid page number\n"); } } //end if(inchar =='c') else if((inchar == 'p') || (inchar == 'r')) { if (inchar == 'p') { // Use start for page to print printf("Page number to print out?"); start = input_number(); // Check that it is a valid page if(start < 0 || start >= sf_blocks) { printf("Invalid page number.\n\n"); continue; } // Set single page range for 'p' command end = start; } else { printf("Starting page number to print out?"); start = input_number(); // Check that it is a valid page if(start < 0 || start >= sf_blocks) { printf("Invalid page number.\n\n"); continue; } printf("\nEnding page number to print out?"); end = input_number(); if(end < start || end >= sf_blocks) { printf("Invalid page number.\n\n"); continue; } } // Loop through range of pages (range of 1 page for 'p' command) for (pagenum = start; pagenum <= end; pagenum++) { printf("\nPage %d", pagenum); sf_pageToRAM(pagenum); sf_readRAM(flash_buf, 0, sf_blocksize); // Test if entire buffer filled with a single value buf = flash_buf; for (j = k = 0, ch = *buf; j < 512; j++) { if(ch != *buf++) { k = 1; break; } } // See if page is all the same value if (k) { printf("\n"); // No, drop through to print data } else { // Yes, print out message instead printf(" ALL = 0x%02x\n", ch); continue; } k = (sf_blocksize & 0xFFF0) + ((sf_blocksize & 0x000F) ? 16 : 0); ascii_buffer[16] = 0; for (j = 0, buf = flash_buf; j < k; j++) { if (j % 16 == 0) { p = linebuf; p += sprintf (p, "%04x: ", j); } fbyte = *buf++; if (j >= sf_blocksize) { p += sprintf (p, " "); ascii_buffer[j % 16] = ' '; } else { p += sprintf (p, "%02x ", fbyte); ascii_buffer[j % 16] = isprint (fbyte) ? fbyte : '.'; } if (j % 16 == 15) { printf ("%s %s\n", linebuf, ascii_buffer); } } } } // end if((inchar =='p') || (inchar == 'r')) else if(inchar == 'f') { printf("page number to fill with specified value? "); pagenum = input_number(); if(pagenum >= 0 && pagenum < sf_blocks) { printf("\nPage %d\n", pagenum); printf("enter fill value " ); value = input_number(); printf("\nValue is %d dec is %02x hex", value,value); printf("\nFilling page %d with value %02x hex\n", pagenum,value); memset (flash_buf, value, sf_blocksize); sf_writeRAM(flash_buf, 0, sf_blocksize); sf_RAMToPage(pagenum); } else { printf("ERROR: invalid page number\n"); } } // end of if(inchar == 'f') else if(inchar == 't') { printf("page number in which to write text? "); pagenum = input_number(); if(pagenum >= 0 && pagenum < sf_blocks) { printf("\nPage %d\n", pagenum); printf("enter character string followed by RETURN \n" ); gets (flash_buf); printf("Storing the following text ==> %s \n",flash_buf); sf_writeRAM(flash_buf, 0, sf_blocksize); sf_RAMToPage(pagenum); } else { printf("ERROR: invalid page number\n"); } } // end of if(inchar == 't') print_command(); } // end of while }
int main(int argc, char* argv[]) { int dim, n[SF_MAX_DIM], rect; int it0, it1, niter, n1, n2, i2, n3, i3, i1, gate1, gate2, k2, k3, i5, n5; float ***scan, ***weight, **pick, *ampl, **pick2; float o2, d2, o3, d3, an1, an2, asum, a, ct0, ct1, vel2, vel3; bool smooth, verb; sf_file scn, pik; sf_init(argc,argv); scn = sf_input("in"); pik = sf_output("out"); if (SF_FLOAT != sf_gettype(scn)) sf_error("Need float input"); dim = sf_filedims (scn,n); /* if (dim != 3) sf_error("Need three dimensions"); */ n1 = n[0]; n2 = n[1]; n3 = n[2]; n5 = sf_leftsize(scn,3); if (!sf_histfloat(scn,"o2",&o2)) o2=0.; if (!sf_histfloat(scn,"d2",&d2)) d2=1.; if (!sf_histfloat(scn,"o3",&o3)) o3=0.; if (!sf_histfloat(scn,"d3",&d3)) d3=1.; if (!sf_getfloat("vel1",&vel2)) vel2=o2; if (!sf_getfloat("vel2",&vel3)) vel3=o3; /* surface velocity */ k2 = 0.5 + (vel2-o2)/d2; if (k2 < 0) k2=0; if (k2 >= n2) k2=n2-1; k3 = 0.5 + (vel3-o3)/d2; if (k3 < 0) k3=0; if (k3 >= n3) k3=n3-1; sf_putint(pik,"n2",1); sf_putint(pik,"n3",1); sf_putint(pik,"n4",2); sf_putint(pik,"n5",n5); if (!sf_getint("rect1",&rect)) rect=1; /* smoothing radius */ if (!sf_getint("niter",&niter)) niter=100; /* number of iterations */ if (!sf_getfloat("an1",&an1)) an1=1.; if (!sf_getfloat("an2",&an2)) an2=1.; /* axes anisotropy */ if (!sf_getint("gate1",&gate1)) gate1=3; if (!sf_getint("gate2",&gate2)) gate2=3; /* picking gate */ if (!sf_getbool("smooth",&smooth)) smooth=true; /* if apply smoothing */ if (!sf_getbool("verb",&verb)) verb=true; /* verbosity */ scan = sf_floatalloc3(n1,n2,n3); weight = sf_floatalloc3(n2,n3,n1); (void) dynprog3_init(n1,n2,n3,gate1,gate2,an1,an2,false); if (smooth) { pick = sf_floatalloc2(n1,2); pick2 = sf_floatalloc2(n1,2); ampl = sf_floatalloc(n1); sf_divn_init(1,n1,&n1,&rect,niter,verb); } else { pick = NULL; pick2 = sf_floatalloc2(n1,2); ampl = NULL; } for(i5=0; i5 < n5; i5++) { sf_warning("slice %d of %d;",i5+1,n5); sf_floatread(scan[0][0],n1*n2*n3,scn); /* transpose and reverse */ for (i3=0; i3 < n3; i3++) { for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1; i1++) { weight[i1][i3][i2] = expf(-scan[i3][i2][i1]); } } } dynprog3(k2, k3, weight); dynprog3_traj(pick2); if (smooth) { for (i1=0; i1 < n1; i1++) { ct0 = pick2[0][i1]; it0 = floorf(ct0); ct0 -= it0; if (it0 >= n2-1) { it0 = n2-2; ct0 = 0.; } else if (it0 < 0) { it0 = 0; ct0 = 0.; } ct1 = pick2[1][i1]; it1 = floorf(ct1); ct1 -= it1; if (it1 >= n3-1) { it1 = n3-2; ct1 = 0.; } else if (it1 < 0) { it1 = 0; ct1 = 0.; } ampl[i1]= scan[it1 ][it0 ][i1]*(1.-ct0)*(1.-ct1) + scan[it1+1][it0 ][i1]*(1.-ct0)*ct1 + scan[it1 ][it0+1][i1]*ct0*(1.-ct1) + scan[it1+1][it0+1][i1]*ct0*ct1; } } else { for (i1=0; i1 < n1; i1++) { pick2[0][i1] = o2+pick2[0][i1]*d2; pick2[1][i1] = o3+pick2[1][i1]*d3; } } if (smooth) { /* normalize amplitudes */ asum = 0.; for (i1 = 0; i1 < n1; i1++) { a = ampl[i1]; asum += a*a; } asum = sqrtf (asum/n1); for(i1=0; i1 < n1; i1++) { ampl[i1] /= asum; pick[0][i1] = (o2+pick2[0][i1]*d2-vel2)*ampl[i1]; pick[1][i1] = (o3+pick2[1][i1]*d3-vel3)*ampl[i1]; } sf_divn(pick[0],ampl,pick2[0]); sf_divn(pick[1],ampl,pick2[1]); for(i1=0; i1 < n1; i1++) { pick2[0][i1] += vel2; pick2[1][i1] += vel3; } } sf_floatwrite(pick2[0],n1*2,pik); } sf_warning("."); 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[]) { int n1, n2, n3, n12, i1, i2, i3, j, m, *coor, xc, yc, nw, rect; bool boundary, verb, var; float *input, *output, *dd, *data, *weight; sf_file in, out, dip; 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"); n3 = sf_leftsize(in,2); n12 = n1*n2; /* get the trace length (n1) and the number of traces (n2) and n3*/ if (!sf_getint("nw",&nw)) sf_error("nw needs integer input"); /* data-window length (positive and odd integer) */ if (0 == nw%2) nw++; m = (nw-1)/2; if (!sf_getint("rect",&rect)) rect=nw; /* Correlation window */ if (0 == rect%2) rect++; if (rect > nw) rect=nw; if (!sf_getbool("boundary",&boundary)) boundary = true; /* if y, boundary is data, whereas zero*/ if (!sf_getbool("var",&var)) var = false; /* if y, variance weights, whereas correlation weights*/ if (!sf_getbool("verb",&verb)) verb = false; /* verbosity flag */ input = sf_floatalloc(n12); output = sf_floatalloc(n12); dd = sf_floatalloc(n12); coor = sf_intalloc(nw*2); data = sf_floatalloc(nw); weight = sf_floatalloc(nw); for(i3=0; i3 < n3; i3++) { if (verb) sf_warning("3rd axis: %d of %d",i3+1,n3); sf_floatread(input,n12,in); sf_floatread(dd,n12,dip); for(i2=0; i2 < n2; i2++) { if (verb && (10*i2)%n2==0) sf_warning("2nd axis: %d of %d",i2+1,n2); for(i1=0; i1 < n1; i1++) { coor[0*nw+m] = i1; coor[1*nw+m] = i2; data[m] = input[coor[1*nw+m]*n1+coor[0*nw+m]]; for(j=1; j < m+1; j++) { xc = (int) coor[0*nw+j+m-1]+dd[coor[1*nw+j+m-1]*n1+coor[0*nw+j+m-1]]+0.5; yc = coor[1*nw+j+m-1]+1; if (xc < 0 || xc >= n1 || yc < 0 || yc >= n2) { coor[1*nw+j+m] = coor[1*nw+j+m-1]; coor[0*nw+j+m] = coor[0*nw+j+m-1]; if (boundary) { data[j+m] = input[coor[1*nw+j+m]*n1+coor[0*nw+j+m]]; } else { data[j+m] = 0.; } } else { coor[1*nw+j+m] = yc; coor[0*nw+j+m] = xc; data[j+m] = input[coor[1*nw+j+m]*n1+coor[0*nw+j+m]]; } } for(j=-1; j > (-1*(m+1)); j--) { xc = (int) coor[0*nw+j+m+1]-dd[coor[1*nw+j+m+1]*n1+coor[0*nw+j+m+1]]+0.5; yc = coor[1*nw+j+m+1]-1; if (xc < 0 || xc >= n1 || yc < 0 || yc >= n2) { coor[1*nw+j+m] = coor[1*nw+j+m+1]; coor[0*nw+j+m] = coor[0*nw+j+m+1]; if (boundary) { data[j+m] = input[coor[1*nw+j+m]*n1+coor[0*nw+j+m]]; } else { data[j+m] = 0.; } } else { coor[1*nw+j+m] = yc; coor[0*nw+j+m] = xc; data[j+m] = input[coor[1*nw+j+m]*n1+coor[0*nw+j+m]]; } } if (var) { lvweight(data,weight,nw,rect); } else { cweight(data,weight,nw,rect); } output[i2*n1+i1] = wmedianfilter(data,weight,nw); } } sf_floatwrite(output,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 verb; bool adj; bool anis; sf_file Fcip=NULL; /* lag-domain CIPs */ sf_file Fang=NULL; /* angle-domain CIPs */ sf_file Fvel=NULL; /* velocity @ CIPs */ sf_file Fnor=NULL; /* normals @ CIPs */ sf_file Ftlt=NULL; /* tilt @ CIPs */ sf_file Fani=NULL; /* anisotropy @ CIPs */ sf_axis ahx,ahy,ahz,aht,ac,ath,aph,aps,aj; int ihx,ihy,ihz,iht,ic,ith,iph; /* angle parameters */ int nth,nph,nps,nhx,nhy,nhz,nht; float oth,oph,ops,ohx,ohy,ohz,oht; float dth,dph,dps,dhx,dhy,dhz,dht; float phi; float tht; float psi; float v_s,v_r; float cosum,codif,sitovel; /* arrays 1 2 3 4 */ float ****cip; /* nhx-nhy-nhz-nht */ float **ang; /* nph-nth */ float *vep; /* nc */ float *ves; /* nc */ float *eps=NULL; /* nc */ float *dlt=NULL; /* nc */ vc3d vv; /* azimuth reference vector */ vc3d *nn; /* normal vectors */ vc3d *tt=NULL; /* tilt vectors */ vc3d *aa; /* in-plane reference vector */ vc3d qq; vc3d jk; /* temp vector */ float hx,hy,hz; float tau; /* time lag */ int jht; /* tau axis index */ float fht; /* tau axis weight */ float ssn; /* slant-stack normalization */ float *ttipar; /*-----------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); #ifdef _OPENMP omp_init(); /* OMP parameters */ #endif if(! sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ if(! sf_getbool("anis",&anis)) anis=false; /* anisotropy flag */ if(! sf_getbool("adj", &adj)) adj=true; /* adj flag */ /* * ADJ: cip to ang * FOR: ang to cip */ sf_warning("verb=%d",verb); sf_warning("anis=%d",anis); /* select anisotropy model */ if(anis) sf_warning("ANI model"); else sf_warning("ISO model"); if(adj) { Fcip=sf_input ( "in"); /* CIP file */ Fang=sf_output("out"); /* ANG file */ } else { Fcip=sf_output("out"); /* CIP file */ Fang=sf_input ("in"); /* ANG file */ } Fvel=sf_input ("vel"); /* velocity file */ Fnor=sf_input ("nor"); /* normal vectors */ if(anis) { Ftlt=sf_input ("tlt"); /* tilt vectors */ Fani=sf_input ("ani"); /* anisotropy */ } aj = sf_maxa(1,0,1); if(adj) { /* input axes */ ahx = sf_iaxa(Fcip,1); sf_setlabel(ahx,"hx"); ahy = sf_iaxa(Fcip,2); sf_setlabel(ahy,"hy"); ahz = sf_iaxa(Fcip,3); sf_setlabel(ahz,"hz"); aht = sf_iaxa(Fcip,4); sf_setlabel(aht,"ht"); /* CIP axis */ ac = sf_iaxa(Fcip,5); sf_setlabel(ac ,"c "); /* reflection angle */ if(! sf_getint ("nth",&nth)) nth=90; if(! sf_getfloat("oth",&oth)) oth=0; if(! sf_getfloat("dth",&dth)) dth=1.; ath = sf_maxa(nth,oth,dth); sf_setlabel(ath,"th"); sf_setunit (ath,"deg"); /* azimuth angle */ if(! sf_getint ("nph",&nph)) nph=360; if(! sf_getfloat("oph",&oph)) oph=-180; if(! sf_getfloat("dph",&dph)) dph=1.; aph = sf_maxa(nph,oph,dph); sf_setlabel(aph,"ph"); sf_setunit (aph,"deg"); /* output axes */ sf_oaxa(Fang,ath,1); sf_oaxa(Fang,aph,2); sf_oaxa(Fang,ac ,3); sf_oaxa(Fang,aj ,4); sf_oaxa(Fang,aj ,5); } else { /* lag in x */ if(! sf_getint ("nhx",&nhx)) nhx=1; if(! sf_getfloat("ohx",&ohx)) ohx=0; if(! sf_getfloat("dhx",&dhx)) dhx=1.; ahx = sf_maxa(nhx,ohx,dhx); sf_setlabel(ahx,"hx"); sf_setunit (ahx,""); /* lag in y */ if(! sf_getint ("nhy",&nhy)) nhy=1; if(! sf_getfloat("ohy",&ohy)) ohy=0; if(! sf_getfloat("dhy",&dhy)) dhy=1.; ahy = sf_maxa(nhy,ohy,dhy); sf_setlabel(ahy,"hy"); sf_setunit (ahy,""); /* lag in z */ nhz=1; ohz=0.; dhz=1.; ahz = sf_maxa(nhz,ohz,dhz); sf_setlabel(ahz,"hz"); sf_setunit (ahz,""); /* lag in t */ if(! sf_getint ("nht",&nht)) nht=1; if(! sf_getfloat("oht",&oht)) oht=0.; if(! sf_getfloat("dht",&dht)) dht=1.; aht = sf_maxa(nht,oht,dht); sf_setlabel(aht,"ht"); sf_setunit (aht,""); /* reflection angle */ ath = sf_iaxa(Fang,1); sf_setlabel(ath,"th"); /* azimuth angle */ aph = sf_iaxa(Fang,2); sf_setlabel(aph,"ph"); /* CIP axis */ ac = sf_iaxa(Fang,3); sf_setlabel(ac ,"c "); /* output axes */ sf_oaxa(Fcip,ahx,1); sf_oaxa(Fcip,ahy,2); sf_oaxa(Fcip,ahz,3); sf_oaxa(Fcip,aht,4); sf_oaxa(Fcip,ac ,5); } if (verb){ sf_raxa(ahx); sf_raxa(ahy); sf_raxa(ahz); sf_raxa(aht); sf_raxa(ac); sf_raxa(ath); sf_raxa(aph); } if(anis) { /* deviation angle */ if(! sf_getint ("nps",&nps)) nps=251; if(! sf_getfloat("ops",&ops)) ops=-25; if(! sf_getfloat("dps",&dps)) dps=0.2; aps = sf_maxa(nps,ops,dps); sf_setlabel(aps,"ps"); sf_setunit (aps,"deg"); if(verb) sf_raxa(aps); } else { aps = NULL; } /*------------------------------------------------------------*/ /* allocate arrays */ cip = sf_floatalloc4 (sf_n(ahx),sf_n(ahy),sf_n(ahz),sf_n(aht)); ang = sf_floatalloc2 (sf_n(ath),sf_n(aph)); /* read velocity */ vep = sf_floatalloc (sf_n(ac)); sf_floatread(vep,sf_n(ac),Fvel); ves = sf_floatalloc (sf_n(ac)); sf_floatread(ves,sf_n(ac),Fvel); /*------------------------------------------------------------*/ /* read normals */ nn = (vc3d*) sf_alloc(sf_n(ac),sizeof(*nn)); /* normals */ vc3dread1(Fnor,nn,sf_n(ac)); if(anis) { /* read anisotropy */ eps = sf_floatalloc (sf_n(ac)); sf_floatread(eps,sf_n(ac),Fani); dlt = sf_floatalloc (sf_n(ac)); sf_floatread(dlt,sf_n(ac),Fani); /* read tilts */ tt = (vc3d*) sf_alloc(sf_n(ac),sizeof(*tt)); vc3dread1(Ftlt,tt,sf_n(ac)); } /*------------------------------------------------------------*/ /* in-plane azimuth reference */ vv.dx=1; vv.dy=0; vv.dz=0; aa = (vc3d*) sf_alloc(sf_n(ac),sizeof(*aa)); for(ic=0;ic<sf_n(ac);ic++) { jk =vcp3d(&nn[ic],&vv); aa[ic]=vcp3d(&jk,&nn[ic]); } /*------------------------------------------------------------*/ ssn = 1./sqrt(sf_n(ahx)*sf_n(ahy)*sf_n(ahz)); /*------------------------------------------------------------*/ /* loop over CIPs */ /* if(verb) fprintf(stderr,"ic\n");*/ for(ic=0;ic<sf_n(ac);ic++) { /* if(verb) fprintf(stderr,"\b\b\b\b\b%d",ic);*/ if(adj) { /* read CIP */ sf_floatread(cip[0][0][0],sf_n(ahx)*sf_n(ahy)*sf_n(ahz)*sf_n(aht),Fcip); /* init ANG */ for (iph=0;iph<sf_n(aph);iph++) { for(ith=0;ith<sf_n(ath);ith++) { ang[iph][ith]=0; } } } else { /* init CIP */ for (iht=0;iht<sf_n(aht);iht++) { for (ihz=0;ihz<sf_n(ahz);ihz++) { for (ihy=0;ihy<sf_n(ahy);ihy++) { for(ihx=0;ihx<sf_n(ahx);ihx++) { cip[iht][ihz][ihy][ihx]=0; } } } } /* read ANG */ sf_floatread(ang[0],sf_n(ath)*sf_n(aph),Fang); } /* phi loop */ nph = sf_n(aph); #ifdef _OPENMP #pragma omp parallel for schedule(static) \ private(iph,phi,jk,qq, \ ith,tht, \ ihy,ihx,hy,hx,hz, \ tau,jht,fht,cosum,codif,v_s,v_r,psi,sitovel) \ shared( nph,aph,ath,aps,ahy,ahx,aht,cip,ang,vep,ves,eps,dlt) #endif for(iph=0;iph<nph;iph++) { phi=(180+sf_o(aph)+iph*sf_d(aph))/180.*SF_PI; /* use '180' to reverse illumination direction: */ /* at a CIP, look toward the source */ /* reflection azimuth vector */ jk = rot3d(nn,aa,phi); qq = nor3d(&jk); /* theta loop */ for(ith=0;ith<sf_n(ath);ith++) { tht=(sf_o(ath)+ith*sf_d(ath))/180.*SF_PI; if(anis) { ttipar = psitti(nn,&qq,tt,aa, tht,phi,aps, vep[ic],ves[ic],eps[ic],dlt[ic]); psi = ttipar[0]; v_s = ttipar[1]; v_r = ttipar[2]; psi *= SF_PI/180.; cosum = cosf(tht+psi); codif = cosf(tht-psi); sitovel = sinf(2*tht)/(v_s*cosum + v_r*codif); } else { sitovel = sinf(tht)/vep[ic]; } /* lag loops */ if(adj) { for (ihy=0;ihy<sf_n(ahy);ihy++) { hy=sf_o(ahy)+ihy*sf_d(ahy); for(ihx=0;ihx<sf_n(ahx);ihx++) { hx=sf_o(ahx)+ihx*sf_d(ahx); hz = -(hx*(nn[ic].dx)+hy*(nn[ic].dy))/(nn[ic].dz); tau = -((qq.dx)*hx+(qq.dy)*hy+(qq.dz)*hz)*sitovel; jht=0.5+(tau-sf_o(aht))/sf_d(aht); if(jht>=0 && jht<sf_n(aht)-1) { fht= (tau-sf_o(aht))/sf_d(aht)-jht; ang[iph][ith] += (1-fht)*ssn*cip[jht ][0][ihy][ihx] + fht *ssn*cip[jht+1][0][ihy][ihx]; } } /* hx */ } /* hy */ } else { for (ihy=0;ihy<sf_n(ahy);ihy++) { hy=sf_o(ahy)+ihy*sf_d(ahy); for(ihx=0;ihx<sf_n(ahx);ihx++) { hx=sf_o(ahx)+ihx*sf_d(ahx); hz = -(hx*(nn[ic].dx)+hy*(nn[ic].dx))/(nn[ic].dz); tau = -((qq.dx)*hx+(qq.dy)*hy+(qq.dz)*hz)*sitovel; jht=0.5+(tau-sf_o(aht))/sf_d(aht); if(jht>=0 && jht<sf_n(aht)-1) { fht= (tau-sf_o(aht))/sf_d(aht)-jht; cip[jht ][0][ihy][ihx] += (1-fht)*ssn*ang[iph][ith]; cip[jht+1][0][ihy][ihx] += fht *ssn*ang[iph][ith]; } } /* hx */ } /* hy */ } } /* th */ } /* ph */ if(adj) { /* write ANG */ sf_floatwrite(ang[0],sf_n(ath)*sf_n(aph),Fang); } else { /* write CIP */ sf_floatwrite(cip[0][0][0],sf_n(ahx)*sf_n(ahy)*sf_n(ahz)*sf_n(aht),Fcip); } } if(verb) fprintf(stderr,"\n"); /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ if(verb) fprintf(stderr,"free memory..."); free(***cip);free(**cip);free(*cip);free(cip); ; free(*ang);free(ang); ; free(vep); ; free (nn); ; free (aa); if(anis) { free(ves); free(eps); free(dlt); free(tt); } if(verb) fprintf(stderr,"OK\n"); /*------------------------------------------------------------*/ exit(0); }
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 nx, na, na2, ia, nz, order, maxsplit, ix, iz, *siz; float **place, *slow, **out, dx,dz, x0,z0, x[2]; float max1, min1, max2, min2; bool isvel, lsint; agrid grd; sf_file vel, outp, size, grid; sf_init (argc,argv); /* get 2-D grid parameters */ vel = sf_input("in"); if (!sf_histint(vel,"n1",&nz)) sf_error("No n1= in input"); if (!sf_histint(vel,"n2",&nx)) sf_error("No n2= in input"); if (!sf_histfloat(vel,"d1",&dz)) sf_error("No d1= in input"); if (!sf_histfloat(vel,"d2",&dx)) sf_error("No d2= in input"); if (!sf_histfloat(vel,"o1",&z0)) z0=0.; if (!sf_histfloat(vel,"o2",&x0)) x0=0.; outp = sf_output("out"); sf_putint(outp,"n4",nz); sf_putfloat(outp,"d4",dz); sf_putfloat(outp,"o4",z0); sf_putint(outp,"n3",nx); sf_putfloat(outp,"d3",dx); sf_putfloat(outp,"o3",x0); if (!sf_getint("na",&na)) na=60; /* number of angles */ if (!sf_getfloat("da",&da)) da=3.1; /* angle increment (in degrees) */ if (!sf_getfloat("a0",&a0)) a0=-90.; /* initial angle (in degrees) */ if (!sf_getint("maxsplit",&maxsplit)) maxsplit=10; /* maximum splitting for adaptive grid */ if (!sf_getfloat("minx",&min1)) min1=0.5*dx; /* parameters for adaptive grid */ if (!sf_getfloat("maxx",&max1)) max1=2.*dx; if (!sf_getfloat("mina",&min2)) min2=0.5*da; if (!sf_getfloat("maxa",&max2)) max2=2.*da; sf_putint(outp,"n2",na); sf_putfloat(outp,"d2",da); sf_putfloat(outp,"o2",a0); da *= (SF_PI/180.); a0 *= (SF_PI/180.); sf_putint(outp,"n1",5); size = sf_output("size"); sf_putint(size,"n1",nx); sf_putint(size,"n2",nz); sf_settype(size,SF_INT); grid = sf_output("grid"); /* additional parameters */ if(!sf_getbool("vel",&isvel)) isvel=true; /* y: velocity, n: slowness */ if(!sf_getint("order",&order)) order=3; /* velocity interpolation order */ if (!sf_getbool("lsint",&lsint)) lsint=false; /* if use least-squares interpolation */ slow = sf_floatalloc(nz*nx); place = sf_floatalloc2(5,na); siz = sf_intalloc(nx); sf_floatread(slow,nx*nz,vel); if (isvel) { for(ix = 0; ix < nx*nz; ix++){ slow[ix] = 1./slow[ix]; } } ct = sf_celltrace_init (lsint, order, nz*nx, nz, nx, dz, dx, z0, x0, slow); free (slow); grd = agrid_init (na, 5, maxsplit); agrid_set (grd,place); for (iz = 0; iz < nz; iz++) { x[0] = z0+iz*dz; sf_warning("depth %d of %d;",iz+1, nz); for (ix = 0; ix < nx; ix++) { x[1] = x0+ix*dx; fill_grid(grd,min1,max1,min2,max2,(void*) x, raytrace); na2 = grid_size (grd); out = write_grid (grd); siz[ix] = na2; for (ia=0; ia < na2; ia++) { if (ia < na) sf_floatwrite (place[ia], 5, outp); sf_floatwrite(out[ia], 5, grid); } free (out); } sf_intwrite (siz,nx,size); } sf_warning("."); exit (0); }
int main(int argc, char* argv[]) { int nx, nz, na, nb, i, j; float fx, fz, dx, dz, da, db; sf_init(argc,argv); sf_file Fo1, Fo2, Fo3, Fo4, Fo5, Fo6; Fo1 = sf_input("in"); // wavefront1 Fo2 = sf_input("wave2"); // wavefront2 Fo3 = sf_output("out"); // wavetrans1 Fo4 = sf_output("wavetrans2"); // wavetrans2 Fo5 = sf_output("amp1"); // amplitue1 Fo6 = sf_output("amp2"); // amplitue2 float **snap1, **snap2; float **sn1, **sn2; float *amp1, *amp2; float amax, amax1, amax2; /* Read/Write axes */ sf_axis az, ax; az = sf_iaxa(Fo1,1); nz = sf_n(az); dz = sf_d(az)*1000; ax = sf_iaxa(Fo1,2); nx = sf_n(ax); dx = sf_d(ax)*1000; fx=sf_o(ax); fz=sf_o(az); sf_warning("nx= %d nz= %d",nx,nz); sf_warning("dx= %f dz= %f",dx,dz); na = 720; da = 180.0/na; nb = nx*2; db = dx/2.0; sf_warning("da= %f db= %f",da,db); sf_putint(Fo3,"n1",nb); sf_putint(Fo3,"n2",na); sf_putfloat(Fo3,"d1",db); sf_putfloat(Fo3,"o1",0.0f); sf_putfloat(Fo3,"d2",da); sf_putfloat(Fo3,"o2",-90.0f); sf_putint(Fo4,"n1",nb); sf_putint(Fo4,"n2",na); sf_putfloat(Fo4,"d1",db); sf_putfloat(Fo4,"o1",0.0f); sf_putfloat(Fo4,"d2",da); sf_putfloat(Fo4,"o2",-90.0f); sf_putint(Fo5,"n2",1); sf_putint(Fo5,"n1",na); sf_putfloat(Fo5,"d1",da); sf_putfloat(Fo5,"o1",-90.0f); sf_putstring(Fo5,"label1","Phase angle"); sf_putstring(Fo5,"unit1","Degree"); sf_putint(Fo6,"n2",1); sf_putint(Fo6,"n1",na); sf_putfloat(Fo6,"d1",da); sf_putfloat(Fo6,"o1",-90.0f); sf_putstring(Fo6,"label1","Phase angle"); sf_putstring(Fo6,"unit1","Degree"); snap1=sf_floatalloc2(nz, nx); snap2=sf_floatalloc2(nz, nx); sn1=sf_floatalloc2(nb, na); sn2=sf_floatalloc2(nb, na); amp1=sf_floatalloc(na); amp2=sf_floatalloc(na); for(i=0;i<nx;i++){ sf_floatread(snap1[i], nz, Fo1); sf_floatread(snap2[i], nz, Fo2); } for(i=0;i<na;i++){ amp1[i]=0.0; amp2[i]=0.0; for(j=0;j<nb;j++){ sn1[i][j]=0.0; sn2[i][j]=0.0; } } for(i=0;i<na;i++){ float a=i*da; a *= SF_PI/180.0; for(j=0;j<nb;j++){ float b=j*db; float x=(nx-1)*dx*0.5-b*cos(a); float z=(nz-1)*dz*0.5+b*sin(a); int ix, iz; ix=x/dx; iz=z/dz; if(ix>=0&&ix<nx&&iz>=nz/2&&iz<nz){ //sf_warning("i=%d a=%f j=%d b=%f x=%f z=%f ix=%d iz=%d",i,a,j,b,x,z,ix,iz); sn1[i][j]=snap1[ix][iz]; sn2[i][j]=snap2[ix][iz]; } } sf_floatwrite(sn1[i], nb, Fo3); sf_floatwrite(sn2[i], nb, Fo4); } for(i=0;i<na;i++){ amax=0.0; for(j=0;j<nb;j++) if(fabs(sn1[i][j])>amax) amax=fabs(sn1[i][j]); amp1[i]=amax; amax=0.0; for(j=0;j<nb;j++) if(fabs(sn2[i][j])>amax) amax=fabs(sn2[i][j]); amp2[i]=amax; } amax1=0.0; amax2=0.0; for(i=na/2-2;i<na/2+2;i++){ if(amp1[i]>amax1) amax1=amp1[i]; if(amp2[i]>amax2) amax2=amp2[i]; } for(i=0;i<na;i++){ amp1[i] /= amax1; amp2[i] /= amax2; } sf_floatwrite(amp1, na, Fo5); sf_floatwrite(amp2, na, Fo6); free(*snap1); free(*snap2); free(*sn1); free(*sn2); free(amp1); free(amp2); }
int main(int argc, char* argv[]) { int n1, n2, n3, n12, i3,mint,n,type, niter; float *dat1=NULL, *dat2=NULL, t0,dt,dx,velhalf, h0, dh; bool inv, half; sf_file in=NULL, out=NULL; sf_init(argc,argv); in = sf_input("in"); out = sf_output("out"); if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(in,"n2",&n2)) sf_error("No n2= in input"); n12 = n1*n2; n3 = sf_leftsize(in,2); if (!sf_getint ("mint",&mint)) mint=2; /* starting time sample */ if (!sf_getint ("n",&n)) n=32; /* number of offset samples */ if (!sf_getint ("niter",&niter)) niter=5; /* iterative number */ if (!sf_getbool ("inv",&inv)) inv=false; /* inversion flag */ if (!sf_getint ("type",&type)) type=1; /* type of amplitude (0,1,2,3) */ if (1==n3) { if (!sf_getfloat ("h",&h0)) sf_error("Need h="); dh = 0.; /* half-offset */ } else { if (!sf_histfloat(in,"o3",&h0)) sf_error("No o3= in input"); if (!sf_histfloat(in,"d3",&dh)) sf_error("No d3= in input"); if (!sf_getbool("half",&half)) half=true; /* if y, the third axis is half-offset instead of full offset */ if (!half) { h0 *= 0.5; dh *= 0.5; } } if (!sf_getfloat ("velhalf",&velhalf)) velhalf=0.75; /* half-velocity */ if (!sf_histfloat(in,"o1",&t0)) sf_error("No o1= in input"); if (!sf_histfloat(in,"d1",&dt)) sf_error("No d1= in input"); if (!sf_histfloat(in,"d2",&dx)) sf_error("No d2= in input"); dat1 = sf_floatalloc(n12); dat2 = sf_floatalloc(n12); dmo_init (velhalf,inv,t0,dt,dx,n1,n2,mint,n,type); for (i3=0; i3 < n3; i3++) { sf_warning("i3/n3=%d/%d",i3+1,n3); dmo_set(h0 + i3*dh); sf_floatread(dat2,n12,in); sf_warning("n12=%d",n12); sf_solver(dmo_lop,sf_cgstep,n12,n12,dat1,dat2,niter); sf_warning("n12=%d",n12); sf_floatwrite(dat1,n12,out); } exit(0); }
int main(int argc, char* argv[]) { float **data /* input [ny][nx] */; int niter /* number of iterations */; int nx, ny /* axis */; float dx, dy, x0, y0 /* axis and initials */; bool verb /* verbosity flag */; int ix, iy, iter, j; float f2, fl, ll, flp[3], llp[3], lplp[6], x, y, da[3], aa, f, l2; float lp[3], eps, num[3], den[6], r2, a[3], l, x2, y2, xy, det, r; sf_file in, out; /* Estimate shape (Caution: data gets corrupted) */ sf_init (argc,argv); in = sf_input("in"); out = sf_output("out"); if (SF_FLOAT != sf_gettype(in)) sf_error("Need float input"); if (!sf_histint(in,"n1",&nx)) sf_error("No n1= in input"); if (!sf_histint(in,"n2",&ny)) sf_error("No n2= in input"); if (!sf_histfloat(in,"d1",&dx)) sf_error("No d1= in input"); if (!sf_histfloat(in,"o1",&x0)) sf_error("No o1= in input"); if (!sf_histfloat(in,"d2",&dy)) sf_error("No d2= in input"); if (!sf_histfloat(in,"o2",&y0)) sf_error("No o2= in input"); if (!sf_getfloat("a0",&a[0])) a[0]=1000.; /* starting correlation length in xx */ if (!sf_getfloat("b0",&a[1])) a[1]=0.; /* starting correlation length in xy */ if (!sf_getfloat("c0",&a[2])) a[2]=400.; /* starting correlation length in yy */ if (!sf_getint("niter",&niter)) niter=100; /* number of iterations */ if (!sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ data = sf_floatalloc2(nx,ny); /* Inversion */ eps = 10.*FLT_EPSILON; eps *= eps; sf_floatread(data[0],nx*ny,in); f2 = 0.; for (iy=0; iy < ny; iy++) { for (ix=0; ix < nx; ix++) { f = log(data[iy][ix]); f2 += f*f; } } aa = -0.5; if (verb) sf_warning("got a0=%g b0=%g c0=%g niter=%d\n" "nx=%d dx=%g x0=%g ny=%d dy=%g y0=%g", a[0],a[1],a[2],niter,nx,dx,x0,ny,dy,y0); /* Gauss-Newton iterations */ for (iter = 0; iter < niter; iter++) { ll = eps; fl = 0.; for (j=0; j < 3; j++) { flp[j] = 0.; llp[j] = 0.; lplp[j] = 0.; lplp[3+j] = 0.; } for (iy=0; iy < ny; iy++) { y = y0+iy*dy; y2 = y*y; for (ix=0; ix < nx; ix++) { x = x0+ix*dx; x2 = x*x; xy = x*y; r = 1 + a[0]*x2 + a[1]*xy + a[2]*y2; l = log(r); l2 = l*l; /* Derivative of l with respect to a */ lp[0] = x2/r; lp[1] = xy/r; lp[2] = y2/r; f = log(data[iy][ix]); ll += l2; fl += f*l; for (j=0; j < 3; j++) { flp[j] += f*lp[j]; llp[j] += l*lp[j]; } lplp[0] += lp[0]*lp[0]; lplp[1] += lp[0]*lp[1]; lplp[2] += lp[0]*lp[2]; lplp[3] += lp[1]*lp[1]; lplp[4] += lp[1]*lp[2]; lplp[5] += lp[2]*lp[2]; } } aa = fl/ll; /* amplitude */ for (j=0; j < 3; j++) { da[j] = (flp[j] - 2.*aa*llp[j])/ll; num[j] = aa*(aa*llp[j] + da[j]*(ll+eps)); } den[0] = aa*aa*lplp[0] + da[0]*(2.*aa*llp[0] + da[0]*(ll-eps)); den[1] = aa*(aa*lplp[1] + da[1]*llp[0]) + da[0]*(aa*llp[1] + da[1]*(ll-eps)); den[2] = aa*(aa*lplp[2] + da[2]*llp[0]) + da[0]*(aa*llp[2] + da[2]*(ll-eps)); den[3] = aa*aa*lplp[3] + da[1]*(2.*aa*llp[1] + da[1]*(ll-eps)); den[4] = aa*(aa*lplp[4] + da[1]*llp[2]) + da[2]*(aa*llp[1] + da[1]*(ll-eps)); den[5] = aa*aa*lplp[5] + da[2]*(2.*aa*llp[2] + da[2]*(ll-eps)); det = den[2]*(den[2]*den[3] - den[1]*den[4]) + den[1]*(den[1]*den[5] - den[2]*den[4]) + den[0]*(den[4]*den[4] - den[3]*den[5]); if (det > 0. && eps > det) { det = eps; } else if (det < 0. && -eps < det) { det = -eps; } da[0] = ( num[2]*(den[2]*den[3] - den[1]*den[4]) + num[1]*(den[1]*den[5] - den[2]*den[4]) + num[0]*(den[4]*den[4] - den[3]*den[5]) )/det; da[1] = ( num[1]*(den[2]*den[2] - den[0]*den[5]) + num[0]*(den[1]*den[5] - den[2]*den[4]) + num[2]*(den[4]*den[0] - den[1]*den[2]) )/det; da[2] = ( num[0]*(den[2]*den[3] - den[1]*den[4]) + num[2]*(den[1]*den[1] - den[3]*den[0]) + num[1]*(den[4]*den[0] - den[1]*den[2]) )/det; r2 = f2 - aa*aa*(ll+eps); /* residual squared */ if (verb) sf_warning("iter=%d r2=%g da=(%g,%g,%g) " "aa=%g a=(%g,%g,%g)", iter,r2,da[0],da[1],da[2],aa,a[0],a[1],a[2]); /* Update a */ for (j=0; j < 3; j++) { a[j] += da[j]; } if (a[0] < 0.) a[0] = 0.; if (a[2] < 0.) a[2] = 0.; if (r2 < eps || da[0]*da[0] + da[1]*da[1] + da[2]*da[2] < eps) break; } /* iter */ for (iy=0; iy < ny; iy++) { y = y0+iy*dy; y2 = y*y; for (ix=0; ix < nx; ix++) { x = x0+ix*dx; x2 = x*x; xy = x*y; data[iy][ix] = exp(aa*log(1+a[0]*x2+a[1]*xy+a[2]*y2)); } } if (verb) sf_warning ("%d iterations", iter); /* Optimized parameters for f = log(data) = aa*log(1+a[0]*x2+a[1]*xy+a[2]*y2) with a=b*b and aa = -(nu/2+1/2) */ sf_warning ("axx=%g axy=%g ayy=%g nu=%g",a[0],a[1],a[2],-2*aa-1.); sf_floatwrite (data[0],nx*ny,out); exit (0); }
int main (int argc, char* argv[]) { int n1,n2,n3; /*n1 is trace length, n2 is the number of traces, n3 is the number of 3th axis*/ int i,j,k,kk,ii; int nfw; /*nfw is the reference filter-window length*/ int tempnfw; /*temporary variable*/ int m; float medianv; /*temporary median variable*/ bool boundary; int alpha,beta,gamma,delta; /*time-varying window coefficients*/ float *trace; float *tempt; /*temporary array*/ float *result; /*output array*/ float *extendt; float *medianarray; /*1D median filtered array*/ float *temp1,*temp2,*temp3; /*temporary array*/ sf_file in, out; sf_init (argc, argv); in = sf_input("in"); out = sf_output("out"); if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(in,"n2",&n2)) sf_error("No n2= in input"); n3 = sf_leftsize(in,2); /* get the trace length (n1) and the number of traces (n2) and n3*/ if (!sf_getbool("boundary",&boundary)) boundary=false; /* if y, boundary is data, whereas zero*/ if (!sf_getint("nfw",&nfw)) sf_error("Need integer input"); /* reference filter-window length (>delta, positive and odd integer)*/ if (!sf_getint("alpha",&alpha)) alpha=2; /* time-varying window parameter "alpha" (default=2)*/ if (!sf_getint("beta",&beta)) beta=0; /* time-varying window parameter "beta" (default=0)*/ if (!sf_getint("gamma",&gamma)) gamma=2; /* time-varying window parameter "gamma" (default=2)*/ if (!sf_getint("delta",&delta)) delta=4; /* time-varying window parameter "delta" (default=4)*/ if (alpha<beta || delta<gamma) sf_error("Need alpha>=beta && delta>=gamma"); if ((alpha%2)!=0) alpha = alpha+1; if ((beta%2)!=0) beta = beta+1; if ((gamma%2)!=0) gamma = gamma+1; if ((delta%2)!=0) delta = delta+1; if (nfw <=delta) sf_error("Need nfw > delta"); if (nfw%2 == 0) nfw++; m=(nfw-1)/2; tempnfw=nfw; trace = sf_floatalloc(n1*n2); tempt = sf_floatalloc(n1*n2); result = sf_floatalloc(n1*n2); extendt = sf_floatalloc((n1+2*m)*n2); medianarray =sf_floatalloc(n1*n2); temp1 = sf_floatalloc(nfw); temp2 = sf_floatalloc(n1); /*set the data space*/ for(ii=0;ii<n3;ii++){ sf_floatread(trace,n1*n2,in); for(i=0;i<n1*n2;i++){ tempt[i]=trace[i]; } bound1(tempt,extendt,nfw,n1,n2,boundary); /************1D reference median filtering****************/ for(i=0;i<n2;i++){ for(j=0;j<n1;j++){ for(k=0;k<nfw;k++){ temp1[k]=extendt[(n1+2*m)*i+j+k]; } medianarray[n1*i+j]=sf_quantile(m,nfw,temp1); } } medianv=0.0; for(i=0;i<n1*n2;i++){ medianv=medianv+fabs(medianarray[i]); } medianv=medianv/(1.0*n1*n2); /************1D time-varying median filter****************/ for(i=0;i<n2;i++){ for(kk=0;kk<n1;kk++){ temp2[kk]=trace[n1*i+kk]; } for(j=0;j<n1;j++){ if(fabs(medianarray[n1*i+j])<medianv){ if(fabs(medianarray[n1*i+j])<medianv/2.0){ tempnfw=nfw+alpha; } else{ tempnfw=nfw+beta; } } else{ if(fabs(medianarray[n1*i+j])>=(medianv*2.0)){ tempnfw=nfw-delta; } else{ tempnfw=nfw-gamma; } } temp3 = sf_floatalloc(tempnfw); bound2(temp2,temp3,n1,tempnfw,j,boundary); result[n1*i+j]=sf_quantile((tempnfw-1)/2,tempnfw,temp3); tempnfw=nfw; } } sf_floatwrite(result,n1*n2,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[]) { bool verb,fsrf,snap,expl; int jsnap,ntsnap; int jdata; /* I/O files */ sf_file Fwav=NULL; /* wavelet */ sf_file Fsou=NULL; /* sources */ sf_file Frec=NULL; /* receivers */ sf_file Fvel=NULL; /* velocity */ sf_file Fref=NULL; /* reflectivity */ sf_file Fden=NULL; /* density */ sf_file Fdat=NULL; /* data (background) */ sf_file Fwfl=NULL; /* wavefield (background) */ sf_file Flid=NULL; /* data (scattered) */ sf_file Fliw=NULL; /* wavefield (scattered) */ /* I/O arrays */ float *ww=NULL; /* wavelet */ pt2d *ss=NULL; /* sources */ pt2d *rr=NULL; /* receivers */ float **vpin=NULL; /* velocity */ float **roin=NULL; /* density */ float **rfin=NULL; /* reflectivity */ float **vp=NULL; /* velocity in expanded domain */ float **ro=NULL; /* density in expanded domain */ float **ro1=NULL; /* normalized 1st derivative of density on axis 1 */ float **ro2=NULL; /* normalized 1st derivative of density on axis 2 */ float **rf=NULL; /* reflectivity in expanded domain */ float *bdd=NULL; /* data (background) */ float *sdd=NULL; /* data (scattered) */ float **vt=NULL; /* temporary vp*vp * dt*dt */ float **bum,**buo,**bup,**bua,**but; /* wavefield: um = U @ t-1; uo = U @ t; up = U @ t+1 */ float **sum,**suo,**sup,**sua,**sut; /* wavefield: um = U @ t-1; uo = U @ t; up = U @ t+1 */ /* cube axes */ sf_axis at,a1,a2,as,ar; int nt,n1,n2,ns,nr,nb; int it,i1,i2; float dt,d1,d2,id1,id2,dt2; /* linear interpolation weights/indices */ lint2d cs,cr; fdm2d fdm; abcone2d abc; /* abc */ sponge spo; /* FD operator size */ float co,ca2,cb2,ca1,cb1; int ompchunk; #ifdef _OPENMP int ompnth,ompath; #endif sf_axis ac1=NULL,ac2=NULL; int nqz,nqx; float oqz,oqx; float dqz,dqx; float **uc=NULL; /*------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); if(! sf_getint("ompchunk",&ompchunk)) ompchunk=1; /* OpenMP data chunk size */ #ifdef _OPENMP if(! sf_getint("ompnth", &ompnth)) ompnth=0; /* OpenMP available threads */ #pragma omp parallel ompath=omp_get_num_threads(); if(ompnth<1) ompnth=ompath; omp_set_num_threads(ompnth); sf_warning("using %d threads of a total of %d",ompnth,ompath); #endif if(! sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ if(! sf_getbool("snap",&snap)) snap=false; /* wavefield snapshots flag */ if(! sf_getbool("free",&fsrf)) fsrf=false; /* free surface flag */ if(! sf_getbool("expl",&expl)) expl=false; /* "exploding reflector" */ Fwav = sf_input ("in" ); /* wavelet */ Fsou = sf_input ("sou"); /* sources */ Frec = sf_input ("rec"); /* receivers */ Fvel = sf_input ("vel"); /* velocity */ Fden = sf_input ("den"); /* density */ Fref = sf_input ("ref"); /* reflectivity */ Fwfl = sf_output("wfl"); /* wavefield */ Fdat = sf_output("out"); /* data */ Fliw = sf_output("liw"); /* wavefield (scattered) */ Flid = sf_output("lid"); /* data (scattered) */ /* axes */ at = sf_iaxa(Fwav,2); sf_setlabel(at,"t"); if(verb) sf_raxa(at); /* time */ as = sf_iaxa(Fsou,2); sf_setlabel(as,"s"); if(verb) sf_raxa(as); /* sources */ ar = sf_iaxa(Frec,2); sf_setlabel(ar,"r"); if(verb) sf_raxa(ar); /* receivers */ a1 = sf_iaxa(Fvel,1); sf_setlabel(a1,"z"); if(verb) sf_raxa(a1); /* depth */ a2 = sf_iaxa(Fvel,2); sf_setlabel(a2,"x"); if(verb) sf_raxa(a2); /* space */ nt = sf_n(at); dt = sf_d(at); ns = sf_n(as); nr = sf_n(ar); n1 = sf_n(a1); d1 = sf_d(a1); n2 = sf_n(a2); d2 = sf_d(a2); if(! sf_getint("jdata",&jdata)) jdata=1; if(snap) { /* save wavefield every *jsnap* time steps */ if(! sf_getint("jsnap",&jsnap)) jsnap=nt; } /*------------------------------------------------------------*/ /* setup output data header */ sf_oaxa(Fdat,ar,1); sf_oaxa(Flid,ar,1); sf_setn(at,nt/jdata); sf_setd(at,dt*jdata); sf_oaxa(Fdat,at,2); sf_oaxa(Flid,at,2); /* setup output wavefield header */ if(snap) { if(!sf_getint ("nqz",&nqz)) nqz=sf_n(a1); if(!sf_getint ("nqx",&nqx)) nqx=sf_n(a2); if(!sf_getfloat("oqz",&oqz)) oqz=sf_o(a1); if(!sf_getfloat("oqx",&oqx)) oqx=sf_o(a2); dqz=sf_d(a1); dqx=sf_d(a2); ac1 = sf_maxa(nqz,oqz,dqz); ac2 = sf_maxa(nqx,oqx,dqx); /* check if the imaging window fits in the wavefield domain */ uc=sf_floatalloc2(sf_n(ac1),sf_n(ac2)); ntsnap=0; for(it=0; it<nt; it++) { if(it%jsnap==0) ntsnap++; } sf_setn(at, ntsnap); sf_setd(at,dt*jsnap); if(verb) sf_raxa(at); /* sf_setn(at,nt/jsnap); sf_setd(at,dt*jsnap); */ sf_oaxa(Fwfl,ac1,1); sf_oaxa(Fwfl,ac2,2); sf_oaxa(Fwfl,at, 3); sf_oaxa(Fliw,ac1,1); sf_oaxa(Fliw,ac2,2); sf_oaxa(Fliw,at, 3); } /*------------------------------------------------------------*/ /* expand domain for FD operators and ABC */ if( !sf_getint("nb",&nb) || nb<NOP) nb=NOP; fdm=fdutil_init(verb,fsrf,a1,a2,nb,ompchunk); sf_setn(a1,fdm->nzpad); sf_seto(a1,fdm->ozpad); if(verb) sf_raxa(a1); sf_setn(a2,fdm->nxpad); sf_seto(a2,fdm->oxpad); if(verb) sf_raxa(a2); /*------------------------------------------------------------*/ if(expl) ww = sf_floatalloc( 1); else ww = sf_floatalloc(ns); bdd =sf_floatalloc(nr); sdd =sf_floatalloc(nr); /*------------------------------------------------------------*/ /* setup source/receiver coordinates */ ss = (pt2d*) sf_alloc(ns,sizeof(*ss)); rr = (pt2d*) sf_alloc(nr,sizeof(*rr)); pt2dread1(Fsou,ss,ns,2); /* read (x,z) coordinates */ pt2dread1(Frec,rr,nr,2); /* read (x,z) coordinates */ cs = lint2d_make(ns,ss,fdm); cr = lint2d_make(nr,rr,fdm); /*------------------------------------------------------------*/ /* setup FD coefficients */ dt2 = dt*dt; id1 = 1/d1; id2 = 1/d2; co = C0 * (id2*id2+id1*id1); ca2= CA * id2*id2; cb2= CB * id2*id2; ca1= CA * id1*id1; cb1= CB * id1*id1; /*------------------------------------------------------------*/ /* input density */ roin=sf_floatalloc2(n1, n2 ); ro =sf_floatalloc2(fdm->nzpad,fdm->nxpad); ro1 =sf_floatalloc2(fdm->nzpad,fdm->nxpad); ro2 =sf_floatalloc2(fdm->nzpad,fdm->nxpad); sf_floatread(roin[0],n1*n2,Fden); expand(roin,ro,fdm); /* normalized density derivatives */ for (i2=NOP; i2<fdm->nxpad-NOP; i2++) { for(i1=NOP; i1<fdm->nzpad-NOP; i1++) { ro1[i2][i1] = D1(ro,i2,i1,id1) / ro[i2][i1]; ro2[i2][i1] = D2(ro,i2,i1,id2) / ro[i2][i1]; } } free(*roin); free(roin); /*------------------------------------------------------------*/ /* input velocity */ vpin=sf_floatalloc2(n1, n2 ); vp =sf_floatalloc2(fdm->nzpad,fdm->nxpad); vt =sf_floatalloc2(fdm->nzpad,fdm->nxpad); sf_floatread(vpin[0],n1*n2,Fvel); expand(vpin,vp,fdm); free(*vpin); free(vpin); /*------------------------------------------------------------*/ /* input reflectivity */ rfin=sf_floatalloc2(n1, n2 ); rf =sf_floatalloc2(fdm->nzpad,fdm->nxpad); sf_floatread(rfin[0],n1*n2,Fref); expand(rfin,rf,fdm); free(*rfin); free(rfin); for (i2=0; i2<fdm->nxpad; i2++) { for(i1=0; i1<fdm->nzpad; i1++) { vt[i2][i1] = vp[i2][i1] * vp[i2][i1] * dt2; } } /* free surface */ if(fsrf) { for (i2=0; i2<fdm->nxpad; i2++) { for(i1=0; i1<fdm->nb; i1++) { vt[i2][i1]=0; } } } /*------------------------------------------------------------*/ /* allocate wavefield arrays */ bum=sf_floatalloc2(fdm->nzpad,fdm->nxpad); buo=sf_floatalloc2(fdm->nzpad,fdm->nxpad); bup=sf_floatalloc2(fdm->nzpad,fdm->nxpad); bua=sf_floatalloc2(fdm->nzpad,fdm->nxpad); sum=sf_floatalloc2(fdm->nzpad,fdm->nxpad); suo=sf_floatalloc2(fdm->nzpad,fdm->nxpad); sup=sf_floatalloc2(fdm->nzpad,fdm->nxpad); sua=sf_floatalloc2(fdm->nzpad,fdm->nxpad); for (i2=0; i2<fdm->nxpad; i2++) { for(i1=0; i1<fdm->nzpad; i1++) { bum[i2][i1]=0; buo[i2][i1]=0; bup[i2][i1]=0; bua[i2][i1]=0; sum[i2][i1]=0; suo[i2][i1]=0; sup[i2][i1]=0; sua[i2][i1]=0; } } /*------------------------------------------------------------*/ /* one-way abc setup */ abc = abcone2d_make(NOP,dt,vp,fsrf,fdm); /* sponge abc setup */ spo = sponge_make(fdm->nb); /*------------------------------------------------------------*/ /* * MAIN LOOP */ /*------------------------------------------------------------*/ if(verb) fprintf(stderr,"\n"); for (it=0; it<nt; it++) { if(verb) fprintf(stderr,"\b\b\b\b\b%d",it); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,fdm->ompchunk) private(i2,i1) shared(fdm,bua,buo,sua,suo,co,ca2,ca1,cb2,cb1,id2,id1) #endif for (i2=NOP; i2<fdm->nxpad-NOP; i2++) { for(i1=NOP; i1<fdm->nzpad-NOP; i1++) { /* 4th order Laplacian operator */ bua[i2][i1] = co * buo[i2 ][i1 ] + ca2*(buo[i2-1][i1 ] + buo[i2+1][i1 ]) + cb2*(buo[i2-2][i1 ] + buo[i2+2][i1 ]) + ca1*(buo[i2 ][i1-1] + buo[i2 ][i1+1]) + cb1*(buo[i2 ][i1-2] + buo[i2 ][i1+2]); sua[i2][i1] = co * suo[i2 ][i1 ] + ca2*(suo[i2-1][i1 ] + suo[i2+1][i1 ]) + cb2*(suo[i2-2][i1 ] + suo[i2+2][i1 ]) + ca1*(suo[i2 ][i1-1] + suo[i2 ][i1+1]) + cb1*(suo[i2 ][i1-2] + suo[i2 ][i1+2]); /* density term */ bua[i2][i1] -= ( D1(buo,i2,i1,id1) * ro1[i2][i1] + D2(buo,i2,i1,id2) * ro2[i2][i1] ); sua[i2][i1] -= ( D1(suo,i2,i1,id1) * ro1[i2][i1] + D2(suo,i2,i1,id2) * ro2[i2][i1] ); } } /* inject acceleration source */ if(expl) { sf_floatread(ww, 1,Fwav); lint2d_inject1(bua,ww[0],cs); } else { sf_floatread(ww,ns,Fwav); lint2d_inject(bua,ww,cs); } /* single scattering */ #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(i2,i1) shared(fdm,buo,sua,rf) #endif for (i2=0; i2<fdm->nxpad; i2++) { for (i1=0; i1<fdm->nzpad; i1++) { sua[i2][i1] -= bua[i2][i1] * 2*rf[i2][i1]; } } /* step forward in time */ #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,fdm->ompchunk) private(i2,i1) shared(fdm,bua,buo,bum,bup,sua,suo,sum,sup,vt,dt2) #endif for (i2=0; i2<fdm->nxpad; i2++) { for(i1=0; i1<fdm->nzpad; i1++) { bup[i2][i1] = 2*buo[i2][i1] - bum[i2][i1] + bua[i2][i1] * vt[i2][i1]; sup[i2][i1] = 2*suo[i2][i1] - sum[i2][i1] + sua[i2][i1] * vt[i2][i1]; } } /* circulate wavefield arrays */ but=bum; bum=buo; buo=bup; bup=but; sut=sum; sum=suo; suo=sup; sup=sut; /* one-way abc apply*/ abcone2d_apply(buo,bum,NOP,abc,fdm); sponge2d_apply(bum, spo,fdm); sponge2d_apply(buo, spo,fdm); abcone2d_apply(suo,sum,NOP,abc,fdm); sponge2d_apply(sum, spo,fdm); sponge2d_apply(suo, spo,fdm); /* extract data at receivers */ lint2d_extract(buo,bdd,cr); lint2d_extract(suo,sdd,cr); if( it%jdata==0) { sf_floatwrite(bdd,nr,Fdat); sf_floatwrite(sdd,nr,Flid); } /* extract wavefield in the "box" */ if(snap && it%jsnap==0) { cut2d(buo,uc,fdm,ac1,ac2); sf_floatwrite(uc[0],sf_n(ac1)*sf_n(ac2),Fwfl); cut2d(suo,uc,fdm,ac1,ac2); sf_floatwrite(uc[0],sf_n(ac1)*sf_n(ac2),Fliw); } } if(verb) fprintf(stderr,"\n"); 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; }