static void labelaxis(struct Axis *axis) { float vs, ch, xc, yc, pos1, pos2; float x, y, xup, yup, xpath, ypath; ch = labelsz / 33.; vs = 0.75 * ch; if (axis == &axis2) { pos1 = 0.5*(max1 + min1); pos2 = where1? min2: max2; x = xc; xpath = ch ; xup = 0.; ypath = 0.; yup = ch; vp_umove (pos1, pos2); vp_where (&xc, &yc); y = where1? yc + ch + 2*vs: yc - ch - 2*vs; } else { pos1 = where2? min1: max1; pos2 = 0.5*(min2 + max2); y = yc; ypath = labelrot? ch: -ch; yup = 0.; xpath = 0.; xup = labelrot? -ch: ch; vp_umove (pos1, pos2); vp_where (&xc, &yc); if (labelrot) { x = where2? xc - ch - 2*vs: xc + ch + 2*vs; } else { x += where2? - (ch+vs): + (ch+vs); } } vp_fat (labelfat); tjust((axis == &axis2)? where1: where2); vp_gtext (x, y, xpath, ypath, xup, yup, axis->label); }
void vp_framenum (int i3, float d3, float o3, float xmin, float ymin, float labelsz) { float ch, xc, yc, f; char string[80]; vp_fat (0); f = i3 * d3 + o3; sprintf (string, (fmodf(f,1.) == 0.)? "%.0f": "%.3f", f); vp_umove (xmin, ymin); vp_where (&xc, &yc); ch = labelsz / 33.; tjust (true); vp_gtext (xc, yc - 4 * ch, ch, 0., 0., ch, string); }
void vp_plottitle(void) { float labelvs, labelch, ch, vs, xc, yc, pos1, pos2; float x, y, xup, yup, xpath, ypath; ch = titlesz / 33.; vs = ch * 0.6; vp_fat (titlefat); vp_color(axiscol); if (( verttitle && wheretitle != where2) || (!verttitle && wheretitle != where1)) { labelch = labelsz / 33.; labelvs = 0.75 * labelch; } else { labelch = 0.; labelvs = 0.; } if (!verttitle) { pos1 = 0.5*(max1+min1); pos2 = wheretitle? max2: min2; ypath = 0.; yup = ch; xpath = ch; xup = 0.; vp_umove (pos1, pos2); vp_where (&xc, &yc); x = xc; y = wheretitle? yc + vs + labelch + 3*labelvs: yc - vs - labelch - 3*labelvs; } else { pos2 = 0.5*(max2+min2); pos1 = wheretitle? max1: min1; ypath = labelrot? 0.: -ch; yup = 0.; xpath = 0.; xup = labelrot? 0.: ch; vp_umove (pos1, pos2); vp_where (&xc, &yc); y = yc; if (labelrot) { x = wheretitle? xc - vs - labelch - 3*labelvs: xc + vs + labelch + 3*labelvs; } else { x += wheretitle? -(ch + vs + labelvs): +(ch + vs + labelvs); } } tjust(wheretitle); vp_gtext(x, y, xpath, ypath, xup, yup ,title); }
static void maketic (float num, struct Axis *axis) { float xc, yc, pos1, pos2, ch; float lmin1, lmax1, lmin2, lmax2, tic, num0, dtic, dnum, vs; ch = labelsz / 33.; vs = 0.5 * ch; if (axis == &axis2) { lmin1 = min2; lmin2 = min1; lmax1 = max2; lmax2 = max1; } else { lmin1 = min1; lmin2 = min2; lmax1 = max1; lmax2 = max2; } if (fabsf (num) < (max1 - min1)/10000.) num = 0.; if (axis == &axis2) { pos1 = num; if (wheretics) { pos2 = axis->or; } else { pos2 = where2? lmin2: lmax2; } } else { if (wheretics) { pos1 = axis->or; } else { pos1 = where1? lmin2: lmax2; } pos2 = num; } vp_umove (pos1, pos2); vp_where (&xc, &yc); if (axis == &axis2) { pos1 = xc; pos2 = where2? yc-vs: yc+vs; } else { pos1 = where1? xc-vs: xc+vs; pos2 = yc; } vp_draw (pos1, pos2); num0 = axis->num0; dnum = axis->dnum; dtic = axis->dtic; if (dtic != dnum) { for (tic = num0; tic <= lmax1; tic += dtic) { if (axis == &axis2) { pos1 = tic; pos2 = where2? lmin2: lmax2; } else { pos1 = where1? lmin2: lmax2; pos2 = tic; } vp_umove (pos1, pos2); vp_where (&xc, &yc); if (axis == &axis2) { pos1 = xc; if (axis->or == lmin2) { pos2 = where2? yc-0.5*vs: yc+0.5*vs; } else { pos2 = where2? yc-0.25*vs: yc+0.25*vs; } } else { if (axis->or == lmin2) { pos1 = where1? xc-0.5*vs: xc+0.5*vs; } else { pos1 = where1? xc-0.25*vs: xc+0.25*vs; } pos2 = yc; } vp_draw (pos1, pos2); } } }
static void makelabel (float num, float num2, struct Axis *axis) { float xc, yc, lmin1, lmin2, lmax1, lmax2, point1, point2; float x, y, xup, yup, xpath, ypath, ftmp, num1, ch, vs; const float eps=.0000001; char string[80]; ch = labelsz / 33.; vs = 0.75 * ch; if (axis == &axis2) { lmin1 = min2; lmax1 = max2; lmin2 = min1; lmax2 = max1; } else { lmax1 = max1; lmin1 = min1; lmax2 = max2; lmin2 = min2; } if (lmax1 < lmin1 || (xreverse && axis == &axis1) || (yreverse && axis == &axis2)) { ftmp = lmin1; lmin1 = lmax1; lmax1 = ftmp; } if (fabsf (num) < (lmax1 - lmin1) / 10000) num = 0.0; if (!wheretics) { if (axis == &axis2) { point1 = num; point2 = where1? min2: max2; } else { point1 = where2? max2: min2; point2 = num; } } else { if (axis == &axis2) { point1 = num; point2 = axis->or; } else { point1 = axis->or; point2 = num; } } vp_umove (point1, point2); vp_where (&xc, &yc); num1 = (fabsf(num2) < eps)? 0.0: num2; sprintf (string, "%1.5g", num1); if (axis == &axis1) { y = yc; xpath = 0.; ypath = labelrot * ch; xup = -labelrot * ch; yup = 0; if (!where2) { x = xc - vs; if (!labelrot) x -= (ch + vs); } else { x = xc + vs; if (!labelrot) x += (ch + vs); } } else { x = xc; yup = ch; xpath = ch; ypath = 0.; xup = 0.; y = where1? yc - vs: yc + vs; } tjust ((axis == &axis2)? where1: where2); vp_gtext (x, y, xpath, ypath, xup, yup, string); }
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); }