int main (int argc, char* argv[]) { int dim, i, j, n[SF_MAX_DIM], w[SF_MAX_DIM], k[SF_MAX_DIM], np, nw, n12; float *data, *wind; char *temp; FILE *tmp; sf_file in, out; sf_init (argc, argv); in = sf_input("in"); out = sf_output("out"); dim = sf_filedims(in,n); if (!sf_getints("w",w,dim)) sf_error("Need w="); if (!sf_getints("k",k,dim)) sf_error("Need k="); n12 = 1; np = 1; nw = 1; for(j=0; j < dim; j++) { n12 *= n[j]; np *= k[j]; nw *= w[j]; } nw *= np; data = sf_floatalloc (n12); wind = sf_floatalloc (nw); sf_floatread(data,n12,in); tmp = sf_tempfile(&temp,"w+b"); ocparcel_init (dim, k, n, w); if (n12 != fwrite(data,sizeof(float),n12,tmp)) sf_error("writing error:"); ocparcel_lop (false, n12, nw, tmp, wind); oc_zero(n12*sizeof(float),tmp); ocparcel_lop ( true, n12, nw, tmp, wind); rewind(tmp); if (n12 != fread(data,sizeof(float),n12,tmp)) sf_error("reading error"); for (i=0; i < n12; i++) { sf_line2cart(dim, n, i, k); if (k[0] <= 1 || k[0] >= n[0] - 2) data[i] = 0.; } sf_floatwrite (data,n12,out); unlink(temp); exit (0); }
void vp_plot_init(int n2) { int i, len; dashtype = sf_floatalloc(n2); if (!sf_getfloats ("dash",dashtype,n2)) { /* line dash type 0 continuos (default) 1 fine dash 2 fine dot 3 dash 4 large dash 5 dot dash 6 large dash small dash 7 double dot 8 double dash 9 loose dash The part after the decimal point determines the pattern repetition interval */ for (i = 0; i < n2; i++) dashtype[i] = 0.; } fat = sf_intalloc(n2); if (!sf_getints("plotfat",fat,n2)) { /* line fatness */ for (i = 0; i < n2; i++) fat[i] = 0; } col = sf_intalloc(n2); if (!sf_getints("plotcol",col,n2)) { /* line color 7 white 6 yellow (default) 5 cyan 4 green 3 magenta 2 red 1 blue 0 black */ for (i = 0; i < n2; i++) col[i] = 6 - (i % 6); } }
int main(int argc, char* argv[]) { int n[SF_MAX_DIM], a[SF_MAX_DIM], center[SF_MAX_DIM], gap[SF_MAX_DIM]; int *pch, *nh, dim, n123, nf, i, niter, nbf, nbp, id, ip, ig, np; int *kk, *pp; float *dd, eps, dabs, di; nfilter aa, bb; char varname[6], *lagfile; sf_file in, flt, lag, mask, patch, reg; sf_init(argc,argv); in = sf_input("in"); flt = sf_output("out"); dim = sf_filedims(in,n); if (NULL == (lagfile = sf_getstring("lag"))) sf_error("Need lag="); /* output file for filter lags */ lag = sf_output(lagfile); sf_settype(lag,SF_INT); sf_putstring(flt,"lag",lagfile); sf_putints(lag,"n",n,dim); if (!sf_getints("a",a,dim)) sf_error("Need a="); if (!sf_getints("center",center,dim)) { for (i=0; i < dim; i++) { center[i] = (i+1 < dim && a[i+1] > 1)? a[i]/2: 0; } } if (!sf_getints("gap",gap,dim)) { for (i=0; i < dim; i++) { gap[i] = 0; } } n123 = 1; for (i=0; i < dim; i++) { n123 *= n[i]; } dd = sf_floatalloc(n123); kk = sf_intalloc(n123); if (NULL != sf_getstring("maskin")) { /* optional input mask file */ mask = sf_input("maskin"); switch (sf_gettype(mask)) { case SF_INT: sf_intread (kk,n123,mask); break; case SF_FLOAT: sf_floatread (dd,n123,mask); for (i=0; i < n123; i++) { kk[i] = (dd[i] != 0.); } break; default: sf_error ("Wrong data type in maskin"); break; } sf_fileclose (mask); } else { for (i=0; i < n123; i++) { kk[i] = 1; } } sf_floatread(dd,n123,in); dabs = fabsf(dd[0]); for (i=1; i < n123; i++) { di = fabsf(dd[i]); if (di > dabs) dabs=di; } random_init(2004); for (i=0; i < n123; i++) { dd[i] = dd[i]/dabs+ 100.*FLT_EPSILON*(random0()-0.5);; } pp = sf_intalloc(n123); if (NULL != sf_getstring("pch")) { patch = sf_input("pch"); if (SF_INT != sf_gettype(patch)) sf_error("Need int pch"); sf_intread(pp,n123,patch); np = pp[0]; for (i=1; i < n123; i++) { if (pp[i] > np) np = pp[i]; } sf_fileclose(patch); } else { np = n123; for (i=0; i < n123; i++) { pp[i] = i; } } aa = createnhelix(dim, n, center, gap, a, pp); free (pp); nf = aa->hlx[0]->nh; nfind_mask(n123, kk, aa); if(!sf_getint("niter",&niter)) niter=100; /* number of iterations */ if (!sf_getfloat("epsilon",&eps)) eps=0.01; /* regularization parameter */ sf_putint(flt,"n1",nf); sf_putint(flt,"n2",np); sf_putint(lag,"n1",nf); sf_putint(lag,"n2",np); for (i=2; i < dim; i++) { sprintf(varname,"n%d",i+1); sf_putint(flt,varname,1); sf_putint(lag,varname,1); } for (ip=0; ip < np; ip++) { sf_intwrite(aa->hlx[ip]->lag,nf,lag); } sf_fileclose(lag); if (NULL != sf_getstring("maskout")) { /* optional output mask file */ mask = sf_output("maskout"); for (i=0; i < n123; i++) { kk[i] = aa->mis[i]? 0.: 1.; } sf_settype(mask,SF_INT); sf_intwrite (kk,n123,mask); } reg = sf_input("filt"); if (!sf_histint(reg,"n1",&nbf)) sf_error("No n1= in filt"); if (!sf_histint(reg,"n2",&nbp)) sf_error("No n2= in filt"); if (NULL != sf_getstring("filt_pch")) { patch = sf_input("filt_pch"); if (SF_INT != sf_gettype(patch)) sf_error("Need int filt_pch"); pp = sf_intalloc(np); sf_intread(pp,np,patch); } else { if (nbp != np) sf_error ("Wrong filter size: %d != %d",nbp,np); pp = NULL; } pch = sf_intalloc(nf*np); nh = sf_intalloc(nbp); for (i=0; i < nbp; i++) { nh[i] = nbf; } for (id=ig=0; ig < nf; ig++) { for (ip=0; ip < np; ip++, id++) { pch[id] = (NULL != pp)? pp[ip]: ip; } } bb = nallocate (nbp, nf*np, nh, pch); if (NULL == (lagfile = sf_getstring("filt_lag")) && NULL == (lagfile = sf_histstring(reg,"lag"))) sf_error("Need filt_lag="); /* input file for double-helix filter lags */ lag = sf_input(lagfile); if (SF_INT != sf_gettype(lag)) sf_error("Need int filt_lag"); for (ip=0; ip < nbp; ip++) { sf_intread (kk,nbf,lag); for (i=0; i < nbf; i++) { bb->hlx[ip]->lag[i] = kk[i]*nf; } } for (ip=0; ip < nbp; ip++) { sf_floatread (bb->hlx[ip]->flt,nbf,reg); } nfind_pef (n123, dd, aa, bb, niter, eps, nf); for (ip=0; ip < np; ip++) { sf_floatwrite (aa->hlx[ip]->flt,nf,flt); } exit(0); }
int main(int argc, char* argv[]) { bool verb; int n[SF_MAX_DIM], n0[SF_MAX_DIM], rect[SF_MAX_DIM]; int a[SF_MAX_DIM], center[SF_MAX_DIM], gap[SF_MAX_DIM]; int ndim, dim, n123, n123s, i, ia, ns, i1, niter, na, i4, n4, *kk; float *d, *f, *dd; double mean; char *lagfile, key[6]; sf_filter aa; sf_file in, filt, lag; sf_init(argc,argv); in = sf_input("in"); filt = sf_output("out"); if (NULL == (lagfile = sf_getstring("lag"))) sf_error("Need lag="); /* output file for filter lags */ lag = sf_output(lagfile); sf_settype(lag,SF_INT); sf_putstring(filt,"lag",lagfile); ndim = sf_filedims(in,n); if (!sf_getint("dim",&dim)) dim=ndim; /* number of dimensions */ n4 = sf_leftsize(in,dim); sf_putints (lag,"n",n,dim); if (!sf_getints("a",a,dim)) sf_error("Need a="); if (!sf_getints("center",center,dim)) { for (i=0; i < dim; i++) { center[i] = (i+1 < dim && a[i+1] > 1)? a[i]/2: 0; } } if (!sf_getint("na",&na)) na=0; /* filter size */ if (0 == na) { if (!sf_getints("gap",gap,dim)) { for (i=0; i < dim; i++) { gap[i] = 0; } } aa = createhelix(dim, n, center, gap, a); /* allocate PEF */ for (i=0; i < dim; i++) { n0[i] = n[i]; } } else { aa = sf_allocatehelix (na); if (!sf_getints ("lags", aa->lag, na)) sf_error("Need lags="); if (!sf_getints ("n", n0, dim)) { for (i=0; i < dim; i++) { n0[i] = n[i]; } } } n123 = 1; for (i=0; i < dim; i++) { n123 *= n[i]; snprintf(key,6,"rect%d",i+1); if (!sf_getint(key,rect+i)) rect[i]=1; } dd = sf_floatalloc(n123); kk = sf_intalloc(n123); for (i1=0; i1 < n123; i1++) { kk[i1] = 1; } bound (dim, n0, n, a, aa); find_mask(n123, kk, aa); na = aa->nh; snprintf(key,3,"n%d",dim+1); sf_putint(filt,key,na); sf_shiftdim(in, filt, dim+1); if (!sf_getint("niter",&niter)) niter=100; /* number of iterations */ if (!sf_getbool("verb",&verb)) verb = true; /* verbosity flag */ n123s = n123*na; d = sf_floatalloc(n123s); f = sf_floatalloc(n123s); sf_multidivn_init(na, dim, n123, n, rect, d, NULL, verb); for (i4=0; i4 < n4; i4++) { sf_floatread(dd,n123,in); /* apply shifts: dd -> d */ mean = 0.; for (i=ia=0; ia < na; ia++) { ns = aa->lag[ia]; for (i1=0; i1 < n123; i1++,i++) { if (i1 < ns) { d[i] = 0.0f; } else { d[i] = dd[i1-ns]; mean += d[i]*d[i]; } } } if (mean == 0.) { sf_floatwrite(d,n123s,filt); continue; } mean = sqrt (n123s/mean); /* -> apply mask */ for(i=0; i < n123s; i++) { d[i] *= mean; } for(i1=0; i1 < n123; i1++) { dd[i1] *= mean; } sf_multidivn (dd,f,niter); sf_floatwrite(f,n123s,filt); } exit(0); }
int main(int argc, char* argv[]) { int i, ia, na, nx, ns, dim, n[SF_MAX_DIM], m[SF_MAX_DIM]; float a0, *pp, *qq; bool adj; sf_filter aa; char* lagfile; sf_file in, out, filt, lag; sf_init (argc,argv); in = sf_input("in"); filt = sf_input("filt"); out = sf_output("out"); dim = sf_filedims (in,n); if (!sf_histint(filt,"n1",&na)) sf_error("No n1= in filt"); aa = sf_allocatehelix (na); if (!sf_histfloat(filt,"a0",&a0)) a0=1.; sf_floatread (aa->flt,na,filt); for( ia=0; ia < na; ia++) { aa->flt[ia] /= a0; } if (NULL != (lagfile = sf_getstring("lag")) /* file with filter lags */ || NULL != (lagfile = sf_histstring(filt,"lag"))) { lag = sf_input(lagfile); sf_intread(aa->lag,na,lag); } else { lag = NULL; for( ia=0; ia < na; ia++) { aa->lag[ia] = ia+1; } } sf_fileclose(filt); if (!sf_getints ("n",m,dim) && (NULL == lag || !sf_histints (lag,"n",m,dim))) { for (i=0; i < dim; i++) { m[i] = n[i]; } } if (NULL != lag) sf_fileclose(lag); regrid (dim, m, n, aa); if (!sf_getbool ("adj",&adj)) adj=false; /* if y, do adjoint operation */ if (!sf_getint ("ns",&ns)) sf_error("Need ns="); /* scaling */ nx = 1; for( i=0; i < dim; i++) { nx *= n[i]; } pp = sf_floatalloc (nx); qq = sf_floatalloc (nx); if (adj) { sf_floatread (qq,nx,in); } else { sf_floatread (pp,nx,in); } hshape_init (nx,ns,aa); hshape_lop (adj,false,nx,nx,pp,qq); if (adj) { sf_floatwrite (pp,nx,out); } else { sf_floatwrite (qq,nx,out); } exit (0); }
int main(int argc, char* argv[]) { int i, j, is, ip, dim, n[SF_MAX_DIM], ii[SF_MAX_DIM]; int nsp, **k=NULL, **l=NULL, n1, n2, i1, i2, kk, ll; char key[7]; const char *label, *unit; float f, *trace, *mag=NULL, **p=NULL, pp; sf_file in, spike; sf_init (argc,argv); if (!sf_stdin()) { /* no input file in stdin */ in = NULL; } else { in = sf_input("in"); } spike = sf_output("out"); if (NULL == in) { sf_setformat(spike,"native_float"); } else if (SF_FLOAT != sf_gettype(in)) { sf_error("Need float input"); } /* dimensions */ for (i=0; i < SF_MAX_DIM; i++) { snprintf(key,3,"n%d",i+1); if (!sf_getint(key,n+i) && (NULL == in || !sf_histint(in,key,n+i))) break; /*( n# size of #-th axis )*/ sf_putint(spike,key,n[i]); } if (0==i) sf_error("Need n1="); dim=i; /* basic parameters */ for (i=0; i < dim; i++) { snprintf(key,3,"o%d",i+1); if (!sf_getfloat(key,&f) && (NULL == in || !sf_histfloat(in,key,&f))) f=0.; /*( o#=[0,0,...] origin on #-th axis )*/ sf_putfloat(spike,key,f); snprintf(key,3,"d%d",i+1); if (!sf_getfloat(key,&f) && (NULL == in || !sf_histfloat(in,key,&f))) f = (i==0)? 0.004: 0.1; /*( d#=[0.004,0.1,0.1,...] sampling on #-th axis )*/ sf_putfloat(spike,key,f); snprintf(key,7,"label%d",i+1); if (NULL == (label = sf_getstring(key)) && (NULL == in || NULL == (label = sf_histstring(in,key)))) label = (i==0)? "Time":"Distance"; /*( label#=[Time,Distance,Distance,...] label on #-th axis )*/ if (*label != '\0' && (*label != ' ' || *(label+1) != '\0')) sf_putstring(spike,key,label); snprintf(key,6,"unit%d",i+1); if (NULL == (unit = sf_getstring(key)) && (NULL == in || NULL == (unit = sf_histstring(in,key)))) unit = (i==0)? "s":"km"; /*( unit#=[s,km,km,...] unit on #-th axis )*/ if (*unit != '\0' && (*unit != ' ' || *(unit+1) != '\0')) sf_putstring(spike,key,unit); } if (NULL != (label = sf_getstring("title"))) sf_putstring(spike,"title",label); /* title for plots */ if (!sf_getint("nsp",&nsp)) nsp=1; /* Number of spikes */ if (nsp >= 1) { mag = sf_floatalloc (nsp); k = sf_intalloc2 (nsp,dim); l = sf_intalloc2 (nsp,dim); p = sf_floatalloc2 (nsp,dim); for (i=0; i < dim; i++) { snprintf(key,3,"k%d",i+1); if ( !sf_getints(key,k[i],nsp)) { /*( k#=[0,...] spike starting position )*/ for (is=0; is < nsp; is++) { k[i][is]=-1; } } else { for (is=0; is < nsp; is++) { if (k[i][is] > n[i]) sf_error("Invalid k%d[%d]=%d > n%d=%d", i+1,is+1,k[i][is],i+1,n[i]); k[i][is]--; /* C notation */ } } snprintf(key,3,"l%d",i+1); if (!sf_getints(key,l[i],nsp)) { /*( l#=[k1,k2,...] spike ending position )*/ for (is=0; is < nsp; is++) { l[i][is]=k[i][is]; } } else { for (is=0; is < nsp; is++) { if (l[i][is] > n[i]) sf_error("Invalid l%d[%d]=%d > n%d=%d", i+1,is+1,l[i][is],i+1,n[i]); l[i][is]--; /* C notation */ } } snprintf(key,3,"p%d",i+1); if (!sf_getfloats(key,p[i],nsp)) { /*( p#=[0,...] spike inclination (in samples) )*/ for (is=0; is < nsp; is++) { p[i][is]=0.; } } } if (!sf_getfloats("mag",mag,nsp)) { /* spike magnitudes */ for (is=0; is < nsp; is++) { mag[is]=1.; } } } n1 = n[0]; n2 = sf_leftsize(spike,1); trace = sf_floatalloc (n[0]); for (i2=0; i2 < n2; i2++) { /* loop over traces */ sf_line2cart(dim-1, n+1, i2, ii+1); /* zero trace */ for (i1=0; i1 < n1; i1++) trace[i1]=0.; /* put spikes in it */ for (is=0; is < nsp; is++) { /* loop over spikes */ pp = 0.; for (i=1; i < dim; i++) { kk = k[i][is]; ll = l[i][is]; if ((kk < -1 && ll < -1) || (kk >= 0 && ll >= 0 && (kk > ii[i] || ll < ii[i]))) break; pp += p[i][is]*(ii[i]-k[i][is]-1); } if (i < dim) continue; /* skip this spike */ /* linear interpolation */ ip = floorf(pp); pp = 1.-(pp-ip); kk = k[0][is]; ll = l[0][is]; if (kk >= 0) { /* one segment per trace */ kk = SF_MAX(kk+ip,0); ll = SF_MIN(ll+ip,n1-1); } else { kk = SF_MAX(ip,0); ll = SF_MIN(n1-1+ip,n1-1); } for (j=kk; j <= ll; j++) { trace[j] += pp*mag[is]; if (j+1 < n1) trace[j+1] += (1.-pp)*mag[is]; } } sf_floatwrite(trace,n1,spike); } exit (0); }
int main(int argc, char* argv[]) { /*survey parameters*/ int nx, nz; float dx, dz; int n_srcs; int *spx, *spz; int gpz, gpx, gpl; int gpz_v, gpx_v, gpl_v; int snap; /*fft related*/ bool cmplx; int pad1; /*absorbing boundary*/ bool abc; int nbt, nbb, nbl, nbr; float ct,cb,cl,cr; /*source parameters*/ int src; /*source type*/ int nt,ntsnap; float dt,*f0,*t0,*A; /*misc*/ bool verb, ps, mig; float vref; pspar par; int nx1, nz1; /*domain of interest*/ int it; float *vel,**dat,**dat_v,**wvfld,*img; /*velocity profile*/ sf_file Fi,Fo,Fd,Fd_v,snaps; /* I/O files */ sf_axis az,ax; /* cube axes */ sf_init(argc,argv); if (!sf_getint("snap",&snap)) snap=0; /* interval for snapshots */ if (!sf_getbool("cmplx",&cmplx)) cmplx=true; /* use complex fft */ if (!sf_getint("pad1",&pad1)) pad1=1; /* padding factor on the first axis */ if(!sf_getbool("abc",&abc)) abc=false; /* absorbing flag */ if (abc) { if(!sf_getint("nbt",&nbt)) sf_error("Need nbt!"); if(!sf_getint("nbb",&nbb)) nbb = nbt; if(!sf_getint("nbl",&nbl)) nbl = nbt; if(!sf_getint("nbr",&nbr)) nbr = nbt; if(!sf_getfloat("ct",&ct)) sf_error("Need ct!"); if(!sf_getfloat("cb",&cb)) cb = ct; if(!sf_getfloat("cl",&cl)) cl = ct; if(!sf_getfloat("cr",&cr)) cr = ct; } else { nbt = 0; nbb = 0; nbl = 0; nbr = 0; ct = 0; cb = 0; cl = 0; cr = 0; } if (!sf_getbool("verb",&verb)) verb=false; /* verbosity */ if (!sf_getbool("ps",&ps)) ps=false; /* use pseudo-spectral */ if (ps) sf_warning("Using pseudo-spectral..."); else sf_warning("Using pseudo-analytical..."); if (!sf_getbool("mig",&mig)) mig=false; /* use pseudo-spectral */ if (mig) sf_warning("Time-reversal propagation"); else sf_warning("Forward modeling"); if (!sf_getfloat("vref",&vref)) vref=1500; /* reference velocity (default using water) */ /* setup I/O files */ Fi = sf_input ("in"); Fo = sf_output("out"); if (mig) { gpl = -1; gpl_v = -1; if (NULL==sf_getstring("dat") && NULL==sf_getstring("dat_v")) sf_error("Need Data!"); if (NULL!=sf_getstring("dat")) { Fd = sf_input("dat"); sf_histint(Fd,"n1",&nt); sf_histfloat(Fd,"d1",&dt); sf_histint(Fd,"n2",&gpl); } else Fd = NULL; if (NULL!=sf_getstring("dat_v")) { Fd_v = sf_input("dat_v"); sf_histint(Fd_v,"n1",&nt); sf_histfloat(Fd_v,"d1",&dt); sf_histint(Fd_v,"n2",&gpl_v); } else Fd_v = NULL; src = -1; n_srcs = -1; spx = NULL; spz = NULL; f0 = NULL; t0 = NULL; A = NULL; } else { Fd = NULL; if (!sf_getint("nt",&nt)) sf_error("Need nt!"); if (!sf_getfloat("dt",&dt)) sf_error("Need dt!"); if (!sf_getint("gpl",&gpl)) gpl = -1; /* geophone length */ if (!sf_getint("gpl_v",&gpl_v)) gpl_v = -1; /* geophone height */ if (!sf_getint("src",&src)) src=0; /* source type */ if (!sf_getint("n_srcs",&n_srcs)) n_srcs=1; /* source type */ spx = sf_intalloc(n_srcs); spz = sf_intalloc(n_srcs); f0 = sf_floatalloc(n_srcs); t0 = sf_floatalloc(n_srcs); A = sf_floatalloc(n_srcs); if (!sf_getints("spx",spx,n_srcs)) sf_error("Need spx!"); /* shot position x */ if (!sf_getints("spz",spz,n_srcs)) sf_error("Need spz!"); /* shot position z */ if (!sf_getfloats("f0",f0,n_srcs)) sf_error("Need f0! (e.g. 30Hz)"); /* wavelet peak freq */ if (!sf_getfloats("t0",t0,n_srcs)) sf_error("Need t0! (e.g. 0.04s)"); /* wavelet time lag */ if (!sf_getfloats("A",A,n_srcs)) sf_error("Need A! (e.g. 1)"); /* wavelet amplitude */ } if (!sf_getint("gpx",&gpx)) gpx = -1; /* geophone position x */ if (!sf_getint("gpz",&gpz)) gpz = -1; /* geophone position z */ if (!sf_getint("gpx_v",&gpx_v)) gpx_v = -1; /* geophone position x */ if (!sf_getint("gpz_v",&gpz_v)) gpz_v = -1; /* geophone position z */ if (SF_FLOAT != sf_gettype(Fi)) sf_error("Need float input"); /* Read/Write axes */ az = sf_iaxa(Fi,1); nz = sf_n(az); dz = sf_d(az); ax = sf_iaxa(Fi,2); nx = sf_n(ax); dx = sf_d(ax); nz1 = nz-nbt-nbb; nx1 = nx-nbl-nbr; if (gpx==-1) gpx = nbl; if (gpz==-1) gpz = nbt; if (gpl==-1) gpl = nx1; if (gpx_v==-1) gpx_v = nbl; if (gpz_v==-1) gpz_v = nbt; if (gpl_v==-1) gpl_v = nz1; ntsnap=0; if (snap) for (it=0;it<nt;it++) if (it%snap==0) ntsnap++; if (mig) { /*output final wavefield*/ sf_setn(az,nz1); sf_setn(ax,nx1); sf_oaxa(Fo,az,1); sf_oaxa(Fo,ax,2); sf_settype(Fo,SF_FLOAT); } else { /*output data*/ sf_setn(ax,gpl); /*output horizontal data is mandatory*/ sf_putint(Fo,"n1",nt); sf_putfloat(Fo,"d1",dt); sf_putfloat(Fo,"o1",0.); sf_putstring(Fo,"label1","Time"); sf_putstring(Fo,"unit1","s"); sf_oaxa(Fo,ax,2); sf_settype(Fo,SF_FLOAT); /*output vertical data is optional*/ if (NULL!=sf_getstring("dat_v")) { Fd_v = sf_output("dat_v"); sf_setn(az,gpl_v); sf_putint(Fd_v,"n1",nt); sf_putfloat(Fd_v,"d1",dt); sf_putfloat(Fd_v,"o1",0.); sf_putstring(Fd_v,"label1","Time"); sf_putstring(Fd_v,"unit1","s"); sf_oaxa(Fd_v,az,2); sf_settype(Fd_v,SF_FLOAT); } else Fd_v = NULL; } if (snap > 0) { snaps = sf_output("snaps"); /* (optional) snapshot file */ sf_setn(az,nz1); sf_setn(ax,nx1); sf_oaxa(snaps,az,1); sf_oaxa(snaps,ax,2); sf_putint(snaps,"n3",ntsnap); sf_putfloat(snaps,"d3",dt*snap); sf_putfloat(snaps,"o3",0.); sf_putstring(snaps,"label3","Time"); sf_putstring(snaps,"unit3","s"); } else snaps = NULL; par = (pspar) sf_alloc(1,sizeof(*par)); vel = sf_floatalloc(nz*nx); if (mig && NULL==Fd) dat = NULL; else dat = sf_floatalloc2(nt,gpl); if (NULL!=Fd_v) dat_v = sf_floatalloc2(nt,gpl_v); else dat_v = NULL; if (mig) img = sf_floatalloc(nz1*nx1); else img = NULL; if (snap>0) wvfld = sf_floatalloc2(nx1*nz1,ntsnap); else wvfld = NULL; sf_floatread(vel,nz*nx,Fi); if (mig) { if (NULL!=Fd) sf_floatread(dat[0],gpl*nt,Fd); if (NULL!=Fd_v) sf_floatread(dat_v[0],gpl_v*nt,Fd_v); } /*passing the parameters*/ par->nx = nx; par->nz = nz; par->dx = dx; par->dz = dz; par->n_srcs= n_srcs; par->spx = spx; par->spz = spz; par->gpz = gpz; par->gpx = gpx; par->gpl = gpl; par->gpz_v = gpz_v; par->gpx_v = gpx_v; par->gpl_v = gpl_v; par->snap = snap; par->cmplx = cmplx; par->pad1 = pad1; par->abc = abc; par->nbt = nbt; par->nbb = nbb; par->nbl = nbl; par->nbr = nbr; par->ct = ct; par->cb = cb; par->cl = cl; par->cr = cr; par->src = src; par->nt = nt; par->dt = dt; par->f0 = f0; par->t0 = t0; par->A = A; par->verb = verb; par->ps = ps; par->vref = vref; /*do the work*/ psp(wvfld, dat, dat_v, img, vel, par, mig); if (mig) { sf_floatwrite(img,nz1*nx1,Fo); } else { sf_floatwrite(dat[0],gpl*nt,Fo); if (NULL!=Fd_v) sf_floatwrite(dat_v[0],gpl_v*nt,Fd_v); } if (snap>0) sf_floatwrite(wvfld[0],nz1*nx1*ntsnap,snaps); exit (0); }
int main(int argc, char* argv[]) { bool verb, pow2; char key[7], *mode;; int n1, n2, n1padded, n2padded, num, dim, n[SF_MAX_DIM], npadded[SF_MAX_DIM], ii[SF_MAX_DIM]; int i, j, i1, i2, index, nw, iter, niter, nthr, *pad; float thr, pclip, normp; float *dobs_t, *thresh, *mask; fftwf_complex *mm, *dd, *dobs; fftwf_plan fft1, ifft1, fftrem, ifftrem;/* execute plan for FFT and IFFT */ sf_file in, out, Fmask; /* mask and I/O files*/ sf_init(argc,argv); /* Madagascar initialization */ in=sf_input("in"); /* read the data to be interpolated */ out=sf_output("out"); /* output the reconstructed data */ Fmask=sf_input("mask"); /* read the (n-1)-D mask for n-D data */ if(!sf_getbool("verb",&verb)) verb=false; /* verbosity */ if(!sf_getbool("pow2",&pow2)) pow2=false; /* round up the length of each axis to be power of 2 */ if (!sf_getint("niter",&niter)) niter=100; /* total number of iterations */ if (!sf_getfloat("pclip",&pclip)) pclip=10.; /* starting data clip percentile (default is 10)*/ if ( !(mode=sf_getstring("mode")) ) mode = "exp"; /* thresholding mode: 'hard', 'soft','pthresh','exp'; 'hard', hard thresholding; 'soft', soft thresholding; 'pthresh', generalized quasi-p; 'exp', exponential shrinkage */ if (pclip <=0. || pclip > 100.) sf_error("pclip=%g should be > 0 and <= 100",pclip); if (!sf_getfloat("normp",&normp)) normp=1.; /* quasi-norm: normp<2 */ for (i=0; i < SF_MAX_DIM; i++) {/* dimensions */ snprintf(key,3,"n%d",i+1); if (!sf_getint(key,n+i) && (NULL == in || !sf_histint(in,key,n+i))) break; /*( n# size of #-th axis )*/ sf_putint(out,key,n[i]); } if (0==i) sf_error("Need n1="); dim=i; pad=sf_intalloc (dim); for (i=0; i<dim; i++) pad[i]=0; sf_getints("pad",pad,dim); /* number of zeros to be padded for each axis */ n1=n[0]; n2=sf_leftsize(in,1); for (i=0; i<SF_MAX_DIM; i++) npadded[i]=1; npadded[0]=n1+pad[0]; n1padded=npadded[0]; n2padded=1; for (i=1; i<dim; i++){ npadded[i]=n[i]+pad[i]; if (pow2) {/* zero-padding to be power of 2 */ npadded[i]=nextpower2(n[i]); fprintf(stderr,"n%d=%d n%dpadded=%d\n",i,n[i],i,npadded[i]); } n2padded*=npadded[i]; } nw=npadded[0]/2+1; num=nw*n2padded;/* data: total number of elements in frequency domain */ /* allocate data and mask arrays */ thresh=(float*) malloc(nw*n2padded*sizeof(float)); dobs_t=(float*) fftwf_malloc(n1padded*n2padded*sizeof(float)); /* time domain observation */ dobs=(fftwf_complex*)fftwf_malloc(nw*n2padded*sizeof(fftwf_complex));/* freq-domain observation */ dd=(fftwf_complex*) fftwf_malloc(nw*n2padded*sizeof(fftwf_complex)); mm=(fftwf_complex*) fftwf_malloc(nw*n2padded*sizeof(fftwf_complex)); if (NULL != sf_getstring("mask")){ mask=sf_floatalloc(n2padded); } else sf_error("mask needed!"); /* initialize the input data and mask arrays */ memset(dobs_t,0,n1padded*n2padded*sizeof(float)); memset(mask,0,n2padded*sizeof(float)); for (i=0; i<n1*n2; i+=n1){ sf_line2cart(dim,n,i,ii); j=sf_cart2line(dim,npadded,ii); sf_floatread(&dobs_t[j], n1, in); sf_floatread(&mask[j/n1padded], 1, Fmask); } /* FFT for the 1st dimension and the remaining dimensions */ fft1=fftwf_plan_many_dft_r2c(1, &n1padded, n2padded, dobs_t, &n1padded, 1, n1padded, dobs, &n1padded, 1, nw, FFTW_MEASURE); ifft1=fftwf_plan_many_dft_c2r(1, &n1padded, n2padded, dobs, &n1padded, 1, nw, dobs_t, &n1padded, 1, n1padded, FFTW_MEASURE); fftrem=fftwf_plan_many_dft(dim-1, &npadded[1], nw, dd, &npadded[1], nw, 1, dd, &npadded[1], nw, 1, FFTW_FORWARD, FFTW_MEASURE); ifftrem=fftwf_plan_many_dft(dim-1, &npadded[1], nw, dd, &npadded[1], nw, 1, dd, &npadded[1], nw, 1, FFTW_BACKWARD, FFTW_MEASURE); /* transform the data from time domain to frequency domain: dobs_t-->dobs */ fftwf_execute(fft1); for(i=0; i<num; i++) dobs[i]/=sqrtf(n1padded); memset(mm,0,num*sizeof(fftwf_complex)); /* Iterative Shrinkage-Thresholding (IST) Algorithm: mm^{k+1}=T[mm^k+A^* M^* (dobs-M A mm^k)] (M^*=M; Mdobs=dobs) =T[mm^k+A^*(dobs-M A mm^k)]; (k=0,1,...niter-1) dd^=A mm^; */ for(iter=0; iter<niter; iter++) { /* dd<-- A mm^k */ memcpy(dd, mm, num*sizeof(fftwf_complex)); fftwf_execute(ifftrem); for(i=0; i<num; i++) dd[i]/=sqrtf(n2padded); /* apply mask: dd<--dobs-M A mm^k=dobs-M dd */ for(i2=0; i2<n2padded; i2++) for(i1=0; i1<nw; i1++) { index=i1+nw*i2; dd[index]=dobs[index]-mask[i2]*dd[index]; } /* mm^k += A^*(dobs-M A mm^k); dd=dobs-M A mm^k */ fftwf_execute(fftrem); for(i=0; i<num; i++) mm[i]+=dd[i]/sqrtf(n2padded); /* perform thresholding */ for(i=0; i<num; i++) thresh[i]=cabsf(mm[i]); nthr = 0.5+num*(1.-0.01*pclip); /* round off */ if (nthr < 0) nthr=0; if (nthr >= num) nthr=num-1; thr=sf_quantile(nthr, num, thresh); sf_cpthresh(mm, num, thr, normp, mode); if (verb) sf_warning("iteration %d;",iter+1); } /* frequency--> time domain: dobs-->dobs_t */ memcpy(dd, mm, num*sizeof(fftwf_complex)); fftwf_execute(ifftrem); for(i=0; i<num; i++) dd[i]/=sqrtf(n2padded); memcpy(dobs, dd, num*sizeof(fftwf_complex)); fftwf_execute(ifft1); for(i=0; i<n1padded*n2padded; i++) dobs_t[i]/=sqrtf(n1padded); for (i=0; i<n1*n2; i+=n1){ sf_line2cart(dim,n,i,ii); j=sf_cart2line(dim,npadded,ii); sf_floatwrite(&dobs_t[j],n1,out); } free(thresh); fftwf_free(dobs_t); fftwf_free(dobs); fftwf_free(dd); fftwf_free(mm); exit(0); }
int main(int argc, char* argv[]) { int i, ia, na, nx, ns, dim, niter; int n[SF_MAX_DIM], m[SF_MAX_DIM], a[SF_MAX_DIM]; float a0, eps, *mm, *pp; bool verb, *known; sf_filter aa; char* lagfile; sf_file in, out, filt, lag, mask; sf_init (argc,argv); in = sf_input("in"); filt = sf_input("filt"); out = sf_output("out"); dim = sf_filedims (in,n); if (!sf_histint(filt,"n1",&na)) sf_error("No n1= in filt"); aa = sf_allocatehelix (na); if (!sf_histfloat(filt,"a0",&a0)) a0=1.; if (!sf_histints(filt,"a",a,dim)) { for (i=0; i < dim; i++) { a[i]=1; } } if (NULL != (lagfile = sf_getstring("lag")) /* file with filter lags */ || NULL != (lagfile = sf_histstring(filt,"lag"))) { lag = sf_input(lagfile); sf_intread(aa->lag,na,lag); } else { lag = NULL; for( ia=0; ia < na; ia++) { aa->lag[ia] = ia+1; } } if (!sf_getints ("n",m,dim) && (NULL == lag || !sf_histints (lag,"n",m,dim))) { for (i=0; i < dim; i++) { m[i] = n[i]; } } if (NULL != lag) sf_fileclose(lag); bound (dim, m, n, a, aa); sf_floatread (aa->flt,na,filt); sf_fileclose(filt); for( ia=0; ia < na; ia++) { aa->flt[ia] /= a0; } if (!sf_getint ("ns",&ns)) sf_error("Need ns="); /* scaling */ if (!sf_getint("niter",&niter)) niter=100; /* Number of iterations */ if (!sf_getfloat("eps",&eps)) eps=1.; /* regularization parameter */ if (!sf_getbool("verb",&verb)) verb=true; /* verbosity flag */ nx = 1; for( i=0; i < dim; i++) { nx *= n[i]; } mm = sf_floatalloc (nx); pp = sf_floatalloc (nx); known = sf_boolalloc (nx); sf_mask_init(known); hshape_init (nx,ns,aa); sf_conjgrad_init(nx, nx, nx, nx, eps, 1.e-8, verb, false); if (NULL != sf_getstring("mask")) { /* optional input mask file for known data */ mask = sf_input("mask"); sf_floatread(mm,nx,mask); sf_fileclose(mask); for (i=0; i < nx; i++) { known[i] = (bool) (mm[i] != 0.); } sf_floatread(mm,nx,in); } else { sf_floatread(mm,nx,in); for (i=0; i < nx; i++) { known[i] = (bool) (mm[i] != 0.); } } sf_conjgrad(NULL, sf_mask_lop, hshape_lop, pp, mm, mm, niter); sf_floatwrite (mm,nx,out); exit (0); }
int main(int argc, char* argv[]) { int n[SF_MAX_DIM], w[3], k[3], a[3], gap[3], center[3]; int n123, n1, dim, dim1, nk, i, j, ik, na; bool stp; float *data, d[3], o[3], *mask, vel, tgap, dabs, di; char varname[6], *lagfile; sf_filter aa, bb, ak; sf_file dat, pef, lag, known; sf_init(argc,argv); dat = sf_input("in"); pef = sf_output("out"); if (NULL == (lagfile = sf_getstring("lag"))) sf_error("Need lag="); /* output file for filter lags */ lag = sf_output(lagfile); sf_settype(lag,SF_INT); sf_putstring(pef,"lag",lagfile); dim = sf_filedims(dat,n); if (dim > 3) sf_error("Need 3 dimensions or less"); if (!sf_getint("dim",&dim1)) dim1=dim; /* PEF dimensionality */ if (dim1 > dim) dim1=dim; sf_putint(pef,"dim",dim1); if (!sf_getints("w",w,dim1)) sf_error("Need w="); /* window size */ for (j=0; j < dim1; j++) { if (w[j] > n[j]) w[j] = n[j]; } sf_putints(pef,"w",w,dim1); if (!sf_getints("a",a,dim1)) sf_error("Need a="); /* filter size */ sf_putints(pef,"a",a,dim1); if (!sf_getints("k",k,dim1)) { /* number of windows */ for (j=0; j < dim1; j++) { k[j] = 1.5 * n[j] / (w[j] - a[j] + 1.); } } sf_putints(pef,"k",k,dim1); if (!sf_getints("gap",gap,dim1)) { /* filter gap */ for (j=0; j < dim1; j++) { gap[j] = 0; } } sf_putints(pef,"gap",gap,dim1); if (!sf_getints("center",center,dim1)) { /* filter center */ for (j=0; j < dim1-1; j++) { center[j] = (a[j+1] > 1)? a[j]/2: 0; } center[dim1-1] = 0; } sf_putints(pef,"center",center,dim1); if (!sf_getbool("steepdip",&stp)) stp=false; /* if y, do steep-dip PEF estimation */ for (j=0; j < dim1; j++) { sprintf(varname,"d%d",j+1); if (!sf_histfloat(dat,varname,d+j)) sf_error("No %s= in input",varname); sprintf(varname,"o%d",j+1); if (!sf_histfloat(dat,varname,o+j)) sf_error("No %s= in input",varname); } if (stp) { if (!sf_getfloat ("vel",&vel)) vel=1.7; /* velocity for steep-dip decon */ if (!sf_getfloat("tgap",&tgap)) tgap=0.030; /* time gap for steep-dip decon */ bb = steep(dim1, w, a, d, vel, tgap); } else { bb = createhelix(dim1, w, center, gap, a); } sf_putints (lag,"n",w,dim1); bound (dim1, w, w, a, bb); for (i=0; i < bb->nh; i++) { bb->flt[i] = 2.; } print(dim1, w, center, a, bb); n123=n1=nk=1; for (j=0; j < dim; j++) { n123 *= n[j]; if (j < dim1) { n1 = n123; nk *= k[j]; } } na = bb->nh; sf_putint(pef,"n1",na); sf_putint(lag,"n1",na); for (j=0; j < dim; j++) { sprintf(varname,"n%d",j+2); sf_putint(lag,varname,1); if (j < dim1) { sf_putint(pef,varname,k[j]); sprintf(varname,"o%d",j+2); sf_putfloat(pef,varname,o[j]+0.5*w[j]*d[j]); sprintf(varname,"d%d",j+2); sf_putfloat(pef,varname,(n[j]-w[j])/(k[j]-1.)*d[j]); } else if (j == dim1) { sf_putint(pef,varname,n123/n1); } else { sf_putint(pef,varname,1); } } sf_intwrite(bb->lag,na,lag); data = sf_floatalloc(n123); aa = (sf_filter) sf_alloc(nk,sizeof(*aa)); if (NULL != sf_getstring ("mask")) { known = sf_input("mask"); mask = sf_floatalloc(n123); sf_floatread(mask,n123,known); sf_fileclose(known); } else { mask = NULL; } sf_floatread(data,n123,dat); dabs = fabsf(data[0]); for (i=1; i < n123; i++) { di = fabsf(data[i]); if (di > dabs) dabs=di; } random_init (2004); for (i=0; i < n123; i++) { data[i] = data[i]/dabs + 100.*FLT_EPSILON*(random0()-0.5); } for (ik=0; ik < nk; ik++) { ak = aa+ik; ak->nh = na; ak->flt = sf_floatalloc(na); for (i=0; i < na; i++) { ak->flt[i] = 0.; } ak->lag = bb->lag; ak->mis = bb->mis; } for (i=0; i < n123-n1+1; i += n1) { find_lopef (dim1, data+i, aa, k, n, w, mask); for (ik=0; ik < nk; ik++) { sf_floatwrite ((aa+ik)->flt,na,pef); } } exit(0); }
int main(int argc, char* argv[]) { int n[SF_MAX_DIM], m[SF_MAX_DIM]; int ndim, dim, n123, n123s, i, ia, ns, i1, na, i4, n4; float *f, *dd; char *lagfile; sf_filter aa; sf_file in, filt, lag, out; sf_init(argc,argv); in = sf_input("in"); filt = sf_output("filt"); out = sf_output("out"); if (!sf_histint(filt,"n1",&na)) sf_error("No n1= in filt"); aa = sf_allocatehelix (na); if (NULL != (lagfile = sf_getstring("lag")) /*( lag file with filter lags )*/ || NULL != (lagfile = sf_histstring(filt,"lag"))) { lag = sf_input(lagfile); sf_intread(aa->lag,na,lag); } else { lag = NULL; for( ia=0; ia < na; ia++) { aa->lag[ia] = ia+1; } } ndim = sf_filedims(in,n); if (!sf_getint("dim",&dim)) dim=ndim; /* number of dimensions */ if (!sf_getints ("n",m,dim) && (NULL == lag || !sf_histints (lag,"n",m,dim))) { for (i=0; i < dim; i++) { m[i] = n[i]; } } regrid (dim, m, n, aa); n4 = sf_leftsize(in,dim); n123 = 1; for (i=0; i < dim; i++) { n123 *= n[i]; } dd = sf_floatalloc(n123); n123s = n123*na; f = sf_floatalloc(n123s); for (i4=0; i4 < n4; i4++) { sf_floatread(dd,n123,in); sf_floatread(f,n123s,in); /* apply shifts: dd -> d */ for (i=ia=0; ia < na; ia++) { ns = aa->lag[ia]; for (i1=0; i1 < n123; i1++,i++) { dd[i1] -= f[i]*dd[i1-ns]; } } sf_floatwrite(dd,n123,out); } exit(0); }
int main(int argc, char* argv[]) { /*survey parameters*/ int nx, nz; float dx, dz; int n_srcs=1; int *spx, *spz; int gpz, gpx, gpl; int gpz_v, gpx_v, gpl_v; int snap; /*fft related*/ bool cmplx; int pad1; /*absorbing boundary*/ bool abc; int nbt, nbb, nbl, nbr; float ct,cb,cl,cr; /*source parameters*/ int src; /*source type*/ int nt; float dt,*f0,*t0,*A; /*misc*/ bool verb, ps, adj; float vref; bool born; pspar par; int nx1, nz1; /*domain of interest*/ float *vel,***dat,***dat_v,**wvfld1,**wvfld,*img,*imgs; /*velocity profile*/ sf_file Fi,Fo,Fv,Fd_v,snaps; /* I/O files */ sf_axis az,ax; /* cube axes */ int shtbgn,shtend,shtnum,shtint; int ix,iz,is,which; bool justrec; bool diff; sf_file Fi1; float ***dat1; sf_init(argc,argv); if (!sf_getint("snap",&snap)) snap=0; /* interval for snapshots */ if (!sf_getbool("cmplx",&cmplx)) cmplx=true; /* use complex fft */ if (!sf_getint("pad1",&pad1)) pad1=1; /* padding factor on the first axis */ if(!sf_getbool("abc",&abc)) abc=false; /* absorbing flag */ if(!sf_getbool("born",&born)) born=false; /* born modeling flag */ if(!sf_getbool("diff",&diff)) diff=false; /* diffraction imaging flag */ if(!sf_getbool("justrec",&justrec)) justrec=false; /* just need full waveform record (no born or rtdm) */ if (abc) { if(!sf_getint("nbt",&nbt)) sf_error("Need nbt!"); if(!sf_getint("nbb",&nbb)) nbb = nbt; if(!sf_getint("nbl",&nbl)) nbl = nbt; if(!sf_getint("nbr",&nbr)) nbr = nbt; if(!sf_getfloat("ct",&ct)) sf_error("Need ct!"); if(!sf_getfloat("cb",&cb)) cb = ct; if(!sf_getfloat("cl",&cl)) cl = ct; if(!sf_getfloat("cr",&cr)) cr = ct; } else { nbt = 0; nbb = 0; nbl = 0; nbr = 0; ct = 0; cb = 0; cl = 0; cr = 0; } if (!sf_getbool("verb",&verb)) verb=false; /* verbosity */ if (!sf_getbool("ps",&ps)) ps=false; /* use pseudo-spectral */ if (ps) sf_warning("Using pseudo-spectral..."); else sf_warning("Using pseudo-analytical..."); if (!sf_getbool("adj",&adj)) adj=false; /* use pseudo-spectral */ if (justrec && adj) sf_error("No migration in justrec mode!"); if (adj) sf_warning("RTM"); else sf_warning("RTDM"); if (!sf_getfloat("vref",&vref)) vref=1500; /* reference velocity (default using water) */ /* setup I/O files */ Fi = sf_input ("in"); Fo = sf_output("out"); Fv = sf_input("vel"); if (adj) { gpl = -1; gpl_v = -1; sf_histint(Fi,"n1",&nt); sf_histfloat(Fi,"d1",&dt); sf_histint(Fi,"n2",&gpl); if (NULL!=sf_getstring("dat_v")) { Fd_v = sf_input("dat_v"); sf_histint(Fd_v,"n2",&gpl_v); } else Fd_v = NULL; if (diff) Fi1 = sf_input("dat_2"); else Fi1 = NULL; } else { if (!sf_getint("nt",&nt)) sf_error("Need nt!"); if (!sf_getfloat("dt",&dt)) sf_error("Need dt!"); if (!sf_getint("gpl",&gpl)) gpl = -1; /* geophone length */ if (!sf_getint("gpl_v",&gpl_v)) gpl_v = -1; /* geophone height */ } if (!sf_getint("src",&src)) src=0; /* source type */ //if (!sf_getint("n_srcs",&n_srcs)) n_srcs=1; /* source type */ spx = sf_intalloc(n_srcs); spz = sf_intalloc(n_srcs); f0 = sf_floatalloc(n_srcs); t0 = sf_floatalloc(n_srcs); A = sf_floatalloc(n_srcs); //if (!sf_getints("spx",spx,n_srcs)) sf_error("Need spx!"); /* shot position x */ if (!sf_getints("spz",spz,n_srcs)) sf_error("Need spz!"); /* shot position z */ if (!sf_getfloats("f0",f0,n_srcs)) sf_error("Need f0! (e.g. 30Hz)"); /* wavelet peak freq */ if (!sf_getfloats("t0",t0,n_srcs)) sf_error("Need t0! (e.g. 0.04s)"); /* wavelet time lag */ if (!sf_getfloats("A",A,n_srcs)) sf_error("Need A! (e.g. 1)"); /* wavelet amplitude */ if (!sf_getint("shtbgn", &shtbgn)) sf_error("Need shot starting location on grid!"); if (!sf_getint("shtend", &shtend)) sf_error("Need shot ending location on grid!"); if (!sf_getint("shtint", &shtint)) sf_error("Need shot interval on grid!"); shtnum = (int)((shtend-shtbgn)/shtint) + 1; if (!sf_getint("which", &which)) which = 0; if (!sf_getint("gpx",&gpx)) gpx = -1; /* geophone position x */ if (!sf_getint("gpz",&gpz)) gpz = -1; /* geophone position z */ if (!sf_getint("gpx_v",&gpx_v)) gpx_v = -1; /* geophone position x */ if (!sf_getint("gpz_v",&gpz_v)) gpz_v = -1; /* geophone position z */ if (SF_FLOAT != sf_gettype(Fv)) sf_error("Need float input"); /* Read/Write axes */ az = sf_iaxa(Fv,1); nz = sf_n(az); dz = sf_d(az); ax = sf_iaxa(Fv,2); nx = sf_n(ax); dx = sf_d(ax); nz1 = nz-nbt-nbb; nx1 = nx-nbl-nbr; if (gpx==-1) gpx = nbl; if (gpz==-1) gpz = nbt; if (gpl==-1) gpl = nx1; if (gpx_v==-1) gpx_v = nbl; if (gpz_v==-1) gpz_v = nbt; if (gpl_v==-1) gpl_v = nz1; if (adj) { /*output image*/ sf_setn(az,nz1); sf_setn(ax,nx1); sf_oaxa(Fo,az,1); sf_oaxa(Fo,ax,2); sf_putint(Fo,"n3",1); sf_putfloat(Fo,"d3",shtint*dx); sf_putfloat(Fo,"o3",0.); sf_settype(Fo,SF_FLOAT); } else { /*output data*/ sf_setn(ax,gpl); /*output horizontal data is mandatory*/ sf_putint(Fo,"n1",nt); sf_putfloat(Fo,"d1",dt); sf_putfloat(Fo,"o1",0.); sf_putstring(Fo,"label1","Time"); sf_putstring(Fo,"unit1","s"); sf_oaxa(Fo,ax,2); sf_putint(Fo,"n3",shtnum); sf_putfloat(Fo,"d3",shtint*dx); sf_putfloat(Fo,"o3",0.); sf_putstring(Fo,"label3","Shot"); sf_settype(Fo,SF_FLOAT); /*output vertical data is optional*/ if (NULL!=sf_getstring("dat_v")) { Fd_v = sf_output("dat_v"); sf_setn(ax,gpl_v); /*output horizontal data is mandatory*/ sf_putint(Fd_v,"n1",nt); sf_putfloat(Fd_v,"d1",dt); sf_putfloat(Fd_v,"o1",0.); sf_putstring(Fd_v,"label1","Time"); sf_putstring(Fd_v,"unit1","s"); sf_oaxa(Fd_v,ax,2); sf_putint(Fd_v,"n3",shtnum); sf_putfloat(Fd_v,"d3",shtint*dx); sf_putfloat(Fd_v,"o3",0.); sf_putstring(Fd_v,"label3","Shot"); sf_settype(Fd_v,SF_FLOAT); } else Fd_v = NULL; } if (snap > 0) { snaps = sf_output("snaps"); /* (optional) snapshot file */ sf_setn(az,nz1); sf_setn(ax,nx1); sf_oaxa(snaps,az,1); sf_oaxa(snaps,ax,2); sf_putint(snaps,"n3",nt/snap); sf_putfloat(snaps,"d3",dt*snap); sf_putfloat(snaps,"o3",0.); sf_putstring(snaps,"label3","Time"); sf_putstring(snaps,"unit3","s"); } else snaps = NULL; par = (pspar) sf_alloc(1,sizeof(*par)); vel = sf_floatalloc(nz*nx); dat = sf_floatalloc3(nt,gpl,shtnum); img = sf_floatalloc(nz1*nx1); if (adj) { imgs= sf_floatalloc(nz1*nx1); if (adj) { for (ix=0; ix<nx1; ix++) for (iz=0; iz<nz1; iz++) imgs[ix*nz1+iz] = 0.; } } else imgs = NULL; if (NULL!=Fd_v) dat_v = sf_floatalloc3(nt,gpl_v,shtnum); else dat_v = NULL; if (snap>0) { wvfld1 = sf_floatalloc2(nx1*nz1,nt/snap); wvfld = sf_floatalloc2(nx1*nz1,nt/snap); } else { wvfld1 = NULL; wvfld = NULL; } if (adj && diff) dat1 = sf_floatalloc3(nt,gpl,shtnum); else dat1 = NULL; sf_floatread(vel,nz*nx,Fv); if (adj) { sf_floatread(dat[0][0],gpl*nt*shtnum,Fi); if (NULL!=Fd_v) sf_floatread(dat_v[0][0],gpl_v*nt*shtnum,Fd_v); if (diff) sf_floatread(dat1[0][0],gpl_v*nt*shtnum,Fi1); } else { sf_floatread(img,nz1*nx1,Fi); } /*passing the parameters*/ par->nx = nx; par->nz = nz; par->dx = dx; par->dz = dz; par->n_srcs= n_srcs; par->spx = spx; par->spz = spz; par->gpz = gpz; par->gpx = gpx; par->gpl = gpl; par->gpz_v = gpz_v; par->gpx_v = gpx_v; par->gpl_v = gpl_v; par->snap = snap; par->cmplx = cmplx; par->pad1 = pad1; par->abc = abc; par->nbt = nbt; par->nbb = nbb; par->nbl = nbl; par->nbr = nbr; par->ct = ct; par->cb = cb; par->cl = cl; par->cr = cr; par->src = src; par->nt = nt; par->dt = dt; par->f0 = f0; par->t0 = t0; par->A = A; par->verb = verb; par->ps = ps; par->vref = vref; for (is=0; is<shtnum; is++){ *spx = shtbgn + shtint*is; //par->spx = spx; //pointer sf_warning("Processing shot # %d/%d",is,shtnum-1); if (adj && diff) { sf_warning("Simultaneously propagating two receiver wavefields..."); psp3(wvfld, wvfld1, dat[is], dat1[is], img, vel, par); for (ix=0; ix<nx1; ix++) for (iz=0; iz<nz1; iz++) imgs[ix*nz1+iz] += img[ix*nz1+iz]; } else { if (justrec) { if (NULL == dat_v) psp(wvfld, dat[is], NULL, NULL, vel, par, false); else psp(wvfld, dat[is], dat_v[is], NULL, vel, par, false); } else { sf_warning("Computing source wavefield ..."); psp(wvfld1, NULL, NULL, NULL, vel, par, false); if (born) dt2v2(wvfld1, vel, par); sf_warning("Computing receiver wavefield ..."); if (NULL == dat_v) psp2(wvfld1, wvfld, dat[is], NULL, img, vel, par, adj); else psp2(wvfld1, wvfld, dat[is], dat_v[is], img, vel, par, adj); if (adj) { for (ix=0; ix<nx1; ix++) for (iz=0; iz<nz1; iz++) imgs[ix*nz1+iz] += img[ix*nz1+iz]; } } } if (snap>0 && is==which) sf_floatwrite(wvfld[0],nz1*nx1*nt/snap,snaps); } if (adj) { sf_floatwrite(imgs,nz1*nx1,Fo); } else { sf_floatwrite(dat[0][0],gpl*nt*shtnum,Fo); if (NULL!=Fd_v) sf_floatwrite(dat_v[0][0],gpl_v*nt*shtnum,Fd_v); } exit (0); }