/**---------------------------------------------------------------------------
 ** 
 ** dnmi_.h -- 
 ** 
 ** Author          : Pierre Jaccard
 ** Created On      : 1999/08/02 09:26:47
 ** Last Modified By: Pierre Jaccard
 ** Last Modified On: 1999/08/02 09:42:38
 ** Update Count    : 4
 ** Directory       : /home/pego/pcd1/codas3c/gfi/src/apps/misc/
 ** Version         : 0.0
 ** Status          : Unknown
 ** ---------------------------------------------------------------------- ** 
 ** DESCRIPTION: 
 ** 
 **    Undocumented.
 ** 
 ** ---------------------------------------------------------------------- ** 
 ** REVISIONS: 
 ** ---------------------------------------------------------------------- ** 
 ** CHANGES: 
 **------------------------------------------------------------------------**/

#ifndef  dnmi__already_included
#define  dnmi__already_included

#include "geninc.h"
#include "ioserv.h"
#include "use_db.h"
#include "gfimisc.h"

/* ------------------------------------------------------------------
	 -Definitions:
	 ------------------------------------------------------------------ */

#define DNMI_HEADER_SIZE        20
#define DNMI_HEADER_DELIM       40
#define DNMI_ARRAY_DELIM     29232

#define DNMI_S_CODE            301
#define DNMI_U_CODE            302
#define DNMI_V_CODE            303

#ifdef  LONGITUDE_180_CODE
#undef  LONGITUDE_180_CODE
#endif
#ifdef  LONGITUDE_180_BIT
#undef  LONGITUDE_180_BIT
#endif

#define LONGITUDE_180_CODE       0
#define LONGITUDE_180_BIT      ((ULONG) (to_bit(LONGITUDE_180_CODE)))

/* ------------------------------------------------------------------
	 -Type Definitions for DNMI 2D Tide Data:
	 ------------------------------------------------------------------ */

/* ---------------------------------
	 This is a copy of the DNMI header
	 --------------------------------- */

typedef struct
{
  USHORT producer; 
	USHORT grid_area; 
	USHORT prognosis; 
	USHORT relative_hour;
	USHORT vertical_coord_type; 
	USHORT data_type;
	USHORT unused_1;
	USHORT vertical_reference;
	USHORT grid_type;
	USHORT x_grid_number;
	USHORT y_grid_number;
	USHORT origin_year;
	USHORT origin_month_day;
 	USHORT origin_hour;
	SHORT  x_coord_N_pole; 
	SHORT  y_coord_N_pole;
	SHORT  grid_spacing;
	SHORT  y_axis_parallel_longitude;
	USHORT unused_2;
	SHORT  scaling_factor;
} DNMI_HEADER_TYPE;

/* ---------------------------------
	 This is for storing data from DNMI files
	 --------------------------------- */

typedef struct
{
	DNMI_HEADER_TYPE hdr;         /* Header                   */
	SHORT            *data;       /* Pointer to array of data */
} DNMI_DATA_TYPE;

/* ---------------------------------
	 These are structures for specified ranges
	 --------------------------------- */

typedef struct
{
	DMSH_LL_TYPE min;
	DMSH_LL_TYPE max;
} DNMI_POS_RNG_TYPE;

typedef struct
{
	YMDHMS_TIME_TYPE min;
	YMDHMS_TIME_TYPE max;
} DNMI_TIME_RNG_TYPE;

typedef struct
{
	DNMI_POS_RNG_TYPE  pos;
	DNMI_TIME_RNG_TYPE time;
	int *index;                 /* Pointer to array of index flags */
	int  n;                     /* Number of good indexes          */
} DNMI_RNG_TYPE;

/* ---------------------------------
	 This is to have a copy of the CONFIGURATION_1 variable
	 --------------------------------- */

typedef struct
{
	FLOAT  x_coord_N_pole; 
	FLOAT  y_coord_N_pole;
	FLOAT  grid_spacing;
	FLOAT  grid_points;
	FLOAT  y_axis_parallel_longitude;
	FLOAT  U_scaling_factor;
	FLOAT  V_scaling_factor;
	FLOAT  S_scaling_factor;
  USHORT producer; 
	USHORT grid_area; 
	USHORT prognosis; 
	USHORT vertical_coord_type; 
	SHORT  vertical_coord_reference;
	USHORT grid_type;
	USHORT x_grid_number;
	USHORT y_grid_number;
	USHORT origin_year;
	USHORT origin_month;
	USHORT origin_day;
	USHORT origin_hour;
	BYTE   grid_spacing_flag;
	BYTE   original_host_type;
} DNMI_CONFIGURATION_1_TYPE;

/* ---------------------------------
	 This is a copy of the ANCILLARY_1 variable
	 --------------------------------- */
typedef struct
{
	USHORT rel_hour;
} DNMI_ANCILLARY_1_TYPE;

/* ---------------------------------
	 This is a copy of the BLOCK variables
	 --------------------------------- */

typedef struct
{
	DNMI_CONFIGURATION_1_TYPE config_1;
	FLOAT *x;
	FLOAT *y;
} DNMI_DB_BLK_TYPE;

/* ---------------------------------
	 This is a copy of the PROFILE variables
	 --------------------------------- */

typedef struct 
{
	FLOAT *u;
	FLOAT *v;
	FLOAT *s;
	UBYTE *f;
	DNMI_ANCILLARY_1_TYPE anc_1;
} DNMI_DB_PRF_TYPE;

/* ---------------------------------
	 This groups information specified in the definitions file
	 --------------------------------- */

typedef struct
{
	DNMI_DB_BLK_TYPE blk;
	DNMI_DB_PRF_TYPE prf;
} DNMI_DB_TYPE;

/* ---------------------------------
	 This groups conversion parameters and other miscellaneous things
	 --------------------------------- */

typedef struct 
{
	int    n_data;       /* Number of grid data points     */
	double grid_points;  /* Position conversion parameter  */
	int    from_host;    /* Original host environment type */
	ULONG  bits;         /* Option bits                    */
} DNMI_MISC_TYPE;
	 
/* ---------------------------------
	 This groups everything into one structure
	 --------------------------------- */

typedef struct
{
	DNMI_DATA_TYPE    s, u, v;       /* Data from DNMI file              */
	DNMI_RNG_TYPE     *rng;          /* User specified ranges            */
	YMDHMS_TIME_TYPE  prf_time;      /* Current profile time             */
	double            *lat, *lon;    /* Geographical positions           */
	DNMI_MISC_TYPE    *misc;
	DNMI_DB_TYPE      db;            /* Database copy                    */
} DNMI_PROFILE_TYPE;

/* ------------------------------------------------------------------
	 -Functions:
	 ------------------------------------------------------------------ */

#if PROTOTYPE_ALLOWED
int dnmi_free_pointer(char **p);
#else
int dnmi_free_pointer();
#endif

#if PROTOTYPE_ALLOWED
int init_dnmi(DNMI_PROFILE_TYPE *dnmi);
#else
int init_dnmi();
#endif

#if PROTOTYPE_ALLOWED
int dnmi_free_data(DNMI_PROFILE_TYPE *dnmi);
#else
int dnmi_free_data();
#endif

#if PROTOTYPE_ALLOWED
int read_dnmi_data(FILE *fp, char *data, int n, int from_host, int code);
#else
int read_dnmi_data();
#endif

#if PROTOTYPE_ALLOWED
int get_dnmi_profile(FILE *fp, DNMI_PROFILE_TYPE *dnmi);
#else
int get_dnmi_profile();
#endif

#if PROTOTYPE_ALLOWED
int dnmi_to_ymdhmh_time(YMDHMS_TIME_TYPE *time, DNMI_HEADER_TYPE *hdr);
#else
int dnmi_to_ymdhmh_time();
#endif

#if PROTOTYPE_ALLOWED
int dnmi_to_gpos(DNMI_PROFILE_TYPE *dnmi);
#else
int dnmi_to_gpos();
#endif

#if PROTOTYPE_ALLOWED
int dnmi_set_xy(DNMI_PROFILE_TYPE *dnmi);
#else
int dnmi_set_xy();
#endif

#if PROTOTYPE_ALLOWED
int dnmi_cmp_hdr(DNMI_HEADER_TYPE *h0, DNMI_HEADER_TYPE *h1);
#else
int ();
#endif



#endif /* dnmi__already_included */
