This is plaxes.c in view mode; [Download] [Up]
/* This draws a box around the current viewport. XOPT and YOPT are */ /* character strings which define the box as follows: */ /* A: Draw axis (X is horizontal line Y=0, Y is vertical line X=0) */ /* B: Draw bottom (X) or left (Y) edge of frame */ /* C: Draw top (X) or right (Y) edge of frame */ /* G: Draws a grid at the major tick interval */ /* I: Inverts tick marks */ /* L: Logarithmic axes, major ticks at decades, minor ticks at units */ /* N: Write numeric label at conventional location */ /* M: Write numeric label at unconventional location */ /* T: Draw major tick marks */ /* S: Draw minor tick marks */ /* V: (for Y only) Label vertically */ /* xtick, ytick are the major tick intervals required, zero for */ /* automatic selection */ /* nxsub, nysub are the number of subtick intervals in a major tick */ /* interval */ #include "plplot.h" #include <stdio.h> #include <math.h> #ifdef PLSTDC #include <string.h> #else extern char *strcat(); extern char *strcpy(); #endif #define betw(c,a,b) ((a<=c && c<=b) || (b<=c && c<=a)) static double xlog[8] = {0.301030, 0.477121, 0.602060, 0.698970, 0.778151, 0.845098, 0.903090, 0.954243}; void plaxes(x0,y0,xopt,xtick,nxsub,yopt,ytick,nysub) FLOAT x0,y0; char *xopt, *yopt; double xtick, ytick; int nxsub, nysub; { static char string[40]; int lax,lbx,lcx,lgx,lix,llx,lmx,lnx,lsx,ltx; int lay,lby,lcy,lgy,liy,lly,lmy,lny,lsy,lty,lvy; int xmajor, xminor, ymajor, yminor, xmode, xprec, xscal; int xorigin, yorigin; int ymode, yprec, yscal; int i, i1x, i2x, i3x, i4x, i1y, i2y, i3y, i4y; int nxsub1, nysub1; int lxmin, lxmax, lymin, lymax; int pxmin, pxmax, pymin, pymax; int vppxmi, vppxma, vppymi, vppyma; int level; double xpmm, ypmm, defmaj, defmin, htmaj, htmin; double xtick1, ytick1, vpwxmi, vpwxma, vpwymi, vpwyma; double pos, tn, tp, temp; glev(&level); if (level<3) plexit("Please set up window before calling plaxes."); /* Open the clip limits to the subpage limits */ gclp(&lxmin,&lxmax,&lymin,&lymax); gphy(&pxmin,&pxmax,&pymin,&pymax); sclp(pxmin,pxmax,pymin,pymax); gvpp(&vppxmi,&vppxma,&vppymi,&vppyma); /* convert world coordinates to physical */ xorigin = wcpcx(x0); yorigin = wcpcy(y0); /* Tick and subtick sizes in device coords */ gpixmm(&xpmm,&ypmm); gmaj(&defmaj,&htmaj); gmin(&defmin,&htmin); xmajor=MAX(round(htmaj*ypmm),1); ymajor=MAX(round(htmaj*xpmm),1); xminor=MAX(round(htmin*ypmm),1); yminor=MAX(round(htmin*xpmm),1); xtick1=xtick; nxsub1=nxsub; ytick1=ytick; nysub1=nysub; lax=stsearch(xopt,'a'); lbx=stsearch(xopt,'b'); lcx=stsearch(xopt,'c'); lgx=stsearch(xopt,'g'); lix=stsearch(xopt,'i'); llx=stsearch(xopt,'l'); lmx=stsearch(xopt,'m'); lnx=stsearch(xopt,'n'); lsx=stsearch(xopt,'s'); ltx=stsearch(xopt,'t'); lay=stsearch(yopt,'a'); lby=stsearch(yopt,'b'); lcy=stsearch(yopt,'c'); lgy=stsearch(yopt,'g'); liy=stsearch(yopt,'i'); lly=stsearch(yopt,'l'); lmy=stsearch(yopt,'m'); lny=stsearch(yopt,'n'); lsy=stsearch(yopt,'s'); lty=stsearch(yopt,'t'); lvy=stsearch(yopt,'v'); gvpw(&vpwxmi,&vpwxma,&vpwymi,&vpwyma); lax=lax && (vpwymi*vpwyma<0.0) && !llx; lay=lay && (vpwxmi*vpwxma<0.0) && !lly; if (llx) xtick1=1.0; if (lly) ytick1=1.0; if (ltx || lgx) pldtik(vpwxmi,vpwxma,&xtick1,&nxsub1,&xmode,&xprec,&xscal); if (lty || lgy) pldtik(vpwymi,vpwyma,&ytick1,&nysub1,&ymode,&yprec,&yscal); /* Set up tick variables */ i1x=xminor; i2x=xminor; i3x=xmajor; i4x=xmajor; i1y=yminor; i2y=yminor; i3y=ymajor; i4y=ymajor; /* draw boxing */ if (lbx) { movphy(vppxmi, vppymi); draphy(vppxma, vppymi); } if (lcx) { movphy(vppxmi, vppyma); draphy(vppxma, vppyma); } if (lby) { movphy(vppxmi, vppymi); draphy(vppxmi, vppyma); } if (lcy) { movphy(vppxma, vppymi); draphy(vppxma, vppyma); } /* Draw the horizontal axis */ movphy(vppxmi,yorigin); if (ltx) { tp=xtick1*floor(vpwxmi/xtick1); for(;;) { tn=tp+xtick1; if (lsx) { if (llx) { for(i=0; i<=7;i++){ temp=tp+xlog[i]; if (betw(temp,vpwxmi,vpwxma)) plxtik(wcpcx(temp),yorigin,i1x,i2x); } } else { for ( i=1;i<=nxsub1-1;i++) { temp=tp+i*(tn-tp)/nxsub1; if (betw(temp,vpwxmi,vpwxma)) plxtik(wcpcx(temp),yorigin,i1x,i2x); } } } if (!betw(tn,vpwxmi,vpwxma)) break; plxtik(wcpcx(tn),yorigin,i3x,i4x); tp=tn; } } draphy(vppxma,yorigin); /* Draw vertical axis */ if (lby) { movphy(xorigin,vppyma); if (lty) { tp=ytick1*(floor(vpwyma/ytick1)+1); for(;;) { tn=tp-ytick1; if (lsy) { if (lly) { for(i=7;i>=0;i--) { temp=tn+xlog[i]; if (betw(temp,vpwymi,vpwyma)) plytik(xorigin,wcpcy(temp),i1y,i2y); } } else { for(i=nysub1-1;i>=1;i--) { temp=tn+i*(tp-tn)/nysub1; if (betw(temp,vpwymi,vpwyma)) plytik(xorigin,wcpcy(temp),i1y,i2y); } } } if (!betw(tn,vpwymi,vpwyma)) break; plytik(xorigin,wcpcy(tn),i3y,i4y); tp=tn; } } draphy(xorigin,vppymi); } /* Draw grid in x direction */ if (lgx) { tp=xtick1*(1.+floor(vpwxmi/xtick1+.5)); for(tn=tp; betw(tn+xtick1/2.,vpwxmi,vpwxma); tn+=xtick1) pljoin(tn,vpwymi,tn,vpwyma); } /* Draw grid in y direction */ if (lgy) { tp=ytick1*(1.+floor(vpwymi/ytick1+.5)); for(tn=tp; betw(tn+ytick1/2.,vpwymi,vpwyma); tn+=ytick1) pljoin(vpwxmi,tn,vpwxma,tn); } /* Write horizontal label(s) */ if ((lmx || lnx) && ltx) { tp=xtick1*(1.+floor(vpwxmi/xtick1)); for(tn=tp; betw(tn,vpwxmi,vpwxma); tn+=xtick1) { if (!llx) plform(tn,xscal,xprec,string); else { sprintf(string,"10#u%d",round(tn)); } pos=(tn-vpwxmi)/(vpwxma-vpwxmi); if (lnx) plmtex("b",1.5,pos,0.5,string); if (lmx) plmtex("t",1.5,pos,0.5,string); } if(!llx && xmode) { sprintf(string,"E%+d",xscal); if (lnx) plmtex("b",3.0,1.,0.5,string); if (lmx) plmtex("t",3.0,1.,0.5,string); } } /* Write vertical label(s) */ if ((lmy || lny) && lty) { tp=ytick1*(1.+floor(vpwymi/ytick1)); for(tn=tp; betw(tn,vpwymi,vpwyma); tn+=ytick1) { if (!lly) plform(tn,yscal,yprec,string); else { sprintf(string,"10#u%d",round(tn)); } pos=(tn-vpwymi)/(vpwyma-vpwymi); if (lny) { if (lvy) plmtex("lv",0.5,pos,1.0,string); else plmtex("l",1.5,pos,0.5,string); } if (lmy) { if (lvy) plmtex("rv",0.5,pos,0.0,string); else plmtex("r",1.5,pos,0.5,string); } } if(!lly && ymode) { sprintf(string,"E%+d",yscal); if (lny) { if (lvy) plmtex("t",2.0,0.0,1.0,string); else plmtex("l",3.0,1.0,0.5,string); } if (lmy) { if (lvy) plmtex("t",2.0,1.0,0.0,string); else plmtex("r",3.0,1.0,0.5,string); } } } /* Restore the clip limits to viewport edge */ sclp(lxmin,lxmax,lymin,lymax); }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.