int main(int argc, char **argv) { /* Segy data constans */ int ntr=0; /* number of traces */ char *outpar=NULL; /* name of file holding output */ FILE *outparfp=stdout; /* ... its file pointer */ initargs(argc, argv); requestdoc(1); /* Get information from the first header */ if (!gettr(&tr)) err("can't get first trace"); if (!getparstring("outpar", &outpar)) outpar = "/dev/stdout" ; outparfp = efopen(outpar, "w"); checkpars(); /* Loop over traces getting a count */ do { ++ntr; } while(gettr(&tr)); fprintf(outparfp, "%d", ntr); return(CWP_Exit()); }
int main(int argc, char **argv) { int ns; /* samples on output traces */ /* Initialize */ initargs(argc, argv); requestdoc(1); /* Get info from first trace */ if (!fvgettr(stdin, &tr)) err("can't get first trace"); if (!getparint("ns", &ns)) ns = tr.ns; checkpars(); /* Loop over the traces */ do { int nt = tr.ns; if (nt < ns) /* pad with zeros */ memset((void *)(tr.data + nt), 0, (ns-nt)*FSIZE); tr.ns = ns; puttr(&tr); } while (fvgettr(stdin, &tr)); return(CWP_Exit()); }
int main(int argc, char **argv) { int nt; /* number of samples on input */ int ntout; /* number of samples on output */ int it; /* counter */ int istart; /* beginning sample */ int izero; /* - istart */ int norm; /* user defined normalization value */ int sym; /* symmetric plot? */ float scale; /* scale factor computed from norm */ float *temp=NULL; /* temporary array */ float dt; /* time sampling interval (sec) */ /* hook up getpar */ initargs(argc, argv); requestdoc(1); /* get information from the first header */ if (!gettr(&tr)) err("can't get first trace"); nt = tr.ns; dt = tr.dt/1000000.0; /* get parameters */ if (!getparint("ntout",&ntout)) ntout=101; if (!getparint("norm",&norm)) norm = 1; if (!getparint("sym",&sym)) sym = 1; checkpars(); /* allocate workspace */ temp = ealloc1float(ntout); /* index of first sample */ if (sym == 0) istart = 0; else istart = -(ntout-1)/2; /* index of sample at time zero */ izero = -istart; /* loop over traces */ do { xcor(nt,0,tr.data,nt,0,tr.data,ntout,istart,temp); if (norm) { scale = 1.0/(temp[izero]==0.0?1.0:temp[izero]); for (it=0; it<ntout; ++it) temp[it] *= scale; } memcpy((void *) tr.data, (const void *) temp, ntout*FSIZE); tr.ns = ntout; tr.f1 = -dt*ntout/2.0; tr.delrt = 0; puttr(&tr); } while(gettr(&tr)); return(CWP_Exit()); }
int main(int argc, char **argv) { int i; /* counter */ int itr=0; /* trace counter */ int verbose; /* =0 silent, =1 chatty */ int interp; /* =1 interpolate to get NaN */ /* and Inf replacement values */ float value; /* value to set NaN and Infs to */ /* Initialize */ initargs(argc,argv); requestdoc(1); /* Get info from first trace */ if(!gettr(&tr) ) err("Can't get first trace \n"); /* Get parameters */ if(!getparint("verbose",&verbose)) verbose = 1; if(!getparint("interp",&interp)) interp = 0; if(!getparfloat("value",&value)) value = 0.0; checkpars(); /* Loop over traces */ do{ ++itr; for(i=0; i<tr.ns; ++i){ if(!isfinite(tr.data[i])) { if (verbose) warn("found NaN trace = %d sample = %d", itr, i); if (interp) { /* interpolate nearest neighbors */ /* for NaN replacement value */ if (i==0 && isfinite(tr.data[i+1])) { tr.data[i]=tr.data[i+1]; } else if(i==tr.ns-1 && isfinite(tr.data[i-2])) { tr.data[i]= tr.data[i-2]; } else if( isfinite(tr.data[i-1]) && isfinite(tr.data[i+1]) ) { tr.data[i]=(tr.data[i-1]+tr.data[i+1])/2.0; } } /* use user defined NaNs replacement value */ tr.data[i] = value; } } puttr(&tr); } while(gettr(&tr)); return(CWP_Exit()); }
int main(int argc, char **argv) { int ix; /*index for nx*/ int iy; /*index for ny*/ int nx; /*number of sampels in horizon*/ int ny; /*number of sampels in horizon*/ float xmin,xmax; float ymin,ymax; float zmin,zmax; float ***databot; /*data for plotting*/ float ***datatop; float ***emisbot; /*color on top horizon*/ float ***emistop; /*color right above base horizon*/ float v0; int verbose; /*if =1 print some useful information*/ float eyez; int ihz; /*index for interfaces*/ int *ntris; /*number of triangles*/ int nt; /*number of samples in each ray*/ int iray; /*index for nrays*/ int it; /*index for nt*/ int iw,iwf,nwf; int is,ns; /*number of sources*/ float q0[4]; char *rayfile=""; /*ray file*/ char *wffile=""; char *sttfile=""; FILE *rayfp=NULL; FILE *wffp=NULL; FILE *sttfp=NULL; Layer *horz; Layer *ray; Layer *wf; float vmin=99999.0; float vmax=0.0; float tt; /*debugging information in the ray file*/ int itri; char names[10]; int iflag; /*flag: =1 means ray effective*/ float emission[4]; float tmax=0.0,tmin=FLT_MAX; float ***stt=NULL; float **ttt=NULL; int ntr; /* hook up getpar */ initargs(argc,argv); requestdoc(1); /* get parameters */ if (!getparint("verbose",&verbose)) verbose=0; /****************************************** Read model parameters from hzfile ******************************************/ fread(&nhz,sizeof(int),1,stdin); fread(&nx,sizeof(int),1,stdin); fread(&ny,sizeof(int),1,stdin); fread(&xmin,sizeof(float),1,stdin); fread(&xmax,sizeof(float),1,stdin); fread(&ymin,sizeof(float),1,stdin); fread(&ymax,sizeof(float),1,stdin); fread(&zmin,sizeof(float),1,stdin); fread(&zmax,sizeof(float),1,stdin); if (verbose) fprintf(stderr,"xmin=%f\nxmax=%f\nymin=%f\nymax=%f\nzmin=%f\nzmax=%f\n", xmin,xmax,ymin,ymax,zmin,zmax); if (getparstring("rayfile",&rayfile)) if ((rayfp=fopen(rayfile,"r"))==NULL) err("Can not open rayfile %s",rayfile); if (getparstring("wffile",&wffile)) if ((wffp=fopen(wffile,"r"))==NULL) err("Can not open wffile %s",wffile); if (getparstring("sttfile",&sttfile)) if ((sttfp=fopen(sttfile,"r"))==NULL) err("Can not open sttfile %s",sttfile); if (!getparfloat("tbs",&tbs)) tbs=0.8; if (!getparint("hue",&glb_hue)) glb_hue=1; /*1 for glb_hue*/ if (verbose) warn("nhz=%d, nx=%d, ny=%d\n",nhz,nx,ny); glb_on_or_off=(enum On_or_Off *)ealloc1int(3*nhz+6); for (ihz=0;ihz<nhz;ihz++) glb_on_or_off[ihz]=ON; horz=(Layer *)alloc1float(sizeof(Layer)*(nhz+1)); /********************************************************* Do not use GLUT_INDEX, which gives no image; GLUT_SINGLE will cause redrawing every time you retate it; *********************************************************/ glutInit(&argc, argv); glutInitWindowSize(768,768); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow("viewer3"); glutDisplayFunc(redraw); glutIdleFunc(NULL); if (!getparfloat("q",q0)){ q0[0]=-0.6; q0[1]=0.05; q0[2]=-0.06; q0[3]=0.8; } checkpars(); normalize_quat(q0); curquat[0]=q0[0]; curquat[1]=q0[1]; curquat[2]=q0[2]; curquat[3]=q0[3]; glutReshapeFunc(myReshape); glutVisibilityFunc(vis); glutMouseFunc(mouse); glutMotionFunc(motion); glutCreateMenu(controlLights); glutAddMenuEntry("Quit",-1); glutAddMenuEntry("Full Screen",0); glutAddMenuEntry("White/Color Rays",1); glutAddMenuEntry("Plot Rays",2); glutAddMenuEntry("Surface Traveltimes",3); glutAddMenuEntry("Wired or Solid WFs",4); glutAddMenuEntry("Plot Wavefronts",5); glutAddMenuEntry("TRI or TETRA or LAYER or HORZ",6); for (ihz=0;ihz<nhz;ihz++) { sprintf(names,"Layer %d",ihz+1); glutAddMenuEntry(names,ihz+7); } glutAttachMenu(GLUT_RIGHT_BUTTON); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); eyez=25; glMatrixMode(GL_PROJECTION); gluPerspective( 40.0, /*fovy: view angle in y direction*/ 1.0, /*aspect: ratio of width (x) to y (height)*/ eyez-DIAMETER, /*near clipping plane*/ eyez+DIAMETER); /*far clipping plane*/ glMatrixMode(GL_MODELVIEW); gluLookAt( 0.0, 0.0, eyez, /*(eyex,eyey,eyez): the eye position*/ 0.0, 0.0, 0.0, /*(centerx,centery,centerz): the center*/ 0.0, 1.0, 0.0); /*(upx,upy,upz): the up direction*/ glPushMatrix(); /*the order that tetramod uses is like this*/ for (ihz=0;ihz<nhz;ihz++) { fprintf(stderr,"reading horizon information %d\n",ihz); /********************************************************** input the horizon information from file hzfile: **********************************************************/ horz[ihz].x=ealloc2float(nx,ny); horz[ihz].y=ealloc2float(nx,ny); horz[ihz].z=ealloc2float(nx,ny); horz[ihz].v0=ealloc2float(nx,ny); horz[ihz].v1=ealloc2float(nx,ny); fprintf(stderr,"read horz[%d].x...\n",ihz); if (fread(horz[ihz].x[0],sizeof(float),nx*ny, stdin)!=nx*ny) err("Can not read x to stdin"); fprintf(stderr,"read horz[%d].y...\n",ihz); if (fread(horz[ihz].y[0],sizeof(float),nx*ny, stdin)!=nx*ny) err("Can not read y to stdin"); fprintf(stderr,"read horz[%d].z...\n",ihz); if (fread(horz[ihz].z[0],sizeof(float),nx*ny, stdin)!=nx*ny) err("Can not read z to stdin"); fprintf(stderr,"read horz[%d].v0...\n",ihz); if (fread(horz[ihz].v0[0],sizeof(float),nx*ny,stdin)!= nx*ny) err("Can not read v0 to stdin"); fprintf(stderr,"read horz[%d].v1...\n",ihz); if (fread(horz[ihz].v1[0],sizeof(float),nx*ny,stdin)!= nx*ny) err("Can not read v1 to stdin"); for (iy=0;iy<ny;iy++) { for (ix=0;ix<nx;ix++) { vmin=MIN(vmin,horz[ihz].v0[iy][ix]); vmax=MAX(vmax,horz[ihz].v0[iy][ix]); vmin=MIN(vmin,horz[ihz].v1[iy][ix]); vmax=MAX(vmax,horz[ihz].v1[iy][ix]); } } } if (verbose) fprintf(stderr,"vmin=%f, vmax=%f\n",vmin,vmax); horz[nhz].x=ealloc2float(nx,ny); horz[nhz].y=ealloc2float(nx,ny); horz[nhz].z=ealloc2float(nx,ny); fprintf(stderr,"assign horz[%d].x,y,z\n",nhz); for (ix=0;ix<nx;ix++) { for (iy=0;iy<ny;iy++) { horz[nhz].x[iy][ix]=horz[nhz-1].x[iy][ix]; horz[nhz].y[iy][ix]=horz[nhz-1].y[iy][ix]; horz[nhz].z[iy][ix]=zmax; } } databot=ealloc3float(3,nx,ny); emisbot=ealloc3float(4,nx,ny); datatop=ealloc3float(3,nx,ny); emistop=ealloc3float(4,nx,ny); for (ihz=0;ihz<nhz;ihz++) { fprintf(stderr,"assigning datatop for ihz=%d\n",ihz); for (ix=0;ix<nx;ix++) { for (iy=0;iy<ny;iy++) { datatop[iy][ix][0]=( (horz[ihz].x[iy][ix]-xmin)/ (xmax-xmin)-0.5)*DIAMETER; datatop[iy][ix][1]=-( (horz[ihz].y[iy][ix]-ymin)/ (ymax-ymin)-0.5)*DIAMETER; datatop[iy][ix][2]=( (horz[ihz].z[iy][ix]-zmin)/ (zmax-zmin)-0.5)*DIAMETER; v0=horz[ihz].v0[iy][ix]; vEmission(v0,vmin,vmax,emistop[iy][ix]); } } fprintf(stderr,"assigning databot for ihz=%d\n",ihz); for (ix=0;ix<nx;ix++) { for (iy=0;iy<ny;iy++) { databot[iy][ix][0]=( (horz[ihz+1].x[iy][ix]-xmin) /(xmax-xmin)-0.5)*DIAMETER; databot[iy][ix][1]=-( (horz[ihz+1].y[iy][ix]-ymin) /(ymax-ymin)-0.5)*DIAMETER; databot[iy][ix][2]=( (horz[ihz+1].z[iy][ix]-zmin) /(zmax-zmin)-0.5)*DIAMETER; v0=horz[ihz].v1[iy][ix]; vEmission(v0,vmin,vmax,emisbot[iy][ix]); } } showLayer(ihz,databot,datatop,nx,ny,emisbot,emistop); showHorz(ihz,datatop,nx,ny,emistop); showTetra(ihz,databot,datatop,nx,ny,emisbot,emistop); showTri(ihz,datatop,nx,ny,emistop); } free3float(databot); free3float(datatop); free3float(emisbot); free3float(emistop); /******************************************************************* The ray positions are generated by sutetraray, named by rayfile. This part will be ignored if rayfile not specified. ********************************************************************/ if (rayfp!=NULL) { fscanf(rayfp, "%d =Number of shots\n",&ns); fprintf(stderr,"ns=%d\n",ns); if (ns<=0 || ns>100) { ns=0; rayfp=NULL; } ray=(Layer *)alloc1float(sizeof(Layer)*ns); tmax=0.0; for (is=0;is<ns;is++) { fscanf(rayfp, "%d =Maximum number of segments\n",&nt); fprintf(stderr,"%d =Maximum number of segments\n",nt); fscanf(rayfp, "%d =Number of rays\n",&ray[is].nrays); fprintf(stderr,"%d =Number of rays\n",ray[is].nrays); ray[is].x=ealloc2float(ray[is].nrays,nt); ray[is].y=ealloc2float(ray[is].nrays,nt); ray[is].z=ealloc2float(ray[is].nrays,nt); ray[is].v0=ealloc2float(ray[is].nrays,nt); ray[is].nseg=ealloc1int(ray[is].nrays); for (iray=0;iray<ray[is].nrays;iray++) { fscanf(rayfp,"%d=nseg %f=ttotal\n",&ray[is].nseg[iray],&tt); if (nt<ray[is].nseg[iray]) err("nt should >=ray[is].nseg[iray]"); for (it=0;it<ray[is].nseg[iray];it++) { fscanf(rayfp,"%f %f %f %f %f\n", &ray[is].x[it][iray], &ray[is].y[it][iray], &ray[is].z[it][iray], &ray[is].v0[it][iray],&tt); tmax=MAX(tmax,ray[is].v0[it][iray]); } ray[is].z[ray[is].nseg[iray]-1][iray]= MAX(0.001,ray[is].z[ray[is].nseg[iray]-1][iray]); for (it=0;it<ray[is].nseg[iray];it++) { ray[is].x[it][iray]=((ray[is].x[it][iray]-xmin)/ (xmax-xmin)-0.5)*DIAMETER; ray[is].y[it][iray]=-((ray[is].y[it][iray]-ymin)/ (ymax-ymin)-0.5)*DIAMETER; ray[is].z[it][iray]=((ray[is].z[it][iray]-zmin)/ (zmax-zmin)-0.5)*DIAMETER; } } } fclose(rayfp); /*white rays*/ glNewList(nhz*4+3,GL_COMPILE); emission[0]=emission[1]=emission[2]=emission[3]=1.0; glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,emission); for (is=0;is<ns;is++) { for (iray=0;iray<ray[is].nrays;iray++) { iflag=0; glBegin(GL_LINE_STRIP); for (it=0;it<ray[is].nseg[iray];it++) { if (fabs(ray[is].x[it][iray])<RADIUS && fabs(ray[is].y[it][iray])<RADIUS && fabs(ray[is].z[it][iray])<RADIUS) { glVertex3f(ray[is].x[it][iray],ray[is].y[it][iray], ray[is].z[it][iray]); iflag=1; } else if (iflag) break; /*once good, now bad*/ } glEnd(); } } glEndList(); /*colored rays*/ glNewList(nhz*4+4,GL_COMPILE); for (is=0;is<ns;is++) { for (iray=0;iray<ray[is].nrays;iray++) { iflag=0; glBegin(GL_LINE_STRIP); for (it=0;it<ray[is].nseg[iray];it++) { if (fabs(ray[is].x[it][iray])<RADIUS && fabs(ray[is].y[it][iray])<RADIUS && fabs(ray[is].z[it][iray])<RADIUS) { tEmission( ray[is].v0[it][iray], 0.0, /*tmin*/ tmax, emission); glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,emission); glVertex3f( ray[is].x[it][iray], ray[is].y[it][iray], ray[is].z[it][iray]); iflag=1; } else if (iflag) break; /*once good, now bad*/ } glEnd(); } } glEndList(); } /************************************************************* Plot the wavefront if it is given. If the wffile does not contain effective data, ntris may be wild. In this case, do thing about the wavefront. *************************************************************/ if (wffp!=NULL) { fscanf(wffp,"%d = nwf2dump\n",&nwf); fprintf(stderr,"nwf2dump=%d\n",nwf); if (nwf>200) wffp=NULL; } if (wffp!=NULL) { emission[0]=1.0; emission[1]=1.0; emission[2]=0.0; emission[3]=1.0; wf=(Layer *)alloc1float(sizeof(Layer)*nwf); ntris=ealloc1int(sizeof(int)*nwf); for (iwf=0;iwf<nwf;iwf++) { if (1!=fscanf(wffp,"%d = ntris\n",&ntris[iwf])) { nwf=iwf; break; } if (ntris[iwf]==0) { nwf=iwf; break; } if (verbose) warn("ntris=%d of nwf=%d\n",ntris[iwf],nwf); wf[iwf].x=ealloc2float(3,ntris[iwf]); wf[iwf].y=ealloc2float(3,ntris[iwf]); wf[iwf].z=ealloc2float(3,ntris[iwf]); for (it=0;it<ntris[iwf];it++) { fscanf(wffp,"%f %f %f %f %f %f %f %f %f\n", wf[iwf].x[it], wf[iwf].y[it], wf[iwf].z[it], wf[iwf].x[it]+1,wf[iwf].y[it]+1,wf[iwf].z[it]+1, wf[iwf].x[it]+2,wf[iwf].y[it]+2,wf[iwf].z[it]+2); } fprintf(stderr,"Totally read in %d wavefront triangles\n",ntris[iwf]); for (it=0;it<ntris[iwf];it++) { for (iw=0;iw<3;iw++) { wf[iwf].x[it][iw]=((wf[iwf].x[it][iw]-xmin)/ (xmax-xmin)-0.5)*DIAMETER; wf[iwf].y[it][iw]=-((wf[iwf].y[it][iw]-ymin)/ (ymax-ymin)-0.5)*DIAMETER; wf[iwf].z[it][iw]=((wf[iwf].z[it][iw]-zmin)/ (zmax-zmin)-0.5)*DIAMETER; } } } fclose(wffp); fprintf(stderr,"Click right MB to get menu\n"); fprintf(stderr,"Click left MB and drag to rotate\n"); fprintf(stderr,"Press shift and push left MB to scale\n"); glNewList(nhz*4+6,GL_COMPILE); glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,emission); for (iwf=0;iwf<nwf;iwf++) { for (itri=0;itri<ntris[iwf];itri++) { glBegin(GL_LINE_LOOP); if (fabs(wf[iwf].x[itri][0])<RADIUS && fabs(wf[iwf].y[itri][0])<RADIUS && fabs(wf[iwf].z[itri][0])<RADIUS && fabs(wf[iwf].x[itri][1])<RADIUS && fabs(wf[iwf].y[itri][1])<RADIUS && fabs(wf[iwf].z[itri][1])<RADIUS && fabs(wf[iwf].x[itri][2])<RADIUS && fabs(wf[iwf].y[itri][2])<RADIUS && fabs(wf[iwf].z[itri][2])<RADIUS) { glVertex3f(wf[iwf].x[itri][0], wf[iwf].y[itri][0], wf[iwf].z[itri][0]); glVertex3f(wf[iwf].x[itri][1], wf[iwf].y[itri][1], wf[iwf].z[itri][1]); glVertex3f(wf[iwf].x[itri][2], wf[iwf].y[itri][2], wf[iwf].z[itri][2]); } else { fprintf(stderr,"warning: some triangles ignored\n"); glEnd(); break; } glEnd(); } } glEndList(); /*solid wavefronts*/ glNewList(nhz*4+7,GL_COMPILE); glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,emission); for (iwf=0;iwf<nwf;iwf++) { for (itri=0;itri<ntris[iwf];itri++) { glBegin(GL_TRIANGLE_STRIP); if (fabs(wf[iwf].x[itri][0])<RADIUS && fabs(wf[iwf].y[itri][0])<RADIUS && fabs(wf[iwf].z[itri][0])<RADIUS && fabs(wf[iwf].x[itri][1])<RADIUS && fabs(wf[iwf].y[itri][1])<RADIUS && fabs(wf[iwf].z[itri][1])<RADIUS && fabs(wf[iwf].x[itri][2])<RADIUS && fabs(wf[iwf].y[itri][2])<RADIUS && fabs(wf[iwf].z[itri][2])<RADIUS) { glVertex3f(wf[iwf].x[itri][0], wf[iwf].y[itri][0], wf[iwf].z[itri][0]); glVertex3f(wf[iwf].x[itri][1], wf[iwf].y[itri][1], wf[iwf].z[itri][1]); glVertex3f(wf[iwf].x[itri][2], wf[iwf].y[itri][2], wf[iwf].z[itri][2]); } else { fprintf(stderr,"warning: some triangles ignored\n"); glEnd(); break; } glEnd(); } } glEndList(); } /*surface traveltimes*/ if (sttfp!=NULL) { fscanf(sttfp,"%d = ntris\n",&ntr); fprintf(stderr,"ntr=%d\n",ntr); if (ntr>2000) sttfp=NULL; } if (sttfp!=NULL && ntr>0) { stt=ealloc3float(3,3,ntr); ttt=ealloc2float(3,ntr); tmax=0.0; tmin=1.0e+10; for (itri=0;itri<ntr;itri++) { fscanf(sttfp,"%f %f %f %f %f %f %f %f %f %f %f %f\n", &stt[itri][0][0], &stt[itri][0][1], &stt[itri][0][2], &ttt[itri][0], &stt[itri][1][0], &stt[itri][1][1], &stt[itri][1][2], &ttt[itri][1], &stt[itri][2][0], &stt[itri][2][1], &stt[itri][2][2], &ttt[itri][2]); tmax=MAX(tmax,ttt[itri][0]); tmax=MAX(tmax,ttt[itri][1]); tmax=MAX(tmax,ttt[itri][2]); tmin=MIN(tmin,ttt[itri][0]); tmin=MIN(tmin,ttt[itri][1]); tmin=MIN(tmin,ttt[itri][2]); stt[itri][0][0]=((stt[itri][0][0]-xmin)/ (xmax-xmin)-0.5)*DIAMETER; stt[itri][0][1]=-((stt[itri][0][1]-ymin)/ (ymax-ymin)-0.5)*DIAMETER; stt[itri][0][2]=((stt[itri][0][2]-zmin)/ (zmax-zmin)-0.5)*DIAMETER; stt[itri][1][0]=((stt[itri][1][0]-xmin)/ (xmax-xmin)-0.5)*DIAMETER; stt[itri][1][1]=-((stt[itri][1][1]-ymin)/ (ymax-ymin)-0.5)*DIAMETER; stt[itri][1][2]=((stt[itri][1][2]-zmin)/ (zmax-zmin)-0.5)*DIAMETER; stt[itri][2][0]=((stt[itri][2][0]-xmin)/ (xmax-xmin)-0.5)*DIAMETER; stt[itri][2][1]=-((stt[itri][2][1]-ymin)/ (ymax-ymin)-0.5)*DIAMETER; stt[itri][2][2]=((stt[itri][2][2]-zmin)/ (zmax-zmin)-0.5)*DIAMETER; } } tmax=MAX(tmax,tmin+0.01); glNewList(nhz*4+5,GL_COMPILE); for (itri=0;itri<ntr;itri++) { glBegin(GL_TRIANGLE_STRIP); tEmission(ttt[itri][0],tmin,tmax,emission); glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,emission); glVertex3fv(stt[itri][0]); tEmission(ttt[itri][1],tmin,tmax,emission); glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,emission); glVertex3fv(stt[itri][1]); tEmission(ttt[itri][2],tmin,tmax,emission); glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,emission); glVertex3fv(stt[itri][2]); glEnd(); } glEndList(); glutMainLoop(); return 0; }
/* the main program */ int main (int argc, char **argv) { double vp,vs,rho; double aspect,cdens; double scale,eps,delta,gamma; int fill; char *outpar=NULL; /* name of file holding output parfile */ FILE *outparfp=NULL; /* ... its file pointer */ /* Stiff2D *spar1, *spar2; */ Stiff2D *spar1; spar1=(Stiff2D*)emalloc(sizeof(Stiff2D)); /* spar2=(Stiff2D*)emalloc(sizeof(Stiff2D)); */ /* hook up getpar to handle the parameters */ initargs(argc,argv); requestdoc(0); if (!getpardouble("vp",&vp)) vp = 4.5; if (!getpardouble("vs",&vs)) vs = 2.53; if (!getpardouble("rho",&rho)) rho = 2.8; if (!getpardouble("aspect",&aspect)) aspect = 0.000001; if (!getpardouble("cdens",&cdens)) cdens = 0.0; if (!getparint("fill",&fill)) fill = 0; /*************** open par-file ******************/ if (!getparstring("outpar", &outpar)) outpar = "/dev/tty" ; outparfp = efopen(outpar, "w"); checkpars(); /*************** check input **********************/ if (fill !=0 && fill !=1 ) err(" \n wrong FILL parameter !! \n"); if(cdens !=0 && aspect==0) err(" \n wrong value for <aspect> "); if ( hudsonstiff(fill,vp,vs,rho,cdens,aspect,spar1) !=1 ) err(" ERROR in <hudsonstiff> \n "); fprintf(outparfp," \n ----------Hudson's crack model ----------\n \n"); fprintf(outparfp," vp=%g \t vs=%g \t rho=%g \n",vp,vs,rho); fprintf(outparfp," cdens=%g \t aspect=%g \t fill=%i \n\n", cdens,aspect,fill); fprintf(outparfp," \n ----------Hudson output ----------\n \n"); fprintf(outparfp," c11=%g \t c33=%g \n",spar1->a1111,spar1->a3333); fprintf(outparfp," c44=%g \t c55=%g \n",spar1->a2323,spar1->a1313); fprintf(outparfp," c13=%g \n\n",spar1->a1133); /* convert stiffness into density normalized stiffnesses */ scale=1./rho; spar1->a1111=scale*spar1->a1111; spar1->a3333=scale*spar1->a3333; spar1->a2323=scale*spar1->a2323; spar1->a1313=scale*spar1->a1313; spar1->a1133=scale*spar1->a1133; fprintf(outparfp," a11=%g \t a33=%g \n", spar1->a1111,spar1->a3333); fprintf(outparfp," a44=%g \t a55=%g \n", spar1->a2323,spar1->a1313); fprintf(outparfp," a13=%g \n\n",spar1->a1133); /* convert stiffnesses into generic Thomsen */ if (stiff2thomVTI (spar1->a3333, spar1->a1111, spar1->a1133, spar1->a1313, spar1-> a2323,&vp,&vs,&eps, &delta,&gamma) != 1) err(" ERROR in <stiff2thomVTI> "); fprintf(outparfp," vp0=%g \t vs0=%g \t rho=%g \n",vp,vs,rho); fprintf(outparfp," eps=%g \t delta=%g \t gamma=%g \n\n",eps,delta,gamma); /* compute thomsen of equivalent VTI medium */ spar1->a1212=spar1->a1313; if(stiff2tv(spar1,&vp,&vs,&eps,&delta,&gamma) != 1) err("\n ERROR in <stiff2tv> \n\n"); fprintf(outparfp," alpha=%g \t beta=%g \t rho=%g \n",vp,vs,rho); fprintf(outparfp," e(V)=%g \t d(V)=%g \t g(V)=%g \n\n",eps,delta,gamma); fclose(outparfp); return 1; }
/* the main program */ int main (int argc, char **argv) { /* int want,mindex=0; */ int want; float x,z,a1111,a3333,a1133,a1313,a1113,a3313,v_p,v_s; float a1212,a2323,a1223,rho; Model *m; Face *t; FaceAttributes *fa; char *mfile; FILE *mfp; want=1; /* hook up getpar to handle the parameters */ initargs(argc,argv); requestdoc(0); if (!getparstring("file",&mfile)) err("ERROR: No modelfile defined"); mfp = efopen(mfile,"r"); checkpars(); a1111=a3333=a1133=a1313=a1113=a3313=v_p=v_s=0; a1212=a1223=a2323=rho=0; /* read model */ m = readModel(mfp); fprintf (stderr," **********************************************\n"); fprintf (stderr," *********check stiffness coefficients*********\n"); fprintf (stderr," **********************************************\n\n"); do { want = 1; fprintf (stderr," Enter x-coordinate \n"); scanf ("%f", &x); fprintf (stderr," Enter z-coordinate \n"); scanf ("%f", &z); /* determine triangle containing point (x,z) */ if(x > m->ymax || x < m->ymin || z > m->xmax || z < m->xmin){ fprintf (stderr," Coordinate outside of model \n\n"); continue; } t = insideTriInModel(m,NULL,z,x); if ((fa=t->fa)!=NULL){ a1111 = fa->a1111; a3333 = fa->a3333; a1133 = fa->a1133; a1313 = fa->a1313; a1113 = fa->a1113; a3313 = fa->a3313; v_p = sqrt(a3333); v_s = sqrt(a1313); a1212 = fa->a1212; a1223 = fa->a1223; a2323 = fa->a2323; rho = fa->rho; /* mindex = fa->mindex; */ } fprintf(stderr,"\n ----Coordinates x=%g \t z=%g ----\n\n",x,z); /* fprintf(stderr,"\t\t mindex=%i \n ",mindex); */ fprintf(stderr,"\t\t a1111=%g \n",a1111); fprintf(stderr,"\t\t a3333=%g \n",a3333); fprintf(stderr,"\t\t a1133=%g \n",a1133); fprintf(stderr,"\t\t a1313=%g \n",a1313); fprintf(stderr,"\t\t a1113=%g \n",a1113); fprintf(stderr,"\t\t a3313=%g \n",a3313); fprintf(stderr,"\t\t a1212=%g \n",a1212); fprintf(stderr,"\t\t a1223=%g \n",a1223); fprintf(stderr,"\t\t a2323=%g \n",a2323); fprintf(stderr,"\t\t rho=%g \n",rho); fprintf(stderr,"\t\t v_p=%g \n",v_p); fprintf(stderr,"\t\t v_s=%g \n\n",v_s); fprintf (stderr," More checks type: 1 if yes, 0 if no \n"); scanf ("%i", &want); } while (want!=0); return 1; }
int main(int argc, char **argv) /*argc, argv - the arguments to the main() function*/ { int nt; /*number of time samples*/ int nz; /*number of migrated depth samples*/ int nx; /*number of midpoints (traces)*/ int ix; int iz; float dt; /*time sampling interval*/ float dx; /*spatial sampling interval*/ float dz; /*migrated depth sampling interval*/ float **data; /*input seismic data*/ complex **image; /*migrated image*/ float **rimage; /*migrated image*/ float **v; /*velocity model*/ FILE *vfp; char *vfile=""; /*name of velocity file*/ int verbose=1; char *tmpdir; /* directory path for tmp files*/ cwp_Bool istmpdir=cwp_false; /* true for user-given path*/ /******************************* Intialize *********************************************/ initargs(argc,argv); requestdoc(1); /********************************* Get parameters **************************************/ /*get info from first trace*/ if (!gettr(&tr)) err("can't get first trace"); /*fgettr: get a fixed-length segy trace from a file by file pointer*/ nt = tr.ns; /*nt*/ /*gettr: macro using fgettr to get a trace from stdin*/ if (!getparfloat("dt", &dt)) { /*dt*/ if (tr.dt) { dt = ((double) tr.dt)/1000000.0; } else {err("dt is not set");} } if (!getparfloat("dx", &dx)) { /*dx*/ if (tr.d2) { dx = tr.d2; } else { err("dx is not set"); } } /*get optional parameters*/ if (!getparint("nz",&nz)) err("nz must be specified"); if (!getparfloat("dz",&dz)) err("dz must be specified"); if (!getparstring("vfile", &vfile)) err("velocity file must be specified"); 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(); /**************************** Count trace number nx ******************************/ /* store traces and headers in tempfiles while getting a count */ if (STREQ(tmpdir,"")) { tracefp = etmpfile(); headerfp = etmpfile(); if (verbose) warn("using tmpfile() call"); } else { /* user-supplied tmpdir */ char directory[BUFSIZ]; strcpy(directory, tmpdir); strcpy(tracefile, temporary_filename(directory)); strcpy(headerfile, 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+"); headerfp = efopen(headerfile, "w+"); istmpdir=cwp_true; if (verbose) warn("putting temporary files in %s", directory); } nx = 0; do { ++nx; /*get the number of traces nx*/ efwrite(&tr,HDRBYTES,1,headerfp); efwrite(tr.data, FSIZE, nt, tracefp); } while (gettr(&tr)); erewind(tracefp); /*Set position of stream to the beginning*/ erewind(headerfp); /******************************************************************************************/ /*allocate memory*/ data = alloc2float(nt,nx); /*2D array nx by nt*/ image = alloc2complex(nz,nx); /*2D array nx by nz*/ rimage = alloc2float(nz,nx); /*2D array nx by nz*/ v= alloc2float(nz,nx); /*2D array, in Fortran the velocity model is nz by nx 2D array*/ /*in binary, it is actually 1D*/ /* load traces into the zero-offset array and close tmpfile */ efread(*data, FSIZE, nt*nx, tracefp); /*read traces to data*/ efclose(tracefp); /*load velicoty file*/ vfp=efopen(vfile,"r"); efread(v[0],FSIZE,nz*nx,vfp); /*load velocity*/ efclose(vfp); /***********************finish reading data*************************************************/ /* call pspi migration function*/ pspimig(data,image,v,nt,nx,nz,dt,dx,dz); /*get real part of image*/ for (iz=0;iz<nz;iz++){ for (ix=0;ix<nx;ix++){ rimage[ix][iz] = image[ix][iz].r; } } /* restore header fields and write output */ for (ix=0; ix<nx; ix++) { efread(&tr,HDRBYTES,1,headerfp); tr.ns = nz; tr.d1 = dz; memcpy( (void *) tr.data, (const void *) rimage[ix],nz*FSIZE); puttr(&tr); } /* Clean up */ efclose(headerfp); if (istmpdir) eremove(headerfile); if (istmpdir) eremove(tracefile); return(CWP_Exit()); }
int main(int argc, char **argv) { int nx,nz; float fx,fz,dx,dz,xs,zs,ex,ez,**v,**t,**a,**sg,**bet; FILE *vfp=stdin,*tfp=stdout,*afp,*sfp,*bfp; char *bfile="", *sfile="", *afile=""; /* hook up getpar to handle the parameters */ initargs(argc,argv); requestdoc(0); /* get required parameters */ if (!getparint("nx",&nx)) err("must specify nx!\n"); if (!getparint("nz",&nz)) err("must specify nz!\n"); if (!getparfloat("xs",&xs)) err("must specify xs!\n"); if (!getparfloat("zs",&zs)) err("must specify zs!\n"); /* get optional parameters */ if (!getparfloat("dx",&dx)) dx = 1.0; if (!getparfloat("fx",&fx)) fx = 0.0; if (!getparfloat("dz",&dz)) dz = 1.0; if (!getparfloat("fz",&fz)) fz = 0.0; if (!getparstring("sfile",&sfile)) sfile = "sfile"; if (!getparstring("bfile",&bfile)) bfile = "bfile"; if (!getparstring("afile",&afile)) afile = "afile"; checkpars(); if ((sfp=fopen(sfile,"w"))==NULL) err("cannot open sfile=%s",sfile); if ((bfp=fopen(bfile,"w"))==NULL) err("cannot open bfile=%s",bfile); if ((afp=fopen(afile,"w"))==NULL) err("cannot open afile=%s",afile); /* ensure source is in grid */ ex = fx+(nx-1)*dx; ez = fz+(nz-1)*dz; if (fx>xs || ex<xs || fz>zs || ez<zs) err("source lies outside of specified (x,z) grid\n"); /* allocate space */ v = alloc2float(nz,nx); t = alloc2float(nz,nx); sg = alloc2float(nz,nx); a = alloc2float(nz,nx); bet = alloc2float(nz,nx); /* read velocities */ fread(v[0],sizeof(float),nx*nz,vfp); /* compute times, angles, sigma, and betas */ eiktam(xs,zs,nz,dz,fz,nx,dx,fx,v,t,a,sg,bet); /* write first-arrival times */ fwrite(t[0],sizeof(float),nx*nz,tfp); /* write sigma */ fwrite(sg[0],sizeof(float),nx*nz,sfp); /* write angle */ fwrite(a[0],sizeof(float),nx*nz,afp); /* write beta */ fwrite(bet[0],sizeof(float),nx*nz,bfp); /* close files */ fclose(sfp); fclose(afp); fclose(bfp); /* free space */ free2float(v); free2float(t); free2float(a); free2float(sg); free2float(bet); return(CWP_Exit()); }
int main (int argc, char **argv) { int nt; /* number of time samples */ int ntau; /* number of migrated time samples */ int nx; /* number of midpoints */ int ik,ix,it,itau,itmig;/* loop counters */ int nxfft; /* fft size */ int nk; /* number of wave numbers */ int ntmig,nvmig; float dt; /* time sampling interval */ float ft; /* first time sample */ float dtau; /* migrated time sampling interval */ float ftau; /* first migrated time value */ float dk; /* wave number sampling interval */ float fk; /* first wave number */ float Q, ceil; /* quality factor, ceiling of amplitude */ float t,k; /* time,wave number */ float *tmig, *vmig; /* arrays of time, interval velocities */ float dx; /* spatial sampling interval */ float *vt; /* velocity v(t) */ float **p,**q; /* input, output data */ complex **cp,**cq; /* complex input,output */ char *vfile=""; /* name of file containing velocities */ int verbose=0; /* flag for echoing info */ char *tmpdir; /* directory path for tmp files */ cwp_Bool istmpdir=cwp_false;/* true for user-given path */ /* hook up getpar to handle the parameters */ initargs(argc,argv); requestdoc(1); /* get info from first trace */ if (!gettr(&tr)) err("can't get first trace"); nt = tr.ns; /* let user give dt and/or dx from command line */ if (!getparfloat("dt", &dt)) { if (tr.dt) { /* is dt field set? */ dt = ((double) tr.dt)/1000000.0; } else { /* dt not set, assume 4 ms */ dt = 0.004; warn("tr.dt not set, assuming dt=0.004"); } } if (!getparfloat("dx",&dx)) { if (tr.d2) { /* is d2 field set? */ dx = tr.d2; } else { dx = 1.0; warn("tr.d2 not set, assuming d2=1.0"); } } /* get optional parameters */ if (!getparfloat("ft",&ft)) ft = 0.0; if (!getparint("ntau",&ntau)) ntau = nt; CHECK_NT("ntau",ntau); if (!getparfloat("dtau",&dtau)) dtau = dt; if (!getparfloat("ftau",&ftau)) ftau = ft; if (!getparfloat("Q",&Q)) Q = 1.0e6; if (!getparfloat("ceil",&ceil)) ceil = 1.0e6; if (verbose)warn("Q=%f ceil=%f",Q,ceil); 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); /* store traces and headers in tempfiles while getting a count */ if (STREQ(tmpdir,"")) { tracefp = etmpfile(); headerfp = etmpfile(); if (verbose) warn("using tmpfile() call"); } else { /* user-supplied tmpdir */ char directory[BUFSIZ]; strcpy(directory, tmpdir); strcpy(tracefile, temporary_filename(directory)); strcpy(headerfile, 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+"); headerfp = efopen(headerfile, "w+"); istmpdir=cwp_true; if (verbose) warn("putting temporary files in %s", directory); } nx = 0; do { ++nx; efwrite(&tr,HDRBYTES,1,headerfp); efwrite(tr.data, FSIZE, nt, tracefp); } while (gettr(&tr)); erewind(tracefp); erewind(headerfp); /* determine wavenumber sampling (for real to complex FFT) */ nxfft = npfar(nx); nk = nxfft/2+1; dk = 2.0*PI/(nxfft*dx); fk = 0.0; /* allocate space */ p = alloc2float(nt,nxfft); q = alloc2float(ntau,nxfft); cp = alloc2complex(nt,nk); cq = alloc2complex(ntau,nk); /* load traces into the zero-offset array and close tmpfile */ efread(*p, FSIZE, nt*nx, tracefp); efclose(tracefp); /* determine velocity function v(t) */ vt = ealloc1float(ntau); if (!getparstring("vfile",&vfile)) { ntmig = countparval("tmig"); if (ntmig==0) ntmig = 1; tmig = ealloc1float(ntmig); if (!getparfloat("tmig",tmig)) tmig[0] = 0.0; nvmig = countparval("vmig"); if (nvmig==0) nvmig = 1; if (nvmig!=ntmig) err("number of tmig and vmig must be equal"); vmig = ealloc1float(nvmig); if (!getparfloat("vmig",vmig)) vmig[0] = 1500.0; for (itmig=1; itmig<ntmig; ++itmig) if (tmig[itmig]<=tmig[itmig-1]) err("tmig must increase monotonically"); for (it=0,t=0.0; it<ntau; ++it,t+=dt) intlin(ntmig,tmig,vmig,vmig[0],vmig[ntmig-1], 1,&t,&vt[it]); } else { if (fread(vt,sizeof(float),nt,fopen(vfile,"r"))!=nt) err("cannot read %d velocities from file %s",nt,vfile); } checkpars(); /* pad with zeros and Fourier transform x to k */ for (ix=nx; ix<nxfft; ix++) for (it=0; it<nt; it++) p[ix][it] = 0.0; pfa2rc(-1,2,nt,nxfft,p[0],cp[0]); /* migrate each wavenumber */ for (ik=0,k=fk; ik<nk; ik++,k+=dk) gazdagvt(k,nt,dt,ft,ntau,dtau,ftau,vt,cp[ik],cq[ik], Q, ceil); /* Fourier transform k to x (including FFT scaling) */ pfa2cr(1,2,ntau,nxfft,cq[0],q[0]); for (ix=0; ix<nx; ix++) for (itau=0; itau<ntau; itau++) q[ix][itau] /= nxfft; /* restore header fields and write output */ for (ix=0; ix<nx; ++ix) { efread(&tr,HDRBYTES,1,headerfp); tr.ns = ntau ; tr.dt = dtau * 1000000.0 ; tr.delrt = ftau * 1000.0 ; memcpy( (void *) tr.data, (const void *) q[ix],ntau*FSIZE); puttr(&tr); } /* Clean up */ efclose(headerfp); if (istmpdir) eremove(headerfile); if (istmpdir) eremove(tracefile); return(CWP_Exit()); }
int main (int argc, char **argv) { int nt; /* number of time samples */ int nz; /* number of migrated depth samples */ int nx; /* number of horizontal samples */ int nxshot; /* number of shots to be migrated */ /*int nxshot_orig;*/ /* first value of nxshot */ int iz,iw,ix,it; /* loop counters */ int igx; /* integerized gx value */ int ntfft; /* fft size */ int nw,truenw; /* number of wave numbers */ int dip=79; /* dip angle */ float sx,gx; /* x source and geophone location */ float gxmin=0.0,gxmax=0.0; /* x source and geophone location */ float min_sx_gx; /* min(sx,gx) */ float oldgx; /* old gx position */ /* float oldgxmin; */ /* old gx position */ /* float oldgxmax; */ /* old gx position */ float oldsx=0.0; /* old sx position */ int isx=0,nxo; /* index for source and geophone */ int oldisx=0; /* old value of source index */ int oldigx=0; /* old value of integerized gx value */ int ix1,ix2,ix3,ixshot; /* dummy index */ int lpad,rpad; /* padding on both sides of the migrated section */ float *wl=NULL,*wtmp=NULL; float fmax; float f1,f2,f3,f4; int nf1,nf2,nf3,nf4; int ntw; float dt=0.004,dz; /* time and depth sampling interval */ float dw; /* frequency sampling interval */ float fw; /* first frequency */ float w; /* frequency */ float dx; /* spatial sampling interval */ float **p=NULL; /* input data */ float **cresult=NULL; /* output result */ float v1; /* average velocity */ double kz2; float **v=NULL,**vp=NULL;/* pointers for the velocity profile */ complex cshift2; complex *wlsp=NULL; /* complex input,output */ complex **cp=NULL; /* ... */ complex **cp1=NULL; /* ... */ complex **cq=NULL; /* ... */ char *vfile=""; /* name of file containing velocities */ FILE *vfp=NULL; int verbose; /* verbose flag */ /* hook up getpar to handle the parameters */ initargs(argc,argv); requestdoc(1); /* get required parameters */ MUSTGETPARINT("nz",&nz); MUSTGETPARINT("nxo",&nxo); MUSTGETPARFLOAT("dz",&dz); MUSTGETPARSTRING("vfile",&vfile); MUSTGETPARINT("nxshot",&nxshot); /* get optional parameters */ if (!getparfloat("fmax",&fmax)) fmax = 25.0; if (!getparfloat("f1",&f1)) f1 = 10.0; if (!getparfloat("f2",&f2)) f2 = 20.0; if (!getparfloat("f3",&f3)) f3 = 40.0; if (!getparfloat("f4",&f4)) f4 = 50.0; if (!getparint("lpad",&lpad)) lpad=9999; if (!getparint("rpad",&rpad)) rpad=9999; if (!getparint("dip",&dip)) dip=79; if (!getparint("verbose",&verbose)) verbose = 0; /* allocating space */ cresult = alloc2float(nz,nxo); vp = alloc2float(nxo,nz); /* load velicoty file */ vfp=efopen(vfile,"r"); efread(vp[0],FSIZE,nz*nxo,vfp); efclose(vfp); /* zero out cresult array */ memset((void *) cresult[0], 0, nxo*nz*FSIZE); /* save value of nxshot */ /* nxshot_orig=nxshot; */ /* get info from first trace */ if (!gettr(&tr)) err("can't get first trace"); nt = tr.ns; get_sx_gx(&sx,&gx); min_sx_gx = MIN(sx,gx); sx = sx - min_sx_gx; gx = gx - min_sx_gx; /* let user give dt and/or dx from command line */ if (!getparfloat("dt", &dt)) { if (tr.dt) { /* is dt field set? */ dt = ((double) tr.dt)/1000000.0; } else { /* dt not set, assume 4 ms */ dt = 0.004; if(verbose) warn("tr.dt not set, assuming dt=0.004"); } } if (!getparfloat("dx",&dx)) { if (tr.d2) { /* is d2 field set? */ dx = tr.d2; } else { dx = 1.0; if(verbose) warn("tr.d2 not set, assuming d2=1.0"); } } checkpars(); oldisx=0; do { /* begin loop over shots */ /* determine frequency sampling interval*/ ntfft = npfar(nt); nw = ntfft/2+1; dw = 2.0*PI/(ntfft*dt); /* compute the index of the frequency to be migrated*/ fw=2.0*PI*f1; nf1=fw/dw+0.5; fw=2.0*PI*f2; nf2=fw/dw+0.5; fw=2.0*PI*f3; nf3=fw/dw+0.5; fw=2.0*PI*f4; nf4=fw/dw+0.5; /* the number of frequencies to migrated*/ truenw=nf4-nf1+1; fw=0.0+nf1*dw; if(verbose) warn("nf1=%d nf2=%d nf3=%d nf4=%d nw=%d",nf1,nf2,nf3,nf4,truenw); /* allocate space */ wl=alloc1float(ntfft); wlsp=alloc1complex(nw); /* generate the Ricker wavelet */ wtmp=ricker(fmax,dt,&ntw); /* zero out wl[] array */ memset((void *) wl, 0, ntfft*FSIZE); /* CHANGE BY CHRIS STOLK, Dec. 11, 2005 */ /* The next two lines are the old code, */ /* it is erroneous because the peak of */ /* the wavelet occurs at positive time */ /* instead of time zero. */ /* for(it=0;it<ntw;it++) wl[it]=wtmp[it]; */ /* New code: we put in the wavelet in a centered fashion */ for(it=0;it<ntw;it++) wl[(it-ntw/2+ntfft) % ntfft]=wtmp[it]; /* End of new code */ free1float(wtmp); /* fourier transform wl array */ pfarc(-1,ntfft,wl,wlsp); /* allocate space */ p = alloc2float(ntfft,nxo); cq = alloc2complex(nw,nxo); /* zero out p[][] array */ memset((void *) p[0], 0, ntfft*nxo*FSIZE); /* initialize a number of items before looping over traces */ nx = 0; igx=0; oldigx=0; oldsx=sx; oldgx=gx; /* oldgxmax=gxmax; */ /* oldgxmin=gxmin; */ do { /* begin looping over traces within a shot gather */ memcpy( (void *) p[igx], (const void *) tr.data,nt*FSIZE); /* get sx and gx */ get_sx_gx(&sx,&gx); sx = (sx - min_sx_gx); gx = (gx - min_sx_gx); igx = NINT(gx/dx); if (igx==oldigx) warn("repeated igx!!! check dx or scalco value!!!"); oldigx = igx; if(gxmin>gx)gxmin=gx; if(gxmax<gx)gxmax=gx; if(verbose) warn(" inside loop: min_sx_gx %f isx %d igx %d gx %f sx %f",min_sx_gx,isx,igx,gx,sx); /* sx, gx must increase monotonically */ if (!(oldsx <= sx) ) err("sx field must be monotonically increasing!"); if (!(oldgx <= gx) ) err("gx field must be monotonically increasing!"); ++nx; } while(gettr(&tr) && sx==oldsx); isx=NINT(oldsx/dx); ixshot=isx; if (isx==oldisx) warn("repeated isx!!! check dx or scalco value!!!"); oldisx=isx; if(verbose) { warn("sx %f, gx %f , gxmin %f gxmax %f nx %d",sx,gx,gxmin,gxmax, nx); warn("isx %d igx %d ixshot %d" ,isx,igx,ixshot); } /* transform the shot gather from time to frequency domain */ pfa2rc(1,1,ntfft,nxo,p[0],cq[0]); /* compute the most left and right index for the migrated */ /* section */ ix1=NINT(oldsx/dx); ix2=NINT(gxmin/dx); ix3=NINT(gxmax/dx); if(ix1>=ix3)ix3=ix1; if(ix1<=ix2)ix2=ix1; ix2-=lpad; ix3+=rpad; if(ix2<0)ix2=0; if(ix3>nxo-1)ix3=nxo-1; /* the total traces to be migrated */ nx=ix3-ix2+1; nw=truenw; /* allocate space for velocity profile within the aperature */ v=alloc2float(nx,nz); for(iz=0;iz<nz;iz++) for(ix=0;ix<nx;ix++) v[iz][ix]=vp[iz][ix+ix2]; /* allocate space */ cp = alloc2complex(nx,nw); cp1 = alloc2complex(nx,nw); /* transpose the frequency domain data from */ /* data[ix][iw] to data[iw][ix] and apply a */ /* Hamming at the same time */ for (ix=0; ix<nx; ++ix) { for (iw=0; iw<nw; iw++){ float tmpp=0.0,tmppp=0.0; if(iw>=(nf1-nf1)&&iw<=(nf2-nf1)){ tmpp=PI/(nf2-nf1); tmppp=tmpp*(iw-nf1)-PI; tmpp=0.54+0.46*cos(tmppp); cp[iw][ix]=crmul(cq[ix+ix2][iw+nf1],tmpp); } else { if(iw>=(nf3-nf1)&&iw<=(nf4-nf1)) { tmpp=PI/(nf4-nf3); tmppp=tmpp*(iw-nf3); tmpp=0.54+0.46*cos(tmppp); cp[iw][ix]=crmul(cq[ix+ix2][iw+nf1],tmpp); } else { cp[iw][ix]=cq[ix+ix2][iw+nf1]; } } cp1[iw][ix]=cmplx(0.0,0.0); } } for(iw=0;iw<nw;iw++){ cp1[iw][ixshot-ix2]=wlsp[iw+nf1]; } if(verbose) { warn("ixshot %d ix %d ix1 %d ix2 %d ix3 %d",ixshot,ix,ix1,ix2,ix3); warn("oldsx %f ",oldsx); } free2float(p); free2complex(cq); free1float(wl); free1complex(wlsp); /* loops over depth */ for(iz=0; iz<nz; ++iz) { /* the imaging condition */ for(ix=0; ix<nx; ++ix){ for(iw=0,w=fw;iw<nw;w+=dw,iw++){ complex tmp; float ratio=10.0; if(fabs(ix+ix2-ixshot)*dx<ratio*iz*dz) tmp=cmul(cp[iw][ix],cp1[iw][ix]); else tmp=cmplx(0.0,0.0); cresult[ix+ix2][iz]+=tmp.r/ntfft; } } /* get the average velocity */ v1=0.0; for(ix=0;ix<nx;++ix) v1+=v[iz][ix]/nx; /* compute time-invariant wavefield */ for(ix=0;ix<nx;++ix) { for(iw=0,w=fw;iw<nw;w+=dw,++iw) { kz2=-(1.0/v1)*w*dz; cshift2=cmplx(cos(kz2),sin(kz2)); cp[iw][ix]=cmul(cp[iw][ix],cshift2); cp1[iw][ix]=cmul(cp1[iw][ix],cshift2); } } /* wave-propagation using finite-difference method */ fdmig(cp, nx, nw,v[iz],fw,dw,dz,dx,dt,dip); fdmig(cp1,nx, nw,v[iz],fw,dw,dz,dx,dt,dip); /* apply thin lens term here */ for(ix=0;ix<nx;++ix) { for(iw=0,w=fw;iw<nw;w+=dw,++iw){ kz2=-(1.0/v[iz][ix]-1.0/v1)*w*dz; cshift2=cmplx(cos(kz2),sin(kz2)); cp[iw][ix]=cmul(cp[iw][ix],cshift2); cp1[iw][ix]=cmul(cp1[iw][ix],cshift2); } } } free2complex(cp); free2complex(cp1); free2float(v); --nxshot; } while(nxshot); /* restore header fields and write output */ for(ix=0; ix<nxo; ix++){ tr.ns = nz; tr.d1 = dz; tr.d2 = dx; tr.offset = 0; tr.cdp = tr.tracl = ix; memcpy( (void *) tr.data, (const void *) cresult[ix],nz*FSIZE); puttr(&tr); } return(CWP_Exit()); }
int main(int argc, char **argv) { float *rt=NULL; /* real trace */ float *amp=NULL; /* amplitude spectra */ float *ph=NULL; /* phase */ register complex *ct=NULL; /* complex time trace */ int nt; /* number of points on input trace */ int nfft; /* transform length */ int nf; /* number of frequencies in transform */ float dt; /* sampling interval in secs */ float d1; /* output sample interval in Hz */ int count=0; /* counter */ /* linear phase function */ float a; /* bias (intercept) of new phase */ float b; /* slope of linear phase function */ float c; /* new phase value */ float onfft; /* 1/nfft */ /* Initialize */ initargs(argc, argv); requestdoc(1); /* Get info from first trace */ if (!gettr(&tr)) err("can't get first trace"); nt = tr.ns; /* get parameters */ /* dt is used only to set output header value d1 */ if (!getparfloat("dt", &dt)) dt = ((double) tr.dt)/1000000.0; if (!dt) { dt = .004; warn("dt not set, assumed to be .002"); } /* linear phase paramter values */ if (!getparfloat("a", &a)) a = 0; if (!getparfloat("b", &b)) b = 180/PI; if (!getparfloat("c", &c)) c = 0.0; a *= PI/180.0; b *= PI/180.0; /* Set up pfa fft */ nfft = npfaro(nt, LOOKFAC * nt); if (nfft >= SU_NFLTS || nfft >= PFA_MAX) err("Padded nt=%d--too big", nfft); d1 = 1.0/(nfft*dt); nf = nfft/2 + 1; onfft = 1.0/nfft; checkpars(); /* Allocate space */ rt = ealloc1float(nfft); ct = ealloc1complex(nf); amp = ealloc1float(nf); ph = ealloc1float(nf); /* Main loop over traces */ count=0; do { register int i; /* Load trace into rt (zero-padded) */ memcpy((void *) rt, (const void *) &tr.data, nt*FSIZE); memset((void *) (rt + nt), (int) '\0', (nfft-nt)*FSIZE); /* FFT */ pfarc(1, nfft, rt, ct); for (i = 0; i < nf; ++i) { amp[i] = AMPSP(ct[i]); ph[i] = a+b*atan2(ct[i].i,ct[i].r)+c*i; } for (i = 0; i < nf; ++i) { ct[i].r = amp[i]*cos(ph[i]); ct[i].i = amp[i]*sin(ph[i]); } pfacr(-1,nfft,ct,rt); for (i = 0; i < nt; ++i) rt[i]*=onfft; memcpy((void *) tr.data, (const void *) rt, nt*FSIZE); puttr(&tr); } while (gettr(&tr)); return(CWP_Exit()); }
int main( int argc, char *argv[] ) { int nx; int fbt; int nt; float *stacked=NULL; int *nnz=NULL; int itr=0; initargs(argc, argv); requestdoc(1); if (!getparint("nx", &nx)) nx = 51; if( !ISODD(nx) ) { nx++; warn(" nx has been changed to %d to be odd.\n",nx); } if (!getparint("fbt", &fbt)) fbt = 60; checkpars(); /* Get info from first trace */ if (!gettr(&tr)) err("can't get first trace"); nt = tr.ns; stacked = ealloc1float(fbt); nnz = ealloc1int(fbt); memset((void *) nnz, (int) '\0', fbt*ISIZE); memset((void *) stacked, (int) '\0', fbt*FSIZE); /* read nx traces and stack them */ /* The first trace is already read */ { int i,it; float **tr_b; char **hdr_b; int NXP2=nx/2; short shft,scaler; /* ramp on read the first nx traces and create stack */ tr_b = ealloc2float(nt,nx); hdr_b = (char**)ealloc2(HDRBYTES,nx,sizeof(char)); memcpy((void *) hdr_b[0], (const void *) &tr, HDRBYTES); memcpy((void *) tr_b[0], (const void *) &tr.data, nt*FSIZE); for(i=1;i<nx;i++) { gettr(&tr); memcpy((void *) hdr_b[i], (const void *) &tr, HDRBYTES); memcpy((void *) tr_b[i], (const void *) &tr.data, nt*FSIZE); } for(i=0;i<nx;i++) for(it=0;it<fbt;it++) stacked[it] += tr_b[i][it]; for(it=0;it<fbt;it++) stacked[it] /=(float)nx; /* filter and write out the first nx/2 +1 traces */ for(i=0;i<NXP2+1;i++) { memcpy((void *) &tr, (const void *) hdr_b[i], HDRBYTES); memcpy((void *) tr.data, (const void *) tr_b[i], nt*FSIZE); remove_fb(tr.data,stacked,fbt,&scaler,&shft); tr.trwf = scaler; tr.grnors = shft; puttr(&tr); ++itr; } /* do the rest of the traces */ gettr(&tr); do { /* Update the stacked trace - remove old */ for(it=0;it<fbt;it++) stacked[it] -= tr_b[0][it]/(float)nx; /* Bump up the storage arrays */ /* This is not very efficient , but good enough */ {int ib; for(ib=1;ib<nx;ib++) { memcpy((void *) hdr_b[ib-1], (const void *) hdr_b[ib], HDRBYTES); memcpy((void *) tr_b[ib-1], (const void *) tr_b[ib], nt*FSIZE); } } /* Store the new trace */ memcpy((void *) hdr_b[nx-1], (const void *) &tr, HDRBYTES); memcpy((void *) tr_b[nx-1], (const void *) &tr.data, nt*FSIZE); /* Update the stacked array - add new */ for(it=0;it<fbt;it++) stacked[it] += tr_b[nx-1][it]/(float)nx; /* Filter and write out the middle one NXP2+1 */ memcpy((void *) &tr, (const void *) hdr_b[NXP2], HDRBYTES); memcpy((void *) tr.data, (const void *) tr_b[NXP2], nt*FSIZE); remove_fb(tr.data,stacked,fbt,&scaler,&shft); tr.trwf = scaler; tr.grnors = shft; puttr(&tr); ++itr; } while(gettr(&tr)); /* Ramp out - write ot the rest of the traces */ /* filter and write out the last nx/2 traces */ for(i=NXP2+1;i<nx;i++) { memcpy((void *) &tr, (const void *) hdr_b[i], HDRBYTES); memcpy((void *) tr.data, (const void *) tr_b[i], nt*FSIZE); remove_fb(tr.data,stacked,fbt,&scaler,&shft); tr.trwf = scaler; tr.grnors = shft; puttr(&tr); itr++; } } free1float(stacked); free1int(nnz); return EXIT_SUCCESS; }
int main (int argc, char **argv) { int n1,n2,nz,iz,verbose,looping,nTic1,nTic2,width,height,interp; float d1,f1,d2,f2,*z, clip,bclip,wclip,white,wfrac, perc,bperc,wperc,*temp, bhue,whue,sat,bright, x1beg,x2beg,x1end,x2end, x1min,x1max,x2min,x2max, fframe,dframe; char *label1="",*label2="",*format="",*windowtitle="", *labelFont="",*titleFont="", *axesColor="",*gridColor="",*titleColor="", *style="normal",*grid1="none",*grid2="none", *cmap; ClientData cd; XrmValue from,to; Widget toplevel,axes; XtAppContext ac; Display *dpy; Window win; Arg args[98]; int nargs; int scr; unsigned int depth; /* initialize getpar */ initargs(argc,argv); requestdoc(1); /* get parameters describing colormaps */ cmap = "gray"; getparstring("cmap",&cmap); if (STREQ("saturation",cmap)) cmap = "sat"; bhue = 0; getparfloat("bhue",&bhue); bhue /= 360.0; whue = 240; getparfloat("whue",&whue); whue /= 360.0; sat = 1.0; getparfloat("sat",&sat); if (sat<0.0 || sat>1.0) err("sat must be in range [0,1]!\n"); bright = 1.0; getparfloat("bright",&bright); if (bright<0.0 || bright>1.0) err("bright must be in range [0,1]!\n"); /* get parameters describing 1st dimension sampling */ if (!getparint("n1",&n1)) err("Must specify number of samples in 1st dimension!\n"); if (!getparfloat("d1",&d1)) d1 = 1.0; if (!getparfloat("f1",&f1)) f1 = 0.0; x1min = (d1>0.0)?f1:f1+(n1-1)*d1; x1max = (d1<0.0)?f1:f1+(n1-1)*d1; if (!getparfloat("x1beg",&x1beg)) x1beg = x1min; if (!getparfloat("x1end",&x1end)) x1end = x1max; /* get parameters describing 2nd dimension sampling */ if (!getparint("n2",&n2)) err("Must specify number of samples in 2nd dimension!\n"); if (!getparfloat("d2",&d2)) d2 = 1.0; if (!getparfloat("f2",&f2)) f2 = 0.0; x2min = (d2>0.0)?f2:f2+(n2-1)*d2; x2max = (d2<0.0)?f2:f2+(n2-1)*d2; if (!getparfloat("x2beg",&x2beg)) x2beg = x2min; if (!getparfloat("x2end",&x2end)) x2end = x2max; /* read first frame of float data */ nz = n1*n2; z = ealloc1float(nz); if (fread(z,sizeof(float),nz,stdin)!=nz) err("error reading input file"); /* if necessary, determine clips from percentiles */ if (getparfloat("clip",&clip)) { bclip = clip; wclip = -clip; } if ((!getparfloat("bclip",&bclip) || !getparfloat("wclip",&wclip)) && !getparfloat("clip",&clip)) { perc = 100.0; getparfloat("perc",&perc); temp = ealloc1float(nz); for (iz=0; iz<nz; iz++) temp[iz] = z[iz]; if (!getparfloat("bclip",&bclip)) { bperc = perc; getparfloat("bperc",&bperc); iz = (nz*bperc/100.0); if (iz<0) iz = 0; if (iz>nz-1) iz = nz-1; qkfind(iz,nz,temp); bclip = temp[iz]; } if (!getparfloat("wclip",&wclip)) { wperc = 100.0-perc; getparfloat("wperc",&wperc); iz = (nz*wperc/100.0); if (iz<0) iz = 0; if (iz>nz-1) iz = nz-1; qkfind(iz,nz,temp); wclip = temp[iz]; } free1float(temp); } if (!getparfloat("white",&white)) white = (bclip+wclip)/2.0; if (!getparint("verbose",&verbose)) verbose = 1; if (!getparint("sleep",&cd.sleep)) cd.sleep=0 ; if (!getparint("loop",&looping)) looping = 0; if (verbose) { if(STREQ(cmap,"sat") || STREQ(cmap,"customsat")) { warn("bclip=%g wclip=%g white=%g",bclip,wclip,white); } else { warn("bclip=%g wclip=%g",bclip,wclip); } } wfrac = (bclip!=wclip) ? (bclip-white)/(bclip-wclip) : 1.0; /* initialize toolkit and set toplevel parameters */ toplevel = XtAppInitialize(&ac,"XMovie_XAPP_DEF",NULL,0,&argc,argv,NULL,NULL,0); dpy = XtDisplay(toplevel); nargs = 0; if (getparstring("windowtitle",&windowtitle)) {XtSetArg(args[nargs],XtNtitle,windowtitle); nargs++;} if (getparstring("windowtitle",&windowtitle)) {XtSetArg(args[nargs],XtNiconName,windowtitle); nargs++;} if (getparint("width",&width)) {XtSetArg(args[nargs],XtNwidth,width); nargs++;} if (getparint("height",&height)) {XtSetArg(args[nargs],XtNheight,height); nargs++;} XtSetArg(args[nargs],XtNinput,TRUE);nargs++; XtSetValues(toplevel,args,nargs); /* if necessary, make private colormap */ win = XRootWindowOfScreen(XtScreen(toplevel)); nargs = 0; scr=DefaultScreen(dpy); depth=(unsigned int)DefaultDepth(dpy,scr); if (depth<=8) { if (STREQ(cmap,"gray")) { Colormap cm=XtcwpCreateGrayColormap(dpy,win); XtSetArg(args[nargs],XtNcolormap,cm); nargs++; } else if (STREQ(cmap,"hue")) { Colormap cm=XtcwpCreateHueColormap(dpy,win, bhue,whue,sat,bright); XtSetArg(args[nargs],XtNcolormap,cm); nargs++; } else if (STREQ(cmap,"sat")) { Colormap cm=XtcwpCreateSatColormap(dpy,win, bhue,whue,wfrac,bright); XtSetArg(args[nargs],XtNcolormap,cm); nargs++; } XtSetValues(toplevel,args,nargs); } /* create axes and set axes parameters */ axes = XtCreateManagedWidget("axes",xtcwpAxesWidgetClass, toplevel,NULL,0); nargs = 0; if (getparstring("grid1",&grid1)) { from.addr = (char *)grid1; XtConvertAndStore(axes,XtRString,&from,XtcwpRAxesGrid,&to); if (to.addr) XtSetArg(args[nargs],XtNgrid1,*((int*)to.addr)); nargs++; } if (getparstring("grid2",&grid2)) { from.addr = (char *)grid2; XtConvertAndStore(axes,XtRString,&from,XtcwpRAxesGrid,&to); if (to.addr) XtSetArg(args[nargs],XtNgrid2,*((int*)to.addr)); nargs++; } if (getparint("nTic1",&nTic1)) {XtSetArg(args[nargs],XtNnTic1,nTic1); nargs++;} if (getparint("nTic2",&nTic2)) {XtSetArg(args[nargs],XtNnTic2,nTic2); nargs++;} if (getparstring("label1",&label1)) {XtSetArg(args[nargs],XtNlabel1,label1); nargs++;} if (getparstring("label2",&label2)) {XtSetArg(args[nargs],XtNlabel2,label2); nargs++;} if (getparstring("title",&format)) {XtSetArg(args[nargs],XtNtitle,format); nargs++;} if (getparstring("style",&style)) { from.size = (unsigned int) strlen(style); from.addr = (char *)style; XtConvertAndStore(axes,XtRString,&from,XtcwpRAxesStyle,&to); if (to.addr) XtSetArg(args[nargs],XtNstyle,*((int*)to.addr)); nargs++; } if (getparstring("axesColor",&axesColor)) { from.addr = (char *)axesColor; XtConvertAndStore(axes,XtRString,&from,XtRPixel,&to); if (to.addr) XtSetArg(args[nargs],XtNaxesColor, *((unsigned long*)to.addr)); nargs++; } if (getparstring("gridColor",&gridColor)) { from.addr = (char *)gridColor; XtConvertAndStore(axes,XtRString,&from,XtRPixel,&to); if (to.addr) XtSetArg(args[nargs],XtNgridColor, *((unsigned long*)to.addr)); nargs++; } if (getparstring("titleColor",&titleColor)) { from.addr = (char *)titleColor; XtConvertAndStore(axes,XtRString,&from,XtRPixel,&to); if (to.addr) XtSetArg(args[nargs],XtNtitleColor, *((unsigned long*)to.addr)); nargs++; } if (getparstring("labelFont",&labelFont)) { from.addr = (char *)labelFont; XtConvertAndStore(axes,XtRString,&from,XtRFont,&to); if (to.addr) XtSetArg(args[nargs],XtNlabelFont, *((Font*)to.addr)); nargs++; } if (getparstring("titleFont",&titleFont)) { from.addr = (char *)titleFont; XtConvertAndStore(axes,XtRString,&from,XtRFont,&to); if (to.addr) XtSetArg(args[nargs],XtNtitleFont, *((Font*)to.addr)); nargs++; } XtSetValues(axes,args,nargs); x1beg = x1min; getparfloat("x1beg",&x1beg); x1end = x1max; getparfloat("x1end",&x1end); x2beg = x2min; getparfloat("x2beg",&x2beg); x2end = x2max; getparfloat("x2end",&x2end); adjustAxesValues(n1,d1,f1,n2,d2,f2,&x1beg,&x1end,&x2beg,&x2end); XtcwpSetAxesValues(axes,x1beg,x1end,x2beg,x2end); /* frame sampling */ if (!getparfloat("fframe",&fframe)) fframe = 1.0; if (!getparfloat("dframe",&dframe)) dframe = 1.0; /* interpolation */ if (!getparint("interp",&interp)) interp = 1; /* initial display mode: cont or step */ if (!getparint("idm", &displayMode)) displayMode = DM_CONT; checkpars(); /* initialize client data */ cd.n1 = n1; cd.d1 = d1; cd.f1 = f1; cd.n2 = n2; cd.d2 = d2; cd.f2 = f2; cd.floats = z; cd.fmin = bclip; cd.fmax = wclip; cd.bmin = (unsigned char) (XtcwpGetFirstPixel(dpy)); cd.bmax = (unsigned char) (XtcwpGetLastPixel(dpy)); if(cd.bmax==0)cd.bmax=255; warn("bmin=%d bmax=%d",cd.bmin,cd.bmax); cd.x1bega = x1beg; cd.x1enda = x1end; cd.x2bega = x2beg; cd.x2enda = x2end; cd.abytes = NULL; cd.bbytes = NULL; cd.image = NULL; cd.exposed = 0; cd.noframes = 1; cd.axes = axes; cd.looping = looping; cd.frame = NULL; cd.format = format; cd.iframe = 0; cd.fframe = fframe; cd.dframe = dframe; cd.interp = interp; cd.forward = 1; cd.ac = ac; /* adjust axes title if formatted */ if (strchr(cd.format,'%') && !strstr(cd.format,"%%")) { sprintf(cd.title,cd.format,cd.fframe+cd.iframe*cd.dframe); XtVaSetValues(cd.axes,XtNtitle,cd.title,NULL); } /* add work procedure */ cd.wpid = XtAppAddWorkProc(ac,(XtWorkProc) readFrame,&cd); /* add callbacks to axes widget */ XtAddCallback(axes,XtNresizeCallback,(XtCallbackProc) resizeCB,&cd); XtAddCallback(axes,XtNexposeCallback,(XtCallbackProc) exposeCB,&cd); XtAddCallback(axes,XtNinputCallback,(XtCallbackProc) inputCB,&cd); /* add Button2 translation for reversing the movie */ XtOverrideTranslations(axes, XtParseTranslationTable("<Btn2Up>: input()")); /* add Button3 translation for pausing the movie */ XtOverrideTranslations(axes, XtParseTranslationTable("<Btn3Up>: input()")); /* set up keypress */ XtAddEventHandler(axes, KeyPress, FALSE, (XtEventHandler) key_pressed, &cd); /* realize everything */ XtRealizeWidget(toplevel); /* go */ XtAppMainLoop(ac); return EXIT_SUCCESS; }
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) { char *tmpdir ; /* directory path for tmp files */ cwp_Bool istmpdir=cwp_false ; /* true for user given path */ float *hedr ; /* the headers */ float *data ; /* the data */ int nt ; /* number of trace samples */ float dt ; /* sample interval, sec */ float delrt ; /* delay recording time, sec */ cwp_String key[SU_NKEYS] ; /* array of keywords */ cwp_String type ; /* key string type */ int nkeys ; /* number of keywords */ int ikey,ntr = 0 ; /* counters */ int num ; /* number of traces to dump */ int numtr = 4 ; /* number of traces to dump */ int hpf ; /* header print format */ /* Initialize */ initargs(argc, argv) ; requestdoc(1) ; /* 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); /* Get values from first trace */ if (!gettr(&tr)) err("can't get first trace"); nt = (int) tr.ns ; /* Get nt */ dt = ((double) tr.dt)/1000000.0 ; /* microsecs to secs */ if (!dt) getparfloat("dt", &dt) ; if (!dt) MUSTGETPARFLOAT("dt", &dt) ; delrt = ((double) tr.delrt)/1000.0 ; /* millisecs to secs */ /* Get parameters */ if (getparint ("num", &num)) numtr = num ; if ((nkeys=countparval("key"))!=0) getparstringarray("key",key) ; hedr = ealloc1float(nkeys*numtr) ; /* make space for headers */ if (!getparint ("hpf", &hpf)) hpf = 0 ; checkpars(); /* Store traces, headers in tempfiles */ if (STREQ(tmpdir,"")) { tracefp = etmpfile(); headerfp = etmpfile(); do { ++ntr; efwrite(&tr, HDRBYTES, 1, headerfp); efwrite(tr.data, FSIZE, nt, tracefp); /* Get header values */ for (ikey=0; ikey<nkeys; ++ikey) { Value val; float fval; gethdval(&tr, key[ikey], &val) ; type = hdtype(key[ikey]) ; fval = vtof(type,val) ; hedr[(ntr-1)*nkeys+ikey] = fval ; } } while (ntr<numtr && gettr(&tr)) ; } else /* user-supplied tmpdir */ { char directory[BUFSIZ]; strcpy(directory, tmpdir); strcpy(tracefile, temporary_filename(directory)); strcpy(headerfile, temporary_filename(directory)); /* Handle user interrupts */ signal(SIGINT, (void (*) (int)) closefiles); signal(SIGQUIT, (void (*) (int)) closefiles); signal(SIGHUP, (void (*) (int)) closefiles); signal(SIGTERM, (void (*) (int)) closefiles); tracefp = efopen(tracefile, "w+"); headerfp = efopen(headerfile, "w+"); istmpdir=cwp_true; do { ++ntr; efwrite(&tr, HDRBYTES, 1, headerfp); efwrite(tr.data, FSIZE, nt, tracefp); /* Get header values */ for (ikey=0; ikey<nkeys; ++ikey) { Value val; float fval; gethdval(&tr, key[ikey], &val) ; type = hdtype(key[ikey]) ; fval = vtof(type,val) ; hedr[(ntr-1)*nkeys+ikey] = fval ; } } while (ntr<numtr && gettr(&tr)) ; } /* Rewind after read, allocate space */ erewind(tracefp); erewind(headerfp); data = ealloc1float(nt*ntr); /* Load traces into data and close tmpfile */ efread(data, FSIZE, nt*ntr, tracefp); efclose(tracefp); if (istmpdir) eremove(tracefile); rewind(headerfp); rewind(tracefp); /* Do trace work */ dump(data, dt, hedr, key, delrt, nkeys, ntr, nt, hpf) ; /* close */ efclose(headerfp); if (istmpdir) eremove(headerfile); free1(hedr) ; free1(data) ; return(CWP_Exit()) ; }
/* the main program */ int main (int argc, char **argv) { int nx,nz,ix,iz; float dx,fx,dz,fz,x,z,xmin,xmax,zmin,zmax; float **a1111,**a3333,**a1133,**a1313,**a1113; float **a1212,**a2323,**a1223,**rho; float **a3313; Tri *t; TriAttributes *ta; Model *m; char *a1111file, *a3333file, *a1133file; char *a1313file, *a1113file, *a3313file; char *a1212file, *a1223file, *a2323file; char *rhofile; FILE *a1111fp=NULL, *a3333fp=NULL, *a1133fp=NULL; FILE *a1313fp=NULL, *a1113fp=NULL, *a3313fp=NULL; FILE *a1212fp=NULL, *a1223fp=NULL, *a2323fp=NULL; FILE *rhofp=NULL; /* hook up getpar to handle the parameters */ initargs(argc,argv); requestdoc(0); /* get required parameters */ if (!getparint("nx",&nx)) err("must specify nx!"); if (!getparint("nz",&nz)) err("must specify nz!"); /* get optional parameters */ if (!getparfloat("dx",&dx)) dx = 1.0; if (!getparfloat("dz",&dz)) dz = 1.0; if (!getparfloat("fx",&fx)) fx = 0.0; if (!getparfloat("fz",&fz)) fz = 0.0; if(getparstring("a1111file",&a1111file)) a1111fp = efopen(a1111file,"w"); else a1111fp = efopen("a1111.bin","w"); if(getparstring("a3333file",&a3333file)) a3333fp = efopen(a3333file,"w"); else a3333fp = efopen("a3333.bin","w"); if(getparstring("a1133file",&a1133file)) a1133fp = efopen(a1133file,"w"); else a1133fp = efopen("a1133.bin","w"); if(getparstring("a1313file",&a1313file)) a1313fp = efopen(a1313file,"w"); else a1313fp = efopen("a1313.bin","w"); if(getparstring("a1113file",&a1113file)) a1113fp = efopen(a1113file,"w"); else a1113fp = efopen("a1113.bin","w"); if(getparstring("a3313file",&a3313file)) a3313fp = efopen(a3313file,"w"); else a3313fp = efopen("a3313.bin","w"); if(getparstring("a1212file",&a1212file)) a1212fp = efopen(a1212file,"w"); else a1212fp = efopen("a1212.bin","w"); if(getparstring("a2323file",&a2323file)) a2323fp = efopen(a2323file,"w"); else a2323fp = efopen("a2323.bin","w"); if(getparstring("a1223file",&a1223file)) a1223fp = efopen(a1223file,"w"); else a1223fp = efopen("a1223.bin","w"); if(getparstring("rhofile",&rhofile)) rhofp = efopen(rhofile,"w"); else rhofp = efopen("rho.bin","w"); checkpars(); /* read input triangulated sloth model */ m = readModel(stdin); /* determine min and max x and z coordinates */ xmin = m->ymin; xmax = m->ymax; zmin = m->xmin; zmax = m->xmax; /* allocate space for uniformly sampled stiffnesses */ a1111 = ealloc2float(nz,nx); a3333 = ealloc2float(nz,nx); a1133 = ealloc2float(nz,nx); a1313 = ealloc2float(nz,nx); a1113 = ealloc2float(nz,nx); a3313 = ealloc2float(nz,nx); a1212 = ealloc2float(nz,nx); a1223 = ealloc2float(nz,nx); a2323 = ealloc2float(nz,nx); rho = ealloc2float(nz,nx); /* loop over all samples */ for (ix=0,x=fx,t=NULL; ix<nx; ++ix,x+=dx) { if (x<xmin || x>xmax) err("x=%g must be between xmin=%g and xmax=%g", x,xmin,xmax); for (iz=0,z=fz; iz<nz; ++iz,z+=dz) { if (z<zmin || z>zmax) err("z=%g must be between zmin=%g and zmax=%g", z,zmin,zmax); t = insideTriInModel(m,t,z,x); ta = (TriAttributes*)t->fa; a1111[ix][iz] = ta->a1111; a3333[ix][iz] = ta->a3333; a1133[ix][iz] = ta->a1133; a1313[ix][iz] = ta->a1313; a1113[ix][iz] = ta->a1113; a3313[ix][iz] = ta->a3313; a1212[ix][iz] = ta->a1212; a2323[ix][iz] = ta->a2323; a1223[ix][iz] = ta->a1223; rho[ix][iz] = ta->rho; } } /* write uniformly sampled sloth */ fwrite(a1111[0],sizeof(float),nz*nx,a1111fp); fwrite(a3333[0],sizeof(float),nz*nx,a3333fp); fwrite(a1133[0],sizeof(float),nz*nx,a1133fp); fwrite(a1313[0],sizeof(float),nz*nx,a1313fp); fwrite(a1113[0],sizeof(float),nz*nx,a1113fp); fwrite(a3313[0],sizeof(float),nz*nx,a3313fp); fwrite(a1212[0],sizeof(float),nz*nx,a1212fp); fwrite(a2323[0],sizeof(float),nz*nx,a2323fp); fwrite(a1223[0],sizeof(float),nz*nx,a1223fp); fwrite(rho[0],sizeof(float),nz*nx,rhofp); return 1; }
int main(int argc, char **argv) { int nv; /* number of velocities */ float dv; /* velocity sampling interval */ float fv; /* first velocity */ float anis1; /* quartic term, or numerator of an extended one */ float anis2; /* inside denominator of an extended quartic term */ int iv; /* velocity index */ int dtratio; /* ratio of output to input sampling intervals */ int nsmooth; /* length in samples of num and den smoothing window */ int nt; /* number of time samples per input trace */ float dt; /* time sampling interval for input traces */ float ft; /* time of first sample input and output */ int ntout; /* number of output samples */ float dtout; /* time sampling interval for output traces */ int it; /* input time sample index */ int itout; /* output time sample index */ int is; /* time sample index for smoothing window */ int ismin; /* lower limit on is */ int ismax; /* upper limit on is */ int itmute; /* time sample index of first sample not muted */ int iti; /* time sample index used in linear interpolation */ float ti; /* normalized time for linear interpolation */ float frac; /* fractional distance from sample in interpolation */ int gottrace; /* =1 if an input trace was read */ int verbose; /* =1 for diagnostic print */ long cdp; /* cdp from current input trace header */ long cdpprev; /* cdp from previous input trace header */ float smute; /* NMO stretch mute factor */ float offset; /* offset from input trace header */ float offovs; /* (offset/velocity)^2 */ float offan=0.0; /* shift of tnmo due to anisotropy */ float tn; /* time after NMO */ float tnmute; /* mute time after NMO */ float nsum; /* semblance numerator sum */ float dsum; /* semblance denominator sum */ float v; /* velocity */ float temp; /* temporary scalar */ float *data; /* array[nt] of input trace */ float *sem; /* array[ntout] of semblance */ float **num; /* array[nv][nt] of semblance numerators */ float **den; /* array[nv][nt] of semblance denominators */ float **nnz; /* array[nv][nt] for counting non-zero samples */ float pwr; /* power of semblance */ /* hook up getpar */ initargs(argc,argv); requestdoc(0); /* get parameters from the first trace */ if (!gettr(&tr)) err("can't get first trace"); nt = tr.ns; dt = ((double) tr.dt)/1000000.0; ft = tr.delrt/1000.0; cdp = tr.cdp; offset = tr.offset; /* get optional parameters */ if (!getparint("nv",&nv)) nv = 50; if (!getparfloat("dv",&dv)) dv = 50.0; if (!getparfloat("fv",&fv)) fv = 1500.0; if (!getparfloat("anis1",&anis1)) anis1 = 0.0; if (!getparfloat("anis2",&anis2)) anis2 = 0.0; if (!getparfloat("smute",&smute)) smute = 1.5; if (smute<=1.0) err("smute must be greater than 1.0"); if (!getparint("dtratio",&dtratio)) dtratio = 5; if (!getparint("nsmooth",&nsmooth)) nsmooth = dtratio*2+1; if (!getparint("verbose",&verbose)) verbose = 0; if (!getparfloat("pwr",&pwr)) pwr = 1.0; if (pwr < 0.0) err("we are not looking for noise: pwr < 0"); if (pwr == 0.0) err("we are creating an all-white semblance: pwr = 0"); checkpars(); /* determine output sampling */ ntout = 1+(nt-1)/dtratio; CHECK_NT("ntout",ntout); dtout = dt*dtratio; if (verbose) { fprintf(stderr, "\tnumber of output time samples is %d\n",ntout); fprintf(stderr, "\toutput time sampling interval is %g\n",dtout); fprintf(stderr, "\toutput time of first sample is %g\n",ft); } /* allocate memory */ data = ealloc1float(nt); num = ealloc2float(nt,nv); den = ealloc2float(nt,nv); nnz = ealloc2float(nt,nv); sem = ealloc1float(ntout); /* zero accumulators */ for (iv=0; iv<nv; ++iv) { for (it=0; it<nt; ++it) { num[iv][it] = 0.0; den[iv][it] = 0.0; nnz[iv][it] = 0.0; } } /* initialize flag */ gottrace = 1; /* remember previous cdp */ cdpprev = tr.cdp; /* loop over input traces */ while (gottrace|(~gottrace)/*True*/) { /* middle exit loop */ /* if got a trace */ if (gottrace) { /* determine offset and cdp */ offset = tr.offset; cdp = tr.cdp; if ((1.0 + offset*offset*anis2) <= 0.0) err ("anis2 too small"); offan = (offset*offset*offset*offset*anis1) / (1.0 + offset*offset*anis2); /* get trace samples */ memcpy( (void *) data, (const void *) tr.data,nt*sizeof(float)); } /* if cdp has changed or no more input traces */ if (cdp!=cdpprev || !gottrace) { /* set output trace header fields */ tr.offset = 0; tr.cdp = (int) cdpprev; tr.ns = ntout; tr.dt = dtout*1000000.0; /* loop over velocities */ for (iv=0; iv<nv; ++iv) { /* compute semblance quotients */ for (itout=0; itout<ntout; ++itout) { it = itout*dtratio; ismin = it-nsmooth/2; ismax = it+nsmooth/2; if (ismin<0) ismin = 0; if (ismax>nt-1) ismax = nt-1; nsum = dsum = 0.0; for (is=ismin; is<ismax; ++is) { nsum += num[iv][is]* num[iv][is]; dsum += nnz[iv][is]* den[iv][is]; } sem[itout] = (dsum!=0.0?nsum/dsum:0.0); } /* powering the semblance */ if (pwr != 1.0) { for (itout=0; itout<ntout; ++itout) sem[itout] = pow (sem[itout], pwr); }; /* output semblances */ memcpy((void *) tr.data, (const void *) sem,ntout*sizeof(float)); puttr(&tr); /* zero accumulators */ for (it=0; it<nt; ++it) { num[iv][it] = 0.0; den[iv][it] = 0.0; nnz[iv][it] = 0.0; } } /* diagnostic print */ if (verbose) warn("semblance output for cdp=%d",cdpprev); /* if no more input traces, break input trace loop */ if (!gottrace) break; /* remember previous cdp */ cdpprev = cdp; } /* loop over velocities */ for (iv=0,v=fv; iv<nv; ++iv,v+=dv) { /* compute offset/velocity squared */ offovs = (offset*offset)/(v*v) + offan; /* decrease of traveltime with distance due to highly increasing velocity cannot be handled yet */ if (offovs < 0.0) warn("no moveout; check anis1 and anis2"); /* determine mute time after nmo */ tnmute = sqrt(offovs/(smute*smute-1.0)); if (tnmute > ft) { itmute = (tnmute-ft)/dt; } else { itmute = 0 ; } /* do nmo via quick and dirty linear interpolation (accurate enough for velocity analysis) and accumulate semblance numerator and denominator */ for (it=itmute,tn=ft+itmute*dt; it<nt; ++it,tn+=dt) { ti = (sqrt(tn*tn+offovs)-ft)/dt; iti = ti; if (iti<nt-1) { frac = ti-iti; temp = (1.0-frac)*data[iti]+ frac*data[iti+1]; if (temp!=0.0) { num[iv][it] += temp; den[iv][it] += temp*temp; nnz[iv][it] += 1.0; } } } } /* get next trace (if there is one) */ if (!gettr(&tr)) gottrace = 0; } return(CWP_Exit()); }
int main(int argc, char **argv) { int nt; /* number of time samples per trace */ float dt; /* time sampling interval */ float ft; /* time of first sample */ int it; /* time sample index */ int cdpmin; /* minimum cdp to process */ int cdpmax; /* maximum cdp to process */ float dxcdp; /* cdp sampling interval */ int noffmix; /* number of offsets to mix */ float offmax; /* maximum offset */ float tmute; /* mute time at far offset */ float vrms; /* rms velocity at mute time */ int nsmax; /* maximum number of time shifts per trace in DMO */ int ns; /* actual number of time shifts per trace in DMO */ float *p; /* input trace */ float **q; /* output DMO-corrected traces */ float *temp; /* temporary array */ float *ts; /* table of time shifts for DMO */ float *as; /* table of amplitudes for DMO */ float offset=0.0;/* source-receiver offset of current trace */ float oldoffset;/* offset of previous trace */ int cdp=0; /* cdp number of current trace */ int ncdp; /* number of cdps */ int icdp; /* cdp index */ int jcdp; /* cdp index */ int jcdplo; /* lower bound for jcdp */ int jcdphi; /* upper bound for jcdp */ int ntrace; /* number of traces processed in current mix */ int itrace; /* trace index */ int noff; /* number of offsets processed in current mix */ int gottrace; /* non-zero if an input trace was read */ int done; /* non-zero if done */ float *ds; /* shaping filter to complete DMO processing */ int lds=125; /* length of shaping filter */ int ifds=-100; /* time index of first sample in shaping filter */ int verbose; /* =1 for diagnostic print */ char *tmpdir; /* directory path for tmp files */ cwp_Bool istmpdir=cwp_false;/* true for user given path */ /* hook up getpar */ initargs(argc, argv); requestdoc(1); /* get information from the first header */ if (!gettr(&tr)) err("can't get first trace"); nt = tr.ns; dt = ((double) tr.dt)/1000000.0; ft = tr.delrt/1000.0; /* get parameters */ if (!getparint("cdpmin",&cdpmin)) err("must specify cdpmin"); if (!getparint("cdpmax",&cdpmax)) err("must specify cdpmax"); if (cdpmin>cdpmax) err("cdpmin must be less than cdpmax"); if (!getparfloat("dxcdp",&dxcdp)) err("must specify dxcdp"); if (!getparint("noffmix",&noffmix)) err("must specify noffmix"); if (!getparfloat("offmax",&offmax)) offmax=3000.0; if (!getparfloat("tmute",&tmute)) tmute=2.0; if (!getparfloat("vrms",&vrms)) vrms=1500.0; if (!getparint("nsmax",&nsmax)) nsmax=400; 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(); /* determine number of cdps */ ncdp = cdpmax-cdpmin+1; /* allocate workspace */ q = ealloc2float(nt,ncdp); p = ealloc1float(nt); temp = ealloc1float(nt); ts = ealloc1float(nsmax); as = ealloc1float(nsmax); ds = ealloc1float(lds); /* tabulate time shifts and amplitudes for dmo */ maketa(dxcdp,dt,offmax,tmute,vrms,nsmax,&ns,ts,as); if (verbose) fprintf(stderr,"\tDMO will be performed via %d time shifts\n", ns); /* compute shaping filter for dmo horizontal reflection response */ makeds(ns,ts,as,lds,ifds,ds); /* open temporary file for headers */ if (STREQ(tmpdir,"")) { headerfp = etmpfile(); if (verbose) warn("using tmpfile() call"); } else { /* user-supplied tmpdir */ char directory[BUFSIZ]; strcpy(directory, tmpdir); strcpy(headerfile, 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); headerfp = efopen(headerfile, "w+"); istmpdir=cwp_true; if (verbose) warn("putting temporary header file in %s", directory); } /* initialize */ oldoffset = tr.offset; gottrace = 1; done = 0; ntrace = 0; noff = 0; for (icdp=0; icdp<ncdp; ++icdp) for (it=0; it<nt; ++it) q[icdp][it] = 0.0; /* loop over traces */ do { /* if got a trace */ if (gottrace) { /* determine offset and cdp */ offset = tr.offset; cdp = tr.cdp; /* update number of offsets mixed */ if (offset!=oldoffset) noff++; /* get trace samples */ memcpy( (void *) p, (const void *) tr.data, nt*sizeof(float)); } /* if a mix of offsets is complete */ if (noff==noffmix || !gottrace) { /* update number of offsets mixed */ if (!gottrace) noff++; /* apply shaping filter to complete dmo processing */ for (icdp=0; icdp<ncdp; ++icdp) { convolve_cwp(lds,ifds,ds,nt,0,q[icdp],nt,0,temp); memcpy( (void *) q[icdp], (const void *) temp, nt*sizeof(float)); } /* rewind trace header file */ erewind(headerfp); /* loop over all output traces */ for (itrace=0; itrace<ntrace; ++itrace) { /* read trace header and determine cdp index */ efread(&tro,HDRBYTES,1,headerfp); icdp = tro.cdp-cdpmin; /* get dmo-corrected data */ memcpy((void *) tro.data, (const void *) q[icdp],nt*sizeof(float)); /* write output trace */ puttr(&tro); } /* report */ if (verbose) fprintf(stderr,"\tCompleted mix of " "%d offsets with %d traces\n", noff,ntrace); /* if no more traces, break */ if (!gottrace) break; /* rewind trace header file */ erewind(headerfp); /* reset number of offsets and traces */ noff = 0; ntrace = 0; /* zero dmo accumulators */ for (icdp=0; icdp<ncdp; ++icdp) for (it=0; it<nt; ++it) q[icdp][it] = 0.0; } /* if cdp is within range of cdps to process */ if (cdp>=cdpmin && cdp<=cdpmax) { /* save trace header and update number of traces */ efwrite(&tr,HDRBYTES,1,headerfp); ntrace++; /* determine output traces potentially modified by input */ icdp = cdp-cdpmin; jcdplo = MAX(0,icdp-0.5*ABS(offset/dxcdp)); jcdphi = MIN(ncdp-1,icdp+0.5*ABS(offset/dxcdp)); /* loop over potentially modified output traces */ for (jcdp=jcdplo; jcdp<=jcdphi; ++jcdp) { /* do dmo for one output trace */ dmotx(ns,ts,as,offset,(jcdp-icdp)*dxcdp,dxcdp, 0,nt,dt,ft,p,q[jcdp]); } /* remember offset */ oldoffset = offset; } /* get next trace (if there is one) */ if (!gettr(&tr)) gottrace = 0; } while (!done); /* clean up */ efclose(headerfp); if (istmpdir) eremove(headerfile); return(CWP_Exit()); }
int main(int argc,char **argv) { int n1, n2, n3, depth, time, verbose, iter, slowness; float r1, r2, r3, d1, d2, d3, *wl, ***vel, mu, vminc, vmaxc; FILE *invp=stdin, *outvp=stdout; /* initialization */ initargs(argc,argv) ; requestdoc(0); /*-----------get required parameters-----------*/ if( !getparint("n1",&n1) ) n1 = 0 ; if( n1 <= 0 ) err("sample number of 1st dimension invalid" ) ; if( !getparint("n2",&n2) ) n2 = 0 ; if( n2 <= 0 ) err("sample number of 2nd dimension invalid" ) ; if( !getparint("n3",&n3) ) n3 = 0 ; if( n3 <= 0 ) err("sample number of 3rd dimension invalid" ) ; /*-----------get optional parameters-----------*/ /* sample intervals */ if( !getparfloat("d1",&d1) ) d1 = 1.0 ; if( !getparfloat("d2",&d2) ) d2 = 1.0 ; if( !getparfloat("d3",&d3) ) d3 = 1.0 ; /* smoothing parameters */ if( !getparfloat("r1",&r1) || n1<4) r1 = 0. ; if( !getparfloat("r2",&r2) || n2<4) r2 = 0. ; if( !getparfloat("r3",&r3) || n3<4) r3 = 0. ; /* scale smoothing parameters */ r1 = (d1>0)?r1/d1:0; r2 = (d2>0)?r2/d2:0; r3 = (d3>0)?r3/d3:0; r1 = 0.5*r1*r1 ; r2 = 0.5*r2*r2 ; r3 = 0.5*r3*r3 ; /* get iteration number for smoothing operator */ if(!getparint("iter", &iter)) iter = 2; if(iter<=0 || iter>3) err("\t iter must be between 1 and 3!\n"); /* description for vertical dimension */ if(!getparint("time",&time )) time = 0; if(!getparint("depth",&depth) ) depth = 1; if(time) depth = time; /* relative weight at bottom */ if(!getparfloat("mu",&mu) ) mu = 1.0; if(mu<1) err("mu must not be less than 1 \n"); /* smoothing on velocity or slowness */ if(!getparint("slowness",&slowness) ) slowness = 0; /* clips of velocity before smoothing */ if(!getparfloat("vminc",&vminc) ) vminc = 0; if(!getparfloat("vmaxc",&vmaxc) ) vmaxc = 99999; /* allocate input file */ vel = alloc3float(n1,n2,n3) ; wl = alloc1float(4); /* read input velocity file */ efread((char *)vel[0][0],sizeof(float),n1*n2*n3,invp); /* perform smoothing operation */ vsm3d(vel,n3,n2,n1,iter,depth,r3,r2,r1,mu,slowness,vminc,vmaxc); /* write output velocity file */ efwrite((char *)vel[0][0],sizeof(float),n1*n2*n3,outvp); if(!getparint("verbose",&verbose)) verbose = 0; if(verbose) { wavel(n1,n2,n3,d1,d2,d3,time,wl,vel); fprintf(stderr,"minimum wavelengths of smoothed velocity:\n"); fprintf(stderr,"\tlambda1 = %g,\n", wl[1]); fprintf(stderr,"\tlambda2 = %g,\n", wl[2]); fprintf(stderr,"\tlambda3 = %g,\n", wl[3]); fprintf(stderr,"\tlambda = %g,\n", wl[0]); } checkpars(); /* close input and output files */ efclose(invp) ; efclose(outvp) ; return(CWP_Exit()); }
int main(int argc, char **argv) { int i,j,k; /* counters */ int ns=0; /* number of samples in input data */ int nwavelet=1024; /* number of samples in mother wavelet */ float base=0.0; /* base */ float first=0.0; /* first exponent */ float expinc=0.0; /* exponent increment */ float last=0.0; /* last exponent */ float exponent=0.0; /* each exponent */ float maxscale=0.0; /* maximum scale value */ float minscale=0.0; /* minimum scale value */ float x=0.0; float dx=0.0; /* xvalues incr */ float xmin=0.0; /* last xvalues - first vval */ float xcenter=0.0; /* x value of center of wavelet */ float xmax=0.0; /* last xvalues - first vval */ float sigma=1.0; /* sharpening parameter */ float waveletinc=0.0; /* wavelet interval */ float fmin=0.0; /* min, max filt value (debug) */ float *xvalues=NULL; /* wavelet xvalues */ float **filt=NULL; /* filter used for each conv */ float *f=NULL; /* scratch for filter fliplr */ float *sucwt_buff=NULL; /* scratch for convolution */ float *scales=NULL; /* scales */ float *waveletsum=NULL; /* cumulative sum of wavelet */ float *rt=NULL; /* temp data storage */ float *qt=NULL; /* temp hilbert transformed data storage */ float **tmpdata=NULL; /* temp data storage */ int wtype=0; /* type of wavelet selected */ float *wavelet=NULL; /* pointer to data constituting the wavelet */ int verbose=0; /* verbose flag */ int *index=NULL; /* wavelet subscripts to use for filter */ int *nconv=NULL; /* length of each filter */ int nscales=0; /* number of scales */ int holder=0; /* =1 compute the Holder-Lipschitz regularity */ float divisor=1.0; /* divisor used in Holder exponent calculation*/ /* Initialize */ initargs(argc, argv); requestdoc(1); /* Get parameters */ if(!getparfloat("base",&base)) base = 10.; if(!getparfloat("first",&first)) first = -1.0; if(!getparfloat("expinc",&expinc)) expinc = 0.01; if(!getparfloat("last",&last)) last = 1.5; if(!getparint("wtype",&wtype)) wtype = 0; if(!getparint("nwavelet",&nwavelet)) nwavelet = 1024; if(!getparfloat("xmin",&xmin)) xmin = -20.0; if(!getparfloat("xcenter",&xcenter)) xmin = 0.0; if(!getparfloat("xmax",&xmax)) xmax = 20.0; if(!getparfloat("sigma",&sigma)) sigma = 1.0; if(!getparint("holder",&holder)) holder = 0; if(!getparfloat("divisor",&divisor)) divisor = 1.0; if(!getparint("verbose",&verbose)) verbose = 0; checkpars(); if(verbose) warn("base=%f, first=%f, expinc=%f, last=%f",base,first,expinc,last); /* Allocate space */ xvalues = ealloc1float(nwavelet); wavelet = ealloc1float(nwavelet); memset((void *) xvalues, 0, nwavelet*FSIZE); memset((void *) wavelet, 0, nwavelet*FSIZE); /* Compute wavelet */ if (wtype == 0 ) { /* so far only Mex. Hat function */ MexicanHatFunction(nwavelet, xmin, xcenter, xmax, sigma, wavelet); } else { err("%d type of wavelet not yet implemented",wtype); } /* wavelet increment */ waveletinc = (xmax - xmin)/(nwavelet - 1); /* verbose warning */ if(verbose) warn("xmin=%f, xmax=%f, nwavelet=%d, waveletinc=%f", xmin,xmax,nwavelet,waveletinc); /* form xvalues[] array */ for(i=0,x=xmin; i<nwavelet; ++i,x+=waveletinc) xvalues[i] = x; xvalues[nwavelet-1] = xmax; /* compute scales */ scales = ealloc1float(SHRT_MAX); memset((void *) scales, 0, SHRT_MAX*FSIZE); exponent = first; x = 0; nscales = 0; minscale = pow(base,first); maxscale = pow(base,last); while(x <= maxscale) { x = pow(base,exponent); scales[nscales] = x; exponent+=expinc; ++nscales; if(nscales == SHRT_MAX) err("Too many scales, change params and re-run\n"); } --nscales; /* Allocate space */ nconv = ealloc1int(nscales); index = ealloc1int(nwavelet); waveletsum = ealloc1float(nwavelet); filt = ealloc2float(nwavelet,nscales); f = ealloc1float(nwavelet); /* Zero out arrays */ memset((void *) nconv, 0, nscales*ISIZE); memset((void *) index, 0, nwavelet*ISIZE); memset((void *) waveletsum, 0, nwavelet*FSIZE); memset((void *) filt[0], 0, nwavelet*nscales*FSIZE); memset((void *) f, 0, nwavelet*FSIZE); /* Form difference of xvalues */ for(i=nwavelet-1; i>=0; --i) xvalues[i] = xvalues[i] - xvalues[0]; dx = xvalues[1]; xmax = xvalues[nwavelet-1]; /* verbose warning */ if(verbose) { warn("first xvalues=%f, last xvalues=%f", xvalues[0],xvalues[nwavelet-1]); warn("dx=%f, xmax=%f",dx,xmax); } /* waveletsum is cumulative sum of wavelet multipled by dx */ fmin = 0; for(i=0; i<nwavelet; ++i) { fmin += wavelet[i]; waveletsum[i] = fmin * dx; } /* Build filters from summed wavelet */ for(i=0; i<nscales; ++i) { nconv[i] = 1 + (int)(scales[i] * xmax); for(j=0; j<nconv[i]; ++j) index[j] = 1 + j / (scales[i] * dx); for(j=0; j<nconv[i]; ++j) f[j] = waveletsum[index[j]-1]; /* flip left right */ for(j=0,k=nconv[i]-1; j<nconv[i]; ++j,--k) filt[i][j] = f[k]; } /* Verbose warning */ if(verbose) { warn("Convolution Lengths"); for(i=0; i<nscales; ++i) warn("%d ",nconv[i]); } if(verbose) warn("%d scales will be used for transforms",nscales); /* Get information from first trace */ if(!gettr(&tr)) err("Cannot get first trace\n"); ns = tr.ns; /* Allocate temporary storage space */ rt = ealloc1float(ns); qt = ealloc1float(ns); tmpdata = ealloc2float(nscales,ns); /* Zero out rt and qt */ memset((void *) rt, 0, ns*FSIZE); memset((void *) qt, 0, ns*FSIZE); /* Alloc sucwt_buffer for longest convolution */ sucwt_buff = ealloc1float(ns+nconv[nscales-1]+1); do { /* main loop over traces */ outtr.d2 = waveletinc; outtr.f2 = minscale; memcpy((void *)&outtr,(const void *)&tr,HDRBYTES); /* Apply filters to produce wavelet transform */ for(i=0; i<nscales; ++i) { /* loop over scales */ for(j=0; j<ns+nconv[nscales-1]+1; ++j) sucwt_buff[j] = 0; /* convolve wavelet with data */ convolve_cwp(ns,0,tr.data,nconv[i],0, filt[i],ns,0,sucwt_buff); for(j=0; j<ns; ++j) rt[j] = sucwt_buff[j+nconv[i]/2-1]; for(j=ns-1; j>0; --j) rt[j] = rt[j] - rt[j-1]; for(j=0; j<ns; ++j) rt[j] = -sqrt(scales[i]) * rt[j]; /* form the hilbert transform of rt */ hilbert(ns,rt,qt); /* If not holder, then output envelope */ if (!holder) { for (j=0 ; j<ns; ++j) { outtr.data[j] = sqrt(rt[j]*rt[j] + qt[j]*qt[j]); } outtr.cdpt = i + 1; puttr(&outtr); } else { /* compute the modulus */ for (j=0 ; j<ns; ++j) { tmpdata[j][i] = sqrt(rt[j]*rt[j] + qt[j]*qt[j]); } } } if (holder) { /* compute the Holder regularity traces */ float *x; float *y; float lrcoeff[4]; x = ealloc1float(nscales); y = ealloc1float(nscales); /* Compute an estimate of the Lipschitz (Holder) * regularity. Following Mallat (1992) * * ln | Wf(x,s)| < ln C + alpha * ln|s| * * alpha here is the Holder or Lipschitz exponent * s is the length scale, and Wf(x,s) is f in the * wavelet basis. * * Here we merely fit a straight line * through the log-log graph of the of our wavelet * transformed data and return the slope as * the regularity measure. * */ for ( j =0 ; j< ns ; ++j ) { int icount=0; x[0]=0; for ( i = 1 ; i < nscales ; ++i ) { /* We stay away from values that will make */ /* NANs in the output */ if ((i>1) && (tmpdata[j][i-1] - tmpdata[j][1] > 0.0)) { y[icount] = log(ABS(tmpdata[j][i] - tmpdata[j][1])); x[icount] = log(scales[i]-scales[1]); ++icount; } } --icount; /* straight line fit, return slope */ if ((icount> 10) && (divisor==1.0) ) { linear_regression(y, x, icount, lrcoeff); /* lrcoeff[0] is the slope of the line */ /* which is the Holder (Lipschitz) */ /* exponent */ outtr.data[j] = lrcoeff[0]; } else if ((icount> 10) && (divisor>1.0) ) { float maxalpha=0.0; float interval=icount/divisor; for ( k = interval; k < icount; k+=interval){ linear_regression(y, x, k, lrcoeff); maxalpha = MAX(lrcoeff[0],maxalpha); } outtr.data[j] = maxalpha; } else if ((icount < 10) && (divisor>=1.0)) { outtr.data[j] = 0.0; } else if ( divisor < 1.0 ) { err("divisor = %f < 1.0!", divisor); } } puttr(&outtr); /* output holder regularity traces */ } } while(gettr(&tr)); return(CWP_Exit()); }
int main(int argc, char **argv) { /* output file pointers */ FILE *rlfp=NULL, *taufp=NULL, *e21fp=NULL; FILE *e31fp=NULL, *e32fp=NULL, *plnfp=NULL; FILE *f1fp=NULL, *l1fp=NULL; FILE *thetafp=NULL, *phifp=NULL, *dirfp=NULL; FILE *erfp=NULL, *irfp=NULL, *qrfp=NULL; FILE *headerfp=NULL, *pfiltfp=NULL, *sfiltfp=NULL; FILE *nfiltfp=NULL, *efiltfp=NULL; // FILE *pkur=NULL, *skur=NULL; /* temporary file for trace headers */ /* (one 3C station only) */ char *file=NULL; /* base of output file name(s) */ char *fname=NULL; /* complete output file name */ char *angle=NULL; /* unit used for angles theta and phi */ char *win=NULL; /* shape of used time window */ float fangle=0.0; /* unit conversion factor applied to angles theta and phi */ int iwin=0; /* time window shape identifier */ /* flags (see selfdoc) */ int rl,theta,phi,tau,ellip,pln,f1,l1,dir,amp,verbose,all; int i,j,icomp; /* indices for components (in loops) */ int it; /* index for time sample in main loop */ int iwl; /* correlation window length in samples */ int nstat; /* number of 3-component datasets */ int nt; /* number of time samples in one trace */ // int kwl; /* kurtosis window length in seconds */ float **data3c; /* three-component data ([1..3][0..nt-1]) */ float **a; /* covariance matrix (a[1..3][1..3]) */ float **v; /* eigenvectors of covariance matrix (v[1..3][1..3]) */ float *d; /* the corresponding eigenvalues (d[1..3]) */ float *w; /* time window weights for correlation window */ float dt; /* sampling interval in seconds */ float rlq; /* contrast factor of rectilinearity */ float wl; /* correlation window length in seconds */ float *data_e21=NULL; /* main ellipticity */ float *data_e31=NULL; /* second ellipticity */ float *data_e32=NULL; /* transverse ellipticity */ float *data_er=NULL; /* eigenresultant */ float *data_f1=NULL; /* flatness coefficient */ float *data_ir=NULL; /* instantaneous resultant */ float *data_l1=NULL; /* linearity coefficient */ float *data_phi=NULL; /* horizontal azimuth phi */ float *data_pln=NULL; /* planarity */ float *data_qr=NULL; /* quadratic resultant */ float *data_rl=NULL; /* rectilinearity factor */ float *data_tau=NULL; /* polarization parameter tau */ float *data_theta=NULL; /* inclination angle theta */ float *data_pfilt=NULL; /* P (vertical) polarization filter */ float *data_sfilt=NULL; /* S (horizontal) polarization filter */ float *data_zfilt=NULL; /* Z Filtered Trace */ float *data_nfilt=NULL; /* N Filtered Trace */ float *data_efilt=NULL; /* E Filtered Trace */ // float *data_kwl=NULL; /* Data for Kurtosis Window */ // float *data_pkur=NULL; /* Kurtosis detector for P */ // float *data_skur=NULL; /* Kurtosis detector for S */ float **data3c_dir=NULL; /* 3 components of direction of polarization ([1..3][0..nt-1]) */ /* initialize */ initargs(argc, argv); requestdoc(1); /* get info from first trace */ if(!gettr(&tr)) err("can't get first trace"); nt = tr.ns; /* get parameters ... */ if (!getparstring("file", &file)) file="polar"; if (!getparstring("angle", &angle)) angle="rad"; if (!getparstring("win", &win)) win="boxcar"; if (!getparfloat("wl", &wl)) wl = 0.1; if (!getparfloat("dt", &dt)) dt = ((double) tr.dt)/1000000.0; if (!getparfloat("rlq", &rlq)) rlq = 1.0; if (!getparint("verbose", &verbose)) verbose = 0; // if (!getparint("kwl", &kwl)) kwl = 5 * ((int) 1/dt); /* ... and output flags */ if (!getparint("all", &all)) all = 0; if (!getparint("rl", &rl)) rl = (all) ? all : 1; if (!getparint("dir", &dir)) dir = (all) ? 1 : 1; if (!getparint("theta", &theta)) theta = (all) ? all : 0; if (!getparint("phi", &phi)) phi = (all) ? all : 0; if (!getparint("tau", &tau)) tau = (all) ? 1 : 0; if (!getparint("ellip", &ellip)) ellip = (all) ? 1 : 0; if (!getparint("pln", &pln)) pln = (all) ? 1 : 0; if (!getparint("f1", &f1)) f1 = (all) ? 1 : 0; if (!getparint("l1", &l1)) l1 = (all) ? 1 : 0; if (!getparint("amp", &)) amp = (all) ? 1 : 0; checkpars(); /* get time window shape */ if (STREQ(win, "boxcar")) iwin=WBOXCAR; else if (STREQ(win, "bartlett")) iwin=WBARTLETT; else if (STREQ(win, "hanning")) iwin=WHANNING; else if (STREQ(win, "welsh")) iwin=WWELSH; else err("unknown win=%s", win); /* get unit conversion factor for angles */ if (STREQ(angle, "rad")) fangle=1.0; else if (STREQ(angle, "deg")) fangle=180.0/PI; else if (STREQ(angle, "gon")) fangle=200.0/PI; else err("unknown angle=%s", angle); /* convert seconds to samples */ if (!dt) { dt = 0.004; warn("dt not set, assuming dt=0.004"); } iwl = NINT(wl/dt); /* data validation */ if (iwl<1) err("wl=%g must be positive", wl); if (iwl>nt) err("wl=%g too long for trace", wl); if (!strlen(file)) err("file= not set and default overridden"); /* echo some information */ if (verbose && (theta || phi)) warn("computing angles in %s", angle); if (verbose) warn("%s window length = %d samples\n", win, iwl); if (rl && theta) warn("computing filtered phase"); /* open temporary file for trace headers */ headerfp = etmpfile(); /* set filenames and open files */ fname = malloc( strlen(file)+7 ); sprintf(fname, "%s.rl", file); if (rl) rlfp = efopen(fname, "w"); sprintf(fname, "%s.theta", file); if (theta) thetafp = efopen(fname, "w"); sprintf(fname, "%s.phi", file); if (phi) phifp = efopen(fname, "w"); sprintf(fname, "%s.tau", file); if (tau) taufp = efopen(fname, "w"); sprintf(fname, "%s.e21", file); if (ellip) e21fp = efopen(fname, "w"); sprintf(fname, "%s.e31", file); if (ellip) e31fp = efopen(fname, "w"); sprintf(fname, "%s.e32", file); if (ellip) e32fp = efopen(fname, "w"); sprintf(fname, "%s.pln", file); if (pln) plnfp = efopen(fname, "w"); sprintf(fname, "%s.f1", file); if (f1) f1fp = efopen(fname, "w"); sprintf(fname, "%s.l1", file); if (l1) l1fp = efopen(fname, "w"); sprintf(fname, "%s.dir", file); if (dir) dirfp = efopen(fname, "w"); sprintf(fname, "%s.er", file); if (amp) erfp = efopen(fname, "w"); sprintf(fname, "%s.ir", file); if (amp) irfp = efopen(fname, "w"); sprintf(fname, "%s.qr", file); if (amp) qrfp = efopen(fname, "w"); sprintf(fname, "%s.pfilt", file); if (rl && theta) pfiltfp = efopen(fname, "w"); sprintf(fname, "%s.sfilt", file); if (rl && theta) sfiltfp = efopen(fname, "w"); sprintf(fname, "%s.nfilt", file); if (rl && theta) nfiltfp = efopen(fname, "w"); sprintf(fname, "%s.efilt", file); if (rl && theta) efiltfp = efopen(fname, "w"); // sprintf(fname, "%s.pkur", file); if (rl && theta) pkur = efopen(fname, "w"); // sprintf(fname, "%s.skur", file); if (rl && theta) skur = efopen(fname, "w"); free(fname); /* allocate space for input data and analysis matrices */ /* index ranges used here: data3c[1..3][0..nt-1], */ /* a[1..3][1..3], v[1..3][1..3], d[1..3] */ data3c = ealloc2float(nt,3); data3c-=1; a = ealloc2float(3,3); a[0]-=1; a-=1; v = ealloc2float(3,3); v[0]-=1; v-=1; d = ealloc1float(3); d-=1; /* calculate time window weights */ w = ealloc1float(iwl); memset((void *) w, 0, iwl*FSIZE); calc_window(w, iwl, iwin); /* allocate and zero out space for output data */ if (rl) { data_rl = ealloc1float(nt); memset((void *) data_rl, 0, nt*FSIZE); } if (theta) { data_theta = ealloc1float(nt); memset((void *) data_theta, 0, nt*FSIZE); } if (phi) { data_phi = ealloc1float(nt); memset((void *) data_phi, 0, nt*FSIZE); } if (tau) { data_tau = ealloc1float(nt); memset((void *) data_tau, 0, nt*FSIZE); } if (ellip) { data_e21 = ealloc1float(nt); data_e31 = ealloc1float(nt); data_e32 = ealloc1float(nt); memset((void *) data_e21, 0, nt*FSIZE); memset((void *) data_e31, 0, nt*FSIZE); memset((void *) data_e32, 0, nt*FSIZE); } if (pln) { data_pln = ealloc1float(nt); memset((void *) data_pln, 0, nt*FSIZE); } if (f1) { data_f1 = ealloc1float(nt); memset((void *) data_f1, 0, nt*FSIZE); } if (l1) { data_l1 = ealloc1float(nt); memset((void *) data_l1, 0, nt*FSIZE); } if (amp) { data_er = ealloc1float(nt); data_ir = ealloc1float(nt); data_qr = ealloc1float(nt); memset((void *) data_er, 0, nt*FSIZE); memset((void *) data_ir, 0, nt*FSIZE); memset((void *) data_qr, 0, nt*FSIZE); } if (dir) { data3c_dir = ealloc2float(nt,3); data3c_dir-=1; for (i=1;i<=3;i++) memset((void *) data3c_dir[i], 0, nt*FSIZE); } if (rl && theta) { data_pfilt = ealloc1float(nt); memset((void *) data_pfilt, 0, nt*FSIZE); data_sfilt = ealloc1float(nt); memset((void *) data_pfilt, 0, nt*FSIZE); /* data_3Cfilt = ealloc2float(nt,3); for (i=1;i<=3;i++) memset((void *) data_3Cfilt[i], 0, nt*FSIZE); */ data_zfilt = ealloc1float(nt); data_nfilt = ealloc1float(nt); data_efilt = ealloc1float(nt); memset((void *) data_zfilt, 0, nt*FSIZE); memset((void *) data_nfilt, 0, nt*FSIZE); memset((void *) data_efilt, 0, nt*FSIZE); // data_pkur = ealloc1float(nt); // data_skur = ealloc1float(nt); // memset((void *) data_pkur, 0, nt*FSIZE); // memset((void *) data_skur, 0, nt*FSIZE); /* Allocate data for kurtosis window arrays */ // data_kwl = ealloc1float(iwl); // memset((void *) data_kwl, 0, kwl*FSIZE); } /* ************************ BEGIN CALCULATION ******************************* */ /* loop over traces */ icomp=0; nstat=0; // Need to convert this do while loop into a for loop so as to be easier // to parallelize warn("Trace Start Time: %d %d %d %d %d", tr.year, tr.day, tr.hour, tr.minute, tr.sec); do { /* store trace header in temporary file and read data */ efwrite(&tr, HDRBYTES, 1, headerfp); icomp++; memcpy((void *)data3c[icomp], (const void *) tr.data, nt*FSIZE); /* process 3-component dataset */ if (icomp==3) { erewind(headerfp); icomp = 0; nstat++; if (verbose) fprintf(stderr,"%s: analyzing station %d \r",argv[0], nstat); /* start loop over samples */ for (it=iwl/2;it<nt-iwl/2;it++) { //warn("Sample %d", it); /* covariance matrix */ for (i=1;i<=3;i++) { for (j=i;j<=3;j++) { a[i][j]=a[j][i]=covar(data3c[i], data3c[j], it-iwl/2, iwl, w); } } /* compute eigenvalues and vectors */ eig_jacobi(a,d,v,3); sort_eigenvalues(d,v,3); /* polarization parameters */ if (rl) data_rl[it]=calc_rl(d,rlq,rl); if (theta) data_theta[it]=calc_theta(v, theta) * fangle; if (phi) data_phi[it]=calc_phi(v, phi) * fangle; if (tau) data_tau[it]=calc_tau(d); if (ellip) { data_e21[it]=calc_ellip(d,2,1); data_e31[it]=calc_ellip(d,3,1); data_e32[it]=calc_ellip(d,3,2); } if (pln) data_pln[it]=calc_plan(d); if (f1) data_f1[it]=calc_f1(d); if (l1) data_l1[it]=calc_l1(d); if (amp) data_er[it]=calc_er(d); if (dir) calc_dir(data3c_dir,v,it); if (rl && theta) { data_zfilt[it] = data3c[1][it] * calc_pfilt(rl, theta); data_nfilt[it] = data3c[2][it] * calc_sfilt(rl, theta); data_efilt[it] = data3c[3][it] * calc_sfilt(rl, theta); data_pfilt[it] = data_zfilt[it]; data_sfilt[it] = (data_nfilt[it] + data_efilt[it]) / 2; // data_pkur[it] = kurtosiswindow(data_pfilt,data_kwl,it - kwl/2,kwl,nt); // data_skur[it] = kurtosiswindow(data_sfilt,data_kwl,it - kwl/2,kwl,nt); } } /* end loop over samples */ /* compute amplitude parameters */ if (amp) ampparams(data3c, data_ir, data_qr, nt, iwl); /* *************************** END CALCULATION ****************************** */ /* ***************************** BEGIN WRITE ******************************** */ /* write polarization attributes to files */ if (rl) fputdata(rlfp, headerfp, data_rl, nt); if (theta) fputdata(thetafp, headerfp, data_theta, nt); if (phi) fputdata(phifp, headerfp, data_phi, nt); if (tau) fputdata(taufp, headerfp, data_tau, nt); if (ellip) { fputdata(e21fp, headerfp, data_e21, nt); fputdata(e31fp, headerfp, data_e31, nt); fputdata(e32fp, headerfp, data_e32, nt); } if (pln) fputdata(plnfp, headerfp, data_pln, nt); if (f1) fputdata(f1fp, headerfp, data_f1, nt); if (l1) fputdata(l1fp, headerfp, data_l1, nt); if (amp) { fputdata(erfp, headerfp, data_er, nt); fputdata(irfp, headerfp, data_ir, nt); fputdata(qrfp, headerfp, data_qr, nt); } if (dir) fputdata3c(dirfp, headerfp, data3c_dir, nt); if (rl && theta) { fputdata(pfiltfp, headerfp, data_pfilt, nt); fputdata(sfiltfp, headerfp, data_sfilt, nt); fputdata(nfiltfp, headerfp, data_nfilt, nt); fputdata(efiltfp, headerfp, data_efilt, nt); // fputdata(pkur, headerfp, data_pkur, nt); // fputdata(skur, headerfp, data_skur, nt); } /* ****************************** END WRITE ********************************* */ } /* end of processing three-component dataset */ } while (gettr(&tr)); /* end loop over traces */ if (verbose) { fprintf(stderr,"\n"); if (icomp) warn("last %d trace(s) skipped", icomp); } /* close files */ efclose(headerfp); if (rl) efclose(rlfp); if (theta) efclose(thetafp); if (phi) efclose(phifp); if (tau) efclose(taufp); if (ellip) { efclose(e21fp); efclose(e31fp); efclose(e32fp); } if (pln) efclose(plnfp); if (f1) efclose(f1fp); if (l1) efclose(l1fp); if (amp) { efclose(erfp); efclose(irfp); efclose(qrfp); } if (dir) efclose(dirfp); if (rl && theta) { efclose(pfiltfp); efclose(sfiltfp); // efclose(pkur); // efclose(skur); } 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()); }
int main(int argc, char **argv) { cwp_String key[SU_NKEYS]; /* array of keywords */ cwp_String type[SU_NKEYS]; /* array of keywords */ int index[SU_NKEYS]; /* name of type of getparred key */ int ikey; /* key counter */ int nkeys; /* number of header fields set */ int count=0; /* number of header fields from file */ double i; /* parameters for computing fields */ int itr = 0; /* trace counter */ Value val; /* value of key field */ char *infile=""; /* name of input file of header values */ FILE *infp=NULL; /* pointer to input file */ cwp_Bool from_file=cwp_false; /* is the data from infile? */ float *afile=NULL; /* array of "a" values from file */ double *a=NULL; /* array of "a" values */ double *b=NULL; /* array of "b" values */ double *c=NULL; /* array of "c" values */ double *d=NULL; /* array of "d" values */ double *j=NULL; /* array of "j" values */ int n; /* number of a,b,c,d,j values */ /* Initialize */ initargs(argc, argv); requestdoc(1); /* Get "key" values */ if ((nkeys=countparval("key"))!=0) { getparstringarray("key",key); } else { key[0]="cdp"; } /* get types and indexes corresponding to the keys */ for (ikey=0; ikey<nkeys; ++ikey) { type[ikey]=hdtype(key[ikey]); index[ikey]=getindex(key[ikey]); } /* get name of infile */ getparstring("infile",&infile); /* if infile is specified get specified keys from file */ if (*infile!='\0') { /* open infile */ if((infp=efopen(infile,"r"))==NULL) err("cannot open infile=%s\n",infile); /* set from_file flag */ from_file=cwp_true; } /* If not from file, getpar a,b,c,d,j */ if (!from_file) { /* get "a" values */ if ((n=countparval("a"))!=0) { if (n!=nkeys) err("number of a values not equal to number of keys"); a=ealloc1double(n); getpardouble("a",a); } else { a=ealloc1double(nkeys); for (ikey=0; ikey<nkeys; ++ikey) a[ikey]=0.; } /* get "b" values */ if ((n=countparval("b"))!=0) { if (n!=nkeys) err("number of b values not equal to number of keys"); b=ealloc1double(n); getpardouble("b",b); } else { b=ealloc1double(nkeys); for (ikey=0; ikey<nkeys; ++ikey) b[ikey]=0.; } /* get "c" values */ if ((n=countparval("c"))!=0) { if (n!=nkeys) err("number of c values not equal to number of keys"); c=ealloc1double(n); getpardouble("c",c); } else { c=ealloc1double(nkeys); for (ikey=0; ikey<nkeys; ++ikey) c[ikey]=0.; } /* get "d" values */ if ((n=countparval("d"))!=0) { if (n!=nkeys) err("number of d values not equal to number of keys"); d=ealloc1double(n); getpardouble("d",d); } else { d=ealloc1double(nkeys); for (ikey=0; ikey<nkeys; ++ikey) d[ikey]=0.; } /* get "j" values */ if ((n=countparval("j"))!=0) { if (n!=nkeys) err("number of j values not equal to number of keys"); j=ealloc1double(n); getpardouble("j",j); /* make sure that j!=0 */ for (ikey=0; ikey<nkeys; ++ikey) if(j[ikey]==0) j[ikey]=ULONG_MAX; } else { j=ealloc1double(nkeys); for (ikey=0; ikey<nkeys; ++ikey) j[ikey]=ULONG_MAX; } } else { /* if reading from a file */ /* allocate space for afile */ afile=ealloc1float(nkeys); } checkpars(); /* loop over traces */ while (gettr(&tr)) { if (from_file) { /* use the "a" value from file to trace by trace */ if (efread(afile,FSIZE,nkeys,infp)!=0) { for (ikey=0; ikey<nkeys; ++ikey) { double a_in; a_in=(double) afile[ikey]; setval(type[ikey],&val,a_in, 0,0,0,ULONG_MAX); puthval(&tr,index[ikey],&val); ++count; } } } else { /* use getparred values of a,b,c,d,j */ for (ikey=0; ikey<nkeys; ++ikey) { i = (double) itr + d[ikey]; setval(type[ikey],&val,a[ikey],b[ikey], c[ikey],i,j[ikey]); puthval(&tr,index[ikey],&val); } } ++itr; puttr(&tr); } if (from_file) { efclose(infp); if (count < (int)(itr*nkeys) ) { warn("itr=%d > count=%d %s",(int) itr*count,count); warn("n traces=%d > data count =%d",(itr*nkeys),count); } } return(CWP_Exit()); }
int main(int argc, char **argv) { int nt; /* number of time samples per trace */ float dt; /* time sampling interval */ float ft; /* time of first sample */ int it; /* time sample index */ int cdpmin; /* minimum cdp to process */ int cdpmax; /* maximum cdp to process */ float dx; /* cdp sampling interval */ int nx; /* number of cdps to process */ int nxfft; /* number of cdps after zero padding for fft */ int nxpad; /* minimum number of cdps for zero padding */ int ix; /* cdp index, starting with ix=0 */ int noffmix; /* number of offsets to mix */ float *tdmo; /* times at which rms velocities are specified */ float *vdmo; /* rms velocities at times specified in tdmo */ float gamma; /* upgoing to downging velocity ratio */ float *zoh=NULL;/* tabulated z/h */ float *boh=NULL;/* tabulated b/h */ int ntable; /* number of tabulated zoh and boh */ float sdmo; /* DMO stretch factor */ float s1; /* DMO stretch factor */ float s2; /* DMO stretch factor */ float temps; /* temp value used in excahnging s1 and s2 */ int flip; /* apply negative shifts and exchange s1 and s2 */ float sign; /* + if flip=0, negative if flip=1 */ int ntdmo; /* number tnmo values specified */ int itdmo; /* index into tnmo array */ int nvdmo; /* number vnmo values specified */ float fmax; /* maximum frequency */ float *vrms; /* uniformly sampled vrms(t) */ float **p; /* traces for one offset - common-offset gather */ float **q; /* DMO-corrected and mixed traces to be output */ float offset; /* source-receiver offset of current trace */ float oldoffset;/* offset of previous trace */ int noff; /* number of offsets processed in current mix */ int ntrace; /* number of traces processed in current mix */ int itrace; /* trace index */ int gottrace; /* non-zero if an input trace was read */ int done; /* non-zero if done */ int verbose; /* =1 for diagnostic print */ FILE *hfp; /* file pointer for temporary header file */ /* hook up getpar */ initargs(argc, argv); requestdoc(1); /* get information from the first header */ if (!gettr(&tr)) err("can't get first trace"); nt = tr.ns; dt = tr.dt/1000000.0; ft = tr.delrt/1000.0; offset = tr.offset; /* get parameters */ if (!getparint("cdpmin",&cdpmin)) err("must specify cdpmin"); if (!getparint("cdpmax",&cdpmax)) err("must specify cdpmax"); if (cdpmin>cdpmax) err("cdpmin must not be greater than cdpmax"); if (!getparfloat("dxcdp",&dx)) err("must specify dxcdp"); if (!getparint("noffmix",&noffmix)) err("must specify noffmix"); ntdmo = countparval("tdmo"); if (ntdmo==0) ntdmo = 1; tdmo = ealloc1float(ntdmo); if (!getparfloat("tdmo",tdmo)) tdmo[0] = 0.0; nvdmo = countparval("vdmo"); if (nvdmo==0) nvdmo = 1; if (nvdmo!=ntdmo) err("number of tdmo and vdmo must be equal"); vdmo = ealloc1float(nvdmo); if (!getparfloat("vdmo",vdmo)) vdmo[0] = 1500.0; for (itdmo=1; itdmo<ntdmo; ++itdmo) if (tdmo[itdmo]<=tdmo[itdmo-1]) err("tdmo must increase monotonically"); if (!getparfloat("gamma",&gamma)) gamma = 0.5; if (!getparint("ntable",&ntable)) ntable = 1000; if (!getparfloat("sdmo",&sdmo)) sdmo = 1.0; if (!getparint("flip",&flip)) flip=0; if (flip) sign = -1.0; else sign = 1.0; if (!getparfloat("fmax",&fmax)) fmax = 0.5/dt; if (!getparint("verbose",&verbose)) verbose=0; checkpars(); /* allocate and generate tables of b/h and z/h if gamma not equal 1 */ if(gamma != 1.0){ zoh=alloc1float(ntable); boh=alloc1float(ntable); table(ntable, gamma, zoh, boh); } /* make uniformly sampled rms velocity function of time */ vrms = ealloc1float(nt); mkvrms(ntdmo,tdmo,vdmo,nt,dt,ft,vrms); /* determine number of cdps to process */ nx = cdpmax-cdpmin+1; /* allocate and zero common-offset gather p(t,x) */ nxpad = 0.5*ABS(offset/dx); nxfft = npfar(nx+nxpad); p = ealloc2float(nt,nxfft+2); for (ix=0; ix<nxfft; ++ix) for (it=0; it<nt; ++it) p[ix][it] = 0.0; /* allocate and zero offset mix accumulator q(t,x) */ q = ealloc2float(nt,nx); for (ix=0; ix<nx; ++ix) for (it=0; it<nt; ++it) q[ix][it] = 0.0; /* open temporary file for headers */ hfp = tmpfile(); /* initialize */ oldoffset = offset; gottrace = 1; done = 0; ntrace = 0; noff = 0; /* get DMO stretch/squeeze factors s1 and s2 */ stretchfactor (sdmo,gamma,&s1,&s2); if(flip) { temps = s1; s1 = s2; s2 = temps; } /* print useful information if requested */ if (verbose)fprintf(stderr,"stretching factors: s1=%f s2=%f\n",s1,s2); /* loop over traces */ do { /* if got a trace, determine offset */ if (gottrace) offset = tr.offset; /* if an offset is complete */ if ((gottrace && offset!=oldoffset) || !gottrace) { /* do dmo for old common-offset gather */ dmooff(oldoffset,fmax,nx,dx,nt,dt,ft,vrms,p, gamma,boh,zoh,ntable,s1,s2,sign); /* add dmo-corrected traces to mix */ for (ix=0; ix<nx; ++ix) for (it=0; it<nt; ++it) q[ix][it] += p[ix][it]; /* count offsets in mix */ noff++; /* free space for old common-offset gather */ free2float(p); /* if beginning a new offset */ if (offset!=oldoffset) { /* allocate space for new offset */ nxpad = 0.5*ABS(offset/dx); nxfft = npfar(nx+nxpad); p = ealloc2float(nt,nxfft+2); for (ix=0; ix<nxfft; ++ix) for (it=0; it<nt; ++it) p[ix][it] = 0.0; } } /* if a mix of offsets is complete */ if (noff==noffmix || !gottrace) { /* rewind trace header file */ efseeko(hfp, (off_t) 0,SEEK_SET); /* loop over all output traces */ for (itrace=0; itrace<ntrace; ++itrace) { /* read trace header and determine cdp index */ efread(&tro,HDRBYTES,1,hfp); /* get dmo-corrected data */ memcpy((void *) tro.data, (const void *) q[tro.cdp-cdpmin], nt*sizeof(float)); /* write output trace */ puttr(&tro); } /* report */ if (verbose) fprintf(stderr,"\tCompleted mix of " "%d offsets with %d traces\n", noff,ntrace); /* if no more traces, break */ if (!gottrace) break; /* rewind trace header file */ efseeko(hfp, (off_t) 0,SEEK_SET); /* reset number of offsets and traces in mix */ noff = 0; ntrace = 0; /* zero offset mix accumulator */ for (ix=0; ix<nx; ++ix) for (it=0; it<nt; ++it) q[ix][it] = 0.0; } /* if cdp is within range to process */ if (tr.cdp>=cdpmin && tr.cdp<=cdpmax) { /* save trace header and update number of traces */ efwrite(&tr,HDRBYTES,1,hfp); ntrace++; /* remember offset */ oldoffset = offset; /* get trace samples */ memcpy((void *) p[tr.cdp-cdpmin], (const void *) tr.data, nt*sizeof(float)); } /* get next trace (if there is one) */ if (!gettr(&tr)) gottrace = 0; } while (!done); return(CWP_Exit()); }
int main(int argc, char **argv) { cwp_String key1,key2,key3; /* panel/trace/flag key */ cwp_String type1,type2,type3; /* type for panel/trace/flag key*/ int index1,index2,index3; /* indexes for key1/2/3 */ Value val1,val2,val3; /* value of key1/2/3 */ double dval1=0.0,dval2=0.0,dval3=0.0; /* value of key1/2/3 */ double c; /* trace key spacing */ double dmin,dmax,dx; /* trace key start/end/spacing */ double panelno=0.0,traceno=0.0; int nt; /* number of samples per trace */ int isgn; /* sort order */ int iflag; /* internal flag: */ /* -1 exit */ /* 0 regular mode */ /* 1 first time */ /* 2 trace out of range */ /* initialize */ initargs(argc, argv); requestdoc(1); /* get parameters */ if (!getparstring("key1", &key1)) key1 = "ep"; if (!getparstring("key2", &key2)) key2 = "tracf"; if (!getparstring("key3", &key3)) key3 = "trid"; if (!getpardouble("val3", &dval3)) dval3 = 2.; if (!getpardouble("d", &dx)) dx = 1.; if (!getpardouble("min", &dmin)) err("need lower panel boundary MIN"); if (!getpardouble("max", &dmax)) err("need upper panel boundary MAX"); checkpars(); /* check parameters */ if (dx==0) err("trace spacing d cannot be zero"); if (dmax<dmin) err("max needs to be greater than min"); if (dx<0) { isgn = -1; } else { isgn = 1; } /* get types and index values */ type1 = hdtype(key1); type2 = hdtype(key2); type3 = hdtype(key3); index1 = getindex(key1); index2 = getindex(key2); index3 = getindex(key3); /* loop over traces */ iflag = 1; while (iflag>=0) { if (gettr(&tr)) { /* get header values */ gethval(&tr, index1, &val1); gethval(&tr, index2, &val2); dval1 = vtod(type1, val1); dval2 = vtod(type2, val2); /* Initialize zero trace */ nt = tr.ns; memset( (void *) nulltr.data, 0, nt*FSIZE); if ( iflag==1 ) { panelno = dval1; traceno = dmin - dx; } iflag = 0; if ( dval2<dmin || dval2>dmax ) iflag = 2; /* fprintf(stderr,"if=%d, dmin=%8.0f, dmax=%8.0f\n",iflag,dmin,dmax);*/ } else { iflag = -1; /* exit flag */ } /* fprintf(stderr,"if=%d, dval1=%8.0f, dval2=%8.0f\n",iflag,dval1,dval2);*/ /* if new panel or last trace --> finish the previous panel */ if ( panelno!=dval1 || iflag==-1 ) { /* fprintf(stderr,"finish previous\n");*/ for (c=traceno+dx; isgn*c<=isgn*dmax; c=c+dx) { assgnval(type2, &val2, c); puthval(&nulltr, index2, &val2); assgnval(type3, &val3, dval3); puthval(&nulltr, index3, &val3); puttr(&nulltr); } traceno = dmin - dx; /* reset to pad present panel */ panelno = dval1; /* added by Ted Stieglitz 28Nov2012*/ } /* if trace within boundaries --> pad the present panel */ if ( iflag==0 ) { /* fprintf(stderr,"pad present, trn=%5.0f,dval2=%5.0f\n",traceno,dval2);*/ memcpy( (void *) &nulltr, (const void *) &tr, 240); for (c=traceno+dx; isgn*c<isgn*dval2; c=c+dx) { assgnval(type2, &val2, c); puthval(&nulltr, index2, &val2); assgnval(type3, &val3, dval3); puthval(&nulltr, index3, &val3); puttr(&nulltr); } } /* write the present trace and save header indices */ if ( iflag==0 ) { puttr(&tr); panelno = dval1; traceno = dval2; } } return(CWP_Exit()); }
int main(int argc, char **argv) { char *key=NULL; /* header key word from segy.h */ char *type=NULL; /* ... its type */ int index; /* ... its index */ Value val; /* ... its value */ float fval; /* ... its value cast to float */ float twfval; /* ... its value cast to float */ float *xmute=NULL; /* array of key mute curve values */ float *tmute=NULL; /* ... mute curve time values */ float *twindow=NULL; /* ... mute window time values mode=4 */ float linvel; /* linear velocity */ float tm0; /* time shift of mute=2 or 3 for 'key'=0*/ float *taper=NULL; /* ... taper values */ int nxmute=0; /* number of key mute values */ int ntmute; /* ... mute time values */ int ntwindow; /* ... mute time values */ int ntaper; /* ... taper values */ int below; /* mute below curve */ int mode; /* kind of mute (top, bottom, linear) */ int absolute; /* Take absolute value of key for mode=2 */ int hmute=0; /* read mute times from header */ int nxtmute; /* number of mute values */ cwp_String xfile=""; /* file containing positions by key */ FILE *xfilep; /* ... its file pointer */ cwp_String tfile=""; /* file containing times */ FILE *tfilep; /* ... its file pointer */ cwp_String twfile=""; /* file containing mute time windows */ FILE *twfilep; /* ... its file pointer */ cwp_Bool seismic; /* cwp_true if seismic, cwp_false not seismic */ /* Initialize */ initargs(argc, argv); requestdoc(1); /* Get parameters */ if (!getparint("mode", &mode)) mode = 0; if (getparstring("hmute", &key)) { hmute = 1; } else if (!(getparstring("xfile",&xfile) && getparstring("tfile",&tfile))) { if (!(nxmute = countparval("xmute"))) err("must give xmute= vector"); if (!(ntmute = countparval("tmute"))) err("must give tmute= vector"); if (nxmute != ntmute) err("lengths of xmute, tmute must be the same"); xmute = ealloc1float(nxmute); getparfloat("xmute", xmute); tmute = ealloc1float(nxmute); getparfloat("tmute", tmute); if (mode==4) { if (!(ntwindow = countparval("twindow"))) err("must give twindow= vector"); if (nxmute != ntwindow) err("lengths of xmute, twindow must be the same"); twindow = ealloc1float(nxmute); getparfloat("twindow", twindow); } } else { MUSTGETPARINT("nmute",&nxtmute); nxmute = nxtmute; xmute = ealloc1float(nxtmute); tmute = ealloc1float(nxtmute); if((xfilep=fopen(xfile,"r"))==NULL) err("cannot open xfile=%s\n",xfile); if (fread(xmute,sizeof(float),nxtmute,xfilep)!=nxtmute) err("error reading xfile=%s\n",xfile); fclose(xfilep); if((tfilep=fopen(tfile,"r"))==NULL) err("cannot open tfile=%s\n",tfile); if (fread(tmute,sizeof(float),nxtmute,tfilep)!=nxtmute) err("error reading tfile=%s\n",tfile); fclose(tfilep); if (mode==4) { if((twfilep=fopen(twfile,"r"))==NULL) err("cannot open tfile=%s\n",twfile); if (fread(twindow,sizeof(float),nxtmute,twfilep)!=nxtmute) err("error reading tfile=%s\n",tfile); fclose(twfilep); } } if (!getparint("ntaper", &ntaper)) ntaper = 0; if (getparint("below", &below)) { mode = below; warn ("use of below parameter is obsolete. mode value set to %d \n", mode); } if (!getparint("absolute", &absolute)) absolute = 1; if (hmute==0) if (!getparstring("key", &key)) key = "offset"; if (!getparfloat("linvel", &linvel)) linvel = 330; if (!getparfloat("tm0", &tm0)) tm0 = 0; checkpars(); if (linvel==0) err ("linear velocity can't be 0"); /* get key type and index */ type = hdtype(key); index = getindex(key); /* Set up taper weights if tapering requested */ if (ntaper) { register int k; taper = ealloc1float(ntaper); for (k = 0; k < ntaper; ++k) { float s = sin((k+1)*PI/(2*ntaper)); taper[k] = s*s; } } /* Get info from first trace */ if (!gettr(&tr)) err("can't read first trace"); seismic = ISSEISMIC(tr.trid); if (seismic) { if (!tr.dt) err("dt header field must be set"); } else if (tr.trid==TRID_DEPTH) { /* depth section */ if (!tr.d1) err("d1 header field must be set"); } else { err ("tr.trid = %d, unsupported trace id",tr.trid); } /* Loop over traces */ do { int nt = (int) tr.ns; float tmin = tr.delrt/1000.0; float dt = ((double) tr.dt)/1000000.0; float t; float tw; int nmute; int itaper; int topmute; int botmute; int ntair=0; register int i; if (!seismic) { tmin = 0.0; dt = tr.d1; } /* get value of key and convert to float */ gethval(&tr, index, &val); fval = vtof(type,val); if (hmute==1) { t = fval/1000.; } else { /* linearly interpolate between (xmute,tmute) values */ intlin(nxmute,xmute,tmute,tmin,tmute[nxmute-1],1,&fval,&t); } if (absolute) fval = abs(fval); /* do the mute */ if (mode==0) { /* mute above */ nmute = MIN(NINT((t - tmin)/dt),nt); if (nmute>0) memset( (void *) tr.data, 0, nmute*FSIZE); for (i = 0; i < ntaper; ++i) if (i+nmute>0) tr.data[i+nmute] *= taper[i]; if (seismic) { tr.muts = NINT(t*1000); } else { tr.muts = NINT(t); } } else if (mode==1){ /* mute below */ nmute = MAX(0,NINT((tmin + nt*dt - t)/dt)); memset( (void *) (tr.data+nt-nmute), 0, nmute*FSIZE); for (i = 0; i < ntaper; ++i) if (nt>nmute+i && nmute+i>0) tr.data[nt-nmute-1-i] *= taper[i]; if (seismic) { tr.mute = NINT(t*1000); } else { tr.mute = NINT(t); } } else if (mode==2){ /* air wave mute */ nmute = NINT((tmin+t)/dt); ntair=NINT(tm0/dt+fval/linvel/dt); topmute=MIN(MAX(0,ntair-nmute/2),nt); botmute=MIN(nt,ntair+nmute/2); memset( (void *) (tr.data+topmute), 0, (botmute-topmute)*FSIZE); for (i = 0; i < ntaper; ++i){ itaper=ntair-nmute/2-i; if (itaper > 0) tr.data[itaper] *=taper[i]; } for (i = 0; i < ntaper; ++i){ itaper=ntair+nmute/2+i; if (itaper<nt) tr.data[itaper] *=taper[i]; } } else if (mode==3) { /* hyperbolic mute */ nmute = NINT((tmin + t)/dt); ntair=NINT(sqrt( SQ((float)(tm0/dt))+SQ((float)(fval/linvel/dt)) )); topmute=MIN(MAX(0,ntair-nmute/2),nt); botmute=MIN(nt,ntair+nmute/2); memset( (void *) (tr.data+topmute), 0, (botmute-topmute)*FSIZE); for (i = 0; i < ntaper; ++i){ itaper=ntair-nmute/2-i; if (itaper > 0) tr.data[itaper] *=taper[i]; } for (i = 0; i < ntaper; ++i){ itaper=ntair+nmute/2+i; if (itaper<nt) tr.data[itaper] *=taper[i]; } } else if (mode==4) { /* polygonal mute */ tmin=twindow[0]; intlin(nxmute,xmute,twindow,tmin,twindow[nxmute-1],1,&twfval,&tw); if (absolute) twfval = abs(twfval); nmute = NINT(tw/dt); ntair = NINT(t/dt); topmute=MIN(MAX(0,ntair-nmute/2),nt); botmute=MIN(nt,ntair+nmute/2); memset( (void *) (tr.data+topmute), 0, (botmute-topmute)*FSIZE); for (i = 0;i < ntaper; ++i){ itaper=ntair-nmute/2-i; if (itaper > 0) tr.data[itaper] *=taper[i]; } for (i = 0; i < ntaper; ++i){ itaper=ntair+nmute/2+i; if (itaper<nt) tr.data[itaper] *=taper[i]; } } puttr(&tr); } while (gettr(&tr)); return(CWP_Exit()); }
int main(int argc, char **argv) { int nx,nz,ix,iz,verbose; float tmp; float **c11,**c13,**c33,**c44,**vp,**vs,**rho,**eps, **delta; /* input files */ char *c11_file, *c13_file, *c33_file, *c44_file; FILE *c11fp, *c13fp, *c33fp, *c44fp; /* output files */ char *vp_file,*vs_file,*rho_file,*eps_file,*delta_file; FILE *vpfp,*vsfp,*rhofp,*epsfp,*deltafp; /* hook up getpar */ initargs(argc, argv); requestdoc(1); /* get required parameters */ MUSTGETPARINT("nx", &nx ); MUSTGETPARINT("nz", &nz ); /* get parameters */ if (!getparstring("rho_file", &rho_file)) rho_file="rho.bin"; if (!getparstring("c11_file", &c11_file)) c11_file="c11.bin"; if (!getparstring("c13_file", &c13_file)) c13_file="c13.bin"; if (!getparstring("c33_file", &c33_file)) c33_file="c33.bin"; if (!getparstring("c44_file", &c44_file)) c44_file="c44.bin"; if (!getparstring("vp_file", &vp_file)) vp_file="vp.bin"; if (!getparstring("vs_file", &vs_file)) vs_file="vs.bin"; if (!getparstring("eps_file", &eps_file)) eps_file="eps.bin"; if (!getparstring("delta_file", &delta_file)) delta_file="delta.bin"; if (!getparint("verbose", &verbose)) verbose = 1; checkpars(); /* allocate space */ rho = alloc2float(nz,nx); c11 = alloc2float(nz,nx); c13 = alloc2float(nz,nx); c33 = alloc2float(nz,nx); c44 = alloc2float(nz,nx); vp = alloc2float(nz,nx); vs = alloc2float(nz,nx); eps = alloc2float(nz,nx); delta = alloc2float(nz,nx); /* read mandatory input files */ rhofp = efopen(rho_file,"r"); if (efread(*rho, sizeof(float), nz*nx, rhofp)!=nz*nx) err("error reading rho_file=%s!\n",rho_file); c11fp = efopen(c11_file,"r"); if (efread(*c11, sizeof(float), nz*nx, c11fp)!=nz*nx) err("error reading c11_file=%s!\n",c11_file); c13fp = efopen(c13_file,"r"); if (efread(*c13, sizeof(float), nz*nx, c13fp)!=nz*nx) err("error reading c13_file=%s!\n",c13_file); c33fp = efopen(c33_file,"r"); if (efread(*c33, sizeof(float), nz*nx, c33fp)!=nz*nx) err("error reading c33_file=%s!\n",c33_file); c44fp = efopen(c44_file,"r"); if (efread(*c44, sizeof(float), nz*nx, c44fp)!=nz*nx) err("error reading c44_file=%s!\n",c44_file); fclose(rhofp); fclose(c11fp); fclose(c13fp); fclose(c33fp); fclose(c44fp); /* open output file: */ vpfp = fopen(vp_file,"w"); vsfp = fopen(vs_file,"w"); epsfp = fopen(eps_file,"w"); deltafp = fopen(delta_file,"w"); /* loop over gridpoints and do calculations */ for(ix=0; ix<nx; ++ix){ for(iz=0; iz<nz; ++iz){ vp[ix][iz] = sqrt(c33[ix][iz]/rho[ix][iz]); vs[ix][iz] = sqrt(c44[ix][iz]/rho[ix][iz]); eps[ix][iz] = (c11[ix][iz]-c33[ix][iz])/(2*c33[ix][iz]); tmp = (c13[ix][iz]+c44[ix][iz])*(c13[ix][iz]+c44[ix][iz]); tmp = tmp - (c33[ix][iz]-c44[ix][iz])*(c33[ix][iz]-c44[ix][iz]); delta[ix][iz] = tmp/(2*c33[ix][iz]*(c33[ix][iz]-c44[ix][iz])); } } /* write the output files to disk */ efwrite(*vp,sizeof(float),nz*nx,vpfp); efwrite(*vs,sizeof(float),nz*nx,vsfp); efwrite(*eps,sizeof(float),nz*nx,epsfp); efwrite(*delta,sizeof(float),nz*nx,deltafp); if(verbose){ warn("Output file for vp : %s ",vp_file); warn("Output file for vs : %s ",vs_file); warn("Output file for epsilon : %s ",eps_file); warn("Output file for delta : %s ",delta_file); } /* free workspace */ free2float(vp); free2float(vs); free2float(rho); free2float(eps); free2float(delta); free2float(c11); free2float(c13); free2float(c33); free2float(c44); return(CWP_Exit()); }
int main (int argc, char **argv) { char **text,**font,*textcolor,*boxcolor; float size,labelCD=0.0,labelCA,labelCW=0.0,labelCH,bigx,bigy,eps,eps2; float *x; int n,j,nsub; size_t nchar; /* Hook up getpars */ initargs(argc,argv); requestdoc(0); /* Get parameters */ if(!getparint("nsub",&nsub))nsub=0; if(!getparfloat("size",&size))size=30; if(!getparstring("tcolor",&textcolor))textcolor="black"; if(!getparstring("bcolor",&boxcolor))boxcolor="white"; checkpars(); eps=0.25*size; eps2=0.1*size; n=countparname("t"); if(n==0) err("must enter at least one PSTEXT text stream as parameter t"); if(n!=countparname("f")) warn("suggest specify same number of values for t and f"); text =(char **)malloc( (n+1)*sizeof(char *) ); font =(char **)malloc( (n+1)*sizeof(char *) ); x = (float *)malloc( (n+1)*sizeof(float) ); for(bigx=eps,bigy=0.,j=0;j<n;j++){ x[j]=bigx; if(!getnparstring(j+1,"t",&text[j]))text[j]="hello"; if(!getnparstring(j+1,"f",&font[j]))font[j]="Times-Bold"; labelCH = fontheight(font[j],size); labelCW = fontwidth(font[j],size); labelCA = fontascender(font[j],size); labelCD = MIN(labelCD,fontdescender(font[j],size)); nchar = strlen(text[j]); bigx+=0.5*(((double) nchar)*labelCW); bigy=MAX(bigy,labelCH+eps+0.0*labelCA); } bigx+=eps; bigx-=0.5*nsub*labelCW; /* open output eps file */ boundingbox(-eps2,-eps2,bigx+eps2,bigy+eps2); begineps(); gsave(); rectclip(0.,0.,bigx,bigy); /* fill background box with background color */ newpath(); moveto(0.,0.); lineto(bigx,0.); lineto(bigx,bigy); lineto(0.,bigy); closepath(); setcolor(boxcolor); fill(); /* write out text strings */ setcolor(textcolor); moveto(eps,eps-labelCD); for(j=0;j<n;j++) { setfont(font[j],size); show(text[j]); } /* close output stream */ grestore(); showpage(); endeps(); return EXIT_SUCCESS; }