/* Break up reflectors by duplicating interior (x,z) points */ void breakReflectors (int *nr, float **ar, int **nu, float ***xu, float ***zu) { int nri,nro,*nui,*nuo,ir,jr,iu; float *ari,*aro,**xui,**zui,**xuo,**zuo; /* input reflectors */ nri = *nr; ari = *ar; nui = *nu; xui = *xu; zui = *zu; /* number of output reflectors */ for (ir=0,nro=0; ir<nri; ++ir) nro += nui[ir]-1; /* make output reflectors and free space for input reflectors */ aro = ealloc1float(nro); nuo = ealloc1int(nro); xuo = ealloc1(nro,sizeof(float*)); zuo = ealloc1(nro,sizeof(float*)); for (ir=0,jr=0; ir<nri; ++ir) { for (iu=0; iu<nui[ir]-1; ++iu,++jr) { aro[jr] = ari[ir]; nuo[jr] = 2; xuo[jr] = ealloc1float(2); zuo[jr] = ealloc1float(2); xuo[jr][0] = xui[ir][iu]; zuo[jr][0] = zui[ir][iu]; xuo[jr][1] = xui[ir][iu+1]; zuo[jr][1] = zui[ir][iu+1]; } free1float(xui[ir]); free1float(zui[ir]); } free1float(ari); free1int(nui); free1(xui); free1(zui); /* output reflectors */ *nr = nro; *ar = aro; *nu = nuo; *xu = xuo; *zu = zuo; }
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 *xshift=NULL; /* array of key shift curve values */ float *tshift=NULL; /* ... shift curve time values */ int nxshift; /* number of key shift values */ int ntshift; /* ... shift time values */ int nxtshift; /* number of shift values */ int it; /* sample counter */ int itr; /* trace counter */ int nt; /* number of time samples */ int ntr=0; /* number of traces */ int *inshift=NULL; /* array of (integer) time shift values used for positioning shifted trace in data[][] */ float dt; /* time sampling interval */ cwp_String xfile=""; /* file containing positions by key */ FILE *xfilep=NULL; /* ... its file pointer */ cwp_String tfile=""; /* file containing times */ FILE *tfilep=NULL; /* ... its file pointer */ int verbose; /* flag for printing information */ char *tmpdir=NULL; /* directory path for tmp files */ cwp_Bool istmpdir=cwp_false;/* true for user-given path */ int median; /* flag for median filter */ int nmed; /* no. of traces to median filter */ int nmix; /* number of traces to mix over */ int imix; /* mixing counter */ float *mix=NULL; /* array of mix values */ int sign; /* flag for up/down shift */ int shiftmin=0; /* minimum time shift (in samples) */ int shiftmax=0; /* maximum time shift (in samples) */ int ntdshift; /* nt + shiftmax */ size_t mixbytes; /* size of mixing array */ size_t databytes; /* size of data array */ size_t shiftbytes; /* size of data array */ float *temp=NULL; /* temporary array */ float *dtemp=NULL; /* temporary array */ float *stemp=NULL; /* rwh median sort array */ float **data=NULL; /* mixing array */ int subtract; /* flag for subtracting shifted data */ /* rwh extra pointers for median sort */ int first; /* start pointer in ring buffer */ int middle; /* middle pointer in ring buffer */ int last; /* last pointer in ring buffer */ int halfwidth; /* mid point */ int trcount; /* pointer to current start trace number */ float tmp; /* temp storage for bubble sort */ int rindex; /* wrap around index for ring buffer */ int jmix; /* internal pointer for bubble sort */ /* Initialize */ initargs(argc, argv); requestdoc(1); /* Get parameters */ if (!(getparstring("xfile",&xfile) && getparstring("tfile",&tfile))) { if (!(nxshift = countparval("xshift"))) err("must give xshift= vector"); if (!(ntshift = countparval("tshift"))) err("must give tshift= vector"); if (nxshift != ntshift) err("lengths of xshift, tshift must be the same"); xshift = ealloc1float(nxshift); getparfloat("xshift", xshift); tshift = ealloc1float(nxshift); getparfloat("tshift", tshift); } else { MUSTGETPARINT("nshift",&nxtshift); nxshift = nxtshift; xshift = ealloc1float(nxtshift); tshift = ealloc1float(nxtshift); if((xfilep=fopen(xfile,"r"))==NULL) err("cannot open xfile=%s\n",xfile); if (fread(xshift,sizeof(float),nxtshift,xfilep)!=nxtshift) err("error reading xfile=%s\n",xfile); fclose(xfilep); if((tfilep=fopen(tfile,"r"))==NULL) err("cannot open tfile=%s\n",tfile); if (fread(tshift,sizeof(float),nxtshift,tfilep)!=nxtshift) err("error reading tfile=%s\n",tfile); fclose(tfilep); } if (!getparstring("key", &key)) key = "tracl"; /* Get key type and index */ type = hdtype(key); index = getindex(key); /* Get mix weighting values values */ if ((nmix = countparval("mix"))!=0) { mix = ealloc1float(nmix); getparfloat("mix",mix); /* rwh check nmix is odd */ if (nmix%2==0) { err("number of mixing coefficients must be odd"); } } else { nmix = 5; mix = ealloc1float(nmix); mix[0] = VAL0; mix[1] = VAL1; mix[2] = VAL2; mix[3] = VAL3; mix[4] = VAL4; } /* Get remaning parameters */ if (!getparint("median",&median)) median = 0; if (!getparint("nmed",&nmed) && median) nmed = 5; if (!getparint("sign",&sign)) sign = -1; if (!getparint("subtract",&subtract)) subtract = 1; if (!getparint("verbose", &verbose)) verbose = 0; /* rwh check nmed is odd */ if (median && nmed%2==0) { nmed=nmed+1; warn("increased nmed by 1 to ensure it is odd"); } /* 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); /* rwh fix for median filter if median true set nmix=nmed */ if (!median) { /* Divide mixing weights by number of traces to mix */ for (imix = 0; imix < nmix; ++imix) mix[imix]=mix[imix]/((float) nmix); } else { nmix=nmed; } /* Get info from first trace */ if (!gettr(&tr)) err("can't read first trace"); if (!tr.dt) err("dt header field must be set"); dt = ((double) tr.dt)/1000000.0; nt = (int) tr.ns; databytes = FSIZE*nt; /* Tempfiles */ 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); } /* Read headers and data while getting a count */ do { ++ntr; efwrite(&tr, 1, HDRBYTES, headerfp); efwrite(tr.data, 1, databytes, tracefp); } while (gettr(&tr)); rewind(headerfp); rewind(tracefp); /* Allocate space for inshift vector */ inshift = ealloc1int(ntr); /* Loop over headers */ for (itr=0; itr<ntr; ++itr) { float tmin=tr.delrt/1000.0; float t; /* Read header values */ efread(&tr, 1, HDRBYTES, headerfp); /* Get value of key and convert to float */ gethval(&tr, index, &val); fval = vtof(type,val); /* Linearly interpolate between (xshift,tshift) values */ intlin(nxshift,xshift,tshift,tmin,tshift[nxshift-1],1,&fval,&t); /* allow for fractional shifts -> requires interpolation */ inshift[itr] = NINT((t - tmin)/dt); /* Find minimum and maximum shifts */ if (itr==0) { shiftmax=inshift[0]; shiftmin=inshift[0]; } else { shiftmax = MAX(inshift[itr],shiftmax); shiftmin = MIN(inshift[itr],shiftmin); } } rewind(headerfp); rewind(tracefp); if (verbose) { for (itr=0;itr<ntr;itr++) warn("inshift[%d]=%d",itr,inshift[itr]); } /* Compute databytes per trace and bytes in mixing panel */ ntdshift = nt + shiftmax; shiftbytes = FSIZE*ntdshift; mixbytes = shiftbytes*nmix; if (verbose) { warn("nt=%d shiftmax=%d shiftmin=%d",nt,shiftmax,shiftmin); warn("ntdshift=%d shiftbytes=%d mixbytes=%d", ntdshift,shiftbytes,mixbytes); } /* Allocate space and zero data array */ data = ealloc2float(ntdshift,nmix); temp = ealloc1float(ntdshift); dtemp = ealloc1float(nt); memset( (void *) data[0], 0, mixbytes); /* rwh array for out of place bubble sort (so we do not corrupt order in ring buffer */ stemp = ealloc1float(nmix); /* rwh first preload ring buffer symmetrically (now you know why nmix must be odd) */ trcount=-1; halfwidth=(nmix-1)/2+1; first = 0; last = nmix-1; middle = (nmix-1)/2; for (itr=0; itr<halfwidth; itr++) { efread(tr.data, 1, databytes, tracefp); trcount++; for(it=0; it<nt; ++it) { /* sign to account for positive or negative shift */ /* tr.data needs to be interpolated for non-integer shifts */ data[middle-itr][it + shiftmax + sign*inshift[itr]] = tr.data[it]; data[middle+itr][it + shiftmax + sign*inshift[itr]] = tr.data[it]; } } /* Loop over traces performing median filtering */ for (itr=0; itr<ntr; ++itr) { /* paste header and data on output trace */ efread(&tr, 1, HDRBYTES, headerfp); /* Zero out temp and dtemp */ memset((void *) temp, 0, shiftbytes); memset((void *) dtemp, 0, databytes); /* Loop over time samples */ for (it=0; it<nt; ++it) { /* Weighted moving average (mix) ? */ if (!median) { for(imix=0; imix<nmix; ++imix) { temp[it] += data[imix][it] * mix[imix]; } } else { /* inlcude median stack */ /* rwh do bubble sort and choose median value */ for(imix=0; imix<nmix; ++imix) { stemp[imix]=data[imix][it]; } for (imix=0; imix<nmix-1; imix++) { for (jmix=0; jmix<nmix-1-imix; jmix++) { if (stemp[jmix+1] < stemp[jmix]) { tmp = stemp[jmix]; stemp[jmix] = stemp[jmix+1]; stemp[jmix+1] = tmp; } } } temp[it] = stemp[middle]; } /* shift back mixed data and put into dtemp */ if (subtract) { if ((it - shiftmax - sign*inshift[itr])>=0) dtemp[it - shiftmax - sign*inshift[itr]] = data[middle][it]-temp[it]; } else { if ((it - shiftmax)>=0) dtemp[it - shiftmax - sign*inshift[itr]] = temp[it]; } } memcpy((void *) tr.data,(const void *) dtemp,databytes); /* Bump rows of data[][] over by 1 to free first row for next tr.data */ for (imix=nmix-1; 0<imix; --imix) memcpy((void *) data[imix],(const void *) data[imix-1],shiftbytes); /*for (it=0; it<nt; ++it) data[imix][it] = data[imix-1][it];*/ /* Write output trace */ tr.ns = nt; puttr(&tr); /* read next trace into buffer */ if (trcount < ntr) { efread(tr.data, 1, databytes, tracefp); trcount++; /* read tr.data into first row of mixing array */ /* WMH: changed ntdshift to nt */ for(it=0; it<nt; ++it) { /* sign to account for positive or negative shift */ /* tr.data needs to be interpolated for non-integer shifts */ data[0][it + shiftmax + sign*inshift[trcount]] = tr.data[it]; } } else { rindex=2*(trcount-ntr); memcpy((void *) data[0],(const void *) data[rindex],shiftbytes); trcount++; } } if (verbose && subtract) warn("filtered data subtracted from input"); /* Clean up */ efclose(headerfp); if (istmpdir) eremove(headerfile); efclose(tracefp); if (istmpdir) eremove(tracefile); return(CWP_Exit()); }
int main(int argc, char **argv) { int verbose; time_t start,finish; double elapsed_time; int ix,nt,nx,nx_out; float dt,dh,hmin,hmax; float *h,*h_out; float **din,**dout,**din_tw,**dout_tw; int *ih,*ih_out; int padt,padx; int Ltw,Dtw; int twstart; float taper; int itw,Itw,Ntw,niter; float fmin,fmax; /********/ fprintf(stderr,"*******SUALFT*********\n"); /* Initialize */ initargs(argc, argv); requestdoc(1); start=time(0); /* Get parameters */ if (!getparint("verbose", &verbose)) verbose = 0; if (!getparint("nx", &nx)) nx = 10000; if (!getparfloat("dh", &dh)) dh = 10; if (!gettr(&tr)) err("can't read first trace"); if (!tr.dt) err("dt header field must be set"); if (!tr.ns) err("ns header field must be set"); if (!getparint("Ltw", &Ltw)) Ltw = 200; /* length of time window in samples */ if (!getparint("Dtw", &Dtw)) Dtw = 10; /* overlap of time windows in samples */ dt = ((float) tr.dt)/1000000.0; nt = (int) tr.ns; if (!getparint("padt", &padt)) padt = 2; /* padding factor in time dimension*/ if (!getparint("padx", &padx)) padx = 2; /* padding factor in spatial dimension*/ if (!getparfloat("fmin",&fmin)) fmin = 0; if (!getparfloat("fmax",&fmax)) fmax = 0.5/dt; if (!getparint("niter", &niter)) niter = 100; fmax = MIN(fmax,0.5/dt); din = ealloc2float(nt,nx); h = ealloc1float(nx); ih = ealloc1int(nx); /* *********************************************************************** input data *********************************************************************** */ ix=0; do { h[ix]=(float) tr.offset; memcpy((void *) din[ix],(const void *) tr.data,nt*sizeof(float)); ix++; if (ix > nx) err("Number of traces > %d\n",nx); } while (gettr(&tr)); erewind(stdin); nx=ix; if (verbose) fprintf(stderr,"processing %d traces \n", nx); hmin = h[0]; hmax = h[0]; for (ix=0;ix<nx;ix++){ if (hmin>h[ix]) hmin = h[ix]; if (hmax<h[ix]) hmax = h[ix]; } for (ix=0;ix<nx;ix++){ ih[ix] = (int) truncf((h[ix]-hmin)/dh); } nx_out = 0; for (ix=0;ix<nx;ix++){ if (nx_out<ih[ix]) nx_out = ih[ix] + 1; } nx_out = nx_out + 1; ih_out = ealloc1int(nx_out); h_out = ealloc1float(nx_out); for (ix=0;ix<nx_out;ix++){ ih_out[ix] = ix; h_out[ix] = ix*dh + hmin; } dout = ealloc2float(nt,nx_out); Ntw = 9999; /* number of time windows (will be updated during first iteration to be consistent with total number of time samples and the length of each window) */ din_tw = ealloc2float(Ltw,nx); dout_tw = ealloc2float(Ltw,nx_out); /*********************************************************************** process using sliding time windows ***********************************************************************/ twstart = 0; taper = 0; for (Itw=0;Itw<Ntw;Itw++){ if (Itw == 0){ Ntw = (int) truncf(nt/(Ltw-Dtw)); if ( (float) nt/(Ltw-Dtw) - (float) Ntw > 0) Ntw++; } twstart = (int) Itw * (int) (Ltw-Dtw); if ((twstart+Ltw-1 >nt) && (Ntw > 1)){ twstart=nt-Ltw; } if (Itw*(Ltw-Dtw+1) > nt){ Ltw = (int) Ltw + nt - Itw*(Ltw-Dtw+1); } for (ix=0;ix<nx;ix++){ for (itw=0;itw<Ltw;itw++){ din_tw[ix][itw] = din[ix][twstart+itw]; } } fprintf(stderr,"processing time window %d of %d\n",Itw+1,Ntw); if (verbose) fprintf(stderr,"Ltw=%d\n",Ltw); if (verbose) fprintf(stderr,"Dtw=%d\n",Dtw); process_time_window(din_tw,dout_tw,h,h_out,hmin,hmax,dt,Ltw,nx,nx_out,fmin,fmax,niter,padt,padx,verbose); if (Itw==0){ for (ix=0;ix<nx_out;ix++){ for (itw=0;itw<Ltw;itw++){ dout[ix][twstart+itw] = dout_tw[ix][itw]; } } } else{ for (ix=0;ix<nx_out;ix++){ for (itw=0;itw<Dtw;itw++){ /* taper the top of the time window */ taper = (float) ((Dtw-1) - itw)/(Dtw-1); dout[ix][twstart+itw] = dout[ix][twstart+itw]*(taper) + dout_tw[ix][itw]*(1-taper); } for (itw=Dtw;itw<Ltw;itw++){ dout[ix][twstart+itw] = dout_tw[ix][itw]; } } } } /*********************************************************************** end of processing time windows ***********************************************************************/ /* *********************************************************************** output data *********************************************************************** */ rewind(stdin); for (ix=0;ix<nx_out;ix++){ memcpy((void *) tr.data,(const void *) dout[ix],nt*sizeof(float)); tr.offset=(int) h_out[ix]; tr.ntr=nx_out; tr.ns=nt; tr.dt = NINT(dt*1000000.); tr.tracl = ix+1; tr.tracr = ix+1; fputtr(stdout,&tr); } /******** End of output **********/ finish=time(0); elapsed_time=difftime(finish,start); fprintf(stderr,"Total time required: %6.2fs\n", elapsed_time); free1float(h); free1float(h_out); free2float(din); free2float(dout); free1int(ih); free1int(ih_out); free2float(din_tw); free2float(dout_tw); return EXIT_SUCCESS; }
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; }
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; 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 */ conv(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) { int n1; /*number of samples in the fastest direction.*/ int n2; /*number of samples in the 2nd direction*/ int n3; /*number of samples in slownest direction*/ int n1s; /*stride in the fastest direction.*/ int n2s; /*stride in the 2nd direction*/ int n3s; /*stride in slownest direction*/ int i1,i2,i3; int i1min,i1max; /*indice for min max in n1*/ int i2min,i2max; /*indice for min max in n2*/ int i3min,i3max; /*indice for min max in n3*/ int newn1,newn2,newn3; int i1new,i2new,i3new; float v0; float emission[4]; float ***data; /*data for plotting*/ float ***emis; /*emission for plotting*/ int verbose; /*if =1 print some useful information*/ float ***cube; /*the 3D data set*/ float vmin; float vmax; float xmin,xmax; float ymin,ymax; float zmin,zmax; float eyez; float q0[4]; int cx,cy,cz; /*center of the 1st, 2nd and 3rd view plane*/ /* hook up getpar */ initargs(argc,argv); requestdoc(1); /* get parameters */ if (!getparint("n1",&n1)) err("Must specify n1"); if (!getparint("n2",&n2)) err("Must specify n2\n"); if (!getparint("n3",&n3)) err("Must specify n3\n"); if (!getparint("n1s",&n1s)) n1s=1; if (!getparint("n2s",&n2s)) n2s=1; if (!getparint("n3s",&n3s)) n3s=1; if (!getparint("hue",&glb_hue)) glb_hue=1; /*1 for glb_hue*/ if (!getparfloat("tbs",&tbs)) tbs=0.8; if (glb_hue!=0) glb_hue=1; if (n1<1) err("n1=%d < 1",n1); if (n2<1) err("n2=%d < 1",n2); if (n3<1) err("n3=%d < 1",n3); n1s=MAX(1,n1s); n1s=MIN(n1,n1s); n2s=MAX(1,n2s); n2s=MIN(n2,n2s); n3s=MAX(1,n3s); n3s=MIN(n3,n3s); newn1=MAX(2,n1/n1s); newn2=MAX(2,n2/n2s); newn3=MAX(2,n3/n3s); if (!getparint("verbose",&verbose)) verbose=0; if (!getparint("cx",&cx)) cx=n2/2; if (!getparint("cy",&cy)) cy=n3/2; if (!getparint("cz",&cz)) cz=n1/2; cx=MAX(0,MIN(newn2-1,cx/n2s)); cy=MAX(0,MIN(newn3-1,cy/n3s)); cz=MAX(0,MIN(newn1-1,cz/n1s)); if (verbose) { warn("newn1=%d\nnewn2=%d\nnewn3=%d\ncx=%d\ncy=%d\ncz=%d", newn1,newn2,newn3,cx,cy,cz); warn("hue=%d",glb_hue); } cube=ealloc3float(newn1,newn2,newn3); for (i3=0;i3<n3;i3++) { for (i2=0;i2<n2;i2++) { for (i1=0;i1<n1;i1++) { if (fread(&v0,sizeof(float),1,stdin)!=1) err("Can not read in cube"); if ( i3%n3s==0 && i2%n2s==0 && i1%n1s==0) { i3new=MIN(newn3-1,i3/n3s); i2new=MIN(newn2-1,i2/n2s); i1new=MIN(newn1-1,i1/n1s); cube[i3new][i2new][i1new]=v0; if (n1/n1s<2) cube[i3new][i2new][1]=cube[i3new][i2new][0]; if (n2/n2s<2) cube[i3new][1][i1new]=cube[i3new][0][i1new]; if (n3/n3s<2) cube[1][i2new][i1new]=cube[0][i2new][i1new]; } } } } n1=newn1; n2=newn2; n3=newn3; zmin=0; zmax=MAX(n1-1,1); ymin=0; ymax=MAX(n3-1,1); xmin=0; xmax=MAX(n2-1,1); glb_plane_flag=(enum On_or_Off *)ealloc1int(3); glb_plane_flag[2]=OFF; glb_plane_flag[1]=ON; glb_plane_flag[0]=OFF; glb_plot_axis=DO_NOT_PLOT_AXIS; vmin=cube[0][0][0]; vmax=vmin; i1min=i2min=i3min=0; i1max=i2max=i3max=0; for (i1=0;i1<n1;i1++) { for (i2=0;i2<n2;i2++) { for (i3=0;i3<n3;i3++) { if (vmin<cube[i3][i2][i1]) { i3min=i3; i2min=i2; i1min=i1; vmin=cube[i3][i2][i1]; } if (vmax>cube[i3][i2][i1]) { i3max=i3; i2max=i2; i1max=i1; vmax=cube[i3][i2][i1]; } } } } fprintf(stderr, "max value=%e, at i3=%d i2=%d i1=%d\n",vmin,i3min,i2min,i1min); fprintf(stderr, "min value=%e, at i3=%d i2=%d i1=%d\n",vmax,i3max,i2max,i1max); glutInit(&argc, argv); glutInitWindowSize(512, 512); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow("trip"); glutDisplayFunc(redraw); glutIdleFunc(NULL); if (!getparfloat("q",q0)){ q0[0]=-0.6; q0[1]=0.05; q0[2]=-0.06; q0[3]=0.8; } 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(controlPanel); glutAddMenuEntry("Full screen",1); glutAddMenuEntry("Quit", 2); glutAddMenuEntry("First vertical plane",3); glutAddMenuEntry("Second vertical plane",4); glutAddMenuEntry("Horizontal plane",5); glutAddMenuEntry("Plot Axes",6); glutAttachMenu(GLUT_RIGHT_BUTTON); glShadeModel(GL_SMOOTH); /* colors will be continuous */ glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); glLineWidth(1.0); glMatrixMode(GL_PROJECTION); eyez=25; 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(); /**************************************************** Let's plot the first vertical plane (facing x-axis): ****************************************************/ data=ealloc3float(3,n1,n3); emis=ealloc3float(4,n1,n3); for (i1=0;i1<n1;i1++) { for (i3=0;i3<n3;i3++) { data[i3][i1][0]=((cx-xmin)/(xmax-xmin)-0.5)*DIAMETER; data[i3][i1][1]=((i3-ymin)/(ymax-ymin)-0.5)*DIAMETER; data[i3][i1][2]=((i1-zmin)/(zmax-zmin)-0.5)*DIAMETER; v0=cube[i3][cx][i1]; zmEmission(v0,vmin,vmax,emis[i3][i1]); } } showPlane( 3, /*list of plot*/ data, /*2-D plane data*/ emis, /*emission*/ n3, /*slow dimension in the 2D data*/ n1); /*fast dimension in the 2D data*/ free3float(data); free3float(emis); /**************************************************** Let's plot the second vertical plane (facing y-axis): ****************************************************/ data=ealloc3float(3,n1,n2); emis=ealloc3float(4,n1,n2); for (i1=0;i1<n1;i1++) { for (i2=0;i2<n2;i2++) { data[i2][i1][0]=((i2-xmin)/(xmax-xmin)-0.5)*DIAMETER; data[i2][i1][1]=((cy-ymin)/(ymax-ymin)-0.5)*DIAMETER; data[i2][i1][2]=((i1-zmin)/(zmax-zmin)-0.5)*DIAMETER; v0=cube[cy][i2][i1]; zmEmission(v0,vmin,vmax,emis[i2][i1]); } } showPlane( 4, /*list of plot*/ data, /*2-D plane data*/ emis, /*emission*/ n2, /*slow dimension in the 2D data*/ n1); /*fast dimension in the 2D data*/ free3float(data); free3float(emis); /**************************************************** Let's plot the horizontal plane: ****************************************************/ data=ealloc3float(3,n3,n2); emis=ealloc3float(4,n3,n2); for (i3=0;i3<n3;i3++) { for (i2=0;i2<n2;i2++) { data[i2][i3][0]=((i2-xmin)/(xmax-xmin)-0.5)*DIAMETER; data[i2][i3][1]=((i3-ymin)/(ymax-ymin)-0.5)*DIAMETER; data[i2][i3][2]=((cz-zmin)/(zmax-zmin)-0.5)*DIAMETER; v0=cube[i3][i2][cz]; zmEmission(v0,vmin,vmax,emis[i2][i3]); } } showPlane( 5, /*list of plot*/ data, /*2-D plane data*/ emis, /*emission*/ n2, /*slow dimension in the 2D data*/ n3); /*fast dimension in the 2D data*/ free3float(data); free3float(emis); /*show axes*/ glNewList(6,GL_COMPILE); glLineWidth(1.5); emission[0]=1.0; emission[1]=1.0; emission[2]=1.0; emission[3]=1.0; glMaterialfv(GL_FRONT,GL_EMISSION,emission); glBegin(GL_LINES); glVertex3f(0.0,0.0,0.0); glVertex3f(RADIUS,0.0,0.0); glEnd(); glBegin(GL_LINES); glVertex3f(0.0,0.0,0.0); glVertex3f(0.0,RADIUS,0.0); glEnd(); glBegin(GL_LINES); glVertex3f(0.0,0.0,0.0); glVertex3f(0.0,0.0,-RADIUS); glEnd(); glEndList(); glutMainLoop(); return 0; }
main(int argc, char **argv) { float **filter; /* filter arrays */ float *tf; /* times at which filters are centered */ int *itf; /* ... as integers */ int jmin; /* index of first filter itf value */ int jmax; /* index of last filter itf value */ int nfft; /* fft sizes in each time gate */ int nfreq; /* number of frequencies */ float **ftrace; /* filtered sub-traces */ int nfilter; /* number of filters specified */ float dt; /* sample spacing */ float tmin; /* first time on traces */ int nt; /* number of points on input trace */ float *data; FILE *infp=stdin, *outfp=stdout; /* Initialize */ initargs(argc, argv); requestdoc(1); /* Get info from first trace */ file2g(infp); file2g(outfp); if (!fgettr(infp,&tr)) err("can't get first trace"); if (tr.trid && tr.trid != TREAL) err("input is not seismic data, trid=%d", tr.trid); nt = tr.ns; if (!getparfloat("dt", &dt)) dt = (float)tr.dt/1000000.0; if (!dt) err("dt field is zero and not getparred"); tmin = tr.delrt/1000.0; /* Get number of filters and center times */ if (!(nfilter = countparval("tf"))) MUSTGETPARFLOAT("tf", tf); if (countparname("f") != nfilter) err("must give one f 4-tuple for each" " (%d) tf value", nfilter); /* Leave room for possibly missing filters at endpoints */ tf = ealloc1float(nfilter+4); /* never use ist2 or last 2 */ itf = ealloc1int(nfilter+4); getparfloat("tf", tf+2); jmin = 2; jmax = nfilter + 1; { register int j; for (j = jmin; j <= jmax; ++j) itf[j] = NINT((tf[j] - tmin)/dt); } /* Make filters with scale for inverse transform */ nfft = npfaro(nt, LOOKFAC * nt); if (nfft >= MIN(SU_NFLTS, PFA_MAX)) err("Padded nt=%d -- too big", nfft); nfreq = nfft/2 + 1; filter = ealloc2float(nfreq, nfilter+4); /* never use 1st & last */ { register int j; for (j = jmin; j <= jmax; ++j) { float *f = ealloc1float(4); if (getnparfloat(j-jmin+1, "f", f) != 4) err("must give 4 corner frequencies in f="); if (f[0] < 0.0 || f[0] > f[1] || f[1] >= f[2] || f[2] > f[3]) err("Filter #%d has bad frequencies", j - jmin + 1); makefilter(f, nfft, nfreq, dt, filter[j]); } } /* User may not have given a filter for tmin and/or tmax-- */ /* Extend array so can always assume these filters are present. */ /* Note don't really use any of the extra storage in **filter! */ if (itf[jmin] > 0) { filter[jmin-1] = filter[jmin]; itf[jmin-1] = 0; --jmin; } if (itf[jmax] < nt - 1) { filter[jmax+1] = filter[jmax]; itf[jmax+1] = nt - 1; ++jmax; } /* Extend array so can always consider time points to be interior */ itf[jmin-1] = 0; /* now jmin - 1 is a valid index */ itf[jmax+1] = nt - 1; /* now jmax + 1 is a valid index */ /* Main loop over traces */ ftrace = ealloc2float(nt, nfilter+4); /* never use 1st & last */ data = ealloc1float(nt); do { register int i, j; /* Construct filtered sub-traces */ for (j = jmin; j <= jmax; ++j) { bzero(data, nt*FSIZE); for (i = itf[j-1]; i <= itf[j+1]; ++i) data[i] = tr.data[i]; bandpass(data,nt,nfft,nfreq,filter[j],ftrace[j]); } /* Compose filtered trace from sub-traces */ for (j = jmin; j < jmax; ++j) { float fitfj; for (fitfj = i = itf[j]; i <= itf[j+1]; ++i) { float a = (i - fitfj)/(itf[j+1] - fitfj); tr.data[i] = (1-a)*ftrace[j][i] + a*ftrace[j+1][i]; } } fputtr(outfp,&tr); } while (fgettr(infp,&tr)); return EXIT_SUCCESS; }
int main( int argc, char *argv[] ) { 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) { /********************* variables declaration **************************/ int info, itype, lda, ldb, lwork, order; /* variables for lapack function */ char jobz, uplo; /* variables for lapack function */ int nfreq; /* number of frequencies displayed on the screen */ int d; /* dimension of the problem - determine the size r of the partial basis*/ int shape; /* shape of the body */ int r; /* actual size of the partial basis */ int i, j; /* indices */ int ir1; int *itab, *ltab, *mtab, *ntab; /* tabulation of indices */ int *irk; int k; int ns; /* symmetry of the system */ int hextype; /* type of hexagonal symmetry - VTI or HTI*/ double d1, d2, d3; /* dimension of the sample */ double rho; /* density */ double **cm; double ****c; /* stiffness tensor */ double **e, **gamma, *work, **w; /* matrices of the eigenvalue problem */ double *wsort; int outeigen; /* 1 if eigenvectors calculated */ char *eigenfile; /** FILE *file; */ /********************* end variables declaration **********************/ /* hook up getpar to handle the parameters */ initargs(argc,argv); requestdoc(1); /* get required parameters */ if (!getparint("d", &d)) err("must specify d!\n"); if (!getpardouble("d1", &d1)) err("must specify d1!\n"); if (!getpardouble("d2", &d2)) err("must specify d2!\n"); if (!getpardouble("d3", &d3)) err("must specify d3!\n"); if (!getpardouble("rho", &rho)) err("must specify rho!\n"); if (!getparint("ns", &ns)) err("must specify ns!\n"); cm=ealloc2double(6,6); for (i=0; i<6; ++i) for (j=0; j<6; ++j) cm[i][j]=0.0; if (ns==2) { /* isotropic */ if (!getpardouble("c11", &cm[0][0])) err("must specify c11!\n"); if (!getpardouble("c44", &cm[3][3])) err("must specify c44!\n"); cm[0][0]=cm[0][0]/100; cm[3][3]=cm[3][3]/100; cm[1][1]=cm[2][2]=cm[0][0]; cm[4][4]=cm[5][5]=cm[3][3]; cm[0][1]=cm[0][2]=cm[1][2]=cm[0][0]- 2.0*cm[3][3]; cm[1][0]=cm[2][0]=cm[2][1]=cm[0][0]- 2.0*cm[3][3]; } else if (ns==3) { /* cubic */ if (!getpardouble("c11", &cm[0][0])) err("must specify c11!\n"); if (!getpardouble("c12", &cm[0][1])) err("must specify c12!\n"); if (!getpardouble("c44", &cm[3][3])) err("must specify c44!\n"); cm[0][0]=cm[0][0]/100; cm[0][1]=cm[0][1]/100; cm[3][3]=cm[3][3]/100; cm[1][1]=cm[2][2]=cm[0][0]; cm[4][4]=cm[5][5]=cm[3][3]; cm[0][2]=cm[1][2]=cm[0][1]; cm[2][0]=cm[2][1]=cm[1][0]=cm[0][1]; } else if (ns==5) { /* hexagonal */ if (!getparint("hextype", &hextype)) err("must specify hextype!\n"); if (hextype==1) { /* VTI */ if (!getpardouble("c33", &cm[2][2])) err("must specify c33!\n"); if (!getpardouble("c23", &cm[1][2])) err("must specify c23!\n"); if (!getpardouble("c12", &cm[0][1])) err("must specify c12!\n"); if (!getpardouble("c44", &cm[3][3])) err("must specify c44!\n"); if (!getpardouble("c66", &cm[5][5])) err("must specify c66!\n"); cm[2][2]=cm[2][2]/100; cm[1][2]=cm[1][2]/100; cm[0][1]=cm[0][1]/100; cm[3][3]=cm[3][3]/100; cm[5][5]=cm[5][5]/100; cm[0][0]=cm[1][1]=2.0*cm[5][5] + cm[0][1]; cm[0][2]=cm[2][0]=cm[2][1]=cm[1][2]; cm[1][0]=cm[0][1]; cm[4][4]=cm[3][3]; } else if (hextype==2) { /* HTI */ if (!getpardouble("c11", &cm[0][0])) err("must specify c11!\n"); if (!getpardouble("c33", &cm[2][2])) err("must specify c33!\n"); if (!getpardouble("c12", &cm[0][1])) err("must specify c12!\n"); if (!getpardouble("c44", &cm[3][3])) err("must specify c44!\n"); if (!getpardouble("c66", &cm[5][5])) err("must specify c66!\n"); cm[0][0]=cm[0][0]/100; cm[2][2]=cm[2][2]/100; cm[0][1]=cm[0][1]/100; cm[3][3]=cm[3][3]/100; cm[5][5]=cm[5][5]/100; cm[1][2]=cm[2][1]=cm[2][2] - 2.0*cm[3][3]; cm[0][2]=cm[1][0]=cm[2][0]=cm[0][1]; cm[1][1]=cm[2][2]; cm[4][4]=cm[5][5]; } else { err("for hexagonal symmetry hextype must equal 1 (VTI) or 2 (HTI)!\n"); } } else if (ns==6){ /* tetragonal */ if (!getpardouble("c11", &cm[0][0])) err("must specify c11!\n"); if (!getpardouble("c33", &cm[2][2])) err("must specify c33!\n"); if (!getpardouble("c23", &cm[1][2])) err("must specify c23!\n"); if (!getpardouble("c12", &cm[0][1])) err("must specify c12!\n"); if (!getpardouble("c44", &cm[3][3])) err("must specify c44!\n"); if (!getpardouble("c66", &cm[5][5])) err("must specify c66!\n"); cm[0][0]=cm[0][0]/100; cm[2][2]=cm[2][2]/100; cm[1][2]=cm[1][2]/100; cm[3][3]=cm[3][3]/100; cm[0][1]=cm[0][1]/100; cm[5][5]=cm[5][5]/100; cm[1][1]=cm[0][0]; cm[0][2]=cm[2][0]=cm[1][2]; cm[1][0]=cm[0][1]; cm[2][1]=cm[1][2]; cm[4][4]=cm[3][3]; } else if (ns==9){/* orthorhombic */ if (!getpardouble("c11", &cm[0][0])) err("must specify c11!\n"); if (!getpardouble("c22", &cm[1][1])) err("must specify c22!\n"); if (!getpardouble("c33", &cm[2][2])) err("must specify c33!\n"); if (!getpardouble("c23", &cm[1][2])) err("must specify c23!\n"); if (!getpardouble("c13", &cm[0][2])) err("must specify c13!\n"); if (!getpardouble("c12", &cm[0][1])) err("must specify c12!\n"); if (!getpardouble("c44", &cm[3][3])) err("must specify c44!\n"); if (!getpardouble("c55", &cm[4][4])) err("must specify c55!\n"); if (!getpardouble("c66", &cm[5][5])) err("must specify c66!\n"); cm[0][0]=cm[0][0]/100; cm[1][1]=cm[1][1]/100; cm[2][2]=cm[2][2]/100; cm[1][2]=cm[1][2]/100; cm[0][2]=cm[0][2]/100; cm[0][1]=cm[0][1]/100; cm[3][3]=cm[3][3]/100; cm[4][4]=cm[4][4]/100; cm[5][5]=cm[5][5]/100; cm[2][0]=cm[0][2]; cm[1][0]=cm[0][1]; cm[2][1]=cm[1][2]; } else err("given elatic moduli does not fit given ns"); /* get optional parameters */ if (!getparint("outeigen", &outeigen)) outeigen=0; if (outeigen!=0) if (!getparstring("eigenfile", &eigenfile)) err("must specify eigenfile since outeigen>0!\n"); if (!getparint("shape", &shape)) shape=1; /* changed from zero default to 1 */ if (!getparint("nfreq", &nfreq)) nfreq=10; /* dimension of the problem */ r= 3*(d+1)*(d+2)*(d+3)/6; d1=d1/2.0; /* half sample dimensions are used in calculations */ d2=d2/2.0; d3=d3/2.0; /* alloc work space*/ itab=ealloc1int(r); ltab=ealloc1int(r); mtab=ealloc1int(r); ntab=ealloc1int(r); /* relationship between ir and l,m,n - filling tables */ irk=ealloc1int(8); index_relationship(itab, ltab, mtab, ntab, d, irk); /* alloc workspace to solve for eigenvalues and eigenfunctions */ e= (double **) malloc(8*sizeof(double *)); for (k=0; k<8; ++k) e[k] = ealloc1double(irk[k]*irk[k]); gamma= (double **) malloc(8*sizeof(double *)); for (k=0; k<8; ++k) gamma[k] = ealloc1double(irk[k]*irk[k]); /* filling matrix e */ for (k=0; k<8; ++k) e_fill(e[k], itab, ltab, mtab, ntab, r, d1, d2, d3, rho, shape, k, irk); /* stiffness tensor calculation*/ c= (double ****) malloc(sizeof(double ***)*3); for (i=0; i<3; ++i) c[i]=ealloc3double(3,3,3); stiffness (c, cm); /* filling matrix gamma */ for (k=0; k<8; ++k) gamma_fill(gamma[k], itab, ltab, mtab, ntab, r, d1, d2, d3, c, shape, k, irk); /* clean workspace */ free1int(itab); free1int(ltab); free1int(mtab); free1int(ntab); for (i=0; i<3; ++i) free3double(c[i]); free(c); fprintf(stderr,"done preparing matrices\n"); /*-------------------------------------------------------------*/ /*--------- solve the generalized eigenvalue problem ----------*/ /*-------------------------------------------------------------*/ w= (double **) malloc(sizeof(double *)*8); itype=1; if (outeigen==0) jobz='N'; else jobz='V'; uplo='U'; for (k=0; k<8; ++k){ w[k] =ealloc1double(irk[k]); lda=ldb=irk[k]; order=irk[k]; lwork=MAX(1, 3*order-1); work=ealloc1double(lwork); /* lapack routine */ dsygv_(&itype, &jobz, &uplo, &order, gamma[k], &lda, e[k], &ldb, w[k], work, &lwork, &info); free1double(work); } /*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/ wsort=ealloc1double(r); for (i=0, k=0; k<8; ++k) for (ir1=0;ir1<irk[k];++ir1,++i) wsort[i]=w[k][ir1]; /* sorting the eigenfrequencies */ dqksort(r,wsort); for (i=0, ir1=0; ir1<nfreq;++i) if ((wsort[i]>0) && ((sqrt(wsort[i])/(2.0*PI))>0.00001)){ ++ir1; /*fprintf(stderr," f%d = %f\n", ir1, 1000000*sqrt(wsort[i])/(2.0*PI));*/ fprintf(stderr," f%d = %f\n", ir1, 1000000*sqrt(wsort[i])/(2.0*PI)); } /* modify output of freq values here*/ /* for (k=0;k<8;++k){ for (ir2=0;ir2<irk[k]*irk[k];++ir2){ fprintf(stderr,"gamma[%d][%d]=%f\n",k,ir2,gamma[k][ir2]); fprintf(stderr,"e[%d][%d]=%f\n",k,ir2,e[k][ir2]); } }*/ /******************* write eigenvectors in files ***************/ /*if (outeigen==1){ z=ealloc2double(r,r); for (ir1=0; ir1<r; ++ir1) for (ir2=0; ir2<r; ++ir2) z[ir2][ir1]=gamma[ir1][ir2*r+ir1]; */ /* change the order of the array at the same time */ /* since we go from fortran array */ /* to C array */ /* clean workspace */ /* free1double(gamma); file = efopen(eigenfile, "w"); efwrite(&irf, sizeof(int), 1, file); efwrite(w, sizeof(double), r, file); efwrite(z[0], sizeof(double), r*r, file); efclose(file);*/ /* clean workspace */ /* free2double(z); */ /* }*/ /* clean workspace */ /* free1double(w); */ /* end of main */ return EXIT_SUCCESS; }
int main( int argc, char *argv[] ) { int ntr=0; /* number of traces */ int ntrv=0; /* number of traces */ int ns=0; int nsv=0; float dt; float dtv; cwp_String fs; cwp_String fv; FILE *fps; FILE *fpv; FILE *headerfp; float *data; /* data matrix of the migration volume */ float *vel; /* velocity matrix */ float *velfi; /* velocity function interpolated to ns values*/ float *velf; /* velocity function */ float *vdt; float *ddt; float *ap; /* array of apperture values in m */ float apr; /* array of apperture values in m */ int *apt=NULL; /* array of apperture time limits in mig. gath*/ float r; /* maximum radius with a given apperture */ float ir2; /* r/d2 */ float ir3; /* r/d3 */ float d2; /* spatial sampling int. in dir 2. */ float d3; /* spatial sampling int. in dir 3. */ float **mgd=NULL; /* migration gather data */ float *migt; /* migrated data trace */ int **mgdnz=NULL; /* migration gather data non zero samples*/ float dm; /* migration gather spatial sample int. */ int im; /* number of traces in migration gather */ int *mtnz; /* migrated trace data non zero smaples */ char **dummyi; /* index array that the trace contains zeros only */ float fac; /* velocity scale factor */ int sphr; /* spherical divergence flag */ int imt; /* mute time sample of trace */ float tmp; int imoff; int **igtr=NULL; int nigtr; int n2; int n3; int verbose; /* phase shift filter stuff */ float power; /* power of i omega applied to data */ float amp; /* amplitude associated with the power */ float arg; /* argument of power */ float phasefac; /* phase factor */ float phase; /* phase shift = phasefac*PI */ complex exparg; /* cexp(I arg) */ register float *rt; /* real trace */ register complex *ct; /* complex transformed trace */ complex *filt; /* complex power */ float omega; /* circular frequency */ float domega; /* circular frequency spacing (from dt) */ float sign; /* sign in front of i*omega default -1 */ int nfft; /* number of points in nfft */ int nf; /* number of frequencies (incl Nyq) */ float onfft; /* 1 / nfft */ size_t nzeros; /* number of padded zeroes in bytes */ initargs(argc, argv); requestdoc(1); MUSTGETPARSTRING("fs",&fs); MUSTGETPARSTRING("fv",&fv); MUSTGETPARINT("n2",&n2); MUSTGETPARINT("n3",&n3); MUSTGETPARFLOAT("d2",&d2); MUSTGETPARFLOAT("d3",&d3); if (!getparfloat("dm", &dm)) dm=(d2+d3)/2.0; /* open datafile */ fps = efopen(fs,"r"); fpv = efopen(fv,"r"); /* Open tmpfile for headers */ headerfp = etmpfile(); /* get information from the first data trace */ ntr = fgettra(fps,&tr,0); if(n2*n3!=ntr) err(" Number of traces in file %d not equal to n2*n3 %d \n", ntr,n2*n3); ns=tr.ns; if (!getparfloat("dt", &dt)) dt = ((float) tr.dt)/1000000.0; if (!dt) { dt = .002; warn("dt not set, assumed to be .002"); } /* get information from the first velocity trace */ ntrv = fgettra(fpv,&trv,0); if(ntrv!=ntr) err(" Number of traces in velocity file %d differ from %d \n", ntrv,ntr); nsv=trv.ns; if (!getparfloat("dtv", &dtv)) dtv = ((float) trv.dt)/1000000.0; if (!dtv) { dtv = .002; warn("dtv not set, assumed to be .002 for velocity"); } if (!getparfloat("fac", &fac)) fac=2.0; if (!getparint("verbose", &verbose)) verbose=0; if (!getparint("sphr", &sphr)) sphr=0; if (!getparfloat("apr", &apr)) apr=75; apr*=3.141592653/180; /* allocate arrays */ data = bmalloc(sizeof(float),ns,ntr); vel = bmalloc(sizeof(float),nsv,ntr); velf = ealloc1float(nsv); velfi = ealloc1float(ns); migt = ealloc1float(ns); vdt = ealloc1float(nsv); ddt = ealloc1float(ns); ap = ealloc1float(ns); mtnz = ealloc1int(ns); dummyi = (char **) ealloc2(n2,n3,sizeof(char)); /* Times to do interpolation of velocity from sparse sampling */ /* to fine sampling of the data */ { register int it; for(it=0;it<nsv;it++) vdt[it]=it*dtv; for(it=0;it<ns;it++) ddt[it]=it*dt; } /* Read traces into data */ /* Store headers in tmpfile */ ntr=0; erewind(fps); erewind(fpv); { register int i2,i3; for(i3=0;i3<n3;i3++) for(i2=0;i2<n2;i2++) { fgettr(fps,&tr); fgettr(fpv,&trv); if(tr.trid > 2) dummyi[i3][i2]=1; else dummyi[i3][i2]=0; efwrite(&tr, 1, HDRBYTES, headerfp); bmwrite(data,1,0,i3*n2+i2,ns,tr.data); bmwrite(vel,1,0,i3*n2+i2,nsv,trv.data); } erewind(headerfp); /* set up the phase filter */ power = 1.0;sign = 1.0;phasefac = 0.5; phase = phasefac * PI; /* Set up for fft */ nfft = npfaro(ns, LOOKFAC * ns); if (nfft >= SU_NFLTS || nfft >= PFA_MAX) err("Padded nt=%d -- too big", nfft); nf = nfft/2 + 1; onfft = 1.0 / nfft; nzeros = (nfft - ns) * FSIZE; domega = TWOPI * onfft / dt; /* Allocate fft arrays */ rt = ealloc1float(nfft); ct = ealloc1complex(nf); filt = ealloc1complex(nf); /* Set up args for complex power evaluation */ arg = sign * PIBY2 * power + phase; exparg = cexp(crmul(I, arg)); { register int i; for (i = 0 ; i < nf; ++i) { omega = i * domega; /* kludge to handle omega=0 case for power < 0 */ if (power < 0 && i == 0) omega = FLT_MAX; /* calculate filter */ amp = pow(omega, power) * onfft; filt[i] = crmul(exparg, amp); } } /* set up constants for migration */ if(verbose) fprintf(stderr," Setting up constants....\n"); r=0; for(i3=0;i3<n3;i3++) for(i2=0;i2<n2;i2++) { if(dummyi[i3][i2] < 1) { /* get the velocity function */ bmread(vel,1,0,i3*n2+i2,nsv,velf); /* linear interpolation from nsv to ns values */ intlin(nsv,vdt,velf,velf[0],velf[nsv-1],ns,ddt,velfi); /* Apply scale factor to velocity */ { register int it; for(it=0;it<ns;it++) velfi[it] *=fac; } /* compute maximum radius from apperture and velocity */ { register int it; for(it=0;it<ns;it++) ap[it] = ddt[it]*velfi[it]*tan(apr)/2.0; } tmp = ap[isamax(ns,ap,1)]; if(tmp>r) r=tmp; } } r=MIN(r,sqrt(SQR((n2-1)*d2)+SQR((n3-1)*d3))); ir2 = (int)(2*r/d2)+1; ir3 = (int)(2*r/d3)+1; im = (int)(r/dm)+1; /* allocate migration gather */ mgd = ealloc2float(ns,im); mgdnz = ealloc2int(ns,im); apt = ealloc1int(im); /* set up the stencil for selecting traces */ igtr = ealloc2int(ir2*ir3,2); stncl(r, d2, d3,igtr,&nigtr); if(verbose) { fprintf(stderr," Maximum radius %f\n",r); fprintf(stderr," Maximum offset %f\n", sqrt(SQR((n2-1)*d2)+SQR((n3-1)*d3))); } /* main processing loop */ for(i3=0;i3<n3;i3++) for(i2=0;i2<n2;i2++) { memset( (void *) tr.data, (int) '\0',ns*FSIZE); if(dummyi[i3][i2] < 1) { memset( (void *) mgd[0], (int) '\0',ns*im*FSIZE); memset( (void *) mgdnz[0], (int) '\0',ns*im*ISIZE); /* get the velocity function */ bmread(vel,1,0,i3*n2+i2,nsv,velf); /* linear interpolation from nsv to ns values */ intlin(nsv,vdt,velf,velf[0],velf[nsv-1],ns,ddt,velfi); /* Apply scale factor to velocity */ { register int it; for(it=0;it<ns;it++) velfi[it] *=fac; } /* create the migration gather */ { register int itr,ist2,ist3; for(itr=0;itr<nigtr;itr++) { ist2=i2+igtr[0][itr]; ist3=i3+igtr[1][itr]; if(ist2 >= 0 && ist2 <n2) if(ist3 >= 0 && ist3 <n3) { if(dummyi[ist3][ist2] <1) { imoff = (int) ( sqrt(SQR(igtr[0][itr]*d2) +SQR(igtr[1][itr]*d3))/dm+0.5); bmread(data,1,0,ist3*n2+ist2,ns,tr.data); imoff=MIN(imoff,im-1); { register int it; /* get the mute time for this offset, apperture and velocity */ xindex(ns,ap,imoff*dm,&imt); for(it=imt;it<ns;it++) if(tr.data[it]!=0) { mgd[imoff][it]+=tr.data[it]; mgdnz[imoff][it]+=1; } } } } } } /* normalize the gather */ { register int ix,it; for(ix=0;ix<im;ix++) for(it=0;it<ns;it++) if(mgdnz[ix][it] > 1) mgd[ix][it] /=(float) mgdnz[ix][it]; } memset( (void *) tr.data, (int) '\0',ns*FSIZE); memset( (void *) mtnz, (int) '\0',ns*ISIZE); /* do a knmo */ { register int ix,it; for(ix=0;ix<im;ix++) { /* get the mute time for this offset, apperture and velocity */ xindex(ns,ap,ix*dm,&imt); knmo(mgd[ix],migt,ns,velfi,0,ix*dm,dt,imt,sphr); /* stack the gather */ for(it=0;it<ns;it++) { if(migt[it]!=0.0) { tr.data[it] += migt[it]; mtnz[it]++; } /* tr.data[it] += mgd[ix][it]; */ } } } { register int it; for(it=0;it<ns;it++) if(mtnz[it]>1) tr.data[it] /=(float)mtnz[it]; } /*Do the phase filtering before the trace is released*/ /* Load trace into rt (zero-padded) */ memcpy( (void *) rt, (const void *) tr.data, ns*FSIZE); memset((void *) (rt + ns), (int) '\0', nzeros); pfarc(1, nfft, rt, ct); { register int i; for (i = 0; i < nf; ++i) ct[i] = cmul(ct[i], filt[i]); } pfacr(-1, nfft, ct, rt); memcpy( (void *) tr.data, (const void *) rt, ns*FSIZE); } /* end of dummy if */ /* spit out the gather */ efread(&tr, 1, HDRBYTES, headerfp); puttr(&tr); if(verbose) fprintf(stderr," %d %d\n",i2,i3); } /* end of i2 loop */ } /* end of i3 loop */ /* This should be the last thing */ efclose(headerfp); /* Free memory */ free2int(igtr); free2float(mgd); free2int(mgdnz); free1int(apt); bmfree(data); bmfree(vel); free1float(velfi); free1float(velf); free1float(ddt); free1float(vdt); free1float(ap); free1int(mtnz); free1float(migt); free1float(rt); free1complex(ct); free1complex(filt); free2((void **) dummyi); return EXIT_SUCCESS; }
static float getbbohitn (float x, int itmin, int nt, float dt, float *v, int ntable, float *boh, float *zoh, float gamma, float **bbohp, int **itnp) /***************************************************************************** convert b/h from a function of depth to a function of NMO time ****************************************************************************** Input: x offset itmin mininimum NMO time index to process nt number of time samples dt time sampling interval v array[nt] of RMS velocities ntable number of tabulated zoh or boh boh array[ntable] of b/h zoh array[ntable] of z/h gamma velocity ratio (upgoing/downgoing) Output: bbohp array[nt] of b/h itnp array[nt] of time-sample indexes ****************************************************************************** Author: Mohammed Alfaraj, Colorado School of Mines, 01/08/92 *****************************************************************************/ { int i, j=0, it, gotit; float alpha, beta, tossq, xov, nz, t, xsq, tog, temp; float *bboh; int *itn; /* allocate space */ bboh = ealloc1float(nt); itn = ealloc1int(nt); /* constants depending on gamma */ alpha = 1.0+1.0/(gamma*gamma); beta = 1.0-1.0/(gamma*gamma); tossq = 2.0/((1.0+1.0/gamma)*(1.0+1.0/gamma)); tog=2.0/gamma; xsq = x*x; /* loop over it */ for (it=itmin,t=itmin*dt; it<nt; it++,t+=dt) { xov = x/v[it]; nz = t/xov; gotit = 0; /* loop over table */ for (i=j; i<ntable; i++) if(zoh[i]>=nz) { bboh[it] = boh[i]; temp = (t*t/(1-boh[i]*boh[i])-xov*xov \ *(tog/(alpha+ beta*boh[i])-1))* \ (alpha+beta*boh[i])*tossq; /* zero time if evanscent */ if (temp<0.0) itn[it] = 0; else{ itn[it] = NINT(sqrt(temp)/dt); /* bboh[it]=boh[i-60]; */ } j = i; gotit = 1; break; } if (gotit) continue; /* else set boh to asymtotic value then break */ for (j=it; j<nt; j++,t+=dt) { bboh[j] = boh[ntable-1]; itn[j]=NINT(sqrt((t*t/(1-bboh[j]*bboh[j])-(xsq/(v[j]* \ v[j]))*(tog/(alpha+ beta*bboh[j])-1))* \ (alpha+beta*bboh[j])*tossq)/dt); } break; } /* set returned values */ *bbohp = bboh; *itnp = itn; return(CWP_Exit()); }
int main (int argc, char **argv) { int n1,n2,n1tic,n2tic,nfloats,bbox[4], i1,i2,grid1,grid2,style, n1c,n2c,n1s,n2s,i1beg,i1end,i2beg,i2end,i1c,i2c, nz,iz,i1step,i2step,verbose,hls,bps, legend,ugrid=SOLID,lstyle=VERTLEFT,lz,lbegsup=0,lendsup=0,ln=256, lbbox[4], threecolor=0; /* BEREND, Schoenfelder */ int lnice; /* c liner */ float labelsize,titlesize,perc,clip,bperc,wperc,bclip,wclip, d1,f1,d2,f2,*z,*temp,zscale,zoffset,zi, xbox,ybox,width,height, x1beg,x1end,x2beg,x2end, x1min,x1max,x2min,x2max, d1num,f1num,d2num,f2num, p1beg,p1end,p2beg,p2end,matrix[6],colors[3][3], /* for 3 color mode */ d1s,d2s, lwidth,lheight,lx,ly,lbeg,lend,lmin=(float) FLT_MAX,lmax=(float) -FLT_MAX, ldnum,lfnum,ld,lf=0,labmatrix[6]; /* BEREND, Schoenfelder */ float axeswidth, ticwidth, gridwidth; unsigned char *cz,*czp,*sz,*data_legend=NULL; char *label1="",*label2="",*title="",*units="", *legendfont="times_roman10", *labelfont="Helvetica",*titlefont="Helvetica-Bold", *styles="seismic",*grid1s="none",*grid2s="none", *titlecolor="black",*axescolor="black",*gridcolor="black", *lstyles="vertleft",*lgrids="none"; FILE *infp=stdin; float **x1curve=NULL,**x2curve=NULL,*curvewidth=NULL; int i,j,curve=0,*npair=NULL,ncurvecolor=0,ncurvewidth=0,ncurvedash=0,*curvedash=NULL; char **curvecolor=NULL,**curvefile=NULL; FILE *curvefp=NULL; cwp_Bool is_curve = cwp_false; /* initialize getpar */ initargs(argc,argv); requestdoc(1); /* get parameters describing 1st dimension sampling */ if (!getparint("n1",&n1)) err("must specify n1!\n"); d1 = 1.0; getparfloat("d1",&d1); f1 = 0.0; getparfloat("f1",&f1); x1min = (d1>0.0)?f1:f1+(n1-1)*d1; x1max = (d1<0.0)?f1:f1+(n1-1)*d1; /* get parameters describing 2nd dimension sampling */ if (!getparint("n2",&n2)) { if (efseeko(infp,(off_t) 0,SEEK_END)!=0) err("must specify n2 if in a pipe!\n"); nfloats = (int) (eftello(infp)/((off_t) sizeof(float))); efseeko(infp,(off_t) 0,SEEK_SET); n2 = nfloats/n1; } d2 = 1.0; getparfloat("d2",&d2); f2 = 0.0; getparfloat("f2",&f2); x2min = (d2>0.0)?f2:f2+(n2-1)*d2; x2max = (d2<0.0)?f2:f2+(n2-1)*d2; /* read color parameters */ if (!getparint("threecolor",&threecolor)) threecolor=1; bps = 8; hls = 0; /* color[][0] is black, color[][2] is white in 2 color mode */ colors[R][0] = colors[G][0] = colors[B][0] = 0.0; colors[R][1] = colors[G][1] = colors[B][1] = 0.5; colors[R][2] = colors[G][2] = colors[B][2] = 1.0; if (countparval("brgb") || countparval("wrgb")) { float brgb[3],grgb[3],wrgb[3]; brgb[R] = brgb[G] = brgb[B] = 0.0; wrgb[R] = wrgb[G] = wrgb[B] = 1.0; getparfloat("brgb",&brgb[0]); getparfloat("wrgb",&wrgb[0]); grgb[R] = (brgb[R] + wrgb[R])/2.; grgb[G] = (brgb[G] + wrgb[G])/2.; grgb[B] = (brgb[B] + wrgb[B])/2.; if (threecolor==1) getparfloat("grgb",&grgb[0]); brgb[R] = MAX(0.0,MIN(1.0,brgb[R])); grgb[R] = MAX(0.0,MIN(1.0,grgb[R])); wrgb[R] = MAX(0.0,MIN(1.0,wrgb[R])); brgb[G] = MAX(0.0,MIN(1.0,brgb[G])); grgb[G] = MAX(0.0,MIN(1.0,grgb[G])); wrgb[G] = MAX(0.0,MIN(1.0,wrgb[G])); brgb[B] = MAX(0.0,MIN(1.0,brgb[B])); grgb[B] = MAX(0.0,MIN(1.0,grgb[B])); wrgb[B] = MAX(0.0,MIN(1.0,wrgb[B])); colors[R][0] = brgb[R]; colors[R][1] = grgb[R]; colors[R][2] = wrgb[R]; colors[G][0] = brgb[G]; colors[G][1] = grgb[G]; colors[G][2] = wrgb[G]; colors[B][0] = brgb[B]; colors[B][1] = grgb[B]; colors[B][2] = wrgb[B]; if (!getparint("bps",&bps)) bps = 12; if (bps!=12 && bps!=24) err("bps must equal 12 or 24 for color plots!\n"); } else if (countparval("bhls") || countparval("whls")) { float bhls[3],ghls[3],whls[3]; hls = 1; bhls[H] = ghls[H] = whls[H] = 0.0; bhls[L] = 0.0; ghls[L] = 0.5; whls[L] = 1.0; bhls[S] = ghls[S] = whls[S] = 0.0; getparfloat("bhls",&bhls[0]); getparfloat("whls",&whls[0]); ghls[H] = (bhls[H] + whls[H])/2.; ghls[L] = (bhls[L] + whls[L])/2.; ghls[S] = (bhls[S] + whls[S])/2.; if (threecolor==1) getparfloat("ghls",&ghls[0]); bhls[L] = MAX(0.0,MIN(1.0,bhls[L])); ghls[L] = MAX(0.0,MIN(1.0,ghls[L])); whls[L] = MAX(0.0,MIN(1.0,whls[L])); bhls[S] = MAX(0.0,MIN(1.0,bhls[S])); ghls[S] = MAX(0.0,MIN(1.0,ghls[S])); whls[S] = MAX(0.0,MIN(1.0,whls[S])); colors[H][0] = bhls[0]; colors[H][1] = ghls[0]; colors[H][2] = whls[0]; colors[L][0] = bhls[1]; colors[L][1] = ghls[1]; colors[L][2] = whls[1]; colors[S][0] = bhls[2]; colors[S][1] = ghls[2]; colors[S][2] = whls[2]; if (!getparint("bps",&bps)) bps = 12; if (bps!=12 && bps!=24) err("bps must equal 12 or 24 for color plots!\n"); } /* get legend specs BEREND, Schoenfelder */ legend = 0; getparint("legend", &legend); /* BEREND, Schoenfelder */ getparstring("units", &units); /* BEREND, Schoenfelder */ getparstring("legendfont", &legendfont); /* BEREND, Schoenfelder */ /* set up curve plotting */ if ((curve=countparval("curve"))!=0) { curvefile=(char**)ealloc1(curve,sizeof(void*)); getparstringarray("curve",curvefile); if ((x1curve=(float**)malloc(curve*sizeof(void*)))==NULL) err("Could not allocate x1curve pointers\n"); if ((x2curve=(float**)malloc(curve*sizeof(void*)))==NULL) err("Could not allocate x2curve pointers\n"); npair=ealloc1int(curve); getparint("npair",npair); is_curve = cwp_true; } else { npair=(int *)NULL; curvefile=(char **)NULL; x1curve=(float **)NULL; x2curve=(float **)NULL; is_curve = cwp_false; } if (is_curve) { if ((ncurvecolor=countparval("curvecolor"))<curve) { curvecolor=(char**)ealloc1(curve,sizeof(void*)); if (!getparstringarray("curvecolor",curvecolor)) { curvecolor[0]=(char *)cwp_strdup("black\0"); ncurvecolor=1; } for (i=ncurvecolor; i<curve; i++) curvecolor[i]=(char *)cwp_strdup(curvecolor[ncurvecolor-1]); } else if (ncurvecolor) { curvecolor=(char**)ealloc1(ncurvecolor,sizeof(void*)); getparstringarray("curvecolor",curvecolor); } for (j=0; j<curve; j++) { curvefp=efopen(curvefile[j],"r"); x1curve[j]=ealloc1float(npair[j]); x2curve[j]=ealloc1float(npair[j]); for (i=0; i<npair[j]; i++) { fscanf(curvefp,"%f",&x1curve[j][i]); fscanf(curvefp,"%f",&x2curve[j][i]); } efclose(curvefp); } } /* read binary data to be plotted */ nz = n1*n2; z = ealloc1float(nz); if (fread(z,sizeof(float),nz,infp)!=nz) err("error reading input file!\n"); /* 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); } verbose = 1; getparint("verbose",&verbose); if (verbose) warn("bclip=%g wclip=%g",bclip,wclip); /* get scaled sampling intervals */ d1s = 1.0; getparfloat("d1s",&d1s); d2s = 1.0; getparfloat("d2s",&d2s); d1s = fabs(d1s); d1s *= d1; d2s = fabs(d2s); d2s *= d2; /* get axes parameters */ xbox = 1.5; getparfloat("xbox",&xbox); /* if psimage is called by ximage, it */ ybox = 1.5; getparfloat("ybox",&ybox); /* will xbox=1.166 and ybox=1.167 */ width = 6.0; getparfloat("wbox",&width); getparfloat("width",&width); height = 8.0;getparfloat("hbox",&height);getparfloat("height",&height); /* begin c liner */ lnice = 0; getparint("lnice",&lnice); if (lnice==1) { ybox = 2.2; /* lx=8 is set below, after getpar on lx ... c liner */ width = 5.4; height = 7.2; } /* end c liner */ x1beg = x1min; getparfloat("x1beg",&x1beg); x1end = x1max; getparfloat("x1end",&x1end); d1num = 0.0; getparfloat("d1num",&d1num); f1num = x1min; getparfloat("f1num",&f1num); n1tic = 1; getparint("n1tic",&n1tic); getparstring("grid1",&grid1s); if (STREQ("dot",grid1s)) grid1 = DOT; else if (STREQ("dash",grid1s)) grid1 = DASH; else if (STREQ("solid",grid1s)) grid1 = SOLID; else grid1 = NONE; getparstring("label1",&label1); x2beg = x2min; getparfloat("x2beg",&x2beg); x2end = x2max; getparfloat("x2end",&x2end); d2num = 0.0; getparfloat("d2num",&d2num); f2num = 0.0; getparfloat("f2num",&f2num); n2tic = 1; getparint("n2tic",&n2tic); getparstring("grid2",&grid2s); if (STREQ("dot",grid2s)) grid2 = DOT; else if (STREQ("dash",grid2s)) grid2 = DASH; else if (STREQ("solid",grid2s)) grid2 = SOLID; else grid2 = NONE; getparstring("label2",&label2); getparstring("labelfont",&labelfont); labelsize = 18.0; getparfloat("labelsize",&labelsize); getparstring("title",&title); getparstring("titlefont",&titlefont); titlesize = 24.0; getparfloat("titlesize",&titlesize); getparstring("titlecolor",&titlecolor); getparstring("axescolor",&axescolor); getparstring("gridcolor",&gridcolor); /* axes and tic width */ if(!getparfloat("axeswidth",&axeswidth)) axeswidth=1; if (!getparfloat("ticwidth",&ticwidth)) ticwidth=axeswidth; if(!getparfloat("gridwidth",&gridwidth)) gridwidth =axeswidth; if (is_curve) { if ((ncurvewidth=countparval("curvewidth"))<curve) { curvewidth=ealloc1float(curve); if (!getparfloat("curvewidth",curvewidth)) { curvewidth[0]=axeswidth; ncurvewidth=1; } for (i=ncurvewidth; i<curve; i++) curvewidth[i]=curvewidth[ncurvewidth-1]; } else { curvewidth=ealloc1float(ncurvewidth); getparfloat("curvewidth",curvewidth); } if ((ncurvedash=countparval("curvedash"))<curve) { curvedash=ealloc1int(curve); if (!getparint("curvedash",curvedash)) { curvedash[0]=0; ncurvedash=1; } for (i=ncurvedash; i<curve; i++) curvedash[i]=curvedash[ncurvedash-1]; } else { curvedash=ealloc1int(ncurvedash); getparint("curvedash",curvedash); } } getparstring("style",&styles); if (STREQ("normal",styles)) style = NORMAL; else style = SEISMIC; /* Get or calc legend parameters */ /* Legend min and max: Calc from data read in */ if (legend) { for (lz=0;lz<nz;lz++) { lmin=FMIN(lmin,z[lz]); lmax=FMAX(lmax,z[lz]); } if (verbose==2) warn("lmin=%g lmax=%g",lmin,lmax); } if (legend) { lbeg = lmin; if (getparfloat("lbeg",&lbeg)) lbegsup=1; lend = lmax; if (getparfloat("lend",&lend)) lendsup=1; /* Change wclip,bclip to be inside legend range */ wclip = FMAX(lbeg,wclip); /* [wclip,bclip] has to be in [lbeg,lend] */ bclip = FMIN(lend,bclip); if (lbegsup!=1) { /* Add white and black areas to show possible clipping */ float rangeperc=(bclip-wclip)/20.; lbeg=wclip-rangeperc; } if (lendsup!=1) { float rangeperc=(bclip-wclip)/20.; lend=bclip+rangeperc; } lfnum = lmin; getparfloat("lfnum",&lfnum); getparstring("lstyle",&lstyles); if (STREQ("vertright",lstyles)) lstyle = VERTRIGHT; else if (STREQ("horibottom",lstyles)) lstyle = HORIBOTTOM; /* legend dimensions (BEREND), Schoenfelder */ lwidth = 0.1 ;lheight = height/2; if (lstyle==HORIBOTTOM) { lwidth=width/1.2 ;lheight = 0.24; } getparfloat("lwidth",&lwidth); getparfloat("lheight",&lheight); lx=.8;ly = ybox+(height-lheight)/2; if (lstyle==VERTRIGHT) { lx=xbox+width+0.1; } else if (lstyle==HORIBOTTOM) { lx=xbox+(width-lwidth)/2.0;ly = 1.0; } getparfloat("lx",&lx); if (lnice==1) lx = 8; /* c liner */ getparfloat("ly",&ly); getparstring("lgrid",&lgrids); if (STREQ("dot",lgrids)) ugrid = DOT; else if (STREQ("dash",lgrids)) ugrid = DASH; else if (STREQ("solid",lgrids)) ugrid = SOLID; else ugrid = NONE; } /* adjust x1beg and x1end to fall on sampled values */ /* This will not allow to display an area greater than the data supplied */ i1beg = NINT((x1beg-f1)/d1); i1beg = MAX(0,MIN(n1-1,i1beg)); x1beg = f1+i1beg*d1; i1end = NINT((x1end-f1)/d1); i1end = MAX(0,MIN(n1-1,i1end)); x1end = f1+i1end*d1; /* adjust x2beg and x2end to fall on sampled values */ i2beg = NINT((x2beg-f2)/d2); i2beg = MAX(0,MIN(n2-1,i2beg)); x2beg = f2+i2beg*d2; i2end = NINT((x2end-f2)/d2); i2end = MAX(0,MIN(n2-1,i2end)); x2end = f2+i2end*d2; if (legend) { /* Make legend color values */ int lll=0,lcount,perc5=13,ilbeg,ilend; /* color scale */ if (lbegsup!=1) { ln+=perc5; /* white area */ } if (lendsup!=1) { ln+=perc5; /* black area */ } data_legend = ealloc1(ln,sizeof(char)); if (lbegsup!=1) { for (lll=0;lll<perc5;lll++) data_legend[lll]=(char) 255; /* white area */ } for (lcount=255;lcount>=0;lcount--,lll++) data_legend[lll]=(char) lcount; if (lendsup!=1) { for (;lll<ln;lll++) data_legend[lll]=(char) 0; /* black area */ } lf=lbeg;ld=(lend-lbeg)/(ln-1); if (!(getparfloat("ldnum",&ldnum))) ldnum=0.0; /* adjust lbeg and lend to fall on sampled values */ ilbeg = NINT((lbeg-lf)/ld); ilbeg = MAX(0,MIN(ln-1,ilbeg)); lbeg = lf+ilbeg*ld; ilend = NINT((lend-lf)/ld); ilend = MAX(0,MIN(ln-1,ilend)); lend = lf+ilend*ld; } /* allocate space for image bytes */ n1c = 1+abs(i1end-i1beg); n2c = 1+abs(i2end-i2beg); cz = ealloc1(n1c*n2c,sizeof(char)); /* convert data to be imaged into unsigned characters */ zscale = (wclip!=bclip)?255.0/(wclip-bclip):1.0e10; zoffset = -bclip*zscale; i1step = (i1end>i1beg)?1:-1; i2step = (i2end>i2beg)?1:-1; czp = cz; for (i1c=0,i1=i1beg; i1c<n1c; i1c++,i1+=i1step) { for (i2c=0,i2=i2beg; i2c<n2c; i2c++,i2+=i2step) { zi = zoffset+z[i1+i2*n1]*zscale; if (zi<0.0) zi = 0.0; if (zi>255.0) zi = 255.0; *czp++ = (unsigned char)zi; } } free1float(z); /* determine sampling after scaling */ n1s = MAX(1,NINT(1+(n1c-1)*d1/d1s)); d1s = (n1s>1)?d1*(n1c-1)/(n1s-1):d1; n2s = MAX(1,NINT(1+(n2c-1)*d2/d2s)); d2s = (n2s>1)?d2*(n2c-1)/(n2s-1):d2; /* if necessary, interpolate to scaled sampling intervals */ if (n1s!=n1c || n2s!=n2c) { sz = ealloc1(n1s*n2s,sizeof(char)); intl2b(n2c,d2,0.0,n1c,d1,0.0,cz,n2s,d2s,0.0,n1s,d1s,0.0,sz); /* Interpol array */ free1(cz); } else { sz = cz; } /* determine axes pads */ p1beg = (x1end>x1beg)?-fabs(d1s)/2:fabs(d1s)/2; p1end = (x1end>x1beg)?fabs(d1s)/2:-fabs(d1s)/2; p2beg = (x2end>x2beg)?-fabs(d2s)/2:fabs(d2s)/2; p2end = (x2end>x2beg)?fabs(d2s)/2:-fabs(d2s)/2; /* convert axes box parameters from inches to points */ xbox *= 72.0; ybox *= 72.0; width *= 72.0; height *= 72.0; if (legend) { lx *= 72.0; /* Schoenfelder */ ly *= 72.0; /* Schoenfelder */ lwidth *= 72.0; /* Schoenfelder */ lheight *= 72.0; /* Schoenfelder */ } /* set bounding box */ psAxesBBox( xbox,ybox,width,height, labelfont,labelsize, titlefont,titlesize, style,bbox); if (legend) { psLegendBBox( /* Space for legend Schoenfelder */ lx,ly,lwidth,lheight, labelfont,labelsize, lstyle,lbbox); /* Include space for legend Schoenfelder */ bbox[0]=MIN(bbox[0],lbbox[0]); bbox[1]=MIN(bbox[1],lbbox[1]); bbox[2]=MAX(bbox[2],lbbox[2]); bbox[3]=MAX(bbox[3],lbbox[3]); } boundingbox(bbox[0],bbox[1],bbox[2],bbox[3]); /* begin PostScript */ begineps(); /* save graphics state */ gsave(); /* translate coordinate system by box offset */ translate(xbox,ybox); /* determine image matrix */ if (style==NORMAL) { matrix[0] = 0; matrix[1] = n1s; matrix[2] = n2s; matrix[3] = 0; matrix[4] = 0; matrix[5] = 0; } else { matrix[0] = n2s; matrix[1] = 0; matrix[2] = 0; matrix[3] = -n1s; matrix[4] = 0; matrix[5] = n1s; } scale(width,height); /* draw the image (before axes so grid lines are visible) */ drawimage(hls,colors,n2s,n1s,bps,matrix,sz); /***************************/ /* main image has been drawn, restore graphics state */ grestore(); /* *********************************/ /* draw the colorbar (before axes so grid lines are visible) Schoenfelder*/ if (legend) { gsave(); translate(lx,ly); scale(lwidth,lheight); if ((lstyle==VERTLEFT) || (lstyle==VERTRIGHT)) { labmatrix[0] = 1; labmatrix[1] = 0; labmatrix[2] = 0; labmatrix[3] = ln; labmatrix[4] = 0; labmatrix[5] = 0; drawimage(hls,colors,1,ln,bps,labmatrix,data_legend); } else { labmatrix[0] = -1; labmatrix[1] = 0; labmatrix[2] = 0; labmatrix[3] = ln; labmatrix[4] = 0; labmatrix[5] = 0; rotate(-90); drawimage(hls,colors,1,ln,bps,labmatrix,data_legend); rotate(90); } grestore(); } /* draw curve */ for (i=0; i<curve; i++) { gsave(); psDrawCurve( xbox,ybox,width,height, x1beg,x1end,p1beg,p1end, x2beg,x2end,p2beg,p2end, x1curve[i],x2curve[i],npair[i], curvecolor[i],curvewidth[i],curvedash[i],style); grestore(); } gsave(); /* draw axes and title */ psAxesBox( xbox,ybox,width,height, x1beg,x1end,p1beg,p1end, d1num,f1num,n1tic,grid1,label1, x2beg,x2end,p2beg,p2end, d2num,f2num,n2tic,grid2,label2, labelfont,labelsize, title,titlefont,titlesize, titlecolor,axescolor,gridcolor, ticwidth,axeswidth,gridwidth, style); /* restore graphics state */ grestore(); /* draw axes and title for legend Schoenfelder*/ if (legend) { float lpbeg,lpend; int lntic=1; gsave(); lpbeg = 0.0; /*(lend>lbeg)?-fabs(d1s)/2:fabs(d1s)/2;*/ lpend = 0.0; /*(lend>lbeg)?fabs(d1s)/2:-fabs(d1s)/2;*/ psLegendBox( lx,ly,lwidth,lheight, lbeg,lend,lpbeg,lpend, ldnum,lf,lntic,ugrid,units, labelfont,labelsize, axescolor,gridcolor, lstyle); grestore(); } /* end PostScript */ showpage(); endeps(); if (curve) { free1int(npair); for (i=0; i<curve; i++) { free1float(x1curve[i]); free1float(x2curve[i]); } free1float(curvewidth); free1int(curvedash); free((void**)x1curve); free((void**)x2curve); free((void**)curvefile); free((void**)curvecolor); } return 0; }