home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / graphics-0.17 / graph / graph.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-27  |  19.0 KB  |  685 lines

  1. /* plot, a set of unix plot utilities.
  2.    Copyright (C) 1989 Free Software Foundation, Inc.
  3.  
  4.    Plot is distributed in the hope that it will be useful, but WITHOUT
  5.    ANY WARRANTY.  No author or distributor accepts responsibility to
  6.    anyone for the consequences of using it or for whether it serves any
  7.    particular purpose or works at all, unless he says so in writing.
  8.    Refer to the GNU General Public License for full details.
  9.  
  10.    Everyone is granted permission to copy, modify and redistribute plot,
  11.    but only under the conditions described in the GNU General Public
  12.    License.  A copy of this license is supposed to have been given to you
  13.    along with plot so you can know your rights and responsibilities.  It
  14.    should be in a file named COPYING.  Among other things, the copyright
  15.    notice and this notice must be preserved on all copies.  */
  16.  
  17. /* This file is the main routine for graph. */
  18.  
  19. #include "getopt.h"
  20. #include "sys-defines.h"
  21. #include "libplot.h"
  22. #include "extern.h"
  23. #include "../COPYING"
  24.  
  25. #define    ARG_NONE    0
  26. #define    ARG_REQUIRED    1
  27. #define    ARG_OPTIONAL    2
  28.  
  29. struct option long_options[] =
  30. {
  31.   {"auto-abscissa",    ARG_OPTIONAL,    NULL, 'a'},
  32.   {"bottom-move-margin", ARG_REQUIRED,    NULL, 'u'},
  33.   {"break-non-monotone", ARG_NONE,    NULL, 'M'},
  34.   {"break-on-labels",    ARG_NONE,    NULL, 'b'},
  35.   {"data-format",    ARG_REQUIRED,    NULL, 'd'},
  36.   {"dont-round-to-next-tick", ARG_NONE,    NULL, 'R'},
  37.   {"fontsize",        ARG_REQUIRED,    NULL, 'f'},
  38.   {"grid",        ARG_REQUIRED,    NULL, 'g'},
  39.   {"height-plot",    ARG_REQUIRED,    NULL, 'h'},
  40.   {"help",        ARG_NONE,    NULL, 'H'},
  41.   {"linestyle",        ARG_REQUIRED,    NULL, 'm'},
  42.   {"log-axis",        ARG_REQUIRED,    NULL, 'l'},
  43.   {"no-label",        ARG_REQUIRED,    NULL, 'N'},
  44.   {"point-label",    ARG_NONE,    NULL, 'c'},
  45.   {"right-margin-posn",    ARG_REQUIRED,    NULL, 'r'},
  46.   {"save-screen",    ARG_NONE,    NULL, 's'},
  47.   {"symbol",        ARG_OPTIONAL,    NULL, 'S'},
  48.   {"ticksize",        ARG_NONE,    NULL, 'T'},
  49.   {"toptitle",        ARG_REQUIRED,    NULL, 'L'},
  50.   {"transpose",        ARG_REQUIRED,    NULL, 't'},
  51.   {"version",        ARG_NONE,    NULL, 'v'},
  52.   {"width-plot",    ARG_REQUIRED,    NULL, 'w'},
  53.   {"xlimits",        ARG_OPTIONAL,    NULL, 'x'},
  54.   {"xtitle",        ARG_REQUIRED,    NULL, 'X'},
  55.   {"ylimits",        ARG_OPTIONAL,    NULL, 'y'},
  56.   {"ytitle",        ARG_REQUIRED,    NULL, 'Y'},
  57.   /* Long options with no equivalent short option alias */
  58.   {"debug",        ARG_NONE,    NULL, 'd' << 8},
  59.   {"fontname",        ARG_REQUIRED,    NULL, 'f' << 8},
  60.   {"margin",        ARG_REQUIRED,    NULL, 'm' << 8},
  61.   {"copying",        ARG_NONE,    NULL, 'c' << 8},
  62.   {"warranty",        ARG_NONE,    NULL, 'w' << 8},
  63.   {"high-byte-first",    ARG_NONE,    NULL, 'H' << 8},
  64.   {"low-byte-first",    ARG_NONE,    NULL, 'L' << 8},
  65.   {NULL, 0, 0, 0}
  66. };
  67.  
  68. const char *progname;        /* Program name */
  69.  
  70. VOIDPTR *
  71. do_malloc (length)
  72.      int length;
  73. {
  74.   VOIDPTR *p;
  75.   p = (VOIDPTR *) malloc (length);
  76.  
  77.   if (p <= (VOIDPTR *) NULL)
  78.     {
  79.       perror ("malloc failed");
  80.       exit (-1);
  81.     }
  82.   return p;
  83. }
  84.  
  85.  
  86. VOIDPTR *
  87. do_realloc (p, length)
  88.      VOIDPTR *p;
  89.      int length;
  90. {
  91.   p = (VOIDPTR *) realloc (p, length);
  92.  
  93.   if (p <= (VOIDPTR *) NULL)
  94.     {
  95.       perror ("realloc failed");
  96.       exit (-1);
  97.     }
  98.   return p;
  99. }
  100.  
  101.  
  102. void
  103. usage ()
  104. {
  105.   int i;
  106.   fprintf (stderr, "usage: %s", progname);
  107.   for (i=0; long_options[i].name; i++)
  108.     {
  109.       fprintf (stderr, " [+%s", long_options[i].name);
  110.       if (isprint (long_options[i].val))
  111.     fprintf (stderr, "|-%c", long_options[i].val);
  112.       if (long_options[i].has_arg == ARG_REQUIRED)
  113.     fprintf (stderr, " arg]");
  114.       else
  115.     fprintf (stderr, "]");
  116.     }
  117.   fprintf (stderr, "\n");
  118. }
  119.  
  120. void
  121. display_version ()
  122. {
  123.   (void) fprintf (stderr, "\
  124. graph version %s, Copyright (C) 1989 Free Software Foundation, Inc.\n\
  125. graph comes with ABSOLUTELY NO WARRANTY; type `graph +warranty' for\n\
  126. details.  This is free software, and you are welcome to redistribute it.\n\
  127. Type `graph +copying' to view the copying conditions.\n\n", VERS);
  128. }
  129.  
  130. int
  131. main (argc, argv)
  132.      int argc;
  133.      char *argv[];
  134. {
  135.   int i;
  136.   int option;
  137.   int opt_index;
  138.   int errcnt = 0;            /* errors encountered */
  139.   int show_version = 0;        /* remember to show version message */
  140.   int show_usage = 0;        /* remember whether to output usage message. */
  141.   int show_copying = 0;        /* remember to show copying conditions */
  142.   int opened = 0;        /* nonzero if we have opened named input file */
  143.   int debug = 0;        /* debug option flag */
  144.   int break_flag = 0;        /* non-zero means break lines after labels. */
  145.   int m_break_flag = 0;        /* non-zero means break when x decreases. */
  146.   int linemode_index = 0;    /* the line style for curves */
  147.   int log_axis = 0;        /* no log axes by default */
  148.   int omit_labels = 0;        /* label both axes by default */
  149.   int transpose_axes = 0;    /* nonzero means -x applies to y axis. */
  150.   data_type data_spec = ASCII_DATA; /* by default we read ascii data */
  151.   grid_type grid_spec = FULL_GRID; /* by default we plot a full grid */
  152.   int symbol_index = -1;    /* 0=none, 1=plus, 2=cross, 3=star */
  153.   double symbol_size = .01;    /* fractional size of the symbols */
  154.   double tick_size = .02;    /* fractional size of the tick marks */
  155.   int default_fontsize = -1;    /* size in printers points for text.
  156.                    -1 means use the default. */
  157.   point_struct *p;        /* an array of points */
  158.   int points_length;        /* the size of the points array */
  159.   int no_of_points = 0;        /* the number of points in the array */
  160.   int save_screen = 0;        /* save the screen == do not erase */
  161.   int auto_abscissa = 0;    /* flag to turn on automatic generation
  162.                    of abscissa */
  163.   int round_to_next_tick = 1;    /* flag to specify rounding the limits
  164.                    to the next tick mark */
  165.   double x_start = 0.;        /* start and increment of auto abscissa */
  166.   double delta_x = 1.;
  167.   double margin_below = .1;    /* fractional margin below the plot */
  168.   double margin_left = .1;    /* fractional margin left of the plot */
  169.   double plot_height = .8;    /* fractional height of the plot */
  170.   double plot_width = .8;    /* fractional width of the plot */
  171.   char *point_label = 0;    /* label for each point, 0 means no label. */
  172.   char *x_label = 0;        /* label for the x axis, 0 means no label.  */
  173.   char *y_label = 0;        /* label for the y axis, 0 means no label.  */
  174.   char *top_label = 0;        /* label above the plot, 0 means no label.  */
  175.   double margin = 0.;        /* fractional margin between data and box */
  176.  
  177.   /* flags to indicate which limits the user has specified */
  178.   int spec_min_x = 0, spec_min_y = 0, spec_max_x = 0, spec_max_y = 0;
  179.   int spec_spacing_x = 0, spec_spacing_y = 0;
  180.   /* user specified limits on the axes */
  181.   double user_min_x = 0., user_min_y = 0., user_max_x = 0., user_max_y = 0.;
  182.   double user_spacing_x = 0., user_spacing_y = 0.;
  183.   double min_x, min_y, max_x, max_y;
  184.  
  185.   progname = strrchr (argv[0], '/');
  186.   if (progname == NULL)
  187.     progname = argv[0];
  188.   else
  189.     progname++;
  190.  
  191.   points_length = 4096;
  192.   p = (point_struct *) do_malloc (points_length * sizeof (point_struct));
  193.  
  194.   errcnt = 0;
  195.  
  196.   while ((option = getopt_long (argc, argv, "-N:M::VbsvRL:T:c:X:Y:d:f:g:h:l:m:r:u:w:x::y::S::a::",
  197.                 long_options, &opt_index)) != EOF)
  198.     {
  199.       if (option == 0)
  200.     option = long_options[opt_index].val;
  201.  
  202.       switch (option)
  203.     {
  204.     case 'a':        /* Auto-abscissa    */
  205.       auto_abscissa = 1;
  206.       if (optind >= argc)
  207.         break;
  208.       if (sscanf (argv [optind], "%lf", &delta_x) <= 0)
  209.         break;
  210.       optind++;    /* tell getopt we recognized delta_x */
  211.       if (delta_x == 0.)
  212.         {
  213.           auto_abscissa = 0; /* reset abscissa option to the default */
  214.           delta_x = 1.;
  215.           x_start = 0.;
  216.         }
  217.       if (optind >= argc)
  218.         break;
  219.       if (sscanf (argv [optind], "%lf", &x_start) <= 0)
  220.         break;
  221.       optind++;    /* tell getopt we recognized x_start */
  222.       break;
  223.  
  224.     case 'b':        /* Break-on-labels    */
  225.       break_flag = 1;
  226.       break;
  227.     case 'M':        /* Break-non-monotone    */
  228.       m_break_flag = 1;    /* same line style for each curve */
  229.       if (optind >= argc)    /* optind is the index of the optional arg */
  230.         break;
  231.       if (strcmp ("m", argv[optind]) == 0)
  232.         {
  233.           m_break_flag = 2;    /* switch line style when breaking lines */
  234.           optind++;        /* tell getopt we recognized the optional arg */
  235.         }
  236.       break;
  237.     case 'f':        /* Fontsize        */
  238.       if (isdigit(*optarg))
  239.         default_fontsize = atoi (optarg);
  240.       else
  241.         {
  242.           fprintf (stderr,
  243.                "%s: Error: fontsize must be an integer.  Was `%s'.\n",
  244.                progname, optarg);
  245.           errcnt++;
  246.         }
  247.       break;
  248.     case 'g':        /* Grid-style        */
  249.       switch (*optarg)
  250.         {
  251.         case '0':
  252.           grid_spec = NO_GRID;
  253.           break;
  254.         case '1':
  255.           grid_spec = FULL_GRID;
  256.           break;
  257.         case '2':
  258.           grid_spec = TICKS_ALL_AROUND;
  259.           break;
  260.         case '3':
  261.           grid_spec = TICKS_LEFT_AND_BELOW;
  262.           break;
  263.         case '4':
  264.           grid_spec = AXES_AT_ORIGIN;
  265.           break;
  266.         default:
  267.           fprintf (stderr,
  268.                "%s:  Unrecognized grid option `%s' ignored.\n",
  269.                progname, argv[i]);
  270.           errcnt++;
  271.         }
  272.       break;
  273.     case 'd':        /* Data-format        */
  274.       switch (*optarg)
  275.         {
  276.         case 'a':
  277.         case 'A':
  278.           data_spec = ASCII_DATA;
  279.           break;
  280.         case 'i':
  281.         case 'I':
  282.           data_spec = INT_DATA;
  283.           break;
  284.         case 's':
  285.         case 'S':
  286.           data_spec = SHORT_INT_DATA;
  287.           break;
  288.         case 'f':
  289.         case 'F':
  290.           data_spec = FLOAT_DATA;
  291.           break;
  292.         case 'd':
  293.         case 'D':
  294.           data_spec = DOUBLE_DATA;
  295.           break;
  296.         default:
  297.           fprintf (stderr,
  298.                "%s:  Unrecognized data option `%s' ignored.\n",
  299.                progname, argv[i]);
  300.           errcnt++;
  301.         }
  302.       break;
  303.     case 'm':        /* Line-style        */
  304.       if (isdigit(*optarg) || (*optarg == '-'))
  305.         linemode_index = atoi (optarg);
  306.       else
  307.         {
  308.           fprintf (stderr,
  309.                "%s: Error: line style must be an integer. Was `%s'.\n",
  310.                progname, optarg);
  311.           errcnt++;
  312.         }
  313.       break;
  314.     case 'S':        /* Symbol        */
  315.       symbol_index = 1;    /* symbol # 1 is the default! */
  316.  
  317.       if (optind >= argc)
  318.         break;
  319.       if (sscanf (argv [optind], "%d", &symbol_index) <= 0)
  320.         break;
  321.       optind++;    /* tell getopt we recognized symbol_index */
  322.  
  323.       if (optind >= argc)
  324.         break;
  325.       if (sscanf (argv [optind], "%lf", &symbol_size) <= 0)
  326.         break;
  327.       spec_min_x++;
  328.       optind++;    /* tell getopt we recognized symbol_size */
  329.       break;
  330.  
  331.     case 'H':        /* Help            */
  332.       show_usage++;
  333.       show_version++;
  334.       break;
  335.     case 'v':        /* Version        */
  336.     case 'V':
  337.       show_version++;
  338.       break;
  339.     case 'T':        /* Ticksize        */
  340.       tick_size = atof (optarg);
  341.       break;
  342.     case 'L':        /* Top-title        */
  343.       top_label = do_malloc (strlen (optarg) + 1);
  344.       strcpy (top_label, optarg);
  345.       break;
  346.     case 'l':
  347.       switch (*optarg)
  348.         {
  349.         case 'x':
  350.         case 'X':
  351.           log_axis |= transpose_axes ? Y_AXIS : X_AXIS;
  352.           break;
  353.         case 'y':
  354.         case 'Y':
  355.           log_axis |= transpose_axes ? X_AXIS : Y_AXIS;
  356.           break;
  357.         default:
  358.           (void) fprintf (stderr, "%s:  ignoring unknown log axis type `%s'\n", progname, optarg);
  359.           break;
  360.         }
  361.       break;
  362.     case 'N':        /* omit labels on the specified axis */
  363.       switch (*optarg)
  364.         {
  365.         case 'x':
  366.         case 'X':
  367.           omit_labels |= transpose_axes ? Y_AXIS : X_AXIS;
  368.           break;
  369.         case 'y':
  370.         case 'Y':
  371.           omit_labels |= transpose_axes ? X_AXIS : Y_AXIS;
  372.           break;
  373.         default:
  374.           (void) fprintf (stderr, "%s:  ignoring unrecognized axis specification `%s'\n", progname, optarg);
  375.           break;
  376.         }
  377.       switch (optarg[1])
  378.         {
  379.         case '\0':
  380.           break;
  381.         case 'x':
  382.         case 'X':
  383.           log_axis |= X_AXIS;
  384.           break;
  385.         case 'y':
  386.         case 'Y':
  387.           log_axis |= Y_AXIS;
  388.           break;
  389.         default:
  390.           (void) fprintf (stderr, "%s:  ignoring unknown log axis type `%s'\n", progname, optarg);
  391.           break;
  392.         }
  393.       break;
  394.     case 'c':        /* point label */
  395.       point_label = do_malloc (strlen (optarg) + 1);
  396.       strcpy (point_label, optarg);
  397.       break;
  398.     case 'X':        /* Xtitle        */
  399.       if (transpose_axes) goto Ytitle;
  400.     Xtitle:
  401.       x_label = do_malloc (strlen (optarg) + 1);
  402.       strcpy (x_label, optarg);
  403.       break;
  404.     case 'Y':        /* Ytitle        */
  405.       if (transpose_axes) goto Xtitle;
  406.     Ytitle:
  407.       y_label = do_malloc (strlen (optarg) + 1);
  408.       strcpy (y_label, optarg);
  409.       break;
  410.     case 'u':        /* bottom-margin-posn    */
  411.       margin_below = atof (optarg);
  412.       break;
  413.     case 'r':        /* right-margin-posn    */
  414.       margin_left = atof (optarg);
  415.       break;
  416.     case 'R':        /* round limits to the next tick mark */
  417.       round_to_next_tick = 0;
  418.       break;
  419.     case 'w':        /* width-plot        */
  420.       plot_width = atof (optarg);
  421.       break;
  422.     case 'h':        /* height-plot        */
  423.       plot_height = atof (optarg);
  424.       break;
  425.     case 'x':        /* xlimits        */
  426.       if (transpose_axes) goto ylimits;
  427.     xlimits:
  428.       if (optind >= argc)    /* optind is the index of the optional arg */
  429.         break;
  430.       if (strcmp ("l", argv[optind]) == 0)
  431.         {
  432.           log_axis |= X_AXIS;
  433.           optind++;        /* tell getopt we recognized log axis arg */
  434.         }
  435.       if (optind >= argc)
  436.         break;
  437.                 /* parse minimum x argument */
  438.       if (sscanf (argv [optind], "%lf", &user_min_x) <= 0)
  439.         break;
  440.       spec_min_x++;
  441.       optind++;    /* tell getopt we recognized user_min_x */
  442.       if (optind >= argc)
  443.         break;
  444.                 /* parse maximum x argument */
  445.       if (sscanf (argv [optind], "%lf", &user_max_x) <= 0)
  446.         break;
  447.       spec_max_x++;
  448.       optind++;    /* tell getopt we recognized user_max_x */
  449.       if (optind >= argc)
  450.         break;
  451.                 /* parse x tick spacing argument */
  452.       if (sscanf (argv [optind], "%lf", &user_spacing_x) <= 0)
  453.         break;
  454.       spec_spacing_x++;
  455.       optind++;    /* tell getopt we recognized user_spacing_x */
  456.       break;
  457.  
  458.     case 'y':
  459.       if (transpose_axes) goto xlimits;
  460.     ylimits:
  461.       if (optind >= argc)    /* optind is the index of the optional arg */
  462.         break;
  463.       if (strcmp ("l", argv[optind]) == 0)
  464.         {
  465.           log_axis |= Y_AXIS;
  466.           optind++;        /* tell getopt we recognized log axis arg */
  467.         }
  468.       if (optind >= argc)
  469.         break;
  470.                 /* parse minimum y argument */
  471.       if (sscanf (argv [optind], "%lf", &user_min_y) <= 0)
  472.         break;
  473.       spec_min_y++;
  474.       optind++;    /* tell getopt we recognized user_min_y */
  475.       if (optind >= argc)
  476.         break;
  477.                 /* parse maximum y argument */
  478.       if (sscanf (argv [optind], "%lf", &user_max_y) <= 0)
  479.         break;
  480.       spec_max_y++;
  481.       optind++;    /* tell getopt we recognized user_max_y */
  482.       if (optind >= argc)
  483.         break;
  484.                 /* parse y tick spacing argument */
  485.       if (sscanf (argv [optind], "%lf", &user_spacing_y) <= 0)
  486.         break;
  487.       spec_spacing_y++;
  488.       optind++;    /* tell getopt we recognized user_spacing_y */
  489.       break;
  490.  
  491.     case 's':
  492.       save_screen = 1;
  493.       break;
  494.     case 't':
  495.       transpose_axes = 1;
  496.       break;
  497.       /*---------------- Long options below here ----------------*/
  498.     case 'd' << 8:        /* debug */
  499.       debug = 1;
  500.       break;
  501.     case 'f' << 8:        /* fontname */
  502.       (void) fontname (optarg);
  503.       break;
  504.     case 'm' << 8:        /* margin */
  505.       margin = atof (optarg);
  506.       break;
  507.     case 'w' << 8:        /* warranty */
  508.     case 'c' << 8:        /* copying */
  509.       show_copying = 1;
  510.       break;
  511.     case 'H' << 8:        /* output byte order */
  512.       output_high_byte_first = 1;
  513.       break;
  514.     case 'L' << 8:        /* output byte order */
  515.       output_high_byte_first = -1;
  516.       break;
  517.     default:
  518.       errcnt++;
  519.       break;
  520.     case 1:
  521.       {
  522.         FILE *data_file;
  523.  
  524.         if (strcmp (optarg, "-") == 0)
  525.           data_file = stdin;
  526.         else
  527.           {
  528.         data_file = fopen (optarg, "r");
  529.         if (data_file == NULL)
  530.           {
  531.             (void) fprintf (stderr, "%s:  ignoring nonexistent or inaccessible file `%s'\n",
  532.                     progname, optarg);
  533.             continue;
  534.           }
  535.           }
  536.         opened++;
  537.         read_file (data_file, &p, &points_length, &no_of_points,
  538.                auto_abscissa, x_start, delta_x, data_spec,
  539.                symbol_index, transpose_axes, point_label,
  540.                linemode_index, m_break_flag);
  541.  
  542.         if (data_file != stdin) /* Don't close stdin */
  543.           fclose (data_file);
  544.       }
  545.       break;
  546.     }            /* endswitch */
  547.     }                /* endwhile */
  548.  
  549.  
  550.   if (show_version)
  551.     display_version ();
  552.  
  553.   if ((show_usage > 0) || (errcnt > 0))
  554.     usage ();
  555.  
  556.   if (show_copying)
  557.     {
  558.       int k;
  559.       for (k = 0; *copy_notice[k] != '\0'; k++)
  560.     fputs (copy_notice[k], stderr);
  561.     }
  562.  
  563.   if (errcnt > 0)
  564.     exit (1);
  565.  
  566.   if (show_copying || show_usage)
  567.     exit (0);
  568.  
  569.   /* Let's read in the named data files on the command line, if any.
  570.      Read stdin if no files are given */
  571.  
  572.   if (optind < argc)
  573.     {
  574.       for (; optind < argc; optind++)
  575.     {
  576.       FILE *data_file;
  577.  
  578.       if (strcmp (argv[optind], "-") == 0)
  579.         data_file = stdin;
  580.       else
  581.         {
  582.           data_file = fopen (argv[optind], "r");
  583.           if (data_file == NULL)
  584.         {
  585.           (void) fprintf (stderr, "%s:  ignoring nonexistent or inaccessible file `%s'\n",
  586.                   progname, argv[optind]);
  587.           continue;
  588.         }
  589.         }
  590.       opened++;
  591.       read_file (data_file, &p, &points_length, &no_of_points,
  592.              auto_abscissa, x_start, delta_x, data_spec, symbol_index,
  593.              transpose_axes, point_label, linemode_index, m_break_flag);
  594.  
  595.       if (data_file != stdin) /* Don't close stdin */
  596.         fclose (data_file);
  597.     }
  598.     } /* endfor */
  599.  
  600.   if (!opened)
  601.     /* Read stdin if no files were named on the command line. */
  602.     read_file (stdin, &p, &points_length, &no_of_points, auto_abscissa,
  603.            x_start, delta_x, data_spec, symbol_index, transpose_axes,
  604.            point_label, linemode_index, m_break_flag);
  605.   
  606.   /* if the user doesn't specify all the limits, we compute them. */
  607.   if (!spec_min_x || !spec_min_y)
  608.     array_min (p, no_of_points, &min_x, &min_y);
  609.   if (!spec_max_x || !spec_max_y)
  610.     array_max (p, no_of_points, &max_x, &max_y);
  611.   if (min_x == max_x)
  612.     {
  613.       min_x -= 1.;
  614.       max_x += 1.;
  615.     }
  616.   if (min_y == max_y)
  617.     {
  618.       min_y -= 1.;
  619.       max_y += 1.;
  620.     }
  621.  
  622.   if (debug)
  623.     {
  624.       int j;
  625.  
  626.       fprintf (stderr, "%d elements read.\n", no_of_points);
  627.       for (j = 0; j < no_of_points; j++)
  628.     {
  629.       fprintf (stderr, "%g %g", p[j].x, p[j].y);
  630.       if (p[j].string)
  631.         fprintf (stderr, " \"%s\"", p[j].string);
  632.       if (p[j].symbol >= 0)
  633.         fprintf (stderr, " symbol %d", p[j].symbol);
  634.       if (p[j].linemode == 0)
  635.         putc ('\n', stderr);
  636.       else
  637.         fprintf (stderr, " linemode %d\n", p[j].linemode);
  638.     }
  639.  
  640.       fprintf (stderr, "x min: %g max: %g\n", min_x, max_x);
  641.       fprintf (stderr, "y min: %g max: %g\n", min_y, max_y);
  642.       if (no_of_points == 0)
  643.     fprintf (stderr, "Warning: no data read from input.\n");
  644.       fflush (stderr);
  645.     }
  646.   if (!save_screen)
  647.     erase ();
  648.  
  649.   if (   ((margin_below<=0.) && !x_label)
  650.       || ((margin_left<=0.) && !y_label)
  651.       || ((margin_below+plot_height>=1.) && !top_label))
  652.     fprintf (stderr, "Warning: one of the margins is too narrow for a label.\n");
  653.  
  654.   /* If abscissal or ordinate values increase from left to right or
  655.      bottom ot top respectively, spacing is positive, otherwise negative.
  656.      Abort if the user specifies an inconsistent spacing. */
  657.   if ( spec_spacing_x
  658.       && ((user_max_x - user_min_x) * user_spacing_x <= 0.))
  659.     {
  660.       fprintf (stderr, "Error: x spacing must be the same sign as xmax-xmin.\n");
  661.       exit (-1);
  662.     }
  663.   if ( spec_spacing_y
  664.       && ((user_max_y - user_min_y) * user_spacing_y <= 0.))
  665.     {
  666.       fprintf (stderr, "Error: y spacing must be the same sign as ymax-ymin.\n");
  667.       exit (-1);
  668.     }
  669.  
  670.  
  671.   write_plot (stdout, p, no_of_points,
  672.           spec_min_x ? user_min_x : min_x,
  673.           spec_max_x ? user_max_x : max_x,
  674.           spec_spacing_x ? user_spacing_x : 0.,
  675.           spec_min_y ? user_min_y : min_y,
  676.           spec_max_y ? user_max_y : max_y,
  677.           spec_spacing_y ? user_spacing_y : 0.,
  678.           plot_width, plot_height, margin_below, margin_left,
  679.           symbol_size, tick_size, grid_spec,
  680.           x_label, y_label, top_label, margin, log_axis,
  681.           break_flag, round_to_next_tick, default_fontsize,
  682.           omit_labels);
  683.   return 0;
  684. }
  685.