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

RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-datawalls-data-hanging-as-warning
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
RevLine 
[421b7d2]1/* img.h
[d1b1380]2 * Header file for routines to read and write Survex ".3d" image files
[1ee204e]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
[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]37extern "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]73typedef struct {
[a9f5117]74   double x, y, z;
[0ed0e16]75} img_point;
[421b7d2]76
[d1b1380]77typedef 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) */
135extern unsigned int img_output_version;
136
[0ed0e16]137/* Open a .3d file for reading
[d1b1380]138 * fnm is the filename
139 * Returns pointer to an img struct or NULL
140 */
[a2ad284]141#define img_open(F) img_open_survey((F), NULL)
[76bbb7c9]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 */
[a2ad284]149img *img_open_survey(const char *fnm, const char *survey);
[d1b1380]150
151/* Open a .3d file for output
152 * fnm is the filename
[95c3272]153 * title_buf is the title
[27b8b59]154 * fBinary is ignored (it used to select an ASCII variant of the earliest
155 * version of the 3d file format)
[ad9a5cd]156 * Returns pointer to an img struct or NULL for error (check img_error()
157 * for details)
[d1b1380]158 */
[72af530]159# ifdef IMG_HOSTED
[95c3272]160img *img_open_write(const char *fnm, char *title_buf, bool fBinary);
[d1b1380]161# else
[95c3272]162img *img_open_write(const char *fnm, char *title_buf, int fBinary);
[d1b1380]163# endif
164
[0ed0e16]165/* Read an item from a .3d file
[d1b1380]166 * pimg is a pointer to an img struct returned by img_open()
[0ed0e16]167 * coordinates are returned in p
[23f7ea7]168 * flags and label name are returned in fields in pimg
[d1b1380]169 * Returns img_XXXX as #define-d above
170 */
[23f7ea7]171int img_read_item(img *pimg, img_point *p);
[d1b1380]172
[0ed0e16]173/* Write a item to a .3d file
[d1b1380]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
[ee05463]176 * flags is the leg, station, or xsect flags
177 * (meaningful for img_LINE, img_LABEL, and img_XSECT respectively)
[95c3272]178 * s is the label (only meaningful for img_LABEL)
[0ed0e16]179 * x, y, z are the coordinates
[d1b1380]180 */
[95c3272]181void img_write_item(img *pimg, int code, int flags, const char *s,
[a9f5117]182                    double x, double y, double z);
[f2588ca]183
[c61aa79]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
[f2588ca]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()
[9f3e5df]197 * Returns: non-zero for success, zero for error (check img_error() for
198 *   details)
[f2588ca]199 */
[9f3e5df]200int img_rewind(img *pimg);
[f2588ca]201
[d1b1380]202/* Close a .3d file
203 * pimg is a pointer to an img struct returned by img_open() or
204 *   img_open_write()
[ad9a5cd]205 * Returns: non-zero for success, zero for error (check img_error() for
206 *   details)
[d1b1380]207 */
[ad9a5cd]208int img_close(img *pimg);
[d1b1380]209
210/* Codes returned by img_error */
[72af530]211# ifndef IMG_HOSTED
[a420b49]212typedef enum {
213   IMG_NONE = 0, IMG_FILENOTFOUND, IMG_OUTOFMEMORY,
[ad9a5cd]214   IMG_CANTOPENOUT, IMG_BADFORMAT, IMG_DIRECTORY,
[6c1c4f3]215   IMG_READERROR, IMG_WRITEERROR, IMG_TOONEW
[a420b49]216} img_errcode;
[d1b1380]217
218/* Read the error code
219 * if img_open() or img_open_write() returns NULL, you can call this
[a420b49]220 * to discover why */
221img_errcode img_error(void);
[d1b1380]222# else
[a420b49]223int img_error(void);
[d1b1380]224# endif
225
[8df22e9]226#ifdef __cplusplus
[f2daf3b]227}
228#endif
229
[d1b1380]230#endif
Note: See TracBrowser for help on using the repository browser.