void err(int status, const char *fmt, ...) { va_list ap; va_start(ap, fmt); verr(status, fmt, ap); va_end(ap); }
void err(int eval, const char *fmt, ...) { va_list argptr; va_start(argptr, fmt); verr(eval, fmt, argptr); /* NOTREACHED, so don't worry about va_end() */ }
void err(int eval, const char *format, ...) { va_list ap; va_start(ap, format); verr(eval, format, ap); va_end(ap); }
void err(int eval, const char *fmt, ...) { va_list argp; va_start(argp, fmt); verr(eval, fmt, argp); va_end(argp); }
__attribute__((format(printf, 2, 3))) static bool check_eagain(intmax_t rc, const char *fmt, ...) { va_list args; va_start(args, fmt); if (rc == -1 && errno != EAGAIN) verr(EXIT_FAILURE, fmt, args); va_end(args); return rc == -1 && errno == EAGAIN; }
/** * Print an error message to stderr, followed by a * description of the value of `errno`. Then exit the process. * * This is a non-standard BSD extension. * * @etymology Report (err)or! * * @param status The exit status the process should have. * @param format Formatting-string for the warning. * @param ... Formatting-arguments. * * @since Always. */ void err(int status, const char* format, ...) { va_list args; va_start(args, format); verr(status, format, args); va_end(args); }
void err(int exitcode, const char *fmt, ...) { va_list ap; va_start(ap, fmt); verr(exitcode, fmt, ap); va_end(ap); }
static void die(const char *err, ...) { va_list params; va_start(params, err); verr(EXIT_FAILURE, err, params); va_end(params); }
void err(int exitcode, const char *fmt, ...) { va_list args; va_start(args, fmt); verr(exitcode, fmt, args); }
__dead void err(jmp_buf* exit_jmp, int eval, const char *fmt, ...) { va_list ap; va_start(ap, fmt); verr(exit_jmp, eval, fmt, ap); va_end(ap); }
__dead void err(int eval, const char *fmt, ...) { va_list ap; va_start(ap, fmt); verr(eval, fmt, ap); va_end(ap); }
static void check_posix(intmax_t rc, const char *fmt, ...) { if (rc < 0) { va_list args; va_start(args, fmt); verr(EXIT_FAILURE, fmt, args); va_end(args); } }
void warn(const char *fmt, ...) { va_list ap; va_start(ap, fmt); verr(fmt, ap); va_end(ap); }
void die(const char *fmt, ...) { va_list ap; va_start(ap, fmt); verr(fmt, ap); va_end(ap); exit(1); }
/* * leave: * Leave the game somewhat gracefully, restoring all current * tty stats, and print errno. */ void leave(int exitval, const char *fmt, ...) { int serrno = errno; va_list ap; fincurs(); va_start(ap, fmt); errno = serrno; verr(exitval, fmt, ap); va_end(ap); }
double compareT(Eigen::Isometry3d a, Eigen::Isometry3d b, Eigen::VectorXd weight) { Eigen::Quaterniond qa(a.rotation()); Eigen::Quaterniond qb(b.rotation()); Eigen::Vector3d pa = a.translation(); Eigen::Vector3d pb = b.translation(); Eigen::VectorXd va(7), vb(7), verr(7), vScaled(7); va << pa, qa.x(), qa.y(), qa.z(), qa.w(); vb << pb, qb.x(), qb.y(), qb.z(), qb.w(); verr = vb - va; vScaled = weight.cwiseProduct(verr); return vScaled.squaredNorm(); }
void errc(int eval, int code, const char *fmt, ...) { va_list ap; int saved_errno = errno; errno = code; va_start(ap, fmt); verr(eval, fmt, ap); va_end(ap); /* NOTREACHED */ errno = saved_errno; }
void error(int status, int errnum, const char *format, ...) { va_list arg; va_start(arg, format); if (errnum == 0) { if (status == 0) vwarnx(format, arg); else verrx(status, format, arg); } else { if (status == 0) vwarn(format, arg); else verr(status, format, arg); } va_end(arg); }
void * xalloc(size_t n, const char *fmt, ...) { void *p = malloc(n); if (p == NULL) { if (fmt == NULL) err(1, "malloc"); else { va_list va; va_start(va, fmt); verr(1, fmt, va); va_end(va); } } return p; }
/* Logs the given error message to syslog if running in daemon mode, or * to the console if running in the foreground. */ void log_err(int e, const char *fmt, ...) { va_list ap; va_start(ap, fmt); if (Foreground) verr(e, fmt, ap); else { int olderrno = errno; vsyslog(LOG_DAEMON | LOG_ERR, fmt, ap); errno = olderrno; syslog(LOG_DAEMON | LOG_ERR, "%m"); exit(e); } /* NOTREACHED */ va_end(ap); }
void * xrealloc(void *old, size_t n, const char *fmt, ...) { char *p = realloc(old, n); if (p == NULL) { free(old); if (fmt == NULL) err(1, "realloc"); else { va_list va; va_start(va, fmt); verr(1, fmt, va); va_end(va); } } return p; }
void * xreallocarray(void *old, size_t s1, size_t s2, const char *fmt, ...) { void *p = reallocarray(old, s1, s2); if (p == NULL) { free(old); if (fmt == NULL) err(1, "reallocarray"); else { va_list va; va_start(va, fmt); verr(1, fmt, va); va_end(va); } } return p; }
long recvPar3D(recPar *rec, float sub_x0, float sub_y0, float sub_z0, float dx, float dy, float dz, long nx, long ny, long nz) { float *xrcv1, *xrcv2, *yrcv1, *yrcv2, *zrcv1, *zrcv2; long i, ix, iy, ir, verbose; float dxrcv, dyrcv, dzrcv, *dxr, *dyr, *dzr; float rrcv, dphi, oxrcv, oyrcv, ozrcv, arcv; double circ, h, a, b, e, s, xr, yr, zr, dr, srun, phase; float xrange, yrange, zrange, sub_x1, sub_y1, sub_z1; long Nx1, Nx2, Ny1, Ny2, Nz1, Nz2, Ndx, Ndy, Ndz, iarray, nrec, nh; long nxrcv, nyrcv, nzrcv, ncrcv, nrcv, ntrcv, *nlxrcv, *nlyrcv; float *xrcva, *yrcva, *zrcva; char* rcv_txt; FILE *fp; if (!getparlong("verbose", &verbose)) verbose = 0; /* Calculate Model Dimensions */ sub_x1=sub_x0+(nx-1)*dx; sub_y1=sub_y0+(ny-1)*dy; sub_z1=sub_z0+(nz-1)*dz; /* Compute how many receivers are defined and then allocate the receiver arrays */ /* Receiver Array */ nxrcv=countparval("xrcva"); nyrcv=countparval("yrcva"); nzrcv=countparval("zrcva"); if (nxrcv!=nzrcv) verr("Number of receivers in array xrcva (%li), yrcva (%li), zrcva(%li) are not equal",nxrcv,nyrcv,nzrcv); if (verbose&&nxrcv) vmess("Total number of array receivers: %li",nxrcv); /* Linear Receiver Arrays */ Nx1 = countparval("xrcv1"); Nx2 = countparval("xrcv2"); Ny1 = countparval("yrcv1"); Ny2 = countparval("yrcv2"); Nz1 = countparval("zrcv1"); Nz2 = countparval("zrcv2"); if (Nx1!=Nx2) verr("Number of receivers starting points in 'xrcv1' (%li) and number of endpoint in 'xrcv2' (%li) are not equal",Nx1,Nx2); if (Ny1!=Ny2) verr("Number of receivers starting points in 'yrcv1' (%li) and number of endpoint in 'yrcv2' (%li) are not equal",Ny1,Ny2); if (Nz1!=Nz2) verr("Number of receivers starting points in 'zrcv1' (%li) and number of endpoint in 'zrcv2' (%li) are not equal",Nz1,Nz2); if (Nx1!=Ny2) verr("Number of receivers starting points in 'xrcv1' (%li) and number of endpoint in 'yrcv2' (%li) are not equal",Nx1,Ny2); if (Nx1!=Nz2) verr("Number of receivers starting points in 'xrcv1' (%li) and number of endpoint in 'zrcv2' (%li) are not equal",Nx1,Nz2); rec->max_nrec=nyrcv*nxrcv; /* no receivers are defined use default linear array of receivers on top of model */ if (!rec->max_nrec && Nx1==0) Nx1=1; // Default is to use top of model to record data if (!rec->max_nrec && Ny1==0) Ny1=1; if (Nx1) { /* Allocate Start & End Points of Linear Arrays */ xrcv1=(float *)malloc(Nx1*sizeof(float)); xrcv2=(float *)malloc(Nx1*sizeof(float)); yrcv1=(float *)malloc(Nx1*sizeof(float)); yrcv2=(float *)malloc(Nx1*sizeof(float)); zrcv1=(float *)malloc(Nx1*sizeof(float)); zrcv2=(float *)malloc(Nx1*sizeof(float)); if (!getparfloat("xrcv1",xrcv1)) xrcv1[0]=sub_x0; if (!getparfloat("xrcv2",xrcv2)) xrcv2[0]=sub_x1; if (!getparfloat("yrcv1",yrcv1)) yrcv1[0]=sub_y0; if (!getparfloat("yrcv2",yrcv2)) yrcv2[0]=sub_y1; if (!getparfloat("zrcv1",zrcv1)) zrcv1[0]=sub_z0; if (!getparfloat("zrcv2",zrcv2)) zrcv2[0]=zrcv1[0]; /* check if receiver arrays fit into model */ for (iarray=0; iarray<Nx1; iarray++) { xrcv1[iarray] = MAX(sub_x0, xrcv1[iarray]); xrcv1[iarray] = MIN(sub_x0+nx*dx,xrcv1[iarray]); xrcv2[iarray] = MAX(sub_x0, xrcv2[iarray]); xrcv2[iarray] = MIN(sub_x0+nx*dx,xrcv2[iarray]); yrcv1[iarray] = MAX(sub_y0, yrcv1[iarray]); yrcv1[iarray] = MIN(sub_y0+ny*dy,yrcv1[iarray]); yrcv2[iarray] = MAX(sub_y0, yrcv2[iarray]); yrcv2[iarray] = MIN(sub_y0+ny*dy,yrcv2[iarray]); zrcv1[iarray] = MAX(sub_z0, zrcv1[iarray]); zrcv1[iarray] = MIN(sub_z0+nz*dz,zrcv1[iarray]); zrcv2[iarray] = MAX(sub_z0, zrcv2[iarray]); zrcv2[iarray] = MIN(sub_z0+nz*dz,zrcv2[iarray]); } /* Crop to Fit Model */ /* Max's addtion still have to check if it has the same fucntionality */ for (iarray=0;iarray<Nx1;iarray++) { if (xrcv1[iarray]<sub_x0) { if (xrcv2[iarray]<sub_x0) { verr("Linear array %li outside model bounds",iarray); } else { vwarn("Cropping element %li of 'xrcv1' (%f) to model bounds (%f)",iarray,xrcv1[iarray],sub_x0); xrcv1[iarray]=sub_x0; } } else if (xrcv1[iarray] > sub_x1) { verr("Linear array %li outside model bounds",iarray); } if ( (xrcv2[iarray] < xrcv1[iarray]) ) { verr("Ill defined linear array %li, 'xrcv1' (%f) greater than 'xrcv2' (%f)",iarray,xrcv1[iarray],xrcv2[iarray]); } else if (xrcv2[iarray]>sub_x1) { vwarn("Cropping element %li of 'xrcv2' (%f) to model bounds (%f)",iarray,xrcv2[iarray],sub_x1); xrcv2[iarray]=sub_x1; } if (yrcv1[iarray]<sub_y0) { if (yrcv2[iarray]<sub_y0) { verr("Linear array %li outside model bounds",iarray); } else { vwarn("Cropping element %li of 'yrcv1' (%f) to model bounds (%f)",iarray,yrcv1[iarray],sub_y0); yrcv1[iarray]=sub_y0; } } else if (yrcv1[iarray] > sub_y1) { verr("Linear array %li outside model bounds",iarray); } if ( (yrcv2[iarray] < yrcv1[iarray]) ) { verr("Ill defined linear array %li, 'yrcv1' (%f) greater than 'yrcv2' (%f)",iarray,yrcv1[iarray],yrcv2[iarray]); } else if (yrcv2[iarray]>sub_y1) { vwarn("Cropping element %li of 'yrcv2' (%f) to model bounds (%f)",iarray,yrcv2[iarray],sub_y1); yrcv2[iarray]=sub_y1; } if (zrcv1[iarray] < sub_z0) { if (zrcv2[iarray] < sub_z0) { verr("Linear array %li outside model bounds",iarray); } else { vwarn("Cropping element %li of 'zrcv1' (%f) to model bounds (%f)",iarray,zrcv1[iarray],sub_z0); zrcv1[iarray]=sub_z0; } } else if (zrcv1[iarray] > sub_z1) { verr("Linear array %li outside model bounds",iarray); } if ( (zrcv2[iarray] < zrcv1[iarray]) ) { verr("Ill defined linear array %li, 'zrcv1' (%f) greater than 'zrcv2' (%f)",iarray,zrcv1[iarray],zrcv2[iarray]); } else if (zrcv2[iarray]>sub_z1) { vwarn("Cropping element %li of 'xrcv2' (%f) to model bounds (%f)",iarray,zrcv2[iarray],sub_z1); zrcv2[iarray]=sub_z1; } } /* Get Sampling Rates */ Ndx = countparval("dxrcv"); Ndy = countparval("dyrcv"); Ndz = countparval("dzrcv"); dxr = (float *)malloc(Nx1*sizeof(float)); dyr = (float *)malloc(Nx1*sizeof(float)); dzr = (float *)malloc(Nx1*sizeof(float)); if(!getparfloat("dxrcv", dxr)) dxr[0]=dx; if(!getparfloat("dyrcv", dyr)) dyr[0]=dy; if(!getparfloat("dzrcv", dzr)) dzr[0]=0.0; if ( (Ndx<=1) && (Ndy<=1) && (Ndz==0) ){ /* default values are set */ for (i=1; i<Nx1; i++) { dxr[i] = dxr[0]; dyr[i] = dyr[0]; dzr[i] = dzr[0]; } Ndx=1; Ndy=1; Ndz=1; } else if ( (Ndz==1) && (Ndx==0) && (Ndy==0) ){ /* default values are set */ for (i=1; i<Nx1; i++) { dxr[i] = dxr[0]; dyr[i] = dyr[0]; dzr[i] = dzr[0]; } Ndz=1; Ndy=1; Ndx=1; } else { /* make sure that each array has dzrcv or dxrcv defined for each line or receivers */ if (Ndx!=Ndz) { verr("Number of 'dxrcv' (%li) is not equal to number of 'dzrcv' (%li) or 1",Ndx,Ndz); } if (Ndx!=Ndy) { verr("Number of 'dxrcv' (%li) is not equal to number of 'dyrcv' (%li) or 1",Ndx,Ndy); } if (Ndx!=Nx1 && Ndx!=1) { verr("Number of 'dxrcv' (%li) is not equal to number of starting points in 'xrcv1' (%li) or 1",Ndx,Nx1); } if (Ndy!=Ny1 && Ndy!=1) { verr("Number of 'dyrcv' (%li) is not equal to number of starting points in 'yrcv1' (%li) or 1",Ndy,Ny1); } } /* check consistency of receiver steps */ for (iarray=0; iarray<Ndx; iarray++) { if (dxr[iarray]<0) { dxr[i]=dx; vwarn("'dxrcv' element %li (%f) is less than zero, changing it to %f'",iarray,dxr[iarray],dx); } } for (iarray=0; iarray<Ndy; iarray++) { if (dyr[iarray]<0) { dyr[i]=dx; vwarn("'dyrcv' element %li (%f) is less than zero, changing it to %f'",iarray,dyr[iarray],dy); } } for (iarray=0;iarray<Ndz;iarray++) { if (dzr[iarray]<0) { dzr[iarray]=dz; vwarn("'dzrcv' element %li (%f) is less than zero, changing it to %f'",iarray,dzr[iarray],dz); } } for (iarray=0;iarray<Ndx;iarray++){ if (dxr[iarray]==0 && dzr[iarray]==0) { xrcv2[iarray]=xrcv1[iarray]; dxr[iarray]=1.; vwarn("'dxrcv' element %li & 'dzrcv' element 1 are both 0.",iarray+1); vmess("Placing 1 receiver at (%li,%li)",xrcv1[iarray],zrcv1[iarray]); } } for (iarray=0;iarray<Ndx;iarray++){ if (xrcv1[iarray]==xrcv2[iarray] && dxr[iarray]!=0) { dxr[iarray]=0.; vwarn("Linear array %li: 'xrcv1'='xrcv2' and 'dxrcv' is not 0. Setting 'dxrcv'=0",iarray+1); } } for (iarray=0;iarray<Ndx;iarray++){ if (yrcv1[iarray]==yrcv2[iarray] && dyr[iarray]!=0) { dyr[iarray]=0.; vwarn("Linear array %li: 'yrcv1'='yrcv2' and 'dyrcv' is not 0. Setting 'dyrcv'=0",iarray+1); } } for (iarray=0;iarray<Ndx;iarray++){ if (zrcv1[iarray]==zrcv2[iarray] && dzr[iarray]!=0.){ dzr[iarray]=0.; vwarn("Linear array %li: 'zrcv1'='zrcv2' and 'dzrcv' is not 0. Setting 'dzrcv'=0",iarray+1); } } /* Calculate Number of Receivers */ nrcv = 0; nlxrcv=(long *)malloc(Nx1*sizeof(long)); nlyrcv=(long *)malloc(Nx1*sizeof(long)); for (iarray=0; iarray<Nx1; iarray++) { xrange = (xrcv2[iarray]-xrcv1[iarray]); yrange = (yrcv2[iarray]-yrcv1[iarray]); zrange = (zrcv2[iarray]-zrcv1[iarray]); if (dxr[iarray] != 0.0 && dyr[iarray] != 0.0) { nlxrcv[iarray] = NINT(fabs(xrange/dxr[iarray]))+1; nlyrcv[iarray] = NINT(fabs(yrange/dyr[iarray]))+1; } else if (dxr[iarray] != 0.0) { nlxrcv[iarray] = NINT(fabs(xrange/dxr[iarray]))+1; nlyrcv[iarray] = 1; } else if (dyr[iarray] != 0.0) { nlxrcv[iarray] = 1; nlyrcv[iarray] = NINT(fabs(yrange/dyr[iarray]))+1; } else { if (dzr[iarray] == 0) { verr("For receiver array %li: receiver distance dzrcv is not given", iarray); } nlxrcv[iarray] = NINT(fabs(zrange/dzr[iarray]))+1; nlyrcv[iarray] = NINT(fabs(zrange/dzr[iarray]))+1; } nrcv+=nlyrcv[iarray]*nlxrcv[iarray]; } /* Calculate Number of Receivers */ if (verbose) vmess("Total number of linear array receivers: %li",nrcv); if (!nrcv) { free(xrcv1); free(xrcv2); free(yrcv1); free(yrcv2); free(zrcv1); free(zrcv2); free(dxr); free(dyr); free(dzr); free(nlxrcv); free(nlyrcv); } rec->max_nrec+=nrcv; } else { nrcv=0; } /* allocate the receiver arrays */ /* Total Number of Receivers */ if (verbose) vmess("Total number of receivers: %li",rec->max_nrec); /* Allocate Arrays */ rec->x = (long *)calloc(rec->max_nrec,sizeof(long)); rec->y = (long *)calloc(rec->max_nrec,sizeof(long)); rec->z = (long *)calloc(rec->max_nrec,sizeof(long)); rec->xr = (float *)calloc(rec->max_nrec,sizeof(float)); rec->yr = (float *)calloc(rec->max_nrec,sizeof(float)); rec->zr = (float *)calloc(rec->max_nrec,sizeof(float)); /* read in the receiver postions */ nrec=0; /* Receiver Array */ if (nxrcv != 0 && nyrcv != 0) { /* receiver array is defined */ xrcva = (float *)malloc(nxrcv*sizeof(float)); yrcva = (float *)malloc(nxrcv*sizeof(float)); zrcva = (float *)malloc(nxrcv*sizeof(float)); getparfloat("xrcva", xrcva); getparfloat("yrcva", yrcva); getparfloat("zrcva", zrcva); for (iy=0; iy<nyrcv; iy++) { for (ix=0; ix<nxrcv; ix++) { rec->xr[nrec+iy*nxrcv+ix] = xrcva[ix]-sub_x0; rec->yr[nrec+iy*nxrcv+ix] = yrcva[iy]-sub_y0; rec->zr[nrec+iy*nxrcv+ix] = zrcva[ix]-sub_z0; rec->x[nrec+iy*nxrcv+ix] = NINT((xrcva[ix]-sub_x0)/dx); rec->y[nrec+iy*nxrcv+ix] = NINT((yrcva[iy]-sub_y0)/dy); rec->z[nrec+iy*nxrcv+ix] = NINT((zrcva[ix]-sub_z0)/dz); if (verbose>4) fprintf(stderr,"Receiver Array: xrcv[%li]=%f yrcv[%li]=%f zrcv=%f\n", ix, rec->xr[nrec+ix]+sub_x0, iy, rec->yr[nrec+ix]+sub_y0, rec->zr[nrec+ix]+sub_z0); } } free(xrcva); free(yrcva); free(zrcva); nrec += nyrcv*nxrcv; } /* Linear Receiver Arrays */ if (nrcv!=0) { xrcv1 = (float *)malloc(Nx1*sizeof(float)); xrcv2 = (float *)malloc(Nx1*sizeof(float)); yrcv1 = (float *)malloc(Nx1*sizeof(float)); yrcv2 = (float *)malloc(Nx1*sizeof(float)); zrcv1 = (float *)malloc(Nx1*sizeof(float)); zrcv2 = (float *)malloc(Nx1*sizeof(float)); if(!getparfloat("xrcv1", xrcv1)) xrcv1[0]=sub_x0; if(!getparfloat("xrcv2", xrcv2)) xrcv2[0]=(nx-1)*dx+sub_x0; if(!getparfloat("yrcv1", yrcv1)) yrcv1[0]=sub_y0; if(!getparfloat("yrcv2", yrcv2)) yrcv2[0]=(ny-1)*dy+sub_y0; if(!getparfloat("zrcv1", zrcv1)) zrcv1[0]=sub_z0; if(!getparfloat("zrcv2", zrcv2)) zrcv2[0]=zrcv1[0]; Ndx = countparval("dxrcv"); Ndy = countparval("dyrcv"); Ndz = countparval("dzrcv"); dxr = (float *)malloc(Nx1*sizeof(float)); dyr = (float *)malloc(Nx1*sizeof(float)); dzr = (float *)malloc(Nx1*sizeof(float)); if(!getparfloat("dxrcv", dxr)) dxr[0]=dx; if(!getparfloat("dyrcv", dyr)) dyr[0]=dy; if(!getparfloat("dzrcv", dzr)) dzr[0]=0.0; if ( (Ndx<=1) && (Ndy<=1) && (Ndz==0) ){ /* default values are set */ for (i=1; i<Nx1; i++) { dxr[i] = dxr[0]; dyr[i] = dyr[0]; dzr[i] = dzr[0]; } Ndx=1; Ndy=1; } else if ( (Ndx<=1) && (Ndy==0) && (Ndz==0) ){ /* default values are set */ for (i=1; i<Nx1; i++) { dxr[i] = dxr[0]; dyr[i] = dyr[0]; dzr[i] = dzr[0]; } Ndx=1; } else if ( (Ndy<=1) && (Ndx==0) && (Ndz==0) ){ /* default values are set */ for (i=1; i<Nx1; i++) { dxr[i] = dxr[0]; dyr[i] = dyr[0]; dzr[i] = dzr[0]; } Ndy=1; } else if ( (Ndz==1) && (Ndy==0) && (Ndx==0) ){ /* default values are set */ for (i=1; i<Nx1; i++) { dxr[i] = dxr[0]; dyr[i] = dyr[0]; dzr[i] = dzr[0]; } Ndz=1; } else { /* make sure that each array has dzrcv or dxrcv defined for each line or receivers */ if (Ndx>1) assert(Ndx==Nx1); if (Ndy>1) assert(Ndy==Ny1); if (Ndz>1) assert(Ndz==Nx1); } /* check if receiver arrays fit into model */ for (iarray=0; iarray<Nx1; iarray++) { xrcv1[iarray] = MAX(sub_x0, xrcv1[iarray]); xrcv1[iarray] = MIN(sub_x0+nx*dx,xrcv1[iarray]); xrcv2[iarray] = MAX(sub_x0, xrcv2[iarray]); xrcv2[iarray] = MIN(sub_x0+nx*dx,xrcv2[iarray]); yrcv1[iarray] = MAX(sub_y0, yrcv1[iarray]); yrcv1[iarray] = MIN(sub_y0+ny*dy,yrcv1[iarray]); yrcv2[iarray] = MAX(sub_y0, yrcv2[iarray]); yrcv2[iarray] = MIN(sub_y0+ny*dy,yrcv2[iarray]); zrcv1[iarray] = MAX(sub_z0, zrcv1[iarray]); zrcv1[iarray] = MIN(sub_z0+nz*dz,zrcv1[iarray]); zrcv2[iarray] = MAX(sub_z0, zrcv2[iarray]); zrcv2[iarray] = MIN(sub_z0+nz*dz,zrcv2[iarray]); } /* calculate receiver array and store into rec->x,y,z */ for (iarray=0; iarray<Nx1; iarray++) { xrange = (xrcv2[iarray]-xrcv1[iarray]); yrange = (yrcv2[iarray]-yrcv1[iarray]); zrange = (zrcv2[iarray]-zrcv1[iarray]); if (dxr[iarray] != 0.0) { nrcv = nlyrcv[iarray]*nlxrcv[iarray]; dxrcv = dxr[iarray]; dyrcv = yrange/(nlyrcv[iarray]-1); dzrcv = zrange/(nlxrcv[iarray]-1); if (dyrcv != dyr[iarray]) { vwarn("For receiver array %li: calculated dyrcv=%f given=%f", iarray, dyrcv, dyr[iarray]); vwarn("The calculated receiver distance %f is used", dyrcv); } if (dzrcv != dzr[iarray]) { vwarn("For receiver array %li: calculated dzrcv=%f given=%f", iarray, dzrcv, dzr[iarray]); vwarn("The calculated receiver distance %f is used", dzrcv); } } else if (dyr[iarray] != 0.0) { nrcv = nlyrcv[iarray]*nlxrcv[iarray]; dxrcv = xrange/(nlxrcv[iarray]-1); dyrcv = dyr[iarray]; dzrcv = zrange/(nlxrcv[iarray]-1); if (dxrcv != dxr[iarray]) { vwarn("For receiver array %li: calculated dxrcv=%f given=%f", iarray, dxrcv, dxr[iarray]); vwarn("The calculated receiver distance %f is used", dxrcv); } if (dzrcv != dzr[iarray]) { vwarn("For receiver array %li: calculated dzrcv=%f given=%f", iarray, dzrcv, dzr[iarray]); vwarn("The calculated receiver distance %f is used", dzrcv); } } else { if (dzr[iarray] == 0) { verr("For receiver array %li: receiver distance dzrcv is not given", iarray); } nrcv = nlyrcv[iarray]*nlxrcv[iarray]; dxrcv = xrange/(nrcv-1); dyrcv = yrange/(nrcv-1); dzrcv = dzr[iarray]; if (dxrcv != dxr[iarray]) { vwarn("For receiver array %li: calculated dxrcv=%f given=%f", iarray, dxrcv, dxr[iarray]); vwarn("The calculated receiver distance %f is used", dxrcv); } if (dyrcv != dyr[iarray]) { vwarn("For receiver array %li: calculated dyrcv=%f given=%f", iarray, dyrcv, dyr[iarray]); vwarn("The calculated receiver distance %f is used", dyrcv); } } // calculate coordinates for (iy=0; iy<nlyrcv[iarray]; iy++) { for (ix=0; ix<nlxrcv[iarray]; ix++) { rec->xr[nrec]=xrcv1[iarray]-sub_x0+ix*dxrcv; rec->yr[nrec]=yrcv1[iarray]-sub_y0+iy*dyrcv; rec->zr[nrec]=zrcv1[iarray]-sub_z0+ix*dzrcv; rec->x[nrec]=NINT((rec->xr[nrec])/dx); rec->y[nrec]=NINT((rec->yr[nrec])/dy); rec->z[nrec]=NINT((rec->zr[nrec])/dz); nrec++; } } } free(xrcv1); free(xrcv2); free(yrcv1); free(yrcv2); free(zrcv1); free(zrcv2); free(dxr); free(dyr); free(dzr); free(nlxrcv); free(nlyrcv); } rec->n=rec->max_nrec; return 0; }
int main (int argc, char **argv) { FILE *fp_in, *fp_out; char *fin, *fout, *ptr, fbegin[100], fend[100], fins[100], fin2[100], numb1[100]; float *indata, *outdata, *rtrace, fz, fx; float dt, dx, t0, x0, xmin, xmax, sclsxgx, dt2, dx2, t02, x02, xmin2, xmax2, sclsxgx2, dxrcv, dzrcv; int nshots, nt, nx, ntraces, nshots2, nt2, nx2, ntraces2, ix, it, is, ir, pos, ifile, file_det, nxs, nzs; int xcount, numb, dnumb, ret, nzmax, verbose; segy *hdr_in, *hdr_out; initargs(argc, argv); requestdoc(1); if (!getparstring("file_in", &fin)) fin = NULL; if (!getparstring("file_out", &fout)) fout = "out.su"; if (!getparint("numb", &numb)) numb=0; if (!getparint("dnumb", &dnumb)) dnumb=0; if (!getparint("nzmax", &nzmax)) nzmax=0; if (!getparint("verbose", &verbose)) verbose=0; if (fin == NULL) verr("Incorrect downgoing input"); if (dnumb < 1) dnumb = 1; sprintf(numb1,"%d",numb); ptr = strstr(fin,numb1); pos = ptr - fin + 1; sprintf(fbegin,"%*.*s", pos-1, pos-1, fin); sprintf(fend,"%s", fin+pos); file_det = 1; nzs=0; while (file_det) { sprintf(fins,"%d",nzs*dnumb+numb); sprintf(fin,"%s%s%s",fbegin,fins,fend); fp_in = fopen(fin, "r"); if (fp_in == NULL) { if (nzs == 0) { verr("error on opening basefile=%s", fin); } else if (nzs == 1) { vmess("1 file detected"); } else { vmess("%d files detected",nzs); file_det = 0; break; } } fclose(fp_in); nzs++; if (nzmax!=0 && nzs == nzmax) { vmess("%d files detected",nzs); file_det = 0; break; } } sprintf(fins,"%d",numb); sprintf(fin2,"%s%s%s",fbegin,fins,fend); nshots = 0; getFileInfo(fin2, &nt, &nx, &nshots, &dt, &dx, &t0, &x0, &xmin, &xmax, &sclsxgx, &ntraces); sprintf(fins,"%d",numb+dnumb); sprintf(fin2,"%s%s%s",fbegin,fins,fend); nshots = 0; getFileInfo(fin2, &nt2, &nx2, &nshots2, &dt2, &dx2, &t02, &x02, &xmin2, &xmax2, &sclsxgx2, &ntraces2); dxrcv=dx*1000; dzrcv=t02-t0; if (nshots==0) nshots=1; nxs = ntraces; // ngath zijn het aantal schoten hdr_out = (segy *)calloc(nxs,sizeof(segy)); outdata = (float *)calloc(nxs*nzs,sizeof(float)); hdr_in = (segy *)calloc(nxs,sizeof(segy)); indata = (float *)calloc(nxs,sizeof(float)); readSnapData(fin2, &indata[0], &hdr_in[0], nshots, nxs, nt, 0, nxs, 0, nt); nshots = hdr_in[nxs-1].fldr; nxs = hdr_in[nxs-1].tracf; for (ir = 0; ir < nzs; ir++) { if (verbose) vmess("Depth:%d out of %d",ir+1,nzs); sprintf(fins,"%d",ir*dnumb+numb); sprintf(fin2,"%s%s%s",fbegin,fins,fend); fp_in = fopen(fin2, "r"); if (fp_in == NULL) { verr("Error opening file"); } fclose(fp_in); readSnapData(fin2, &indata[0], &hdr_in[0], nshots, nxs, nt, 0, nxs, 0, nt); if (ir==0) fz=hdr_in[0].f1; fx=hdr_in[0].f2; if (ir==1) dzrcv=hdr_in[0].f1-fz; for (is = 0; is < nxs; is++) { for (it = 0; it < nshots; it++) { outdata[it*nxs*nzs+is*nzs+ir] = indata[it*nxs+is]; } } } free(indata); fp_out = fopen(fout, "w+"); for (is = 0; is < nshots; is++) { for (ix = 0; ix < nxs; ix++) { hdr_out[ix].fldr = is+1; hdr_out[ix].tracl = is*nxs+ix+1; hdr_out[ix].tracf = ix+1; hdr_out[ix].scalco = -1000; hdr_out[ix].scalel = -1000; hdr_out[ix].sdepth = hdr_in[0].sdepth; hdr_out[ix].trid = 1; hdr_out[ix].ns = nzs; hdr_out[ix].trwf = nxs; hdr_out[ix].ntr = hdr_out[ix].fldr*hdr_out[ix].trwf; hdr_out[ix].f1 = fz; hdr_out[ix].f2 = fx; hdr_out[ix].dt = dt*(1E6); hdr_out[ix].d1 = dzrcv; hdr_out[ix].d2 = dxrcv; hdr_out[ix].sx = (int)roundf(fx + (ix*hdr_out[ix].d2)); hdr_out[ix].gx = (int)roundf(fx + (ix*hdr_out[ix].d2)); hdr_out[ix].offset = (hdr_out[ix].gx - hdr_out[ix].sx)/1000.0; } ret = writeData(fp_out, &outdata[is*nxs*nzs], hdr_out, nzs, nxs); if (ret < 0 ) verr("error on writing output file."); } fclose(fp_out); return 0; }
int getFileInfo(char *filename, int *n1, int *n2, int *ngath, float *d1, float *d2, float *f1, float *f2, float *xmin, float *xmax, float *sclsxgx, int *nxm) { FILE *fp; size_t nread, data_sz; off_t bytes, ret, trace_sz, ntraces; int sx_shot, gx_start, gx_end, itrace, one_shot, igath, end_of_file, fldr_shot; int verbose=2; float scl, *trace, dxsrc, dxrcv, offset; segy hdr; if (filename == NULL) { /* read from input pipe */ *n1=0; *n2=0; return -1; /* Input pipe */ } else fp = fopen( filename, "r" ); if (fp == NULL) verr("File %s does not exist or cannot be opened", filename); nread = fread( &hdr, 1, TRCBYTES, fp ); assert(nread == TRCBYTES); ret = fseeko( fp, 0, SEEK_END ); if (ret<0) perror("fseeko"); bytes = ftello( fp ); *n1 = hdr.ns; if (hdr.trid == 1 || hdr.dt != 0) { *d1 = ((float) hdr.dt)*1.e-6; *f1 = ((float) hdr.delrt)/1000.; } else { *d1 = hdr.d1; *f1 = hdr.f1; } *f2 = hdr.f2; data_sz = sizeof(float)*(*n1); trace_sz = sizeof(float)*(*n1)+TRCBYTES; ntraces = (int) (bytes/trace_sz); // fprintf(stderr,"data_sz %ld trace_sz %lld bytes = %lld\n", data_sz, trace_sz, bytes); if (hdr.scalco < 0) scl = 1.0/fabs(hdr.scalco); else if (hdr.scalco == 0) scl = 1.0; else scl = hdr.scalco; *sclsxgx = scl; /* check to find out number of traces in shot gather */ one_shot = 1; itrace = 0; fldr_shot = hdr.fldr; sx_shot = hdr.sx; gx_start = hdr.gx; trace = (float *)malloc(hdr.ns*sizeof(float)); fseeko( fp, TRCBYTES, SEEK_SET ); while (one_shot) { nread = fread( trace, sizeof(float), hdr.ns, fp ); assert (nread == hdr.ns); itrace++; gx_end = hdr.gx; nread = fread( &hdr, 1, TRCBYTES, fp ); if (nread==0) break; if ((sx_shot != hdr.sx) || (fldr_shot != hdr.fldr) ) break; } if (itrace>1) { dxrcv = (float)(gx_end - gx_start)/(float)(itrace-1); *n2 = itrace; *d2 = fabs(dxrcv)*scl; if (NINT(dxrcv*1e3) != NINT(fabs(hdr.d2)*1e3)) { if (dxrcv != 0) *d2 = fabs(dxrcv)*scl; else *d2 = hdr.d2; } } else { *n2 = MAX(hdr.trwf, 1); *d2 = hdr.d2; dxrcv = hdr.d2; } /* check if the total number of traces (ntraces) is correct */ /* expensive way to find out how many gathers there are */ // fprintf(stderr, "ngath = %d dxrcv=%f d2=%f scl=%f \n", *ngath, dxrcv, *d2, scl); if (*ngath == 0) { *n2 = 0; end_of_file = 0; one_shot = 1; igath = 0; fseeko( fp, 0, SEEK_SET ); offset = (NINT((hdr.gx-hdr.sx)*scl*100)/100.0); *xmax = offset; *xmin = offset; dxrcv = *d2; while (!end_of_file) { itrace = 0; nread = fread( &hdr, 1, TRCBYTES, fp ); if (nread != TRCBYTES) { break; } fldr_shot = hdr.fldr; sx_shot = hdr.sx; gx_start = hdr.gx; gx_end = hdr.gx; itrace = 0; while (one_shot) { fseeko( fp, data_sz, SEEK_CUR ); itrace++; if (hdr.gx != gx_end) dxrcv = MIN(dxrcv,abs(hdr.gx-gx_end)); gx_end = hdr.gx; offset = (NINT((hdr.gx-hdr.sx)*scl*100)/100.0); *xmax = MAX(*xmax,offset); *xmin = MIN(*xmin,offset); nread = fread( &hdr, 1, TRCBYTES, fp ); if (nread != TRCBYTES) { one_shot = 0; end_of_file = 1; break; } if ((sx_shot != hdr.sx) || (fldr_shot != hdr.fldr) ) break; } if (itrace>1) { dxrcv = (float)fabs(gx_end - gx_start)/((float)(itrace-1)); dxsrc = (float)(hdr.sx - sx_shot)*scl; *n2 = MAX(*n2,itrace); } if (verbose>1) { fprintf(stderr," . Scanning shot %d (%d) with %d traces dxrcv=%.2f dxsrc=%.2f %d %d\n",sx_shot,igath,itrace,dxrcv*scl,dxsrc,gx_end,gx_start); } if (itrace != 0) { /* end of shot record */ fseeko( fp, -TRCBYTES, SEEK_CUR ); igath++; } else { end_of_file = 1; } } *ngath = igath; *d2 = dxrcv*scl; } else { /* read last trace header */ fseeko( fp, -trace_sz, SEEK_END ); nread = fread( &hdr, 1, TRCBYTES, fp ); offset = (NINT((hdr.gx-hdr.sx)*scl*100)/100.0); *xmax = MAX(*xmax,offset); *xmin = MIN(*xmin,offset); *xmin = MIN(sx_shot,hdr.sx*scl); *ngath = ntraces/(*n2); } // *nxm = NINT((*xmax-*xmin)/dxrcv)+1; *nxm = (int)ntraces; fclose( fp ); free(trace); 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); }
__attribute__((format(printf, 2, 3))) static void check_posix(intmax_t rc, const char *fmt, ...) { va_list args; va_start(args, fmt); if (rc == -1) verr(EXIT_FAILURE, fmt, args); va_end(args); }
void * lsd_nomem_error (char *file, int line, char *msg) { verr (NULL, "Out of memory: %s: %s:%d\n", msg, file, line); return NULL; }
void lsd_fatal_error (char *file, int line, char *msg) { verr (NULL, msg); exit (1); }
void verrc (int status, int code, const char *format, va_list ap) { errno = code; verr (status, format, ap); }