-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathdatafile.h
More file actions
314 lines (263 loc) · 11.8 KB
/
datafile.h
File metadata and controls
314 lines (263 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/* GNUPLOT - datafile.h */
/*[
* Copyright 1986 - 1993, 1998, 2004 Thomas Williams, Colin Kelley
*
* Permission to use, copy, and distribute this software and its
* documentation for any purpose with or without fee is hereby granted,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation.
*
* Permission to modify the software is granted, but not the right to
* distribute the complete modified source code. Modifications are to
* be distributed as patches to the released version. Permission to
* distribute binaries produced by compiling modified sources is granted,
* provided you
* 1. distribute the corresponding source modifications from the
* released version in the form of a patch file along with the binaries,
* 2. add special version identification to distinguish your version
* in addition to the base release version number,
* 3. provide your name and address as the primary contact for the
* support of your modified version, and
* 4. retain our contact information in regard to use of the base
* software.
* Permission to distribute the released version of the source code along
* with corresponding source modifications in the form of a patch file is
* granted with same provisions 2 through 4 for binary distributions.
*
* This software is provided "as is" without express or implied warranty
* to the extent permitted by applicable law.
]*/
#ifndef GNUPLOT_DATAFILE_H
# define GNUPLOT_DATAFILE_H
/* #if... / #include / #define collection: */
#include "axis.h"
#include "graph3d.h"
#include "graphics.h"
/* returns from DF_READLINE in datafile.c */
/* +ve is number of columns read */
enum DF_STATUS {
DF_BAD = 0,
DF_GOOD = 1,
DF_EOF = -1,
DF_UNDEFINED = -2,
DF_FIRST_BLANK = -3,
DF_SECOND_BLANK = -4,
DF_MISSING = -5,
DF_FOUND_KEY_TITLE = -6,
DF_KEY_TITLE_MISSING = -7,
DF_STRINGDATA = -8,
DF_COLUMN_HEADERS = -9,
DF_COMPLEX_VALUE = -10
};
/* large file support (offsets potentially > 2GB) */
#if defined(HAVE_FSEEKO) && defined(HAVE_OFF_T)
# define fseek(stream,pos,whence) fseeko(stream,pos,whence)
# define ftell(stream) ftello(stream)
#elif defined(_MSC_VER)
# define fseek(stream,pos,whence) _fseeki64(stream,pos,whence)
# define ftell(stream) _ftelli64(stream)
#elif defined(__MINGW32__)
# define fseek(stream,pos,whence) fseeko64(stream,pos,whence)
# define ftell(stream) ftello64(stream)
#endif
/* Variables of datafile.c needed by other modules: */
/* how many using columns were specified in the current command */
extern int df_no_use_specs;
/* Maximum number of columns returned to caller by df_readline */
/* Various data structures are dimensioned to hold this many entries. */
/* As of June 2013, plot commands never ask for more than 7 columns of */
/* data, but fit commands can use more. "fit" is also limited by */
/* the number of parameters that can be passed to a user function, so */
/* let's try setting MAXDATACOLS to match. */
/* At present this bumps it from 7 to 14. */
#define MAXDATACOLS (MAX_NUM_VAR+2)
/* suggested x value if none given */
extern int df_datum;
/* is this a matrix splot? */
extern TBOOLEAN df_matrix;
/* is this a binary file? */
extern TBOOLEAN df_binary;
/* will this need to be expanded into a fully populated grid? */
extern TBOOLEAN df_sparse_matrix;
/* was df_open called on something that turned out to be a voxel grid? */
extern TBOOLEAN df_voxelgrid;
extern char *df_filename;
extern int df_line_number;
extern AXIS_INDEX df_axis[];
/* Returned to caller by df_readline() */
extern char *df_tokens[];
extern struct value df_strings[]; /* used only by TABLESTYLE */
/* number of columns in first row of data return to user in STATS_columns */
extern int df_last_col;
/* number of matrix elements entered as missing or NaN */
extern int df_bad_matrix_values;
/* First row of data is known to contain headers rather than data */
extern TBOOLEAN df_columnheaders;
/* string representing missing values, ascii datafiles */
extern char *missing_val;
/* input field separators, NULL if whitespace is the separator */
extern char *df_separators;
/* comments chars */
extern char *df_commentschars;
/* flag if any 'inline' data are in use, for the current plot */
extern TBOOLEAN plotted_data_from_stdin;
/* Setting this allows the parser to recognize Fortran D or Q */
/* format constants in the input file. But it slows things down */
extern TBOOLEAN df_fortran_constants;
/* Setting this disables initialization of the floating point exception */
/* handler before every expression evaluation in a using specifier. */
/* This can speed data input significantly, but assumes valid input. */
extern TBOOLEAN df_nofpe_trap;
extern TBOOLEAN evaluate_inside_using;
extern TBOOLEAN df_warn_on_missing_columnheader;
/* Used by plot title columnhead, stats name columnhead */
extern char *df_key_title;
extern struct at_type *df_plot_title_at;
/* Prototypes of functions exported by datafile.c */
int df_open(const char *, int, struct curve_points *);
int df_readline(double [], int);
void df_close(void);
void df_init(void);
char * df_fgets(FILE *);
void df_showdata(void);
int df_2dbinary(struct curve_points *);
int df_3dmatrix(struct surface_points *, int);
void df_set_key_title(struct curve_points *);
void df_set_key_title_columnhead(struct curve_points *);
char * df_parse_string_field(char *);
int expect_string(const signed char column);
void require_value(const char column);
char *df_retrieve_columnhead(int column);
void df_reset_after_error(void);
void f_dollars(union argument *x);
void f_column (union argument *x);
void f_columnhead (union argument *x);
void f_valid (union argument *x);
void f_timecolumn (union argument *x);
void f_stringcolumn (union argument *x);
struct use_spec_s {
int column;
int expected_type;
struct at_type *at;
int depends_on_column;
};
/* Details about the records contained in a binary data file. */
typedef enum df_translation_type {
DF_TRANSLATE_DEFAULT, /* Gnuplot will position in first quadrant at origin. */
DF_TRANSLATE_VIA_ORIGIN,
DF_TRANSLATE_VIA_CENTER
} df_translation_type;
typedef enum df_sample_scan_type {
DF_SCAN_POINT = -3, /* fastest */
DF_SCAN_LINE = -4,
DF_SCAN_PLANE = -5 /* slowest */
} df_sample_scan_type;
/* To generate a swap, take the bit-wise complement of the lowest two bits. */
typedef enum df_endianess_type {
DF_LITTLE_ENDIAN,
DF_PDP_ENDIAN,
DF_DPD_ENDIAN,
DF_BIG_ENDIAN,
DF_ENDIAN_TYPE_LENGTH /* Must be last */
} df_endianess_type;
/* The various types of numerical types that can be read from a data file. */
typedef enum df_data_type {
DF_CHAR, DF_UCHAR, DF_SHORT, DF_USHORT, DF_INT,
DF_UINT, DF_LONG, DF_ULONG, DF_FLOAT, DF_DOUBLE,
DF_LONGLONG, DF_ULONGLONG,
DF_BAD_TYPE
} df_data_type;
#define DF_DEFAULT_TYPE DF_FLOAT
/* Some macros for making the compiler figure out what function
* the "machine independent" names should execute to read the
* appropriately sized variable from a data file.
*/
#define SIGNED_TEST(val) ((val)==sizeof(long) ? DF_LONG : \
((val)==sizeof(long long) ? DF_LONGLONG : \
((val)==sizeof(int) ? DF_INT : \
((val)==sizeof(short) ? DF_SHORT : \
((val)==sizeof(char) ? DF_CHAR : DF_BAD_TYPE)))))
#define UNSIGNED_TEST(val) ((val)==sizeof(unsigned long) ? DF_ULONG : \
((val)==sizeof(unsigned long long) ? DF_ULONGLONG : \
((val)==sizeof(unsigned int) ? DF_UINT : \
((val)==sizeof(unsigned short) ? DF_USHORT : \
((val)==sizeof(unsigned char) ? DF_UCHAR : DF_BAD_TYPE)))))
#define FLOAT_TEST(val) ((val)==sizeof(float) ? DF_FLOAT : \
((val)==sizeof(double) ? DF_DOUBLE : DF_BAD_TYPE))
typedef enum df_records_type {
DF_CURRENT_RECORDS,
DF_DEFAULT_RECORDS
} df_records_type;
typedef struct df_binary_type_struct {
df_data_type read_type;
unsigned short read_size;
} df_binary_type_struct;
typedef struct df_column_bininfo_struct {
long skip_bytes;
df_binary_type_struct column;
} df_column_bininfo_struct;
/* NOTE TO THOSE WRITING FILE TYPE FUNCTIONS
*
* "cart" means Cartesian, i.e., the (x,y,z) [or (r,t,z)] coordinate
* system of the plot. "scan" refers to the scanning method of the
* file in question, i.e., first points, then lines, then planes.
* The important variables for a file type function to fill in are
* those beginning with "scan". There is a tricky set of rules
* related to the "scan_cart" mapping, the file-specified variables,
* the default variables, and the command-line variables. Basically,
* command line overrides data file which overrides default. (Yes,
* like a confusing version of rock, paper, scissors.) So, from the
* file type function perspective, it is better to leave those
* variables which are not specifically known from file data or
* otherwise (e.g., sample periods "scan_delta") unaltered in case
* the user has issued "set datafile" to define defaults.
*/
typedef struct df_binary_file_record_struct {
int cart_dim[3]; /* dimension array size, x/y/z */
int cart_dir[3]; /* 1 scan in positive direction, -1 negative, x/y/z */
double cart_delta[3]; /* spacing between array points, x/y/z */
df_translation_type cart_trans; /* translate via origin, center or default */
double cart_cen_or_ori[3]; /* vector representing center or origin, x/y/z */
double cart_alpha; /* 2D rotation angle (rotate) */
double cart_p[3]; /* 3D rotation normal vector (perpendicular) */
df_sample_scan_type cart_scan[3]; /* how to assign the dimensions read from file when generating coordinates */
TBOOLEAN scan_generate_coord; /* whether or not Gnuplot should generate coordinates. */
off_t scan_skip[3]; /* skip bytes before the record, line, plane */
/* Not controllable by the user, only by file type functions.
* These are all points/lines/planes format.
*/
int scan_dim[3]; /* number of points, lines, planes */
int scan_dir[3]; /* 1 scan in positive direction wrt Cartesian coordinate system, -1 negative */
double scan_delta[3]; /* sample period along points, lines, planes */
df_translation_type scan_trans; /* translate via origin, center or default */
double scan_cen_or_ori[3]; /* vector representing center or origin, x/y/z */
/* `matrix every ::lowx:lowy:` can select a submatrix.
* This is its size.
*/
int submatrix_ncols;
int submatrix_nrows;
/* *** Do not modify outside of datafile.c!!! *** */
char *memory_data;
} df_binary_file_record_struct;
extern df_binary_file_record_struct *df_bin_record;
extern int df_num_bin_records;
extern const struct coordinate blank_data_line;
extern struct use_spec_s use_spec[];
/* Prototypes of functions exported by datafile.c */
void df_show_binary(FILE *fp);
void df_show_datasizes(FILE *fp);
void df_show_filetypes(FILE *fp);
void df_set_datafile_binary(void);
void df_unset_datafile_binary(void);
void df_add_binary_records(int, df_records_type);
void df_extend_binary_columns(int);
void df_set_skip_before(int col, int bytes); /* Number of bytes to skip before a binary column. */
#define df_set_skip_after(col,bytes) df_set_skip_before(col+1,bytes) /* Number of bytes to skip after a binary column. */
void df_set_read_type(int col, df_data_type type); /* Type of data in the binary column. */
df_data_type df_get_read_type(int col); /* Type of data in the binary column. */
int df_get_read_size(int col); /* Size of data in the binary column. */
int df_get_num_matrix_cols(void);
void df_set_plot_mode(int);
void populate_sparse_matrix(struct coordinate **points, int *p_count);
#endif /* GNUPLOT_DATAFILE_H */