upgrad upgrad_init(int mdim /* number of dimensions */, const int *mm /* [dim] data size */, const float *d /* [dim] data sampling */) /*< initialize >*/ { 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 = (upgrad) sf_alloc(1,sizeof(*upg)); upg->update = sf_ucharalloc2(2,nt); upg->wt = sf_floatalloc2(ndim+1,nt); upg->wx = sf_floatalloc2(ndim+1,nt); upg->order = sf_intalloc(nt); return upg; }
void rgradient_init(char* type, int horder, int m1, int m2) /*< initialize >*/ { float **p; int i; order = horder; nf = 2*order+1; c = sf_floatalloc2(nf, 2); p = lphpoly(order, order, type); for(i=0; i<2*nf; i++) c[0][i] = p[0][i]; free(p[0]); free(p); mode = type[0]; n1 = m1; n2 = m2; b1 = sf_floatalloc2(n1, n2); b2 = sf_floatalloc2(n1, n2); g = sf_floatalloc3(n1*3, n2, nf); b = g[0]; memset(g[0][0], 0, n1*n2*nf*sizeof(float)); #ifdef _OPENMP omp_init(); #endif }
int main(int argc, char* argv[]) { int j, k, n, n2, i3, n3, iter, niter; float **a, *e, **v, s2; sf_file mat, val, eig; sf_init(argc,argv); mat = sf_input("in"); val = sf_output("out"); if (SF_FLOAT != sf_gettype(mat)) sf_error("Need float input"); if (!sf_histint(mat,"n1",&n)) sf_error("No n1= in input"); if (!sf_histint(mat,"n2",&n2) || n2 != n) sf_error("Need n1=n2 in input"); n3 = sf_leftsize(mat,2); sf_putint(val,"n2",1); if (!sf_getint("niter",&niter)) niter=10; a = sf_floatalloc2(n,n); e = sf_floatalloc(n); if (NULL != sf_getstring("eig")) { eig = sf_output("eig"); /* eigenvectors */ v = sf_floatalloc2(n,n); for (j=0; j < n; j++) { for (k=0; k < n; k++) { v[j][k] = (j==k)? 1.0:0.0; } } } else { eig = NULL; v = NULL; } jacobi_init(n); for (i3=0; i3 < n3; i3++) { sf_floatread(a[0],n*n,mat); for (iter=0; iter < niter; iter++) { s2 = 0.; for (j=0; j < n-1; j++) { for (k=j+1; k < n; k++) { s2 += jacobi(a,j,k,v); } } sf_warning("iter=%d s2=%g",iter+1,s2); } for (j=0; j < n; j++) { e[j]=a[j][j]; } sf_floatwrite(e,n, val); if (NULL != v) sf_floatwrite(v[0],n*n, eig); } exit(0); }
int main(int argc, char* argv[]) { int n1, n2, n3, i3; float **pp, **qq; sf_file in=NULL, out=NULL; sf_init(argc,argv); in = sf_input("in"); out = sf_output("out"); if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(in,"n2",&n2)) sf_error("No n2= in input"); n3 = sf_leftsize(in,2); pp = sf_floatalloc2(n1,n2); qq = sf_floatalloc2(n1,n2); for (i3=0; i3 < n3; i3++) { sf_floatread(pp[0],n1*n2,in); sf_sobel2(n1,n2,pp,qq); sf_floatwrite(qq[0],n1*n2,out); } exit(0); }
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; }
void fbdip_init(float rad, int m1, int m2, int *rect, int niter, float dip0, bool vb) /*< initialize >*/ { int n, nn[2]; n1 = m1; n2 = m2; verb = vb; u1 = sf_floatalloc2(n1, n2); u2 = sf_floatalloc2(n1, n2); u3 = sf_floatalloc2(n1, n2); u4 = sf_floatalloc2(n1, n2); u5 = sf_floatalloc2(n1, n2); p = sf_complexalloc2(n1, n2); r=rad; p0 = rad*cexpf(sf_cmplx(0, dip0)); if(rect[0]>0 && rect[1]>0) { n = n1*n2; nn[0] = n1; nn[1] = n2; sf_divn_init (2, n, nn, rect, niter, false); use_divn=true; }else use_divn=false; }
void inmo_init(const float* vel /* velocity */, const float* off /* offset */, int nh1 /* number of offsets */, float h0, float dh, int CDPtype, int ix, int nt1 /* time samples */, bool slow, float t0, float dt, float eps, bool half, int jump1 /* subsampling */) /*< initialization >*/ { int it, ih; float f, h, *coord; const int nw=4; nh = nh1; ns = nt1; jump = jump1; nt = (ns-1)*jump+1; dt = dt/jump; nmo = (map4*) sf_alloc(nh,sizeof(map4)); stretch = sf_floatalloc(nt); for (ih=0; ih < nh; ih++) { nmo[ih] = stretch4_init (nt, t0, dt, nt, eps); h = off[ih] + (dh/CDPtype)*(ix%CDPtype); if (half) h *= 2; h = h*h - h0*h0; for (it=0; it < nt; it++) { f = t0 + it*dt; if (slow) { f = f*f + h*vel[it]*vel[it]; } else { f = f*f + h/(vel[it]*vel[it]); } if (f < 0.) { stretch[it]=t0-10.*dt; } else { stretch[it] = sqrtf(f); } } stretch4_define (nmo[ih],stretch); } coord = sf_floatalloc(nt); for (it=0; it < nt; it++) { coord[it] = it; } spl = sf_spline_init(nw,ns); sf_int1_init (coord, 0.0, jump, ns, sf_spline_int, nw, nt, 0.0); free(coord); dense2 = sf_floatalloc2(nt,nh); sparse2 = sf_floatalloc2(ns,nh); }
int main(int argc, char* argv[]) { int n1, n2,o1,d1,d2,i1,i2,ix,iz; float ***dat,**sum; float sum1; sf_file in, out; /* Input and output files */ /* Initialize RSF */ sf_init(argc,argv); /* standard input */ in = sf_input("in"); /* standard output */ out = sf_output("out"); /* parameters from input file*/ if (SF_FLOAT != sf_gettype(in)) sf_error("Need float input"); if (!sf_histint(in,"o1",&o1)) sf_error("No o1= in input"); if (!sf_histint(in,"d1",&d1)) sf_error("No d1= in input"); if (!sf_histint(in,"d2",&d2)) sf_error("No d2= in input"); if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(in,"n2",&n2)) sf_error("No n2= in input"); if (!sf_histint(in,"n3",&n3)) sf_error("No n3= in input"); fprintf(stderr,"values: %d %d\n",n1,n2,n3); sum = sf_floatalloc2(n3,n3); dat = sf_floatalloc3 (n1,n2,n3); fprintf(stderr,"values: %d %d\n",n1,n2); dat = sf_floatalloc2 (n1,n2); for (ix=0; ix<n2; ++ix) { for (iz=0; iz<n1; ++iz) { dat[ix][iz]=0.0; } } sum1=0; fprintf(stderr,"values1: %f\n",sum1); sf_floatread(dat[0],n1*n2,in); //sum1=0; fprintf(stderr,"values1: %f\n",sum1); for (i2=o1; i2<n2; ++i2){ for (i1=o1; i1<n1; ++i1){ sum1 += dat[i2][i1]; } } fprintf(stderr,"values: %f\n",sum1); sum[0][0]=sum1; sf_floatwrite(sum[0],1*1,out); exit(0); }
int main(int argc, char* argv[]) { int i3, n3, ix, nx, iz, nz; int nx2, nz2, scalex, scalez; float dx, dz; float **a, **b; sf_file in, out; sf_init(argc, argv); in=sf_input("in"); out=sf_output("out"); if(!sf_getint("scalex", &scalex)) sf_error("Need scalex="); if(!sf_getint("scalez", &scalez)) sf_error("Need scalez="); if(!sf_histint(in, "n1", &nz)) sf_error("No n1= in input"); if(!sf_histfloat(in, "d1", &dz)) sf_error("No d1= in input"); if(!sf_histint(in, "n2", &nx)) sf_error("No n2= in input"); if(!sf_histfloat(in, "d2", &dx)) sf_error("No d2= in input"); nx2=(nx-1)*scalex+1; nz2=(nz-1)*scalez+1; n3=sf_leftsize(in, 2); sf_putint(out, "n1", nz2); sf_putfloat(out, "d1", dz/scalez); sf_putint(out, "n2", nx2); sf_putfloat(out, "d2", dx/scalex); a=sf_floatalloc2(nz, nx); b=sf_floatalloc2(nz2, nx2); for (i3=0; i3<n3; i3++){ sf_floatread(a[0], nz*nx, in); #pragma omp parallel for private(ix, iz) for(ix=0; ix<nx2; ix++){ for(iz=0; iz<nz2; iz++){ b[ix][iz]=0.; } } #pragma omp parallel for private(ix, iz) for(ix=0; ix<nx; ix++){ for(iz=0; iz<nz; iz++){ b[ix*scalex][iz*scalez]=a[ix][iz]; } } sf_floatwrite(b[0], nz2*nx2, out); } exit(0); }
int main(int argc, char*argv[]) { int n1, n2, n3,n4, i2, i3, i4, m2, m3; sf_file in, hor, out; float **u, **v, **h, o1, d1; char *interp; sinterp intp; sf_init(argc, argv); in = sf_input("in"); hor = sf_input("horizon"); out = sf_output("out"); if(!sf_histint(in, "n1", &n1)) sf_error("n1 needed in input"); if(!sf_histfloat(in, "o1", &o1)) o1=0.0; if(!sf_histfloat(in, "d1", &d1)) d1=1.0; if(!sf_histint(in, "n2", &n2)) sf_error("n2 needed in input"); if(!sf_histint(in, "n3", &n3)) n3=1; if(!sf_histint(in, "n4", &n4)) n4=1; if(!sf_histint(hor, "n1", &m2)) sf_error("n1 needed in horizon file"); if(!sf_histint(hor, "n2", &m3)) m3=1; if((interp=sf_getstring("interp")) ==NULL ) interp="linear"; /*< interpolation method: nearest, linear >*/ intp = sinterp_c2f(interp); if(n2!=m2 || n3!= m3) sf_error("horizon file not match"); sf_unshiftdim(in,out,1); u = sf_floatalloc2(n1, n2); v = sf_floatalloc2(n2, n3); h = sf_floatalloc2(n2, n3); sf_floatread(h[0], n3*n2, hor); for(i4=0; i4<n4; i4++) { for(i3=0; i3<n3; i3++) { sf_floatread(u[0], n1*n2, in); for(i2=0; i2<n2; i2++) v[i3][i2] = intp(u[i2], (h[i3][i2]-o1)/d1, n1); } sf_floatwrite(*v, n2*n3, out); } free(*u); free(u); free(*v); free(v); free(*h); free(h); }
int main(int argc,char*argv[]) { sf_file in, out; int i1, i2, j2, i3, n1, n2, n3, nf; float **u1, **u2, sigma, d2; sf_init(argc,argv); in = sf_input("in"); out = sf_output("out"); n3 = sf_leftsize(in, 2); if (!sf_histint(in, "n1", &n1)) sf_error("No n1= in input file"); if (!sf_histint(in, "n2", &n2)) sf_error("No n2= in input file"); if (!sf_getfloat("sigma", &sigma)) sigma=1.0; /* sigma */ if (!sf_getint("nf", &nf)) nf=100; /* frequency samples [0, 0.5] */ d2 = SF_PI/(nf-1); sf_putint(out, "n2", nf); sf_putfloat(out, "d2", 0.5/(nf-1)); dgauss_init(n1, 1.0/sigma); u1 = sf_floatalloc2(n1, n2); u2 = sf_floatalloc2(n1, nf); for (i3=0; i3<n3; i3++) { sf_floatread(u1[0], n1*n2, in); for(i1=0; i1<n1; i1++) { for (j2=0; j2<nf; j2++) for (i2=0; i2<n2; i2++) { u2[j2][i1] = u1[i2][i1] * dgauss_val(i2, d2*j2) * powf(0.5/SF_PI, i2); } } sf_floatwrite(u2[0], n1*nf, out); } free(u1[0]); free(u2[0]); free(u1); free(u2); dgauss_close(); exit(0); }
int main(int argc, char* argv[]) { int nt, nd; float dist; float **points, *point; kd_node tree, near; sf_file inp, out; sf_init(argc,argv); inp = sf_input("in"); out = sf_output("out"); if (SF_FLOAT != sf_gettype(inp)) sf_error("Need float input"); if (!sf_histint(inp,"n1",&nd)) sf_error("No n1= in input"); if (!sf_histint(inp,"n2",&nt)) sf_error("No n2= in input"); sf_putint(out,"n2",1); points = sf_floatalloc2(nd,nt); sf_floatread(points[0],nd*nt,inp); tree = kd_tree(points,nt,nd); point = sf_floatalloc(nd); if (!sf_getfloats("point",point,nd)) sf_error("Need point="); dist = SF_HUGE; kd_nearest(tree, point, 0, nd, &near, &dist); sf_floatwrite(kd_coord(near),nd,out); exit(0); }
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; }
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; }
void warp3_init(int n1_in, float o1, float d1, int n2_in, float o2, float d2, int n3_in, float o3, float d3 /* output grid */, int nt, int ny_in, int nx_in /* input grid */, float eps /* regularization */) /*< initialize >*/ { n1 = n1_in; n2 = n2_in; n3 = n3_in; ny = ny_in; nx = nx_in; map1 = stretch4_init (n1, o1, d1, nt, eps); trace1 = sf_floatalloc(n1); trace2 = sf_floatalloc2(n2,n3); warp2_init(n2,o2,d2, n3,o3,d3, ny,nx,eps); str2 = sf_floatalloc3(ny,nx,n1); str3 = sf_floatalloc3(ny,nx,n1); slice1 = sf_floatalloc3(ny,nx,n1); }
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; } } } }
int main(int argc, char* argv[]) { int n1, n2, box1,box2,klo1,khi1,klo2,khi2,kmid1,kmid2; float **dat,**nsum,**neg,sumA; sf_file in, out; /* Input and output files */ /* Initialize RSF */ sf_init(argc,argv); /* standard input */ in = sf_input("in"); /* standard output */ out = sf_output("out"); /* check that the input is float */ if (SF_FLOAT != sf_gettype(in)) sf_error("Need float input"); /* n1 is the fastest dimension (trace length) */ if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); /* leftsize gets n2*n3*n4*... (the number of traces) */ n2 = sf_leftsize(in,1); /* parameter from the command line (i.e. box1=50 box2=50 ) */ if (!sf_getfloat("box1",&box1)) sf_error("Need box1="); if (!sf_getfloat("box2",&box2)) sf_error("Nedd box2="); /* allocate floating point array */ dat= sf_floatalloc2 (n1,n2); /* initialise the size of the searching box*/ klo1=0; khi1=box1; klo2=0; khi2=box2; for (int klo1=0, int khi1=box1; khi1<=xmax; ++klo1,++khi1) /* loop over traces */ for (i2=0; i2 < n2; i2++) { /* read a trace */ sf_floatread(trace,n1,in); /* loop over samples */ for (i1=0; i1 < n1; i1++) { if (trace[i1] > clip) trace[i1]= clip; else if (trace[i1] < -clip) trace[i1]=-clip; } /* write a trace */ sf_floatwrite(trace,n1,out); } exit(0); }
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); }
int main(int argc, char* argv[]) { bool adj, verb; int n1, n2, n12, n3, i3, order, ns; float *input, *smooth, **slope, eps; sf_file in, out, dip; sf_init(argc,argv); in = sf_input("in"); dip = sf_input("dip"); out = sf_output("out"); if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(in,"n2",&n2)) sf_error("No n2= in input"); n3 = sf_leftsize(in,2); n12 = n1*n2; if (!sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ if (!sf_getint("ns",&ns)) ns=0; /* smoothing radius */ if (!sf_getbool("adj",&adj)) adj=false; /* adjoint flag */ if (!sf_getfloat("eps",&eps)) eps=0.01; /* regularization */ if (!sf_getint("order",&order)) order=1; /* accuracy order */ input = sf_floatalloc(n12); smooth = sf_floatalloc(n12); slope = sf_floatalloc2(n1,n2); pwsmooth_init(ns, n1, n2, order, eps); for (i3=0; i3 < n3; i3++) { if (verb) sf_warning("slice %d of %d;",i3+1,n3); sf_floatread(input,n12,in); sf_floatread(slope[0],n12,dip); pwsmooth_set(slope); if (adj) { pwsmooth_lop(true,false,n12,n12,smooth,input); } else { pwsmooth_lop(false,false,n12,n12,input,smooth); } sf_floatwrite(smooth,n12,out); } if (verb) sf_warning("."); exit(0); }
/*------------------------------------------------------------*/ ofg2d offgrid_init(fdm2d fdm) /*< init off-grid interpolation >*/ { ofg2d ofg; ofg = (ofg2d) sf_alloc(1,sizeof(*ofg)); ofg->tt = sf_floatalloc2(fdm->nzpad,fdm->nxpad); return ofg; }
sf_lsint2 sf_lsint2_init (int n1, int n2 /* data dimensions */) /*< Initialize interpolation object >*/ { sf_lsint2 pnt; pnt = (sf_lsint2) sf_alloc(1,sizeof(*pnt)); pnt->n1 = n1; pnt->n2 = n2; pnt->data2 = sf_floatalloc2(n1,n2); return pnt; }
int main(int argc, char*argv[]) { sf_file in, out; int nf, n1, n2, n3, m, n; int i3; float **wav, ****fb; char *interp; sf_init(argc, argv); in = sf_input("in"); out = sf_output("out"); if (SF_FLOAT != sf_gettype(in)) sf_error("Need float type"); if (!sf_histint(in, "n1", &n1)) sf_error("No n1= in input"); if (!sf_histint(in, "n2", &n2)) sf_error("No n2= in input"); n3 = sf_leftsize(in, 2); sf_shiftdim2(in,out,2); if(!sf_getint("m", &m)) m=1; /* b[-m, ... ,n] */ if(!sf_getint("n", &n)) n=1; /* b[-m, ... ,n] */ if ((interp=sf_getstring("interp"))==NULL) interp="maxflat"; /* interpolation method: maxflat lagrange bspline */ nf = m+n+1; wav = sf_floatalloc2(n1,n2); fb = sf_floatalloc4(n1, n2, nf, nf); sf_putint(out, "n3", nf); sf_putint(out, "n4", nf); sf_putfloat(out, "o3", 0); sf_putfloat(out, "d3", 1); sf_putfloat(out, "o4", 0); sf_putfloat(out, "d4", 1); fbank_init(m, n, interp); for(i3=0; i3<n3; i3++) { sf_floatread(wav[0], n1*n2, in); fbank2(n1, n2, wav, fb); sf_floatwrite(fb[0][0][0], n1*n2*nf*nf, out); } fbank_close(); return 0; }
/*------------------------------------------------------------*/ ssroperator3d zomig3_init(cub3d cub) /*< initialize >*/ { ssroperator3d weop; weop = (ssroperator3d) sf_alloc(1,sizeof(*weop)); weop->ww = sf_complexalloc3(cub->amx.n,cub->amy.n,cub->ompnth); weop->qq = sf_floatalloc2 (cub->amx.n,cub->amy.n); return weop; }
void phs_init(axa am_, axa ah_, axa aw_, axa az_) /*< initialize >*/ { int im,ih; int jm,jh; float km,kh,k; am = am_; ah = ah_; aw = aw_; az = az_; X2K(am,bm,0); X2K(ah,bh,0); fft2_init(bm.n,bh.n); wk = sf_complexalloc2(bm.n,bh.n); /* precompute wavenumbers */ ks= sf_floatalloc2(bm.n,bh.n); kr= sf_floatalloc2(bm.n,bh.n); for (im=0; im<bm.n; im++) { jm = KMAP(im,bm.n); km = bm.o + jm*bm.d; for (ih=0; ih<bh.n; ih++) { jh = KMAP(ih,bh.n); kh = bh.o + jh*bh.d; k = 0.5*(km-kh); ks[ih][im] = k*k; /* ks^2 */ k = 0.5*(km+kh); kr[ih][im] = k*k; /* kr^2 */ } } }
int main(int argc, char* argv[]) { int n, nx, nz; float dx, dz; float ** t0, **tinit, **t; sf_file so1, so2, so3; char * fname = 0; sf_init(argc,argv); so1 = sf_output("out"); so2 = sf_output("init"); so3 = sf_output("final"); if (!sf_getint("N",&n)) sf_error("No N= "); nx = nz = n; dx = dz = 1.f / (n - 1); putf(so1, nx, nz, dx, dz); putf(so2, nx, nz, dx, dz); putf(so3, nx, nz, dx, dz); fname = sf_getstring ("sample"); t0 = sf_floatalloc2(nz,nx); tinit = sf_floatalloc2(nz,nx); t = sf_floatalloc2(nz,nx); // sprintf(fname,"sample%-3d",S.nx); read4file(fname, t0, tinit, t, nx, nz); sf_floatwrite(t0[0], nx*nz, so1); sf_floatwrite(tinit[0], nx*nz, so2); sf_floatwrite(t[0], nx*nz, so3); sf_close(); exit(0); }
int main(void) { int i, j, m, n, order=6, n1x=11, n1y=11, n2x=31, n2y=31; /*for 2D eno, order must be less than 7, or ng=2*(order-1) is too big */ float **a, **a1, **a2, x, y, f1; /* a is reference data, a1 is true data, a2 is interpolated data. */ sf_eno2 map; a=sf_floatalloc2(n1x,n1y); /*n1x and n1y are original total grid points*/ a1=sf_floatalloc2(n2x,n2y);/*n2x and n2y are interpolated total grid points*/ a2=sf_floatalloc2(n2x,n2y); for(i=0;i<n1x;i++) for(j=0;j<n1y;j++) a[j][i]=sinf(SF_PI/100*i*j)+cosf(SF_PI/100*i*j); /* Calculate original data point value. */ for(i=0;i<n2x;i++) for(j=0;j<n2y;j++) {a1[j][i]=sinf(SF_PI/100*(0+1.0/3*i)*(0+1.0/3*j))+cosf(SF_PI/100*(0+1.0/3*i)*(0+1.0/3*j));} /* Calculate true fine-grid data point value. */ map = sf_eno2_init(order,n1x,n1y); sf_eno2_set (map,a); sf_warning("hello1"); for(i=0;i<n2x;i++) for(j=0;j<n2y;j++) { x=(0+1.0/3*i-0)/1; y=(0+1.0/3*j-0)/1; m=x; /* m is grid location in x direction */ n=y; /* n is grid location in y direction */ x-=m; /* x is offset from grid location m */ y-=n; /* y is offset from grid location n */ sf_eno2_apply (map, m, n, x, y, &a2[j][i], &f1, FUNC); /* Interpolate fine-grid data point. f1 is the derivative sequence. FUNC is a flag value for eno interpolation */ } sf_warning("hello2"); for(i=0;i<n2x;i++) for(j=0;j<n2y;j++) {sf_warning("Interpolation comparison: True[%d][%d]=%f, Inter[%d][%d]=%f",j,i,a1[j][i],j,i,a2[j][i]);} exit(0); }
int main(int argc, char* argv[]) { int nt, nx, ntx, n2, n3, next; float v0, v1, dt, dx, t0, kur; float **data; sf_file inp, out; sf_init(argc,argv); inp = sf_input("in"); out = sf_output("out"); if (SF_FLOAT != sf_gettype(inp)) sf_error("Need float input"); if (!sf_histint(inp,"n1",&nt)) sf_error("No n1= in input"); if (!sf_histfloat(inp,"d1",&dt)) sf_error("No d1= in input"); if (!sf_histfloat(inp,"o1",&t0)) t0=0.; if (!sf_histint(inp,"n2",&nx)) sf_error("No n2= in input"); if (!sf_histfloat(inp,"d2",&dx)) sf_error("No d2= in input"); ntx = nt*nx; if (!sf_getfloat("v0",&v0)) v0=SF_EPS; /* initial velocity */ if (!sf_getfloat("v",&v1)) sf_error("Need v="); /* final velocity */ if (!sf_getint("pad",&n2)) n2=nt; /* padding for stretch */ if (!sf_getint("pad2",&n3)) n3=2*kiss_fft_next_fast_size((n2+1)/2); /* padding for FFT */ if (!sf_getint("extend",&next)) next=4; /* trace extension */ velcon_init(nt,nx,dt,dx,t0,n2,n3,next); data = sf_floatalloc2(nt,nx); sf_floatread(data[0],ntx,inp); kur = kurtosis(ntx,data[0]); sf_warning("kurtosis before: %g",kur); velcon(data,v0,v1); kur = kurtosis(ntx,data[0]); sf_warning("kurtosis after: %g",kur); sf_floatwrite(data[0],ntx,out); exit(0); }
/*------------------------------------------------------------*/ 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; }
omni2 opwd2_init(int nw /* filter order */, int nx, int ny /* data size */, float *p1, float *p2 /* dip [ny][nx] */) /*< Initialize >*/ { omni2 ap; ap = (omni2) sf_alloc(1,sizeof(*ap)); ap->nw = nw; ap->nx = nx; ap->ny = ny; ap->p1 = p1; ap->p2 = p2; ap->flt = sf_floatalloc(2*nw+1); ap->t1 = sf_floatalloc2(nx,ny); ap->t2 = sf_floatalloc2(nx,ny); apfilt_init(nw); return ap; }
void curv2_init(int mf, int nf, char* interp, int m1, int m2, int niter) /*< initialize >*/ { int i1; m = mf; n = nf; c = lphpoly(m, n, interp); b1 = c[1]+m; b2 = c[2]+m; for(i1=-m; i1<=n; i1++) b2[i1] /= 2; n1 = m1; n2 = m2; iter = niter; ut = sf_floatalloc2(n1, n2); ux = sf_floatalloc2(n1, n2); u2x2 = sf_floatalloc2(n1, n2); u2tx = sf_floatalloc2(n1, n2); }