int main(int argc, char* argv[]) { sf_file in=NULL; sf_init (argc,argv); in = sf_input("in"); vp_erase(); vp_stdplot_init (0.,2.,0.,1., true,false,true,true); vp_frame_init(in,"blt",false); vp_framenum(0.0001); vp_frame(); vp_erase(); vp_stdplot_init (0.,0.036,0.,0.9, true,false,true,false); vp_frame_init(in,"tlb",true); vp_framenum(15.); vp_frame(); vp_barframe_init (in,0.,1.); vp_barframe (); exit(0); }
static void setgraphics (float ox, float oz, float lengthx, float lengthz) { float dash[1]; float gap[1]; dash[0] = 0.1; dash[0] = 0.1; vp_init(); vp_erase (); vp_tjust (TH_CENTER, TV_TOP); vp_tfont (ROMANC, VP_STROKE, VP_NO_CHANGE); vp_purge (); vp_orig (XMIN + .165 * XMAX , YMIN + .875 * YMAX); vp_clip (-VP_MAX, -VP_MAX, VP_MAX, VP_MAX); vp_color (VP_RED); vp_fat (THIN); vp_setdash (dash, gap, 0); vp_uorig (ox , oz); vp_scale (0.75 * XMAX / (lengthx), -0.75 * YMAX / (lengthz)); return; }
static void feedpage (void) { vp_erase (); /* feed a page, and reset defaults */ vp_clip (0., 0., 8.0, 11.0);/* reset our clipping window */ vp_tfont (1, VP_STROKE, 0); /* reset our font */ vp_fat ((int) (charsz / 2));/* reset our fatness */ vp_orig (0., 0.); /* reset our origin */ vpos = 10.3; /* start at the top of the page */ }
int main(int argc, char* argv[]) { int n1, n2, n3, gainstep, panel, it, nreserve, i1, i2, i3, j, orient; float o1, o2, o3, d1, d2, d3, gpow, clip, pclip, phalf, bias=0., minmax[2]; float pbias, gain=0., x1, y1, x2, y2, **data=NULL, f, barmin, barmax, dat; bool transp, yreverse, xreverse, allpos, polarity, symcp, verb; bool eclip=false, egpow=false, barreverse, mean=false; bool scalebar, nomin=true, nomax=true, framenum, sfbyte, sfbar, charin; char *gainpanel, *color, *barfile; unsigned char tbl[TSIZE+1], **buf, tmp, *barbuf[1]; enum {GAIN_EACH=-3,GAIN_ALL=-2,NO_GAIN=-1}; off_t pos; sf_file in, out=NULL, bar=NULL; sf_init(argc,argv); in = sf_input("in"); sfbyte = (bool) (NULL != strstr (sf_getprog(),"byte")); sfbar = (bool) (NULL != strstr (sf_getprog(),"bar")); if (sfbyte) { out = sf_output("out"); sf_settype(out,SF_UCHAR); } else if (sfbar) { bar = sf_output("out"); sf_settype(bar,SF_UCHAR); } else { vp_init(); } charin = (bool) (SF_UCHAR == sf_gettype(in)); if (charin && sfbyte) sf_error("Cannot input uchar to byte"); if (!charin && SF_FLOAT != sf_gettype(in)) sf_error("Need float input"); if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(in,"n2",&n2)) n2=1; n3 = sf_leftsize(in,2); if (!sf_histfloat(in,"o1",&o1)) o1=0.; if (!sf_histfloat(in,"o2",&o2)) o2=0.; if (!sf_histfloat(in,"o3",&o3)) o3=0.; if (!sf_histfloat(in,"d1",&d1)) d1=1.; if (!sf_histfloat(in,"d2",&d2)) d2=1.; if (!sf_histfloat(in,"d3",&d3)) d3=1.; if (!sf_getbool("transp",&transp)) transp=true; /* if y, transpose the display axes */ if (!sf_getbool("yreverse",&yreverse)) yreverse=true; /* if y, reverse the vertical axis */ if (!sf_getbool("xreverse",&xreverse)) xreverse=false; /* if y, reverse the horizontal axis */ if (transp) { orient = 3; } else { orient = (xreverse==yreverse)? 0:2; } if (!charin) { panel = NO_GAIN; /* no need for gain */ phalf=85.; egpow = false; if (!sf_getfloat("gpow",&gpow)) { gpow=1.; /*( gpow=1 raise data to gpow power for display )*/ } else if (gpow <= 0.) { gpow=0.; egpow = true; sf_getfloat("phalf",&phalf); /* percentage for estimating gpow */ if (phalf <=0. || phalf > 100.) sf_error("phalf=%g should be > 0 and <= 100",phalf); panel = 0; } pclip=99.; eclip = (bool) (!sf_getfloat("clip",&clip)); /* data clip */ if (eclip) { clip = 0.; sf_getfloat("pclip",&pclip); /* data clip percentile (default is 99) */ if (pclip <=0. || pclip > 100.) sf_error("pclip=%g should be > 0 and <= 100",pclip); panel = 0; } else if (clip <= 0.) { sf_warning("clip=%g <= 0",clip); clip = FLT_EPSILON; } if (0==panel) { if (!sf_getint("gainstep",&gainstep)) gainstep=0.5+n1/256.; /* subsampling for gpow and clip estimation */ if (gainstep <= 0) gainstep=1; gainpanel = sf_getstring("gainpanel"); /* gain reference: 'a' for all, 'e' for each, or number */ if (NULL != gainpanel) { switch (gainpanel[0]) { case 'a': panel=GAIN_ALL; break; case 'e': panel=GAIN_EACH; break; default: if (0 ==sscanf(gainpanel,"%d",&panel) || panel < 1 || panel > n3) sf_error("gainpanel= should be all," " each, or a number" " between 1 and %d",n3); panel--; break; } free (gainpanel); } sf_unpipe(in,sf_filesize(in)*sizeof(float)); } if (!sf_getbool("allpos",&allpos)) allpos=false; /* if y, assume positive data */ if (!sf_getbool("mean",&mean)) mean=false; /* if y, bias on the mean value */ if (!sf_getfloat("bias",&pbias)) pbias=0.; /* value mapped to the center of the color table */ if (!sf_getbool("polarity",&polarity)) polarity=false; /* if y, reverse polarity (white is high by default) */ if (!sf_getbool("symcp",&symcp)) symcp=false; /* if y, assume symmetric color palette of 255 colors */ if (!sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ } /* if !charin */ barfile = sf_getstring("bar"); /* file for scalebar data */ if (sfbyte) { scalebar = (bool) (NULL != barfile); if (scalebar) sf_putstring(out,"bar",barfile); } else if (sfbar) { scalebar = true; } else { if (!sf_getbool ("wantscalebar",&scalebar) && !sf_getbool ("scalebar",&scalebar)) scalebar = false; /* if y, draw scalebar */ } if (scalebar) { nomin = (bool) (!sf_getfloat("minval",&barmin)); /* minimum value for scalebar (default is the data minimum) */ nomax = (bool) (!sf_getfloat("maxval",&barmax)); /* maximum value for scalebar (default is the data maximum) */ barbuf[0] = sf_ucharalloc(VP_BSIZE); if (!sf_getbool("barreverse",&barreverse)) barreverse=false; /* if y, go from small to large on the bar scale */ if (sfbyte || sfbar) { if (sfbyte) { bar = sf_output("bar"); sf_settype(bar,SF_UCHAR); } sf_putint(bar,"n1",VP_BSIZE+2*sizeof(float)); sf_putint(bar,"n2",1); sf_putint(bar,"n3",n3); if (!nomin) sf_putfloat(bar,"minval",barmin); if (!nomax) sf_putfloat(bar,"maxval",barmax); } else if (charin) { if (NULL == barfile) { barfile=sf_histstring(in,"bar"); if (NULL == barfile) sf_error("Need bar="); } bar = sf_input(barfile); if (SF_UCHAR != sf_gettype(bar)) sf_error("Need uchar in bar"); if (nomin) nomin = (bool) (!sf_histfloat(bar,"minval",&barmin)); if (nomax) nomax = (bool) (!sf_histfloat(bar,"maxval",&barmax)); } } if (!sf_getbool("wantframenum",&framenum)) framenum = (bool) (n3 > 1); /* if y, display third axis position in the corner */ x1 = o1-0.5*d1; x2 = o1+(n1-1)*d1+0.5*d1; y1 = o2-0.5*d2; y2 = o2+(n2-1)*d2+0.5*d2; if (!sfbyte && !sfbar) { vp_stdplot_init (x1, x2, y1, y2, transp, false, yreverse, false); vp_frame_init(in,"tlb",false); /* if (scalebar && !nomin && !nomax) vp_barframe_init (in,barmin,barmax); */ } if (transp) { f=x1; x1=y1; y1=f; f=x2; x2=y2; y2=f; } if (yreverse) { f=y1; y1=y2; y2=f; } if (xreverse) { f=x1; x1=x2; x2=f; } buf = sf_ucharalloc2(n1,n2); if (!charin) { data = sf_floatalloc2(n1,n2); if (GAIN_ALL==panel || panel >= 0) { pos = sf_tell(in); if (panel > 0) sf_seek(in, pos+panel*n1*n2*sizeof(float), SEEK_SET); vp_gainpar (in,data,n1,n2,gainstep, pclip,phalf,&clip,&gpow,mean,&pbias, n3,panel,panel); if (verb) sf_warning("panel=%d bias=%g clip=%g gpow=%g", panel,pbias,clip,gpow); if (sfbyte) sf_putfloat(out,"clip",clip); sf_seek(in,pos,SEEK_SET); /* rewind */ } } if (!sfbyte && !sfbar) { /* initialize color table */ if (NULL == (color = sf_getstring("color"))) color="i"; /* color scheme (default is i) */ if (!sf_getint ("nreserve",&nreserve)) nreserve = 8; /* reserved colors */ vp_rascoltab (nreserve, color); } for (i3=0; i3 < n3; i3++) { if (!charin) { if (GAIN_EACH == panel) { if (eclip) clip=0.; if (egpow) gpow=0.; vp_gainpar (in,data,n1,n2,gainstep, pclip,phalf,&clip,&gpow, mean,&pbias,n3,0,n3); if (verb) sf_warning("bias=%g clip=%g gpow=%g",pbias,clip,gpow); } else { sf_floatread(data[0],n1*n2,in); } if (1 == panel || GAIN_EACH == panel || 0==i3) { /* initialize the conversion table */ if(!allpos) { /* negative and positive values */ for (it=1; it<=TSIZE/2; it++) { if (symcp) { tbl[TSIZE-it] = (gpow != 1.)? 254*(pow(((TSIZE-2.0*it)/TSIZE),gpow)+1.)/2.+1.: 254*( ((TSIZE-2.0*it)/TSIZE) +1.)/2.+1.; tbl[it] = 255 - tbl[TSIZE-it] + 1.0; } else { tbl[TSIZE-it] = (gpow != 1.)? 252*(pow(((TSIZE-2.0*it)/TSIZE),gpow)+1.)/2.+3.: 252*( ((TSIZE-2.0*it)/TSIZE) +1.)/2.+3.; tbl[it] = 255 - tbl[TSIZE-it] + 2.0; } } bias = TSIZE/2.; gain = TSIZE/(2.*clip); } else { /* all positive */ if (symcp) { for (it=1; it < TSIZE ; it++) { tbl[it] = 255*((it-1.0)/TSIZE) + 1.0; } } else { for (it=1; it < TSIZE ; it++) { tbl[it] = 256*((it-1.0)/TSIZE); } } bias = 0.; gain = TSIZE/clip; } tbl[0] = tbl[1]; tbl[TSIZE] = tbl[TSIZE-1]; if (polarity) { /* switch polarity */ for (it=0; it<=TSIZE; it++) { tbl[it]=255-tbl[it]; } } } /* convert to bytes */ for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1; i1++) { j = (data[i2][i1]-pbias)*gain + bias; if (j < 0) j=0; else if (j > TSIZE) j=TSIZE; buf[i2][i1] = tbl[j]; } } } else { sf_ucharread(buf[0],n1*n2,in); } if (!sfbyte && !sfbar) { if (yreverse) { for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1/2; i1++) { tmp = buf[i2][i1]; buf[i2][i1] = buf[i2][n1-1-i1]; buf[i2][n1-1-i1] = tmp; } } } if ((xreverse && transp) || (!xreverse && !transp)) { for (i2=0; i2 < n2/2; i2++) { for (i1=0; i1 < n1; i1++) { tmp = buf[i2][i1]; buf[i2][i1] = buf[n2-1-i2][i1]; buf[n2-1-i2][i1] = tmp; } } } if (i3 > 0) vp_erase (); if (framenum) vp_framenum(o3+i3*d3); vp_frame(); vp_uraster (buf, false, 256, n1, n2, x1, y1, x2, y2, orient); vp_simpleframe(); } if (scalebar) { if (!charin) { if (nomin) barmin = data[0][0]; if (nomax) barmax = data[0][0]; if (nomin || nomax) { for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1; i1++) { dat = data[i2][i1]; if (nomin && barmin > dat) barmin = dat; if (nomax && barmax < dat) barmax = dat; } } } for (it=0; it < VP_BSIZE; it++) { if (barreverse) { dat = (barmin*it + barmax*(VP_BSIZE-1-it))/(VP_BSIZE-1); } else { dat = (barmax*it + barmin*(VP_BSIZE-1-it))/(VP_BSIZE-1); } j = (dat-pbias)*gain + bias; if (j < 0) j=0; else if (j > TSIZE) j=TSIZE; barbuf[0][it] = tbl[j]; } } else { sf_floatread(minmax,2,bar); sf_ucharread(barbuf[0],VP_BSIZE,bar); if (nomin) barmin=minmax[0]; if (nomax) barmax=minmax[1]; } if (sfbyte || sfbar) { sf_floatwrite(&barmin,1,bar); sf_floatwrite(&barmax,1,bar); sf_ucharwrite(barbuf[0],VP_BSIZE,bar); } else { if (barreverse) { vp_barframe_init (in,barmax,barmin); } else { vp_barframe_init (in,barmin,barmax); } vp_barraster(VP_BSIZE, barbuf); } } /* if scalebar */ if (sfbyte) { sf_ucharwrite(buf[0],n1*n2,out); } else if (!sfbar) { vp_purge(); } } /* i3 loop */ exit (0); }
int main (void) { float xval[NARRAY], zval[NARRAY]; int plotfat=1, ith, iflag, emph; bool wantframe=false,option=true,animate=false; float xll=1.705,yll=1.37,xur=11.945,yur=8.87; float h=1.0,y=0.0,time=1.6,v=2.0,theta=30., xstart, zstart; float a, b, xs, xg, surface,slop,xmin,zmin,xmax,zmax; float xscale, zscale, dth, thtmp, xsp; float tanth, sinth, costh, d, xr, zr, x,z, x1,z1, xend,zend; vp_init(); /* set parameters */ a = v * time /2.; b = sqrtf(a*a-h*h); xs = y - h; xg = y + h; surface = 0.; slop = 0.05*a; xmin = -2.; zmin = -1.; xmax = 2.; zmax = 2.; /* set vplot scales */ vp_orig(xll,yur); vp_uorig(xmin,zmin); xscale = (xur-xll)/(xmax-xmin); zscale = -(yur-yll)/(zmax-zmin); vp_scale(xscale,zscale); /* draw and annotate surface */ vp_fat(2*plotfat); vp_color(7); vp_umove(xmin,surface); vp_udraw(xmax,surface); vp_color(5); vp_fat(plotfat); vp_tjust(4,6); vp_utext(xs-0.5*slop,surface-slop,8,0,"S"); vp_utext(xg,surface-slop,8,0,"G"); vp_utext(y,surface-slop,8,0,"M"); dth = 180./(NARRAY-1); vp_color(4); /* LOOP on theta (ith) to generate ellipse */ for (ith = 0; ith < NARRAY; ith++) { thtmp = 90. - ith * dth; thtmp = thtmp*SF_PI/180.; tanth = tanf(thtmp); sinth = sinf(thtmp); costh = cosf(thtmp); d = hypotf(a*sinth,b*costh); xr = y - d*sinth - h*h*costh*costh*sinth/d; zr = surface + d*costh - h*h*costh*sinth*sinth/d; xval[ith] = xr; zval[ith] = zr; } /* Draw ellipse */ vp_color(5); vp_upline(xval,zval,NARRAY); if (option) { /* Loop on theta to draw SRG raypaths */ iflag = 0; emph = 3; for (ith = 0; ith < NARRAY; ith +=5) { iflag++; thtmp = 90. - ith * dth; thtmp = thtmp*SF_PI/180.; tanth = tanf(thtmp); sinth = sinf(thtmp); costh = cosf(thtmp); d = hypotf(a*sinth,b*costh); xr = y - d*sinth - h*h*costh*costh*sinth/d; zr = surface + d*costh - h*h*costh*sinth*sinth/d; /* Shot to reflection point */ vp_color(4); x = xs; z = surface; x1 = xr; z1 = zr; if(iflag == emph) vp_color(6); if(ith != 1 && ith != NARRAY) vp_uarrow(x,z,x1,z1,0.02*zmax); if(iflag == emph) vp_color(4); /* Annotate beta */ xend = (xs + xr)/2.; zend = (surface + zr)/2.; if(iflag == emph) { vp_color(6); vp_utext(xend-slop, zend+0.8*slop,8,0,"\\F9 b"); vp_color(4); } /* reflection point to geophone */ x = xr; z = zr; vp_umove(x,z); x1 = xg; z1 = surface; if(iflag == emph) vp_color(6); if(ith != 1 && ith != NARRAY) vp_uarrow(x,z,x1,z1,0.02*zmax); if(iflag == emph) vp_color(6); /* Annotate alpha */ xend = (xg + xr)/2.; zend = (surface + zr)/2.; if(iflag == emph) { vp_color(6); vp_utext(xend+slop, zend+0.5*slop,8,0,"\\F9 a"); vp_color(4); } if(animate) { vp_erase(); /* clear screen, then redraw basic stuff */ /* redraw and annotate surface */ vp_fat(2*plotfat); vp_color(7); vp_umove(xmin,surface); vp_udraw(xmax,surface); vp_color(5); vp_fat(plotfat); vp_tjust(4,6); vp_utext(xs-0.5*slop,surface-slop,8,0,"S"); vp_utext(xg,surface-slop,8,0,"G"); vp_utext(y,surface-slop,8,0,"M"); /* redraw ellipse */ vp_color(5); vp_upline(xval,zval,NARRAY); } } /* end loop on theta */ } else { /* Begin work for drawing dipping layer */ theta *= SF_PI/180.; tanth = tanf(theta); sinth = sinf(theta); costh = cosf(theta); d = hypotf(a*sinth,b*costh); xr = y - d*sinth - h*h*costh*costh*sinth/d; zr = surface + d*costh - h*h*costh*sinth*sinth/d; xsp = y - h - 2*(d-h*sinth)*sinth; xstart = xsp; zstart = surface + d/costh + tanth * (xstart-y); xend = 0.5*(xg + y); zend = surface + d/costh + tanth * (xend-y); /* Draw dipping reflector */ vp_color(2); vp_umove(xstart,zstart); vp_udraw(xend,zend); vp_dash(0.,0.,0.,0.); /* indicate angle theta */ vp_color(7); vp_dash(.1,.1,.1,.1); vp_umove(xend,zend); vp_udraw(xend-0.5*h,zend); vp_dash(.0,.0,.0,.0); /* finite-offset raypaths */ vp_color(4); /* Shot to reflection point */ vp_uarrow(xs,surface,xr,zr,0.02*zmax); /* reflection point to geophone */ vp_uarrow(xr,zr,xg,surface,0.02*zmax); /* text */ vp_color(5); vp_fat(plotfat); vp_tjust(4,6); vp_utext(xr,zr+2.0*slop,8,0,"R"); vp_utext(xend-5*slop, zend-1.*slop,8,0,"\\F9 q"); } if(wantframe) { vp_dash(0.,0.,0.,0.); vp_color(7); vp_fat(1); vp_umove(xmin,zmin); vp_udraw(xmin,zmax); vp_udraw(xmax,zmax); vp_udraw(xmax,zmin); vp_udraw(xmin,zmin); } return 0; }
int main(int argc, char* argv[]) { int n1,n2,n3, frame2,frame3, i1,i2,i3, iframe, np=3, orient; int n1pix,n2pix, m1pix,m2pix, n1front,n2front, movie, nframe=1; float point1, point2, **front, **side, **top, **topt, *x, *y, o1, d1, o2, d2; float min, max, f, frame1, dframe, oo1, dd1; bool nomin, nomax, yreverse; char *label1, *label2, *unit1, *unit2; off_t esize; bool flat; vp_contour cnt; sf_file in=NULL; sf_init(argc,argv); in = sf_input("in"); vp_init(); if (SF_FLOAT != sf_gettype(in)) sf_error("Need float input"); if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(in,"n2",&n2)) n2=1; n3 = sf_leftsize(in,2); esize = sf_esize(in); sf_unpipe(in,n1*n2*n3*esize); if (!sf_getint("orient",&orient)) orient=1; /* function orientation */ if (!sf_getbool("yreverse",&yreverse)) yreverse=false; front = sf_floatalloc2(n1,1); side = sf_floatalloc2(1,n2); top = sf_floatalloc2(n1,n2); topt = (2==orient)? sf_floatalloc2(n2,n1): NULL; nomin = (bool) !sf_getfloat("min",&min); /* minimum function value */ nomax = (bool) !sf_getfloat("max",&max); /* maximum function value */ if (nomin) min = +FLT_MAX; if (nomax) max = -FLT_MAX; if (nomin || nomax) { for (i3=0; i3 < n3; i3++) { sf_floatread(top[0],n1*n2,in); for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1; i1++) { f = top[i2][i1]; if (nomax && f > max) max=f; if (nomin && f < min) min=f; } } } } if (min == 0. && max == 0.) { min = -1.; max = 1.; } else if (min == max) { max *= 1.04; min *= 0.96; } if (!sf_histfloat(in,"o1",&o1)) o1=0.; if (!sf_histfloat(in,"d1",&d1)) d1=1.; if (!sf_histfloat(in,"o2",&o2)) o2=0.; if (!sf_histfloat(in,"d2",&d2)) d2=1.; switch(orient) { case 1: default: dd1 = (min-max)/np; oo1 = max+0.5*dd1; sf_putint(in,"n1",np); sf_putfloat(in,"o1",oo1); sf_putfloat(in,"d1",dd1); sf_putint(in,"n2",n1); sf_putfloat(in,"o2",o1); sf_putfloat(in,"d2",d1); sf_putint(in,"n3",n2); sf_putfloat(in,"o3",o2); sf_putfloat(in,"d3",d2); break; case 2: dd1 = (max-min)/np; oo1 = min+0.5*dd1; sf_putint(in,"n2",np); sf_putfloat(in,"o2",oo1); sf_putfloat(in,"d2",dd1); sf_putint(in,"n3",n2); sf_putfloat(in,"o3",o2); sf_putfloat(in,"d3",d2); break; case 3: dd1 = (max-min)/np; oo1 = min+0.5*dd1; sf_putint(in,"n1",n2); sf_putfloat(in,"o1",o2); sf_putfloat(in,"d1",d2); sf_putint(in,"n2",n1); sf_putfloat(in,"o2",o1); sf_putfloat(in,"d2",d1); sf_putint(in,"n3",np); sf_putfloat(in,"o3",oo1); sf_putfloat(in,"d3",dd1); break; } label1 = sf_histstring(in,"label1"); label2 = sf_histstring(in,"label2"); if (NULL != label1) { sf_putstring(in,"label1",""); sf_putstring(in,"label2",label1); free(label1); } if (NULL != label2) { sf_putstring(in,"label3",label2); free(label2); } unit1 = sf_histstring(in,"unit1"); unit2 = sf_histstring(in,"unit2"); if (NULL != unit1) { sf_putstring(in,"unit1",""); sf_putstring(in,"unit2",unit1); free(unit1); } if (NULL != unit2) { sf_putstring(in,"unit3",unit2); free(unit2); } if (!sf_getfloat("point1",&point1)) point1=0.5; /* fraction of the vertical axis for front face */ if (!sf_getfloat("point2",&point2)) point2=0.5; /* fraction of the horizontal axis for front face */ if (!sf_getfloat("frame1",&frame1)) frame1=0.5*(min+max); if (!sf_getint("frame2",&frame2)) frame2=n1-1; if (!sf_getint("frame3",&frame3)) frame3=0; /* frame numbers for cube faces */ /* sanity check */ if (min < max) { if (frame1 < min) frame1 = min; if (frame1 > max) frame1 = max; } else { if (frame1 > min) frame1 = min; if (frame1 < max) frame1 = max; } if (frame2 < 0) frame2 = 0; if (frame3 < 0) frame3 = 0; if (frame2 >= n1) frame2 = n1-1; if (frame3 >= n2) frame3 = n2-1; if (!sf_getint("movie",&movie)) movie=0; /* 0: no movie, 1: movie over axis 1, 2: axis 2, 3: axis 3 */ if (!sf_getfloat("dframe",&dframe)) dframe=1; /* frame increment in a movie */ switch (movie) { case 0: nframe = 1; break; case 1: nframe = 0.5+(max-frame1)/dframe; break; case 2: nframe = (n1-frame2)/dframe; break; case 3: nframe = (n2-frame3)/dframe; break; default: sf_error("movie=%d is outside [0,3]",movie); break; } if (sf_getint("nframe",&iframe) && iframe < nframe) nframe=iframe; /* number of frames in a movie */ if (nframe < 1) nframe=1; if (!sf_getint("n1pix",&n1pix)) n1pix = n1/point1+n3/(1.-point1); /* number of vertical pixels */ if (!sf_getint("n2pix",&n2pix)) n2pix = n2/point2+n3/(1.-point2); /* number of horizontal pixels */ m1pix = VP_STANDARD_HEIGHT*72; m2pix = VP_STANDARD_HEIGHT*72/VP_SCREEN_RATIO; if (n1pix < m1pix) n1pix=m1pix; if (n2pix < m2pix) n2pix=m2pix; n1front = n1pix*point1; n2front = n2pix*point2; if (n1front <= 0) n1front=1; if (n2front <= 0) n2front=1; if (n1front >= n1pix) n1front=n1pix-1; if (n2front >= n2pix) n2front=n2pix-1; x = sf_floatalloc(n1); y = sf_floatalloc(n2); for (i1=0; i1 < n1; i1++) { x[i1] = o1 + i1*d1; } for (i2=0; i2 < n2; i2++) { y[i2] = o2 + i2*d2; } if (!sf_getbool("flat",&flat)) flat=true; /* if n, display perspective view */ vp_cubeplot_init (n1pix, n2pix, n1front, n2front, flat, false); vp_frame_init (in,"blt",false); vp_plot_init(n3); cnt = vp_contour_init(false, n1,o1,d1,0., n2,o2,d2,0.); for (iframe=0; iframe < nframe; iframe++) { if (iframe > 0) vp_erase (); for (i3=0; i3 < n3; i3++) { vp_plot_set (i3); /* front face */ switch(orient) { case 1: default: sf_seek(in,(off_t) (i3*n1*n2+frame3*n1)*esize,SEEK_SET); sf_floatread(front[0],n1,in); vp_cubecoord(3,x[0],x[n1-1],min,max); vp_umove(x[0],front[0][0]); for (i1=1; i1 < n1; i1++) { vp_udraw(x[i1],front[0][i1]); } break; case 2: sf_seek(in,(off_t) (i3*n1*n2+frame3*n1)*esize,SEEK_SET); sf_floatread(front[0],n1,in); if (yreverse) { vp_cubecoord(3,min,max,x[n1-1],x[0]); vp_umove(front[0][n1-1],x[n1-1]); for (i1=n1-2; i1 >= 0; i1--) { vp_udraw(front[0][i1],x[i1]); } } else { vp_cubecoord(3,min,max,x[0],x[n1-1]); vp_umove(front[0][0],x[0]); for (i1=1; i1 < n1; i1++) { vp_udraw(front[0][i1],x[i1]); } } break; case 3: sf_seek(in,(off_t) (i3*n1*n2*esize),SEEK_SET); sf_floatread(top[0],n1*n2,in); vp_cubecoord(3,x[0],x[n1-1],y[0],y[n2-1]); vp_contour_draw(cnt,false,top,frame1); break; } /* side face */ switch(orient) { case 1: default: for (i2=0; i2 < n2; i2++) { sf_seek(in,(off_t) (i3*n1*n2+i2*n1+frame2)*esize,SEEK_SET); sf_floatread(side[i2],1,in); } vp_cubecoord(2,y[0],y[n2-1],min,max); vp_umove(y[0],side[0][0]); for (i2=1; i2 < n2; i2++) { vp_udraw(y[i2],side[i2][0]); } break; case 2: sf_seek(in,(off_t) (i3*n1*n2*esize),SEEK_SET); sf_floatread(top[0],n1*n2,in); /* transpose */ for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1; i1++) { topt[i1][i2] = top[i2][i1]; } } if (yreverse) { vp_cubecoord(2,y[0],y[n2-1],x[n1-1],x[0]); } else { vp_cubecoord(2,y[0],y[n2-1],x[0],x[n1-1]); } vp_contour_draw(cnt,false,topt,frame1); break; case 3: for (i2=0; i2 < n2; i2++) { sf_seek(in,(off_t) (i3*n1*n2+i2*n1+frame2)*esize,SEEK_SET); sf_floatread(side[i2],1,in); } vp_cubecoord(2,min,max,y[0],y[n2-1]); vp_umove(side[0][0],y[0]); for (i2=1; i2 < n2; i2++) { vp_udraw(side[i2][0],y[i2]); } break; } /* top face */ switch(orient) { case 1: default: sf_seek(in,(off_t) (i3*n1*n2*esize),SEEK_SET); sf_floatread(top[0],n1*n2,in); vp_cubecoord(1,x[0],x[n1-1],y[0],y[n2-1]); vp_contour_draw(cnt,false,top,frame1); break; case 2: for (i2=0; i2 < n2; i2++) { sf_seek(in,(off_t) (i3*n1*n2+i2*n1+frame2)*esize,SEEK_SET); sf_floatread(side[i2],1,in); } vp_cubecoord(1,min,max,y[0],y[n2-1]); vp_umove(side[0][0],y[0]); for (i2=1; i2 < n2; i2++) { vp_udraw(side[i2][0],y[i2]); } break; case 3: sf_seek(in,(off_t) (i3*n1*n2+frame3*n1)*esize,SEEK_SET); sf_floatread(front[0],n1,in); vp_cubecoord(1,x[0],x[n1-1],min,max); vp_umove(x[0],front[0][0]); for (i1=1; i1 < n1; i1++) { vp_udraw(x[i1],front[0][i1]); } break; } } vp_plot_unset(); vp_coordinates(); switch(orient) { case 1: default: vp_cubeframe((frame1-oo1)/dd1,frame2,frame3); break; case 2: vp_cubeframe(frame2,(frame1-oo1)/dd1,frame3); break; case 3: vp_cubeframe(frame2,frame3,(frame1-oo1)/dd1); break; } switch (movie) { case 2: frame2 += (int) dframe; break; case 3: frame3 += (int) dframe; break; case 1: frame1 += dframe; break; default: break; } vp_purge(); } /* frame loop */ exit(0); }
int main(int argc, char* argv[]) { int nang, N; float dx, dz; int nx, nz; float ox, oz; int gnx, gnz; float gdx, gdz, gox, goz; struct point length; int inter; float TETAMAX, alpha2; FILE *outfile; int ii; int rays, wfront, gap; int lomx, first; int nr, nrmax, nt; int prcube, pr, ste; int ns, nou; float DSmax, dt, T, freq; float *vel; float ds, os, goox; float xmin, xmax, zmin, zmax; float depth; struct point *pos; struct heptagon *cube; struct grid *out; sf_file inp, ampl, time; sf_init(argc,argv); inp = sf_input("in"); /* GET MODEL PARAMETERS */ if (!sf_histint(inp,"n1",&nz)) sf_error("No n1= in input"); if (!sf_histint(inp,"n2",&nx)) sf_error("No n2= in input"); if (!sf_histfloat(inp,"d1",&dz)) sf_error("No d1= in input"); if (!sf_histfloat(inp,"d2",&dx)) sf_error("No d2= in input"); if (!sf_histfloat(inp,"o1",&oz)) sf_error("No o1= in input"); if (!sf_histfloat(inp,"o2",&ox)) sf_error("No o2= in input"); /* GET TRACING PARAMETERS */ if(!sf_getint("nang",&nang)) nang = 10; /* Number of take-off angles */ if(!sf_getint("rays",&rays)) rays = 0; /* If draw rays */ if(!sf_getint("wfront",&wfront)) wfront = 0; /* If draw wavefronts */ if(!sf_getint("gap",&gap)) gap = 1; /* Draw wavefronts every gap intervals */ if(!sf_getint("inter",&inter)) inter = 1; /* If use linear interpolation */ if(!sf_getfloat("DSmax",&DSmax)) DSmax = 5; /* Maximum distance between contiguos points of a wavefront */ if(!sf_getfloat("dt",&dt)) dt = 0.0005; /* time step */ if(!sf_getint("nt",&nt)) nt = 5; /* Number of time steps between wavefronts */ if(!sf_getint("nrmax",&nrmax)) nrmax = 2000; /* Maximum number of points that define a wavefront */ if(!sf_getint("lomx",&lomx)) lomx = 1; /* Use Lomax's waveray method */ if(!sf_getint("first",&first)) first = 1; /* Obtain first arrivals only */ if(!sf_getint("nou",&nou)) nou = 6; /* GET GRIDDING PARAMETERS */ if(!sf_getint("gnx",&gnx)) gnx = nx; /* Coordinates of output grid */ if(!sf_getint("gnz",&gnz)) gnz = nz; if(!sf_getfloat("gdx",&gdx)) gdx = dx; if(!sf_getfloat("gdz",&gdz)) gdz = dz; if(!sf_getfloat("gox",&goox)) goox = ox; if(!sf_getfloat("goz",&goz)) goz = oz; /* GET LOMAX SPECIFIC PARAMETERS */ if(!sf_getint("N",&N)) N = 3; /* Number of control points */ if(!sf_getfloat("TETAMAX",&TETAMAX)) TETAMAX = 1.5; /* Truncation parameter */ if(!sf_getfloat("alpha2",&alpha2)) alpha2 = 4.0; /* Width of gaussian weighting function */ if(!sf_getfloat("freq",&freq)) freq = 100.; /* Pseudo-frequency of waverays */ /* GET DEBUGGING INFO */ if(!sf_getint("prcube",&prcube)) prcube=0; /* For debugging porpouses */ if(!sf_getint("pr",&pr)) pr=0; /* For debugging porpouses */ /* GET SOURCE LOCATIONS */ if(!sf_getint("ns",&ns) || ns==0) ns=1; /* Number of source locations */ if(!sf_getfloat("ds",&ds)) ds=1.; /* interval between sources */ if(!sf_getfloat("os",&os)) os=0.; /* first source location */ if(!sf_getfloat("depth",&depth)) depth=dz; /* Depth location of sources */ pos = (struct point *) sf_alloc (ns,sizeof(struct point)); for(ii=0;ii<ns;ii++) { pos[ii] = makepoint(ii*ds + os, depth); } /* PREPARE OUTPUT */ ampl = sf_output("ampl"); sf_putint(ampl,"n1",gnz); sf_putint(ampl,"n2",gnx); sf_putint(ampl,"n3",ns); sf_putfloat(ampl,"d1",gdz); sf_putfloat(ampl,"d2",gdx); sf_putfloat(ampl,"d3",ds); sf_putfloat(ampl,"o1",goz); sf_putfloat(ampl,"o2",goox); sf_putfloat(ampl,"o3",os); time = sf_output("time"); sf_putint(time,"n1",gnz); sf_putint(time,"n2",gnx); sf_putint(time,"n3",ns); sf_putfloat(time,"d1",gdz); sf_putfloat(time,"d2",gdx); sf_putfloat(time,"d3",ds); sf_putfloat(time,"o1",goz); sf_putfloat(time,"o2",goox); sf_putfloat(time,"o3",os); /* READ VELOCITY MODEL */ vel = sf_floatalloc(nx*nz+2); sf_floatread(vel,nx*nz,inp); /* ALLOCATE MEMORY FOR OUTPUT */ out = (struct grid *) sf_alloc (1,sizeof(struct grid)); out->time = sf_floatalloc (gnx*gnz); out->ampl = sf_floatalloc (gnx*gnz); out->flag = sf_intalloc (gnx*gnz); T = 1. / freq; length = makepoint((nx-1)*dx,(nz-1)*dz); cube = (struct heptagon *) sf_alloc (nrmax,sizeof(struct heptagon)); /* FOR DEBUGGING PORPOUSES, PRINT TO FILE */ if(pr||prcube) { outfile = fopen("junk","w"); } else { outfile = NULL; } /* SET DISPLAY IN ORDER TO SHOW RAYS ON SCREEN */ /* NOTE: THIS PROGRAM USES DIRECT CALLS TO LIB_VPLOT * TO DRAW THE RAYS AND THE WAVEFRONTS */ if(rays || wfront) { setgraphics(ox, oz, length.x, length.z); /* vp_color(BLUE); for(ii=0;ii<gnx;ii++) { vp_umove(ii*gdx+gox, goz); vp_udraw(ii*gdx+gox, (gnz-1)*gdz+goz); } for(ii=0;ii<gnz;ii++) { vp_umove(gox, ii*gdz+goz); vp_udraw((gnx-1)*gdx+gox, ii*gdz+goz); } */ } norsar_init(gnx,gnz, TETAMAX,N,alpha2,inter, nx,nz,ox,oz,dx,dz,length); /* ALGORITHM: * For every source: */ for(ii=0;ii<ns;ii++) { ste = 0; gox = goox + pos[ii].x; sf_warning("\nSource #%d\n", ii); /* 1.- Construct the inital wavefront */ nr = nang; initial (pos[ii], cube, vel, dt, nt, T, lomx, nr, out); gridding_init(gnx,gnz, gdx,gdz,gox,goz, outfile); /* run while the wavefront is not too small */ while (nr > 4) { ste++; /* 2.- Propagate wavefront */ wavefront (cube, nr, vel, dt, nt, T, lomx); if(prcube || pr) { fprintf(outfile,"\n\nwavefront"); printcube(cube, nr, outfile); } /* 3.- Get rid of caustics */ if(first) { if(ste%2==1) { caustics_up (cube, 0, nr); } else { caustics_down (cube, nr-1, nr); } if(prcube || pr) { fprintf(outfile,"\n\ncaustics"); printcube(cube, nr, outfile); } } /* 4.- Eliminate rays that cross boundaries, defined by xmin, xmax, zmin, zmax. Note that the computational grid is a little bigger than the ouput grid. */ xmin = gox-nou*gdx; xmax = 2*pos[ii].x-gox+nou*gdx; zmin = oz-nou*gdz; zmax = length.z+oz+nou*gdz; mark_pts_outofbounds (cube, nr, xmin, xmax, zmin, zmax); if(prcube) { fprintf(outfile, "\n\nboundaries"); printcube(cube, nr, outfile); } /* 5.- Rearrange cube */ makeup(cube, &nr); if(nr<4) break; if(prcube || pr) { fprintf(outfile, "\n\nmakeup"); printcube(cube, nr, outfile); } /* 6.- Calculate amplitudes for new wavefront */ amplitudes (cube, nr); if(prcube) { fprintf(outfile, "\n\namplitudes"); printcube(cube, nr, outfile); } /* 7.- Draw rays */ if(rays) draw_rays (cube, nr); /* 8.- Draw wavefront */ if(wfront && (ste%gap==0)) draw_wavefronts (cube, nr, DSmax); /* 9.- Parameter estimation at receivers */ gridding (cube, nr, out, DSmax, (ste-1)*nt*dt, vel, first); /* pos[ii]); */ /* 10.- Interpolate new points of wavefront */ interpolation (cube, &nr, nrmax, DSmax); /* 0); */ if(prcube) { fprintf(outfile,"\n\ninterpolation"); printcube(cube, nr, outfile); } /* 11.- Prepare to trace new wavefront */ movwavf (cube, nr); if(prcube) { fprintf(outfile,"\n\nmovwavf"); printcube(cube, nr, outfile); } if((wfront || rays) && (ste%gap==0)) vp_erase(); } /* Finally interpolate amplitude and traveltime values to receivers that has not being covered. */ TwoD_interp (out, gnx, gnz); sf_floatwrite(out->time, gnx * gnz, time); sf_floatwrite(out->ampl, gnx * gnz, ampl); } if(pr||prcube) fclose(outfile); exit(0); }
int main(int argc, char* argv[]) { bool transp, start, scalebar, nomin=true, nomax=true, barreverse, framenum; int n1, n2, n3, i1, i2, i3, len, nreserve; float min1, max1, min2, max2, o3, d3, o1, d1, xi, yi, tt; float **x, **y, **tmp, *symbolsz=NULL, symsize, xc, yc; float ***data=NULL, barmin, barmax, minmax[2]; char *symbol, sym[2]=" ", *color=NULL, *barfile; unsigned char **z=NULL, *barbuf[1]; sf_datatype type; sf_file in, depth, bar=NULL; sf_init(argc,argv); in = sf_input("in"); vp_init(); if (NULL != sf_getstring("depth")) { depth = sf_input("depth"); /* values for colored plots */ if (SF_UCHAR != sf_gettype(depth)) sf_error("Need uchar in depth"); } else { depth = NULL; } if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(in,"n2",&n2)) n2=1; n = n1*n2; n3 = sf_leftsize(in,2); if (n3 > 1) { if (!sf_histfloat(in,"o3",&o3)) o3=0.; if (!sf_histfloat(in,"d3",&d3)) d3=1.; } x = sf_floatalloc2(n1,n2); y = sf_floatalloc2(n1,n2); t = sf_floatalloc(n); if (!sf_getbool("scalebar",&scalebar)) scalebar=false; /* if y, draw scalebar */ if (!sf_getbool("wantframenum",&framenum)) framenum = (bool) (n3 > 1); /* if y, display third axis position in the corner */ if (NULL != depth) { z = sf_ucharalloc2(n1,n2); /* initialize color table */ if (NULL == (color = sf_getstring("color"))) color="j"; /* color scheme (default is j) */ if (!sf_getint ("nreserve",&nreserve)) nreserve = 8; /* reserved colors */ vp_rascoltab(nreserve,color); if (scalebar) { barfile = sf_getstring("bar"); /* file for scalebar data */ if (NULL == barfile) { barfile=sf_histstring(depth,"bar"); if (NULL == barfile) sf_error("Need bar="); } nomin = (bool) (!sf_getfloat("minval",&barmin)); /* minimum value for scalebar (default is the data minimum) */ nomax = (bool) (!sf_getfloat("maxval",&barmax)); /* maximum value for scalebar (default is the data maximum) */ bar = sf_input(barfile); if (SF_UCHAR != sf_gettype(bar)) sf_error("Need uchar in bar"); if (nomin) nomin = (bool) (!sf_histfloat(bar,"minval",&barmin)); if (nomax) nomax = (bool) (!sf_histfloat(bar,"maxval",&barmax)); barbuf[0] = (unsigned char*) sf_alloc(VP_BSIZE,sizeof(unsigned char)); if (!sf_getbool("barreverse",&barreverse)) barreverse=false; /* if y, go from small to large on the bar scale */ } } if (!sf_getfloat("pclip",&pclip)) pclip=100.; /* clip percentile */ type = sf_gettype(in); switch (type) { case SF_FLOAT: if (!sf_histfloat(in,"o1",&o1)) o1=0.; if (!sf_histfloat(in,"d1",&d1)) d1=1.; for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1; i1++) { x[i2][i1] = o1 + i1*d1; } } break; case SF_COMPLEX: data = sf_floatalloc3(2,n1,n2); break; default: sf_error("Wrong data type (need float or complex)"); } vp_plot_init(n2); symbol = sf_getstring("symbol"); /* if set, plot with symbols instead of lines */ if (NULL != symbol) { len = strlen(symbol); if (len < n2) { symbol = (char*) sf_realloc(symbol,n2,sizeof(char)); for (i2=len; i2 < n2; i2++) { symbol[i2] = symbol[i2 % len]; } } symbolsz = sf_floatalloc(n2); if (!sf_getfloats("symbolsz",symbolsz,n2)) { /* symbol size (default is 2) */ for (i2 = 0; i2 < n2; i2++) symbolsz[i2] = 2./33.; } else { for (i2 = 0; i2 < n2; i2++) symbolsz[i2] /= 33.; } } if (!sf_getbool ("transp",&transp)) transp=false; /* if y, transpose the axes */ for (i3 = 0; i3 < n3; i3++) { if (SF_COMPLEX == type) { sf_floatread(data[0][0],2*n,in); for (i2=0; i2 < n2; i2++) { for (i1=0; i1 < n1; i1++) { x[i2][i1] = data[i2][i1][0]; y[i2][i1] = data[i2][i1][1]; } } getminmax(x[0],&min1,&max1); } else { sf_floatread(y[0],n,in); min1=o1; max1=o1+(n1-1)*d1; } getminmax(y[0],&min2,&max2); if (NULL != depth) sf_ucharread(z[0],n,depth); vp_stdplot_init (min1, max1, min2, max2, transp,false,false,true); vp_frame_init(in,"blt",false); if (transp) { tmp=x; x=y; y=tmp; tt=max1; max1=max2; max2=tt; tt=min1; min1=min2; min2=tt; } if (i3 > 0) vp_erase(); if (framenum) vp_framenum(o3+i3*d3); vp_frame(); for (i2=0; i2 < n2; i2++) { vp_plot_set (i2); symsize = 2./33.; if (NULL != symbol) { sym[0] = symbol[i2]; symsize = symbolsz[i2]; } start = true; for (i1=0; i1 < n1; i1++) { xi = x[i2][i1]; yi = y[i2][i1]; if (NULL != depth) vp_color(z[i2][i1]+256); if (isfinite(xi) && isfinite(yi)) { if (NULL != symbol) { vp_umove(xi,yi); vp_where (&xc, &yc); vp_tjust (TH_SYMBOL, TV_SYMBOL); vp_gtext (xc,yc,symsize,0.,0.,symsize,sym); } else if (start) { vp_umove(xi,yi); start=false; } else { vp_udraw(xi,yi); } } else { start=true; } } } if (depth && scalebar) { sf_floatread(minmax,2,bar); sf_ucharread(barbuf[0],VP_BSIZE,bar); if (nomin) barmin=minmax[0]; if (nomax) barmax=minmax[1]; if (barreverse) { vp_barframe_init (depth,barmax,barmin); } else { vp_barframe_init (depth,barmin,barmax); } vp_barraster(VP_BSIZE, barbuf); } if (transp) { tmp=x; x=y; y=tmp; tt=max1; max1=max2; max2=tt; tt=min1; min1=min2; min2=tt; } } exit(0); }