home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 344b.lha / plplot_v2.6 / src / plstar.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-27  |  3.7 KB  |  190 lines

  1. #include "plplot.h"
  2. #include "declare.h"
  3. #include "dispatch.h"
  4. #include <stdio.h>
  5.  
  6. /* Asks for number of plotting device, and call plbeg to divide the */
  7. /* page into nx by ny subpages */
  8. void plstar(nx,ny)
  9. PLINT nx, ny;
  10. {
  11.    PLINT dev, i;
  12.    char response[10];
  13.    extern PLINT npldrivers;
  14.    extern DISPATCH_TABLE  plDispatchTable[];
  15.  
  16.    if(level != 0)
  17.       plend();
  18.  
  19.    dev = 0;
  20.    while(dev<1 || dev>npldrivers) {
  21.       printf("\nPlotting Options:\n");
  22.       for(i=0; i<npldrivers;i++)
  23.          printf(" <%2d> %s\n",i+1,plDispatchTable[i].pl_MenuStr);
  24.       printf("\nEnter device number: ");
  25.       fgets(response,sizeof(response),stdin);
  26.       if(sscanf(response,"%d",&dev) != 1) {
  27.          printf("Invalid device number.");
  28.          dev = 0;
  29.       }
  30.    }
  31.    plbeg(dev,nx,ny);
  32. }
  33.  
  34. static pagesetup=0, select=0;
  35.  
  36. /* Initializes the graphics device "dev"  */
  37. void grbeg(dev)
  38. PLINT dev;
  39. {
  40.    PLINT phyxmi, phyxma, phyymi, phyyma;
  41.    PLINT mk=0, sp=0;
  42.    PLINT inc=0, del=2000;
  43.  
  44.    /* Set device number, graphics mode and font */
  45.    device = dev;
  46.    graphx = 0;
  47.    font = 1;
  48.  
  49.    /* Start by initializing device */
  50.    if(pagesetup) {
  51.       grsetup();
  52.       pagesetup = 0;
  53.    }
  54.    if(select) {
  55.       grselect();
  56.       select = 0;
  57.    }
  58.    grinit();
  59.    grpage();
  60.  
  61.    /* Set default sizes */
  62.    plschr((PLFLT)4.0,(PLFLT)1.0);
  63.    plssym((PLFLT)4.0,(PLFLT)1.0);
  64.    plsmaj((PLFLT)3.0,(PLFLT)1.0);
  65.    plsmin((PLFLT)1.5,(PLFLT)1.0);
  66.  
  67.    /* Switch to graphics mode and set color */
  68.    grgra();
  69.    grcol();
  70.    grwid();
  71.  
  72.    /* Load standard font */
  73.    plfontld(0);
  74.    plprec(0,0);
  75.    plstyl(0,&mk,&sp);
  76.    plpat(1,&inc,&del);
  77.  
  78.    gphy(&phyxmi,&phyxma,&phyymi,&phyyma);
  79.    /* Set clip limits. */
  80.    sclp(phyxmi,phyxma,phyymi,phyyma);
  81. }
  82.  
  83. static PLINT orient, xwidth, ywidth;
  84. static PLFLT xdpi, ydpi;
  85. char FileName[80];
  86.  
  87. void plsetup(xpmm,ypmm,xwid,ywid)
  88. PLINT xwid, ywid;
  89. PLFLT xpmm, ypmm;
  90. {
  91.    xdpi = xpmm;
  92.    ydpi = ypmm;
  93.    xwidth = xwid;
  94.    ywidth = ywid;
  95.    pagesetup = 1;
  96. }
  97.  
  98. void plselect(ori, file)
  99. PLINT ori;
  100. char *file;
  101. {
  102.    orient = ori;
  103.    strncpy(FileName,file,sizeof(FileName)-1);
  104.    FileName[sizeof(FileName)-1] = '\0';
  105.    select = 1;
  106. }
  107.  
  108. void grsetup()
  109. {
  110.    if(plDispatchTable[device-1].pl_setup)
  111.       (*plDispatchTable[device-1].pl_setup)(xdpi,ydpi,xwidth,ywidth);
  112. }
  113.  
  114. void grselect()
  115. {
  116.    if(plDispatchTable[device-1].pl_select)
  117.       (*plDispatchTable[device-1].pl_select)(orient, FileName);
  118. }
  119.  
  120. /* Initializes the graphics device */
  121. void grinit()
  122. {
  123.    if(plDispatchTable[device-1].pl_init)
  124.       (*plDispatchTable[device-1].pl_init)();
  125. }
  126.  
  127. /* Clears the graphics screen */
  128. void grclr()
  129. {
  130.    if(plDispatchTable[device-1].pl_clear)
  131.       (*plDispatchTable[device-1].pl_clear)();
  132. }
  133.  
  134. void grpage()
  135. {
  136.    if(select) {
  137.       grselect();
  138.       select = 0;
  139.    }
  140.    if(plDispatchTable[device-1].pl_page)
  141.       (*plDispatchTable[device-1].pl_page)();
  142. }
  143.  
  144. /* Sets up the line colour to value in global variable "colour" */
  145. void grcol()
  146. {
  147.    if(plDispatchTable[device-1].pl_color)
  148.       (*plDispatchTable[device-1].pl_color)(colour);
  149. }
  150.  
  151. void grwid()
  152. {
  153.    if(plDispatchTable[device-1].pl_width)
  154.       (*plDispatchTable[device-1].pl_width)(width);
  155. }
  156.  
  157. /* Switches to graphics mode */
  158. void grgra()
  159. {
  160.    if(plDispatchTable[device-1].pl_graph)
  161.       (*plDispatchTable[device-1].pl_graph)();
  162.  
  163.    graphx = 1;
  164. }
  165.  
  166. /* Draws a line from (x1,x2) to (x2,y2), used by genlin() */
  167. void grline(x1,y1,x2,y2)
  168. PLINT x1,y1,x2,y2;
  169. {
  170.    if(plDispatchTable[device-1].pl_line)
  171.       (*plDispatchTable[device-1].pl_line)( x1,y1, x2,y2);
  172. }
  173.  
  174. /* Switches to text mode */
  175. void grtext()
  176. {
  177.    if(plDispatchTable[device-1].pl_text)
  178.       (*plDispatchTable[device-1].pl_text)();
  179.  
  180.    graphx = 0;
  181. }
  182.  
  183. /* Called by plend to tidy up graphics device */
  184. void grtidy()
  185. {
  186.    if(plDispatchTable[device-1].pl_tidy)
  187.       (*plDispatchTable[device-1].pl_tidy)();
  188. }
  189.  
  190.