TraceThreadListener::~TraceThreadListener() { traceWrite(); traceFlush(); traceClose(); ProcessListener.deregisterThreadListener(ThreadID); }
int writeRec(recPar rec, modPar mod, bndPar bnd, wavPar wav, int ixsrc, int izsrc, int nsam, int ishot, int fileno, float *rec_vx, float *rec_vz, float *rec_txx, float *rec_tzz, float *rec_txz, float *rec_p, float *rec_pp, float *rec_ss, float *rec_udp, float *rec_udvz, int verbose) { FILE *fpvx, *fpvz, *fptxx, *fptzz, *fptxz, *fpp, *fppp, *fpss, *fpup, *fpdown; float *rec_up, *rec_down, *trace, *rec_vze, *rec_pe; float dx, dt, cp, rho, fmin, fmax; complex *crec_vz, *crec_p, *crec_up, *crec_dw; int irec, ntfft, nfreq, nkx, xorig, ix, iz, it, ibndx; int append; double ddt; char number[16], filename[1024]; segy hdr; if (!rec.n) return 0; if (ishot) append=1; else append=0; /* if the total number of samples exceeds rec_ntsam then a new (numbered) file is opened */ /* fileno has a non-zero value (from fdelmodc.c) if the number of samples exceeds rec_ntsam. */ strcpy(filename, rec.file_rcv); if (fileno) { sprintf(number,"_%03d",fileno); name_ext(filename, number); } if (verbose>2) vmess("Writing receiver data to file %s", filename); if (nsam != rec.nt && verbose) vmess("Number of samples written to last file = %d",nsam); memset(&hdr,0,TRCBYTES); ddt = (double)mod.dt;/* to avoid rounding in 32 bit precision */ dt = (float)ddt*rec.skipdt; dx = (rec.x[1]-rec.x[0])*mod.dx; hdr.dt = (unsigned short)lround((((double)1.0e6*ddt*rec.skipdt))); hdr.scalco = -1000; hdr.scalel = -1000; hdr.sx = 1000*(mod.x0+ixsrc*mod.dx); hdr.sdepth = 1000*(mod.z0+izsrc*mod.dz); hdr.selev = (int)(-1000.0*(mod.z0+izsrc*mod.dz)); hdr.fldr = ishot+1; hdr.trid = 1; hdr.ns = nsam; hdr.trwf = rec.n; hdr.ntr = (ishot+1)*rec.n; hdr.f1 = 0.0; hdr.d1 = mod.dt*rec.skipdt; hdr.d2 = (rec.x[1]-rec.x[0])*mod.dx; hdr.f2 = mod.x0+rec.x[0]*mod.dx; if (rec.type.vx) fpvx = fileOpen(filename, "_rvx", append); if (rec.type.vz) fpvz = fileOpen(filename, "_rvz", append); if (rec.type.p) fpp = fileOpen(filename, "_rp", append); if (rec.type.txx) fptxx = fileOpen(filename, "_rtxx", append); if (rec.type.tzz) fptzz = fileOpen(filename, "_rtzz", append); if (rec.type.txz) fptxz = fileOpen(filename, "_rtxz", append); if (rec.type.pp) fppp = fileOpen(filename, "_rpp", append); if (rec.type.ss) fpss = fileOpen(filename, "_rss", append); /* decomposed wavefield */ if (rec.type.ud && (mod.ischeme==1 || mod.ischeme==2) ) { fpup = fileOpen(filename, "_ru", append); fpdown = fileOpen(filename, "_rd", append); ntfft = optncr(nsam); nfreq = ntfft/2+1; fmin = 0.0; fmax = wav.fmax; nkx = optncc(2*mod.nax); ibndx = mod.ioPx; if (bnd.lef==4 || bnd.lef==2) ibndx += bnd.ntap; cp = rec.cp; rho = rec.rho; if (verbose) vmess("Decomposition array at z=%.2f with cp=%.2f rho=%.2f", rec.zr[0]+mod.z0, cp, rho); rec_up = (float *)calloc(ntfft*nkx,sizeof(float)); rec_down= (float *)calloc(ntfft*nkx,sizeof(float)); crec_vz = (complex *)malloc(nfreq*nkx*sizeof(complex)); crec_p = (complex *)malloc(nfreq*nkx*sizeof(complex)); crec_up = (complex *)malloc(nfreq*nkx*sizeof(complex)); crec_dw = (complex *)malloc(nfreq*nkx*sizeof(complex)); rec_vze = rec_up; rec_pe = rec_down; /* copy input data into extended arrays with padded zeroes */ for (ix=0; ix<mod.nax; ix++) { memcpy(&rec_vze[ix*ntfft],&rec_udvz[ix*rec.nt],nsam*sizeof(float)); memcpy(&rec_pe[ix*ntfft], &rec_udp[ix*rec.nt], nsam*sizeof(float)); } /* transform from t-x to kx-w */ xorig = ixsrc+ibndx; xt2wkx(rec_vze, crec_vz, ntfft, nkx, ntfft, nkx, xorig); xt2wkx(rec_pe, crec_p, ntfft, nkx, ntfft, nkx, xorig); /* apply decomposition operators */ kxwdecomp(crec_p, crec_vz, crec_up, crec_dw, nkx, mod.dx, nsam, dt, fmin, fmax, cp, rho, verbose); /* transform back to t-x */ wkx2xt(crec_up, rec_up, ntfft, nkx, nkx, ntfft, xorig); wkx2xt(crec_dw, rec_down, ntfft, nkx, nkx, ntfft, xorig); /* reduce array to rec.nt samples rec.n traces */ for (irec=0; irec<rec.n; irec++) { ix = rec.x[irec]+ibndx; for (it=0; it<rec.nt; it++) { rec_up[irec*rec.nt+it] = rec_up[ix*ntfft+it]; rec_down[irec*rec.nt+it] = rec_down[ix*ntfft+it]; } } free(crec_vz); free(crec_p); free(crec_up); free(crec_dw); } if (rec.type.ud && (mod.ischeme==3 || mod.ischeme==4) ) { } for (irec=0; irec<rec.n; irec++) { hdr.tracf = irec+1; hdr.tracl = ishot*rec.n+irec+1; hdr.gx = 1000*(mod.x0+rec.x[irec]*mod.dx); hdr.offset = (rec.x[irec]-ixsrc)*mod.dx; hdr.gelev = (int)(-1000*(mod.z0+rec.z[irec]*mod.dz)); if (rec.type.vx) { traceWrite( &hdr, &rec_vx[irec*rec.nt], nsam, fpvx) ; } if (rec.type.vz) { traceWrite( &hdr, &rec_vz[irec*rec.nt], nsam, fpvz) ; } if (rec.type.p) { traceWrite( &hdr, &rec_p[irec*rec.nt], nsam, fpp) ; } if (rec.type.txx) { traceWrite( &hdr, &rec_txx[irec*rec.nt], nsam, fptxx) ; } if (rec.type.tzz) { traceWrite( &hdr, &rec_tzz[irec*rec.nt], nsam, fptzz) ; } if (rec.type.txz) { traceWrite( &hdr, &rec_txz[irec*rec.nt], nsam, fptxz) ; } if (rec.type.pp) { traceWrite( &hdr, &rec_pp[irec*rec.nt], nsam, fppp) ; } if (rec.type.ss) { traceWrite( &hdr, &rec_ss[irec*rec.nt], nsam, fpss) ; } if (rec.type.ud && mod.ischeme==1) { traceWrite( &hdr, &rec_up[irec*rec.nt], nsam, fpup) ; traceWrite( &hdr, &rec_down[irec*rec.nt], nsam, fpdown) ; } } if (rec.type.vx) fclose(fpvx); if (rec.type.vz) fclose(fpvz); if (rec.type.p) fclose(fpp); if (rec.type.txx) fclose(fptxx); if (rec.type.tzz) fclose(fptzz); if (rec.type.txz) fclose(fptxz); if (rec.type.pp) fclose(fppp); if (rec.type.ss) fclose(fpss); if (rec.type.ud) { fclose(fpup); fclose(fpdown); free(rec_up); free(rec_down); } return 0; }
long writeSnapTimes3D(modPar mod, snaPar sna, bndPar bnd, wavPar wav, long ixsrc, long iysrc, long izsrc, long itime, float *vx, float *vy, float *vz, float *tzz, float *tyy, float *txx, float *txz, float *tyz, float *txy, long verbose) { FILE *fpvx, *fpvy, *fpvz, *fptxx, *fptyy, *fptzz, *fptxz, *fptyz, *fptxy, *fpp, *fppp, *fpss; long append, isnap; static long first=1; long n1, n2, ibndx, ibndy, ibndz, ixs, iys, izs, ize, i, j, l; long ix, iy, iz, ix2, iy2; float *snap, sdx, stime; segy hdr; if (sna.nsnap==0) return 0; ibndx = mod.ioXx; ibndy = mod.ioXy; ibndz = mod.ioXz; n1 = mod.naz; n2 = mod.nax; sdx = 1.0/mod.dx; if (sna.withbnd) { sna.nz=mod.naz; sna.z1=0; sna.z2=mod.naz-1; sna.skipdz=1; sna.ny=mod.nax; sna.y1=0; sna.y2=mod.nay-1; sna.skipdy=1; sna.nx=mod.nax; sna.x1=0; sna.x2=mod.nax-1; sna.skipdx=1; } /* check if this itime is a desired snapshot time */ if ( (((itime-sna.delay) % sna.skipdt)==0) && (itime >= sna.delay) && (itime <= sna.delay+(sna.nsnap-1)*sna.skipdt) ) { isnap = NINT((itime-sna.delay)/sna.skipdt); if (mod.grid_dir) stime = (-wav.nt+1+itime+1)*mod.dt; /* reverse time modeling */ else stime = itime*mod.dt; if (verbose) vmess("Writing snapshot(%li) at time=%.4f", isnap+1, stime); if (first) { append=0; first=0; } else { append=1; } if (sna.type.vx) fpvx = fileOpen(sna.file_snap, "_svx", (int)append); if (sna.type.vy) fpvy = fileOpen(sna.file_snap, "_svy", (int)append); if (sna.type.vz) fpvz = fileOpen(sna.file_snap, "_svz", (int)append); if (sna.type.p) fpp = fileOpen(sna.file_snap, "_sp", (int)append); if (sna.type.txx) fptxx = fileOpen(sna.file_snap, "_stxx", (int)append); if (sna.type.tyy) fptyy = fileOpen(sna.file_snap, "_styy", (int)append); if (sna.type.tzz) fptzz = fileOpen(sna.file_snap, "_stzz", (int)append); if (sna.type.txz) fptxz = fileOpen(sna.file_snap, "_stxz", (int)append); if (sna.type.tyz) fptyz = fileOpen(sna.file_snap, "_styz", (int)append); if (sna.type.txy) fptxy = fileOpen(sna.file_snap, "_stxy", (int)append); if (sna.type.pp) fppp = fileOpen(sna.file_snap, "_spp", (int)append); if (sna.type.ss) fpss = fileOpen(sna.file_snap, "_sss", (int)append); memset(&hdr,0,TRCBYTES); hdr.dt = 1000000*(sna.skipdt*mod.dt); hdr.ungpow = (sna.delay*mod.dt); hdr.scalco = -1000; hdr.scalel = -1000; hdr.sx = 1000*(mod.x0+ixsrc*mod.dx); hdr.sy = 1000*(mod.y0+iysrc*mod.dy); hdr.sdepth = 1000*(mod.z0+izsrc*mod.dz); hdr.fldr = isnap+1; hdr.trid = 1; hdr.ns = sna.nz; hdr.trwf = sna.nx*sna.nx; hdr.ntr = (isnap+1)*sna.nx; hdr.f1 = sna.z1*mod.dz+mod.z0; hdr.f2 = sna.x1*mod.dx+mod.x0; hdr.d1 = mod.dz*sna.skipdz; hdr.d2 = mod.dx*sna.skipdx; if (sna.withbnd) { if ( !ISODD(bnd.top)) hdr.f1 = mod.z0 - bnd.ntap*mod.dz; if ( !ISODD(bnd.lef)) hdr.f2 = mod.x0 - bnd.ntap*mod.dx; //if ( !ISODD(bnd.rig)) ; //if ( !ISODD(bnd.bot)) store=1; } /*********************************************************************** * vx velocities have one sample less in x-direction * vz velocities have one sample less in z-direction * txz stresses have one sample less in z-direction and x-direction ***********************************************************************/ snap = (float *)malloc(sna.nz*sizeof(float)); /* Decimate, with skipdx and skipdz, the number of gridpoints written to file and write to file. */ for (iys=sna.y1, l=0; iys<=sna.y2; iys+=sna.skipdy, l++) { for (ixs=sna.x1, i=0; ixs<=sna.x2; ixs+=sna.skipdx, i++) { hdr.tracf = l*sna.nx+i+1; hdr.tracl = isnap*sna.nx*sna.ny+l*sna.nx+i+1; hdr.gx = 1000*(mod.x0+ixs*mod.dx); hdr.gy = 1000*(mod.y0+iys*mod.dy); ix = ixs+ibndx; ix2 = ix+1; iy = iys+ibndy; iy2 = iy+1; izs = sna.z1+ibndz; ize = sna.z2+ibndz; if (sna.withbnd) { izs = 0; ize = sna.z2; ix = ixs; ix2 = ix; iy = iys; iy2 = iy; if (sna.type.vz || sna.type.txz || sna.type.tyz) izs = -1; if ( !ISODD(bnd.lef)) hdr.gx = 1000*(mod.x0 - bnd.ntap*mod.dx); if ( !ISODD(bnd.fro)) hdr.gy = 1000*(mod.y0 - bnd.ntap*mod.dy); } if (sna.type.vx) { for (iz=izs, j=0; iz<=ize; iz+=sna.skipdz, j++) { snap[j] = vx[iy*n1*n2+ix2*n1+iz]; } traceWrite(&hdr, snap, (int)sna.nz, fpvx); } if (sna.type.vy) { for (iz=izs, j=0; iz<=ize; iz+=sna.skipdz, j++) { snap[j] = vy[iy2*n1*n2+ix*n1+iz]; } traceWrite(&hdr, snap, (int)sna.nz, fpvy); } if (sna.type.vz) { for (iz=izs, j=0; iz<=ize; iz+=sna.skipdz, j++) { snap[j] = vz[iy*n1*n2+ix*n1+iz+1]; } traceWrite(&hdr, snap, (int)sna.nz, fpvz); } if (sna.type.p) { for (iz=izs, j=0; iz<=ize; iz+=sna.skipdz, j++) { snap[j] = tzz[iy*n1*n2+ix*n1+iz]; } traceWrite(&hdr, snap, (int)sna.nz, fpp); } if (sna.type.tzz) { for (iz=izs, j=0; iz<=ize; iz+=sna.skipdz, j++) { snap[j] = tzz[iy*n1*n2+ix*n1+iz]; } traceWrite(&hdr, snap, (int)sna.nz, fptzz); } if (sna.type.tyy) { for (iz=izs, j=0; iz<=ize; iz+=sna.skipdz, j++) { snap[j] = tyy[iy*n1*n2+ix*n1+iz]; } traceWrite(&hdr, snap, (int)sna.nz, fptyy); } if (sna.type.txx) { for (iz=izs, j=0; iz<=ize; iz+=sna.skipdz, j++) { snap[j] = txx[iy*n1*n2+ix*n1+iz]; } traceWrite(&hdr, snap, (int)sna.nz, fptxx); } if (sna.type.txz) { for (iz=izs, j=0; iz<=ize; iz+=sna.skipdz, j++) { snap[j] = txz[iy*n1*n2+ix2*n1+iz+1]; } traceWrite(&hdr, snap, (int)sna.nz, fptxz); } if (sna.type.txy) { for (iz=izs, j=0; iz<=ize; iz+=sna.skipdz, j++) { snap[j] = txy[iy2*n1*n2+ix2*n1+iz]; } traceWrite(&hdr, snap, (int)sna.nz, fptxy); } if (sna.type.tyz) { for (iz=izs, j=0; iz<=ize; iz+=sna.skipdz, j++) { snap[j] = tyz[iy2*n1*n2+ix*n1+iz+1]; } traceWrite(&hdr, snap, (int)sna.nz, fptyz); } /* calculate divergence of velocity field */ if (sna.type.pp) { for (iz=izs, j=0; iz<=ize; iz+=sna.skipdz, j++) { snap[j] = sdx*((vx[iy*n1*n2+(ix+1)*n1+iz]-vx[iy*n1*n2+ix*n1+iz])+ (vy[(iy+1)*n1*n2+ix*n1+iz]-vy[iy*n1*n2+ix*n1+iz])+ (vz[iy*n1*n2+ix*n1+iz+1]-vz[iy*n1*n2+ix*n1+iz])); } traceWrite(&hdr, snap, (int)sna.nz, fppp); } /* calculate rotation of velocity field */ if (sna.type.ss) { for (iz=izs, j=0; iz<=ize; iz+=sna.skipdz, j++) { snap[j] = sdx*((vx[iy*n1*n2+ix*n1+iz]-vx[(iy-1)*n1*n2+ix*n1+iz-1])- (vy[iy*n1*n2+ix*n1+iz]-vy[iy*n1*n2+(ix-1)*n1+iz-1])- (vz[iy*n1*n2+ix*n1+iz]-vz[(iy-1)*n1*n2+(ix-1)*n1+iz])); } traceWrite(&hdr, snap, (int)sna.nz, fpss); } } } if (sna.type.vx) fclose(fpvx); if (sna.type.vy) fclose(fpvy); if (sna.type.vz) fclose(fpvz); if (sna.type.p) fclose(fpp); if (sna.type.txx) fclose(fptxx); if (sna.type.tyy) fclose(fptyy); if (sna.type.tzz) fclose(fptzz); if (sna.type.txz) fclose(fptxz); if (sna.type.tyz) fclose(fptyz); if (sna.type.txy) fclose(fptxy); if (sna.type.pp) fclose(fppp); if (sna.type.ss) fclose(fpss); free(snap); } return 0; }
int writeSnapTimes(modPar mod, snaPar sna, bndPar bnd, int ixsrc, int izsrc, int itime, float *vx, float *vz, float *tzz, float *txx, float *txz, int verbose) { FILE *fpvx, *fpvz, *fptxx, *fptzz, *fptxz, *fpp, *fppp, *fpss; int append, isnap; static int first=1; int n1, ibndx, ibndz, ixs, izs, ize, i, j; int ix, iz, ix2; float *snap, sdx; segy hdr; if (sna.nsnap==0) return 0; ibndx = mod.ioXx; ibndz = mod.ioXz; n1 = mod.naz; sdx = 1.0/mod.dx; if (sna.withbnd) { sna.nz=mod.naz; sna.z1=0; sna.z2=mod.naz-1; sna.skipdz=1; sna.nx=mod.nax; sna.x1=0; sna.x2=mod.nax-1; sna.skipdx=1; } /* check if this itime is a desired snapshot time */ if ( (((itime-sna.delay) % sna.skipdt)==0) && (itime >= sna.delay) && (itime <= sna.delay+(sna.nsnap-1)*sna.skipdt) ) { isnap = NINT((itime-sna.delay)/sna.skipdt); if (verbose) vmess("Writing snapshot(%d) at time=%.4f", isnap+1, itime*mod.dt); if (first) { append=0; first=0; } else { append=1; } if (sna.type.vx) fpvx = fileOpen(sna.file_snap, "_svx", append); if (sna.type.vz) fpvz = fileOpen(sna.file_snap, "_svz", append); if (sna.type.p) fpp = fileOpen(sna.file_snap, "_sp", append); if (sna.type.txx) fptxx = fileOpen(sna.file_snap, "_stxx", append); if (sna.type.tzz) fptzz = fileOpen(sna.file_snap, "_stzz", append); if (sna.type.txz) fptxz = fileOpen(sna.file_snap, "_stxz", append); if (sna.type.pp) fppp = fileOpen(sna.file_snap, "_spp", append); if (sna.type.ss) fpss = fileOpen(sna.file_snap, "_sss", append); memset(&hdr,0,TRCBYTES); hdr.dt = 1000000*(sna.skipdt*mod.dt); hdr.ungpow = (sna.delay*mod.dt); hdr.scalco = -1000; hdr.scalel = -1000; hdr.sx = 1000*(mod.x0+ixsrc*mod.dx); hdr.sdepth = 1000*(mod.z0+izsrc*mod.dz); hdr.fldr = isnap+1; hdr.trid = 1; hdr.ns = sna.nz; hdr.trwf = sna.nx; hdr.ntr = (isnap+1)*sna.nx; hdr.f1 = sna.z1*mod.dz+mod.z0; hdr.f2 = sna.x1*mod.dx+mod.x0; hdr.d1 = mod.dz*sna.skipdz; hdr.d2 = mod.dx*sna.skipdx; if (sna.withbnd) { if ( !ISODD(bnd.top)) hdr.f1 = mod.z0 - bnd.ntap*mod.dz; if ( !ISODD(bnd.lef)) hdr.f2 = mod.x0 - bnd.ntap*mod.dx; //if ( !ISODD(bnd.rig)) ; //if ( !ISODD(bnd.bot)) store=1; } /*********************************************************************** * vx velocities have one sample less in x-direction * vz velocities have one sample less in z-direction * txz stresses have one sample less in z-direction and x-direction ***********************************************************************/ snap = (float *)malloc(sna.nz*sizeof(float)); /* Decimate, with skipdx and skipdz, the number of gridpoints written to file and write to file. */ for (ixs=sna.x1, i=0; ixs<=sna.x2; ixs+=sna.skipdx, i++) { hdr.tracf = i+1; hdr.tracl = isnap*sna.nx+i+1; hdr.gx = 1000*(mod.x0+ixs*mod.dx); ix = ixs+ibndx; ix2 = ix+1; izs = sna.z1+ibndz; ize = sna.z2+ibndz; if (sna.withbnd) { izs = 0; ize = sna.z2; ix = ixs; ix2 = ix; if (sna.type.vz || sna.type.txz) izs = -1; if ( !ISODD(bnd.lef)) hdr.gx = 1000*(mod.x0 - bnd.ntap*mod.dx); } if (sna.type.vx) { for (iz=izs, j=0; iz<=ize; iz+=sna.skipdz, j++) { snap[j] = vx[ix2*n1+iz]; } traceWrite(&hdr, snap, sna.nz, fpvx); } if (sna.type.vz) { for (iz=izs, j=0; iz<=ize; iz+=sna.skipdz, j++) { snap[j] = vz[ix*n1+iz+1]; } traceWrite(&hdr, snap, sna.nz, fpvz); } if (sna.type.p) { for (iz=izs, j=0; iz<=ize; iz+=sna.skipdz, j++) { snap[j] = tzz[ix*n1+iz]; } traceWrite(&hdr, snap, sna.nz, fpp); } if (sna.type.tzz) { for (iz=izs, j=0; iz<=ize; iz+=sna.skipdz, j++) { snap[j] = tzz[ix*n1+iz]; } traceWrite(&hdr, snap, sna.nz, fptzz); } if (sna.type.txx) { for (iz=izs, j=0; iz<=ize; iz+=sna.skipdz, j++) { snap[j] = txx[ix*n1+iz]; } traceWrite(&hdr, snap, sna.nz, fptxx); } if (sna.type.txz) { for (iz=izs, j=0; iz<=ize; iz+=sna.skipdz, j++) { snap[j] = txz[ix2*n1+iz+1]; } traceWrite(&hdr, snap, sna.nz, fptxz); } /* calculate divergence of velocity field */ if (sna.type.pp) { for (iz=izs, j=0; iz<=ize; iz+=sna.skipdz, j++) { snap[j] = sdx*((vx[(ix+1)*n1+iz]-vx[ix*n1+iz])+ (vz[ix*n1+iz+1]-vz[ix*n1+iz])); } traceWrite(&hdr, snap, sna.nz, fppp); } /* calculate rotation of velocity field */ if (sna.type.ss) { for (iz=izs, j=0; iz<=ize; iz+=sna.skipdz, j++) { snap[j] = sdx*((vx[ix*n1+iz]-vx[ix*n1+iz-1])- (vz[ix*n1+iz]-vz[(ix-1)*n1+iz])); } traceWrite(&hdr, snap, sna.nz, fpss); } } if (sna.type.vx) fclose(fpvx); if (sna.type.vz) fclose(fpvz); if (sna.type.p) fclose(fpp); if (sna.type.txx) fclose(fptxx); if (sna.type.tzz) fclose(fptzz); if (sna.type.txz) fclose(fptxz); if (sna.type.pp) fclose(fppp); if (sna.type.ss) fclose(fpss); free(snap); } return 0; }
int writeBeams(modPar mod, snaPar sna, int ixsrc, int izsrc, int ishot, int fileno, float *beam_vx, float *beam_vz, float *beam_txx, float *beam_tzz, float *beam_txz, float *beam_p, float *beam_pp, float *beam_ss, int verbose) { FILE *fpvx, *fpvz, *fptxx, *fptzz, *fptxz, *fpp, *fppp, *fpss; int append; int ix; char number[16], filename[1024]; segy hdr; if (sna.beam==0) return 0; /* all beam snapshots are written to the same output file(s) */ if (ishot) append=1; else append=0; strcpy(filename, sna.file_beam); if (fileno) { sprintf(number,"_%03d",fileno); name_ext(filename, number); } if (verbose>2) vmess("Writing beam data to file %s", filename); if (sna.type.vx) fpvx = fileOpen(filename, "_bvx", append); if (sna.type.vz) fpvz = fileOpen(filename, "_bvz", append); if (sna.type.p) fpp = fileOpen(filename, "_bp", append); if (sna.type.txx) fptxx = fileOpen(filename, "_btxx", append); if (sna.type.tzz) fptzz = fileOpen(filename, "_btzz", append); if (sna.type.txz) fptxz = fileOpen(filename, "_btxz", append); if (sna.type.pp) fppp = fileOpen(filename, "_bpp", append); if (sna.type.ss) fpss = fileOpen(filename, "_bss", append); memset(&hdr,0,TRCBYTES); hdr.dt = 1000000*(mod.dt); hdr.scalco = -1000; hdr.scalel = -1000; hdr.sx = 1000*(mod.x0+ixsrc*mod.dx); hdr.sdepth = 1000*(mod.z0+izsrc*mod.dz); hdr.fldr = ishot+1; hdr.trid = 1; hdr.ns = sna.nz; hdr.trwf = sna.nx; hdr.ntr = sna.nx; hdr.f1 = sna.z1*mod.dz+mod.z0; hdr.f2 = sna.x1*mod.dx+mod.x0; hdr.d1 = mod.dz*sna.skipdz; hdr.d2 = mod.dx*sna.skipdx; for (ix=0; ix<sna.nx; ix++) { hdr.tracf = ix+1; hdr.tracl = ix+1; hdr.gx = 1000*(mod.x0+(sna.x1+ix)*mod.dx); if (sna.type.vx) { traceWrite( &hdr, &beam_vx[ix*sna.nz], sna.nz, fpvx) ; } if (sna.type.vz) { traceWrite( &hdr, &beam_vz[ix*sna.nz], sna.nz, fpvz) ; } if (sna.type.p) { traceWrite( &hdr, &beam_p[ix*sna.nz], sna.nz, fpp) ; } if (sna.type.tzz) { traceWrite( &hdr, &beam_tzz[ix*sna.nz], sna.nz, fptzz) ; } if (sna.type.txx) { traceWrite( &hdr, &beam_txx[ix*sna.nz], sna.nz, fptxx) ; } if (sna.type.txz) { traceWrite( &hdr, &beam_txz[ix*sna.nz], sna.nz, fptxz) ; } if (sna.type.pp) { traceWrite( &hdr, &beam_pp[ix*sna.nz], sna.nz, fppp) ; } if (sna.type.ss) { traceWrite( &hdr, &beam_ss[ix*sna.nz], sna.nz, fpss) ; } } if (sna.type.vx) fclose(fpvx); if (sna.type.vz) fclose(fpvz); if (sna.type.p) fclose(fpp); if (sna.type.txx) fclose(fptxx); if (sna.type.tzz) fclose(fptzz); if (sna.type.txz) fclose(fptxz); if (sna.type.pp) fclose(fppp); if (sna.type.ss) fclose(fpss); return 0; }