1 /***************************************************************************
2  *
3  * Project:  OpenCPN
4  * Purpose:  Tide and Current Manager
5  * Author:   David Register
6  * Todo add original author
7  *
8  ***************************************************************************
9  *   Copyright (C) 2010 by David S. Register                               *
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  *   This program is distributed in the hope that it will be useful,       *
17  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
19  *   GNU General Public License for more details.                          *
20  *                                                                         *
21  *   You should have received a copy of the GNU General Public License     *
22  *   along with this program; if not, write to the                         *
23  *   Free Software Foundation, Inc.,                                       *
24  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,  USA.         *
25  **************************************************************************/
26 
27 #ifndef __TCMGR_H__
28 #define __TCMGR_H__
29 
30 #include <wx/arrstr.h>
31 #include <map>
32 
33 #include "Station_Data.h"
34 #include "IDX_entry.h"
35 #include "TC_Error_Code.h"
36 #include "TCDataSource.h"
37 
38 // ----------------------------------------------------------------------------
39 // external C linkages
40 // ----------------------------------------------------------------------------
41 
42 //----------------------------------------------------------------------------
43 //   constants
44 //----------------------------------------------------------------------------
45 
46 #define USF_REMOVE 1
47 #define USF_UPDATE 2
48 #define USF_WRITE  3
49 
50 #ifndef M_PI
51 #define M_PI 3.141592654
52 #endif
53 
54 #define TIDE_MAX_DERIV (2)      // Maximum derivative supported
55 /* TIDE_TIME_PREC
56  *   Precision (in seconds) to which we will find roots
57  */
58 #define TIDE_TIME_PREC (15)
59 
60 /* TIDE_TIME_BLEND
61  *   Half the number of seconds over which to blend the tides from
62  *   one epoch to the next.
63  */
64 #define TIDE_BLEND_TIME (3600)
65 
66 /* TIDE_TIME_STEP
67  *   We are guaranteed to find all high and low tides as long as their
68  * spacing is greater than this value (in seconds).
69  */
70 #define TIDE_TIME_STEP (TIDE_TIME_PREC)
71 #define TIDE_BAD_TIME   ((time_t) -1)
72 
73 
74 //----------------------------------------------------------------------------
75 //   Reference Station Data
76 //----------------------------------------------------------------------------
77 
78 typedef struct {
79     Station_Data      *sta_data;
80     void        *next;
81 } mru_entry;
82 
83 
84 //----------------------------------------------------------------------------
85 //   TCMgr
86 //----------------------------------------------------------------------------
87 
88 class TCMgr
89 {
90 public:
91     TCMgr();
92     ~TCMgr();
93 
94     TC_Error_Code LoadDataSources(wxArrayString &sources);
GetDataSet(void)95     wxArrayString GetDataSet( void ) {
96         return m_sourcefile_array;
97     }
98 
IsReady(void)99     bool IsReady(void) {
100         return bTCMReady;
101     }
102 
103     bool GetTideOrCurrent(time_t t, int idx, float &value, float& dir);
104     bool GetTideOrCurrent15(time_t t, int idx, float &tcvalue, float& dir, bool &bnew_val);
105     bool GetTideFlowSens(time_t t, int sch_step, int idx, float &tcvalue_now, float &tcvalue_prev, bool &w_t);
106     void GetHightOrLowTide(time_t t, int sch_step_1, int sch_step_2, float tide_val ,bool w_t , int idx, float &tcvalue, time_t &tctime);
107 
108     int GetStationTimeOffset(IDX_entry *pIDX);
109     int GetNextBigEvent(time_t *tm, int idx);
110     double GetStationLat(IDX_entry *pIDX);
111     double GetStationLon(IDX_entry *pIDX);
112 
113     const IDX_entry *GetIDX_entry(int index) const;
114 
Get_max_IDX()115     int Get_max_IDX() const
116 	{
117         return m_Combined_IDX_array.GetCount()-1;
118     }
119 
120     std::map<double, const IDX_entry*> GetStationsForLL(double xlat, double xlon) const;
121 
122     int GetStationIDXbyName(const wxString & prefix, double xlat, double xlon) const;
123     int GetStationIDXbyNameType(const wxString & prefix, double xlat, double xlon, char type) const;
124 
125 private:
126     void PurgeData();
127 
128     void LoadMRU(void);
129     void SaveMRU(void);
130     void AddMRU(Station_Data *psd);
131     void FreeMRU(void);
132 
133     bool bTCMReady;
134     wxString pmru_file_name;
135 
136     ArrayOfTCDSources   m_source_array;
137     wxArrayString       m_sourcefile_array;
138 
139     ArrayOfIDXEntry     m_Combined_IDX_array;
140 
141 };
142 
143 /* $Id: tcd.h.in 3744 2010-08-17 22:34:46Z flaterco $ */
144 /* tcd.h.  Generated from tcd.h.in by configure. */
145 
146 #ifndef __OAML_TIDES_H__
147 #define __OAML_TIDES_H__
148 
149 
150 /*****************************************************************************
151  *
152  *                            DISTRIBUTION STATEMENT
153  *
154  *    This source file is unclassified, distribution unlimited, public
155  *    domain.  It is distributed in the hope that it will be useful, but
156  *    WITHOUT ANY WARRANTY; without even the implied warranty of
157  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
158  *
159  ******************************************************************************/
160 
161 
162 /*
163  *  Data types for libtcd API
164  *  Formerly nvtypes.h, NAVO Standard Data Type Definitions
165  *
166  *  This section may appear slightly different from one platform to the
167  *  next.  The build process for libtcd generates #includes and data
168  *  type definitions as needed to provide integer types of specific
169  *  sizes.
170  */
171 
172 /* Generated includes */
173 #include <sys/types.h>
174 #ifndef __WXMSW__
175 #include <inttypes.h>
176 
177 /* Generated data types */
178 #define NV_BYTE    int8_t
179 #define NV_INT16   int16_t
180 #define NV_INT32   int32_t
181 #define NV_INT64   int64_t
182 #define NV_U_BYTE  uint8_t
183 #define NV_U_INT16 uint16_t
184 #define NV_U_INT32 uint32_t
185 #define NV_U_INT64 uint64_t
186 #else
187 #define NV_BYTE    unsigned char
188 #define NV_INT16   short
189 #define NV_INT32   int
190 #define NV_INT64   long
191 #define NV_U_BYTE  unsigned char
192 #define NV_U_INT16 unsigned short
193 #define NV_U_INT32 unsigned int
194 #define NV_U_INT64 unsigned long
195 
196 #endif
197 
198 /* Hard-coded data types */
199 #define NV_BOOL    unsigned char
200 #define NV_CHAR    char
201 #define NV_U_CHAR  unsigned char
202 #define NV_FLOAT32 float
203 #define NV_FLOAT64 double
204 
205 /* Defined values */
206 #define NVFalse         0
207 #define NVTrue          1
208 #define NV_U_INT32_MAX  4294967295
209 #define NV_INT32_MAX    2147483647
210 #define NV_U_INT16_MAX  65535
211 #define NV_INT16_MAX    32767
212 
213 
214 #define LIBTCD_VERSION   "PFM Software - libtcd v2.2.5 - 2010-08-17"
215 #define LIBTCD_MAJOR_REV 2
216 #define LIBTCD_MINOR_REV 2
217 
218 
219 /*
220  *  COMPAT114 is defined here if and only if libtcd was compiled with
221  *  --enable-COMPAT114.  COMPAT114 forces API changes to enable
222  *  applications written against the v1 API to build with more recent
223  *  libraries and successfully interact with v2 TCD files.  This will
224  *  BREAK applications expecting the v2 API.  It is for localized use
225  *  only (libraries built with this option should not be distributed).
226  */
227 #undef COMPAT114
228 
229 /* Select #warning versus #pragma message (whichever works) */
230 #undef USE_PRAGMA_MESSAGE
231 
232 #ifdef COMPAT114
233 #ifdef USE_PRAGMA_MESSAGE
234 #pragma message("WARNING:  COMPAT114 is enabled!  See libtcd.html.")
235 #else
236 #warning COMPAT114 is enabled!  See libtcd.html.
237 #endif
238 #endif
239 
240 
241 /*  Maximum values.  */
242 
243 /* One-line character strings */
244 #define ONELINER_LENGTH      90
245 /* Verbose character strings */
246 #define MONOLOGUE_LENGTH  10000
247 #define MAX_CONSTITUENTS    255
248 
249 
250 #ifdef  __cplusplus
251 extern "C" {
252     #endif
253 
254 
255     /*  Public portion of the database header.  */
256     /* See libtcd.html for documentation */
257 
258     typedef struct
259     {
260         NV_CHAR           version[ONELINER_LENGTH];
261         NV_U_INT32        major_rev;
262         NV_U_INT32        minor_rev;
263         NV_CHAR           last_modified[ONELINER_LENGTH];
264         NV_U_INT32        number_of_records;
265         NV_INT32          start_year;
266         NV_U_INT32        number_of_years;
267         NV_U_INT32        constituents;
268         NV_U_INT32        level_unit_types;
269         NV_U_INT32        dir_unit_types;
270         NV_U_INT32        restriction_types;
271         NV_U_INT32        datum_types;
272         NV_U_INT32        countries;
273         NV_U_INT32        tzfiles;
274         NV_U_INT32        legaleses;
275 
276         /* Need this to read V1 files. */
277         NV_U_INT32        pedigree_types;
278     } DB_HEADER_PUBLIC;
279 
280 
281     /*  Header portion of each station record.  */
282     /* See libtcd.html for documentation */
283 
284     enum TIDE_RECORD_TYPE {REFERENCE_STATION=1, SUBORDINATE_STATION=2};
285 
286     typedef struct
287     {
288         NV_INT32                record_number;
289         NV_U_INT32              record_size;
290         NV_U_BYTE               record_type;
291         NV_FLOAT64              latitude;
292         NV_FLOAT64              longitude;
293         NV_INT32                reference_station;
294         NV_INT16                tzfile;
295         NV_CHAR                 name[ONELINER_LENGTH];
296     } TIDE_STATION_HEADER;
297 
298 
299     /*  Tide station record.  */
300     /* See libtcd.html for documentation */
301 
302     typedef struct
303     {
304         /* Common */
305         TIDE_STATION_HEADER     header;
306         NV_INT16                country;
307         NV_CHAR                 source[ONELINER_LENGTH];
308         NV_U_BYTE               restriction;
309         NV_CHAR                 comments[MONOLOGUE_LENGTH];
310         NV_CHAR                 notes[MONOLOGUE_LENGTH];
311         NV_U_BYTE               legalese;
312         NV_CHAR                 station_id_context[ONELINER_LENGTH];
313         NV_CHAR                 station_id[ONELINER_LENGTH];
314         NV_U_INT32              date_imported;
315         NV_CHAR                 xfields[MONOLOGUE_LENGTH];
316         NV_U_BYTE               direction_units;
317         NV_INT32                min_direction;
318         NV_INT32                max_direction;
319         NV_U_BYTE               level_units;
320 
321         /* Type 1 */
322         NV_FLOAT32              datum_offset;
323         NV_INT16                datum;
324         NV_INT32                zone_offset;
325         NV_U_INT32              expiration_date;
326         NV_U_INT16              months_on_station;
327         NV_U_INT32              last_date_on_station;
328         NV_U_BYTE               confidence;
329         NV_FLOAT32              amplitude[MAX_CONSTITUENTS];
330         NV_FLOAT32              epoch[MAX_CONSTITUENTS];
331 
332         /* Type 2 */
333         NV_INT32                min_time_add;
334         NV_FLOAT32              min_level_add;
335         NV_FLOAT32              min_level_multiply;
336         NV_INT32                max_time_add;
337         NV_FLOAT32              max_level_add;
338         NV_FLOAT32              max_level_multiply;
339         NV_INT32                flood_begins;
340         NV_INT32                ebb_begins;
341 
342         #ifdef COMPAT114
343         /* Deprecated */
344         NV_INT16                pedigree;
345         NV_U_BYTE               units;
346         NV_U_BYTE               avg_level_units;
347         NV_FLOAT32              min_avg_level;
348         NV_FLOAT32              max_avg_level;
349         #endif
350     } TIDE_RECORD;
351 
352 
353     /* DWF: This value signifies "null" or "omitted" slack offsets
354      *   (flood_begins, ebb_begins).  Zero is *not* the same. */
355     /* Time offsets are represented as hours * 100 plus minutes.
356      *   0xA00 = 2560
357      *   It turns out that offsets do exceed 24 hours (long story), but we
358      *   should still be safe with the 60.
359      */
360     #define NULLSLACKOFFSET 0xA00
361 
362     /* This is the level below which an amplitude rounds to zero. */
363     /* It should be exactly (0.5 / DEFAULT_AMPLITUDE_SCALE). */
364     #define AMPLITUDE_EPSILON 0.00005
365 
366     /* Rounding function. */
367     #define NINT(a)   ((a)<0.0 ? (NV_INT32) ((a) - 0.5) : (NV_INT32) ((a) + 0.5))
368 
369 
370     /*  Public function prototypes.  */
371 
372     /* Prints a low-level dump of the tide record to stderr. */
373     void dump_tide_record (const TIDE_RECORD *rec);
374 
375     /* For fields in the tide record that are indices into tables of
376      *   character string values, these functions are used to retrieve the
377      *   character string value corresponding to a particular index.  The
378      *   value "Unknown" is returned when no translation exists.  The return
379      *   value is a pointer into static memory. */
380     const NV_CHAR *get_country (NV_INT32 num);
381     const NV_CHAR *get_tzfile (NV_INT32 num);
382     const NV_CHAR *get_level_units (NV_INT32 num);
383     const NV_CHAR *get_dir_units (NV_INT32 num);
384     const NV_CHAR *get_restriction (NV_INT32 num);
385     const NV_CHAR *get_datum (NV_INT32 num);
386     const NV_CHAR *get_legalese (NV_INT32 num);
387 
388     /* Get the name of the constituent corresponding to index num
389      *   [0,constituents-1].  The return value is a pointer into static
390      *   memory. */
391     const NV_CHAR *get_constituent (NV_INT32 num);
392 
393     /* Get the name of the station whose record_number is num
394      *   [0,number_of_records-1].  The return value is a pointer into static
395      *   memory. */
396     const NV_CHAR *get_station (NV_INT32 num);
397 
398     /* Returns the speed of the constituent indicated by num
399      *   [0,constituents-1]. */
400     NV_FLOAT64 get_speed (NV_INT32 num);
401 
402     /* Get the equilibrium argument and node factor for the constituent
403      *   indicated by num [0,constituents-1], for the year
404      *   start_year+year. */
405     NV_FLOAT32 get_equilibrium (NV_INT32 num, NV_INT32 year);
406     NV_FLOAT32 get_node_factor (NV_INT32 num, NV_INT32 year);
407 
408     /* Get all available equilibrium arguments and node factors for the
409      *   constituent indicated by num [0,constituents-1].  The return value
410      *   is a pointer into static memory which is an array of
411      *   number_of_years floats, corresponding to the years start_year
412      *   through start_year+number_of_years-1. */
413     NV_FLOAT32 *get_equilibriums (NV_INT32 num);
414     NV_FLOAT32 *get_node_factors (NV_INT32 num);
415 
416     /* Convert between character strings of the form "[+-]HH:MM" and the
417      *   encoding Hours * 100 + Minutes.  ret_time pads the hours with a
418      *   leading zero when less than 10; ret_time_neat omits the leading
419      *   zero and omits the sign when the value is 0:00.  Returned pointers
420      *   point into static memory. */
421     NV_INT32 get_time (const NV_CHAR *string);
422     NV_CHAR *ret_time (NV_INT32 time);
423     NV_CHAR *ret_time_neat (NV_INT32 time);
424 
425     /* Convert the encoding Year * 10000 + Month [1, 12] * 100 + Day [1,
426      *   31] to a character string of the form "YYYY-MM-DD", or "NULL" if
427      *   the value is zero.  The returned pointer points into static memory.
428      *   (The compact form, without hyphens, is obtainable just by printing
429      *   the integer.) */
430     NV_CHAR *ret_date (NV_U_INT32 date);
431 
432     /* When invoked multiple times with the same string, returns record
433      *   numbers of all stations that have that string anywhere in the
434      *   station name.  This search is case insensitive.  When no more
435      *   records are found it returns -1. */
436     NV_INT32 search_station (const NV_CHAR *string);
437 
438     /* Inverses of the corresponding get_ operations.  Return -1 for not
439      *   found. */
440     NV_INT32 find_station (const NV_CHAR *name);
441     NV_INT32 find_tzfile (const NV_CHAR *name);
442     NV_INT32 find_country (const NV_CHAR *name);
443     NV_INT32 find_level_units (const NV_CHAR *name);
444     NV_INT32 find_dir_units (const NV_CHAR *name);
445     NV_INT32 find_restriction (const NV_CHAR *name);
446     NV_INT32 find_datum (const NV_CHAR *name);
447     NV_INT32 find_constituent (const NV_CHAR *name);
448     NV_INT32 find_legalese (const NV_CHAR *name);
449 
450     /* Add the value of name to the corresponding lookup table and return
451      *   the index of the new value.  If db is not NULL, the database header
452      *   struct pointed to will be updated to reflect the changes. */
453     NV_INT32 add_restriction (const NV_CHAR *name, DB_HEADER_PUBLIC *db);
454     NV_INT32 add_tzfile (const NV_CHAR *name, DB_HEADER_PUBLIC *db);
455     NV_INT32 add_country (const NV_CHAR *name, DB_HEADER_PUBLIC *db);
456     NV_INT32 add_datum (const NV_CHAR *name, DB_HEADER_PUBLIC *db);
457     NV_INT32 add_legalese (const NV_CHAR *name, DB_HEADER_PUBLIC *db);
458 
459     /* Add the value of name to the corresponding lookup table if and
460      *   only if it is not already present.  Return the index of the value.
461      *   If db is not NULL, the database header struct pointed to will be
462      *   updated to reflect the changes. */
463     NV_INT32 find_or_add_restriction (const NV_CHAR *name, DB_HEADER_PUBLIC *db);
464     NV_INT32 find_or_add_tzfile (const NV_CHAR *name, DB_HEADER_PUBLIC *db);
465     NV_INT32 find_or_add_country (const NV_CHAR *name, DB_HEADER_PUBLIC *db);
466     NV_INT32 find_or_add_datum (const NV_CHAR *name, DB_HEADER_PUBLIC *db);
467     NV_INT32 find_or_add_legalese (const NV_CHAR *name, DB_HEADER_PUBLIC *db);
468 
469     /* Set the speed for the constituent corresponding to index num
470      *   [0,constituents-1]. */
471     void set_speed (NV_INT32 num, NV_FLOAT64 value);
472 
473     /* Set the equilibrium argument and node factor for the constituent
474      *   corresponding to index num [0,constituents-1], for the year
475      *   start_year+year. */
476     void set_equilibrium (NV_INT32 num, NV_INT32 year, NV_FLOAT32 value);
477     void set_node_factor (NV_INT32 num, NV_INT32 year, NV_FLOAT32 value);
478 
479     /* Opens the specified TCD file.  If a different database is already
480      *   open, it will be closed.  libtcd maintains considerable internal
481      *   state and can only handle one open database at a time.  Returns
482      *   false if the open failed. */
483     NV_BOOL open_tide_db (const NV_CHAR *file);
484 
485     /* Closes the open database. */
486     void close_tide_db ();
487 
488     /* Creates a TCD file with the supplied constituents and no tide
489      *   stations.  Returns false if creation failed.  The database is left
490      *   in an open state. */
491     NV_BOOL create_tide_db (const NV_CHAR *file, NV_U_INT32 constituents,
492                             NV_CHAR const * const constituent[], const NV_FLOAT64 *speed,
493                             NV_INT32 start_year, NV_U_INT32 num_years,
494                             NV_FLOAT32 const * const equilibrium[],
495                             NV_FLOAT32 const * const node_factor[]);
496 
497     /* Returns a copy of the database header for the open database. */
498     DB_HEADER_PUBLIC get_tide_db_header ();
499 
500     /* Gets "header" portion of tide record for the station whose
501      *   record_number is num [0,number_of_records-1] and writes it into
502      *   rec.  Returns false if num is out of range.  num is preserved in
503      *   the static variable current_index. */
504     NV_BOOL get_partial_tide_record (NV_INT32 num, TIDE_STATION_HEADER *rec);
505 
506     /* Invokes get_partial_tide_record for current_index+1.  Returns the
507      *   record number or -1 for failure. */
508     NV_INT32 get_next_partial_tide_record (TIDE_STATION_HEADER *rec);
509 
510     /* Invokes get_partial_tide_record for a station that appears closest
511      *   to the specified lat and lon in the Cylindrical Equidistant
512      *   projection.  Returns the record number or -1 for failure. */
513     NV_INT32 get_nearest_partial_tide_record (NV_FLOAT64 lat, NV_FLOAT64 lon,
514                                               TIDE_STATION_HEADER *rec);
515 
516     /* Gets tide record for the station whose record_number is num
517      *   [0,number_of_records-1] and writes it into rec.  num is preserved
518      *   in the static variable current_record.  Returns num, or -1 if num is
519      *   out of range. */
520     NV_INT32 read_tide_record (NV_INT32 num, TIDE_RECORD *rec);
521 
522     /* Invokes read_tide_record for current_record+1.  Returns the record
523      *   number or -1 for failure. */
524     NV_INT32 read_next_tide_record (TIDE_RECORD *rec);
525 
526     /* Add a new record, update an existing record, or delete an existing
527      *   record.  If the deleted record is a reference station, all
528      *   dependent subordinate stations will also be deleted.  Add and
529      *   update return false if the new record is invalid; delete and update
530      *   return false if the specified num is invalid.  If db is not NULL,
531      *   the database header struct pointed to will be updated to reflect
532      *   the changes. */
533     NV_BOOL add_tide_record (TIDE_RECORD *rec, DB_HEADER_PUBLIC *db);
534     #ifdef COMPAT114
535     /* Omission of db parameter was a bug. */
536     NV_BOOL update_tide_record (NV_INT32 num, TIDE_RECORD *rec);
537     #else
538     NV_BOOL update_tide_record (NV_INT32 num, TIDE_RECORD *rec, DB_HEADER_PUBLIC *db);
539     #endif
540     NV_BOOL delete_tide_record (NV_INT32 num, DB_HEADER_PUBLIC *db);
541 
542     /* Computes inferred constituents when M2, S2, K1, and O1 are given
543      *   and fills in the remaining unfilled constituents.  The inferred
544      *   constituents are developed or decided based on Article 230 of
545      *   "Manual of Harmonic Analysis and Prediction of Tides," Paul
546      *   Schureman, C&GS Special Publication No. 98, October 1971.  Returns
547      *   false if M2, S2, K1, or O1 is missing. */
548     NV_BOOL infer_constituents (TIDE_RECORD *rec);
549 
550 
551     #ifdef COMPAT114
552     /* Deprecated stuff. */
553     #define NAME_LENGTH         ONELINER_LENGTH
554     #define SOURCE_LENGTH       ONELINER_LENGTH
555     #define COMMENTS_LENGTH     MONOLOGUE_LENGTH
556     NV_CHAR *get_pedigree (NV_INT32 num);
557     NV_INT32 find_pedigree (const NV_CHAR *name);
558     NV_INT32 add_pedigree (const NV_CHAR *name, const DB_HEADER_PUBLIC *db);
559     NV_BOOL check_simple (TIDE_RECORD rec);
560     #endif
561 
562     #ifdef  __cplusplus
563 }
564 #endif
565 
566 #endif
567 
568 
569 /* $Id: tide_db_header.h 1092 2006-11-16 03:02:42Z flaterco $ */
570 
571 /*****************************************************************************\
572  *
573  *                            DISTRIBUTION STATEMENT
574  *
575  *    This source file is unclassified, distribution unlimited, public
576  *    domain.  It is distributed in the hope that it will be useful, but
577  *    WITHOUT ANY WARRANTY; without even the implied warranty of
578  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
579  *
580  * \*****************************************************************************/
581 
582 
583 
584 
585 /***************************************************************************\
586  *
587  *    Module Name:        TIDE DB option header file
588  *
589  *    Programmer(s):      Jan C. Depner
590  *
591  *    Date Written:       July 2002
592  *
593  *    Purpose:            This header file defines all of the format options
594  *                        that are stored in the TIDE DB file header.  To add a
595  *                        new option you simply add it to the header_data
596  *                        structure, then put a definition in the keys structure.
597  *                        The keys structure contains a keyphrase such as
598  *                        "[DATE]", a format like "%s", a datatype (see the
599  *                        union in the TIDE_HEADER_DATA structure, a pointer to
600  *                        the location at which to store the value(s), a count
601  *                        if it is a repeating field (array), and a version
602  *                        dependency flag (major.minor * 10).
603  *
604  *
605  *
606  *****************************************************************************
607 
608  This header file uses the NAVO standard data types.  You must set one of
609  the following options on the compile command line:
610 
611  NVDOS, NVHPUX, NVIRIX, NVCLIX, NVLinux, NVSUNOS, NVWINNT, or NVWIN3X
612 
613  The only one referenced in libtcd is NVWIN3X. -- DWF, 2004-09-29
614 
615  \***************************************************************************/
616 
617 
618 #ifndef __TIDE_HEADER__
619 #define __TIDE_HEADER__
620 
621 //#include "tcd.h"
622 
623 
624 typedef struct
625 {
626     const NV_CHAR                    *keyphrase;
627     const NV_CHAR                    *datatype;
628     union
629     {
630         const NV_CHAR                *cstr;
631         NV_INT32               *i32;
632         NV_U_INT32             *ui32;
633     } address;
634 } KEY;
635 
636 
637 typedef struct
638 {
639     DB_HEADER_PUBLIC  pub;
640     NV_CHAR           **constituent;
641     NV_FLOAT64        *speed;
642     NV_FLOAT32        **equilibrium;
643     NV_FLOAT32        **node_factor;
644     NV_CHAR           **level_unit;
645     NV_CHAR           **dir_unit;
646     NV_CHAR           **restriction;
647     NV_CHAR           **tzfile;
648     NV_CHAR           **country;
649     NV_CHAR           **datum;
650     NV_CHAR           **legalese;
651     NV_U_INT32        header_size;
652     NV_U_INT32        speed_bits;
653     NV_U_INT32        speed_scale;
654     NV_INT32          speed_offset;
655     NV_U_INT32        equilibrium_bits;
656     NV_U_INT32        equilibrium_scale;
657     NV_INT32          equilibrium_offset;
658     NV_U_INT32        node_bits;
659     NV_U_INT32        node_scale;
660     NV_INT32          node_offset;
661     NV_U_INT32        amplitude_bits;
662     NV_U_INT32        amplitude_scale;
663     NV_U_INT32        epoch_bits;
664     NV_U_INT32        epoch_scale;
665     NV_U_INT32        constituent_bits;
666     NV_U_INT32        record_type_bits;
667     NV_U_INT32        latitude_scale;
668     NV_U_INT32        latitude_bits;
669     NV_U_INT32        longitude_scale;
670     NV_U_INT32        longitude_bits;
671     NV_U_INT32        record_size_bits;
672     NV_U_INT32        station_bits;
673     NV_U_INT32        level_unit_bits;
674     NV_U_INT32        dir_unit_bits;
675     NV_U_INT32        restriction_bits;
676     NV_U_INT32        max_restriction_types;
677     NV_U_INT32        tzfile_bits;
678     NV_U_INT32        max_tzfiles;
679     NV_U_INT32        country_bits;
680     NV_U_INT32        max_countries;
681     NV_U_INT32        datum_bits;
682     NV_U_INT32        max_datum_types;
683     NV_U_INT32        legalese_bits;
684     NV_U_INT32        max_legaleses;
685     NV_U_INT32        datum_offset_bits;
686     NV_U_INT32        datum_offset_scale;
687     NV_U_INT32        date_bits;
688     NV_U_INT32        months_on_station_bits;
689     NV_U_INT32        confidence_value_bits;
690     NV_U_INT32        time_bits;
691     NV_U_INT32        level_add_bits;
692     NV_U_INT32        level_add_scale;
693     NV_U_INT32        level_multiply_bits;
694     NV_U_INT32        level_multiply_scale;
695     NV_U_INT32        direction_bits;
696     NV_U_INT32        constituent_size;
697     NV_U_INT32        level_unit_size;
698     NV_U_INT32        dir_unit_size;
699     NV_U_INT32        restriction_size;
700     NV_U_INT32        tzfile_size;
701     NV_U_INT32        country_size;
702     NV_U_INT32        datum_size;
703     NV_U_INT32        legalese_size;
704     NV_U_INT32        end_of_file;
705 
706     /* Need these to read V1 files. */
707     NV_U_INT32        pedigree_bits;
708     NV_U_INT32        pedigree_size;
709 } TIDE_HEADER_DATA;
710 
711 
712 static TIDE_HEADER_DATA        hd;
713 
714 /* "The initializer for a union with no constructor is either a single
715  *   expression of the same type, or a brace-enclosed initializer for
716  *   the first member of the union." -- Ellis & Stroustrup, The Annotated
717  *   C++ Reference Manual, 1990, Section 8.4.1. */
718 
719 static KEY                     keys[] =
720 {
721     {
722         "[VERSION]",
723         "cstr",
724         {(NV_CHAR *) hd.pub.version},
725     },
726     {
727         "[MAJOR REV]",
728         "ui32",
729         {(NV_CHAR *) &hd.pub.major_rev},
730     },
731     {
732         "[MINOR REV]",
733         "ui32",
734         {(NV_CHAR *) &hd.pub.minor_rev},
735     },
736     {
737         "[LAST MODIFIED]",
738         "cstr",
739         {(NV_CHAR *) hd.pub.last_modified},
740     },
741     {
742         "[NUMBER OF RECORDS]",
743         "ui32",
744         {(NV_CHAR *) &hd.pub.number_of_records},
745     },
746     {
747         "[START YEAR]",
748         "i32",
749         {(NV_CHAR *) &hd.pub.start_year},
750     },
751     {
752         "[NUMBER OF YEARS]",
753         "ui32",
754         {(NV_CHAR *) &hd.pub.number_of_years},
755     },
756     {
757         "[CONSTITUENTS]",
758         "ui32",
759         {(NV_CHAR *) &hd.pub.constituents},
760     },
761     {
762         "[LEVEL UNIT TYPES]",
763         "ui32",
764         {(NV_CHAR *) &hd.pub.level_unit_types},
765     },
766     {
767         "[DIRECTION UNIT TYPES]",
768         "ui32",
769         {(NV_CHAR *) &hd.pub.dir_unit_types},
770     },
771     {
772         "[RESTRICTION TYPES]",
773         "ui32",
774         {(NV_CHAR *) &hd.pub.restriction_types},
775     },
776     {
777         "[PEDIGREE TYPES]",
778         "ui32",
779         {(NV_CHAR *) &hd.pub.pedigree_types},
780     },
781     {
782         "[TZFILES]",
783         "ui32",
784         {(NV_CHAR *) &hd.pub.tzfiles},
785     },
786     {
787         "[COUNTRIES]",
788         "ui32",
789         {(NV_CHAR *) &hd.pub.countries},
790     },
791     {
792         "[DATUM TYPES]",
793         "ui32",
794         {(NV_CHAR *) &hd.pub.datum_types},
795     },
796     {
797         "[LEGALESES]",
798         "ui32",
799         {(NV_CHAR *) &hd.pub.legaleses},
800     },
801     {
802         "[HEADER SIZE]",
803         "ui32",
804         {(NV_CHAR *) &hd.header_size},
805     },
806     {
807         "[SPEED BITS]",
808         "ui32",
809         {(NV_CHAR *) &hd.speed_bits},
810     },
811     {
812         "[SPEED SCALE]",
813         "ui32",
814         {(NV_CHAR *) &hd.speed_scale},
815     },
816     {
817         "[SPEED OFFSET]",
818         "i32",
819         {(NV_CHAR *) &hd.speed_offset},
820     },
821     {
822         "[EQUILIBRIUM BITS]",
823         "ui32",
824         {(NV_CHAR *) &hd.equilibrium_bits},
825     },
826     {
827         "[EQUILIBRIUM SCALE]",
828         "ui32",
829         {(NV_CHAR *) &hd.equilibrium_scale},
830     },
831     {
832         "[EQUILIBRIUM OFFSET]",
833         "i32",
834         {(NV_CHAR *) &hd.equilibrium_offset},
835     },
836     {
837         "[NODE BITS]",
838         "ui32",
839         {(NV_CHAR *) &hd.node_bits},
840     },
841     {
842         "[NODE SCALE]",
843         "ui32",
844         {(NV_CHAR *) &hd.node_scale},
845     },
846     {
847         "[NODE OFFSET]",
848         "i32",
849         {(NV_CHAR *) &hd.node_offset},
850     },
851     {
852         "[AMPLITUDE BITS]",
853         "ui32",
854         {(NV_CHAR *) &hd.amplitude_bits},
855     },
856     {
857         "[AMPLITUDE SCALE]",
858         "ui32",
859         {(NV_CHAR *) &hd.amplitude_scale},
860     },
861     {
862         "[EPOCH BITS]",
863         "ui32",
864         {(NV_CHAR *) &hd.epoch_bits},
865     },
866     {
867         "[EPOCH SCALE]",
868         "ui32",
869         {(NV_CHAR *) &hd.epoch_scale},
870     },
871     {
872         "[CONSTITUENT BITS]",
873         "ui32",
874         {(NV_CHAR *) &hd.constituent_bits},
875     },
876     {
877         "[LEVEL UNIT BITS]",
878         "ui32",
879         {(NV_CHAR *) &hd.level_unit_bits},
880     },
881     {
882         "[DIRECTION UNIT BITS]",
883         "ui32",
884         {(NV_CHAR *) &hd.dir_unit_bits},
885     },
886     {
887         "[RESTRICTION BITS]",
888         "ui32",
889         {(NV_CHAR *) &hd.restriction_bits},
890     },
891     {
892         "[PEDIGREE BITS]",
893         "ui32",
894         {(NV_CHAR *) &hd.pedigree_bits},
895     },
896     {
897         "[TZFILE BITS]",
898         "ui32",
899         {(NV_CHAR *) &hd.tzfile_bits},
900     },
901     {
902         "[COUNTRY BITS]",
903         "ui32",
904         {(NV_CHAR *) &hd.country_bits},
905     },
906     {
907         "[DATUM BITS]",
908         "ui32",
909         {(NV_CHAR *) &hd.datum_bits},
910     },
911     {
912         "[LEGALESE BITS]",
913         "ui32",
914         {(NV_CHAR *) &hd.legalese_bits},
915     },
916     {
917         "[RECORD TYPE BITS]",
918         "ui32",
919         {(NV_CHAR *) &hd.record_type_bits},
920     },
921     {
922         "[LATITUDE SCALE]",
923         "ui32",
924         {(NV_CHAR *) &hd.latitude_scale},
925     },
926     {
927         "[LATITUDE BITS]",
928         "ui32",
929         {(NV_CHAR *) &hd.latitude_bits},
930     },
931     {
932         "[LONGITUDE SCALE]",
933         "ui32",
934         {(NV_CHAR *) &hd.longitude_scale},
935     },
936     {
937         "[LONGITUDE BITS]",
938         "ui32",
939         {(NV_CHAR *) &hd.longitude_bits},
940     },
941     {
942         "[RECORD SIZE BITS]",
943         "ui32",
944         {(NV_CHAR *) &hd.record_size_bits},
945     },
946     {
947         "[STATION BITS]",
948         "ui32",
949         {(NV_CHAR *) &hd.station_bits},
950     },
951     {
952         "[DATUM OFFSET BITS]",
953         "ui32",
954         {(NV_CHAR *) &hd.datum_offset_bits},
955     },
956     {
957         "[DATUM OFFSET SCALE]",
958         "ui32",
959         {(NV_CHAR *) &hd.datum_offset_scale},
960     },
961     {
962         "[DATE BITS]",
963         "ui32",
964         {(NV_CHAR *) &hd.date_bits},
965     },
966     {
967         "[MONTHS ON STATION BITS]",
968         "ui32",
969         {(NV_CHAR *) &hd.months_on_station_bits},
970     },
971     {
972         "[CONFIDENCE VALUE BITS]",
973         "ui32",
974         {(NV_CHAR *) &hd.confidence_value_bits},
975     },
976     {
977         "[TIME BITS]",
978         "ui32",
979         {(NV_CHAR *) &hd.time_bits},
980     },
981     {
982         "[LEVEL ADD BITS]",
983         "ui32",
984         {(NV_CHAR *) &hd.level_add_bits},
985     },
986     {
987         "[LEVEL ADD SCALE]",
988         "ui32",
989         {(NV_CHAR *) &hd.level_add_scale},
990     },
991     {
992         "[LEVEL MULTIPLY BITS]",
993         "ui32",
994         {(NV_CHAR *) &hd.level_multiply_bits},
995     },
996     {
997         "[LEVEL MULTIPLY SCALE]",
998         "ui32",
999         {(NV_CHAR *) &hd.level_multiply_scale},
1000     },
1001     {
1002         "[DIRECTION BITS]",
1003         "ui32",
1004         {(NV_CHAR *) &hd.direction_bits},
1005     },
1006     {
1007         "[CONSTITUENT SIZE]",
1008         "ui32",
1009         {(NV_CHAR *) &hd.constituent_size},
1010     },
1011     {
1012         "[LEVEL UNIT SIZE]",
1013         "ui32",
1014         {(NV_CHAR *) &hd.level_unit_size},
1015     },
1016     {
1017         "[DIRECTION UNIT SIZE]",
1018         "ui32",
1019         {(NV_CHAR *) &hd.dir_unit_size},
1020     },
1021     {
1022         "[RESTRICTION SIZE]",
1023         "ui32",
1024         {(NV_CHAR *) &hd.restriction_size},
1025     },
1026     {
1027         "[PEDIGREE SIZE]",
1028         "ui32",
1029         {(NV_CHAR *) &hd.pedigree_size},
1030     },
1031     {
1032         "[TZFILE SIZE]",
1033         "ui32",
1034         {(NV_CHAR *) &hd.tzfile_size},
1035     },
1036     {
1037         "[COUNTRY SIZE]",
1038         "ui32",
1039         {(NV_CHAR *) &hd.country_size},
1040     },
1041     {
1042         "[DATUM SIZE]",
1043         "ui32",
1044         {(NV_CHAR *) &hd.datum_size},
1045     },
1046     {
1047         "[LEGALESE SIZE]",
1048         "ui32",
1049         {(NV_CHAR *) &hd.legalese_size},
1050     },
1051     {
1052         "[END OF FILE]",
1053         "ui32",
1054         {(NV_CHAR *) &hd.end_of_file},
1055     }
1056 };
1057 #endif
1058 
1059 
1060 
1061 #endif
1062