1 | /* img.h |
---|
2 | * Header file for routines to read and write Survex ".3d" image files |
---|
3 | * Copyright (C) Olly Betts 1993,1994,1997,2001,2002,2003,2004,2005,2006,2010,2011 |
---|
4 | * |
---|
5 | * This program is free software; you can redistribute it and/or modify |
---|
6 | * it under the terms of the GNU General Public License as published by |
---|
7 | * the Free Software Foundation; either version 2 of the License, or |
---|
8 | * (at your option) any later version. |
---|
9 | * |
---|
10 | * This program is distributed in the hope that it will be useful, |
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | * GNU General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU General Public License |
---|
16 | * along with this program; if not, write to the Free Software |
---|
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
18 | */ |
---|
19 | |
---|
20 | #ifndef IMG_H |
---|
21 | # define IMG_H |
---|
22 | |
---|
23 | /* Define IMG_API_VERSION if you want more recent versions of the img API. |
---|
24 | * |
---|
25 | * 0 (default) The old API. date1 and date2 give the survey date as time_t. |
---|
26 | * Set to 0 for "unknown". |
---|
27 | * 1 days1 and days2 give survey dates as days since 1st Jan 1900. |
---|
28 | * Set to -1 for "unknown". |
---|
29 | */ |
---|
30 | #ifndef IMG_API_VERSION |
---|
31 | # define IMG_API_VERSION 0 |
---|
32 | #elif IMG_API_VERSION > 1 |
---|
33 | # error IMG_API_VERSION > 1 too new |
---|
34 | #endif |
---|
35 | |
---|
36 | #ifdef __cplusplus |
---|
37 | extern "C" { |
---|
38 | #endif |
---|
39 | |
---|
40 | #include <stdio.h> |
---|
41 | #include <time.h> /* for time_t */ |
---|
42 | |
---|
43 | # ifdef IMG_HOSTED |
---|
44 | # include "useful.h" |
---|
45 | # endif |
---|
46 | |
---|
47 | # define img_BAD -2 |
---|
48 | # define img_STOP -1 |
---|
49 | # define img_MOVE 0 |
---|
50 | # define img_LINE 1 |
---|
51 | /* NB: img_CROSS is never output and ignored on input. |
---|
52 | * Put crosses where labels are. */ |
---|
53 | /* # define img_CROSS 2 */ |
---|
54 | # define img_LABEL 3 |
---|
55 | # define img_XSECT 4 |
---|
56 | # define img_XSECT_END 5 |
---|
57 | # define img_ERROR_INFO 6 |
---|
58 | |
---|
59 | # define img_FLAG_SURFACE 0x01 |
---|
60 | # define img_FLAG_DUPLICATE 0x02 |
---|
61 | # define img_FLAG_SPLAY 0x04 |
---|
62 | |
---|
63 | # define img_SFLAG_SURFACE 0x01 |
---|
64 | # define img_SFLAG_UNDERGROUND 0x02 |
---|
65 | # define img_SFLAG_ENTRANCE 0x04 |
---|
66 | # define img_SFLAG_EXPORTED 0x08 |
---|
67 | # define img_SFLAG_FIXED 0x10 |
---|
68 | |
---|
69 | /* No longer used: */ |
---|
70 | # define img_XFLAG_END 0x01 |
---|
71 | |
---|
72 | /* 3D coordinates (in metres) */ |
---|
73 | typedef struct { |
---|
74 | double x, y, z; |
---|
75 | } img_point; |
---|
76 | |
---|
77 | typedef struct { |
---|
78 | /* members you can access when reading (don't touch when writing) */ |
---|
79 | char *label; |
---|
80 | int flags; |
---|
81 | char *title; |
---|
82 | char *datestamp; |
---|
83 | char separator; /* character used to separate survey levels ('.' usually) */ |
---|
84 | #if IMG_API_VERSION == 0 |
---|
85 | time_t date1, date2; |
---|
86 | #else /* IMG_API_VERSION == 1 */ |
---|
87 | int days1, days2; |
---|
88 | #endif |
---|
89 | double l, r, u, d; |
---|
90 | /* Error information - valid when IMG_ERROR is returned: */ |
---|
91 | int n_legs; |
---|
92 | double length; |
---|
93 | double E, H, V; |
---|
94 | /* The filename actually opened (e.g. may have ".3d" added). */ |
---|
95 | char * filename_opened; |
---|
96 | int is_extended_elevation; |
---|
97 | /* all other members are for internal use only */ |
---|
98 | FILE *fh; /* file handle of image file */ |
---|
99 | char *label_buf; |
---|
100 | size_t buf_len; |
---|
101 | size_t label_len; |
---|
102 | # ifdef IMG_HOSTED |
---|
103 | bool fRead; /* fTrue for reading, fFalse for writing */ |
---|
104 | # else |
---|
105 | int fRead; /* fTrue for reading, fFalse for writing */ |
---|
106 | # endif |
---|
107 | long start; |
---|
108 | /* version of file format: |
---|
109 | * -4 => CMAP .xyz file, shot format |
---|
110 | * -3 => CMAP .xyz file, station format |
---|
111 | * -2 => Compass .plt file |
---|
112 | * -1 => .pos file |
---|
113 | * 0 => 0.01 ascii |
---|
114 | * 1 => 0.01 binary, |
---|
115 | * 2 => byte actions and flags |
---|
116 | * 3 => prefixes for legs; compressed prefixes |
---|
117 | * 4 => survey date |
---|
118 | * 5 => LRUD info |
---|
119 | * 6 => error info |
---|
120 | * 7 => more compact dates with wider range |
---|
121 | */ |
---|
122 | int version; |
---|
123 | char *survey; |
---|
124 | size_t survey_len; |
---|
125 | int pending; /* for old style text format files and survey filtering */ |
---|
126 | img_point mv; |
---|
127 | #if IMG_API_VERSION == 0 |
---|
128 | time_t olddate1, olddate2; |
---|
129 | #else /* IMG_API_VERSION == 1 */ |
---|
130 | int olddays1, olddays2; |
---|
131 | #endif |
---|
132 | } img; |
---|
133 | |
---|
134 | /* Which version of the file format to output (defaults to newest) */ |
---|
135 | extern unsigned int img_output_version; |
---|
136 | |
---|
137 | /* Minimum supported value for img_output_version: */ |
---|
138 | #define IMG_VERSION_MIN 1 |
---|
139 | |
---|
140 | /* Maximum supported value for img_output_version: */ |
---|
141 | #define IMG_VERSION_MAX 7 |
---|
142 | |
---|
143 | /* Open a .3d file for reading |
---|
144 | * fnm is the filename |
---|
145 | * Returns pointer to an img struct or NULL |
---|
146 | */ |
---|
147 | #define img_open(F) img_open_survey((F), NULL) |
---|
148 | |
---|
149 | /* Open a .3d file for reading |
---|
150 | * fnm is the filename |
---|
151 | * Returns pointer to an img struct or NULL |
---|
152 | * survey points to a survey name to restrict reading to (or NULL for all |
---|
153 | * survey data in the file) |
---|
154 | */ |
---|
155 | img *img_open_survey(const char *fnm, const char *survey); |
---|
156 | |
---|
157 | /* Open a .3d file for output |
---|
158 | * fnm is the filename |
---|
159 | * title_buf is the title |
---|
160 | * fBinary is ignored (it used to select an ASCII variant of the earliest |
---|
161 | * version of the 3d file format) |
---|
162 | * Returns pointer to an img struct or NULL for error (check img_error() |
---|
163 | * for details) |
---|
164 | */ |
---|
165 | # ifdef IMG_HOSTED |
---|
166 | img *img_open_write(const char *fnm, char *title_buf, bool fBinary); |
---|
167 | # else |
---|
168 | img *img_open_write(const char *fnm, char *title_buf, int fBinary); |
---|
169 | # endif |
---|
170 | |
---|
171 | /* Read an item from a .3d file |
---|
172 | * pimg is a pointer to an img struct returned by img_open() |
---|
173 | * coordinates are returned in p |
---|
174 | * flags and label name are returned in fields in pimg |
---|
175 | * Returns img_XXXX as #define-d above |
---|
176 | */ |
---|
177 | int img_read_item(img *pimg, img_point *p); |
---|
178 | |
---|
179 | /* Write a item to a .3d file |
---|
180 | * pimg is a pointer to an img struct returned by img_open_write() |
---|
181 | * code is one of the img_XXXX #define-d above |
---|
182 | * flags is the leg, station, or xsect flags |
---|
183 | * (meaningful for img_LINE, img_LABEL, and img_XSECT respectively) |
---|
184 | * s is the label (only meaningful for img_LABEL) |
---|
185 | * x, y, z are the coordinates |
---|
186 | */ |
---|
187 | void img_write_item(img *pimg, int code, int flags, const char *s, |
---|
188 | double x, double y, double z); |
---|
189 | |
---|
190 | /* Write error information for the current traverse |
---|
191 | * n_legs is the number of legs in the traverse |
---|
192 | * length is the traverse length (in m) |
---|
193 | * E is the ratio of the observed misclosure to the theoretical one |
---|
194 | * H is the ratio of the observed horizontal misclosure to the theoretical one |
---|
195 | * V is the ratio of the observed vertical misclosure to the theoretical one |
---|
196 | */ |
---|
197 | void img_write_errors(img *pimg, int n_legs, double length, |
---|
198 | double E, double H, double V); |
---|
199 | |
---|
200 | /* rewind a .3d file opened for reading so the data can be read in |
---|
201 | * several passes |
---|
202 | * pimg is a pointer to an img struct returned by img_open() |
---|
203 | * Returns: non-zero for success, zero for error (check img_error() for |
---|
204 | * details) |
---|
205 | */ |
---|
206 | int img_rewind(img *pimg); |
---|
207 | |
---|
208 | /* Close a .3d file |
---|
209 | * pimg is a pointer to an img struct returned by img_open() or |
---|
210 | * img_open_write() |
---|
211 | * Returns: non-zero for success, zero for error (check img_error() for |
---|
212 | * details) |
---|
213 | */ |
---|
214 | int img_close(img *pimg); |
---|
215 | |
---|
216 | /* Codes returned by img_error */ |
---|
217 | # ifndef IMG_HOSTED |
---|
218 | typedef enum { |
---|
219 | IMG_NONE = 0, IMG_FILENOTFOUND, IMG_OUTOFMEMORY, |
---|
220 | IMG_CANTOPENOUT, IMG_BADFORMAT, IMG_DIRECTORY, |
---|
221 | IMG_READERROR, IMG_WRITEERROR, IMG_TOONEW |
---|
222 | } img_errcode; |
---|
223 | |
---|
224 | /* Read the error code |
---|
225 | * if img_open() or img_open_write() returns NULL, you can call this |
---|
226 | * to discover why */ |
---|
227 | img_errcode img_error(void); |
---|
228 | # else |
---|
229 | int img_error(void); |
---|
230 | # endif |
---|
231 | |
---|
232 | #ifdef __cplusplus |
---|
233 | } |
---|
234 | #endif |
---|
235 | |
---|
236 | #endif |
---|