void pt2dwrite1(sf_file F, pt2d *v, size_t n1, int k) /*< output point2d 1-D vector >*/ { int i1; float **w; w=sf_floatalloc2(k,n1); for( i1=0; i1<(int)n1; i1++) { ; w[i1][0] = v[i1].x; ; w[i1][1] = v[i1].z; if(k==3) w[i1][2] = v[i1].v; } sf_floatwrite(w[0],k*n1,F); free( *w); free(w); }
int main (int argc, char* argv[]) { bool scale; int n1,n2, i1,i2, n; float d1, *dat, *der; sf_file in=NULL, out=NULL; 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",&n1)) sf_error("No n1= in input"); n2 = sf_leftsize(in,1); dat = sf_floatalloc(n1); der = sf_floatalloc(n1); if (!sf_getint("order",&n)) n=6; /* filter order */ if (!sf_getbool("scale",&scale) || !sf_histfloat(in,"d1",&d1)) scale=false; /*(scale=n if scale by 1/dx )*/ sf_deriv_init(n1, n, 0.); for (i2=0; i2 < n2; i2++) { sf_floatread(dat,n1,in); sf_deriv(dat,der); if (scale) { for (i1=0; i1 < n1; i1++) { der[i1] /= d1; } } sf_floatwrite(der,n1,out); } exit(0); }
int main(int argc, char* argv[]) { bool adj, inv; int nn,n1,n2,i1,i2; float rho, *pp=NULL; 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"); n2 = sf_leftsize(in,1); if (!sf_getbool("adj",&adj)) adj=false; /* If y, apply adjoint */ if (!sf_getbool("inv",&inv)) inv=false; /* If y, do differentiation instead of integration */ if (!sf_getfloat("rho",&rho)) rho = 1.-1./n1; /* Leaky integration constant */ if (inv) { sf_warning("%s half-order differentiation",adj? "anticausal":"causal"); } else { sf_warning("%s half-order integration",adj? "anticausal":"causal"); } nn = 2*kiss_fft_next_fast_size((n1+1)/2); pp = sf_floatalloc(nn); sf_halfint_init (inv, nn, rho); for (i2=0; i2 < n2; i2++) { sf_floatread (pp,n1,in); for (i1=n1; i1 < nn; i1++) { pp[i1]=0.; } sf_halfint (adj, pp); sf_floatwrite (pp,n1,out); } exit(0); }
int main(int argc, char* argv[]) { int nt, ns, nx, ix, is, it; float *trace=NULL, *picks=NULL, **semb=NULL, s0, ds, s; sf_file in=NULL, out=NULL, pick=NULL; sf_init(argc,argv); in = sf_input("in"); pick = sf_input("pick"); out = sf_output("out"); if (!sf_histint(in,"n1",&nt)) sf_error("No n1= in input"); if (!sf_histint(in,"n2",&ns)) sf_error("No n2= in input"); if (!sf_histfloat(in,"o2",&s0)) sf_error("No o2= in input"); if (!sf_histfloat(in,"d2",&ds)) sf_error("No d2= in input"); nx = sf_unshiftdim(in,out,2); semb = sf_floatalloc2(nt,ns); picks = sf_floatalloc (nt); trace = sf_floatalloc (nt); for (ix=0; ix < nx; ix++) { sf_floatread (semb[0],nt*ns,in); sf_floatread (picks,nt,pick); for (it=0; it < nt; it++) { s = (picks[it] - s0)/ds; is = floorf(s); s -= is; if (is >= 0 && is < ns-1) { trace[it] = s * semb[is+1][it] + (1.-s) * semb[is][it]; } else { trace[it] = 0.; } } sf_floatwrite (trace,nt,out); } exit (0); }
int main(int argc, char* argv[]) { int i1, i2, n1,n2,n3,n12; float s=0, *pp1, *pp2; sf_file inp1, inp2, dif; sf_init(argc,argv); inp1 = sf_input("in"); inp2 = sf_input("match"); dif = sf_output("out"); sf_putfloat(dif,"o2",0); sf_putfloat(dif,"o1",0); sf_putint(dif,"n1",1); sf_putint(dif,"n2",1); if (!sf_histint(inp1,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(inp1,"n2",&n2)) sf_error("No n2= in input"); if (!sf_histint(inp1,"n3",&n3)) n3=1; n2 = sf_leftsize(inp1,1); /* left dimensions after the first one */ n12 = n1*n2; if (n3!=1) {sf_putint(dif,"n3",1); sf_putint(dif,"d3",1); } pp1 = sf_floatalloc(n12); pp2 = sf_floatalloc(n12); sf_floatread(pp1,n12,inp1); sf_floatread(pp2,n12,inp2); for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1; i1++) { s = s + pow((pp1[i2*n1+i1]-pp2[i2*n1+i1]),2); } } sf_warning("The difference is %f", s ); sf_floatwrite(&s,1,dif); exit(0); }
int main(int argc, char* argv[]) { int nx, nz, ix, iz; float* trace; float dx, dz, x[2]; sf_file mod; sf_init (argc,argv); mod = sf_output("out"); if (!sf_getint("nx",&nx)) nx=400; /* horizontal dimension */ if (!sf_getint("nz",&nz)) nz=800; /* vertical dimension */ dx = 1./(nx-1); dz = 2./(nz-1); sf_putint (mod,"n1",nz); sf_putfloat (mod,"d1",dz); sf_putfloat (mod,"o1",0.); sf_putint (mod,"n2",nx); sf_putfloat (mod,"d2",dx); sf_putfloat (mod,"o2",0.); sf_setformat (mod,"native_float"); trace = sf_floatalloc(nz); for (ix = 0; ix < nx; ix++) { x[1] = ix*dx; for (iz = 0; iz < nz; iz++) { x[0] = iz*dz; trace[iz] = 1./sqrtf(symes_vel(NULL,x)); } sf_floatwrite(trace,nz,mod); } exit (0); }
void pt2dwrite2(sf_file F, pt2d **v, size_t n1, size_t n2, int k) /*< output point2d 2-D vector >*/ { int i1,i2; float ***w; w=sf_floatalloc3(k,n1,n2); for( i2=0; i2<(int)n2; i2++) { for( i1=0; i1<(int)n1; i1++) { ; w[i2][i1][0] = v[i2][i1].x; ; w[i2][i1][1] = v[i2][i1].z; if(k==3) w[i2][i1][2] = v[i2][i1].v; } } sf_floatwrite(w[0][0],k*n1*n2,F); free(**w); free(*w); free(w); }
int main(int argc, char* argv[]) { int n1, n2, i2; float *pp, *qq; bool square, adj; 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"); if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); n2 = sf_leftsize(in,1); if (!sf_getbool("square",&square)) square=false; /* if y, use gradient squared */ if (!sf_getbool("adj",&adj)) adj=false; /* adjoint flag */ pp = sf_floatalloc(n1); qq = sf_floatalloc(n1); for (i2=0; i2 < n2; i2++) { sf_floatread(pp,n1,in); if (square) { sf_grad2 (n1,pp,qq); } else if (adj) { sf_igrad1_lop (true,false,n1,n1,qq,pp); } else { sf_igrad1_lop (false,false,n1,n1,pp,qq); } sf_floatwrite(qq,n1,out); } exit(0); }
int main(int argc,char *argv[]) { int i,j,n1,n2,n3; float o1,d1,o2,d2,max; float *orig,*output; 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_histfloat(in,"d1",&d1)) sf_error("No d1= in input"); if (!sf_histfloat(in,"o1",&o1)) sf_error("No o1= in input"); if (!sf_histint(in,"n2",&n2)) n2=1; if (!sf_histfloat(in,"d2",&d2)) d2=1; if (!sf_histfloat(in,"o2",&o2)) o2=1; n3=sf_leftsize(in,2); orig = sf_floatalloc(n1*n2); output = sf_floatalloc(n1*n2); for(j = 0; j < n3; j++){ sf_floatread(orig,n1*n2,in); max=0; for(i=0;i<n1*n2;i++){ if(orig[i]>max) max=orig[i]; } for(i=0;i<n1*n2;i++){ output[i]=max-orig[i]; } sf_floatwrite(output,n1*n2,out); } exit(0); }
int main(int argc, char* argv[]) { int dim, m[SF_MAX_DIM], nd, i, niter, rect[SF_MAX_DIM]; float **inp, *rat; char key[6]; 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,m); nd=1; for (i=0; i < dim; i++) { nd *= m[i]; snprintf(key,6,"rect%d",i+1); if (!sf_getint(key,rect+i)) rect[i]=1; } if (!sf_getint("niter",&niter)) niter=100; /* number of iterations */ inp = sf_floatalloc2 (m[0],nd/m[0]); rat = sf_floatalloc (nd); envcorr_init(dim,m,rect,niter); sf_floatread(inp[0],nd,in); envcorr(inp,rat); sf_floatwrite(rat,nd,out); exit (0); }
int main(int argc, char** argv) { int n1, n2, i1, i2; float* vint=NULL; float o1, d1, v0, alpha, t; 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\n"); if (!sf_histint (in,"n2",&n2)) sf_error ("No n2= in input\n"); if (!sf_histfloat (in,"o1",&o1)) o1=0.; if (!sf_histfloat (in,"d1",&d1)) sf_error ("No d1= in input\n"); if (!sf_getfloat ("v0",&v0)) v0 = 1.5; /* initial velocity */ if (!sf_getfloat ("alpha",&alpha)) alpha = 0.5; /* velocity gradient */ vint = sf_floatalloc(n1); for (i1=0; i1 < n1; i1++) { t = alpha*(o1+i1*d1); if (t > 0.) { vint[i1] = v0 * sqrtf((expf(t)-1.)/t); } else { vint[i1] = v0; } } for (i2=0; i2 < n2; i2++) { sf_floatwrite(vint,n1,out); } exit (0); }
int main (int argc, char *argv[]) { int n1, n2, n3, i2, i3, order; float *trace; 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"); 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_getint("order",&order)) order=4; /* Accuracy order */ trace = sf_floatalloc (n1); pick0_init (n1, n2, order); for (i3=0; i3 < n3; i3++) { for (i2=0; i2 < n2; i2++) { sf_floatread(trace,n1,in); pick0_set (i2, trace); } for (i2=0; i2 < n2; i2++) { pick0_delta (i2, trace); sf_floatwrite(trace,n1,out); } } exit (0); }
int main(int argc, char *argv[]) { int i, m, n, k, n1a, n1b, n2a, n2b, n3a, n3b; /*n1 is trace length, n2 is the number of traces, n3 is the number of 3th axis*/ sf_file in, mat, out; float *a, *b, *c; char *type; sf_init(argc,argv); in = sf_input("in"); /* in is the input matrix A, with m rows and n columns */ mat= sf_input("mat"); /* mat is the input matrix B, with n rows and k columns */ out = sf_output("out"); /* out is the output matrix C, with m rows and k columns */ if (NULL == (type=sf_getstring("type"))) type="mul"; /* [mul, add, sub, dotmul] operation type, the default is mul */ if (!sf_histint(in,"n1",&n1a)) sf_error("No n1= in input"); if (!sf_histint(in,"n2",&n2a)) sf_error("No n2= in input"); n3a = sf_leftsize(in,2); if (!sf_histint(mat,"n1",&n1b)) sf_error("No n1= in input"); if (!sf_histint(mat,"n2",&n2b)) sf_error("No n2= in input"); n3b = sf_leftsize(mat,2); if (type[0]=='m') { if (n1a!=n2b) sf_error("n1 of A must be equal to n2 of B for multiplication"); m=n2a;n=n1a;k=n1b; } if (type[0]!='m') { if (n1a!=n1b || n2a!=n2b) sf_error(" n1 of A must be equal to n1 of B and n2 of A must be equal to n2 of B"); m=n2a;n=n1a;k=n; } if (n3a != n3b) sf_error("n3 must be equal"); sf_putint(out, "n1", k); sf_putint(out, "n2", m); sf_putint(out, "n3", n3a); a = sf_floatalloc(m*n); b = sf_floatalloc(n*k); c = sf_floatalloc(m*k); for(i=0;i<n3a;i++) { sf_floatread(a, m*n, in); if(type[0]!='m') sf_floatread(b, m*n, mat); else sf_floatread(b,n*k,mat); switch(type[0]) { case 'm': mul(a, b, m, n, k, c); break; case 'a': add(a, b, m, n, c); break; case 's': sub(a, b, m, n, c); break; case 'd': dotmul(a, b, m, n, c); } sf_floatwrite(c, m*k, out); } exit(0); }
int main (int argc, char *argv[]) { bool verb; int n1,n2,n3, n12, n23, ref2, ref3, i2,i3,i1, ud, lr, order; float eps, ***dat, ***p, ***q, **p2, **q2, *trace; sf_file dip, out, seed, cost; sf_init(argc,argv); dip = sf_input("in"); out = sf_output("out"); seed = sf_input("seed"); cost = sf_input("cost"); if (!sf_histint(dip,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(dip,"n2",&n2)) sf_error("No n2= in input"); if (!sf_histint(dip,"n3",&n3)) sf_error("No n3= in input"); n23 = n2*n3; n12 = n1*n23; if (!sf_getbool("verb",&verb)) verb=false; if (!sf_getfloat("eps",&eps)) eps=0.01; /* regularization */ if (!sf_getint("ref2",&ref2)) ref2=0; if (!sf_getint("ref3",&ref3)) ref3=0; /* reference trace */ sf_putint(out,"n4",1); p = sf_floatalloc3(n1,n2,n3); q = sf_floatalloc3(n1,n2,n3); dat = sf_floatalloc3(n1,n2,n3); sf_floatread(p[0][0],n12,dip); sf_floatread(q[0][0],n12,dip); p2 = sf_floatalloc2(n2,n3); q2 = sf_floatalloc2(n2,n3); sf_floatread(p2[0],n23,cost); sf_floatread(q2[0],n23,cost); dijkstra_init(n2,n3,p2,q2); dijkstra_source(ref2,ref3); sf_floatread(dat[ref3][ref2],n1,seed); if (verb) sf_warning("%d %d",ref2,ref3); if (!sf_getint("order",&order)) order=1; /* accuracy order */ predict_init(n1,n2, eps*eps, order, 1, false); while (dijskstra_step(&i2,&i3,&ud,&lr)) { if (verb) sf_warning("%d %d",i2,i3); trace = dat[i3][i2]; for (i1=0; i1 < n1; i1++) { trace[i1] = dat[i3-lr][i2-ud][i1]; } if (ud > 0) { predict_step(false,true,trace,p[i3][i2-ud]); } else if (ud < 0) { predict_step(false,false,trace,p[i3][i2]); } if (lr > 0) { predict_step(false,true,trace,q[i3-lr][i2]); } else if (lr < 0) { predict_step(false,false,trace,q[i3][i2]); } } sf_floatwrite(dat[0][0],n12,out); exit (0); }
int main(int argc, char* argv[]) { int nx, nz, nt, ix, iz, it, nbt, nbb, nxl, nxr, nxb, nyb, nzb, isx, isz; float dt, dx, dy, dz, o1, o2, o3; float **old, **cur, **tmp, *wav; float **v, **vtmp, v0, **sigma, **delta, **seta; float ***aa, w, g1, g2, czt, czb, cxl, cxr; /* top, bottom, left, right */ float ax, az, factor; sf_file out, vel, source, fsigma, fdelta, fseta; int opt, snap, nsnap; /* optimal padding */ sf_init(argc,argv); out = sf_output("out"); vel = sf_input("vel"); /* velocity */ fsigma = sf_input("sigma"); /* velocity */ fdelta = sf_input("delta"); /* velocity */ fseta = sf_input("seta"); /* velocity */ source = sf_input("in"); /* source wavlet*/ if (SF_FLOAT != sf_gettype(vel)) sf_error("Need float input"); if (SF_FLOAT != sf_gettype(source)) sf_error("Need float input"); if (!sf_histint(vel,"n1",&nz)) sf_error("No n1= in input"); if (!sf_histfloat(vel,"d1",&dz)) sf_error("No d1= in input"); if (!sf_histint(vel,"n2",&nx)) sf_error("No n2= in input"); if (!sf_histfloat(vel,"d2",&dx)) sf_error("No d2= in input"); if (!sf_histfloat(vel,"o1",&o1)) o1=0.0; if (!sf_histfloat(vel,"o2",&o2)) o2=0.0; if (!sf_getint("opt",&opt)) opt=1; /* if y, determine optimal size for efficiency */ if (!sf_getfloat("dt",&dt)) sf_error("Need dt input"); if (!sf_getint("nt",&nt)) sf_error("Need nt input"); if (!sf_getint("isx",&isx)) sf_error("Need isx input"); if (!sf_getint("isz",&isz)) sf_error("Need isz input"); if (!sf_getint("nbt",&nbt)) nbt=44; if (!sf_getint("nbb",&nbb)) nbb=44; if (!sf_getint("nxl",&nxl)) nxl=44; if (!sf_getint("nxr",&nxr)) nxr=44; /* assume ABC pars are the same */ if (nbt != nbb || nxl != nxr || nbt!=nxl) sf_error("ABC pars are not the same"); if (!sf_getfloat("czt",&czt)) czt = 0.01; /*decaying parameter*/ if (!sf_getfloat("czb",&czb)) czb = 0.01; /*decaying parameter*/ if (!sf_getfloat("cxl",&cxl)) cxl = 0.01; /*decaying parameter*/ if (!sf_getfloat("cxr",&cxr)) cxr = 0.01; /*decaying parameter*/ if (!sf_getint("snap",&snap)) snap=1; nsnap=0; for (it=0; it < nt; it++) { if (it%snap == 0) nsnap++; } sf_putfloat(out,"d1",dz); sf_putfloat(out,"d2",dx); sf_putfloat(out,"d3",dt*snap); sf_putfloat(out,"o1",o1); sf_putfloat(out,"o2",o2); sf_putfloat(out,"o3",0.0); nxb = nx + nxl + nxr; nzb = nz + nbt + nbb; sf_putint(out,"n1",nzb); sf_putint(out,"n2",nxb); sf_putint(out,"n3",nsnap); wav = sf_floatalloc(nt); sf_floatread(wav,nt,source); old = sf_floatalloc2(nzb,nxb); cur = sf_floatalloc2(nzb,nxb); aa = sf_floatalloc3(nzb,nxb,3); bd2_init(nx,nz,nxl,nxr,nbt,nbb,cxl,cxr,czt,czb); /*input & extend velocity model*/ v = sf_floatalloc2(nzb,nxb); vtmp = sf_floatalloc2(nz,nx); sf_floatread(vtmp[0],nx*nz,vel); v = extmodel(vtmp, nz, nx, nbt); sigma = sf_floatalloc2(nzb,nxb); sf_floatread(vtmp[0],nx*nz,fsigma); sigma = extmodel(vtmp, nz, nx, nbt); delta = sf_floatalloc2(nzb,nxb); sf_floatread(vtmp[0],nx*nz,fdelta); delta = extmodel(vtmp, nz, nx, nbt); seta = sf_floatalloc2(nzb,nxb); sf_floatread(vtmp[0],nx*nz,fseta); seta = extmodel(vtmp, nz, nx, nbt); v0 =0.0; for (ix=0; ix < nxb; ix++) { for (iz=0; iz < nzb; iz++) { v0 += v[ix][iz]*v[ix][iz]; } } v0 = sqrtf(v0/(nxb*nzb)); fprintf(stderr, "v0=%f\n\n", v0); for (ix=0; ix < nxb; ix++) { for (iz=0; iz < nzb; iz++) { cur[ix][iz] = 0.0; old[ix][iz] = 0.0; } } /* propagation in time */ pamstep2_init(nzb,nxb,dz,dx,opt); for (it=0; it < nt; it++) { fprintf(stderr, "\b\b\b\b\b%d", it); pamstep2(old, cur, nzb, nxb, dz, dx, v0, v, sigma, delta, seta, dt); old[isx+nxl][isz+nbt] += wav[it]; bd2_decay(old); bd2_decay(cur); tmp = old; old = cur; cur = tmp; if (it%nsnap==0) sf_floatwrite(cur[0], nxb*nzb, out); } pamstep2_close(); bd2_close(); free(**aa); free(*aa); free(aa); free(*v); free(*sigma); free(*delta); free(*seta); free(*vtmp); free(*cur); free(*old); free(v); free(sigma); free(delta); free(seta); free(vtmp); free(cur); free(old); exit(0); }
int main(int argc, char* argv[]) { bool verb,isreversed; sf_file Fs,Fr,Fi; /* I/O files */ sf_axis az,ax,at,aa; /* cube axes */ int iz,ix,it; int nz,nx,nt; off_t iseek; float **us=NULL,**ur=NULL,**ii=NULL; float scale; /*------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); /* OMP parameters */ #ifdef _OPENMP omp_init(); #endif if(! sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ if(! sf_getbool("isreversed",&isreversed)) isreversed=false; /* received wavefield */ Fs = sf_input ("in" ); Fr = sf_input ("ur" ); Fi = sf_output("out"); /*------------------------------------------------------------*/ /* read axes */ az=sf_iaxa(Fs,1); nz = sf_n(az); ax=sf_iaxa(Fs,2); nx = sf_n(ax); at=sf_iaxa(Fs,3); nt = sf_n(at); aa=sf_maxa(1,0,1); sf_setlabel(aa,""); sf_setunit (aa,""); if(verb) { sf_raxa(az); sf_raxa(ax); sf_raxa(at); } /* write axes */ sf_oaxa(Fi,az,1); sf_oaxa(Fi,ax,2); sf_oaxa(Fi,aa,3); /*------------------------------------------------------------*/ /* allocate work arrays */ ii = sf_floatalloc2(nz,nx); us = sf_floatalloc2(nz,nx); ur = sf_floatalloc2(nz,nx); for (ix=0; ix<nx; ix++) { for(iz=0; iz<nz; iz++) { ii[ix][iz]=0.; } } /*------------------------------------------------------------*/ if(isreversed) { /* receiver wavefield is reversed */ if(verb) fprintf(stderr,"nt\n"); for (it=0; it<nt; it++) { if(verb) fprintf(stderr,"\b\b\b\b\b\b\b\b\b\b%04d",it); sf_floatread(us[0],nz*nx,Fs); sf_floatread(ur[0],nz*nx,Fr); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) \ private(ix,iz) \ shared (ii,us,ur,nx,nz) #endif for (ix=0; ix<nx; ix++) { for(iz=0; iz<nz; iz++) { ii[ix][iz] += us[ix][iz]*ur[ix][iz]; } } } /* it */ if(verb) fprintf(stderr,"\n"); } else { /* receiver wavefield is NOT reversed */ if(verb) fprintf(stderr,"nt\n"); for (it=0; it<nt; it++) { if(verb) fprintf(stderr,"\b\b\b\b\b%d",(nt-it-1)); sf_floatread(us[0],nz*nx,Fs); iseek=(off_t)(nt-1-it)*nz*nx*sizeof(float); sf_seek(Fr,iseek,SEEK_SET); sf_floatread(ur[0],nz*nx,Fr); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) \ private(ix,iz) \ shared (ii,us,ur,nx,nz) #endif for (ix=0; ix<nx; ix++) { for(iz=0; iz<nz; iz++) { ii[ix][iz] += us[ix][iz]*ur[ix][iz]; } } } /* it */ if(verb) fprintf(stderr,"\n"); } /* end "is reversed" */ /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* scale image */ scale = 1./nt; for (ix=0; ix<nx; ix++) { for(iz=0; iz<nz; iz++) { ii[ix][iz] *=scale; } } /*------------------------------------------------------------*/ /* write image */ sf_floatwrite(ii[0],nx*nz,Fi); /*------------------------------------------------------------*/ /* deallocate arrays */ free(*ii); free(ii); free(*us); free(us); free(*ur); free(ur); /*------------------------------------------------------------*/ exit (0); }
int main(int argc, char** argv) { bool verb, fsrf, snap, expl, dabc, cden, adj; bool optfd, hybrid, sinc; int jsnap, jdata; /* I/O files */ sf_file file_wav=NULL; /* wavelet */ sf_file file_vel=NULL; /* velocity */ sf_file file_den=NULL; /* density */ sf_file file_wfl=NULL; /* wavefield */ sf_file file_dat=NULL; /* data */ sf_file file_src=NULL; /* sources */ sf_file file_rec=NULL; /* receivers */ /* cube axes */ sf_axis at = NULL, az = NULL, ax = NULL, ay = NULL; sf_axis as = NULL, ar = NULL; int nbd; /* ABC boundary size */ int fdorder; /* finite difference spatial accuracy order */ int nzpad,nxpad,nypad; /* boundary padded model size */ int ix,iy,it,is,nx,ny,nz,nt,ns,nr; float dx,dy,dz,dt,dt2; float* damp=NULL; /* damping profile for hybrid bc */ float* ws; /* wavelet */ float*** vel=NULL; /* velocity */ float*** rho=NULL; /* density */ float*** u0=NULL; /* wavefield array u@t-1 (u@t+1) */ float*** u1=NULL; /* wavefield array u@t */ float* u_dat=NULL; /* output data */ float*** ptr_tmp=NULL; pt3d* src3d=NULL; /* source position */ pt3d* rec3d=NULL; /*receiver position*/ scoef3d cssinc = NULL, crsinc = NULL; lint3d cslint = NULL, crlint = NULL; /* FDM structure */ fdm3d fdm = NULL; abcone3d abc = NULL; sponge spo = NULL; int nbell; float* fdcoef_d2; float* fdcoef_d1; sf_axis acz = NULL, acx = NULL, acy = NULL; int nqz, nqx, nqy; float oqz, oqx, oqy, dqz, dqx, dqy; float** oslice = NULL; /* output 3D wavefield slice-by-slice */ float*** tmp_array; double wall_clock_time_s, wall_clock_time_e; const int SECOND_DERIV = 2; const int FIRST_DERIV = 1; int nop; #if defined _OPENMP && _DEBUG double tic; double toc; #endif /* init RSF */ sf_init(argc,argv); #ifdef _OPENMP omp_init(); wall_clock_time_s = omp_get_wtime(); #else wall_clock_time_s = (double) clock() / CLOCKS_PER_SEC; #endif if (!sf_getbool("verb",&verb)) verb=false; /* Verbosity flag */ if (!sf_getbool("snap",&snap)) snap=false; /* Wavefield snapshots flag */ if (!sf_getbool("expl",&expl)) expl=false; /* Multiple sources, one wvlt*/ if (!sf_getbool("dabc",&dabc)) dabc=false; /* Absorbing BC */ if (!sf_getbool("cden",&cden)) cden=false; /* Constant density */ if (!sf_getbool("adj",&adj)) adj=false; /* adjoint flag */ if (!sf_getbool("free",&fsrf) && !sf_getbool("fsrf",&fsrf)) fsrf=false; /* Free surface flag */ if (!sf_getint("nbell",&nbell)) nbell=5; /* gaussian for source injection */ if (!sf_getbool("optfd",&optfd)) optfd=false; /* optimized FD coefficients flag */ if (!sf_getint("fdorder",&fdorder)) fdorder=4; /* spatial FD order */ if (!sf_getbool("hybridbc",&hybrid)) hybrid=false; /* hybrid Absorbing BC */ if (!sf_getbool("sinc",&sinc)) sinc=false; /* sinc source injection */ /* Initialize variables */ file_wav = sf_input("in"); /* wavelet */ file_vel = sf_input("vel"); /* velocity */ file_src = sf_input("sou"); /* sources */ file_rec = sf_input("rec"); /* receivers */ file_dat = sf_output("out"); /* data */ if (snap) file_wfl = sf_output("wfl"); /* wavefield */ if (!cden) { if (sf_getstring("cden")) { file_den = sf_input ("den"); /* density */ } else { cden = true; if (verb) sf_warning("No density file provided, running with constant density"); } } at = sf_iaxa(file_wav,2); sf_setlabel(at,"t"); if(verb) sf_raxa(at); /* time */ az = sf_iaxa(file_vel,1); sf_setlabel(az,"z"); if(verb) sf_raxa(az); /* depth */ ax = sf_iaxa(file_vel,2); sf_setlabel(ax,"x"); if(verb) sf_raxa(ax); /* space */ ay = sf_iaxa(file_vel,3); sf_setlabel(ay,"y"); if(verb) sf_raxa(ay); /* space */ as = sf_iaxa(file_src,2); sf_setlabel(as,"s"); if(verb) sf_raxa(as); /* sources */ ar = sf_iaxa(file_rec,2); sf_setlabel(ar,"r"); if(verb) sf_raxa(ar); /* receivers */ nt = sf_n(at); dt = sf_d(at); nz = sf_n(az); dz = sf_d(az); nx = sf_n(ax); dx = sf_d(ax); ny = sf_n(ay); dy = sf_d(ay); ns = sf_n(as); nr = sf_n(ar); /* other execution parameters */ if (snap) { if (!sf_getint("jsnap",&jsnap)) jsnap=nt; /* # of t steps at which to save wavefield */ } if (!sf_getint("jdata",&jdata)) jdata=1; /* # of t steps at which to save receiver data */ /* setup output data header */ sf_oaxa(file_dat,ar,1); sf_setn(at,(nt-1)/jdata+1); sf_setd(at,dt*jdata); sf_oaxa(file_dat,at,2); /* wavefield cut params */ /* setup output wavefield header */ if (snap) { if (!sf_getint ("nqz",&nqz)) nqz=sf_n(az); /* Saved wfld window nz */ if (!sf_getint ("nqx",&nqx)) nqx=sf_n(ax); /* Saved wfld window nx */ if (!sf_getint ("nqy",&nqy)) nqy=sf_n(ay); /* Saved wfld window ny */ if (!sf_getfloat("oqz",&oqz)) oqz=sf_o(az); /* Saved wfld window oz */ if (!sf_getfloat("oqx",&oqx)) oqx=sf_o(ax); /* Saved wfld window ox */ if (!sf_getfloat("oqy",&oqy)) oqy=sf_o(ay); /* Saved wfld window oy */ if (!sf_getfloat("dqz",&dqz)) dqz=sf_d(az); /* Saved wfld window dz */ if (!sf_getfloat("dqx",&dqx)) dqx=sf_d(ax); /* Saved wfld window dx */ if (!sf_getfloat("dqy",&dqy)) dqy=sf_d(ay); /* Saved wfld window dy */ acz = sf_maxa(nqz,oqz,dqz); if (verb) sf_raxa(acz); acx = sf_maxa(nqx,oqx,dqx); if (verb) sf_raxa(acx); acy = sf_maxa(nqy,oqy,dqy); if (verb) sf_raxa(acy); /* check if the imaging window fits in the wavefield domain */ sf_setn(at,(nt-1)/jsnap+1); sf_setd(at,dt*jsnap); if (verb) sf_raxa(at); sf_oaxa(file_wfl,acz,1); sf_oaxa(file_wfl,acx,2); sf_oaxa(file_wfl,acy,3); sf_oaxa(file_wfl,at,4); } /* 2-2N finite difference coefficient */ nop = fdorder/2; /* fd half-length stencil */ if (!sf_getint("nb",&nbd) || nbd<nop) nbd=nop; if (dabc && hybrid && nbd<=nop) nbd = 2*nop; /* expand domain for FD operators and ABC */ fdm = fdutil3d_init(verb,fsrf,az,ax,ay,nbd,1); sf_setn(az,fdm->nzpad); sf_seto(az,fdm->ozpad); if (verb) sf_raxa(az); sf_setn(ax,fdm->nxpad); sf_seto(ax,fdm->oxpad); if (verb) sf_raxa(ax); sf_setn(ay,fdm->nypad); sf_seto(ay,fdm->oypad); if (verb) sf_raxa(ay); /* Precompute coefficients */ dt2 = dt*dt; nzpad = nz+2*nbd; nxpad = nx+2*nbd; nypad = ny+2*nbd; fdcoef_d2 = compute_fdcoef(nop,dz,dx,dy,optfd,SECOND_DERIV); fdcoef_d1 = compute_fdcoef(nop,dz,dx,dy,optfd,FIRST_DERIV); /* Allocate memories */ if (expl) ws = sf_floatalloc(1); else ws = sf_floatalloc(ns); vel = sf_floatalloc3(nzpad,nxpad,nypad); if (!cden) rho = sf_floatalloc3(nzpad,nxpad,nypad); u_dat = sf_floatalloc(nr); src3d = pt3dalloc1(ns); rec3d = pt3dalloc1(nr); if (snap) oslice = sf_floatalloc2(sf_n(acz),sf_n(acx)); /* source and receiver position */ pt3dread1(file_src,src3d,ns,3); /* read format: (x,y,z) */ if (sinc) cssinc = sinc3d_make(ns,src3d,fdm); else cslint = lint3d_make(ns,src3d,fdm); pt3dread1(file_rec,rec3d,nr,3); /* read format: (x,y,z) */ if (sinc) crsinc = sinc3d_make(nr,rec3d,fdm); else crlint = lint3d_make(nr,rec3d,fdm); if (!sinc) fdbell3d_init(nbell); /* temperary array */ tmp_array = sf_floatalloc3(nz,nx,ny); /* read velocity and pad */ sf_floatread(tmp_array[0][0],nz*nx*ny,file_vel); expand3d(tmp_array,vel,fdm); /* read density and pad */ if (!cden) { sf_floatread(tmp_array[0][0],nz*nx*ny,file_den); expand3d(tmp_array,rho,fdm); } free(**tmp_array); free(*tmp_array); free(tmp_array); /* A1 one-way ABC implicit scheme coefficients */ if (dabc) { abc = abcone3d_make(nbd,dt,vel,fsrf,fdm); if (hybrid) damp = damp_make(nbd-nop); /* compute damping profiles for hybrid bc */ else spo = sponge_make(fdm->nb); } /* allocate memory for wavefield variables */ u0 = sf_floatalloc3(nzpad,nxpad,nypad); u1 = sf_floatalloc3(nzpad,nxpad,nypad); /* initialize variables */ memset(u0[0][0],0,sizeof(float)*nzpad*nxpad*nypad); memset(u1[0][0],0,sizeof(float)*nzpad*nxpad*nypad); memset(u_dat,0,sizeof(float)*nr); /* v = (v*dt)^2 */ for (ix=0;ix<nzpad*nxpad*nypad;ix++) *(vel[0][0]+ix) *= *(vel[0][0]+ix)*dt2; if (fsrf && !hybrid) { for (iy=0; iy<nypad; iy++) for (ix=0; ix<nxpad; ix++) memset(vel[iy][ix],0,sizeof(float)*fdm->nb); } for (it=0; it<nt; it++) { if (verb) sf_warning("it=%d;",it+1); #if defined _OPENMP && _DEBUG tic=omp_get_wtime(); #endif step_forward(u0,u1,vel,rho,fdcoef_d2,fdcoef_d1,nop,nzpad,nxpad,nypad); if (adj) { /* backward inject source wavelet */ if (expl) { sf_seek(file_wav,(off_t)(nt-it-1)*sizeof(float),SEEK_SET); sf_floatread(ws,1,file_wav); ws[0] *= dt2; if (sinc) sinc3d_inject1(u0,ws[0],cssinc); else lint3d_inject1(u0,ws[0],cslint); } else { sf_seek(file_wav,(off_t)(nt-it-1)*ns*sizeof(float),SEEK_SET); sf_floatread(ws,ns,file_wav); for (is=0; is<ns; is++) ws[is] *= dt2; if (sinc) sinc3d_inject(u0,ws,cssinc); else lint3d_inject(u0,ws,cslint); } } else { /* forward inject source wavelet */ if (expl) { sf_floatread(ws,1,file_wav); ws[0] *= dt2; if (sinc) sinc3d_inject1(u0,ws[0],cssinc); else lint3d_inject1(u0,ws[0],cslint); } else { sf_floatread(ws,ns,file_wav); for (is=0; is<ns; is++) ws[is] *= dt2; if (sinc) sinc3d_inject(u0,ws,cssinc); else lint3d_inject(u0,ws,cslint); } } /* apply abc */ if (dabc) { if (hybrid) apply_abc(u0,u1,nz,nx,ny,nbd,abc,nop,damp); else { abcone3d_apply(u0,u1,nop,abc,fdm); sponge3d_apply(u0,spo,fdm); sponge3d_apply(u1,spo,fdm); } } /* loop over pointers */ ptr_tmp = u0; u0 = u1; u1 = ptr_tmp; /* extract snapshot */ if (snap && it%jsnap==0) { int fy = (floor)((sf_o(acy)-fdm->oypad)/fdm->dy); int jy = floor(sf_d(acy)/fdm->dy); float **ptr_slice; for (iy=0; iy<sf_n(acy); iy++) { ptr_slice = u0[fy+iy*jy]; cut3d_slice(ptr_slice,oslice,fdm,acz,acx); sf_floatwrite(oslice[0],sf_n(acz)*sf_n(acx),file_wfl); } } /* extract receiver data */ if (sinc) sinc3d_extract(u0,u_dat,crsinc); else lint3d_extract(u0,u_dat,crlint); sf_floatwrite(u_dat,nr,file_dat); #if defined _OPENMP && _DEBUG toc=omp_get_wtime(); fprintf(stderr,"%5.2gs",(float)(toc-tic)); #endif } #ifdef _OPENMP wall_clock_time_e = omp_get_wtime(); #else wall_clock_time_e = (double) clock() / CLOCKS_PER_SEC; #endif if (verb) fprintf(stderr,"\nElapsed time: %lf s\n",wall_clock_time_e-wall_clock_time_s); free(**u0); free(*u0); free(u0); free(**u1); free(*u1); free(u1); free(**vel); free(*vel); free(vel); free(u_dat); free(ws); free(fdcoef_d2); free(fdcoef_d1); if (snap) { free(*oslice); free(oslice); } if(!cden) { free(**rho); free(*rho); free(rho); } if (hybrid) free(damp); free(src3d); free(rec3d); return 0; }
int main(int argc, char ** argv) { /* BEGIN DECLARATIONS */ WINFO wi; /* struct for command line input */ /* workspace */ float * v; /* velocity field */ float * p1; /* pressure field, current time step */ float * p0; /* pressure field, last time step */ float * tr; /* storage for traces */ float * tmp; /* used to swap p1 and p0 */ int ix, it; /* counters */ int isrc; /* source counter */ int imf; /* movie frame counter */ int isx; /* source location, in units of dx */ int nxz; /* number of spatial grid points */ /* int nz; local number of gridpoints */ int ntr; /* number of traces */ int nsam; /* number of trace samples */ int nsrc; /* number of shots */ float rz,rx,s; /* precomputed coefficients */ float vmax,vmin; /* max, min velocity values */ /* float two; two */ /* END DECLARATIONS */ sf_init(argc,argv); /* read inputs from command line */ getinputs(true,&wi); /* compute number of shots */ nsrc = (wi.isxend-wi.isxbeg)/(wi.iskip); nsrc++; /* compute number of spatial grid points */ nxz=wi.nx * wi.nz; /* compute number of traces, samples in each record */ ntr=wi.igxend-wi.igxbeg+1; nsam=ntr*wi.nt; /* allocate, initialize p0, p1, v, traces */ p0=sf_floatalloc(nxz); p1=sf_floatalloc(nxz); v =sf_floatalloc(nxz); tr=sf_floatalloc(nsam); /* read velocity */ sf_floatread(v,nxz,wi.vfile); /* CFL, sanity checks */ vmax=fgetmax(v,nxz); vmin=fgetmin(v,nxz); if (vmax*wi.dt>CFL*fmaxf(wi.dx,wi.dz)) { sf_warning("CFL criterion violated"); sf_warning("vmax=%e dx=%e dz=%e dt=%e\n",vmax,wi.dx,wi.dz,wi.dt); sf_error("max permitted dt=%e\n",CFL*fmaxf(wi.dx,wi.dz)/vmax); } if (vmin<=0.0) sf_error("min velocity nonpositive"); /* only square of velocity array needed from here on */ fsquare(v,nxz); /* precalculate some coefficients */ rz=wi.dt*wi.dt/(wi.dz*wi.dz); rx=wi.dt*wi.dt/(wi.dx*wi.dx); s =2.0*(rz+rx); /* two=2.0; nz=wi.nz; */ /* shot loop */ isrc=0; isx=wi.isxbeg; while (isx <= wi.isxend) { /* initialize pressure fields, traces */ fzeros(p0,nxz); fzeros(p1,nxz); fzeros(tr,nsam); /* initialize movie frame counter */ imf=0; /* time loop */ for (it=0;it<wi.nt;it++) { /* construct next time step, overwrite on p0 */ step_forward(p0,p1,v,wi.nz,wi.nx,rz,rx,s); /* tack on source */ p0[wi.isz+isx*wi.nz]+=fgetrick(it*wi.dt,wi.freq); /* swap pointers */ tmp=p0; p0=p1; p1=tmp; /* store trace samples if necessary */ if (NULL != wi.tfile) for (ix=0;ix<ntr;ix++) tr[ix*wi.nt+it]=p1[(wi.igxbeg+ix)*wi.nz+wi.igz]; /* write movie snap to file if necessary */ if (NULL != wi.mfile && wi.nm && !(it%wi.nm)) { sf_floatwrite(p1,nxz,wi.mfile); imf++; } /* next t */ } /* write traces to file if necessary */ if (NULL != wi.tfile) sf_floatwrite(tr,nsam,wi.tfile); isx += wi.iskip; isrc++; } exit(0); }
int main(int argc, char* argv[]) { int p[4][2], i, im, id, status; unsigned long mseed, dseed; off_t nm, nd, msiz, dsiz; size_t nbuf, mbuf, dbuf; float *buf; double dp; pid_t pid[6]={1,1,1,1,1,1}; sf_file mod=NULL; sf_file dat=NULL; sf_file pip=NULL; sf_init(argc,argv); mod = sf_input("mod"); dat = sf_input("dat"); if (SF_FLOAT != sf_gettype(mod) || SF_FLOAT != sf_gettype(dat)) sf_error("Need float type in mod and dat"); nm = sf_filesize(mod); nd = sf_filesize(dat); nbuf = BUFSIZ/sizeof(float); buf = sf_floatalloc(nbuf); mseed = (unsigned long) time(NULL); init_genrand(mseed); mseed = genrand_int32(); dseed = genrand_int32(); for (i=0; i < argc-1; i++) { argv[i]=argv[i+1]; } argv[argc-1] = sf_charalloc(6); snprintf(argv[argc-1],6,"adj=X"); for (i=0; i < 4; i++) { /* make four pipes */ if (pipe(p[i]) < 0) sf_error("pipe error:"); } for (i=0; i < 6; i++) { /* fork six children */ if ((pid[i] = fork()) < 0) sf_error("fork error:"); if (0 == pid[i]) break; } if (0 == pid[0]) { /* makes random model and writes it to p[0] */ close(p[0][0]); close(STDOUT_FILENO); DUP(p[0][1]); pip = sf_output("out"); sf_fileflush(pip,mod); init_genrand(mseed); for (msiz=nm, mbuf=nbuf; msiz > 0; msiz -= mbuf) { if (msiz < mbuf) mbuf=msiz; sf_random(mbuf,buf); sf_floatwrite(buf,mbuf,pip); } } if (0 == pid[1]) { /* reads from p[0], runs the program, and writes to p[1] */ close(p[0][1]); close(STDIN_FILENO); DUP(p[0][0]); close(p[1][0]); close(STDOUT_FILENO); DUP(p[1][1]); argv[argc-1][4]='0'; execvp(argv[0],argv); _exit(1); } if (0 == pid[2]) { /* reads from p[1] and multiplies it with random data */ close(p[1][1]); close(STDIN_FILENO); DUP(p[1][0]); pip = sf_input("in"); init_genrand(dseed); dp = 0.; for (dsiz=nd, dbuf=nbuf; dsiz > 0; dsiz -= dbuf) { if (dsiz < dbuf) dbuf=dsiz; sf_floatread(buf,dbuf,pip); for (id=0; id < dbuf; id++) { dp += buf[id]*genrand_real1 (); } } sf_warning(" L[m]*d=%g",dp); _exit(2); } if (0 == pid[3]) { /* makes random data and writes it to p[2] */ close(p[2][0]); close(STDOUT_FILENO); DUP(p[2][1]); pip = sf_output("out"); sf_fileflush(pip,dat); init_genrand(dseed); for (dsiz=nd, dbuf=nbuf; dsiz > 0; dsiz -= dbuf) { if (dsiz < dbuf) dbuf=dsiz; sf_random(dbuf,buf); sf_floatwrite(buf,dbuf,pip); } } if (0 == pid[4]) { /* reads from p[2], runs the adjoint, and writes to p[3] */ close(p[2][1]); close(STDIN_FILENO); DUP(p[2][0]); close(p[3][0]); close(STDOUT_FILENO); DUP(p[3][1]); argv[argc-1][4]='1'; execvp(argv[0],argv); _exit(4); } if (0 == pid[5]) { /* reads from p[3] and multiplies it with random model */ close(p[3][1]); close(STDIN_FILENO); DUP(p[3][0]); pip = sf_input("in"); init_genrand(mseed); dp = 0.; for (msiz=nm, mbuf=nbuf; msiz > 0; msiz -= mbuf) { if (msiz < mbuf) mbuf=msiz; sf_floatread(buf,mbuf,pip); for (im=0; im < mbuf; im++) { dp += buf[im]*genrand_real1 (); } } sf_warning("L'[d]*m=%g",dp); _exit(5); } for (i=0; i < 6; i++) { if (0 == pid[i]) break; } if (6==i) { /* parent waits */ waitpid(pid[2],&status,0); waitpid(pid[5],&status,0); exit(0); } }
int main(int argc, char* argv[]) { int nt, nh, ncmp, it, icmp, ih, iw, w, zero, shift; float *indata, *outdata, *stack, *win1, *win2, *outweight; float dt,var, maxwin1, maxwin2, ee, esp, dh, dcmp,cmp0, t0, h0, /* sumab, sumwin1, sumwin2, */ sumweight, sft; sf_file in, out; /* initialization */ sf_init(argc,argv); in = sf_input("in"); out = sf_output("out"); /* get rsf_file parameters */ if (!sf_histint(in,"n1",&nt)) sf_error("Need n1="); if (!sf_histfloat(in,"d1",&dt)) dt=1.; if (!sf_histfloat(in,"o1",&t0)) t0=0.; if (!sf_histint(in,"n2",&nh)) sf_error("Need n2="); if (!sf_histfloat(in,"d2",&dh)) dh=1.; if (!sf_histfloat(in,"o2",&h0)) h0=0.; if (!sf_histint(in,"n3",&ncmp)) ncmp=1; if (!sf_histfloat(in,"d3",&dcmp)) dcmp=1.; if (!sf_histfloat(in,"o3",&cmp0)) cmp0=0.; /* get other parameters */ if (!sf_getint("w",&w)) w=50; /* sliding window size*/ if (!sf_getfloat("sft",&sft)) sft=1; /*weight shift*/ if (!sf_getfloat("ee",&ee)) ee=1.0; if (!sf_getfloat("esp",&esp)) esp=1.0; sf_putint(out,"n1",nt); sf_putint(out,"n2",ncmp); sf_putfloat(out,"d1",dt); sf_putfloat(out,"o1",t0); sf_putfloat(out,"d2",dcmp); sf_putfloat(out,"o2",cmp0); sf_putint(out,"n3",1); indata = sf_floatalloc(nt*nh); outdata = sf_floatalloc(nt); outweight = sf_floatalloc(nt*nh); stack = sf_floatalloc(nt); win1 = sf_floatalloc(w); win2 = sf_floatalloc(w); for (icmp=0; icmp < ncmp; icmp++){ sf_floatread(indata,nt*nh,in); for (it=0; it < nt; it++){ stack[it] = 0; outdata[it] = 0; for (ih=0;ih<nh;ih++){ outweight[nt*ih+it]=0; } } /* computer the directly stack trace */ for (it=0; it < nt; it++){ zero=0; for(ih=0; ih < nh; ih++){ if (indata[ih*nt+it]!=0) zero++; stack[it]+= indata[ih*nt+it]; } if (zero==0) stack[it]=stack[it]; else stack[it]=stack[it]/zero; } /* estimate the noise variances */ for (it=0; it < nt; it++){ zero = 0; sumweight=0; for (ih=0; ih < nh; ih++){ /* sumwin1 = 0; sumwin2 = 0; sumab = 0; */ shift = SF_MAX(0,SF_MIN(nt-w, it-w/2-1)); /* weight=0; */ var=0; maxwin1=0; maxwin2=0; for (iw=0; iw <w; iw++){ win1[iw] = indata[ih*nt+iw+shift]; win2[iw] = stack[iw+shift]; if (fabs(win1[iw])>fabs(maxwin1)) maxwin1 = fabs(win1[iw]); if (fabs(win2[iw])>fabs(maxwin2)) maxwin2 = fabs(win2[iw]); } for (iw=0; iw <w; iw++){ var += fabs(win1[iw]/maxwin1-win2[iw]/maxwin2)*fabs(win1[iw]/maxwin1-win2[iw]/maxwin2); } outweight[nt*ih+it] =1./(var+ee); if (indata[ih*nt+it]!=0){ zero++; outdata[it] += pow(1./(var+ee),1)*indata[ih*nt+it]; sumweight += pow(1./(var+ee),1); } } if (zero==0) outdata[it]=0; else outdata[it] = outdata[it]/(zero*sumweight+esp); } sf_floatwrite(outdata,nt,out); sf_warning("running cmp is = %d of %d",icmp, ncmp); } exit(0); }
int main (int argc, char *argv[]) { int ir, nr, n1,n2,n3, m1, m2, m3, n12, nw, nj1, i3; float *u1, *u2, *p; sf_file in, out, dip; bool verb; allpass ap; sf_init(argc,argv); in = sf_input ("in"); dip = sf_input ("dip"); out = sf_output ("out"); if (SF_FLOAT != sf_gettype(in) || SF_FLOAT != sf_gettype(dip)) sf_error("Need float type"); if (!sf_histint(in,"n1",&n1)) sf_error("Need n1= in input"); if (!sf_histint(in,"n2",&n2)) n2=1; if (!sf_histint(in,"n3",&n3)) n3=1; n12 = n1*n2; nr = sf_leftsize(in,2); if (!sf_histint(dip,"n1",&m1) || m1 != n1) sf_error("Need n1=%d in dip",n1); if (1 != n2 && (!sf_histint(dip,"n2",&m2) || m2 != n2)) sf_error("Need n2=%d in dip",n2); if (1 != n3 && (!sf_histint(dip,"n3",&m3) || m3 != n3)) sf_error("Need n3=%d in dip",n3); if (!sf_getint("order",&nw)) nw=1; /* accuracy */ if (!sf_getbool("verb",&verb)) verb = false; /* verbosity flag */ if (!sf_getint("nj1",&nj1)) nj1=1; /* aliasing */ n3 = 1; for (ir=0; ir < nr; ir++) { if (verb) sf_warning("slice %d of %d", ir+1, nr); u1 = sf_floatalloc(n12); u2 = sf_floatalloc(n12); p = sf_floatalloc(n12); for (i3=0; i3 < n3; i3++) { /* read data */ sf_floatread(u1,n12,in); /* read t-x dip */ sf_floatread(p,n12,dip); ap = allpass_init (nw,nj1,n1,n2,1,p); /* apply */ allpass1(false, false, ap, u1, u2); /* write t-x destruction */ sf_floatwrite(u2,n12,out); } free(u1); free(u2); free(p); } exit (0); }
int main(int argc, char* argv[]) { int nz,nx, iz,ix, order; bool vel; float x1,x2,z1,z2,v1,v2,x0,dx,z0,dz,fx,fz; float **slow, *time, g1[2],g2[2],p1[2],p2[2]; sf_eno2 cvel; sf_file in, out; sf_init(argc,argv); in = sf_input("in"); /* velocity or slowness */ out = sf_output("out"); /* traveltime */ if (!sf_histint(in,"n1",&nz)) sf_error("No n1= in input"); if (!sf_histint(in,"n2",&nx)) sf_error("No n2= in input"); if (!sf_histfloat(in,"d1",&dz)) sf_error("No d1= in input"); if (!sf_histfloat(in,"d2",&dx)) sf_error("No d2= in input"); if (!sf_histfloat(in,"o1",&z0)) sf_error("No o1= in input"); if (!sf_histfloat(in,"o2",&x0)) sf_error("No o2= in input"); if(!sf_getbool("vel",&vel)) vel=true; /* y, input is velocity; n, slowness */ if(!sf_getint("order",&order)) order=3; /* interpolation accuracy for velocity */ if (!sf_getfloat("yshot",&x1)) x1=x0 + 0.5*(nx-1)*dx; if (!sf_getfloat("zshot",&z1)) z1=z0; /* read velocity or slowness */ slow = sf_floatalloc2(nz,nx); sf_floatread(slow[0],nz*nx,in); /* convert to slowness squared */ for(ix = 0; ix < nx; ix++){ for (iz = 0; iz < nz; iz++) { v1 = slow[ix][iz]; v1 *= v1; slow[ix][iz] = vel? 1/v1:v1; } } cvel = sf_eno2_init (order, nz, nx); sf_eno2_set (cvel, slow); time = sf_floatalloc(nz); fx = (x1-x0)/dx; ix = floorf(fx); fx -= ix; fz = (z1-z0)/dz; iz = floorf(fz); fz -= iz; sf_eno2_apply(cvel,iz,ix,fz,fx,&v1,g1,BOTH); g1[1] /= dx; g1[0] /= dz; for(ix = 0; ix < nx; ix++){ x2 = x0+ix*dx; for (iz = 0; iz < nz; iz++) { z2 = z0+iz*dz; sf_eno2_apply(cvel,iz,ix,0.,0.,&v2,g2,BOTH); g2[1] /= dx; g2[0] /= dz; time[iz] = analytical(x1,z1,v1,g1,p1, x2,z2,v2,g2,p2); } sf_floatwrite(time,nz,out); } exit(0); }
int main(int argc, char* argv[]) { bool verb; sf_file Fu,Fw; /* I/O files */ sf_axis a1,a2,a3; /* cube axes */ float ***uu=NULL, ***ww=NULL; int *ii,ik; int nh1,nh2,nh3; int nb1,nb2,nb3; int ih1,ih2,ih3; int ib1,ib2,ib3; int n3; int i3; int j1, j2, j3; int k1, k2, k3; int ompchunk; int lo1,hi1; int lo2,hi2; int lo3,hi3; /*------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); if(! sf_getint("ompchunk",&ompchunk)) ompchunk=1; /* OpenMP data chunk size */ if(! sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ Fu = sf_input ("in" ); /* input field */ Fw = sf_output("out"); /* wigner distribution */ /* read axes */ a1=sf_iaxa(Fu,1); sf_setlabel(a1,"a1"); if(verb) sf_raxa(a1); a2=sf_iaxa(Fu,2); sf_setlabel(a2,"a2"); if(verb) sf_raxa(a2); a3=sf_iaxa(Fu,3); sf_setlabel(a3,"a3"); if(verb) sf_raxa(a3); n3 = sf_n(a3); if(! sf_getint("nh1",&nh1)) nh1=0; if(! sf_getint("nh2",&nh2)) nh2=0; if(! sf_getint("nh3",&nh3)) nh3=0; if(n3<=1) nh3=0; if(verb) sf_warning("nh1=%d nh2=%d nh3=%d",2*nh1+1,2*nh2+1,2*nh3+1); nb1 = sf_n(a1); nb2 = sf_n(a2); nb3=2*nh3+1; uu=sf_floatalloc3(nb1,nb2,nb3); ww=sf_floatalloc3(nb1,nb2,nb3); ii = sf_intalloc(nb3); for(ib3=0;ib3<nb3;ib3++) { ii[ib3]=ib3; } /*------------------------------------------------------------*/ /* low end on axis 3 */ /*------------------------------------------------------------*/ for( ib3=0; ib3<nb3; ib3++) { for( ib2=0; ib2<nb2; ib2++) { for( ib1=0; ib1<nb1; ib1++) { ww[ib3][ib2][ib1] = 0.; } } } sf_floatread(uu[0][0],nb1*nb2*nb3,Fu); for( ih3=-nh3; ih3<nh3+1; ih3++) { lo3=SF_ABS(ih3); hi3=nb3-lo3; for( ih2=-nh2; ih2<nh2+1; ih2++) { lo2=SF_ABS(ih2); hi2=nb2-lo2; for(ih1=-nh1; ih1<nh1+1; ih1++) { lo1=SF_ABS(ih1); hi1=nb1-lo1; for( ib3=lo3; ib3<nh3+1;ib3++) { j3=ii[ib3-ih3]; k3=ii[ib3+ih3]; #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) \ private(ib1,ib2,j2,j1,k2,k1) \ shared(ib3,j3,k3,ih2,ih1,lo2,hi2,lo1,hi1,uu,ww) #endif for( ib2=lo2; ib2<hi2; ib2++) { j2=ib2-ih2; k2=ib2+ih2; for(ib1=lo1; ib1<hi1; ib1++) { j1=ib1-ih1; k1=ib1+ih1; ww[ib3][ib2][ib1] += uu[j3][j2][j1] * uu[k3][k2][k1]; } /* nb1 */ } /* nb2 */ } /* nb3 */ } /* nh1 */ } /* nh2 */ } /* nh3 */ for(ih3=0;ih3<nh3+1;ih3++) { sf_floatwrite(ww[ih3][0],nb1*nb2,Fw); } /*------------------------------------------------------------*/ /* loop on axis 3 */ /*------------------------------------------------------------*/ if(verb) fprintf(stderr," n3\n"); if(verb) fprintf(stderr,"%5d\n",n3-1); for(i3=nh3+1;i3<n3-nh3;i3++) { if(verb) fprintf(stderr,"%5d",i3); /* zero WDF */ ib3=nh3; for( ib2=0; ib2<nb2; ib2++) { for( ib1=0; ib1<nb1; ib1++) { ww[ib3][ib2][ib1] = 0.; } } /* circulate index to slices */ ik = ii[0]; for(ib3=0;ib3<nb3-1;ib3++) { ii[ib3]=ii[ib3+1]; } ii[nb3-1]=ik; /* read new slice */ sf_floatread(uu[ ii[nb3-1] ][0],nb1*nb2,Fu); for( ih3=-nh3; ih3<nh3+1; ih3++) { for( ih2=-nh2; ih2<nh2+1; ih2++) { lo2=SF_ABS(ih2); hi2=nb2-lo2; for(ih1=-nh1; ih1<nh1+1; ih1++) { lo1=SF_ABS(ih1); hi1=nb1-lo1; ib3=nh3; j3=ii[ib3-ih3]; k3=ii[ib3+ih3]; #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) \ private(ib1,ib2,j2,j1,k2,k1) \ shared(ib3,j3,k3,ih2,ih1,lo2,hi2,lo1,hi1,uu,ww) #endif for( ib2=lo2; ib2<hi2; ib2++) { j2=ib2-ih2; k2=ib2+ih2; for(ib1=lo1; ib1<hi1; ib1++) { j1=ib1-ih1; k1=ib1+ih1; ww[ib3][ib2][ib1] += uu[j3][j2][j1] * uu[k3][k2][k1]; } /* nb1 */ } /* nb2 */ } /* nh1 */ } /* nh2 */ } /* nh3 */ sf_floatwrite(ww[nh3][0],nb1*nb2,Fw); if(verb) fprintf(stderr,"\b\b\b\b\b"); } /*------------------------------------------------------------*/ /* high-end on axis 3*/ /*------------------------------------------------------------*/ for( ih3=-nh3; ih3<nh3+1; ih3++) { lo3=SF_ABS(ih3); hi3=nb3-lo3; for( ih2=-nh2; ih2<nh2+1; ih2++) { lo2=SF_ABS(ih2); hi2=nb2-lo2; for(ih1=-nh1; ih1<nh1+1; ih1++) { lo1=SF_ABS(ih1); hi1=nb1-lo1; for( ib3=nh3+1; ib3<hi3; ib3++) { j3=ii[ib3-ih3]; k3=ii[ib3+ih3]; #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) \ private(ib1,ib2,j2,j1,k2,k1) \ shared(ib3,j3,k3,ih2,ih1,lo2,hi2,lo1,hi1,uu,ww) #endif for( ib2=lo2; ib2<hi2; ib2++) { j2=ib2-ih2; k2=ib2+ih2; for(ib1=lo1; ib1<hi1; ib1++) { j1=ib1-ih1; k1=ib1+ih1; ww[ib3][ib2][ib1] += uu[j3][j2][j1] * uu[k3][k2][k1]; } /* nb1 */ } /* nb2 */ } /* nb3 */ } /* nh1 */ } /* nh2 */ } /* nh3 */ for(ih3=nh3+1;ih3<2*nh3+1;ih3++) { sf_floatwrite(ww[ih3][0],nb1*nb2,Fw); } /*------------------------------------------------------------*/ exit (0); }
int main(int argc, char* argv[]) { int i1, n1, i2, n2, ia, na, n; float *trace, *hilbt, *phase, **rotat, a, a0, da, c, deg2rad; sf_file inp, pha, out; sf_init(argc,argv); inp = sf_input("in"); pha = sf_input("phase"); out = sf_output("out"); if (!sf_histint(inp,"n1",&n1)) sf_error("No n1= in input"); n2 = sf_leftsize(inp,1); if (!sf_getint("na",&na)) na=721; /* number of angles */ if (!sf_getfloat("da",&da)) da=1.0; /* angle increment */ if (!sf_getfloat("a0",&a0)) a0=-360.; /* first angle */ /* convert to radians */ deg2rad = SF_PI/180.; trace = sf_floatalloc(n1); hilbt = sf_floatalloc(n1); phase = sf_floatalloc(n1); rotat = sf_floatalloc2(n1,na); if (!sf_getint("order",&n)) n=100; /* Hilbert transformer order */ if (!sf_getfloat("ref",&c)) c=1.; /* Hilbert transformer reference (0.5 < ref <= 1) */ sf_hilbert_init(n1, n, c); for (i2=0; i2 < n2; i2++) { sf_floatread(trace,n1,inp); sf_hilbert(trace,hilbt); /* loop over angles */ for (ia=0; ia < na; ia++) { a = deg2rad*(a0 + ia*da); for (i1=0; i1 < n1; i1++) { rotat[ia][i1] = trace[i1]*cosf(a) + hilbt[i1]*sinf(a); } } sf_floatread(phase,n1,pha); /* linear interpolation */ for (i1=0; i1 < n1; i1++) { a = (phase[i1]-a0)/da; ia = floorf(a); a -= ia; if (ia >=0 && ia < na-1) { trace[i1] = a * rotat[ia+1][i1] + (1.-a) * rotat[ia][i1]; } else { trace[i1] = 0.; } } sf_floatwrite(trace,n1,out); } exit(0); }
int main(int argc,char **argv) { int isx,isy,isz,bd; int i,j,k,im,jm,it; int nth, rank; float t; float fx,fy,fz,dt2; float ***c11, ***c22, ***c33, ***c12, ***c13, ***c23, ***c44, ***c55, ***c66; float ***phaix, ***phaiy, ***phaiz; sf_init(argc,argv); sf_file Fo1, Fo2, Fo3; float f0=40; // main frequency of the wavelet(usually 30Hz) float t0=0.04; // time delay of the wavelet(if f0=30Hz, t0=0.04s)*/ float A=1.0; // the amplitude of wavelet clock_t t1, t2, t3; float timespent; t1=clock(); /* time samping paramter */ if (!sf_getint("nt",&nt)) nt=301; if (!sf_getfloat("dt",&dt)) dt=0.001; if (!sf_getint("bd",&bd)) bd=20; sf_warning("nt=%d dt=%f",nt,dt); /* setup I/O files */ sf_file Fc11, Fc22, Fc33, Fc12, Fc13, Fc23, Fc44, Fc55, Fc66; sf_file Fphiz, Fphiy, Fphix; Fc11 = sf_input ("c11"); /* c11 using standard input */ Fc22 = sf_input ("c22"); /* c22 */ Fc33 = sf_input ("c33"); /* c33 */ Fc12 = sf_input ("c12"); /* c12 */ Fc13 = sf_input ("c13"); /* c13 */ Fc23 = sf_input ("c23"); /* c23 */ Fc44 = sf_input ("c44"); /* c44 */ Fc55 = sf_input ("c55"); /* c55 */ Fc66 = sf_input ("c66"); /* c66 */ Fphix = sf_input ("phix"); /* phix x ccw*/ Fphiy = sf_input ("phiy"); /* phiy y ccw*/ Fphiz = sf_input ("phiz"); /* phiz z ccw */ /* Read/Write axes */ sf_axis az, ax, ay; az = sf_iaxa(Fc11,1); nz = sf_n(az); dz = sf_d(az)*1000.0; ax = sf_iaxa(Fc11,2); nx = sf_n(ax); dx = sf_d(ax)*1000.0; ay = sf_iaxa(Fc11,3); ny = sf_n(ay); dy = sf_d(ay)*1000.0; fy=sf_o(ay)*1000.0; fx=sf_o(ax)*1000.0; fz=sf_o(az)*1000.0; int nxpad, nypad, nzpad; nxpad=nx+2*bd; nypad=ny+2*bd; nzpad=nz+2*bd; sf_warning("nxpad=%d nypad=%d nzpad=%d ",nxpad,nypad,nzpad); sf_warning("dx=%f dy=%f dz=%f ",dx,dy,dz); c11=sf_floatalloc3(nzpad,nxpad,nypad); c22=sf_floatalloc3(nzpad,nxpad,nypad); c33=sf_floatalloc3(nzpad,nxpad,nypad); c12=sf_floatalloc3(nzpad,nxpad,nypad); c13=sf_floatalloc3(nzpad,nxpad,nypad); c23=sf_floatalloc3(nzpad,nxpad,nypad); c44=sf_floatalloc3(nzpad,nxpad,nypad); c55=sf_floatalloc3(nzpad,nxpad,nypad); c66=sf_floatalloc3(nzpad,nxpad,nypad); phaix=sf_floatalloc3(nzpad,nxpad,nypad); phaiy=sf_floatalloc3(nzpad,nxpad,nypad); phaiz=sf_floatalloc3(nzpad,nxpad,nypad); /* read velocity model */ for(i=bd;i<nypad-bd;i++) for(j=bd;j<nxpad-bd;j++){ sf_floatread(&c11[i][j][bd],nz,Fc11); sf_floatread(&c22[i][j][bd],nz,Fc22); sf_floatread(&c33[i][j][bd],nz,Fc33); sf_floatread(&c12[i][j][bd],nz,Fc12); sf_floatread(&c13[i][j][bd],nz,Fc13); sf_floatread(&c23[i][j][bd],nz,Fc23); sf_floatread(&c44[i][j][bd],nz,Fc44); sf_floatread(&c55[i][j][bd],nz,Fc55); sf_floatread(&c66[i][j][bd],nz,Fc66); sf_floatread(&phaix[i][j][bd],nz,Fphix); sf_floatread(&phaiy[i][j][bd],nz,Fphiy); sf_floatread(&phaiz[i][j][bd],nz,Fphiz); } vmodelboundary3d(c11, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(c22, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(c33, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(c12, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(c13, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(c23, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(c44, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(c55, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(c66, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(phaix, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(phaiy, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(phaiz, nx, ny, nz, nxpad, nypad, nzpad, bd); for(i=0;i<nypad;i++) for(j=0;j<nxpad;j++) for(k=0;k<nzpad;k++){ phaix[i][j][k] *= SF_PI/180.0; phaiy[i][j][k] *= SF_PI/180.0; phaiz[i][j][k] *= SF_PI/180.0; } sf_warning("Read velocity model parameters ok !"); int mm=2*_m+1; int mmix=2*_mix+1; sf_warning("m=%d mix=%d",_m,_mix); float *coeff_2dx,*coeff_2dy,*coeff_2dz,*coeff_1dx,*coeff_1dy,*coeff_1dz; coeff_2dy=sf_floatalloc(mm); coeff_2dx=sf_floatalloc(mm); coeff_2dz=sf_floatalloc(mm); coeff_1dy=sf_floatalloc(mmix); coeff_1dx=sf_floatalloc(mmix); coeff_1dz=sf_floatalloc(mmix); coeff2d(coeff_2dx,dx); coeff2d(coeff_2dy,dy); coeff2d(coeff_2dz,dz); coeff1dmix(coeff_1dx, dx); coeff1dmix(coeff_1dy, dy); coeff1dmix(coeff_1dz, dz); float*** p1=sf_floatalloc3(nzpad,nxpad,nypad); float*** p2=sf_floatalloc3(nzpad,nxpad,nypad); float*** p3=sf_floatalloc3(nzpad,nxpad,nypad); zero3float(p1,nzpad,nxpad,nypad); zero3float(p2,nzpad,nxpad,nypad); zero3float(p3,nzpad,nxpad,nypad); float*** q1=sf_floatalloc3(nzpad,nxpad,nypad); float*** q2=sf_floatalloc3(nzpad,nxpad,nypad); float*** q3=sf_floatalloc3(nzpad,nxpad,nypad); zero3float(q1,nzpad,nxpad,nypad); zero3float(q2,nzpad,nxpad,nypad); zero3float(q3,nzpad,nxpad,nypad); float*** r1=sf_floatalloc3(nzpad,nxpad,nypad); float*** r2=sf_floatalloc3(nzpad,nxpad,nypad); float*** r3=sf_floatalloc3(nzpad,nxpad,nypad); zero3float(r1,nzpad,nxpad,nypad); zero3float(r2,nzpad,nxpad,nypad); zero3float(r3,nzpad,nxpad,nypad); t2=clock(); /* setup I/O files */ Fo1 = sf_output("out"); /* original elasticwave iLine x-component */ Fo2 = sf_output("Elasticy"); /* original elasticwave iLine y-component */ Fo3 = sf_output("Elasticz"); /* original elasticwave xLine z-component */ puthead3x(Fo1, nz, nx, ny, dz/1000.0, dx/1000.0, dy/1000.0, 0.0, 0.0, 0.0); puthead3x(Fo2, nz, nx, ny, dz/1000.0, dx/1000.0, dy/1000.0, 0.0, 0.0, 0.0); puthead3x(Fo3, nz, nx, ny, dz/1000.0, dx/1000.0, dy/1000.0, 0.0, 0.0, 0.0); /* source definition */ isy=nypad/2; isx=nxpad/2; isz=nzpad/2; dt2=dt*dt; #ifdef _OPENMP #pragma omp parallel { nth = omp_get_num_threads(); rank = omp_get_thread_num(); sf_warning("Using %d threads, this is %dth thread",nth, rank); } #endif float*** px_tmp=sf_floatalloc3(nzpad,nxpad,nypad); float*** pz_tmp=sf_floatalloc3(nzpad,nxpad,nypad); float*** qx_tmp=sf_floatalloc3(nzpad,nxpad,nypad); float*** qz_tmp=sf_floatalloc3(nzpad,nxpad,nypad); float*** rx_tmp=sf_floatalloc3(nzpad,nxpad,nypad); float*** rz_tmp=sf_floatalloc3(nzpad,nxpad,nypad); /*********the kernel calculation ************/ for(it=0;it<nt;it++) { t=it*dt; /* source Type 0: oriented 45 degree to vertical and 45 degree azimuth: Yan & Sava (2012) */ p2[isy][isx][isz]+=Ricker(t, f0, t0, A); // x-component q2[isy][isx][isz]+=Ricker(t, f0, t0, A); // y-component r2[isy][isx][isz]+=Ricker(t, f0, t0, A); // z-component // 3D exploding force source (e.g., Wu's PhD /* for(k=-1;k<=1;k++)*/ /* for(i=-1;i<=1;i++)*/ /* for(j=-1;j<=1;j++)*/ /* {*/ /* if(fabs(i)+fabs(j)+fabs(k)==3)*/ /* {*/ /* p2[isy+k][isx+i][isz+j]+=i*Ricker(t, f0, t0, A); // x-component*/ /* q2[isy+k][isx+i][isz+j]+=k*Ricker(t, f0, t0, A); // y-component*/ /* r2[isy+k][isx+i][isz+j]+=j*Ricker(t, f0, t0, A); // z-component*/ /* }*/ /* }*/ fwportelastic3d(dt2,p1,p2,p3,q1,q2,q3,r1,r2,r3, px_tmp,pz_tmp, qx_tmp,qz_tmp, rx_tmp,rz_tmp, coeff_2dx,coeff_2dy,coeff_2dz, coeff_1dx,coeff_1dy,coeff_1dz, dx,dy,dz,nxpad,nypad,nzpad, c11,c22,c33,c12,c13,c23,c44,c55,c66,phaix,phaiy,phaiz); if(it==nt-1) // output snapshot { // output iLine for(i=0;i<ny;i++) { im=i+bd; for(j=0;j<nx;j++) { jm=j+bd; sf_floatwrite(&p3[im][jm][bd],nz,Fo1); sf_floatwrite(&q3[im][jm][bd],nz,Fo2); sf_floatwrite(&r3[im][jm][bd],nz,Fo3); } } } for(i=0;i<nypad;i++) for(j=0;j<nxpad;j++) for(k=0;k<nzpad;k++) { p1[i][j][k]=p2[i][j][k]; p2[i][j][k]=p3[i][j][k]; q1[i][j][k]=q2[i][j][k]; q2[i][j][k]=q3[i][j][k]; r1[i][j][k]=r2[i][j][k]; r2[i][j][k]=r3[i][j][k]; } sf_warning("forward propagation... it= %d t=%f",it,t); } printf("ok3\n"); t3=clock(); timespent=(float)(t3-t2)/CLOCKS_PER_SEC; sf_warning("CPU time for 3D ORT elastic modeling: %f(second)",timespent); free(**p1); free(**p2); free(**p3); free(**q1); free(**q2); free(**q3); free(**r1); free(**r2); free(**r3); free(**px_tmp); free(**qx_tmp); free(**rx_tmp); free(**pz_tmp); free(**qz_tmp); free(**rz_tmp); free(**c11); free(**c33); free(**c13); free(**c55); free(**c66); free(**phaiz); free(**phaiy); free(**phaix); return 0; }
int main(int argc, char* argv[]) { bool verb; /* verbosity flag */ float clip; /* threshold (clip value) */ sf_file Fc; /* cube file */ sf_file Fl; /* list file */ extern int fseeko(FILE *stream, off_t offset, int whence); sf_axis ax,ay,az; sf_axis aa; int ix,iy,iz; int nx,ny,nz,nj,na; int nk=0,jk; float **cube; float dx,dy,dz; float x0,y0,z0; FILE* tfile; char* tname; float t2[3],t3[4]; /*------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); if(! sf_getbool("verb",&verb)) verb=false; if(! sf_getfloat("clip",&clip)) clip=0; Fc = sf_input ( "in"); /* input cube */ Fl = sf_output("out"); /* output list */ /* read axes*/ az=sf_iaxa(Fc,1); sf_setlabel(az,"z"); ax=sf_iaxa(Fc,2); sf_setlabel(ax,"x"); ay=sf_iaxa(Fc,3); sf_setlabel(ay,"y"); nz=sf_n(az); z0=sf_o(az); dz=sf_d(az); nx=sf_n(ax); x0=sf_o(ax); dx=sf_d(ax); ny=sf_n(ay); y0=sf_o(ay); dy=sf_d(ay); na=0; if(ny>1) { if(verb) sf_warning("initiating 3D points"); nj=4; } else { if(verb) sf_warning("initiating 2D points"); nj=3; } /*------------------------------------------------------------*/ cube = sf_floatalloc2(nz,nx); tfile = sf_tempfile(&(tname), "w+b"); for (iy=0; iy<ny; iy++) { /* if(verb) sf_warning("iy=%d",iy);*/ sf_floatread(cube[0],nz*nx,Fc); nk=0; for (ix=0; ix<nx; ix++) { for (iz=0; iz<nz; iz++) { if( fabs(cube[ix][iz]) > clip) { nk++; } } } if(ny>1) { jk=0; for (ix=0; ix<nx; ix++) { for (iz=0; iz<nz; iz++) { if( fabs(cube[ix][iz]) > clip) { t3[0] = x0 + ix * dx; t3[1] = y0 + iy * dy; t3[2] = z0 + iz * dz; t3[3] = cube[ix][iz]; fseeko(tfile,jk*4*sizeof(float),SEEK_SET); fwrite( t3, sizeof(float),4,tfile); jk++; } } } } else { jk=0; for (ix=0; ix<nx; ix++) { for (iz=0; iz<nz; iz++) { if( fabs(cube[ix][iz]) > clip) { t2[0] = x0 + ix * dx; t2[1] = z0 + iz * dz; t2[2] = cube[ix][iz]; fseeko(tfile,jk*3*sizeof(float),SEEK_SET); fwrite( t2, sizeof(float),3,tfile); jk++; } } } } /* else ny=1 */ na += nk; } /* iy */ /* output axes */ aa = sf_maxa(nj,0,1); sf_oaxa(Fl,aa,1); if(verb) sf_raxa(aa); free(aa); aa = sf_maxa(na,0,1); sf_oaxa(Fl,aa,2); if(verb) sf_raxa(aa); free(aa); if( ny>1) { for( jk=0; jk<nk; jk++) { fseeko(tfile,jk*4*sizeof(float),SEEK_SET); fread( t3, sizeof(float),4,tfile); /* if(verb) sf_warning("%d, %g %g %g %g",jk,t3[0],t3[1],t3[2],t3[3]);*/ sf_floatwrite(t3,4,Fl); } } else { for( jk=0; jk<nk; jk++) { fseeko(tfile,jk*3*sizeof(float),SEEK_SET); fread( t2, sizeof(float),3,tfile); /* if(verb) sf_warning("%d, %g %g %g",jk,t2[0],t2[1],t2[2]);*/ sf_floatwrite(t2,3,Fl); } } free(cube); unlink(tname); exit (0); }
int main(int argc, char* argv[]) { int n123, n1, i, ik, dim, nk, nf, sf, niter, nw; int n[SF_MAX_DIM], w[SF_MAX_DIM], k[SF_MAX_DIM]; int sa[SF_MAX_DIM], na[SF_MAX_DIM], sc[SF_MAX_DIM], nc[SF_MAX_DIM]; int ma[SF_MAX_DIM], mc[SF_MAX_DIM]; float *data, *wind, *sign, eps, di, dabs; char varname[6], *lagfile; sf_filter saa, naa, sbb, nbb, scc, ncc; sf_file dat, signal, spef, npef, slag, nlag; sf_init (argc,argv); dat = sf_input("in"); signal = sf_output("out"); spef = sf_input("sfilt"); npef = sf_input("nfilt"); n123 = sf_filesize(dat); if (!sf_histint(spef,"dim",&dim)) sf_error("No dim= in sfilt"); n1 = 1; for (i=0; i < dim; i++) { sprintf(varname,"n%d",i+1); if (!sf_histint(dat,varname,n+i)) sf_error("No %s= in input",varname); n1 *= n[i]; } if (!sf_histints(spef,"w",w,dim)) sf_error("No w= in sfilt"); if (!sf_histints(spef,"k",k,dim)) sf_error("No k= in sfilt"); if (!sf_histints(spef,"a",sa,dim)) sf_error("No a= in sfilt"); if (!sf_histints(npef,"a",na,dim)) sf_error("No a= in nfilt"); if (!sf_histints(spef,"center",sc,dim)) sf_error("No center= in sfilt"); if (!sf_histints(npef,"center",nc,dim)) sf_error("No center= in nfilt"); nk=nw=1; for (i=0; i < dim; i++) { nw *= w[i]; nk *= k[i]; } if (!sf_histint(spef,"n1",&sf)) sf_error("No n1= in sfilt"); if (!sf_histint(npef,"n1",&nf)) sf_error("No n1= in nfilt"); sbb = sf_allocatehelix(sf); nbb = sf_allocatehelix(nf); if (NULL == (lagfile = sf_histstring(spef,"lag")) && NULL == (lagfile = sf_getstring("slag"))) sf_error("Need slag="); slag = sf_input(lagfile); if (NULL == (lagfile = sf_histstring(npef,"lag")) && NULL == (lagfile = sf_getstring("nlag"))) sf_error("Need nlag="); nlag = sf_input(lagfile); sf_intread(sbb->lag,sf,slag); sf_intread(nbb->lag,nf,nlag); if (!sf_getfloat("eps",&eps)) sf_error("Need eps="); /* regularization parameter */ if (!sf_getint("niter",&niter)) niter=20; /* number of iterations */ data = sf_floatalloc(n123); sign = sf_floatalloc(n123); sf_floatread(data,n123,dat); dabs = fabsf(data[0]); for (i=1; i < n123; i++) { di = fabsf(data[i]); if (di > dabs) dabs=di; } for (i=0; i < n123; i++) { data[i] /= dabs; } saa = (sf_filter) sf_alloc(nk,sizeof(*saa)); naa = (sf_filter) sf_alloc(nk,sizeof(*naa)); for (ik=0; ik < nk; ik++) { scc = saa+ik; ncc = naa+ik; scc->nh = sf; ncc->nh = nf; scc->flt = sf_floatalloc(sf); ncc->flt = sf_floatalloc(nf); scc->lag = sbb->lag; ncc->lag = nbb->lag; scc->mis = NULL; ncc->mis = NULL; } wind = sf_floatalloc(nw); for (i=0; i < dim; i++) { mc[i] = SF_MIN(sc[i],nc[i]); ma[i] = SF_MIN(sa[i],na[i]); } tent (dim, w, mc, ma, wind); for (i=0; i < n123-n1+1; i += n1) { signoi_init (naa, saa, niter, nw, eps, false); for (ik=0; ik < nk; ik++) { sf_floatread((naa+ik)->flt,nf,npef); sf_floatread((saa+ik)->flt,sf,spef); } patching (signoi_lop, data+i, sign+i, dim, k, n, w, wind); } sf_floatwrite (sign,n123,signal); exit(0); }
int main(int argc, char* argv[]) { map4 mo; bool inv; int n1, i2, n2, i3, n3; float o1, d1, o2, d2, eps, t, t0; float *trace, *t2, *trace2; sf_file in, out; sf_init(argc,argv); in = sf_input("in"); out = sf_output("out"); if (!sf_getbool("inv",&inv)) inv=false; /* inversion flag */ if (inv) { if (!sf_histint(in,"n1",&n2)) sf_error("No n1= in input"); if (!sf_histfloat(in,"d1",&d2)) d2=1.; if (!sf_histfloat(in,"o1",&o2)) o2=0.; if (!sf_histint(in,"n1_logwarp",&n1)) n1=n2; if (!sf_getfloat("t0",&t0) && !sf_histfloat(in,"t0_logwarp",&t0)) sf_error("Need t0="); o1 = t0*expf(o2); d1 = o2+(n2-1)*d2; d1 = (t0*expf(d1)-o1)/(n1-1); 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_getint("pad",&n2)) n2=n1; /* output time samples */ if (!sf_histfloat(in,"d1",&d1)) d1=1.; if (!sf_histfloat(in,"o1",&o1)) o1=0.; if (!sf_getfloat("t0",&t0)) t0=o1; sf_putfloat(out,"t0_logwarp",t0); o2 = logf(o1/t0); d2 = o1+(n1-1)*d1; d2 = (logf(d2/t0) - o2)/(n2-1); sf_putint(out,"n1",n2); sf_putfloat(out,"d1",d2); sf_putfloat(out,"o1",o2); sf_putint(out,"n1_t2warp",n1); } n3 = sf_leftsize(in,1); if (!sf_getfloat("eps",&eps)) eps=0.01; /* stretch regularization */ trace = sf_floatalloc(n2); t2 = sf_floatalloc(n2); trace2 = sf_floatalloc(n1); mo = stretch4_init (n1, o1, d1, n2, eps); for (i2=0; i2 < n2; i2++) { t = o2+i2*d2; t2[i2] = t0*expf(t); } stretch4_define (mo,t2); for (i3=0; i3 < n3; i3++) { if (inv) { sf_floatread(trace,n2,in); stretch4_apply (false,mo,trace,trace2); sf_floatwrite (trace2,n1,out); } else { sf_floatread(trace2,n1,in); stretch4_invert (false,mo,trace,trace2); sf_floatwrite (trace,n2,out); } } exit(0); }
int main(int argc, char* argv[]) { int n1, n2, n3, gainstep, panel, it, nreserve, i1, i2, i3, j, orient; float o1, o2, o3, d1, d2, d3, gpow, clip, pclip, phalf, bias=0., minmax[2]; float pbias, gain=0., x1, y1, x2, y2, **data=NULL, f, barmin, barmax, dat; bool transp, yreverse, xreverse, allpos, polarity, symcp, verb; bool eclip=false, egpow=false, barreverse, mean=false; bool scalebar, nomin=true, nomax=true, framenum, sfbyte, sfbar, charin; char *gainpanel, *color, *barfile; unsigned char tbl[TSIZE+1], **buf, tmp, *barbuf[1]; enum {GAIN_EACH=-3,GAIN_ALL=-2,NO_GAIN=-1}; off_t pos; sf_file in, out=NULL, bar=NULL; sf_init(argc,argv); in = sf_input("in"); sfbyte = (bool) (NULL != strstr (sf_getprog(),"byte")); sfbar = (bool) (NULL != strstr (sf_getprog(),"bar")); if (sfbyte) { out = sf_output("out"); sf_settype(out,SF_UCHAR); } else if (sfbar) { bar = sf_output("out"); sf_settype(bar,SF_UCHAR); } else { vp_init(); } charin = (bool) (SF_UCHAR == sf_gettype(in)); if (charin && sfbyte) sf_error("Cannot input uchar to byte"); if (!charin && SF_FLOAT != sf_gettype(in)) sf_error("Need float input"); if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(in,"n2",&n2)) n2=1; n3 = sf_leftsize(in,2); if (!sf_histfloat(in,"o1",&o1)) o1=0.; if (!sf_histfloat(in,"o2",&o2)) o2=0.; if (!sf_histfloat(in,"o3",&o3)) o3=0.; if (!sf_histfloat(in,"d1",&d1)) d1=1.; if (!sf_histfloat(in,"d2",&d2)) d2=1.; if (!sf_histfloat(in,"d3",&d3)) d3=1.; if (!sf_getbool("transp",&transp)) transp=true; /* if y, transpose the display axes */ if (!sf_getbool("yreverse",&yreverse)) yreverse=true; /* if y, reverse the vertical axis */ if (!sf_getbool("xreverse",&xreverse)) xreverse=false; /* if y, reverse the horizontal axis */ if (transp) { orient = 3; } else { orient = (xreverse==yreverse)? 0:2; } if (!charin) { panel = NO_GAIN; /* no need for gain */ phalf=85.; egpow = false; if (!sf_getfloat("gpow",&gpow)) { gpow=1.; /*( gpow=1 raise data to gpow power for display )*/ } else if (gpow <= 0.) { gpow=0.; egpow = true; sf_getfloat("phalf",&phalf); /* percentage for estimating gpow */ if (phalf <=0. || phalf > 100.) sf_error("phalf=%g should be > 0 and <= 100",phalf); panel = 0; } pclip=99.; eclip = (bool) (!sf_getfloat("clip",&clip)); /* data clip */ if (eclip) { clip = 0.; sf_getfloat("pclip",&pclip); /* data clip percentile (default is 99) */ if (pclip <=0. || pclip > 100.) sf_error("pclip=%g should be > 0 and <= 100",pclip); panel = 0; } else if (clip <= 0.) { sf_warning("clip=%g <= 0",clip); clip = FLT_EPSILON; } if (0==panel) { if (!sf_getint("gainstep",&gainstep)) gainstep=0.5+n1/256.; /* subsampling for gpow and clip estimation */ if (gainstep <= 0) gainstep=1; gainpanel = sf_getstring("gainpanel"); /* gain reference: 'a' for all, 'e' for each, or number */ if (NULL != gainpanel) { switch (gainpanel[0]) { case 'a': panel=GAIN_ALL; break; case 'e': panel=GAIN_EACH; break; default: if (0 ==sscanf(gainpanel,"%d",&panel) || panel < 1 || panel > n3) sf_error("gainpanel= should be all," " each, or a number" " between 1 and %d",n3); panel--; break; } free (gainpanel); } sf_unpipe(in,sf_filesize(in)*sizeof(float)); } if (!sf_getbool("allpos",&allpos)) allpos=false; /* if y, assume positive data */ if (!sf_getbool("mean",&mean)) mean=false; /* if y, bias on the mean value */ if (!sf_getfloat("bias",&pbias)) pbias=0.; /* value mapped to the center of the color table */ if (!sf_getbool("polarity",&polarity)) polarity=false; /* if y, reverse polarity (white is high by default) */ if (!sf_getbool("symcp",&symcp)) symcp=false; /* if y, assume symmetric color palette of 255 colors */ if (!sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ } /* if !charin */ barfile = sf_getstring("bar"); /* file for scalebar data */ if (sfbyte) { scalebar = (bool) (NULL != barfile); if (scalebar) sf_putstring(out,"bar",barfile); } else if (sfbar) { scalebar = true; } else { if (!sf_getbool ("wantscalebar",&scalebar) && !sf_getbool ("scalebar",&scalebar)) scalebar = false; /* if y, draw scalebar */ } if (scalebar) { nomin = (bool) (!sf_getfloat("minval",&barmin)); /* minimum value for scalebar (default is the data minimum) */ nomax = (bool) (!sf_getfloat("maxval",&barmax)); /* maximum value for scalebar (default is the data maximum) */ barbuf[0] = sf_ucharalloc(VP_BSIZE); if (!sf_getbool("barreverse",&barreverse)) barreverse=false; /* if y, go from small to large on the bar scale */ if (sfbyte || sfbar) { if (sfbyte) { bar = sf_output("bar"); sf_settype(bar,SF_UCHAR); } sf_putint(bar,"n1",VP_BSIZE+2*sizeof(float)); sf_putint(bar,"n2",1); sf_putint(bar,"n3",n3); if (!nomin) sf_putfloat(bar,"minval",barmin); if (!nomax) sf_putfloat(bar,"maxval",barmax); } else if (charin) { if (NULL == barfile) { barfile=sf_histstring(in,"bar"); if (NULL == barfile) sf_error("Need bar="); } bar = sf_input(barfile); if (SF_UCHAR != sf_gettype(bar)) sf_error("Need uchar in bar"); if (nomin) nomin = (bool) (!sf_histfloat(bar,"minval",&barmin)); if (nomax) nomax = (bool) (!sf_histfloat(bar,"maxval",&barmax)); } } if (!sf_getbool("wantframenum",&framenum)) framenum = (bool) (n3 > 1); /* if y, display third axis position in the corner */ x1 = o1-0.5*d1; x2 = o1+(n1-1)*d1+0.5*d1; y1 = o2-0.5*d2; y2 = o2+(n2-1)*d2+0.5*d2; if (!sfbyte && !sfbar) { vp_stdplot_init (x1, x2, y1, y2, transp, false, yreverse, false); vp_frame_init(in,"tlb",false); /* if (scalebar && !nomin && !nomax) vp_barframe_init (in,barmin,barmax); */ } if (transp) { f=x1; x1=y1; y1=f; f=x2; x2=y2; y2=f; } if (yreverse) { f=y1; y1=y2; y2=f; } if (xreverse) { f=x1; x1=x2; x2=f; } buf = sf_ucharalloc2(n1,n2); if (!charin) { data = sf_floatalloc2(n1,n2); if (GAIN_ALL==panel || panel >= 0) { pos = sf_tell(in); if (panel > 0) sf_seek(in, pos+panel*n1*n2*sizeof(float), SEEK_SET); vp_gainpar (in,data,n1,n2,gainstep, pclip,phalf,&clip,&gpow,mean,&pbias, n3,panel,panel); if (verb) sf_warning("panel=%d bias=%g clip=%g gpow=%g", panel,pbias,clip,gpow); if (sfbyte) sf_putfloat(out,"clip",clip); sf_seek(in,pos,SEEK_SET); /* rewind */ } } if (!sfbyte && !sfbar) { /* initialize color table */ if (NULL == (color = sf_getstring("color"))) color="i"; /* color scheme (default is i) */ if (!sf_getint ("nreserve",&nreserve)) nreserve = 8; /* reserved colors */ vp_rascoltab (nreserve, color); } for (i3=0; i3 < n3; i3++) { if (!charin) { if (GAIN_EACH == panel) { if (eclip) clip=0.; if (egpow) gpow=0.; vp_gainpar (in,data,n1,n2,gainstep, pclip,phalf,&clip,&gpow, mean,&pbias,n3,0,n3); if (verb) sf_warning("bias=%g clip=%g gpow=%g",pbias,clip,gpow); } else { sf_floatread(data[0],n1*n2,in); } if (1 == panel || GAIN_EACH == panel || 0==i3) { /* initialize the conversion table */ if(!allpos) { /* negative and positive values */ for (it=1; it<=TSIZE/2; it++) { if (symcp) { tbl[TSIZE-it] = (gpow != 1.)? 254*(pow(((TSIZE-2.0*it)/TSIZE),gpow)+1.)/2.+1.: 254*( ((TSIZE-2.0*it)/TSIZE) +1.)/2.+1.; tbl[it] = 255 - tbl[TSIZE-it] + 1.0; } else { tbl[TSIZE-it] = (gpow != 1.)? 252*(pow(((TSIZE-2.0*it)/TSIZE),gpow)+1.)/2.+3.: 252*( ((TSIZE-2.0*it)/TSIZE) +1.)/2.+3.; tbl[it] = 255 - tbl[TSIZE-it] + 2.0; } } bias = TSIZE/2.; gain = TSIZE/(2.*clip); } else { /* all positive */ if (symcp) { for (it=1; it < TSIZE ; it++) { tbl[it] = 255*((it-1.0)/TSIZE) + 1.0; } } else { for (it=1; it < TSIZE ; it++) { tbl[it] = 256*((it-1.0)/TSIZE); } } bias = 0.; gain = TSIZE/clip; } tbl[0] = tbl[1]; tbl[TSIZE] = tbl[TSIZE-1]; if (polarity) { /* switch polarity */ for (it=0; it<=TSIZE; it++) { tbl[it]=255-tbl[it]; } } } /* convert to bytes */ for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1; i1++) { j = (data[i2][i1]-pbias)*gain + bias; if (j < 0) j=0; else if (j > TSIZE) j=TSIZE; buf[i2][i1] = tbl[j]; } } } else { sf_ucharread(buf[0],n1*n2,in); } if (!sfbyte && !sfbar) { if (yreverse) { for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1/2; i1++) { tmp = buf[i2][i1]; buf[i2][i1] = buf[i2][n1-1-i1]; buf[i2][n1-1-i1] = tmp; } } } if ((xreverse && transp) || (!xreverse && !transp)) { for (i2=0; i2 < n2/2; i2++) { for (i1=0; i1 < n1; i1++) { tmp = buf[i2][i1]; buf[i2][i1] = buf[n2-1-i2][i1]; buf[n2-1-i2][i1] = tmp; } } } if (i3 > 0) vp_erase (); if (framenum) vp_framenum(o3+i3*d3); vp_frame(); vp_uraster (buf, false, 256, n1, n2, x1, y1, x2, y2, orient); vp_simpleframe(); } if (scalebar) { if (!charin) { if (nomin) barmin = data[0][0]; if (nomax) barmax = data[0][0]; if (nomin || nomax) { for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1; i1++) { dat = data[i2][i1]; if (nomin && barmin > dat) barmin = dat; if (nomax && barmax < dat) barmax = dat; } } } for (it=0; it < VP_BSIZE; it++) { if (barreverse) { dat = (barmin*it + barmax*(VP_BSIZE-1-it))/(VP_BSIZE-1); } else { dat = (barmax*it + barmin*(VP_BSIZE-1-it))/(VP_BSIZE-1); } j = (dat-pbias)*gain + bias; if (j < 0) j=0; else if (j > TSIZE) j=TSIZE; barbuf[0][it] = tbl[j]; } } else { sf_floatread(minmax,2,bar); sf_ucharread(barbuf[0],VP_BSIZE,bar); if (nomin) barmin=minmax[0]; if (nomax) barmax=minmax[1]; } if (sfbyte || sfbar) { sf_floatwrite(&barmin,1,bar); sf_floatwrite(&barmax,1,bar); sf_ucharwrite(barbuf[0],VP_BSIZE,bar); } else { if (barreverse) { vp_barframe_init (in,barmax,barmin); } else { vp_barframe_init (in,barmin,barmax); } vp_barraster(VP_BSIZE, barbuf); } } /* if scalebar */ if (sfbyte) { sf_ucharwrite(buf[0],n1*n2,out); } else if (!sfbar) { vp_purge(); } } /* i3 loop */ exit (0); }
int main(int argc, char* argv[]) { bool verb; /* verbosity flag */ bool abc; /* absorbing boundary conditions flag */ bool free; /* free surface flag*/ bool snap; /* wavefield snapshots flag */ int jsnap;/* save wavefield every *jsnap* time steps */ /* cube axes */ sf_axis at,az,ax,as,ar,bt; int it,iz,ix,is,ir, iop; int nt,nz,nx,ns,nr,nz2,nx2; float z0,x0,dt,dx,dz, idx,idz,dt2; /* Laplacian */ int nop=2; /* Laplacian operator size */ float c0, c1, c2; /* Laplacian operator coefficients */ float co,c1x,c2x,c1z,c2z; int nbz,nbx; /* boundary size */ float tz, tx; /* sponge boundary decay coefficients */ float dp; float ws; /* injected data */ /* linear interpolation */ float *fzs,*fxs, *fzr,*fxr; int *jzs,*jxs, *jzr,*jxr; float *ws00,*ws01,*ws10,*ws11; float *wr00,*wr01,*wr10,*wr11; /* boundary */ float *bzl,*bzh,*bxl,*bxh; /* I/O files */ sf_file Fw,Fs,Fr; float *ww; /* wavelet */ pt2d *ss, *rr; /* source/receiver locations */ float **tt; /* taper */ /* background */ sf_file Bv,Bd,Bu; /* velocity, data, wavefield */ float **bvv,**bvo; /* velocity */ float *bdd; /* data */ float **bum,**buo,**bup,**bud; /* wavefields */ /* perturbation */ sf_file Pv,Pd,Pu; float **pvv,**pvo; float *pdd; float **pum,**puo,**pup,**pud; int ompchunk; /* OpenMP data chunk size */ /*------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); if(! sf_getint("ompchunk",&ompchunk)) ompchunk=1; if(! sf_getbool("verb",&verb)) verb=false; if(! sf_getbool( "abc",&abc )) abc=false; if(! sf_getbool("snap",&snap)) snap=false; if(! sf_getbool("free",&free)) free=false; Fw = sf_input ("in" ); /* wavelet */ Fs = sf_input ("sou"); /* sources */ Fr = sf_input ("rec"); /* receivers */ Bv = sf_input ("vel"); /* velocity */ Bu = sf_output("wfl"); /* wavefield */ Bd = sf_output("out"); /* data */ Pv = sf_input ("ref"); /* velocity */ Pu = sf_output("liw"); /* linearized wavefield */ Pd = sf_output("lid"); /* linearized data */ /* read axes*/ at=sf_iaxa(Fw,1); sf_setlabel(at,"t"); nt=sf_n(at); dt=sf_d(at); if(verb) sf_raxa(at); /* time */ as=sf_iaxa(Fs,2); sf_setlabel(as,"s"); ns=sf_n(as); if(verb) sf_raxa(as); /* sources */ ar=sf_iaxa(Fr,2); sf_setlabel(ar,"r"); nr=sf_n(ar); if(verb) sf_raxa(ar); /* receivers */ az=sf_iaxa(Bv,1); sf_setlabel(az,"z"); nz=sf_n(az); dz=sf_d(az); if(verb) sf_raxa(az); /* depth */ ax=sf_iaxa(Bv,2); sf_setlabel(ax,"x"); nx=sf_n(ax); dx=sf_d(ax); if(verb) sf_raxa(ax); /* space */ /* configure wavefield snapshots */ if(snap) { if(! sf_getint("jsnap",&jsnap)) jsnap=nt; } /*------------------------------------------------------------*/ /* expand domain for absorbing boundary conditions */ if(abc) { if(! sf_getint("nbz",&nbz)) nbz=nop; if(nbz<nop) nbz=nop; if(! sf_getint("nbx",&nbx)) nbx=nop; if(nbx<nop) nbx=nop; if(! sf_getfloat("tz",&tz)) tz=0.025; if(! sf_getfloat("tx",&tx)) tx=0.025; } else { nbz=nop; nbx=nop; } /* expanded domain ( az+2 nz, ax+2 nx ) */ nz2=nz+2*nbz; z0=sf_o(az)-nbz*dz; nx2=nx+2*nbx; x0=sf_o(ax)-nbx*dx; sf_setn(az,nz2); sf_seto(az,z0); if(verb) sf_raxa(az); sf_setn(ax,nx2); sf_seto(ax,x0); if(verb) sf_raxa(ax); /*------------------------------------------------------------*/ /* setup output wavefield header */ if(snap) { bt = sf_maxa(nt/jsnap,sf_o(at),dt*jsnap); sf_setlabel(bt,"t"); sf_oaxa(Bu,az,1); sf_oaxa(Bu,ax,2); sf_oaxa(Bu,bt,3); sf_oaxa(Pu,az,1); sf_oaxa(Pu,ax,2); sf_oaxa(Pu,bt,3); } /* setup output data header */ sf_oaxa(Bd,ar,1); sf_oaxa(Bd,at,2); sf_oaxa(Pd,ar,1); sf_oaxa(Pd,at,2); dt2 = dt*dt; idz = 1/(dz*dz); idx = 1/(dx*dx); /* Laplacian coefficients */ c0=-30./12.; c1=+16./12.; c2=- 1./12.; co = c0 * (idx+idz); c1x= c1 * idx; c2x= c2 * idx; c1z= c1 * idz; c2z= c2 * idz; /*------------------------------------------------------------*/ /* allocate arrays */ ww=sf_floatalloc (nt); sf_floatread(ww ,nt ,Fw); bvv=sf_floatalloc2(nz,nx); sf_floatread(bvv[0],nz*nx,Bv); pvv=sf_floatalloc2(nz,nx); sf_floatread(pvv[0],nz*nx,Pv); /* allocate source/receiver point arrays */ ss = (pt2d*) sf_alloc(ns,sizeof(*ss)); rr = (pt2d*) sf_alloc(nr,sizeof(*rr)); pt2dread1(Fs,ss,ns,3); /* read 3 elements (x,z,v) */ pt2dread1(Fr,rr,nr,2); /* read 2 elements (x,z) */ bdd=sf_floatalloc(nr); pdd=sf_floatalloc(nr); jzs=sf_intalloc(ns); fzs=sf_floatalloc(ns); jzr=sf_intalloc(nr); fzr=sf_floatalloc(nr); jxs=sf_intalloc(ns); fxs=sf_floatalloc(ns); jxr=sf_intalloc(nr); fxr=sf_floatalloc(nr); ws00 = sf_floatalloc(ns); wr00 = sf_floatalloc(nr); ws01 = sf_floatalloc(ns); wr01 = sf_floatalloc(nr); ws10 = sf_floatalloc(ns); wr10 = sf_floatalloc(nr); ws11 = sf_floatalloc(ns); wr11 = sf_floatalloc(nr); /*------------------------------------------------------------*/ for (is=0;is<ns;is++) { if(ss[is].z >= z0 && ss[is].z < z0 + (nz2-1)*dz && ss[is].x >= x0 && ss[is].x < x0 + (nx2-1)*dx) { jzs[is] = (int)( (ss[is].z-z0)/dz); fzs[is] = (ss[is].z-z0)/dz - jzs[is]; jxs[is] = (int)( (ss[is].x-x0)/dx); fxs[is] = (ss[is].x-x0)/dx - jxs[is]; } else { jzs[is] = 0; jxs[is] = 0; fzs[is] = 1; fxs[is] = 0; ss[is].v= 0; } ws00[is] = (1-fzs[is])*(1-fxs[is]); ws01[is] = ( fzs[is])*(1-fxs[is]); ws10[is] = (1-fzs[is])*( fxs[is]); ws11[is] = ( fzs[is])*( fxs[is]); } for (ir=0;ir<nr;ir++) { if(rr[ir].z >= z0 && rr[ir].z < z0 + (nz2-1)*dz && rr[ir].x >= x0 && rr[ir].x < x0 + (nx2-1)*dx) { jzr[ir] = (int)( (rr[ir].z-z0)/dz); fzr[ir] = (rr[ir].z-z0)/dz - jzr[ir]; jxr[ir] = (int)( (rr[ir].x-x0)/dx); fxr[ir] = (rr[ir].x-x0)/dx - jxr[ir]; rr[ir].v=1; } else { jzr[ir] = 0; fzr[ir] = 1; rr[ir].v= 0; } wr00[ir] = (1-fzr[ir])*(1-fxr[ir]); wr01[ir] = ( fzr[ir])*(1-fxr[ir]); wr10[ir] = (1-fzr[ir])*( fxr[ir]); wr11[ir] = ( fzr[ir])*( fxr[ir]); } /*------------------------------------------------------------*/ /* allocate temporary arrays */ bum=sf_floatalloc2(nz2,nx2); buo=sf_floatalloc2(nz2,nx2); bup=sf_floatalloc2(nz2,nx2); bud=sf_floatalloc2(nz2,nx2); pum=sf_floatalloc2(nz2,nx2); puo=sf_floatalloc2(nz2,nx2); pup=sf_floatalloc2(nz2,nx2); pud=sf_floatalloc2(nz2,nx2); tt=sf_floatalloc2(nz2,nx2); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(iz,ix) shared(nx2,nz2,bum,buo,bup,bud,pum,puo,pup,pud,tt) #endif for (iz=0; iz<nz2; iz++) { for (ix=0; ix<nx2; ix++) { bum[ix][iz]=pum[ix][iz]=0; buo[ix][iz]=puo[ix][iz]=0; bup[ix][iz]=pup[ix][iz]=0; bud[ix][iz]=pud[ix][iz]=0; tt[ix][iz]=1; } } /*------------------------------------------------------------*/ /* velocity in the expanded domain (vo=vv^2)*/ bvo=sf_floatalloc2(nz2,nx2); pvo=sf_floatalloc2(nz2,nx2); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(iz,ix) shared(nz,nx,bvv,pvv,bvo,pvo) #endif for (iz=0; iz<nz; iz++) { for (ix=0; ix<nx; ix++) { bvo[nbx+ix][nbz+iz] = bvv[ix][iz] * bvv[ix][iz]; pvo[nbx+ix][nbz+iz] = pvv[ix][iz]; } } /* fill boundaries */ for (iz=0; iz<nbz; iz++) { for (ix=0; ix<nx2; ix++) { bvo[ix][ iz ] = bvo[ix][ nbz ]; bvo[ix][nz2-iz-1] = bvo[ix][nz2-nbz-1]; pvo[ix][ iz ] = pvo[ix][ nbz ]; pvo[ix][nz2-iz-1] = pvo[ix][nz2-nbz-1]; } } for (iz=0; iz<nz2; iz++) { for (ix=0; ix<nbx; ix++) { bvo[ ix ][iz] = bvo[ nbx ][iz]; bvo[nx2-ix-1][iz] = bvo[nx2-nbx-1][iz]; pvo[ ix ][iz] = pvo[ nbx ][iz]; pvo[nx2-ix-1][iz] = pvo[nx2-nbx-1][iz]; } } /*------------------------------------------------------------*/ /* free surface */ if(abc && free) { for (iz=0; iz<nbz; iz++) { for (ix=0; ix<nx2; ix++) { bvo[ix][iz]=0; pvo[ix][iz]=0; } } } /*------------------------------------------------------------*/ /* sponge ABC setup */ if(abc) { for (iz=0; iz<nbz; iz++) { for (ix=0; ix<nx2; ix++) { tt[ix][ iz ] = exp( - (tz*(nbz-iz))*(tz*(nbz-iz)) ); tt[ix][nz2-iz-1] = tt[ix][iz]; } } for (iz=0; iz<nz2; iz++) { for (ix=0; ix<nbx; ix++) { tt[ ix ][iz] = exp( - (tx*(nbx-ix))*(tx*(nbx-ix)) ); tt[nx2-ix-1][iz] = tt[ix][iz]; } } } /* one-way ABC setup */ bzl=sf_floatalloc(nx2); bzh=sf_floatalloc(nx2); bxl=sf_floatalloc(nz2); bxh=sf_floatalloc(nz2); for (ix=0;ix<nx2;ix++) { dp = bvo[ix][ nop ] *dt/dz; bzl[ix] = (1-dp)/(1+dp); dp = bvo[ix][nz2-nop-1] *dt/dz; bzh[ix] = (1-dp)/(1+dp); } for (iz=0;iz<nz2;iz++) { dp = bvo[ nop ][iz] *dt/dx; bxl[iz] = (1-dp)/(1+dp); dp = bvo[nx2-nop-1][iz] *dt/dx; bxh[iz] = (1-dp)/(1+dp); } /*------------------------------------------------------------*/ /* * MAIN LOOP */ if(verb) fprintf(stderr,"\n"); for (it=0; it<nt; it++) { if(verb) fprintf(stderr,"\b\b\b\b\b%d",it); /* 4th order Laplacian operator */ #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(iz,ix) shared(nop,nx2,nz2,bud,buo,pud,puo,co,c1x,c1z,c2x,c2z,idx,idz) #endif for (ix=nop; ix<nx2-nop; ix++) { for (iz=nop; iz<nz2-nop; iz++) { bud[ix][iz] = co * buo[ix ][iz ] + c1x*(buo[ix-1][iz ] + buo[ix+1][iz ]) + c2x*(buo[ix-2][iz ] + buo[ix+2][iz ]) + c1z*(buo[ix ][iz-1] + buo[ix ][iz+1]) + c2z*(buo[ix ][iz-2] + buo[ix ][iz+2]); pud[ix][iz] = co * puo[ix ][iz ] + c1x*(puo[ix-1][iz ] + puo[ix+1][iz ]) + c2x*(puo[ix-2][iz ] + puo[ix+2][iz ]) + c1z*(puo[ix ][iz-1] + puo[ix ][iz+1]) + c2z*(puo[ix ][iz-2] + puo[ix ][iz+2]); } } /* inject source */ for (is=0;is<ns;is++) { ws = ww[it] * ss[is].v; bud[ jxs[is] ][ jzs[is] ] -= ws * ws00[is]; bud[ jxs[is] ][ jzs[is]+1] -= ws * ws01[is]; bud[ jxs[is]+1][ jzs[is] ] -= ws * ws10[is]; bud[ jxs[is]+1][ jzs[is]+1] -= ws * ws11[is]; } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(ix,iz) shared(nx2,nz2,pud,bud,pvo) #endif for (ix=0; ix<nx2; ix++) { for (iz=0; iz<nz2; iz++) { pud[ix][iz] -= bud[ix][iz] * 2*pvo[ix][iz]; } } /* velocity scale */ #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(ix,iz) shared(nx2,nz2,bud,pud,bvo) #endif for (ix=0; ix<nx2; ix++) { for (iz=0; iz<nz2; iz++) { bud[ix][iz] *= bvo[ix][iz]; pud[ix][iz] *= bvo[ix][iz]; } } /* time step */ #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(ix,iz) shared(nx2,nz2,bud,buo,bum,bup,pud,puo,pum,pup,dt2) #endif for (ix=0; ix<nx2; ix++) { for (iz=0; iz<nz2; iz++) { bup[ix][iz] = 2*buo[ix][iz] - bum[ix][iz] + bud[ix][iz] * dt2; bum[ix][iz] = buo[ix][iz]; buo[ix][iz] = bup[ix][iz]; pup[ix][iz] = 2*puo[ix][iz] - pum[ix][iz] + pud[ix][iz] * dt2; pum[ix][iz] = puo[ix][iz]; puo[ix][iz] = pup[ix][iz]; } } /* one-way ABC apply */ if(abc) { #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(ix,iz,iop) shared(nx2,nz2,nop,buo,bum,puo,pum,bzl,bzh) #endif for(ix=0;ix<nx2;ix++) { for(iop=0;iop<nop;iop++) { iz = nop-iop; buo [ix][iz ] = bum[ix][iz+1] +(bum[ix][iz ] - buo[ix][iz+1]) * bzl[ix]; puo [ix][iz ] = pum[ix][iz+1] +(pum[ix][iz ] - puo[ix][iz+1]) * bzl[ix]; iz = nz2-nop+iop-1; buo [ix][iz ] = bum[ix][iz-1] +(bum[ix][iz ] - buo[ix][iz-1]) * bzh[ix]; puo [ix][iz ] = pum[ix][iz-1] +(pum[ix][iz ] - puo[ix][iz-1]) * bzh[ix]; } } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,1) private(ix,iz,iop) shared(nx2,nz2,nop,buo,bum,puo,pum,bzl,bzh) #endif for(iop=0;iop<nop;iop++) { for(iz=0;iz<nz2;iz++) { ix = nop-iop; buo [ix ][iz] = bum[ix+1][iz] +(bum[ix ][iz] - buo[ix+1][iz]) * bxl[iz]; puo [ix ][iz] = pum[ix+1][iz] +(pum[ix ][iz] - puo[ix+1][iz]) * bxl[iz]; ix = nx2-nop+iop-1; buo [ix ][iz] = bum[ix-1][iz] +(bum[ix ][iz] - buo[ix-1][iz]) * bxh[iz]; puo [ix ][iz] = pum[ix-1][iz] +(pum[ix ][iz] - puo[ix-1][iz]) * bxh[iz]; } } } /* sponge ABC apply */ if(abc) { #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(ix,iz) shared(nx2,nz2,buo,bum,bud,puo,pum,pud,tt) #endif for (ix=0; ix<nx2; ix++) { for (iz=0; iz<nz2; iz++) { buo[ix][iz] *= tt[ix][iz]; bum[ix][iz] *= tt[ix][iz]; bud[ix][iz] *= tt[ix][iz]; puo[ix][iz] *= tt[ix][iz]; pum[ix][iz] *= tt[ix][iz]; bud[ix][iz] *= tt[ix][iz]; } } } /* write wavefield */ if(snap && it%jsnap==0) { sf_floatwrite(buo[0],nz2*nx2,Bu); sf_floatwrite(puo[0],nz2*nx2,Pu); } /* write data */ #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,1) private(ir) shared(bdd,pdd,rr,buo,puo,jzr,wr00,wr01,wr10,wr11) #endif for (ir=0;ir<nr;ir++) { bdd[ir] = buo[ jxr[ir] ][ jzr[ir] ] * wr00[ir] + buo[ jxr[ir] ][ jzr[ir]+1] * wr01[ir] + buo[ jxr[ir]+1][ jzr[ir] ] * wr10[ir] + buo[ jxr[ir]+1][ jzr[ir]+1] * wr11[ir]; bdd[ir] *= rr[ir].v; pdd[ir] = puo[ jxr[ir] ][ jzr[ir] ] * wr00[ir] + puo[ jxr[ir] ][ jzr[ir]+1] * wr01[ir] + puo[ jxr[ir]+1][ jzr[ir] ] * wr10[ir] + puo[ jxr[ir]+1][ jzr[ir]+1] * wr11[ir]; pdd[ir] *= rr[ir].v; } /* write data */ sf_floatwrite(bdd,nr,Bd); sf_floatwrite(pdd,nr,Pd); } if(verb) fprintf(stderr,"\n"); exit (0); }