void integ(float **mig,int nz,float dz,int nx,int m,float **migi) /* integration of a two-dimensional array input: mig[nx][nz] two-dimensional array output: migi[nx][nz+2*m] integrated array */ { int nfft, nw, ix, iz, iw; float *amp, dw, *rt; complex *ct; /* Set up FFT parameters */ nfft = npfaro(nz+m, 2 * (nz+m)); if (nfft >= SU_NFLTS || nfft >= 720720) err("Padded nt=%d -- too big", nfft); nw = nfft/2 + 1; dw = 2.0*PI/(nfft*dz); amp = ealloc1float(nw); for(iw=1; iw<nw; ++iw) amp[iw] = 0.5/(nfft*(1-cos(iw*dw*dz))); amp[0] = amp[1]; /* Allocate fft arrays */ rt = ealloc1float(nfft); ct = ealloc1complex(nw); for(ix=0; ix<nx; ++ix) { memcpy(rt, mig[ix], nz*FSIZE); memset((void *) (rt + nz), 0, (nfft-nz)*FSIZE); pfarc(1, nfft, rt, ct); /* Integrate traces */ for(iw=0; iw<nw; ++iw){ ct[iw].i = ct[iw].i*amp[iw]; ct[iw].r = ct[iw].r*amp[iw]; } pfacr(-1, nfft, ct, rt); for (iz=0; iz<m; ++iz) migi[ix][iz] = rt[nfft-m+iz]; for (iz=0; iz<nz+m; ++iz) migi[ix][iz+m] = rt[iz]; } free1float(amp); free1float(rt); free1complex(ct); }
int main(int argc, char **argv) { int nx1,nx2; /* numbers of samples */ int ix1, ix2; /* sample indices */ float a1,a2; /* filter dimensions */ float pi; /* pi number */ float vmax; /* maximum value of the data */ float vfmax; /* scale factor after filtering */ float c1,c2; float **v=NULL; /* array of velocities */ float *k1=NULL,*k2=NULL; /* wavenumber arrays */ float *kfilt1=NULL,*kfilt2=NULL;/* intermediate filter arrays */ float dk1,dk2; /* wavenumber interval */ float **kfilter=NULL; /* array of filter values */ int nx1fft,nx2fft; /* dimensions after padding for FFT */ int nK1,nK2; /* transform dimension */ int ik1,ik2; /* wavenumber indices */ register complex **ct=NULL; /* complex FFT workspace */ register float **rt=NULL; /* float FFT workspace */ FILE *tracefp=NULL; /* temp file to hold traces */ FILE *hfp=NULL; /* temp file to hold trace headers */ /* hook up getpar to handle the parameters */ initargs(argc, argv); requestdoc(1); /* Get parameters from command line */ if (!getparfloat("a1",&a1)) a1=0.; if (!getparfloat("a2",&a2)) a2=0.; /* Get info from first trace */ if (!gettr(&tr)) err("can't get first trace"); if (tr.trid != TRID_DEPTH) warn("tr.trid=%d",tr.trid); nx1=tr.ns; /* Store traces in tmpfile while getting a count */ tracefp=etmpfile(); hfp=etmpfile(); nx2=0; do { ++nx2; efwrite(&tr,HDRBYTES, 1, hfp); efwrite(tr.data, FSIZE, nx1, tracefp); } while (gettr(&tr)); /* Determine number of wavenumbers in K1 and K2 */ nx1fft=npfaro(nx1, LOOKFAC*nx1); nx2fft=npfa(nx2); if (nx1fft >=SU_NFLTS || nx1fft >= PFA_MAX) err("Padded nx1=%d--too big",nx1fft); if (nx2fft >= PFA_MAX) err("Padded nx2=%d--too big",nx2fft); /* Determine number of wavenumbers in K1 and K2 */ nK1=nx1fft/2 + 1; nK2=nx2fft/2 + 1; /* Allocate space */ v=alloc2float(nx1,nx2); rt=alloc2float(nx1fft,nx2fft); ct=alloc2complex(nK1,nx2fft); kfilter=alloc2float(nx1fft,nx2fft); k1=alloc1float(nK1); k2=alloc1float(nK2); kfilt1= alloc1float(nK1); kfilt2= alloc1float(nK2); /* Zero all arrays */ memset((void *) rt[0], 0, nx1fft*nx2fft*FSIZE); memset((void *) kfilter[0], 0, nx1fft*nx2fft*FSIZE); memset((void *) ct[0], 0, nK1*nx2fft*sizeof(complex)); memset((void *) k1, 0, nK1*FSIZE); memset((void *) k2, 0, nK2*FSIZE); memset((void *) kfilt1, 0, nK1*FSIZE); memset((void *) kfilt2, 0, nK2*FSIZE); /* Determine wavenumber arrays for the filter */ pi=PI; dk1=2*pi / nx1fft; dk2=2*pi / nx2fft; for (ik1=0; ik1<nK1; ++ik1) { c1=a1*ik1*dk1/ 2; kfilt1[ik1]= exp(-pow(c1,2)); } for (ik2=0; ik2<nK2; ++ik2) { c2= a2*ik2*dk2/2; kfilt2[ik2]= exp(-pow(c2,2)); } /* Build Gaussian filter */ /* positive k1, positive k2 */ for (ik2=0; ik2<nK2; ++ik2) { for (ik1=0; ik1<nK1; ++ik1) { kfilter[ik2][ik1]=kfilt2[ik2]*kfilt1[ik1]; } } /* positive k1, negative k2 */ for (ik2=nK2; ik2<nx2fft; ++ik2) { for (ik1=0; ik1<nK1; ++ik1) { kfilter[ik2][ik1]=kfilt2[nx2fft-ik2]*kfilt1[ik1]; } } /* Read velocities from temp file and determine maximum */ rewind(tracefp); fread(v[0],sizeof(float),nx2*nx1,tracefp); vmax=v[0][0]; for (ix2=0; ix2<nx2; ++ix2) { for (ix1=0; ix1<nx1; ++ix1) { vmax=MAX(vmax,v[ix2][ix1]); } } /* Load data into FFT arrays */ rewind(tracefp); for (ix2=0; ix2<nx2; ++ix2) { efread(rt[ix2], FSIZE, nx1, tracefp); } /* Fourier transform dimension 1 */ pfa2rc(-1,1,nx1fft,nx2,rt[0],ct[0]); /* Fourier transform dimension 2 */ pfa2cc(-1,2,nK1,nx2fft,ct[0]); /* Apply filter to the data */ for (ik2=0; ik2<nx2fft; ++ik2) { for (ik1=0; ik1<nK1; ++ik1) { ct[ik2][ik1]=crmul(ct[ik2][ik1], kfilter[ik2][ik1]) ; } } /* Inverse Fourier transformation dimension 2 */ pfa2cc(1,2,nK1,nx2fft,ct[0]); /* Inverse Fourier transformation dimension 1 */ pfa2cr(1,1,nx1fft,nx2,ct[0],rt[0]); /* Find maximum of filtered data */ vfmax=rt[0][0]; for (ix2=0; ix2<nx2; ++ix2) { for (ix1=0; ix1<nx1; ++ix1) { vfmax=MAX(vfmax,rt[ix2][ix1]); } } /* Rescale and output filtered data */ erewind(hfp); for (ix2=0; ix2<nx2; ++ix2) { efread(&tr, HDRBYTES, 1, hfp); for (ix1=0; ix1<nx1; ++ix1) tr.data[ix1]=(rt[ix2][ix1]) * vmax / vfmax; puttr(&tr); } efclose(hfp); return(CWP_Exit()); }
int main(int argc, char **argv) { float phase; /* phase shift = phasefac*PI */ float power; /* phase shift = phasefac*PI */ register float *rt; /* real trace */ register complex *ct; /* complex transformed trace */ complex *filt; /* complex power */ int nt; /* number of points on input trace */ size_t ntsize; /* nt in bytes */ int ncdp; /* number of cdps specified */ int icdp; /* index into cdp array */ long oldoffset; /* offset of previous trace */ long oldcdp; /* cdp of previous trace */ int newsloth; /* if non-zero, new sloth function was computed */ int jcdp; /* index into cdp array */ float dt; /* sample spacing (secs) on input trace */ float tn; /* sample spacing (secs) on input trace */ float omega; /* circular frequency */ float domega; /* circular frequency spacing (from dt) */ int nfft; /* number of points in nfft */ int ntnmo; /* number of tnmos specified */ float *cdp; /* array[ncdp] of cdps */ float *vnmo; /* array[nvnmo] of vnmos */ float *ovvt; /* array[nvnmo] of vnmos */ int nvnmo; /* number of tnmos specified */ float *fnmo; /* array[ntnmo] of tnmos */ float **ovv; /* array[nf] of fnmos */ float doffs; /* offset */ float acdp; /* temporary used to sort cdp array */ float *aovv; /* temporary used to sort ovv array */ int invert; /* if non-zero, do invers DLMO */ int cm; /* if non-zero, the offset in cm */ int nf; /* number of frequencies (incl Nyq) */ int it; /* number of frequencies (incl Nyq) */ float onfft; /* 1 / nfft */ float v; /* velocity */ size_t nzeros; /* number of padded zeroes in bytes */ /* Initialize */ initargs(argc, argv); requestdoc(1); /* Set parameters */ power=0.0; /* Get info from first trace*/ if (!gettr(&tr)) err("can't get first trace"); nt = tr.ns; if (!getparfloat("dt", &dt)) dt = ((double) tr.dt)/1000000.0; if (!dt) err("dt field is zero and not getparred"); ntsize = nt * FSIZE; if (!getparint("invert",&invert)) invert = 0; if (!getparint("cm",&cm)) cm = 0; /* Set up for fft */ nfft = npfaro(nt, LOOKFAC * nt); if (nfft >= SU_NFLTS || nfft >= PFA_MAX) err("Padded nt=%d -- too big", nfft); nf = nfft/2 + 1; onfft = 1.0 / nfft; nzeros = (nfft - nt) * FSIZE; domega = TWOPI * onfft / dt; /* get velocity functions, linearly interpolated in frequency */ ncdp = countparval("cdp"); if (ncdp>0) { if (countparname("vnmo")!=ncdp) err("a vnmo array must be specified for each cdp"); if (countparname("fnmo")!=ncdp) err("a tnmo array must be specified for each cdp"); } else { ncdp = 1; if (countparname("vnmo")>1) err("only one (or no) vnmo array must be specified"); if (countparname("fnmo")>1) err("only one (or no) tnmo array must be specified"); } cdp = ealloc1float(ncdp); if (!getparfloat("cdp",cdp)) cdp[0] = tr.cdp; ovv = ealloc2float(nf,ncdp); for (icdp=0; icdp<ncdp; ++icdp) { nvnmo = countnparval(icdp+1,"vnmo"); ntnmo = countnparval(icdp+1,"fnmo"); if (nvnmo!=ntnmo && !(ncdp==1 && nvnmo==1 && ntnmo==0)) err("number of vnmo and tnmo values must be equal"); if (nvnmo==0) nvnmo = 1; if (ntnmo==0) ntnmo = nvnmo; /* equal numbers of parameters vnmo, fnmo */ vnmo = ealloc1float(nvnmo); fnmo = ealloc1float(nvnmo); if (!getnparfloat(icdp+1,"vnmo",vnmo)) vnmo[0] = 400.0; if (!getnparfloat(icdp+1,"fnmo",fnmo)) fnmo[0] = 0.0; for (it=0; it<ntnmo; ++it) fnmo[it]*=TWOPI; for (it=1; it<ntnmo; ++it) if (fnmo[it]<=fnmo[it-1]) err("tnmo values must increase monotonically"); for (it=0,tn=0; it<nf; ++it,tn+=domega) { intlin(ntnmo,fnmo,vnmo,vnmo[0],vnmo[nvnmo-1],1,&tn,&v); ovv[icdp][it] = 1.0/(v); } free1float(vnmo); free1float(fnmo); } /* sort (by insertion) sloth and anis functions by increasing cdp */ for (jcdp=1; jcdp<ncdp; ++jcdp) { acdp = cdp[jcdp]; aovv = ovv[jcdp]; for (icdp=jcdp-1; icdp>=0 && cdp[icdp]>acdp; --icdp) { cdp[icdp+1] = cdp[icdp]; ovv[icdp+1] = ovv[icdp]; } cdp[icdp+1] = acdp; ovv[icdp+1] = aovv; } /* allocate workspace */ ovvt = ealloc1float(nf); /* interpolate sloth and anis function for first trace */ interpovv(nf,ncdp,cdp,ovv,(float)tr.cdp,ovvt); /* set old cdp and old offset for first trace */ oldcdp = tr.cdp; oldoffset = tr.offset-1; /* Allocate fft arrays */ rt = ealloc1float(nfft); ct = ealloc1complex(nf); filt = ealloc1complex(nf); /* Loop over traces */ do { /* if necessary, compute new sloth and anis function */ if (tr.cdp!=oldcdp && ncdp>1) { interpovv(nt,ncdp,cdp,ovv,(float)tr.cdp, ovvt); newsloth = 1; } else { newsloth = 0; } /* if sloth and anis function or offset has changed */ if (newsloth || tr.offset!=oldoffset) { doffs = (fabs)((float)(tr.offset)); if (cm==1) doffs/=100; /* Load trace into rt (zero-padded) */ memcpy( (void *) rt, (const void *) tr.data, ntsize); memset((void *) (rt + nt), (int) '\0', nzeros); /* FFT */ pfarc(1, nfft, rt, ct); /* Apply filter */ { register int i; for (i = 0; i < nf; ++i){ omega = i * domega; if (power < 0 && i == 0) omega = FLT_MAX; if (invert==0) phase = -1.0*omega*ovvt[i]*doffs; else phase = 1.0*omega*ovvt[i]*doffs; /* filt[i] = cmplx(cos(phase),sin(phase)); */ filt[i] = cwp_cexp(crmul(I,phase)); filt[i] = crmul(filt[i], onfft); ct[i] = cmul(ct[i], filt[i]); } } } /* Invert */ pfacr(-1, nfft, ct, rt); /* Load traces back in, recall filter had nfft factor */ { register int i; for (i = 0; i < nt; ++i) tr.data[i] = rt[i]; } puttr(&tr); } while (gettr(&tr)); return EXIT_SUCCESS; }
int main(int argc, char **argv) { float a, b; /* powers for amp and phase */ register float *rt=NULL;/* real trace */ register complex *ct=NULL; /* complex transformed trace */ complex filt; /* pow'd input at one frequency */ int nt; /* number of points on input trace */ size_t ntsize; /* nt in bytes */ float dt; /* sample spacing (secs) on input trace */ int nfft; /* number of points in nfft */ int nf; /* number of frequencies (incl Nyq) */ float onfft; /* 1 / nfft */ int verbose; /* flag to get advisory messages */ size_t nzeros; /* number of padded zeroes in bytes */ cwp_Bool seismic; /* is this seismic data? */ int ntout, sym; /* output params */ /* Initialize */ initargs(argc, argv); requestdoc(1); /* Set parameters */ if (!getparint("verbose", &verbose)) verbose = 0; if (!getparfloat("a", &a)) a = 0.0; if (!getparfloat("b", &b)) b = 0.0; if (!getparint("sym",&sym)) sym = 0; /* Get info from first trace */ if (!gettr(&tr)) err("can't get first trace"); seismic = ISSEISMIC(tr.trid); if (seismic) { if (verbose) warn("input is seismic data, trid=%d",tr.trid); dt = ((double) tr.dt)/1000000.0; } else { if (verbose) warn("input is not seismic data, trid=%d",tr.trid); dt = tr.d1; } if (!dt) err("dt or d1 field is zero and not getparred"); nt = tr.ns; ntsize = nt * FSIZE; if (!getparint("ntout",&ntout)) ntout=tr.ns; /* Set up for fft extra 2 in nfft is to avoid wrap around */ nfft = npfaro(nt, LOOKFAC * nt); if (nfft >= SU_NFLTS || nfft >= PFA_MAX) err("Padded nt=%d -- too big", nfft); nf = nfft/2 + 1; onfft = 1.0 / nfft; nzeros = (nfft - nt) * FSIZE; /* Allocate fft arrays */ rt = ealloc1float(nfft); ct = ealloc1complex(nf); /* Loop over traces */ do { /* Load trace into rt (zero-padded) */ memcpy( (void *) rt, (const void *) tr.data, ntsize); memset((void *) (rt + nt), 0, nzeros); /* FFT */ pfarc(1, nfft, rt, ct); /* Apply filter */ { register int i; for (i = 0; i < nf; ++i) { filt = dopow(ct[i], a, b); ct[i] = cmul(ct[i], filt); /* symmetric output: flip sign of odd values */ if (sym){ if (ISODD(i)) { ct[i].r = -ct[i].r; ct[i].i = -ct[i].i; } } } } /* Invert */ pfacr(-1, nfft, ct, rt); /* Load traces back in */ { register int i; for (i = 0; i < nt; ++i) tr.data[i] = rt[i]; } puttr(&tr); } while (gettr(&tr)); return(CWP_Exit()); }
int main(int argc, char **argv) { float c; /* speed */ float dt; /* sampling rate */ int nt; /* number of samples */ size_t ntsize; /* ... in bytes */ int nshot; /* number of shots */ int nrec; /* number of receivers */ float x0, y0, z0; /* point scatterer location */ float sxmin, symin, szmin; /* first shot location */ float gxmin, gymin, gzmin; /* first receiver location */ float dsx, dsy, dsz; /* step in shot location */ float dgx, dgy, dgz; /* step in receiver location */ float sx, sy, sz; /* shot location */ float gx, gy, gz; /* receiver location */ float rs; /* distance to shot */ float rg; /* distance to receiver */ float d; /* rs + rg */ float t; /* total travel time */ float k; /* constant part of response */ register float *rt; /* real trace */ register complex *ct; /* complex transformed trace */ int nfft; /* size of fft */ int nfby2; /* nfft/2 */ int nfby2p1; /* nfft/2 + 1 */ size_t nzeros; /* padded zeroes in bytes */ float spread; /* 3-D spreading factor */ register int i; /* counter */ register int s; /* shot counter */ register int g; /* receiver counter */ register int tracl; /* trace counter */ float amplitude[1]; /* amplitude */ float *tout; /* times[nt] for interpolation */ /* Initialize */ initargs(argc, argv); requestdoc(0); /* Get parameters */ if (!getparint("nshot", &nshot)) nshot = 1; if (!getparint("nrec", &nrec)) nrec = 1; if (!getparint("nt", &nt)) nt = 256; if (!getparfloat("c", &c)) c = 5000.0; if (!getparfloat("dt", &dt)) dt = 0.004; if (!getparfloat("x0", &x0)) x0 = 1000.0; if (!getparfloat("y0", &y0)) y0 = 0.0; if (!getparfloat("z0", &z0)) z0 = 1000.0; if (!getparfloat("sxmin", &sxmin)) sxmin = 0.0; if (!getparfloat("symin", &symin)) symin = 0.0; if (!getparfloat("szmin", &szmin)) szmin = 0.0; if (!getparfloat("gxmin", &gxmin)) gxmin = 0.0; if (!getparfloat("gymin", &gymin)) gymin = 0.0; if (!getparfloat("gzmin", &gzmin)) gzmin = 0.0; if (!getparfloat("dsx", &dsx)) dsx = 100.0; if (!getparfloat("dsy", &dsy)) dsy = 0.0; if (!getparfloat("dsz", &dsz)) dsz = 0.0; if (!getparfloat("dgx", &dgx)) dgx = 100.0; if (!getparfloat("dgy", &dgy)) dgy = 0.0; if (!getparfloat("dgz", &dgz)) dgz = 0.0; /* Set the constant header fields */ tr.ns = nt; tr.dt = dt * 1000000.0; ntsize = nt * FSIZE; /* Set up for fft */ nfft = npfaro(nt, LOOKFAC * nt); if (nfft >= SU_NFLTS || nfft >= PFA_MAX) err("Padded nt=%d -- too big", nfft); nfby2 = nfft / 2; nfby2p1 = nfby2 + 1; nzeros = (nfft - nt) * FSIZE; /* Allocate fft arrays */ rt = ealloc1float(nfft); ct = ealloc1complex(nfby2p1); /* Set the constant in the response amplitude including scale for inverse fft below */ k = 1.0 / (4.0 * c * c * dt * dt * dt * nfft * nfft * nfft); /* Compute output times for interpolation */ tout = ealloc1float(nt); for (i=0; i<nt; i++) tout[i]=i*dt; /* Create the traces */ tracl = 0; for (s = 0; s < nshot; ++s) { /* loop over shots */ sx = sxmin + s * dsx; sy = symin + s * dsy; sz = szmin + s * dsz; rs = sqrt((sx - x0)*(sx - x0) + (sy - y0)*(sy - y0) + (sz - z0)*(sz - z0)); for (g = 0; g < nrec; ++g) { /* loop over receivers */ memset( (void *) tr.data, 0, ntsize); gx = gxmin + g * dgx; gy = gymin + g * dgy; gz = gzmin + g * dgz; rg = sqrt((gx - x0)*(gx - x0) + (gy - y0)*(gy - y0) + (gz - z0)*(gz - z0)); d = rs + rg; t = d/c; spread = rs*rg; amplitude[0] = k/spread; /* Distribute response over full trace */ ints8r(1,dt,t,amplitude,0,0,nt,tout,tr.data); /* Load trace into rt (zero-padded) */ memcpy( (void *) rt, (const void *) tr.data, ntsize); memset( (void *) (rt + nt), 0, nzeros); /* FFT */ pfarc(1, nfft, rt, ct); /* Multiply by omega^2 */ for (i = 0; i < nfby2p1; ++i) ct[i] = crmul(ct[i], i*i); /* Invert and take real part */ pfacr(-1, nfft, ct, rt); /* Load traces back in */ memcpy( (void *) tr.data, (const void *) rt, ntsize); /* Set header fields---shot fields set above */ tr.tracl = tr.tracr = ++tracl; tr.fldr = 1 + s; tr.tracf = 1 + g; tr.sx = NINT(sx); tr.sy = NINT(sy); tr.selev = -NINT(sz); /* above sea level > 0 */ tr.gx = NINT(gx); tr.gy = NINT(gy); tr.gelev = -NINT(gz); /* above sea level > 0 */ /* If along a coordinate axis, use a signed offset */ tr.offset = sqrt((sx - gx)*(sx - gx) + (sy - gy)*(sy - gy) + (sz - gz)*(sz - gz)); if (dgy == 0 && dgz == 0) tr.offset = NINT(dsx > 0 ? gx - sx : sx - gx); if (dgx == 0 && dgz == 0) tr.offset = NINT(dsy > 0 ? gy - sy : sy - gy); if (dgx == 0 && dgy == 0) tr.offset = NINT(dsz > 0 ? gz - sz : sz - gz); puttr(&tr); } /* end loop on receivers */ } /* end loop on shots */ return(CWP_Exit()); }
int main(int argc, char **argv) { register float *rt; /* real trace */ register complex *ct; /* complex transformed trace */ int nt; /* number of points on input trace */ int nfft; /* transform length */ int nf; /* number of frequencies */ int sign; /* sign in exponent of transform */ int verbose; /* flag to get advisory messages */ float dt; /* sampling interval in secs */ float d1; /* output sample interval in Hz */ cwp_Bool seismic; /* is this seismic data? */ float c; /* multiplier */ float w0, w1, w2; /* weights */ /* Initialize */ initargs(argc, argv); requestdoc(1); if (!getparint("verbose", &verbose)) verbose=1; /* Get info from first trace */ if (!gettr(&tr)) err("can't get first trace"); nt = tr.ns; /* check for seismic or well log data */ seismic = ISSEISMIC(tr.trid); if (seismic) { if (verbose) warn("input is seismic data, trid=%d",tr.trid); dt = ((double) tr.dt)/1000000.0; } else { if (verbose) warn("input is not seismic data, trid=%d",tr.trid); dt = tr.d1; } if (!dt) { dt = .004; if (verbose) warn("dt or d1 not set, assumed to be .004"); } /* Set up pfa fft */ nfft = npfaro(nt, LOOKFAC * nt); if (nfft >= SU_NFLTS || nfft >= PFA_MAX) err("Padded nt=%d--too big", nfft); nf = nfft/2 + 1; d1 = 1.0/(nfft*dt); if (!getparint("sign", &sign)) sign = 1; if (sign != 1 && sign != -1) err("sign = %d must be 1 or -1", sign); /* get weights */ if (!getparfloat("w0",&w0)) w0 = 0.75; if (!getparfloat("w1",&w1)) w1 = 1.00; if (!getparfloat("w2",&w2)) w2 = 0.75; rt = ealloc1float(nfft); ct = ealloc1complex(nf); /* If dt not set, issue advisory on frequency step d1 */ if (dt && verbose) warn("d1=%f", 1.0/(nfft*dt)); /* Main loop over traces */ do { register int i; /* Load trace into rt (zero-padded) */ memcpy((void *) rt, (const void *) tr.data, nt*FSIZE); memset((void *) (rt + nt), (int) '\0', (nfft-nt)*FSIZE); /* FFT */ pfarc(sign, nfft, rt, ct); /* Store values */ for (i = 0; i < nf; ++i) { c =w0*rcabs(ct[i-1])+w1*rcabs(ct[i])+w2*rcabs(ct[i+1]); if (i==0 || i==nf) { tr.data[2*i] = ct[i].r / rcabs(ct[i]); tr.data[2*i+1] = ct[i].i / rcabs(ct[i]); } else { tr.data[2*i] = ct[i].r / c; tr.data[2*i+1] = ct[i].i / c; } } /* Set header values--npfaro makes nfft even */ tr.ns = 2 * nf; tr.trid = FUNPACKNYQ; tr.d1 = d1; tr.f1 = 0.0; puttr(&tr); } while (gettr(&tr)); return(CWP_Exit()); }
main(int argc, char **argv) { float **filter; /* filter arrays */ float *tf; /* times at which filters are centered */ int *itf; /* ... as integers */ int jmin; /* index of first filter itf value */ int jmax; /* index of last filter itf value */ int nfft; /* fft sizes in each time gate */ int nfreq; /* number of frequencies */ float **ftrace; /* filtered sub-traces */ int nfilter; /* number of filters specified */ float dt; /* sample spacing */ float tmin; /* first time on traces */ int nt; /* number of points on input trace */ float *data; FILE *infp=stdin, *outfp=stdout; /* Initialize */ initargs(argc, argv); requestdoc(1); /* Get info from first trace */ file2g(infp); file2g(outfp); if (!fgettr(infp,&tr)) err("can't get first trace"); if (tr.trid && tr.trid != TREAL) err("input is not seismic data, trid=%d", tr.trid); nt = tr.ns; if (!getparfloat("dt", &dt)) dt = (float)tr.dt/1000000.0; if (!dt) err("dt field is zero and not getparred"); tmin = tr.delrt/1000.0; /* Get number of filters and center times */ if (!(nfilter = countparval("tf"))) MUSTGETPARFLOAT("tf", tf); if (countparname("f") != nfilter) err("must give one f 4-tuple for each" " (%d) tf value", nfilter); /* Leave room for possibly missing filters at endpoints */ tf = ealloc1float(nfilter+4); /* never use ist2 or last 2 */ itf = ealloc1int(nfilter+4); getparfloat("tf", tf+2); jmin = 2; jmax = nfilter + 1; { register int j; for (j = jmin; j <= jmax; ++j) itf[j] = NINT((tf[j] - tmin)/dt); } /* Make filters with scale for inverse transform */ nfft = npfaro(nt, LOOKFAC * nt); if (nfft >= MIN(SU_NFLTS, PFA_MAX)) err("Padded nt=%d -- too big", nfft); nfreq = nfft/2 + 1; filter = ealloc2float(nfreq, nfilter+4); /* never use 1st & last */ { register int j; for (j = jmin; j <= jmax; ++j) { float *f = ealloc1float(4); if (getnparfloat(j-jmin+1, "f", f) != 4) err("must give 4 corner frequencies in f="); if (f[0] < 0.0 || f[0] > f[1] || f[1] >= f[2] || f[2] > f[3]) err("Filter #%d has bad frequencies", j - jmin + 1); makefilter(f, nfft, nfreq, dt, filter[j]); } } /* User may not have given a filter for tmin and/or tmax-- */ /* Extend array so can always assume these filters are present. */ /* Note don't really use any of the extra storage in **filter! */ if (itf[jmin] > 0) { filter[jmin-1] = filter[jmin]; itf[jmin-1] = 0; --jmin; } if (itf[jmax] < nt - 1) { filter[jmax+1] = filter[jmax]; itf[jmax+1] = nt - 1; ++jmax; } /* Extend array so can always consider time points to be interior */ itf[jmin-1] = 0; /* now jmin - 1 is a valid index */ itf[jmax+1] = nt - 1; /* now jmax + 1 is a valid index */ /* Main loop over traces */ ftrace = ealloc2float(nt, nfilter+4); /* never use 1st & last */ data = ealloc1float(nt); do { register int i, j; /* Construct filtered sub-traces */ for (j = jmin; j <= jmax; ++j) { bzero(data, nt*FSIZE); for (i = itf[j-1]; i <= itf[j+1]; ++i) data[i] = tr.data[i]; bandpass(data,nt,nfft,nfreq,filter[j],ftrace[j]); } /* Compose filtered trace from sub-traces */ for (j = jmin; j < jmax; ++j) { float fitfj; for (fitfj = i = itf[j]; i <= itf[j+1]; ++i) { float a = (i - fitfj)/(itf[j+1] - fitfj); tr.data[i] = (1-a)*ftrace[j][i] + a*ftrace[j+1][i]; } } fputtr(outfp,&tr); } while (fgettr(infp,&tr)); return EXIT_SUCCESS; }
int main(int argc, char **argv) { float *rt=NULL; /* real trace */ float *amp=NULL; /* amplitude spectra */ float *ph=NULL; /* phase */ register complex *ct=NULL; /* complex time trace */ int nt; /* number of points on input trace */ int nfft; /* transform length */ int nf; /* number of frequencies in transform */ float dt; /* sampling interval in secs */ float d1; /* output sample interval in Hz */ int count=0; /* counter */ /* linear phase function */ float a; /* bias (intercept) of new phase */ float b; /* slope of linear phase function */ float c; /* new phase value */ float onfft; /* 1/nfft */ /* Initialize */ initargs(argc, argv); requestdoc(1); /* Get info from first trace */ if (!gettr(&tr)) err("can't get first trace"); nt = tr.ns; /* get parameters */ /* dt is used only to set output header value d1 */ if (!getparfloat("dt", &dt)) dt = ((double) tr.dt)/1000000.0; if (!dt) { dt = .004; warn("dt not set, assumed to be .002"); } /* linear phase paramter values */ if (!getparfloat("a", &a)) a = 0; if (!getparfloat("b", &b)) b = 180/PI; if (!getparfloat("c", &c)) c = 0.0; a *= PI/180.0; b *= PI/180.0; /* Set up pfa fft */ nfft = npfaro(nt, LOOKFAC * nt); if (nfft >= SU_NFLTS || nfft >= PFA_MAX) err("Padded nt=%d--too big", nfft); d1 = 1.0/(nfft*dt); nf = nfft/2 + 1; onfft = 1.0/nfft; checkpars(); /* Allocate space */ rt = ealloc1float(nfft); ct = ealloc1complex(nf); amp = ealloc1float(nf); ph = ealloc1float(nf); /* Main loop over traces */ count=0; do { register int i; /* Load trace into rt (zero-padded) */ memcpy((void *) rt, (const void *) &tr.data, nt*FSIZE); memset((void *) (rt + nt), (int) '\0', (nfft-nt)*FSIZE); /* FFT */ pfarc(1, nfft, rt, ct); for (i = 0; i < nf; ++i) { amp[i] = AMPSP(ct[i]); ph[i] = a+b*atan2(ct[i].i,ct[i].r)+c*i; } for (i = 0; i < nf; ++i) { ct[i].r = amp[i]*cos(ph[i]); ct[i].i = amp[i]*sin(ph[i]); } pfacr(-1,nfft,ct,rt); for (i = 0; i < nt; ++i) rt[i]*=onfft; memcpy((void *) tr.data, (const void *) rt, nt*FSIZE); puttr(&tr); } while (gettr(&tr)); return(CWP_Exit()); }
main(int argc, char **argv) { register float *rt; /* real trace */ register complex *ct; /* complex transformed trace */ float *filter; /* filter array */ float f1; /* left lower corner frequency */ float f2; /* left upper corner frequency */ float f4; /* right lower corner frequency */ float f3; /* right upper corner frequency */ int if1,if2,if3,if4; /* integerizations of f1,f2,f3,f4 */ float dt; /* sample spacing */ float nyq; /* nyquist frequency */ int nt; /* number of points on input trace */ int nfft; /* number of points for fft trace */ int nf; /* number of frequencies (incl Nyq) */ int nfm1; /* nf-1 */ float onfft; /* reciprocal of nfft */ float df; /* frequency spacing (from dt) */ /* Initialize */ initargs(argc, argv); askdoc(1); /* Get info from first trace */ if (!gettr(&tr)) err("can't get first trace"); if (tr.trid && tr.trid != TREAL) err("input is not seismic data, trid=%d", tr.trid); nt = tr.ns; if (!getparfloat("dt", &dt)) dt = tr.dt/1000000.0; if (!dt) err("dt field is zero and not getparred"); nyq = 0.5/dt; /* Set up FFT parameters */ nfft = npfaro(nt, LOOKFAC * nt); if (nfft >= MIN(SU_NFLTS, PFA_MAX)) err("Padded nt=%d -- too big", nfft); nf = nfft/2 + 1; nfm1 = nf - 1; onfft = 1.0 / nfft; /* Get corner frequencies */ if (!getparfloat("f1", &f1)) f1 = FRAC1 * nyq; if (!getparfloat("f2", &f2)) f2 = FRAC2 * nyq; if (!getparfloat("f3", &f3)) f3 = FRAC3 * nyq; if (!getparfloat("f4", &f4)) f4 = FRAC4 * nyq; if (f1 < 0.0 || f1 > f2 || f2 >= f3 || f3 > f4) err("Bad filter parameters"); /* Allocate fft arrays */ rt = ealloc1float(nfft); ct = ealloc1complex(nf); filter = ealloc1float(nf); /* Compute integer frequencies */ df = onfft / dt; if1 = NINT(f1/df); if2 = NINT(f2/df); if3 = NINT(f3/df); if (if3 > nfm1) if3 = nfm1; if4 = NINT(f4/df); if (if4 > nfm1) if4 = nfm1; /* Make filter with scale for inverse transform */ { register int i; register float c = PIBY2 / (if2 - if1 + 2); for (i = if1; i <= if2; ++i) { register float s = sin(c*(i - if1 + 1)); filter[i] = s * s * onfft; } } { register int i; register float c = PIBY2 / (if4 - if3 + 2); for (i = if3; i <= if4; ++i) { register float s = sin(c*(if4 - i + 1)); filter[i] = s * s * onfft; } } { register int i; for (i = if2 + 1; i < if3; ++i) filter[i] = onfft; for (i = 0; i < if1; ++i) filter[i] = 0.0; for (i = if4 + 1; i < nf; ++i) filter[i] = 0.0; } /* Main loop over traces */ do { register int i; /* Load trace into rt (zero-padded) */ memcpy(rt, tr.data, nt*FSIZE); bzero(rt + nt, (nfft-nt)*FSIZE); /* FFT, filter, inverse FFT */ pfarc(1, nfft, rt, ct); for (i = 0; i < nf; ++i) ct[i] = crmul(ct[i], filter[i]); pfacr(-1, nfft, ct, rt); /* Load traces back in, recall filter had nfft factor */ for (i = 0; i < nt; ++i) tr.data[i] = rt[i]; puttr(&tr); } while (gettr(&tr)); return EXIT_SUCCESS; }
int main( int argc, char *argv[] ) { int ntr=0; /* number of traces */ int ntrv=0; /* number of traces */ int ns=0; int nsv=0; float dt; float dtv; cwp_String fs; cwp_String fv; FILE *fps; FILE *fpv; FILE *headerfp; float *data; /* data matrix of the migration volume */ float *vel; /* velocity matrix */ float *velfi; /* velocity function interpolated to ns values*/ float *velf; /* velocity function */ float *vdt; float *ddt; float *ap; /* array of apperture values in m */ float apr; /* array of apperture values in m */ int *apt=NULL; /* array of apperture time limits in mig. gath*/ float r; /* maximum radius with a given apperture */ float ir2; /* r/d2 */ float ir3; /* r/d3 */ float d2; /* spatial sampling int. in dir 2. */ float d3; /* spatial sampling int. in dir 3. */ float **mgd=NULL; /* migration gather data */ float *migt; /* migrated data trace */ int **mgdnz=NULL; /* migration gather data non zero samples*/ float dm; /* migration gather spatial sample int. */ int im; /* number of traces in migration gather */ int *mtnz; /* migrated trace data non zero smaples */ char **dummyi; /* index array that the trace contains zeros only */ float fac; /* velocity scale factor */ int sphr; /* spherical divergence flag */ int imt; /* mute time sample of trace */ float tmp; int imoff; int **igtr=NULL; int nigtr; int n2; int n3; int verbose; /* phase shift filter stuff */ float power; /* power of i omega applied to data */ float amp; /* amplitude associated with the power */ float arg; /* argument of power */ float phasefac; /* phase factor */ float phase; /* phase shift = phasefac*PI */ complex exparg; /* cexp(I arg) */ register float *rt; /* real trace */ register complex *ct; /* complex transformed trace */ complex *filt; /* complex power */ float omega; /* circular frequency */ float domega; /* circular frequency spacing (from dt) */ float sign; /* sign in front of i*omega default -1 */ int nfft; /* number of points in nfft */ int nf; /* number of frequencies (incl Nyq) */ float onfft; /* 1 / nfft */ size_t nzeros; /* number of padded zeroes in bytes */ initargs(argc, argv); requestdoc(1); MUSTGETPARSTRING("fs",&fs); MUSTGETPARSTRING("fv",&fv); MUSTGETPARINT("n2",&n2); MUSTGETPARINT("n3",&n3); MUSTGETPARFLOAT("d2",&d2); MUSTGETPARFLOAT("d3",&d3); if (!getparfloat("dm", &dm)) dm=(d2+d3)/2.0; /* open datafile */ fps = efopen(fs,"r"); fpv = efopen(fv,"r"); /* Open tmpfile for headers */ headerfp = etmpfile(); /* get information from the first data trace */ ntr = fgettra(fps,&tr,0); if(n2*n3!=ntr) err(" Number of traces in file %d not equal to n2*n3 %d \n", ntr,n2*n3); ns=tr.ns; if (!getparfloat("dt", &dt)) dt = ((float) tr.dt)/1000000.0; if (!dt) { dt = .002; warn("dt not set, assumed to be .002"); } /* get information from the first velocity trace */ ntrv = fgettra(fpv,&trv,0); if(ntrv!=ntr) err(" Number of traces in velocity file %d differ from %d \n", ntrv,ntr); nsv=trv.ns; if (!getparfloat("dtv", &dtv)) dtv = ((float) trv.dt)/1000000.0; if (!dtv) { dtv = .002; warn("dtv not set, assumed to be .002 for velocity"); } if (!getparfloat("fac", &fac)) fac=2.0; if (!getparint("verbose", &verbose)) verbose=0; if (!getparint("sphr", &sphr)) sphr=0; if (!getparfloat("apr", &apr)) apr=75; apr*=3.141592653/180; /* allocate arrays */ data = bmalloc(sizeof(float),ns,ntr); vel = bmalloc(sizeof(float),nsv,ntr); velf = ealloc1float(nsv); velfi = ealloc1float(ns); migt = ealloc1float(ns); vdt = ealloc1float(nsv); ddt = ealloc1float(ns); ap = ealloc1float(ns); mtnz = ealloc1int(ns); dummyi = (char **) ealloc2(n2,n3,sizeof(char)); /* Times to do interpolation of velocity from sparse sampling */ /* to fine sampling of the data */ { register int it; for(it=0;it<nsv;it++) vdt[it]=it*dtv; for(it=0;it<ns;it++) ddt[it]=it*dt; } /* Read traces into data */ /* Store headers in tmpfile */ ntr=0; erewind(fps); erewind(fpv); { register int i2,i3; for(i3=0;i3<n3;i3++) for(i2=0;i2<n2;i2++) { fgettr(fps,&tr); fgettr(fpv,&trv); if(tr.trid > 2) dummyi[i3][i2]=1; else dummyi[i3][i2]=0; efwrite(&tr, 1, HDRBYTES, headerfp); bmwrite(data,1,0,i3*n2+i2,ns,tr.data); bmwrite(vel,1,0,i3*n2+i2,nsv,trv.data); } erewind(headerfp); /* set up the phase filter */ power = 1.0;sign = 1.0;phasefac = 0.5; phase = phasefac * PI; /* Set up for fft */ nfft = npfaro(ns, LOOKFAC * ns); if (nfft >= SU_NFLTS || nfft >= PFA_MAX) err("Padded nt=%d -- too big", nfft); nf = nfft/2 + 1; onfft = 1.0 / nfft; nzeros = (nfft - ns) * FSIZE; domega = TWOPI * onfft / dt; /* Allocate fft arrays */ rt = ealloc1float(nfft); ct = ealloc1complex(nf); filt = ealloc1complex(nf); /* Set up args for complex power evaluation */ arg = sign * PIBY2 * power + phase; exparg = cexp(crmul(I, arg)); { register int i; for (i = 0 ; i < nf; ++i) { omega = i * domega; /* kludge to handle omega=0 case for power < 0 */ if (power < 0 && i == 0) omega = FLT_MAX; /* calculate filter */ amp = pow(omega, power) * onfft; filt[i] = crmul(exparg, amp); } } /* set up constants for migration */ if(verbose) fprintf(stderr," Setting up constants....\n"); r=0; for(i3=0;i3<n3;i3++) for(i2=0;i2<n2;i2++) { if(dummyi[i3][i2] < 1) { /* get the velocity function */ bmread(vel,1,0,i3*n2+i2,nsv,velf); /* linear interpolation from nsv to ns values */ intlin(nsv,vdt,velf,velf[0],velf[nsv-1],ns,ddt,velfi); /* Apply scale factor to velocity */ { register int it; for(it=0;it<ns;it++) velfi[it] *=fac; } /* compute maximum radius from apperture and velocity */ { register int it; for(it=0;it<ns;it++) ap[it] = ddt[it]*velfi[it]*tan(apr)/2.0; } tmp = ap[isamax(ns,ap,1)]; if(tmp>r) r=tmp; } } r=MIN(r,sqrt(SQR((n2-1)*d2)+SQR((n3-1)*d3))); ir2 = (int)(2*r/d2)+1; ir3 = (int)(2*r/d3)+1; im = (int)(r/dm)+1; /* allocate migration gather */ mgd = ealloc2float(ns,im); mgdnz = ealloc2int(ns,im); apt = ealloc1int(im); /* set up the stencil for selecting traces */ igtr = ealloc2int(ir2*ir3,2); stncl(r, d2, d3,igtr,&nigtr); if(verbose) { fprintf(stderr," Maximum radius %f\n",r); fprintf(stderr," Maximum offset %f\n", sqrt(SQR((n2-1)*d2)+SQR((n3-1)*d3))); } /* main processing loop */ for(i3=0;i3<n3;i3++) for(i2=0;i2<n2;i2++) { memset( (void *) tr.data, (int) '\0',ns*FSIZE); if(dummyi[i3][i2] < 1) { memset( (void *) mgd[0], (int) '\0',ns*im*FSIZE); memset( (void *) mgdnz[0], (int) '\0',ns*im*ISIZE); /* get the velocity function */ bmread(vel,1,0,i3*n2+i2,nsv,velf); /* linear interpolation from nsv to ns values */ intlin(nsv,vdt,velf,velf[0],velf[nsv-1],ns,ddt,velfi); /* Apply scale factor to velocity */ { register int it; for(it=0;it<ns;it++) velfi[it] *=fac; } /* create the migration gather */ { register int itr,ist2,ist3; for(itr=0;itr<nigtr;itr++) { ist2=i2+igtr[0][itr]; ist3=i3+igtr[1][itr]; if(ist2 >= 0 && ist2 <n2) if(ist3 >= 0 && ist3 <n3) { if(dummyi[ist3][ist2] <1) { imoff = (int) ( sqrt(SQR(igtr[0][itr]*d2) +SQR(igtr[1][itr]*d3))/dm+0.5); bmread(data,1,0,ist3*n2+ist2,ns,tr.data); imoff=MIN(imoff,im-1); { register int it; /* get the mute time for this offset, apperture and velocity */ xindex(ns,ap,imoff*dm,&imt); for(it=imt;it<ns;it++) if(tr.data[it]!=0) { mgd[imoff][it]+=tr.data[it]; mgdnz[imoff][it]+=1; } } } } } } /* normalize the gather */ { register int ix,it; for(ix=0;ix<im;ix++) for(it=0;it<ns;it++) if(mgdnz[ix][it] > 1) mgd[ix][it] /=(float) mgdnz[ix][it]; } memset( (void *) tr.data, (int) '\0',ns*FSIZE); memset( (void *) mtnz, (int) '\0',ns*ISIZE); /* do a knmo */ { register int ix,it; for(ix=0;ix<im;ix++) { /* get the mute time for this offset, apperture and velocity */ xindex(ns,ap,ix*dm,&imt); knmo(mgd[ix],migt,ns,velfi,0,ix*dm,dt,imt,sphr); /* stack the gather */ for(it=0;it<ns;it++) { if(migt[it]!=0.0) { tr.data[it] += migt[it]; mtnz[it]++; } /* tr.data[it] += mgd[ix][it]; */ } } } { register int it; for(it=0;it<ns;it++) if(mtnz[it]>1) tr.data[it] /=(float)mtnz[it]; } /*Do the phase filtering before the trace is released*/ /* Load trace into rt (zero-padded) */ memcpy( (void *) rt, (const void *) tr.data, ns*FSIZE); memset((void *) (rt + ns), (int) '\0', nzeros); pfarc(1, nfft, rt, ct); { register int i; for (i = 0; i < nf; ++i) ct[i] = cmul(ct[i], filt[i]); } pfacr(-1, nfft, ct, rt); memcpy( (void *) tr.data, (const void *) rt, ns*FSIZE); } /* end of dummy if */ /* spit out the gather */ efread(&tr, 1, HDRBYTES, headerfp); puttr(&tr); if(verbose) fprintf(stderr," %d %d\n",i2,i3); } /* end of i2 loop */ } /* end of i3 loop */ /* This should be the last thing */ efclose(headerfp); /* Free memory */ free2int(igtr); free2float(mgd); free2int(mgdnz); free1int(apt); bmfree(data); bmfree(vel); free1float(velfi); free1float(velf); free1float(ddt); free1float(vdt); free1float(ap); free1int(mtnz); free1float(migt); free1float(rt); free1complex(ct); free1complex(filt); free2((void **) dummyi); return EXIT_SUCCESS; }
int main(int argc, char **argv) { register float *rt; /* real trace */ register complex *ct; /* complex transformed trace */ int nt; /* number of points on input trace */ int nfft; /* number of points on output trace */ int nfby2p1; /* nfft/2 + 1 */ float dt; /* sample interval in secs */ float d1; /* output sample interval in Hz */ int ntr=0; /* number of traces */ register int i; /* counter */ /* Initialize */ initargs(argc, argv); requestdoc(1); /* Get info from first trace */ if (!gettr(&tr)) err("can't get first trace"); nt = tr.ns; /* dt is used only to set output header value d1 */ if (!getparfloat("dt", &dt)) dt = ((double) tr.dt)/1000000.0; if (!dt) { dt = .004; warn("dt not set, assumed to be .004"); } checkpars(); /* Set up pfa fft */ nfft = npfaro(nt, LOOKFAC * nt); if (nfft >= SU_NFLTS || nfft >= PFA_MAX) err("Padded nt=%d--too big", nfft); nfby2p1 = nfft/2 + 1; d1 = 1.0/(nfft*dt); rt = ealloc1float(nfft); ct = ealloc1complex(nfby2p1); /* Main loop over traces */ do { ++ntr; /* Load trace into rt (zero-padded) */ memcpy( (void *) rt, (const void *) tr.data, nt*FSIZE); memset( (void *) (rt + nt), 0, (nfft - nt)*FSIZE); /* FFT */ pfarc(1, nfft, rt, ct); /* Compute amplitude spectrum */ tr.data[0] = rcabs(ct[0])/2.0; for (i = 1; i < nfby2p1; ++i) tr.data[i] = rcabs(ct[i]); /* Set header values */ tr.ns = nfby2p1; tr.dt = 0; /* d1=df is now the relevant step size */ tr.trid = AMPLITUDE; tr.d1 = d1; tr.f1 = 0.0; puttr(&tr); } while (gettr(&tr)); return(CWP_Exit()); }