home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / gnuplot.lha / gnuplot / src / plot.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-28  |  15.4 KB  |  614 lines

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