/*------------------------------------------------------------------------

     B U F R   E N C O D I N G   A N D   D E C O D I N G   S O F T W A R E 

FILE:          DESC.H
IDENT:         $Id: desc.h 17473 2006-08-11 18:41:04Z sip $

AUTHOR:        Konrad Koeck
               Institute of Communication and Wave Propagation, 
               Technical University Graz, Austria

VERSION NUMBER:2.3

DATE CREATED:  18-DEC-2001

STATUS:        DEVELOPMENT FINISHED


FUNCTIONAL DESCRIPTION:
-----------------------
Includefile that defines the data-structures needed to hold the supported
data-descriptors. Function-prototype for READDESC.

AMENDMENT RECORD:

ISSUE       DATE            SCNREF      CHANGE DETAILS
-----       ----            ------      --------------
V2.0        18-DEC-2001     Koeck       Initial Issue

$Log$
Revision 810.1  2006/08/11 18:41:03  sip
Upgrade BUFR library to version 2.3

Revision 1.7  2005/04/04 14:56:09  helmutp
update to version 2.3

Revision 1.6  2003/06/11 08:43:03  helmutp
added serial number to desc struct (for local table overruling)

Revision 1.5  2003/06/06 11:58:21  helmutp
changed read_tables

Revision 1.4  2003/03/27 17:17:39  helmutp
update to version 2.2

Revision 1.3  2003/03/13 17:03:31  helmutp
define local table names, added search key and optional descriptors

Revision 1.2  2003/03/06 17:12:32  helmutp
update to version 2.1

Revision 1.1  2003/02/28 13:41:12  helmutp
Initial revision

--------------------------------------------------------------------------- */

#ifndef DESC_H_INCLUDED
#define DESC_H_INCLUDED

typedef double varfl;    /* Defines the internal float-variable type. This can
                            be float or double. Float needs less memory than
                            double. Double-floats need not to be converted by
                            your machine before operation (software runs 
                            faster).
                            Note that the format-string in all scanf-calls
                            must be changed for VARFL-values !
                         */

#define MISSVAL 9999.999999
                         /* This is the internal missing value indicator.
                            Missing values are indicated as "missing" and if
                            we find such a value we set it internally to
                            MISSVAL
                         */

/*===========================================================================*/
/* definitions of data-structures                                            */
/*===========================================================================*/

typedef struct sect_1 {   /* This structure holds the information contained in section 1 */
  int mtab;      /*  BUFR master table (zero if standard WMO FM 94
                     BUFR tables are used - provides for BUFR to be
                     used to represent data from other disciplines, and
                     with their own versions of master tables and local
                     tables) */
  int subcent;   /*  Originating centre: subcenter */
  int gencent;   /*  Originating centre: generating center */
  int updsequ;   /*  Update sequence number (zero for original BUFR
                     messages; incremented for updates) */
  int opsec;     /*  Bit 1 = 0 No optional section
                           = 1 Optional section included
                     Bits 2 - 8 set to zero (reserved) */
  int dcat;      /*  Data Category type (BUFR Table A) */
  int dcatst;    /*  Data Category sub-type (defined by local ADP centres) */
  int vmtab;     /*  Version number of master tables used (currently 2
                     for WMO FM 94 BUFR tables) */
  int vltab;     /*  Version number of local tables used to augment the master table in use */
  int year;      /*  Year of century */
  int mon;       /*  Month */
  int day;       /*  Day */
  int hour;      /*  Hour */
  int min;       /*  Minute */
} sect_1_t;

typedef struct dd {          /* Structure that describes one data descriptor */
  int f;
  int x;
  int y;
} dd;

typedef struct del {         /* Structure that defines an element descriptor */
  dd d;                      /* Descriptor ID */
  char *unit;                /* Unit */
  int scale;                 /* Scale */
  varfl refval;              /* Reference Value */
  int dw;                    /* Data width (number of bits) */
  char *elname;              /* element name */
} del;

typedef struct dseq {        /* Structure that defines a sequence of descriptors */
  dd d;                      /* sequence-descriptor ID */
  int nel;                   /* Number of elements */
  dd *del;                   /* list of element descriptors */
} dseq;

typedef struct _desc {       /* Structure that defines on descriptor. This can 
                             be an element descriptor or a sequence descriptor */
  int id;                    /* Can be SEQDESC or ELDESC */
  del *el;                   /* Element descriptor */
  dseq *seq;                 /* Sequence descriptor */
  int key;                   /* search key */
  int nr;                    /* serial number (insert position) */
} desc;

#define SEQDESC 0            /* Identifier for a sequence descriptor */
#define ELDESC  1            /* Identifier for an element descriptor */


/*===========================================================================*/
/* variables needed to hold data descriptors                                 */
/* If READDESC_MAIN is not defined all variables are declared as external.   */
/* So you sould define READDESC_MAIN only in one function. Otherwise you will*/
/* have this symbols multiple defined.                                       */
/*===========================================================================*/

#define MAXDESC   2000       /* Max. number of descriptors in the descriptor-file */
#define OPTDESC   4          /* Number of optional descriptors at end */

#ifdef READDESC_MAIN
  int ndes;                  /* Number of descriptors found in the descriptor file */
  desc *des[MAXDESC+OPTDESC];/* data descriptors */
  int dw = 128;              /* add dw - 128 to the data-width (dw can be optionally set by 2 01 YYY) */
  int sc = 128;              /* multiply the scale-factor by (sc - 128). sc can be optionally set by 2 02 YYY */
  int addfields = 0;         /* Number of additional fields to be added to any data-item. addfields can be canceled by 2 04 000 */
  int ccitt_special = 0;     /* This value is pointing to a special descriptor we need to encode a single character of a character string */
  int cf_special = 0;        /* This value is pointing to a special descriptor we need to encode new reference values changed by 2 03 YYY  */
  int add_f_special = 0;     /* This value is pointing to a special descriptor we need to encode assiciated fields  */
#else
  extern int ndes;
  extern desc *des[MAXDESC+OPTDESC];
  extern int dw;
  extern int sc;
  extern int addfields;
  extern int ccitt_special;
  extern int cf_special;
  extern int add_f_special;
#endif

/*===========================================================================*/
/* The following definition will be used to have either                      */
/* function-prototyping in ANSI-C e.g.: void abc (int a, int b);   or        */
/* Kernighan-Ritchie-prototyping link   void abc ();                         */
/*===========================================================================*/

#if defined (NON_ANSI)
#define P0
#define P1(a)                
#define P2(a,b)              
#define P3(a,b,c)            
#define P4(a,b,c,d)          
#define P5(a,b,c,d,e)        
#define P6(a,b,c,d,e,f)      
#define P7(a,b,c,d,e,f,g)    
#define P8(a,b,c,d,e,f,g,h)  
#else
#define P0                   void
#define P1(a)                a
#define P2(a,b)              a,b
#define P3(a,b,c)            a,b,c
#define P4(a,b,c,d)          a,b,c,d
#define P5(a,b,c,d,e)        a,b,c,d,e
#define P6(a,b,c,d,e,f)      a,b,c,d,e,f
#define P7(a,b,c,d,e,f,g)    a,b,c,d,e,f,g
#define P8(a,b,c,d,e,f,g,h)  a,b,c,d,e,f,g,h
#endif

/* for compilers having SEEK_CUR and SEEK_SET not defined: */

#ifndef SEEK_SET
#define SEEK_SET 0
#endif
#ifndef SEEK_END
#define SEEK_END 2
#endif

/*===========================================================================*/
/* function prototype                                                        */
/*===========================================================================*/

int read_tab_b (P1(char *fname));
int read_tab_d (P1(char *fname));
char *get_unit (P1(dd *d));
int get_index (P2(int typ, dd *d));
void free_descs (P1(void));
void trim (P1(char *buf));
int read_tables (P5(char *dir, int vm, int vl, int subcenter, int gencenter));
void show_desc (P3(int f, int x, int y));

#endif

/* end of file */
