ftp.nice.ch/pub/next/unix/developer/plplot.3.0.s.tar.gz#/plplot/src/global.c

This is global.c in view mode; [Download] [Up]

/*
* All the variables for PLPLOT, several routines
* to safely read and write these variables, several coordinate
* transformation routines which make extensive use of these variables,
* and all the device independent stub routines.
*
* device  :  Graphics device number
* termin  :  Zero for noninteractive device, non-zero for terminal
* graphx  :  Zero if currently in text mode, non-zero for graphics mode
* currx   :  Physical x-coordinate of current point
* curry   :  Physical y-coordinate of current point
* vpp...  :  Viewport boundaries in physical coordinates
* spp...  :  Subpage  boundaries in physical coordinates
* clp...  :  Clip     boundaries in physical coordinates
* phy...  :  Physical device limits in physical coordinates
* nsub.   :  Number of subpages on physical device
* cursub  :  Current subpage
* um.     :  Number of micrometres in a pixel
* font    :  Current default font
* colour  :  Current default colour
* width   :  Current pen width
* mark    :  Array of mark lengths in micrometres for broken lines
* space   :  Array of space lengths in micrometres for broken lines
* nms     :  Number of elements for current broken line style
* timecnt :  Timer for broken lines
* alarm   :  Alarm indicating change of broken line status
* pendn   :  Flag indicating if pen is up or down
* curel   :  Current element within broken line
* inclin  :  Array of inclinations in tenths of degree for fill lines
* delta   :  Array of spacings in micrometers between fill lines
* nps     :  Number of distinct line styles for fills
* level   :  Initialization level
*
* spd...  :  Subpage  boundaries in normalized device coordinates
* vpd...  :  Viewport boundaries in normalized device coordinates
* vpw...  :  Viewport boundaries in world coordinates
* .pmm    :  Number of pixels to a millimetre
* wp....  :  Transformation variables for world  to physical conversion
* dp....  :  Transformation variables for device to physical conversion
* mp....  :  Transformation variables for millimetres from bottom left
*             hand corner to physical coordinates
* wm....  :  Transformation variables for world coordinates to mm
* chr...  :  Character default height and current (scaled) height
* sym...  :  Symbol    default height and current (scaled) height
* maj...  :  Major tick default height and current (scaled) height
* min...  :  Minor tick default height and current (scaled) height
* base3.  :  World coordinate size of base for 3-d plot
* basec.  :  Position of centre of base for 3-d plot
* dom...  :  Minimum and maximum values for domain
* zzscl   :  Vertical (z) scale for 3-d plot
* ran..   :  Minimum and maximum z values for 3-d plot
* c..     :  Coordinate transformation from 3-d to 2-d
*/

#include "plplot.h"
#include "dispatch.h"
#include <stdio.h>
#include <math.h>

/* device is the only global variable. It is globally visible for speed */
static int device, termin, graphx;
static int currx,  curry;
static int vppxmi, vppxma, vppymi, vppyma;
static int sppxmi, sppxma, sppymi, sppyma;
static int clpxmi, clpxma, clpymi, clpyma;
static int phyxmi, phyxma, phyymi, phyyma;
static int nsubx,  nsuby, cursub;
static int umx,    umy;
static int font,   colour, width, style;
static int mark[10], space[10], nms, timecnt;
static int alarm,  pendn,  curel;
static int inclin[2], delta[2], nps;
static int level=0;

static double spdxmi, spdxma, spdymi, spdyma;
static double vpdxmi, vpdxma, vpdymi, vpdyma;
static double vpwxmi, vpwxma, vpwymi, vpwyma;
static double xpmm,   ypmm;
static double wpxscl, wpxoff, wpyscl, wpyoff;
static double dpxscl, dpxoff, dpyscl, dpyoff;
static double mpxscl, mpxoff, mpyscl, mpyoff;
static double wmxscl, wmxoff, wmyscl, wmyoff;
static double chrdef, chrht;
static double symdef, symht;
static double majdef, majht;
static double mindef, minht;
static double base3x, base3y, basecx, basecy;
static double domxmi, domxma, domymi, domyma;
static double zzscl,  ranmi,  ranma;
static double cxx,    cxy,    cyx,    cyy,   cyz;

static int orient;
static double xdpi, ydpi;
static int xwidth, ywidth;
static FILE *outfile;
static int initfont;
static int orientset=0, fileset=0, pageset=0, fontset=0;

/* Initializes the graphics device "dev"  */
void grbeg(dev)
int dev;
{
   int mk=0, sp=0;
   int inc=0, del=2000;

   /* Set device number, graphics mode and font */
   device = dev;
   graphx = 0;
   font = 1;
   colour = 1;
   style = 0;

   /* Start by initializing device */
   if(orientset) {
      grorient();
      orientset = 0;
   }
   if(fileset) {
      grselect();
      fileset = 0;
   }
   if(pageset) {
      grsetup();
      pageset = 0;
   }
   if(fontset) {
      plfntld(initfont);
      fontset = 0;
   }
   else
      plfntld(0);

   grinit();
   grpage();

   /* Set default sizes */
   plschr(4.0,1.0);
   plssym(4.0,1.0);
   plsmaj(3.0,1.0);
   plsmin(1.5,1.0);

   /* Switch to graphics mode and set color */
   grgra();
   grcol();
   grwid();

   plprec(0,0);
   plstyl(0,&mk,&sp);
   plpat(1,&inc,&del);

   /* Set clip limits. */
   clpxmi = phyxmi;
   clpxma = phyxma;
   clpymi = phyymi;
   clpyma = phyyma;
}

void plsetup(xp,yp,xwid,ywid)
double xp, yp;
int xwid, ywid;
{
   xdpi = xp;
   ydpi = yp;
   xwidth = xwid;
   ywidth = ywid;
   pageset = 1;
}

void plorient(ori)
int ori;
{
   orient = ori;
   orientset = 1;
}

void plselect(file)
FILE *file;
{
   outfile = file;
   fileset = 1;
}

void plfontld(fnt)
int fnt;
{
   if(fnt != 0)
     fnt = 1;

   if(level>0) 
     plfntld(fnt);
   else {
     initfont = fnt;
     fontset = 1;
   }
}

extern DISPATCH_TABLE  plDispatchTable[];

void grsetup()
{
   (*plDispatchTable[device-1].pl_setup)(xdpi,ydpi,xwidth,ywidth);
}

void grorient()
{
   (*plDispatchTable[device-1].pl_orient)(orient);
}

void grselect()
{
   (*plDispatchTable[device-1].pl_select)(outfile);
}

/* Initializes the graphics device */
void grinit()
{
   (*plDispatchTable[device-1].pl_init)();
}

/* Clears the graphics screen */
void grclr()
{
   (*plDispatchTable[device-1].pl_clear)();
}

void grpage()
{
   (*plDispatchTable[device-1].pl_page)();
}

void greop()
{
   (*plDispatchTable[device-1].pl_eop)();
}

/* Sets up the line colour to value in global variable "colour" */
void grcol()
{
   (*plDispatchTable[device-1].pl_color)(colour);
}

void grwid()
{
   (*plDispatchTable[device-1].pl_width)(width);
}

void grcwin()
{
   (*plDispatchTable[device-1].pl_cwin)();
}

void grgwin()
{
   (*plDispatchTable[device-1].pl_gwin)();
}

/* Switches to graphics mode */
void grgra()
{
   (*plDispatchTable[device-1].pl_graph)();
   graphx = 1;
}

/* Draws a line from (x1,x2) to (x2,y2), used by genlin() */
void grline(x1,y1,x2,y2)
int x1,y1,x2,y2;
{
   (*plDispatchTable[device-1].pl_line)( x1,y1, x2,y2);
}

/* Switches to text mode */
void grtext()
{
   (*plDispatchTable[device-1].pl_text)();
   graphx = 0;
}

/* Called by plend to tidy up graphics device */
void grtidy()
{
   (*plDispatchTable[device-1].pl_tidy)();
}


/* Sets and gets global variables */
void glev(n)
int *n;
{
      *n = level;
}

void slev(n)
int n;
{
      level = n;
}

void gbase(x,y,xc,yc)
double *x,*y,*xc,*yc;
{
      *x = base3x;
      *y = base3y;
      *xc = basecx;
      *yc = basecy;
}

void sbase(x,y,xc,yc)
double x,y,xc,yc;
{
      base3x = x;
      base3y = y;
      basecx = xc;
      basecy = yc;
}

void gnms(n)
int *n;
{
      *n = nms;
}

void snms(n)
int n;
{
      nms = n;
}

void gdev(dev,term,gra)
int *dev,*term,*gra;
{
      *dev = device;
      *term = termin;
      *gra = graphx;
}

void sdev(dev,term,gra)
int dev,term,gra;
{
      device = dev;
      termin = term;
      graphx = gra;
}

void gdevice(dev)
int *dev;
{
      *dev = device;
}

void sdevice(dev)
int dev;
{
      device = dev;
}

void ggra(gra)
int *gra;
{
      *gra = graphx;
}

void sgra(gra)
int gra;
{
      graphx = gra;
}

void smod(term)
int term;
{
      termin = term;
}

void gcurr(ix,iy)
int *ix,*iy;
{
      *ix = currx;
      *iy = curry;
}

void scurr(ix,iy)
int ix,iy;
{
      currx = ix;
      curry = iy;
}

void gdom(xmin,xmax,ymin,ymax)
double *xmin,*xmax,*ymin,*ymax;
{
      *xmin = domxmi;
      *xmax = domxma;
      *ymin = domymi;
      *ymax = domyma;
}

void sdom(xmin,xmax,ymin,ymax)
double xmin,xmax,ymin,ymax;
{
      domxmi = xmin;
      domxma = xmax;
      domymi = ymin;
      domyma = ymax;
}

void grange(zscl,zmin,zmax)
double *zscl,*zmin,*zmax;
{
      *zscl = zzscl;
      *zmin = ranmi;
      *zmax = ranma;
}

void srange(zscl,zmin,zmax)
double zscl,zmin,zmax;
{
      zzscl = zscl;
      ranmi = zmin;
      ranma = zmax;
}

void gw3wc(dxx,dxy,dyx,dyy,dyz)
double *dxx,*dxy,*dyx,*dyy,*dyz;
{
      *dxx = cxx;
      *dxy = cxy;
      *dyx = cyx;
      *dyy = cyy;
      *dyz = cyz;
}

void sw3wc(dxx,dxy,dyx,dyy,dyz)
double dxx,dxy,dyx,dyy,dyz;
{
      cxx = dxx;
      cxy = dxy;
      cyx = dyx;
      cyy = dyy;
      cyz = dyz;
}

void gvpp(ixmin,ixmax,iymin,iymax)
int *ixmin,*ixmax,*iymin,*iymax;
{
      *ixmin = vppxmi;
      *ixmax = vppxma;
      *iymin = vppymi;
      *iymax = vppyma;
}

void svpp(ixmin,ixmax,iymin,iymax)
int ixmin,ixmax,iymin,iymax;
{
      vppxmi = ixmin;
      vppxma = ixmax;
      vppymi = iymin;
      vppyma = iymax;
}

void gspp(ixmin,ixmax,iymin,iymax)
int *ixmin,*ixmax,*iymin,*iymax;
{
      *ixmin = sppxmi;
      *ixmax = sppxma;
      *iymin = sppymi;
      *iymax = sppyma;
}

void sspp(ixmin,ixmax,iymin,iymax)
int ixmin,ixmax,iymin,iymax;
{
      sppxmi = ixmin;
      sppxma = ixmax;
      sppymi = iymin;
      sppyma = iymax;
}

void gclp(ixmin,ixmax,iymin,iymax)
int *ixmin,*ixmax,*iymin,*iymax;
{
      *ixmin = clpxmi;
      *ixmax = clpxma;
      *iymin = clpymi;
      *iymax = clpyma;
}

void sclp(ixmin,ixmax,iymin,iymax)
int ixmin,ixmax,iymin,iymax;
{
      clpxmi = ixmin;
      clpxma = ixmax;
      clpymi = iymin;
      clpyma = iymax;
}

void gphy(ixmin,ixmax,iymin,iymax)
int *ixmin,*ixmax,*iymin,*iymax;
{
      *ixmin = phyxmi;
      *ixmax = phyxma;
      *iymin = phyymi;
      *iymax = phyyma;
}

void sphy(ixmin,ixmax,iymin,iymax)
int ixmin,ixmax,iymin,iymax;
{
      phyxmi = ixmin;
      phyxma = ixmax;
      phyymi = iymin;
      phyyma = iymax;
}

void gsub(nx,ny,cs)
int *nx,*ny,*cs;
{
      *nx = nsubx;
      *ny = nsuby;
      *cs = cursub;
}

void ssub(nx,ny,cs)
int nx,ny,cs;
{
      nsubx = nx;
      nsuby = ny;
      cursub = cs;
}

void gumpix(ix,iy)
int *ix,*iy;
{
      *ix = umx;
      *iy = umy;
}

void sumpix(ix,iy)
int ix,iy;
{
      umx = ix;
      umy = iy;
}

void gatt(ifnt,icol)
int *ifnt,*icol;
{
      *ifnt = font;
      *icol = colour;
}

void satt(ifnt,icol)
int ifnt,icol;
{
      font = ifnt;
      colour = icol;
}

void gcol(icol)
int *icol;
{
      *icol = colour;
}

void scol(icol)
int icol;
{
      colour = icol;
}

void gwid(pwid)
int *pwid;
{
      *pwid = width;
}

void swid(pwid)
int pwid;
{
      width = pwid;
}

void gspd(xmin,xmax,ymin,ymax)
double *xmin,*xmax,*ymin,*ymax;
{
      *xmin = spdxmi;
      *xmax = spdxma;
      *ymin = spdymi;
      *ymax = spdyma;
}

void sspd(xmin,xmax,ymin,ymax)
double xmin,xmax,ymin,ymax;
{
      spdxmi = xmin;
      spdxma = xmax;
      spdymi = ymin;
      spdyma = ymax;
}

void gvpd(xmin,xmax,ymin,ymax)
double *xmin,*xmax,*ymin,*ymax;
{
      *xmin = vpdxmi;
      *xmax = vpdxma;
      *ymin = vpdymi;
      *ymax = vpdyma;
}

void svpd(xmin,xmax,ymin,ymax)
double xmin,xmax,ymin,ymax;
{
      vpdxmi = xmin;
      vpdxma = xmax;
      vpdymi = ymin;
      vpdyma = ymax;
}

void gvpw(xmin,xmax,ymin,ymax)
double *xmin,*xmax,*ymin,*ymax;
{
      *xmin = vpwxmi;
      *xmax = vpwxma;
      *ymin = vpwymi;
      *ymax = vpwyma;
}

void svpw(xmin,xmax,ymin,ymax)
double xmin,xmax,ymin,ymax;
{
      vpwxmi = xmin;
      vpwxma = xmax;
      vpwymi = ymin;
      vpwyma = ymax;
}

void gpixmm(x,y)
double *x,*y;
{
      *x = xpmm;
      *y = ypmm;
}

void spixmm(x,y)
double x,y;
{
      xpmm = x;
      ypmm = y;
}

void gwp(xscl,xoff,yscl,yoff)
double *xscl,*xoff,*yscl,*yoff;
{
      *xscl = wpxscl;
      *xoff = wpxoff;
      *yscl = wpyscl;
      *yoff = wpyoff;
}

void swp(xscl,xoff,yscl,yoff)
double xscl,xoff,yscl,yoff;
{
      wpxscl = xscl;
      wpxoff = xoff;
      wpyscl = yscl;
      wpyoff = yoff;
}

void gwm(xscl,xoff,yscl,yoff)
double *xscl,*xoff,*yscl,*yoff;
{
      *xscl = wmxscl;
      *xoff = wmxoff;
      *yscl = wmyscl;
      *yoff = wmyoff;
}

void swm(xscl,xoff,yscl,yoff)
double xscl,xoff,yscl,yoff;
{
      wmxscl = xscl;
      wmxoff = xoff;
      wmyscl = yscl;
      wmyoff = yoff;
}

void gdp(xscl,xoff,yscl,yoff)
double *xscl,*xoff,*yscl,*yoff;
{
      *xscl = dpxscl;
      *xoff = dpxoff;
      *yscl = dpyscl;
      *yoff = dpyoff;
}

void sdp(xscl,xoff,yscl,yoff)
double xscl,xoff,yscl,yoff;
{
      dpxscl = xscl;
      dpxoff = xoff;
      dpyscl = yscl;
      dpyoff = yoff;
}

void gmp(xscl,xoff,yscl,yoff)
double *xscl,*xoff,*yscl,*yoff;
{
      *xscl = mpxscl;
      *xoff = mpxoff;
      *yscl = mpyscl;
      *yoff = mpyoff;
}

void smp(xscl,xoff,yscl,yoff)
double xscl,xoff,yscl,yoff;
{
      mpxscl = xscl;
      mpxoff = xoff;
      mpyscl = yscl;
      mpyoff = yoff;
}

void gchr(def,ht)
double *def,*ht;
{
      *def = chrdef;
      *ht = chrht;
}

void schr(def,ht)
double def,ht;
{
      chrdef = def;
      chrht = ht;
}

void gsym(def,ht)
double *def,*ht;
{
      *def = symdef;
      *ht = symht;
}

void ssym(def,ht)
double def,ht;
{
      symdef = def;
      symht = ht;
}

void gmaj(def,ht)
double *def,*ht;
{
      *def = majdef;
      *ht = majht;
}

void smaj(def,ht)
double def,ht;
{
      majdef = def;
      majht = ht;
}

void gmin(def,ht)
double *def,*ht;
{
      *def = mindef;
      *ht = minht;
}

void smin(def,ht)
double def,ht;
{
      mindef = def;
      minht = ht;
}

void gpat(inc, del, nlin)
int **inc, **del, *nlin;
{
  *inc = inclin;
  *del = delta;
  *nlin = nps;
}

void spat(inc, del, nlin)
int *inc, *del, nlin;
{
  int i;
  
  nps = nlin;
  for(i=0; i<nlin; i++) {
    inclin[i] = inc[i];
    delta[i] = del[i];
  }
}

void gmark(mar, spa, nels)
int **mar, **spa, **nels;
{
  *mar = mark;
  *spa = space;
  *nels = &nms;
}

void smark(mar, spa, nels)
int *mar, *spa, nels;
{
  int i;
  
  nms = nels;
  for(i=0; i<nels; i++) {
    mark[i] = mar[i];
    space[i] = spa[i];
  }
}

void gcure(cur, pen, tim, ala)
int **cur, **pen, **tim, **ala;
{
  *cur = &curel;
  *pen = &pendn;
  *tim = &timecnt;
  *ala = &alarm;
}

void scure(cur, pen, tim, ala)
int cur, pen, tim, ala;
{
  curel = cur;
  pendn = pen;
  timecnt = tim;
  alarm = ala;
}

/* Coordinate transformations for plotting package */
/* Convertion routines yielding an integer result  */

/* dcpc. converts device coordinates to physical coordinates */

int dcpcx(x)
double x;
{
      return(round(dpxoff + dpxscl * x));
}

int dcpcy(y)
double y;
{
      return(round(dpyoff + dpyscl * y));
}

/* mmpc. converts millimetres from bottom left-hand corner to physical */
/* coordinates */

int mmpcx(x)
double x;
{
      return(round(mpxoff + mpxscl * x));
}

int mmpcy(y)
double y;
{
      return(round(mpyoff + mpyscl * y));
}

/* wcpc. converts world coordinates to physical coordinates */

int wcpcx(x)
double x;
{
      return(round(wpxoff + wpxscl * x));
}

int wcpcy(y)
double y;
{
      return(round(wpyoff + wpyscl * y));
}

/* Coordinate transformations for plotting package */
/* Convertion routines yielding a double result  */

/* dcmm. converts from device coordinates to millimetres from bottom */
/* left-hand corner */

double dcmmx(x)
double x;
{
      return((double)(x * ABS(phyxma-phyxmi) / xpmm));
}

double dcmmy(y)
double y;
{
      return((double)(y * ABS(phyyma-phyymi) / ypmm));
}

/* dcsc. define transformations between device coordinates and subpage */
/* coordinates */

double dcscx(x)
double x;
{
      return((double)((x - spdxmi)/(spdxma-spdxmi)));
}

double dcscy(y)
double y;
{
      return((double)((y - spdymi)/(spdyma-spdymi)));
}

/* mmdc. converts millimetres from bottom left corner into device */
/* coordinates */

double mmdcx(x)
double x;
{
      return((double)(x * xpmm / ABS(phyxma - phyxmi)));
}

double mmdcy(y)
double y;
{
      return((double)(y * ypmm / ABS(phyyma - phyymi)));
}

/* scdc. converts subpage coordinates to device coordinates */

double scdcx(x)
double x;
{
      return((double)(spdxmi + (spdxma-spdxmi) * x));
}

double scdcy(y)
double y;
{
      return((double)(spdymi + (spdyma-spdymi) * y));
}

/* wcmm. converts world coordinates into millimetres */

double wcmmx(x)
double x;
{
      return((double)(wmxoff + wmxscl*x));
}

double wcmmy(y)
double y;
{
      return((double)(wmyoff + wmyscl*y));
}

double w3wcx(x,y,z)
double x, y, z;
{
      return((double)((x-basecx)*cxx + (y-basecy)*cxy));
}

double w3wcy(x,y,z)
double x, y, z;
{
      return((double)((x-basecx)*cyx+(y-basecy)*cyy+(z-ranmi)*cyz));
}


These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.