Icons are changed
[gnuplot] / src / datafile.h
1 /*
2  * $Id: datafile.h,v 1.20.2.1 2007/03/22 04:48:24 sfeam Exp $
3  */
4
5 /* GNUPLOT - datafile.h */
6
7 /*[
8  * Copyright 1986 - 1993, 1998, 2004   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 complete modified source code.  Modifications are to
18  * be distributed as patches to the released version.  Permission to
19  * distribute binaries produced by compiling modified sources is granted,
20  * provided you
21  *   1. distribute the corresponding source modifications from the
22  *    released version in the form of a patch file along with the binaries,
23  *   2. add special version identification to distinguish your version
24  *    in addition to the base release version number,
25  *   3. provide your name and address as the primary contact for the
26  *    support of your modified version, and
27  *   4. retain our contact information in regard to use of the base
28  *    software.
29  * Permission to distribute the released version of the source code along
30  * with corresponding source modifications in the form of a patch file is
31  * granted with same provisions 2 through 4 for binary distributions.
32  *
33  * This software is provided "as is" without express or implied warranty
34  * to the extent permitted by applicable law.
35 ]*/
36
37 #ifndef GNUPLOT_DATAFILE_H
38 # define GNUPLOT_DATAFILE_H
39
40 /* #if... / #include / #define collection: */
41
42 #include "axis.h"
43 #include "graph3d.h"
44 #include "graphics.h"
45
46 /* returns from DF_READLINE in datafile.c */
47 /* +ve is number of columns read */
48 #define DF_EOF          (-1)
49 #define DF_UNDEFINED    (-2)
50 #define DF_FIRST_BLANK  (-3)
51 #define DF_SECOND_BLANK (-4)
52 #define DF_MISSING      (-5)
53 #define DF_FOUND_KEY_TITLE   (-6)
54 #define DF_KEY_TITLE_MISSING (-7)
55 #define DF_STRINGDATA   (-8)
56 #ifdef EAM_HISTOGRAMS
57 /* should really be a parameter to df_readline rather than a global */
58 extern struct curve_points *df_current_plot;
59 #endif
60
61
62 #ifndef MAXINT                  /* should there be one already defined ? */
63 # ifdef INT_MAX                 /* in limits.h ? */
64 #  define MAXINT INT_MAX
65 # else
66 #  define MAXINT ((~0)>>1)
67 # endif
68 #endif
69
70 /* Variables of datafile.c needed by other modules: */
71
72 /* how many using columns were specified, and max possible */
73 extern int df_no_use_specs;
74 #define MAXDATACOLS 7
75
76 /* suggested x value if none given */
77 extern int df_datum;
78
79 /* is this a matrix splot? */
80 extern TBOOLEAN df_matrix;
81
82 /* is this a binary file? */
83 extern TBOOLEAN df_binary;
84
85 extern int df_eof;
86 extern int df_line_number;
87 extern AXIS_INDEX df_axis[];
88 extern struct udft_entry ydata_func; /* HBB 990829: moved from command.h */
89
90 #ifdef EAM_DATASTRINGS
91 /* Returned to caller by df_readline() */
92 extern char *df_tokens[];
93 #endif
94
95 /* string representing missing values, ascii datafiles */
96 extern char *missing_val;
97
98 /* input field separator, NUL if whitespace is the separator */
99 extern char df_separator;
100
101 /* comments chars */
102 extern char *df_commentschars;
103
104 /* flag if any 'inline' data are in use, for the current plot */
105 extern TBOOLEAN plotted_data_from_stdin;
106
107 /* Setting this allows the parser to recognize Fortran D or Q   */
108 /* format constants in the input file. But it slows things down */
109 extern TBOOLEAN df_fortran_constants;
110
111 /* Prototypes of functions exported by datafile.c */
112
113 int df_open __PROTO((const char *, int));
114 int df_readline __PROTO((double [], int));
115 void df_close __PROTO((void));
116 void df_showdata __PROTO((void));
117 int df_2dbinary __PROTO((struct curve_points *));
118 int df_3dmatrix __PROTO((struct surface_points *, int));
119 #ifdef EAM_DATASTRINGS
120 void df_set_key_title __PROTO((struct curve_points *));
121 int expect_string __PROTO((const char column ));
122 #endif
123
124 void df_reset_after_error __PROTO((void));
125 void f_dollars __PROTO((union argument *x));
126 void f_column  __PROTO((union argument *x));
127 void f_valid   __PROTO((union argument *x));
128 void f_timecolumn   __PROTO((union argument *x));
129 #ifdef GP_STRING_VARS
130 void f_stringcolumn   __PROTO((union argument *x));
131 #endif
132
133 struct use_spec_s {
134     int column;
135 #ifdef EAM_DATASTRINGS
136     int expected_type;
137 #endif
138     struct at_type *at;
139 };
140
141 #ifndef BINARY_DATA_FILE
142 #define df_set_plot_mode(mode)  /* Not needed except for binary data files */
143 #endif
144
145 #ifdef BINARY_DATA_FILE
146 /* Details about the records contained in a binary data file. */
147
148 typedef enum df_translation_type {
149     DF_TRANSLATE_DEFAULT,     /* Gnuplot will position in first quadrant at origin. */
150     DF_TRANSLATE_VIA_ORIGIN,
151     DF_TRANSLATE_VIA_CENTER
152 } df_translation_type;
153
154 typedef enum df_sample_scan_type {
155     DF_SCAN_POINT = -3,  /* fastest */
156     DF_SCAN_LINE  = -4,
157     DF_SCAN_PLANE = -5   /* slowest */
158 } df_sample_scan_type;
159
160 /* To generate a swap, take the bit-wise complement of the lowest two bits. */
161 typedef enum df_endianess_type {
162     DF_LITTLE_ENDIAN,
163     DF_PDP_ENDIAN,
164     DF_DPD_ENDIAN,
165     DF_BIG_ENDIAN,
166     DF_ENDIAN_TYPE_LENGTH  /* Must be last */
167 } df_endianess_type;
168
169 /* The various types of numerical types that can be read from a data file. */
170 typedef enum df_data_type {
171     DF_CHAR, DF_UCHAR, DF_SHORT, DF_USHORT, DF_INT,
172     DF_UINT, DF_LONG,  DF_ULONG, DF_FLOAT,  DF_DOUBLE,
173     DF_BAD_TYPE
174 } df_data_type;
175 #define DF_DEFAULT_TYPE DF_FLOAT
176
177 /* Some macros for making the compiler figure out what function
178  * the "machine independent" names should execute to read the
179  * appropriately sized variable from a data file.
180  */ 
181 #define SIGNED_TEST(val) ((val)==sizeof(long) ? DF_LONG : \
182                          ((val)==sizeof(int) ? DF_INT : \
183                          ((val)==sizeof(short) ? DF_SHORT : \
184                          ((val)==sizeof(char) ? DF_CHAR : DF_BAD_TYPE))))
185 #define UNSIGNED_TEST(val) ((val)==sizeof(unsigned long) ? DF_ULONG : \
186                            ((val)==sizeof(unsigned int) ? DF_UINT : \
187                            ((val)==sizeof(unsigned short) ? DF_USHORT : \
188                            ((val)==sizeof(unsigned char) ? DF_UCHAR : DF_BAD_TYPE))))
189 #define FLOAT_TEST(val) ((val)==sizeof(float) ? DF_FLOAT : \
190                         ((val)==sizeof(double) ? DF_DOUBLE : DF_BAD_TYPE))
191
192 typedef enum df_records_type {
193     DF_CURRENT_RECORDS,
194     DF_DEFAULT_RECORDS
195 } df_records_type;
196
197 typedef struct df_binary_type_struct {
198     df_data_type read_type;
199     unsigned short read_size;
200 } df_binary_type_struct;
201
202 typedef struct df_column_bininfo_struct {
203     short skip_bytes;
204     df_binary_type_struct column;
205 } df_column_bininfo_struct;
206
207 /* NOTE TO THOSE WRITING FILE TYPE FUNCTIONS
208  *
209  * "cart" means Cartesian, i.e., the (x,y,z) [or (r,t,z)] coordinate
210  * system of the plot.  "scan" refers to the scanning method of the
211  * file in question, i.e., first points, then lines, then planes.
212  * The important variables for a file type function to fill in are
213  * those beginning with "scan".  There is a tricky set of rules
214  * related to the "scan_cart" mapping, the file-specified variables,
215  * the default variables, and the command-line variables.  Basically,
216  * command line overrides data file which overrides default.  (Yes,
217  * like a confusing version of rock, paper, scissors.) So, from the
218  * file type function perspective, it is better to leave those
219  * variables which are not specifically known from file data or
220  * otherwise (e.g., sample periods "scan_delta") unaltered in case
221  * the user has issued "set datafile" to define defaults.
222  */
223 typedef struct df_binary_file_record_struct {
224     int cart_dim[3];                  /* dimension array size, x/y/z */
225     int cart_dir[3];                  /* 1 scan in positive direction, -1 negative, x/y/z */
226     double cart_delta[3];             /* spacing between array points, x/y/z */
227     df_translation_type cart_trans;   /* translate via origin, center or default */
228     double cart_cen_or_ori[3];        /* vector representing center or origin, x/y/z */
229     double cart_alpha;                /* 2D rotation angle (rotate) */
230     double cart_p[3];                 /* 3D rotation normal vector (perpendicular) */
231
232     df_sample_scan_type cart_scan[3]; /* how to assign the dimensions read from file when generating coordinates */
233     TBOOLEAN scan_generate_coord;     /* whether or not Gnuplot should generate coordinates. */
234     int scan_skip[3];                 /* skip bytes before the record, line, plane */
235
236     /* Not controllable by the user, only by file type functions.
237      * These are all points/lines/planes format.
238      */
239     int scan_dim[3];                  /* number of points, lines, planes */
240     int scan_dir[3];                  /* 1 scan in positive direction wrt Cartesian coordinate system, -1 negative */
241     double scan_delta[3];             /* sample period along points, lines, planes */
242     df_translation_type scan_trans;   /* translate via origin, center or default */
243     double scan_cen_or_ori[3];        /* vector representing center or origin, x/y/z */
244
245     /* *** Do not modify outside of datafile.c!!! *** */
246     char GPFAR *memory_data;
247 } df_binary_file_record_struct;
248
249 extern df_binary_file_record_struct *df_bin_record;
250 extern int df_num_bin_records;
251
252 extern struct use_spec_s use_spec[];
253
254 /* Prototypes of functions exported by datafile.c */
255
256 void df_show_binary __PROTO((FILE *fp));
257 void df_show_datasizes __PROTO((FILE *fp));
258 void df_show_filetypes __PROTO((FILE *fp));
259 void df_set_datafile_binary __PROTO((void)); 
260 void df_unset_datafile_binary __PROTO((void));
261 void df_add_binary_records __PROTO((int, df_records_type));
262 void df_extend_binary_columns __PROTO((int));
263 void df_set_skip_before __PROTO((int col, int bytes));                /* Number of bytes to skip before a binary column. */
264 #define df_set_skip_after(col,bytes) df_set_skip_before(col+1,bytes)  /* Number of bytes to skip after a binary column. */
265 void df_set_read_type __PROTO((int col, df_data_type type));          /* Type of data in the binary column. */
266 df_data_type df_get_read_type __PROTO((int col));                     /* Type of data in the binary column. */
267 int df_get_read_size __PROTO((int col));                              /* Size of data in the binary column. */
268 int df_get_num_matrix_cols __PROTO((void));
269 void df_set_plot_mode __PROTO((int));
270 #endif /* BINARY_DATA_FILE */
271
272 #endif /* GNUPLOT_DATAFILE_H */