home *** CD-ROM | disk | FTP | other *** search
/ CICA 1995 May / cica_0595_4.zip / cica_0595_4 / UTIL / GPT34SRC / PLOT.H < prev    next >
C/C++ Source or Header  |  1993-06-04  |  16KB  |  606 lines

  1. /*
  2.  * $Id: plot.h%v 3.38.2.130 1993/05/26 01:02:10 woo Exp woo $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - plot.h */
  7. /*
  8.  * Copyright (C) 1986 - 1993   Thomas Williams, Colin Kelley
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted, 
  12.  * provided that the above copyright notice appear in all copies and 
  13.  * that both that copyright notice and this permission notice appear 
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software is provided "as is" without express or implied warranty.
  21.  * 
  22.  *
  23.  * AUTHORS
  24.  * 
  25.  *   Original Software:
  26.  *     Thomas Williams,  Colin Kelley.
  27.  * 
  28.  *   Gnuplot 2.0 additions:
  29.  *       Russell Lang, Dave Kotz, John Campbell.
  30.  *
  31.  *   Gnuplot 3.0 additions:
  32.  *       Gershon Elber and many others.
  33.  * 
  34.  * There is a mailing list for gnuplot users. Note, however, that the
  35.  * newsgroup 
  36.  *    comp.graphics.gnuplot 
  37.  * is identical to the mailing list (they
  38.  * both carry the same set of messages). We prefer that you read the
  39.  * messages through that newsgroup, to subscribing to the mailing list.
  40.  * (If you can read that newsgroup, and are already on the mailing list,
  41.  * please send a message info-gnuplot-request@dartmouth.edu, asking to be
  42.  * removed from the mailing list.)
  43.  *
  44.  * The address for mailing to list members is
  45.  *       info-gnuplot@dartmouth.edu
  46.  * and for mailing administrative requests is 
  47.  *       info-gnuplot-request@dartmouth.edu
  48.  * The mailing list for bug reports is 
  49.  *       bug-gnuplot@dartmouth.edu
  50.  * The list of those interested in beta-test versions is
  51.  *       info-gnuplot-beta@dartmouth.edu
  52.  */
  53.  
  54. #define PROGRAM "G N U P L O T"
  55. #define PROMPT "gnuplot> "
  56. #if defined(AMIGA_SC_6_1) || defined(AMIGA_AC_5)
  57. #define SHELL "NewShell"
  58. #else /* AMIGA */
  59. #ifdef ATARI
  60. #define SHELL "gulam.prg"
  61. #else /* ATARI */
  62. #ifdef OS2
  63. #define SHELL "c:\\cmd.exe"
  64. #else /*OS2 */
  65. #define SHELL "/bin/sh"        /* used if SHELL env variable not set */
  66. #endif /*OS2 */
  67. #endif /* ATARI */
  68. #endif /* AMIGA  */
  69.  
  70. #if defined(__unix__) && !defined(unix)
  71. #define unix
  72. #endif
  73.  
  74. #define SAMPLES 100        /* default number of samples for a plot */
  75. #define ISO_SAMPLES 10        /* default number of isolines per splot */
  76. #define ZERO    1e-8        /* default for 'zero' set option */
  77.  
  78. #ifndef TERM
  79. /* default terminal is "unknown"; but see init_terminal */
  80. #define TERM "unknown"
  81. #endif
  82.  
  83. #define TRUE 1
  84. #define FALSE 0
  85.  
  86.  
  87. #define Pi 3.141592653589793
  88. #define DEG2RAD (Pi / 180.0)
  89.  
  90.  
  91. #define MIN_CRV_POINTS 100        /* minimum size of points[] in curve_points */
  92. #define MIN_SRF_POINTS 1000        /* minimum size of points[] in surface_points */
  93.  
  94. #define MAX_LINE_LEN 1024    /* maximum number of chars allowed on line */
  95. #define MAX_TOKENS 400
  96. #define MAX_ID_LEN 50        /* max length of an identifier */
  97.  
  98.  
  99. #define MAX_AT_LEN 150        /* max number of entries in action table */
  100. #define STACK_DEPTH 100
  101. #define NO_CARET (-1)
  102.  
  103. #ifdef MSDOS
  104. #define MAX_NUM_VAR    3    /* Ploting projection of func. of max. five vars. */
  105. #else
  106. #define MAX_NUM_VAR    5    /* Ploting projection of func. of max. five vars. */
  107. #endif
  108.  
  109. #define MAP3D_CARTESIAN        0    /* 3D Data mapping. */
  110. #define MAP3D_SPHERICAL        1
  111. #define MAP3D_CYLINDRICAL    2
  112.  
  113. #define CONTOUR_NONE    0    /* Where to place contour maps if at all. */
  114. #define CONTOUR_BASE    1
  115. #define CONTOUR_SRF    2
  116. #define CONTOUR_BOTH    3
  117.  
  118. #define CONTOUR_KIND_LINEAR    0 /* See contour.h in contours subdirectory. */
  119. #define CONTOUR_KIND_CUBIC_SPL    1
  120. #define CONTOUR_KIND_BSPLINE    2
  121.  
  122. #define LEVELS_AUTO            0        /* How contour levels are set */
  123. #define LEVELS_INCREMENTAL    1        /* user specified start & incremnet */
  124. #define LEVELS_DISCRETE        2        /* user specified discrete levels */
  125. #define MAX_DISCRETE_LEVELS   30
  126.  
  127. #define ANGLES_RADIANS    0
  128. #define ANGLES_DEGREES    1
  129.  
  130.  
  131. #if defined(AMIGA_SC_6_1) || defined(AMIGA_AC_5)
  132. #define OS "Amiga "
  133. #endif
  134.  
  135. #ifdef OS2
  136. #ifdef unix
  137. #undef unix    /* GCC might declare this */
  138. #define OS "OS/2"
  139. #endif
  140. #endif  /* OS2 */
  141.  
  142. #ifdef vms
  143. #define OS "VMS "
  144. #endif
  145.  
  146.  
  147. #ifdef unix
  148. #define OS "unix "
  149. #endif
  150.  
  151.  
  152. #ifdef _WINDOWS
  153. #define _Windows
  154. #endif
  155.  
  156. #ifdef DOS386
  157. #define OS "DOS 386 "
  158. #endif
  159. #ifdef _Windows
  160. #define OS "MS-Windows "
  161. #else
  162. #ifdef MSDOS
  163. #ifdef unix    /* __EMX__ and DJGPP may set this */
  164. #undef OS
  165. #undef unix
  166. #endif
  167. #define OS "MS-DOS "
  168. #endif
  169. #endif
  170.  
  171.  
  172. #ifdef ATARI
  173. #define OS "TOS "
  174. #endif
  175.  
  176. #ifndef OS
  177. #define OS ""
  178. #endif
  179.  
  180.  
  181. /* To access curves larger than 64k, MSDOS needs to use huge pointers */
  182. #if (defined(__TURBOC__) && defined(MSDOS)) || (defined(_Windows) && !defined(WIN32))
  183. #define GPHUGE huge
  184. #define GPFAR far
  185. #else
  186. #define GPHUGE
  187. #define GPFAR
  188. #endif
  189.  
  190.  
  191. /*
  192.  * Note about VERYLARGE:  This is the upper bound double (or float, if PC)
  193.  * numbers. This flag indicates very large numbers. It doesn't have to 
  194.  * be the absolutely biggest number on the machine.  
  195.  * If your machine doesn't have HUGE, or float.h,
  196.  * define VERYLARGE here. 
  197.  *
  198.  * This is a mess.  If someone figures out how to clean this up, please
  199.  *    diff -c  of your fixes
  200.  *
  201.  *
  202.  * example:
  203. #define VERYLARGE 1e37
  204.  */
  205.  
  206. #ifdef ATARI
  207. #include <stdlib.h>        /* Prototyping used !! 'size_t' */
  208. #include <stdio.h>
  209. #include <string.h>
  210. #include <math.h>
  211. #define VERYLARGE    HUGE_VAL
  212. #else  /* not ATARI */
  213. #if defined(MSDOS) || defined(_Windows)
  214. #include <float.h>
  215. #define VERYLARGE (FLT_MAX/2 -1)
  216. #else  /* not MSDOS || _Windows */
  217. #if defined( vms ) || defined( _CRAY ) || defined( NEXT ) || defined(__osf__) || defined( OS2 ) || defined(__EMX__) || defined( DOS386) || defined(KSR)
  218. #include <float.h>
  219. #if defined ( NEXT )  /* bug in NeXT OS 2.0 */
  220. #if defined ( DBL_MAX)
  221. #undef DBL_MAX
  222. #endif
  223. #define DBL_MAX 1.7976931348623157e+308 
  224. #undef HUGE
  225. #define HUGE    DBL_MAX
  226. #undef HUGE_VAL
  227. #define HUGE_VAL DBL_MAX
  228. #endif /* not NEXT but CRAY, VMS or OSF */
  229. #define VERYLARGE (DBL_MAX/2 -1)
  230. #else  /* not vms, CRAY, NEXT, OS/2 or OSF */
  231. #ifdef AMIGA_AC_5
  232. #include <math.h>
  233. #define VERYLARGE (HUGE/2 -1)
  234. #else /* not AMIGA_AC_5 */
  235. #ifdef AMIGA_SC_6_1
  236. #include <float.h>
  237. #ifndef HUGE
  238. #define HUGE DBL_MAX
  239. #endif
  240. #define VERYLARGE (HUGE/2 -1)
  241. #else /* !AMIGA_SC_6_1 */
  242. /* #include <float.h> */
  243. #ifdef ISC22
  244. #include <float.h>
  245. #ifndef HUGE
  246. #define HUGE DBL_MAX
  247. #endif
  248. #endif /* ISC22 */
  249. /* This is the default */
  250. #ifndef HUGE
  251. #define HUGE DBL_MAX
  252. #endif
  253. #define VERYLARGE (HUGE/2 -1)
  254. /* default */
  255. #endif /* !AMIGA_SC_6_1 */
  256. #endif /* !AMIGA_AC_5 */
  257. #endif /* !VMS !CRAY !NEXT */
  258. #endif /* !MSDOS || !_Windows */
  259. #endif /* !ATARI */
  260.  
  261. #ifdef AMIGA_SC_6_1
  262. /* Get function prototypes */
  263. #include <stdio.h>
  264. #include <stdlib.h>
  265. #include <string.h>
  266. #include <math.h>
  267. #endif /* AMIGA_SC_6_1 */
  268.  
  269. #define END_OF_COMMAND (c_token >= num_tokens || equals(c_token,";"))
  270.  
  271. #ifdef vms
  272.  
  273.  
  274. #define is_comment(c) ((c) == '#' || (c) == '!')
  275. #define is_system(c) ((c) == '$')
  276.  
  277.  
  278. #else /* vms */
  279.  
  280. #define is_comment(c) ((c) == '#')
  281. #define is_system(c) ((c) == '!')
  282.  
  283. #endif /* vms */
  284.  
  285. /* If you don't have vfork, then undefine this */
  286. #if defined(NOVFORK) || defined(MSDOS) || defined( OS2 ) || defined(_Windows) || defined(DOS386)
  287. # undef VFORK
  288. #else
  289. # ifdef unix
  290. #  define VFORK
  291. # endif
  292. #endif
  293.  
  294. /* 
  295.  * memcpy() comes by many names. The default is now to assume bcopy, 
  296.  * since it is the most common case. Define 
  297.  *  MEMCPY to use memcpy(), 
  298.  *  vms to use the vms function,
  299.  *  NOCOPY to use a handwritten version in parse.c
  300.  */
  301. #ifdef vms
  302. # define memcpy(dest,src,len) lib$movc3(&len,src,dest)
  303. #else
  304. # if defined(MEMCPY) || defined(MSDOS) || defined (ATARI) || defined( OS2 ) || defined(_Windows) || defined(DOS386)
  305.    /* use memcpy directly */
  306. # else 
  307. #  ifdef NOCOPY
  308.     /* use the handwritten memcpy in parse.c */
  309. #  else
  310.     /* assume bcopy is in use */
  311. #   define memcpy(dest,src,len) bcopy(src,dest,len)
  312. #  endif /* NOCOPY */
  313. # endif /* MEMCPY || MSDOS */
  314. #endif /* vms */
  315.  
  316. /*
  317.  * In case you have MEMSET instead of BZERO. If you have something 
  318.  * else, define bzero to that something.
  319.  */
  320. #if defined(MEMSET) || defined(MSDOS) || defined( OS2 ) || defined(_Windows) || defined(DOS386)
  321. #define bzero(dest,len)  (void)(memset(dest, 0, len))
  322. #endif /* MEMSET || MSDOS */
  323.  
  324. #define top_of_stack stack[s_p]
  325.  
  326. typedef int TBOOLEAN;
  327.  
  328. #ifdef __ZTC__
  329. typedef int (*FUNC_PTR)(...);
  330. #else
  331. typedef int (*FUNC_PTR)();
  332. #endif
  333.  
  334. enum operators {
  335.     PUSH, PUSHC, PUSHD1, PUSHD2, PUSHD, CALL, CALLN, LNOT, BNOT, UMINUS,
  336.     LOR, LAND, BOR, XOR, BAND, EQ, NE, GT, LT, GE, LE, PLUS, MINUS, MULT,
  337.     DIV, MOD, POWER, FACTORIAL, BOOLE, JUMP, JUMPZ, JUMPNZ, JTERN, SF_START
  338. };
  339.  
  340.  
  341. #define is_jump(operator) ((operator) >=(int)JUMP && (operator) <(int)SF_START)
  342.  
  343.  
  344. enum DATA_TYPES {
  345.     INTGR, CMPLX
  346. };
  347.  
  348.  
  349. enum PLOT_TYPE {
  350.     FUNC, DATA, FUNC3D, DATA3D
  351. };
  352.  
  353. /*XXX - JG */
  354. enum PLOT_STYLE {
  355.     LINES, POINTSTYLE, IMPULSES, LINESPOINTS, DOTS, ERRORBARS, BOXES, BOXERROR, STEPS
  356. };
  357.  
  358. enum JUSTIFY {
  359.     LEFT, CENTRE, RIGHT
  360. };
  361.  
  362. #if !(defined(ATARI)&&defined(__GNUC__)&&defined(_MATH_H)) /* FF's math.h has the type already */
  363. struct cmplx {
  364.     double real, imag;
  365. };
  366. #endif
  367.  
  368.  
  369. struct value {
  370.     enum DATA_TYPES type;
  371.     union {
  372.         int int_val;
  373.         struct cmplx cmplx_val;
  374.     } v;
  375. };
  376.  
  377.  
  378. struct lexical_unit {    /* produced by scanner */
  379.     TBOOLEAN is_token;    /* true if token, false if a value */ 
  380.     struct value l_val;
  381.     int start_index;    /* index of first char in token */
  382.     int length;            /* length of token in chars */
  383. };
  384.  
  385.  
  386. struct ft_entry {        /* standard/internal function table entry */
  387.     char *f_name;        /* pointer to name of this function */
  388.     FUNC_PTR func;        /* address of function to call */
  389. };
  390.  
  391.  
  392. struct udft_entry {                /* user-defined function table entry */
  393.     struct udft_entry *next_udf;         /* pointer to next udf in linked list */
  394.     char udf_name[MAX_ID_LEN+1];         /* name of this function entry */
  395.     struct at_type *at;            /* pointer to action table to execute */
  396.     char *definition;             /* definition of function as typed */
  397.     struct value dummy_values[MAX_NUM_VAR];    /* current value of dummy variables */
  398. };
  399.  
  400.  
  401. struct udvt_entry {            /* user-defined value table entry */
  402.     struct udvt_entry *next_udv; /* pointer to next value in linked list */
  403.     char udv_name[MAX_ID_LEN+1]; /* name of this value entry */
  404.     TBOOLEAN udv_undef;        /* true if not defined yet */
  405.     struct value udv_value;    /* value it has */
  406. };
  407.  
  408.  
  409. union argument {            /* p-code argument */
  410.     int j_arg;                /* offset for jump */
  411.     struct value v_arg;        /* constant value */
  412.     struct udvt_entry *udv_arg;    /* pointer to dummy variable */
  413.     struct udft_entry *udf_arg; /* pointer to udf to execute */
  414. };
  415.  
  416.  
  417. struct at_entry {            /* action table entry */
  418.     enum operators index;    /* index of p-code function */
  419.     union argument arg;
  420. };
  421.  
  422.  
  423. struct at_type {
  424.     int a_count;                /* count of entries in .actions[] */
  425.     struct at_entry actions[MAX_AT_LEN];
  426.         /* will usually be less than MAX_AT_LEN is malloc()'d copy */
  427. };
  428.  
  429.  
  430. /* Defines the type of a coordinate */
  431. /* INRANGE and OUTRANGE points have an x,y point associated with them */
  432. enum coord_type {
  433.     INRANGE,                /* inside plot boundary */
  434.     OUTRANGE,                /* outside plot boundary, but defined */
  435.     UNDEFINED                /* not defined at all */
  436. };
  437.   
  438. #if defined(MSDOS) || defined(_Windows) 
  439. typedef float coordval;        /* memory is tight on PCs! */
  440. #else
  441. typedef double coordval;
  442. #endif
  443.  
  444. struct coordinate {
  445.     enum coord_type type;    /* see above */
  446.     coordval x, y, z;
  447.     coordval ylow, yhigh;    /* ignored in 3d */
  448. #if (defined(_Windows) && !defined(WIN32)) || (defined(MSDOS) && defined(__TURBOC__))
  449.     char pad[10];        /* pad to 32 byte boundary */
  450. #endif
  451. };
  452.  
  453. struct curve_points {
  454.     struct curve_points *next_cp;    /* pointer to next plot in linked list */
  455.     enum PLOT_TYPE plot_type;
  456.     enum PLOT_STYLE plot_style;
  457.     char *title;
  458.     int line_type;
  459.     int point_type;
  460.      int p_max;                    /* how many points are allocated */
  461.     int p_count;                    /* count of points in points */
  462.     struct coordinate GPHUGE *points;
  463. };
  464.  
  465. struct gnuplot_contours {
  466.     struct gnuplot_contours *next;
  467.     struct coordinate GPHUGE *coords;
  468.      char isNewLevel;
  469.      char label[12];
  470.     int num_pts;
  471. };
  472.  
  473. struct iso_curve {
  474.     struct iso_curve *next;
  475.      int p_max;                    /* how many points are allocated */
  476.     int p_count;                    /* count of points in points */
  477.     struct coordinate GPHUGE *points;
  478. };
  479.  
  480. struct surface_points {
  481.     struct surface_points *next_sp;    /* pointer to next plot in linked list */
  482.     enum PLOT_TYPE plot_type;
  483.     enum PLOT_STYLE plot_style;
  484.     char *title;
  485.     int line_type;
  486.     int point_type;
  487.     int has_grid_topology;
  488.     int num_iso_read;  /* Data files only - num of isolines read from file. */
  489.     struct gnuplot_contours *contours;    /* Not NULL If have contours. */
  490.     struct iso_curve *iso_crvs;
  491. };
  492.  
  493. struct TERMENTRY {
  494.     char *name;
  495. #if defined(_Windows) && !defined(WIN32)
  496.     char GPFAR description[80];    /* to make text go in FAR segment */
  497. #else
  498.     char *description;
  499. #endif
  500.     unsigned int xmax,ymax,v_char,h_char,v_tic,h_tic;
  501.     FUNC_PTR options,init,reset,text,scale,graphics,move,vector,linetype,
  502.         put_text,text_angle,justify_text,point,arrow;
  503. };
  504.  
  505. #ifdef _Windows
  506. #define termentry TERMENTRY far
  507. #else
  508. #define termentry TERMENTRY
  509. #endif
  510.  
  511.  
  512. struct text_label {
  513.     struct text_label *next;    /* pointer to next label in linked list */
  514.     int tag;            /* identifies the label */
  515.     double x,y,z;
  516.     enum JUSTIFY pos;
  517.     char text[MAX_LINE_LEN+1];
  518. };
  519.  
  520. struct arrow_def {
  521.     struct arrow_def *next;    /* pointer to next arrow in linked list */
  522.     int tag;            /* identifies the arrow */
  523.     double sx,sy,sz;        /* start position */
  524.     double ex,ey,ez;        /* end position */
  525.     TBOOLEAN head;            /* arrow has a head or not */
  526. };
  527.  
  528. /* Tic-mark labelling definition; see set xtics */
  529. struct ticdef {
  530.     int type;                /* one of three values below */
  531. #define TIC_COMPUTED 1        /* default; gnuplot figures them */
  532. #define TIC_SERIES 2        /* user-defined series */
  533. #define TIC_USER 3            /* user-defined points */
  534. #define TIC_MONTH 4        /* print out month names ((mo-1)%12)+1 */
  535. #define TIC_DAY 5        /* print out day of week */
  536.     union {
  537.        struct {            /* for TIC_SERIES */
  538.           double start, incr;
  539.           double end;        /* ymax, if VERYLARGE */
  540.        } series;
  541.        struct ticmark *user;    /* for TIC_USER */
  542.     } def;
  543. };
  544.  
  545. /* Defines one ticmark for TIC_USER style.
  546.  * If label==NULL, the value is printed with the usual format string.
  547.  * else, it is used as the format string (note that it may be a constant
  548.  * string, like "high" or "low").
  549.  */
  550. struct ticmark {
  551.     double position;        /* where on axis is this */
  552.     char *label;            /* optional (format) string label */
  553.     struct ticmark *next;    /* linked list */
  554. };
  555.  
  556. /*
  557.  * SS$_NORMAL is "normal completion", STS$M_INHIB_MSG supresses
  558.  
  559.  * printing a status message.
  560.  * SS$_ABORT is the general abort status code.
  561.  from:    Martin Minow
  562.     decvax!minow
  563.  */
  564. #ifdef    vms
  565. #include        <ssdef.h>
  566. #include        <stsdef.h>
  567. #define    IO_SUCCESS    (SS$_NORMAL | STS$M_INHIB_MSG)
  568. #define    IO_ERROR    SS$_ABORT
  569. #endif /* vms */
  570.  
  571.  
  572. #ifndef    IO_SUCCESS    /* DECUS or VMS C will have defined these already */
  573. #define    IO_SUCCESS    0
  574. #endif
  575. #ifndef    IO_ERROR
  576. #define    IO_ERROR    1
  577. #endif
  578.  
  579. /* Some key global variables */
  580. extern TBOOLEAN screen_ok;
  581. extern TBOOLEAN term_init;
  582. extern TBOOLEAN undefined;
  583. extern struct termentry term_tbl[];
  584.  
  585. extern char *alloc();
  586. extern char GPFAR *gpfaralloc();    /* far versions */
  587. extern char GPFAR *gpfarrealloc();
  588. extern void gpfarfree();
  589. /* allocating and managing curve_points structures */
  590. extern struct curve_points *cp_alloc();
  591. extern int cp_extend();
  592. extern int cp_free();
  593. /* allocating and managing surface_points structures */
  594. extern struct surface_points *sp_alloc();
  595. extern int sp_replace();
  596. extern int sp_free();
  597. /* allocating and managing is_curve structures */
  598. extern struct iso_curve *iso_alloc();
  599. extern int iso_extend();
  600. extern int iso_free();
  601.  
  602. /* Windows needs to redefine stdin/stdout functions */
  603. #ifdef _Windows
  604. #include "win/wtext.h"
  605. #endif
  606.