int main(int argc, char **argv) { int nx,nz; float fx,fz,dx,dz,xs,zs,ex,ez,**v,**t,**a,**sg,**bet; FILE *vfp=stdin,*tfp=stdout,*afp,*sfp,*bfp; char *bfile="", *sfile="", *afile=""; /* hook up getpar to handle the parameters */ initargs(argc,argv); requestdoc(0); /* get required parameters */ if (!getparint("nx",&nx)) err("must specify nx!\n"); if (!getparint("nz",&nz)) err("must specify nz!\n"); if (!getparfloat("xs",&xs)) err("must specify xs!\n"); if (!getparfloat("zs",&zs)) err("must specify zs!\n"); /* get optional parameters */ if (!getparfloat("dx",&dx)) dx = 1.0; if (!getparfloat("fx",&fx)) fx = 0.0; if (!getparfloat("dz",&dz)) dz = 1.0; if (!getparfloat("fz",&fz)) fz = 0.0; if (!getparstring("sfile",&sfile)) sfile = "sfile"; if (!getparstring("bfile",&bfile)) bfile = "bfile"; if (!getparstring("afile",&afile)) afile = "afile"; checkpars(); if ((sfp=fopen(sfile,"w"))==NULL) err("cannot open sfile=%s",sfile); if ((bfp=fopen(bfile,"w"))==NULL) err("cannot open bfile=%s",bfile); if ((afp=fopen(afile,"w"))==NULL) err("cannot open afile=%s",afile); /* ensure source is in grid */ ex = fx+(nx-1)*dx; ez = fz+(nz-1)*dz; if (fx>xs || ex<xs || fz>zs || ez<zs) err("source lies outside of specified (x,z) grid\n"); /* allocate space */ v = alloc2float(nz,nx); t = alloc2float(nz,nx); sg = alloc2float(nz,nx); a = alloc2float(nz,nx); bet = alloc2float(nz,nx); /* read velocities */ fread(v[0],sizeof(float),nx*nz,vfp); /* compute times, angles, sigma, and betas */ eiktam(xs,zs,nz,dz,fz,nx,dx,fx,v,t,a,sg,bet); /* write first-arrival times */ fwrite(t[0],sizeof(float),nx*nz,tfp); /* write sigma */ fwrite(sg[0],sizeof(float),nx*nz,sfp); /* write angle */ fwrite(a[0],sizeof(float),nx*nz,afp); /* write beta */ fwrite(bet[0],sizeof(float),nx*nz,bfp); /* close files */ fclose(sfp); fclose(afp); fclose(bfp); /* free space */ free2float(v); free2float(t); free2float(a); free2float(sg); free2float(bet); return(CWP_Exit()); }
int main (int argc, char **argv) { int nr,ir,ls,smooth,ndpfz,ns,ixo,ixm,nxo,nxm,nt, nx,nz,nxb,nxd,ixd,i,ix,iz,nx1,nx0,nxd1, verbose,tracl, *nxz; float tmin,temp,temp1, dsmax,fpeak,dx,dz,fx,ex,fx1,ex1, dxm,dxo,dt,fxm,fxo,ft,xo,xm,vs0,vg0, xs,xg,ez, *ar,**xr,**zr, **vold,**ts,**as,**sgs,**tg,**ag,**sgg,**bas,**bag, **v,**ts1=NULL,**as1=NULL,**sgs1=NULL, **tg1=NULL,**ag1=NULL,**sgg1=NULL; FILE *vfp=stdin; Reflector *r; Wavelet *w; /* hook up getpar to handle the parameters */ initargs(argc,argv); requestdoc(0); /* get required parameters */ if (!getparint("nx",&nx)) err("must specify nx!\n"); if (!getparint("nz",&nz)) err("must specify nz!\n"); /* get optional parameters */ if (!getparint("nxb",&nxb)) nxb = nx; if (!getparint("nxd",&nxd)) nxd = 1; if (!getparfloat("dx",&dx)) dx = 100; if (!getparfloat("fx",&fx)) fx = 0.0; if (!getparfloat("dz",&dz)) dz = 100; if (!getparint("nt",&nt)) nt = 101; CHECK_NT("nt",nt); if (!getparfloat("dt",&dt)) dt = 0.04; if (!getparfloat("ft",&ft)) ft = 0.0; if (!getparint("nxo",&nxo)) nxo = 1; if (!getparfloat("dxo",&dxo)) dxo = 50; if (!getparfloat("fxo",&fxo)) fxo = 0.0; if (!getparint("nxm",&nxm)) nxm = 101; if (!getparfloat("dxm",&dxm)) dxm = 50; if (!getparfloat("fxm",&fxm)) fxm = 0.0; if (!getparfloat("fpeak",&fpeak)) fpeak = 0.2/dt; if (!getparint("ls",&ls)) ls = 0; if (!getparfloat("tmin",&tmin)) tmin = 10.0*dt; if (!getparint("ndpfz",&ndpfz)) ndpfz = 5; if (!getparint("smooth",&smooth)) smooth = 0; if (!getparint("verbose",&verbose)) verbose = 0; /* check the ranges of shots and receivers */ ex = fx+(nx-1)*dx; ez = (nz-1)*dz; for (ixm=0; ixm<nxm; ++ixm) for (ixo=0; ixo<nxo; ++ixo) { /* compute source and receiver coordinates */ xs = fxm+ixm*dxm-0.5*(fxo+ixo*dxo); xg = xs+fxo+ixo*dxo; if (fx>xs || ex<xs || fx>xg || ex<xg) err("shot or receiver lie outside of specified (x,z) grid\n"); } decodeReflectors(&nr,&ar,&nxz,&xr,&zr); if (!smooth) breakReflectors(&nr,&ar,&nxz,&xr,&zr); /* allocate space */ vold = ealloc2float(nz,nx); /* read velocities */ if(fread(vold[0],sizeof(float),nx*nz,vfp)!=nx*nz) err("cannot read %d velocities from file %s",nx*nz,vfp); /* determine maximum reflector segment length */ tmin = MAX(tmin,MAX(ft,dt)); dsmax = vold[0][0]/(2*ndpfz)*sqrt(tmin/fpeak); /* make reflectors */ makeref(dsmax,nr,ar,nxz,xr,zr,&r); /* count reflector segments */ for (ir=0,ns=0; ir<nr; ++ir) ns += r[ir].ns; /* make wavelet */ makericker(fpeak,dt,&w); /* if requested, print information */ if (verbose) { warn("\nSUSYNVXZ:"); warn("Total number of small reflecting segments is %d.\n",ns); } /* set constant segy trace header parameters */ memset( (void *) &tr, 0, sizeof(segy)); tr.trid = 1; tr.counit = 1; tr.ns = nt; tr.dt = 1.0e6*dt; tr.delrt = 1.0e3*ft; /* allocate space */ nx1 = 1+2*nxb; ts = ealloc2float(nz,nx1); as = ealloc2float(nz,nx1); sgs = ealloc2float(nz,nx1); tg = ealloc2float(nz,nx1); ag = ealloc2float(nz,nx1); sgg = ealloc2float(nz,nx1); v = ealloc2float(nz,nx1); bas = ealloc2float(nz,nx1); bag = ealloc2float(nz,nx1); if(nxd>1) { /* allocate space for interpolation */ ts1 = ealloc2float(nz,nx1); as1 = ealloc2float(nz,nx1); sgs1 = ealloc2float(nz,nx1); tg1 = ealloc2float(nz,nx1); ag1 = ealloc2float(nz,nx1); sgg1 = ealloc2float(nz,nx1); } /* loop over offsets and midpoints */ for (ixo=0, tracl=0; ixo<nxo; ++ixo){ xo = fxo+ixo*dxo; if(ABS(xo)>nxb*dx) err("\t band NXB is too small!\n"); nxd1 = nxd; for (ixm=0; ixm<nxm; ixm +=nxd1){ xm = fxm+ixm*dxm; xs = xm-0.5*xo; xg = xs+xo; /* set range for traveltimes' calculation */ fx1 = xm-nxb*dx; ex1 = MIN(ex+(nxd1-1)*dxm,xm+nxb*dx); nx1 = 1+(ex1-fx1)/dx; nx0 = (fx1-fx)/dx; temp = (fx1-fx)/dx-nx0; /* transpose velocity such that the first row is at fx1 */ for(ix=0;ix<nx1;++ix) for(iz=0;iz<nz;++iz){ if(ix<-nx0) v[ix][iz] = vold[0][iz]; else if(ix+nx0>nx-2) v[ix][iz]=vold[nx-1][iz]; else v[ix][iz] = vold[ix+nx0][iz]*(1.0-temp) +temp*vold[ix+nx0+1][iz]; } if(ixm==0 || nxd1==1){ /* No interpolation */ /* compute traveltimes, propagation angles, sigmas from shot and receiver respectively */ eiktam(xs,0.,nz,dz,0.,nx1,dx,fx1,v,ts,as,sgs,bas); eiktam(xg,0.,nz,dz,0.,nx1,dx,fx1,v,tg,ag,sgg,bag); ixd = NINT((xs-fx)/dx); vs0 = vold[ixd][0]; ixd = NINT((xg-fx)/dx); vg0 = vold[ixd][0]; /* make one trace */ ex1 = MIN(ex,xm+nxb*dx); makeone(ts,as,sgs,tg,ag,sgg,ex1,ez,dx,dz,fx1,vs0,vg0, ls,w,nr,r,nt,dt,ft,tr.data); /* set segy trace header parameters */ tr.tracl = tr.tracr = ++tracl; tr.cdp = 1+ixm; tr.cdpt = 1+ixo; tr.offset = NINT(xo); tr.sx = NINT(xs); tr.gx = NINT(xg); /* write trace */ puttr(&tr); } else { /* Linear interpolation */ eiktam(xs,0,nz,dz,0,nx1,dx,fx1,v,ts1,as1,sgs1,bas); eiktam(xg,0,nz,dz,0,nx1,dx,fx1,v,tg1,ag1,sgg1,bag); ixd = NINT((xs-fx)/dx); vs0 = vold[ixd][0]; ixd = NINT((xg-fx)/dx); vg0 = vold[ixd][0]; xm -= nxd1*dxm; for(i=1; i<=nxd1; ++i) { xm += dxm; xs = xm-0.5*xo; xg = xs+xo; fx1 = xm-nxb*dx; ex1 = MIN(ex+(nxd1-1)*dxm,xm+nxb*dx); nx1 = 1+(ex1-fx1)/dx; temp = nxd1-i; temp1 = 1.0/(nxd1-i+1); for(ix=0;ix<nx1;++ix) for(iz=0;iz<nz;++iz){ if(i==nxd1){ ts[ix][iz] = ts1[ix][iz]; tg[ix][iz] = tg1[ix][iz]; sgs[ix][iz] = sgs1[ix][iz]; ag[ix][iz] = ag1[ix][iz]; sgg[ix][iz] = sgg1[ix][iz]; as[ix][iz] = as1[ix][iz]; } else{ ts[ix][iz] = (temp*ts[ix][iz] +ts1[ix][iz])*temp1; tg[ix][iz] = (temp*tg[ix][iz] +tg1[ix][iz])*temp1; as[ix][iz] = (temp*as[ix][iz] +as1[ix][iz])*temp1; sgs[ix][iz] = (temp*sgs[ix][iz] +sgs1[ix][iz])*temp1; ag[ix][iz] = (temp*ag[ix][iz] +ag1[ix][iz])*temp1; sgg[ix][iz] = (temp*sgg[ix][iz] +sgg1[ix][iz])*temp1; } } /* make one trace */ ex1 = MIN(ex,xm+nxb*dx); makeone(ts,as,sgs,tg,ag,sgg,ex1,ez,dx,dz,fx1,vs0,vg0, ls,w,nr,r,nt,dt,ft,tr.data); /* set segy trace header parameters */ tr.tracl = tr.tracr = ++tracl; tr.cdp = 1+ixm-nxd1+i; tr.cdpt = 1+ixo; tr.offset = NINT(xo); tr.d2=dxm; tr.f2=fxm; tr.sx = NINT(xs); tr.gx = NINT(xg); /* write trace */ puttr(&tr); } } /* set skip parameter */ if(ixm<nxm-1 && ixm>nxm-1-nxd1) nxd1 = nxm-1-ixm; } warn("\t finish offset %f\n",xo); } free2float(vold); free2float(ts); free2float(bas); free2float(sgs); free2float(as); free2float(v); free2float(tg); free2float(bag); free2float(sgg); free2float(ag); if(nxd>1) { free2float(ts1); free2float(as1); free2float(sgs1); free2float(tg1); free2float(ag1); free2float(sgg1); } return(CWP_Exit()); }