void psrtm_lop(bool adj, bool add, int nm, int nd, sf_complex *mod, sf_complex *dat) /*< lowrank onestep psrtm linear operator >*/ { sf_complex ***rec, **img; int nz, nx, nt, gpl, shtnum; int ix,is; nz = geop->nz; nx = geop->nx; nt = geop->nt; gpl = geop->gpl; shtnum = geop->shtnum; /*check the dimension*/ if (nm!=nz*nx || nd!=nt*gpl*shtnum) sf_error("%s: wrong dimensions",__FILE__); sf_cadjnull(adj, add, nm, nd, mod, dat); /*allocate memory and transform the dimension*/ img = (sf_complex**) sf_alloc (nx,sizeof(sf_complex*)); img[0] = mod; for (ix=1; ix<nx; ix++) img[ix] = img[0]+ix*nz; rec = (sf_complex***) sf_alloc (shtnum,sizeof(sf_complex**)); rec[0] = (sf_complex**) sf_alloc (gpl*shtnum,sizeof(sf_complex*)); rec[0][0] = dat; for (ix=1; ix<gpl*shtnum; ix++) rec[0][ix] = rec[0][0]+ix*nt; for (is=1; is<shtnum; is++) rec[is] = rec[0]+is*gpl; /* prestack migration */ geop->adj=adj; psrtm(rec, img, geop); free(img); free(*rec); free(rec); }
int main (int argc, char **argv) { int np; char buf[BUFSZ*PARSZ], **para, *p, *sep; sf_init(argc, argv); if ((sep=sf_getstring("sep"))==NULL) sep=""; /* cmd separater */ para = (char **)sf_alloc(PARSZ, sizeof(char*)); *para = (char *)sf_alloc(PARSZ*BUFSZ, sizeof(char)); for(np=1;np<PARSZ; np++) para[np] = para[np-1] + BUFSZ; vp_init(); p=buf; while(1) { *p=fgetc(stdin); if(issep(*p, sep)) { p = cmdline(buf, p, para); }else if(*p==EOF) { p = cmdline(buf, p, para); break; }else p++; } free(*para); free(para); return 0; }
void layer_init(int n_in /* number of layers */, char *types /* [n] velocity model types */, float *v0_in /* [n] reference velocity */, float **g_in /* [n] velocity gradient */, float **x0_in /* [n] gradient reference point */, int order /* interpolation order */, int nx /* horizontal sampling */, float **lays, float **dips, float **curs /* [n+1][nx] interfaces */) /*< initialize >*/ { int k; n = n_in; y = sf_floatalloc(n-1); type = types; lay = (sf_eno*) sf_alloc(n,sizeof(sf_eno)); dip = (sf_eno*) sf_alloc(n,sizeof(sf_eno)); cur = (sf_eno*) sf_alloc(n,sizeof(sf_eno)); table = (ktable) sf_alloc(1,sizeof(*table)); for (k=0; k < n+1; k++) { lay[k] = sf_eno_init (order,nx); sf_eno_set (lay[k],lays[k]); dip[k] = sf_eno_init (order,nx); sf_eno_set (dip[k],dips[k]); cur[k] = sf_eno_init (order,nx); sf_eno_set (cur[k],curs[k]); } v0 = v0_in; g = g_in; x0 = x0_in; }
agrid2 agrid2_init (int order /* interpolation order */, int n1, int n2 /* data dimensions */, int nd, int max) /*< Initialize interpolation object >*/ { agrid2 pnt; int i2; pnt = (agrid2) sf_alloc(1,sizeof(*pnt)); pnt->order = order; pnt->n1 = n1; pnt->n2 = n2; pnt->nd = nd; pnt->ng = 2*order-2; if (pnt->ng > pnt->n2) sf_error("ng is too big in agrid2"); pnt->jnt = sf_eno_init (order, pnt->ng); pnt->f = sf_floatalloc2(pnt->nd,pnt->ng); pnt->f1 = sf_floatalloc(pnt->ng); pnt->ent = (agrid*) sf_alloc(n2,sizeof(agrid)); for (i2 = 0; i2 < n2; i2++) { pnt->ent[i2] = agrid_init (n1, nd, max); } return pnt; }
/*------------------------------------------------------------*/ ompfft3d sf_ompfft3a3_init(int n1_, int n2_, int n3_, int ompnth_) /*< initialize FFT on axis 3 >*/ { int ompith; ompfft3d fft; fft = (ompfft3d) sf_alloc(1,sizeof(*fft)); fft->n1 = n1_; fft->n2 = n2_; fft->n3 = n3_; fft->ompnth=ompnth_; fft->forw = (kiss_fft_cfg*) sf_alloc(fft->ompnth,sizeof(kiss_fft_cfg)); fft->invs = (kiss_fft_cfg*) sf_alloc(fft->ompnth,sizeof(kiss_fft_cfg)); for(ompith=0; ompith<fft->ompnth; ompith++) { fft->forw[ompith] = kiss_fft_alloc(fft->n3,0,NULL,NULL); fft->invs[ompith] = kiss_fft_alloc(fft->n3,1,NULL,NULL); if (NULL == fft->forw[ompith] || NULL == fft->invs[ompith]) sf_error("%s: KISS FFT allocation error",__FILE__); fft->trace = (kiss_fft_cpx**) sf_complexalloc2(fft->n3,fft->ompnth); } fft->scale = 1./sqrtf(fft->n3); return fft; }
nfilter nallocate(int np /* number of patches */, int nd /* data size */, int *nh /* filter size [np] */, int *pch /* patching [nd] */) /*< allocate >*/ { nfilter aa; int ip, id; aa = (nfilter) sf_alloc(1,sizeof(*aa)); aa->np = np; aa->hlx = (sf_filter*) sf_alloc(np,sizeof(sf_filter)); for (ip=0; ip < np; ip++) { aa->hlx[ip] = sf_allocatehelix(nh[ip]); } aa->pch = sf_intalloc(nd); for (id=0; id < nd; id++) { aa->pch[id] = pch[id]; } aa->mis = NULL; return aa; }
eno3 eno3_init (int order /* interpolation order */, int n1, int n2, int n3 /* data dimensions */) /*< Initialize interpolation object >*/ { eno3 pnt; int i2, i3; pnt = (eno3) sf_alloc(1,sizeof(*pnt)); pnt->order = order; pnt->n1 = n1; pnt->n2 = n2; pnt->n3 = n3; pnt->ng = 2*order-2; if (pnt->ng > n2 || pnt->ng > n3) sf_error("%s: ng=%d is too big",__FILE__,pnt->ng); pnt->jnt = sf_eno2_init (order, pnt->ng, pnt->ng); pnt->f = sf_floatalloc2(pnt->ng,pnt->ng); pnt->f1 = sf_floatalloc2(pnt->ng,pnt->ng); pnt->ent = (sf_eno**) sf_alloc(n3,sizeof(sf_eno*)); for (i3 = 0; i3 < n3; i3++) { pnt->ent[i3] = (sf_eno*) sf_alloc(n2,sizeof(sf_eno)); for (i2 = 0; i2 < n2; i2++) { pnt->ent[i3][i2] = sf_eno_init (order, n1); } } return pnt; }
int fft2_init(bool cmplx1 /* if complex transform */, int pad1 /* padding on the first axis */, int nx, int ny /* input data size */, int *nx2, int *ny2 /* padded data size */) /*< initialize >*/ { #ifndef SF_HAS_FFTW int i2; #endif cmplx = cmplx1; if (cmplx) { nk = n1 = kiss_fft_next_fast_size(nx*pad1); #ifndef SF_HAS_FFTW cfg1 = kiss_fft_alloc(n1,0,NULL,NULL); icfg1 = kiss_fft_alloc(n1,1,NULL,NULL); #endif } else { nk = kiss_fft_next_fast_size(pad1*(nx+1)/2)+1; n1 = 2*(nk-1); #ifndef SF_HAS_FFTW cfg = kiss_fftr_alloc(n1,0,NULL,NULL); icfg = kiss_fftr_alloc(n1,1,NULL,NULL); #endif } n2 = kiss_fft_next_fast_size(ny); if (cmplx) { cc = sf_complexalloc2(n1,n2); } else { ff = sf_floatalloc2(n1,n2); } #ifndef SF_HAS_FFTW cfg2 = kiss_fft_alloc(n2,0,NULL,NULL); icfg2 = kiss_fft_alloc(n2,1,NULL,NULL); tmp = (kiss_fft_cpx **) sf_alloc(n2,sizeof(*tmp)); tmp[0] = (kiss_fft_cpx *) sf_alloc(nk*n2,sizeof(kiss_fft_cpx)); for (i2=0; i2 < n2; i2++) { tmp[i2] = tmp[0]+i2*nk; } trace2 = sf_complexalloc(n2); ctrace2 = (kiss_fft_cpx *) trace2; #endif *nx2 = n1; *ny2 = n2; wt = 1.0/(n1*n2); return (nk*n2); }
sf_stack sf_stack_init (size_t size) /*< create a stack >*/ { sf_stack s; s = (sf_stack) sf_alloc (1, sizeof(*s)); s->size = size; s->entry = (struct entry*) sf_alloc(size,sizeof(struct entry)); s->top = s->entry-1; return s; }
int cfft2_init(int pad1 /* padding on the first axis */, int nx, int ny /* input data size */, int *nx2, int *ny2 /* padded data size */) /*< initialize >*/ { #ifdef SF_HAS_FFTW #ifdef _OPENMP fftw_init_threads(); sf_warning("Using threaded FFTW3! \n"); fftw_plan_with_nthreads(omp_get_max_threads()); #endif #endif #ifndef SF_HAS_FFTW int i2; #endif nk = n1 = kiss_fft_next_fast_size(nx*pad1); #ifndef SF_HAS_FFTW cfg1 = kiss_fft_alloc(n1,0,NULL,NULL); icfg1 = kiss_fft_alloc(n1,1,NULL,NULL); #endif n2 = kiss_fft_next_fast_size(ny); cc = sf_complexalloc2(n1,n2); dd = sf_complexalloc2(nk,n2); #ifndef SF_HAS_FFTW cfg2 = kiss_fft_alloc(n2,0,NULL,NULL); icfg2 = kiss_fft_alloc(n2,1,NULL,NULL); tmp = (kiss_fft_cpx **) sf_alloc(n2,sizeof(*tmp)); tmp[0] = (kiss_fft_cpx *) sf_alloc(nk*n2,sizeof(kiss_fft_cpx)); for (i2=0; i2 < n2; i2++) { tmp[i2] = tmp[0]+i2*nk; } trace2 = sf_complexalloc(n2); ctrace2 = (kiss_fft_cpx *) trace2; #endif *nx2 = n1; *ny2 = n2; wt = 1.0/(n1*n2); return (nk*n2); }
/*------------------------------------------------------------*/ wexcub3d wex_cube(bool verb_, sf_axis amx_, sf_axis amy_, sf_axis az_, sf_axis alx_, sf_axis aly_, sf_axis aw_, sf_axis ae_, float eps_, int ompnth_ ) /*< initialize SR migration space >*/ { wexcub3d cub; cub = (wexcub3d) sf_alloc(1,sizeof(*cub)); cub->verb=verb_; cub->amx = sf_nod(amx_); cub->amy = sf_nod(amy_); cub->az = sf_nod(az_); cub->alx = sf_nod(alx_); cub->aly = sf_nod(aly_); cub->ae = sf_nod(ae_); cub->aw = sf_nod(aw_); cub->aw.d *= 2.*SF_PI; /* from hertz to radians */ cub->aw.o *= 2.*SF_PI; cub->eps = eps_; cub->ompnth = ompnth_; return cub; }
sf_map sf_stretch_init (int n1, float o1, float d1 /* regular axis */, int nd /* data length */, float eps /* regularization */, bool narrow /* if zero boundary */) /*< initialize >*/ { sf_map str; str = (sf_map) sf_alloc (1, sizeof(*str)); str->nt = n1; str->t0 = o1; str->dt = d1; str->nd = nd; str->eps = eps; str->narrow = narrow; str->x = sf_intalloc (nd); str->m = sf_boolalloc (nd); str->w = sf_floatalloc (nd); str->diag = sf_floatalloc (n1); str->offd = sf_floatalloc (n1-1); str->slv = sf_tridiagonal_init (n1); return str; }
/*------------------------------------------------------------*/ fdm2d fdutil_init(bool verb_, bool free_, sf_axis a1_, sf_axis a2_, int nb_, int ompchunk_) /*< init fdm utilities >*/ { fdm2d fdm; fdm = (fdm2d) sf_alloc(1,sizeof(*fdm)); fdm->free=free_; fdm->verb=verb_; fdm->nb=nb_; fdm->n1=sf_n(a1_); fdm->n2=sf_n(a2_); fdm->d1=sf_d(a1_); fdm->d2=sf_d(a2_); fdm->o1=sf_o(a1_); fdm->o2=sf_o(a2_); fdm->n1pad=sf_n(a1_)+2*fdm->nb; fdm->n2pad=sf_n(a2_)+2*fdm->nb; fdm->o1pad=sf_o(a1_)-fdm->nb*fdm->d1; fdm->o2pad=sf_o(a2_)-fdm->nb*fdm->d2; fdm->ompchunk=ompchunk_; return fdm; }
/*------------------------------------------------------------*/ abcone2d abcone2d_make(int nop, float dt, float** vp, bool free, fdm2d fdm) /*< init 2D ABC >*/ { abcone2d abc; int i1,i2; float d; abc = (abcone2d) sf_alloc(1,sizeof(*abc)); abc->free = free; abc->b1l = sf_floatalloc(fdm->n2pad); abc->b1h = sf_floatalloc(fdm->n2pad); abc->b2l = sf_floatalloc(fdm->n1pad); abc->b2h = sf_floatalloc(fdm->n1pad); for (i2=0;i2<fdm->n2pad;i2++) { d = vp[i2][ nop ] *dt/fdm->d1; abc->b1l[i2] = (1-d)/(1+d); d = vp[i2][fdm->n1pad-nop-1] *dt/fdm->d1; abc->b1h[i2] = (1-d)/(1+d); } for (i1=0;i1<fdm->n1pad;i1++) { d = vp[ nop ][i1] *dt/fdm->d2; abc->b2l[i1] = (1-d)/(1+d); d = vp[fdm->n2pad-nop-1][i1] *dt/fdm->d2; abc->b2h[i1] = (1-d)/(1+d); } return abc; }
/*------------------------------------------------------------*/ ompsft3d sf_ompsft3_init(int n, float o, float d, int ompnth) /*< origin shift (assumes no centering) >*/ { int ompith; int k,i; float w,s; ompsft3d sft; sft = (ompsft3d) sf_alloc(1,sizeof(*sft)); w=2.0*SF_PI/(n*d) * o; k=n/2; sft->www = sf_complexalloc2(n,ompnth); for(ompith=0; ompith<ompnth; ompith++) { for(i=0; i<n; i++) { sft->www[ompith][i]=sf_cmplx(1.0,0.0); } } for(ompith=0; ompith<ompnth; ompith++) { for(i=0; i<k; i++) { s = w * i; sft->www[ompith][i] = sf_cmplx(cosf(s),sinf(s)); s = w * (-k+i); sft->www[ompith][k+i] = sf_cmplx(cosf(s),sinf(s)); } } return sft; }
/*------------------------------------------------------------*/ sft3d sf_sft3_init(int n, float o, float d) /*< origin shift (assumes no centering) >*/ { int k,i; float w,s; sft3d sft; sft = (sft3d) sf_alloc(1,sizeof(*sft)); w=2.0*SF_PI/(n*d) * o; k=n/2; sft->www = sf_complexalloc(n); for(i=0; i<n; i++) { sft->www[i]=sf_cmplx(1.0,0.0); } for(i=0; i<k; i++) { s = w * i; sft->www[i] = sf_cmplx(cosf(s),sinf(s)); s = w * (-k+i); sft->www[k+i] = sf_cmplx(cosf(s),sinf(s)); } return sft; }
void heap_init (int n) /*< initialize with the maximum number of points >*/ { x = (hpoint **) sf_alloc (n+1,sizeof (hpoint *)); xn = x; x1 = x+1; }
grid2 grid2_init (int n1, float o1, float d1 /* first axis */, int n2, float o2, float d2 /* second axis */, float *slow2 /* data values [n1*n2] */, int order /* interpolation order */) /*< Initialize grid object >*/ { int i, j; float v, vgrad[2]; grid2 grd; grd = (grid2) sf_alloc(1,sizeof(*grd)); grd->n1 = n1; grd->o1 = o1; grd->d1 = d1; grd->n2 = n2; grd->o2 = o2; grd->d2 = d2; grd->pnt = sf_eno2_init (order != 0 ? order : 3, n1, n2); sf_eno2_set1 (grd->pnt, slow2); grd->vel = NULL; if (order <= 0) { grd->vel = sf_floatalloc3 (3, n1, n2); for (j = 0; j < n2; j++) { for (i = 0; i < n1; i++) { sf_eno2_apply (grd->pnt, i, j, 0., 0., &v, vgrad, BOTH); grd->vel[j][i][0] = slow2[j*n1 + i]; grd->vel[j][i][1] = 0.5*vgrad[0]/d1; grd->vel[j][i][2] = 0.5*vgrad[1]/d2; } } sf_eno2_close (grd->pnt); } return grd; }
/*------------------------------------------------------------*/ wexfft2d wexfft_init(wexcub3d cub, int n1_, int n2_) /*< initialize OMP fft >*/ { /*------------------------------------------------------------*/ wexfft2d fft; fft = (wexfft2d) sf_alloc(1,sizeof(*fft)); fft->n1 = n1_; fft->n2 = n2_; fft->ctmp1 = (kiss_fft_cpx*) sf_complexalloc(fft->n1); fft->ctmp2 = (kiss_fft_cpx*) sf_complexalloc(fft->n2); fft->forw1 = kiss_fft_alloc(fft->n1,0,NULL,NULL); fft->invs1 = kiss_fft_alloc(fft->n1,1,NULL,NULL); fft->forw2 = kiss_fft_alloc(fft->n2,0,NULL,NULL); fft->invs2 = kiss_fft_alloc(fft->n2,1,NULL,NULL); if (NULL == fft->forw2 || NULL == fft->invs2 || NULL == fft->forw1 || NULL == fft->invs1) sf_error("%s: KISS FFT allocation error",__FILE__); fft->fftscale = 1./sqrtf(fft->n1*fft->n2); return fft; }
/*------------------------------------------------------------*/ sponge sponge_make(fdm2d fdm) /*< init boundary sponge >*/ /* Sponge boundary conditions multiply incoming wavefields by smaller coefficients to attenuate the wavefield over time and space. The sponge coefficients need to deviate from 1 very gradually to ensure that there are no induced reflections caused by large impedance contrasts */ { sponge spo; int ib,nbp; float sb,fb; nbp = fdm->nb+fdm->nop; spo = (sponge)sf_alloc(1,sizeof(*spo)); spo->w = sf_floatalloc(nbp); sb = 4.0*nbp; for(ib=0; ib<nbp; ib++) { fb = ib/(sqrt(2.0)*sb); spo->w[ib] = exp(-fb*fb); } return spo; }
pt3d* pt3dalloc1( size_t n1) /*< alloc point3d 1-D vector >*/ { pt3d *ptr; ptr = (pt3d*) sf_alloc(n1,sizeof(pt3d)); return ptr; }
/*------------------------------------------------------------*/ fdm2d fdutil_init(bool verb_, bool free_, sf_axis az_, sf_axis ax_, int nb_, int ompchunk_) /*< init fdm utilities >*/ { fdm2d fdm; fdm = (fdm2d) sf_alloc(1,sizeof(*fdm)); fdm->free=free_; fdm->verb=verb_; fdm->nb=nb_; fdm->nz=sf_n(az_); fdm->nx=sf_n(ax_); fdm->dz=sf_d(az_); fdm->dx=sf_d(ax_); fdm->oz=sf_o(az_); fdm->ox=sf_o(ax_); fdm->nzpad=sf_n(az_)+2*fdm->nb; fdm->nxpad=sf_n(ax_)+2*fdm->nb; fdm->ozpad=sf_o(az_)-fdm->nb*fdm->dz; fdm->oxpad=sf_o(ax_)-fdm->nb*fdm->dx; fdm->ompchunk=ompchunk_; return fdm; }
map4 stretch4_init (int n1, float o1, float d1 /* regular axis */, int nd /* data samples */, float eps /* regularization */) /*< initialize >*/ { int i; map4 str; str = (map4) sf_alloc (1, sizeof(*str)); str->nt = n1; str->t0 = o1; str->dt = d1; str->nd = nd; str->eps = eps; str->x = sf_intalloc (nd); str->m = sf_boolalloc (nd); str->w = sf_floatalloc2 (4,nd); str->diag = sf_floatalloc (str->nt); for (i = 0; i < 3; i++) { str->offd[i] = sf_floatalloc (str->nt-1-i); } str->slv = sf_banded_init (str->nt,3); str->tslv = sf_spline4_init(str->nt); return str; }
fint1 fint1_init (int nw /* trace extension */, int n1 /* trace length */, int mute /* taper length */) /*< intialize single-function interpolation >*/ { fint1 fnt; float t; int it; fnt = (fint1) sf_alloc (1, sizeof (*fnt)); fnt->nw = nw; fnt->n1 = n1; fnt->spl = sf_floatalloc (n1+2*nw); fnt->slv = sf_spline4_init (n1+2*nw); fnt->nt = mute; if (mute > 0) { fnt->t = sf_floatalloc(mute); for (it=0; it < mute; it++) { t = sinf(0.5*SF_PI*(it+1.)/(mute+1.)); fnt->t[it]= t*t; } } fnt->ir = -1; return fnt; }
sf_upgrad sf_upgrad_init(int mdim /* number of dimensions */, const int *mm /* [dim] data size */, const float *d /* [dim] data sampling */) /*< initialize >*/ { sf_upgrad upg; int i; if (mdim > 3) sf_error("%s: dim=%d > 3",__FILE__,mdim); ndim = mdim; nn = mm; nt = 1; for (i=0; i < ndim; i++) { ss[i] = nt; nt *= nn[i]; dd[i] = 1.0/(d[i]*d[i]); } upg = (sf_upgrad) sf_alloc(1,sizeof(*upg)); upg->update = sf_ucharalloc2(2,nt); upg->ww = sf_floatalloc2(ndim+1,nt); upg->order = sf_intalloc(nt); return upg; }
geopar creategeo(void) /*< Create geometry used in RTM >*/ { geopar geop; geop = (geopar) sf_alloc(1, sizeof(*geop)); return geop; }
void tomo2_init (float*** rays, int *raylen, int nrays, float o1, float o2, float d1, float d2, int n1, int n2, interpolator interp, int nf_in) { int ir, id, i1, i2, nd; float x1, x2, rx; nf = nf_in; m1 = n1; m2 = n2; nr = nrays; rl = raylen; nxy = (int***) sf_alloc(nr,sizeof(int**)); mask = (bool**) sf_alloc(nr,sizeof(bool*)); w1 = (float***) sf_alloc(nr,sizeof(float**)); w2 = (float***) sf_alloc(nr,sizeof(float**)); for (ir = 0; ir < nr; ir++) { nd = rl[ir]; nxy[ir] = sf_intalloc2(2,nd); mask[ir] = sf_boolalloc(nd); w1[ir] = sf_floatalloc2(nf,nd); w2[ir] = sf_floatalloc2(nf,nd); for (id = 0; id < nd; id++) { rx = (rays[ir][id][0] - o1)/d1; i1 = (int) floor(rx + 1. - 0.5*nf); x1 = rx - floor(rx); rx = (rays[ir][id][1] - o2)/d2; i2 = (int) floor(rx + 1. - 0.5*nf); x2 = rx - floor(rx); if (i1 > - nf && i1 < n1 && i2 > - nf && i2 < n2) { mask[ir][id] = false; interp (x1, nf, w1[ir][id]); interp (x2, nf, w2[ir][id]); nxy[ir][id][0] = i1; nxy[ir][id][1] = i2; } else { mask[ir][id] = true; } } } }
/*------------------------------------------------------------*/ abcone3d abcone3d_make(int nop, float dt, float ***vv, bool free, fdm3d fdm) /*< init 3D ABC >*/ /*This absorbing boundary condition follows the work done in Absorbing Boundary Conditions , by Robert Clayton and Bjorn Engquist Which can be found at: http://sepwww.stanford.edu/public/docs/sep11/11_12_abs.html */ { abcone3d abc; int iz,ix,iy; float d; abc = (abcone3d) sf_alloc(1,sizeof(*abc)); abc->free = free; /* z */ abc->bzl = sf_floatalloc2(fdm->nxpad,fdm->nypad); abc->bzh = sf_floatalloc2(fdm->nxpad,fdm->nypad); /* x */ abc->bxl = sf_floatalloc2(fdm->nzpad,fdm->nypad); abc->bxh = sf_floatalloc2(fdm->nzpad,fdm->nypad); /* y */ abc->byl = sf_floatalloc2(fdm->nzpad,fdm->nxpad); abc->byh = sf_floatalloc2(fdm->nzpad,fdm->nxpad); for (iy=0;iy<fdm->nypad;iy++) { for (ix=0;ix<fdm->nxpad;ix++) { d = vv[iy][ix][ nop ] *dt/fdm->dz; abc->bzl[iy][ix] = (1-d)/(1+d); d = vv[iy][ix][fdm->nzpad-nop-1] *dt/fdm->dz; abc->bzh[iy][ix] = (1-d)/(1+d); } } for (iy=0;iy<fdm->nypad;iy++) { for (iz=0;iz<fdm->nzpad;iz++) { d = vv[iy][ nop ][iz] *dt/fdm->dx; abc->bxl[iy][iz] = (1-d)/(1+d); d = vv[iy][fdm->nxpad-nop-1][iz] *dt/fdm->dx; abc->bxh[iy][iz] = (1-d)/(1+d); } } for (ix=0;ix<fdm->nxpad;ix++) { for (iz=0;iz<fdm->nzpad;iz++) { d = vv[ nop ][ix][iz] *dt/fdm->dy; abc->byl[ix][iz] = (1-d)/(1+d); d = vv[fdm->nypad-nop-1][ix][iz] *dt/fdm->dy; abc->byh[ix][iz] = (1-d)/(1+d); } } return abc; }
int main(int argc, char* argv[]) { int n1, n2, i2, esize; off_t pos; struct skey *sorted; float *unsorted; char *trace, *header; sf_file in, head, out; sf_init (argc,argv); in = sf_input ("in"); out = sf_output ("out"); header = sf_getstring("head"); /* header file */ if (NULL == header) { header = sf_histstring(in,"head"); if (NULL == header) sf_error("Need head="); } head = sf_input(header); if (SF_FLOAT != sf_gettype(head)) sf_error("Need float header"); n2 = sf_filesize(head); unsorted = sf_floatalloc(n2); sorted = (struct skey*) sf_alloc(n2,sizeof(struct skey)); sf_floatread(unsorted,n2,head); for (i2 = 0; i2 < n2; i2++) { sorted[i2].key = unsorted[i2]; sorted[i2].pos = i2; } free (unsorted); sf_fileclose(head); qsort(sorted,n2,sizeof(struct skey),key_compare); if (!sf_histint(in,"n1",&n1)) n1=1; esize = sf_esize(in); n1 *= esize; trace = sf_charalloc(n1); sf_unpipe(in,((off_t) n1)*((off_t) n2)); sf_fileflush(out,in); sf_setform(in,SF_NATIVE); sf_setform(out,SF_NATIVE); pos = sf_tell(in); for (i2=0; i2<n2; i2++) { sf_seek(in,pos+(sorted[i2].pos)*n1,SEEK_SET); sf_charread(trace,n1,in); sf_charwrite(trace,n1,out); } exit(0); }
sf_eno sf_eno_init (int order /* interpolation order */, int n /* data size */) /*< Initialize interpolation object. >*/ { sf_eno ent; int i; ent = (sf_eno) sf_alloc(1,sizeof(*ent)); ent->order = order; ent->n = n; ent->diff = (float**) sf_alloc(order,sizeof(float*)); for (i = 0; i < order; i++) { ent->diff[i] = sf_floatalloc(n-i); } return ent; }