home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Science / Science.zip / gmt_os2.zip / src / psmegaplot.c < prev    next >
C/C++ Source or Header  |  1995-02-04  |  3KB  |  109 lines

  1. /*--------------------------------------------------------------------
  2.  *    The GMT-system:    @(#)psmegaplot.c    2.9  2/4/95
  3.  *
  4.  *    Copyright (c) 1991-1995 by P. Wessel and W. H. F. Smith
  5.  *    See README file for copying and redistribution conditions.
  6.  *--------------------------------------------------------------------*/
  7. /*
  8.  * psmegaplot allows a regular postscript file to be magnified and split up into
  9.  * pieces that are plotted out to make up a jigsaw puzzle. The source PS file
  10.  * is assumed to have any translate/offset/scale statements reversed at the end
  11.  * and that there is no showpage statement at the bottom.
  12.  *
  13.  * Author:    Paul Wessel
  14.  * Date:    21-MAY-1991-1995
  15.  * Version:    2.0
  16.  */
  17.  
  18. #include "gmt.h"
  19.  
  20. #define XL 575    /* Actual plotsize on paper, origin is <18,8> (varies from printer to printer) */
  21. #define YL 775
  22.  
  23. main (argc, argv)
  24. int argc;
  25. char **argv; {
  26.     int x0, y0, i, j, nx, ny;
  27.     double scale = 0.0;
  28.     FILE *fp;
  29.     char ifile[100], buffer[512], first, crop_marks = FALSE, error = FALSE;
  30.  
  31.     for (i = 1; i < argc; i++) {
  32.         if (argv[i][0] == '-') {
  33.             switch (argv[i][1]) {
  34.                 case 'C' :
  35.                     crop_marks = TRUE;
  36.                     break;
  37.                 case 'S' :
  38.                     scale = atof (&argv[i][2]);
  39.                     break;
  40.                 case '\0' :
  41.                     gmt_quick = TRUE;
  42.                     break;
  43.                 default :
  44.                     error = TRUE;
  45.                     gmt_default_error (argv[i][1]);
  46.                     break;
  47.             }
  48.         }
  49.         else
  50.             strcpy (ifile, argv[i]);
  51.     }
  52.     
  53.     if (argc == 1 || gmt_quick) {
  54.         fprintf(stderr, "psmegaplot %s - Make postersize plot using tiling\n\n", GMT_VERSION);
  55.         fprintf(stderr, "usage : psmegaplot psfile -S<scale> [-C]\n");
  56.  
  57.         if (gmt_quick) exit (-1);
  58.  
  59.         fprintf(stderr, "    -S sets scale, must be > 1.0\n");
  60.         fprintf (stderr, "\n\tOPTIONS:\n");
  61.         fprintf(stderr, "    -C means plot crop marks at corners\n");
  62.         exit(-1);
  63.     }
  64.     
  65.     if (scale <= 1.0) {
  66.         fprintf (stderr, "%s: GMT SYNTAX ERROR -S option:  scale must be larger than 1\n", gmt_program);
  67.         error++;
  68.     }
  69.     if (error) exit (-1);
  70.     
  71.     if ((fp = fopen(ifile, "r")) == NULL) {
  72.         fprintf(stderr, "psmegaplot: Could not open file %s\n", ifile);
  73.         exit(-1);
  74.     }
  75.     
  76.     ny = nx = ceil (scale);
  77.     first = TRUE;
  78.     printf("%%!\n");
  79.     for (i = 0; i < nx; i++) {
  80.         x0 = XL * i;
  81.         for (j = 0; j < ny; j++) {
  82.             y0 = YL * j;
  83.             if (crop_marks) {
  84.                 printf ("1 setlinewidth\n");
  85.                 printf ("18 9 moveto 0 -1 rlineto 1 0 rlineto\n");
  86.                 printf ("574 0 rmoveto 1 0 rlineto 0 1 rlineto\n");
  87.                 printf ("0 774 rmoveto 0 1 rlineto -1 0 rlineto\n");
  88.                 printf ("-574 0 rmoveto -1 0 rlineto 0 -1 rlineto stroke\n");
  89.             }
  90.             printf ("%d %d translate\n", -x0, -y0);
  91.             printf ("%.3lf %.3lf scale\n", scale, scale);
  92.             fseek (fp, 0L, 0);
  93.             while (fgets (buffer, 512, fp)) {
  94.                 if (!first && strstr (buffer, "dict begin")) continue;
  95.                 if (!first && strstr (buffer, "gsave")) continue;
  96.                 if (buffer[0] == '/' && first)
  97.                     printf("%s", buffer);
  98.                 else if (buffer[0] != '/')
  99.                     printf("%s", buffer);
  100.             }
  101.             first = FALSE;
  102.             printf ("%.3lf %.3lf scale\n", 1./scale, 1./scale);
  103.             printf ("%d %d translate showpage\n", x0, y0);
  104.         }
  105.     }
  106.     printf ("end grestore\n");
  107.     fclose(fp);
  108. }
  109.