home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 334_02 / plot.h < prev    next >
Text File  |  1991-02-05  |  9KB  |  371 lines

  1. /* GNUPLOT - plot.h */
  2. /*
  3.  * Copyright (C) 1986, 1987, 1990   Thomas Williams, Colin Kelley
  4.  *
  5.  * Permission to use, copy, and distribute this software and its
  6.  * documentation for any purpose with or without fee is hereby granted, 
  7.  * provided that the above copyright notice appear in all copies and 
  8.  * that both that copyright notice and this permission notice appear 
  9.  * in supporting documentation.
  10.  *
  11.  * Permission to modify the software is granted, but not the right to
  12.  * distribute the modified code.  Modifications are to be distributed 
  13.  * as patches to released version.
  14.  *  
  15.  * This software  is provided "as is" without express or implied warranty.
  16.  * 
  17.  *
  18.  * AUTHORS
  19.  * 
  20.  *   Original Software:
  21.  *     Thomas Williams,  Colin Kelley.
  22.  * 
  23.  *   Gnuplot 2.0 additions:
  24.  *       Russell Lang, Dave Kotz, John Campbell.
  25.  * 
  26.  * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
  27.  * 
  28.  */
  29.  
  30.  
  31. #define PROGRAM "G N U P L O T"
  32. #define PROMPT "gnuplot> "
  33. #define SHELL "/bin/sh"        /* used if SHELL env variable not set */
  34.  
  35. #define SAMPLES 160        /* default number of samples for a plot */
  36. #define ZERO    1e-8        /* default for 'zero' set option */
  37.  
  38. #ifndef TERM
  39. /* default terminal is "unknown"; but see init_terminal */
  40. #define TERM "unknown"
  41. #endif
  42.  
  43. #define TRUE 1
  44. #define FALSE 0
  45.  
  46.  
  47. #define Pi 3.141592653589793
  48.  
  49.  
  50. #define MAX_POINTS 1
  51. #define MAX_LINE_LEN 1024    /* maximum number of chars allowed on line */
  52. #define MAX_TOKENS 200
  53. #define MAX_ID_LEN 50        /* max length of an identifier */
  54.  
  55.  
  56. #define MAX_AT_LEN 150        /* max number of entries in action table */
  57. #define STACK_DEPTH 100
  58. #define NO_CARET (-1)
  59.  
  60.  
  61.  
  62.  
  63. #ifdef vms
  64. #define OS "VMS "
  65. #endif
  66.  
  67.  
  68. #ifdef unix
  69. #define OS "unix "
  70. #endif
  71.  
  72.  
  73. #ifdef MSDOS
  74. #define OS "MS-DOS "
  75. #endif
  76.  
  77.  
  78. #ifndef OS
  79. #define OS ""
  80. #endif
  81.  
  82.  
  83. /*
  84.  * Note about VERYLARGE:  This is the upper bound double (or float, if PC)
  85.  * numbers. This flag indicates very large numbers. It doesn't have to 
  86.  * be the absolutely biggest number on the machine.  
  87.  * If your machine doesn't have HUGE, or float.h,
  88.  * define VERYLARGE here. 
  89.  *
  90.  * example:
  91. #define VERYLARGE 1e38
  92.  */
  93.  
  94. #ifdef PC
  95. #include <float.h>
  96. #define VERYLARGE FLT_MAX
  97. #else
  98. #ifdef vms
  99. #include <float.h>
  100. #define VERYLARGE DBL_MAX
  101. #else
  102. #define VERYLARGE HUGE
  103. #endif
  104. #endif
  105.  
  106.  
  107. #define END_OF_COMMAND (c_token >= num_tokens || equals(c_token,";"))
  108.  
  109.  
  110.  
  111.  
  112. #ifdef vms
  113.  
  114.  
  115. #define is_comment(c) ((c) == '#' || (c) == '!')
  116. #define is_system(c) ((c) == '$')
  117.  
  118.  
  119. #else /* vms */
  120.  
  121.  
  122. #define is_comment(c) ((c) == '#')
  123. #define is_system(c) ((c) == '!')
  124.  
  125.  
  126. #endif /* vms */
  127.  
  128.  
  129. /*
  130.  * If you're memcpy() has another name, define it below as bcopy() is.
  131.  * If you don't have a memcpy():
  132. #define NOCOPY
  133.  */
  134.  
  135.  
  136. #ifdef BCOPY
  137. #define memcpy(dest,src,len) bcopy(src,dest,len)
  138. #endif /* BCOPY */
  139.  
  140.  
  141. #ifdef vms
  142. #define memcpy(dest,src,len) lib$movc3(&len,src,dest)
  143. #endif /* vms */
  144.  
  145.  
  146. /*
  147.  * If you don't have BZERO, define it below.
  148.  */
  149. #ifndef BZERO
  150. #define bzero(dest,len)  (void)(memset(dest, (char)NULL, len))
  151. #endif /* BZERO */
  152.  
  153.  
  154. #define top_of_stack stack[s_p]
  155.  
  156.  
  157. typedef int BOOLEAN;
  158.  
  159. #ifdef __ZTC__
  160. typedef int (*FUNC_PTR)(...);
  161. #else
  162. typedef int (*FUNC_PTR)();
  163. #endif
  164.  
  165.  
  166. enum operators {
  167.     PUSH, PUSHC, PUSHD, CALL, LNOT, BNOT, UMINUS, LOR, LAND, BOR, XOR,
  168.     BAND, EQ, NE, GT, LT, GE, LE, PLUS, MINUS, MULT, DIV, MOD, POWER,
  169.     FACTORIAL, BOOL, JUMP, JUMPZ, JUMPNZ, JTERN, SF_START
  170. };
  171.  
  172.  
  173. #define is_jump(operator) ((operator) >=(int)JUMP && (operator) <(int)SF_START)
  174.  
  175.  
  176. enum DATA_TYPES {
  177.     INT, CMPLX
  178. };
  179.  
  180.  
  181. enum PLOT_TYPE {
  182.     FUNC, DATA
  183. };
  184.  
  185.  
  186. enum PLOT_STYLE {
  187.     LINES, POINTS, IMPULSES, LINESPOINTS, DOTS
  188. };
  189.  
  190. enum JUSTIFY {
  191.     LEFT, CENTRE, RIGHT
  192. };
  193.  
  194. struct cmplx {
  195.     double real, imag;
  196. };
  197.  
  198.  
  199. struct value {
  200.     enum DATA_TYPES type;
  201.     union {
  202.         int int_val;
  203.         struct cmplx cmplx_val;
  204.     } v;
  205. };
  206.  
  207.  
  208. struct lexical_unit {    /* produced by scanner */
  209.     BOOLEAN is_token;    /* true if token, false if a value */ 
  210.     struct value l_val;
  211.     int start_index;    /* index of first char in token */
  212.     int length;            /* length of token in chars */
  213. };
  214.  
  215.  
  216. struct ft_entry {        /* standard/internal function table entry */
  217.     char *f_name;        /* pointer to name of this function */
  218.     FUNC_PTR func;        /* address of function to call */
  219. };
  220.  
  221.  
  222. struct udft_entry {                /* user-defined function table entry */
  223.     struct udft_entry *next_udf; /* pointer to next udf in linked list */
  224.     char udf_name[MAX_ID_LEN+1]; /* name of this function entry */
  225.     struct at_type *at;            /* pointer to action table to execute */
  226.     char *definition;             /* definition of function as typed */
  227.     struct value dummy_value;    /* current value of dummy variable */
  228. };
  229.  
  230.  
  231. struct udvt_entry {            /* user-defined value table entry */
  232.     struct udvt_entry *next_udv; /* pointer to next value in linked list */
  233.     char udv_name[MAX_ID_LEN+1]; /* name of this value entry */
  234.     BOOLEAN udv_undef;        /* true if not defined yet */
  235.     struct value udv_value;    /* value it has */
  236. };
  237.  
  238.  
  239. union argument {            /* p-code argument */
  240.     int j_arg;                /* offset for jump */
  241.     struct value v_arg;        /* constant value */
  242.     struct udvt_entry *udv_arg;    /* pointer to dummy variable */
  243.     struct udft_entry *udf_arg; /* pointer to udf to execute */
  244. };
  245.  
  246.  
  247. struct at_entry {            /* action table entry */
  248.     enum operators index;    /* index of p-code function */
  249.     union argument arg;
  250. };
  251.  
  252.  
  253. struct at_type {
  254.     int a_count;                /* count of entries in .actions[] */
  255.     struct at_entry actions[MAX_AT_LEN];
  256.         /* will usually be less than MAX_AT_LEN is malloc()'d copy */
  257. };
  258.  
  259.  
  260. /* Defines the type of a coordinate */
  261. /* INRANGE and OUTRANGE points have an x,y point associated with them */
  262. enum coord_type {
  263.     INRANGE,                /* inside plot boundary */
  264.     OUTRANGE,                /* outside plot boundary, but defined */
  265.     UNDEFINED                /* not defined at all */
  266. };
  267.  
  268. struct coordinate {
  269.     enum coord_type type;    /* see above */
  270. #ifdef PC
  271.     float x, y;            /* memory is tight on PCs! */
  272. #else
  273.     double x, y;
  274. #endif /* PC */
  275. };
  276.  
  277.  
  278. struct curve_points {
  279.     struct curve_points *next_cp;    /* pointer to next plot in linked list */
  280.     enum PLOT_TYPE plot_type;
  281.     enum PLOT_STYLE plot_style;
  282.     char *title;
  283.     int line_type;
  284.     int point_type;
  285.     int p_count;                    /* count of points in .points[] */
  286.     struct coordinate points[MAX_POINTS];
  287.         /* will usually be less in malloc()'d copy */
  288. };
  289.  
  290.  
  291. struct termentry {
  292.     char *name;
  293.     char *description;
  294.     unsigned int xmax,ymax,v_char,h_char,v_tic,h_tic;
  295.     FUNC_PTR init,reset,text,scale,graphics,move,vector,linetype,
  296.         put_text,text_angle,justify_text,point,arrow;
  297. };
  298.  
  299.  
  300. struct text_label {
  301.     struct text_label *next;    /* pointer to next label in linked list */
  302.     int tag;                /* identifies the label */
  303.     double x,y;
  304.     enum JUSTIFY pos;
  305.     char text[MAX_LINE_LEN+1];
  306. };
  307.  
  308. struct arrow_def {
  309.     struct arrow_def *next;    /* pointer to next arrow in linked list */
  310.     int tag;                /* identifies the arrow */
  311.     double sx,sy;            /* start position */
  312.     double ex,ey;            /* end position */
  313. };
  314.  
  315. /* Tic-mark labelling definition; see set xtics */
  316. struct ticdef {
  317.     int type;                /* one of three values below */
  318. #define TIC_COMPUTED 1        /* default; gnuplot figures them */
  319. #define TIC_SERIES 2        /* user-defined series */
  320. #define TIC_USER 3            /* user-defined points */
  321.     union {
  322.        struct {            /* for TIC_SERIES */
  323.           double start, incr;
  324.           double end;        /* ymax, if VERYLARGE */
  325.        } series;
  326.        struct ticmark *user;    /* for TIC_USER */
  327.     } def;
  328. };
  329.  
  330. /* Defines one ticmark for TIC_USER style.
  331.  * If label==NULL, the value is printed with the usual format string.
  332.  * else, it is used as the format string (note that it may be a constant
  333.  * string, like "high" or "low").
  334.  */
  335. struct ticmark {
  336.     double position;        /* where on axis is this */
  337.     char *label;            /* optional (format) string label */
  338.     struct ticmark *next;    /* linked list */
  339. };
  340.  
  341. /*
  342.  * SS$_NORMAL is "normal completion", STS$M_INHIB_MSG supresses
  343.  
  344.  * printing a status message.
  345.  * SS$_ABORT is the general abort status code.
  346.  from:    Martin Minow
  347.     decvax!minow
  348.  */
  349. #ifdef    vms
  350. #include        <ssdef.h>
  351. #include        <stsdef.h>
  352. #define    IO_SUCCESS    (SS$_NORMAL | STS$M_INHIB_MSG)
  353. #define    IO_ERROR    SS$_ABORT
  354. #endif /* vms */
  355.  
  356.  
  357. #ifndef    IO_SUCCESS    /* DECUS or VMS C will have defined these already */
  358. #define    IO_SUCCESS    0
  359. #endif
  360. #ifndef    IO_ERROR
  361. #define    IO_ERROR    1
  362. #endif
  363.  
  364. /* Some key global variables */
  365. extern BOOLEAN screen_ok;
  366. extern BOOLEAN term_init;
  367. extern BOOLEAN undefined;
  368. extern struct termentry term_tbl[];
  369.  
  370. extern char *alloc();
  371.