source: git/src/img.h @ 1ee204e

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

doc/3dformat.htm,lib/messages.txt,src/,tests/: New v7 of .3d format
which stores survey dates as number of days since Jan 1st 1900, so
we now support dates from 1900-2078 (rather than 1970-2037) with a
smaller file size. The img API is now versioned - you can select
the new "version 1" by compiling with -DIMG_API_VERSION=1, which
gives the survey dates in days in days1 and days2 instead of as
time_t values in date1 and date2. Fixes ticket#14.

git-svn-id: file:///home/survex-svn/survex/trunk@3519 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100644
File size: 6.8 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
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# 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) */
73typedef struct {
74   double x, y, z;
75} img_point;
76
77typedef 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) */
135extern unsigned int img_output_version;
136
137/* Open a .3d file for reading
138 * fnm is the filename
139 * Returns pointer to an img struct or NULL
140 */
141#define img_open(F) img_open_survey((F), NULL)
142
143/* Open a .3d file for reading
144 * fnm is the filename
145 * Returns pointer to an img struct or NULL
146 * survey points to a survey name to restrict reading to (or NULL for all
147 * survey data in the file)
148 */
149img *img_open_survey(const char *fnm, const char *survey);
150
151/* Open a .3d file for output
152 * fnm is the filename
153 * title_buf is the title
154 * fBinary is ignored (it used to select an ASCII variant of the earliest
155 * version of the 3d file format)
156 * Returns pointer to an img struct or NULL for error (check img_error()
157 * for details)
158 */
159# ifdef IMG_HOSTED
160img *img_open_write(const char *fnm, char *title_buf, bool fBinary);
161# else
162img *img_open_write(const char *fnm, char *title_buf, int fBinary);
163# endif
164
165/* Read an item from a .3d file
166 * pimg is a pointer to an img struct returned by img_open()
167 * coordinates are returned in p
168 * flags and label name are returned in fields in pimg
169 * Returns img_XXXX as #define-d above
170 */
171int img_read_item(img *pimg, img_point *p);
172
173/* Write a item to a .3d file
174 * pimg is a pointer to an img struct returned by img_open_write()
175 * code is one of the img_XXXX #define-d above
176 * flags is the leg, station, or xsect flags
177 * (meaningful for img_LINE, img_LABEL, and img_XSECT respectively)
178 * s is the label (only meaningful for img_LABEL)
179 * x, y, z are the coordinates
180 */
181void img_write_item(img *pimg, int code, int flags, const char *s,
182                    double x, double y, double z);
183
184/* Write error information for the current traverse
185 * n_legs is the number of legs in the traverse
186 * length is the traverse length (in m)
187 * E is the ratio of the observed misclosure to the theoretical one
188 * H is the ratio of the observed horizontal misclosure to the theoretical one
189 * V is the ratio of the observed vertical misclosure to the theoretical one
190 */
191void img_write_errors(img *pimg, int n_legs, double length,
192                      double E, double H, double V);
193
194/* rewind a .3d file opened for reading so the data can be read in
195 * several passes
196 * pimg is a pointer to an img struct returned by img_open()
197 * Returns: non-zero for success, zero for error (check img_error() for
198 *   details)
199 */
200int img_rewind(img *pimg);
201
202/* Close a .3d file
203 * pimg is a pointer to an img struct returned by img_open() or
204 *   img_open_write()
205 * Returns: non-zero for success, zero for error (check img_error() for
206 *   details)
207 */
208int img_close(img *pimg);
209
210/* Codes returned by img_error */
211# ifndef IMG_HOSTED
212typedef enum {
213   IMG_NONE = 0, IMG_FILENOTFOUND, IMG_OUTOFMEMORY,
214   IMG_CANTOPENOUT, IMG_BADFORMAT, IMG_DIRECTORY,
215   IMG_READERROR, IMG_WRITEERROR, IMG_TOONEW
216} img_errcode;
217
218/* Read the error code
219 * if img_open() or img_open_write() returns NULL, you can call this
220 * to discover why */
221img_errcode img_error(void);
222# else
223int img_error(void);
224# endif
225
226#ifdef __cplusplus
227}
228#endif
229
230#endif
Note: See TracBrowser for help on using the repository browser.