source: git/src/img.h @ 6a6cb97

RELEASE/1.0
Last change on this file since 6a6cb97 was 6a6cb97, checked in by Olly Betts <olly@…>, 14 years ago

src/img.c,src/img.h: Update to the version from 1.1.13 so that we
can read version 6 .3d files written by newer 1.1.x releases.
src/dump3d.c,src/extend.c,src/netskel.c: Set img_output_version to 3
before writing out a .3d file for compatibility with older 1.0.x
releases. We don't use any of the newer features, so there's no
benefit to using a newer format version.

git-svn-id: file:///home/survex-svn/survex/branches/1.0@3444 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100644
File size: 6.2 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#ifdef __cplusplus
24extern "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# define img_XSECT_END 5
44# define img_ERROR_INFO 6
45
46# define img_FLAG_SURFACE   0x01
47# define img_FLAG_DUPLICATE 0x02
48# define img_FLAG_SPLAY     0x04
49
50# define img_SFLAG_SURFACE     0x01
51# define img_SFLAG_UNDERGROUND 0x02
52# define img_SFLAG_ENTRANCE    0x04
53# define img_SFLAG_EXPORTED    0x08
54# define img_SFLAG_FIXED       0x10
55
56/* No longer used: */
57# define img_XFLAG_END      0x01
58
59/* 3D coordinates (in metres) */
60typedef struct {
61   double x, y, z;
62} img_point;
63
64typedef struct {
65   /* members you can access when reading (don't touch when writing) */
66   char *label;
67   int flags;
68   char *title;
69   char *datestamp;
70   char separator; /* character used to separate survey levels ('.' usually) */
71   time_t date1, date2;
72   double l, r, u, d;
73   /* Error information - valid when IMG_ERROR is returned: */
74   int n_legs;
75   double length;
76   double E, H, V;
77   /* The filename actually opened (e.g. may have ".3d" added). */
78   char * filename_opened;
79   int is_extended_elevation;
80   /* all other members are for internal use only */
81   FILE *fh;          /* file handle of image file */
82   char *label_buf;
83   size_t buf_len;
84   size_t label_len;
85# ifdef IMG_HOSTED
86   bool fRead;        /* fTrue for reading, fFalse for writing */
87# else
88   int fRead;        /* fTrue for reading, fFalse for writing */
89# endif
90   long start;
91   /* version of file format:
92    *  -4 => CMAP .xyz file, shot format
93    *  -3 => CMAP .xyz file, station format
94    *  -2 => Compass .plt file
95    *  -1 => .pos file
96    *   0 => 0.01 ascii
97    *   1 => 0.01 binary,
98    *   2 => byte actions and flags
99    *   3 => prefixes for legs; compressed prefixes
100    *   4 => survey date
101    *   5 => LRUD info
102    *   6 => error info
103    */
104   int version;
105   char *survey;
106   size_t survey_len;
107   int pending; /* for old style text format files and survey filtering */
108   img_point mv;
109   time_t olddate1, olddate2;
110} img;
111
112/* Which version of the file format to output (defaults to newest) */
113extern unsigned int img_output_version;
114
115/* Open a .3d file for reading
116 * fnm is the filename
117 * Returns pointer to an img struct or NULL
118 */
119#define img_open(F) img_open_survey((F), NULL)
120
121/* Open a .3d file for reading
122 * fnm is the filename
123 * Returns pointer to an img struct or NULL
124 * survey points to a survey name to restrict reading to (or NULL for all
125 * survey data in the file)
126 */
127img *img_open_survey(const char *fnm, const char *survey);
128
129/* Open a .3d file for output
130 * fnm is the filename
131 * title_buf is the title
132 * fBinary is ignored (it used to select an ASCII variant of the earliest
133 * version of the 3d file format)
134 * Returns pointer to an img struct or NULL for error (check img_error()
135 * for details)
136 */
137# ifdef IMG_HOSTED
138img *img_open_write(const char *fnm, char *title_buf, bool fBinary);
139# else
140img *img_open_write(const char *fnm, char *title_buf, int fBinary);
141# endif
142
143/* Read an item from a .3d file
144 * pimg is a pointer to an img struct returned by img_open()
145 * coordinates are returned in p
146 * flags and label name are returned in fields in pimg
147 * Returns img_XXXX as #define-d above
148 */
149int img_read_item(img *pimg, img_point *p);
150
151/* Write a item to a .3d file
152 * pimg is a pointer to an img struct returned by img_open_write()
153 * code is one of the img_XXXX #define-d above
154 * flags is the leg, station, or xsect flags
155 * (meaningful for img_LINE, img_LABEL, and img_XSECT respectively)
156 * s is the label (only meaningful for img_LABEL)
157 * x, y, z are the coordinates
158 */
159void img_write_item(img *pimg, int code, int flags, const char *s,
160                    double x, double y, double z);
161
162/* Write error information for the current traverse
163 * n_legs is the number of legs in the traverse
164 * length is the traverse length (in m)
165 * E is the ratio of the observed misclosure to the theoretical one
166 * H is the ratio of the observed horizontal misclosure to the theoretical one
167 * V is the ratio of the observed vertical misclosure to the theoretical one
168 */
169void img_write_errors(img *pimg, int n_legs, double length,
170                      double E, double H, double V);
171
172/* rewind a .3d file opened for reading so the data can be read in
173 * several passes
174 * pimg is a pointer to an img struct returned by img_open()
175 * Returns: non-zero for success, zero for error (check img_error() for
176 *   details)
177 */
178int img_rewind(img *pimg);
179
180/* Close a .3d file
181 * pimg is a pointer to an img struct returned by img_open() or
182 *   img_open_write()
183 * Returns: non-zero for success, zero for error (check img_error() for
184 *   details)
185 */
186int img_close(img *pimg);
187
188/* Codes returned by img_error */
189# ifndef IMG_HOSTED
190typedef enum {
191   IMG_NONE = 0, IMG_FILENOTFOUND, IMG_OUTOFMEMORY,
192   IMG_CANTOPENOUT, IMG_BADFORMAT, IMG_DIRECTORY,
193   IMG_READERROR, IMG_WRITEERROR, IMG_TOONEW
194} img_errcode;
195
196/* Read the error code
197 * if img_open() or img_open_write() returns NULL, you can call this
198 * to discover why */
199img_errcode img_error(void);
200# else
201int img_error(void);
202# endif
203
204#ifdef __cplusplus
205}
206#endif
207
208#endif
Note: See TracBrowser for help on using the repository browser.