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 |
---|
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
18 | */ |
---|
19 | |
---|
20 | #ifndef IMG_H |
---|
21 | # define IMG_H |
---|
22 | |
---|
23 | #ifdef __cplusplus |
---|
24 | extern "C" { |
---|
25 | #endif |
---|
26 | |
---|
27 | #include <stdio.h> |
---|
28 | #include <time.h> /* for time_t */ |
---|
29 | |
---|
30 | # ifdef IMG_HOSTED |
---|
31 | # include "useful.h" |
---|
32 | # endif |
---|
33 | |
---|
34 | # define img_BAD -2 |
---|
35 | # define img_STOP -1 |
---|
36 | # define img_MOVE 0 |
---|
37 | # define img_LINE 1 |
---|
38 | /* NB: img_CROSS is never output and ignored on input. |
---|
39 | * Put crosses where labels are. */ |
---|
40 | /* # define img_CROSS 2 */ |
---|
41 | # define img_LABEL 3 |
---|
42 | # define img_XSECT 4 |
---|
43 | |
---|
44 | # define img_FLAG_SURFACE 0x01 |
---|
45 | # define img_FLAG_DUPLICATE 0x02 |
---|
46 | # define img_FLAG_SPLAY 0x04 |
---|
47 | |
---|
48 | # define img_SFLAG_SURFACE 0x01 |
---|
49 | # define img_SFLAG_UNDERGROUND 0x02 |
---|
50 | # define img_SFLAG_ENTRANCE 0x04 |
---|
51 | # define img_SFLAG_EXPORTED 0x08 |
---|
52 | # define img_SFLAG_FIXED 0x10 |
---|
53 | |
---|
54 | # define img_XFLAG_END 0x01 |
---|
55 | |
---|
56 | /* 3D coordinates (in metres) */ |
---|
57 | typedef struct { |
---|
58 | double x, y, z; |
---|
59 | } img_point; |
---|
60 | |
---|
61 | typedef struct { |
---|
62 | /* members you can access when reading (don't touch when writing) */ |
---|
63 | char *label; |
---|
64 | int flags; |
---|
65 | char *title; |
---|
66 | char *datestamp; |
---|
67 | char separator; /* character used to separate survey levels ('.' usually) */ |
---|
68 | time_t date1, date2; |
---|
69 | double l, r, u, d; |
---|
70 | char * filename_opened; /* The filename actually opened (e.g. may have ".3d" added). */ |
---|
71 | /* all other members are for internal use only */ |
---|
72 | FILE *fh; /* file handle of image file */ |
---|
73 | char *label_buf; |
---|
74 | size_t buf_len; |
---|
75 | size_t label_len; |
---|
76 | # ifdef IMG_HOSTED |
---|
77 | bool fRead; /* fTrue for reading, fFalse for writing */ |
---|
78 | # else |
---|
79 | int fRead; /* fTrue for reading, fFalse for writing */ |
---|
80 | # endif |
---|
81 | long start; |
---|
82 | /* version of file format: |
---|
83 | * -4 => CMAP .xyz file, shot format |
---|
84 | * -3 => CMAP .xyz file, station format |
---|
85 | * -2 => Compass .plt file |
---|
86 | * -1 => .pos file |
---|
87 | * 0 => 0.01 ascii |
---|
88 | * 1 => 0.01 binary, |
---|
89 | * 2 => byte actions and flags |
---|
90 | * 3 => prefixes for legs; compressed prefixes |
---|
91 | * 4 => survey date |
---|
92 | * 5 => LRUD info |
---|
93 | */ |
---|
94 | int version; |
---|
95 | char *survey; |
---|
96 | size_t survey_len; |
---|
97 | int pending; /* for old style text format files and survey filtering */ |
---|
98 | img_point mv; |
---|
99 | time_t olddate1, olddate2; |
---|
100 | } img; |
---|
101 | |
---|
102 | /* Which version of the file format to output (defaults to newest) */ |
---|
103 | extern unsigned int img_output_version; |
---|
104 | |
---|
105 | /* Open a .3d file for reading |
---|
106 | * fnm is the filename |
---|
107 | * Returns pointer to an img struct or NULL |
---|
108 | */ |
---|
109 | #define img_open(F) img_open_survey((F), NULL) |
---|
110 | |
---|
111 | /* Open a .3d file for reading |
---|
112 | * fnm is the filename |
---|
113 | * Returns pointer to an img struct or NULL |
---|
114 | * survey points to a survey name to restrict reading to (or NULL for all |
---|
115 | * survey data in the file) |
---|
116 | */ |
---|
117 | img *img_open_survey(const char *fnm, const char *survey); |
---|
118 | |
---|
119 | /* Open a .3d file for output |
---|
120 | * fnm is the filename |
---|
121 | * title_buf is the title |
---|
122 | * fBinary is ignored (it used to select an ASCII variant of the earliest |
---|
123 | * version of the 3d file format) |
---|
124 | * Returns pointer to an img struct or NULL for error (check img_error() |
---|
125 | * for details) |
---|
126 | */ |
---|
127 | # ifdef IMG_HOSTED |
---|
128 | img *img_open_write(const char *fnm, char *title_buf, bool fBinary); |
---|
129 | # else |
---|
130 | img *img_open_write(const char *fnm, char *title_buf, int fBinary); |
---|
131 | # endif |
---|
132 | |
---|
133 | /* Read an item from a .3d file |
---|
134 | * pimg is a pointer to an img struct returned by img_open() |
---|
135 | * coordinates are returned in p |
---|
136 | * flags and label name are returned in fields in pimg |
---|
137 | * Returns img_XXXX as #define-d above |
---|
138 | */ |
---|
139 | int img_read_item(img *pimg, img_point *p); |
---|
140 | |
---|
141 | /* Write a item to a .3d file |
---|
142 | * pimg is a pointer to an img struct returned by img_open_write() |
---|
143 | * code is one of the img_XXXX #define-d above |
---|
144 | * flags is the leg, station, or xsect flags |
---|
145 | * (meaningful for img_LINE, img_LABEL, and img_XSECT respectively) |
---|
146 | * s is the label (only meaningful for img_LABEL) |
---|
147 | * x, y, z are the coordinates |
---|
148 | */ |
---|
149 | void img_write_item(img *pimg, int code, int flags, const char *s, |
---|
150 | double x, double y, double z); |
---|
151 | |
---|
152 | /* rewind a .3d file opened for reading so the data can be read in |
---|
153 | * several passes |
---|
154 | * pimg is a pointer to an img struct returned by img_open() |
---|
155 | * Returns: non-zero for success, zero for error (check img_error() for |
---|
156 | * details) |
---|
157 | */ |
---|
158 | int img_rewind(img *pimg); |
---|
159 | |
---|
160 | /* Close a .3d file |
---|
161 | * pimg is a pointer to an img struct returned by img_open() or |
---|
162 | * img_open_write() |
---|
163 | * Returns: non-zero for success, zero for error (check img_error() for |
---|
164 | * details) |
---|
165 | */ |
---|
166 | int img_close(img *pimg); |
---|
167 | |
---|
168 | /* Codes returned by img_error */ |
---|
169 | # ifndef IMG_HOSTED |
---|
170 | typedef enum { |
---|
171 | IMG_NONE = 0, IMG_FILENOTFOUND, IMG_OUTOFMEMORY, |
---|
172 | IMG_CANTOPENOUT, IMG_BADFORMAT, IMG_DIRECTORY, |
---|
173 | IMG_READERROR, IMG_WRITEERROR, IMG_TOONEW |
---|
174 | } img_errcode; |
---|
175 | |
---|
176 | /* Read the error code |
---|
177 | * if img_open() or img_open_write() returns NULL, you can call this |
---|
178 | * to discover why */ |
---|
179 | img_errcode img_error(void); |
---|
180 | # else |
---|
181 | int img_error(void); |
---|
182 | # endif |
---|
183 | |
---|
184 | #ifdef __cplusplus |
---|
185 | } |
---|
186 | #endif |
---|
187 | |
---|
188 | #endif |
---|