source: git/src/img.h @ ad4e7b08

RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-datawalls-data-hanging-as-warning
Last change on this file since ad4e7b08 was 43d63e57, checked in by Olly Betts <olly@…>, 10 years ago

src/img.c,src/img.h: Add ability to store a proj string describing
the coordinate system in use in 3d v8 files.

  • Property mode set to 100644
File size: 9.3 KB
Line 
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,2012,2013,2014
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
37extern "C" {
38#endif
39
40#include <stdio.h>
41#include <time.h> /* for time_t */
42
43# define img_BAD   -2
44# define img_STOP  -1
45# define img_MOVE   0
46# define img_LINE   1
47/* NB: img_CROSS is never output and ignored on input.
48 * Put crosses where labels are. */
49/* # define img_CROSS  2 */
50# define img_LABEL  3
51# define img_XSECT  4
52# define img_XSECT_END 5
53# define img_ERROR_INFO 6
54
55/* Leg flags */
56# define img_FLAG_SURFACE   0x01
57# define img_FLAG_DUPLICATE 0x02
58# define img_FLAG_SPLAY     0x04
59
60/* Station flags */
61# define img_SFLAG_SURFACE     0x01
62# define img_SFLAG_UNDERGROUND 0x02
63# define img_SFLAG_ENTRANCE    0x04
64# define img_SFLAG_EXPORTED    0x08
65# define img_SFLAG_FIXED       0x10
66# define img_SFLAG_ANON        0x20
67# define img_SFLAG_WALL        0x40
68
69/* File-wide flags */
70# define img_FFLAG_EXTENDED 0x80
71
72/* When writing img_XSECT, img_XFLAG_END in pimg->flags means this is the last
73 * img_XSECT in this tube:
74 */
75# define img_XFLAG_END      0x01
76
77# define img_STYLE_UNKNOWN   -1
78# define img_STYLE_NORMAL     0
79# define img_STYLE_DIVING     1
80# define img_STYLE_CARTESIAN  2
81# define img_STYLE_CYLPOLAR   3
82# define img_STYLE_NOSURVEY   4
83
84/* 3D coordinates (in metres) */
85typedef struct {
86   double x, y, z;
87} img_point;
88
89typedef struct {
90   /* members you can access when reading (don't touch when writing) */
91   char *label;
92   int flags;
93   char *title;
94   /* If the coordinate system was specified, this contains a PROJ4 string
95    * describing it.  If not, this member will be NULL.
96    */
97   char *cs;
98   /* Older .3d format versions stored a human readable datestamp string.
99    * Format versions >= 8 versions store a string consisting of "@" followed
100    * by the number of seconds since midnight UTC on 1/1/1970.  Some foreign
101    * formats contain a human readable string, others no date information
102    * (which results in "?" being returned).
103    */
104   char *datestamp;
105   /* The datestamp as a time_t (or (time_t)-1 if not available).
106    *
107    * For 3d format versions >= 8, this is a reliable value and in UTC.  Older
108    * 3d format versions store a human readable time, which img will attempt
109    * to decode, but it may fail, particularly with handling timezones.  Even
110    * if it does work, beware that times in local time where DST applies are
111    * inherently ambiguous around when the clocks go back.
112    *
113    * CMAP XYZ files contain a timestamp.  It's probably in localtime (but
114    * without any timezone information) and the example files are all pre-2000
115    * and have two digit years.  We do our best to turn these into a useful
116    * time_t value.
117    */
118   time_t datestamp_numeric;
119   char separator; /* character used to separate survey levels ('.' usually) */
120#if IMG_API_VERSION == 0
121   time_t date1, date2;
122#else /* IMG_API_VERSION == 1 */
123   int days1, days2;
124#endif
125   double l, r, u, d;
126   /* Error information - valid when IMG_ERROR is returned: */
127   int n_legs;
128   double length;
129   double E, H, V;
130   /* The filename actually opened (e.g. may have ".3d" added). */
131   char * filename_opened;
132   int is_extended_elevation;
133   /* The style of the data - one of the img_STYLE_* constants above */
134   int style;
135
136   /* all other members are for internal use only */
137   FILE *fh;          /* file handle of image file */
138   char *label_buf;
139   size_t buf_len;
140   size_t label_len;
141   int fRead;        /* 1 for reading, 0 for writing */
142   long start;
143   /* version of file format:
144    *  -4 => CMAP .xyz file, shot format
145    *  -3 => CMAP .xyz file, station format
146    *  -2 => Compass .plt file
147    *  -1 => .pos file
148    *   0 => 0.01 ascii
149    *   1 => 0.01 binary,
150    *   2 => byte actions and flags
151    *   3 => prefixes for legs; compressed prefixes
152    *   4 => survey date
153    *   5 => LRUD info
154    *   6 => error info
155    *   7 => more compact dates with wider range
156    *   8 => lots of changes
157    */
158   int version;
159   char *survey;
160   size_t survey_len;
161   int pending; /* for old style text format files and survey filtering */
162   img_point mv;
163#if IMG_API_VERSION == 0
164   time_t olddate1, olddate2;
165#else /* IMG_API_VERSION == 1 */
166   int olddays1, olddays2;
167#endif
168   int oldstyle;
169} img;
170
171/* Which version of the file format to output (defaults to newest) */
172extern unsigned int img_output_version;
173
174/* Minimum supported value for img_output_version: */
175#define IMG_VERSION_MIN 1
176
177/* Maximum supported value for img_output_version: */
178#define IMG_VERSION_MAX 8
179
180/* Open a .3d file for reading
181 * fnm is the filename
182 * Returns pointer to an img struct or NULL
183 */
184#define img_open(F) img_open_survey((F), NULL)
185
186/* Open a .3d file for reading
187 * fnm is the filename
188 * Returns pointer to an img struct or NULL
189 * survey points to a survey name to restrict reading to (or NULL for all
190 * survey data in the file)
191 */
192img *img_open_survey(const char *fnm, const char *survey);
193
194/* Open a .3d file for output
195 * fnm is the filename
196 * title is the title
197 * flags contains a bitwise-or of any file-wide flags - currently only one
198 * is available: img_FFLAG_EXTENDED.  (The third parameter used to be
199 * 'fBinary', but has been ignored for many years, so the parameter has
200 * been repurposed for flags - for this reason, img.c deliberately ignores bit
201 * 1 being set, but callers should be written/updated not to set it).
202 *
203 * Returns pointer to an img struct or NULL for error (check img_error()
204 * for details)
205 */
206#define img_open_write(F, T, S) img_open_write_cs(F, T, NULL, S)
207
208/* Open a .3d file for output in a specified coordinate system
209 * fnm is the filename
210 * title is the title
211 * cs is a PROJ4 string describing the coordinate system (or NULL)
212 * flags contains a bitwise-or of any file-wide flags - currently only one
213 * is available: img_FFLAG_EXTENDED.
214 *
215 * Returns pointer to an img struct or NULL for error (check img_error()
216 * for details)
217 */
218img *img_open_write_cs(const char *fnm, const char *title, const char * cs,
219                       int flags);
220
221/* Read an item from a .3d file
222 * pimg is a pointer to an img struct returned by img_open()
223 * coordinates are returned in p
224 * flags and label name are returned in fields in pimg
225 * Returns img_XXXX as #define-d above
226 */
227int img_read_item(img *pimg, img_point *p);
228
229/* Write a item to a .3d file
230 * pimg is a pointer to an img struct returned by img_open_write()
231 * code is one of the img_XXXX #define-d above
232 * flags is the leg, station, or xsect flags
233 * (meaningful for img_LINE, img_LABEL, and img_XSECT respectively)
234 * s is the label (only meaningful for img_LABEL)
235 * x, y, z are the coordinates
236 */
237void img_write_item(img *pimg, int code, int flags, const char *s,
238                    double x, double y, double z);
239
240/* Write error information for the current traverse
241 * n_legs is the number of legs in the traverse
242 * length is the traverse length (in m)
243 * E is the ratio of the observed misclosure to the theoretical one
244 * H is the ratio of the observed horizontal misclosure to the theoretical one
245 * V is the ratio of the observed vertical misclosure to the theoretical one
246 */
247void img_write_errors(img *pimg, int n_legs, double length,
248                      double E, double H, double V);
249
250/* rewind a .3d file opened for reading so the data can be read in
251 * several passes
252 * pimg is a pointer to an img struct returned by img_open()
253 * Returns: non-zero for success, zero for error (check img_error() for
254 *   details)
255 */
256int img_rewind(img *pimg);
257
258/* Close a .3d file
259 * pimg is a pointer to an img struct returned by img_open() or
260 *   img_open_write()
261 * Returns: non-zero for success, zero for error (check img_error() for
262 *   details)
263 */
264int img_close(img *pimg);
265
266/* Codes returned by img_error */
267typedef enum {
268   IMG_NONE = 0, IMG_FILENOTFOUND, IMG_OUTOFMEMORY,
269   IMG_CANTOPENOUT, IMG_BADFORMAT, IMG_DIRECTORY,
270   IMG_READERROR, IMG_WRITEERROR, IMG_TOONEW
271} img_errcode;
272
273/* Read the error code
274 * If img_open(), img_open_survey() or img_open_write() returns NULL, or
275 * img_rewind() or img_close() returns 0, or img_read_item() returns img_BAD
276 * then you can call this function to discover why.
277 */
278img_errcode img_error(void);
279
280#ifdef __cplusplus
281}
282#endif
283
284#endif
Note: See TracBrowser for help on using the repository browser.