OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
vpftable.h
Go to the documentation of this file.
1 /* ================ SCCS_ID[] = "@(#) vpftable.h 2.2 10/29/91" =================
2 
3  Environmental Systems Research Institute (ESRI) Applications Programming
4 
5  Project: Conversion from ARC/INFO to VPF
6  Original Coding: Barry Michaels April 1991
7  Modifications: David Flinn April 1991
8  Barry June 1991
9  Dave October 1991
10  ======================================================================== */
11 
12 /* VPFTABLE.H */
13 
14 #ifndef _VPF_TABLE_H_
15 
16 #define _VPF_TABLE_H_
17 
18 #include <stdio.h>
19 #include <ossim/vpfutil/machine.h>
20 
21 #include <ossim/ossimConfig.h>
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #ifndef TRUE
27 #define TRUE 1
28 #endif
29 #ifndef FALSE
30 #define FALSE 0
31 #endif
32 
33 /* Possible byte ordering of the data */
34 #define LEAST_SIGNIFICANT 0
35 #define MOST_SIGNIFICANT 1
37 /* The next definition is machine-specific and may need to be changed */
38 /* before recompiling on a different machine */
39 #define MACHINE_BYTE_ORDER (vpfutilMachineByteOrder())
40 
41 
42 
43 #include <ossim/vpfutil/vpfio.h>
44 
45 /* This should be the ISO definition of date */
46 
47 typedef char date_type[21] ; /* Include null end of string */
48 
49 /* NULL valuse type */
50 
51 typedef union {
52  char *Char ;
53  short int Short ;
55  float Float ;
56  double Double ;
58  char Other ;
59 } null_field;
60 
61 /* The basic information carried for each field in the table */
62 typedef struct {
63  char *name; /* Name of the field */
64  char description[81]; /* Field description */
65  char keytype; /* Type of key - (P)rimary, (F)oreign, (N)onkey */
66  char vdt[13]; /* Value description table name */
67  char *tdx; /* Thematic index file name */
68  char type; /* Data type - T,I,F,K,D */
69  ossim_int32 count; /* Number of items in this column (-1 =>variable)*/
70  null_field nullval ; /* This is used for the converter */
71  char *narrative; /* Name of a narrative table describing the field*/
73 
74 typedef enum { ram, disk, either, compute } storage_type;
75 #define RAM 0
76 #define DISK 1
77 #define EITHER 2
78 #define COMPUTE 3
79 
80 typedef enum { Read, Write } file_mode ;
81 
82 #define CLOSED 0
83 #define OPENED 1
84 
85 /* Each column in a table row has a count and a pointer to the data */
86 /* and a null value default */
87 typedef struct {
89  void *ptr;
90 } column_type;
91 
92 /* A table row is an array of columns */
94 
95 /* Index for variable width tables. */
96 /* One index cell for each row in the table. */
97 typedef struct {
101 
102 /* VPF table structure: */
103 typedef struct {
104  char name[13]; /* Name of the VPF table */
105  char *path; /* Directory path to the table */
106  ossim_int32 nfields; /* Number of fields */
107  char description[81]; /* Table description */
108  char narrative[13]; /* Table narrative file name */
109  header_type header; /* Table header structure */
110  FILE *xfp; /* Index file pointer */
111  index_type index; /* Index structure */
112  storage_type xstorage; /* Flag indicating where index stored */
113  FILE *fp; /* Table file pointer */
114  ossim_int32 nrows; /* Number of rows in the table */
115  row_type *row; /* Array of table rows */
116  ossim_int32 reclen; /* Table record length (-1 => variable */
117  ossim_int32 ddlen; /* Data definition string length */
118  char *defstr ; /* rdf, definition string */
119  storage_type storage; /* Flag indicating table storage method */
120  file_mode mode ; /* Table is either reading or writing */
121  unsigned char status; /* VPF table status - OPENED or CLOSED */
122  unsigned char byte_order; /* Byte order of the table's data */
124 
125 typedef struct {
126  float x,y;
128 
129 typedef struct {
130  double x,y;
132 
133 typedef struct {
134  float x,y,z;
136 
137 typedef struct {
138  double x,y, z;
140 
141 /* These macros help determine the type in the key datatype */
142 
143 #define TYPE0(cell) ((cell>>6)&(3))
144 #define TYPE1(cell) ((cell>>4)&(3))
145 #define TYPE2(cell) ((cell>>2)&(3))
146 #define TYPE3(cell) ((cell)&(3))
147 
148 /* These macros set the value in the key datatype */
149 
150 #define SETTYPE0(cell,value) cell = (((cell)&(~(3<<6)))|(((3)&(value))<<6))
151 #define SETTYPE1(cell,value) cell = (((cell)&(~(3<<4)))|(((3)&(value))<<4))
152 #define SETTYPE2(cell,value) cell = (((cell)&(~(3<<2)))|(((3)&(value))<<2))
153 #define SETTYPE3(cell,value) cell = (((cell)&(~(3)))|(((3)&(value))))
154 
155 /* This macro helps to write out a key */
156 
157 #define ASSIGN_KEY(tYPE,kEY,loc,val)\
158 { \
159  if (val < 1) \
160  { \
161  tYPE(kEY.type,0); \
162  } else if (val < (1<<8)) \
163  { \
164  tYPE(kEY.type,1); \
165  kEY.loc = val ; \
166  } else if ( val < (1<<16)) \
167  { \
168  tYPE(kEY.type,2); \
169  kEY.loc = val; \
170  } else \
171  { \
172  tYPE(kEY.type,3); \
173  kEY.loc = val; \
174  } \
175 }
176 
177 /* define NULL values */
178 #if defined(__CYGWIN__) || defined(__APPLE__) || defined(USING_VISUALAGE) || defined(_WIN32)
179 #include <ossim/vpfutil/values.h>
180 #else
181 #include <ossim/vpfutil/values.h>
182 #endif
183 
184 #include <math.h>
185 
186 #ifdef __MSDOS__
187 double quiet_nan(int unused);
188 #endif
189 
190 int is_vpf_null_float( float num );
191 int is_vpf_null_double( double num );
192 
193 #define VARIABLE_STRING_NULL_LENGTH 10
194 #define NULLCHAR ' '
195 #define NULLTEXT " "
196 #define NULLSHORT -MAXSHORT
197 #define NULLINT -MAXLONG
198 #define NULLDATE " "
199 /* #if UNIX */
200 #define NULLFLOAT ((float) quiet_nan (0))
201 #define NULLDOUBLE ((double) quiet_nan (0))
202 /* #else
203 #define NULLFLOAT ((float) MAXFLOAT)
204 #define NULLDOUBLE ((double) MAXFLOAT)
205 #endif */
206 
207 typedef union {
208  unsigned char f1;
209  unsigned short int f2;
211 } key_field;
212 
213 /* id triplet internal storage type */
214 typedef struct {
215  unsigned char type;
216  ossim_int32 id, tile, exid;
218 
221 
222 /* Functions: */
223 
224 char *get_string(ossim_int32 *ind,char *src,char delimit);
225 char get_char (ossim_int32 *ind,char *src);
226 ossim_int32 get_number(ossim_int32 *ind,char *src,char delemit);
227 
229 
230 char *read_text_defstr( FILE *infile, FILE *outerr );
231 
233  vpf_table_type table );
234 
235 ossim_int32 index_pos( ossim_int32 row_number,
236  vpf_table_type table );
237 #if 0
238 ossim_int32 row_offset( int field,
239  row_type row,
240  vpf_table_type table);
241 #endif
242 
244 
245 row_type read_row( ossim_int32 row_number,
246  vpf_table_type table );
247 
248 vpf_table_type vpf_open_table( const char *tablename,
249  storage_type storage,
250  const char *mode,
251  char *defstr ); /* rdf added */
252 
253 row_type get_row( ossim_int32 row_number,
254  vpf_table_type table );
255 
256 void free_row( row_type row, vpf_table_type table );
257 
258 ossim_int32 table_pos( const char *field_name,
259  vpf_table_type table );
260 
261 void *get_table_element( ossim_int32 field_number,
262  row_type row,
263  vpf_table_type table,
264  void *value,
265  ossim_int32 *count );
266 
267 void *named_table_element( char *field_name,
268  ossim_int32 row_number,
269  vpf_table_type table,
270  void *value,
271  ossim_int32 *count );
272 
273 void *table_element( ossim_int32 field_number,
274  ossim_int32 row_number,
275  vpf_table_type table,
276  void *value,
277  ossim_int32 *count );
278 
279 void vpf_close_table( vpf_table_type *table );
280 
281 void vpf_dump_table( char *tablename, char *outname );
282 
283 ossim_int32 is_vpf_table( const char *fname );
284 
285 /* Write functions */
286 
288 
290 
292  vpf_table_type table );
293 
295  vpf_table_type table,
296  void *value, ossim_int32 count );
297 void vpf_dump_table( char *tablename, char *outname );
298 void vpf_dump_doc_table( char *tablename, char *outname );
299 
300 void swap_two(char*, char*);
301 void swap_four(char*, char*);
302 void swap_eight(char*, char*);
303 
304 #if MAIN
305  FILE * errorfp = stderr;
306 #else
307  extern FILE * errorfp;
308 #endif
309 #if defined(__cplusplus)
310 }
311 #endif
312 
313 #endif /* #ifndef _VPF_TABLE_H_ */
314 
315 
float Float
Definition: vpftable.h:55
ossim_uint32 x
void free_row(row_type row, vpf_table_type table)
char * read_text_defstr(FILE *infile, FILE *outerr)
row_type create_row(vpf_table_type table)
date_type Date
Definition: vpftable.h:57
void swap_four(char *, char *)
char * defstr
Definition: vpftable.h:118
vpf_table_type vpf_open_table(const char *tablename, storage_type storage, const char *mode, char *defstr)
char * name
Definition: vpftable.h:63
ossim_uint32 y
unsigned char status
Definition: vpftable.h:121
ddef_state_type
Definition: vpftable.h:219
header_type header
Definition: vpftable.h:109
row_type * row
Definition: vpftable.h:115
char * tdx
Definition: vpftable.h:67
file_mode mode
Definition: vpftable.h:120
column_type * row_type
Definition: vpftable.h:93
char * path
Definition: vpftable.h:105
void swap_two(char *, char *)
FILE * xfp
Definition: vpftable.h:110
void * ptr
Definition: vpftable.h:89
file_mode
Definition: vpftable.h:80
char Other
Definition: vpftable.h:58
row_type read_row(ossim_int32 row_number, vpf_table_type table)
ossim_int32 get_number(ossim_int32 *ind, char *src, char delemit)
void * table_element(ossim_int32 field_number, ossim_int32 row_number, vpf_table_type table, void *value, ossim_int32 *count)
ossim_int32 index_pos(ossim_int32 row_number, vpf_table_type table)
ossim_uint32 f3
Definition: vpftable.h:210
ossim_int32 table_pos(const char *field_name, vpf_table_type table)
void * named_table_element(char *field_name, ossim_int32 row_number, vpf_table_type table, void *value, ossim_int32 *count)
ossim_int32 put_table_element(ossim_int32 field, row_type row, vpf_table_type table, void *value, ossim_int32 count)
ossim_int32 tile
Definition: vpftable.h:216
void nullify_table_element(ossim_int32 field, row_type row, vpf_table_type table)
ossim_int32 parse_data_def(vpf_table_type *table)
storage_type storage
Definition: vpftable.h:119
ossim_int32 is_vpf_table(const char *fname)
ossim_int32 write_next_row(row_type row, vpf_table_type *table)
row_type get_row(ossim_int32 row_number, vpf_table_type table)
int is_vpf_null_float(float num)
unsigned int ossim_uint32
ossim_int32 ddlen
Definition: vpftable.h:117
ossim_int32 nrows
Definition: vpftable.h:114
unsigned char f1
Definition: vpftable.h:208
index_type index
Definition: vpftable.h:111
Definition: vpftable.h:74
void vpf_dump_doc_table(char *tablename, char *outname)
void vpf_dump_table(char *tablename, char *outname)
void * get_table_element(ossim_int32 field_number, row_type row, vpf_table_type table, void *value, ossim_int32 *count)
Definition: vpftable.h:80
int vpfutilMachineByteOrder()
ossim_int32 nfields
Definition: vpftable.h:106
ossim_int32 index_length(ossim_int32 row_number, vpf_table_type table)
unsigned char type
Definition: vpftable.h:215
int is_vpf_null_double(double num)
unsigned char byte_order
Definition: vpftable.h:122
storage_type
Definition: vpftable.h:74
row_type read_next_row(vpf_table_type table)
void vpf_close_table(vpf_table_type *table)
char * get_string(ossim_int32 *ind, char *src, char delimit)
Definition: vpftable.h:80
char get_char(ossim_int32 *ind, char *src)
ossim_int32 count
Definition: vpftable.h:69
short int Short
Definition: vpftable.h:53
double Double
Definition: vpftable.h:56
ossim_int32 Int
Definition: vpftable.h:54
ossim_int32 count
Definition: vpftable.h:88
null_field nullval
Definition: vpftable.h:70
char keytype
Definition: vpftable.h:65
ossim_uint32 pos
Definition: vpftable.h:98
char date_type[21]
Definition: vpftable.h:47
ossim_int32 reclen
Definition: vpftable.h:116
struct index_cell * index_type
Definition: vpftable.h:74
storage_type xstorage
Definition: vpftable.h:112
unsigned short int f2
Definition: vpftable.h:209
FILE * errorfp
char type
Definition: vpftable.h:68
struct header_cell * header_type
char * narrative
Definition: vpftable.h:71
int ossim_int32
char * Char
Definition: vpftable.h:52
void swap_eight(char *, char *)
ossim_uint32 length
Definition: vpftable.h:99