Beispiel #1
0
static void tjust(bool where)
{
    if (where) {
	vp_tjust (TH_CENTER, TV_TOP);
    } else {
	vp_tjust (TH_CENTER, TV_BOTTOM);
    }

/*	vp_tjust (TH_SYMBOL, TV_SYMBOL); */
}
Beispiel #2
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;
}
Beispiel #3
0
static void mapunit (char *symbol, char *text)	
/* produce an entry for a map legend */
{
    if (vpos < 1.0)		/* leave 1" bottom margin */
	feedpage ();
    vpos -= vspace / 2;		/* space down a half line */
    if (strcmp (symbol, "nobox"))	/* strcmp==TRUE means `no match' */
    {
	drawbox (tab[0], vpos);	/* draw the box */
	vp_tjust (TH_CENTER, TV_HALF);	/* center the symbol in the box */
	vp_fat ((int) ((charsz - 1) / 2));	/* pick a good text fatness */
	vp_text (tab[0] + (boxsz[0] / 2),
		 vpos, charsz - 1, 0, symbol);	/* write the map symbol */
    }
    vp_fat ((int) (charsz / 2));
    vp_tjust (TH_LEFT, TV_HALF);/* reset left justification */
    vp_text (tab[1], vpos, charsz, 0, text);	/* write the explanation */
    vpos -= vspace / 2;		/* space down a half line */
}
Beispiel #4
0
int main(void)
{
    bool wantframe=false;
    float xll=1.705,yll=1.37,xur=11.945,yur=8.87,theta3=20.;
    float sn[3],cs[3],vv[3]={1.5,2.0,2.5},dz[3]={1.0,2.0,1.5};
    float zbottom, h, t, x, z, x1,z1, xtxt, ztxt;
    float xmin, zmin, xmax, zmax, xscale, zscale;
    int i, plotcol=6,plotfat=1;

    vp_init();

/* precompute quantities related to vplot scales */
    zbottom = 0.;
    for (i = 0; i < 3; i++) {
	zbottom += dz[i];
    }
    theta3 *= acosf(-1.)/180.;
    sn[2]=sinf(theta3);

    h=0.; 
    t=0.;
    for (i=2; i >= 0; i--) {
	if (i != 2)  sn[i] = sn[i+1]*vv[i]/vv[i+1]; /* snell's law */
	cs[i] = sqrtf(1. - sn[i]*sn[i]);
	h += dz[i]*sn[i]/cs[i];
	t += 2*dz[i]/(cs[i]*vv[i]);
    }

    xmin = -h - 0.1*zbottom; if (xmin > -2.) xmin=-2.;
    zmin = -0.1 * zbottom;
    xmax = -xmin;
    zmax = 1.1*zbottom; if (zmax < 3.) zmax=3.;

/* 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 flat reflectors */
    vp_color(plotcol);
    vp_fat(plotfat);

    z=0.;
    for (i=0; i < 3; i++) {
	z += dz[i];
	vp_umove(xmin,z);
	vp_udraw(xmax,z);
    }

/* draw vertical zero-offset ray */
    vp_color(7);
    vp_umove(0.,0.);
    vp_udraw(0.,zbottom);

/* draw ray paths from bottom reflector to geophone */
    vp_color(2);

    x=0; 
    z=zbottom;
    for (i=2; i >= 0; i--) {	
	if (i != 0) {
	    vp_umove(x,z);
	    x += dz[i]*sn[i]/cs[i];
	    z -= dz[i];
	    vp_udraw(x,z);
	} else  {
	    x1 = x; 
	    z1 = z; 
	    x += dz[i]*sn[i]/cs[i];
	    z -= dz[i]; 
	    vp_uarrow(x1,z1,x,z,0.02*zbottom);
	}  
    }

/* draw ray paths from source to bottom reflector */
    vp_color(2);
    x=0; 
    z=zbottom;
    for (i=2; i >= 0; i--) {
	if (i != 2) {
	    vp_umove(x,z);
	    x -= dz[i]*sn[i]/cs[i];
	    z -= dz[i];
	    vp_udraw(x,z);
	} else  {
	    x1 = x; 
	    z1 = z; 
	    x -= dz[i]*sn[i]/cs[i];
	    z -= dz[i]; 
	    vp_uarrow(x,z,x1,z1,0.02*zbottom);
	}  
    }

/* draw surface */
    vp_color(7);
    vp_fat(2*plotfat);
    vp_umove(xmin,0.);
    vp_udraw(xmax,0.);

/* draw text */
    vp_color(5);
    vp_fat(plotfat);
    vp_tjust(2,3);

    x = 0.;
    z = zbottom * 1.05;
    vp_utext(x,z,8,0,"R");

    x = -h;
    z = 0.- zbottom *.05;
    vp_utext(x,z,8,0,"S");

    x = h;
    z = 0. - zbottom *.05;
    vp_utext(x,z,8,0,"G");

    x = -h;
    z = 0. + dz[0]/2.;
    vp_utext(x,z,8,0,"v\\s60 \\_1");

    z += dz[0]/2. + dz[1]/2.;
    vp_utext(x,z,8,0,"v\\s60 \\_2");

    z += dz[1]/2. + dz[2]/2.;
    vp_utext(x,z,8,0,"v\\s60 \\_3");

    x = 0.;
    z = 0. - zbottom *.05;
    vp_utext(x,z,8,0,"2h");
    x = 0. + 0.05*zbottom;
    vp_umove(x,z);
    x1 = h - 0.05 * zbottom;
    vp_uarrow(x,z,x1,z,-0.02*zbottom);
    x = 0. - 0.05*zbottom;
    vp_umove(x,z);
    x1 = -h + 0.05 * zbottom;
    vp_uarrow(x,z,x1,z,-0.02*zbottom);
	
/*						Highlight the trigonometry */
    vp_color(7);
    vp_fat(plotfat);
/*						bottom of triangle */
    z=zbottom-dz[2];
    x=dz[2]*sn[2]/cs[2];
    vp_umove(x,z);
    x1 = x + dz[1]*sn[1]/cs[1];
    z1 = z;
    vp_udraw(x1,z1);
    xtxt = (x+x1)/2.;
    ztxt = z + 0.05 * zbottom;
    vp_utext(xtxt,ztxt,8,0,"\\F9 D\\F3 x\\_\\s60 i");

/*						vertical side of triangle */
    x = x1;
    z = z1 - dz[1];
    vp_umove(x1,z1);
    vp_udraw(x,z);
    xtxt = x + 0.05 * zbottom;
    ztxt = (z+z1)/2.;
    vp_utext(xtxt,ztxt,8,0,"\\F9 D\\F3 z\\_\\s60 i");
    xtxt = x - sn[1]/cs[1]*dz[1]/8.;
    ztxt = z + dz[1]/4.;
    vp_utext(xtxt,ztxt,8,0,"\\F9 q\\F3 \\s60 \\_i");

/*						vertical side in tau space */
    xtxt = 0. - 0.05*zbottom;
    ztxt = z + dz[1]/2.;
    vp_utext(xtxt,ztxt,8,90,
	     "\\F9 Dt\\F3 \\s60 \\_i\\^\\s100 v\\s60 \\_i\\^\\s100 /2");

/*						hypotenuse of triangle */
    z1=zbottom-dz[2];
    x1=dz[2]*sn[2]/cs[2];
    vp_umove(x,z);
    vp_udraw(x1,z1);
    xtxt = (x+x1)/2. - 0.05 *zbottom;
    ztxt = (z+z1)/2.;
    vp_utext(xtxt,ztxt,8,60,
	     "\\F9 D\\F3 t\\s60 \\_i\\^\\s100 v\\s60 \\_i\\^\\s100 /2");

/* draw a frame */

    if(wantframe) {
	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);
    }
	   
    exit(0);
}
Beispiel #5
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;
}
Beispiel #6
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);
}