home *** CD-ROM | disk | FTP | other *** search
- #include "plplot.h"
- #include "declare.h"
- #include "dispatch.h"
- #include <stdio.h>
-
- /* Asks for number of plotting device, and call plbeg to divide the */
- /* page into nx by ny subpages */
- void plstar(nx,ny)
- PLINT nx, ny;
- {
- PLINT dev, i;
- char response[10];
- extern PLINT npldrivers;
- extern DISPATCH_TABLE plDispatchTable[];
-
- if(level != 0)
- plend();
-
- dev = 0;
- while(dev<1 || dev>npldrivers) {
- printf("\nPlotting Options:\n");
- for(i=0; i<npldrivers;i++)
- printf(" <%2d> %s\n",i+1,plDispatchTable[i].pl_MenuStr);
- printf("\nEnter device number: ");
- fgets(response,sizeof(response),stdin);
- if(sscanf(response,"%d",&dev) != 1) {
- printf("Invalid device number.");
- dev = 0;
- }
- }
- plbeg(dev,nx,ny);
- }
-
- static pagesetup=0, select=0;
-
- /* Initializes the graphics device "dev" */
- void grbeg(dev)
- PLINT dev;
- {
- PLINT phyxmi, phyxma, phyymi, phyyma;
- PLINT mk=0, sp=0;
- PLINT inc=0, del=2000;
-
- /* Set device number, graphics mode and font */
- device = dev;
- graphx = 0;
- font = 1;
-
- /* Start by initializing device */
- if(pagesetup) {
- grsetup();
- pagesetup = 0;
- }
- if(select) {
- grselect();
- select = 0;
- }
- grinit();
- grpage();
-
- /* Set default sizes */
- plschr((PLFLT)4.0,(PLFLT)1.0);
- plssym((PLFLT)4.0,(PLFLT)1.0);
- plsmaj((PLFLT)3.0,(PLFLT)1.0);
- plsmin((PLFLT)1.5,(PLFLT)1.0);
-
- /* Switch to graphics mode and set color */
- grgra();
- grcol();
- grwid();
-
- /* Load standard font */
- plfontld(0);
- plprec(0,0);
- plstyl(0,&mk,&sp);
- plpat(1,&inc,&del);
-
- gphy(&phyxmi,&phyxma,&phyymi,&phyyma);
- /* Set clip limits. */
- sclp(phyxmi,phyxma,phyymi,phyyma);
- }
-
- static PLINT orient, xwidth, ywidth;
- static PLFLT xdpi, ydpi;
- char FileName[80];
-
- void plsetup(xpmm,ypmm,xwid,ywid)
- PLINT xwid, ywid;
- PLFLT xpmm, ypmm;
- {
- xdpi = xpmm;
- ydpi = ypmm;
- xwidth = xwid;
- ywidth = ywid;
- pagesetup = 1;
- }
-
- void plselect(ori, file)
- PLINT ori;
- char *file;
- {
- orient = ori;
- strncpy(FileName,file,sizeof(FileName)-1);
- FileName[sizeof(FileName)-1] = '\0';
- select = 1;
- }
-
- void grsetup()
- {
- if(plDispatchTable[device-1].pl_setup)
- (*plDispatchTable[device-1].pl_setup)(xdpi,ydpi,xwidth,ywidth);
- }
-
- void grselect()
- {
- if(plDispatchTable[device-1].pl_select)
- (*plDispatchTable[device-1].pl_select)(orient, FileName);
- }
-
- /* Initializes the graphics device */
- void grinit()
- {
- if(plDispatchTable[device-1].pl_init)
- (*plDispatchTable[device-1].pl_init)();
- }
-
- /* Clears the graphics screen */
- void grclr()
- {
- if(plDispatchTable[device-1].pl_clear)
- (*plDispatchTable[device-1].pl_clear)();
- }
-
- void grpage()
- {
- if(select) {
- grselect();
- select = 0;
- }
- if(plDispatchTable[device-1].pl_page)
- (*plDispatchTable[device-1].pl_page)();
- }
-
- /* Sets up the line colour to value in global variable "colour" */
- void grcol()
- {
- if(plDispatchTable[device-1].pl_color)
- (*plDispatchTable[device-1].pl_color)(colour);
- }
-
- void grwid()
- {
- if(plDispatchTable[device-1].pl_width)
- (*plDispatchTable[device-1].pl_width)(width);
- }
-
- /* Switches to graphics mode */
- void grgra()
- {
- if(plDispatchTable[device-1].pl_graph)
- (*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)
- PLINT x1,y1,x2,y2;
- {
- if(plDispatchTable[device-1].pl_line)
- (*plDispatchTable[device-1].pl_line)( x1,y1, x2,y2);
- }
-
- /* Switches to text mode */
- void grtext()
- {
- if(plDispatchTable[device-1].pl_text)
- (*plDispatchTable[device-1].pl_text)();
-
- graphx = 0;
- }
-
- /* Called by plend to tidy up graphics device */
- void grtidy()
- {
- if(plDispatchTable[device-1].pl_tidy)
- (*plDispatchTable[device-1].pl_tidy)();
- }
-
-