int main (int argc, char **argv) { int n1,n2,n3,i1,i2,i3, n1tic,n2tic,n3tic,grid1,grid2,grid3,nz,iz, faces,style=SEISMIC,bbox[4], npar,nc,nplaces,ic; int labelcf, nlabelc, labelcper; float d1,d2,d3,f1,f2,f3,size1,size2,size3,xbox,ybox,angle, x1min,x1max,x2min,x2max,x3min,x3max, x1beg,x1end,x2beg,x2end,x3beg,x3end, d1num,f1num,d2num,f2num,d3num,f3num, p1beg,p1end,p2beg,p2end,p3beg,p3end, labelsize,titlesize, *z,*zfront,*zside,*ztop,*temp,matrix[6], cwidth[NCMAX],cgray[NCMAX],cdash[NCMAX], dc,fc,*x1,*x2,*x3,c[NCMAX],zmin,zmax, x1scale,x2scale,x3scale; float labelcsize,lcsize,*w,*wfront,*wside,*wtop; char *label1="",*label2="",*label3="",*title="", *labelfont="Helvetica",*titlefont="Helvetica-Bold", *labelcfont="Helvetica-Bold",*labelccolor="black", *grid1s="none",*grid2s="none",*grid3s="none", *titlecolor="black",*axescolor="black",*gridcolor="black", *frontf,*sidef,*topf, *scolor="none",*ccolor[NCMAX]; FILE *infp=stdin,*frontfp,*sidefp,*topfp; /* initialize getpar */ initargs(argc,argv); requestdoc(1); /* get parameters describing 1st dimension sampling */ if (!getparint("n1",&n1)) err("must specify n1!\n"); if (!getparfloat("d1",&d1)) d1 = 1.0; if (!getparfloat("f1",&f1)) f1 = 0.0; x1 = ealloc1float(n1); for (i1=0; i1<n1; i1++) x1[i1] = f1+i1*d1; for (i1=1,x1min=x1max=x1[0]; i1<n1; i1++) { x1min = MIN(x1min,x1[i1]); x1max = MAX(x1max,x1[i1]); } /* get parameters describing 2nd dimension sampling */ if (!getparint("n2",&n2)) err("must specify n2!\n"); if (!getparfloat("d2",&d2)) d2 = 1.0; if (!getparfloat("f2",&f2)) f2 = 0.0; x2 = ealloc1float(n2); for (i2=0; i2<n2; i2++) x2[i2] = f2+i2*d2; for (i2=1,x2min=x2max=x2[0]; i2<n2; i2++) { x2min = MIN(x2min,x2[i2]); x2max = MAX(x2max,x2[i2]); } /* get parameters describing 3rd dimension sampling */ if (!getparint("n3",&n3)) err("must specify n3!\n"); if (n3<2)err("must have n3>=2!"); if (!getparfloat("d3",&d3)) d3 = 1.0; if (!getparfloat("f3",&f3)) f3 = 0.0; x3 = ealloc1float(n3); for (i3=0; i3<n3; i3++) x3[i3] = f3+i3*d3; for (i3=1,x3min=x3max=x3[0]; i3<n3; i3++) { x3min = MIN(x3min,x3[i3]); x3max = MAX(x3max,x3[i3]); } /* determine input type */ if (!getparint("faces",&faces)) faces = 0; /* allocate space */ nz = n1*n2+n1*n3+n2*n3; z = ealloc1float(nz); zfront = z; zside = zfront+n1*n2; ztop = zside+n1*n3; /* read data */ if (getparstring("front",&frontf) && getparstring("side",&sidef) && getparstring("top",&topf)) { /* read face files */ if ((frontfp = fopen(frontf,"r")) == NULL) err("error opening front file!\n"); if (fread(zfront,sizeof(float),n1*n2,frontfp)!=n1*n2) err("error reading front file!\n"); if ((sidefp = fopen(sidef,"r")) == NULL) err("error opening side file!\n"); if (fread(zside,sizeof(float),n1*n3,sidefp)!=n1*n3) err("error reading side file!\n"); if ((topfp = fopen(topf,"r")) == NULL) err("error opening top file!\n"); if (fread(ztop,sizeof(float),n2*n3,topfp)!=n2*n3) err("error reading top file!\n"); } else if (getparstring("front",&frontf) || getparstring("side",&sidef) || getparstring("top",&topf)) { err("must specify all or none of face, side, and top!\n"); } else if (faces) { /* read faces from stdin */ if (fread(zfront,sizeof(float),n1*n2,infp)!=n1*n2) err("error reading front from input!\n"); if (fread(zside,sizeof(float),n1*n3, infp)!=n1*n3) err("error reading side from input!\n"); if (fread(ztop,sizeof(float),n2*n3, infp)!=n2*n3) err("error reading top from input!\n"); } else { /* read cube from stdin, pick off faces */ temp = ealloc1float(n1); for (i3=0; i3<n3; i3++) { for (i2=0; i2<n2; i2++) { if (fread(temp,sizeof(float),n1,infp)!=n1) err("error reading cube from input!\n"); if (i3==0) for (i1=0; i1<n1; i1++) zfront[i1+i2*n1] = temp[i1]; if (i2==n2-1) for (i1=0; i1<n1; i1++) zside[i1+i3*n1] = temp[i1]; ztop[i2+i3*n2] = temp[0]; } } free1float(temp); } /* zero w array for contour labeling */ w = ealloc1float(nz); wfront = w; wside = wfront+n1*n2; wtop = wside+n1*n3; for(iz=0; iz<nz; iz++) w[iz] = 0.; /* determine data min and max */ for (iz=0,zmin=zmax=z[0]; iz<nz; iz++){ zmin = MIN(zmin,z[iz]); zmax = MAX(zmax,z[iz]); } /* get contouring parameters */ if ((nc=getparfloat("c",c))==0) { nc = 5; getparint("nc",&nc); dc = (zmax-zmin)/nc; getparfloat("dc",&dc); fc = zmin+dc; getparfloat("fc",&fc); for (ic=0; ic<nc; ic++) c[ic] = fc+ic*dc; } for (ic=0; ic<nc; ic++) { cwidth[ic] = 1.0; cgray[ic] = 0.0; cdash[ic] = 0.0; ccolor[ic] = scolor; } if ((npar=getparfloat("cwidth",cwidth))!=0) for (ic=npar; ic<nc; ic++) cwidth[ic] = cwidth[npar-1]; if ((npar=getparfloat("cgray",cgray))!=0) for (ic=npar; ic<nc; ic++) cgray[ic] = cgray[npar-1]; if ((npar=getparfloat("cdash",cdash))!=0) for (ic=npar; ic<nc; ic++) cdash[ic] = cdash[npar-1]; if (getparstring("ccolor",&scolor)) { int i,j; char *s; for (i=0,s=strtok(scolor,","); s!=NULL; ++i,s=strtok(NULL,",")) ccolor[i] = s; for (j=i-1; i<nc; ++i) ccolor[i] = ccolor[j]; } labelcf = 1; getparint("labelcf",&labelcf); labelcper = 1; getparint("labelcper",&labelcper); nlabelc = nc; getparint("nlabelc",&nlabelc); labelcsize = 6; getparfloat("labelcsize",&labelcsize); getparstring("labelcfont",&labelcfont); getparstring("labelccolor",&labelccolor); if (!getparint("nplaces",&nplaces)) nplaces = 6; /* get axes parameters, convert to points */ if(!getparfloat("size1",&size1)) size1 = 4.0; if(!getparfloat("size2",&size2)) size2 = 4.0; if(!getparfloat("size3",&size3)) size3 = 3.0; if (!getparfloat("xbox",&xbox)) xbox = 1.5; if (!getparfloat("ybox",&ybox)) ybox = 1.5; size1 *= 72; size2 *= 72; size3 *= 72; xbox *= 72; ybox *= 72; /* get projection angle, convert to radians */ if(!getparfloat("angle",&angle)) angle = 45.0; angle = MAX(angle,0.00001); angle = MIN(angle,90.0); angle *= PI/180.0; /* get axis1 parameters */ x1beg = x1min; 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); /* get axis2 parameters */ x2beg = x2min; getparfloat("x2beg",&x2beg); x2end = x2max; d2num = 0.0; getparfloat("d2num",&d2num); f2num = x2min; 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); /* get axis3 parameters */ x3beg = x3min; x3end = x3max; getparfloat("x3end",&x3end); d3num = 0.0; getparfloat("d3num",&d3num); f3num = x3min; getparfloat("f3num",&f3num); n3tic = 1; getparint("n3tic",&n3tic); getparstring("grid3",&grid3s); if (STREQ("dot",grid3s)) grid3 = DOT; else if (STREQ("dash",grid3s)) grid3 = DASH; else if (STREQ("solid",grid3s)) grid3 = SOLID; else grid3 = NONE; getparstring("label3",&label3); /* get additional font parameters */ 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); style = SEISMIC; /* determine axes pads */ p1beg = (x1end>x1beg)?-fabs(d1)/2:fabs(d1)/2; p1end = (x1end>x1beg)?fabs(d1)/2:-fabs(d1)/2; p2beg = (x2end>x2beg)?-fabs(d2)/2:fabs(d2)/2; p2end = (x2end>x2beg)?fabs(d2)/2:-fabs(d2)/2; p3beg = (x3end>x3beg)?-fabs(d3)/2:fabs(d3)/2; p3end = (x3end>x3beg)?fabs(d3)/2:-fabs(d3)/2; /* set bounding box */ psAxesBBox(xbox,ybox,size2+cos(angle)*size3,size1+sin(angle)*size3, labelfont,labelsize,titlefont,titlesize,style,bbox); 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); /* begin top */ gsave(); /* determine x2 and x3 scale factors */ x2scale = size2/(x2end-x2beg); x3scale = size3*sin(angle)/(x3end-x3beg); /* scale x2 and x3 coordinates */ for (i2=0; i2<n2; i2++) x2[i2] *= x2scale; for (i3=0; i3<n3; i3++) x3[i3] *= x3scale; /* transform and skew coordinates */ matrix[0] = 1; matrix[1] = 0; matrix[2] = 1/tan(angle); matrix[3] = 1; matrix[4] = 0; matrix[5] = 0; translate(-(f2-x2min+x2beg)*x2scale-f3*x3scale/tan(angle),size1-f3*x3scale); concat(matrix); rectclip(x2beg*x2scale,f3*x3scale,size2,size3*sin(angle)); /* draw contours */ for (ic=0; ic<nc; ic++) { setlinewidth(cwidth[ic]); if (strcmp(ccolor[ic],"none")) setcolor(ccolor[ic]); else setgray(cgray[ic]); if (cdash[ic]!=0.0) setdash(&cdash[ic],1,0.0); else setdash(&cdash[ic],0,0.0); lcsize = 0.; if (nlabelc>0) { if((ic-labelcf+1)%labelcper==0 && ic>=labelcf-1 && ic<labelcf-1+labelcper*nlabelc) { setlinewidth(cwidth[ic]); lcsize = labelcsize; } else { lcsize = 0.; setlinewidth(0.25*cwidth[ic]); } } /* no labels -> lcsize=0 to psContour */ psContour(c[ic],n2,x2,n3,x3,ztop,0,labelcfont,labelccolor,wtop,nplaces); } /* unscale x2 and x3 coordinates */ for (i2=0; i2<n2; i2++) x2[i2] /= x2scale; for (i3=0; i3<n3; i3++) x3[i3] /= x3scale; translate((f2-x2min+x2beg)*x2scale+f3*x3scale/tan(angle),-size1+f3*x3scale); /* end top */ grestore(); /* begin front */ gsave(); /* determine x1 and x2 scale factors */ x1scale = size1/(x1end-x1beg); x2scale = size2/(x2end-x2beg); /* scale x1 and x2 coordinates */ for (i1=0; i1<n1; i1++) x1[i1] *= x1scale; for (i2=0; i2<n2; i2++) x2[i2] *= x2scale; rotate(-90); translate(-size1-f1*x1scale,-(f2-x2min+x2beg)*x2scale); rectclip(size1+f1*x1scale,(f2-x2min+x2beg)*x2scale,-size1,size2); /* draw contours */ for (ic=0; ic<nc; ic++) { setlinewidth(cwidth[ic]); if (strcmp(ccolor[ic],"none")) setcolor(ccolor[ic]); else setgray(cgray[ic]); if (cdash[ic]!=0.0) setdash(&cdash[ic],1,0.0); else setdash(&cdash[ic],0,0.0); lcsize = 0.; if (nlabelc>0) { if((ic-labelcf+1)%labelcper==0 && ic>=labelcf-1 && ic<labelcf-1+labelcper*nlabelc) { setlinewidth(cwidth[ic]); lcsize = labelcsize; } else { lcsize = 0.; setlinewidth(0.25*cwidth[ic]); } } psContour(c[ic],n1,x1,n2,x2,z,lcsize,labelcfont,labelccolor,w,nplaces); } /* unscale x1 and x2 coordinates */ for (i1=0; i1<n1; i1++) x1[i1] /= x1scale; for (i2=0; i2<n2; i2++) x2[i2] /= x2scale; translate(size1+f1*x1scale,(f2-x2min+x2beg)*x2scale); rotate(90); /* end front */ grestore(); /* begin side */ gsave(); /* determine x1 and x3 scale factors */ x1scale = size1/(x1end-x1beg); x3scale = size3*cos(angle)/(x3end-x3beg); /* scale x1 and x3 coordinates */ for (i1=0; i1<n1; i1++) x1[i1] *= x1scale; for (i3=0; i3<n3; i3++) x3[i3] *= x3scale; /* transform and skew coordinates */ matrix[0] = 1; matrix[1] = tan(angle); matrix[2] = 0; matrix[3] = 1; matrix[4] = 0; matrix[5] = 0; translate(size2-f3*x3scale,size1+f1*x1scale-f3*x3scale*tan(angle)); concat(matrix); rectclip(f3*x3scale,-x1end*x1scale,size3*cos(angle),size1); rotate(-90); /* draw contours */ for (ic=0; ic<nc; ic++) { setlinewidth(cwidth[ic]); if (strcmp(ccolor[ic],"none")) setcolor(ccolor[ic]); else setgray(cgray[ic]); if (cdash[ic]!=0.0) setdash(&cdash[ic],1,0.0); else setdash(&cdash[ic],0,0.0); lcsize = 0.; if (nlabelc>0) { if((ic-labelcf+1)%labelcper==0 && ic>=labelcf-1 && ic<labelcf-1+labelcper*nlabelc) { setlinewidth(cwidth[ic]); lcsize = labelcsize; } else { lcsize = 0.; setlinewidth(0.25*cwidth[ic]); } } /* no labels -> lcsize=0 to psContour */ psContour(c[ic],n1,x1,n3,x3,zside,0,labelcfont,labelccolor,wside,nplaces); } /* unscale x1 and x3 coordinates */ for (i1=0; i1<n1; i1++) x1[i1] /= x1scale; for (i3=0; i3<n3; i3++) x3[i3] /= x3scale; rotate(90); translate(-size2+f3*x3scale,-size1-f1*x1scale+f3*x3scale*tan(angle)); /* end side */ grestore(); /* restore graphics state */ grestore(); psCubeAxesBox(xbox,ybox,size1,size2,size3,angle, x1beg,x1end,p1beg,p1end, d1num,f1num,n1tic,grid1,label1, x2beg,x2end,p2beg,p2end, d2num,f2num,n2tic,grid2,label2, x3beg,x3end,p3beg,p3end, d3num,f3num,n3tic,grid3,label3, labelfont,labelsize, title,titlefont,titlesize, titlecolor,axescolor,gridcolor); /* end PostScript */ showpage(); endeps(); return 0; }
void subplot(float *data, int nt, int nx, string title, string label1, string label2, float truemax, float max) { int i,plotfat,axisfat,dtict,ntict,nticx; float sizet,sizex,scalet,scalex,zerot,zerox,margint,marginx,dticx; float dash,gap,truedticx,xmin,dx; int titlsz,lablsz,ticsz,hcopy,dashflag; char tval[8]; /* tic value string */ zerot = 0.5; fgetpar("zerox",&zerot); zerox = 1.0; fgetpar("zeroy",&zerox); sizet = 8.0; fgetpar("sizex",&sizet); sizex = 5.0; fgetpar("sizey",&sizex); dashflag = 0; igetpar("dash",&dashflag); nticx = 1; igetpar("nticy",&nticx); ntict = 5; fgetpar("nticx",&ntict); dtict = nt/ntict; if (dtict>10) dtict -= dtict%10; igetpar("dticx",&dtict); margint = 0.01; fgetpar("marginx",&margint); marginx = 0.04; fgetpar("marginy",&marginx); ticsz = 3; igetpar("ticsz",&ticsz); hcopy = 0; igetpar("hcopy",&hcopy); if ( hcopy == 1 ) { sizet=4.5; sizex=3.5; ticsz=2; } scalet = sizet/nt; scalex = 0.5*sizex; setscl(scalet,scalex); set0(zerot, zerox + 0.5*sizex ); setfat(axisfat); /* ZERO LINE*/ setcol(3); umove( 0.0, 0.0 ); udraw( (float)nt, 0.0 ); /* Amplitude tics */ dticx = max/nticx; truedticx = truemax/nticx; for ( i = -nticx ; i <= nticx ; i++ ) { umove( (float)nt , i*dticx / max ); udraw( (1.0 + margint) * nt, i*dticx / max ); sprintf( tval, "%.3g", i*truedticx ); utext( (1.0 + 2*margint) * nt, i*dticx / max , ticsz, 0, tval); } /* DRAW N2 WIGGLE TRACES */ for ( i = 0 ; i < nx ; i++ ) { if ( dashflag ) { dash = ( i % 6 ) * .05; gap = dash; if ( dash ) { setdash(dash,gap,dash,gap); } } setcol(6 - i % 6); wgl1( data + nt*i, nt); } }
void psAxesBox( float x, float y, float width, float height, float x1Beg, float x1End, float p1Beg, float p1End, float d1Num, float f1Num, int n1Tic, int grid1, char *label1, float x2Beg, float x2End, float p2Beg, float p2End, float d2Num, float f2Num, int n2Tic, int grid2, char *label2, char *labelFont, float labelSize, char *title, char *titleFont, float titleSize, int style) /* FUNCTION: draw an axes box via PostScript PARAMETERS: x i x coordinate of lower left corner of box y i y coordinate of lower left corner of box width i width of box height i height of box x1Beg i axis value at beginning of axis 1 x1End i axis value at end of axis 1 p1Beg i pad value at beginning of axis 1 p1End i pad value at end of axis 1 d1Num i numbered tic increment for axis 1 (0.0 for automatic) f1Num i first numbered tic for axis 1 n1Tic i number of horizontal tics per numbered tic for axis 1 grid1 i grid code for axis 1: NONE, DOT, DASH, or SOLID label1 i label for axis 1 x2Beg i axis value at beginning of axis 2 x2End i axis value at end of axis 2 p2Beg i pad value at beginning of axis 2 p2End i pad value at end of axis 2 d2Num i vertical numbered tic increment (0.0 for automatic) f2Num i first numbered vertical tic n2Tic i number of vertical tics per numbered tic grid2 i grid code for vertical axis: NONE, DOT, DASH, or SOLID label2 i vertical axis label labelFont i name of font to use for axes labels labelSize i size of font to use for axes labels title i axes box title titleFont i name of font to use for title titleSize i size of font to use for title style i NORMAL (axis 1 on bottom, axis 2 on left) SEISMIC (axis 1 on left, axis 2 on top) NOTES: psAxesBox will determine the numbered tic increment and first numbered tic automatically, if the specified increment is zero. Axis numbering is in scientific notation, if necessary and is plotted to four significant digits. Pad values must be specified in the same units as the corresponding axes values. These pads are useful when the contents of the axes box requires more space than implied by the axes values. For example, the first and last seismic wiggle traces plotted inside an axes box will typically extend beyond the axes values corresponding to the first and last traces. However, all tics will lie with the limits specified in the axes values (x1Beg, x1End, x2Beg, x2End). AUTHOR: Dave Hale, Colorado School of Mines, 06/27/89 MODIFIED: Ken Larner, Colorado School of Mines, 08/30/90 */ { int n1num,n2num,ntic,ndash,grided; int ndig,ndigits,nexp,nexpmax,nexplot1,nexplot2, nplaces,nplacesmax,nformat; float xa,xas,ya,yas,yb,xb,ticsize,dnum,fnum,dtic,amin,amax,azero, base,scale,anum,anumnorm,atic,fnexp, size1,size2,ticb,numb,numb2,labelb,dash[2], labelCH,labelCW,labelCA,labelCD, titleCH,titleCW,titleCA,titleCD, pnorm,fdexp,azeronorm; char str[256],str2[256],sformat[256]; /* determine font dimensions */ labelCH = fontheight(labelFont,labelSize); labelCW = fontwidth(labelFont,labelSize); labelCA = fontascender(labelFont,labelSize); labelCD = fontdescender(labelFont,labelSize); titleCH = fontheight(titleFont,titleSize); titleCW = fontwidth(titleFont,titleSize); titleCA = fontascender(titleFont,titleSize); titleCD = fontdescender(titleFont,titleSize); /* determine sizes of axes 1 and 2 */ if (style==NORMAL) { size1 = width; size2 = height; } else { size1 = height; size2 = width; } /* determine numbered tic intervals */ if (d1Num==0.0) { n1num = size1/(4*labelCW); scaxis(x1Beg,x1End,&n1num,&d1Num,&f1Num); } if (d2Num==0.0) { n2num = size2/(4*labelCW); scaxis(x2Beg,x2End,&n2num,&d2Num,&f2Num); } /* save graphics state */ gsave(); /* set gray (for black axes) */ setgray(0.0); /* translate coordinate system, so that origin is at x,y */ translate(x,y); /* if style is not NORMAL, rotate coordinate system */ if (style!=NORMAL) { rotate(-90.0); translate(-height,0.0); } /* start a new path (just to be safe) */ newpath(); /* set font and character size */ setfont(labelFont,labelSize); /* determine tic size */ ticsize = 0.3*labelCH; /* draw axis 1 */ amin = (x1Beg<x1End)?x1Beg:x1End; amax = (x1Beg>x1End)?x1Beg:x1End; azero = 0.0001*(amax-amin); dnum = d1Num; fnum = f1Num; ntic = n1Tic; scale = size1/(x1End+p1End-x1Beg-p1Beg); base = -scale*(x1Beg+p1Beg); ticb = -ticsize; numb = 1.2*ticb-labelCA; if(style!=NORMAL) numb = 1.2*ticb; labelb = numb-labelCH; /* determine axes1 exponent for scientific notation */ ndigits = 0; ndig = 0; fdexp = log10(1.001*ABS(dnum)); if(fdexp<0.) fdexp -=1.0; for (anum=fnum; anum<=amax; anum+=dnum) { if(anum==fnum && anum==0.) nexpmax = 0; nexp = 0; if(anum!=0.) { fnexp = log10(1.001*ABS(anum)); if(fnexp>0.) nexp = (int)fnexp; else nexp = (int)fnexp-1; if(anum==fnum) nexpmax = nexp; if(nexpmax<nexp || nexpmax==0) nexpmax = nexp; ndig = 1+nexp-(int)fdexp; } if(ndigits<ndig) ndigits = ndig; } nexplot1 = 0; if(ABS(nexpmax)>3) nexplot1 = nexpmax; if((nexpmax<0) && (ndigits+ABS(nexpmax))>4) nexplot1 = nexpmax; /* loop for axis1 numbering */ nplacesmax = 0; pnorm = pow(10.0,(double)nexplot1); azeronorm = azero/pnorm; fdexp = log10(1.001*ABS(dnum/pnorm)); if(fdexp<0.) fdexp -=1.0; for (anum=fnum; anum<=amax; anum+=dnum) { if (anum<amin) continue; xa = base+scale*anum; xas = xa+0.25*labelCH; moveto(xa,0.0); lineto(xa,ticb); anumnorm = anum/pnorm; /* find the number of places in axis1 numbers */ nplaces = 1; nexp = 1; nexp = 0; if (anumnorm<-azeronorm || anumnorm>azeronorm) { fnexp = log10(1.001*ABS(anumnorm)); if(fnexp>0.) { nexp = (int)fnexp; nplaces = nexp+2; } else { nexp = (int)fnexp-1; nplaces = -nexp+2; } } /* numbers limited to four significant digits */ ndigits = 1+nexp-(int)fdexp; if(ndigits>4) ndigits = 4; if((nexp>=0) && ((ndigits+1)>nplaces)) nplaces = ndigits+1; if(anum<0. ) nplaces +=1; if(nexp<0) nplaces = nplaces+ndigits-1; if(nplacesmax<nplaces) nplacesmax = nplaces; nformat = ndigits-(nexp+1); if(nformat<0) nformat = 0; if (anumnorm>-azeronorm && anumnorm<azeronorm) sprintf(str,"%.4g",0.0); else { sprintf(sformat,"%%.%df",nformat); sprintf(str,sformat,anumnorm); } if (style!=NORMAL) { moveto(xas,numb); rotate(90.0); justshow(-1.0,str); rotate(-90.0); } else { moveto(xa,numb); justshow(-0.5,str); } } /* draw exponential multiplier for axis1 */ if(nexplot1!=0) { if(style==NORMAL) { moveto(size1,labelb); show("x10"); moveto(size1+1.5*labelCW,labelb+0.5*labelCA); sprintf(str2,"%d",nexplot1); show(str2); } else { moveto(size1+1.4*labelCH,-2.0*labelCW); rotate(90.); show("x10"); rotate(-90.); moveto(size1+1.05*labelCH,-0.5*labelCW); sprintf(str2,"%d",nexplot1); rotate(90.); show(str2); rotate(-90.); } } stroke(); /* draw axis1 tick marks */ if(style!=NORMAL) labelb = numb-0.5*nplacesmax*labelCW; dtic = dnum/ntic; for (atic=fnum-ntic*dtic-dtic; atic<=amax; atic+=dtic) { if (atic<amin) continue; xa = base+scale*atic; moveto(xa,0.0); lineto(xa,ticb/2); } stroke(); /* draw axis1 grid lines */ if (grid1==SOLID) { grided = 1; ndash = 0; } else if (grid1==DASH) { grided = 1; ndash = 1; dash[0] = 10; } else if (grid1==DOT) { grided = 1; ndash = 2; dash[0] = 1; dash[1] = 5; } else grided = 0; if (grided) { for (anum=fnum; anum<=amax; anum+=dnum) { if (anum<amin) continue; xa = base+scale*anum; moveto(xa,0.0); lineto(xa,size2); } setdash(dash,ndash,0.0); stroke(); setdash(dash,0,0.0); } /* draw axis1 label */ moveto(size1/2.0,labelb); if(style!=NORMAL) { rotate(180.); justshow(-0.5,label1); rotate(-180.); } else justshow(-0.5,label1); /* draw axis 2 */ amin = (x2Beg<x2End)?x2Beg:x2End; amax = (x2Beg>x2End)?x2Beg:x2End; azero = 0.0001*(amax-amin); dnum = d2Num; fnum = f2Num; ntic = n2Tic; scale = size2/(x2End+p2End-x2Beg-p2Beg); base = -scale*(x2Beg+p2Beg); ticb = -ticsize; numb = ticb+labelCD; labelb = numb-labelCH; /* determine axes2 exponent for scientific notation */ ndigits = 0; ndig = 0; fdexp = log10(1.001*ABS(dnum)); if(fdexp<0.) fdexp -=1.0; for (anum=fnum; anum<=amax; anum+=dnum) { if(anum==fnum && anum==0.) nexpmax = 0; nexp = 0; if(anum!=0.) { fnexp = log10(1.001*ABS(anum)); if(fnexp>0.) nexp = (int)fnexp; else nexp = (int)fnexp-1; if(anum==fnum) nexpmax = nexp; if(nexpmax<nexp || nexpmax==0) nexpmax = nexp; ndig = 1+nexp-(int)fdexp; } if(ndigits<ndig) ndigits = ndig; } nexplot2 = 0; if(ABS(nexpmax)>3) nexplot2 = nexpmax; if((nexpmax<0) && (ndigits+ABS(nexpmax))>4) nexplot2 = nexpmax; /* loop for axis 2 numbering */ nplacesmax = 0; pnorm = pow(10.0,(double)nexplot2); azeronorm = azero/pnorm; fdexp = log10(1.001*ABS(dnum/pnorm)); if(fdexp<0.) fdexp -=1.0; for (anum=fnum; anum<=amax; anum+=dnum) { ya = base+scale*anum; moveto(0.0,ya); lineto(ticb,ya); anumnorm = anum/pnorm; yas = ya-0.25*labelCH; /* find the number of places in axis2 numbers */ nplaces = 1; nexp = 1; if (anumnorm<-azeronorm || anumnorm>azeronorm) { fnexp = log10(1.001*ABS(anumnorm)); if(fnexp>0.) { nexp = (int)fnexp; nplaces = nexp+2; } else { nexp = (int)fnexp-1; nplaces = -nexp+2; } } /* numbers limited to four significant digits */ ndigits = 1+nexp-(int)fdexp; if(ndigits>4) ndigits = 4; if((nexp>=0) && ((ndigits+1)>nplaces)) nplaces = ndigits+1; if(anum<0. ) nplaces +=1; if(nexp<0) nplaces = nplaces+ndigits-1; if(nplacesmax<nplaces) nplacesmax = nplaces; nformat = ndigits-(nexp+1); if(nformat<0) nformat = 0; if (anumnorm>-azeronorm && anumnorm<azeronorm) sprintf(str,"%.4g",0.0); else { sprintf(sformat,"%%.%df",nformat); sprintf(str,sformat,anumnorm); } if (style!=NORMAL) { moveto(numb,ya); rotate(90.0); justshow(-0.5,str); rotate(-90.0); } else { moveto(numb,yas); justshow(-1.,str); } } /* draw exponential mulitplier for axis2 */ if(nexplot2!=0) { if(style==NORMAL) { numb2 = size2+.5*labelCH; moveto(labelb,numb2); show("x10"); xb = labelb+1.5*labelCW; numb2 = numb2+0.5*labelCA; moveto(xb,numb2); sprintf(str2,"%d",nexplot2); show(str2); } else { moveto(labelb,size2-.5*labelCW); rotate(90.); show("x10"); rotate(-90.); moveto(labelb-.35*labelCH,size2+1.0*labelCW); sprintf(str2,"%d",nexplot2); rotate(90.); show(str2); rotate(-90.); } } stroke(); /* draw axis2 tick marks */ if(style==NORMAL) labelb = numb-0.5*nplacesmax*labelCW; dtic = dnum/ntic; for (atic=fnum-ntic*dtic-dtic; atic<=amax; atic+=dtic) { if (atic<amin) continue; ya = base+scale*atic; moveto(0.0,ya); lineto(ticb/2,ya); } stroke(); /* draw axis2 grid lines */ if (grid2==SOLID) { grided = 1; ndash = 0; } else if (grid2==DASH) { grided = 1; ndash = 1; dash[0] = 10; } else if (grid2==DOT) { grided = 1; ndash = 2; dash[0] = 1; dash[1] = 5; } else grided = 0; if (grided) { for (anum=fnum; anum<=amax; anum+=dnum) { if (anum<amin) continue; ya = base+scale*anum; moveto(0.0,ya); lineto(size1,ya); } setdash(dash,ndash,0.0); stroke(); setdash(dash,0,0.0); } /* draw axis2 label */ moveto(labelb,size2/2.0); rotate(90.0); justshow(-0.5,label2); rotate(-90.0); /* draw title */ setfont(titleFont,titleSize); if (style==NORMAL) { numb2 = size2+0.5*titleCH-titleCD; if(nexplot2!=0) numb2 = numb2+.5*(labelCH+labelCA); moveto(size1/2.0,numb2); justshow(-0.5,title); } else { numb2 = size1+0.5*titleCH+titleCA; if(nexplot1!=0) numb2 = numb2+labelCH; moveto(numb2,size2/2.0); rotate(90.0); justshow(-0.5,title); rotate(-90.0); } /* draw axes box */ moveto(0.0,0.0); lineto(size1,0.0); lineto(size1,size2); lineto(0.0,size2); lineto(0.0,0.0); stroke(); /* restore graphics state */ grestore(); }