[421b7d2] | 1 | /* img.h |
---|
[d1b1380] | 2 | * Header file for routines to read and write Survex ".3d" image files |
---|
[2bb17c9] | 3 | * Copyright (C) Olly Betts 1993,1994,1997,2001,2002,2003,2004,2005,2006,2010,2011 |
---|
[846746e] | 4 | * |
---|
[89231c4] | 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. |
---|
[846746e] | 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 |
---|
[89231c4] | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 13 | * GNU General Public License for more details. |
---|
[846746e] | 14 | * |
---|
[89231c4] | 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 |
---|
[d7d7fa7] | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
[d1b1380] | 18 | */ |
---|
| 19 | |
---|
| 20 | #ifndef IMG_H |
---|
| 21 | # define IMG_H |
---|
| 22 | |
---|
[1ee204e] | 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 | |
---|
[8df22e9] | 36 | #ifdef __cplusplus |
---|
[f2daf3b] | 37 | extern "C" { |
---|
| 38 | #endif |
---|
| 39 | |
---|
[0d2b588] | 40 | #include <stdio.h> |
---|
[dfb7670] | 41 | #include <time.h> /* for time_t */ |
---|
[0d2b588] | 42 | |
---|
[72af530] | 43 | # ifdef IMG_HOSTED |
---|
[d1b1380] | 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 |
---|
[437caf3] | 51 | /* NB: img_CROSS is never output and ignored on input. |
---|
[0ff23cb] | 52 | * Put crosses where labels are. */ |
---|
| 53 | /* # define img_CROSS 2 */ |
---|
[d1b1380] | 54 | # define img_LABEL 3 |
---|
[ee05463] | 55 | # define img_XSECT 4 |
---|
[d7d7fa7] | 56 | # define img_XSECT_END 5 |
---|
[c61aa79] | 57 | # define img_ERROR_INFO 6 |
---|
[5c3c61a] | 58 | |
---|
| 59 | # define img_FLAG_SURFACE 0x01 |
---|
| 60 | # define img_FLAG_DUPLICATE 0x02 |
---|
[95c3272] | 61 | # define img_FLAG_SPLAY 0x04 |
---|
[d1b1380] | 62 | |
---|
[5cb0e72] | 63 | # define img_SFLAG_SURFACE 0x01 |
---|
| 64 | # define img_SFLAG_UNDERGROUND 0x02 |
---|
[dfb4240] | 65 | # define img_SFLAG_ENTRANCE 0x04 |
---|
| 66 | # define img_SFLAG_EXPORTED 0x08 |
---|
| 67 | # define img_SFLAG_FIXED 0x10 |
---|
[5cb0e72] | 68 | |
---|
[d7d7fa7] | 69 | /* No longer used: */ |
---|
[ee05463] | 70 | # define img_XFLAG_END 0x01 |
---|
| 71 | |
---|
[be97baf] | 72 | /* 3D coordinates (in metres) */ |
---|
[0ed0e16] | 73 | typedef struct { |
---|
[a9f5117] | 74 | double x, y, z; |
---|
[0ed0e16] | 75 | } img_point; |
---|
[421b7d2] | 76 | |
---|
[d1b1380] | 77 | typedef struct { |
---|
[6f6356c4] | 78 | /* members you can access when reading (don't touch when writing) */ |
---|
[23f7ea7] | 79 | char *label; |
---|
[5c3c61a] | 80 | int flags; |
---|
[a2ad284] | 81 | char *title; |
---|
| 82 | char *datestamp; |
---|
[eef68f9] | 83 | char separator; /* character used to separate survey levels ('.' usually) */ |
---|
[1ee204e] | 84 | #if IMG_API_VERSION == 0 |
---|
[b5a3219] | 85 | time_t date1, date2; |
---|
[1ee204e] | 86 | #else /* IMG_API_VERSION == 1 */ |
---|
| 87 | int days1, days2; |
---|
| 88 | #endif |
---|
[ee7af72] | 89 | double l, r, u, d; |
---|
[c61aa79] | 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; |
---|
[eef68f9] | 96 | int is_extended_elevation; |
---|
[5c3c61a] | 97 | /* all other members are for internal use only */ |
---|
[a420b49] | 98 | FILE *fh; /* file handle of image file */ |
---|
[0ff23cb] | 99 | char *label_buf; |
---|
[23f7ea7] | 100 | size_t buf_len; |
---|
[d69255f] | 101 | size_t label_len; |
---|
[72af530] | 102 | # ifdef IMG_HOSTED |
---|
[a420b49] | 103 | bool fRead; /* fTrue for reading, fFalse for writing */ |
---|
[d1b1380] | 104 | # else |
---|
[a420b49] | 105 | int fRead; /* fTrue for reading, fFalse for writing */ |
---|
[d1b1380] | 106 | # endif |
---|
[f2588ca] | 107 | long start; |
---|
[0da6e60] | 108 | /* version of file format: |
---|
[f1c7c9c7] | 109 | * -4 => CMAP .xyz file, shot format |
---|
| 110 | * -3 => CMAP .xyz file, station format |
---|
[ad4eaf3f] | 111 | * -2 => Compass .plt file |
---|
[0da6e60] | 112 | * -1 => .pos file |
---|
| 113 | * 0 => 0.01 ascii |
---|
| 114 | * 1 => 0.01 binary, |
---|
| 115 | * 2 => byte actions and flags |
---|
[ad4eaf3f] | 116 | * 3 => prefixes for legs; compressed prefixes |
---|
[b5a3219] | 117 | * 4 => survey date |
---|
[f4c5932] | 118 | * 5 => LRUD info |
---|
[c61aa79] | 119 | * 6 => error info |
---|
[1ee204e] | 120 | * 7 => more compact dates with wider range |
---|
[0da6e60] | 121 | */ |
---|
[5c3c61a] | 122 | int version; |
---|
[76bbb7c9] | 123 | char *survey; |
---|
| 124 | size_t survey_len; |
---|
| 125 | int pending; /* for old style text format files and survey filtering */ |
---|
| 126 | img_point mv; |
---|
[1ee204e] | 127 | #if IMG_API_VERSION == 0 |
---|
[ee05463] | 128 | time_t olddate1, olddate2; |
---|
[1ee204e] | 129 | #else /* IMG_API_VERSION == 1 */ |
---|
| 130 | int olddays1, olddays2; |
---|
| 131 | #endif |
---|
[d1b1380] | 132 | } img; |
---|
| 133 | |
---|
[5c3c61a] | 134 | /* Which version of the file format to output (defaults to newest) */ |
---|
| 135 | extern unsigned int img_output_version; |
---|
| 136 | |
---|
[2bb17c9] | 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 | |
---|
[0ed0e16] | 143 | /* Open a .3d file for reading |
---|
[d1b1380] | 144 | * fnm is the filename |
---|
| 145 | * Returns pointer to an img struct or NULL |
---|
| 146 | */ |
---|
[a2ad284] | 147 | #define img_open(F) img_open_survey((F), NULL) |
---|
[76bbb7c9] | 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 | */ |
---|
[a2ad284] | 155 | img *img_open_survey(const char *fnm, const char *survey); |
---|
[d1b1380] | 156 | |
---|
| 157 | /* Open a .3d file for output |
---|
| 158 | * fnm is the filename |
---|
[95c3272] | 159 | * title_buf is the title |
---|
[27b8b59] | 160 | * fBinary is ignored (it used to select an ASCII variant of the earliest |
---|
| 161 | * version of the 3d file format) |
---|
[ad9a5cd] | 162 | * Returns pointer to an img struct or NULL for error (check img_error() |
---|
| 163 | * for details) |
---|
[d1b1380] | 164 | */ |
---|
[72af530] | 165 | # ifdef IMG_HOSTED |
---|
[95c3272] | 166 | img *img_open_write(const char *fnm, char *title_buf, bool fBinary); |
---|
[d1b1380] | 167 | # else |
---|
[95c3272] | 168 | img *img_open_write(const char *fnm, char *title_buf, int fBinary); |
---|
[d1b1380] | 169 | # endif |
---|
| 170 | |
---|
[0ed0e16] | 171 | /* Read an item from a .3d file |
---|
[d1b1380] | 172 | * pimg is a pointer to an img struct returned by img_open() |
---|
[0ed0e16] | 173 | * coordinates are returned in p |
---|
[23f7ea7] | 174 | * flags and label name are returned in fields in pimg |
---|
[d1b1380] | 175 | * Returns img_XXXX as #define-d above |
---|
| 176 | */ |
---|
[23f7ea7] | 177 | int img_read_item(img *pimg, img_point *p); |
---|
[d1b1380] | 178 | |
---|
[0ed0e16] | 179 | /* Write a item to a .3d file |
---|
[d1b1380] | 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 |
---|
[ee05463] | 182 | * flags is the leg, station, or xsect flags |
---|
| 183 | * (meaningful for img_LINE, img_LABEL, and img_XSECT respectively) |
---|
[95c3272] | 184 | * s is the label (only meaningful for img_LABEL) |
---|
[0ed0e16] | 185 | * x, y, z are the coordinates |
---|
[d1b1380] | 186 | */ |
---|
[95c3272] | 187 | void img_write_item(img *pimg, int code, int flags, const char *s, |
---|
[a9f5117] | 188 | double x, double y, double z); |
---|
[f2588ca] | 189 | |
---|
[c61aa79] | 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 | |
---|
[f2588ca] | 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() |
---|
[9f3e5df] | 203 | * Returns: non-zero for success, zero for error (check img_error() for |
---|
| 204 | * details) |
---|
[f2588ca] | 205 | */ |
---|
[9f3e5df] | 206 | int img_rewind(img *pimg); |
---|
[f2588ca] | 207 | |
---|
[d1b1380] | 208 | /* Close a .3d file |
---|
| 209 | * pimg is a pointer to an img struct returned by img_open() or |
---|
| 210 | * img_open_write() |
---|
[ad9a5cd] | 211 | * Returns: non-zero for success, zero for error (check img_error() for |
---|
| 212 | * details) |
---|
[d1b1380] | 213 | */ |
---|
[ad9a5cd] | 214 | int img_close(img *pimg); |
---|
[d1b1380] | 215 | |
---|
| 216 | /* Codes returned by img_error */ |
---|
[72af530] | 217 | # ifndef IMG_HOSTED |
---|
[a420b49] | 218 | typedef enum { |
---|
| 219 | IMG_NONE = 0, IMG_FILENOTFOUND, IMG_OUTOFMEMORY, |
---|
[ad9a5cd] | 220 | IMG_CANTOPENOUT, IMG_BADFORMAT, IMG_DIRECTORY, |
---|
[6c1c4f3] | 221 | IMG_READERROR, IMG_WRITEERROR, IMG_TOONEW |
---|
[a420b49] | 222 | } img_errcode; |
---|
[d1b1380] | 223 | |
---|
| 224 | /* Read the error code |
---|
| 225 | * if img_open() or img_open_write() returns NULL, you can call this |
---|
[a420b49] | 226 | * to discover why */ |
---|
| 227 | img_errcode img_error(void); |
---|
[d1b1380] | 228 | # else |
---|
[a420b49] | 229 | int img_error(void); |
---|
[d1b1380] | 230 | # endif |
---|
| 231 | |
---|
[8df22e9] | 232 | #ifdef __cplusplus |
---|
[f2daf3b] | 233 | } |
---|
| 234 | #endif |
---|
| 235 | |
---|
[d1b1380] | 236 | #endif |
---|