void sf_putint (sf_file file, const char* key, int par) /*< put an int parameter to a file >*/ { char val[256]; if (NULL == file->dataname) sf_warning("%s: putint to a closed file",__FILE__); snprintf(val,256,"%d",par); sf_simtab_enter (file->pars,key,val); }
void hhimc_init(axa ahx_, axa ahy_, axa ahz_ ) /*< initialize prestack IC >*/ { ahx = ahx_; ahy = ahy_; ahz = ahz_; LOx = floor(ahx.o/ahx.d); HIx = LOx + ahx.n; LOy = floor(ahy.o/ahy.d); HIy = LOy + ahy.n; LOz = floor(ahz.o/ahz.d); HIz = LOz + ahz.n; sf_warning("LOx=%d HIx=%d",LOx,HIx); sf_warning("LOy=%d HIy=%d",LOy,HIy); sf_warning("LOz=%d HIz=%d",LOz,HIz); }
int main (int argc, char *argv[]) { int m, k, l, seed; sf_file bshuffle,ashuffle; sf_axis ax,at,ap,av; int nx,nt,np,nv,iteration,*a1, *a2; float ***bsh, ***bsh2; sf_init(argc,argv); bshuffle=sf_input("in"); ashuffle=sf_output("out"); if (!sf_getint("iteration",&iteration)) iteration=1; if (!sf_getint("seed",&seed)) seed=2012; at=sf_iaxa( bshuffle,1); nt=sf_n(at); ax=sf_iaxa( bshuffle,3); nx=sf_n(ax); ap=sf_iaxa( bshuffle,2); np=sf_n(ap); av=sf_iaxa( bshuffle,4); nv=sf_n(av); bsh=sf_floatalloc3(nt,np,nx); bsh2=sf_floatalloc3(nt,np,nx); a1=sf_intalloc(np); a2=sf_intalloc(np); sf_warning("ntpx=%d",nt*np*nx); srand(seed); for (m=0; m<np; m++) { a1[m]=rand(); } bubble(a1, a2, np); for (k=0; k<nv; k++) { sf_floatread(bsh[0][0],nt*np*nx,bshuffle); for(l=0; l<nx; l++) { for (m=0; m<np; m++) { memcpy(bsh2[l][m], bsh[l][a2[m]], nt*sizeof(float)); } } sf_floatwrite(bsh2[0][0],nt*np*nx,ashuffle); } free(bsh[0][0]); free(bsh[0]); free(bsh); free(bsh2[0][0]); free(bsh2[0]); free(bsh2); free(a1); free(a2); exit (0); }
int mcfft3_init(int pad1 /* padding on the first axis */, int nx, int ny, int nz /* input data size */, int *nx2, int *ny2, int *nz2 /* padded data size */, int *n_local, int *o_local /* local size & start */) /*< initialize >*/ { int cpuid; MPI_Comm_rank(MPI_COMM_WORLD, &cpuid); if (threads_ok) threads_ok = fftwf_init_threads(); fftwf_mpi_init(); if (false) sf_warning("Using threaded FFTW3! \n"); if (threads_ok) fftwf_plan_with_nthreads(omp_get_max_threads()); /* axis 1 */ nk = n1 = kiss_fft_next_fast_size(nx*pad1); /* axis 2 */ n2 = kiss_fft_next_fast_size(ny); /* axis 3 */ n3 = kiss_fft_next_fast_size(nz); alloc_local = fftwf_mpi_local_size_3d(n3, n2, n1, MPI_COMM_WORLD, &local_n0, &local_0_start); //cc = sf_complexalloc3(n1,n2,n3); cc = sf_complexalloc(alloc_local); cfg = fftwf_mpi_plan_dft_3d(n3,n2,n1, (fftwf_complex *) cc, (fftwf_complex *) cc, MPI_COMM_WORLD, FFTW_FORWARD, FFTW_MEASURE); icfg = fftwf_mpi_plan_dft_3d(n3,n2,n1, (fftwf_complex *) cc, (fftwf_complex *) cc, MPI_COMM_WORLD, FFTW_BACKWARD, FFTW_MEASURE); if (NULL == cfg || NULL == icfg) sf_error("FFTW failure."); *nx2 = n1; *ny2 = n2; *nz2 = n3; *n_local = (int) local_n0; *o_local = (int) local_0_start; wt = 1.0/(n3*n2*n1); return (nk*n2*n3); }
void sf_putstring (sf_file file, const char* key,const char* par) /*< put a string parameter to a file >*/ { char *val; if (NULL == file->dataname) sf_warning("%s: putstring to a closed file",__FILE__); val = (char*) alloca(strlen(par)+3); sprintf(val,"\"%s\"",par); sf_simtab_enter (file->pars,key,val); }
static void checktree( int ind, const char * str ) { int k1, k2, k, i,i1=0,i2=0; for( k=1; k<=count; k++ ) { k1=k*2; k2=k1+1; i=*(r+k); if( k1 <= count ) { i1=*(r+k1); if( *(t0+i) > *(t0+i1) ) { i=*(r+k); sf_warning("%s",str); sf_warning("at updating the point (%i, %i)=%i",ind%nx,ind/nx,ind); sf_warning(" parent: (%i, %i)=%i, %.8e",i%nx,i/nx,i, *(t0+i)); sf_error("children: %i, %.8e\t %i, %.8e",i1,*(t0+i1),i2,*(t0+i2)); } } if( k2 <= count ) { i2=*(r+k2); if( *(t0+i) > *(t0+i2) ) { i=*(r+k); sf_warning("%s",str); sf_warning("at updating the point (%i, %i)=%i",ind%nx,ind/nx,ind); sf_warning("parent: (%i, %i)=%i, .%.8e",i%nx,i/nx,i,*(t0+i)); sf_error("children: %i, %.8e\t %i, %.8e",i1,*(t0+i1),i2,*(t0+i2)); } } } }
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); }
void wavmod_shot(sf_file dat, sf_file wfl, int ns, int *ps, float **ws) /*< shot modelling >*/ { int it, ig, is; int i1, n1, n2, n3; float *p; n1 = sf_n(vel->z); n2=1; n3=1; if(vel->nd >= 2) n2 = sf_n(vel->x); if(vel->nd >= 3) n3 = sf_n(vel->y); memset(owv, 0, nxyz*sizeof(float)); memset(wav, 0, nxyz*sizeof(float)); memset(nwv, 0, nxyz*sizeof(float)); memset(ud, 0, nxyz*sizeof(float)); for (it=0; it < nt; it++) { fd3_laplacian(n1, n2, n3, wav, ud); for (is=0; is<ns; is++) ud[ps[is]] += ws[is][it]; #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,n1) \ private(i1) #endif for(i1=0; i1<nxyz; i1++) nwv[i1] = 2.0*wav[i1] - owv[i1] + ud[i1]*vel->p[i1]; p = owv; owv = wav; wav = nwv; nwv = p; if(it >= st && (it-st)%jt==0) { #ifdef _OPENMP #pragma omp parallel for \ schedule(dynamic,8) \ private(ig) #endif for(ig=0; ig<ng; ig++) data[ig][(it-st)/jt] = wav[pg[ig]]; } if(wfl!=NULL && it>=st && (it-st)%jtm == 0) /* wave */ sf_floatwrite(wav, nxyz, wfl); if(verb) sf_warning("%d of %d;", it, nt); } /* output seismic data */ sf_floatwrite(data[0], ntj*ng, dat); }
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); }
int cfft2_init(int pad1 /* padding on the first axis */, int nx, int ny /* input data size */, int *nx2, int *ny2 /* padded data size */, int *n_local, int *o_local /* local size & start */, MPI_Comm comm) /*< initialize >*/ { if (threads_ok) threads_ok = fftwf_init_threads(); fftwf_mpi_init(); if (false) sf_warning("Using threaded FFTW3! \n"); if (threads_ok) fftwf_plan_with_nthreads(omp_get_max_threads()); nk = n1 = kiss_fft_next_fast_size(nx*pad1); n2 = kiss_fft_next_fast_size(ny); alloc_local = fftwf_mpi_local_size_2d(n2, n1, comm, &local_n0, &local_0_start); //cc = sf_complexalloc2(n1,n2); //dd = sf_complexalloc2(nk,n2); cc = sf_complexalloc(alloc_local); dd = sf_complexalloc(alloc_local); cfg = fftwf_mpi_plan_dft_2d(n2,n1, (fftwf_complex *) cc, (fftwf_complex *) dd, comm, FFTW_FORWARD, FFTW_MEASURE); icfg = fftwf_mpi_plan_dft_2d(n2,n1, (fftwf_complex *) dd, (fftwf_complex *) cc, comm, FFTW_BACKWARD, FFTW_MEASURE); if (NULL == cfg || NULL == icfg) sf_error("FFTW failure."); *nx2 = n1; *ny2 = n2; *n_local = (int) local_n0; *o_local = (int) local_0_start; wt = 1.0/(n1*n2); return (nk*n2); }
void rweone_psc_coef( float **aa, float **bb, float **a0, float **b0) /*< PSC coefficients >*/ { float tt,tt2, *tb; int ii,ir,it,ig; float boa, boa2; float aoa; float bob; if(verb) sf_warning("compute PSC coef"); /* find max(b0) */ tb=sf_floatalloc (ar.n*at.n); ii=0; for(it=0;it<at.n;it++) { for(ir=0;ir<ar.n;ir++) { tb[ii] = b0[it][ir]; ii++; } } tt = SF_ABS(sf_quantile(ar.n*at.n-1,ar.n*at.n,tb)); tt2= tt*tt; free(tb); for(it=0;it<at.n;it++) { for(ir=0;ir<ar.n;ir++) { boa = ( b0[it][ir]/tt ) / a0[it][ir]; boa2=boa*boa; for(ig=0;ig<ag.n;ig++) { aoa = aa[it][ig]/a0[it][ir]; bob = bb[it][ig]/b0[it][ir]; m0[it][ir][ig] = 1 / tt2; n0[it][ir][ig] = a0[it][ir] * boa2 * (c1*(aoa-1.) - (bob-1.)); r0[it][ir][ig] = 3 * c2 * boa2; m0[it][ir][ig] *= kmu; n0[it][ir][ig] *= knu; r0[it][ir][ig] *= kro; } } } }
int main(int argc, char* argv[]) { bool verb; int j, k, n, n2, i3, n3, iter, niter; sf_complex **a=NULL, *e=NULL; float s2; sf_file mat=NULL, val=NULL; sf_init(argc,argv); mat = sf_input("in"); val = sf_output("out"); if (SF_COMPLEX != sf_gettype(mat)) sf_error("Need complex 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; if (!sf_getbool("verb",&verb)) verb=false; a = sf_complexalloc2(n,n); e = sf_complexalloc(n); jacobi2_init(n,verb); for (i3=0; i3 < n3; i3++) { sf_complexread(a[0],n*n,mat); for (iter=0; iter < niter; iter++) { s2 = 0.; for (j=0; j < n; j++) { for (k=0; k < n; k++) { s2 += jacobi2(a,n,j,k); } } sf_warning("iter=%d s2=%g",iter+1,s2); } for (j=0; j < n; j++) { e[j]=a[j][j]; } sf_complexwrite(e,n, val); } exit(0); }
int getnumpars(const char* key) /*< get number of pars >*/ { char* par; int numpars=0; sf_warning("in getnumpars call sf_getstring key=%s\n",key); if(NULL==(par=sf_getstring(key)))return 0; numpars=counttokens(par,","); fprintf(stderr,"free(par)\n"); free(par); return numpars; }
void sf_putfloats (sf_file file, const char* key, const float* par, size_t n) /*< put a float array of size n parameter to a file >*/ { int i; char val[1024], *v; if (NULL == file->dataname) sf_warning("%s: putfloats to a closed file",__FILE__); v = val; for (i=0; i < (int) n-1; i++) { v += snprintf(v,1024,"%g,",par[i]); } snprintf(v,1024,"%g",par[n-1]); sf_simtab_enter (file->pars,key,val); }
int main (int argc, char* argv[]) { int i,n1,n2,n22,n; float *A, *x, *d; bool verb; sf_file in, rhs, out; sf_init (argc,argv); in = sf_input("in"); rhs= sf_input("rhs"); out = sf_output("out"); if (SF_FLOAT != sf_gettype(in)) sf_error("Need float"); if(!sf_histint(in,"n1",&n1)) sf_error("No n1 in input matrix!"); if(!sf_histint(in,"n2",&n2)) sf_error("No n2 in input matrix!"); if(!sf_histint(rhs,"n2",&n22))sf_error("No n2 in input vector!"); if(!sf_getbool("verb",&verb)) verb=false; if((n1!=n2) || (n1!=n22)) sf_error("Dimension mistake!"); n=n1; x = sf_floatalloc(n); A=sf_floatalloc(n*n); d=sf_floatalloc(n); sf_floatread(A,n*n,in); sf_floatread(d,n,rhs); trid_init(n, A); trid_solve(d, x); if(verb) { for(i=0;i<n;i++) sf_warning("x[%d]=%f",i+1,x[i]); } sf_putint(out,"n2",n); sf_putint(out,"n1",1); sf_floatwrite(x,n,out); trid_close(); free(A); free(d); free(x); exit(0); }
void ceig(int niter /* number of iterations */, float tol /* tolerance */, int m /* effective matrix size */, sf_complex** a /* [n][n] matrix */, sf_complex *e /* [n] eigenvalues */) /*< find eigenvalues >*/ { int iter, j, k, info; float s2,s0=1.; if (niter > 0) { /* Jacobi iterations */ for (iter=0; iter < niter; iter++) { s2 = 0.; for (j=0; j < m; j++) { for (k=0; k < m; k++) { s2 += jacobi2(a,m,j,k); } } if (verb) sf_warning("iter=%d s2=%g",iter+1,s2); if (0==iter) { s0 = s2; } else { if (s2 <= s0*tol) break; } } for (j=0; j < m; j++) { e[j]=a[j][j]; } } else { for (j=0; j < m; j++) { for (k=0; k < m; k++) { b[k+j*m] = a[j][k]; } } #ifdef SF_HAS_LAPACK cgeev_( "N", "N", &m, b, &m, e, work, &n2, work, &n2, work, &n2, rwork, &info ); if (info) sf_error("cgeev_ failed"); #else sf_error("No LAPACK"); #endif } for (j=m; j < n-1; j++) { e[j]=sf_cmplx(0.,0.); } }
vel_t *clone_vel(float ***vel, int nz, int nx, int ny, float oz, float ox, float oy, float dz, float dx, float dy, float w0, float qfact) { vel_t *v = malloc(sizeof *v); v->n1 = nz; v->n2 = nx; v->n3 = ny; v->o1 = oz; v->o2 = ox; v->o3 = oy; v->d1 = dz; v->d2 = dx; v->d3 = dy; v->dat = sf_floatalloc3(nz, nx, ny); memcpy(v->dat[0][0], vel[0][0], nz*nx*ny*sizeof(float)); v->vgamma = sf_floatalloc3(1,1,1); gs_w0 = w0; gs_qfact= qfact; gs_gamma = 1.0/SF_PI*atan(2*SF_PI/qfact); sf_warning("gs_gamma: %f", gs_gamma); return v; }
struct shot_image_par_type shot_image_grab_par(void) /*< initialize >*/ { struct shot_image_par_type image_par; float min_x,max_x,min_y,max_y; int nhx,nhy,ihx; if (!sf_getint("nhx",&nhx) ) nhx=1; if (!sf_getint("nhy",&nhy) ) nhy=1; if (!sf_getfloat("image_min_x",&min_x)) min_x=1000.0; if (!sf_getfloat("image_max_x",&max_x)) max_x=10000.0; if (!sf_getfloat("image_min_y",&min_y)) min_y=0.0; if (!sf_getfloat("image_max_y",&max_y)) max_y=0.0; image_par.nhx=nhx; image_par.nhy=nhy; image_par.min_x=min_x; image_par.max_x=max_x; image_par.min_y=min_y; image_par.max_y=max_y; image_par.sincx_table=sf_floatalloc(8*2001); for(ihx=0;ihx<2001;ihx++) mksinc((float)(ihx)*0.0005,8,image_par.sincx_table+ihx*8); sf_warning("Image: minx=%f maxx=%f\n",image_par.min_x,image_par.max_x); return image_par; }
void distance (int np /* number of points */, float **points /* point coordinates [np][3] */, float* dist /* distance */, float* v /* slowness squared */, int* in /* in/front/out flag */, int n3,int n2,int n1 /* dimensions */, float o3,float o2,float o1 /* origin */, float d3,float d2,float d1 /* sampling */, int order /* accuracy order (1,2,3) */) /*< Run fast marching eikonal solver >*/ { float d[3], o[3], *p; int n[3], npoints, i; n[0] = n1; o[0] = o1; d[0] = d1; n[1] = n2; o[1] = o2; d[1] = d2; n[2] = n3; o[2] = o3; d[2] = d3; sf_pqueue_start(); sf_neighbors_init (in, d, n, order, dist); for (npoints = sf_neighbors_distance (np, v, points, d, o); npoints > 0; npoints -= sf_neighbours(i)) { /* Pick smallest value in the NarrowBand mark as good, decrease points_left */ /* sf_warning("npoints=%d",npoints); */ p = sf_pqueue_extract(); if (p == NULL) { sf_warning("%s: heap exausted!",__FILE__); break; } i = p - dist; in[i] = SF_IN; } }
void rweone_xfd_coef( float **aa, float **bb) /*< XFD coefficients >*/ { int it,ig; if(verb) sf_warning("compute XFD coef"); for(it=0;it<at.n;it++) { for(ig=0;ig<ag.n;ig++) { m0[it][0][ig] = 1.; n0[it][0][ig] = - c1 * (bb[it][ig]*bb[it][ig]) / aa[it][ig]; r0[it][0][ig] = c2 * (bb[it][ig]*bb[it][ig]) / (aa[it][ig] * aa[it][ig]); m0[it][0][ig] *= kmu; n0[it][0][ig] *= knu; r0[it][0][ig] *= kro; } } }
int main(int argc, char* argv[]) { int i1, i2, n1,n2,n3,n12; float s=0, *pp1, *pp2; sf_file inp1, inp2, dif; sf_init(argc,argv); inp1 = sf_input("in"); inp2 = sf_input("match"); dif = sf_output("out"); sf_putfloat(dif,"o2",0); sf_putfloat(dif,"o1",0); sf_putint(dif,"n1",1); sf_putint(dif,"n2",1); if (!sf_histint(inp1,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(inp1,"n2",&n2)) sf_error("No n2= in input"); if (!sf_histint(inp1,"n3",&n3)) n3=1; n2 = sf_leftsize(inp1,1); /* left dimensions after the first one */ n12 = n1*n2; if (n3!=1) {sf_putint(dif,"n3",1); sf_putint(dif,"d3",1); } pp1 = sf_floatalloc(n12); pp2 = sf_floatalloc(n12); sf_floatread(pp1,n12,inp1); sf_floatread(pp2,n12,inp2); for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1; i1++) { s = s + pow((pp1[i2*n1+i1]-pp2[i2*n1+i1]),2); } } sf_warning("The difference is %f", s ); sf_floatwrite(&s,1,dif); exit(0); }
static void qp_lf(void) /* Lax-Friedrichs algorithm */ { int i,k=0,ind; const float lam=ht/(hx*hx); float ff,qq,/* f0,f1, */ f2,f3,q0,q1,q2,q3; sf_warning("lam=%.4e",lam); for( i=0;i<nxt;i++ ) { *(g+i)=0.0; } for( k=0;k < nt1;k++) { for( i=1; i<nx1; i++ ) { ind=i+nx*k; q0=*(q+ind-1); q1=*(q+ind+1); q2=(i>1) ? *(q+ind-2) : 1.0; q3=(i<nx2) ? *(q+ind+2) : 1.0; qq=*(q+ind); /* f0=*(f+ind-1); f1=*(f+ind+1); */ f2=(i>1) ? *(f+ind-2) : *(f+k*nx); f3=(i<nx1) ? *(f+ind+2) : *(f+nx1+k*nx); ff=*(f+ind); *(g+ind+nx)=0.5*(*(g+ind-1)+(*(g+ind+1)))- 0.25*lam*((f3*q3-ff*qq)/(q1)-(ff*qq-f2*q2)/(q0))/(ff*qq); f2=*(f+ind+nx); *(q+ind+nx)=-1.0/ (-1.0/(qq)+0.5*ht*(ff*ff*(*(g+ind))+f2*f2*(*(g+ind+nx)))); } } for( i=0; i<nx; i++ ) { for( k=0; k<nt; k++ ) { ind=i+nx*k; *(s+ind)=1.0/(*(f+ind)*(*(q+ind))); } } }
void hhfic(fslice sdat /* source data [nw][nz][ny][nx] */, fslice rdat /* receiver data [nw][nz][ny][nx] */, fslice imag /* image [nz][ny][nx] */ ) /*< apply imaging condition >*/ { int im,ih,iw; /* read wavefields */ fslice_get(sdat,0,us[0]); fslice_get(rdat,0,ur[0]); for(ih=0; ih<ah.n; ih++){ if(verb) sf_warning ("ih=%3d of %3d",ih+1,ah.n); for(im=0; im<am.n; im++){ qq[im] = 0.0; } for (iw=0; iw<aw.n; iw++) { for(im=0; im<am.n; im++){ ; qq [im] += crealf ( conjf(us[iw][im]) * ur[iw][im]*tt[ih][iw] ); } } /* for (iw=0; iw<aw.n; iw++) { for(im=0; im<am.n; im++){ ; qq [im] += crealf ( conjf(us[iw][im]*ts[ih][iw]) * ur[iw][im]*tr[ih][iw] ); } } */ fslice_put(imag,ih,qq); } /* ih */ }
void shot_image_decompose(float *image_hx,float *image_hz,int nx,int nz,float rotate_angle,struct shot_image_par_type image_par) /*< decompose >*/ { int ix,iz; int iblock,pointmove; float *tmp_image_hx,*tmp_image_hz; float tmpmax; for(iz=54;iz<55;iz++){ for(ix=635;ix<636;ix++){ //for(iz=0;iz<nz;iz++){ // for(ix=0;ix<nx;ix++){ iblock=iz*nx+ix; pointmove=image_par.nhx*image_par.nhy*iblock; tmp_image_hx=image_hx+pointmove; tmp_image_hz=image_hz+pointmove; shot_image_decompose_1imagepoint(tmp_image_hx,tmp_image_hz,nx,nz,rotate_angle,image_par); tmpmax=maxval(tmp_image_hz,image_par.nhx); if (tmpmax>10000000.0) sf_warning("ix=%d,iz=%d,max=%f",ix,iz,tmpmax); } } }
void impl1_init (float r /* radius */, int n1 /* data size */, float tau /* duration */, float pclip /* percentage clip */, bool up_in /* weight version */) /*< initialize >*/ { float q; q = 0.25/SF_PI; t = r*r*q; nstep = t/tau; if (nstep > 1) { t /= nstep; } else { nstep = 1; } n = n1; w = sf_floatalloc(n); d1 = sf_floatalloc(n); w1 = sf_floatalloc(n); slv = sf_tridiagonal_init (n); nclip = (int) n*pclip*0.01; if (nclip < 1) { nclip = 1; } else if (nclip > n) { nclip = n; } nclip--; sf_warning("%s: nstep=%d tau=%g nclip=%d",__FILE__,nstep,t,nclip); }
int main(int argc, char* argv[]) { int n1, n2, n3, gainstep, panel, it, nreserve, i1, i2, i3, j, orient; float o1, o2, o3, d1, d2, d3, gpow, clip, pclip, phalf, bias=0., minmax[2]; float pbias, gain=0., x1, y1, x2, y2, **data=NULL, f, barmin, barmax, dat; bool transp, yreverse, xreverse, allpos, polarity, symcp, verb; bool eclip=false, egpow=false, barreverse, mean=false; bool scalebar, nomin=true, nomax=true, framenum, sfbyte, sfbar, charin; char *gainpanel, *color, *barfile; unsigned char tbl[TSIZE+1], **buf, tmp, *barbuf[1]; enum {GAIN_EACH=-3,GAIN_ALL=-2,NO_GAIN=-1}; off_t pos; sf_file in, out=NULL, bar=NULL; sf_init(argc,argv); in = sf_input("in"); sfbyte = (bool) (NULL != strstr (sf_getprog(),"byte")); sfbar = (bool) (NULL != strstr (sf_getprog(),"bar")); if (sfbyte) { out = sf_output("out"); sf_settype(out,SF_UCHAR); } else if (sfbar) { bar = sf_output("out"); sf_settype(bar,SF_UCHAR); } else { vp_init(); } charin = (bool) (SF_UCHAR == sf_gettype(in)); if (charin && sfbyte) sf_error("Cannot input uchar to byte"); if (!charin && SF_FLOAT != sf_gettype(in)) sf_error("Need float input"); if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(in,"n2",&n2)) n2=1; n3 = sf_leftsize(in,2); if (!sf_histfloat(in,"o1",&o1)) o1=0.; if (!sf_histfloat(in,"o2",&o2)) o2=0.; if (!sf_histfloat(in,"o3",&o3)) o3=0.; if (!sf_histfloat(in,"d1",&d1)) d1=1.; if (!sf_histfloat(in,"d2",&d2)) d2=1.; if (!sf_histfloat(in,"d3",&d3)) d3=1.; if (!sf_getbool("transp",&transp)) transp=true; /* if y, transpose the display axes */ if (!sf_getbool("yreverse",&yreverse)) yreverse=true; /* if y, reverse the vertical axis */ if (!sf_getbool("xreverse",&xreverse)) xreverse=false; /* if y, reverse the horizontal axis */ if (transp) { orient = 3; } else { orient = (xreverse==yreverse)? 0:2; } if (!charin) { panel = NO_GAIN; /* no need for gain */ phalf=85.; egpow = false; if (!sf_getfloat("gpow",&gpow)) { gpow=1.; /*( gpow=1 raise data to gpow power for display )*/ } else if (gpow <= 0.) { gpow=0.; egpow = true; sf_getfloat("phalf",&phalf); /* percentage for estimating gpow */ if (phalf <=0. || phalf > 100.) sf_error("phalf=%g should be > 0 and <= 100",phalf); panel = 0; } pclip=99.; eclip = (bool) (!sf_getfloat("clip",&clip)); /* data clip */ if (eclip) { clip = 0.; sf_getfloat("pclip",&pclip); /* data clip percentile (default is 99) */ if (pclip <=0. || pclip > 100.) sf_error("pclip=%g should be > 0 and <= 100",pclip); panel = 0; } else if (clip <= 0.) { sf_warning("clip=%g <= 0",clip); clip = FLT_EPSILON; } if (0==panel) { if (!sf_getint("gainstep",&gainstep)) gainstep=0.5+n1/256.; /* subsampling for gpow and clip estimation */ if (gainstep <= 0) gainstep=1; gainpanel = sf_getstring("gainpanel"); /* gain reference: 'a' for all, 'e' for each, or number */ if (NULL != gainpanel) { switch (gainpanel[0]) { case 'a': panel=GAIN_ALL; break; case 'e': panel=GAIN_EACH; break; default: if (0 ==sscanf(gainpanel,"%d",&panel) || panel < 1 || panel > n3) sf_error("gainpanel= should be all," " each, or a number" " between 1 and %d",n3); panel--; break; } free (gainpanel); } sf_unpipe(in,sf_filesize(in)*sizeof(float)); } if (!sf_getbool("allpos",&allpos)) allpos=false; /* if y, assume positive data */ if (!sf_getbool("mean",&mean)) mean=false; /* if y, bias on the mean value */ if (!sf_getfloat("bias",&pbias)) pbias=0.; /* value mapped to the center of the color table */ if (!sf_getbool("polarity",&polarity)) polarity=false; /* if y, reverse polarity (white is high by default) */ if (!sf_getbool("symcp",&symcp)) symcp=false; /* if y, assume symmetric color palette of 255 colors */ if (!sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ } /* if !charin */ barfile = sf_getstring("bar"); /* file for scalebar data */ if (sfbyte) { scalebar = (bool) (NULL != barfile); if (scalebar) sf_putstring(out,"bar",barfile); } else if (sfbar) { scalebar = true; } else { if (!sf_getbool ("wantscalebar",&scalebar) && !sf_getbool ("scalebar",&scalebar)) scalebar = false; /* if y, draw scalebar */ } if (scalebar) { nomin = (bool) (!sf_getfloat("minval",&barmin)); /* minimum value for scalebar (default is the data minimum) */ nomax = (bool) (!sf_getfloat("maxval",&barmax)); /* maximum value for scalebar (default is the data maximum) */ barbuf[0] = sf_ucharalloc(VP_BSIZE); if (!sf_getbool("barreverse",&barreverse)) barreverse=false; /* if y, go from small to large on the bar scale */ if (sfbyte || sfbar) { if (sfbyte) { bar = sf_output("bar"); sf_settype(bar,SF_UCHAR); } sf_putint(bar,"n1",VP_BSIZE+2*sizeof(float)); sf_putint(bar,"n2",1); sf_putint(bar,"n3",n3); if (!nomin) sf_putfloat(bar,"minval",barmin); if (!nomax) sf_putfloat(bar,"maxval",barmax); } else if (charin) { if (NULL == barfile) { barfile=sf_histstring(in,"bar"); if (NULL == barfile) sf_error("Need bar="); } bar = sf_input(barfile); if (SF_UCHAR != sf_gettype(bar)) sf_error("Need uchar in bar"); if (nomin) nomin = (bool) (!sf_histfloat(bar,"minval",&barmin)); if (nomax) nomax = (bool) (!sf_histfloat(bar,"maxval",&barmax)); } } if (!sf_getbool("wantframenum",&framenum)) framenum = (bool) (n3 > 1); /* if y, display third axis position in the corner */ x1 = o1-0.5*d1; x2 = o1+(n1-1)*d1+0.5*d1; y1 = o2-0.5*d2; y2 = o2+(n2-1)*d2+0.5*d2; if (!sfbyte && !sfbar) { vp_stdplot_init (x1, x2, y1, y2, transp, false, yreverse, false); vp_frame_init(in,"tlb",false); /* if (scalebar && !nomin && !nomax) vp_barframe_init (in,barmin,barmax); */ } if (transp) { f=x1; x1=y1; y1=f; f=x2; x2=y2; y2=f; } if (yreverse) { f=y1; y1=y2; y2=f; } if (xreverse) { f=x1; x1=x2; x2=f; } buf = sf_ucharalloc2(n1,n2); if (!charin) { data = sf_floatalloc2(n1,n2); if (GAIN_ALL==panel || panel >= 0) { pos = sf_tell(in); if (panel > 0) sf_seek(in, pos+panel*n1*n2*sizeof(float), SEEK_SET); vp_gainpar (in,data,n1,n2,gainstep, pclip,phalf,&clip,&gpow,mean,&pbias, n3,panel,panel); if (verb) sf_warning("panel=%d bias=%g clip=%g gpow=%g", panel,pbias,clip,gpow); if (sfbyte) sf_putfloat(out,"clip",clip); sf_seek(in,pos,SEEK_SET); /* rewind */ } } if (!sfbyte && !sfbar) { /* initialize color table */ if (NULL == (color = sf_getstring("color"))) color="i"; /* color scheme (default is i) */ if (!sf_getint ("nreserve",&nreserve)) nreserve = 8; /* reserved colors */ vp_rascoltab (nreserve, color); } for (i3=0; i3 < n3; i3++) { if (!charin) { if (GAIN_EACH == panel) { if (eclip) clip=0.; if (egpow) gpow=0.; vp_gainpar (in,data,n1,n2,gainstep, pclip,phalf,&clip,&gpow, mean,&pbias,n3,0,n3); if (verb) sf_warning("bias=%g clip=%g gpow=%g",pbias,clip,gpow); } else { sf_floatread(data[0],n1*n2,in); } if (1 == panel || GAIN_EACH == panel || 0==i3) { /* initialize the conversion table */ if(!allpos) { /* negative and positive values */ for (it=1; it<=TSIZE/2; it++) { if (symcp) { tbl[TSIZE-it] = (gpow != 1.)? 254*(pow(((TSIZE-2.0*it)/TSIZE),gpow)+1.)/2.+1.: 254*( ((TSIZE-2.0*it)/TSIZE) +1.)/2.+1.; tbl[it] = 255 - tbl[TSIZE-it] + 1.0; } else { tbl[TSIZE-it] = (gpow != 1.)? 252*(pow(((TSIZE-2.0*it)/TSIZE),gpow)+1.)/2.+3.: 252*( ((TSIZE-2.0*it)/TSIZE) +1.)/2.+3.; tbl[it] = 255 - tbl[TSIZE-it] + 2.0; } } bias = TSIZE/2.; gain = TSIZE/(2.*clip); } else { /* all positive */ if (symcp) { for (it=1; it < TSIZE ; it++) { tbl[it] = 255*((it-1.0)/TSIZE) + 1.0; } } else { for (it=1; it < TSIZE ; it++) { tbl[it] = 256*((it-1.0)/TSIZE); } } bias = 0.; gain = TSIZE/clip; } tbl[0] = tbl[1]; tbl[TSIZE] = tbl[TSIZE-1]; if (polarity) { /* switch polarity */ for (it=0; it<=TSIZE; it++) { tbl[it]=255-tbl[it]; } } } /* convert to bytes */ for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1; i1++) { j = (data[i2][i1]-pbias)*gain + bias; if (j < 0) j=0; else if (j > TSIZE) j=TSIZE; buf[i2][i1] = tbl[j]; } } } else { sf_ucharread(buf[0],n1*n2,in); } if (!sfbyte && !sfbar) { if (yreverse) { for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1/2; i1++) { tmp = buf[i2][i1]; buf[i2][i1] = buf[i2][n1-1-i1]; buf[i2][n1-1-i1] = tmp; } } } if ((xreverse && transp) || (!xreverse && !transp)) { for (i2=0; i2 < n2/2; i2++) { for (i1=0; i1 < n1; i1++) { tmp = buf[i2][i1]; buf[i2][i1] = buf[n2-1-i2][i1]; buf[n2-1-i2][i1] = tmp; } } } if (i3 > 0) vp_erase (); if (framenum) vp_framenum(o3+i3*d3); vp_frame(); vp_uraster (buf, false, 256, n1, n2, x1, y1, x2, y2, orient); vp_simpleframe(); } if (scalebar) { if (!charin) { if (nomin) barmin = data[0][0]; if (nomax) barmax = data[0][0]; if (nomin || nomax) { for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1; i1++) { dat = data[i2][i1]; if (nomin && barmin > dat) barmin = dat; if (nomax && barmax < dat) barmax = dat; } } } for (it=0; it < VP_BSIZE; it++) { if (barreverse) { dat = (barmin*it + barmax*(VP_BSIZE-1-it))/(VP_BSIZE-1); } else { dat = (barmax*it + barmin*(VP_BSIZE-1-it))/(VP_BSIZE-1); } j = (dat-pbias)*gain + bias; if (j < 0) j=0; else if (j > TSIZE) j=TSIZE; barbuf[0][it] = tbl[j]; } } else { sf_floatread(minmax,2,bar); sf_ucharread(barbuf[0],VP_BSIZE,bar); if (nomin) barmin=minmax[0]; if (nomax) barmax=minmax[1]; } if (sfbyte || sfbar) { sf_floatwrite(&barmin,1,bar); sf_floatwrite(&barmax,1,bar); sf_ucharwrite(barbuf[0],VP_BSIZE,bar); } else { if (barreverse) { vp_barframe_init (in,barmax,barmin); } else { vp_barframe_init (in,barmin,barmax); } vp_barraster(VP_BSIZE, barbuf); } } /* if scalebar */ if (sfbyte) { sf_ucharwrite(buf[0],n1*n2,out); } else if (!sfbar) { vp_purge(); } } /* i3 loop */ exit (0); }
int main(int argc, char* argv[]) { int p[4][2], i, im, id, status; unsigned long mseed, dseed; off_t nm, nd, msiz, dsiz; size_t nbuf, mbuf, dbuf; float *buf; double dp; pid_t pid[6]={1,1,1,1,1,1}; sf_file mod=NULL; sf_file dat=NULL; sf_file pip=NULL; sf_init(argc,argv); mod = sf_input("mod"); dat = sf_input("dat"); if (SF_FLOAT != sf_gettype(mod) || SF_FLOAT != sf_gettype(dat)) sf_error("Need float type in mod and dat"); nm = sf_filesize(mod); nd = sf_filesize(dat); nbuf = BUFSIZ/sizeof(float); buf = sf_floatalloc(nbuf); mseed = (unsigned long) time(NULL); init_genrand(mseed); mseed = genrand_int32(); dseed = genrand_int32(); for (i=0; i < argc-1; i++) { argv[i]=argv[i+1]; } argv[argc-1] = sf_charalloc(6); snprintf(argv[argc-1],6,"adj=X"); for (i=0; i < 4; i++) { /* make four pipes */ if (pipe(p[i]) < 0) sf_error("pipe error:"); } for (i=0; i < 6; i++) { /* fork six children */ if ((pid[i] = fork()) < 0) sf_error("fork error:"); if (0 == pid[i]) break; } if (0 == pid[0]) { /* makes random model and writes it to p[0] */ close(p[0][0]); close(STDOUT_FILENO); DUP(p[0][1]); pip = sf_output("out"); sf_fileflush(pip,mod); init_genrand(mseed); for (msiz=nm, mbuf=nbuf; msiz > 0; msiz -= mbuf) { if (msiz < mbuf) mbuf=msiz; sf_random(mbuf,buf); sf_floatwrite(buf,mbuf,pip); } } if (0 == pid[1]) { /* reads from p[0], runs the program, and writes to p[1] */ close(p[0][1]); close(STDIN_FILENO); DUP(p[0][0]); close(p[1][0]); close(STDOUT_FILENO); DUP(p[1][1]); argv[argc-1][4]='0'; execvp(argv[0],argv); _exit(1); } if (0 == pid[2]) { /* reads from p[1] and multiplies it with random data */ close(p[1][1]); close(STDIN_FILENO); DUP(p[1][0]); pip = sf_input("in"); init_genrand(dseed); dp = 0.; for (dsiz=nd, dbuf=nbuf; dsiz > 0; dsiz -= dbuf) { if (dsiz < dbuf) dbuf=dsiz; sf_floatread(buf,dbuf,pip); for (id=0; id < dbuf; id++) { dp += buf[id]*genrand_real1 (); } } sf_warning(" L[m]*d=%g",dp); _exit(2); } if (0 == pid[3]) { /* makes random data and writes it to p[2] */ close(p[2][0]); close(STDOUT_FILENO); DUP(p[2][1]); pip = sf_output("out"); sf_fileflush(pip,dat); init_genrand(dseed); for (dsiz=nd, dbuf=nbuf; dsiz > 0; dsiz -= dbuf) { if (dsiz < dbuf) dbuf=dsiz; sf_random(dbuf,buf); sf_floatwrite(buf,dbuf,pip); } } if (0 == pid[4]) { /* reads from p[2], runs the adjoint, and writes to p[3] */ close(p[2][1]); close(STDIN_FILENO); DUP(p[2][0]); close(p[3][0]); close(STDOUT_FILENO); DUP(p[3][1]); argv[argc-1][4]='1'; execvp(argv[0],argv); _exit(4); } if (0 == pid[5]) { /* reads from p[3] and multiplies it with random model */ close(p[3][1]); close(STDIN_FILENO); DUP(p[3][0]); pip = sf_input("in"); init_genrand(mseed); dp = 0.; for (msiz=nm, mbuf=nbuf; msiz > 0; msiz -= mbuf) { if (msiz < mbuf) mbuf=msiz; sf_floatread(buf,mbuf,pip); for (im=0; im < mbuf; im++) { dp += buf[im]*genrand_real1 (); } } sf_warning("L'[d]*m=%g",dp); _exit(5); } for (i=0; i < 6; i++) { if (0 == pid[i]) break; } if (6==i) { /* parent waits */ waitpid(pid[2],&status,0); waitpid(pid[5],&status,0); exit(0); } }
int main(int argc, char* argv[]) { int nt, nh, ncmp, it, icmp, ih, iw, w, zero, shift; float *indata, *outdata, *stack, *win1, *win2, *outweight; float dt,var, maxwin1, maxwin2, ee, esp, dh, dcmp,cmp0, t0, h0, /* sumab, sumwin1, sumwin2, */ sumweight, sft; sf_file in, out; /* initialization */ sf_init(argc,argv); in = sf_input("in"); out = sf_output("out"); /* get rsf_file parameters */ if (!sf_histint(in,"n1",&nt)) sf_error("Need n1="); if (!sf_histfloat(in,"d1",&dt)) dt=1.; if (!sf_histfloat(in,"o1",&t0)) t0=0.; if (!sf_histint(in,"n2",&nh)) sf_error("Need n2="); if (!sf_histfloat(in,"d2",&dh)) dh=1.; if (!sf_histfloat(in,"o2",&h0)) h0=0.; if (!sf_histint(in,"n3",&ncmp)) ncmp=1; if (!sf_histfloat(in,"d3",&dcmp)) dcmp=1.; if (!sf_histfloat(in,"o3",&cmp0)) cmp0=0.; /* get other parameters */ if (!sf_getint("w",&w)) w=50; /* sliding window size*/ if (!sf_getfloat("sft",&sft)) sft=1; /*weight shift*/ if (!sf_getfloat("ee",&ee)) ee=1.0; if (!sf_getfloat("esp",&esp)) esp=1.0; sf_putint(out,"n1",nt); sf_putint(out,"n2",ncmp); sf_putfloat(out,"d1",dt); sf_putfloat(out,"o1",t0); sf_putfloat(out,"d2",dcmp); sf_putfloat(out,"o2",cmp0); sf_putint(out,"n3",1); indata = sf_floatalloc(nt*nh); outdata = sf_floatalloc(nt); outweight = sf_floatalloc(nt*nh); stack = sf_floatalloc(nt); win1 = sf_floatalloc(w); win2 = sf_floatalloc(w); for (icmp=0; icmp < ncmp; icmp++){ sf_floatread(indata,nt*nh,in); for (it=0; it < nt; it++){ stack[it] = 0; outdata[it] = 0; for (ih=0;ih<nh;ih++){ outweight[nt*ih+it]=0; } } /* computer the directly stack trace */ for (it=0; it < nt; it++){ zero=0; for(ih=0; ih < nh; ih++){ if (indata[ih*nt+it]!=0) zero++; stack[it]+= indata[ih*nt+it]; } if (zero==0) stack[it]=stack[it]; else stack[it]=stack[it]/zero; } /* estimate the noise variances */ for (it=0; it < nt; it++){ zero = 0; sumweight=0; for (ih=0; ih < nh; ih++){ /* sumwin1 = 0; sumwin2 = 0; sumab = 0; */ shift = SF_MAX(0,SF_MIN(nt-w, it-w/2-1)); /* weight=0; */ var=0; maxwin1=0; maxwin2=0; for (iw=0; iw <w; iw++){ win1[iw] = indata[ih*nt+iw+shift]; win2[iw] = stack[iw+shift]; if (fabs(win1[iw])>fabs(maxwin1)) maxwin1 = fabs(win1[iw]); if (fabs(win2[iw])>fabs(maxwin2)) maxwin2 = fabs(win2[iw]); } for (iw=0; iw <w; iw++){ var += fabs(win1[iw]/maxwin1-win2[iw]/maxwin2)*fabs(win1[iw]/maxwin1-win2[iw]/maxwin2); } outweight[nt*ih+it] =1./(var+ee); if (indata[ih*nt+it]!=0){ zero++; outdata[it] += pow(1./(var+ee),1)*indata[ih*nt+it]; sumweight += pow(1./(var+ee),1); } } if (zero==0) outdata[it]=0; else outdata[it] = outdata[it]/(zero*sumweight+esp); } sf_floatwrite(outdata,nt,out); sf_warning("running cmp is = %d of %d",icmp, ncmp); } exit(0); }
int main(int argc,char **argv) { int isx,isy,isz,bd; int i,j,k,im,jm,it; int nth, rank; float t; float fx,fy,fz,dt2; float ***c11, ***c22, ***c33, ***c12, ***c13, ***c23, ***c44, ***c55, ***c66; float ***phaix, ***phaiy, ***phaiz; sf_init(argc,argv); sf_file Fo1, Fo2, Fo3; float f0=40; // main frequency of the wavelet(usually 30Hz) float t0=0.04; // time delay of the wavelet(if f0=30Hz, t0=0.04s)*/ float A=1.0; // the amplitude of wavelet clock_t t1, t2, t3; float timespent; t1=clock(); /* time samping paramter */ if (!sf_getint("nt",&nt)) nt=301; if (!sf_getfloat("dt",&dt)) dt=0.001; if (!sf_getint("bd",&bd)) bd=20; sf_warning("nt=%d dt=%f",nt,dt); /* setup I/O files */ sf_file Fc11, Fc22, Fc33, Fc12, Fc13, Fc23, Fc44, Fc55, Fc66; sf_file Fphiz, Fphiy, Fphix; Fc11 = sf_input ("c11"); /* c11 using standard input */ Fc22 = sf_input ("c22"); /* c22 */ Fc33 = sf_input ("c33"); /* c33 */ Fc12 = sf_input ("c12"); /* c12 */ Fc13 = sf_input ("c13"); /* c13 */ Fc23 = sf_input ("c23"); /* c23 */ Fc44 = sf_input ("c44"); /* c44 */ Fc55 = sf_input ("c55"); /* c55 */ Fc66 = sf_input ("c66"); /* c66 */ Fphix = sf_input ("phix"); /* phix x ccw*/ Fphiy = sf_input ("phiy"); /* phiy y ccw*/ Fphiz = sf_input ("phiz"); /* phiz z ccw */ /* Read/Write axes */ sf_axis az, ax, ay; az = sf_iaxa(Fc11,1); nz = sf_n(az); dz = sf_d(az)*1000.0; ax = sf_iaxa(Fc11,2); nx = sf_n(ax); dx = sf_d(ax)*1000.0; ay = sf_iaxa(Fc11,3); ny = sf_n(ay); dy = sf_d(ay)*1000.0; fy=sf_o(ay)*1000.0; fx=sf_o(ax)*1000.0; fz=sf_o(az)*1000.0; int nxpad, nypad, nzpad; nxpad=nx+2*bd; nypad=ny+2*bd; nzpad=nz+2*bd; sf_warning("nxpad=%d nypad=%d nzpad=%d ",nxpad,nypad,nzpad); sf_warning("dx=%f dy=%f dz=%f ",dx,dy,dz); c11=sf_floatalloc3(nzpad,nxpad,nypad); c22=sf_floatalloc3(nzpad,nxpad,nypad); c33=sf_floatalloc3(nzpad,nxpad,nypad); c12=sf_floatalloc3(nzpad,nxpad,nypad); c13=sf_floatalloc3(nzpad,nxpad,nypad); c23=sf_floatalloc3(nzpad,nxpad,nypad); c44=sf_floatalloc3(nzpad,nxpad,nypad); c55=sf_floatalloc3(nzpad,nxpad,nypad); c66=sf_floatalloc3(nzpad,nxpad,nypad); phaix=sf_floatalloc3(nzpad,nxpad,nypad); phaiy=sf_floatalloc3(nzpad,nxpad,nypad); phaiz=sf_floatalloc3(nzpad,nxpad,nypad); /* read velocity model */ for(i=bd;i<nypad-bd;i++) for(j=bd;j<nxpad-bd;j++){ sf_floatread(&c11[i][j][bd],nz,Fc11); sf_floatread(&c22[i][j][bd],nz,Fc22); sf_floatread(&c33[i][j][bd],nz,Fc33); sf_floatread(&c12[i][j][bd],nz,Fc12); sf_floatread(&c13[i][j][bd],nz,Fc13); sf_floatread(&c23[i][j][bd],nz,Fc23); sf_floatread(&c44[i][j][bd],nz,Fc44); sf_floatread(&c55[i][j][bd],nz,Fc55); sf_floatread(&c66[i][j][bd],nz,Fc66); sf_floatread(&phaix[i][j][bd],nz,Fphix); sf_floatread(&phaiy[i][j][bd],nz,Fphiy); sf_floatread(&phaiz[i][j][bd],nz,Fphiz); } vmodelboundary3d(c11, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(c22, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(c33, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(c12, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(c13, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(c23, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(c44, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(c55, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(c66, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(phaix, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(phaiy, nx, ny, nz, nxpad, nypad, nzpad, bd); vmodelboundary3d(phaiz, nx, ny, nz, nxpad, nypad, nzpad, bd); for(i=0;i<nypad;i++) for(j=0;j<nxpad;j++) for(k=0;k<nzpad;k++){ phaix[i][j][k] *= SF_PI/180.0; phaiy[i][j][k] *= SF_PI/180.0; phaiz[i][j][k] *= SF_PI/180.0; } sf_warning("Read velocity model parameters ok !"); int mm=2*_m+1; int mmix=2*_mix+1; sf_warning("m=%d mix=%d",_m,_mix); float *coeff_2dx,*coeff_2dy,*coeff_2dz,*coeff_1dx,*coeff_1dy,*coeff_1dz; coeff_2dy=sf_floatalloc(mm); coeff_2dx=sf_floatalloc(mm); coeff_2dz=sf_floatalloc(mm); coeff_1dy=sf_floatalloc(mmix); coeff_1dx=sf_floatalloc(mmix); coeff_1dz=sf_floatalloc(mmix); coeff2d(coeff_2dx,dx); coeff2d(coeff_2dy,dy); coeff2d(coeff_2dz,dz); coeff1dmix(coeff_1dx, dx); coeff1dmix(coeff_1dy, dy); coeff1dmix(coeff_1dz, dz); float*** p1=sf_floatalloc3(nzpad,nxpad,nypad); float*** p2=sf_floatalloc3(nzpad,nxpad,nypad); float*** p3=sf_floatalloc3(nzpad,nxpad,nypad); zero3float(p1,nzpad,nxpad,nypad); zero3float(p2,nzpad,nxpad,nypad); zero3float(p3,nzpad,nxpad,nypad); float*** q1=sf_floatalloc3(nzpad,nxpad,nypad); float*** q2=sf_floatalloc3(nzpad,nxpad,nypad); float*** q3=sf_floatalloc3(nzpad,nxpad,nypad); zero3float(q1,nzpad,nxpad,nypad); zero3float(q2,nzpad,nxpad,nypad); zero3float(q3,nzpad,nxpad,nypad); float*** r1=sf_floatalloc3(nzpad,nxpad,nypad); float*** r2=sf_floatalloc3(nzpad,nxpad,nypad); float*** r3=sf_floatalloc3(nzpad,nxpad,nypad); zero3float(r1,nzpad,nxpad,nypad); zero3float(r2,nzpad,nxpad,nypad); zero3float(r3,nzpad,nxpad,nypad); t2=clock(); /* setup I/O files */ Fo1 = sf_output("out"); /* original elasticwave iLine x-component */ Fo2 = sf_output("Elasticy"); /* original elasticwave iLine y-component */ Fo3 = sf_output("Elasticz"); /* original elasticwave xLine z-component */ puthead3x(Fo1, nz, nx, ny, dz/1000.0, dx/1000.0, dy/1000.0, 0.0, 0.0, 0.0); puthead3x(Fo2, nz, nx, ny, dz/1000.0, dx/1000.0, dy/1000.0, 0.0, 0.0, 0.0); puthead3x(Fo3, nz, nx, ny, dz/1000.0, dx/1000.0, dy/1000.0, 0.0, 0.0, 0.0); /* source definition */ isy=nypad/2; isx=nxpad/2; isz=nzpad/2; dt2=dt*dt; #ifdef _OPENMP #pragma omp parallel { nth = omp_get_num_threads(); rank = omp_get_thread_num(); sf_warning("Using %d threads, this is %dth thread",nth, rank); } #endif float*** px_tmp=sf_floatalloc3(nzpad,nxpad,nypad); float*** pz_tmp=sf_floatalloc3(nzpad,nxpad,nypad); float*** qx_tmp=sf_floatalloc3(nzpad,nxpad,nypad); float*** qz_tmp=sf_floatalloc3(nzpad,nxpad,nypad); float*** rx_tmp=sf_floatalloc3(nzpad,nxpad,nypad); float*** rz_tmp=sf_floatalloc3(nzpad,nxpad,nypad); /*********the kernel calculation ************/ for(it=0;it<nt;it++) { t=it*dt; /* source Type 0: oriented 45 degree to vertical and 45 degree azimuth: Yan & Sava (2012) */ p2[isy][isx][isz]+=Ricker(t, f0, t0, A); // x-component q2[isy][isx][isz]+=Ricker(t, f0, t0, A); // y-component r2[isy][isx][isz]+=Ricker(t, f0, t0, A); // z-component // 3D exploding force source (e.g., Wu's PhD /* for(k=-1;k<=1;k++)*/ /* for(i=-1;i<=1;i++)*/ /* for(j=-1;j<=1;j++)*/ /* {*/ /* if(fabs(i)+fabs(j)+fabs(k)==3)*/ /* {*/ /* p2[isy+k][isx+i][isz+j]+=i*Ricker(t, f0, t0, A); // x-component*/ /* q2[isy+k][isx+i][isz+j]+=k*Ricker(t, f0, t0, A); // y-component*/ /* r2[isy+k][isx+i][isz+j]+=j*Ricker(t, f0, t0, A); // z-component*/ /* }*/ /* }*/ fwportelastic3d(dt2,p1,p2,p3,q1,q2,q3,r1,r2,r3, px_tmp,pz_tmp, qx_tmp,qz_tmp, rx_tmp,rz_tmp, coeff_2dx,coeff_2dy,coeff_2dz, coeff_1dx,coeff_1dy,coeff_1dz, dx,dy,dz,nxpad,nypad,nzpad, c11,c22,c33,c12,c13,c23,c44,c55,c66,phaix,phaiy,phaiz); if(it==nt-1) // output snapshot { // output iLine for(i=0;i<ny;i++) { im=i+bd; for(j=0;j<nx;j++) { jm=j+bd; sf_floatwrite(&p3[im][jm][bd],nz,Fo1); sf_floatwrite(&q3[im][jm][bd],nz,Fo2); sf_floatwrite(&r3[im][jm][bd],nz,Fo3); } } } for(i=0;i<nypad;i++) for(j=0;j<nxpad;j++) for(k=0;k<nzpad;k++) { p1[i][j][k]=p2[i][j][k]; p2[i][j][k]=p3[i][j][k]; q1[i][j][k]=q2[i][j][k]; q2[i][j][k]=q3[i][j][k]; r1[i][j][k]=r2[i][j][k]; r2[i][j][k]=r3[i][j][k]; } sf_warning("forward propagation... it= %d t=%f",it,t); } printf("ok3\n"); t3=clock(); timespent=(float)(t3-t2)/CLOCKS_PER_SEC; sf_warning("CPU time for 3D ORT elastic modeling: %f(second)",timespent); free(**p1); free(**p2); free(**p3); free(**q1); free(**q2); free(**q3); free(**r1); free(**r2); free(**r3); free(**px_tmp); free(**qx_tmp); free(**rx_tmp); free(**pz_tmp); free(**qz_tmp); free(**rz_tmp); free(**c11); free(**c33); free(**c13); free(**c55); free(**c66); free(**phaiz); free(**phaiy); free(**phaix); return 0; }
int main (int argc, char *argv[]) { int ir, nr, n1,n2,n3, m1, m2, m3, n12, nw, nj1, i3; float *u1, *u2, *p; sf_file in, out, dip; bool verb; allpass ap; sf_init(argc,argv); in = sf_input ("in"); dip = sf_input ("dip"); out = sf_output ("out"); if (SF_FLOAT != sf_gettype(in) || SF_FLOAT != sf_gettype(dip)) sf_error("Need float type"); if (!sf_histint(in,"n1",&n1)) sf_error("Need n1= in input"); if (!sf_histint(in,"n2",&n2)) n2=1; if (!sf_histint(in,"n3",&n3)) n3=1; n12 = n1*n2; nr = sf_leftsize(in,2); if (!sf_histint(dip,"n1",&m1) || m1 != n1) sf_error("Need n1=%d in dip",n1); if (1 != n2 && (!sf_histint(dip,"n2",&m2) || m2 != n2)) sf_error("Need n2=%d in dip",n2); if (1 != n3 && (!sf_histint(dip,"n3",&m3) || m3 != n3)) sf_error("Need n3=%d in dip",n3); if (!sf_getint("order",&nw)) nw=1; /* accuracy */ if (!sf_getbool("verb",&verb)) verb = false; /* verbosity flag */ if (!sf_getint("nj1",&nj1)) nj1=1; /* aliasing */ n3 = 1; for (ir=0; ir < nr; ir++) { if (verb) sf_warning("slice %d of %d", ir+1, nr); u1 = sf_floatalloc(n12); u2 = sf_floatalloc(n12); p = sf_floatalloc(n12); for (i3=0; i3 < n3; i3++) { /* read data */ sf_floatread(u1,n12,in); /* read t-x dip */ sf_floatread(p,n12,dip); ap = allpass_init (nw,nj1,n1,n2,1,p); /* apply */ allpass1(false, false, ap, u1, u2); /* write t-x destruction */ sf_floatwrite(u2,n12,out); } free(u1); free(u2); free(p); } exit (0); }