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()); }
int main(int argc, char **argv) { FILE *headerfp=NULL; /* temporary file for trace header */ /* ... (1st trace of ensemble); */ char *key=NULL; /* header key word from segy.h */ char *type=NULL; /* ... its type */ int index; /* ... its index */ Value val; /* ... its value */ float fval = 0; /* ... its value cast to float */ float prevfval; /* ... its value of the previous trace */ complex *ct=NULL; /* complex trace */ complex *psct=NULL; /* phase-stack data array */ float *data=NULL; /* input data array */ float *hdata=NULL; /* array of Hilbert transformed input data */ float *stdata=NULL; /* stacked data ("ordinary" stack) */ float *psdata; /* phase-stack data array (real weights for PWS)*/ float a; /* inst. amplitude */ float dt; /* time sample spacing in seconds */ float pwr; /* raise phase stack to power pwr */ float sl; /* smoothing window length in seconds */ int gottrace; /* flag: set to 1, if trace is read from stdin */ int i; /* loop index */ int isl; /* smoothing window length in samples */ int nt; /* number of points on input trace */ int ntr; /* trace counter */ int ps; /* flag: output is PWS (0) or phase stack (1) */ int verbose; /* verbose flag */ cwp_Bool pws_and_cdp=cwp_false; /* are PWS and CDP set? */ /* Initialize */ initargs(argc, argv); requestdoc(1); /* Get info from first trace */ if(!gettr(&intr)) err("can't get first trace"); nt = intr.ns; /* Get parameters */ if (!getparstring("key", &key)) key="cdp"; if (!getparfloat("pwr", &pwr)) pwr = 1.0; if (!getparfloat("dt", &dt)) dt = ((double) intr.dt)/1000000.0; if (!getparfloat("sl", &sl)) sl = 0.0; if (!getparint("ps", &ps)) ps = 0; if (!getparint("verbose", &verbose)) verbose = 0; if (STREQ(key, "cdp") && !(ps)) pws_and_cdp = cwp_true; /* convert seconds to samples (necessary only for smoothing) */ if (!dt) { dt = 0.004; warn("dt not set, assuming dt=0.004"); } /* integerized smoothing window length */ isl = NINT(fabs(sl)/dt); if (isl>nt) err("sl=%g too long for trace", fabs(sl)); /* diagnostic print */ if (verbose && isl) warn("smoothing window = %d samples", isl); /* initialize flag */ gottrace = 1; /* get key type and index */ type = hdtype(key); index = getindex(key); /* Get value of key and convert to float */ prevfval = fval; gethval(&intr, index, &val); fval = vtof(type,val); /* remember previous value of key */ prevfval = fval; /* allocate space for data, hilbert transformed data, */ /* phase-stacked data and complex trace */ data = ealloc1float(nt); hdata = ealloc1float(nt); stdata = ealloc1float(nt); psdata = ealloc1float(nt); psct = ealloc1complex(nt); ct = ealloc1complex(nt); /* zero out accumulators */ memset( (void *) stdata, 0, nt*FSIZE); memset( (void *) psct, 0, nt*(sizeof(complex))); /* open temporary file for trace header */ headerfp = etmpfile(); /* store trace header in temporary file and read data */ efwrite(&intr, HDRBYTES, 1, headerfp); /* loop over input traces */ ntr=0; while (gottrace|(~gottrace) ) { /* middle exit loop */ /* if got a trace */ if (gottrace) { /* get value of key */ gethval(&intr, index, &val); fval = vtof(type,val); /* get data */ memcpy((void *) data, (const void *) intr.data, nt*FSIZE); } /* construct quadrature trace with hilbert transform */ hilbert(nt, data, hdata); /* build the complex trace and get rid of amplitude */ for (i=0; i<nt; i++) { ct[i] = cmplx(data[i],hdata[i]); a = (rcabs(ct[i])) ? 1.0 / rcabs(ct[i]) : 0.0; ct[i] = crmul(ct[i], a); } /* stacking */ if (fval==prevfval && gottrace) { ++ntr; for (i=0; i<nt; ++i) { stdata[i] += data[i]; psct[i] = cadd(psct[i],ct[i]); } } /* if key-value has changed or no more input traces */ if (fval!=prevfval || !gottrace) { /* diagnostic print */ if (verbose) warn("%s=%g, fold=%d\n", key, prevfval, ntr); /* convert complex phase stack to real weights */ for (i=0; i<nt; ++i) { psdata[i] = rcabs(psct[i]) / (float) ntr; psdata[i] = pow(psdata[i], pwr); } /* smooth phase-stack (weights) */ if (isl) do_smooth(psdata,nt,isl); /* apply weights to "ordinary" stack (do PWS) */ if (!ps) { for (i=0; i<nt; ++i) { stdata[i] *= psdata[i] / (float) ntr; } } /* set header and write PS trace or */ /* PWS trace to stdout */ erewind(headerfp); efread(&outtr, 1, HDRBYTES, headerfp); outtr.nhs=ntr; if (ps) { memcpy((void *) outtr.data, (const void *) psdata, nt*FSIZE); } else { memcpy((void *) outtr.data, (const void *) stdata, nt*FSIZE); } /* zero offset field if a pws and cdp stack */ if (pws_and_cdp) outtr.offset = 0; puttr(&outtr); /* if no more input traces, break input trace loop* */ if (!gottrace) break; /* remember previous value of key */ prevfval = fval; /* zero out accumulators */ ntr=0; memset( (void *) stdata, 0, nt*FSIZE); memset( (void *) psct, 0, nt*(sizeof(complex))); /* stacking */ if (gottrace) { ++ntr; for (i=0; i<nt; ++i) { stdata[i] += data[i]; psct[i] = cadd(psct[i],ct[i]); } } /* save trace header for output trace */ erewind(headerfp); efwrite(&intr, HDRBYTES, 1, headerfp); } /* get next trace (if there is one) */ if (!gettr(&intr)) gottrace = 0; } /* end loop over traces */ return(CWP_Exit()); }
int main(int argc, char **argv) { int nt,nx; /* numbers of samples */ float dt; /* sampling intervals */ int it,ix; /* sample indices */ int ntfft; /* dimensions after padding for FFT */ int nF; /* transform (output) dimensions */ int iF; /* transform sample indices */ register complex **ct=NULL; /* complex FFT workspace */ register float **rt=NULL; /* float FFT workspace */ int verbose; /* flag for echoing information */ char *tmpdir=NULL; /* directory path for tmp files */ cwp_Bool istmpdir=cwp_false;/* true for user-given path */ float v,fv,dv; /* phase velocity, first, step */ float amp,oamp; /* temp vars for amplitude spectrum */ int nv,iv; /* number of phase vels, counter */ float x; /* offset */ float omega; /* circular frequency */ float domega; /* circular frequency spacing (from dt) */ float onfft; /* 1 / nfft */ float phi; /* omega/phase_velocity */ complex *cDisp=NULL; /* temp array for complex dispersion */ float arg; /* temp var for phase calculation */ complex cExp; /* temp vars for phase calculation */ float *offs=NULL; /* input data offsets */ float fmax; /* max freq to proc (Hz) */ int out; /* output real or abs v(f) spectrum */ int norm; /* normalization flag */ float xmax; /* maximum abs(offset) of input */ float twopi, f; /* constant and frequency (Hz) */ /* Hook up getpar to handle the parameters */ initargs(argc,argv); requestdoc(1); /* Get info from first trace */ if (!gettr(&intrace)) err("can't get first trace"); nt = intrace.ns; /* dt is used only to set output header value d1 */ if (!getparfloat("dt", &dt)) { if (intrace.dt) { /* is dt field set? */ dt = ((double) intrace.dt)/ 1000000.0; } else { /* dt not set, exit */ err("tr.dt not set, stop."); } } warn("dt=%f",dt); if (!getparfloat("fv",&fv)) fv = 330; if (!getparfloat("dv",&dv)) dv = 25; if (!getparint("nv",&nv)) nv = 100; if (!getparint("out",&out)) out = 0; if (!getparint("norm",&norm)) norm = 0; if (!getparfloat("fmax",&fmax)) fmax = 50; if (!getparint("verbose", &verbose)) verbose = 0; /* Look for user-supplied tmpdir */ if (!getparstring("tmpdir",&tmpdir) && !(tmpdir = getenv("CWP_TMPDIR"))) tmpdir=""; if (!STREQ(tmpdir, "") && access(tmpdir, WRITE_OK)) err("you can't write in %s (or it doesn't exist)", tmpdir); checkpars(); /* Set up tmpfile */ if (STREQ(tmpdir,"")) { tracefp = etmpfile(); if (verbose) warn("using tmpfile() call"); } else { /* user-supplied tmpdir */ char directory[BUFSIZ]; strcpy(directory, tmpdir); strcpy(tracefile, temporary_filename(directory)); /* Trap signals so can remove temp files */ signal(SIGINT, (void (*) (int)) closefiles); signal(SIGQUIT, (void (*) (int)) closefiles); signal(SIGHUP, (void (*) (int)) closefiles); signal(SIGTERM, (void (*) (int)) closefiles); tracefp = efopen(tracefile, "w+"); istmpdir=cwp_true; if (verbose) warn("putting temporary files in %s", directory); } /* we have to allocate offs(nx) before we know nx */ offs = alloc1float(MAX_OFFS); ix = 0; nx = 0; xmax = 0.0; /* get nx and max abs(offset) */ do { ++nx; efwrite(intrace.data, FSIZE, nt, tracefp); offs[ix] = intrace.offset; if ( abs(intrace.offset) > xmax ) xmax = abs(intrace.offset); ++ix; } while (gettr(&intrace)); /* confirm that offsets are set */ if ( xmax == 0.0 ) err("tr.offset not set, stop."); /* Determine lengths for prime-factor FFTs */ ntfft = npfar(nt); if (ntfft >= SU_NFLTS || ntfft >= PFA_MAX) err("Padded nt=%d--too big",ntfft); /* Determine complex transform sizes */ nF = ntfft/2+1; /* must be this nF for fft */ onfft = 1.0 / ntfft; twopi = 2.0 * PI; domega = twopi * onfft / dt; /* Allocate space */ ct = alloc2complex(nF,nx); rt = alloc2float(ntfft,nx); /* Load traces into fft arrays and close tmpfile */ erewind(tracefp); for (ix=0; ix<nx; ++ix) { efread(rt[ix], FSIZE, nt, tracefp); /* pad dimension 1 with zeros */ for (it=nt; it<ntfft; ++it) rt[ix][it] = 0.0; } efclose(tracefp); /* Fourier transform dimension 1 */ pfa2rc(1,1,ntfft,nx,rt[0],ct[0]); /* set nF for processing */ if (fmax == 0) { /* process to nyquist */ nF = ntfft/2+1; } else { /* process to given fmax */ nF = (int) (twopi * fmax / domega); } /* data now in (w,x) domain allocate arrays */ cDisp = alloc1complex(nF); /* if requested, normalize by amplitude spectrum (normalizing by amplitude blows up aliasing and other artifacts) */ if (norm == 1) { for (iF=0; iF<nF; ++iF) { /* calc this frequency */ omega = iF * domega; f = omega / twopi; /* loop over traces */ for (ix=0; ix<nx; ++ix) { /* calc amplitude at this (f,x) location */ amp = rcabs(ct[ix][iF]); oamp = 1.0/amp; /* scale field by amp spectrum */ ct[ix][iF] = crmul(ct[ix][iF],oamp); } } } /* set global output trace headers */ outtrace.ns = 2 * nF; outtrace.dt = dt*1000000.; outtrace.trid = FUNPACKNYQ; outtrace.d1 = 1.0 / (ntfft * dt); /* Hz */ outtrace.f1 = 0; outtrace.d2 = dv; outtrace.f2 = fv; /* loop over phase velocities */ for (iv=0; iv<nv; ++iv) { /* this velocity */ v = fv + iv*dv; /* loop over frequencies */ for (iF=0; iF<nF; ++iF) { /* this frequency and phase */ omega = iF * domega; f = omega / twopi; phi = omega / v; /* initialize */ cDisp[iF] = cmplx(0.0,0.0); /* sum over abs offset (this is ok for 3D, too) */ for (ix=0; ix<nx; ++ix) { /* get this x */ x = abs(offs[ix]); /* target phase */ arg = - phi * x; cExp = cwp_cexp(crmul(cmplx(0.0,1.0), arg)); /* phase vel profile for this frequency */ cDisp[iF] = cadd(cDisp[iF],cmul(ct[ix][iF],cExp)); } } /* set trace counter */ outtrace.tracl = iv + 1; /* copy results to output trace interleaved format like sufft.c */ for (iF = 0; iF < nF; ++iF) { outtrace.data[2*iF] = cDisp[iF].r; outtrace.data[2*iF+1] = cDisp[iF].i; } /* output freqs at this vel */ puttr(&outtrace); } /* next frequency */ /* Clean up */ if (istmpdir) eremove(tracefile); 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; /* 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()); }