libdballe 4.0.18
vartable.h
Go to the documentation of this file.
00001 /*
00002  * DB-ALLe - Archive for punctual meteorological data
00003  *
00004  * Copyright (C) 2005--2008  ARPA-SIM <urpsim@smr.arpa.emr.it>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00018  *
00019  * Author: Enrico Zini <enrico@enricozini.com>
00020  */
00021 
00022 #ifndef DBA_VARTABLE_H
00023 #define DBA_VARTABLE_H
00024 
00025 #ifdef  __cplusplus
00026 extern "C" {
00027 #endif
00028 
00085 #include <dballe/core/error.h>
00086 
00090 typedef short unsigned int dba_varcode;
00091 
00097 typedef short unsigned int dba_alteration;
00098 
00106 struct _dba_varinfo
00107 {
00109     dba_varcode var;
00111     char desc[64];
00113     char unit[24];
00116     int scale;
00119     int ref;
00122     int len;
00125     int bit_ref;
00128     int bit_len;
00130     int is_string;
00132     int imin;
00134     int imax;
00136     double dmin;
00138     double dmax;
00140     dba_alteration alteration;
00142     struct _dba_varinfo* alterations;
00144     char bufr_unit[24];
00146     int bufr_scale;
00147 };
00149 typedef struct _dba_varinfo* dba_varinfo;
00150 
00158 struct _dba_vartable;
00160 typedef struct _dba_vartable* dba_vartable;
00161 
00165 #define DBA_VAR(f, x, y) ((dba_varcode)( ((unsigned)(f)<<14) | ((unsigned)(x)<<8) | (unsigned)(y) ))
00166 
00173 #define DBA_STRING_TO_VAR(str) ((dba_varcode)( \
00174         (( ((str)[0] - '0')*10 + ((str)[1] - '0') ) << 8) | \
00175         ( ((str)[2] - '0')*100 + ((str)[3] - '0')*10 + ((str)[4] - '0') ) \
00176 ))
00177 
00181 #define DBA_VAR_F(code) ((code) >> 14)
00182 
00185 #define DBA_VAR_X(code) ((code) >> 8 & 0x3f)
00186 
00189 #define DBA_VAR_Y(code) ((code) & 0xff)
00190 
00194 #define DBA_ALT(width, scale) (((width)+128) << 8 | ((scale)+128))
00195 
00199 #define DBA_ALT_WIDTH(code) (((code) >> 8) - 128)
00200 
00204 #define DBA_ALT_SCALE(code) (((code) & 0xff) - 128)
00205 
00218 dba_err dba_varinfo_query_local(dba_varcode code, dba_varinfo* info);
00219 
00234 dba_err dba_varinfo_query_local_altered(dba_varcode code, dba_alteration change, dba_varinfo* info);
00235 
00246 dba_err dba_varinfo_get_local_table(dba_vartable* table);
00247 
00258 dba_varcode dba_descriptor_code(const char* desc);
00259 
00268 int dba_vartable_exists(const char* id);
00269 
00282 dba_err dba_vartable_create(const char* id, dba_vartable* table);
00283 
00293 const char* dba_vartable_id(dba_vartable table);
00294 
00309 dba_err dba_vartable_query(dba_vartable table, dba_varcode var, dba_varinfo* info);
00310 
00327 dba_err dba_vartable_query_altered(dba_vartable table, dba_varcode var, dba_alteration change, dba_varinfo* info);
00328 
00337 typedef void (*dba_vartable_iterator)(dba_varinfo info, void* data);
00338 
00351 dba_err dba_vartable_iterate(dba_vartable table, dba_vartable_iterator func, void* data);
00352 
00353 #ifdef  __cplusplus
00354 }
00355 #endif
00356 
00357 #endif
00358 /* vim:set ts=4 sw=4: */