/**---------------------------------------------------------------------------
 ** 
 ** access.h -- 
 ** 
 ** Author          : Pierre Jaccard
 ** Created On      : 1999/07/15 23:13:41
 ** Last Modified By: Pierre Jaccard
 ** Last Modified On: 1999/07/16 19:43:00
 ** Update Count    : 10
 ** Directory       : /home/pego/pcd1/codas3c/gfi/src/libs/db/
 ** Version         : 0.0
 ** Status          : Unknown
 ** ---------------------------------------------------------------------- ** 
 ** DESCRIPTION: 
 ** 
 **    See associated file access.c
 ** 
 ** ---------------------------------------------------------------------- ** 
 ** REVISIONS: 
 ** ---------------------------------------------------------------------- ** 
 ** CHANGES: 
 **------------------------------------------------------------------------**/

#ifndef gfilib_db_access_already_included
#define gfilib_db_access_already_included

#include "geninc.h"
#include "dbglo.h"
#include "use_db.h"
#include "gficnv.h"
#include "gfimisc.h"
#include "manip.h"

/*
  The next structure is used to store various information about variables in
  databasses. Note that element count is one for arrays
*/
typedef struct {
	CHAR  name[20];       /* Name of variable            */
	CHAR  elem[20];       /* Element name                */
	CHAR  units[12];      /* Units                       */
	CHAR  unused_1[12];   
	SHORT entry_id;       /* Identifier of variable      */ 
	SHORT value_type;     /* Value type of data          */
	SHORT count;          /* Number of elements          */
	SHORT size;           /* Size of data representation */
	FLOAT offset;         /* Offset for conversion       */
	FLOAT scale;          /* Scaling factor              */
} DB_DATA_INFO_TYPE;

/* 
	 Definitions for database seek indexes
	 */
#define TIME_SEEK       1
#define DAY_SEEK        2
#define LONGITUDE_SEEK  3
#define LATITUDE_SEEK   4
#define BLOCK_SEEK      5
#define BLKPRF_SEEK     6

#if PROTOTYPE_ALLOWED

int split_db_variable_name(char *str, char *name, char *elem);
int init_db_data_info(DB_DATA_INFO_TYPE *dbinfo);
int get_db_variable_id(char *name, int *id);
int get_db_struct_info(char *name, char *elem, DB_DATA_INFO_TYPE *dbinfo);
int get_db_data_info(char *name, char *elem, DB_DATA_INFO_TYPE *dbinfo);
int get_db_data(char *name, char *elem, char **data, int *id, unsigned int *nb);
int get_db_data_f(char *name, char *elem, FLOAT **data, unsigned int *n, 
									int year_base);
int get_db_data_d(char *name, char *elem, DOUBLE **data, unsigned int *n,
									int param);
int get_db_time_d(DOUBLE *yd, int year_base);
int get_db_pos_d(DOUBLE *pos, int lon_180);
int seek_db(char *index, int code, RANGE_TYPE *range, int par, int *n);

#else

#error "Declaration not implemented yet for non-prototypes"

#endif /* PROTOTYPE_ALLOWED */


/*
  Used to test if a variable identifier is associated to a list
*/
#define is_db_struct(x)  (((db->data_list[(x)].value_type) \
													 == STRUCT_VALUE_CODE) ? (1) : (0))
													

#endif /* gfilib_db_access_already_included */
