int main (int argc, char **argv) { FILE *fp_in1, *fp_in2, *fp_out, *fp_chk, *fp_psline1, *fp_psline2; int verbose, shift, k, nx1, nt1, nx2, nt2; int ntmax, nxmax, ret, i, j, jmax, imax, above, check; int size, ntraces, ngath, *maxval, hw, smooth; int tstart, tend, scale, *xrcv; float dt, d2, f1, f2, t0, t1, f1b, f2b, d1, d1b, d2b; float w1, w2, dxrcv; float *tmpdata, *tmpdata2, *costaper; char *file_mute, *file_shot, *file_out; float scl, sclsxgx, sclshot, xmin, xmax, tmax, lmax; segy *hdrs_in1, *hdrs_in2; t0 = wallclock_time(); initargs(argc, argv); requestdoc(1); if(!getparstring("file_mute", &file_mute)) file_mute=NULL; if(!getparstring("file_shot", &file_shot)) file_shot=NULL; if(!getparstring("file_out", &file_out)) file_out=NULL; if(!getparint("ntmax", &ntmax)) ntmax = 1024; if(!getparint("nxmax", &nxmax)) nxmax = 512; if(!getparint("above", &above)) above = 0; if(!getparint("check", &check)) check = 0; if(!getparint("scale", &scale)) scale = 0; if(!getparint("hw", &hw)) hw = 15; if(!getparint("smooth", &smooth)) smooth = 0; if(!getparfloat("w1", &w1)) w1=1.0; if(!getparfloat("w2", &w2)) w2=1.0; if(!getparint("shift", &shift)) shift=0; if(!getparint("verbose", &verbose)) verbose=0; /* Reading input data for file_mute */ if (file_mute != NULL) { ngath = 1; getFileInfo(file_mute, &nt1, &nx1, &ngath, &d1, &d2, &f1, &f2, &xmin, &xmax, &sclsxgx, &ntraces); if (!getparint("ntmax", &ntmax)) ntmax = nt1; if (!getparint("nxmax", &nxmax)) nxmax = nx1; if (verbose>=2 && (ntmax!=nt1 || nxmax!=nx1)) vmess("dimensions overruled: %d x %d",ntmax,nxmax); if(!getparfloat("dt", &dt)) dt=d1; fp_in1 = fopen(file_mute, "r"); if (fp_in1 == NULL) verr("error on opening input file_mute=%s", file_mute); size = ntmax * nxmax; tmpdata = (float *)malloc(size*sizeof(float)); hdrs_in1 = (segy *) calloc(nxmax,sizeof(segy)); nx1 = readData(fp_in1, tmpdata, hdrs_in1, nt1); if (nx1 == 0) { fclose(fp_in1); if (verbose) vmess("end of file_mute data reached"); } if (verbose) { disp_fileinfo(file_mute, nt1, nx1, f1, f2, dt, d2, hdrs_in1); } } /* Reading input data for file_shot */ ngath = 1; getFileInfo(file_shot, &nt2, &nx2, &ngath, &d1b, &d2b, &f1b, &f2b, &xmin, &xmax, &sclshot, &ntraces); if (!getparint("ntmax", &ntmax)) ntmax = nt2; if (!getparint("nxmax", &nxmax)) nxmax = nx2; size = ntmax * nxmax; tmpdata2 = (float *)malloc(size*sizeof(float)); hdrs_in2 = (segy *) calloc(nxmax,sizeof(segy)); if (file_shot != NULL) fp_in2 = fopen(file_shot, "r"); else fp_in2=stdin; if (fp_in2 == NULL) verr("error on opening input file_shot=%s", file_shot); nx2 = readData(fp_in2, tmpdata2, hdrs_in2, nt2); if (nx2 == 0) { fclose(fp_in2); if (verbose) vmess("end of file_shot data reached"); } nt2 = hdrs_in2[0].ns; f1b = hdrs_in2[0].f1; f2b = hdrs_in2[0].f2; d1b = (float)hdrs_in2[0].dt*1e-6; if (verbose) { disp_fileinfo(file_shot, nt2, nx2, f1b, f2b, d1b, d2b, hdrs_in2); } /* file_shot will be used as well to define the mute window */ if (file_mute == NULL) { nx1=nx2; nt1=nt2; dt=d1b; f1=f1b; f2=f2b; tmpdata = tmpdata2; hdrs_in1 = hdrs_in2; } if (verbose) vmess("sampling file_mute=%d, file_shot=%d", nt1, nt2); /*================ initializations ================*/ maxval = (int *)calloc(nx1,sizeof(int)); xrcv = (int *)calloc(nx1,sizeof(int)); if (file_out==NULL) fp_out = stdout; else { fp_out = fopen(file_out, "w+"); if (fp_out==NULL) verr("error on ceating output file"); } if (check!=0){ fp_chk = fopen("check.su", "w+"); if (fp_chk==NULL) verr("error on ceating output file"); fp_psline1 = fopen("pslinepos.asci", "w+"); if (fp_psline1==NULL) verr("error on ceating output file"); fp_psline2 = fopen("pslineneg.asci", "w+"); if (fp_psline2==NULL) verr("error on ceating output file"); } if (smooth) { costaper = (float *)malloc(smooth*sizeof(float)); scl = M_PI/((float)smooth); for (i=0; i<smooth; i++) { costaper[i] = 0.5*(1.0+cos((i+1)*scl)); /* fprintf(stderr,"costaper[%d]=%f\n",i,costaper[i]);*/ } } /*================ loop over all shot records ================*/ k=1; while (nx1 > 0) { if (verbose) vmess("processing input gather %d", k); /*================ loop over all shot records ================*/ /* find consistent (one event) maximum related to maximum value */ /* find global maximum xmax=0.0; for (i = 0; i < nx1; i++) { tmax=0.0; jmax = 0; for (j = 0; j < nt1; j++) { lmax = fabs(tmpdata[i*nt1+j]); if (lmax > tmax) { jmax = j; tmax = lmax; if (lmax > xmax) { imax = i; xmax=lmax; } } } maxval[i] = jmax; } */ /* alternative find maximum at source position */ dxrcv = (hdrs_in1[nx1-1].gx - hdrs_in1[0].gx)*sclsxgx/(float)(nx1-1); imax = NINT(((hdrs_in1[0].sx-hdrs_in1[0].gx)*sclsxgx)/dxrcv); tmax=0.0; jmax = 0; for (j = 0; j < nt1; j++) { lmax = fabs(tmpdata[imax*nt1+j]); if (lmax > tmax) { jmax = j; tmax = lmax; if (lmax > xmax) { xmax=lmax; } } } maxval[imax] = jmax; if (verbose >= 3) vmess("Mute max at src-trace %d is sample %d", imax, maxval[imax]); /* search forward */ for (i = imax+1; i < nx1; i++) { tstart = MAX(0, (maxval[i-1]-hw)); tend = MIN(nt1-1, (maxval[i-1]+hw)); jmax=tstart; tmax=0.0; for(j = tstart; j <= tend; j++) { lmax = fabs(tmpdata[i*nt1+j]); if (lmax > tmax) { jmax = j; tmax = lmax; } } maxval[i] = jmax; } /* search backward */ for (i = imax-1; i >=0; i--) { tstart = MAX(0, (maxval[i+1]-hw)); tend = MIN(nt1-1, (maxval[i+1]+hw)); jmax=tstart; tmax=0.0; for(j = tstart; j <= tend; j++) { lmax = fabs(tmpdata[i*nt1+j]); if (lmax > tmax) { jmax = j; tmax = lmax; } } maxval[i] = jmax; } /* scale with maximum ampltiude */ if (scale==1) { for (i = 0; i < nx2; i++) { lmax = fabs(tmpdata2[i*nt2+maxval[i]]); xrcv[i] = i; for (j = 0; j < nt2; j++) { tmpdata2[i*nt2+j] = tmpdata2[i*nt2+j]/lmax; } } } /*================ apply mute window ================*/ applyMute(tmpdata2, maxval, smooth, above, 1, nx2, nt2, xrcv, nx2, shift); /*================ write result to output file ================*/ ret = writeData(fp_out, tmpdata2, hdrs_in2, nt2, nx2); if (ret < 0 ) verr("error on writing output file."); /* put mute window in file to check correctness of mute */ if (check !=0) { for (i = 0; i < nx1; i++) { jmax = maxval[i]-shift; tmpdata[i*nt1+jmax] = 2*xmax; } if (above==0){ for (i = 0; i < nx1; i++) { jmax = nt2-maxval[i]+shift; tmpdata[i*nt1+jmax] = 2*xmax; } } ret = writeData(fp_chk, tmpdata, hdrs_in1, nt1, nx1); if (ret < 0 ) verr("error on writing check file."); for (i=0; i<nx1; i++) { jmax = maxval[i]-shift; ret = fprintf(fp_psline1, "%.5f %.5f \n",jmax*dt,hdrs_in1[i].gx*sclshot); jmax =-maxval[i]+shift; ret = fprintf(fp_psline2, "%.5f %.5f \n",jmax*dt,hdrs_in1[i].gx*sclshot); } } /*================ Read next record for muting ================*/ if (file_mute != NULL) { nx1 = readData(fp_in1, tmpdata, hdrs_in1, nt1); if (nx1 == 0) { fclose(fp_in1); if (verbose) vmess("end of file_mute data reached"); fclose(fp_in2); if (fp_out!=stdout) fclose(fp_out); if (check!=0) fclose(fp_chk); if (check!=0) { fclose(fp_psline1); fclose(fp_psline2); } break; } nt1 = (int)hdrs_in1[0].ns; if (nt1 > ntmax) verr("n_samples (%d) greater than ntmax", nt1); if (nx1 > nxmax) verr("n_traces (%d) greater than nxmax", nx1); } /*================ Read next shot record(s) ================*/ nx2 = readData(fp_in2, tmpdata2, hdrs_in2, nt2); if (nx2 == 0) { if (verbose) vmess("end of file_shot data reached"); fclose(fp_in2); break; } nt2 = (int)hdrs_in2[0].ns; if (nt2 > ntmax) verr("n_samples (%d) greater than ntmax", nt2); if (nx2 > nxmax) verr("n_traces (%d) greater than nxmax", nx2); if (file_mute == NULL) { nx1=nx2; nt1=nt2; hdrs_in1 = hdrs_in2; tmpdata = tmpdata2; } k++; } t1 = wallclock_time(); if (verbose) vmess("Total CPU-time = %f",t1-t0); return 0; }
int main (int argc, char **argv) { FILE *fp_out, *fp_f1plus, *fp_f1min; FILE *fp_gmin, *fp_gplus, *fp_f2, *fp_pmin; int i, j, l, ret, nshots, Nsyn, nt, nx, nts, nxs, ngath; int size, n1, n2, ntap, tap, di, ntraces, nb, ib; int nw, nw_low, nw_high, nfreq, *xnx, *xnxsyn, *synpos; int reci, mode, ixa, ixb, n2out, verbose, ntfft; int iter, niter, niterh, tracf, *muteW, pad, nt0, ampest, *hmuteW, *hxnxsyn; int hw, smooth, above, shift, *ixpossyn, npossyn, ix, first=1; float fmin, fmax, *tapersh, *tapersy, fxf, dxf, fxs2, *xsrc, *xrcv, *zsyn, *zsrc, *xrcvsyn; float *hzsyn, *hxsyn, *hxrcvsyn, *hG_d, xloc, zloc, *HomG; double t0, t1, t2, t3, tsyn, tread, tfft, tcopy, energyNi, *J; float d1, d2, f1, f2, fxs, ft, fx, *xsyn, dxsrc, Q, f0, *Costdet; float *green, *f2p, *pmin, *G_d, dt, dx, dxs, scl, mem, *Image, *Image2; float *f1plus, *f1min, *iRN, *Ni, *trace, *Gmin, *Gplus, *Gm0; float xmin, xmax, weight, tsq, *Gd, *amp, bstart, bend, db, *bdet, bp, b, bmin; complex *Refl, *Fop, *cshot; char *file_tinv, *file_shot, *file_green, *file_iter, *file_wav, *file_ray, *file_amp, *file_img, *file_cp, *file_rays, *file_amps; char *file_f1plus, *file_f1min, *file_gmin, *file_gplus, *file_f2, *file_pmin, *wavtype, *wavtype2, *file_homg, *file_tinvs; segy *hdrs_im, *hdrs_homg; WavePar WP,WPs; modPar mod; recPar rec; srcPar src; shotPar shot; rayPar ray; initargs(argc, argv); requestdoc(1); tsyn = tread = tfft = tcopy = 0.0; t0 = wallclock_time(); if (!getparstring("file_img", &file_img)) file_img = "img.su"; if (!getparstring("file_homg", &file_homg)) file_homg = NULL; if (!getparstring("file_shot", &file_shot)) file_shot = NULL; if (!getparstring("file_tinv", &file_tinv)) file_tinv = NULL; if (!getparstring("file_tinvs", &file_tinvs)) file_tinvs = NULL; if (!getparstring("file_f1plus", &file_f1plus)) file_f1plus = NULL; if (!getparstring("file_f1min", &file_f1min)) file_f1min = NULL; if (!getparstring("file_gplus", &file_gplus)) file_gplus = NULL; if (!getparstring("file_gmin", &file_gmin)) file_gmin = NULL; if (!getparstring("file_pplus", &file_f2)) file_f2 = NULL; if (!getparstring("file_f2", &file_f2)) file_f2 = NULL; if (!getparstring("file_pmin", &file_pmin)) file_pmin = NULL; if (!getparstring("file_iter", &file_iter)) file_iter = NULL; if (!getparstring("file_wav", &file_wav)) file_wav=NULL; if (!getparstring("file_ray", &file_ray)) file_ray=NULL; if (!getparstring("file_amp", &file_amp)) file_amp=NULL; if (!getparstring("file_rays", &file_rays)) file_rays=NULL; if (!getparstring("file_amps", &file_amps)) file_amps=NULL; if (!getparstring("file_cp", &file_cp)) file_cp = NULL; if (!getparint("verbose", &verbose)) verbose = 0; if (file_tinv == NULL && file_shot == NULL) verr("file_tinv and file_shot cannot be both input pipe"); if (!getparstring("file_green", &file_green)) { if (verbose) vwarn("parameter file_green not found, assume pipe"); file_green = NULL; } if (!getparfloat("fmin", &fmin)) fmin = 0.0; if (!getparfloat("fmax", &fmax)) fmax = 70.0; if (!getparint("ixa", &ixa)) ixa = 0; if (!getparint("ixb", &ixb)) ixb = ixa; // if (!getparint("reci", &reci)) reci = 0; reci=0; // source-receiver reciprocity is not yet fully build into the code if (!getparfloat("weight", &weight)) weight = 1.0; if (!getparfloat("tsq", &tsq)) tsq = 0.0; if (!getparfloat("Q", &Q)) Q = 0.0; if (!getparfloat("f0", &f0)) f0 = 0.0; if (!getparint("tap", &tap)) tap = 0; if (!getparint("ntap", &ntap)) ntap = 0; if (!getparint("pad", &pad)) pad = 0; if(!getparint("hw", &hw)) hw = 15; if(!getparint("smooth", &smooth)) smooth = 5; if(!getparint("above", &above)) above = 0; if(!getparint("shift", &shift)) shift=12; if(!getparint("ampest", &est)) ampest=0; if(!getparint("nb", &nb)) nb=0; if (!getparfloat("bstart", &bstart)) bstart = 1.0; if (!getparfloat("bend", &bend)) bend = 1.0; if (reci && ntap) vwarn("tapering influences the reciprocal result"); /* Reading in wavelet parameters */ if(!getparfloat("fpw", &WP.fp)) WP.fp = -1.0; if(!getparfloat("fminw", &WP.fmin)) WP.fmin = 10.0; if(!getparfloat("flefw", &WP.flef)) WP.flef = 20.0; if(!getparfloat("frigw", &WP.frig)) WP.frig = 50.0; if(!getparfloat("fmaxw", &WP.fmax)) WP.fmax = 60.0; else WP.fp = -1; if(!getparfloat("dbw", &WP.db)) WP.db = -20.0; if(!getparfloat("t0w", &WP.t0)) WP.t0 = 0.0; if(!getparint("shiftw", &WP.shift)) WP.shift = 0; if(!getparint("invw", &WP.inv)) WP.inv = 0; if(!getparfloat("epsw", &WP.eps)) WP.eps = 1.0; if(!getparfloat("scalew", &WP.scale)) WP.scale = 1.0; if(!getparint("scfftw", &WP.scfft)) WP.scfft = 1; if(!getparint("cmw", &WP.cm)) WP.cm = 10; if(!getparint("cnw", &WP.cn)) WP.cn = 1; if(!getparint("wav", &WP.wav)) WP.wav = 0; if(!getparstring("file_wav", &WP.file_wav)) WP.file_wav=NULL; if(!getparstring("w", &wavtype)) strcpy(WP.w, "g2"); else strcpy(WP.w, wavtype); if(!getparfloat("fpws", &WPs.fp)) WPs.fp = -1.0; if(!getparfloat("fminws", &WPs.fmin)) WPs.fmin = 10.0; if(!getparfloat("flefws", &WPs.flef)) WPs.flef = 20.0; if(!getparfloat("frigws", &WPs.frig)) WPs.frig = 50.0; if(!getparfloat("fmaxws", &WPs.fmax)) WPs.fmax = 60.0; else WPs.fp = -1; if(!getparfloat("dbw", &WPs.db)) WPs.db = -20.0; if(!getparfloat("t0ws", &WPs.t0)) WPs.t0 = 0.0; if(!getparint("shiftws", &WPs.shift)) WPs.shift = 0; if(!getparint("invws", &WPs.inv)) WPs.inv = 0; if(!getparfloat("epsws", &WPs.eps)) WPs.eps = 1.0; if(!getparfloat("scalews", &WPs.scale)) WPs.scale = 1.0; if(!getparint("scfftws", &WPs.scfft)) WPs.scfft = 1; if(!getparint("cmws", &WPs.cm)) WPs.cm = 10; if(!getparint("cnws", &WPs.cn)) WPs.cn = 1; if(!getparint("wavs", &WPs.wav)) WPs.wav = 0; if(!getparstring("file_wavs", &WPs.file_wav)) WPs.file_wav=NULL; if(!getparstring("ws", &wavtype2)) strcpy(WPs.w, "g2"); else strcpy(WPs.w, wavtype2); if(!getparint("niter", &niter)) niter = 10; if(!getparint("niterh", &niterh)) niterh = niter; /*================ Reading info about shot and initial operator sizes ================*/ ngath = 0; /* setting ngath=0 scans all traces; n2 contains maximum traces/gather */ if (file_ray!=NULL && file_tinv==NULL) { ret = getFileInfo(file_ray, &n2, &n1, &ngath, &d1, &d2, &f2, &f1, &xmin, &xmax, &scl, &ntraces); n1 = 1; ntraces = n2*ngath; scl = 0.0010; d1 = -1.0*xmin; xmin = -1.0*xmax; xmax = d1; WP.wav = 1; WP.xloc = -123456.0; WP.zloc = -123456.0; synpos = (int *)calloc(ngath,sizeof(int)); shot.nz = 1; shot.nx = ngath; shot.n = shot.nx*shot.nz; for (l=0; l<shot.nz; l++) { for (j=0; j<shot.nx; j++) { synpos[l*shot.nx+j] = j*shot.nz+l; } } } else if (file_ray==NULL && file_tinv==NULL) { getParameters(&mod, &rec, &src, &shot, &ray, verbose); n1 = 1; n2 = rec.n; ngath = shot.n; d1 = mod.dt; d2 = (rec.x[1]-rec.x[0])*mod.dx; f1 = 0.0; f2 = mod.x0+rec.x[0]*mod.dx; xmin = mod.x0+rec.x[0]*mod.dx; xmax = mod.x0+rec.x[rec.n-1]*mod.dx; scl = 0.0010; ntraces = n2*ngath; WP.wav = 1; WP.xloc = -123456.0; WP.zloc = -123456.0; synpos = (int *)calloc(ngath,sizeof(int)); for (l=0; l<shot.nz; l++) { for (j=0; j<shot.nx; j++) { synpos[l*shot.nx+j] = j*shot.nz+l; } } } else { ret = getFileInfo(file_tinv, &n1, &n2, &ngath, &d1, &d2, &f1, &f2, &xmin, &xmax, &scl, &ntraces); } Nsyn = ngath; nxs = n2; nts = n1; nt0 = n1; dxs = d2; fxs = f2; ngath = 0; /* setting ngath=0 scans all traces; nx contains maximum traces/gather */ ret = getFileInfo(file_shot, &nt, &nx, &ngath, &d1, &dx, &ft, &fx, &xmin, &xmax, &scl, &ntraces); nshots = ngath; assert (nxs >= nshots); if (!getparfloat("dt", &dt)) dt = d1; ntfft = optncr(MAX(nt+pad, nts+pad)); nfreq = ntfft/2+1; nw_low = (int)MIN((fmin*ntfft*dt), nfreq-1); nw_low = MAX(nw_low, 1); nw_high = MIN((int)(fmax*ntfft*dt), nfreq-1); nw = nw_high - nw_low + 1; scl = 1.0/((float)ntfft); if (nb > 1) { db = (bend-bstart)/((float)(nb-1)); } else if (nb == 1) { db = 0; bend = bstart; } /*================ Allocating all data arrays ================*/ green = (float *)calloc(Nsyn*nxs*ntfft,sizeof(float)); f2p = (float *)calloc(Nsyn*nxs*ntfft,sizeof(float)); pmin = (float *)calloc(Nsyn*nxs*ntfft,sizeof(float)); f1plus = (float *)calloc(Nsyn*nxs*ntfft,sizeof(float)); f1min = (float *)calloc(Nsyn*nxs*ntfft,sizeof(float)); G_d = (float *)calloc(Nsyn*nxs*ntfft,sizeof(float)); muteW = (int *)calloc(Nsyn*nxs,sizeof(int)); trace = (float *)malloc(ntfft*sizeof(float)); ixpossyn = (int *)malloc(nxs*sizeof(int)); xrcvsyn = (float *)calloc(Nsyn*nxs,sizeof(float)); xsyn = (float *)malloc(Nsyn*sizeof(float)); zsyn = (float *)malloc(Nsyn*sizeof(float)); xnxsyn = (int *)calloc(Nsyn,sizeof(int)); tapersy = (float *)malloc(nxs*sizeof(float)); Refl = (complex *)malloc(nw*nx*nshots*sizeof(complex)); tapersh = (float *)malloc(nx*sizeof(float)); xsrc = (float *)calloc(nshots,sizeof(float)); zsrc = (float *)calloc(nshots,sizeof(float)); xrcv = (float *)calloc(nshots*nx,sizeof(float)); xnx = (int *)calloc(nshots,sizeof(int)); /*================ Read and define mute window based on focusing operator(s) ================*/ /* G_d = p_0^+ = G_d (-t) ~ Tinv */ WPs.nt = ntfft; WPs.dt = dt; WP.nt = ntfft; WP.dt = dt; if (file_ray!=NULL || file_cp!=NULL) { makeWindow(WP, file_ray, file_amp, dt, xrcvsyn, xsyn, zsyn, xnxsyn, Nsyn, nxs, ntfft, mode, muteW, G_d, hw, verbose); } else { mode=-1; /* apply complex conjugate to read in data */ readTinvData(file_tinv, dt, xrcvsyn, xsyn, zsyn, xnxsyn, Nsyn, nxs, ntfft, mode, muteW, G_d, hw, verbose); } /* reading data added zero's to the number of time samples to be the same as ntfft */ nts = ntfft; /* define tapers to taper edges of acquisition */ if (tap == 1 || tap == 3) { for (j = 0; j < ntap; j++) tapersy[j] = (cos(PI*(j-ntap)/ntap)+1)/2.0; for (j = ntap; j < nxs-ntap; j++) tapersy[j] = 1.0; for (j = nxs-ntap; j < nxs; j++) tapersy[j] =(cos(PI*(j-(nxs-ntap))/ntap)+1)/2.0; } else { for (j = 0; j < nxs; j++) tapersy[j] = 1.0; } if (tap == 1 || tap == 3) { if (verbose) vmess("Taper for operator applied ntap=%d", ntap); for (l = 0; l < Nsyn; l++) { for (i = 0; i < nxs; i++) { for (j = 0; j < nts; j++) { G_d[l*nxs*nts+i*nts+j] *= tapersy[i]; } } } } /* check consistency of header values */ dxf = (xrcvsyn[nxs-1] - xrcvsyn[0])/(float)(nxs-1); if (NINT(dxs*1e3) != NINT(fabs(dxf)*1e3)) { vmess("dx in hdr.d1 (%.3f) and hdr.gx (%.3f) not equal",d2, dxf); if (dxf != 0) dxs = fabs(dxf); vmess("dx in operator => %f", dxs); } if (xrcvsyn[0] != 0 || xrcvsyn[1] != 0 ) fxs = xrcvsyn[0]; fxs2 = fxs + (float)(nxs-1)*dxs; /*================ Reading shot records ================*/ mode=1; readShotData(file_shot, xrcv, xsrc, zsrc, xnx, Refl, nw, nw_low, ngath, nx, nx, ntfft, mode, weight, tsq, Q, f0, verbose); tapersh = (float *)malloc(nx*sizeof(float)); if (tap == 2 || tap == 3) { for (j = 0; j < ntap; j++) tapersh[j] = (cos(PI*(j-ntap)/ntap)+1)/2.0; for (j = ntap; j < nx-ntap; j++) tapersh[j] = 1.0; for (j = nx-ntap; j < nx; j++) tapersh[j] =(cos(PI*(j-(nx-ntap))/ntap)+1)/2.0; } else { for (j = 0; j < nx; j++) tapersh[j] = 1.0; } if (tap == 2 || tap == 3) { if (verbose) vmess("Taper for shots applied ntap=%d", ntap); for (l = 0; l < nshots; l++) { for (j = 1; j < nw; j++) { for (i = 0; i < nx; i++) { Refl[l*nx*nw+j*nx+i].r *= tapersh[i]; Refl[l*nx*nw+j*nx+i].i *= tapersh[i]; } } } } free(tapersh); /* check consistency of header values */ fxf = xsrc[0]; if (nx > 1) dxf = (xrcv[0] - xrcv[nx-1])/(float)(nx-1); else dxf = d2; if (NINT(dx*1e3) != NINT(fabs(dxf)*1e3)) { vmess("dx in hdr.d1 (%.3f) and hdr.gx (%.3f) not equal",dx, dxf); if (dxf != 0) dx = fabs(dxf); else verr("gx hdrs not set"); vmess("dx used => %f", dx); } dxsrc = (float)xsrc[1] - xsrc[0]; if (dxsrc == 0) { vwarn("sx hdrs are not filled in!!"); dxsrc = dx; } /*================ Check the size of the files ================*/ if (NINT(dxsrc/dx)*dx != NINT(dxsrc)) { vwarn("source (%.2f) and receiver step (%.2f) don't match",dxsrc,dx); if (reci == 2) vwarn("step used from operator (%.2f) ",dxs); } di = NINT(dxf/dxs); if ((NINT(di*dxs) != NINT(dxf)) && verbose) vwarn("dx in receiver (%.2f) and operator (%.2f) don't match",dx,dxs); if (nt != nts) vmess("Time samples in shot (%d) and focusing operator (%d) are not equal",nt, nts); if (verbose) { vmess("Number of focusing operators = %d", Nsyn); vmess("Number of receivers in focusop = %d", nxs); vmess("number of shots = %d", nshots); vmess("number of receiver/shot = %d", nx); vmess("first model position = %.2f", fxs); vmess("last model position = %.2f", fxs2); vmess("first source position fxf = %.2f", fxf); vmess("source distance dxsrc = %.2f", dxsrc); vmess("last source position = %.2f", fxf+(nshots-1)*dxsrc); vmess("receiver distance dxf = %.2f", dxf); vmess("direction of increasing traces = %d", di); vmess("number of time samples (nt,nts) = %d (%d,%d)", ntfft, nt, nts); vmess("time sampling = %e ", dt); if (ampest > 0) vmess("Amplitude correction estimation is switched on"); if (nb > 0) vmess("Scaling estimation in %d step(s) from %.3f to %.3f (db=%.3f)",nb,bstart,bend,db); if (file_green != NULL) vmess("Green output file = %s ", file_green); if (file_gmin != NULL) vmess("Gmin output file = %s ", file_gmin); if (file_gplus != NULL) vmess("Gplus output file = %s ", file_gplus); if (file_pmin != NULL) vmess("Pmin output file = %s ", file_pmin); if (file_f2 != NULL) vmess("f2 (=pplus) output file = %s ", file_f2); if (file_f1min != NULL) vmess("f1min output file = %s ", file_f1min); if (file_f1plus != NULL)vmess("f1plus output file = %s ", file_f1plus); if (file_iter != NULL) vmess("Iterations output file = %s ", file_iter); } /*================ initializations ================*/ if (ixa || ixb) n2out = ixa + ixb + 1; else if (reci) n2out = nxs; else n2out = nshots; mem = Nsyn*n2out*ntfft*sizeof(float)/1048576.0; if (verbose) { vmess("number of output traces = %d", n2out); vmess("number of output samples = %d", ntfft); vmess("Size of output data/file = %.1f MB", mem); } //memcpy(Ni, G_d, Nsyn*nxs*ntfft*sizeof(float)); if (file_homg!=NULL) { hG_d = (float *)calloc(nxs*ntfft,sizeof(float)); hmuteW = (int *)calloc(nxs,sizeof(int)); hxrcvsyn = (float *)calloc(nxs,sizeof(float)); hxsyn = (float *)calloc(1,sizeof(float)); hzsyn = (float *)calloc(1,sizeof(float)); hxnxsyn = (int *)calloc(1,sizeof(int)); cshot = (complex *)calloc(nxs*nfreq,sizeof(complex)); if(!getparfloat("xloc", &WPs.xloc)) WPs.xloc = -123456.0; if(!getparfloat("zloc", &WPs.zloc)) WPs.zloc = -123456.0; if (WPs.xloc == -123456.0 && WPs.zloc == -123456.0) file_cp = NULL; if (WPs.xloc == -123456.0) WPs.xloc = 0.0; if (WPs.zloc == -123456.0) WPs.zloc = 0.0; xloc = WPs.xloc; zloc = WPs.zloc; ngath = 1; if (file_rays!=NULL || file_cp!=NULL) { WPs.wav=1; makeWindow(WPs, file_rays, file_amps, dt, hxrcvsyn, hxsyn, hzsyn, hxnxsyn, ngath, nxs, ntfft, mode, hmuteW, hG_d, hw, verbose); } else { mode=-1; /* apply complex conjugate to read in data */ readTinvData(file_tinvs, dt, hxrcvsyn, hxsyn, hzsyn, hxnxsyn, ngath, nxs, ntfft, mode, hmuteW, hG_d, hw, verbose); } WPs.xloc = -123456.0; WPs.zloc = -123456.0; if (tap == 1 || tap == 3) { if (verbose) vmess("Taper for operator applied ntap=%d", ntap); for (i = 0; i < nxs; i++) { for (j = 0; j < nts; j++) { hG_d[i*nts+j] *= tapersy[i]; } } } ngath = omp_get_max_threads(); synthesisPosistions(nx, nt, nxs, nts, dt, hxsyn, 1, xrcv, xsrc, fxs2, fxs, dxs, dxsrc, dx, ixa, ixb, reci, nshots, ixpossyn, &npossyn, verbose); iterations(Refl,nx,nt,nxs,nts,dt,hxsyn,1,xrcv,xsrc,fxs2,fxs,dxs,dxsrc,dx,ixa,ixb, ntfft,nw,nw_low,nw_high,mode,reci,nshots,ixpossyn,npossyn,pmin,f1min,f1plus, f2p,hG_d,hmuteW,smooth,shift,above,pad,nt0,&first,niterh,verbose); /* compute full Green's function G = int R * f2(t) + f2(-t) = Pplus + Pmin */ for (i = 0; i < npossyn; i++) { j = 0; /* set green to zero if mute-window exceeds nt/2 */ if (hmuteW[ixpossyn[i]] >= nts/2) { memset(&green[i*nts],0, sizeof(float)*nt); continue; } green[i*nts+j] = f2p[i*nts+j] + pmin[i*nts+j]; for (j = 1; j < nts; j++) { green[i*nts+j] = f2p[i*nts+nts-j] + pmin[i*nts+j]; } } applyMute(green, hmuteW, smooth, 4, 1, nxs, nts, ixpossyn, npossyn, shift, pad, nt0); omp_set_num_threads(ngath); /* Transform the green position to the frequency domain */ /*for (i = 0; i < npossyn; i++) { rc1fft(&green[i*nts],&cshot[i*nfreq],ntfft,-1); }*/ //free(hG_d);free(hmuteW);free(hxrcvsyn); free(hmuteW);free(hxrcvsyn); free(hxsyn);free(hzsyn);free(hxnxsyn);free(cshot); } /* dry-run of synthesis to get all x-positions calcalated by the integration */ synthesisPosistions(nx, nt, nxs, nts, dt, xsyn, Nsyn, xrcv, xsrc, fxs2, fxs, dxs, dxsrc, dx, ixa, ixb, reci, nshots, ixpossyn, &npossyn, verbose); if (verbose) { vmess("synthesisPosistions: nshots=%d npossyn=%d", nshots, npossyn); } t1 = wallclock_time(); tread = t1-t0; iterations(Refl,nx,nt,nxs,nts,dt,xsyn,Nsyn,xrcv,xsrc,fxs2,fxs,dxs,dxsrc,dx,ixa,ixb, ntfft,nw,nw_low,nw_high,mode,reci,nshots,ixpossyn,npossyn,pmin,f1min,f1plus, f2p,G_d,muteW,smooth,shift,above,pad,nt0,&first,niter,verbose); /*if (niter==0) { for (l = 0; l < Nsyn; l++) { for (i = 0; i < npossyn; i++) { j = 0; ix = ixpossyn[i]; f2p[l*nxs*nts+i*nts+j] = G_d[l*nxs*nts+ix*nts+j]; f1plus[l*nxs*nts+i*nts+j] = G_d[l*nxs*nts+ix*nts+j]; for (j = 1; j < nts; j++) { f2p[l*nxs*nts+i*nts+j] = G_d[l*nxs*nts+ix*nts+j]; f1plus[l*nxs*nts+i*nts+j] = G_d[l*nxs*nts+ix*nts+j]; } } } }*/ if (niterh==0) { for (l = 0; l < Nsyn; l++) { for (i = 0; i < npossyn; i++) { j = 0; ix = ixpossyn[i]; green[i*nts+j] = hG_d[ix*nts+j]; for (j = 1; j < nts; j++) { green[i*nts+j] = hG_d[ix*nts+nts-j]; } } } } if (file_img!=NULL) { /*================ set variables for output data ================*/ hdrs_im = (segy *) calloc(shot.nx,sizeof(segy)); if (hdrs_im == NULL) verr("allocation for hdrs_out"); Image = (float *)calloc(Nsyn,sizeof(float)); first=0; imaging(Image,WPs,Refl,nx,nt,nxs,nts,dt,xsyn,Nsyn,xrcv,xsrc,fxs2,fxs,dxs,dxsrc,dx,ixa,ixb, ntfft,nw,nw_low,nw_high,mode,reci,nshots,ixpossyn,npossyn,pmin,f1min,f1plus, f2p,G_d,muteW,smooth,shift,above,pad,nt0,synpos,verbose); /*============= write output files ================*/ fp_out = fopen(file_img, "w+"); for (i = 0; i < shot.nx; i++) { hdrs_im[i].fldr = 1; hdrs_im[i].tracl = 1; hdrs_im[i].tracf = i+1; hdrs_im[i].scalco = -1000; hdrs_im[i].scalel = -1000; hdrs_im[i].sdepth = 0; hdrs_im[i].trid = 1; hdrs_im[i].ns = shot.nz; hdrs_im[i].trwf = shot.nx; hdrs_im[i].ntr = hdrs_im[i].fldr*hdrs_im[i].trwf; hdrs_im[i].f1 = zsyn[0]; hdrs_im[i].f2 = xsyn[0]; hdrs_im[i].dt = dt*(1E6); hdrs_im[i].d1 = (float)zsyn[shot.nx]-zsyn[0]; hdrs_im[i].d2 = (float)xsyn[1]-xsyn[0]; hdrs_im[i].sx = (int)roundf(xsyn[0] + (i*hdrs_im[i].d2)); hdrs_im[i].gx = (int)roundf(xsyn[0] + (i*hdrs_im[i].d2)); hdrs_im[i].offset = (hdrs_im[i].gx - hdrs_im[i].sx)/1000.0; } ret = writeData(fp_out, &Image[0], hdrs_im, shot.nz, shot.nx); if (ret < 0 ) verr("error on writing output file."); fclose(fp_out); } if (file_homg!=NULL) { /*================ set variables for output data ================*/ hdrs_homg = (segy *) calloc(shot.nx,sizeof(segy)); if (hdrs_homg == NULL) verr("allocation for hdrs_out"); HomG = (float *)calloc(Nsyn*ntfft,sizeof(float)); homogeneousg(HomG,green,Refl,nx,nt,nxs,nts,dt,xsyn,Nsyn,xrcv,xsrc,fxs2,fxs,dxs,dxsrc,dx,ixa,ixb, ntfft,nw,nw_low,nw_high,mode,reci,nshots,ixpossyn,npossyn,pmin,f1min,f1plus, f2p,G_d,muteW,smooth,shift,above,pad,nt0,synpos,verbose); /*============= write output files ================*/ fp_out = fopen(file_homg, "w+"); for (j = 0; j < ntfft; j++) { for (i = 0; i < shot.nx; i++) { hdrs_homg[i].fldr = j+1; hdrs_homg[i].tracl = j*shot.nx+i+1; hdrs_homg[i].tracf = i+1; hdrs_homg[i].scalco = -1000; hdrs_homg[i].scalel = -1000; hdrs_homg[i].sdepth = (int)(zloc*1000.0); hdrs_homg[i].trid = 1; hdrs_homg[i].ns = shot.nz; hdrs_homg[i].trwf = shot.nx; hdrs_homg[i].ntr = hdrs_homg[i].fldr*hdrs_homg[i].trwf; hdrs_homg[i].f1 = zsyn[0]; hdrs_homg[i].f2 = xsyn[0]; hdrs_homg[i].dt = dt*(1E6); hdrs_homg[i].d1 = (float)zsyn[shot.nx]-zsyn[0]; hdrs_homg[i].d2 = (float)xsyn[1]-xsyn[0]; hdrs_homg[i].sx = (int)roundf(xsyn[0] + (i*hdrs_homg[i].d2)); hdrs_homg[i].gx = (int)roundf(xsyn[0] + (i*hdrs_homg[i].d2)); hdrs_homg[i].offset = (hdrs_homg[i].gx - hdrs_homg[i].sx)/1000.0; } ret = writeData(fp_out, &HomG[j*shot.n], hdrs_homg, shot.nz, shot.nx); if (ret < 0 ) verr("error on writing output file."); } fclose(fp_out); } if (verbose) { t1 = wallclock_time(); vmess("and CPU-time write data = %.3f", t1-t2); } free(tapersy); exit(0); }
void AmpEst(float *ampest, WavePar WP, complex *Refl, int nx, int nt, int nxs, int nts, float dt, float *xsyn, int Nsyn, float *xrcv, float *xsrc, float fxs2, float fxs, float dxs, float dxsrc, float dx, int ixa, int ixb, int ntfft, int nw, int nw_low, int nw_high, int mode, int reci, int nshots, int *ixpossyn, int npossyn, float *pmin, float *f1min, float *f1plus, float *f2p, float *G_d, int *muteW, int smooth, int shift, int above, int pad, int nt0, int *synpos, int verbose) { int l, i, j, ix, iw, nfreq, first=0; float Amax, *At, *wavelet, *iRN, *f1d, *Gp, Wmax, *Wt, *f1dw, Am, Wm; complex *Gdf, *f1df, *Af, *Fop; double tfft; nfreq = ntfft/2+1; wavelet = (float *)calloc(ntfft,sizeof(float)); Gdf = (complex *)malloc(nfreq*sizeof(complex)); f1df = (complex *)malloc(nfreq*sizeof(complex)); Af = (complex *)calloc(nfreq,sizeof(complex)); At = (float *)malloc(nxs*ntfft*sizeof(complex)); Wt = (float *)malloc(nxs*ntfft*sizeof(complex)); Fop = (complex *)calloc(nxs*nw*Nsyn,sizeof(complex)); iRN = (float *)calloc(Nsyn*nxs*ntfft,sizeof(float)); f1d = (float *)calloc(Nsyn*nxs*ntfft,sizeof(float)); f1dw = (float *)calloc(Nsyn*nxs*ntfft,sizeof(float)); Gp = (float *)calloc(Nsyn*nxs*ntfft,sizeof(float)); freqwave(wavelet, WP.nt, WP.dt, WP.fp, WP.fmin, WP.flef, WP.frig, WP.fmax, WP.t0, WP.db, WP.shift, WP.cm, WP.cn, WP.w, WP.scale, WP.scfft, WP.inv, WP.eps, 0); Wmax = maxest(wavelet,WP.nt); if (verbose) vmess("Calculating amplitude"); //memcpy(f1d, G_d, Nsyn*nxs*ntfft*sizeof(float)); mode=-1; synthesis(Refl, Fop, f1min, iRN, nx, nt, nxs, nts, dt, xsyn, Nsyn, xrcv, xsrc, fxs2, fxs, dxs, dxsrc, dx, ixa, ixb, ntfft, nw, nw_low, nw_high, mode, reci, nshots, ixpossyn, npossyn, &tfft, &first, verbose); for (l = 0; l < Nsyn; l++) { for (i = 0; i < npossyn; i++) { j=0; Gp[l*nxs*nts+i*nts+j] = -iRN[l*nxs*nts+i*nts+j] + f1plus[l*nxs*nts+i*nts+j]; for (j = 1; j < nts; j++) { Gp[l*nxs*nts+i*nts+j] = -iRN[l*nxs*nts+i*nts+j] + f1plus[l*nxs*nts+i*nts+nts-j]; } } } applyMute(Gp, muteW, smooth, 2, Nsyn, nxs, nts, ixpossyn, npossyn, shift, pad, nt0); for (l = 0; l < Nsyn; l++) { for (i = 0; i < npossyn; i++) { ix = ixpossyn[i]; j=0; f1d[l*nxs*nts+i*nts+j] = G_d[l*nxs*nts+ix*nts+j]; f1dw[l*nxs*nts+i*nts+j] = G_d[l*nxs*nts+ix*nts+j]; for (j = 1; j < nts; j++) { f1d[l*nxs*nts+i*nts+j] = G_d[l*nxs*nts+ix*nts+j]; f1dw[l*nxs*nts+i*nts+j] = G_d[l*nxs*nts+ix*nts+nts-j]; } } } /*for (l = 0; l < Nsyn; l++) { for (i = 0; i < npossyn; i++) { ix = ixpossyn[i]; rc1fft(&Gp[l*nxs*ntfft+i*ntfft],Gdf,ntfft,-1); rc1fft(&f1d[l*nxs*ntfft+ix*ntfft],f1df,ntfft,-1); for (iw=0; iw<nfreq; iw++) { Af[iw].r += f1df[iw].r*Gdf[iw].r-f1df[iw].i*Gdf[iw].i; Af[iw].i += f1df[iw].r*Gdf[iw].i+f1df[iw].i*Gdf[iw].r; } } cr1fft(&Af[0],At,ntfft,1); //Amax = maxest(At,ntfft); Amax = At[0]; ampest[l] = (Wmax*Wmax)/(Amax/((float)ntfft)); memset(&Af[0],0.0, sizeof(float)*2*nfreq); vmess("Wmax:%.8f Amax:%.8f",Wmax,Amax); }*/ for (l = 0; l < Nsyn; l++) { Wm = 0.0; Am = 0.0; convol(&Gp[l*nxs*nts], &f1d[l*nxs*nts], At, nxs, nts, dt, 0); convol(&f1dw[l*nxs*nts], &f1d[l*nxs*nts], Wt, nxs, nts, dt, 0); for (i = 0; i < npossyn; i++) { Wm += Wt[i*nts]; Am += At[i*nts]; } ampest[l] = sqrtf(Wm/Am); } if (verbose) vmess("Amplitude calculation finished"); free(Gdf);free(f1df);free(Af);free(At);free(wavelet); free(iRN);free(f1d);free(Gp);free(Fop); return; }