int main(int argc, char* argv[]) { /*------------------------------------------------------------*/ /* Execution control, I/O files and geometry */ /*------------------------------------------------------------*/ bool verb,fsrf,snap,back,esou; /* execution flags */ int jsnap,ntsnap,jdata; /* jump along axes */ int shft; /* time shift for wavefield matching in RTM */ /* I/O files */ sf_file Fwav=NULL; /* wavelet */ sf_file Fdat=NULL; /* data */ sf_file Fsou=NULL; /* sources */ sf_file Frec=NULL; /* receivers */ sf_file Fccc=NULL; /* velocity */ sf_file Frkp=NULL; /* app. rank */ sf_file Fltp=NULL; /* left mat */ sf_file Frtp=NULL; /* right mat */ sf_file Fwfp=NULL; /* wavefield */ sf_file Frks=NULL; /* app. rank */ sf_file Flts=NULL; /* left mat */ sf_file Frts=NULL; /* right mat */ sf_file Fwfs=NULL; /* wavefield */ /* cube axes */ sf_axis at,ax,ay,az; /* time, x, y, z */ sf_axis asx,asy,arx,ary,ac; /* sou, rec-x, rec-y, component */ /* dimension, index and interval */ int nt,nz,nx,ny,ns,nr,nc,nb; int it,iz,ix,iy; float dt,dz,dx,dy; int nxyz, nk; /* FDM and KSP structure */ //!!!JS fdm3d fdm=NULL; dft3d dft=NULL; clr3d clr_p=NULL, clr_s=NULL; /* I/O arrays for sou & rec */ sf_complex***ww=NULL; /* wavelet */ pt3d *ss=NULL; /* sources */ pt3d *rr=NULL; /* receivers */ sf_complex **dd=NULL; /* data */ /*------------------------------------------------------------*/ /* displacement: uo = U @ t; up = U @ t+1 */ /*------------------------------------------------------------*/ sf_complex ***uox, ***uoy, ***uoz, **uo; sf_complex ***uox_p, ***uoy_p, ***uoz_p, **uo_p; sf_complex ***uox_s, ***uoy_s, ***uoz_s, **uo_s; /*sf_complex ***upx, ***upy, ***upz, **up;*/ /*------------------------------------------------------------*/ /* lowrank decomposition arrays */ /*------------------------------------------------------------*/ int ntmp, *n2s_p, *n2s_s; sf_complex **lt_p, **rt_p, **lt_s, **rt_s; /*------------------------------------------------------------*/ /* linear interpolation weights/indices */ /*------------------------------------------------------------*/ lint3d cs,cr; /* for injecting source and extracting data */ /* Gaussian bell */ int nbell; /*------------------------------------------------------------*/ /* wavefield cut params */ /*------------------------------------------------------------*/ sf_axis acz=NULL,acx=NULL,acy=NULL; int nqz,nqx,nqy; float oqz,oqx,oqy; float dqz,dqx,dqy; sf_complex***uc=NULL; /* tmp array for output wavefield snaps */ /*------------------------------------------------------------*/ /* init RSF */ /*------------------------------------------------------------*/ sf_init(argc,argv); /*------------------------------------------------------------*/ /* OMP parameters */ /*------------------------------------------------------------*/ #ifdef _OPENMP omp_init(); #endif /*------------------------------------------------------------*/ /* read execution flags */ /*------------------------------------------------------------*/ if(! sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ if(! sf_getbool("snap",&snap)) snap=false; /* wavefield snapshots flag */ if(! sf_getbool("free",&fsrf)) fsrf=false; /* free surface flag */ if(! sf_getbool("back",&back)) back=false; /* backward extrapolation flag (for rtm) */ if(! sf_getbool("esou",&esou)) esou=false; /* explosive force source */ /*------------------------------------------------------------*/ /* I/O files */ /*------------------------------------------------------------*/ Fwav = sf_input ("in" ); /* wavelet */ Fdat = sf_output("out"); /* data */ Fsou = sf_input ("sou"); /* sources */ Frec = sf_input ("rec"); /* receivers */ Fccc = sf_input ("ccc"); /* stiffness */ Frkp = sf_input ("rkp"); /* app. rank */ Fltp = sf_input ("ltp"); /* left mat */ Frtp = sf_input ("rtp"); /* right mat */ Fwfp = sf_output("wfp"); /* wavefield */ Frks = sf_input ("rks"); /* app. rank */ Flts = sf_input ("lts"); /* left mat */ Frts = sf_input ("rts"); /* right mat */ Fwfs = sf_output("wfs"); /* wavefield */ /*------------------------------------------------------------*/ /* axes */ /*------------------------------------------------------------*/ at = sf_iaxa(Fwav,4); sf_setlabel(at,"t"); if(verb) sf_raxa(at); /* time */ az = sf_iaxa(Fccc,1); sf_setlabel(az,"z"); if(verb) sf_raxa(az); /* depth */ ax = sf_iaxa(Fccc,2); sf_setlabel(ax,"x"); if(verb) sf_raxa(ax); /* space x */ ay = sf_iaxa(Fccc,3); sf_setlabel(ay,"y"); if(verb) sf_raxa(ay); /* space y */ asx = sf_iaxa(Fsou,2); sf_setlabel(asx,"sx"); if(verb) sf_raxa(asx); /* sources x */ asy = sf_iaxa(Fsou,3); sf_setlabel(asy,"sy"); if(verb) sf_raxa(asy); /* sources y */ arx = sf_iaxa(Frec,2); sf_setlabel(arx,"rx"); if(verb) sf_raxa(arx); /* receivers x */ ary = sf_iaxa(Frec,3); sf_setlabel(ary,"ry"); if(verb) sf_raxa(ary); /* receivers y */ nt = sf_n(at); dt = sf_d(at); nz = sf_n(az); dz = sf_d(az); nx = sf_n(ax); dx = sf_d(ax); ny = sf_n(ay); dy = sf_d(ay); ns = sf_n(asx)*sf_n(asy); nr = sf_n(arx)*sf_n(ary); /*------------------------------------------------------------*/ /* other execution parameters */ /*------------------------------------------------------------*/ if(! sf_getint("nbell",&nbell)) nbell=NOP; /* bell size */ if(verb) sf_warning("nbell=%d",nbell); if(! sf_getint("jdata",&jdata)) jdata=1; if(snap) { /* save wavefield every *jsnap* time steps */ if(! sf_getint("jsnap",&jsnap)) jsnap=nt; } if(back) { shft = (nt-1)%jsnap; sf_warning("For backward extrapolation, make sure nbell(%d)=0",nbell); } else shft = 0; /*------------------------------------------------------------*/ /* expand domain for FD operators and ABC */ /*------------------------------------------------------------*/ if( !sf_getint("nb",&nb)) nb=NOP; fdm=fdutil3d_init(verb,fsrf,az,ax,ay,nb,1); if(nbell) fdbell3d_init(nbell); sf_setn(az,fdm->nzpad); sf_seto(az,fdm->ozpad); if(verb) sf_raxa(az); sf_setn(ax,fdm->nxpad); sf_seto(ax,fdm->oxpad); if(verb) sf_raxa(ax); sf_setn(ay,fdm->nypad); sf_seto(ay,fdm->oypad); if(verb) sf_raxa(ay); /*------------------------------------------------------------*/ /* 3D vector components */ /*------------------------------------------------------------*/ nc=3; ac=sf_maxa(nc,0,1); /* output 3 cartesian components */ /*------------------------------------------------------------*/ /* setup output data header */ /*------------------------------------------------------------*/ sf_settype(Fdat,SF_COMPLEX); sf_oaxa(Fdat,arx,1); sf_oaxa(Fdat,ary,2); sf_oaxa(Fdat,ac,3); sf_setn(at,nt/jdata); sf_setd(at,dt*jdata); sf_oaxa(Fdat,at,4); /* setup output wavefield header */ if(snap) { if(!sf_getint ("nqz",&nqz)) nqz=sf_n(az); if(!sf_getint ("nqx",&nqx)) nqx=sf_n(ax); if(!sf_getint ("nqy",&nqy)) nqy=sf_n(ay); if(!sf_getfloat("oqz",&oqz)) oqz=sf_o(az); if(!sf_getfloat("oqx",&oqx)) oqx=sf_o(ax); if(!sf_getfloat("oqy",&oqy)) oqy=sf_o(ay); dqz=sf_d(az); dqx=sf_d(ax); dqy=sf_d(ay); acz = sf_maxa(nqz,oqz,dqz); sf_raxa(acz); acx = sf_maxa(nqx,oqx,dqx); sf_raxa(acx); acy = sf_maxa(nqy,oqy,dqy); sf_raxa(acy); uc=sf_complexalloc3(sf_n(acz),sf_n(acx),sf_n(acy)); ntsnap=0; /* ntsnap = it/jsnap+1; */ for(it=0; it<nt; it++) { if(it%jsnap==0) ntsnap++; } sf_setn(at, ntsnap); sf_setd(at,dt*jsnap); if(verb) sf_raxa(at); sf_settype(Fwfp,SF_COMPLEX); sf_oaxa(Fwfp,acz,1); sf_oaxa(Fwfp,acx,2); sf_oaxa(Fwfp,acy,3); sf_oaxa(Fwfp,ac, 4); sf_oaxa(Fwfp,at, 5); sf_settype(Fwfs,SF_COMPLEX); sf_oaxa(Fwfs,acz,1); sf_oaxa(Fwfs,acx,2); sf_oaxa(Fwfs,acy,3); sf_oaxa(Fwfs,ac, 4); sf_oaxa(Fwfs,at, 5); } /*------------------------------------------------------------*/ /* source and data array */ /*------------------------------------------------------------*/ ww=sf_complexalloc3(ns,nc,nt); /* Fast axis: n_sou > n_comp > n_time */ sf_complexread(ww[0][0],nt*nc*ns,Fwav); dd=sf_complexalloc2(nr,nc); /*------------------------------------------------------------*/ /* setup source/receiver coordinates */ /*------------------------------------------------------------*/ ss = (pt3d*) sf_alloc(ns,sizeof(*ss)); rr = (pt3d*) sf_alloc(nr,sizeof(*rr)); pt3dread1(Fsou,ss,ns,3); /* read (x,y,z) coordinates */ pt3dread1(Frec,rr,nr,3); /* read (x,y,z) coordinates */ /* calculate 3d linear interpolation coef for sou & rec */ cs = lint3d_make(ns,ss,fdm); cr = lint3d_make(nr,rr,fdm); /*------------------------------------------------------------*/ /* allocate and initialize wavefield arrays */ /*------------------------------------------------------------*/ /* z-component */ uoz=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); uoz_p=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); uoz_s=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); /*upz=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad);*/ /* x-component */ uox=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); uox_p=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); uox_s=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); /*upx=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad);*/ /* y-component */ uoy=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); uoy_p=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); uoy_s=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); /*upy=sf_complexalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad);*/ /* wavefield vector */ uo = (sf_complex**) sf_alloc(3,sizeof(sf_complex*)); uo[0] = uox[0][0]; uo[1] = uoy[0][0]; uo[2] = uoz[0][0]; uo_p = (sf_complex**) sf_alloc(3,sizeof(sf_complex*)); uo_p[0] = uox_p[0][0]; uo_p[1] = uoy_p[0][0]; uo_p[2] = uoz_p[0][0]; uo_s = (sf_complex**) sf_alloc(3,sizeof(sf_complex*)); uo_s[0] = uox_s[0][0]; uo_s[1] = uoy_s[0][0]; uo_s[2] = uoz_s[0][0]; /*up = (sf_complex**) sf_alloc(3,sizeof(sf_complex*));*/ /*up[0] = upx[0][0]; up[1] = upy[0][0]; up[2] = upz[0][0];*/ /* initialize fft and lrk */ dft = dft3d_init(1,false,false,fdm); nxyz= fdm->nypad*fdm->nxpad*fdm->nzpad; nk = dft->nky *dft->nkx *dft->nkz; /*------------------------------------------------------------*/ /* allocation I/O arrays */ /*------------------------------------------------------------*/ n2s_p = sf_intalloc(9); sf_intread(n2s_p,9,Frkp); clr_p = clr3d_make2(n2s_p,fdm); n2s_s = sf_intalloc(9); sf_intread(n2s_s,9,Frks); clr_s = clr3d_make2(n2s_s,fdm); if (clr_p->n2_max > clr_s->n2_max) clr3d_init(fdm,dft,clr_p); else clr3d_init(fdm,dft,clr_s); /* check the dimension */ if (!sf_histint(Fltp,"n1",&ntmp) || ntmp != nxyz) sf_error("Need n1=%d in left",nxyz); if (!sf_histint(Fltp,"n2",&ntmp) || ntmp != clr_p->n2_sum) sf_error("Need n2=%d in left",clr_p->n2_sum); if (!sf_histint(Frtp,"n1",&ntmp) || ntmp != nk) sf_error("Need n1=%d in right",nk); if (!sf_histint(Frtp,"n2",&ntmp) || ntmp != clr_p->n2_sum) sf_error("Need n2=%d in right",clr_p->n2_sum); lt_p = sf_complexalloc2(nxyz,clr_p->n2_sum); rt_p = sf_complexalloc2(nk ,clr_p->n2_sum); sf_complexread(lt_p[0],nxyz*clr_p->n2_sum,Fltp); sf_complexread(rt_p[0],nk *clr_p->n2_sum,Frtp); if (!sf_histint(Flts,"n1",&ntmp) || ntmp != nxyz) sf_error("Need n1=%d in left",nxyz); if (!sf_histint(Flts,"n2",&ntmp) || ntmp != clr_s->n2_sum) sf_error("Need n2=%d in left",clr_s->n2_sum); if (!sf_histint(Frts,"n1",&ntmp) || ntmp != nk) sf_error("Need n1=%d in right",nk); if (!sf_histint(Frts,"n2",&ntmp) || ntmp != clr_s->n2_sum) sf_error("Need n2=%d in right",clr_s->n2_sum); lt_s = sf_complexalloc2(nxyz,clr_s->n2_sum); rt_s = sf_complexalloc2(nk ,clr_s->n2_sum); sf_complexread(lt_s[0],nxyz*clr_s->n2_sum,Flts); sf_complexread(rt_s[0],nk *clr_s->n2_sum,Frts); /* initialize to zero */ #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,1) \ private(iy,ix,iz) \ shared(fdm,uoz,uox,uoy,uoz_p,uox_p,uoy_p,uoz_s,uox_s,uoy_s) #endif for (iy=0; iy<fdm->nypad; iy++) { for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nzpad; iz++) { uoz [iy][ix][iz]=sf_cmplx(0.,0.); uox [iy][ix][iz]=sf_cmplx(0.,0.); uoy [iy][ix][iz]=sf_cmplx(0.,0.); uoz_p[iy][ix][iz]=sf_cmplx(0.,0.); uox_p[iy][ix][iz]=sf_cmplx(0.,0.); uoy_p[iy][ix][iz]=sf_cmplx(0.,0.); uoz_s[iy][ix][iz]=sf_cmplx(0.,0.); uox_s[iy][ix][iz]=sf_cmplx(0.,0.); uoy_s[iy][ix][iz]=sf_cmplx(0.,0.); /*upz[iy][ix][iz]=sf_cmplx(0.,0.); upx[iy][ix][iz]=sf_cmplx(0.,0.); upy[iy][ix][iz]=sf_cmplx(0.,0.);*/ } } } /*------------------------------------------------------------*/ /*------------------------ MAIN LOOP -------------------------*/ /*------------------------------------------------------------*/ if(verb) fprintf(stderr,"\n"); for (it=0; it<nt; it++) { if(verb) sf_warning("it=%d/%d;",it,nt); /*fprintf(stderr,"\b\b\b\b\b%d",it);*/ /*------------------------------------------------------------*/ /* apply lowrank matrix to wavefield vector */ /*------------------------------------------------------------*/ clr3d_apply(uo_p, uo, lt_p, rt_p, fdm, dft, clr_p); clr3d_apply(uo_s, uo, lt_s, rt_s, fdm, dft, clr_s); /*------------------------------------------------------------*/ /* combine P and S wave modes */ /*------------------------------------------------------------*/ #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,1) \ private(iy,ix,iz) \ shared(fdm,uoz,uox,uoy,uoz_p,uox_p,uoy_p,uoz_s,uox_s,uoy_s) #endif for (iy=0; iy<fdm->nypad; iy++) { for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nzpad; iz++) { uoz[iy][ix][iz] = uoz_p[iy][ix][iz] + uoz_s[iy][ix][iz]; uox[iy][ix][iz] = uox_p[iy][ix][iz] + uox_s[iy][ix][iz]; uoy[iy][ix][iz] = uoy_p[iy][ix][iz] + uoy_s[iy][ix][iz]; /*upz[iy][ix][iz]=sf_cmplx(0.,0.); upx[iy][ix][iz]=sf_cmplx(0.,0.); upy[iy][ix][iz]=sf_cmplx(0.,0.);*/ } } } /*------------------------------------------------------------*/ /* free surface */ /*------------------------------------------------------------*/ if(fsrf) { /* need to do something here */ } /*------------------------------------------------------------*/ /* inject displacement source */ /*------------------------------------------------------------*/ if(esou) { /* exploding force source */ lint3d_expl_complex(uoz,uox,uoy,ww[it],cs); } else { if(nbell) { lint3d_bell_complex(uoz,ww[it][0],cs); lint3d_bell_complex(uox,ww[it][1],cs); lint3d_bell_complex(uoy,ww[it][2],cs); } else { lint3d_inject_complex(uoz,ww[it][0],cs); lint3d_inject_complex(uox,ww[it][1],cs); lint3d_inject_complex(uoy,ww[it][2],cs); } } /*------------------------------------------------------------*/ /* cut wavefield and save */ /*------------------------------------------------------------*/ if(snap && (it-shft)%jsnap==0) { /* P wave */ cut3d_complex(uoz_p,uc,fdm,acz,acx,acy); sf_complexwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfp); cut3d_complex(uox_p,uc,fdm,acz,acx,acy); sf_complexwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfp); cut3d_complex(uoy_p,uc,fdm,acz,acx,acy); sf_complexwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfp); /* S wave */ cut3d_complex(uoz_s,uc,fdm,acz,acx,acy); sf_complexwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfs); cut3d_complex(uox_s,uc,fdm,acz,acx,acy); sf_complexwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfs); cut3d_complex(uoy_s,uc,fdm,acz,acx,acy); sf_complexwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfs); } lint3d_extract_complex(uoz,dd[0],cr); lint3d_extract_complex(uox,dd[1],cr); lint3d_extract_complex(uoy,dd[2],cr); if(it%jdata==0) sf_complexwrite(dd[0],nr*nc,Fdat); } if(verb) sf_warning("."); if(verb) fprintf(stderr,"\n"); /*------------------------------------------------------------*/ /* deallocate arrays */ free(dft); dft3d_finalize(); free(clr_p); free(clr_s); clr3d_finalize(); free(**ww); free(*ww); free(ww); free(ss); free(rr); free(*dd); free(dd); free(n2s_p); free(n2s_s); free(*lt_p); free(lt_p); free(*rt_p); free(rt_p); free(*lt_s); free(lt_s); free(*rt_s); free(rt_s); free(**uoz ); free(*uoz ); free(uoz) ; free(**uoz_p); free(*uoz_p); free(uoz_p); free(**uoz_s); free(*uoz_s); free(uoz_s); /*free(**upz); free(*upz); free(upz);*/ free(uo); free(uo_p); free(uo_s); /*free(up);*/ if (snap) { free(**uc); free(*uc); free(uc); } /*------------------------------------------------------------*/ exit (0); }
int main(int argc, char* argv[]) { int nx, nt, nkx, nkz, ix, it, ikx, ikz, nz, iz, nbt, nbb, nbl, nbr, nxb, nzb, isx, isz; float dt, dx, dkx, kx, dz, dkz, kz, tmpdt, pi=SF_PI, o1, o2, kx0, kz0; float **nxt, **old, **cur, **ukr, **dercur, **derold, *wav; float **vx, vx2, vx0, vx02, **vz, vz2, vz0, vz02, **yi, yi0, **se, se0; float ***aa, dx2, dz2, dx4, dz4, ct, cb, cl, cr; //top, bottom, left, right float w1, w10, w2, w20, w3, w30, h1, h10, h2, h20, h3, h30; float cosg, cosg0, cosg2, cosg02, sing, sing0, sing2, sing02; float vk, vk2, tmpvk, k2, err, dt2, kx1, kz1; kiss_fft_cpx **uk, *ctracex, *ctracez; kiss_fft_cfg cfgx, cfgxi, cfgz, cfgzi; sf_file out, velx, velz, source, yita, seta; bool opt; /* optimal padding */ // #ifdef _OPENMP // int nth; // #endif sf_init(argc,argv); out = sf_output("out"); velx = sf_input("velx"); /* velocity */ velz = sf_input("velz"); /* velocity */ yita = sf_input("yita"); /* anistropic parameter*/ source = sf_input("in"); /* source wavlet*/ seta = sf_input("seta"); /* TTI angle*/ // if (SF_FLOAT != sf_gettype(inp)) sf_error("Need float input"); if (SF_FLOAT != sf_gettype(velx)) sf_error("Need float input"); if (SF_FLOAT != sf_gettype(velz)) sf_error("Need float input"); if (SF_FLOAT != sf_gettype(source)) sf_error("Need float input"); if (SF_FLOAT != sf_gettype(seta)) sf_error("Need float input"); if (!sf_histint(velx,"n1",&nx)) sf_error("No n1= in input"); if (!sf_histfloat(velx,"d1",&dx)) sf_error("No d1= in input"); if (!sf_histint(velx,"n2",&nz)) sf_error("No n2= in input"); if (!sf_histfloat(velx,"d2",&dz)) sf_error("No d2= in input"); if (!sf_histfloat(velx,"o1",&o1)) o1=0.0; if (!sf_histfloat(velx,"o2",&o2)) o2=0.0; // if (!sf_histint(inp,"n2",&nt)) sf_error("No n2= in input"); // if (!sf_histfloat(inp,"d2",&dt)) sf_error("No d2= in input"); if (!sf_getbool("opt",&opt)) opt=true; /* 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_getfloat("err",&err)) err = 0.0001; if (!sf_getint("nbt",&nbt)) nbt=44; if (!sf_getint("nbb",&nbb)) nbb=44; if (!sf_getint("nbl",&nbl)) nbl=44; if (!sf_getint("nbr",&nbr)) nbr=44; if (!sf_getfloat("ct",&ct)) ct = 0.01; /*decaying parameter*/ if (!sf_getfloat("cb",&cb)) cb = 0.01; /*decaying parameter*/ if (!sf_getfloat("cl",&cl)) cl = 0.01; /*decaying parameter*/ if (!sf_getfloat("cr",&cr)) cr = 0.01; /*decaying parameter*/ sf_putint(out,"n1",nx); sf_putfloat(out,"d1",dx); // sf_putfloat(out,"o1",x0); sf_putint(out,"n2",nz); sf_putfloat(out,"d2",dz); sf_putint(out,"n3",nt); sf_putfloat(out,"d3",dt); sf_putfloat(out,"o1",o1); sf_putfloat(out,"o2",o2); sf_putfloat(out,"o3",0.0); nxb = nx + nbl + nbr; nzb = nz + nbt + nbb; nkx = opt? kiss_fft_next_fast_size(nxb): nxb; nkz = opt? kiss_fft_next_fast_size(nzb): nzb; if (nkx != nxb) sf_warning("nkx padded to %d",nkx); if (nkz != nzb) sf_warning("nkz padded to %d",nkz); dkx = 1./(nkx*dx); kx0 = -0.5/dx; dkz = 1./(nkz*dz); kz0 = -0.5/dz; cfgx = kiss_fft_alloc(nkx,0,NULL,NULL); cfgxi = kiss_fft_alloc(nkx,1,NULL,NULL); cfgz = kiss_fft_alloc(nkz,0,NULL,NULL); cfgzi = kiss_fft_alloc(nkz,1,NULL,NULL); uk = (kiss_fft_cpx **) sf_complexalloc2(nkx,nkz); ctracex = (kiss_fft_cpx *) sf_complexalloc(nkx); ctracez = (kiss_fft_cpx *) sf_complexalloc(nkz); wav = sf_floatalloc(nt); sf_floatread(wav,nt,source); old = sf_floatalloc2(nxb,nzb); cur = sf_floatalloc2(nxb,nzb); nxt = sf_floatalloc2(nxb,nzb); ukr = sf_floatalloc2(nxb,nzb); derold = sf_floatalloc2(nxb,nzb); dercur = sf_floatalloc2(nxb,nzb); aa = sf_floatalloc3(6,nxb,nzb); bd_init(nx,nz,nbt,nbb,nbl,nbr,ct,cb,cl,cr); vx = sf_floatalloc2(nxb,nzb); vz = sf_floatalloc2(nxb,nzb); /*input & extend velocity model*/ for (iz=nbt; iz<nz+nbt; iz++){ sf_floatread(vx[iz]+nbl,nx,velx); sf_floatread(vz[iz]+nbl,nx,velz); for (ix=0; ix<nbl; ix++){ vx[iz][ix] = vx[iz][nbl]; vz[iz][ix] = vz[iz][nbl]; } for (ix=0; ix<nbr; ix++){ vx[iz][nx+nbl+ix] = vx[iz][nx+nbl-1]; vz[iz][nx+nbl+ix] = vz[iz][nx+nbl-1]; } } for (iz=0; iz<nbt; iz++){ for (ix=0; ix<nxb; ix++){ vx[iz][ix] = vx[nbt][ix]; vz[iz][ix] = vz[nbt][ix]; } } for (iz=0; iz<nbb; iz++){ for (ix=0; ix<nxb; ix++){ vx[nz+nbt+iz][ix] = vx[nz+nbt-1][ix]; vz[nz+nbt+iz][ix] = vz[nz+nbt-1][ix]; } } vx0 =0.0; vz0 =0.0; for (iz=0; iz < nzb; iz++) { for (ix=0; ix < nxb; ix++) { vx0 += vx[iz][ix]*vx[iz][ix]; vz0 += vz[iz][ix]*vz[iz][ix]; } } vx0 = sqrtf(vx0/(nxb*nzb)); vz0 = sqrtf(vz0/(nxb*nzb)); vx02=vx0*vx0; vz02=vz0*vz0; /*input & extend anistropic model*/ yi = sf_floatalloc2(nxb,nzb); for (iz=nbt; iz<nz+nbt; iz++){ sf_floatread(yi[iz]+nbl,nx,yita); for (ix=0; ix<nbl; ix++){ yi[iz][ix] = yi[iz][nbl]; } for (ix=0; ix<nbr; ix++){ yi[iz][nx+nbl+ix] = yi[iz][nx+nbl-1]; } } for (iz=0; iz<nbt; iz++){ for (ix=0; ix<nxb; ix++){ yi[iz][ix] = yi[nbt][ix]; } } for (iz=0; iz<nbb; iz++){ for (ix=0; ix<nxb; ix++){ yi[nz+nbt+iz][ix] = yi[nz+nbt-1][ix]; } } yi0 = 0.0; for (iz=0; iz < nzb; iz++) { for (ix=0; ix < nxb; ix++) { yi0+= yi[iz][ix]*yi[iz][ix]; } } yi0 = sqrtf(yi0/(nxb*nzb)); se = sf_floatalloc2(nxb,nzb); for (iz=nbt; iz<nz+nbt; iz++){ sf_floatread(se[iz]+nbl,nx,seta); for (ix=0; ix<nbl; ix++){ se[iz][ix] = se[iz][nbl]; } for (ix=0; ix<nbr; ix++){ se[iz][nx+nbl+ix] = se[iz][nx+nbl-1]; } } for (iz=0; iz<nbt; iz++){ for (ix=0; ix<nxb; ix++){ se[iz][ix] = se[nbt][ix]; } } for (iz=0; iz<nbb; iz++){ for (ix=0; ix<nxb; ix++){ se[nz+nbt+iz][ix] = se[nz+nbt-1][ix]; } } se0 = 0.0; for (iz=0; iz < nzb; iz++) { for (ix=0; ix < nxb; ix++) { se0+= se[iz][ix]; } } se0 /= (nxb*nzb); se0 *= pi/180.0; for (iz=0; iz < nzb; iz++) { for (ix=0; ix < nxb; ix++) { se[iz][ix] *= pi/180.0; } } cosg0 = cosf(se0); cosg02 = cosg0*cosg0; sing0 = sinf(se0); sing02 = sing0*sing0; w10 = vx02*cosg02+vz02*sing02; w20 = vz02*cosg02+vx02*sing02; w30 = vx02+vz02+(vx02-vz02)*sinf(2.0*se0); h10 = sqrtf(-8.0*yi0*vx02*vz02*cosg02*sing02/(1.0+2.0*yi0)+w10*w10); h20 = sqrtf(-8.0*yi0*vx02*vz02*cosg02*sing02/(1.0+2.0*yi0)+w20*w20); h30 = sqrtf(-2.0*yi0*vx02*vz02*cosf(2.0*se0)*cosf(2.0*se0)/(1.0+2.0*yi0)+0.25*w30*w30); dt2 = dt*dt; dx2 = dx*dx; dx4 = dx2*dx2; dz2 = dz*dz; dz4 = dz2*dz2; for (iz=0; iz < nzb; iz++){ for (ix=0; ix < nxb; ix++) { vx2 = vx[iz][ix]*vx[iz][ix]; vz2 = vz[iz][ix]*vz[iz][ix]; cosg = cosf(se[iz][ix]); sing = sinf(se[iz][ix]); cosg2 = cosg*cosg; sing2 = sing*sing; w1 = vx2*cosg2+vz2*sing2; w2 = vz2*cosg2+vx2*sing2; w3 = vx2+vz2+(vx2-vz2)*sinf(2.0*se[iz][ix]); h1 = sqrtf(-8.0*yi[iz][ix]*vx2*vz2*cosg2*sing2/(1.0+2.0*yi[iz][ix])+w1*w1); h2 = sqrtf(-8.0*yi[iz][ix]*vx2*vz2*cosg2*sing2/(1.0+2.0*yi[iz][ix])+w2*w2); h3 = sqrtf(-2.0*yi[iz][ix]*vx2*vz2*cosf(2.0*se[iz][ix])*cosf(2.0*se[iz][ix])/(1.0+2.0*yi[iz][ix])+0.25*w3*w3); aa[iz][ix][4] = (w1+h1)*(dt2+(2.0*dx2-dt2*(w1+h1))/(w10+h10))/(24.0*dx4); aa[iz][ix][5] = (w2+h2)*(dt2+(2.0*dz2-dt2*(w2+h2))/(w20+h20))/(24.0*dz4); aa[iz][ix][3] = -aa[iz][ix][4]*dx2/dz2-aa[iz][ix][5]*dz2/dx2+(dt2*(w3+2.0*h3)+dx2*(w1+h1)/(w10+h10)+dz2*(w2+h2)/(w20+h20)-dt2*(w3+2.0*h3)*(w3+2.0*h3)/(w30+2.0*h30))/(12.0*dx2*dz2); aa[iz][ix][1] = -2.0*aa[iz][ix][3]-4.0*aa[iz][ix][4]-(w1+h1)/(dx2*(w10+h10)); aa[iz][ix][2] = -2.0*aa[iz][ix][3]-4.0*aa[iz][ix][5]-(w2+h2)/(dz2*(w20+h20)); aa[iz][ix][0] = -2.0*aa[iz][ix][1]-2.0*aa[iz][ix][2]-4.0*aa[iz][ix][3]-2.0*aa[iz][ix][4]-2.0*aa[iz][ix][5]; } } for (iz=0; iz < nzb; iz++) { for (ix=0; ix < nxb; ix++) { cur[iz][ix] = 0.0; } } cur[isz+nbt][isx+nbl] = wav[0]; for (iz=0; iz < nzb; iz++) { for (ix=0; ix < nxb; ix++) { old[iz][ix] = 0.0; derold[iz][ix] =cur[iz][ix]/dt; } } for (iz=nbt; iz<nz+nbt; iz++){ sf_floatwrite(cur[iz]+nbl,nx,out); } /* #ifdef _OPENMP #pragma omp parallel {nth = omp_get_num_threads();} sf_warning("using %d threads",nth); #endif */ /* propagation in time */ for (it=1; it < nt; it++) { for (iz=0; iz < nzb; iz++){ for (ix=0; ix < nxb; ix++){ nxt[iz][ix] = 0.0; uk[iz][ix].r = cur[iz][ix]; uk[iz][ix].i = 0.0; } } /* compute u(kx,kz) */ for (iz=0; iz < nzb; iz++){ /* Fourier transform x to kx */ for (ix=1; ix < nxb; ix+=2){ uk[iz][ix] = sf_cneg(uk[iz][ix]); } kiss_fft_stride(cfgx,uk[iz],ctracex,1); for (ikx=0; ikx<nkx; ikx++) uk[iz][ikx] = ctracex[ikx]; } for (ikx=0; ikx < nkx; ikx++){ /* Fourier transform z to kz */ for (ikz=1; ikz<nkz; ikz+=2){ uk[ikz][ikx] = sf_cneg(uk[ikz][ikx]); } kiss_fft_stride(cfgz,uk[0]+ikx,ctracez,nkx); for (ikz=0; ikz<nkz; ikz++) uk[ikz][ikx] = ctracez[ikz]; } /* #ifdef _OPENMP #pragma omp parallel for private(ik,ix,x,k,tmp,tmpex,tmpdt) #endif */ for (ikz=0; ikz < nkz; ikz++) { kz1 = (kz0+ikz*dkz)*2.0*pi; for (ikx=0; ikx < nkx; ikx++) { kx1 = (kx0+ikx*dkx)*2.0*pi; kx = kx1*cosg0+kz1*sing0; kz = kz1*cosg0-kx1*sing0; tmpvk = (vx02*kx*kx+vz02*kz*kz); k2 = kx1*kx1+kz1*kz1; vk2 = 0.5*tmpvk+0.5*sqrtf(tmpvk*tmpvk-8.0*yi0/(1.0+2.0*yi0)*vx02*vz02*kx*kx*kz*kz); vk = sqrtf(vk2); tmpdt = 2.0*(cosf(vk*dt)-1.0); if(!k2) tmpdt /=(k2+err); else tmpdt /= (k2); uk[ikz][ikx] = sf_crmul(uk[ikz][ikx],tmpdt); } } /* Inverse FFT*/ for (ikx=0; ikx < nkx; ikx++){ /* Inverse Fourier transform kz to z */ kiss_fft_stride(cfgzi,(kiss_fft_cpx *)uk[0]+ikx,(kiss_fft_cpx *)ctracez,nkx); for (ikz=0; ikz < nkz; ikz++) uk[ikz][ikx] = sf_crmul(ctracez[ikz],ikz%2?-1.0:1.0); } for (ikz=0; ikz < nkz; ikz++){ /* Inverse Fourier transform kx to x */ kiss_fft_stride(cfgxi,(kiss_fft_cpx *)uk[ikz],(kiss_fft_cpx *)ctracex,1); for (ikx=0; ikx < nkx; ikx++) uk[ikz][ikx] = sf_crmul(ctracex[ikx],ikx%2?-1.0:1.0); } for (iz=0; iz < nzb; iz++){ for (ix=0; ix < nxb; ix++){ ukr[iz][ix] = sf_crealf(uk[iz][ix]); ukr[iz][ix] /= (nkx*nkz); } } for (iz=2; iz < nzb-2; iz++) { for (ix=2; ix < nxb-2; ix++) { nxt[iz][ix] = ukr[iz][ix]*aa[iz][ix][0] + (ukr[iz][ix-1]+ukr[iz][ix+1])*aa[iz][ix][1] + (ukr[iz-1][ix]+ukr[iz+1][ix])*aa[iz][ix][2] + (ukr[iz-1][ix-1]+ukr[iz-1][ix+1]+ukr[iz+1][ix-1]+ukr[iz+1][ix+1])*aa[iz][ix][3] + (ukr[iz][ix-2]+ukr[iz][ix+2])*aa[iz][ix][4] + (ukr[iz-2][ix]+ukr[iz+2][ix])*aa[iz][ix][5]; } } /* nxt[0][0] = uk[0][0]*aa[0][0][0] + uk[0][1]*aa[0][0][1] + uk[1][0]*aa[0][0][2]; nxt[0][nxb-1] = uk[0][nxb-1]*aa[0][nxb-1][0] + uk[0][nxb-2]*aa[0][nxb-1][1] + uk[1][nxb-1]*aa[0][nxb-1][2]; nxt[nzb-1][0] = uk[nzb-1][0]*aa[nzb-1][0][0] + uk[nzb-1][1]*aa[nzb-1][0][1] + uk[nzb-2][0]*aa[nzb-1][0][2]; nxt[nzb-1][nxb-1] = uk[nzb-1][nxb-1]*aa[nzb-1][nxb-1][0] + uk[nzb-1][nxb-2]*aa[nzb-1][nxb-1][1] + uk[nzb-2][nxb-1]*aa[nzb-1][nxb-1][2]; for (ix=1; ix < nxb-1; ix++) { nxt[0][ix] = uk[0][ix]*aa[0][ix][0] + (uk[0][ix-1]+uk[0][ix+1])*aa[0][ix][1] + uk[1][ix]*aa[0][ix][2]; nxt[nz-1][ix] = uk[nz-1][ix]*aa[nz-1][ix][0] + (uk[nz-1][ix-1]+uk[nz-1][ix+1])*aa[nz-1][ix][1] + uk[nz-2][ix]*aa[nz-1][ix][2]; } for (iz=1; iz < nzb-1; iz++) { nxt[iz][0] = uk[iz][0]*aa[iz][0][0] + uk[iz][1]*aa[iz][0][1] + (uk[iz-1][0]+uk[iz+1][0])*aa[iz][0][2]; nxt[iz][nx-1] = uk[iz][nx-1]*aa[iz][nx-1][0] + uk[iz][nx-2]*aa[iz][nx-1][1] + (uk[iz-1][nx-1]+uk[iz+1][nx-1])*aa[iz][nx-1][2]; } */ // nxt[isz+nbt][isx+nbl] += wav[it]; for (iz=0; iz < nzb; iz++) { for (ix=0; ix < nxb; ix++) { dercur[iz][ix]= derold[iz][ix] + nxt[iz][ix]/dt; nxt[iz][ix] = cur[iz][ix] + dercur[iz][ix]*dt; // nxt[iz][ix] += 2.0*cur[iz][ix] -old[iz][ix]; } } nxt[isz+nbt][isx+nbl] += wav[it]; bd_decay(nxt); bd_decay(dercur); for (iz=0; iz < nzb; iz++) { for(ix=0; ix < nxb; ix++) { old[iz][ix] = cur[iz][ix]; cur[iz][ix] = nxt[iz][ix]; derold[iz][ix] = dercur[iz][ix]; } } for (iz=nbt; iz<nz+nbt; iz++){ sf_floatwrite(nxt[iz]+nbl,nx,out); } } bd_close(); free(**aa); free(*aa); free(aa); free(*vx); free(*vz); free(*yi); free(*se); free(*nxt); free(*cur); free(*old); free(*dercur); free(*derold); free(*uk); free(*ukr); free(vx); free(vz); free(yi); free(se); free(nxt); free(cur); free(old); free(dercur); free(derold); free(uk); free(ukr); // sf_fileclose(vel); // sf_fileclose(inp); // sf_fileclose(out); exit(0); }
int main(int argc, char* argv[]) { int nx, nt, ix, it, isx; float dt, dx; float *old, *nxt, *cur, *sig, *a, *b1, *b2, *b3, *b4, *b5; sf_file in, out, Gmatrix, vel; int im,im2,im3,im4,im5,ip,ip2,ip3,ip4,ip5; sf_init(argc,argv); in = sf_input("in"); Gmatrix = sf_input("G"); /* velocity */ vel = sf_input("vel"); /* velocity */ out = sf_output("out"); if (SF_FLOAT != sf_gettype(in)) sf_error("Need float input"); if (SF_FLOAT != sf_gettype(Gmatrix)) sf_error("Need float input"); if (!sf_histint(vel,"n1",&nx)) sf_error("No n1= in input"); if (!sf_histfloat(vel,"d1",&dx)) sf_error("No d1= in input"); if (!sf_getint("isx",&isx)) isx=(int)(nx/2); if (!sf_getint("nt",&nt)) sf_error("No nt in input"); if (!sf_getfloat("dt",&dt)) sf_error("No dt in input"); sf_putint(out,"n1",nx); sf_putfloat(out,"d1",dx); sf_putint(out,"n2",nt); sf_putfloat(out,"d2",dt); sf_putfloat(out,"o2",0.0); sig = sf_floatalloc(nx); old = sf_floatalloc(nx); nxt = sf_floatalloc(nx); cur = sf_floatalloc(nx); a = sf_floatalloc(nx); b1 = sf_floatalloc(nx); b2 = sf_floatalloc(nx); b3 = sf_floatalloc(nx); b4 = sf_floatalloc(nx); b5 = sf_floatalloc(nx); sf_floatread(a,nx,Gmatrix); sf_floatread(b1,nx,Gmatrix); sf_floatread(b2,nx,Gmatrix); /* sf_floatread(b3,nx,Gmatrix); sf_floatread(b4,nx,Gmatrix); sf_floatread(b5,nx,Gmatrix); */ sf_floatread(sig,nx,in); /* initial conditions */ for (ix=0; ix < nx; ix++){ cur[ix] = sig[ix]; old[ix] = 0.0; nxt[ix] = 0.; } /* propagation in time */ for (it=0; it < nt; it++) { sf_floatwrite(cur,nx,out); /* Stencil */ for (ix=0; ix < nx; ix++) { im = ix-1 < 0? ix-1+nx:ix-1; im2 = ix-2 < 0? ix-2+nx:ix-2; im3 = ix-3 < 0? ix-3+nx:ix-3; im4 = ix-4 < 0? ix-4+nx:ix-4; im5 = ix-5 < 0? ix-5+nx:ix-5; ip = ix+1 > nx-1? ix+1-nx:ix+1; ip2 = ix+2 > nx-1? ix+2-nx:ix+2; ip3 = ix+3 > nx-1? ix+3-nx:ix+3; ip4 = ix+4 > nx-1? ix+4-nx:ix+4; ip5 = ix+5 > nx-1? ix+5-nx:ix+5; nxt[ix] = ( 0.5* (cur[im]+cur[ip])*b1[ix] + 0.5*(cur[im2]+cur[ip2])*b2[ix]) - old[ix] + 2.0*cur[ix]; old[ix] = cur[ix]; cur[ix] = nxt[ix]; } } exit(0); }
int main (int argc, char *argv[]) { bool both; int ir, nr, n1,n2,n3,n4, m1, m2, m3, n12, n123, nw, nj1, nj2, i3; float *u1, *u2, *p; sf_file in, out, dip; off_t pos=0; 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; n123 = n12*n3; nr = sf_leftsize(in,3); 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_getbool("both",&both)) both=false; /* if y, compute both left and right predictions */ if (1 == n3) { n4=0; if (both) sf_putint(out,"n3",2); } else { if (!sf_getint("n4",&n4)) n4=2; /* what to compute in 3-D. 0: in-line, 1: cross-line, 2: both */ if (n4 > 2) n4=2; if (2==n4) sf_putint(out,"n4",both? 4:2); if (0 != n4 || both) { sf_unpipe(in,(off_t) n123*sizeof(float)); pos = sf_tell(in); } } if (!sf_getint("order",&nw)) nw=1; /* accuracy */ if (!sf_getint("nj1",&nj1)) nj1=1; /* in-line aliasing */ if (!sf_getint("nj2",&nj2)) nj2=1; /* cross-line aliasing */ for (ir=0; ir < nr; ir++) { if (1 != n4) { /* in-line */ 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); } if (0 != n4) { /* cross-line */ u1 = sf_floatalloc(n123); u2 = sf_floatalloc(n123); p = sf_floatalloc(n123); /* read data */ sf_seek(in,pos,SEEK_SET); sf_floatread(u1,n123,in); /* read t-y dip */ sf_floatread(p,n123,dip); ap = allpass_init(nw,nj2,n1,n2,n3,p); /* apply */ allpass2(false, false, ap, u1, u2); /* write t-y destruction */ sf_floatwrite(u2,n123,out); } if (!both) continue; if (1 != n4) { /* in-line */ u1 = sf_floatalloc(n12); u2 = sf_floatalloc(n12); p = sf_floatalloc(n12); sf_seek(in,pos,SEEK_SET); 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(true, false, ap, u1, u2); /* write t-x destruction */ sf_floatwrite(u2,n12,out); } free(u1); free(u2); free(p); } if (0 != n4) { /* cross-line */ u1 = sf_floatalloc(n123); u2 = sf_floatalloc(n123); p = sf_floatalloc(n123); /* read data */ sf_seek(in,pos,SEEK_SET); sf_floatread(u1,n123,in); /* read t-y dip */ sf_floatread(p,n123,dip); ap = allpass_init(nw,nj2,n1,n2,n3,p); /* apply */ allpass2(true, false, ap, u1, u2); /* write t-y destruction */ sf_floatwrite(u2,n123,out); } } exit (0); }
int main(int argc, char* argv[]) { bool sym; float o1,d1, o2,d2, tol; int nd, n1, n2, n12, niter, rect1, rect2, nw; float **xy, *z, *m, *m2, *d; sf_file in, out, coord, pattern; sf_init(argc,argv); in = sf_input("in"); out = sf_output("out"); coord = sf_input("coord"); if (SF_FLOAT != sf_gettype(in)) sf_error("Need float input"); if (!sf_histint(in,"n1",&nd)) sf_error("No n1= in input"); if (NULL != sf_getstring("pattern")) { /* pattern file for output dimensions */ pattern = sf_input("pattern"); if (!sf_histint(pattern,"n1",&n1)) sf_error("No n1= in pattern"); if (!sf_histint(pattern,"n2",&n2)) sf_error("No n2= in pattern"); if (!sf_histfloat(pattern,"d1",&d1)) d1=1.; if (!sf_histfloat(pattern,"d2",&d2)) d2=1.; if (!sf_histfloat(pattern,"o1",&o1)) o1=0.; if (!sf_histfloat(pattern,"o2",&o2)) o2=0.; sf_fileclose(pattern); } else { if (!sf_getint("n1",&n1)) sf_error("Need n1="); if (!sf_getint("n2",&n2)) sf_error("Need n2="); if (!sf_getfloat("d1",&d1)) d1=1.; if (!sf_getfloat("d2",&d2)) d2=1.; if (!sf_getfloat("o1",&o1)) o1=0.; if (!sf_getfloat("o2",&o2)) o2=0.; } n12 = n1*n2; sf_putint(out,"n1",n1); sf_putint(out,"n2",n2); sf_putfloat(out,"d1",d1); sf_putfloat(out,"d2",d2); sf_putfloat(out,"o1",o1); sf_putfloat(out,"o2",o2); if (!sf_getint("niter",&niter)) niter=10; /* number of iterations */ xy = sf_floatalloc2(2,nd); sf_floatread(xy[0],nd*2,coord); if (!sf_getint("rect1",&rect1)) rect1=1; if (!sf_getint("rect2",&rect2)) rect2=1; /* smoothing regularization */ if (!sf_getint("nw",&nw)) nw=2; /* interpolator size */ if (!sf_getbool("sym",&sym)) sym=false; /* if y, use symmetric shaping */ if (!sf_getfloat("tol",&tol)) tol=1e-3; /* tolerance for stopping iteration */ nnshape_init(sym,nd, n1,n2, o1,o2, d1,d2, rect1,rect2, nw, 2, xy); sf_gmres_init(n12,niter); z = sf_floatalloc (n12); m = sf_floatalloc (n12); d = sf_floatalloc(nd); sf_floatread(d,nd,in); /* make right-hand side */ nnshape_back(d,z); nnshape_smooth(z); /* invert */ sf_gmres(z,m,nnshape,NULL,niter,tol,true); if (sym) nnshape_smooth(m); sf_floatwrite (m, n12, out); exit(0); }
int main(int argc, char* argv[]) { int n1,n2,n3, jump, i1,i2,i3, j; float d, *pp=NULL, *zero=NULL, *one=NULL; sf_file in=NULL, out=NULL, mask=NULL; sf_init(argc,argv); in = sf_input("in"); out = sf_output("out"); mask = sf_output("mask"); 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("jump",&jump)) jump=2; /* aliasing */ if (n2 > 1) { sf_putint(out,"n2",n2*jump); sf_putint(mask,"n2",n2*jump); if (sf_histfloat(in,"d2",&d)) { sf_putfloat(out,"d2",d/jump); sf_putfloat(mask,"d2",d/jump); } } if (n3 > 1) { sf_putint(out,"n3",n3*jump); sf_putint(mask,"n3",n3*jump); if (sf_histfloat(in,"d3",&d)) { sf_putfloat(out,"d3",d/jump); sf_putfloat(mask,"d3",d/jump); } } pp = sf_floatalloc(n1); zero = sf_floatalloc(n1); one = sf_floatalloc(n1); for (i1=0; i1 < n1; i1++) { zero[i1] = 0.; one[i1] = 1.; } for (i3=0; i3 < n3; i3++) { for (i2=0; i2 < n2; i2++) { sf_floatread(pp,n1,in); sf_floatwrite(pp,n1,out); sf_floatwrite(one,n1,mask); if (n2 >1) { for (j=0; j < jump-1; j++) { sf_floatwrite(zero,n1,out); sf_floatwrite(zero,n1,mask); } } } if (n3 > 1) { for (i2=0; i2 < n2*jump; i2++) { sf_floatwrite(zero,n1,out); sf_floatwrite(zero,n1,mask); } } } exit(0); }
int main(int argc, char* argv[]) { int i, iter, niter, p[6][2], status, *mask; float *buf, *buf2, *wht; double rn, rnp, alpha, beta; pid_t pid[6]={1,1,1,1,1,1}; off_t nm, nd, msiz, dsiz, pos; size_t nbuf, mbuf, dbuf; FILE *xfile, *Rfile, *gfile, *sfile, *Sfile; char *x, *R, *g, *s, *S, *prog; sf_file mod, dat, from, mwt, x0, known; /* input */ sf_file to, out; /* output */ extern int fseeko(FILE *stream, off_t offset, int whence); extern off_t ftello (FILE *stream); sf_init(argc,argv); dat = sf_input("in"); mod = sf_input("mod"); if (SF_FLOAT != sf_gettype(mod) || SF_FLOAT != sf_gettype(dat)) sf_error("Need float type in mod and dat"); for (i=0; i < argc-1; i++) { argv[i]=argv[i+1]; } for (i=0; i < argc-1; i++) { /* find the program to run */ if (NULL == strchr(argv[i],'=')) { /* first one without the '=' */ prog = argv[0]; argv[0] = argv[i]; argv[i] = prog; break; } } argv[argc-1] = sf_charalloc(6); snprintf(argv[argc-1],6,"adj=X"); if (!sf_getint("niter",&niter)) niter=1; /* number of iterations */ Rfile = sf_tempfile(&R,"w+b"); xfile = sf_tempfile(&x,"w+b"); gfile = sf_tempfile(&g,"w+b"); sfile = sf_tempfile(&s,"w+b"); Sfile = sf_tempfile(&S,"w+b"); fclose(Rfile); fclose(xfile); fclose(gfile); fclose(sfile); fclose(Sfile); nm = sf_filesize(mod); nd = sf_filesize(dat); /* I/O buffers */ nbuf = BUFSIZ/sizeof(float); buf = sf_floatalloc(nbuf); buf2 = sf_floatalloc(nbuf); if (NULL != sf_getstring("mwt")) { mwt = sf_input("mwt"); /* model weight */ wht = sf_floatalloc(nbuf); } else { mwt = NULL; wht = NULL; } if (NULL != sf_getstring("known")) { known = sf_input("known"); /* known model mask */ if (SF_INT != sf_gettype(known)) sf_error("Need int type in known"); mask = sf_intalloc(nbuf); } else { known = NULL; mask = NULL; } if (NULL != sf_getstring("x0")) { x0 = sf_input("x0"); /* initial model */ } else { x0 = NULL; } for (i=0; i < 6; i++) { /* make six pipes */ if (pipe(p[i]) < 0) sf_error("pipe error:"); } for (iter=0; iter < niter; iter++) { for (i=0; i < 6; i++) { /* fork six children */ if ((pid[i] = fork()) < 0) sf_error("fork error:"); if (0 == pid[i]) break; } if (0 == pid[0]) { /* feeds rr to p[0] */ close(p[0][0]); close(STDOUT_FILENO); DUP(p[0][1]); to = sf_output("out"); if (0 == iter) { xfile = fopen(x,"wb"); if (NULL == x0) { for (i=0; i < nbuf; i++) { buf[i] = 0.0f; } } MLOOP( if (NULL != x0) sf_floatread(buf,mbuf,x0); MWRITE(xfile); ); fclose(xfile); Rfile = fopen(R,"wb"); DLOOP( sf_floatread(buf,dbuf,dat); for (i=0; i < dbuf; i++) { buf[i] = -buf[i]; } sf_floatwrite(buf,dbuf,to); DWRITE (Rfile); );
int main(int argc, char* argv[]) { /*survey parameters*/ int nx, nz; float dx, dz; int n_srcs; int *spx, *spz; int gpz, gpx, gpl; int gpz_v, gpx_v, gpl_v; int snap; /*fft related*/ bool cmplx; int pad1; /*absorbing boundary*/ bool abc; int nbt, nbb, nbl, nbr; float ct,cb,cl,cr; /*source parameters*/ int src; /*source type*/ int nt,ntsnap; float dt,*f0,*t0,*A; /*misc*/ bool verb, ps, mig; float vref; pspar par; int nx1, nz1; /*domain of interest*/ int it; float *vel,**dat,**dat_v,**wvfld,*img; /*velocity profile*/ sf_file Fi,Fo,Fd,Fd_v,snaps; /* I/O files */ sf_axis az,ax; /* cube axes */ sf_init(argc,argv); if (!sf_getint("snap",&snap)) snap=0; /* interval for snapshots */ if (!sf_getbool("cmplx",&cmplx)) cmplx=true; /* use complex fft */ if (!sf_getint("pad1",&pad1)) pad1=1; /* padding factor on the first axis */ if(!sf_getbool("abc",&abc)) abc=false; /* absorbing flag */ if (abc) { if(!sf_getint("nbt",&nbt)) sf_error("Need nbt!"); if(!sf_getint("nbb",&nbb)) nbb = nbt; if(!sf_getint("nbl",&nbl)) nbl = nbt; if(!sf_getint("nbr",&nbr)) nbr = nbt; if(!sf_getfloat("ct",&ct)) sf_error("Need ct!"); if(!sf_getfloat("cb",&cb)) cb = ct; if(!sf_getfloat("cl",&cl)) cl = ct; if(!sf_getfloat("cr",&cr)) cr = ct; } else { nbt = 0; nbb = 0; nbl = 0; nbr = 0; ct = 0; cb = 0; cl = 0; cr = 0; } if (!sf_getbool("verb",&verb)) verb=false; /* verbosity */ if (!sf_getbool("ps",&ps)) ps=false; /* use pseudo-spectral */ if (ps) sf_warning("Using pseudo-spectral..."); else sf_warning("Using pseudo-analytical..."); if (!sf_getbool("mig",&mig)) mig=false; /* use pseudo-spectral */ if (mig) sf_warning("Time-reversal propagation"); else sf_warning("Forward modeling"); if (!sf_getfloat("vref",&vref)) vref=1500; /* reference velocity (default using water) */ /* setup I/O files */ Fi = sf_input ("in"); Fo = sf_output("out"); if (mig) { gpl = -1; gpl_v = -1; if (NULL==sf_getstring("dat") && NULL==sf_getstring("dat_v")) sf_error("Need Data!"); if (NULL!=sf_getstring("dat")) { Fd = sf_input("dat"); sf_histint(Fd,"n1",&nt); sf_histfloat(Fd,"d1",&dt); sf_histint(Fd,"n2",&gpl); } else Fd = NULL; if (NULL!=sf_getstring("dat_v")) { Fd_v = sf_input("dat_v"); sf_histint(Fd_v,"n1",&nt); sf_histfloat(Fd_v,"d1",&dt); sf_histint(Fd_v,"n2",&gpl_v); } else Fd_v = NULL; src = -1; n_srcs = -1; spx = NULL; spz = NULL; f0 = NULL; t0 = NULL; A = NULL; } else { Fd = NULL; if (!sf_getint("nt",&nt)) sf_error("Need nt!"); if (!sf_getfloat("dt",&dt)) sf_error("Need dt!"); if (!sf_getint("gpl",&gpl)) gpl = -1; /* geophone length */ if (!sf_getint("gpl_v",&gpl_v)) gpl_v = -1; /* geophone height */ if (!sf_getint("src",&src)) src=0; /* source type */ if (!sf_getint("n_srcs",&n_srcs)) n_srcs=1; /* source type */ spx = sf_intalloc(n_srcs); spz = sf_intalloc(n_srcs); f0 = sf_floatalloc(n_srcs); t0 = sf_floatalloc(n_srcs); A = sf_floatalloc(n_srcs); if (!sf_getints("spx",spx,n_srcs)) sf_error("Need spx!"); /* shot position x */ if (!sf_getints("spz",spz,n_srcs)) sf_error("Need spz!"); /* shot position z */ if (!sf_getfloats("f0",f0,n_srcs)) sf_error("Need f0! (e.g. 30Hz)"); /* wavelet peak freq */ if (!sf_getfloats("t0",t0,n_srcs)) sf_error("Need t0! (e.g. 0.04s)"); /* wavelet time lag */ if (!sf_getfloats("A",A,n_srcs)) sf_error("Need A! (e.g. 1)"); /* wavelet amplitude */ } if (!sf_getint("gpx",&gpx)) gpx = -1; /* geophone position x */ if (!sf_getint("gpz",&gpz)) gpz = -1; /* geophone position z */ if (!sf_getint("gpx_v",&gpx_v)) gpx_v = -1; /* geophone position x */ if (!sf_getint("gpz_v",&gpz_v)) gpz_v = -1; /* geophone position z */ if (SF_FLOAT != sf_gettype(Fi)) sf_error("Need float input"); /* Read/Write axes */ az = sf_iaxa(Fi,1); nz = sf_n(az); dz = sf_d(az); ax = sf_iaxa(Fi,2); nx = sf_n(ax); dx = sf_d(ax); nz1 = nz-nbt-nbb; nx1 = nx-nbl-nbr; if (gpx==-1) gpx = nbl; if (gpz==-1) gpz = nbt; if (gpl==-1) gpl = nx1; if (gpx_v==-1) gpx_v = nbl; if (gpz_v==-1) gpz_v = nbt; if (gpl_v==-1) gpl_v = nz1; ntsnap=0; if (snap) for (it=0;it<nt;it++) if (it%snap==0) ntsnap++; if (mig) { /*output final wavefield*/ sf_setn(az,nz1); sf_setn(ax,nx1); sf_oaxa(Fo,az,1); sf_oaxa(Fo,ax,2); sf_settype(Fo,SF_FLOAT); } else { /*output data*/ sf_setn(ax,gpl); /*output horizontal data is mandatory*/ sf_putint(Fo,"n1",nt); sf_putfloat(Fo,"d1",dt); sf_putfloat(Fo,"o1",0.); sf_putstring(Fo,"label1","Time"); sf_putstring(Fo,"unit1","s"); sf_oaxa(Fo,ax,2); sf_settype(Fo,SF_FLOAT); /*output vertical data is optional*/ if (NULL!=sf_getstring("dat_v")) { Fd_v = sf_output("dat_v"); sf_setn(az,gpl_v); sf_putint(Fd_v,"n1",nt); sf_putfloat(Fd_v,"d1",dt); sf_putfloat(Fd_v,"o1",0.); sf_putstring(Fd_v,"label1","Time"); sf_putstring(Fd_v,"unit1","s"); sf_oaxa(Fd_v,az,2); sf_settype(Fd_v,SF_FLOAT); } else Fd_v = NULL; } if (snap > 0) { snaps = sf_output("snaps"); /* (optional) snapshot file */ sf_setn(az,nz1); sf_setn(ax,nx1); sf_oaxa(snaps,az,1); sf_oaxa(snaps,ax,2); sf_putint(snaps,"n3",ntsnap); sf_putfloat(snaps,"d3",dt*snap); sf_putfloat(snaps,"o3",0.); sf_putstring(snaps,"label3","Time"); sf_putstring(snaps,"unit3","s"); } else snaps = NULL; par = (pspar) sf_alloc(1,sizeof(*par)); vel = sf_floatalloc(nz*nx); if (mig && NULL==Fd) dat = NULL; else dat = sf_floatalloc2(nt,gpl); if (NULL!=Fd_v) dat_v = sf_floatalloc2(nt,gpl_v); else dat_v = NULL; if (mig) img = sf_floatalloc(nz1*nx1); else img = NULL; if (snap>0) wvfld = sf_floatalloc2(nx1*nz1,ntsnap); else wvfld = NULL; sf_floatread(vel,nz*nx,Fi); if (mig) { if (NULL!=Fd) sf_floatread(dat[0],gpl*nt,Fd); if (NULL!=Fd_v) sf_floatread(dat_v[0],gpl_v*nt,Fd_v); } /*passing the parameters*/ par->nx = nx; par->nz = nz; par->dx = dx; par->dz = dz; par->n_srcs= n_srcs; par->spx = spx; par->spz = spz; par->gpz = gpz; par->gpx = gpx; par->gpl = gpl; par->gpz_v = gpz_v; par->gpx_v = gpx_v; par->gpl_v = gpl_v; par->snap = snap; par->cmplx = cmplx; par->pad1 = pad1; par->abc = abc; par->nbt = nbt; par->nbb = nbb; par->nbl = nbl; par->nbr = nbr; par->ct = ct; par->cb = cb; par->cl = cl; par->cr = cr; par->src = src; par->nt = nt; par->dt = dt; par->f0 = f0; par->t0 = t0; par->A = A; par->verb = verb; par->ps = ps; par->vref = vref; /*do the work*/ psp(wvfld, dat, dat_v, img, vel, par, mig); if (mig) { sf_floatwrite(img,nz1*nx1,Fo); } else { sf_floatwrite(dat[0],gpl*nt,Fo); if (NULL!=Fd_v) sf_floatwrite(dat_v[0],gpl_v*nt,Fd_v); } if (snap>0) sf_floatwrite(wvfld[0],nz1*nx1*ntsnap,snaps); exit (0); }
int main(int argc, char* argv[]) { int nx, nt, ix, it, isx; float dt, dx; float *old, *nxt, *cur, *sig, *v; sf_file in, out, vel; int im,im2,im3,im4,im5,ip,ip2,ip3,ip4,ip5; sf_init(argc,argv); in = sf_input("in"); vel = sf_input("vel"); /* velocity */ out = sf_output("out"); if (SF_FLOAT != sf_gettype(in)) sf_error("Need float input"); if (!sf_histint(vel,"n1",&nx)) sf_error("No n1= in input"); if (!sf_histfloat(vel,"d1",&dx)) sf_error("No d1= in input"); if (!sf_getint("isx",&isx)) isx=(int)(nx/2); if (!sf_getint("nt",&nt)) sf_error("No nt in input"); if (!sf_getfloat("dt",&dt)) sf_error("No dt in input"); sf_putint(out,"n1",nx); sf_putfloat(out,"d1",dx); sf_putint(out,"n2",nt); sf_putfloat(out,"d2",dt); sf_putfloat(out,"o2",0.0); sig = sf_floatalloc(nx); old = sf_floatalloc(nx); nxt = sf_floatalloc(nx); cur = sf_floatalloc(nx); v = sf_floatalloc(nx); sf_floatread(v,nx,vel); sf_floatread(sig,nx,in); /* initial conditions */ for (ix=0; ix < nx; ix++){ cur[ix] = sig[ix]; old[ix] = 0.0; nxt[ix] = 0.; } /* propagation in time */ for (it=0; it < nt; it++) { sf_floatwrite(cur,nx,out); /* Stencil */ for (ix=0; ix < nx; ix++) { im =(ix-1+nx)%nx; im2 =(ix-2+nx)%nx; im3 =(ix-3+nx)%nx; im4 =(ix-4+nx)%nx; im5 =(ix-5+nx)%nx; ip = (ix+1+nx)%nx; ip2 =(ix+2+nx)%nx; ip3 =(ix+3+nx)%nx; ip4 =(ix+4+nx)%nx; ip5 =(ix+5+nx)%nx; nxt[ix] = dt*dt/(12.0*dx*dx)*(-30.0*cur[ix] +16.0* (cur[im]+cur[ip]) - (cur[im2]+cur[ip2]))*v[ix]*v[ix] +2.0*cur[ix]- old[ix]; } for (ix=0; ix < nx; ix++) { old[ix] = cur[ix]; cur[ix] = nxt[ix]; } } exit(0); }
int main(int argc, char* argv[]) { int nx, nt, ix, it, what; float dt, dx, w, g, a0, a1, a2, a3, a4, a5; float *old, *nxt, *cur, *sig, *v, *vx, **a; sf_file inp, out, vel, grad; sf_init(argc,argv); inp = sf_input("in"); out = sf_output("out"); vel = sf_input("vel"); /* velocity */ grad = sf_input("grad"); /* velocity gradient */ if (SF_FLOAT != sf_gettype(inp)) sf_error("Need float input"); if (!sf_histint(vel,"n1",&nx)) sf_error("No n1= in input"); if (!sf_histfloat(vel,"d1",&dx)) sf_error("No d1= in input"); if (!sf_histint(inp,"n1",&nt)) sf_error("No n2= in input"); if (!sf_histfloat(inp,"d1",&dt)) sf_error("No d2= in input"); sf_putint(out,"n1",nx); sf_putfloat(out,"d1",dx); sf_putint(out,"n2",nt); sf_putfloat(out,"d2",dt); if (!sf_getint("what",&what)) what=2; /* 2nd or 4th order for FD*/ sig = sf_floatalloc(nt); old = sf_floatalloc(nx); nxt = sf_floatalloc(nx); cur = sf_floatalloc(nx); v = sf_floatalloc(nx); vx = sf_floatalloc(nx); sf_floatread(v,nx,vel); sf_floatread(vx,nx,grad); sf_fileclose(vel); sf_fileclose(grad); sf_floatread(sig,nt,inp); switch(what) { case 2: /* 2nd order FD*/ a = sf_floatalloc2(3,nx); for (ix=0; ix < nx; ix++) { /* dimensionless velocity */ w = v[ix] * dt/dx; /* dimensionless gradient */ g = 0.5 * vx[ix] * dt; a1 = w*w * (1.0 + g*g); a2= g*w; a[ix][0] = a1+a2; a[ix][1] = -2*a1; a[ix][2] = a1-a2; /* initial conditions */ cur[ix] = 0.; nxt[ix] = 0.; } free(v); free(vx); /* propagation in time */ for (it=0; it < nt; it++) { for (ix=0; ix < nx; ix++) { old[ix] = cur[ix]; cur[ix] = nxt[ix]; } /* Stencil */ nxt[0] = sig[it]; for (ix=1; ix < nx-1; ix++) { nxt[ix] = cur[ix]*a[ix][1] + cur[ix+1]*a[ix][0] + cur[ix-1]*a[ix][2]; } nxt[nx-1] = cur[nx-1]*a[nx-1][1] + cur[nx-1]*a[nx-1][0] + cur[nx-2]*a[nx-1][2]; for (ix=1; ix < nx; ix++) { nxt[ix] += 2*cur[ix] - old[ix]; } sf_floatwrite(nxt,nx,out); } break; case 4: /* 4th order FD*/ a = sf_floatalloc2(5,nx); for (ix=0; ix < nx; ix++) { /* dimensionless velocity */ w = v[ix] * dt/dx; /* dimensionless gradient */ g = vx[ix] * dt; a1 = w*w * (4.0 + g*g); a2 = w*w*w*w*(16.0+24.0*g*g+g*g*g*g); a3 = w*g; a4 = w*w*w*g*(12.0+g*g); a[ix][0] = -a1/48.0+a2/192.0-a3/12.0+a4/48.0; a[ix][1] = a1/3.0-a2/48.0+2.0*a3/3.0-a4/24.0; a[ix][2] = -5.0*a1/8.0+a2/32.0; a[ix][3] = a1/3.0-a2/48.0-2.0*a3/3.0+a4/24.0; a[ix][4] = -a1/48.0+a2/192.0+a3/12.0-a4/48.0; /* initial conditions */ cur[ix] = 0.; nxt[ix] = 0.; } free(v); free(vx); /* propagation in time */ for (it=0; it < nt; it++) { for (ix=0; ix < nx; ix++) { old[ix] = cur[ix]; cur[ix] = nxt[ix]; } /* Stencil */ nxt[0] = sig[it]; nxt[1] = cur[0]*a[1][4] +cur[0]*a[1][3] +cur[1]*a[1][2] + cur[2]*a[1][1] + cur[3]*a[1][0]; for (ix=2; ix < nx-2; ix++) { nxt[ix] = cur[ix+2]*a[ix][0] + cur[ix+1]*a[ix][1] + cur[ix]*a[ix][2] + cur[ix-1]*a[ix][3] + cur[ix-2]*a[ix][4]; } nxt[nx-2] = cur[nx-4]*a[nx-2][4] + cur[nx-3]*a[nx-2][3] + cur[nx-2]*a[nx-2][2] + cur[nx-1]*a[nx-2][1] + cur[nx-1]*a[nx-2][0]; nxt[nx-1] = cur[nx-3]*a[nx-1][4] + cur[nx-2]*a[nx-1][3] + cur[nx-1]*a[nx-1][2] + cur[nx-1]*a[nx-1][1] + cur[nx-1]*a[nx-1][0]; for (ix=1; ix < nx; ix++) { nxt[ix] += 2*cur[ix] - old[ix]; } sf_floatwrite(nxt,nx,out); } break; case 8: /* 4th order FD*/ a = sf_floatalloc2(7,nx); for (ix=0; ix < nx; ix++) { /* dimensionless velocity */ w = v[ix] * dt/dx; /* dimensionless gradient */ g = vx[ix] * dt; a0 = w*g; a1 = w*w*(4.0 + g*g); a2 = w*w*w*g*(12.0+g*g); a3 = pow(w,4)*(16.0+24.0*g*g+pow(g,4)); a4 = pow(w,5)*g*(80.0+40.0*g*g+pow(g,4)); a5 = pow(w,6)*(64.0+240.0*g*g+60.0*pow(g,4)+pow(g,6)); a[ix][0] = (384.0*a0+64.0*a1-120.0*a2-20.0*a3+6.0*a4+a5)/23040.0; a[ix][1] = -(576.0*a0+144.0*a1-160.0*a2-40.0*a3+4.0*a4+a5)/3840.0; a[ix][2] = (1152.0*a0+576.0*a1-104.0*a2-52.0*a3+2.0*a4+a5)/1536.0; a[ix][3] = -(784.0*a1-56.0*a3+a5)/1152.0; a[ix][4] = (-1152.0*a0+576.0*a1+104.0*a2-52.0*a3-2.0*a4+a5)/1536.0; a[ix][5] = -(-576.0*a0+144.0*a1+160.0*a2-40.0*a3-4.0*a4+a5)/3840.0; a[ix][6] = (-384.0*a0+64.0*a1+120.0*a2-20.0*a3-6.0*a4+a5)/23040.0; /* initial conditions */ cur[ix] = 0.; nxt[ix] = 0.; } free(v); free(vx); /* propagation in time */ for (it=0; it < nt; it++) { for (ix=0; ix < nx; ix++) { old[ix] = cur[ix]; cur[ix] = nxt[ix]; } /* Stencil */ nxt[0] = sig[it]; nxt[1] = cur[0]*a[1][6] +cur[0]*a[1][5] +cur[0]*a[1][4] +cur[1]*a[1][3] +cur[2]*a[1][2] + cur[3]*a[1][1] + cur[4]*a[1][0]; nxt[2] = cur[0]*a[1][6] +cur[0]*a[1][5] +cur[1]*a[1][4] +cur[2]*a[1][3] +cur[3]*a[1][2] + cur[4]*a[1][1] + cur[5]*a[1][0]; for (ix=3; ix < nx-3; ix++) { nxt[ix] = cur[ix+3]*a[ix][0] +cur[ix+2]*a[ix][1] + cur[ix+1]*a[ix][2] + cur[ix]*a[ix][3] + cur[ix-1]*a[ix][4] + cur[ix-2]*a[ix][5]+ cur[ix-3]*a[ix][6]; } nxt[nx-3] = cur[nx-6]*a[nx-3][6] + cur[nx-5]*a[nx-3][5] + cur[nx-4]*a[nx-3][4] + cur[nx-3]*a[nx-3][3] + cur[nx-2]*a[nx-3][2]+ cur[nx-1]*a[nx-3][1] + cur[nx-1]*a[nx-3][0]; nxt[nx-2] = cur[nx-5]*a[nx-2][6] + cur[nx-4]*a[nx-2][5] + cur[nx-3]*a[nx-2][4] + cur[nx-2]*a[nx-2][3] + cur[nx-1]*a[nx-2][2] + cur[nx-1]*a[nx-2][1] + cur[nx-1]*a[nx-2][0]; nxt[nx-1] = cur[nx-4]*a[nx-1][6] + cur[nx-3]*a[nx-1][5] + cur[nx-2]*a[nx-1][4] + cur[nx-1]*a[nx-1][3] + cur[nx-1]*a[nx-1][2] + cur[nx-1]*a[nx-1][1] + cur[nx-1]*a[nx-1][0]; for (ix=1; ix < nx; ix++) { nxt[ix] += 2*cur[ix] - old[ix]; } sf_floatwrite(nxt,nx,out); } } exit(0); }
int main (int argc, char *argv[]) { int adj; /* forward or adjoint */ int eic; /* EIC or CIC */ bool verb; /* verbosity */ float eps; /* dip filter constant */ int nrmax; /* number of reference velocities */ float dtmax; /* time error */ int pmx,pmy; /* padding in the k domain */ int tmx,tmy; /* boundary taper size */ int nhx, nhy, nhz, nht, nc; int nhx2,nhy2,nhz2,nht2; float dht, oht; sf_axis amx,amy,az; sf_axis alx,aly; sf_axis aw,ae,ac,aa; sf_axis ahx,ahy,ahz,aht; /* I/O files */ sf_file Bws=NULL; /* background wavefield file Bws */ sf_file Bwr=NULL; /* background wavefield file Bwr */ sf_file Bs=NULL; /* background slowness file Bs */ sf_file Ps=NULL; /* slowness perturbation file Ps */ sf_file Pi=NULL; /* image perturbation file Pi */ sf_file Fc=NULL; /* CIP coordinates */ sf_file Pws=NULL; /* perturbed wavefield file Pws */ sf_file Pwr=NULL; /* perturbed wavefield file Pwr */ sf_file Pti=NULL; int ompnth=1; wexcub3d cub; /* wavefield hypercube */ wexcip3d cip; /* CIP gathers */ wextap3d tap; /* tapering */ wexssr3d ssr; /* SSR operator */ wexlsr3d lsr; /* LSR operator */ wexslo3d slo; /* slowness */ wexmvaop3d mva; float dsmax; /*------------------------------------------------------------*/ sf_init(argc,argv); /* OMP parameters */ #ifdef _OPENMP ompnth=omp_init(); #endif if (!sf_getbool( "verb",&verb )) verb = true; /* verbosity flag */ if (!sf_getint( "adj",&adj )) sf_error("Specify adjoint!"); /* y=ADJ Back-projection; n=FWD Forward Scattering */ if (!sf_getint( "feic",&eic )) sf_error("Specify EIC!"); /* extended I.C. flag */ if (!sf_getfloat( "eps",&eps )) eps = 0.01; /* stability parameter */ if (!sf_getint( "nrmax",&nrmax)) nrmax = 1; /* max number of refs */ if (!sf_getfloat("dtmax",&dtmax)) dtmax = 0.004; /* max time error */ if (!sf_getint( "pmx",&pmx )) pmx = 0; /* padding on x */ if (!sf_getint( "pmy",&pmy )) pmy = 0; /* padding on y */ if (!sf_getint( "tmx",&tmx )) tmx = 0; /* taper on x */ if (!sf_getint( "tmy",&tmy )) tmy = 0; /* taper on y */ ae = sf_maxa(1,0,1); nhx=nhy=nhz=nht=nc=nhx2=nhy2=nhz2=nht2=0; oht = dht = 0.0; /*------------------------------------------------------------*/ /* slowness */ Bs = sf_input("slo"); alx = sf_iaxa(Bs,1); sf_setlabel(alx,"lx"); aly = sf_iaxa(Bs,2); sf_setlabel(aly,"ly"); az = sf_iaxa(Bs,3); sf_setlabel(az, "z"); /*------------------------------------------------------------*/ /* input file */ if(adj) Pi = sf_input("in"); else Ps = sf_input("in"); /*------------------------------------------------------------*/ /* wavefield */ Bws = sf_input("swfl"); Bwr = sf_input("rwfl"); amx = sf_iaxa(Bws,1); sf_setlabel(amx,"mx"); amy = sf_iaxa(Bws,2); sf_setlabel(amy,"my"); aw = sf_iaxa(Bws,4); sf_setlabel(aw ,"w" ); Pws = sf_tmpfile(NULL); sf_settype(Pws,SF_COMPLEX); Pwr = sf_tmpfile(NULL); sf_settype(Pwr,SF_COMPLEX); /*------------------------------------------------------------*/ cub = wex_cube(verb, amx,amy,az, alx,aly, aw, ae, eps, ompnth); dsmax = dtmax/cub->az.d; /*------------------------------------------------------------*/ /* init structures */ tap = wextap_init(cub->amx.n, cub->amy.n, 1, SF_MIN(tmx,cub->amx.n-1), /* tmx */ SF_MIN(tmy,cub->amy.n-1), /* tmy */ 0, true,true,false); slo = wexslo_init(cub,Bs,nrmax,dsmax); ssr = wexssr_init(cub,slo,pmx,pmy,tmx,tmy,dsmax); lsr = wexlsr_init(cub,pmx,pmy,dsmax); /*------------------------------------------------------------*/ Pti = sf_tmpfile(NULL); sf_settype(Pti,SF_COMPLEX); /*------------------------------------------------------------*/ /* WEMVA */ if(adj) { sf_warning("adjoint operator..."); if(eic){ ahx = sf_iaxa(Pi,1); sf_setlabel(ahx,"hx"); ahy = sf_iaxa(Pi,2); sf_setlabel(ahy,"hy"); ahz = sf_iaxa(Pi,3); sf_setlabel(ahz,"hz"); aht = sf_iaxa(Pi,4); sf_setlabel(aht,"ht"); dht = sf_d(aht); oht = sf_o(aht); nhx2 = sf_n(ahx); nhx = (nhx2-1)/2; nhy2 = sf_n(ahy); nhy = (nhy2-1)/2; nhz2 = sf_n(ahz); nhz = (nhz2-1)/2; nht2 = sf_n(aht); nht = (nht2-1)/2; /* CIP coordinates */ Fc = sf_input ("cc" ); ac = sf_iaxa(Fc,2); sf_setlabel(ac,"cc"); sf_setunit(ac,""); nc = sf_n(ac); } cip = wexcip_init(cub,nhx,nhy,nhz,nht,nhx2,nhy2,nhz2,nht2,nc,dht,oht,Fc,eic); mva = wexmva_init(cub,cip); Ps = sf_output("out"); sf_settype(Ps,SF_COMPLEX); sf_oaxa(Ps,amx,1); sf_oaxa(Ps,amy,2); sf_oaxa(Ps,az, 3); if(eic){ sf_oaxa(Ps,ae, 4); sf_oaxa(Ps,ae, 5);} /* Adjoint I.C. operator, dI -> dW */ wexcip_adj(cub,cip,Bwr,Pws,Pi,eic,1,1); /* Ws dR */ wexcip_adj(cub,cip,Bws,Pwr,Pi,eic,0,0); /* Wr dR */ sf_filefresh(Pws); sf_filefresh(Pwr); /* Adjoint WEMVA operator, dW -> dS */ wexmva(mva,adj,cub,ssr,lsr,tap,slo,Bws,Bwr,Pws,Pwr,Ps); } else { /* set up the I/O of output CIP gathers */ Pi = sf_output("out"); sf_settype(Pi,SF_COMPLEX); if(eic){ /* CIP coordinates */ Fc = sf_input ("cc" ); ac = sf_iaxa(Fc,2); sf_setlabel(ac,"cc"); sf_setunit(ac,""); nc = sf_n(ac); if(! sf_getint("nhx",&nhx)) nhx=0; /* number of lags on the x axis */ if(! sf_getint("nhy",&nhy)) nhy=0; /* number of lags on the y axis */ if(! sf_getint("nhz",&nhz)) nhz=0; /* number of lags on the z axis */ if(! sf_getint("nht",&nht)) nht=0; /* number of lags on the t axis */ if(! sf_getfloat("dht",&dht)) sf_error("need dht"); oht = -nht*dht; nhx2=2*nhx+1; nhy2=2*nhy+1; nhz2=2*nhz+1; nht2=2*nht+1; aa=sf_maxa(nhx2,-nhx*cub->amx.d,cub->amx.d); sf_setlabel(aa,"hx"); sf_setunit(aa,""); if(verb) sf_raxa(aa); sf_oaxa(Pi,aa,1); aa=sf_maxa(nhy2,-nhy*cub->amy.d,cub->amy.d); sf_setlabel(aa,"hy"); sf_setunit(aa,""); if(verb) sf_raxa(aa); sf_oaxa(Pi,aa,2); aa=sf_maxa(nhz2,-nhz*cub->az.d,cub->az.d); sf_setlabel(aa,"hz"); sf_setunit(aa,""); if(verb) sf_raxa(aa); sf_oaxa(Pi,aa,3); aa=sf_maxa(nht2,-nht*dht,dht); sf_setlabel(aa,"ht"); sf_setunit(aa,"s"); if(verb) sf_raxa(aa); sf_oaxa(Pi,aa,4); sf_oaxa(Pi,ac,5); } else{ sf_oaxa(Pi,amx,1); sf_oaxa(Pi,amy,2); sf_oaxa(Pi,az, 3); } cip = wexcip_init(cub,nhx,nhy,nhz,nht,nhx2,nhy2,nhz2,nht2,nc,dht,oht,Fc,eic); mva = wexmva_init(cub,cip); /* WEMVA operator, dS -> dW */ wexmva(mva,adj,cub,ssr,lsr,tap,slo,Bws,Bwr,Pws,Pwr,Ps); sf_filefresh(Pws); sf_filefresh(Pwr); /* I.C. operator, dW -> dI */ wexcip_for(cub,cip,Bws,Pwr,Pti,eic,0,0); /* CONJ( Ws) dWr */ sf_seek(Pti,(off_t)0,SEEK_SET); wexcip_for(cub,cip,Pws,Bwr,Pti,eic,0,1); /* CONJ(dWs) Wr */ sf_filefresh(Pti); sf_filecopy(Pi,Pti,SF_COMPLEX); } /*------------------------------------------------------------*/ /* close structures */ wexslo_close(slo); wexssr_close(cub,ssr); wextap2D_close(tap); wexmva_close(mva); wexcip_close(cip,eic); /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* close files */ if (Ps!=NULL) sf_fileclose(Ps); if (Fc!=NULL) sf_fileclose(Fc); if (Pi!=NULL) sf_fileclose(Pi); if (Bws!=NULL) sf_fileclose(Bws); if (Bwr!=NULL) sf_fileclose(Bwr); if (Pws!=NULL) sf_tmpfileclose(Pws); if (Pwr!=NULL) sf_tmpfileclose(Pwr); if (Pti!=NULL) sf_tmpfileclose(Pti); /*------------------------------------------------------------*/ exit (0); }
int main (int argc, char* argv[]) { int n1,n2,n3; /*n1 is trace length, n2 is the number of traces, n3 is the number of 3th axis*/ int nfw; /*nfw is the filter-window length*/ int m; int i,j,k,ii; bool boundary; float *trace; float *tempt; float *temp1; float *extendt; sf_file in, out; sf_init (argc, argv); in = sf_input("in"); out = sf_output("out"); if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(in,"n2",&n2)) sf_error("No n2= in input"); n3 = sf_leftsize(in,2); /* get the trace length (n1) and the number of traces (n2) and n3*/ if (!sf_getint("nfw",&nfw)) sf_error("Need integer input"); /* filter-window length (positive and odd integer)*/ if (!sf_getbool("boundary",&boundary)) boundary=false; /* if y, boundary is data, whereas zero*/ if (nfw < 1) sf_error("Need positive integer input"); if (nfw%2 == 0) nfw++; m=(nfw-1)/2; trace = sf_floatalloc(n1*n2); tempt = sf_floatalloc(n1*n2); temp1 = sf_floatalloc(nfw); extendt = sf_floatalloc((n1+2*m)*n2); for(ii=0;ii<n3;ii++){ sf_floatread(trace,n1*n2,in); for(i=0;i<n1*n2;i++){ tempt[i]=trace[i]; } bound1(tempt,extendt,nfw,n1,n2,boundary); /************1D median filter****************/ for(i=0;i<n2;i++){ for(j=0;j<n1;j++){ for(k=0;k<nfw;k++){ temp1[k]=extendt[(n1+2*m)*i+j+k]; } trace[n1*i+j]=sf_quantile(m,nfw,temp1); } } sf_floatwrite(trace,n1*n2,out); } exit (0); }
int main(int argc, char* argv[]) { float *data /*input [nk] */; int nk /* data length */; float dk /* data sampling */; float k0 /* initial location */; bool verb /* verbosity flag */; int niter /* number of iterations */; int ik, iter; float x1, x2, x3, dx1, dx2, dx3, x10, x20, x30, x4, x5; float k, f, s, l, r, p, q, s2, y1, y2, y3, sk, s1, s3; float a11, a12, a13, a22, a23, a33, a2, a3, a4, a5, a6, d; float b11, b12, b13, b22, b23, b33, eps, r2; sf_file in, out, prm; /* Estimate shape (Caution: data gets corrupted) */ sf_init (argc,argv); in = sf_input("in"); out = sf_output("out"); prm = sf_output("prm"); if (SF_FLOAT != sf_gettype(in)) sf_error("Need float input"); if (!sf_histint(in,"n1",&nk)) sf_error("No n1= in input"); if (!sf_histfloat(in,"d1",&dk)) sf_error("No d1= in input"); if (!sf_histfloat(in,"o1",&k0)) sf_error("No o1= in input"); if (!sf_getint("niter",&niter)) niter=100; /* number of iterations */ if (!sf_getfloat("x10",&x10)) x10=6.; /* initial nonlinear parameter x1 value */ if (!sf_getfloat("x20",&x20)) x20=-0.5; /* initial nonlinear parameter x2 value */ if (!sf_getfloat("x30",&x30)) x30=200.; /* initial nonlinear parameter x3 value */ if (!sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ sf_putint(prm,"n1",3); sf_putint(prm,"nk",nk); sf_putfloat(prm,"dk",dk); sf_putfloat(prm,"k0",k0); sf_fileflush(prm,in); data = sf_floatalloc(nk); sf_floatread(data,nk,in); x1 = x10; /* initial x1 */ x2 = x20; /* initial x2 */ x3 = x30; /* initial x3 */ x4 = x3*x3; eps = 10.*FLT_EPSILON; eps *= eps; a11 = (float)nk; if (verb) sf_warning("got x10=%g x20=%g x30=%g k0=%g niter=%d nk=%d dk=%g", x10,x20,x30,k0,niter,nk,dk); /* Gauss iterations */ for (iter = 0; iter < niter; iter++) { x5 = 2.*x2*x3; s2 = y1 = y2 = y3 = sk = s1 = s3 = a12 = r2 = 0.; for (ik = 0; ik < nk; ik++) { k = ik*dk + k0; k *= k; s = 1. + x4*k; l = log(s); q = 1./s; p = k*q; s2 += l*l; sk += p; a12 += l; f = log(data[ik]); r = x1 + x2*l - f; y1 += r; y2 += r*l; y3 += r*p; s1 += p*(r + x2*l); s3 += p*q*(2.*x2*x4*k + r*(1.-x4*k)); r2 += r*r; } y3 *= x5; a13 = x5*sk; a22 = s2; a23 = 2.*x3*s1; a33 = 2.*x2*s3; a2 = a12*a12; a3 = a12*a13; a4 = a13*a13; a5 = a23*a23; a6 = a22*a33; d = 1./(a11*(a6-a5) + 2.*a3*a23 - a33*a2 - a22*a4); b11 = a6-a5; b12 = a13*a23-a12*a33; b13 = a12*a23-a13*a22; b22 = a11*a33-a4; b23 = a3-a23*a11; b33 = a11*a22-a2; dx1 = -d*(b11*y1 + b12*y2 + b13*y3); dx2 = -d*(b12*y1 + b22*y2 + b23*y3); dx3 = -d*(b13*y1 + b23*y2 + b33*y3); x1 += dx1; x2 += dx2; x3 += dx3; x4 = x3*x3; if (verb) sf_warning("iter=%d r2=%g dx1=%g dx2=%g dx3=%g x1=%g x2=%g x3=%g", iter,r2,dx1,dx2,dx3,x1,x2,x3); if (r2 < eps || (dx1*dx1+dx2*dx2+dx3*dx3) < eps) break; } for (ik = 0; ik < nk; ik++) { k = ik*dk + k0; k *= k; data[ik] = exp(x1+x2*log(1.+x4*k)); } if (verb) sf_warning ("%d iterations", iter); /* Optimized parameters for f = log(data) = log(d0) + a*log(1+b*b*k*k) where a = -(nu/2+1/4) */ sf_warning ("b=%g nu=%g d0=%g",x3,-2*x2-0.5,exp(x1)); sf_floatwrite(&x3,1,prm); sf_floatwrite(&x2,1,prm); sf_floatwrite(&x1,1,prm); sf_floatwrite (data,nk,out); exit (0); }
int main (int argc, char* argv[]) { int nz, nx, ny, nb, na, iz, ix, iy, ia, ib, fz, lz; int icpu = 0, ncpu = 1, morder = 2, ic, nc = 1, mp = 1, ith = 0, inet = 0, tdel = 0; float dz, oz, dx, ox, dy, oy, db, ob, da, oa, aper; float z, x, y; float ****e; sf_file spdom, vspline = NULL, scgrid = NULL, scdaemon = NULL, out; char *ext = NULL; bool verb, parab, mmaped, rfail; sf_esc_slowness3 esc_slow; sf_esc_scglstor3 esc_scgrid_lstor; sf_esc_tracer3 *esc_tracers; sf_esc_scgrid3 *esc_scgrids; sf_timer timer; sf_init (argc, argv); if (!sf_stdin ()) { spdom = NULL; } else { spdom = sf_input ("in"); /* Spatial (z,x,y) domain */ } out = sf_output ("out"); /* Escape values */ /* Spatial dimensions */ if (spdom) { if (!sf_histint (spdom, "n1", &nz)) sf_error ("No n1= in input"); if (!sf_histint (spdom, "n2", &nx)) sf_error ("No n2= in input"); if (!sf_histint (spdom, "n3", &ny)) sf_error ("No n3= in input"); if (!sf_histfloat (spdom, "d1", &dz)) sf_error ("No d1= in input"); if (!sf_histfloat (spdom, "o1", &oz)) sf_error ("No o1= in input"); if (!sf_histfloat (spdom, "d2", &dx)) sf_error ("No d2= in input"); if (!sf_histfloat (spdom, "o2", &ox)) sf_error ("No o2= in input"); if (!sf_histfloat (spdom, "d3", &dy)) sf_error ("No d3= in input"); if (!sf_histfloat (spdom, "o3", &oy)) sf_error ("No o3= in input"); if (!sf_histint (spdom, "icpu", &icpu)) icpu = 0; /* Current CPU number */ if (!sf_histint (spdom, "ncpu", &ncpu)) ncpu = 1; /* Total number of CPUs */ } ext = sf_escst3_warnext (spdom); if (!sf_getint ("nz", &nz) && !spdom) sf_error ("Need nz="); /* Number of samples in z axis */ if (!sf_getfloat ("oz", &oz) && !spdom) sf_error ("Need oz="); /* Beginning of z axis */ if (!sf_getfloat ("dz", &dz) && !spdom) sf_error ("Need dz="); /* Sampling of z axis */ if (!sf_getint ("nx", &nx) && !spdom) sf_error ("Need nx="); /* Number of samples in x axis */ if (!sf_getfloat ("ox", &ox) && !spdom) sf_error ("Need ox="); /* Beginning of x axis */ if (!sf_getfloat ("dx", &dx) && !spdom) sf_error ("Need dx="); /* Sampling of x axis */ if (!sf_getint ("ny", &ny) && !spdom) sf_error ("Need ny="); /* Number of samples in y axis */ if (!sf_getfloat ("oy", &oy) && !spdom) sf_error ("Need oy="); /* Beginning of y axis */ if (!sf_getfloat ("dy", &dy) && !spdom) sf_error ("Need dy="); /* Sampling of y axis */ if (!sf_getint ("na", &na)) na = 360; /* Number of azimuth phase angles */ da = 2.0*SF_PI/(float)na; oa = 0.5*da; if (!sf_getint ("nb", &nb)) nb = 180; /* Number of inclination phase angles */ db = SF_PI/(float)nb; ob = 0.5*db; #ifdef _OPENMP if (!sf_getint ("mp", &mp)) mp = 1; /* Bufferization factor for multicore processing (number of points in buffer = mp*nc) */ if (!sf_getint ("nc", &nc)) nc = 0; /* Number of threads to use for ray tracing (OMP_NUM_THREADS by default) */ if (nc) omp_set_num_threads (nc); /* User override */ else nc = omp_get_max_threads (); /* Current default */ sf_warning ("%s Using %d threads", ext, omp_get_max_threads ()); sf_warning ("%s Buffering %d points", ext, nc*mp); #endif if (!sf_getfloat ("aper", &aper)) aper = SF_HUGE; /* Maximum aperture in x and y directions from current point (default - up to grid boundaries) */ if (aper != SF_HUGE) aper = fabsf (aper); if (!sf_getbool ("parab", ¶b)) parab = true; /* y - use parabolic approximation of trajectories, n - straight line */ if (!sf_getbool ("mmaped", &mmaped)) mmaped = true; /* n - do not use memory mapping for local data access */ if (!sf_getbool ("rfail", &rfail)) rfail = true; /* n - do not quit if remote processing fails, try local processing */ if (!sf_getbool ("verb", &verb)) verb = false; /* verbosity flag */ e = sf_floatalloc4 (ESC3_NUM, nb, na, nc*mp); if (!sf_getstring ("vspl")) sf_error ("Need vspl="); /* Spline coefficients for velocity model */ vspline = sf_input ("vspl"); if (!sf_getstring ("scgrid")) sf_error ("Need scgrid="); /* Grid of supercells of local escape solutions */ scgrid = sf_input ("scgrid"); if (sf_getstring ("scdaemon")) { /* Daemon for distributed computation */ scdaemon = sf_input ("scdaemon"); } if (!sf_getint ("morder", &morder)) morder = 1; /* Order of interpolation accuracy in the angular domain (1-3) */ #ifdef LINUX if (!sf_getint ("inet", &inet)) inet = 1; /* Network interface index */ #endif if (!sf_getint ("tdel", &tdel)) tdel = 0; /* Optional delay time before connecting (seconds) */ /* Slowness components module [(an)isotropic] */ esc_slow = sf_esc_slowness3_init (vspline, verb); /* Make room for escape variables in output */ if (spdom) sf_shiftdimn (spdom, out, 1, 3); sf_putint (out, "n1", ESC3_NUM); sf_putfloat (out, "o1", 0.0); sf_putfloat (out, "d1", 1.0); sf_putstring (out, "label1", "Escape variable"); sf_putstring (out, "unit1", ""); sf_putint (out, "n2", nb); sf_putfloat (out, "d2", db*180.0/SF_PI); sf_putfloat (out, "o2", ob*180.0/SF_PI); sf_putstring (out, "label2", "Inclination"); sf_putstring (out, "unit2", "Degrees"); sf_putint (out, "n3", na); sf_putfloat (out, "d3", da*180.0/SF_PI); sf_putfloat (out, "o3", oa*180.0/SF_PI); sf_putstring (out, "label3", "Azimuth"); sf_putstring (out, "unit3", "Degrees"); sf_putint (out, "n4", nz); sf_putfloat (out, "o4", oz); sf_putfloat (out, "d4", dz); if (!spdom) { sf_putstring (out, "label4", "Depth"); sf_putstring (out, "unit4", ""); } sf_putint (out, "n5", nx); sf_putfloat (out, "o5", ox); sf_putfloat (out, "d5", dx); if (!spdom) { sf_putstring (out, "label5", "X"); sf_putstring (out, "unit5", ""); } sf_putint (out, "n6", ny); sf_putfloat (out, "o6", oy); sf_putfloat (out, "d6", dy); if (!spdom) { sf_putstring (out, "label6", "Y"); sf_putstring (out, "unit6", ""); } /* Save min/max possible escape values */ sf_putfloat (out, "Zmin", sf_esc_slowness3_oz (esc_slow)); sf_putfloat (out, "Zmax", sf_esc_slowness3_oz (esc_slow) + (sf_esc_slowness3_nz (esc_slow) - 1)* sf_esc_slowness3_dz (esc_slow)); sf_putfloat (out, "Xmin", sf_esc_slowness3_ox (esc_slow)); sf_putfloat (out, "Xmax", sf_esc_slowness3_ox (esc_slow) + (sf_esc_slowness3_nx (esc_slow) - 1)* sf_esc_slowness3_dx (esc_slow)); sf_putfloat (out, "Ymin", sf_esc_slowness3_oy (esc_slow)); sf_putfloat (out, "Ymax", sf_esc_slowness3_oy (esc_slow) + (sf_esc_slowness3_ny (esc_slow) - 1)* sf_esc_slowness3_dy (esc_slow)); esc_scgrid_lstor = sf_esc_scglstor3_init (scgrid, mmaped, ext, verb); esc_tracers = (sf_esc_tracer3*)sf_alloc (nc, sizeof(sf_esc_tracer3)); esc_scgrids = (sf_esc_scgrid3*)sf_alloc (nc, sizeof(sf_esc_scgrid3)); sleep (tdel); for (ic = 0; ic < nc; ic++) { esc_tracers[ic] = sf_esc_tracer3_init (esc_slow); sf_esc_tracer3_set_parab (esc_tracers[ic], parab); esc_scgrids[ic] = sf_esc_scgrid3_init (scgrid, scdaemon, esc_tracers[ic], esc_scgrid_lstor, morder, inet, (float)icpu/(float)ncpu, ext, rfail, verb && 0 == ic); } timer = sf_timer_init (); for (iy = 0; iy < ny; iy++) { y = oy + iy*dy; /* Set aperture */ if (aper != SF_HUGE) { for (ic = 0; ic < nc; ic++) { sf_esc_scgrid3_set_ymin (esc_scgrids[ic], y - aper); sf_esc_scgrid3_set_ymax (esc_scgrids[ic], y + aper); } } for (ix = 0; ix < nx; ix++) { x = ox + ix*dx; /* Set aperture */ if (aper != SF_HUGE) { for (ic = 0; ic < nc; ic++) { sf_esc_scgrid3_set_xmin (esc_scgrids[ic], x - aper); sf_esc_scgrid3_set_xmax (esc_scgrids[ic], x + aper); } } if (verb) sf_warning ("%s Projecting from lateral location %d of %d at y=%g, x=%g;", ext, iy*nx + ix + 1, ny*nx, y, x); /* Loop over chunks */ for (ic = 0; ic < (nz/(mp*nc) + ((nz % (nc*mp)) != 0)); ic++) { fz = ic*nc*mp; lz = (ic + 1)*nc*mp - 1; if (lz >= nz) lz = nz - 1; sf_timer_start (timer); #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,1) \ private(iz,ia,ib,ith,z) \ shared(fz,lz,iy,ix,nc,mp,nb,na,nz,nx,ny,ob,oa,oz,ox,oy,db,da,dz,dx,dy,x,y,esc_tracers,esc_scgrids,e,out) #endif for (iz = fz; iz <= lz; iz++) { #ifdef _OPENMP ith = omp_get_thread_num (); #endif z = oz + iz*dz; if (sf_esc_tracer3_inside (esc_tracers[ith], &z, &x, &y, false)) { sf_esc_scgrid3_compute (esc_scgrids[ith], z, x, y, oa, da, ob, db, na, nb, e[iz - fz][0][0]); } else { for (ia = 0; ia < na; ia++) { for (ib = 0; ib < nb; ib++) { e[iz - fz][ia][ib][ESC3_Z] = z; e[iz - fz][ia][ib][ESC3_X] = x; e[iz - fz][ia][ib][ESC3_Y] = y; e[iz - fz][ia][ib][ESC3_T] = 0.0; #ifdef ESC_EQ_WITH_L e[iz - fz][ia][ib][ESC3_L] = 0.0; #endif } } } } /* Loop over z */ sf_timer_stop (timer); sf_floatwrite (e[0][0][0], (size_t)(lz - fz + 1)*(size_t)nb*(size_t)na*(size_t)ESC3_NUM, out); } /* Loop over z chunks */ } /* Loop over x */ } /* Loop over y */ if (verb) { sf_warning ("."); sf_warning ("%s Total kernel time: %g s, per depth point: %g s", ext, sf_timer_get_total_time (timer)/1000.0, (sf_timer_get_total_time (timer)/(float)((size_t)nx*(size_t)ny*(size_t)nz))/1000.0); } sf_timer_close (timer); for (ic = 0; ic < nc; ic++) { sf_esc_tracer3_close (esc_tracers[ic]); sf_esc_scgrid3_close (esc_scgrids[ic], verb); } free (esc_tracers); free (esc_scgrids); sf_esc_scglstor3_close (esc_scgrid_lstor); sf_esc_slowness3_close (esc_slow); free (e[0][0][0]); free (e[0][0]); free (e[0]); free (e); free (ext); if (scdaemon) sf_fileclose (scdaemon); sf_fileclose (scgrid); sf_fileclose (vspline); return 0; }
int main(int argc, char* argv[]) { int i1, n1, i2, n2, i3, n3, ip, np, it; float **dat=NULL, *trace=NULL, dp, p0, p, t; vint1 str; sf_file inp=NULL, out=NULL; sf_init(argc,argv); inp = sf_input("in"); out = sf_output("out"); if (!sf_histint(inp,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(inp,"n2",&n2) || n2 < 2) sf_error("No n2= in input"); n3 = sf_leftsize(inp,2); if (!sf_getint("np",&np)) sf_error("Need np="); /* number of slopes */ if (!sf_getfloat("dp",&dp)) sf_error("Need dp="); /* slope sampling */ if (!sf_getfloat("p0",&p0)) sf_error("Need p0="); /* first slope */ sf_putint(out,"n3",np); sf_putfloat(out,"d3",dp); sf_putfloat(out,"o3",p0); sf_shiftdim(inp,out,3); dat = sf_floatalloc2(n1,n2); trace = sf_floatalloc(n2); trace[n2-1] = 0.; str = vint1_init (4,n1,n2-1); for (i3=0; i3 < n3; i3++) { sf_floatread(dat[0],n1*n2,inp); vint1_set(str,dat+1); for (ip=0; ip < np; ip++) { p = p0 + ip*dp; for (i1=0; i1 < n1; i1++) { t = i1+p; it = floorf(t); if (it < -1 || it > n1) { for (i2=0; i2 < n2-1; i2++) { trace[i2]=0.; } } else { vint1_apply(str,it,t-it,false,trace); } for (i2=0; i2 < n2; i2++) { dat[i2][i1] = trace[i2]; } } sf_floatwrite(dat[0],n1*n2,out); } } exit(0); }
int main (int argc, char *argv[]) { bool verb, up2, up3; unsigned char update; int n1,n2,n3, i1,i2,i3, ns2, ns3, ip, np2, np3, n23; int order, np, i4, n4, k2, k3, j2, j3, i, jp, j; float eps, ***u, **p1, **p2, **cost, *trace, *q2=NULL, *q3=NULL; sf_file inp, out, dip; sf_init(argc,argv); inp = sf_input("in"); dip = sf_input("dip"); out = sf_output("out"); if (!sf_histint(inp,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(inp,"n2",&n2)) sf_error("No n2= in input"); if (!sf_histint(inp,"n3",&n3)) sf_error("No n3= in input"); n23 = n2*n3; n4 = sf_leftsize(inp,3); if (!sf_getbool("verb",&verb)) verb=false; /* verbosity */ if (!sf_getfloat("eps",&eps)) eps=0.01; /* regularization */ if (!sf_getint("order",&order)) order=1; /* accuracy order */ if (!sf_getint("ns2",&ns2)) sf_error("Need ns1="); if (!sf_getint("ns3",&ns3)) sf_error("Need ns2="); /* spray radius */ np2 = 2*ns2+1; np3 = 2*ns3+1; np = np2*np3; sf_putint(out,"n2",np); sf_shiftdim(inp, out, 2); cost = sf_floatalloc2(np2,np3); for (i3=0; i3 < np3; i3++) { for (i2=0; i2 < np2; i2++) { cost[i3][i2] = hypotf(i2-ns2,i3-ns3); } } predict_init (n1, n2, eps*eps, order, 1, true); update_init(np2,np3,*cost); u = sf_floatalloc3(n1,np,n23); for (i3=0; i3 < n23; i3++) { for (ip=0; ip < np; ip++) { for (i1=0; i1 < n1; i1++) { u[i3][ip][i1] = 0.; } } } p1 = sf_floatalloc2(n1,n23); p2 = sf_floatalloc2(n1,n23); for (i=0; i < n23; i++) { sf_floatread(p1[i],n1,dip); } for (i=0; i < n23; i++) { sf_floatread(p2[i],n1,dip); } for (i4=0; i4 < n4; i4++) { for (i=0; i < n23; i++) { sf_floatread(u[i][ns3*np2+ns2],n1,inp); i2 = i%n2; i3 = i/n2; for (ip=0; ip < np; ip++) { update = get_update(ip,&up2,&up3,&jp); /* from jp to j */ k2 = jp%np2; k3 = jp/np2; j2 = i2+k2-ns2; j3 = i3+k3-ns3; if (j2 < 0 || j2 >= n2 || j3 < 0 || j3 >= n3) continue; j = j2+j3*n2; trace = u[j][jp]; if (update & 1) { if (up2) { if (j2==0) continue; j2 = j-1; q2 = p1[j2]; k2 = jp-1; } else { if (j2==n2-1) continue; j2 = j+1; q2 = p1[j]; k2 = jp+1; } } if (update & 2) { if (up3) { if (j3==0) continue; j3 = j-n2; q3 = p2[j3]; k3 = jp-np2; } else { if (j3==n3-1) continue; j3 = j+n2; q3 = p2[j]; k3 = jp+np2; } } switch(update) { case 0: break; case 1: predict1_step(up2,u[j2][k2],q2,trace); break; case 2: predict1_step(up3,u[j3][k3],q3,trace); break; case 3: predict2_step(up2,up3,u[j2][k2],u[j3][k3], q2,q3,trace); break; } } } for (i=0; i < n23; i++) { for (ip=0; ip < np; ip++) { sf_floatwrite(u[i][ip],n1,out); } } } exit (0); }
int main (int argc,char* argv[]) { int i, j, ip, n1, n2, np, ndim, order, n123, *pp, n[2], box[2], **shift, b; float o1, o2, d1, d2, slow, *dd, **pts, *vv, *h, *bin, *vor, d[2], **rect; bool isvel, dist, voro; sf_upgrad upg; sf_file coord, ord, grid, vel; sf_init (argc, argv); ord = sf_input("in"); coord = sf_input("coord"); grid = sf_output("out"); if (NULL != sf_getstring("velocity")) { vel = sf_input("velocity"); if(!sf_histint(vel,"n1",&n1)) sf_error("No n1= in vel"); if(!sf_histint(vel,"n2",&n2)) sf_error("No n2= in vel"); /* dimensions */ if(!sf_histfloat(vel,"d1",&d1)) sf_error("No d1= in vel"); if(!sf_histfloat(vel,"d2",&d2)) sf_error("No d2= in vel"); /* sampling */ if(!sf_histfloat(vel,"o1",&o1)) o1=0.; if(!sf_histfloat(vel,"o2",&o2)) o2=0.; /* origin */ } else { vel = NULL; if(!sf_getint("n1",&n1)) sf_error("Need n1="); if(!sf_getint("n2",&n2)) sf_error("Need n2="); /* dimensions */ if(!sf_getfloat("d1",&d1)) sf_error("Need d1="); if(!sf_getfloat("d2",&d2)) sf_error("Need d2="); /* sampling */ if(!sf_getfloat("o1",&o1)) o1=0.; if(!sf_getfloat("o2",&o2)) o2=0.; /* origin */ } sf_putint(grid,"n1",n1); sf_putint(grid,"n2",n2); sf_putfloat(grid,"d1",d1); sf_putfloat(grid,"d2",d2); sf_putfloat(grid,"o1",o1); sf_putfloat(grid,"o2",o2); n[0]=n1; d[0]=d1; n[1]=n2; d[1]=d2; if(!sf_getint("order",&order)) order=2; /* [1,2] Accuracy order for distance calculation */ if(!sf_getbool("vel",&isvel)) isvel=true; /* if y, the input is velocity; n, slowness squared */ if (SF_FLOAT != sf_gettype(coord)) sf_error("Need float input"); if(!sf_histint(coord,"n2",&np)) sf_error("No n2= in input"); if(!sf_histint(coord,"n1",&ndim) || ndim > 3) sf_error("Need n1 <= 3 in input"); pts = sf_floatalloc2 (3,np); for (ip=0; ip < np; ip++) { sf_floatread(pts[ip],ndim,coord); pts[ip][2] = 0.0f; } n123 = n1*n2; dd = sf_floatalloc (n123); vv = sf_floatalloc (n123); pp = sf_intalloc (n123); if (NULL != vel) { sf_floatread(vv,n123,vel); sf_fileclose(vel); /* transform velocity to slowness squared */ if (isvel) { for(i = 0; i < n123; i++) { slow = vv[i]; vv[i] = 1./(slow*slow); } } } else { for(i = 0; i < n123; i++) { vv[i] = 1.; } } /* 1. find distance */ distance_init (1,n2,n1,np); distance(np,pts,dd,vv,pp, 1,n2,n1, 0.,o2,o1, 1.,d2,d1, order); if (!sf_getbool("dist",&dist)) dist=false; /* if output distance */ if (dist) { sf_floatwrite(dd,n123,grid); exit(0); } /* 2. binning */ sf_int2_init (pts, o1,o2,d1,d2,n1,n2, sf_bin_int, 1, np); h = sf_floatalloc(np); for (ip=0; ip<np; ip++) { h[ip]=1.0f; } sf_int2_lop (true,false,n123,np,vv,h); if (SF_FLOAT != sf_gettype(ord)) sf_error("Need float input"); sf_floatread(h,np,ord); bin = sf_floatalloc(n123); sf_int2_lop (true,false,n123,np,bin,h); for (i=0; i < n123; i++) { /* normalize by the fold */ if (vv[i] > FLT_EPSILON) bin[i] /=vv[i]; vv[i]=0.0f; } /* 3. voronoi interpolation */ vor = sf_floatalloc(n123); upg = sf_upgrad_init(2,n,d); sf_upgrad_set(upg,dd); sf_upgrad_solve(upg,vv,vor,bin); if (!sf_getbool("voro",&voro)) voro=false; /* if output Voronoi diagram */ if (voro) { sf_floatwrite(vor,n123,grid); exit(0); } /* 4. smoothing */ rect = sf_floatalloc2(n123,2); shift = sf_intalloc2(n123,2); for (j=0; j < 2; j++) { box[j] = 1; for (i=0; i < n123; i++) { rect[j][i] = 1.0f+dd[i]/d[j]; b = ceilf(rect[j][i]); if (b > box[j]) box[j] = b; shift[j][i] = 0; } } ntrianglen_init(2,box,n,rect,shift,1); ntrianglen_lop(false,false,n123,n123,vor,bin); sf_floatwrite(bin,n123,grid); exit (0); }
int main (int argc, char* argv[]) { map4 nmo; /* using cubic spline interpolation */ bool half, slow; int it,ix,ih, nt,nx, nh, CDPtype; float dt, t0, h, h0, f, dh, eps, dy; float *trace, *vel, *off, *str, *out; sf_file cmp, nmod, velocity, offset; sf_init (argc,argv); cmp = sf_input("in"); velocity = sf_input("velocity"); nmod = sf_output("out"); if (SF_FLOAT != sf_gettype(cmp)) sf_error("Need float input"); if (!sf_histint(cmp,"n1",&nt)) sf_error("No n1= in input"); if (!sf_histfloat(cmp,"d1",&dt)) sf_error("No d1= in input"); if (!sf_histfloat(cmp,"o1",&t0)) sf_error("No o1= in input"); if (!sf_histint(cmp,"n2",&nh)) sf_error("No n2= in input"); off = sf_floatalloc(nh); if (!sf_getbool("half",&half)) half=true; /* if y, the second axis is half-offset instead of full offset */ CDPtype=1; if (NULL != sf_getstring("offset")) { offset = sf_input("offset"); sf_floatread (off,nh,offset); sf_fileclose(offset); } else { if (!sf_histfloat(cmp,"d2",&dh)) sf_error("No d2= in input"); if (!sf_histfloat(cmp,"o2",&h0)) sf_error("No o2= in input"); if (sf_histfloat(cmp,"d3",&dy)) { CDPtype=half? 0.5+dh/dy : 0.5+0.5*dh/dy; if (CDPtype < 1) { CDPtype=1; } else if (1 != CDPtype) { sf_histint(cmp,"CDPtype",&CDPtype); sf_warning("CDPtype=%d",CDPtype); } } for (ih = 0; ih < nh; ih++) { off[ih] = h0 + ih*dh; } } if (!sf_getbool("slowness",&slow)) slow=false; /* if y, use slowness instead of velocity */ nx = sf_leftsize(cmp,2); if (!sf_getfloat ("h0",&h0)) h0=0.; /* reference offset */ if (half) h0 *= 2.; if (!sf_getfloat("eps",&eps)) eps=0.01; /* stretch regularization */ trace = sf_floatalloc(nt); vel = sf_floatalloc(nt); str = sf_floatalloc(nt); out = sf_floatalloc(nt); nmo = stretch4_init (nt, t0, dt, nt, eps); for (ix = 0; ix < nx; ix++) { sf_floatread (vel,nt,velocity); for (ih = 0; ih < nh; ih++) { sf_floatread (trace,nt,cmp); h = off[ih] + (dh/CDPtype)*(ix%CDPtype); if (half) h *= 2; h = h*h - h0*h0; for (it=0; it < nt; it++) { f = t0 + it*dt; if (slow) { f = f*f + h*vel[it]*vel[it]; } else { f = f*f + h/(vel[it]*vel[it]); } if (f < 0.) { str[it]=t0-10.*dt; } else { str[it] = sqrtf(f); } } stretch4_define (nmo,str); stretch4_apply (false,nmo,trace,out); sf_floatwrite (out,nt,nmod); } } exit (0); }
int main(int argc, char* argv[]) { int nx, ny, nt, npara, nc; float x, y, dx, dy, dt, x0, y0, tini, t0; float **t0sq,**time, *coeff, ***dtime; float w1,w2,w3,A1,A2,A3,A4,A5,B1,B2,B3,C1,C2,C3,C4,C5,A,B,C; int i,j,k,test; int count = 0; bool verb; sf_file inp, out, fit ,inicoef; sf_init(argc, argv); inp = sf_input("in"); inicoef = sf_input("coef"); out = sf_output("out"); fit = sf_output("fit"); /* input vector t0^2' */ if (!sf_histint(inp,"n1",&nx)) sf_error("No n1="); if (!sf_histint(inp,"n2",&ny)) sf_error("No n2="); if (!sf_histint(inp,"n3",&nt)) sf_error("No n3="); if (!sf_histfloat(inp,"d1",&dx)) sf_error("No d1="); if (!sf_histfloat(inp,"d2",&dy)) sf_error("No d2="); if (!sf_histfloat(inp,"d3",&dt)) sf_error("No d3="); if (!sf_histfloat(inp,"o1",&x0)) sf_error("No o1="); if (!sf_histfloat(inp,"o2",&y0)) sf_error("No o2="); if (!sf_histfloat(inp,"o3",&tini)) sf_error("No o2="); /*Number of fitting parameters*/ npara=16; /*Verbal flag*/ if (!sf_getbool("verb",&verb)) verb=false; /*Memory allocation*/ coeff = sf_floatalloc(npara); t0sq = sf_floatalloc2(nx,ny); time = sf_floatalloc2(nx,ny); dtime = sf_floatalloc3(nx,ny,npara); /*Output dimension*/ if (!sf_histint(inicoef,"n1",&nc) || nc != npara) sf_error("Need n1=%d in inicoef",npara); /*Shift the third dimension to 4th to insert coefficients*/ sf_shiftdim(inp, fit, 3); sf_putint(fit,"n3",npara); sf_putint(fit,"d3",1); sf_putint(fit,"o3",0); /* Loop over time slices */ for(k=0; k < nt; k++) { /*Read intial parameters*/ sf_floatread(coeff,npara,inicoef); w1 = coeff[0];w2 = coeff[1];w3 = coeff[2]; A1 = coeff[3];A2 = coeff[4];A3 = coeff[5];A4 = coeff[6];A5 = coeff[7]; B1 = coeff[8];B2 = coeff[9];B3 = coeff[10]; C1 = coeff[11];C2 = coeff[12];C3 = coeff[13];C4 = coeff[14];C5 = coeff[15]; sf_floatread(t0sq[0],nx*ny,inp); /* Loops for each x and y*/ for(j=0;j<ny;j++){ y = y0 + j*dy; for(i=0;i<nx;i++){ x = x0 + i*dx; t0 = sqrt(t0sq[j][i]); /* Avoid dividing by zero*/ if (x!=0 || y!=0 || t0!=0) { A = A1*pow(x,4) + A2*pow(x,3)*y + A3*pow(x,2)*pow(y,2) + A4*x*pow(y,3) + A5*pow(y,4); B = B1*pow(x,2) + B2*x*y + B3*pow(y,2); C = C1*pow(x,4) + C2*pow(x,3)*y + C3*pow(x,2)*pow(y,2) + C4*x*pow(y,3) + C5*pow(y,4); /* Compute traveltime (t^2)*/ time[j][i] = pow(t0,2) + w1*pow(x,2) + w2*x*y + w3*pow(y,2) + A/(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B)); /* Compute Derivatives */ dtime[0][j][i] = pow(x,2); // Wx dtime[1][j][i] = x*y; // Wxy dtime[2][j][i] = pow(y,2); //Wy dtime[3][j][i] = pow(x,4)/(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B)); // A1 dtime[4][j][i] = (pow(x,3)*y)/(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B)); // A2 dtime[5][j][i] = (pow(x,2)*pow(y,2))/(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B)); // A3 dtime[6][j][i] = (x*pow(y,3))/(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B)); // A4 dtime[7][j][i] = pow(y,4)/(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B)); // A5 dtime[8][j][i] = (-A*x*x*(1+pow(t0,2)/(sqrt(pow(t0,4) + C + 2*pow(t0,2)*B))))/pow(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B),2); // B1 dtime[9][j][i] = (-A*x*y*(1+pow(t0,2)/(sqrt(pow(t0,4) + C + 2*pow(t0,2)*B))))/pow(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B),2); // B2 dtime[10][j][i] = (-A*y*y*(1+pow(t0,2)/(sqrt(pow(t0,4) + C + 2*pow(t0,2)*B))))/pow(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B),2); // B3 dtime[11][j][i] = (-pow(x,4)*A)/(2*sqrt(pow(t0,4) + C + 2*pow(t0,2)*B)*pow(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B),2)); // C1 dtime[12][j][i] = (-pow(x,3)*y*A)/(2*sqrt(pow(t0,4) + C + 2*pow(t0,2)*B)*pow(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B),2)); // C2 dtime[13][j][i] = (-pow(x,2)*pow(y,2)*A)/(2*sqrt(pow(t0,4) + C + 2*pow(t0,2)*B)*pow(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B),2)); // C3 dtime[14][j][i] = (-x*pow(y,3)*A)/(2*sqrt(pow(t0,4) + C + 2*pow(t0,2)*B)*pow(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B),2)); // C4 dtime[15][j][i] = (-pow(y,4)*A)/(2*sqrt(pow(t0,4) + C + 2*pow(t0,2)*B)*pow(pow(t0,2) + B + sqrt(pow(t0,4) + C + 2*pow(t0,2)*B),2)); // C5 for (test=0;test<16;test++) { if(verb && isnan(dtime[test][j][i]) != 0) { sf_warning("The sqrt is NaN at dtime %d k %d j %d i %d",test,k+1,j,i); sf_warning("x %f y %f B %f %f %f C %f %f %f %f %f",x,y,B1,B2,B3,C1,C2,C3,C4,C5); sf_warning("pow(t0,4) + C + 2*pow(t0,2)*B : %f \n",pow(t0,4) + C + 2*pow(t0,2)*B); } } } else { time[j][i] = 0; dtime[0][j][i] = 0; dtime[1][j][i] = 0; dtime[2][j][i] = 0; dtime[3][j][i] = 0; dtime[4][j][i] = 0; dtime[5][j][i] = 0; dtime[6][j][i] = 0; dtime[7][j][i] = 0; dtime[8][j][i] = 0; dtime[9][j][i] = 0; dtime[10][j][i] = 0; dtime[11][j][i] = 0; dtime[12][j][i] = 0; dtime[13][j][i] = 0; dtime[14][j][i] = 0; dtime[15][j][i] = 0; } count++; /* sf_warning("%d of %d surface locations ;",count,nx*ny);*/ } } sf_warning(" Time step: %d; of %d;",k+1,nt); sf_floatwrite(time[0],nx*ny,out); sf_floatwrite(dtime[0][0],nx*ny*npara,fit); } exit(0); }
int main(int argc, char* argv[]) { bool verb; int it,iz,im,ik,ix,i,j; /* index variables */ int nt,nz,nx, m2, nk, nzx, nz2, nx2, nzx2, n2, pad1; sf_complex c; float *rr; /* I/O arrays*/ sf_complex *ww, *cwave, *cwavem; sf_complex **wave, *curr; float *rcurr; sf_file Fw,Fr,Fo; /* I/O files */ sf_axis at,az,ax; /* cube axes */ sf_complex **lt, **rt; sf_file left, right; sf_init(argc,argv); if(!sf_getbool("verb",&verb)) verb=false; /* verbosity */ /* setup I/O files */ Fw = sf_input ("in" ); Fo = sf_output("out"); Fr = sf_input ("ref"); if (SF_COMPLEX != sf_gettype(Fw)) sf_error("Need complex input"); if (SF_FLOAT != sf_gettype(Fr)) sf_error("Need float ref"); sf_settype(Fo,SF_FLOAT); /* Read/Write axes */ at = sf_iaxa(Fw,1); nt = sf_n(at); az = sf_iaxa(Fr,1); nz = sf_n(az); ax = sf_iaxa(Fr,2); nx = sf_n(ax); sf_oaxa(Fo,az,1); sf_oaxa(Fo,ax,2); sf_oaxa(Fo,at,3); if (!sf_getint("pad1",&pad1)) pad1=1; /* padding factor on the first axis */ nk = cfft2_init(pad1,nz,nx,&nz2,&nx2); nzx = nz*nx; nzx2 = nz2*nx2; /* propagator matrices */ left = sf_input("left"); right = sf_input("right"); if (!sf_histint(left,"n1",&n2) || n2 != nzx) sf_error("Need n1=%d in left",nzx); if (!sf_histint(left,"n2",&m2)) sf_error("Need n2= in left"); if (!sf_histint(right,"n1",&n2) || n2 != m2) sf_error("Need n1=%d in right",m2); if (!sf_histint(right,"n2",&n2) || n2 != nk) sf_error("Need n2=%d in right",nk); // if (!sf_histint(Fw,"n1",&nxx)) sf_error("No n1= in input"); lt = sf_complexalloc2(nzx,m2); rt = sf_complexalloc2(m2,nk); sf_complexread(lt[0],nzx*m2,left); sf_complexread(rt[0],m2*nk,right); // sf_fileclose(left); // sf_fileclose(right); /* read wavelet & reflectivity */ ww=sf_complexalloc(nt); sf_complexread(ww,nt ,Fw); rr=sf_floatalloc(nzx); sf_floatread(rr,nzx,Fr); curr = sf_complexalloc(nzx2); rcurr = sf_floatalloc(nzx2); cwave = sf_complexalloc(nk); cwavem = sf_complexalloc(nk); wave = sf_complexalloc2(nzx2,m2); for (iz=0; iz < nzx2; iz++) { curr[iz] = sf_cmplx(0.,0.); rcurr[iz]= 0.; } /* MAIN LOOP */ for (it=0; it<nt; it++) { if(verb) sf_warning("it=%d;",it); /* matrix multiplication */ cfft2(curr,cwave); for (im = 0; im < m2; im++) { for (ik = 0; ik < nk; ik++) { #ifdef SF_HAS_COMPLEX_H cwavem[ik] = cwave[ik]*rt[ik][im]; #else cwavem[ik] = sf_cmul(cwave[ik],rt[ik][im]); //complex multiplies complex #endif // sf_warning("realcwave=%g, imagcwave=%g", crealf(cwavem[ik]),cimagf(cwavem[ik])); } icfft2(wave[im],cwavem); } for (ix = 0; ix < nx; ix++) { for (iz=0; iz < nz; iz++) { i = iz+ix*nz; /* original grid */ j = iz+ix*nz2; /* padded grid */ #ifdef SF_HAS_COMPLEX_H c = ww[it] * rr[i]; // source term #else c = sf_crmul(ww[it], rr[i]); // source term #endif for (im = 0; im < m2; im++) { #ifdef SF_HAS_COMPLEX_H c += lt[im][i]*wave[im][j]; #else c = sf_cadd(c,sf_cmul(lt[im][i], wave[im][j])); #endif } curr[j] = c; rcurr[j] = crealf(c); // rcurr[j] = cimagf(c); } /* write wavefield to output */ sf_floatwrite(rcurr+ix*nz2,nz,Fo); } } if(verb) sf_warning("."); exit (0); }
int main(int argc, char* argv[]) { int i, niter, n1, n2, n12, i3, n3, rect1, rect2, order; float *mm, *dd, **pp, lam; bool *known; sf_file in, out, dip, mask; sf_init (argc,argv); in = sf_input("in"); out = sf_output("out"); dip = sf_input("dip"); if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(in,"n2",&n2)) sf_error("No n2= in input"); n12 = n1*n2; n3 = sf_leftsize(in,2); if (!sf_getint("niter",&niter)) niter=100; /* number of iterations */ if (!sf_getint("order",&order)) order=1; /* accuracy order */ pp = sf_floatalloc2(n1,n2); mm = sf_floatalloc(n12); known = sf_boolalloc(n12); if (NULL != sf_getstring ("mask")) { mask = sf_input("mask"); dd = sf_floatalloc(n12); } else { mask = NULL; dd = NULL; } if (!sf_getint("rect1",&rect1)) rect1=3; if (!sf_getint("rect2",&rect2)) rect2=3; /* smoothing radius */ pwdsl_init(n1,n2,order,rect1,rect2,0.01); pwdsl_set(pp); sf_mask_init(known); for (i3=0; i3 < n3; i3++) { sf_warning("slice %d of %d",i3+1,n3); sf_floatread(mm,n12,in); if (NULL != mask) { sf_floatread(dd,n12,mask); } else { dd = mm; } /* figure out scaling and make known data mask */ lam = 0.; for (i=0; i < n12; i++) { if (dd[i] != 0.) { known[i] = true; lam += 1.; } else { known[i] = false; } } lam = sqrtf(lam/n12); /* read dip */ sf_floatread(pp[0],n12,dip); sf_conjgrad_init(n12, n12, n12, n12, lam, 10*FLT_EPSILON, true, true); sf_conjgrad(NULL,sf_mask_lop,pwdsl_lop,dd,mm,mm,niter); sf_conjgrad_close(); sf_floatwrite (mm,n12,out); } exit(0); }
int main(int argc, char* argv[]) { clock_t tstart,tend; double duration; /*flag*/ bool verb; bool wantwf; bool wantrecord; /*I/O*/ sf_file Ffvel, Ffden, Fbvel, Fbden; sf_file Fsrc,/*wave field*/ Frcd/*record*/; sf_file Ftmpwf, Ftmpbwf; sf_file Fimg1, Fimg2; sf_file FGx, FGz, Fsxx, Fsxz, Fszx, Fszz; sf_axis at, ax, az; /*grid index variables*/ int nx, nz, nxz, nt, wfnt; int ix, iz, it; int nxb, nzb; float dt, dx, dz, wfdt; float ox, oz; /*source/geophone location*/ float slx, slz; int spx, spz; float gdep; int gp; int ginter, gn; /*SG LFD coefficient*/ int lenx, lenz; int marg; /*Modle*/ float **fvel, **fden, **fc11; float **bvel, **bden, **bc11; float ***wavefld, **record; float **img1, **img2; int snpint; /*source*/ bool srcdecay; int srcrange; float srctrunc; /*pml boundary*/ int pmlout, pmld0, decaybegin; bool decay, freesurface; /*memoray*/ //float memneed; int tmpint; //float tmpfloat; tstart = clock(); sf_init(argc, argv); if (!sf_getbool("verb", &verb)) verb=false; /*verbosity*/ if (!sf_getbool("wantwf", &wantwf)) wantwf=false; /*output forward and backward wavefield*/ if (!sf_getbool("wantrecord", &wantrecord)) wantrecord=true; /*if n, using record data generated by this program */ /*Set I/O file*/ Fsrc = sf_input("in"); /*source wavelet*/ Ffvel = sf_input("fvel"); /*forward velocity*/ Ffden = sf_input("fden"); /*forward density*/ Fbvel = sf_input("bvel"); /*backward velocity*/ Fbden = sf_input("bden"); /*backward velocity*/ if (wantrecord) { Frcd = sf_input("rec"); /*record*/ } else { Frcd = sf_output("rec"); /*record*/ } Fimg1 = sf_output("out"); /*Imaging*/ Fimg2 = sf_output("img2"); /*Imaging*/ if (wantwf) { Ftmpwf = sf_output("tmpwf");/*wavefield snap*/ Ftmpbwf = sf_output("tmpbwf"); } FGx = sf_input("Gx"); FGz = sf_input("Gz"); Fsxx = sf_input("sxx"); Fsxz = sf_input("sxz"); Fszx = sf_input("szx"); Fszz = sf_input("szz"); if (SF_FLOAT != sf_gettype(Ffvel)) sf_error("Need float input"); if (SF_FLOAT != sf_gettype(Ffden)) sf_error("Need float input"); if (SF_FLOAT != sf_gettype(Fbvel)) sf_error("Need float input"); if (SF_FLOAT != sf_gettype(Fbden)) sf_error("Need float input"); if (SF_FLOAT != sf_gettype(Fsrc)) sf_error("Need float input"); /*--- parameters of source ---*/ srcpar srcp; srcp = createsrc(); at = sf_iaxa(Fsrc, 1); nt = sf_n(at); dt = sf_d(at); if (!sf_getbool("srcdecay", &srcdecay)) srcdecay=SRCDECAY; /*source decay*/ if (!sf_getint("srcrange", &srcrange)) srcrange=SRCRANGE; /*source decay range*/ if (!sf_getfloat("srctrunc", &srctrunc)) srctrunc=SRCTRUNC; /*trunc source after srctrunc time (s)*/ srcp->nt = nt; srcp->dt = dt; srcp->decay = srcdecay; srcp->range=srcrange; srcp->trunc=srctrunc; loadsrc(srcp, Fsrc); /*--- parameters of SG LFD Coefficient ---*/ ax = sf_iaxa(Ffvel, 2); nxb = sf_n(ax); dx = sf_d(ax); ox = sf_o(ax); az = sf_iaxa(Ffvel, 1); nzb = sf_n(az); dz = sf_d(az); oz = sf_o(az); if (!sf_histint(FGx, "n1", &nxz)) sf_error("No n1= in input"); if (nxz != nxb*nzb) sf_error (" Need nxz = nxb*nzb"); if (!sf_histint(FGx,"n2", &lenx)) sf_error("No n2= in input"); if (!sf_histint(FGz,"n2", &lenz)) sf_error("No n2= in input"); initsglfdcoe(nxb, nzb, lenx, lenz); loadcoe(nzb, nxb, FGx, FGz); loadschm(Fsxx, Fsxz, Fszx, Fszz); marg = getmarg(); /* pml parameters */ pmlpar pmlp; pmlp = creatpmlpar(); if (!sf_getint("pmlsize", &pmlout)) pmlout=PMLOUT; /* size of PML layer */ if (!sf_getint("pmld0", &pmld0)) pmld0=PMLD0; /* PML parameter */ if (!sf_getbool("decay",&decay)) decay=DECAY_FLAG; /* Flag of decay boundary condtion: 1 = use ; 0 = not use */ if (!sf_getint("decaybegin",&decaybegin)) decaybegin=DECAY_BEGIN; /* Begin time of using decay boundary condition */ if (!sf_getbool("freesurface", &freesurface)) freesurface=false; /*free surface*/ nx = nxb - 2*pmlout - 2*marg; nz = nzb - 2*pmlout - 2*marg; pmlp->pmlout = pmlout; pmlp->pmld0 = pmld0; pmlp->decay = decay; pmlp->decaybegin = decaybegin; pmlp->freesurface = freesurface; /*Geometry parameters*/ geopar geop; geop = creategeo(); /*source loaction parameters*/ slx = -1.0; spx = -1; slz = -1.0; spz = -1; gdep = -1.0; gp = 0; if (!sf_getfloat("slx", &slx)) ; /*source location x */ if (!sf_getint("spx", &spx)); /*source location x (index)*/ if((slx<0 && spx <0) || (slx>=0 && spx >=0 )) sf_error("Need src location"); if (slx >= 0 ) spx = (int)((slx-ox)/dx+0.5); if (!sf_getfloat("slz", &slz)) ; /* source location z */ if (!sf_getint("spz", &spz)) ; /*source location z (index)*/ if((slz<0 && spz <0) || (slz>=0 && spz >=0 )) sf_error("Need src location"); if (slz >= 0 ) spz = (int)((slz-ox)/dz+0.5); if (!sf_getfloat("gdep", &gdep)) ; /* recorder depth on grid*/ if (!sf_getint("gp", &gp)) ; /* recorder depth on index*/ if ( gdep>=oz) { gp = (int)((gdep-oz)/dz+0.5);} if (gp < 0.0) sf_error("gdep need to be >=oz"); /*source and receiver location*/ if (!sf_getint("ginter", &ginter)) ginter = 1; /*geophone interval*/ gn = (nx-1)/ginter+1; /*ceil*/ if (!sf_getint("snapinter", &snpint)) snpint=10; /* snap interval */ /*check record data*/ if (wantrecord){ sf_histint(Frcd,"n1", &tmpint); if (tmpint != nt ) sf_error("Error parameter n1 in record!"); sf_histint(Frcd,"n2", &tmpint); if (tmpint != gn ) sf_error("Error parameter n2 in record!"); } geop->nx = nx; geop->nz = nz; geop->nxb = nxb; geop->nzb = nzb; geop->dx = dx; geop->dz = dz; geop->ox = ox; geop->oz = oz; geop->snpint = snpint; geop->spx = spx; geop->spz = spz; geop->gp = gp; geop->gn = gn; geop->ginter = ginter; /* wavefield and record */ wfnt = (int)(nt-1)/snpint+1; wfdt = dt*snpint; record = sf_floatalloc2(nt, gn); wavefld = sf_floatalloc3(nz, nx, wfnt); /* read model */ fvel = sf_floatalloc2(nzb, nxb); fden = sf_floatalloc2(nzb, nxb); fc11 = sf_floatalloc2(nzb, nxb); /*image*/ img1 = sf_floatalloc2(nz, nx); img2 = sf_floatalloc2(nz, nx); sf_floatread(fvel[0], nxz, Ffvel); sf_floatread(fden[0], nxz, Ffden); for (ix = 0; ix < nxb; ix++) { for ( iz= 0; iz < nzb; iz++) { fc11[ix][iz] = fden[ix][iz]*fvel[ix][iz]*fvel[ix][iz]; if(fc11[ix][iz] == 0.0) sf_warning("c11=0: ix=%d iz%d", ix, iz); } } bvel = sf_floatalloc2(nzb, nxb); bden = sf_floatalloc2(nzb, nxb); bc11 = sf_floatalloc2(nzb, nxb); sf_floatread(bvel[0], nxz, Fbvel); sf_floatread(bden[0], nxz, Fbden); for (ix = 0; ix < nxb; ix++) { for ( iz= 0; iz < nzb; iz++) { bc11[ix][iz] = bden[ix][iz]*bvel[ix][iz]*bvel[ix][iz]; if(bc11[ix][iz] == 0.0) sf_warning("c11=0: ix=%d iz%d", ix, iz); } } if (verb) { sf_warning("============================"); sf_warning("nx=%d nz=%d nt=%d", geop->nx, geop->nz, srcp->nt); sf_warning("dx=%f dz=%f dt=%f", geop->dx, geop->dz, srcp->dt); sf_warning("lenx=%d lenz=%d marg=%d pmlout=%d", lenx, lenz, marg, pmlout); sf_warning("srcdecay=%d srcrange=%d",srcp->decay,srcp->range); sf_warning("spx=%d spz=%d gp=%d snpint=%d", spx, spz, gp, snpint); sf_warning("wfdt=%f wfnt=%d ", wfdt, wfnt); sf_warning("============================"); } /* write record */ sf_setn(ax, gn); sf_setn(az, nz); if(!wantrecord) { sf_oaxa(Frcd, at, 1); sf_oaxa(Frcd, ax, 2); } /*wavefiel and image*/ sf_setn(ax,nx); if (wantwf) { /*write temp wavefield */ sf_setn(ax, nx); sf_setn(at, wfnt); sf_setd(at, wfdt); sf_oaxa(Ftmpwf, az, 1); sf_oaxa(Ftmpwf, ax, 2); sf_oaxa(Ftmpwf, at, 3); /*write temp wavefield */ sf_oaxa(Ftmpbwf, az, 1); sf_oaxa(Ftmpbwf, ax, 2); sf_oaxa(Ftmpbwf, at, 3); } /*write image*/ sf_oaxa(Fimg1, az, 1); sf_oaxa(Fimg1, ax, 2); sf_oaxa(Fimg2, az, 1); sf_oaxa(Fimg2, ax, 2); sglfdfor2(wavefld, record, verb, fden, fc11, geop, srcp, pmlp); if(wantrecord) { sf_floatread(record[0], gn*nt, Frcd); } sglfdback2(img1, img2, wavefld, record, verb, wantwf, bden, bc11, geop, srcp, pmlp, Ftmpbwf); if (!wantrecord) { for (ix=0; ix<gn; ix++) sf_floatwrite(record[ix], nt, Frcd); } if (wantwf) { for (it=0; it<wfnt; it++) for ( ix=0; ix<nx; ix++) sf_floatwrite(wavefld[it][ix], nz, Ftmpwf); } for (ix=0; ix<nx; ix++) sf_floatwrite(img1[ix], nz, Fimg1); for (ix=0; ix<nx; ix++) sf_floatwrite(img2[ix], nz, Fimg2); freertm(); tend = clock(); duration=(double)(tend-tstart)/CLOCKS_PER_SEC; sf_warning(">> The CPU time of sfsglfd2 is: %f seconds << ", duration); exit(0); }
int main (int argc, char ** argv) { /* RSF variables */ bool verb; float *dat=NULL, **datf=NULL, **image=NULL, **tr=NULL, **ts=NULL, **trs=NULL; float **px=NULL, **pz=NULL; sf_file Fin=NULL, Fout=NULL, Ftt=NULL; sf_axis a1,a2,a1t,a2t,a3t,ax,az; int nf,ntaper,i1,i2,i2t,itt; float fmax,df,theta,dtheta,tg,tgtap,tmin,xs,xr,eps; aalias aa; fslice tabtt=NULL; int n1,n2,n1t,n2t,n3t,nx,nz; float o1,d1,o2,d2,o1t,d1t,o2t,d2t,o3t,d3t,ox,oz,dx,dz; sf_init(argc,argv); Fin = sf_input ("in" ); Fout = sf_output ("out" ); Ftt = sf_input ("ttfile" ); /* axes */ a1 = sf_iaxa(Fin,1); /* data */ a2 = sf_iaxa(Fin,2); /* data */ a1t = sf_iaxa(Ftt,1); /* traveltime */ a2t = sf_iaxa(Ftt,2); /* traveltime */ a3t = sf_iaxa(Ftt,3); /* traveltime */ o1 = sf_o(a1); n1 = sf_n(a1); d1 = sf_d(a1); o2 = sf_o(a2); n2 = sf_n(a2); d2 = sf_d(a2); o1t = sf_o(a1t); n1t = sf_n(a1t); d1t = sf_d(a1t); o2t = sf_o(a2t); n2t = sf_n(a2t); d2t = sf_d(a2t); o3t = sf_o(a3t); n3t = sf_n(a3t); d3t = sf_d(a3t); /* migration parameters */ if(! sf_getbool("verb",&verb)) verb = false; /* verbosity flag */ if(! sf_getfloat("theta",&theta)) theta = 30.; /* maximum dip */ if(! sf_getfloat("dtheta",&dtheta)) dtheta = theta/3; /* taper zone */ if(dtheta>theta) dtheta=theta; if(! sf_getfloat("df",&df)) df = 5.; /* anti-aliasing sampling */ if(!sf_getfloat("fmax",&fmax)) fmax=.5/d1; if(fmax>(.5/d1)) fmax=.5/d1; if (!sf_getint("ntaper",&ntaper)) ntaper=11; if(!sf_getfloat("tmin",&tmin)) tmin=3*d1; if(!sf_getfloat("xs",&xs)) sf_error("missing xs parameter\n"); /* image parameters */ if (!sf_getint("nx",&nx)) nx=n2t; if(!sf_getfloat("ox",&ox)) ox=o2t; if(!sf_getfloat("dx",&dx)) dx=d2t; if (!sf_getint("nz",&nz)) nz=n1t; if(!sf_getfloat("oz",&oz)) oz=o1t; if(!sf_getfloat("dz",&dz)) dz=d1t; /* checking dimensions */ if((dx!=d2t)||(dz!=d1t)) sf_error("sampling interval have to be the same in:\n" " image and traveltime file\n"); if(ox<o2t) ox=o2t; if(oz<o1t) oz=o1t; if((ox+(nx-1)*dx)>(o2t+(n2t-1)*d2t)) nx=floor(((o2t+(n2t-1)*d2t)-ox)/dx)+1; if((oz+(nz-1)*dz)>(o1t+(n1t-1)*d1t)) nz=floor(((o1t+(n1t-1)*d1t)-oz)/dz)+1; /* output axis */ ax = sf_maxa(nx,ox,dx); if(verb) sf_raxa(ax); az = sf_maxa(nz,oz,dz); if(verb) sf_raxa(az); sf_oaxa(Fout,az,1); sf_oaxa(Fout,ax,2); /* anti-aliasing */ /* df = fmax; */ nf = initAalias(-1,verb,fmax,df,n1,d1,&aa); /* fprintf(stderr,"forcing nf=%d df=%f\n",nf,df); */ /* aperture angle */ tg = tan(SF_PI*theta/180); tgtap = tan(SF_PI*(theta-dtheta)/180); if(verb) sf_warning("tgmax=%f tgtap=%f",tg,tgtap); /* allocating */ dat = sf_floatalloc(n1); image = sf_floatalloc2(nz,nx); datf = sf_floatalloc2 (n1,nf); ts = sf_floatalloc2(n1t,n2t); tr = sf_floatalloc2(n1t,n2t); trs = sf_floatalloc2(n1t,n2t); px = sf_floatalloc2(n1t,n2t); pz = sf_floatalloc2(n1t,n2t); if(verb) sf_warning("initializing traveltime loading"); /* initializing traveltime maps */ tabtt = fslice_init(n1t*n2t,n3t,sizeof(float)); fslice_load(Ftt,tabtt,SF_FLOAT); if(verb) sf_warning("traveltime loading has finished"); /* reading the source-slice from traveltime table */ eps = .01*d2; itt = floor((xs+eps-o3t)/d3t); fslice_get(tabtt,itt,ts[0]); if(verb) sf_warning("traveltime table from source was read"); for(i2=0;i2<n2;i2++) { sf_floatread(dat,n1,Fin); xr = o2+i2*d2; if((xr>=o3t)&&(xr<(o3t+n3t*d3t))) { for (i1=n1-ntaper;i1<n1;i1++) dat[i1]=(n1-i1-1)*dat[i1]/ntaper; loadBank(aa,dat,datf); /* reading the receiver-slice of traveltime table */ /* itt = floor((o2-o2t)/d2)+i2; */ itt = floor((xr+eps-o3t)/d3t); fslice_get(tabtt,itt,tr[0]); for(i2t=0;i2t<n2t;i2t++) for(i1=0;i1<n1t;i1++) trs[i2t][i1]=ts[i2t][i1]+tr[i2t][i1]; derive_1(n1t,n2t,d1t,trs,pz); derive_2(n1t,n2t,d2t,trs,px); spreadSR(nf,fmax,df,tg,tgtap, n1,o1,d1, nx,ox,dx, nz,oz,dz, o1t,o2t, px,pz,tr,ts,datf,image); if(verb) fprintf(stderr,"+"); }else{ if(verb) fprintf(stderr,".");} } sf_floatwrite(image[0],n1*n2,Fout); fprintf( stderr," \n finished processing \n"); exit(0); }
int main(int argc, char* argv[]) { /* Laplacian coefficients */ float c0=-30./12.,c1=+16./12.,c2=- 1./12.; bool verb,free, ifoneway, ifsponge; /* verbose flag */ sf_file Fw=NULL,Fv=NULL,Fr=NULL,Fo=NULL; /* I/O files */ sf_axis at,az,ax; /* cube axes */ int it,iz,ix,nb; /* index variables */ int nt,nz,nx; float dt,dz,dx,idx,idz,dt2; float *ww,**vv,**rr; /* I/O arrays*/ float **um,**uo,**up,**ud;/* tmp arrays */ #ifdef _OPENMP /* Testing for OpenMP */ double start_time, end_time; #endif sf_init(argc,argv); /* OMP parameters */ #ifdef _OPENMP omp_init(); #endif if(! sf_getbool("verb",&verb)) verb=0; if(! sf_getbool("free",&free)) free=false; if(! sf_getbool("ifoneway",&ifoneway)) ifoneway=true; if(! sf_getbool("ifsponge",&ifsponge)) ifsponge=true; if(! sf_getint("nb",&nb)) nb=5; /* setup I/O files */ Fw = sf_input ("in" ); Fo = sf_output("out"); Fv = sf_input ("vel"); Fr = sf_input ("ref"); /* Read/Write axes */ at = sf_iaxa(Fw,1); nt = sf_n(at); dt = sf_d(at); az = sf_iaxa(Fv,1); nz = sf_n(az); dz = sf_d(az); ax = sf_iaxa(Fv,2); nx = sf_n(ax); dx = sf_d(ax); sf_oaxa(Fo,az,1); sf_oaxa(Fo,ax,2); sf_oaxa(Fo,at,3); dt2 = dt*dt; idz = 1/(dz*dz); idx = 1/(dx*dx); /* read wavelet, velocity & reflectivity */ ww=sf_floatalloc(nt); sf_floatread(ww ,nt ,Fw); vv=sf_floatalloc2(nz,nx); sf_floatread(vv[0],nz*nx,Fv); rr=sf_floatalloc2(nz,nx); sf_floatread(rr[0],nz*nx,Fr); /* allocate temporary arrays */ um=sf_floatalloc2(nz,nx); uo=sf_floatalloc2(nz,nx); up=sf_floatalloc2(nz,nx); ud=sf_floatalloc2(nz,nx); for (iz=0; iz<nz; iz++) { for (ix=0; ix<nx; ix++) { um[ix][iz]=0; uo[ix][iz]=0; up[ix][iz]=0; ud[ix][iz]=0; } } /* MAIN LOOP */ if(verb) fprintf(stderr,"\n"); /* Starting timer */ #ifdef _OPENMP start_time = omp_get_wtime(); #endif for (it=0; it<nt; it++) { if(verb) fprintf(stderr,"\b\b\b\b\b%d",it); /* 4th order laplacian */ if(ifoneway) { #ifdef _OPENMP #pragma omp parallel for default(none) \ private(ix,iz) \ shared(ud,nb,uo,c0,c1,c2,nx,nz,idx,idz) #endif for (iz=nb; iz<nz-nb; iz++) { for (ix=nb; ix<nx-nb; ix++) { ud[ix][iz] = c0* uo[ix ][iz ] * (idx+idz) + c1*(uo[ix-1][iz ] + uo[ix+1][iz ])*idx + c2*(uo[ix-2][iz ] + uo[ix+2][iz ])*idx + c1*(uo[ix ][iz-1] + uo[ix ][iz+1])*idz + c2*(uo[ix ][iz-2] + uo[ix ][iz+2])*idz; } } }else { #ifdef _OPENMP #pragma omp parallel for default(none) \ private(ix,iz) \ shared(ud,uo,c0,c1,c2,nx,nz,idx,idz) #endif for (iz=2; iz<nz-2; iz++) { for (ix=2; ix<nx-2; ix++) { ud[ix][iz] = c0* uo[ix ][iz ] * (idx+idz) + c1*(uo[ix-1][iz ] + uo[ix+1][iz ])*idx + c2*(uo[ix-2][iz ] + uo[ix+2][iz ])*idx + c1*(uo[ix ][iz-1] + uo[ix ][iz+1])*idz + c2*(uo[ix ][iz-2] + uo[ix ][iz+2])*idz; } } } /* inject wavelet */ #ifdef _OPENMP #pragma omp parallel for default(none) \ private(ix,iz) \ shared(nx,nz,ww,rr,ud,it) #endif for (iz=0; iz<nz; iz++) { for (ix=0; ix<nx; ix++) { ud[ix][iz] -= ww[it] * rr[ix][iz]; } } /* scale by velocity */ #ifdef _OPENMP #pragma omp parallel for default(none) \ private(ix,iz) \ shared(ud,vv,nx,nz) #endif for (iz=0; iz<nz; iz++) { for (ix=0; ix<nx; ix++) { ud[ix][iz] *= vv[ix][iz]*vv[ix][iz]; } } /* time step */ #ifdef _OPENMP #pragma omp parallel for default(none) \ private(ix,iz) \ shared(up,uo,um,ud,nx,nz,dt2) #endif for (iz=0; iz<nz; iz++) { for (ix=0; ix<nx; ix++) { up[ix][iz] = 2*uo[ix][iz] - um[ix][iz] + ud[ix][iz] * dt2; um[ix][iz] = uo[ix][iz]; uo[ix][iz] = up[ix][iz]; } } /* one-way abc apply */ if(ifoneway) {oneway_abc(uo,um,vv,nx,nz,nb,dx,dz,dt,free);} if(ifsponge) {sponge_abc(um,nx,nz,nb); sponge_abc(uo,nx,nz,nb);} /* write wavefield to output */ sf_floatwrite(uo[0],nz*nx,Fo); } /* Ending timer */ #ifdef _OPENMP end_time = omp_get_wtime(); sf_warning("Elapsed time is %f.",end_time-start_time); #endif if(verb) fprintf(stderr,"\n"); sf_close(); exit (0); }
int main (int argc, char* argv[]) { bool top; fint1 sft; int ext; float a,n,f,da,a0,t0,dt,s; int fint,na,nx,nz,nt; sf_axis ax,az,at,aa; int ix,iz,it,ia; float **stk=NULL, **ang=NULL, *tmp=NULL, *vel=NULL; sf_file Fstk=NULL, Fang=NULL, velocity=NULL; sf_init (argc,argv); /*------------------------------------------------------------*/ Fstk = sf_input("in"); Fang = sf_output("out"); if (SF_FLOAT != sf_gettype(Fstk)) sf_error("Need float input"); az=sf_iaxa(Fstk,1); nz=sf_n(az); at=sf_iaxa(Fstk,2); nt=sf_n(at); t0=sf_o(at); dt=sf_d(at); ax=sf_iaxa(Fstk,3); nx=sf_n(ax); if (!sf_getint ("na",&na)) na=nt; /* number of angles*/ if (!sf_getfloat("da",&da)) da=90/(nt-1); /* angle sampling */ if (!sf_getfloat("a0",&a0)) a0=0.; /* angle origin */ aa = sf_maxa(na,a0,da); sf_oaxa(Fang,aa,2); if (!sf_getint("extend",&ext)) ext=4; /* tmp extension */ /*------------------------------------------------------------*/ if (!sf_getbool("top",&top)) top=false; /* velocity scaling option */ if (top) { velocity = sf_input("velocity"); vel = sf_floatalloc(nz); } else { velocity = NULL; vel = NULL; } stk = sf_floatalloc2(nz,nt); ang = sf_floatalloc2(nz,na); tmp = sf_floatalloc(nt); sft = fint1_init(ext,nt, 0); for (ix = 0; ix < nx; ix++) { sf_floatread(stk[0],nz*nt,Fstk); if (top) sf_floatread(vel,nz,velocity); /*------------------------------------------------------------*/ for (iz = 0; iz < nz; iz++) { for (it = 0; it < nt; it++) { tmp[it] = stk[it][iz]; } fint1_set(sft,tmp); for (ia=0; ia < na; ia++) { a = a0+ia*da; /* ang or p */ if (top) { s = a*vel[iz]; if (s >= 1.) { n = t0 - 10.*dt; } else { n = s/sqrtf(1.0-s*s); } } else { n = 1.0/(sinf(a/180.0*SF_PI)); /* 1/sin : no angle close to 0 */ } f = (n - t0) / dt; fint = f; if (fint >= 0 && fint < nt) { ang[ia][iz] = fint1_apply(sft,fint,f-fint,false); } else { ang[ia][iz] = 0.; } } } /*------------------------------------------------------------*/ sf_floatwrite(ang[0],nz*na,Fang); } exit (0); }
int main(int argc, char* argv[]) { int nt, n3, nx, np, i3, ntx, ntp; bool adj,verb,rho; float o1,d1, x0,dx, anti, p0,dp,p1; float *cmp=NULL, *vscan=NULL; sf_file in=NULL, out=NULL; sf_init(argc,argv); in = sf_input ("in"); out = sf_output("out"); if (!sf_histint (in,"n1",&nt)) sf_error("No n1= in input"); if (!sf_histfloat(in,"o1",&o1)) sf_error("No o1= in input"); if (!sf_histfloat(in,"d1",&d1)) sf_error("No d1= in input"); n3 = sf_leftsize(in,2); if (!sf_getbool ("verb",&verb)) verb=false; /* verbosity flag */ if (!sf_getbool ( "adj",&adj )) adj=false; /* adjoint flag */ if (!sf_getbool ( "rho",&rho )) rho=true; /* rho filtering */ if (!sf_getfloat("anti",&anti)) anti=1.; /* antialiasing */ if (adj) { if (!sf_histfloat(in,"o2",&x0)) sf_error("No o2= in input"); if (!sf_histfloat(in,"d2",&dx)) sf_error("No d2= in input"); if (!sf_histint (in,"n2",&nx)) sf_error("No n2= in input"); /* specify slope axis */ if (!sf_getint("np",&np)) sf_error("Need np="); /* number of p values (if adj=y) */ if (!sf_getfloat("dp",&dp)) sf_error("Need dp="); /* p sampling (if adj=y) */ if (!sf_getfloat("p0",&p0)) sf_error("Need p0="); /* p origin (if adj=y) */ sf_putint (out,"n2",np); sf_putfloat(out,"d2",dp); sf_putfloat(out,"o2",p0); } else { /* modeling */ if (!sf_histint (in,"n2",&np)) sf_error("No n2= in input"); if (!sf_histfloat(in,"d2",&dp)) sf_error("No d2= in input"); if (!sf_histfloat(in,"o2",&p0)) sf_error("No o2= in input"); if (!sf_getfloat("x0",&x0)) sf_error("Need x0="); /* offset origin */ if (!sf_getfloat("dx",&dx)) sf_error("Need dx="); /* offset sampling */ if (!sf_getint("nx",&nx)) sf_error ("Need nx="); /* number of offsets */ sf_putint (out,"n2",nx); sf_putfloat(out,"o2",x0); sf_putfloat(out,"d2",dx); } if (!sf_getfloat("p1",&p1)) p1=0.; /* reference slope */ ntx = nt*nx; ntp = nt*np; cmp = sf_floatalloc(ntx); vscan = sf_floatalloc(ntp); slant_init (true, rho, x0, dx, nx, p0, dp, np, o1, d1, nt, p1, anti); for (i3=0; i3 < n3; i3++) { if(verb) sf_warning("i=%d of %d",i3+1,n3); if( adj) { sf_floatread( cmp,ntx,in); } else { sf_floatread(vscan,ntp,in); } slant_lop(adj,false,ntp,ntx,vscan,cmp); if( adj) { sf_floatwrite(vscan,ntp,out); } else { sf_floatwrite( cmp,ntx,out); } } exit(0); }
int main(int argc, char* argv[]) { int i, ia, na, nx, ns, dim, n[SF_MAX_DIM], m[SF_MAX_DIM]; float a0, *pp, *qq; bool adj; sf_filter aa; char* lagfile; sf_file in, out, filt, lag; sf_init (argc,argv); in = sf_input("in"); filt = sf_input("filt"); out = sf_output("out"); dim = sf_filedims (in,n); if (!sf_histint(filt,"n1",&na)) sf_error("No n1= in filt"); aa = sf_allocatehelix (na); if (!sf_histfloat(filt,"a0",&a0)) a0=1.; sf_floatread (aa->flt,na,filt); for( ia=0; ia < na; ia++) { aa->flt[ia] /= a0; } if (NULL != (lagfile = sf_getstring("lag")) /* file with filter lags */ || NULL != (lagfile = sf_histstring(filt,"lag"))) { lag = sf_input(lagfile); sf_intread(aa->lag,na,lag); } else { lag = NULL; for( ia=0; ia < na; ia++) { aa->lag[ia] = ia+1; } } sf_fileclose(filt); if (!sf_getints ("n",m,dim) && (NULL == lag || !sf_histints (lag,"n",m,dim))) { for (i=0; i < dim; i++) { m[i] = n[i]; } } if (NULL != lag) sf_fileclose(lag); regrid (dim, m, n, aa); if (!sf_getbool ("adj",&adj)) adj=false; /* if y, do adjoint operation */ if (!sf_getint ("ns",&ns)) sf_error("Need ns="); /* scaling */ nx = 1; for( i=0; i < dim; i++) { nx *= n[i]; } pp = sf_floatalloc (nx); qq = sf_floatalloc (nx); if (adj) { sf_floatread (qq,nx,in); } else { sf_floatread (pp,nx,in); } hshape_init (nx,ns,aa); hshape_lop (adj,false,nx,nx,pp,qq); if (adj) { sf_floatwrite (pp,nx,out); } else { sf_floatwrite (qq,nx,out); } exit (0); }
int main(int argc, char* argv[]) { int i, j, is, ip, dim, n[SF_MAX_DIM], ii[SF_MAX_DIM]; int nsp, **k=NULL, **l=NULL, n1, n2, i1, i2, kk, ll; char key[7]; const char *label, *unit; float f, *trace, *mag=NULL, **p=NULL, pp; sf_file in, spike; sf_init (argc,argv); if (!sf_stdin()) { /* no input file in stdin */ in = NULL; } else { in = sf_input("in"); } spike = sf_output("out"); if (NULL == in) { sf_setformat(spike,"native_float"); } else if (SF_FLOAT != sf_gettype(in)) { sf_error("Need float input"); } /* dimensions */ for (i=0; i < SF_MAX_DIM; i++) { snprintf(key,3,"n%d",i+1); if (!sf_getint(key,n+i) && (NULL == in || !sf_histint(in,key,n+i))) break; /*( n# size of #-th axis )*/ sf_putint(spike,key,n[i]); } if (0==i) sf_error("Need n1="); dim=i; /* basic parameters */ for (i=0; i < dim; i++) { snprintf(key,3,"o%d",i+1); if (!sf_getfloat(key,&f) && (NULL == in || !sf_histfloat(in,key,&f))) f=0.; /*( o#=[0,0,...] origin on #-th axis )*/ sf_putfloat(spike,key,f); snprintf(key,3,"d%d",i+1); if (!sf_getfloat(key,&f) && (NULL == in || !sf_histfloat(in,key,&f))) f = (i==0)? 0.004: 0.1; /*( d#=[0.004,0.1,0.1,...] sampling on #-th axis )*/ sf_putfloat(spike,key,f); snprintf(key,7,"label%d",i+1); if (NULL == (label = sf_getstring(key)) && (NULL == in || NULL == (label = sf_histstring(in,key)))) label = (i==0)? "Time":"Distance"; /*( label#=[Time,Distance,Distance,...] label on #-th axis )*/ if (*label != '\0' && (*label != ' ' || *(label+1) != '\0')) sf_putstring(spike,key,label); snprintf(key,6,"unit%d",i+1); if (NULL == (unit = sf_getstring(key)) && (NULL == in || NULL == (unit = sf_histstring(in,key)))) unit = (i==0)? "s":"km"; /*( unit#=[s,km,km,...] unit on #-th axis )*/ if (*unit != '\0' && (*unit != ' ' || *(unit+1) != '\0')) sf_putstring(spike,key,unit); } if (NULL != (label = sf_getstring("title"))) sf_putstring(spike,"title",label); /* title for plots */ if (!sf_getint("nsp",&nsp)) nsp=1; /* Number of spikes */ if (nsp >= 1) { mag = sf_floatalloc (nsp); k = sf_intalloc2 (nsp,dim); l = sf_intalloc2 (nsp,dim); p = sf_floatalloc2 (nsp,dim); for (i=0; i < dim; i++) { snprintf(key,3,"k%d",i+1); if ( !sf_getints(key,k[i],nsp)) { /*( k#=[0,...] spike starting position )*/ for (is=0; is < nsp; is++) { k[i][is]=-1; } } else { for (is=0; is < nsp; is++) { if (k[i][is] > n[i]) sf_error("Invalid k%d[%d]=%d > n%d=%d", i+1,is+1,k[i][is],i+1,n[i]); k[i][is]--; /* C notation */ } } snprintf(key,3,"l%d",i+1); if (!sf_getints(key,l[i],nsp)) { /*( l#=[k1,k2,...] spike ending position )*/ for (is=0; is < nsp; is++) { l[i][is]=k[i][is]; } } else { for (is=0; is < nsp; is++) { if (l[i][is] > n[i]) sf_error("Invalid l%d[%d]=%d > n%d=%d", i+1,is+1,l[i][is],i+1,n[i]); l[i][is]--; /* C notation */ } } snprintf(key,3,"p%d",i+1); if (!sf_getfloats(key,p[i],nsp)) { /*( p#=[0,...] spike inclination (in samples) )*/ for (is=0; is < nsp; is++) { p[i][is]=0.; } } } if (!sf_getfloats("mag",mag,nsp)) { /* spike magnitudes */ for (is=0; is < nsp; is++) { mag[is]=1.; } } } n1 = n[0]; n2 = sf_leftsize(spike,1); trace = sf_floatalloc (n[0]); for (i2=0; i2 < n2; i2++) { /* loop over traces */ sf_line2cart(dim-1, n+1, i2, ii+1); /* zero trace */ for (i1=0; i1 < n1; i1++) trace[i1]=0.; /* put spikes in it */ for (is=0; is < nsp; is++) { /* loop over spikes */ pp = 0.; for (i=1; i < dim; i++) { kk = k[i][is]; ll = l[i][is]; if ((kk < -1 && ll < -1) || (kk >= 0 && ll >= 0 && (kk > ii[i] || ll < ii[i]))) break; pp += p[i][is]*(ii[i]-k[i][is]-1); } if (i < dim) continue; /* skip this spike */ /* linear interpolation */ ip = floorf(pp); pp = 1.-(pp-ip); kk = k[0][is]; ll = l[0][is]; if (kk >= 0) { /* one segment per trace */ kk = SF_MAX(kk+ip,0); ll = SF_MIN(ll+ip,n1-1); } else { kk = SF_MAX(ip,0); ll = SF_MIN(n1-1+ip,n1-1); } for (j=kk; j <= ll; j++) { trace[j] += pp*mag[is]; if (j+1 < n1) trace[j+1] += (1.-pp)*mag[is]; } } sf_floatwrite(trace,n1,spike); } exit (0); }
int main (int argc, char* argv[]) { int nz, nx, ny, nb, na, ib, ia, iz, ix, iy, i, it, nt, ic, nc = 1, fz, lz, itr = 0; float dz, oz, dx, ox, dy, oy, db, ob, da, oa, z, x, y, a, dt, df, md, aper; float ****e; sf_file spdom, vspline = NULL, out, traj = NULL; sf_escrt3_traj_cbud *tdata = NULL; char *ext = NULL; bool verb, parab; sf_esc_slowness3 esc_slow; sf_esc_tracer3 *esc_tracers; sf_esc_point3 *esc_points; sf_timer timer; sf_init (argc, argv); if (!sf_stdin ()) { spdom = NULL; } else { spdom = sf_input ("in"); /* Spatial (z,x,y) domain */ } out = sf_output ("out"); /* Escape values */ /* Spatial dimensions */ if (spdom) { if (!sf_histint (spdom, "n1", &nz)) sf_error ("No n1= in input"); if (!sf_histint (spdom, "n2", &nx)) sf_error ("No n2= in input"); if (!sf_histint (spdom, "n3", &ny)) sf_error ("No n3= in input"); if (!sf_histfloat (spdom, "d1", &dz)) sf_error ("No d1= in input"); if (!sf_histfloat (spdom, "o1", &oz)) sf_error ("No o1= in input"); if (!sf_histfloat (spdom, "d2", &dx)) sf_error ("No d2= in input"); if (!sf_histfloat (spdom, "o2", &ox)) sf_error ("No o2= in input"); if (!sf_histfloat (spdom, "d3", &dy)) sf_error ("No d3= in input"); if (!sf_histfloat (spdom, "o3", &oy)) sf_error ("No o3= in input"); } ext = sf_escrt3_warnext (spdom); if (!sf_getint ("nz", &nz) && !spdom) sf_error ("Need nz="); /* Number of samples in z axis */ if (!sf_getfloat ("oz", &oz) && !spdom) sf_error ("Need oz="); /* Beginning of z axis */ if (!sf_getfloat ("dz", &dz) && !spdom) sf_error ("Need dz="); /* Sampling of z axis */ if (!sf_getint ("nx", &nx) && !spdom) sf_error ("Need nx="); /* Number of samples in x axis */ if (!sf_getfloat ("ox", &ox) && !spdom) sf_error ("Need ox="); /* Beginning of x axis */ if (!sf_getfloat ("dx", &dx) && !spdom) sf_error ("Need dx="); /* Sampling of x axis */ if (!sf_getint ("ny", &ny) && !spdom) sf_error ("Need ny="); /* Number of samples in y axis */ if (!sf_getfloat ("oy", &oy) && !spdom) sf_error ("Need oy="); /* Beginning of y axis */ if (!sf_getfloat ("dy", &dy) && !spdom) sf_error ("Need dy="); /* Sampling of y axis */ if (!sf_getint ("na", &na)) na = 360; /* Number of azimuth phase angles */ da = 2.0*SF_PI/(float)na; oa = 0.5*da; if (!sf_getint ("nb", &nb)) nb = 180; /* Number of inclination phase angles */ db = SF_PI/(float)nb; ob = 0.5*db; if (!sf_getfloat ("df", &df)) df = 0.1; /*< Maximum distance to travel per step (fraction of the cell size) >*/ if (!sf_getfloat ("md", &md)) md = SF_HUGE; /* Maximum distance for a ray to travel (default - up to model boundaries) */ if (md != SF_HUGE) md = fabsf (md); if (!sf_getfloat ("aper", &aper)) aper = SF_HUGE; /* Maximum aperture in x and y directions from current point (default - up to model boundaries) */ if (aper != SF_HUGE) aper = fabsf (aper); #ifdef _OPENMP if (!sf_getint ("nc", &nc)) nc = 0; /* Number of threads to use for ray tracing (OMP_NUM_THREADS by default) */ if (nc) omp_set_num_threads (nc); /* User override */ else nc = omp_get_max_threads (); /* Current default */ sf_warning ("%s Using %d threads", ext, omp_get_max_threads ()); #endif if (!sf_getbool ("parab", ¶b)) parab = true; /* y - use parabolic approximation of trajectories, n - straight line */ if (!sf_getbool ("verb", &verb)) verb = false; /* verbosity flag */ if (sf_getstring ("traj")) { /* Trajectory output */ traj = sf_output ("traj"); if (!sf_getint ("nt", &nt)) nt = 1001; /* Number of time samples for each trajectory */ if (!sf_getfloat ("dt", &dt)) dt = 0.001; /* Time sampling */ tdata = (sf_escrt3_traj_cbud*)sf_alloc (nc*na*nb, sizeof(sf_escrt3_traj_cbud)); for (itr = 0; itr < nc*na*nb; itr++) { tdata[itr].it = 0; tdata[itr].nt = nt; tdata[itr].dt = dt; tdata[itr].pnts = sf_floatalloc2 (TRAJ3_COMPS - 1, nt); } } e = sf_floatalloc4 (ESC3_NUM, nb, na, nc); if (!sf_getstring ("vspl")) sf_error ("Need vspl="); /* Spline coefficients for velocity model */ vspline = sf_input ("vspl"); /* Slowness components module [(an)isotropic] */ esc_slow = sf_esc_slowness3_init (vspline, verb); /* Make room for escape variables in output */ if (spdom) sf_shiftdimn (spdom, out, 1, 3); sf_putint (out, "n1", ESC3_NUM); sf_putfloat (out, "o1", 0.0); sf_putfloat (out, "d1", 1.0); sf_putstring (out, "label1", "Escape variable"); sf_putstring (out, "unit1", ""); sf_putint (out, "n2", nb); sf_putfloat (out, "d2", db*180.0/SF_PI); sf_putfloat (out, "o2", ob*180.0/SF_PI); sf_putstring (out, "label2", "Inclination"); sf_putstring (out, "unit2", "Degrees"); sf_putint (out, "n3", na); sf_putfloat (out, "d3", da*180.0/SF_PI); sf_putfloat (out, "o3", oa*180.0/SF_PI); sf_putstring (out, "label3", "Azimuth"); sf_putstring (out, "unit3", "Degrees"); sf_putint (out, "n4", nz); sf_putfloat (out, "o4", oz); sf_putfloat (out, "d4", dz); if (!spdom) { sf_putstring (out, "label4", "Depth"); sf_putstring (out, "unit4", ""); } sf_putint (out, "n5", nx); sf_putfloat (out, "o5", ox); sf_putfloat (out, "d5", dx); if (!spdom) { sf_putstring (out, "label5", "X"); sf_putstring (out, "unit5", ""); } sf_putint (out, "n6", ny); sf_putfloat (out, "o6", oy); sf_putfloat (out, "d6", dy); if (!spdom) { sf_putstring (out, "label6", "Y"); sf_putstring (out, "unit6", ""); } /* Save min/max possible escape values */ sf_putfloat (out, "Zmin", sf_esc_slowness3_oz (esc_slow)); sf_putfloat (out, "Zmax", sf_esc_slowness3_oz (esc_slow) + (sf_esc_slowness3_nz (esc_slow) - 1)* sf_esc_slowness3_dz (esc_slow)); sf_putfloat (out, "Xmin", sf_esc_slowness3_ox (esc_slow)); sf_putfloat (out, "Xmax", sf_esc_slowness3_ox (esc_slow) + (sf_esc_slowness3_nx (esc_slow) - 1)* sf_esc_slowness3_dx (esc_slow)); sf_putfloat (out, "Ymin", sf_esc_slowness3_oy (esc_slow)); sf_putfloat (out, "Ymax", sf_esc_slowness3_oy (esc_slow) + (sf_esc_slowness3_ny (esc_slow) - 1)* sf_esc_slowness3_dy (esc_slow)); if (traj) { if (spdom) sf_shiftdimn (spdom, traj, 1, 4); sf_putint (traj, "n1", TRAJ3_COMPS - 1); sf_putfloat (traj, "o1", 0.0); sf_putfloat (traj, "d1", 1.0); sf_putstring (traj, "label1", "Escape variable"); sf_putstring (traj, "unit1", ""); sf_putint (traj, "n2", nt); sf_putfloat (traj, "o2", 0.0); sf_putfloat (traj, "d2", dt); sf_putstring (traj, "label2", "Time"); sf_putstring (traj, "unit2", "s"); sf_putint (traj, "n3", nb); sf_putfloat (traj, "d3", db*180.0/SF_PI); sf_putfloat (traj, "o3", ob*180.0/SF_PI); sf_putstring (traj, "label3", "Inclination"); sf_putstring (traj, "unit3", "Degrees"); sf_putint (traj, "n4", na); sf_putfloat (traj, "d4", da*180.0/SF_PI); sf_putfloat (traj, "o4", oa*180.0/SF_PI); sf_putstring (traj, "label4", "Azimuth"); sf_putstring (traj, "unit4", "Degrees"); sf_putint (traj, "n5", nz); sf_putfloat (traj, "o5", oz); sf_putfloat (traj, "d5", dz); if (!spdom) { sf_putstring (traj, "label5", "Depth"); sf_putstring (traj, "unit5", ""); } sf_putint (traj, "n6", nx); sf_putfloat (traj, "o6", ox); sf_putfloat (traj, "d6", dx); if (!spdom) { sf_putstring (traj, "label6", "X"); sf_putstring (traj, "unit6", ""); } sf_putint (traj, "n7", ny); sf_putfloat (traj, "o7", oy); sf_putfloat (traj, "d7", dy); if (!spdom) { sf_putstring (traj, "label7", "Y"); sf_putstring (traj, "unit7", ""); } } esc_tracers = (sf_esc_tracer3*)sf_alloc (nc, sizeof(sf_esc_tracer3)); esc_points = (sf_esc_point3*)sf_alloc (nc, sizeof(sf_esc_point3)); for (ic = 0; ic < nc; ic++) { esc_tracers[ic] = sf_esc_tracer3_init (esc_slow); sf_esc_tracer3_set_parab (esc_tracers[ic], parab); if (md != SF_HUGE) sf_esc_tracer3_set_mdist (esc_tracers[ic], md); sf_esc_tracer3_set_df (esc_tracers[ic], df); esc_points[ic] = sf_esc_point3_init (); } timer = sf_timer_init (); /* Ray tracing loop */ for (iy = 0; iy < ny; iy++) { y = oy + iy*dy; /* Set aperture */ if (aper != SF_HUGE) { for (ic = 0; ic < nc; ic++) { sf_esc_tracer3_set_ymin (esc_tracers[ic], y - aper); sf_esc_tracer3_set_ymax (esc_tracers[ic], y + aper); } } for (ix = 0; ix < nx; ix++) { x = ox + ix*dx; /* Set aperture */ if (aper != SF_HUGE) { for (ic = 0; ic < nc; ic++) { sf_esc_tracer3_set_xmin (esc_tracers[ic], x - aper); sf_esc_tracer3_set_xmax (esc_tracers[ic], x + aper); } } if (verb) sf_warning ("%s Shooting from lateral location %d of %d at y=%g, x=%g;", ext, iy*nx + ix + 1, ny*nx, y, x); /* Loop over chunks */ for (ic = 0; ic < (nz/nc + ((nz % nc) != 0)); ic++) { fz = ic*nc; lz = (ic + 1)*nc - 1; if (lz >= nz) lz = nz - 1; sf_timer_start (timer); #ifdef _OPENMP #pragma omp parallel for \ schedule(static,1) \ private(iz,ia,ib,a,z,it,i,itr) \ shared(fz,lz,iy,ix,nb,na,nz,nx,ny,ob,oa,oz,ox,oy,db,da,dz,dx,dy,x,y,tdata,esc_tracers,esc_points,e,out,traj) #endif for (iz = fz; iz <= lz; iz++) { z = oz + iz*dz; for (ia = 0; ia < na; ia++) { a = oa + ia*da; for (ib = 0; ib < nb; ib++) { if (traj) { itr = (iz - fz)*na*nb + ia*nb + ib; sf_esc_tracer3_set_trajcb (esc_tracers[iz - fz], sf_escrt3_traj, dt, (void*)&tdata[itr]); } sf_esc_tracer3_compute (esc_tracers[iz - fz], z, x, y, ob + ib*db, a, 0.0, 0.0, esc_points[iz - fz], NULL, NULL); /* Copy escape values to the output buffer */ for (i = 0; i < ESC3_NUM; i++) e[iz - fz][ia][ib][i] = sf_esc_point3_get_esc_var (esc_points[iz - fz], i); if (traj) { /* Fill the rest of the trajectory with the last point */ for (it = tdata[itr].it + 1; it < tdata[itr].nt; it++) { for (i = 0; i < TRAJ3_COMPS - 1; i++) tdata[itr].pnts[it][i] = tdata[itr].pnts[tdata[itr].it][i]; } } } /* Loop over b */ } /* Loop over a */ } /* Loop over z */ sf_timer_stop (timer); sf_floatwrite (e[0][0][0], (size_t)(lz - fz + 1)*(size_t)nb*(size_t)na*(size_t)ESC3_NUM, out); if (tdata) { for (itr = 0; itr < (lz - fz + 1)*na*nb; itr++) { sf_floatwrite (tdata[itr].pnts[0], (size_t)tdata[itr].nt*(size_t)(TRAJ3_COMPS - 1), traj); } } } /* Loop over z chunks */ } /* Loop over x */ } /* Loop over y */ if (verb) { sf_warning ("."); sf_warning ("%s Total kernel time: %g s, per depth point: %g s", ext, sf_timer_get_total_time (timer)/1000.0, (sf_timer_get_total_time (timer)/(float)((size_t)nx*(size_t)ny*(size_t)nz))/1000.0); } sf_timer_close (timer); for (ic = 0; ic < nc; ic++) { sf_esc_point3_close (esc_points[ic]); sf_esc_tracer3_close (esc_tracers[ic]); } free (esc_points); free (esc_tracers); if (traj) { for (itr = 0; itr < nc*na*nb; itr++) { free (tdata[itr].pnts[0]); free (tdata[itr].pnts); } free (tdata); } sf_esc_slowness3_close (esc_slow); free (e[0][0][0]); free (e[0][0]); free (e[0]); free (e); free (ext); sf_fileclose (vspline); if (traj) sf_fileclose (traj); return 0; }
int main(int argc, char* argv[]) { bool verb; sf_axis az,ah,ahx,ahy,ahz; int iz, ihx,ihy,ihz; int nz, nhx,nhy,nhz; float hx, hy, hz; float oh,dh,ohx,dhx,ohy,dhy,ohz,dhz; sf_bands spl; sf_file Fd; /* data = vector offset (hx,hy,hz)-z */ sf_file Fm; /* model = absolute offset h -z */ int nw; /* spline order */ int nd,id; /* data size (nd=nhx*nhy*nhz) */ int nh; /* model size (nm=nh) */ float *dat=NULL; float *mod=NULL; float *map=NULL; float *mwt=NULL; float *dwt=NULL; int i; /* int im;*/ /*------------------------------------------------------------*/ sf_init(argc,argv); if(! sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ if(! sf_getint( "nw",&nw)) nw=4; /* spline order */ Fd = sf_input ("in"); ahx = sf_iaxa(Fd,1); sf_setlabel(ahx,"hx"); if(verb) sf_raxa(ahx); ahy = sf_iaxa(Fd,2); sf_setlabel(ahy,"hy"); if(verb) sf_raxa(ahy); ahz = sf_iaxa(Fd,3); sf_setlabel(ahz,"hz"); if(verb) sf_raxa(ahz); az = sf_iaxa(Fd,4); sf_setlabel(az,"z"); if(verb) sf_raxa(az); nhx = sf_n(ahx); ohx = sf_o(ahx); dhx = sf_d(ahx); nhy = sf_n(ahy); ohy = sf_o(ahy); dhy = sf_d(ahy); nhz = sf_n(ahz); ohz = sf_o(ahz); dhz = sf_d(ahz); nz = sf_n(az); if(!sf_getint ("nh",&nh)) nh=nhx + ohx/dhx; if(!sf_getfloat("oh",&oh)) oh=0; if(!sf_getfloat("dh",&dh)) dh=dhx; ah = sf_maxa(nh,oh,dh); sf_setlabel(ah,"h"); if(verb) sf_raxa(ah); Fm = sf_output("out"); sf_oaxa(Fm,ah,1); sf_oaxa(Fm,az,2); sf_putint(Fm,"n3",1); sf_putint(Fm,"n4",1); /*------------------------------------------------------------*/ nd = nhx*nhy*nhz; /* data size */ map = sf_floatalloc(nd); /* mapping */ mod = sf_floatalloc(nh); /* model vector */ dat = sf_floatalloc(nd); /* data vector */ mwt = sf_floatalloc(nh); /* model weight */ dwt = sf_floatalloc(nd); /* data weight */ spl = sf_spline_init(nw,nd); for(ihz=0;ihz<nhz;ihz++) { hz = ohz + ihz * dhz; hz*=hz; for(ihy=0;ihy<nhy;ihy++) { hy = ohy + ihy * dhy; hy*=hy; for(ihx=0;ihx<nhx;ihx++) { hx = ohx + ihx * dhx; hx*=hx; i = ihz * nhx*nhy + ihy * nhx + ihx; map[i] = sqrtf(hx+hy+hz); } } } sf_int1_init( map, oh, dh, nh, sf_spline_int, nw, nd, 0.0); for(id=0;id<nd;id++) { dwt[id]=1; } sf_banded_solve(spl,dwt); for(iz=0;iz<nz;iz++) { sf_warning("iz=%d of %d",iz+1,nz); sf_floatread(dat,nd,Fd); sf_banded_solve(spl,dat); sf_int1_lop( true, /* adj */ false, /* add */ nh, /* n model */ nd, /* n data */ mod, dat); sf_floatwrite(mod,nh,Fm); } /*------------------------------------------------------------*/ sf_int1_close(); free(map); free(mod); free(dat); free(mwt); free(dwt); exit(0); }