int main(int argc, char* argv[]) { int nz,nx,ny,sou_z,sou_ox,sou_oy,sou_jx,sou_jy,sou_nx,sou_ny,rec_z,rec_nx,rec_ny,npad,noff,roll; int dim1, dim2; sf_axis ad1=NULL, ad2=NULL; sf_file Fgeo=NULL; int **geo=NULL; sf_init(argc,argv); if (!sf_getint("nz",&nz)) sf_error("Need nz="); /* dimension in z */ if (!sf_getint("nx",&nx)) sf_error("Need nx="); /* dimension in x */ if (!sf_getint("ny",&ny)) sf_error("Need ny="); /* dimension in y */ if (!sf_getint("sou_z", &sou_z )) sf_error("Need sou_z=" ); /* source position in depth */ if (!sf_getint("sou_ox",&sou_ox)) sf_error("Need sou_ox="); /* source starting location in x */ if (!sf_getint("sou_oy",&sou_oy)) sf_error("Need sou_oy="); /* source starting location in y */ if (!sf_getint("sou_nx",&sou_nx)) sf_error("Need sou_nx="); /* number of sources in x */ if (!sf_getint("sou_ny",&sou_ny)) sf_error("Need sou_ny="); /* number of sources in y */ if (!sf_getint("sou_jx",&sou_jx)) sou_jx = (sou_nx>1)? (nx-sou_ox)/(sou_nx-1):0; /* source interval in x */ if (!sf_getint("sou_jy",&sou_jy)) sou_jy = (sou_ny>1)? (ny-sou_oy)/(sou_ny-1):0; /* source interval in y */ if (!sf_getint("rec_z", &rec_z )) sf_error("Need rec_z=" ); /* receiver position in depth */ if (!sf_getint("rec_nx",&rec_nx)) sf_error("Need rec_nx="); /* number of receivers in x */ if (!sf_getint("rec_ny",&rec_ny)) sf_error("Need rec_ny="); /* number of receivers in y */ if (!sf_getint("npad",&npad)) sf_error("Need npad="); /* computational domain padding */ if (!sf_getint("noff",&noff)) sf_error("Need noff="); /* near offset */ if (!sf_getint("roll",&roll)) sf_error("Need roll="); /* acquisition pattern: 0-> fixed-spread, 1-> towed-streamer to the negative */ /* double check dimension */ if (sou_nx > (nx-sou_ox)/sou_jx+1) { sou_nx = (nx-sou_ox)/sou_jx+1; sf_warning("Setting sou_nx to %d",sou_nx); } if (sou_ny > 1 && sou_ny > (ny-sou_oy)/sou_jy+1) { sou_ny = (ny-sou_oy)/sou_jy+1; sf_warning("Setting sou_ny to %d",sou_ny); } /* do the work */ dim1 = 14; dim2 = sou_nx*sou_ny; ad1 = sf_maxa(dim1,0,1); sf_setlabel(ad1,"acqpar"); sf_raxa(ad1); ad2 = sf_maxa(dim2,0,1); sf_setlabel(ad2,"shot"); sf_raxa(ad2); Fgeo = sf_output("out"); sf_settype(Fgeo,SF_INT); sf_oaxa(Fgeo,ad1,1); sf_oaxa(Fgeo,ad2,2); geo = sf_intalloc2(dim1,dim2); geogen(geo,nz,nx,ny,sou_z,sou_ox,sou_oy,sou_jx,sou_jy,sou_nx,sou_ny,rec_z,rec_nx,rec_ny,npad,noff,roll); sf_intwrite(geo[0],dim1*dim2,Fgeo); exit(0); }
int main(int argc, char*argv[]) { sf_file in, out ; int i1, i2, n1, n2, *v; float o1, d1, **u; char *l1, *u1; sf_axis ax; sf_init(argc, argv); in = sf_input("in"); /* delay file (int) */ out = sf_output("out"); if(!sf_histint(in, "n1", &n2)) sf_error("n1 needed"); sf_shiftdim(in, out, 1); if(!sf_getint("n1", &n1)) n1=1000; /* samples */ if(!sf_getfloat("o1", &o1)) o1=0.0; /* sampling interval */ if(!sf_getfloat("d1", &d1)) d1=0.004; /* original */ if((l1=sf_getstring("l1")) == NULL) l1="Time"; /* label "Time" */ if((u1=sf_getstring("u1")) == NULL) u1="s"; /* unit "s" */ ax = sf_maxa(n1, o1, d1); sf_setlabel(ax, l1); sf_setunit(ax, u1); sf_oaxa(out, ax, 1); sf_putint(out, "n2", n2); sf_settype(out, SF_FLOAT); v = sf_intalloc(n2); u = sf_floatalloc2(n1, n2); sf_intread(v, n2, in); for(i2=0; i2<n2; i2++) for(i1=0; i1<n1; i1++) if(i1==v[i2]) u[i2][i1] = 1; else u[i2][i1] = 0; sf_floatwrite(u[0], n1*n2, out); free(v); free(u[0]); free(u); return 0; }
int main(int argc, char* argv[]) { bool verb,adj; /* I/O files */ sf_file Ftrc=NULL; /* traces */ sf_file Fcoo=NULL; /* coordinates */ sf_file Fwfl=NULL; /* wavefield */ /* cube axes */ sf_axis at,az,ax,aa,ac; /* I/O arrays */ float *wco=NULL; /* traces */ pt2d *coo=NULL; /* coordinates */ lint2d cow; /* weights/indices */ float **wfl=NULL; /* wavefield */ fdm2d fdm=NULL; int iz,ix,it; int nz,nx; float dz,dx; float oz,ox; /*------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); /*------------------------------------------------------------*/ if(! sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ if(! sf_getbool("adj", &adj)) adj=false; /* adjoint flag */ /*------------------------------------------------------------*/ /* setup I/O */ Fcoo = sf_input("coo"); /* coordinates */ ac = sf_iaxa(Fcoo,2); sf_setlabel(ac,"c"); sf_setunit(ac,""); coo = (pt2d*) sf_alloc(sf_n(ac),sizeof(*coo)); pt2dread1(Fcoo,coo,sf_n(ac),2); /* read (x,z) coordinates */ if(adj) { Fwfl = sf_input ("in"); /* wavefield */ Ftrc = sf_output("out"); /* traces */ az = sf_iaxa(Fwfl,1); sf_setlabel(az,"z"); ax = sf_iaxa(Fwfl,2); sf_setlabel(ax,"x"); at = sf_iaxa(Fwfl,3); sf_setlabel(at,"t"); aa = sf_maxa(1,0,1); sf_oaxa(Ftrc,ac,1); sf_oaxa(Ftrc,at,2); sf_oaxa(Ftrc,aa,3); } else { Ftrc = sf_input ("in" ); /* traces */ Fwfl = sf_output("out"); /* wavefield */ at = sf_iaxa(Ftrc,2); sf_setlabel(at,"t"); if(!sf_getint ("nz",&nz)) nz=1; if(!sf_getfloat("oz",&oz)) oz=0.0; if(!sf_getfloat("dz",&dz)) dz=1.0; az = sf_maxa(nz,oz,dz); sf_setlabel(az,"z"); if(!sf_getint ("nx",&nx)) nx=1; if(!sf_getfloat("ox",&ox)) ox=0.0; if(!sf_getfloat("dx",&dx)) dx=1.0; ax = sf_maxa(nx,ox,dx); sf_setlabel(ax,"x"); sf_oaxa(Fwfl,az,1); sf_oaxa(Fwfl,ax,2); sf_oaxa(Fwfl,at,3); } if(verb) { sf_raxa(az); sf_raxa(ax); sf_raxa(at); sf_raxa(ac); } /* allocate wavefield arrays */ wco = sf_floatalloc (sf_n(ac)); wfl = sf_floatalloc2(sf_n(az),sf_n(ax)); /* interpolation coefficients */ fdm = fdutil_init(verb,'n',az,ax,0,1); cow = lint2d_make(sf_n(ac),coo,fdm); /*------------------------------------------------------------*/ /* * MAIN LOOP */ /*------------------------------------------------------------*/ if(verb) fprintf(stderr,"\n"); for (it=0; it<sf_n(at); it++) { if(verb) fprintf(stderr,"\b\b\b\b\b%d",it); if(adj) { sf_floatread(wfl[0],sf_n(az)*sf_n(ax),Fwfl); lint2d_extract(wfl,wco,cow); sf_floatwrite(wco,sf_n(ac),Ftrc); } else { sf_floatread(wco,sf_n(ac),Ftrc); for (ix=0; ix<sf_n(ax); ix++) for(iz=0; iz<sf_n(az); iz++) wfl[ix][iz]=0; lint2d_inject(wfl,wco,cow); sf_floatwrite(wfl[0],sf_n(az)*sf_n(ax),Fwfl); } } /* end time loop */ if(verb) fprintf(stderr,"\n"); /*------------------------------------------------------------*/ /* deallocate arrays */ free(*wfl); free(wfl); free(wco); free(coo); /*------------------------------------------------------------*/ /* close files */ if (Ftrc!=NULL) sf_fileclose(Ftrc); if (Fwfl!=NULL) sf_fileclose(Fwfl); if (Fcoo!=NULL) sf_fileclose(Fcoo); exit (0); }
int main(int argc, char** argv) { bool verb, fsrf, snap, expl, dabc, cden, adj; bool optfd, hybrid, sinc; int jsnap, jdata; /* I/O files */ sf_file file_wav=NULL; /* wavelet */ sf_file file_vel=NULL; /* velocity */ sf_file file_den=NULL; /* density */ sf_file file_wfl=NULL; /* wavefield */ sf_file file_dat=NULL; /* data */ sf_file file_src=NULL; /* sources */ sf_file file_rec=NULL; /* receivers */ /* cube axes */ sf_axis at = NULL, az = NULL, ax = NULL, ay = NULL; sf_axis as = NULL, ar = NULL; int nbd; /* ABC boundary size */ int fdorder; /* finite difference spatial accuracy order */ int nzpad,nxpad,nypad; /* boundary padded model size */ int ix,iy,it,is,nx,ny,nz,nt,ns,nr; float dx,dy,dz,dt,dt2; float* damp=NULL; /* damping profile for hybrid bc */ float* ws; /* wavelet */ float*** vel=NULL; /* velocity */ float*** rho=NULL; /* density */ float*** u0=NULL; /* wavefield array u@t-1 (u@t+1) */ float*** u1=NULL; /* wavefield array u@t */ float* u_dat=NULL; /* output data */ float*** ptr_tmp=NULL; pt3d* src3d=NULL; /* source position */ pt3d* rec3d=NULL; /*receiver position*/ scoef3d cssinc = NULL, crsinc = NULL; lint3d cslint = NULL, crlint = NULL; /* FDM structure */ fdm3d fdm = NULL; abcone3d abc = NULL; sponge spo = NULL; int nbell; float* fdcoef_d2; float* fdcoef_d1; sf_axis acz = NULL, acx = NULL, acy = NULL; int nqz, nqx, nqy; float oqz, oqx, oqy, dqz, dqx, dqy; float** oslice = NULL; /* output 3D wavefield slice-by-slice */ float*** tmp_array; double wall_clock_time_s, wall_clock_time_e; const int SECOND_DERIV = 2; const int FIRST_DERIV = 1; int nop; #if defined _OPENMP && _DEBUG double tic; double toc; #endif /* init RSF */ sf_init(argc,argv); #ifdef _OPENMP omp_init(); wall_clock_time_s = omp_get_wtime(); #else wall_clock_time_s = (double) clock() / CLOCKS_PER_SEC; #endif if (!sf_getbool("verb",&verb)) verb=false; /* Verbosity flag */ if (!sf_getbool("snap",&snap)) snap=false; /* Wavefield snapshots flag */ if (!sf_getbool("expl",&expl)) expl=false; /* Multiple sources, one wvlt*/ if (!sf_getbool("dabc",&dabc)) dabc=false; /* Absorbing BC */ if (!sf_getbool("cden",&cden)) cden=false; /* Constant density */ if (!sf_getbool("adj",&adj)) adj=false; /* adjoint flag */ if (!sf_getbool("free",&fsrf) && !sf_getbool("fsrf",&fsrf)) fsrf=false; /* Free surface flag */ if (!sf_getint("nbell",&nbell)) nbell=5; /* gaussian for source injection */ if (!sf_getbool("optfd",&optfd)) optfd=false; /* optimized FD coefficients flag */ if (!sf_getint("fdorder",&fdorder)) fdorder=4; /* spatial FD order */ if (!sf_getbool("hybridbc",&hybrid)) hybrid=false; /* hybrid Absorbing BC */ if (!sf_getbool("sinc",&sinc)) sinc=false; /* sinc source injection */ /* Initialize variables */ file_wav = sf_input("in"); /* wavelet */ file_vel = sf_input("vel"); /* velocity */ file_src = sf_input("sou"); /* sources */ file_rec = sf_input("rec"); /* receivers */ file_dat = sf_output("out"); /* data */ if (snap) file_wfl = sf_output("wfl"); /* wavefield */ if (!cden) { if (sf_getstring("cden")) { file_den = sf_input ("den"); /* density */ } else { cden = true; if (verb) sf_warning("No density file provided, running with constant density"); } } at = sf_iaxa(file_wav,2); sf_setlabel(at,"t"); if(verb) sf_raxa(at); /* time */ az = sf_iaxa(file_vel,1); sf_setlabel(az,"z"); if(verb) sf_raxa(az); /* depth */ ax = sf_iaxa(file_vel,2); sf_setlabel(ax,"x"); if(verb) sf_raxa(ax); /* space */ ay = sf_iaxa(file_vel,3); sf_setlabel(ay,"y"); if(verb) sf_raxa(ay); /* space */ as = sf_iaxa(file_src,2); sf_setlabel(as,"s"); if(verb) sf_raxa(as); /* sources */ ar = sf_iaxa(file_rec,2); sf_setlabel(ar,"r"); if(verb) sf_raxa(ar); /* receivers */ nt = sf_n(at); dt = sf_d(at); nz = sf_n(az); dz = sf_d(az); nx = sf_n(ax); dx = sf_d(ax); ny = sf_n(ay); dy = sf_d(ay); ns = sf_n(as); nr = sf_n(ar); /* other execution parameters */ if (snap) { if (!sf_getint("jsnap",&jsnap)) jsnap=nt; /* # of t steps at which to save wavefield */ } if (!sf_getint("jdata",&jdata)) jdata=1; /* # of t steps at which to save receiver data */ /* setup output data header */ sf_oaxa(file_dat,ar,1); sf_setn(at,(nt-1)/jdata+1); sf_setd(at,dt*jdata); sf_oaxa(file_dat,at,2); /* wavefield cut params */ /* setup output wavefield header */ if (snap) { if (!sf_getint ("nqz",&nqz)) nqz=sf_n(az); /* Saved wfld window nz */ if (!sf_getint ("nqx",&nqx)) nqx=sf_n(ax); /* Saved wfld window nx */ if (!sf_getint ("nqy",&nqy)) nqy=sf_n(ay); /* Saved wfld window ny */ if (!sf_getfloat("oqz",&oqz)) oqz=sf_o(az); /* Saved wfld window oz */ if (!sf_getfloat("oqx",&oqx)) oqx=sf_o(ax); /* Saved wfld window ox */ if (!sf_getfloat("oqy",&oqy)) oqy=sf_o(ay); /* Saved wfld window oy */ if (!sf_getfloat("dqz",&dqz)) dqz=sf_d(az); /* Saved wfld window dz */ if (!sf_getfloat("dqx",&dqx)) dqx=sf_d(ax); /* Saved wfld window dx */ if (!sf_getfloat("dqy",&dqy)) dqy=sf_d(ay); /* Saved wfld window dy */ acz = sf_maxa(nqz,oqz,dqz); if (verb) sf_raxa(acz); acx = sf_maxa(nqx,oqx,dqx); if (verb) sf_raxa(acx); acy = sf_maxa(nqy,oqy,dqy); if (verb) sf_raxa(acy); /* check if the imaging window fits in the wavefield domain */ sf_setn(at,(nt-1)/jsnap+1); sf_setd(at,dt*jsnap); if (verb) sf_raxa(at); sf_oaxa(file_wfl,acz,1); sf_oaxa(file_wfl,acx,2); sf_oaxa(file_wfl,acy,3); sf_oaxa(file_wfl,at,4); } /* 2-2N finite difference coefficient */ nop = fdorder/2; /* fd half-length stencil */ if (!sf_getint("nb",&nbd) || nbd<nop) nbd=nop; if (dabc && hybrid && nbd<=nop) nbd = 2*nop; /* expand domain for FD operators and ABC */ fdm = fdutil3d_init(verb,fsrf,az,ax,ay,nbd,1); sf_setn(az,fdm->nzpad); sf_seto(az,fdm->ozpad); if (verb) sf_raxa(az); sf_setn(ax,fdm->nxpad); sf_seto(ax,fdm->oxpad); if (verb) sf_raxa(ax); sf_setn(ay,fdm->nypad); sf_seto(ay,fdm->oypad); if (verb) sf_raxa(ay); /* Precompute coefficients */ dt2 = dt*dt; nzpad = nz+2*nbd; nxpad = nx+2*nbd; nypad = ny+2*nbd; fdcoef_d2 = compute_fdcoef(nop,dz,dx,dy,optfd,SECOND_DERIV); fdcoef_d1 = compute_fdcoef(nop,dz,dx,dy,optfd,FIRST_DERIV); /* Allocate memories */ if (expl) ws = sf_floatalloc(1); else ws = sf_floatalloc(ns); vel = sf_floatalloc3(nzpad,nxpad,nypad); if (!cden) rho = sf_floatalloc3(nzpad,nxpad,nypad); u_dat = sf_floatalloc(nr); src3d = pt3dalloc1(ns); rec3d = pt3dalloc1(nr); if (snap) oslice = sf_floatalloc2(sf_n(acz),sf_n(acx)); /* source and receiver position */ pt3dread1(file_src,src3d,ns,3); /* read format: (x,y,z) */ if (sinc) cssinc = sinc3d_make(ns,src3d,fdm); else cslint = lint3d_make(ns,src3d,fdm); pt3dread1(file_rec,rec3d,nr,3); /* read format: (x,y,z) */ if (sinc) crsinc = sinc3d_make(nr,rec3d,fdm); else crlint = lint3d_make(nr,rec3d,fdm); if (!sinc) fdbell3d_init(nbell); /* temperary array */ tmp_array = sf_floatalloc3(nz,nx,ny); /* read velocity and pad */ sf_floatread(tmp_array[0][0],nz*nx*ny,file_vel); expand3d(tmp_array,vel,fdm); /* read density and pad */ if (!cden) { sf_floatread(tmp_array[0][0],nz*nx*ny,file_den); expand3d(tmp_array,rho,fdm); } free(**tmp_array); free(*tmp_array); free(tmp_array); /* A1 one-way ABC implicit scheme coefficients */ if (dabc) { abc = abcone3d_make(nbd,dt,vel,fsrf,fdm); if (hybrid) damp = damp_make(nbd-nop); /* compute damping profiles for hybrid bc */ else spo = sponge_make(fdm->nb); } /* allocate memory for wavefield variables */ u0 = sf_floatalloc3(nzpad,nxpad,nypad); u1 = sf_floatalloc3(nzpad,nxpad,nypad); /* initialize variables */ memset(u0[0][0],0,sizeof(float)*nzpad*nxpad*nypad); memset(u1[0][0],0,sizeof(float)*nzpad*nxpad*nypad); memset(u_dat,0,sizeof(float)*nr); /* v = (v*dt)^2 */ for (ix=0;ix<nzpad*nxpad*nypad;ix++) *(vel[0][0]+ix) *= *(vel[0][0]+ix)*dt2; if (fsrf && !hybrid) { for (iy=0; iy<nypad; iy++) for (ix=0; ix<nxpad; ix++) memset(vel[iy][ix],0,sizeof(float)*fdm->nb); } for (it=0; it<nt; it++) { if (verb) sf_warning("it=%d;",it+1); #if defined _OPENMP && _DEBUG tic=omp_get_wtime(); #endif step_forward(u0,u1,vel,rho,fdcoef_d2,fdcoef_d1,nop,nzpad,nxpad,nypad); if (adj) { /* backward inject source wavelet */ if (expl) { sf_seek(file_wav,(off_t)(nt-it-1)*sizeof(float),SEEK_SET); sf_floatread(ws,1,file_wav); ws[0] *= dt2; if (sinc) sinc3d_inject1(u0,ws[0],cssinc); else lint3d_inject1(u0,ws[0],cslint); } else { sf_seek(file_wav,(off_t)(nt-it-1)*ns*sizeof(float),SEEK_SET); sf_floatread(ws,ns,file_wav); for (is=0; is<ns; is++) ws[is] *= dt2; if (sinc) sinc3d_inject(u0,ws,cssinc); else lint3d_inject(u0,ws,cslint); } } else { /* forward inject source wavelet */ if (expl) { sf_floatread(ws,1,file_wav); ws[0] *= dt2; if (sinc) sinc3d_inject1(u0,ws[0],cssinc); else lint3d_inject1(u0,ws[0],cslint); } else { sf_floatread(ws,ns,file_wav); for (is=0; is<ns; is++) ws[is] *= dt2; if (sinc) sinc3d_inject(u0,ws,cssinc); else lint3d_inject(u0,ws,cslint); } } /* apply abc */ if (dabc) { if (hybrid) apply_abc(u0,u1,nz,nx,ny,nbd,abc,nop,damp); else { abcone3d_apply(u0,u1,nop,abc,fdm); sponge3d_apply(u0,spo,fdm); sponge3d_apply(u1,spo,fdm); } } /* loop over pointers */ ptr_tmp = u0; u0 = u1; u1 = ptr_tmp; /* extract snapshot */ if (snap && it%jsnap==0) { int fy = (floor)((sf_o(acy)-fdm->oypad)/fdm->dy); int jy = floor(sf_d(acy)/fdm->dy); float **ptr_slice; for (iy=0; iy<sf_n(acy); iy++) { ptr_slice = u0[fy+iy*jy]; cut3d_slice(ptr_slice,oslice,fdm,acz,acx); sf_floatwrite(oslice[0],sf_n(acz)*sf_n(acx),file_wfl); } } /* extract receiver data */ if (sinc) sinc3d_extract(u0,u_dat,crsinc); else lint3d_extract(u0,u_dat,crlint); sf_floatwrite(u_dat,nr,file_dat); #if defined _OPENMP && _DEBUG toc=omp_get_wtime(); fprintf(stderr,"%5.2gs",(float)(toc-tic)); #endif } #ifdef _OPENMP wall_clock_time_e = omp_get_wtime(); #else wall_clock_time_e = (double) clock() / CLOCKS_PER_SEC; #endif if (verb) fprintf(stderr,"\nElapsed time: %lf s\n",wall_clock_time_e-wall_clock_time_s); free(**u0); free(*u0); free(u0); free(**u1); free(*u1); free(u1); free(**vel); free(*vel); free(vel); free(u_dat); free(ws); free(fdcoef_d2); free(fdcoef_d1); if (snap) { free(*oslice); free(oslice); } if(!cden) { free(**rho); free(*rho); free(rho); } if (hybrid) free(damp); free(src3d); free(rec3d); return 0; }
int main(int argc, char* argv[]) { bool verb; /* verbosity flag */ float clip; /* threshold (clip value) */ sf_file Fc; /* cube file */ sf_file Fl; /* list file */ extern int fseeko(FILE *stream, off_t offset, int whence); sf_axis ax,ay,az; sf_axis aa; int ix,iy,iz; int nx,ny,nz,nj,na; int nk=0,jk; float **cube; float dx,dy,dz; float x0,y0,z0; FILE* tfile; char* tname; float t2[3],t3[4]; /*------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); if(! sf_getbool("verb",&verb)) verb=false; if(! sf_getfloat("clip",&clip)) clip=0; Fc = sf_input ( "in"); /* input cube */ Fl = sf_output("out"); /* output list */ /* read axes*/ az=sf_iaxa(Fc,1); sf_setlabel(az,"z"); ax=sf_iaxa(Fc,2); sf_setlabel(ax,"x"); ay=sf_iaxa(Fc,3); sf_setlabel(ay,"y"); nz=sf_n(az); z0=sf_o(az); dz=sf_d(az); nx=sf_n(ax); x0=sf_o(ax); dx=sf_d(ax); ny=sf_n(ay); y0=sf_o(ay); dy=sf_d(ay); na=0; if(ny>1) { if(verb) sf_warning("initiating 3D points"); nj=4; } else { if(verb) sf_warning("initiating 2D points"); nj=3; } /*------------------------------------------------------------*/ cube = sf_floatalloc2(nz,nx); tfile = sf_tempfile(&(tname), "w+b"); for (iy=0; iy<ny; iy++) { /* if(verb) sf_warning("iy=%d",iy);*/ sf_floatread(cube[0],nz*nx,Fc); nk=0; for (ix=0; ix<nx; ix++) { for (iz=0; iz<nz; iz++) { if( fabs(cube[ix][iz]) > clip) { nk++; } } } if(ny>1) { jk=0; for (ix=0; ix<nx; ix++) { for (iz=0; iz<nz; iz++) { if( fabs(cube[ix][iz]) > clip) { t3[0] = x0 + ix * dx; t3[1] = y0 + iy * dy; t3[2] = z0 + iz * dz; t3[3] = cube[ix][iz]; fseeko(tfile,jk*4*sizeof(float),SEEK_SET); fwrite( t3, sizeof(float),4,tfile); jk++; } } } } else { jk=0; for (ix=0; ix<nx; ix++) { for (iz=0; iz<nz; iz++) { if( fabs(cube[ix][iz]) > clip) { t2[0] = x0 + ix * dx; t2[1] = z0 + iz * dz; t2[2] = cube[ix][iz]; fseeko(tfile,jk*3*sizeof(float),SEEK_SET); fwrite( t2, sizeof(float),3,tfile); jk++; } } } } /* else ny=1 */ na += nk; } /* iy */ /* output axes */ aa = sf_maxa(nj,0,1); sf_oaxa(Fl,aa,1); if(verb) sf_raxa(aa); free(aa); aa = sf_maxa(na,0,1); sf_oaxa(Fl,aa,2); if(verb) sf_raxa(aa); free(aa); if( ny>1) { for( jk=0; jk<nk; jk++) { fseeko(tfile,jk*4*sizeof(float),SEEK_SET); fread( t3, sizeof(float),4,tfile); /* if(verb) sf_warning("%d, %g %g %g %g",jk,t3[0],t3[1],t3[2],t3[3]);*/ sf_floatwrite(t3,4,Fl); } } else { for( jk=0; jk<nk; jk++) { fseeko(tfile,jk*3*sizeof(float),SEEK_SET); fread( t2, sizeof(float),3,tfile); /* if(verb) sf_warning("%d, %g %g %g",jk,t2[0],t2[1],t2[2]);*/ sf_floatwrite(t2,3,Fl); } } free(cube); unlink(tname); exit (0); }
int main(int argc, char* argv[]) { int i,j; int n,iseed; int nbin; float dbin,obin; float m1,m2,s1,s2,r; float **hist; sf_axis axis_1,axis_2; sf_file out; sf_init (argc,argv); out = sf_output("out"); sf_settype(out,SF_FLOAT); if (!sf_getint("n",&n)) n=100; /* number of random deviates pairs */ if (!sf_getfloat("m1",&m1)) m1=0.0; /* mean for deviate 1 */ if (!sf_getfloat("m2",&m2)) m2=0.0; /* mean for deviate 2 */ if (!sf_getfloat("s1",&s1)) s1=1.0; /* standard deviation for deviate 1 */ if (!sf_getfloat("s2",&s2)) s2=1.0; /* standard deviation for deviate 2 */ if (!sf_getfloat("r",&r)) r=0.0; /* correlation coefficient */ if (!sf_getint("nbin",&nbin)) nbin=51; /* number of bins for histogram */ if (!sf_getfloat("dbin",&dbin)) dbin=0.1; /* histogram bin size */ if (!sf_getfloat("obin",&obin)) obin=0.0; /* histogram origin */ if (!sf_getint("iseed",&iseed)) iseed=-33; /* random generator seed */ if (iseed >= 0) sf_error("Need strictly negative iseed"); /* output file parameters */ axis_1 = sf_maxa(nbin,obin,dbin); axis_2 = sf_maxa(nbin,obin,dbin); sf_oaxa(out,axis_1,1); sf_oaxa(out,axis_2,2); /* Histogram */ hist = sf_floatalloc2(nbin,nbin); for (j = 0; j < nbin; j++) { for (i = 0; i < nbin; i++) { hist[j][i] = 0.0; } } histgauss(hist,n,r,m1,m2,s1,s2,nbin,dbin,obin,iseed); /* output */ sf_floatwrite(hist[0],nbin*nbin,out); exit(0); }
int main(int argc, char* argv[]) { bool verb; bool adj; bool anis; sf_file Fcip=NULL; /* lag-domain CIPs */ sf_file Fang=NULL; /* angle-domain CIPs */ sf_file Fvel=NULL; /* velocity @ CIPs */ sf_file Fnor=NULL; /* normals @ CIPs */ sf_file Ftlt=NULL; /* tilt @ CIPs */ sf_file Fani=NULL; /* anisotropy @ CIPs */ sf_axis ahx,ahy,ahz,aht,ac,ath,aph,aps,aj; int ihx,ihy,ihz,iht,ic,ith,iph; /* angle parameters */ int nth,nph,nps,nhx,nhy,nhz,nht; float oth,oph,ops,ohx,ohy,ohz,oht; float dth,dph,dps,dhx,dhy,dhz,dht; float phi; float tht; float psi; float v_s,v_r; float cosum,codif,sitovel; /* arrays 1 2 3 4 */ float ****cip; /* nhx-nhy-nhz-nht */ float **ang; /* nph-nth */ float *vep; /* nc */ float *ves; /* nc */ float *eps=NULL; /* nc */ float *dlt=NULL; /* nc */ vc3d vv; /* azimuth reference vector */ vc3d *nn; /* normal vectors */ vc3d *tt=NULL; /* tilt vectors */ vc3d *aa; /* in-plane reference vector */ vc3d qq; vc3d jk; /* temp vector */ float hx,hy,hz; float tau; /* time lag */ int jht; /* tau axis index */ float fht; /* tau axis weight */ float ssn; /* slant-stack normalization */ float *ttipar; /*-----------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); #ifdef _OPENMP omp_init(); /* OMP parameters */ #endif if(! sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ if(! sf_getbool("anis",&anis)) anis=false; /* anisotropy flag */ if(! sf_getbool("adj", &adj)) adj=true; /* adj flag */ /* * ADJ: cip to ang * FOR: ang to cip */ sf_warning("verb=%d",verb); sf_warning("anis=%d",anis); /* select anisotropy model */ if(anis) sf_warning("ANI model"); else sf_warning("ISO model"); if(adj) { Fcip=sf_input ( "in"); /* CIP file */ Fang=sf_output("out"); /* ANG file */ } else { Fcip=sf_output("out"); /* CIP file */ Fang=sf_input ("in"); /* ANG file */ } Fvel=sf_input ("vel"); /* velocity file */ Fnor=sf_input ("nor"); /* normal vectors */ if(anis) { Ftlt=sf_input ("tlt"); /* tilt vectors */ Fani=sf_input ("ani"); /* anisotropy */ } aj = sf_maxa(1,0,1); if(adj) { /* input axes */ ahx = sf_iaxa(Fcip,1); sf_setlabel(ahx,"hx"); ahy = sf_iaxa(Fcip,2); sf_setlabel(ahy,"hy"); ahz = sf_iaxa(Fcip,3); sf_setlabel(ahz,"hz"); aht = sf_iaxa(Fcip,4); sf_setlabel(aht,"ht"); /* CIP axis */ ac = sf_iaxa(Fcip,5); sf_setlabel(ac ,"c "); /* reflection angle */ if(! sf_getint ("nth",&nth)) nth=90; if(! sf_getfloat("oth",&oth)) oth=0; if(! sf_getfloat("dth",&dth)) dth=1.; ath = sf_maxa(nth,oth,dth); sf_setlabel(ath,"th"); sf_setunit (ath,"deg"); /* azimuth angle */ if(! sf_getint ("nph",&nph)) nph=360; if(! sf_getfloat("oph",&oph)) oph=-180; if(! sf_getfloat("dph",&dph)) dph=1.; aph = sf_maxa(nph,oph,dph); sf_setlabel(aph,"ph"); sf_setunit (aph,"deg"); /* output axes */ sf_oaxa(Fang,ath,1); sf_oaxa(Fang,aph,2); sf_oaxa(Fang,ac ,3); sf_oaxa(Fang,aj ,4); sf_oaxa(Fang,aj ,5); } else { /* lag in x */ if(! sf_getint ("nhx",&nhx)) nhx=1; if(! sf_getfloat("ohx",&ohx)) ohx=0; if(! sf_getfloat("dhx",&dhx)) dhx=1.; ahx = sf_maxa(nhx,ohx,dhx); sf_setlabel(ahx,"hx"); sf_setunit (ahx,""); /* lag in y */ if(! sf_getint ("nhy",&nhy)) nhy=1; if(! sf_getfloat("ohy",&ohy)) ohy=0; if(! sf_getfloat("dhy",&dhy)) dhy=1.; ahy = sf_maxa(nhy,ohy,dhy); sf_setlabel(ahy,"hy"); sf_setunit (ahy,""); /* lag in z */ nhz=1; ohz=0.; dhz=1.; ahz = sf_maxa(nhz,ohz,dhz); sf_setlabel(ahz,"hz"); sf_setunit (ahz,""); /* lag in t */ if(! sf_getint ("nht",&nht)) nht=1; if(! sf_getfloat("oht",&oht)) oht=0.; if(! sf_getfloat("dht",&dht)) dht=1.; aht = sf_maxa(nht,oht,dht); sf_setlabel(aht,"ht"); sf_setunit (aht,""); /* reflection angle */ ath = sf_iaxa(Fang,1); sf_setlabel(ath,"th"); /* azimuth angle */ aph = sf_iaxa(Fang,2); sf_setlabel(aph,"ph"); /* CIP axis */ ac = sf_iaxa(Fang,3); sf_setlabel(ac ,"c "); /* output axes */ sf_oaxa(Fcip,ahx,1); sf_oaxa(Fcip,ahy,2); sf_oaxa(Fcip,ahz,3); sf_oaxa(Fcip,aht,4); sf_oaxa(Fcip,ac ,5); } if (verb){ sf_raxa(ahx); sf_raxa(ahy); sf_raxa(ahz); sf_raxa(aht); sf_raxa(ac); sf_raxa(ath); sf_raxa(aph); } if(anis) { /* deviation angle */ if(! sf_getint ("nps",&nps)) nps=251; if(! sf_getfloat("ops",&ops)) ops=-25; if(! sf_getfloat("dps",&dps)) dps=0.2; aps = sf_maxa(nps,ops,dps); sf_setlabel(aps,"ps"); sf_setunit (aps,"deg"); if(verb) sf_raxa(aps); } else { aps = NULL; } /*------------------------------------------------------------*/ /* allocate arrays */ cip = sf_floatalloc4 (sf_n(ahx),sf_n(ahy),sf_n(ahz),sf_n(aht)); ang = sf_floatalloc2 (sf_n(ath),sf_n(aph)); /* read velocity */ vep = sf_floatalloc (sf_n(ac)); sf_floatread(vep,sf_n(ac),Fvel); ves = sf_floatalloc (sf_n(ac)); sf_floatread(ves,sf_n(ac),Fvel); /*------------------------------------------------------------*/ /* read normals */ nn = (vc3d*) sf_alloc(sf_n(ac),sizeof(*nn)); /* normals */ vc3dread1(Fnor,nn,sf_n(ac)); if(anis) { /* read anisotropy */ eps = sf_floatalloc (sf_n(ac)); sf_floatread(eps,sf_n(ac),Fani); dlt = sf_floatalloc (sf_n(ac)); sf_floatread(dlt,sf_n(ac),Fani); /* read tilts */ tt = (vc3d*) sf_alloc(sf_n(ac),sizeof(*tt)); vc3dread1(Ftlt,tt,sf_n(ac)); } /*------------------------------------------------------------*/ /* in-plane azimuth reference */ vv.dx=1; vv.dy=0; vv.dz=0; aa = (vc3d*) sf_alloc(sf_n(ac),sizeof(*aa)); for(ic=0;ic<sf_n(ac);ic++) { jk =vcp3d(&nn[ic],&vv); aa[ic]=vcp3d(&jk,&nn[ic]); } /*------------------------------------------------------------*/ ssn = 1./sqrt(sf_n(ahx)*sf_n(ahy)*sf_n(ahz)); /*------------------------------------------------------------*/ /* loop over CIPs */ /* if(verb) fprintf(stderr,"ic\n");*/ for(ic=0;ic<sf_n(ac);ic++) { /* if(verb) fprintf(stderr,"\b\b\b\b\b%d",ic);*/ if(adj) { /* read CIP */ sf_floatread(cip[0][0][0],sf_n(ahx)*sf_n(ahy)*sf_n(ahz)*sf_n(aht),Fcip); /* init ANG */ for (iph=0;iph<sf_n(aph);iph++) { for(ith=0;ith<sf_n(ath);ith++) { ang[iph][ith]=0; } } } else { /* init CIP */ for (iht=0;iht<sf_n(aht);iht++) { for (ihz=0;ihz<sf_n(ahz);ihz++) { for (ihy=0;ihy<sf_n(ahy);ihy++) { for(ihx=0;ihx<sf_n(ahx);ihx++) { cip[iht][ihz][ihy][ihx]=0; } } } } /* read ANG */ sf_floatread(ang[0],sf_n(ath)*sf_n(aph),Fang); } /* phi loop */ nph = sf_n(aph); #ifdef _OPENMP #pragma omp parallel for schedule(static) \ private(iph,phi,jk,qq, \ ith,tht, \ ihy,ihx,hy,hx,hz, \ tau,jht,fht,cosum,codif,v_s,v_r,psi,sitovel) \ shared( nph,aph,ath,aps,ahy,ahx,aht,cip,ang,vep,ves,eps,dlt) #endif for(iph=0;iph<nph;iph++) { phi=(180+sf_o(aph)+iph*sf_d(aph))/180.*SF_PI; /* use '180' to reverse illumination direction: */ /* at a CIP, look toward the source */ /* reflection azimuth vector */ jk = rot3d(nn,aa,phi); qq = nor3d(&jk); /* theta loop */ for(ith=0;ith<sf_n(ath);ith++) { tht=(sf_o(ath)+ith*sf_d(ath))/180.*SF_PI; if(anis) { ttipar = psitti(nn,&qq,tt,aa, tht,phi,aps, vep[ic],ves[ic],eps[ic],dlt[ic]); psi = ttipar[0]; v_s = ttipar[1]; v_r = ttipar[2]; psi *= SF_PI/180.; cosum = cosf(tht+psi); codif = cosf(tht-psi); sitovel = sinf(2*tht)/(v_s*cosum + v_r*codif); } else { sitovel = sinf(tht)/vep[ic]; } /* lag loops */ if(adj) { for (ihy=0;ihy<sf_n(ahy);ihy++) { hy=sf_o(ahy)+ihy*sf_d(ahy); for(ihx=0;ihx<sf_n(ahx);ihx++) { hx=sf_o(ahx)+ihx*sf_d(ahx); hz = -(hx*(nn[ic].dx)+hy*(nn[ic].dy))/(nn[ic].dz); tau = -((qq.dx)*hx+(qq.dy)*hy+(qq.dz)*hz)*sitovel; jht=0.5+(tau-sf_o(aht))/sf_d(aht); if(jht>=0 && jht<sf_n(aht)-1) { fht= (tau-sf_o(aht))/sf_d(aht)-jht; ang[iph][ith] += (1-fht)*ssn*cip[jht ][0][ihy][ihx] + fht *ssn*cip[jht+1][0][ihy][ihx]; } } /* hx */ } /* hy */ } else { for (ihy=0;ihy<sf_n(ahy);ihy++) { hy=sf_o(ahy)+ihy*sf_d(ahy); for(ihx=0;ihx<sf_n(ahx);ihx++) { hx=sf_o(ahx)+ihx*sf_d(ahx); hz = -(hx*(nn[ic].dx)+hy*(nn[ic].dx))/(nn[ic].dz); tau = -((qq.dx)*hx+(qq.dy)*hy+(qq.dz)*hz)*sitovel; jht=0.5+(tau-sf_o(aht))/sf_d(aht); if(jht>=0 && jht<sf_n(aht)-1) { fht= (tau-sf_o(aht))/sf_d(aht)-jht; cip[jht ][0][ihy][ihx] += (1-fht)*ssn*ang[iph][ith]; cip[jht+1][0][ihy][ihx] += fht *ssn*ang[iph][ith]; } } /* hx */ } /* hy */ } } /* th */ } /* ph */ if(adj) { /* write ANG */ sf_floatwrite(ang[0],sf_n(ath)*sf_n(aph),Fang); } else { /* write CIP */ sf_floatwrite(cip[0][0][0],sf_n(ahx)*sf_n(ahy)*sf_n(ahz)*sf_n(aht),Fcip); } } if(verb) fprintf(stderr,"\n"); /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ if(verb) fprintf(stderr,"free memory..."); free(***cip);free(**cip);free(*cip);free(cip); ; free(*ang);free(ang); ; free(vep); ; free (nn); ; free (aa); if(anis) { free(ves); free(eps); free(dlt); free(tt); } if(verb) fprintf(stderr,"OK\n"); /*------------------------------------------------------------*/ exit(0); }
int main (int argc, char ** argv) { /* 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[]) { /*------------------------------------------------------------*/ /* 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 n,k,nc,i,j; int done; /* boolean for more combinations to compute */ int *a; /* list of elements in the current combination (not needed at startup) */ int **mask; sf_axis areplic; sf_file in,out; sf_init(argc,argv); in = sf_input("in"); out = sf_output("out"); sf_settype(out,SF_INT); if (!sf_getint("k",&k)) sf_error("Need k="); /* combination of k elements */ /* input file */ if (!sf_histint(in,"n1",&n)) sf_error("No n1="); nc = binomial(n,k); sf_warning("Number of combinations is %3d",nc); /* output file parameters */ areplic = sf_maxa(nc,0,1); sf_oaxa(out,areplic,2); sf_putstring (out,"label2", "replication"); /* memory allocations */ a = sf_intalloc(k); mask = sf_intalloc2(n,nc); done = 1; j = 0; while (1) { /* Combination of k elements out of n */ comb_next(n,k,a,&done); if (done) break; /* done = 1 if more combinations to compute */ /* done = 0 when the list is exhausted. */ for (i = 0; i < k; i++) fprintf(stderr," %3d",a[i]); fprintf(stderr," \n"); for (i = 0; i < n; i++) mask[j][i] = 1; for (i = 0; i < k; i++) mask[j][a[i]-1] = 0; j++; } /* output */ sf_warning("Number of combinations is %3d",nc); sf_intwrite(mask[0],n*nc,out); exit(0); }
int main(int argc, char* argv[]) { bool verb,fsrf,snap,ssou,dabc,opot; int jsnap,ntsnap,jdata; /* I/O files */ sf_file Fwav=NULL; /* wavelet */ sf_file Fsou=NULL; /* sources */ sf_file Frec=NULL; /* receivers */ sf_file Fccc=NULL; /* velocity */ sf_file Fden=NULL; /* density */ sf_file Fdat=NULL; /* data */ sf_file Fwfl=NULL; /* wavefield */ /* cube axes */ sf_axis at,ax,ay,az; sf_axis as,ar,ac; int nt,nz,nx,ny,ns,nr,nc,nb; int it,iz,ix,iy; float dt,dz,dx,dy,idz,idx,idy; /* FDM structure */ fdm3d fdm=NULL; abcone3d /* abcp=NULL, */ abcs=NULL; sponge spo=NULL; /* I/O arrays */ float***ww=NULL; /* wavelet */ pt3d *ss=NULL; /* sources */ pt3d *rr=NULL; /* receivers */ float **dd=NULL; /* data */ /*------------------------------------------------------------*/ float ***tt=NULL; float ***ro=NULL; /* density */ /* orthorombic footprint - 9 coefficients */ /* c11 c12 c13 . c22 c23 . . c33 c44 c55 c66 */ float ***c11=NULL; float ***c22=NULL; float ***c33=NULL; float ***c44=NULL; float ***c55=NULL; float ***c66=NULL; float ***c12=NULL; float ***c13=NULL; float ***c23=NULL; float ***vp,***vs; float ***qp=NULL,***qsx=NULL,***qsy=NULL,***qsz=NULL; /*------------------------------------------------------------*/ /* displacement: um = U @ t-1; uo = U @ t; up = U @ t+1 */ float ***umz,***uoz,***upz,***uaz,***utz; float ***umx,***uox,***upx,***uax,***utx; float ***umy,***uoy,***upy,***uay,***uty; /* stress/strain tensor */ float ***tzz,***txx,***tyy,***txy,***tyz,***tzx; float szz, sxx, syy, sxy, syz, szx; /*------------------------------------------------------------*/ /* linear interpolation weights/indices */ lint3d cs,cr; /* 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; float ***uc=NULL; /*------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); /*------------------------------------------------------------*/ /* OMP parameters */ #ifdef _OPENMP omp_init(); #endif /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* 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("ssou",&ssou)) ssou=false; /* stress source */ if(! sf_getbool("dabc",&dabc)) dabc=false; /* absorbing BC */ if(! sf_getbool("opot",&opot)) opot=false; /* output potentials */ /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* I/O files */ Fwav = sf_input ("in" ); /* wavelet */ Fccc = sf_input ("ccc"); /* stiffness */ Fden = sf_input ("den"); /* density */ Fsou = sf_input ("sou"); /* sources */ Frec = sf_input ("rec"); /* receivers */ Fwfl = sf_output("wfl"); /* wavefield */ Fdat = sf_output("out"); /* data */ /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* axes */ at = sf_iaxa(Fwav,3); 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 */ as = sf_iaxa(Fsou,2); sf_setlabel(as,"s"); if(verb) sf_raxa(as); /* sources */ ar = sf_iaxa(Frec,2); sf_setlabel(ar,"r"); if(verb) sf_raxa(ar); /* receivers */ nt = sf_n(at); dt = sf_d(at); nz = sf_n(az); dz = sf_d(az); nx = sf_n(ax); dx = sf_d(ax); ny = sf_n(ay); dy = sf_d(ay); ns = sf_n(as); nr = sf_n(ar); /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* other execution parameters */ if(! sf_getint("nbell",&nbell)) nbell=5; /* 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; } /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* expand domain for FD operators and ABC */ if( !sf_getint("nb",&nb) || nb<NOP) nb=NOP; fdm=fdutil3d_init(verb,fsrf,az,ax,ay,nb,1); 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; if(opot) { ac=sf_maxa(nc+1,0,1); } else { ac=sf_maxa(nc ,0,1); } /*------------------------------------------------------------*/ /* setup output data header */ sf_oaxa(Fdat,ar,1); sf_oaxa(Fdat,ac,2); sf_setn(at,nt/jdata); sf_setd(at,dt*jdata); sf_oaxa(Fdat,at,3); /* 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); /* TODO: check if the imaging window fits in the wavefield domain */ uc=sf_floatalloc3(sf_n(acz),sf_n(acx),sf_n(acy)); ntsnap=0; for(it=0; it<nt; it++) { if(it%jsnap==0) ntsnap++; } sf_setn(at, ntsnap); sf_setd(at,dt*jsnap); if(verb) sf_raxa(at); sf_oaxa(Fwfl,acz,1); sf_oaxa(Fwfl,acx,2); sf_oaxa(Fwfl,acy,3); sf_oaxa(Fwfl,ac, 4); sf_oaxa(Fwfl,at, 5); } /*------------------------------------------------------------*/ /* source array */ ww=sf_floatalloc3(ns,nc,nt); sf_floatread(ww[0][0],nt*nc*ns,Fwav); /* data array */ if(opot) { dd=sf_floatalloc2(nr,nc+1); } else { dd=sf_floatalloc2(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 */ cs = lint3d_make(ns,ss,fdm); cr = lint3d_make(nr,rr,fdm); /*------------------------------------------------------------*/ /* setup FD coefficients */ /* idz = 2/dz;*/ /* idx = 2/dx;*/ /* idy = 2/dy;*/ idz = 1/dz; idx = 1/dx; idy = 1/dy; /*------------------------------------------------------------*/ tt = sf_floatalloc3(nz,nx,ny); ro =sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); c11=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); c22=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); c33=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); c44=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); c55=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); c66=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); c12=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); c13=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); c23=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); /* input density */ sf_floatread(tt[0][0],nz*nx*ny,Fden); expand3d(tt,ro ,fdm); /* input stiffness */ sf_floatread(tt[0][0],nz*nx*ny,Fccc ); expand3d(tt,c11,fdm); sf_floatread(tt[0][0],nz*nx*ny,Fccc ); expand3d(tt,c22,fdm); sf_floatread(tt[0][0],nz*nx*ny,Fccc ); expand3d(tt,c33,fdm); sf_floatread(tt[0][0],nz*nx*ny,Fccc ); expand3d(tt,c44,fdm); sf_floatread(tt[0][0],nz*nx*ny,Fccc ); expand3d(tt,c55,fdm); sf_floatread(tt[0][0],nz*nx*ny,Fccc ); expand3d(tt,c66,fdm); sf_floatread(tt[0][0],nz*nx*ny,Fccc ); expand3d(tt,c12,fdm); sf_floatread(tt[0][0],nz*nx*ny,Fccc ); expand3d(tt,c13,fdm); sf_floatread(tt[0][0],nz*nx*ny,Fccc ); expand3d(tt,c23,fdm); free(**tt); free(*tt); free(tt); /*------------------------------------------------------------*/ if(dabc) { /* one-way abc setup */ vp = sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); vs = sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); for (iy=0; iy<fdm->nypad; iy++) { for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nzpad; iz++) { vp[iy][ix][iz] = sqrt( c11[iy][ix][iz]/ro[iy][ix][iz] ); vs[iy][ix][iz] = sqrt( c55[iy][ix][iz]/ro[iy][ix][iz] ); } } } /* abcp = abcone3d_make(NOP,dt,vp,fsrf,fdm); */ abcs = abcone3d_make(NOP,dt,vs,fsrf,fdm); free(**vp); free(*vp); free(vp); free(**vs); free(*vs); free(vs); /* sponge abc setup */ spo = sponge_make(fdm->nb); } /*------------------------------------------------------------*/ /* precompute 1/ro * dt^2 */ for (iy=0; iy<fdm->nypad; iy++) { for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nzpad; iz++) { ro[iy][ix][iz] = dt*dt/ro[iy][ix][iz]; } } } /*------------------------------------------------------------*/ /* allocate wavefield arrays */ umz=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); uoz=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); upz=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); uaz=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); umx=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); uox=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); upx=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); uax=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); umy=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); uoy=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); upy=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); uay=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); tzz=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); tyy=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); txx=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); txy=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); tyz=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); tzx=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); for (iy=0; iy<fdm->nypad; iy++) { for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nzpad; iz++) { umz[iy][ix][iz]=0; umx[iy][ix][iz]=0; umy[iy][ix][iz]=0; uoz[iy][ix][iz]=0; uox[iy][ix][iz]=0; uoy[iy][ix][iz]=0; upz[iy][ix][iz]=0; upx[iy][ix][iz]=0; upy[iy][ix][iz]=0; uaz[iy][ix][iz]=0; uax[iy][ix][iz]=0; uay[iy][ix][iz]=0; } } } if(opot) { qp =sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); qsx=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); qsy=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); qsz=sf_floatalloc3(fdm->nzpad,fdm->nxpad,fdm->nypad); } /*------------------------------------------------------------*/ /* * MAIN LOOP */ /*------------------------------------------------------------*/ if(verb) fprintf(stderr,"\n"); for (it=0; it<nt; it++) { if(verb) fprintf(stderr,"\b\b\b\b\b%d",it); /*------------------------------------------------------------*/ /* from displacement to strain */ /*------------------------------------------------------------*/ /* * exx = Fx(ux) * eyy = Fy(uy) * ezz = Fz(uz) * exy = By(ux) + Bx(uy) * eyz = Bz(uy) + By(uz) * ezx = Bx(uz) + Bz(ux) */ #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,fdm->ompchunk) \ private(ix,iy,iz) \ shared(fdm,txx,tyy,tzz,txy,tyz,tzx,uox,uoy,uoz,idx,idy,idz) #endif for (iy=NOP; iy<fdm->nypad-NOP; iy++) { for (ix=NOP; ix<fdm->nxpad-NOP; ix++) { for(iz=NOP; iz<fdm->nzpad-NOP; iz++) { txx[iy][ix][iz] = Dx(uox,ix,iy,iz,idx); tyy[iy][ix][iz] = Dy(uoy,ix,iy,iz,idy); tzz[iy][ix][iz] = Dz(uoz,ix,iy,iz,idz); txy[iy][ix][iz] = Dy(uox,ix,iy,iz,idy) + Dx(uoy,ix,iy,iz,idx); tyz[iy][ix][iz] = Dz(uoy,ix,iy,iz,idz) + Dy(uoz,ix,iy,iz,idy); tzx[iy][ix][iz] = Dx(uoz,ix,iy,iz,idx) + Dz(uox,ix,iy,iz,idz); } } } /*------------------------------------------------------------*/ /* from strain to stress */ /*------------------------------------------------------------*/ #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,fdm->ompchunk) \ private(ix,iy,iz,sxx,syy,szz,sxy,syz,szx) \ shared(fdm,txx,tyy,tzz,txy,tyz,tzx,c11,c22,c33,c44,c55,c66,c12,c13,c23) #endif for (iy=0; iy<fdm->nypad; iy++) { for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nzpad; iz++) { sxx = c11[iy][ix][iz] * txx[iy][ix][iz] + c12[iy][ix][iz] * tyy[iy][ix][iz] + c13[iy][ix][iz] * tzz[iy][ix][iz]; syy = c12[iy][ix][iz] * txx[iy][ix][iz] + c22[iy][ix][iz] * tyy[iy][ix][iz] + c23[iy][ix][iz] * tzz[iy][ix][iz]; szz = c13[iy][ix][iz] * txx[iy][ix][iz] + c23[iy][ix][iz] * tyy[iy][ix][iz] + c33[iy][ix][iz] * tzz[iy][ix][iz]; sxy = c66[iy][ix][iz] * txy[iy][ix][iz]; syz = c44[iy][ix][iz] * tyz[iy][ix][iz]; szx = c55[iy][ix][iz] * tzx[iy][ix][iz]; txx[iy][ix][iz] = sxx; tyy[iy][ix][iz] = syy; tzz[iy][ix][iz] = szz; txy[iy][ix][iz] = sxy; tyz[iy][ix][iz] = syz; tzx[iy][ix][iz] = szx; } } } /*------------------------------------------------------------*/ /* free surface */ /*------------------------------------------------------------*/ if(fsrf) { #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,fdm->ompchunk) \ private(ix,iy,iz) \ shared(fdm,txx,tyy,tzz,txy,tyz,tzx) #endif for (iy=0; iy<fdm->nypad; iy++) { for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nb; iz++) { txx[iy][ix][iz]=0; tyy[iy][ix][iz]=0; tzz[iy][ix][iz]=0; txy[iy][ix][iz]=0; tyz[iy][ix][iz]=0; tzx[iy][ix][iz]=0; } } } } /*------------------------------------------------------------*/ /* inject stress source */ /*------------------------------------------------------------*/ if(ssou) { lint3d_bell(tzz,ww[it][0],cs); lint3d_bell(txx,ww[it][1],cs); lint3d_bell(tyy,ww[it][2],cs); } /*------------------------------------------------------------*/ /* from stress to acceleration */ /*------------------------------------------------------------*/ /* * ax = Bx(txx) + Fy(txy) + Fz(txz) * ay = Fx(txy) + By(tyy) + Fz(tyz) * az = Fx(txz) + Fy(tyz) + Bz(tzz) */ #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,fdm->ompchunk) \ private(ix,iy,iz) \ shared(fdm,txx,tyy,tzz,txy,tyz,tzx,uax,uay,uaz,idx,idy,idz) #endif for (iy=NOP; iy<fdm->nypad-NOP; iy++) { for (ix=NOP; ix<fdm->nxpad-NOP; ix++) { for(iz=NOP; iz<fdm->nzpad-NOP; iz++) { uax[iy][ix][iz] = Dx( txx,ix,iy,iz,idx ) + Dy( txy,ix,iy,iz,idy ) + Dz( tzx,ix,iy,iz,idz ) ; uay[iy][ix][iz] = Dx( txy,ix,iy,iz,idx ) + Dy( tyy,ix,iy,iz,idy ) + Dz( tyz,ix,iy,iz,idz ) ; uaz[iy][ix][iz] = Dx( tzx,ix,iy,iz,idx ) + Dy( tyz,ix,iy,iz,idy ) + Dz( tzz,ix,iy,iz,idz ) ; } } } /*------------------------------------------------------------*/ /* inject acceleration source */ /*------------------------------------------------------------*/ if(!ssou) { lint3d_bell(uaz,ww[it][0],cs); lint3d_bell(uax,ww[it][1],cs); lint3d_bell(uay,ww[it][2],cs); } /*------------------------------------------------------------*/ /* step forward in time */ /*------------------------------------------------------------*/ #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,fdm->ompchunk) \ private(ix,iy,iz) \ shared(fdm,uox,uoy,uoz,umx,umy,umz,upx,upy,upz,uax,uay,uaz,ro) #endif for (iy=0; iy<fdm->nypad; iy++) { for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nzpad; iz++) { upx[iy][ix][iz] = 2*uox[iy][ix][iz] - umx[iy][ix][iz] + uax[iy][ix][iz] * ro[iy][ix][iz]; upy[iy][ix][iz] = 2*uoy[iy][ix][iz] - umy[iy][ix][iz] + uay[iy][ix][iz] * ro[iy][ix][iz]; upz[iy][ix][iz] = 2*uoz[iy][ix][iz] - umz[iy][ix][iz] + uaz[iy][ix][iz] * ro[iy][ix][iz]; } } } /* circulate wavefield arrays */ utz=umz; uty=umy; utx=umx; umz=uoz; umy=uoy; umx=uox; uoz=upz; uoy=upy; uox=upx; upz=utz; upy=uty; upx=utx; if(dabc) { /* one-way ABC */ /* abcone3d_apply(uoz,umz,NOP,abcp,fdm); */ /* abcone3d_apply(uox,umx,NOP,abcp,fdm); */ /* abcone3d_apply(uoy,umy,NOP,abcp,fdm); */ abcone3d_apply(uoz,umz,NOP,abcs,fdm); abcone3d_apply(uox,umx,NOP,abcs,fdm); abcone3d_apply(uoy,umy,NOP,abcs,fdm); /* sponge ABC */ sponge3d_apply(umz,spo,fdm); sponge3d_apply(uoz,spo,fdm); sponge3d_apply(umx,spo,fdm); sponge3d_apply(uox,spo,fdm); sponge3d_apply(umy,spo,fdm); sponge3d_apply(uoy,spo,fdm); } /*------------------------------------------------------------*/ /* cut wavefield and save */ /*------------------------------------------------------------*/ if(opot) { #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,fdm->ompchunk) \ private(ix,iy,iz) \ shared(fdm,uox,uoy,uoz,idx,idy,idz) #endif for (iy=NOP; iy<fdm->nypad-NOP; iy++) { for (ix=NOP; ix<fdm->nxpad-NOP; ix++) { for(iz=NOP; iz<fdm->nzpad-NOP; iz++) { qp [iy][ix][iz] = Dx( uox,ix,iy,iz,idx ) + Dy( uoy,ix,iy,iz,idy ) + Dz( uoz,ix,iy,iz,idz ); qsx[iy][ix][iz] = Dy( uoz,ix,iy,iz,idy ) - Dz( uoy,ix,iy,iz,idz ); qsy[iy][ix][iz] = Dz( uox,ix,iy,iz,idz ) - Dx( uoz,ix,iy,iz,idx ); qsz[iy][ix][iz] = Dx( uoy,ix,iy,iz,idx ) - Dy( uox,ix,iy,iz,idy ); } } } if(snap && it%jsnap==0) { cut3d(qp ,uc,fdm,acz,acx,acy); sf_floatwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfl); cut3d(qsz,uc,fdm,acz,acx,acy); sf_floatwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfl); cut3d(qsx,uc,fdm,acz,acx,acy); sf_floatwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfl); cut3d(qsy,uc,fdm,acz,acx,acy); sf_floatwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfl); } lint3d_extract(qp , dd[0],cr); lint3d_extract(qsx, dd[1],cr); lint3d_extract(qsy, dd[2],cr); lint3d_extract(qsz, dd[3],cr); if(it%jdata==0) sf_floatwrite(dd[0],nr*(nc+1),Fdat); } else { if(snap && it%jsnap==0) { cut3d(uoz,uc,fdm,acz,acx,acy); sf_floatwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfl); cut3d(uox,uc,fdm,acz,acx,acy); sf_floatwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfl); cut3d(uoy,uc,fdm,acz,acx,acy); sf_floatwrite(uc[0][0],sf_n(acx)*sf_n(acy)*sf_n(acz),Fwfl); } lint3d_extract(uoz,dd[0],cr); lint3d_extract(uox,dd[1],cr); lint3d_extract(uoy,dd[2],cr); if(it%jdata==0) sf_floatwrite(dd[0],nr*nc,Fdat); } } if(verb) fprintf(stderr,"\n"); /*------------------------------------------------------------*/ /* deallocate arrays */ free(**ww); free(*ww); free(ww); free(ss); free(rr); free(*dd); free(dd); free(**ro); free(*ro); free(ro); free(**c11); free(*c11); free(c11); free(**c22); free(*c22); free(c22); free(**c33); free(*c33); free(c33); free(**c44); free(*c44); free(c44); free(**c55); free(*c55); free(c55); free(**c66); free(*c66); free(c66); free(**c12); free(*c12); free(c12); free(**c13); free(*c13); free(c13); free(**c23); free(*c23); free(c23); free(**umz); free(*umz); free(umz); free(**uoz); free(*uoz); free(uoz); free(**upz); free(*upz); free(upz); free(**uaz); free(*uaz); free(uaz); free(**umx); free(*umx); free(umx); free(**uox); free(*uox); free(uox); free(**upx); free(*upx); free(upx); free(**uax); free(*uax); free(uax); free(**umy); free(*umy); free(umy); free(**uoy); free(*uoy); free(uoy); free(**upy); free(*upy); free(upy); free(**uay); free(*uay); free(uay); free(**tzz); free(*tzz); free(tzz); free(**txx); free(*txx); free(txx); free(**tyy); free(*tyy); free(tyy); free(**txy); free(*txy); free(txy); free(**tyz); free(*tyz); free(tyz); free(**tzx); free(*tzx); free(tzx); if (snap) { free(**uc); free(*uc); free(uc); } if(opot) { free(**qp); free(*qp); free(qp); free(**qsx); free(*qsx); free(qsx); free(**qsy); free(*qsy); free(qsy); free(**qsz); free(*qsz); free(qsz); } /*------------------------------------------------------------*/ exit (0); }
int main(int argc, char* argv[]) { bool verb; int pick; /* method for selecting multi-arrival times */ int fill; /* hole-filling parameter */ int scaleray; int nray,jray,iray; sf_axis az,ax,ay; /* Cartesian coordinates */ int iz,ix,iy; sf_axis at; /* time */ int it; float xsou,ysou,zsou; /* source coordinates */ /* shooting directions */ float gmin,gmax,g; float hmin,hmax,h; sf_file Fv; /* velocity file */ sf_file Ft; /* traveltime file */ float ***vv=NULL; /* velocity cube */ float ***tt=NULL,t; /* traveltime cube */ float ***ll=NULL,l; /* ray length cube */ pt3d Tm,To,Tp; vc3d TmTo; /* Tm-To vector */ int seed; int n; float o,d; /*------------------------------------------------------------*/ sf_init(argc,argv); if(! sf_getbool( "verb",&verb )) verb=false; if(! sf_getint ( "pick",&pick )) pick=2; if(! sf_getint ( "fill",&fill )) fill=1; if(! sf_getint ("scaleray",&scaleray)) scaleray=1.; if(! sf_getint ( "nray",&nray )) nray=1; if(! sf_getint ( "jray",&jray )) jray=1; if(! sf_getfloat("gmin",&gmin)) gmin=-90; if(! sf_getfloat("gmax",&gmax)) gmax=+90; if(! sf_getfloat("hmin",&hmin)) hmin=0; if(! sf_getfloat("hmax",&hmax)) hmax=180; if(verb) sf_warning("gmin=%g gmax=%g",gmin,gmax); if(verb) sf_warning("hmin=%g hmax=%g",hmin,hmax); /* time axis */ if(! sf_getint ("nt",&n)) n=100; if(! sf_getfloat("ot",&o)) o=0; if(! sf_getfloat("dt",&d)) d=0.001; at=sf_maxa(n,o,d); sf_setlabel(at,"t"); /* velocity file */ Fv = sf_input ("in"); az=sf_iaxa(Fv,1); sf_setlabel(az,"z"); if(verb) sf_raxa(az); ax=sf_iaxa(Fv,2); sf_setlabel(ax,"x"); if(verb) sf_raxa(ax); ay=sf_iaxa(Fv,3); sf_setlabel(ay,"y"); if(verb) sf_raxa(ay); vv=sf_floatalloc3(sf_n(az),sf_n(ax),sf_n(ay)); sf_floatread(vv[0][0],sf_n(az)*sf_n(ax)*sf_n(ay),Fv); /* traveltime file */ Ft = sf_output("out"); sf_oaxa(Ft,az,1); sf_oaxa(Ft,ax,2); sf_oaxa(Ft,ay,3); tt=sf_floatalloc3(sf_n(az),sf_n(ax),sf_n(ay)); ll=sf_floatalloc3(sf_n(az),sf_n(ax),sf_n(ay)); for(iy=0;iy<sf_n(ay);iy++) { for(ix=0;ix<sf_n(ax);ix++) { for(iz=0;iz<sf_n(az);iz++) { tt[iy][ix][iz] = MISSING; ll[iy][ix][iz] = MISSING; } } } /* source location */ if(! sf_getfloat("xsou",&xsou)) xsou=sf_o(ax) + sf_n(ax)*sf_d(ax)/2; if(! sf_getfloat("ysou",&ysou)) ysou=sf_o(ay) + sf_n(ay)*sf_d(ay)/2; if(! sf_getfloat("zsou",&zsou)) zsou=sf_o(az) + sf_n(az)*sf_d(az)/2; if(verb) sf_warning("xsou=%f ysou=%f zsou=%f",xsou,ysou,zsou); /*------------------------------------------------------------*/ /* init random numbers */ if(! sf_getint("seed",&seed)) seed = time(NULL); /* random seed */ init_genrand((unsigned long) seed); /*------------------------------------------------------------*/ /* init HWT */ hwt3d_rand(az,ax,ay,at); /*------------------------------------------------------------*/ /* LOOP over rays */ for(iray=0; iray<nray; iray++) { if(verb && iray%jray == 0) sf_warning("iray=%d of %d",iray,nray); /* init ray */ g = gmin + genrand_real1() * (gmax-gmin); h = hmin + genrand_real1() * (hmax-hmin); g *= SF_PI/180; h *= SF_PI/180; /* trace ray */ l = 0; t = 0; Tm.x = xsou; Tm.y = ysou; Tm.z = zsou; Tm.v = hwt3d_getv(vv,Tm); if (pick==2) hwt3d_lint(tt,ll,Tm,t,l); else if(pick==1) hwt3d_tint(tt,ll,Tm,t,l); else hwt3d_nint(tt,ll,Tm,t,l); it=1; t = sf_o(at) + it * sf_d(at); To.x = Tm.x + Tm.v*sf_d(at) * sin(g)*cos(h); To.y = Tm.y + Tm.v*sf_d(at) * sin(g)*sin(h); To.z = Tm.z + Tm.v*sf_d(at) * cos(g); To.v = hwt3d_getv(vv,To); TmTo = vec3d(&Tm,&To); l += len3d(&TmTo); if (pick==2) hwt3d_lint(tt,ll,To,t,l); else if(pick==1) hwt3d_tint(tt,ll,To,t,l); else hwt3d_nint(tt,ll,To,t,l); for(it=2; it<sf_n(at); it++) { t = sf_o(at) + it * sf_d(at); Tp = hwt3d_raytr(vv,Tm,To,scaleray); Tm = To; To = Tp; TmTo = vec3d(&Tm,&To); l += len3d(&TmTo); if (pick==2) hwt3d_lint(tt,ll,To,t,l); else if(pick==1) hwt3d_tint(tt,ll,To,t,l); else hwt3d_nint(tt,ll,To,t,l); } /* end it */ } /* end iray */ /* fill holes */ if(fill>0) hwt3d_fill(tt,fill); /* write traveltime cube */ sf_floatwrite(tt[0][0],sf_n(az)*sf_n(ax)*sf_n(ay),Ft); /*------------------------------------------------------------*/ free(**vv); free(*vv); free(vv); free(**tt); free(*tt); free(tt); free(**ll); free(*ll); free(ll); exit (0); }
int main( int argc , char* argv[] ) { sf_init( argc , argv ); sf_axis at, ax, ay, aw, at_wave, aw_wave; /* * @Define AXIS for DATASETS */ sf_file FD1, FD2, FD3, FD4, FW1, FW2, FW3, FW4, FPR1, FPR2, FPR3, FPR4, FPR5, FPO1, FPO2, FPO3, FPO4, FPO5; /* * @Define File Interfaces for Datasets */ int ix, nx, nx_s, NX, iy, ny, ny_s, NY, iw, nw, nw_s, NW, it, jt, nt, nt_s, NT, nwave; /* * @Define the Dimension of the Input Data & Inversion * @it : index of time axis * @nx : Dimension of Inversion in Inline Direction * @nx_s: Starting place of Inline Direction * @NX : Dimension of Input Data * @NY,ny,ny_s: Parameters in Crossline Direction * @NT,nt,nt_s: Parameters in time direction * @nwave: length of the wavelet */ float sita1, sita2, sita3, sita4; /* * @ Angle Values of NearOffset, Mid1, Mid2 and TeleOffset, respectively! */ float w0, crange, corder, var_e; int wsft; /* * @ Parameters of Inversion, w0 is the reference frequency of the Q model * @ crange and corder are the parameters of Gaussian Shaped Window function * @ var_e is the level of noise estimated * @ wsft is the wave shift of the wavelet to the original point */ int dim, num_dim[SF_MAX_DIM]; /* * @ Detect the Dimension of the DATASETS Using the Interior Function */ float dt, ot, dw, ow; /* * @ PARAMETER of the DATASETS * @ dt is the time interval, ot is the starting time value */ float **NearWave, **Mid1Wave, **Mid2Wave, **TeleWave; /* * @ Input Wavelet file in different frequency and Offset */ float *d, *M_prior, **Cm, **Cn, **A, **W, **D, **WA, **G, *M_post, ****MPOST; /* * @ * @ * @Cm is the covariance matrix of the model * @Cn is the covariance matrix of the noise */ int ipara, jpara; float vpvsratio; /* * @auxiliary variable in calculating the coefficient in AKI-RICHARD formulae */ if(!sf_getint( "nw_start" , &nw_s )) sf_error( "Missing Frequency Start!\n" ); /* Input Parameter: the starting frequency in inversion */ if(!sf_getint( "nw_inv" , &nw )) sf_error( "Missing the Number of Frequency used!\n" ); /* Input Parameter: the number of frequency in inversion */ if(!sf_getint( "ninline_start" , &nx_s )) sf_error( "Missing inline Direction Starting Value !\n" ); /* Input Parameter: the Starting value in inline direction in Inversion */ if(!sf_getint( "ninline_inv" , &nx )) sf_error( "Missing Number of CDPS in inline direction!\n" ); /* Input Parameter: the number of CDPS in inline direction */ if(!sf_getint( "ncrossline_start" , &ny_s )) sf_error( "Missing crossline Direction Starting Value!\n" ); /* Input Paramter: the starting Value in crossline direction in Inversion */ if(!sf_getint( "ncrossline_inv" , &ny )) sf_error( "Missing Number of inlines in Crossline direction!\n" ); /* Input Parameter: the number of INLINES in crossline direction */ if(!sf_getfloat( "nearsita" , &sita1 )) sf_error( "Missing the Near Offset angle Value!\n" ); /* Input Parameter: the Angle Value of Near Offset Trace Gather */ if(!sf_getfloat( "mid1sita" , &sita2 )) sf_error( "Missing the Mid1 Offset angle Value!\n" ); /* Input Parameter: the Angle Value of Mid1 Offset Trace Gather */ if(!sf_getfloat( "mid2sita" , &sita3 )) sf_error( "Missing the Mid2 Offset angle Value!\n" ); /* Input Parameter: the Angle Value of Mid2 Offset Trace Gather */ if(!sf_getfloat( "telesita" , &sita4 )) sf_error( "Missing the Tele Offset angle Value!\n" ); /* Input Parameter: the Angle Value of Tele Offset Trace Gather */ if(!sf_getfloat( "w0" , &w0 )) sf_error( "Missing w0!\n" ); /* Input Parameter: Reference Frequency in Inversion */ if(!sf_getint( "wave_shift" , &wsft )) sf_error( "Missing the Shift of Wavelet!\n" ); /* Input Parameter: Wave Shift in Inversion */ if(!sf_getfloat( "correlation_range" , &crange ))sf_error( "Missing the Correlation Range in Inversion!\n" ); /* Input Parameter: COrrelation range in Inversion */ if(!sf_getfloat( "correlation_order" , &corder ))sf_error( "Missing the Correlation Order in Inversion!\n" ); /* Input Parameter: Correlation Order in Inversion */ if(!sf_getfloat( "variance_noise" , &var_e )) sf_error( "Missing the Variance of Noise in Inversion!\n" ); /* Input Parameter: Variance of Noise in Inversion */ FD1 = sf_input( "NearOffsetGather" ); FD2 = sf_input( "Mid1OffsetGather" ); FD3 = sf_input( "Mid2OffsetGather" ); FD4 = sf_input( "TeleOffsetGather" ); /* * @ Input DATASETs */ FW1 = sf_input( "NearWavelet" ); FW2 = sf_input( "Mid1Wavelet" ); FW3 = sf_input( "Mid2Wavelet" ); FW4 = sf_input( "TeleWavelet" ); /* * @ Input WAVELETs */ FPR1= sf_input( "vp_prior" ); FPR2= sf_input( "vs_prior" ); FPR3= sf_input( "ro_prior" ); FPR4= sf_input( "qp_prior" ); FPR5= sf_input( "qs_prior" ); /* * @ Input a Prior Models */ FPO1= sf_output( "vp_post" ); FPO2= sf_output( "vs_post" ); FPO3= sf_output( "ro_post" ); FPO4= sf_output( "qp_post" ); FPO5= sf_output( "qs_post" ); /* * @ Output Post MODELs by Bayesian Inversion */ dim = sf_filedims( FD1 , num_dim ); if( dim==3 ) { at = sf_iaxa( FD1 , 1 ); NT = sf_n( at ); dt = sf_d( at ); ot = sf_o( at ); aw = sf_iaxa( FD1 , 2 ); NW = sf_n( aw ); dw = sf_d( aw ); ow = sf_o( aw ); ax = sf_iaxa( FD1 , 3 ); NX = sf_n( ax ); NY = 1; } else if( dim==4 ) { at = sf_iaxa( FD1 , 1 ); NT = sf_n( at ); dt = sf_d( at ); ot = sf_o( at ); aw = sf_iaxa( FD1 , 2 ); NW = sf_n( aw ); dw = sf_d( aw ); ow = sf_o( aw ); ax = sf_iaxa( FD1 , 3 ); NX = sf_n( ax ); ay = sf_iaxa( FD1 , 4 ); NY = sf_n( ay ); } else sf_error( "DATA DIMENSION FAULT!\n" ); /* * @ Only Handle the problem owns at least an inline section * @ dimension of the data MUST be 3 or 4! */ at_wave = sf_iaxa( FW1 , 1 ); aw_wave = sf_iaxa( FW1 , 2 ); nwave = sf_n( at_wave ); if( sf_n(aw_wave)!=NW ) sf_error( "The NW dimension of wavelet should equal to the one of the DATASETS!\n" ); if( sf_n(sf_iaxa( FPR1 , 1 ))!=NT+1 ) sf_error( "DATASETS UNMATCHED!\n" ); if( sf_n(sf_iaxa( FPR1 , 2 ))!=NX ) sf_error( "DATASETS UNMATCHED!\n" ); if( nw_s<0 || nw_s>=NW ) sf_error( "The nw_start is inappropriate!\n" ); if( nx_s<0 || nx_s>=NX ) sf_error( "The ninline start is inappropriate!\n" ); if( ny_s<0 || ny_s>=NY ) sf_error( "The ncrossline start is inappropriate!\n" ); if( nw_s+nw>NW ) sf_error( "The nw inversion is inappropriate!\n" ); if( nx_s+nx>NX ) sf_error( "The nx inversion is inappropriate!\n" ); if( ny_s+ny>NY ) sf_error( "The ny inversion is inappropriate!\n" ); /* * @Read Parameter of Wavelet & Check Parameters * @if occurs inappropriate parameter, the program breaks immediately */ NearWave = sf_floatalloc2( nwave , nw ); Mid1Wave = sf_floatalloc2( nwave , nw ); Mid2Wave = sf_floatalloc2( nwave , nw ); TeleWave = sf_floatalloc2( nwave , nw ); sf_seek( FW1 , sizeof(float)*nwave*nw_s , SEEK_SET ); sf_seek( FW2 , sizeof(float)*nwave*nw_s , SEEK_SET ); sf_seek( FW3 , sizeof(float)*nwave*nw_s , SEEK_SET ); sf_seek( FW4 , sizeof(float)*nwave*nw_s , SEEK_SET ); sf_floatread( &NearWave[0][0] , nwave*nw , FW1 ); sf_floatread( &Mid1Wave[0][0] , nwave*nw , FW2 ); sf_floatread( &Mid2Wave[0][0] , nwave*nw , FW3 ); sf_floatread( &TeleWave[0][0] , nwave*nw , FW4 ); /* * @Clip the WAVELET DATASETS and Read Needed Wavelet */ MPOST = sf_floatalloc4( NT+1 , NX , NY , 5 ); zero4float( MPOST , NT+1 , NX , NY , 5 ); /* * @ The MAP solution of all the PARAMETERS */ for( iy=0 ; iy<ny ; iy++ ) for( ix=0 ; ix<nx ; ix++ ) { printf( "ix=%d\n" , ix ); nt = NT; nt_s=0; d = sf_floatalloc( 4*nw*nt ); M_prior = sf_floatalloc ( 5*(nt+1) ); M_post = sf_floatalloc ( 5*(nt+1) ); Cm = sf_floatalloc2( 5*(nt+1) , 5*(nt+1) ); Cn = sf_floatalloc2( 4*nw*nt , 4*nw*nt ); A = sf_floatalloc2( 5*nt , 4*nw*nt ); W = sf_floatalloc2( 4*nw*nt , 4*nw*nt ); D = sf_floatalloc2( 5*(nt+1) , 5*nt ); WA = sf_floatalloc2( 5*nt , 4*nw*nt ); G = sf_floatalloc2( 5*(nt+1) , 4*nw*nt ); /* * @4 means 4 angle gather * @5 means 5 parameter, * @4 &5 could be set up in the parameter list if it's needed! * @To keep simplicity, the two parameters are given explicitly */ for( iw=0 ; iw<nw ; iw++ ) { sf_seek( FD1 , sizeof(float)*((ny_s+iy)*NX*NW*NT+(nx_s+ix)*NW*NT+(nw_s+iw)*NT+nt_s) , SEEK_SET ); sf_seek( FD2 , sizeof(float)*((ny_s+iy)*NX*NW*NT+(nx_s+ix)*NW*NT+(nw_s+iw)*NT+nt_s) , SEEK_SET ); sf_seek( FD3 , sizeof(float)*((ny_s+iy)*NX*NW*NT+(nx_s+ix)*NW*NT+(nw_s+iw)*NT+nt_s) , SEEK_SET ); sf_seek( FD4 , sizeof(float)*((ny_s+iy)*NX*NW*NT+(nx_s+ix)*NW*NT+(nw_s+iw)*NT+nt_s) , SEEK_SET ); sf_floatread( &d[(0*nw+iw)*nt] , nt , FD1 ); sf_floatread( &d[(1*nw+iw)*nt] , nt , FD2 ); sf_floatread( &d[(2*nw+iw)*nt] , nt , FD3 ); sf_floatread( &d[(3*nw+iw)*nt] , nt , FD4 ); } sf_seek( FPR1 , sizeof(float)*((ny_s+iy)*NX*(NT+1)+(nx_s+ix)*(NT+1)+nt_s) , SEEK_SET ); sf_seek( FPR2 , sizeof(float)*((ny_s+iy)*NX*(NT+1)+(nx_s+ix)*(NT+1)+nt_s) , SEEK_SET ); sf_seek( FPR3 , sizeof(float)*((ny_s+iy)*NX*(NT+1)+(nx_s+ix)*(NT+1)+nt_s) , SEEK_SET ); sf_seek( FPR4 , sizeof(float)*((ny_s+iy)*NX*(NT+1)+(nx_s+ix)*(NT+1)+nt_s) , SEEK_SET ); sf_seek( FPR5 , sizeof(float)*((ny_s+iy)*NX*(NT+1)+(nx_s+ix)*(NT+1)+nt_s) , SEEK_SET ); sf_floatread( &M_prior[0*(nt+1)] , nt+1 , FPR1 ); sf_floatread( &M_prior[1*(nt+1)] , nt+1 , FPR2 ); sf_floatread( &M_prior[2*(nt+1)] , nt+1 , FPR3 ); sf_floatread( &M_prior[3*(nt+1)] , nt+1 , FPR4 ); sf_floatread( &M_prior[4*(nt+1)] , nt+1 , FPR5 ); /* * @Read Angle freuquency Gather use FILE SEEK function * @Read a Prior MODEL */ for( iw=0 ; iw<nw ; iw++ ) for( it=0 ; it<nt ; it++ ) { vpvsratio = (M_prior[nt+1+it]+M_prior[nt+1+it+1])/(M_prior[it]+M_prior[it+1]); A[0*nw*nt+iw*nt+it][it] = 0.5*(1.+tan(sita1*SF_PI/180.)*tan(sita1*SF_PI/180.)); A[0*nw*nt+iw*nt+it][nt+it] = -4.*sin(sita1*SF_PI/180.)*sin(sita1*SF_PI/180.)*pow(vpvsratio,2.); A[0*nw*nt+iw*nt+it][2*nt+it] = 0.5*(1.-4.*sin(sita1*SF_PI/180.)*sin(sita1*SF_PI/180.)*pow(vpvsratio,2.)); A[0*nw*nt+iw*nt+it][3*nt+it] = A[0*nw*nt+iw*nt+it][it]*((1./SF_PI)*log((dw*(nw_s+iw)+ow)/w0)); A[0*nw*nt+iw*nt+it][4*nt+it] = A[0*nw*nt+iw*nt+it][nt+it]*((1./SF_PI)*log((dw*(nw_s+iw)+ow)/w0)); A[1*nw*nt+iw*nt+it][it] = 0.5*(1.+tan(sita2*SF_PI/180.)*tan(sita2*SF_PI/180.)); A[1*nw*nt+iw*nt+it][nt+it] = -4.*sin(sita2*SF_PI/180.)*sin(sita2*SF_PI/180.)*pow(vpvsratio,2.); A[1*nw*nt+iw*nt+it][2*nt+it] = 0.5*(1.-4.*sin(sita2*SF_PI/180.)*sin(sita2*SF_PI/180.)*pow(vpvsratio,2.)); A[1*nw*nt+iw*nt+it][3*nt+it] = A[1*nw*nt+iw*nt+it][it]*((1./SF_PI)*log((dw*(nw_s+iw)+ow)/w0)); A[1*nw*nt+iw*nt+it][4*nt+it] = A[1*nw*nt+iw*nt+it][nt+it]*((1./SF_PI)*log((dw*(nw_s+iw)+ow)/w0)); A[2*nw*nt+iw*nt+it][it] = 0.5*(1.+tan(sita3*SF_PI/180.)*tan(sita3*SF_PI/180.)); A[2*nw*nt+iw*nt+it][nt+it] = -4.*sin(sita3*SF_PI/180.)*sin(sita3*SF_PI/180.)*pow(vpvsratio,2.); A[2*nw*nt+iw*nt+it][2*nt+it] = 0.5*(1.-4.*sin(sita3*SF_PI/180.)*sin(sita3*SF_PI/180.)*pow(vpvsratio,2.)); A[2*nw*nt+iw*nt+it][3*nt+it] = A[2*nw*nt+iw*nt+it][it]*((1./SF_PI)*log((dw*(nw_s+iw)+ow)/w0)); A[2*nw*nt+iw*nt+it][4*nt+it] = A[2*nw*nt+iw*nt+it][nt+it]*((1./SF_PI)*log((dw*(nw_s+iw)+ow)/w0)); A[3*nw*nt+iw*nt+it][it] = 0.5*(1.+tan(sita4*SF_PI/180.)*tan(sita4*SF_PI/180.)); A[3*nw*nt+iw*nt+it][nt+it] = -4.*sin(sita4*SF_PI/180.)*sin(sita4*SF_PI/180.)*pow(vpvsratio,2.); A[3*nw*nt+iw*nt+it][2*nt+it] = 0.5*(1.-4.*sin(sita4*SF_PI/180.)*sin(sita4*SF_PI/180.)*pow(vpvsratio,2.)); A[3*nw*nt+iw*nt+it][3*nt+it] = A[3*nw*nt+iw*nt+it][it]*((1./SF_PI)*log((dw*(nw_s+iw)+ow)/w0)); A[3*nw*nt+iw*nt+it][4*nt+it] = A[3*nw*nt+iw*nt+it][nt+it]*((1./SF_PI)*log((dw*(nw_s+iw)+ow)/w0)); } for( iw=0; iw<nw; iw++ ) for( it=0; it<nt; it++ ) for( jt=0; jt<nt; jt++ ) { if ( (it-jt)<=nwave-1-wsft && (it-jt)>=-wsft ) { W[0*nw*nt+iw*nt+it][0*nw*nt+iw*nt+jt]= NearWave[iw][it-jt+wsft]; W[1*nw*nt+iw*nt+it][1*nw*nt+iw*nt+jt]= Mid1Wave[iw][it-jt+wsft]; W[2*nw*nt+iw*nt+it][2*nw*nt+iw*nt+jt]= Mid2Wave[iw][it-jt+wsft]; W[3*nw*nt+iw*nt+it][3*nw*nt+iw*nt+jt]= TeleWave[iw][it-jt+wsft]; } else { W[0*nw*nt+iw*nt+it][0*nw*nt+iw*nt+jt]=0.; W[1*nw*nt+iw*nt+it][1*nw*nt+iw*nt+jt]=0.; W[2*nw*nt+iw*nt+it][2*nw*nt+iw*nt+jt]=0.; W[3*nw*nt+iw*nt+it][3*nw*nt+iw*nt+jt]=0.; } } for( ipara=0 ; ipara<5 ; ipara++ ) for( it=0 ; it<nt ; it++ ) { D[ipara*nt+it][ipara*(nt+1)+it] = -1; D[ipara*nt+it][ipara*(nt+1)+it+1] = 1; } /* * @Build three essential Matrix, A,W,D * @A is the coefficient Matrix in multiple angle(4) and multiple frequency form * @W is the wavelet matrix * @D is the difference matrix * @the forward operator is G=WAD */ lh_matrix_mu_matrix( W , A , WA , 4*nw*nt , 4*nw*nt , 5*nt ); lh_matrix_mu_matrix( WA , D , G , 4*nw*nt , 5*nt , 5*(nt+1)); /* * @ Build forward operator G, using W,A,D */ for( it=0 ; it<3*(nt+1) ; it++ ) { M_prior[it] = log(M_prior[it]); } for( it=3*(nt+1) ; it<5*(nt+1) ; it++ ) { M_prior[it] = 1./M_prior[it]; } /* * @ Revise the A Prior Model Into the expectation value of True Value */ for( it=0 ; it<nt+1 ; it++ ) for( jt=0 ; jt<nt+1 ; jt++ ) for( ipara=0 ; ipara<5 ; ipara++ ) for( jpara=0 ; jpara<5 ; jpara++ ) { if( ipara==jpara ) Cm[ipara*(nt+1)+it][jpara*(nt+1)+jt] = lh_float_variance( &M_prior[ipara*(nt+1)] , nt+1 ) *exp(-1.*pow(fabs((it-jt)*dt/crange),corder)); else Cm[ipara*(nt+1)+it][jpara*(nt+1)+jt] = lh_float_covariance( &M_prior[ipara*(nt+1)] , &M_prior[jpara*(nt+1)] , nt+1 ) *exp(-1.*pow(fabs((it-jt)*dt/crange),corder)); } for( it=0 ; it<4*nw*nt ; it++ ) for( jt=0 ; jt<4*nw*nt ; jt++ ) { if( it==jt ) Cn[it][jt] = var_e; else Cn[it][jt] = 0.; } /* * @ Transfer the ELASTIC parameters into LOG value * @ Transfer the ANELASTIC parameters into RECIPROCAL value * @ Setup the variance of the MODEL and the NOISE, * @ Cm Usually comes from welldata, here is given from MODELS */ lh_direct_LS( G , 4*nw*nt , 5*(nt+1) , Cn , Cm , d, M_prior, M_post ); /* * @ Inversion Under Bayesian Framework, the formulae comes from Tarantola(2005) directly */ if( ix==0 ) { lh_write_1d_float_bin( M_post , 5*(nt+1) , "M_post.bin" ); lh_write_1d_float_bin( M_prior, 5*(nt+1) , "M_prior.bin"); } for( it=0 ; it<nt+1 ; it++ ) { MPOST[0][iy+ny_s][ix+nx_s][nt_s+it] = exp(M_post[0*(nt+1)+it]); MPOST[1][iy+ny_s][ix+nx_s][nt_s+it] = exp(M_post[1*(nt+1)+it]); MPOST[2][iy+ny_s][ix+nx_s][nt_s+it] = exp(M_post[2*(nt+1)+it]); MPOST[3][iy+ny_s][ix+nx_s][nt_s+it] = 1.0/M_post[3*(nt+1)+it]; MPOST[4][iy+ny_s][ix+nx_s][nt_s+it] = 1.0/M_post[4*(nt+1)+it]; } free1float( d ); free1float( M_prior ); free1float( M_post ); free2float( Cm ); free2float( Cn ); free2float( A ); free2float( W ); free2float( D ); free2float( WA ); free2float( G ); } if( dim==3 ) { sf_oaxa( FPO1 , sf_maxa( NT+1 , 0., dt ) , 1 ); sf_oaxa( FPO2 , sf_maxa( NT+1 , 0., dt ) , 1 ); sf_oaxa( FPO3 , sf_maxa( NT+1 , 0., dt ) , 1 ); sf_oaxa( FPO4 , sf_maxa( NT+1 , 0., dt ) , 1 ); sf_oaxa( FPO5 , sf_maxa( NT+1 , 0., dt ) , 1 ); sf_oaxa( FPO1 , sf_maxa( NX , 0., 1 ) , 2 ); sf_oaxa( FPO2 , sf_maxa( NX , 0., 1 ) , 2 ); sf_oaxa( FPO3 , sf_maxa( NX , 0., 1 ) , 2 ); sf_oaxa( FPO4 , sf_maxa( NX , 0., 1 ) , 2 ); sf_oaxa( FPO5 , sf_maxa( NX , 0., 1 ) , 2 ); } if( dim==4 ) { sf_oaxa( FPO1 , sf_maxa( NT+1 , 0., dt ) , 1 ); sf_oaxa( FPO2 , sf_maxa( NT+1 , 0., dt ) , 1 ); sf_oaxa( FPO3 , sf_maxa( NT+1 , 0., dt ) , 1 ); sf_oaxa( FPO4 , sf_maxa( NT+1 , 0., dt ) , 1 ); sf_oaxa( FPO5 , sf_maxa( NT+1 , 0., dt ) , 1 ); sf_oaxa( FPO1 , sf_maxa( NX , 0., 1 ) , 2 ); sf_oaxa( FPO2 , sf_maxa( NX , 0., 1 ) , 2 ); sf_oaxa( FPO3 , sf_maxa( NX , 0., 1 ) , 2 ); sf_oaxa( FPO4 , sf_maxa( NX , 0., 1 ) , 2 ); sf_oaxa( FPO5 , sf_maxa( NX , 0., 1 ) , 2 ); sf_oaxa( FPO1 , sf_maxa( NY , 0., 1 ) , 3 ); sf_oaxa( FPO2 , sf_maxa( NY , 0., 1 ) , 3 ); sf_oaxa( FPO3 , sf_maxa( NY , 0., 1 ) , 3 ); sf_oaxa( FPO4 , sf_maxa( NY , 0., 1 ) , 3 ); sf_oaxa( FPO5 , sf_maxa( NY , 0., 1 ) , 3 ); } sf_floatwrite( &MPOST[0][0][0][0] , (NT+1)*NX*NY , FPO1 ); sf_floatwrite( &MPOST[1][0][0][0] , (NT+1)*NX*NY , FPO2 ); sf_floatwrite( &MPOST[2][0][0][0] , (NT+1)*NX*NY , FPO3 ); sf_floatwrite( &MPOST[3][0][0][0] , (NT+1)*NX*NY , FPO4 ); sf_floatwrite( &MPOST[4][0][0][0] , (NT+1)*NX*NY , FPO5 ); free( MPOST ); exit( 0 ); }
int main(int argc, char* argv[]) { bool verb,fsrf,snap,expl,dabc,sout,uses; int jsnap,ntsnap,jdata; char *atype; #ifdef _OPENMP int ompnth=1; #endif /* I/O files */ sf_file Fwav=NULL; /* wavelet */ sf_file Fsou=NULL; /* sources */ sf_file Frec=NULL; /* receivers */ sf_file Fvel=NULL; /* velocity */ sf_file Fang=NULL; /* angles */ sf_file Fdat=NULL; /* data */ sf_file Fwfl=NULL; /* wavefield */ /* cube axes */ sf_axis at,az,ax; sf_axis as,ar; int nt,nz,nx,ns,nr,nb; int it,iz,ix; float dt,dz,dx,dt2; /* FDM structure */ fdm2d fdm=NULL; abcone2d abc=NULL; sponge spo=NULL; /* I/O arrays */ float *ww=NULL; /* wavelet */ pt2d *ss=NULL; /* sources */ pt2d *rr=NULL; /* receivers */ float *dd=NULL; /* data */ float **tt=NULL; float **vp=NULL; /* velocity */ float **vpn=NULL; float **vpz=NULL; float **vpx=NULL; float **vsz=NULL; float **tht=NULL,**sit=NULL,**cot=NULL; float st,ct; float **pm=NULL,**po=NULL,**pp=NULL,**pa=NULL,**pt=NULL; /* main wavefield */ float **qm=NULL,**qo=NULL,**qp=NULL,**qa=NULL,**qt=NULL; /* auxiliary wavefield */ float **sf=NULL; /* "stress" field */ /* linear inteppolation weights/indices */ lint2d cs,cr; /* FD operator size */ float cox,cax,cbx,c1x,c2x; float coz,caz,cbz,c1z,c2z; /* wavefield cut params */ sf_axis acz=NULL,acx=NULL; int nqz,nqx; float oqz,oqx; float dqz,dqx; float **pc=NULL; float H1p,H2p,H1q,H2q; /*------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); /* select anisotropy model */ if (NULL == (atype = sf_getstring("atype"))) atype = "i"; switch(atype[0]) { case 't': sf_warning("TTI model"); break; case 'v': sf_warning("VTI model"); break; case 'i': default: sf_warning("ISO model"); break; } /*------------------------------------------------------------*/ /* OMP parameters */ #ifdef _OPENMP ompnth=omp_init(); #endif /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ if(! sf_getbool("verb",&verb)) verb=false; /* verbosity */ if(! sf_getbool("snap",&snap)) snap=false; /* wavefield snapshots */ if(! sf_getbool("free",&fsrf)) fsrf=false; /* free surface */ if(! sf_getbool("expl",&expl)) expl=false; /* "exploding reflector" */ if(! sf_getbool("dabc",&dabc)) dabc=false; /* absorbing BC */ if(! sf_getbool("sout",&sout)) sout=false; /* stress output */ if(! sf_getbool("uses",&uses)) uses=false; /* use vsz */ /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* I/O files */ Fwav = sf_input ("in" ); /* wavelet */ Fvel = sf_input ("vel"); /* velocity */ Fsou = sf_input ("sou"); /* sources */ Frec = sf_input ("rec"); /* receivers */ Fang = sf_input ("ang"); /* angles */ Fwfl = sf_output("wfl"); /* wavefield */ Fdat = sf_output("out"); /* data */ /*------------------------------------------------------------*/ /* axes */ at = sf_iaxa(Fwav,2); sf_setlabel(at,"t"); if(verb) sf_raxa(at); /* time */ az = sf_iaxa(Fvel,1); sf_setlabel(az,"z"); if(verb) sf_raxa(az); /* depth */ ax = sf_iaxa(Fvel,2); sf_setlabel(ax,"x"); if(verb) sf_raxa(ax); /* space */ as = sf_iaxa(Fsou,2); sf_setlabel(as,"s"); if(verb) sf_raxa(as); /* sources */ ar = sf_iaxa(Frec,2); sf_setlabel(ar,"r"); if(verb) sf_raxa(ar); /* receivers */ nt = sf_n(at); dt = sf_d(at); nz = sf_n(az); dz = sf_d(az); nx = sf_n(ax); dx = sf_d(ax); ns = sf_n(as); nr = sf_n(ar); /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* other execution parameters */ if(! sf_getint("jdata",&jdata)) jdata=1; if(snap) { /* save wavefield every *jsnap* time steps */ if(! sf_getint("jsnap",&jsnap)) jsnap=nt; } /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* setup output data header */ sf_oaxa(Fdat,ar,1); sf_setn(at,nt/jdata); sf_setd(at,dt*jdata); sf_oaxa(Fdat,at,2); /* 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_getfloat("oqz",&oqz)) oqz=sf_o(az); if(!sf_getfloat("oqx",&oqx)) oqx=sf_o(ax); dqz=sf_d(az); dqx=sf_d(ax); acz = sf_maxa(nqz,oqz,dqz); sf_raxa(acz); acx = sf_maxa(nqx,oqx,dqx); sf_raxa(acx); /* check if the imaging window fits in the wavefield domain */ pc=sf_floatalloc2(sf_n(acz),sf_n(acx)); ntsnap=0; for(it=0; it<nt; it++) { if(it%jsnap==0) ntsnap++; } sf_setn(at, ntsnap); sf_setd(at,dt*jsnap); if(verb) sf_raxa(at); sf_oaxa(Fwfl,acz,1); sf_oaxa(Fwfl,acx,2); sf_oaxa(Fwfl,at, 3); } /*------------------------------------------------------------*/ /* expand domain for FD operators and ABC */ if( !sf_getint("nb",&nb) || nb<NOP) nb=NOP; fdm=fdutil_init(verb,fsrf,az,ax,nb,1); sf_setn(az,fdm->nzpad); sf_seto(az,fdm->ozpad); if(verb) sf_raxa(az); sf_setn(ax,fdm->nxpad); sf_seto(ax,fdm->oxpad); if(verb) sf_raxa(ax); /*------------------------------------------------------------*/ if(expl) { ww = sf_floatalloc( 1); } else { ww = sf_floatalloc(ns); } dd = sf_floatalloc(nr); /*------------------------------------------------------------*/ /* setup source/receiver coordinates */ ss = (pt2d*) sf_alloc(ns,sizeof(*ss)); rr = (pt2d*) sf_alloc(nr,sizeof(*rr)); pt2dread1(Fsou,ss,ns,2); /* read (x,z) coordinates */ pt2dread1(Frec,rr,nr,2); /* read (x,z) coordinates */ cs = lint2d_make(ns,ss,fdm); cr = lint2d_make(nr,rr,fdm); /*------------------------------------------------------------*/ /* setup FD coefficients */ cox = C0 / (dx*dx); cax = CA / (dx*dx); cbx = CB / (dx*dx); c1x = C1 / dx; c2x = C2 / dx; coz = C0 / (dz*dz); caz = CA / (dz*dz); cbz = CB / (dz*dz); c1z = C1 / dz; c2z = C2 / dz; /* precompute dt^2*/ dt2 = dt*dt; /*------------------------------------------------------------*/ tt = sf_floatalloc2(nz,nx); /*------------------------------------------------------------*/ /* input velocity */ vp =sf_floatalloc2(fdm->nzpad,fdm->nxpad); vpz =sf_floatalloc2(fdm->nzpad,fdm->nxpad); sf_floatread(tt[0],nz*nx,Fvel ); expand(tt,vpz,fdm); /* VPz */ for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nzpad; iz++) { vp [ix][iz] = vpz[ix][iz]; vpz[ix][iz] = vpz[ix][iz] * vpz[ix][iz]; } } if(fsrf) { /* free surface */ for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nb; iz++) { vpz[ix][iz]=0; } } } if(atype[0] != 'i') { vpn =sf_floatalloc2(fdm->nzpad,fdm->nxpad); sf_floatread(tt[0],nz*nx,Fvel ); expand(tt,vpn,fdm); /* VPn */ vpx =sf_floatalloc2(fdm->nzpad,fdm->nxpad); sf_floatread(tt[0],nz*nx,Fvel ); expand(tt,vpx,fdm); /* VPx */ for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nzpad; iz++) { vpn[ix][iz] = vpn[ix][iz] * vpn[ix][iz]; vpx[ix][iz] = vpx[ix][iz] * vpx[ix][iz]; } } if(fsrf) { /* free surface */ for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nb; iz++) { vpn[ix][iz]=0; vpx[ix][iz]=0; } } } if(uses) { vsz =sf_floatalloc2(fdm->nzpad,fdm->nxpad); sf_floatread(tt[0],nz*nx,Fvel ); expand(tt,vsz,fdm); /* VSz */ for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nzpad; iz++) { vsz[ix][iz] = vsz[ix][iz] * vsz[ix][iz]; } } } } /*------------------------------------------------------------*/ if( atype[0]=='t') { /* input tilt angle */ tht =sf_floatalloc2(fdm->nzpad,fdm->nxpad); sit =sf_floatalloc2(fdm->nzpad,fdm->nxpad); cot =sf_floatalloc2(fdm->nzpad,fdm->nxpad); sf_floatread(tt[0],nz*nx,Fang); expand(tt,tht,fdm); for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nzpad; iz++) { tht[ix][iz] *= SF_PI/180.; sit[ix][iz] = sinf(tht[ix][iz]); cot[ix][iz] = cosf(tht[ix][iz]); } } free(*tht); free(tht); } /*------------------------------------------------------------*/ free(*tt); free(tt); /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* allocate wavefield arrays */ pm=sf_floatalloc2(fdm->nzpad,fdm->nxpad); po=sf_floatalloc2(fdm->nzpad,fdm->nxpad); pp=sf_floatalloc2(fdm->nzpad,fdm->nxpad); pa=sf_floatalloc2(fdm->nzpad,fdm->nxpad); for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nzpad; iz++) { pm[ix][iz]=0; po[ix][iz]=0; pp[ix][iz]=0; pa[ix][iz]=0; } } if(atype[0] != 'i') { qm=sf_floatalloc2(fdm->nzpad,fdm->nxpad); qo=sf_floatalloc2(fdm->nzpad,fdm->nxpad); qp=sf_floatalloc2(fdm->nzpad,fdm->nxpad); qa=sf_floatalloc2(fdm->nzpad,fdm->nxpad); for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nzpad; iz++) { qm[ix][iz]=0; qo[ix][iz]=0; qp[ix][iz]=0; qa[ix][iz]=0; } } if(sout) sf=sf_floatalloc2(fdm->nzpad,fdm->nxpad); } /*------------------------------------------------------------*/ if(dabc) { abc = abcone2d_make(NOP,dt,vp,fsrf,fdm); /* one-way */ spo = sponge_make(fdm->nb); /* sponge */ } /*------------------------------------------------------------*/ /* * MAIN LOOP */ /*------------------------------------------------------------*/ if(verb) fprintf(stderr,"\n"); for (it=0; it<nt; it++) { if(verb) fprintf(stderr,"\b\b\b\b\b%d",it); /* compute acceleration */ switch(atype[0]) { case 't': if(uses) { #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,fdm->ompchunk) \ private(ix,iz,H1p,H2p,H1q,H2q,st,ct) \ shared(fdm,pa,po,qa,qo, \ cox,cax,cbx,c1x,c2x, \ coz,caz,cbz,c1z,c2z, \ vpn,vpz,vpx,vsz, \ sit,cot) #endif for (ix=NOP; ix<fdm->nxpad-NOP; ix++) { for(iz=NOP; iz<fdm->nzpad-NOP; iz++) { st=sit[ix][iz]; ct=cot[ix][iz]; H1p = H1(po,ix,iz, \ st,ct, \ cox,cax,cbx,c1x,c2x, \ coz,caz,cbz,c1z,c2z); H2p = H2(po,ix,iz, \ st,ct, \ cox,cax,cbx,c1x,c2x, \ coz,caz,cbz,c1z,c2z); H1q = H1(qo,ix,iz, \ st,ct, \ cox,cax,cbx,c1x,c2x, \ coz,caz,cbz,c1z,c2z); H2q = H2(qo,ix,iz, \ st,ct, \ cox,cax,cbx,c1x,c2x, \ coz,caz,cbz,c1z,c2z); /* p - main field */ pa[ix][iz] = H1p * vsz[ix][iz] + H2p * vpx[ix][iz] + H1q * vpz[ix][iz] - H1q * vsz[ix][iz]; /* q - auxiliary field */ qa[ix][iz] = H2p * vpn[ix][iz] - H2p * vsz[ix][iz] + H1q * vpz[ix][iz] + H2q * vsz[ix][iz]; } } } else { #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,fdm->ompchunk) \ private(ix,iz,H2p,H1q,st,ct) \ shared(fdm,pa,po,qa,qo, \ cox,cax,cbx,c1x,c2x, \ coz,caz,cbz,c1z,c2z, \ vpn,vpz,vpx, \ sit,cot) #endif for (ix=NOP; ix<fdm->nxpad-NOP; ix++) { for(iz=NOP; iz<fdm->nzpad-NOP; iz++) { st=sit[ix][iz]; ct=cot[ix][iz]; H2p = H2(po,ix,iz, \ st,ct, \ cox,cax,cbx,c1x,c2x, \ coz,caz,cbz,c1z,c2z); H1q = H1(qo,ix,iz, \ st,ct, \ cox,cax,cbx,c1x,c2x, \ coz,caz,cbz,c1z,c2z); /* p - main field */ pa[ix][iz] = H2p * vpx[ix][iz] + H1q * vpz[ix][iz]; /* q - auxiliary field */ qa[ix][iz] = H2p * vpn[ix][iz] + H1q * vpz[ix][iz]; } } } break; case 'v': if(uses) { #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,fdm->ompchunk) \ private(ix,iz,H1p,H2p,H1q,H2q) \ shared(fdm,pa,po,qa,qo, \ cox,cax,cbx, \ coz,caz,cbz, \ vpn,vpz,vpx,vsz) #endif for (ix=NOP; ix<fdm->nxpad-NOP; ix++) { for(iz=NOP; iz<fdm->nzpad-NOP; iz++) { H1p = Dzz(po,ix,iz,coz,caz,cbz); H1q = Dzz(qo,ix,iz,coz,caz,cbz); H2p = Dxx(po,ix,iz,cox,cax,cbx); H2q = Dxx(qo,ix,iz,cox,cax,cbx); /* p - main field */ pa[ix][iz] = H1p * vsz[ix][iz] + H2p * vpx[ix][iz] + H1q * vpz[ix][iz] - H1q * vsz[ix][iz]; /* q - auxiliary field */ qa[ix][iz] = H2p * vpn[ix][iz] - H2p * vsz[ix][iz] + H1q * vpz[ix][iz] + H2q * vsz[ix][iz]; } } } else { #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,fdm->ompchunk) \ private(ix,iz,H2p,H1q) \ shared(fdm,pa,po,qa,qo, \ cox,cax,cbx, \ coz,caz,cbz, \ vpn,vpx,vpz) #endif for (ix=NOP; ix<fdm->nxpad-NOP; ix++) { for(iz=NOP; iz<fdm->nzpad-NOP; iz++) { H1q = Dzz(qo,ix,iz,coz,caz,cbz); H2p = Dxx(po,ix,iz,cox,cax,cbx); /* p - main field */ pa[ix][iz] = H2p * vpx[ix][iz] + H1q * vpz[ix][iz]; /* q - auxiliary field */ qa[ix][iz] = H2p * vpn[ix][iz] + H1q * vpz[ix][iz]; } } } break; case 'i': default: #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,fdm->ompchunk) \ private(ix,iz) \ shared(fdm,pa,po, \ cox,cax,cbx, \ coz,caz,cbz, \ vpz) #endif for (ix=NOP; ix<fdm->nxpad-NOP; ix++) { for(iz=NOP; iz<fdm->nzpad-NOP; iz++) { pa[ix][iz] = ( Dxx(po,ix,iz,cox,cax,cbx) + Dzz(po,ix,iz,coz,caz,cbz) ) * vpz[ix][iz]; } } break; } /* inject acceleration source */ if(expl) { sf_floatread(ww, 1,Fwav); ; lint2d_inject1(pa,ww[0],cs); if(atype[0] != 'i') lint2d_inject1(qa,ww[0],cs); } else { sf_floatread(ww,ns,Fwav); ; lint2d_inject(pa,ww,cs); if(atype[0] != 'i') lint2d_inject(qa,ww,cs); } /* step forward in time */ #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,fdm->ompchunk) \ private(ix,iz) \ shared(fdm,pa,po,pm,pp,dt2) #endif for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nzpad; iz++) { pp[ix][iz] = 2*po[ix][iz] - pm[ix][iz] + pa[ix][iz] * dt2; } } /* circulate wavefield arrays */ pt=pm; pm=po; po=pp; pp=pt; if(atype[0] != 'i') { #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,fdm->ompchunk) \ private(ix,iz) \ shared(fdm,qa,qo,qm,qp,dt2) #endif for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nzpad; iz++) { qp[ix][iz] = 2*qo[ix][iz] - qm[ix][iz] + qa[ix][iz] * dt2; } } /* circulate wavefield arrays */ qt=qm; qm=qo; qo=qp; qp=qt; } /* one-way abc apply */ if(dabc) { abcone2d_apply(po,pm,NOP,abc,fdm); sponge2d_apply(pm,spo,fdm); sponge2d_apply(po,spo,fdm); if(atype[0] != 'i') { abcone2d_apply(qo,qm,NOP,abc,fdm); sponge2d_apply(qm,spo,fdm); sponge2d_apply(qo,spo,fdm); } } /* compute stress */ if(sout && (atype[0] != 'i')) { #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,fdm->ompchunk) \ private(ix,iz) \ shared(fdm,po,qo,sf) #endif for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nzpad; iz++) { sf[ix][iz] = po[ix][iz] + qo[ix][iz]; } } } /* extract data at receivers */ if(sout && (atype[0] != 'i')) {lint2d_extract(sf,dd,cr); } else { lint2d_extract(po,dd,cr);} if(it%jdata==0) sf_floatwrite(dd,nr,Fdat); /* extract wavefield in the "box" */ if(snap && it%jsnap==0) { if(sout && (atype[0] != 'i')) {cut2d(sf,pc,fdm,acz,acx); } else { cut2d(po,pc,fdm,acz,acx);} sf_floatwrite(pc[0],sf_n(acz)*sf_n(acx),Fwfl); } } if(verb) fprintf(stderr,"\n"); /*------------------------------------------------------------*/ /* deallocate arrays */ free(*pm); free(pm); free(*pp); free(pp); free(*po); free(po); free(*pa); free(pa); free(*pc); free(pc); free(*vp); free(vp); free(*vpz); free(vpz); if(atype[0] != 'i') { free(*qm); free(qm); free(*qp); free(qp); free(*qo); free(qo); free(*qa); free(qa); free(*vpn); free(vpn); free(*vpx); free(vpx); if(uses){ free(*vsz); free(vsz); } if(sout){ free(*sf); free(sf); } } if(atype[0] == 't') { free(*sit); free(sit); free(*cot); free(cot); } free(ww); free(ss); free(rr); free(dd); /*------------------------------------------------------------*/ exit (0); }
int main(int argc, char* argv[]) { bool verb,fsrf,snap,expl,dabc; int jsnap,ntsnap,jdata; /* OMP parameters */ #ifdef _OPENMP int ompnth; #endif /* I/O files */ sf_file Fwav=NULL; /* wavelet */ sf_file Fsou=NULL; /* sources */ sf_file Frec=NULL; /* receivers */ sf_file Fvel=NULL; /* velocity */ sf_file Fdat=NULL; /* data */ sf_file Fwfl=NULL; /* wavefield */ /* cube axes */ sf_axis at,az,ax; sf_axis as,ar; int nt,nz,nx,ns,nr,nb; int it,iz,ix; float dt,dz,dx,idz,idx,dt2; /* FDM structure */ fdm2d fdm=NULL; abcone2d abc=NULL; sponge spo=NULL; /* I/O arrays */ float *ww=NULL; /* wavelet */ pt2d *ss=NULL; /* sources */ pt2d *rr=NULL; /* receivers */ float *dd=NULL; /* data */ float **tt=NULL; float **vp=NULL; /* velocity */ float **vp2=NULL; float **vv2=NULL; float **vh2=NULL; float **rm,**ro,**rp,**ra,**rt; /* main wavefield */ float **qm,**qo,**qp,**qa,**qt; /* auxiliary wavefield */ /* linear interpolation weights/indices */ lint2d cs,cr; /* FD operator size */ float cox,coz,cax,cbx,caz,cbz; /* wavefield cut params */ sf_axis acz=NULL,acx=NULL; int nqz,nqx; float oqz,oqx; float dqz,dqx; float **qc=NULL; float H2q,H1r; /*------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); /*------------------------------------------------------------*/ /* OMP parameters */ #ifdef _OPENMP ompnth=omp_init(); #endif /*------------------------------------------------------------*/ if(! sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ if(! sf_getbool("snap",&snap)) snap=false; /* wavefield snapshots flag */ if(! sf_getbool("free",&fsrf)) fsrf=false; /* free surface flag */ if(! sf_getbool("expl",&expl)) expl=false; /* "exploding reflector" */ if(! sf_getbool("dabc",&dabc)) dabc=false; /* absorbing BC */ /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* I/O files */ Fwav = sf_input ("in" ); /* wavelet */ Fvel = sf_input ("vel"); /* velocity */ Fsou = sf_input ("sou"); /* sources */ Frec = sf_input ("rec"); /* receivers */ Fwfl = sf_output("wfl"); /* wavefield */ Fdat = sf_output("out"); /* data */ /*------------------------------------------------------------*/ /* axes */ at = sf_iaxa(Fwav,2); sf_setlabel(at,"t"); if(verb) sf_raxa(at); /* time */ az = sf_iaxa(Fvel,1); sf_setlabel(az,"z"); if(verb) sf_raxa(az); /* depth */ ax = sf_iaxa(Fvel,2); sf_setlabel(ax,"x"); if(verb) sf_raxa(ax); /* space */ as = sf_iaxa(Fsou,2); sf_setlabel(as,"s"); if(verb) sf_raxa(as); /* sources */ ar = sf_iaxa(Frec,2); sf_setlabel(ar,"r"); if(verb) sf_raxa(ar); /* receivers */ nt = sf_n(at); dt = sf_d(at); nz = sf_n(az); dz = sf_d(az); nx = sf_n(ax); dx = sf_d(ax); ns = sf_n(as); nr = sf_n(ar); /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* other execution parameters */ if(! sf_getint("jdata",&jdata)) jdata=1; if(snap) { /* save wavefield every *jsnap* time steps */ if(! sf_getint("jsnap",&jsnap)) jsnap=nt; } /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* expand domain for FD operators and ABC */ if( !sf_getint("nb",&nb) || nb<NOP) nb=NOP; fdm=fdutil_init(verb,fsrf,az,ax,nb,1); sf_setn(az,fdm->nzpad); sf_seto(az,fdm->ozpad); if(verb) sf_raxa(az); sf_setn(ax,fdm->nxpad); sf_seto(ax,fdm->oxpad); if(verb) sf_raxa(ax); /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* setup output data header */ sf_oaxa(Fdat,ar,1); sf_setn(at,nt/jdata); sf_setd(at,dt*jdata); sf_oaxa(Fdat,at,2); /* 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_getfloat("oqz",&oqz)) oqz=sf_o(az); if(!sf_getfloat("oqx",&oqx)) oqx=sf_o(ax); dqz=sf_d(az); dqx=sf_d(ax); acz = sf_maxa(nqz,oqz,dqz); sf_raxa(acz); acx = sf_maxa(nqx,oqx,dqx); sf_raxa(acx); /* check if the imaging window fits in the wavefield domain */ qc=sf_floatalloc2(sf_n(acz),sf_n(acx)); ntsnap=0; for(it=0; it<nt; it++) { if(it%jsnap==0) ntsnap++; } sf_setn(at, ntsnap); sf_setd(at,dt*jsnap); if(verb) sf_raxa(at); sf_oaxa(Fwfl,acz,1); sf_oaxa(Fwfl,acx,2); sf_oaxa(Fwfl,at, 3); } if(expl) { ww = sf_floatalloc( 1); } else { ww = sf_floatalloc(ns); } dd = sf_floatalloc(nr); /*------------------------------------------------------------*/ /* setup source/receiver coordinates */ ss = (pt2d*) sf_alloc(ns,sizeof(*ss)); rr = (pt2d*) sf_alloc(nr,sizeof(*rr)); pt2dread1(Fsou,ss,ns,2); /* read (x,z) coordinates */ pt2dread1(Frec,rr,nr,2); /* read (x,z) coordinates */ cs = lint2d_make(ns,ss,fdm); cr = lint2d_make(nr,rr,fdm); /*------------------------------------------------------------*/ /* setup FD coefficients */ idz = 1/dz; idx = 1/dx; cox= C0 * (idx*idx); cax= CA * idx*idx; cbx= CB * idx*idx; coz= C0 * (idz*idz); caz= CA * idz*idz; cbz= CB * idz*idz; /* precompute dt^2*/ dt2 = dt*dt; /*------------------------------------------------------------*/ tt = sf_floatalloc2(nz,nx); /*------------------------------------------------------------*/ /* input velocity */ vp =sf_floatalloc2(fdm->nzpad,fdm->nxpad); vp2 =sf_floatalloc2(fdm->nzpad,fdm->nxpad); vv2 =sf_floatalloc2(fdm->nzpad,fdm->nxpad); vh2 =sf_floatalloc2(fdm->nzpad,fdm->nxpad); sf_floatread(tt[0],nz*nx,Fvel ); expand(tt,vv2,fdm); /* vertical v */ sf_floatread(tt[0],nz*nx,Fvel ); expand(tt,vp2,fdm); /* NMO v */ sf_floatread(tt[0],nz*nx,Fvel ); expand(tt,vh2,fdm); /* horizontal v */ for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nzpad; iz++) { vp2[ix][iz] = vp2[ix][iz] * vp2[ix][iz]; vv2[ix][iz] = vv2[ix][iz] * vv2[ix][iz]; vh2[ix][iz] = vh2[ix][iz] * vh2[ix][iz]; } } if(fsrf) { /* free surface */ for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nb; iz++) { vp2[ix][iz]=0; vv2[ix][iz]=0; vh2[ix][iz]=0; } } } /*------------------------------------------------------------*/ free(*tt); free(tt); /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* allocate wavefield arrays */ qm=sf_floatalloc2(fdm->nzpad,fdm->nxpad); qo=sf_floatalloc2(fdm->nzpad,fdm->nxpad); qp=sf_floatalloc2(fdm->nzpad,fdm->nxpad); qa=sf_floatalloc2(fdm->nzpad,fdm->nxpad); rm=sf_floatalloc2(fdm->nzpad,fdm->nxpad); ro=sf_floatalloc2(fdm->nzpad,fdm->nxpad); rp=sf_floatalloc2(fdm->nzpad,fdm->nxpad); ra=sf_floatalloc2(fdm->nzpad,fdm->nxpad); for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nzpad; iz++) { qm[ix][iz]=0; qo[ix][iz]=0; qp[ix][iz]=0; qa[ix][iz]=0; rm[ix][iz]=0; ro[ix][iz]=0; rp[ix][iz]=0; ra[ix][iz]=0; } } /*------------------------------------------------------------*/ if(dabc) { /* one-way abc setup */ abc = abcone2d_make(NOP,dt,vp,fsrf,fdm); /* sponge abc setup */ spo = sponge_make(fdm->nb); } /*------------------------------------------------------------*/ /* * MAIN LOOP */ /*------------------------------------------------------------*/ if(verb) fprintf(stderr,"\n"); for (it=0; it<nt; it++) { if(verb) fprintf(stderr,"\b\b\b\b\b%d",it); #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,fdm->ompchunk) \ private(ix,iz,H2q,H1r) \ shared(fdm,ra,ro,qa,qo,cox,coz,cax,caz,cbx,cbz,idx,idz,vp2) #endif for (ix=NOP; ix<fdm->nxpad-NOP; ix++) { for(iz=NOP; iz<fdm->nzpad-NOP; iz++) { H2q = Dxx(qo,ix,iz,cox,cax,cbx); H1r = Dzz(ro,ix,iz,coz,caz,cbz); /* main field - q */ qa[ix][iz] = H2q * vh2[ix][iz] + H1r * vv2[ix][iz] ; /* auxiliary field - r */ ra[ix][iz] = H2q * vp2[ix][iz] + H1r * vv2[ix][iz] ; } } /* inject acceleration source */ if(expl) { sf_floatread(ww, 1,Fwav); lint2d_inject1(ra,ww[0],cs); lint2d_inject1(qa,ww[0],cs); } else { sf_floatread(ww,ns,Fwav); lint2d_inject(ra,ww,cs); lint2d_inject(qa,ww,cs); } /* step forward in time */ #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,fdm->ompchunk) \ private(ix,iz) \ shared(fdm,ra,ro,rm,rp,qa,qo,qm,qp,dt2) #endif for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nzpad; iz++) { qp[ix][iz] = 2*qo[ix][iz] - qm[ix][iz] + qa[ix][iz] * dt2; rp[ix][iz] = 2*ro[ix][iz] - rm[ix][iz] + ra[ix][iz] * dt2; } } /* circulate wavefield arrays */ qt=qm; qm=qo; qo=qp; qp=qt; rt=rm; rm=ro; ro=rp; rp=rt; if(dabc) { /* one-way abc apply */ abcone2d_apply(qo,qm,NOP,abc,fdm); sponge2d_apply(qm,spo,fdm); sponge2d_apply(qo,spo,fdm); sponge2d_apply(qp,spo,fdm); /* one-way abc apply */ abcone2d_apply(ro,rm,NOP,abc,fdm); sponge2d_apply(rm,spo,fdm); sponge2d_apply(ro,spo,fdm); sponge2d_apply(rp,spo,fdm); } /* extract data */ lint2d_extract(qo,dd,cr); if(snap && it%jsnap==0) { cut2d(qo,qc,fdm,acz,acx); sf_floatwrite(qc[0],sf_n(acz)*sf_n(acx),Fwfl); } if( it%jdata==0) sf_floatwrite(dd,nr,Fdat); } if(verb) fprintf(stderr,"\n"); /*------------------------------------------------------------*/ /* deallocate arrays */ free(*rm); free(rm); free(*rp); free(rp); free(*ro); free(ro); free(*ra); free(ra); free(*qm); free(qm); free(*qp); free(qp); free(*qo); free(qo); free(*qa); free(qa); free(*qc); free(qc); free(*vp); free(vp); free(*vp2); free(vp2); free(*vh2); free(vh2); free(*vv2); free(vv2); free(ww); free(ss); free(rr); free(dd); exit (0); }
int main(int argc, char* argv[]) { bool verb; sf_file Fi,Fs,Fr; /* I/O files */ sf_axis at,az,ax,aa; /* cube axes */ int nt,nz,nx, nhz,nhx,nht; int it,iz,ix, ihz,ihx,iht; int jt,jz,jx; int kt,kz,kx; float **ii=NULL, ***us=NULL,***ur=NULL; /* arrays */ int ompchunk; int lox,hix; int loz,hiz; int lot,hit; float ts,tr; /*------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); if(! sf_getint("ompchunk",&ompchunk)) ompchunk=1; /* OpenMP data chunk size */ if(! sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ if(! sf_getint("nhz",&nhz)) nhz=0; if(! sf_getint("nhx",&nhx)) nhx=0; if(! sf_getint("nht",&nht)) nht=1; sf_warning("nht=%d nhx=%d nhz=%d",2*nht+1,2*nhx+1,2*nhz+1); Fs = sf_input ("in" ); /* source wavefield */ Fr = sf_input ("ur" ); /* receiver wavefield */ Fi = sf_output("out"); /* image */ /* read axes */ az=sf_iaxa(Fs,1); sf_setlabel(az,"z"); if(verb) sf_raxa(az); /* depth */ ax=sf_iaxa(Fs,2); sf_setlabel(ax,"x"); if(verb) sf_raxa(ax); /* position */ at=sf_iaxa(Fs,3); sf_setlabel(at,"t"); if(verb) sf_raxa(at); /* time */ /* set output axes */ aa=sf_maxa(1,0,1); sf_oaxa(Fi,aa,3); nz = sf_n(az); nx = sf_n(ax); nt = sf_n(at); /* allocate work arrays */ us=sf_floatalloc3(nz,nx,nt); ur=sf_floatalloc3(nz,nx,nt); ii=sf_floatalloc2(nz,nx); /* init output */ for (iz=0; iz<nz; iz++) { for (ix=0; ix<nx; ix++) { ii[ix][iz]=0; } } sf_floatread(us[0][0],nz*nx*nt,Fs); sf_floatread(ur[0][0],nz*nx*nt,Fr); if(verb) fprintf(stderr," t x\n"); if(verb) fprintf(stderr,"%4d %4d\n",nt,nx); for( it=nht; it<nt-nht; it++) { lot=-nht; hit=nht+1; for( ix=nhx; ix<nx-nhx; ix++) { lox=-nhx; hix=nhx+1; if(verb) fprintf(stderr,"%4d %4d",it,ix); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(iz,iht,ihx,ihz,ts,tr,loz,hiz,jt,kt,jx,kx,jz,kz) shared(ur,nz,nhz,lot,hit,lox,hix) #endif for(iz=nhz; iz<nz-nhz; iz++) { loz=-nhz; hiz=nhz+1; /* ts = us[it][ix][iz]*us[it][ix][iz];*/ ts = us[it][ix][iz]; tr = 0; for( iht=lot; iht<hit; iht++) { jt=it-iht; kt=it+iht; for( ihx=lox; ihx<hix; ihx++) { jx=ix-ihx; kx=ix+ihx; for(ihz=loz; ihz<hiz; ihz++) { jz=iz-ihz; kz=iz+ihz; tr += ur[jt][jx][jz] * ur[kt][kx][kz]; } /* nhz */ } /* nhx */ } /* nht */ ii[ix][iz] += ts * tr; } /* nz */ if(verb) fprintf(stderr,"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); } /* nx */ } /* nt */ if(verb) fprintf(stderr,"\n"); sf_floatwrite(ii[0],nz*nx,Fi); exit (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); }
int main( int argc , char* argv[] ) { sf_init( argc , argv ); float ***data, ****data_out; int ix, nx, iy, ny, it, nt, nfft, nw, iw; /* * @ Setup the parameters of the dimensions of the DATASETS * @ the Output Parameters also be setup */ sf_file Fi=NULL, Fo=NULL; /* * @ Setup the FILE POINT of Input Data and Output Frequency Dependent Trace */ sf_axis at, ax, ay, aw; /* * @ Setup the AXISes of DataSETS */ float var; /* * @ Variance of the Window Function in FT */ int dim, num_dim[SF_MAX_DIM]; float dt, dw, nw_s, fre; if(!sf_getint ( "nw" , &nw )) sf_error( "Missing nw!\n" ); /* Input Parameter: the Number of Slicing in FD */ if(!sf_getfloat( "nw_s" , &nw_s)) sf_error( "Missing nw_s!\n" ); /* Input Parameter: the starting number of frequency */ if(!sf_getfloat( "dw" , &dw )) sf_error( "Missing dw!\n" ); /* Input Parameter: the interval of OUTPUT frequency */ if(!sf_getint( "nfft" , &nfft )) sf_error( "Missing nfft!\n" ); /* Input Parameter: the length of FFT */ if(!sf_getfloat( "variance" , &var )) sf_error( "Missing variance!\n" ); /* the variance of the window */ Fi = sf_input ( "data_in" ); Fo = sf_output( "data_out" ); dim = sf_filedims( Fi , num_dim ); if( dim==1 ) { at = sf_iaxa( Fi , 1 ); nt = sf_n( at ); dt = sf_d( at ); nx = 1; ny = 1; } else if( dim==2 ) { at = sf_iaxa( Fi , 1 ); nt = sf_n( at ); dt = sf_d( at ); ax = sf_iaxa( Fi , 2 ); nx = sf_n( ax ); ny = 1; } else if( dim==3 ) { at = sf_iaxa( Fi , 1 ); nt = sf_n( at ); dt = sf_d( at ); ax = sf_iaxa( Fi , 2 ); nx = sf_n( ax ); ay = sf_iaxa( Fi , 3 ); ny = sf_n( ay ); } else { sf_error( "DIMENSION WRONG!\n" ); } data = sf_floatalloc3( nt , nx , ny ); data_out = sf_floatalloc4( nt , nw , nx , ny ); sf_floatread( &data[0][0][0] , nt*nx*ny , Fi ); for( iy=0 ; iy<ny ; iy++ ) for( ix=0 ; ix<nx ; ix++ ) for( iw=0 ; iw<nw ; iw++ ) { fre = nw_s+dw*iw; winft( &data[iy][ix][0] , &data_out[iy][ix][iw][0] , nt , nfft , dt , fre , var ); } aw = sf_maxa( nw , nw_s , dw ); sf_oaxa( Fo , at , 1 ); sf_oaxa( Fo , aw , 2 ); if( dim==2 ) { sf_oaxa( Fo , ax , 3 ); } if( dim==3 ) { sf_oaxa( Fo , ax , 3 ); sf_oaxa( Fo , ay , 4 ); } sf_floatwrite( &data_out[0][0][0][0] , ny*nx*nw*nt , Fo ); free( data ); free( data_out ); exit( 0 ); }
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[]) { bool verb,isreversed; sf_file Fs,Fr,Fi,Fc; /* I/O files */ sf_axis az,ax,at,ac,aa; /* cube axes */ int nz,nx,nt, nhx, nhz, nht,nc; int it, ihx, ihz, iht,ic; int nhx2,nhz2,nht2; off_t iseek; float ***us=NULL,***ur=NULL,****ii=NULL; pt2d *cc=NULL; bool *ccin=NULL; float cxmin,czmin; float cxmax,czmax; int icx, icz; int mcx, mcz, mct; int pcx, pcz, pct; int **mcxall, **pcxall; int **mczall, **pczall; int *mctall, *pctall; int lht; float scale; /* gaussian taper */ bool gaus; float gsx,gsz,gst; /* std dev */ float gx, gz, gt; /*------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); /* OMP parameters */ #ifdef _OPENMP omp_init(); #endif if(! sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ if(! sf_getbool("isreversed",&isreversed)) isreversed=false; /* reversed rec wfld? */ Fs = sf_input ("in" ); /* source wavefield */ Fr = sf_input ("ur" ); /* receiver wavefield */ Fc = sf_input ("cc" ); /* CIP coordinates */ Fi = sf_output("out"); /* image */ /*------------------------------------------------------------*/ /* read axes */ az=sf_iaxa(Fs,1); nz = sf_n(az); ax=sf_iaxa(Fs,2); nx = sf_n(ax); at=sf_iaxa(Fs,3); nt = sf_n(at); /* CIP coordinates */ ac = sf_iaxa(Fc,2); sf_setlabel(ac,"cc"); sf_setunit(ac,""); nc = sf_n(ac); if(! sf_getint("nhz",&nhz)) nhz=0; nhz2=2*nhz+1; /* z lags */ if(! sf_getint("nhx",&nhx)) nhx=0; nhx2=2*nhx+1; /* x lags */ if(! sf_getint("nht",&nht)) nht=0; nht2=2*nht+1; /* t lags */ lht=2*nht; if(verb) { sf_warning("nhx=%3d nhz=%3d nht=%3d",nhx2,nhz2,nht2); sf_raxa(az); sf_raxa(ax); sf_raxa(at); sf_raxa(ac); } /* set output axes */ aa=sf_maxa(nhz2,-nhz*sf_d(az),sf_d(az)); sf_setlabel(aa,"hz"); sf_setunit(aa,""); if(verb) sf_raxa(aa); sf_oaxa(Fi,aa,1); aa=sf_maxa(nhx2,-nhx*sf_d(ax),sf_d(ax)); sf_setlabel(aa,"hx"); sf_setunit(aa,""); if(verb) sf_raxa(aa); sf_oaxa(Fi,aa,2); aa=sf_maxa(nht2,-nht*sf_d(at),sf_d(at)); sf_setlabel(aa,"ht"); sf_setunit(aa,""); if(verb) sf_raxa(aa); sf_oaxa(Fi,aa,3); sf_oaxa(Fi,ac,4); if(! sf_getbool("gaus",&gaus)) gaus=false; /* Gaussian taper flag */ if(gaus) { if(! sf_getfloat("gsx",&gsx)) gsx=nhx*sf_d(ax); gsx=1./(2*gsx*gsx); if(! sf_getfloat("gsz",&gsz)) gsz=nhz*sf_d(az); gsz=1./(2*gsz*gsz); if(! sf_getfloat("gst",&gst)) gst=nht*sf_d(at); gst=1./(2*gst*gst); } /*------------------------------------------------------------*/ /* allocate work arrays */ us=sf_floatalloc3(nz,nx,nht2); ur=sf_floatalloc3(nz,nx,nht2); ii=sf_floatalloc4(nhz2,nhx2,nht2,nc); /* zero output */ for(ic=0; ic<nc; ic++) { for (iht=0; iht<nht2; iht++) { for (ihx=0; ihx<nhx2; ihx++) { for(ihz=0; ihz<nhz2; ihz++) { ii[ic][iht][ihx][ihz] = 0; } } } } /*------------------------------------------------------------*/ /* CIP coordinates */ cc= (pt2d*) sf_alloc(nc,sizeof(*cc)); pt2dread1(Fc,cc,nc,2); mcxall=sf_intalloc2(nhx2,nc); pcxall=sf_intalloc2(nhx2,nc); mczall=sf_intalloc2(nhz2,nc); pczall=sf_intalloc2(nhz2,nc); ccin=sf_boolalloc(nc); cxmin = sf_o(ax) + nhx *sf_d(ax); cxmax = sf_o(ax) + (sf_n(ax)-1-nhx)*sf_d(ax); czmin = sf_o(az) + nhz *sf_d(az); czmax = sf_o(az) + (sf_n(az)-1-nhz)*sf_d(az); if(verb) { sf_warning("cxmin=%f,cxmax=%f",cxmin,cxmax); sf_warning("czmin=%f,czmax=%f",czmin,czmax); } for(ic=0; ic<nc; ic++) { ccin[ic]=(cc[ic].x>=cxmin && cc[ic].x<=cxmax && cc[ic].z>=czmin && cc[ic].z<=czmax)?true:false; if(ccin[ic]) { icx = 0.5+(cc[ic].x-sf_o(ax))/sf_d(ax); for(ihx=-nhx; ihx<nhx+1; ihx++) { mcxall[ic][nhx+ihx] = icx-ihx; pcxall[ic][nhx+ihx] = icx+ihx; } icz = 0.5+(cc[ic].z-sf_o(az))/sf_d(az); for(ihz=-nhz; ihz<nhz+1; ihz++) { mczall[ic][nhz+ihz] = icz-ihz; pczall[ic][nhz+ihz] = icz+ihz; } } } mctall=sf_intalloc(nht2); pctall=sf_intalloc(nht2); for (iht=0; iht<nht2; iht++) { mctall[iht]=iht; pctall[iht]=2*nht-iht; } /*------------------------------------------------------------*/ if(isreversed) { /* receiver wavefield is reversed */ /* read wavefield @ [0...2nht-1]*/ for(iht=0;iht<2*nht;iht++) { sf_floatread(us[iht][0],nz*nx,Fs); sf_floatread(ur[iht][0],nz*nx,Fr); } if(verb) fprintf(stderr,"nt\n"); for(it=nht;it<nt-nht;it++) { if(verb) fprintf(stderr,"\b\b\b\b\b\b\b\b\b\b%04d",it); /* read wavefield @ [2nht]*/ sf_floatread(us[ lht ][0],nz*nx,Fs); sf_floatread(ur[ lht ][0],nz*nx,Fr); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) \ private(ic, \ ihx,ihz,iht, \ mcx,mcz,mct, \ pcx,pcz,pct) \ shared (nc,ii,us,ur, \ nhx2, nhz2, nht2, \ mcxall,mczall,mctall, \ pcxall,pczall,pctall,ccin) #endif for(ic=0; ic<nc; ic++) { if(ccin[ic]) { for (iht=0; iht<nht2; iht++) { mct=mctall [iht]; pct=pctall [iht]; for (ihx=0; ihx<nhx2; ihx++) { mcx=mcxall[ic][ihx]; pcx=pcxall[ic][ihx]; for(ihz=0; ihz<nhz2; ihz++) { mcz=mczall[ic][ihz]; pcz=pczall[ic][ihz]; ii[ic][iht][ihx][ihz] += us[mct][mcx][mcz]*ur[pct][pcx][pcz]; } /* ihz */ } /* ihx */ } /* iht */ } } /* ic */ /* update wavefield index (cycle) */ for(iht=0;iht<nht2;iht++) { mctall[iht] = (mctall[iht]+1) % nht2; pctall[iht] = (pctall[iht]+1) % nht2; } lht = (lht+1) % nht2; } /* it */ if(verb) fprintf(stderr,"\n"); } else { /* receiver wavefield is NOT reversed */ /* read wavefield @ [0...2nht-1]*/ for(iht=0;iht<2*nht;iht++) { sf_floatread(us[iht][0],nz*nx,Fs); iseek = (off_t)(nt-1-iht)*nz*nx*sizeof(float); sf_seek(Fr,iseek,SEEK_SET); sf_floatread(ur[iht][0],nz*nx,Fr); } if(verb) fprintf(stderr,"nt\n"); for(it=nht;it<nt-nht;it++) { if(verb) fprintf(stderr,"\b\b\b\b\b\b\b\b\b\b%04d",nt-nht-1-it); /* read wavefield @ [2nht]*/ sf_floatread(us[ lht ][0],nz*nx,Fs); iseek=(off_t)(nt-nht-1-it)*nz*nx*sizeof(float); sf_seek(Fr,iseek,SEEK_SET); sf_floatread(ur[ lht ][0],nz*nx,Fr); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) \ private(ic, \ ihx,ihz,iht, \ mcx,mcz,mct, \ pcx,pcz,pct) \ shared (nc,ii,us,ur, \ nhx2, nhz2, nht2, \ mcxall,mczall,mctall, \ pcxall,pczall,pctall,ccin) #endif for(ic=0; ic<nc; ic++) { if(ccin[ic]) { for (iht=0; iht<nht2; iht++) { mct=mctall [iht]; pct=pctall [iht]; for (ihx=0; ihx<nhx2; ihx++) { mcx=mcxall[ic][ihx]; pcx=pcxall[ic][ihx]; for(ihz=0; ihz<nhz2; ihz++) { mcz=mczall[ic][ihz]; pcz=pczall[ic][ihz]; ii[ic][iht][ihx][ihz] += us[mct][mcx][mcz]*ur[pct][pcx][pcz]; } /* ihz */ } /* ihx */ } /* iht */ } } /* ic */ /* update wavefield index (cycle) */ for(iht=0;iht<nht2;iht++) { mctall[iht] = (mctall[iht]+1) % nht2; pctall[iht] = (pctall[iht]+1) % nht2; } lht = (lht+1) % nht2; } /* it */ if(verb) fprintf(stderr,"\n"); } /* end "is reversed" */ /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* scale image */ scale = 1./nt; for(ic=0; ic<nc; ic++) { for (iht=0; iht<nht2; iht++) { for (ihx=0; ihx<nhx2; ihx++) { for(ihz=0; ihz<nhz2; ihz++) { ii[ic][iht][ihx][ihz] *= scale; } } } } /*------------------------------------------------------------*/ /* apply Gaussian taper */ if(gaus) { for(ic=0; ic<nc; ic++) { for (iht=0;iht<nht2;iht++) { gt=(iht-nht)*sf_d(at); gt*=gt; for (ihx=0;ihx<nhx2;ihx++) { gx=(ihx-nhx)*sf_d(ax); gx*=gx; for(ihz=0;ihz<nhz2;ihz++) { gz=(ihz-nhz)*sf_d(az); gz*=gz; ii[ic][iht][ihx][ihz] *= exp(-gt*gst - gx*gsx - gz*gsz); } } } } } /*------------------------------------------------------------*/ /* write image */ sf_floatwrite(ii[0][0][0],nc*(nhx2)*(nhz2)*(nht2),Fi); /*------------------------------------------------------------*/ /* deallocate arrays */ free(***ii); free(**ii); free(*ii); free(ii); free(*us); free(us); free(*ur); free(ur); free(cc); free(ccin); free(*mcxall); free(mcxall); free(*pcxall); free(pcxall); free(*mczall); free(mczall); free(*pczall); free(pczall); /*------------------------------------------------------------*/ exit (0); }
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[]) { /*grid parameters*/ int nx, nz, nt; float dx, dz, dt; int ix, iz, it; sf_axis at, ax, az; float **vel; /*input velocity*/ float **src, **slt; /*output MMS source and solution*/ /*parameters*/ float slx, slz; float alpha, beta, beta2; float dist2, xx, zz, tt, tmp; sf_file Fvel, Fsrc, Fslt; sf_init(argc, argv); Fvel = sf_input("in"); Fsrc = sf_output("out"); Fslt = sf_output("mslt"); /*the manufactured solution*/ if (SF_FLOAT != sf_gettype(Fvel)) sf_error("Need float input"); ax = sf_iaxa(Fvel, 2); nx = sf_n(ax); dx = sf_d(ax); az = sf_iaxa(Fvel, 1); nz = sf_n(az); dz = sf_d(az); if (!sf_getint("nt",&nt)) sf_error("Need nt"); /*number of time step*/ if (!sf_getfloat("dt", &dt)) sf_error("Need dt"); /*time step*/ if (!sf_getfloat("slx", &slx)) slx = nx*dx*0.5; /*center of source location: x*/ if (!sf_getfloat("slz", &slz)) slz = nz*dz*0.5; /*center of source location: z*/ if (!sf_getfloat("alpha", &alpha)) alpha = 1.0e-2; /*source parameter*/ if (!sf_getfloat("beta", &beta)) beta = 1.0; /*source parameter*/ at = sf_maxa(nt, 0.0, dt); vel = sf_floatalloc2(nz, nx); src = sf_floatalloc2(nz, nx); slt = sf_floatalloc2(nz, nx); sf_floatread(vel[0], nx*nz, Fvel); /*Set output axis*/ sf_oaxa(Fsrc, az, 1); sf_oaxa(Fsrc, ax, 2); sf_oaxa(Fsrc, at, 3); sf_oaxa(Fslt, az, 1); sf_oaxa(Fslt, ax, 2); sf_oaxa(Fslt, at, 3); /*Manufactured Solution Source*/ beta2 = beta*beta; for (it=0; it<nt; it++) { //tt = cosf(it*dt*beta)/beta; tt = expf(-1*(it*dt-0.15)*beta); for (ix=0; ix<nx; ix++) { xx = ix*dx; for (iz=0; iz<nz; iz++) { zz = iz*dz; dist2 = (xx-slx)*(xx-slx) + (zz-slz)*(zz-slz); tmp = expf(-1*alpha*dist2)*tt; //src[ix][iz] = tmp*(beta2+4*alpha*vel[ix][iz]*vel[ix][iz]*(alpha*dist2-1)); src[ix][iz] = tmp*(-1*beta2+4*alpha*vel[ix][iz]*vel[ix][iz]*(alpha*dist2-1)); } sf_floatwrite(src[ix], nz, Fsrc); } } /*solution*/ for (it=0; it<nt; it++) { //tt = sinf(it*dt*beta); tt = expf(-1*(it*dt-0.15)*beta); for (ix=0; ix<nx; ix++) { xx = ix*dx; for (iz=0; iz<nz; iz++) { zz = iz*dz; dist2 = (xx-slx)*(xx-slx) + (zz-slz)*(zz-slz); slt[ix][iz] = expf(-1*alpha*dist2)*tt; } sf_floatwrite(slt[ix], nz, Fslt); } } }
int main(int argc, char* argv[]) { bool verb,fsrf,snap,expl; int jsnap,ntsnap; int jdata; /* I/O files */ sf_file Fwav=NULL; /* wavelet */ sf_file Fsou=NULL; /* sources */ sf_file Frec=NULL; /* receivers */ sf_file Fvel=NULL; /* velocity */ sf_file Fref=NULL; /* reflectivity */ sf_file Fden=NULL; /* density */ sf_file Fdat=NULL; /* data (background) */ sf_file Fwfl=NULL; /* wavefield (background) */ sf_file Flid=NULL; /* data (scattered) */ sf_file Fliw=NULL; /* wavefield (scattered) */ /* I/O arrays */ float *ww=NULL; /* wavelet */ pt2d *ss=NULL; /* sources */ pt2d *rr=NULL; /* receivers */ float **vpin=NULL; /* velocity */ float **roin=NULL; /* density */ float **rfin=NULL; /* reflectivity */ float **vp=NULL; /* velocity in expanded domain */ float **ro=NULL; /* density in expanded domain */ float **ro1=NULL; /* normalized 1st derivative of density on axis 1 */ float **ro2=NULL; /* normalized 1st derivative of density on axis 2 */ float **rf=NULL; /* reflectivity in expanded domain */ float *bdd=NULL; /* data (background) */ float *sdd=NULL; /* data (scattered) */ float **vt=NULL; /* temporary vp*vp * dt*dt */ float **bum,**buo,**bup,**bua,**but; /* wavefield: um = U @ t-1; uo = U @ t; up = U @ t+1 */ float **sum,**suo,**sup,**sua,**sut; /* wavefield: um = U @ t-1; uo = U @ t; up = U @ t+1 */ /* cube axes */ sf_axis at,a1,a2,as,ar; int nt,n1,n2,ns,nr,nb; int it,i1,i2; float dt,d1,d2,id1,id2,dt2; /* linear interpolation weights/indices */ lint2d cs,cr; fdm2d fdm; abcone2d abc; /* abc */ sponge spo; /* FD operator size */ float co,ca2,cb2,ca1,cb1; int ompchunk; #ifdef _OPENMP int ompnth,ompath; #endif sf_axis ac1=NULL,ac2=NULL; int nqz,nqx; float oqz,oqx; float dqz,dqx; float **uc=NULL; /*------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); if(! sf_getint("ompchunk",&ompchunk)) ompchunk=1; /* OpenMP data chunk size */ #ifdef _OPENMP if(! sf_getint("ompnth", &ompnth)) ompnth=0; /* OpenMP available threads */ #pragma omp parallel ompath=omp_get_num_threads(); if(ompnth<1) ompnth=ompath; omp_set_num_threads(ompnth); sf_warning("using %d threads of a total of %d",ompnth,ompath); #endif if(! sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ if(! sf_getbool("snap",&snap)) snap=false; /* wavefield snapshots flag */ if(! sf_getbool("free",&fsrf)) fsrf=false; /* free surface flag */ if(! sf_getbool("expl",&expl)) expl=false; /* "exploding reflector" */ Fwav = sf_input ("in" ); /* wavelet */ Fsou = sf_input ("sou"); /* sources */ Frec = sf_input ("rec"); /* receivers */ Fvel = sf_input ("vel"); /* velocity */ Fden = sf_input ("den"); /* density */ Fref = sf_input ("ref"); /* reflectivity */ Fwfl = sf_output("wfl"); /* wavefield */ Fdat = sf_output("out"); /* data */ Fliw = sf_output("liw"); /* wavefield (scattered) */ Flid = sf_output("lid"); /* data (scattered) */ /* axes */ at = sf_iaxa(Fwav,2); sf_setlabel(at,"t"); if(verb) sf_raxa(at); /* time */ as = sf_iaxa(Fsou,2); sf_setlabel(as,"s"); if(verb) sf_raxa(as); /* sources */ ar = sf_iaxa(Frec,2); sf_setlabel(ar,"r"); if(verb) sf_raxa(ar); /* receivers */ a1 = sf_iaxa(Fvel,1); sf_setlabel(a1,"z"); if(verb) sf_raxa(a1); /* depth */ a2 = sf_iaxa(Fvel,2); sf_setlabel(a2,"x"); if(verb) sf_raxa(a2); /* space */ nt = sf_n(at); dt = sf_d(at); ns = sf_n(as); nr = sf_n(ar); n1 = sf_n(a1); d1 = sf_d(a1); n2 = sf_n(a2); d2 = sf_d(a2); if(! sf_getint("jdata",&jdata)) jdata=1; if(snap) { /* save wavefield every *jsnap* time steps */ if(! sf_getint("jsnap",&jsnap)) jsnap=nt; } /*------------------------------------------------------------*/ /* setup output data header */ sf_oaxa(Fdat,ar,1); sf_oaxa(Flid,ar,1); sf_setn(at,nt/jdata); sf_setd(at,dt*jdata); sf_oaxa(Fdat,at,2); sf_oaxa(Flid,at,2); /* setup output wavefield header */ if(snap) { if(!sf_getint ("nqz",&nqz)) nqz=sf_n(a1); if(!sf_getint ("nqx",&nqx)) nqx=sf_n(a2); if(!sf_getfloat("oqz",&oqz)) oqz=sf_o(a1); if(!sf_getfloat("oqx",&oqx)) oqx=sf_o(a2); dqz=sf_d(a1); dqx=sf_d(a2); ac1 = sf_maxa(nqz,oqz,dqz); ac2 = sf_maxa(nqx,oqx,dqx); /* check if the imaging window fits in the wavefield domain */ uc=sf_floatalloc2(sf_n(ac1),sf_n(ac2)); ntsnap=0; for(it=0; it<nt; it++) { if(it%jsnap==0) ntsnap++; } sf_setn(at, ntsnap); sf_setd(at,dt*jsnap); if(verb) sf_raxa(at); /* sf_setn(at,nt/jsnap); sf_setd(at,dt*jsnap); */ sf_oaxa(Fwfl,ac1,1); sf_oaxa(Fwfl,ac2,2); sf_oaxa(Fwfl,at, 3); sf_oaxa(Fliw,ac1,1); sf_oaxa(Fliw,ac2,2); sf_oaxa(Fliw,at, 3); } /*------------------------------------------------------------*/ /* expand domain for FD operators and ABC */ if( !sf_getint("nb",&nb) || nb<NOP) nb=NOP; fdm=fdutil_init(verb,fsrf,a1,a2,nb,ompchunk); sf_setn(a1,fdm->nzpad); sf_seto(a1,fdm->ozpad); if(verb) sf_raxa(a1); sf_setn(a2,fdm->nxpad); sf_seto(a2,fdm->oxpad); if(verb) sf_raxa(a2); /*------------------------------------------------------------*/ if(expl) ww = sf_floatalloc( 1); else ww = sf_floatalloc(ns); bdd =sf_floatalloc(nr); sdd =sf_floatalloc(nr); /*------------------------------------------------------------*/ /* setup source/receiver coordinates */ ss = (pt2d*) sf_alloc(ns,sizeof(*ss)); rr = (pt2d*) sf_alloc(nr,sizeof(*rr)); pt2dread1(Fsou,ss,ns,2); /* read (x,z) coordinates */ pt2dread1(Frec,rr,nr,2); /* read (x,z) coordinates */ cs = lint2d_make(ns,ss,fdm); cr = lint2d_make(nr,rr,fdm); /*------------------------------------------------------------*/ /* setup FD coefficients */ dt2 = dt*dt; id1 = 1/d1; id2 = 1/d2; co = C0 * (id2*id2+id1*id1); ca2= CA * id2*id2; cb2= CB * id2*id2; ca1= CA * id1*id1; cb1= CB * id1*id1; /*------------------------------------------------------------*/ /* input density */ roin=sf_floatalloc2(n1, n2 ); ro =sf_floatalloc2(fdm->nzpad,fdm->nxpad); ro1 =sf_floatalloc2(fdm->nzpad,fdm->nxpad); ro2 =sf_floatalloc2(fdm->nzpad,fdm->nxpad); sf_floatread(roin[0],n1*n2,Fden); expand(roin,ro,fdm); /* normalized density derivatives */ for (i2=NOP; i2<fdm->nxpad-NOP; i2++) { for(i1=NOP; i1<fdm->nzpad-NOP; i1++) { ro1[i2][i1] = D1(ro,i2,i1,id1) / ro[i2][i1]; ro2[i2][i1] = D2(ro,i2,i1,id2) / ro[i2][i1]; } } free(*roin); free(roin); /*------------------------------------------------------------*/ /* input velocity */ vpin=sf_floatalloc2(n1, n2 ); vp =sf_floatalloc2(fdm->nzpad,fdm->nxpad); vt =sf_floatalloc2(fdm->nzpad,fdm->nxpad); sf_floatread(vpin[0],n1*n2,Fvel); expand(vpin,vp,fdm); free(*vpin); free(vpin); /*------------------------------------------------------------*/ /* input reflectivity */ rfin=sf_floatalloc2(n1, n2 ); rf =sf_floatalloc2(fdm->nzpad,fdm->nxpad); sf_floatread(rfin[0],n1*n2,Fref); expand(rfin,rf,fdm); free(*rfin); free(rfin); for (i2=0; i2<fdm->nxpad; i2++) { for(i1=0; i1<fdm->nzpad; i1++) { vt[i2][i1] = vp[i2][i1] * vp[i2][i1] * dt2; } } /* free surface */ if(fsrf) { for (i2=0; i2<fdm->nxpad; i2++) { for(i1=0; i1<fdm->nb; i1++) { vt[i2][i1]=0; } } } /*------------------------------------------------------------*/ /* allocate wavefield arrays */ bum=sf_floatalloc2(fdm->nzpad,fdm->nxpad); buo=sf_floatalloc2(fdm->nzpad,fdm->nxpad); bup=sf_floatalloc2(fdm->nzpad,fdm->nxpad); bua=sf_floatalloc2(fdm->nzpad,fdm->nxpad); sum=sf_floatalloc2(fdm->nzpad,fdm->nxpad); suo=sf_floatalloc2(fdm->nzpad,fdm->nxpad); sup=sf_floatalloc2(fdm->nzpad,fdm->nxpad); sua=sf_floatalloc2(fdm->nzpad,fdm->nxpad); for (i2=0; i2<fdm->nxpad; i2++) { for(i1=0; i1<fdm->nzpad; i1++) { bum[i2][i1]=0; buo[i2][i1]=0; bup[i2][i1]=0; bua[i2][i1]=0; sum[i2][i1]=0; suo[i2][i1]=0; sup[i2][i1]=0; sua[i2][i1]=0; } } /*------------------------------------------------------------*/ /* one-way abc setup */ abc = abcone2d_make(NOP,dt,vp,fsrf,fdm); /* sponge abc setup */ spo = sponge_make(fdm->nb); /*------------------------------------------------------------*/ /* * MAIN LOOP */ /*------------------------------------------------------------*/ if(verb) fprintf(stderr,"\n"); for (it=0; it<nt; it++) { if(verb) fprintf(stderr,"\b\b\b\b\b%d",it); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,fdm->ompchunk) private(i2,i1) shared(fdm,bua,buo,sua,suo,co,ca2,ca1,cb2,cb1,id2,id1) #endif for (i2=NOP; i2<fdm->nxpad-NOP; i2++) { for(i1=NOP; i1<fdm->nzpad-NOP; i1++) { /* 4th order Laplacian operator */ bua[i2][i1] = co * buo[i2 ][i1 ] + ca2*(buo[i2-1][i1 ] + buo[i2+1][i1 ]) + cb2*(buo[i2-2][i1 ] + buo[i2+2][i1 ]) + ca1*(buo[i2 ][i1-1] + buo[i2 ][i1+1]) + cb1*(buo[i2 ][i1-2] + buo[i2 ][i1+2]); sua[i2][i1] = co * suo[i2 ][i1 ] + ca2*(suo[i2-1][i1 ] + suo[i2+1][i1 ]) + cb2*(suo[i2-2][i1 ] + suo[i2+2][i1 ]) + ca1*(suo[i2 ][i1-1] + suo[i2 ][i1+1]) + cb1*(suo[i2 ][i1-2] + suo[i2 ][i1+2]); /* density term */ bua[i2][i1] -= ( D1(buo,i2,i1,id1) * ro1[i2][i1] + D2(buo,i2,i1,id2) * ro2[i2][i1] ); sua[i2][i1] -= ( D1(suo,i2,i1,id1) * ro1[i2][i1] + D2(suo,i2,i1,id2) * ro2[i2][i1] ); } } /* inject acceleration source */ if(expl) { sf_floatread(ww, 1,Fwav); lint2d_inject1(bua,ww[0],cs); } else { sf_floatread(ww,ns,Fwav); lint2d_inject(bua,ww,cs); } /* single scattering */ #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(i2,i1) shared(fdm,buo,sua,rf) #endif for (i2=0; i2<fdm->nxpad; i2++) { for (i1=0; i1<fdm->nzpad; i1++) { sua[i2][i1] -= bua[i2][i1] * 2*rf[i2][i1]; } } /* step forward in time */ #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,fdm->ompchunk) private(i2,i1) shared(fdm,bua,buo,bum,bup,sua,suo,sum,sup,vt,dt2) #endif for (i2=0; i2<fdm->nxpad; i2++) { for(i1=0; i1<fdm->nzpad; i1++) { bup[i2][i1] = 2*buo[i2][i1] - bum[i2][i1] + bua[i2][i1] * vt[i2][i1]; sup[i2][i1] = 2*suo[i2][i1] - sum[i2][i1] + sua[i2][i1] * vt[i2][i1]; } } /* circulate wavefield arrays */ but=bum; bum=buo; buo=bup; bup=but; sut=sum; sum=suo; suo=sup; sup=sut; /* one-way abc apply*/ abcone2d_apply(buo,bum,NOP,abc,fdm); sponge2d_apply(bum, spo,fdm); sponge2d_apply(buo, spo,fdm); abcone2d_apply(suo,sum,NOP,abc,fdm); sponge2d_apply(sum, spo,fdm); sponge2d_apply(suo, spo,fdm); /* extract data at receivers */ lint2d_extract(buo,bdd,cr); lint2d_extract(suo,sdd,cr); if( it%jdata==0) { sf_floatwrite(bdd,nr,Fdat); sf_floatwrite(sdd,nr,Flid); } /* extract wavefield in the "box" */ if(snap && it%jsnap==0) { cut2d(buo,uc,fdm,ac1,ac2); sf_floatwrite(uc[0],sf_n(ac1)*sf_n(ac2),Fwfl); cut2d(suo,uc,fdm,ac1,ac2); sf_floatwrite(uc[0],sf_n(ac1)*sf_n(ac2),Fliw); } } if(verb) fprintf(stderr,"\n"); exit (0); }
int main(int argc, char* argv[]) { bool inv, verb; sf_file Fstk=NULL; /* SS(h,z) file */ sf_file Fang=NULL; /* AD CIG file */ sf_file Fgam=NULL; /* vpvs ratio file */ sf_file Fdip=NULL; /* dip field file */ float **stk=NULL, *gam=NULL, *dip=NULL, **ang=NULL; /* I/O arrays */ float *tmp=NULL; /* mapping arrays */ sf_axis axz; /* depth axis */ sf_axis axs; /* SS axis */ sf_axis axa; /* angle axis */ int ext; int ncig, icig; /* CIG index */ int na; float oa,da; int ia,iz,is; int fint; fint1 sft; float a,t,g,d,n,f; /*------------------------------------------------------------*/ sf_init (argc,argv); if (!sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ if (!sf_getbool("inv", &inv)) inv=false; /* inverse transformation flag */ Fstk = sf_input ( "in"); /* SS(h,z) CIG */ Fang = sf_output( "out"); /* AD CIG */ Fgam = sf_input ("vpvs"); /* vpvs ratio */ Fdip = sf_input ( "dip"); /* dip field */ if (SF_FLOAT != sf_gettype(Fstk)) sf_error("Need float input"); axz = sf_iaxa(Fstk,1); /* depth axis */ axs = sf_iaxa(Fstk,2); /* SS axis */ ncig = sf_leftsize(Fstk,2); /* number of CIGS to process */ /* angle axis */ if (!sf_getint ("na",&na)) na=sf_n(axs); if (!sf_getfloat("da",&da)) da=1./(sf_n(axs)-1); if (!sf_getfloat("oa",&oa)) oa=0.; axa = sf_maxa(na,oa,da); sf_oaxa(Fang,axa,2); if (!sf_getint("extend",&ext)) ext=4; /* tmp extension */ /*------------------------------------------------------------*/ /* I/O arrays */ stk = sf_floatalloc2(sf_n(axz),sf_n(axs)); /* SS(h,z) CIG */ gam = sf_floatalloc (sf_n(axz) ); /* vpvs ratio */ dip = sf_floatalloc (sf_n(axz) ); /* dip field */ ang = sf_floatalloc2(sf_n(axz),sf_n(axa)); /* AD CIG */ /* temp array */ tmp = sf_floatalloc(sf_n(axs)); /*------------------------------------------------------------*/ sft = fint1_init(ext,sf_n(axs),0); /*------------------------------------------------------------*/ for (icig=0; icig < ncig; icig++) { /* loop over CIG */ if(verb) sf_warning("%d of %d",icig+1,ncig); sf_floatread(stk[0],sf_n(axz)*sf_n(axs),Fstk); sf_floatread(gam ,sf_n(axz) ,Fgam); sf_floatread(dip ,sf_n(axz) ,Fdip); /*------------------------------------------------------------*/ for (iz=0; iz < sf_n(axz); iz++) { /* loop over depth */ g = gam[iz]; d = dip[iz]; d*=(g*g-1.); for (is = 0; is < sf_n(axs); is++) { /* loop over slant-stack index */ tmp[is] = stk[is][iz]; } fint1_set(sft,tmp); for (ia=0; ia < sf_n(axa); ia++) { a = sf_o(axa)+ia*sf_d(axa); /* ang */ t = tanf(a/180*SF_PI); /* tan */ /* * mapping from tan(a) to slant-stack value (n) */ n = (4*g*t+d*(t*t+1.)) / ( t*t * (g-1)*(g-1) + (g+1)*(g+1) ); f = (n - sf_o(axs)) / sf_d(axs); fint = f; if (fint >= 0 && fint < sf_n(axs)) { ang[ia][iz] = fint1_apply(sft,fint,f-fint,false); } else { ang[ia][iz] = 0.; } } /* a */ } /* z */ /*------------------------------------------------------------*/ sf_floatwrite(ang[0],sf_n(axz)*sf_n(axa),Fang); } exit(0); }
int main(int argc, char* argv[]) { bool verb,fsrf,snap,expl,dabc; int jsnap,ntsnap,jdata; /* OMP parameters */ #ifdef _OPENMP int ompnth; #endif /* I/O files */ sf_file Fwav=NULL; /* wavelet */ sf_file Fsou=NULL; /* sources */ sf_file Frec=NULL; /* receivers */ sf_file Fmag=NULL; /* magnetic permitivity */ sf_file Fele=NULL; /* electric susceptibility */ sf_file Fcdt=NULL; /* conductivity */ sf_file Fdat=NULL; /* data */ sf_file Fwfl=NULL; /* wavefield */ /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* cube axes */ sf_axis at,az,ax; sf_axis as,ar; int nt,nz,nx,ns,nr,nb; int it,iz,ix; float dt,dz,dx,idz,idx; /* FDM structure */ fdm2d fdm=NULL; abcone2d abc=NULL; sponge spo=NULL; /* I/O arrays */ float *ww=NULL; /* wavelet */ pt2d *ss=NULL; /* sources */ pt2d *rr=NULL; /* receivers */ float *dd=NULL; /* data */ float **tt=NULL; float **vel=NULL; /* velocity */ float **mag=NULL; float **ele=NULL; float **cdt=NULL; float **cdtele=NULL; /* temporary cdt*dt/2*ele */ float **magele=NULL; /* temporary dt*dt/mag*ele */ /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ float **um,**uo,**up,**ua,**ut; /* wavefield: um = U @ t-1; uo = U @ t; up = U @ t+1 */ /* linear interpolation weights/indices */ lint2d cs,cr; /* FD operator size */ float co,cax,cbx,caz,cbz; /* wavefield cut params */ sf_axis acz=NULL,acx=NULL; int nqz,nqx; float oqz,oqx; float dqz,dqx; float **uc=NULL; /*------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); /*------------------------------------------------------------*/ /* OMP parameters */ #ifdef _OPENMP ompnth=omp_init(); #endif /*------------------------------------------------------------*/ if(! sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ if(! sf_getbool("snap",&snap)) snap=false; /* wavefield snapshots flag */ if(! sf_getbool("free",&fsrf)) fsrf=false; /* free surface flag */ if(! sf_getbool("expl",&expl)) expl=false; /* "exploding reflector" */ if(! sf_getbool("dabc",&dabc)) dabc=false; /* absorbing BC */ /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* I/O files */ Fwav = sf_input ("in" ); /* wavelet */ Fsou = sf_input ("sou"); /* sources */ Frec = sf_input ("rec"); /* receivers */ Fwfl = sf_output("wfl"); /* wavefield */ Fdat = sf_output("out"); /* data */ /*------------------------------------------------------------*/ Fmag = sf_input ("mag"); /* magnetic permitivity */ Fele = sf_input ("ele"); /* electric susceptibility */ Fcdt = sf_input ("cdt"); /* conductivity */ /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* axes */ at = sf_iaxa(Fwav,2); sf_setlabel(at,"t"); if(verb) sf_raxa(at); /* time */ az = sf_iaxa(Fmag,1); sf_setlabel(az,"z"); if(verb) sf_raxa(az); /* depth */ ax = sf_iaxa(Fmag,2); sf_setlabel(ax,"x"); if(verb) sf_raxa(ax); /* space */ as = sf_iaxa(Fsou,2); sf_setlabel(as,"s"); if(verb) sf_raxa(as); /* sources */ ar = sf_iaxa(Frec,2); sf_setlabel(ar,"r"); if(verb) sf_raxa(ar); /* receivers */ nt = sf_n(at); dt = sf_d(at); nz = sf_n(az); dz = sf_d(az); nx = sf_n(ax); dx = sf_d(ax); ns = sf_n(as); nr = sf_n(ar); /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* other execution parameters */ if(! sf_getint("jdata",&jdata)) jdata=1; if(snap) { /* save wavefield every *jsnap* time steps */ if(! sf_getint("jsnap",&jsnap)) jsnap=nt; } /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* expand domain for FD operators and ABC we exclude some of the code to maintain the same size of velocity model*/ if( !sf_getint("nb",&nb) || nb<NOP) nb=NOP; fdm=fdutil_init(verb,fsrf,az,ax,nb,1); /*sf_setn(az,fdm->nzpad); sf_seto(az,fdm->ozpad); if(verb) sf_raxa(az); sf_setn(ax,fdm->nxpad); sf_seto(ax,fdm->oxpad); if(verb) sf_raxa(ax);*/ /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* setup output data header */ sf_oaxa(Fdat,ar,1); sf_setn(at,nt/jdata); sf_setd(at,dt*jdata); sf_oaxa(Fdat,at,2); /* 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_getfloat("oqz",&oqz)) oqz=sf_o(az); if(!sf_getfloat("oqx",&oqx)) oqx=sf_o(ax); dqz=sf_d(az); dqx=sf_d(ax); acz = sf_maxa(nqz,oqz,dqz); sf_raxa(acz); acx = sf_maxa(nqx,oqx,dqx); sf_raxa(acx); /* check if the imaging window fits in the wavefield domain */ uc=sf_floatalloc2(sf_n(acz),sf_n(acx)); ntsnap=0; for(it=0; it<nt; it++) { if(it%jsnap==0) ntsnap++; } sf_setn(at, ntsnap); sf_setd(at,dt*jsnap); if(verb) sf_raxa(at); sf_oaxa(Fwfl,acz,1); sf_oaxa(Fwfl,acx,2); sf_oaxa(Fwfl,at, 3); } if(expl) { ww = sf_floatalloc( 1); } else { ww = sf_floatalloc(ns); } dd = sf_floatalloc(nr); /*------------------------------------------------------------*/ /* setup source/receiver coordinates */ ss = (pt2d*) sf_alloc(ns,sizeof(*ss)); rr = (pt2d*) sf_alloc(nr,sizeof(*rr)); pt2dread1(Fsou,ss,ns,2); /* read (x,z) coordinates */ pt2dread1(Frec,rr,nr,2); /* read (x,z) coordinates */ cs = lint2d_make(ns,ss,fdm); cr = lint2d_make(nr,rr,fdm); /*------------------------------------------------------------*/ /* setup FD coefficients */ idz = 1/dz; idx = 1/dx; co = C0 * (idx*idx+idz*idz); cax= CA * idx*idx; cbx= CB * idx*idx; caz= CA * idz*idz; cbz= CB * idz*idz; /*------------------------------------------------------------*/ tt = sf_floatalloc2(nz,nx); vel = sf_floatalloc2(fdm->nzpad,fdm->nxpad); mag = sf_floatalloc2(fdm->nzpad,fdm->nxpad); ele = sf_floatalloc2(fdm->nzpad,fdm->nxpad); cdt = sf_floatalloc2(fdm->nzpad,fdm->nxpad); cdtele =sf_floatalloc2(fdm->nzpad,fdm->nxpad); magele =sf_floatalloc2(fdm->nzpad,fdm->nxpad); /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* input magnetic susceptibility*/ sf_floatread(tt[0],nz*nx,Fmag ); expand(tt,mag,fdm); /* input electric susceptibility*/ sf_floatread(tt[0],nz*nx,Fele ); expand(tt,ele,fdm); /* input conductivity*/ sf_floatread(tt[0],nz*nx,Fcdt ); expand(tt,cdt,fdm); /*------------------------------------------------------------*/ /* cdtele = sigma*dt/2*epsilon */ /* magele = dt*dt/mu*epsilon */ for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nzpad; iz++) { cdtele[ix][iz] = cdt[ix][iz]*dt/(2*(ele[ix][iz])); magele[ix][iz] = dt*dt/(mag[ix][iz]*ele[ix][iz]); vel[ix][iz] = 1./(sqrt(mag[ix][iz]*ele[ix][iz])); } } if(fsrf) { /* free surface */ for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nb; iz++) { cdtele[ix][iz]=0; magele[ix][iz]=0; } } } /*------------------------------------------------------------*/ free(*tt); free(tt); /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* allocate wavefield arrays */ um=sf_floatalloc2(fdm->nzpad,fdm->nxpad); uo=sf_floatalloc2(fdm->nzpad,fdm->nxpad); up=sf_floatalloc2(fdm->nzpad,fdm->nxpad); ua=sf_floatalloc2(fdm->nzpad,fdm->nxpad); for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nzpad; iz++) { um[ix][iz]=0; uo[ix][iz]=0; up[ix][iz]=0; ua[ix][iz]=0; } } /*------------------------------------------------------------*/ if(dabc) { /* one-way abc setup */ abc = abcone2d_make(NOP,dt,vel,fsrf,fdm); /* sponge abc setup */ spo = sponge_make(fdm->nb); } /*------------------------------------------------------------*/ /* * MAIN LOOP */ /*------------------------------------------------------------*/ if(verb) fprintf(stderr,"\n"); for (it=0; it<nt; it++) { if(verb) fprintf(stderr,"\b\b\b\b\b%d",it); #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,fdm->ompchunk) \ private(ix,iz) \ shared(fdm,ua,uo,co,cax,caz,cbx,cbz,idx,idz) #endif for (ix=NOP; ix<fdm->nxpad-NOP; ix++) { for(iz=NOP; iz<fdm->nzpad-NOP; iz++) { /* 4th order Laplacian operator */ ua[ix][iz] = co * uo[ix ][iz ] + cax*(uo[ix-1][iz ] + uo[ix+1][iz ]) + cbx*(uo[ix-2][iz ] + uo[ix+2][iz ]) + caz*(uo[ix ][iz-1] + uo[ix ][iz+1]) + cbz*(uo[ix ][iz-2] + uo[ix ][iz+2]); } } /* inject acceleration source */ if(expl) { sf_floatread(ww, 1,Fwav); lint2d_inject1(ua,ww[0],cs); } else { sf_floatread(ww,ns,Fwav); lint2d_inject(ua,ww,cs); } /* step forward in time */ #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,fdm->ompchunk) \ private(ix,iz) \ shared(fdm,ua,uo,um,up,cdtele,magele) #endif for (ix=0; ix<fdm->nxpad; ix++) { for(iz=0; iz<fdm->nzpad; iz++) { up[ix][iz] = (2*uo[ix][iz] - (1-cdtele[ix][iz])*um[ix][iz] + ua[ix][iz]*(magele[ix][iz]))/(1+cdtele[ix][iz]); } } /* circulate wavefield arrays */ ut=um; um=uo; uo=up; up=ut; if(dabc) { /* one-way abc apply */ abcone2d_apply(uo,um,NOP,abc,fdm); sponge2d_apply(um,spo,fdm); sponge2d_apply(uo,spo,fdm); sponge2d_apply(up,spo,fdm); } /* extract data */ lint2d_extract(uo,dd,cr); if(snap && it%jsnap==0) { cut2d(uo,uc,fdm,acz,acx); sf_floatwrite(uc[0],sf_n(acz)*sf_n(acx),Fwfl); } if( it%jdata==0) sf_floatwrite(dd,nr,Fdat); } if(verb) fprintf(stderr,"\n"); /*------------------------------------------------------------*/ /* deallocate arrays */ free(*um); free(um); free(*up); free(up); free(*uo); free(uo); free(*ua); free(ua); free(*uc); free(uc); free(*mag); free(mag); free(*ele); free(ele); free(*cdt); free(cdt); free(*vel); free(vel); free(*cdtele); free(cdtele); free(*magele); free(magele); /*------------------------------------------------------------*/ free(ww); free(ss); free(rr); free(dd); /*------------------------------------------------------------*/ sf_close(); exit (0); }
int main (int argc, char* argv[]) { bool verb, fsrf, snap, expl, dabc; int jsnap, ntsnap, jdata; /* I/O files */ sf_file Fwav = NULL; /* wavelet */ sf_file Fsou = NULL; /* sources */ sf_file Frec = NULL; /* receivers */ sf_file Fvel = NULL; /* velocity */ sf_file Fden = NULL; /* density */ sf_file Fdat = NULL; /* data */ sf_file Fwfl = NULL; /* wavefield */ /* cube axes */ sf_axis at, az, ax; sf_axis as, ar; int cpuid; int nt, nz, nx, ns, nr; int it, ia; float dt, dz, dx; /* FDM structure */ /* Wee keep these structures for compatibility, as soon as PETSC version is finished, this will be removed */ fdm2d fdm = NULL; /* I/O arrays */ float *ww = NULL; /* wavelet */ pt2d *ss = NULL; /* sources */ pt2d *rr = NULL; /* receivers */ float *dd = NULL; /* data */ float **u,**v; /* linear interpolation weights/indices */ lint2d cs,cr; /* wavefield cut params */ sf_axis acz = NULL, acx = NULL; int nqz, nqx; float oqz, oqx; float dqz, dqx; float **uc = NULL; sf_petsc_aimplfd2 aimplfd; PetscErrorCode ierr; /* PETSc Initialization */ ierr = PetscInitialize (&argc, &argv, 0, 0); CHKERRQ(ierr); MPI_Comm_rank (MPI_COMM_WORLD, &cpuid); /*------------------------------------------------------------*/ /* init RSF */ sf_init (argc, argv); /*------------------------------------------------------------*/ if (!sf_getbool ("verb", &verb)) verb = false; /* verbosity flag */ if (!sf_getbool ("snap", &snap)) snap = false; /* wavefield snapshots flag */ if (!sf_getbool ("free", &fsrf)) fsrf = false; /* free surface flag */ if (!sf_getbool ("expl", &expl)) expl = false; /* "exploding reflector" */ if (!sf_getbool ("dabc", &dabc)) dabc = false; /* absorbing BC */ /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* I/O files */ Fwav = sf_input ("in" ); /* wavelet */ Fvel = sf_input ("vel"); /* velocity */ Fsou = sf_input ("sou"); /* sources */ Frec = sf_input ("rec"); /* receivers */ Fwfl = sf_output("wfl"); /* wavefield */ Fdat = sf_output("out"); /* data */ Fden = sf_input ("den"); /* density */ /*------------------------------------------------------------*/ /* axes */ at = sf_iaxa (Fwav,2); sf_setlabel (at,"t"); if (verb && 0 == cpuid) sf_raxa (at); /* time */ az = sf_iaxa (Fvel,1); sf_setlabel (az,"z"); if (verb && 0 == cpuid) sf_raxa (az); /* depth */ ax = sf_iaxa (Fvel,2); sf_setlabel (ax,"x"); if (verb && 0 == cpuid) sf_raxa (ax); /* space */ as = sf_iaxa (Fsou, 2); sf_setlabel (as, "s"); if (verb && 0 == cpuid) sf_raxa (as); /* sources */ ar = sf_iaxa (Frec, 2); sf_setlabel (ar, "r"); if (verb && 0 == cpuid) sf_raxa (ar); /* receivers */ nt = sf_n (at); dt = sf_d (at); nz = sf_n (az); dz = sf_d (az); nx = sf_n (ax); dx = sf_d (ax); ns = sf_n (as); nr = sf_n (ar); /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* other execution parameters */ if (!sf_getint ("jdata", &jdata)) jdata = 1; if (snap) { /* save wavefield every *jsnap* time steps */ if (!sf_getint ("jsnap", &jsnap)) jsnap = nt; } /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* expand domain for FD operators and ABC */ /*if (!sf_getint("nb",&nb) || nb<NOP) nb=NOP;*/ fdm = fdutil_init (verb, true, az, ax, 0, 1); /*------------------------------------------------------------*/ if (0 == cpuid) { 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); /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* setup output data header */ sf_oaxa (Fdat, ar, 1); sf_setn (at, nt/jdata); sf_setd (at, dt*jdata); sf_oaxa (Fdat, at, 2); } /* setup output wavefield header */ if (snap && 0 == cpuid) { if (!sf_getint ("nqz", &nqz)) nqz = sf_n (az); if (!sf_getint ("nqx", &nqx)) nqx = sf_n (ax); if (!sf_getfloat ("oqz", &oqz)) oqz = sf_o (az); if (!sf_getfloat ("oqx", &oqx)) oqx = sf_o (ax); dqz = sf_d (az); dqx = sf_d (ax); acz = sf_maxa (nqz, oqz, dqz); sf_raxa (acz); acx = sf_maxa (nqx, oqx, dqx); sf_raxa (acx); /* check if the imaging window fits in the wavefield domain */ uc = sf_floatalloc2 (sf_n (acz), sf_n (acx)); ntsnap = 0; for (it = 0; it < nt; it++) { if (it % jsnap == 0) ntsnap++; } sf_setn (at, ntsnap); sf_setd (at, dt*jsnap); if (verb) sf_raxa(at); sf_oaxa (Fwfl, acz, 1); sf_oaxa (Fwfl, acx, 2); sf_oaxa (Fwfl, at, 3); } if (expl) { ww = sf_floatalloc (1); } else { ww = sf_floatalloc (ns); } dd = sf_floatalloc (nr); /*------------------------------------------------------------*/ /* setup source/receiver coordinates */ ss = (pt2d*) sf_alloc (ns, sizeof (*ss)); rr = (pt2d*) sf_alloc (nr, sizeof (*rr)); pt2dread1 (Fsou, ss, ns, 2); /* read (x,z) coordinates */ pt2dread1 (Frec, rr, nr, 2); /* read (x,z) coordinates */ cs = lint2d_make (ns, ss, fdm); cr = lint2d_make (nr, rr, fdm); v = sf_floatalloc2 (nz, nx); u = sf_floatalloc2 (nz, nx); /* input velocity */ sf_floatread (v[0], nz*nx, Fvel); /*------------------------------------------------------------*/ PetscFPrintf (MPI_COMM_WORLD, stderr, "Initializing GMRES solver\n"); aimplfd = sf_petsc_aimplfd2_init (nz, nx, dz, dx, dt, &v[0][0], 100, true); /*------------------------------------------------------------*/ /* * MAIN LOOP */ /*------------------------------------------------------------*/ for (it = 0; it < nt; it++) { PetscFPrintf (MPI_COMM_WORLD, stderr, "Timestep #%d, t=%f\n", it, it*dt); sf_petsc_aimplfd2_next_step (aimplfd); /* inject acceleration source */ if (expl) { sf_floatread (ww, 1, Fwav); for (ia = 0; ia < cs->n; ia++) { sf_petsc_aimplfd2_add_source_ut1 (aimplfd, ww[0], cs->jz[ia], cs->jx[ia]); } } else { sf_floatread (ww, ns, Fwav); for (ia = 0; ia < cs->n; ia++) { /* PetscFPrintf (MPI_COMM_WORLD, stderr, "Source #%d [%d, %d], f=%f\n", ia, cs->jz[ia], cs->jx[ia], ww[0]); */ sf_petsc_aimplfd2_add_source_ut1 (aimplfd, ww[ia], cs->jz[ia], cs->jx[ia]); } } sf_petsc_aimplfd2_get_wavefield_ut2 (aimplfd, &u[0][0]); /* extract data */ /* lint2d_extract (u, dd, cr); */ for (ia = 0; ia < cr->n; ia++) { dd[ia] = u[cr->jx[ia]][cr->jz[ia]]; } if (snap && it % jsnap == 0 && 0 == cpuid) { cut2d (u, uc, fdm, acz, acx); sf_floatwrite (uc[0], sf_n(acz)*sf_n(acx), Fwfl); } if (it % jdata == 0 && 0 == cpuid) sf_floatwrite (dd, nr, Fdat); } exit (0); }
int main(int argc, char* argv[]) { bool verb; /* verbosity flag */ bool abc; /* absorbing boundary conditions flag */ bool free; /* free surface flag*/ bool snap; /* wavefield snapshots flag */ int jsnap;/* save wavefield every *jsnap* time steps */ /* cube axes */ sf_axis at,az,ax,as,ar,bt; int it,iz,ix,is,ir, iop; int nt,nz,nx,ns,nr,nz2,nx2; float z0,x0,dt,dx,dz, idx,idz,dt2; /* Laplacian */ int nop=2; /* Laplacian operator size */ float c0, c1, c2; /* Laplacian operator coefficients */ float co,c1x,c2x,c1z,c2z; int nbz,nbx; /* boundary size */ float tz, tx; /* sponge boundary decay coefficients */ float dp; float ws; /* injected data */ /* linear interpolation */ float *fzs,*fxs, *fzr,*fxr; int *jzs,*jxs, *jzr,*jxr; float *ws00,*ws01,*ws10,*ws11; float *wr00,*wr01,*wr10,*wr11; /* boundary */ float *bzl,*bzh,*bxl,*bxh; /* I/O files */ sf_file Fw,Fs,Fr; float *ww; /* wavelet */ pt2d *ss, *rr; /* source/receiver locations */ float **tt; /* taper */ /* background */ sf_file Bv,Bd,Bu; /* velocity, data, wavefield */ float **bvv,**bvo; /* velocity */ float *bdd; /* data */ float **bum,**buo,**bup,**bud; /* wavefields */ /* perturbation */ sf_file Pv,Pd,Pu; float **pvv,**pvo; float *pdd; float **pum,**puo,**pup,**pud; int ompchunk; /* OpenMP data chunk size */ /*------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); if(! sf_getint("ompchunk",&ompchunk)) ompchunk=1; if(! sf_getbool("verb",&verb)) verb=false; if(! sf_getbool( "abc",&abc )) abc=false; if(! sf_getbool("snap",&snap)) snap=false; if(! sf_getbool("free",&free)) free=false; Fw = sf_input ("in" ); /* wavelet */ Fs = sf_input ("sou"); /* sources */ Fr = sf_input ("rec"); /* receivers */ Bv = sf_input ("vel"); /* velocity */ Bu = sf_output("wfl"); /* wavefield */ Bd = sf_output("out"); /* data */ Pv = sf_input ("ref"); /* velocity */ Pu = sf_output("liw"); /* linearized wavefield */ Pd = sf_output("lid"); /* linearized data */ /* read axes*/ at=sf_iaxa(Fw,1); sf_setlabel(at,"t"); nt=sf_n(at); dt=sf_d(at); if(verb) sf_raxa(at); /* time */ as=sf_iaxa(Fs,2); sf_setlabel(as,"s"); ns=sf_n(as); if(verb) sf_raxa(as); /* sources */ ar=sf_iaxa(Fr,2); sf_setlabel(ar,"r"); nr=sf_n(ar); if(verb) sf_raxa(ar); /* receivers */ az=sf_iaxa(Bv,1); sf_setlabel(az,"z"); nz=sf_n(az); dz=sf_d(az); if(verb) sf_raxa(az); /* depth */ ax=sf_iaxa(Bv,2); sf_setlabel(ax,"x"); nx=sf_n(ax); dx=sf_d(ax); if(verb) sf_raxa(ax); /* space */ /* configure wavefield snapshots */ if(snap) { if(! sf_getint("jsnap",&jsnap)) jsnap=nt; } /*------------------------------------------------------------*/ /* expand domain for absorbing boundary conditions */ if(abc) { if(! sf_getint("nbz",&nbz)) nbz=nop; if(nbz<nop) nbz=nop; if(! sf_getint("nbx",&nbx)) nbx=nop; if(nbx<nop) nbx=nop; if(! sf_getfloat("tz",&tz)) tz=0.025; if(! sf_getfloat("tx",&tx)) tx=0.025; } else { nbz=nop; nbx=nop; } /* expanded domain ( az+2 nz, ax+2 nx ) */ nz2=nz+2*nbz; z0=sf_o(az)-nbz*dz; nx2=nx+2*nbx; x0=sf_o(ax)-nbx*dx; sf_setn(az,nz2); sf_seto(az,z0); if(verb) sf_raxa(az); sf_setn(ax,nx2); sf_seto(ax,x0); if(verb) sf_raxa(ax); /*------------------------------------------------------------*/ /* setup output wavefield header */ if(snap) { bt = sf_maxa(nt/jsnap,sf_o(at),dt*jsnap); sf_setlabel(bt,"t"); sf_oaxa(Bu,az,1); sf_oaxa(Bu,ax,2); sf_oaxa(Bu,bt,3); sf_oaxa(Pu,az,1); sf_oaxa(Pu,ax,2); sf_oaxa(Pu,bt,3); } /* setup output data header */ sf_oaxa(Bd,ar,1); sf_oaxa(Bd,at,2); sf_oaxa(Pd,ar,1); sf_oaxa(Pd,at,2); dt2 = dt*dt; idz = 1/(dz*dz); idx = 1/(dx*dx); /* Laplacian coefficients */ c0=-30./12.; c1=+16./12.; c2=- 1./12.; co = c0 * (idx+idz); c1x= c1 * idx; c2x= c2 * idx; c1z= c1 * idz; c2z= c2 * idz; /*------------------------------------------------------------*/ /* allocate arrays */ ww=sf_floatalloc (nt); sf_floatread(ww ,nt ,Fw); bvv=sf_floatalloc2(nz,nx); sf_floatread(bvv[0],nz*nx,Bv); pvv=sf_floatalloc2(nz,nx); sf_floatread(pvv[0],nz*nx,Pv); /* allocate source/receiver point arrays */ ss = (pt2d*) sf_alloc(ns,sizeof(*ss)); rr = (pt2d*) sf_alloc(nr,sizeof(*rr)); pt2dread1(Fs,ss,ns,3); /* read 3 elements (x,z,v) */ pt2dread1(Fr,rr,nr,2); /* read 2 elements (x,z) */ bdd=sf_floatalloc(nr); pdd=sf_floatalloc(nr); jzs=sf_intalloc(ns); fzs=sf_floatalloc(ns); jzr=sf_intalloc(nr); fzr=sf_floatalloc(nr); jxs=sf_intalloc(ns); fxs=sf_floatalloc(ns); jxr=sf_intalloc(nr); fxr=sf_floatalloc(nr); ws00 = sf_floatalloc(ns); wr00 = sf_floatalloc(nr); ws01 = sf_floatalloc(ns); wr01 = sf_floatalloc(nr); ws10 = sf_floatalloc(ns); wr10 = sf_floatalloc(nr); ws11 = sf_floatalloc(ns); wr11 = sf_floatalloc(nr); /*------------------------------------------------------------*/ for (is=0;is<ns;is++) { if(ss[is].z >= z0 && ss[is].z < z0 + (nz2-1)*dz && ss[is].x >= x0 && ss[is].x < x0 + (nx2-1)*dx) { jzs[is] = (int)( (ss[is].z-z0)/dz); fzs[is] = (ss[is].z-z0)/dz - jzs[is]; jxs[is] = (int)( (ss[is].x-x0)/dx); fxs[is] = (ss[is].x-x0)/dx - jxs[is]; } else { jzs[is] = 0; jxs[is] = 0; fzs[is] = 1; fxs[is] = 0; ss[is].v= 0; } ws00[is] = (1-fzs[is])*(1-fxs[is]); ws01[is] = ( fzs[is])*(1-fxs[is]); ws10[is] = (1-fzs[is])*( fxs[is]); ws11[is] = ( fzs[is])*( fxs[is]); } for (ir=0;ir<nr;ir++) { if(rr[ir].z >= z0 && rr[ir].z < z0 + (nz2-1)*dz && rr[ir].x >= x0 && rr[ir].x < x0 + (nx2-1)*dx) { jzr[ir] = (int)( (rr[ir].z-z0)/dz); fzr[ir] = (rr[ir].z-z0)/dz - jzr[ir]; jxr[ir] = (int)( (rr[ir].x-x0)/dx); fxr[ir] = (rr[ir].x-x0)/dx - jxr[ir]; rr[ir].v=1; } else { jzr[ir] = 0; fzr[ir] = 1; rr[ir].v= 0; } wr00[ir] = (1-fzr[ir])*(1-fxr[ir]); wr01[ir] = ( fzr[ir])*(1-fxr[ir]); wr10[ir] = (1-fzr[ir])*( fxr[ir]); wr11[ir] = ( fzr[ir])*( fxr[ir]); } /*------------------------------------------------------------*/ /* allocate temporary arrays */ bum=sf_floatalloc2(nz2,nx2); buo=sf_floatalloc2(nz2,nx2); bup=sf_floatalloc2(nz2,nx2); bud=sf_floatalloc2(nz2,nx2); pum=sf_floatalloc2(nz2,nx2); puo=sf_floatalloc2(nz2,nx2); pup=sf_floatalloc2(nz2,nx2); pud=sf_floatalloc2(nz2,nx2); tt=sf_floatalloc2(nz2,nx2); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(iz,ix) shared(nx2,nz2,bum,buo,bup,bud,pum,puo,pup,pud,tt) #endif for (iz=0; iz<nz2; iz++) { for (ix=0; ix<nx2; ix++) { bum[ix][iz]=pum[ix][iz]=0; buo[ix][iz]=puo[ix][iz]=0; bup[ix][iz]=pup[ix][iz]=0; bud[ix][iz]=pud[ix][iz]=0; tt[ix][iz]=1; } } /*------------------------------------------------------------*/ /* velocity in the expanded domain (vo=vv^2)*/ bvo=sf_floatalloc2(nz2,nx2); pvo=sf_floatalloc2(nz2,nx2); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(iz,ix) shared(nz,nx,bvv,pvv,bvo,pvo) #endif for (iz=0; iz<nz; iz++) { for (ix=0; ix<nx; ix++) { bvo[nbx+ix][nbz+iz] = bvv[ix][iz] * bvv[ix][iz]; pvo[nbx+ix][nbz+iz] = pvv[ix][iz]; } } /* fill boundaries */ for (iz=0; iz<nbz; iz++) { for (ix=0; ix<nx2; ix++) { bvo[ix][ iz ] = bvo[ix][ nbz ]; bvo[ix][nz2-iz-1] = bvo[ix][nz2-nbz-1]; pvo[ix][ iz ] = pvo[ix][ nbz ]; pvo[ix][nz2-iz-1] = pvo[ix][nz2-nbz-1]; } } for (iz=0; iz<nz2; iz++) { for (ix=0; ix<nbx; ix++) { bvo[ ix ][iz] = bvo[ nbx ][iz]; bvo[nx2-ix-1][iz] = bvo[nx2-nbx-1][iz]; pvo[ ix ][iz] = pvo[ nbx ][iz]; pvo[nx2-ix-1][iz] = pvo[nx2-nbx-1][iz]; } } /*------------------------------------------------------------*/ /* free surface */ if(abc && free) { for (iz=0; iz<nbz; iz++) { for (ix=0; ix<nx2; ix++) { bvo[ix][iz]=0; pvo[ix][iz]=0; } } } /*------------------------------------------------------------*/ /* sponge ABC setup */ if(abc) { for (iz=0; iz<nbz; iz++) { for (ix=0; ix<nx2; ix++) { tt[ix][ iz ] = exp( - (tz*(nbz-iz))*(tz*(nbz-iz)) ); tt[ix][nz2-iz-1] = tt[ix][iz]; } } for (iz=0; iz<nz2; iz++) { for (ix=0; ix<nbx; ix++) { tt[ ix ][iz] = exp( - (tx*(nbx-ix))*(tx*(nbx-ix)) ); tt[nx2-ix-1][iz] = tt[ix][iz]; } } } /* one-way ABC setup */ bzl=sf_floatalloc(nx2); bzh=sf_floatalloc(nx2); bxl=sf_floatalloc(nz2); bxh=sf_floatalloc(nz2); for (ix=0;ix<nx2;ix++) { dp = bvo[ix][ nop ] *dt/dz; bzl[ix] = (1-dp)/(1+dp); dp = bvo[ix][nz2-nop-1] *dt/dz; bzh[ix] = (1-dp)/(1+dp); } for (iz=0;iz<nz2;iz++) { dp = bvo[ nop ][iz] *dt/dx; bxl[iz] = (1-dp)/(1+dp); dp = bvo[nx2-nop-1][iz] *dt/dx; bxh[iz] = (1-dp)/(1+dp); } /*------------------------------------------------------------*/ /* * MAIN LOOP */ if(verb) fprintf(stderr,"\n"); for (it=0; it<nt; it++) { if(verb) fprintf(stderr,"\b\b\b\b\b%d",it); /* 4th order Laplacian operator */ #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(iz,ix) shared(nop,nx2,nz2,bud,buo,pud,puo,co,c1x,c1z,c2x,c2z,idx,idz) #endif for (ix=nop; ix<nx2-nop; ix++) { for (iz=nop; iz<nz2-nop; iz++) { bud[ix][iz] = co * buo[ix ][iz ] + c1x*(buo[ix-1][iz ] + buo[ix+1][iz ]) + c2x*(buo[ix-2][iz ] + buo[ix+2][iz ]) + c1z*(buo[ix ][iz-1] + buo[ix ][iz+1]) + c2z*(buo[ix ][iz-2] + buo[ix ][iz+2]); pud[ix][iz] = co * puo[ix ][iz ] + c1x*(puo[ix-1][iz ] + puo[ix+1][iz ]) + c2x*(puo[ix-2][iz ] + puo[ix+2][iz ]) + c1z*(puo[ix ][iz-1] + puo[ix ][iz+1]) + c2z*(puo[ix ][iz-2] + puo[ix ][iz+2]); } } /* inject source */ for (is=0;is<ns;is++) { ws = ww[it] * ss[is].v; bud[ jxs[is] ][ jzs[is] ] -= ws * ws00[is]; bud[ jxs[is] ][ jzs[is]+1] -= ws * ws01[is]; bud[ jxs[is]+1][ jzs[is] ] -= ws * ws10[is]; bud[ jxs[is]+1][ jzs[is]+1] -= ws * ws11[is]; } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(ix,iz) shared(nx2,nz2,pud,bud,pvo) #endif for (ix=0; ix<nx2; ix++) { for (iz=0; iz<nz2; iz++) { pud[ix][iz] -= bud[ix][iz] * 2*pvo[ix][iz]; } } /* velocity scale */ #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(ix,iz) shared(nx2,nz2,bud,pud,bvo) #endif for (ix=0; ix<nx2; ix++) { for (iz=0; iz<nz2; iz++) { bud[ix][iz] *= bvo[ix][iz]; pud[ix][iz] *= bvo[ix][iz]; } } /* time step */ #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(ix,iz) shared(nx2,nz2,bud,buo,bum,bup,pud,puo,pum,pup,dt2) #endif for (ix=0; ix<nx2; ix++) { for (iz=0; iz<nz2; iz++) { bup[ix][iz] = 2*buo[ix][iz] - bum[ix][iz] + bud[ix][iz] * dt2; bum[ix][iz] = buo[ix][iz]; buo[ix][iz] = bup[ix][iz]; pup[ix][iz] = 2*puo[ix][iz] - pum[ix][iz] + pud[ix][iz] * dt2; pum[ix][iz] = puo[ix][iz]; puo[ix][iz] = pup[ix][iz]; } } /* one-way ABC apply */ if(abc) { #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(ix,iz,iop) shared(nx2,nz2,nop,buo,bum,puo,pum,bzl,bzh) #endif for(ix=0;ix<nx2;ix++) { for(iop=0;iop<nop;iop++) { iz = nop-iop; buo [ix][iz ] = bum[ix][iz+1] +(bum[ix][iz ] - buo[ix][iz+1]) * bzl[ix]; puo [ix][iz ] = pum[ix][iz+1] +(pum[ix][iz ] - puo[ix][iz+1]) * bzl[ix]; iz = nz2-nop+iop-1; buo [ix][iz ] = bum[ix][iz-1] +(bum[ix][iz ] - buo[ix][iz-1]) * bzh[ix]; puo [ix][iz ] = pum[ix][iz-1] +(pum[ix][iz ] - puo[ix][iz-1]) * bzh[ix]; } } #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,1) private(ix,iz,iop) shared(nx2,nz2,nop,buo,bum,puo,pum,bzl,bzh) #endif for(iop=0;iop<nop;iop++) { for(iz=0;iz<nz2;iz++) { ix = nop-iop; buo [ix ][iz] = bum[ix+1][iz] +(bum[ix ][iz] - buo[ix+1][iz]) * bxl[iz]; puo [ix ][iz] = pum[ix+1][iz] +(pum[ix ][iz] - puo[ix+1][iz]) * bxl[iz]; ix = nx2-nop+iop-1; buo [ix ][iz] = bum[ix-1][iz] +(bum[ix ][iz] - buo[ix-1][iz]) * bxh[iz]; puo [ix ][iz] = pum[ix-1][iz] +(pum[ix ][iz] - puo[ix-1][iz]) * bxh[iz]; } } } /* sponge ABC apply */ if(abc) { #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,ompchunk) private(ix,iz) shared(nx2,nz2,buo,bum,bud,puo,pum,pud,tt) #endif for (ix=0; ix<nx2; ix++) { for (iz=0; iz<nz2; iz++) { buo[ix][iz] *= tt[ix][iz]; bum[ix][iz] *= tt[ix][iz]; bud[ix][iz] *= tt[ix][iz]; puo[ix][iz] *= tt[ix][iz]; pum[ix][iz] *= tt[ix][iz]; bud[ix][iz] *= tt[ix][iz]; } } } /* write wavefield */ if(snap && it%jsnap==0) { sf_floatwrite(buo[0],nz2*nx2,Bu); sf_floatwrite(puo[0],nz2*nx2,Pu); } /* write data */ #ifdef _OPENMP #pragma omp parallel for schedule(dynamic,1) private(ir) shared(bdd,pdd,rr,buo,puo,jzr,wr00,wr01,wr10,wr11) #endif for (ir=0;ir<nr;ir++) { bdd[ir] = buo[ jxr[ir] ][ jzr[ir] ] * wr00[ir] + buo[ jxr[ir] ][ jzr[ir]+1] * wr01[ir] + buo[ jxr[ir]+1][ jzr[ir] ] * wr10[ir] + buo[ jxr[ir]+1][ jzr[ir]+1] * wr11[ir]; bdd[ir] *= rr[ir].v; pdd[ir] = puo[ jxr[ir] ][ jzr[ir] ] * wr00[ir] + puo[ jxr[ir] ][ jzr[ir]+1] * wr01[ir] + puo[ jxr[ir]+1][ jzr[ir] ] * wr10[ir] + puo[ jxr[ir]+1][ jzr[ir]+1] * wr11[ir]; pdd[ir] *= rr[ir].v; } /* write data */ sf_floatwrite(bdd,nr,Bd); sf_floatwrite(pdd,nr,Pd); } if(verb) fprintf(stderr,"\n"); exit (0); }
int main (int argc, char *argv[]) { bool verb; bool rays; sf_axis az,ax; /* Cartesian coordinates */ sf_axis at,ag; /* Ray coordinates */ int it,ig; int nz,nx,nt,ng; float dt,dg,ot,og; float xsou,zsou; /* source coordinates */ sf_file Fv=NULL; /* velocity file */ sf_file Fw=NULL; /* wavefronfs file */ float **vv=NULL; /* velocity */ pt2d *wm=NULL; /* wavefront it-1 */ pt2d *wo=NULL; /* wavefront it */ pt2d *wp=NULL; /* wavefront it+1 */ pt2d Ro; /* point on wft it-1 */ pt2d Pm,Po,Pp; /* points on wft it */ pt2d Qo; /* point on wft it+1 */ /*------------------------------------------------------------*/ sf_init(argc,argv); if(! sf_getbool("verb",&verb)) verb=false; if(! sf_getbool("rays",&rays)) rays=false; /* velocity file */ Fv = sf_input ("in"); az = sf_iaxa(Fv,1); sf_setlabel(az,"z"); nz=sf_n(az); if(verb) sf_raxa(az); ax = sf_iaxa(Fv,2); sf_setlabel(ax,"x"); nx=sf_n(ax); if(verb) sf_raxa(ax); vv=sf_floatalloc2(nz,nx); sf_floatread(vv[0],nz*nx,Fv); /* source location */ if(! sf_getfloat("xsou",&xsou)) xsou=sf_o(ax) + nx*sf_d(ax)/2; if(! sf_getfloat("zsou",&zsou)) zsou=sf_o(az) + nz*sf_d(az)/2; if(verb) fprintf(stderr,"xsou=%f zsou=%f\n",xsou,zsou); /* time axis */ if(! sf_getint ("nt",&nt)) nt=100; if(! sf_getfloat("ot",&ot)) ot=0; if(! sf_getfloat("dt",&dt)) dt=0.001; at = sf_maxa(nt,ot,dt); sf_setlabel(at,"t"); /* shooting angle axis */ if(! sf_getint ("ng",&ng)) ng= 360; if(! sf_getfloat("og",&og)) og=-180; if(! sf_getfloat("dg",&dg)) dg= 1; ag = sf_maxa(ng,og,dg); sf_setlabel(ag,"g"); /*------------------------------------------------------------*/ /* wavefronts file (g,t) */ Fw = sf_output("out"); sf_oaxa(Fw,ag,1); if(verb) sf_raxa(ag); sf_oaxa(Fw,at,2); if(verb) sf_raxa(at); /* set the output to complex */ sf_putint(Fw,"esize",8); sf_settype(Fw,SF_COMPLEX); /*------------------------------------------------------------*/ /* allocate wavefronts */ wm = pt2dalloc1(ng); wo = pt2dalloc1(ng); wp = pt2dalloc1(ng); /* initialize wavefronts */ for( ig=0; ig<ng; ig++) { wm[ig].x=wo[ig].x=wp[ig].x=0; wm[ig].z=wo[ig].z=wp[ig].z=0; wm[ig].v=wo[ig].v=wp[ig].v=0; } /*------------------------------------------------------------*/ /* init HWT */ hwt2d_init(vv,az,ax,at,ag); /*------------------------------------------------------------*/ /* construct it=0 wavefront */ it=0; for( ig=0; ig<ng; ig++) { wm[ig].x=xsou; wm[ig].z=zsou; wm[ig].v=hwt2d_getv(wm[ig]); } pt2dwrite1(Fw,wm,ng,2); /* write wavefront it=0 */ /*------------------------------------------------------------*/ /* construct it=1 wavefront */ it=1; for( ig=0; ig<ng; ig++) { double d,g; d = dt * hwt2d_getv(wm[ig]); g = (og+ig*dg) * SF_PI/180; wo[ig].x=xsou + d*sin(g); wo[ig].z=zsou + d*cos(g); wo[ig].v=hwt2d_getv(wo[ig]); } pt2dwrite1(Fw,wo,ng,2); /* write wavefront it=1 */ /*------------------------------------------------------------*/ /* LOOP over time */ for (it=2; it<nt; it++) { if(verb) fprintf(stderr,"it=%d\n",it); if(ng>3 && !rays) { /* boundaries */ ig=0; wp[ig] = hwt2d_raytr(wm[ig],wo[ig]); ig=ng-1; wp[ig] = hwt2d_raytr(wm[ig],wo[ig]); for (ig=1; ig<ng-1; ig++) { Pm = wo[ig-1]; Po = wo[ig ]; Qo = wm[ig]; Pp = wo[ig+1]; if(hwt2d_cusp(Qo,Pm,Po,Pp)) { Ro = hwt2d_raytr(Qo, Po ); } else { Ro = hwt2d_wfttr(Qo,Pm,Po,Pp); } wp[ig] = Ro; } } else { for (ig=0; ig<ng; ig++) { Po = wo[ig]; Qo = wm[ig]; Ro = hwt2d_raytr(Qo,Po); wp[ig] = Ro; } } /* write wavefront it */ pt2dwrite1(Fw,wp,ng,2); /* step in time */ for( ig=0; ig<ng; ig++) { wm[ig] = wo[ig]; wo[ig] = wp[ig]; } } /* end it */ /*------------------------------------------------------------*/ exit (0); }
int main(int argc, char* argv[]) { bool verb,isreversed; sf_file Fs,Fr,Fi; /* I/O files */ sf_axis az,ax,at,aa; /* cube axes */ int iz,ix,it; int nz,nx,nt; off_t iseek; float **us=NULL,**ur=NULL,**ii=NULL; float scale; /*------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); /* OMP parameters */ #ifdef _OPENMP omp_init(); #endif if(! sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ if(! sf_getbool("isreversed",&isreversed)) isreversed=false; /* received wavefield */ Fs = sf_input ("in" ); Fr = sf_input ("ur" ); Fi = sf_output("out"); /*------------------------------------------------------------*/ /* read axes */ az=sf_iaxa(Fs,1); nz = sf_n(az); ax=sf_iaxa(Fs,2); nx = sf_n(ax); at=sf_iaxa(Fs,3); nt = sf_n(at); aa=sf_maxa(1,0,1); sf_setlabel(aa,""); sf_setunit (aa,""); if(verb) { sf_raxa(az); sf_raxa(ax); sf_raxa(at); } /* write axes */ sf_oaxa(Fi,az,1); sf_oaxa(Fi,ax,2); sf_oaxa(Fi,aa,3); /*------------------------------------------------------------*/ /* allocate work arrays */ ii = sf_floatalloc2(nz,nx); us = sf_floatalloc2(nz,nx); ur = sf_floatalloc2(nz,nx); for (ix=0; ix<nx; ix++) { for(iz=0; iz<nz; iz++) { ii[ix][iz]=0.; } } /*------------------------------------------------------------*/ if(isreversed) { /* receiver wavefield is reversed */ if(verb) fprintf(stderr,"nt\n"); for (it=0; it<nt; it++) { if(verb) fprintf(stderr,"\b\b\b\b\b\b\b\b\b\b%04d",it); sf_floatread(us[0],nz*nx,Fs); sf_floatread(ur[0],nz*nx,Fr); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) \ private(ix,iz) \ shared (ii,us,ur,nx,nz) #endif for (ix=0; ix<nx; ix++) { for(iz=0; iz<nz; iz++) { ii[ix][iz] += us[ix][iz]*ur[ix][iz]; } } } /* it */ if(verb) fprintf(stderr,"\n"); } else { /* receiver wavefield is NOT reversed */ if(verb) fprintf(stderr,"nt\n"); for (it=0; it<nt; it++) { if(verb) fprintf(stderr,"\b\b\b\b\b%d",(nt-it-1)); sf_floatread(us[0],nz*nx,Fs); iseek=(off_t)(nt-1-it)*nz*nx*sizeof(float); sf_seek(Fr,iseek,SEEK_SET); sf_floatread(ur[0],nz*nx,Fr); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) \ private(ix,iz) \ shared (ii,us,ur,nx,nz) #endif for (ix=0; ix<nx; ix++) { for(iz=0; iz<nz; iz++) { ii[ix][iz] += us[ix][iz]*ur[ix][iz]; } } } /* it */ if(verb) fprintf(stderr,"\n"); } /* end "is reversed" */ /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* scale image */ scale = 1./nt; for (ix=0; ix<nx; ix++) { for(iz=0; iz<nz; iz++) { ii[ix][iz] *=scale; } } /*------------------------------------------------------------*/ /* write image */ sf_floatwrite(ii[0],nx*nz,Fi); /*------------------------------------------------------------*/ /* deallocate arrays */ free(*ii); free(ii); free(*us); free(us); free(*ur); free(ur); /*------------------------------------------------------------*/ exit (0); }
int main(int argc, char* argv[]) { sf_file Fi=NULL, Fo=NULL, Fr=NULL; /* I/O files */ bool adj, verb, linear; sf_axis ax,az,at,ag; int ix,iz,it,ig; int nx,nz,nt,ng; float dx,dz,x0,z0; float **mapCC=NULL, **mapRC=NULL; float ***comCC=NULL, ***comRC=NULL; sf_complex **rays=NULL; int nn,ii; bool comp; /* complex input */ /* init RSF */ sf_init(argc,argv); Fi = sf_input ( "in"); Fr = sf_input ("rays"); Fo = sf_output( "out"); if(! sf_getbool( "verb",&verb )) verb=false; if(! sf_getbool( "adj",&adj )) adj=false; if(! sf_getbool("linear",&linear )) linear=true; ag=sf_iaxa(Fr,1); ng=sf_n(ag); if(verb) sf_raxa(ag); at=sf_iaxa(Fr,2); nt=sf_n(at); if(verb) sf_raxa(at); if(adj) { if(! sf_getint ("a2n",&nz)) nz=1; if(! sf_getfloat("a2o",&z0)) z0=0.; if(! sf_getfloat("a2d",&dz)) dz=1.; az = sf_maxa(nz,z0,dz); sf_setlabel(az,"a2"); if(verb) sf_raxa(az); if(! sf_getint ("a1n",&nx)) nx=1; if(! sf_getfloat("a1o",&x0)) x0=0.; if(! sf_getfloat("a1d",&dx)) dx=1.; ax = sf_maxa(nx,x0,dx); sf_setlabel(ax,"a1"); if(verb) sf_raxa(ax); sf_oaxa(Fo,ax,1); sf_oaxa(Fo,az,2); } else { ax = sf_iaxa(Fi,1); nx=sf_n(ax); if(verb) sf_raxa(ax); az = sf_iaxa(Fi,2); nz=sf_n(az); if(verb) sf_raxa(az); sf_oaxa(Fo,ag,1); sf_oaxa(Fo,at,2); } nn = sf_leftsize(Fi,2); rays =sf_complexalloc2(ng,nt); sf_complexread(rays[0],ng*nt,Fr); c2r_init(ax,az,ag,at,verb); /*------------------------------------------------------------*/ comp=false; if(SF_COMPLEX == sf_gettype(Fi)) comp=true; /*------------------------------------------------------------*/ mapCC=sf_floatalloc2(nx,nz); mapRC=sf_floatalloc2(ng,nt); if(comp) { comCC=sf_floatalloc3(2,nx,nz); comRC=sf_floatalloc3(2,ng,nt); for(ii=0;ii<nn;ii++) { sf_warning("%d of %d;",ii,nn); if(adj) { sf_floatread (comRC[0][0],2*ng*nt,Fi); /* REAL */ LOOPRC( mapRC[it][ig] = comRC[it][ig][0]; ); c2r(linear,adj,mapCC,mapRC,rays); LOOPCC( comCC[iz][ix][0] = mapCC[iz][ix]; ); /* IMAGINARY */ LOOPRC( mapRC[it][ig] = comRC[it][ig][1]; ); c2r(linear,adj,mapCC,mapRC,rays); LOOPCC( comCC[iz][ix][1] = mapCC[iz][ix]; );