source: git/src/img.h @ a405bc1

RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-data
Last change on this file since a405bc1 was a405bc1, checked in by Olly Betts <olly@…>, 11 years ago

src/: IMG_HOSTED no longer affects the img API at all.

  • Property mode set to 100644
File size: 7.9 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
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   /* Older .3d format versions stored a human readable datestamp string.
95    * Format versions >= 8 versions store a string consisting of "@" followed
96    * by the number of seconds since midnight UTC on 1/1/1970.  Some foreign
97    * formats contain a human readable string, others no date information
98    * (which results in "?" being returned).
99    */
100   char *datestamp;
101   char separator; /* character used to separate survey levels ('.' usually) */
102#if IMG_API_VERSION == 0
103   time_t date1, date2;
104#else /* IMG_API_VERSION == 1 */
105   int days1, days2;
106#endif
107   double l, r, u, d;
108   /* Error information - valid when IMG_ERROR is returned: */
109   int n_legs;
110   double length;
111   double E, H, V;
112   /* The filename actually opened (e.g. may have ".3d" added). */
113   char * filename_opened;
114   int is_extended_elevation;
115   /* The style of the data - one of the img_STYLE_* constants above */
116   int style;
117
118   /* all other members are for internal use only */
119   FILE *fh;          /* file handle of image file */
120   char *label_buf;
121   size_t buf_len;
122   size_t label_len;
123   int fRead;        /* 1 for reading, 0 for writing */
124   long start;
125   /* version of file format:
126    *  -4 => CMAP .xyz file, shot format
127    *  -3 => CMAP .xyz file, station format
128    *  -2 => Compass .plt file
129    *  -1 => .pos file
130    *   0 => 0.01 ascii
131    *   1 => 0.01 binary,
132    *   2 => byte actions and flags
133    *   3 => prefixes for legs; compressed prefixes
134    *   4 => survey date
135    *   5 => LRUD info
136    *   6 => error info
137    *   7 => more compact dates with wider range
138    *   8 => lots of changes
139    */
140   int version;
141   char *survey;
142   size_t survey_len;
143   int pending; /* for old style text format files and survey filtering */
144   img_point mv;
145#if IMG_API_VERSION == 0
146   time_t olddate1, olddate2;
147#else /* IMG_API_VERSION == 1 */
148   int olddays1, olddays2;
149#endif
150   int oldstyle;
151} img;
152
153/* Which version of the file format to output (defaults to newest) */
154extern unsigned int img_output_version;
155
156/* Minimum supported value for img_output_version: */
157#define IMG_VERSION_MIN 1
158
159/* Maximum supported value for img_output_version: */
160#define IMG_VERSION_MAX 8
161
162/* Open a .3d file for reading
163 * fnm is the filename
164 * Returns pointer to an img struct or NULL
165 */
166#define img_open(F) img_open_survey((F), NULL)
167
168/* Open a .3d file for reading
169 * fnm is the filename
170 * Returns pointer to an img struct or NULL
171 * survey points to a survey name to restrict reading to (or NULL for all
172 * survey data in the file)
173 */
174img *img_open_survey(const char *fnm, const char *survey);
175
176/* Open a .3d file for output
177 * fnm is the filename
178 * title is the title
179 * flags contains a bitwise-or of any file-wide flags - currently only one
180 * is available: img_FFLAG_EXTENDED.  (The third parameter used to be
181 * 'fBinary', but has been ignored for many years, so the parameter has
182 * been repurposed for flags - for this reason, img.c deliberately ignores bit
183 * 1 being set, but callers should be written/updated not to set it).
184 *
185 * Returns pointer to an img struct or NULL for error (check img_error()
186 * for details)
187 */
188img *img_open_write(const char *fnm, char *title, int flags);
189
190/* Read an item from a .3d file
191 * pimg is a pointer to an img struct returned by img_open()
192 * coordinates are returned in p
193 * flags and label name are returned in fields in pimg
194 * Returns img_XXXX as #define-d above
195 */
196int img_read_item(img *pimg, img_point *p);
197
198/* Write a item to a .3d file
199 * pimg is a pointer to an img struct returned by img_open_write()
200 * code is one of the img_XXXX #define-d above
201 * flags is the leg, station, or xsect flags
202 * (meaningful for img_LINE, img_LABEL, and img_XSECT respectively)
203 * s is the label (only meaningful for img_LABEL)
204 * x, y, z are the coordinates
205 */
206void img_write_item(img *pimg, int code, int flags, const char *s,
207                    double x, double y, double z);
208
209/* Write error information for the current traverse
210 * n_legs is the number of legs in the traverse
211 * length is the traverse length (in m)
212 * E is the ratio of the observed misclosure to the theoretical one
213 * H is the ratio of the observed horizontal misclosure to the theoretical one
214 * V is the ratio of the observed vertical misclosure to the theoretical one
215 */
216void img_write_errors(img *pimg, int n_legs, double length,
217                      double E, double H, double V);
218
219/* rewind a .3d file opened for reading so the data can be read in
220 * several passes
221 * pimg is a pointer to an img struct returned by img_open()
222 * Returns: non-zero for success, zero for error (check img_error() for
223 *   details)
224 */
225int img_rewind(img *pimg);
226
227/* Close a .3d file
228 * pimg is a pointer to an img struct returned by img_open() or
229 *   img_open_write()
230 * Returns: non-zero for success, zero for error (check img_error() for
231 *   details)
232 */
233int img_close(img *pimg);
234
235/* Codes returned by img_error */
236typedef enum {
237   IMG_NONE = 0, IMG_FILENOTFOUND, IMG_OUTOFMEMORY,
238   IMG_CANTOPENOUT, IMG_BADFORMAT, IMG_DIRECTORY,
239   IMG_READERROR, IMG_WRITEERROR, IMG_TOONEW
240} img_errcode;
241
242/* Read the error code
243 * If img_open(), img_open_survey() or img_open_write() returns NULL, or
244 * img_rewind() or img_close() returns 0, or img_read_item() returns img_BAD
245 * then you can call this function to discover why.
246 */
247img_errcode img_error(void);
248
249#ifdef __cplusplus
250}
251#endif
252
253#endif
Note: See TracBrowser for help on using the repository browser.