home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d3xx / d306 / rexxplplot.lha / RexxPlPlot / src / src.zoo / postscript.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-06  |  6.9 KB  |  209 lines

  1. /* This file contains the PostScript device dependent subroutines for */
  2. /* use with plplot. */
  3.  
  4. #include "plplot.h"
  5. #include <stdio.h>
  6.  
  7. #define LINELENGTH    70
  8. #define COPIES        1
  9. #define XSIZE        540
  10. #define YSIZE        720
  11. #define XPSSIZE        3000
  12. #define YPSSIZE        2250
  13. #define XOFFSET        576
  14. #define YOFFSET        36
  15. #define XSCALE        100
  16. #define YSCALE        100
  17. #define LINESCALE    100
  18. #define ANGLE        90
  19. char *getdate();
  20. int numpages = 0;
  21. int linepos = 0;
  22.  
  23. static FILE *OutFile;
  24. static int FirstClear=1;
  25.  
  26. /* Open file.  Set up for graphics. */
  27. void psini()
  28. {
  29.       char FileName[80];
  30.  
  31.       printf("Enter file to receive PostScript graphics commands. ");
  32.       scanf("%s",FileName);
  33.  
  34.       if ((OutFile = fopen(FileName,"w")) == NULL)  {
  35.           printf("Error opening %s \n",FileName);
  36.           exit(1);
  37.       }
  38.  
  39.   /* Header comments into PostScript file */
  40.      
  41.       fprintf(OutFile,"%%!PS-Adobe-2.0 EPSF-2.0\n");
  42.       fprintf(OutFile,"%%%%BoundingBox: 36 36 540 720\n");
  43.       fprintf(OutFile,"%%%%Title: %s\n", FileName);
  44.       fprintf(OutFile,"%%%%Creator: PLPLOT Version 1.10\n");
  45.       fprintf(OutFile,"%%%%CreationDate: %s\n", getdate());
  46.       fprintf(OutFile,"%%%%Pages: (atend)\n");
  47.       fprintf(OutFile,"%%%%EndComments\n\n");
  48.  
  49.   /* Definitions */
  50.  
  51.       fprintf(OutFile, "/PSSave save def\n");      /* save VM state */
  52.       fprintf(OutFile, "/PSDict 200 dict def\n");  /* define a dictionary */
  53.       fprintf(OutFile, "PSDict begin\n");          /* start using it */
  54.       fprintf(OutFile, "/@restore /restore load def\n");
  55.       fprintf(OutFile, "/restore\n");
  56.       fprintf(OutFile, "   {vmstatus pop\n");
  57.       fprintf(OutFile, "    dup @VMused lt {pop @VMused} if\n");
  58.       fprintf(OutFile, "    exch pop exch @restore /@VMused exch def\n");
  59.       fprintf(OutFile, "   } def\n");
  60.       fprintf(OutFile, "/@pri\n");
  61.       fprintf(OutFile, "   {\n");
  62.       fprintf(OutFile, "    ( ) print\n");
  63.       fprintf(OutFile, "    (                                       ) cvs print\n");
  64.       fprintf(OutFile, "   } def\n");
  65.       fprintf(OutFile, "/@copies\n");    /* n @copies - */
  66.       fprintf(OutFile, "   {\n");
  67.       fprintf(OutFile, "    /#copies exch def\n");
  68.       fprintf(OutFile, "   } def\n");
  69.       fprintf(OutFile, "/@start\n");    /* - @start -  -- start everything */
  70.       fprintf(OutFile, "   {\n");
  71.       fprintf(OutFile, "    vmstatus pop /@VMused exch def pop\n");
  72.       fprintf(OutFile, "   } def\n");
  73.       fprintf(OutFile, "/@end\n");    /* - @end -  -- finished */
  74.       fprintf(OutFile, "   {(VM Used: ) print @VMused @pri\n");
  75.       fprintf(OutFile, "    (. Unused: ) print vmstatus @VMused sub @pri pop pop\n");
  76.       fprintf(OutFile, "    (\\n) print flush\n");
  77.       fprintf(OutFile, "    end\n");
  78.       fprintf(OutFile, "    PSSave restore\n");
  79.       fprintf(OutFile, "   } def\n");
  80.       fprintf(OutFile, "/bop\n");    /* bop -  -- begin a new page */
  81.       fprintf(OutFile, "   {\n");
  82.       fprintf(OutFile, "    /SaveImage save def\n");
  83.       fprintf(OutFile, "   } def\n");
  84.       fprintf(OutFile, "/eop\n");    /* - eop -  -- end a page */
  85.       fprintf(OutFile, "   {\n");
  86.       fprintf(OutFile, "    showpage\n");
  87.       fprintf(OutFile, "    SaveImage restore\n");
  88.       fprintf(OutFile, "   } def\n");
  89.       fprintf(OutFile, "/@line\n");    /* set line parameters */
  90.       fprintf(OutFile, "   {0 setlinecap\n");
  91.       fprintf(OutFile, "    0 setlinejoin\n");
  92.       fprintf(OutFile, "    1 setmiterlimit\n");
  93.       fprintf(OutFile, "   } def\n");
  94.             /* d @hsize -  horizontal clipping dimension */
  95.       fprintf(OutFile, "/@hsize   {/hs exch def} def\n");
  96.       fprintf(OutFile, "/@vsize   {/vs exch def} def\n");
  97.             /* d @hoffset - shift for the plots */
  98.       fprintf(OutFile, "/@hoffset {/ho exch def} def\n");
  99.       fprintf(OutFile, "/@voffset {/vo exch def} def\n");
  100.             /* s @hscale - scale factors */
  101.       fprintf(OutFile, "/@hscale  {100 div /hsc exch def} def\n");
  102.       fprintf(OutFile, "/@vscale  {100 div /vsc exch def} def\n");
  103.             /* s @lscale - linewidth scale factor */
  104.       fprintf(OutFile, "/@lscale  {100 div /lin exch def} def\n");
  105.             /* a @angle - rotation angle */
  106.       fprintf(OutFile, "/@angle   {/ang exch def} def\n");
  107.       fprintf(OutFile, "/@SetPlot\n");    /* setup user specified offsets, */
  108.       fprintf(OutFile, "   {\n");    /* scales, sizes for clipping    */
  109.       fprintf(OutFile, "    ho vo translate\n");
  110.       fprintf(OutFile, "    XScale YScale scale\n");
  111.       fprintf(OutFile, "    ang rotate\n");
  112.       fprintf(OutFile, "    lin lw mul setlinewidth\n");
  113.       fprintf(OutFile, "   } def\n");
  114.       fprintf(OutFile, "/XScale\n");    /* setup x scale */
  115.       fprintf(OutFile, "   {hsc hs mul %d div} def\n", YPSSIZE);
  116.       fprintf(OutFile, "/YScale\n");    /* setup y scale */
  117.       fprintf(OutFile, "   {vsc vs mul %d div} def\n", XPSSIZE);
  118.       fprintf(OutFile, "/lw 3 def\n");    /* default line width */
  119.       fprintf(OutFile, "/M {moveto} def\n");    
  120.       fprintf(OutFile, "/D {lineto} def\n");    
  121.       fprintf(OutFile, "/S {stroke} def\n");    
  122.       fprintf(OutFile, "/Z {stroke newpath} def\n");
  123.       fprintf(OutFile, "end\n\n");    /* end of dictionary definition */
  124.  
  125.   /* Set up the plots */
  126.  
  127.       fprintf(OutFile, "PSDict begin\n");
  128.       fprintf(OutFile, "@start\n");
  129.       fprintf(OutFile, "%d @copies\n", COPIES);
  130.       fprintf(OutFile, "@line\n");
  131.       fprintf(OutFile, "%d @hsize\n", XSIZE);
  132.       fprintf(OutFile, "%d @vsize\n", YSIZE);
  133.       fprintf(OutFile, "%d @hoffset\n", XOFFSET);
  134.       fprintf(OutFile, "%d @voffset\n", YOFFSET);
  135.       fprintf(OutFile, "%d @hscale\n", XSCALE);
  136.       fprintf(OutFile, "%d @vscale\n", YSCALE);
  137.       fprintf(OutFile, "%d @lscale\n", LINESCALE);
  138.       fprintf(OutFile, "%d @angle\n", ANGLE);
  139.       fprintf(OutFile, "@SetPlot\n\n");
  140.       fprintf(OutFile, "bop\n");
  141.       fprintf(OutFile, "%%%%Page: %d %d\n", numpages+1, numpages+1);
  142. }
  143.  
  144. /* Sets the printer to text mode */
  145. void pstex()
  146. {
  147. }
  148.  
  149. /* Sets the printer to graphics mode */
  150. void psgra()
  151. {
  152. }
  153.  
  154. /* Form feed */
  155. void psclr()
  156. {
  157.       if(FirstClear) 
  158.         FirstClear = 0;
  159.       else {
  160.         fprintf(OutFile," S\neop\nbop\n");
  161.         numpages++;
  162.         fprintf(OutFile, "%%%%Page: %d %d\n", numpages+1, numpages+1);
  163.         linepos = 0;
  164.       }
  165. }
  166.  
  167. /* May put something here someday */
  168. void pscol(colour)
  169. int colour;
  170. {
  171. }
  172.  
  173. void pslin(x1,y1,x2,y2)
  174. int x1,y1,x2,y2;
  175. {
  176.       if (linepos + 21 > LINELENGTH) {
  177.           putc('\n', OutFile);
  178.           linepos = 0;
  179.       } else
  180.           putc(' ', OutFile);
  181.       fprintf(OutFile, "Z %ld %ld M %ld %ld D", x1, y1, x2, y2);
  182.       linepos += 21;
  183. }
  184.       
  185. /* Close graphics file */
  186. void pstid()
  187. {
  188.       fprintf(OutFile," S\neop\n");
  189.       numpages++;
  190.       fprintf(OutFile, "@end\n\n");
  191.       fprintf(OutFile, "%%%%Trailer\n");    
  192.       fprintf(OutFile, "%%%%Pages: %d\n", numpages);    
  193.       fclose(OutFile);
  194. }
  195.  
  196. /* Get the date and time */
  197. char *getdate()
  198. {
  199.     int len;
  200.     long t, time();
  201.     char *p, *ctime();
  202.  
  203.     t = time((long *) 0);
  204.     p = ctime(&t);
  205.     len = strlen(p);
  206.     *(p + len - 1) = '\0';    /* zap the newline character */
  207.     return p;
  208. }
  209.