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
RevLine 
[421b7d2]1/* img.h
[d1b1380]2 * Header file for routines to read and write Survex ".3d" image files
[6a6cb97]3 * Copyright (C) Olly Betts 1993,1994,1997,2001,2002,2003,2004,2005,2006,2010
[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
[6a6cb97]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
[8df22e9]23#ifdef __cplusplus
[f2daf3b]24extern "C" {
25#endif
26
[0d2b588]27#include <stdio.h>
[76d0b1e]28#include <time.h> /* for time_t */
[0d2b588]29
[72af530]30# ifdef IMG_HOSTED
[d1b1380]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
[437caf3]38/* NB: img_CROSS is never output and ignored on input.
[0ff23cb]39 * Put crosses where labels are. */
40/* # define img_CROSS  2 */
[d1b1380]41# define img_LABEL  3
[76d0b1e]42# define img_XSECT  4
[6a6cb97]43# define img_XSECT_END 5
44# define img_ERROR_INFO 6
[5c3c61a]45
46# define img_FLAG_SURFACE   0x01
47# define img_FLAG_DUPLICATE 0x02
[95c3272]48# define img_FLAG_SPLAY     0x04
[d1b1380]49
[5cb0e72]50# define img_SFLAG_SURFACE     0x01
51# define img_SFLAG_UNDERGROUND 0x02
[dfb4240]52# define img_SFLAG_ENTRANCE    0x04
53# define img_SFLAG_EXPORTED    0x08
54# define img_SFLAG_FIXED       0x10
[5cb0e72]55
[6a6cb97]56/* No longer used: */
[76d0b1e]57# define img_XFLAG_END      0x01
58
[0874569e]59/* 3D coordinates (in metres) */
[0ed0e16]60typedef struct {
[a9f5117]61   double x, y, z;
[0ed0e16]62} img_point;
[421b7d2]63
[d1b1380]64typedef struct {
[6f6356c4]65   /* members you can access when reading (don't touch when writing) */
[23f7ea7]66   char *label;
[5c3c61a]67   int flags;
[a2ad284]68   char *title;
69   char *datestamp;
[168df28]70   char separator; /* character used to separate survey levels ('.' usually) */
[76d0b1e]71   time_t date1, date2;
72   double l, r, u, d;
[6a6cb97]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;
[5c3c61a]80   /* all other members are for internal use only */
[a420b49]81   FILE *fh;          /* file handle of image file */
[0ff23cb]82   char *label_buf;
[23f7ea7]83   size_t buf_len;
[d69255f]84   size_t label_len;
[72af530]85# ifdef IMG_HOSTED
[a420b49]86   bool fRead;        /* fTrue for reading, fFalse for writing */
[d1b1380]87# else
[a420b49]88   int fRead;        /* fTrue for reading, fFalse for writing */
[d1b1380]89# endif
[f2588ca]90   long start;
[0da6e60]91   /* version of file format:
[f1c7c9c7]92    *  -4 => CMAP .xyz file, shot format
93    *  -3 => CMAP .xyz file, station format
[ad4eaf3f]94    *  -2 => Compass .plt file
[0da6e60]95    *  -1 => .pos file
96    *   0 => 0.01 ascii
97    *   1 => 0.01 binary,
98    *   2 => byte actions and flags
[ad4eaf3f]99    *   3 => prefixes for legs; compressed prefixes
[76d0b1e]100    *   4 => survey date
101    *   5 => LRUD info
[6a6cb97]102    *   6 => error info
[0da6e60]103    */
[5c3c61a]104   int version;
[76bbb7c9]105   char *survey;
106   size_t survey_len;
107   int pending; /* for old style text format files and survey filtering */
108   img_point mv;
[76d0b1e]109   time_t olddate1, olddate2;
[d1b1380]110} img;
111
[5c3c61a]112/* Which version of the file format to output (defaults to newest) */
113extern unsigned int img_output_version;
114
[0ed0e16]115/* Open a .3d file for reading
[d1b1380]116 * fnm is the filename
117 * Returns pointer to an img struct or NULL
118 */
[a2ad284]119#define img_open(F) img_open_survey((F), NULL)
[76bbb7c9]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 */
[a2ad284]127img *img_open_survey(const char *fnm, const char *survey);
[d1b1380]128
129/* Open a .3d file for output
130 * fnm is the filename
[95c3272]131 * title_buf is the title
[bde0a4c]132 * fBinary is ignored (it used to select an ASCII variant of the earliest
133 * version of the 3d file format)
[ad9a5cd]134 * Returns pointer to an img struct or NULL for error (check img_error()
135 * for details)
[d1b1380]136 */
[72af530]137# ifdef IMG_HOSTED
[95c3272]138img *img_open_write(const char *fnm, char *title_buf, bool fBinary);
[d1b1380]139# else
[95c3272]140img *img_open_write(const char *fnm, char *title_buf, int fBinary);
[d1b1380]141# endif
142
[0ed0e16]143/* Read an item from a .3d file
[d1b1380]144 * pimg is a pointer to an img struct returned by img_open()
[0ed0e16]145 * coordinates are returned in p
[23f7ea7]146 * flags and label name are returned in fields in pimg
[d1b1380]147 * Returns img_XXXX as #define-d above
148 */
[23f7ea7]149int img_read_item(img *pimg, img_point *p);
[d1b1380]150
[0ed0e16]151/* Write a item to a .3d file
[d1b1380]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
[76d0b1e]154 * flags is the leg, station, or xsect flags
155 * (meaningful for img_LINE, img_LABEL, and img_XSECT respectively)
[95c3272]156 * s is the label (only meaningful for img_LABEL)
[0ed0e16]157 * x, y, z are the coordinates
[d1b1380]158 */
[95c3272]159void img_write_item(img *pimg, int code, int flags, const char *s,
[a9f5117]160                    double x, double y, double z);
[f2588ca]161
[6a6cb97]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
[f2588ca]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()
[9f3e5df]175 * Returns: non-zero for success, zero for error (check img_error() for
176 *   details)
[f2588ca]177 */
[9f3e5df]178int img_rewind(img *pimg);
[f2588ca]179
[d1b1380]180/* Close a .3d file
181 * pimg is a pointer to an img struct returned by img_open() or
182 *   img_open_write()
[ad9a5cd]183 * Returns: non-zero for success, zero for error (check img_error() for
184 *   details)
[d1b1380]185 */
[ad9a5cd]186int img_close(img *pimg);
[d1b1380]187
188/* Codes returned by img_error */
[72af530]189# ifndef IMG_HOSTED
[a420b49]190typedef enum {
191   IMG_NONE = 0, IMG_FILENOTFOUND, IMG_OUTOFMEMORY,
[ad9a5cd]192   IMG_CANTOPENOUT, IMG_BADFORMAT, IMG_DIRECTORY,
[6c1c4f3]193   IMG_READERROR, IMG_WRITEERROR, IMG_TOONEW
[a420b49]194} img_errcode;
[d1b1380]195
196/* Read the error code
197 * if img_open() or img_open_write() returns NULL, you can call this
[a420b49]198 * to discover why */
199img_errcode img_error(void);
[d1b1380]200# else
[a420b49]201int img_error(void);
[d1b1380]202# endif
203
[8df22e9]204#ifdef __cplusplus
[f2daf3b]205}
206#endif
207
[d1b1380]208#endif
Note: See TracBrowser for help on using the repository browser.