Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

GRIB.h

Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 //
00003 //  File        : GRIB.h
00004 //  Description : Grib file version1 interface
00005 //  Project     : LAMMA 2004
00006 //  Author      : Graziano Giuliani (LaMMA Regione Toscana)
00007 //  References  : http://www.wmo.ch/web/www/WDM/Guides/Guide-binary-2.html
00008 //  RCS ID      : $Id: GRIB.h,v 1.4 2004/09/03 15:00:47 ocean Exp $
00009 //
00010 //  This program is free software; you can redistribute it and/or modify
00011 //  it under the terms of the GNU General Public License as published by
00012 //  the Free Software Foundation; either version 2 of the License, or
00013 //  (at your option) any later version.
00014 //
00015 //  This program is distributed in the hope that it will be useful,
00016 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 //  GNU General Public License for more details.
00019 //
00020 //  You should have received a copy of the GNU General Public License
00021 //  along with this program; if not, write to the Free Software
00022 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 //
00024 //-----------------------------------------------------------------------------
00025 
00026 #include <string>
00027 #include <cstdio>
00028 
00030 typedef enum t_enum_GRIB_CENTER {
00031   GRIB_CENTER_UNKNOWN = -1,
00032   GRIB_CENTER_MELB    = 1,  
00033   GRIB_CENTER_MOSCOW  = 4,  
00034   GRIB_CENTER_NMC     = 7,  
00035   GRIB_CENTER_NWSTG   = 8,  
00036   GRIB_CENTER_JMA     = 34, 
00037   GRIB_CENTER_BEIJING = 38, 
00038   GRIB_CENTER_BSA     = 46, 
00039   GRIB_CENTER_NHC     = 52, 
00040   GRIB_CENTER_CMC     = 54, 
00041   GRIB_CENTER_GWC     = 57, 
00042   GRIB_CENTER_FNOC    = 58, 
00043   GRIB_CENTER_NOAA    = 59, 
00044   GRIB_CENTER_NCAR    = 60, 
00045   GRIB_CENTER_UKMO    = 74, 
00046   GRIB_CENTER_DWD     = 78, 
00047   GRIB_CENTER_ROME    = 80, 
00048   GRIB_CENTER_FWS     = 85, 
00049   GRIB_CENTER_ESA     = 97, 
00050   GRIB_CENTER_KNMI    = 94, 
00051   GRIB_CENTER_ECMWF   = 98, 
00052   GRIB_CENTER_LOCAL   = 128 
00053 } t_enum_GRIB_CENTER;
00054 
00056 typedef enum t_enum_GRIB_SUBCENTER {
00057   GRIB_SUBCENTER_UNKNOWN = -1,
00058   GRIB_SUBCENTER_LOCAL   = 128
00059 } t_enum_GRIB_SUBCENTER;
00060 
00062 typedef enum t_enum_GRIB_TABLE {
00063   GRIB_TABLE_UNKNOWN       = -1,
00064   GRIB_TABLE_INTERNATIONAL = 2,
00065   GRIB_TABLE_LOCAL         = 128
00066 } t_enum_GRIB_TABLE;
00067 
00069 typedef enum t_enum_GRIB_PROCESS {
00070   GRIB_PROCESS_UNKNOWN = -1,
00071   GRIB_PROCESS_LOCAL   = 128
00072 } t_enum_GRIB_PROCESS;
00073 
00075 typedef enum t_enum_GRIB_PARAMETER_TABLE_VERSION2 {
00076   GRIB_PARAMETER_UNKNOWN  = -1,
00077   GRIB_PARAMETER_RESERVED = 0,
00078   GRIB_PARAMETER_PRES_    = 1,   
00079   GRIB_PARAMETER_PRMSL    = 2,   
00080   GRIB_PARAMETER_PTEND    = 3,   
00081   GRIB_PARAMETER_PVORT    = 4,   
00082   GRIB_PARAMETER_ICAHT    = 5,   
00083   GRIB_PARAMETER_GP___    = 6,   
00084   GRIB_PARAMETER_HGT__    = 7,   
00085   GRIB_PARAMETER_DIST_    = 8,   
00086   GRIB_PARAMETER_HSTDV    = 9,   
00087   GRIB_PARAMETER_TOZNE    = 10,  
00088   GRIB_PARAMETER_TMP__    = 11,  
00089   GRIB_PARAMETER_VTMP_    = 12,  
00090   GRIB_PARAMETER_POT__    = 13,  
00091   GRIB_PARAMETER_EPOT_    = 14,  
00092   GRIB_PARAMETER_T_MAX    = 15,  
00093   GRIB_PARAMETER_T_MIN    = 16,  
00094   GRIB_PARAMETER_DPT__    = 17,  
00095   GRIB_PARAMETER_DEPR_    = 18,  
00096   GRIB_PARAMETER_LAPR_    = 19,  
00097   GRIB_PARAMETER_VIS__    = 20,  
00098   GRIB_PARAMETER_RDSP1    = 21,  
00099   GRIB_PARAMETER_RDSP2    = 22,  
00100   GRIB_PARAMETER_RDSP3    = 23,  
00101   GRIB_PARAMETER_PLI__    = 24,  
00102   GRIB_PARAMETER_TMP_A    = 25,  
00103   GRIB_PARAMETER_PRESA    = 26,  
00104   GRIB_PARAMETER_GP_A_    = 27,  
00105   GRIB_PARAMETER_WVSP1    = 28,  
00106   GRIB_PARAMETER_WVSP2    = 29,  
00107   GRIB_PARAMETER_WVSP3    = 30,  
00108   GRIB_PARAMETER_WDIR_    = 31,  
00109   GRIB_PARAMETER_WIND_    = 32,  
00110   GRIB_PARAMETER_U_GRD    = 33,  
00111   GRIB_PARAMETER_V_GRD    = 34,  
00112   GRIB_PARAMETER_STRM_    = 35,  
00113   GRIB_PARAMETER_V_POT    = 36,  
00114   GRIB_PARAMETER_MNTSF    = 37,  
00115   GRIB_PARAMETER_SGCVV    = 38,  
00116   GRIB_PARAMETER_V_VEL    = 39,  
00117   GRIB_PARAMETER_DZDT_    = 40,  
00118   GRIB_PARAMETER_ABS_V    = 41,  
00119   GRIB_PARAMETER_ABS_D    = 42,  
00120   GRIB_PARAMETER_REL_V    = 43,  
00121   GRIB_PARAMETER_REL_D    = 44,  
00122   GRIB_PARAMETER_VUCSH    = 45,  
00123   GRIB_PARAMETER_VVCSH    = 46,  
00124   GRIB_PARAMETER_DIR_C    = 47,  
00125   GRIB_PARAMETER_SP_C_    = 48,  
00126   GRIB_PARAMETER_UOGRD    = 49,  
00127   GRIB_PARAMETER_VOGRD    = 50,  
00128   GRIB_PARAMETER_SPF_H    = 51,  
00129   GRIB_PARAMETER_R_H__    = 52,  
00130   GRIB_PARAMETER_MIXR_    = 53,  
00131   GRIB_PARAMETER_P_WAT    = 54,  
00132   GRIB_PARAMETER_VAPP_    = 55,  
00133   GRIB_PARAMETER_SAT_D    = 56,  
00134   GRIB_PARAMETER_EVP__    = 57,  
00135   GRIB_PARAMETER_C_ICE    = 58,  
00136   GRIB_PARAMETER_PRATE    = 59,  
00137   GRIB_PARAMETER_TSTM_    = 60,  
00138   GRIB_PARAMETER_A_PCP    = 61,  
00139   GRIB_PARAMETER_NCPCP    = 62,  
00140   GRIB_PARAMETER_ACPCP    = 63,  
00141   GRIB_PARAMETER_SRWEQ    = 64,  
00142   GRIB_PARAMETER_WEASD    = 65,  
00143   GRIB_PARAMETER_SNO_D    = 66,  
00144   GRIB_PARAMETER_MIXHT    = 67,  
00145   GRIB_PARAMETER_TTHDP    = 68,  
00146   GRIB_PARAMETER_MTHD_    = 69,  
00147   GRIB_PARAMETER_MTH_A    = 70,  
00148   GRIB_PARAMETER_T_CDC    = 71,  
00149   GRIB_PARAMETER_CDCON    = 72,  
00150   GRIB_PARAMETER_L_CDC    = 73,  
00151   GRIB_PARAMETER_M_CDC    = 74,  
00152   GRIB_PARAMETER_H_CDC    = 75,  
00153   GRIB_PARAMETER_C_WAT    = 76,  
00154   GRIB_PARAMETER_BLI__    = 77,  
00155   GRIB_PARAMETER_SNO_C    = 78,  
00156   GRIB_PARAMETER_SNO_L    = 79,  
00157   GRIB_PARAMETER_WTMP_    = 80,  
00158   GRIB_PARAMETER_LAND_    = 81,  
00159   GRIB_PARAMETER_DSL_M    = 82,  
00160   GRIB_PARAMETER_SFC_R    = 83,  
00161   GRIB_PARAMETER_ALBDO    = 84,  
00162   GRIB_PARAMETER_TSOIL    = 85,  
00163   GRIB_PARAMETER_SOILM    = 86,  
00164   GRIB_PARAMETER_VEG__    = 87,  
00165   GRIB_PARAMETER_SALTY    = 88,  
00166   GRIB_PARAMETER_DEN__    = 89,  
00167   GRIB_PARAMETER_WATR_    = 90,  
00168   GRIB_PARAMETER_ICE_C    = 91,  
00169   GRIB_PARAMETER_ICETK    = 92,  
00170   GRIB_PARAMETER_DICED    = 93,  
00171   GRIB_PARAMETER_SICED    = 94,  
00172   GRIB_PARAMETER_U_ICE    = 95,  
00173   GRIB_PARAMETER_V_ICE    = 96,  
00174   GRIB_PARAMETER_ICE_G    = 97,  
00175   GRIB_PARAMETER_ICE_D    = 98,  
00176   GRIB_PARAMETER_SNO_M    = 99,  
00177   GRIB_PARAMETER_HTSGW    = 100, 
00178   GRIB_PARAMETER_WVDIR    = 101, 
00179   GRIB_PARAMETER_WVHGT    = 102, 
00180   GRIB_PARAMETER_WVPER    = 103, 
00181   GRIB_PARAMETER_SWDIR    = 104, 
00182   GRIB_PARAMETER_SWELL    = 105, 
00183   GRIB_PARAMETER_SWPER    = 106, 
00184   GRIB_PARAMETER_DIRPW    = 107, 
00185   GRIB_PARAMETER_PERPW    = 108, 
00186   GRIB_PARAMETER_DIRSW    = 109, 
00187   GRIB_PARAMETER_PERSW    = 110, 
00188   GRIB_PARAMETER_NSWRS    = 111, 
00189   GRIB_PARAMETER_NLWRS    = 112, 
00190   GRIB_PARAMETER_NSWRT    = 113, 
00191   GRIB_PARAMETER_NLWRT    = 114, 
00192   GRIB_PARAMETER_LWAVR    = 115, 
00193   GRIB_PARAMETER_SWAVR    = 116, 
00194   GRIB_PARAMETER_G_RAD    = 117, 
00195   GRIB_PARAMETER_BRTMP    = 118, 
00196   GRIB_PARAMETER_LWRAD    = 119, 
00197   GRIB_PARAMETER_SWRAD    = 120, 
00198   GRIB_PARAMETER_LHTFL    = 121, 
00199   GRIB_PARAMETER_SHTFL    = 122, 
00200   GRIB_PARAMETER_BLYDP    = 123, 
00201   GRIB_PARAMETER_U_FLX    = 124, 
00202   GRIB_PARAMETER_V_FLX    = 125, 
00203   GRIB_PARAMETER_WMIXE    = 126, 
00204   GRIB_PARAMETER_IMG_D    = 127, 
00205   GRIB_PARAMETER_LOCALUSE = 128, 
00206   GRIB_PARAMETER_MISSING  = 255  
00207 } t_enum_GRIB_PARAMETER_TABLE_VERSION2;
00208 
00210 typedef enum t_enum_GRIB_TIMEUNIT {
00211   GRIB_TIMEUNIT_UNKNOWN = -1,  
00212   GRIB_TIMEUNIT_MINUTE  = 0,   
00213   GRIB_TIMEUNIT_HOUR    = 1,   
00214   GRIB_TIMEUNIT_DAY     = 2,   
00215   GRIB_TIMEUNIT_MONTH   = 3,   
00216   GRIB_TIMEUNIT_YEAR    = 4,   
00217   GRIB_TIMEUNIT_DECADE  = 5,   
00218   GRIB_TIMEUNIT_NORMAL  = 6,   
00219   GRIB_TIMEUNIT_CENTURY = 7,   
00220   GRIB_TIMEUNIT_HOURS3  = 10,  
00221   GRIB_TIMEUNIT_HOURS6  = 11,  
00222   GRIB_TIMEUNIT_HOURS12 = 12,  
00223   GRIB_TIMEUNIT_SECOND  = 254  
00224 } t_enum_GRIB_TIMEUNIT;
00225 
00227 typedef enum t_enum_GRIB_TIMERANGE {
00228   GRIB_TIMERANGE_UNKNOWN                                                  = -1,
00229   GRIB_TIMERANGE_FORECAST_AT_REFTIME_PLUS_P1                              = 0,
00230   GRIB_TIMERANGE_ANALYSIS_AT_REFTIME                                      = 1,
00231   GRIB_TIMERANGE_VALID_IN_REFTIME_PLUS_P1_REFTIME_PLUS_P2                 = 2,
00232   GRIB_TIMERANGE_AVERAGE_IN_REFTIME_PLUS_P1_REFTIME_PLUS_P2               = 3,
00233   GRIB_TIMERANGE_ACCUMULATED_INTERVAL_REFTIME_PLUS_P1_REFTIME_PLUS_P2     = 4,
00234   GRIB_TIMERANGE_DIFFERENCE_REFTIME_PLUS_P2_REFTIME_PLUS_P1               = 5,
00235   GRIB_TIMERANGE_AVERAGE_IN_REFTIME_MINUS_P1_REFTIME_MINUS_P2             = 6,
00236   GRIB_TIMERANGE_AVERAGE_IN_REFTIME_MINUS_P1_REFTIME_PLUS_P2              = 7,
00237   GRIB_TIMERANGE_VALID_AT_REFTIME_PLUS_P1P2                               = 10,
00238   GRIB_TIMERANGE_CLIMATOLOGICAL_MEAN_OVER_MULTIPLE_YEARS_FOR_P2           = 51,
00239   GRIB_TIMERANGE_AVERAGE_OVER_FORECAST_OF_PERIOD_P1_REFTIME_PERIOD_P2     = 113,
00240   GRIB_TIMERANGE_ACCUMULATED_OVER_FORECAST_PERIOD_P1_REFTIME_PERIOD_P2    = 114,
00241   GRIB_TIMERANGE_AVERAGE_OVER_FORECAST_OF_PERIOD_P1_AT_INTERVALS_P2       = 115,
00242   GRIB_TIMERANGE_ACCUMULATION_OVER_FORECAST_PERIOD_P1_AT_INTERVALS_P2     = 116,
00243   GRIB_TIMERANGE_AVERAGE_OVER_FORECAST_FIRST_P1_OTHER_P2_REDUCED          = 117,
00244   GRIB_TIMERANGE_VARIANCE_OF_ANALYSES_WITH_REFERENCE_TIME_INTERVALS_P2    = 118,
00245   GRIB_TIMERANGE_STDDEV_OF_FORECASTS_FIRST_P1_OTHER_P2_REDUCED            = 119,
00246   GRIB_TIMERANGE_AVERAGE_OVER_ANALYSES_AT_INTERVALS_OF_P2                 = 123,
00247   GRIB_TIMERANGE_ACCUMULATION_OVER_ANALYSES_AT_INTERVALS_OF_P2            = 124,
00248   GRIB_TIMERANGE_STDDEV_OF_FORECASTS_RESPECT_TO_AVERAGE_OF_TENDENCY       = 125,
00249   GRIB_TIMERANGE_AVERAGE_OF_DAILY_FORECAST_ACCUMULATIONS                  = 128,
00250   GRIB_TIMERANGE_AVERAGE_OF_SUCCESSIVE_FORECAST_ACCUMULATIONS             = 129,
00251   GRIB_TIMERANGE_AVERAGE_OF_DAILY_FORECAST_AVERAGES                       = 130,
00252   GRIB_TIMERANGE_AVERAGE_OF_SUCCESSIVE_FORECAST_AVERAGES                  = 131
00253 } t_enum_GRIB_TIMERANGE;
00254 
00256 typedef enum t_enum_GRIB_GRIDS {
00257   GRIB_GRID_UNKNOWN                = -1,
00258   GRIB_GRID_REGULAR_LATLON         = 0,
00259   GRIB_GRID_MERCATOR               = 1,
00260   GRIB_GRID_GNOMONIC               = 2,
00261   GRIB_GRID_LAMBERT_CONFORMAL      = 3,
00262   GRIB_GRID_GAUSSIAN               = 4,
00263   GRIB_GRID_POLAR_STEREOGRAPHIC    = 5,
00264   GRIB_GRID_UTM                    = 6,
00265   GRIB_GRID_SIMPLE_POLYCONIC       = 7,
00266   GRIB_GRID_ALBERS_EQUAL_AREA      = 8,
00267   GRIB_GRID_MILLER_CYLINDRICAL     = 9,
00268   GRIB_GRID_ROTATED_LATLON         = 10,
00269   GRIB_GRID_OBLIQUE_LAMBERT        = 13,
00270   GRIB_GRID_ROTATED_GAUSSIAN       = 14,
00271   GRIB_GRID_STRETCHED_LATLON       = 20,
00272   GRIB_GRID_STRETCHED_GAUSSIAN     = 24,
00273   GRIB_GRID_STRETCHED_ROT_LATLON   = 30,
00274   GRIB_GRID_STRETCHED_ROT_GAUSSIAN = 34,
00275   GRIB_GRID_SPHERICAL_HARMONIC_COE = 50,
00276   GRIB_GRID_ROTATED_SPHER_HARM_COE = 60,
00277   GRIB_GRID_STRETCH_SPHER_HARM_COE = 70,
00278   GRIB_GRID_STRETCHED_ROT_SP_H_COE = 80,
00279   GRIB_GRID_SPACEVIEW              = 90
00280 } t_enum_GRIB_GRIDS;
00281 
00283 typedef enum t_enum_GRIB_LEVELS {
00284   GRIB_LEVEL_UNKNOWN = -1,
00285   GRIB_LEVEL_RESERVED = 0,
00286   GRIB_LEVEL_SURFACE,
00287   GRIB_LEVEL_CLOUD_BASE,
00288   GRIB_LEVEL_CLOUD_TOP,
00289   GRIB_LEVEL_ISOTHERM_0_DEG,
00290   GRIB_LEVEL_ADIABATIC_CONDENSATION_LIFTED_FROM_SURFACE,
00291   GRIB_LEVEL_MAXIMUM_WIND,
00292   GRIB_LEVEL_TROPOPAUSE,
00293   GRIB_LEVEL_NOMINAL_ATMOSPHERE_TOP,
00294   GRIB_LEVEL_SEA_BOTTOM,
00295   GRIB_LEVEL_ISOTHERMAL_K = 20,
00296   GRIB_LEVEL_ISOBARIC_mb = 100,
00297   GRIB_LEVEL_LAYER_ISOBARIC_mb,
00298   GRIB_LEVEL_MEAN_SEA_LEVEL,
00299   GRIB_LEVEL_ALTITUDE_ABOVE_MSL_m,
00300   GRIB_LEVEL_LAYER_ALTITUDE_ABOVE_MSL_m,
00301   GRIB_LEVEL_HEIGHT_ABOVE_GROUND_m,
00302   GRIB_LEVEL_LAYER_HEIGHT_ABOVE_GROUND_m,
00303   GRIB_LEVEL_SIGMA,
00304   GRIB_LEVEL_LAYER_SIGMA,
00305   GRIB_LEVEL_HYBRID,
00306   GRIB_LEVEL_LAYER_HYBRID,
00307   GRIB_LEVEL_DEPTH_BELOW_SURFACE_cm,
00308   GRIB_LEVEL_LAYER_DEPTH_BELOW_SURFACE_cm,
00309   GRIB_LEVEL_ISENTROPIC_K,
00310   GRIB_LEVEL_LAYER_ISENTROPIC_K,
00311   GRIB_LEVEL_PRESSURE_DIFFERENCE_FROM_GROUND_mb,
00312   GRIB_LEVEL_LAYER_PRESSURE_DIFFERENCE_FROM_GROUND_mb,
00313   GRIB_LEVEL_POTENTIAL_VORTICITY_SURFACE_PV_UNITS,
00314   GRIB_LEVEL_ETA,
00315   GRIB_LEVEL_LAYER_ETA,
00316   GRIB_LEVEL_LAYER_ISOBARIC_HIGH_PRECISION_mb,
00317   GRIB_LEVEL_HEIGHT_ABOVE_GROUND_HIGH_PRECISION_cm,
00318   GRIB_LEVEL_ISOBARIC_Pa,
00319   GRIB_LEVEL_LAYER_SIGMA_HIGH_PRECISION,
00320   GRIB_LEVEL_LAYER_ISOBARIC_MIXED_PRECISION_mb,
00321   GRIB_LEVEL_DEPTH_BELOW_SEA_m = 160,
00322   GRIB_LEVEL_ENTIRE_ATMOSPHERE = 200,
00323   GRIB_LEVEL_ENTIRE_OCEAN,
00324   GRIB_LEVEL_SPECIAL = 204
00325 } t_enum_GRIB_LEVELS;
00326 
00327 // ############################################################################
00328 // Interface to time definition
00329 // ############################################################################
00330 
00342 class GRIB_TIME {
00343   public:
00345     GRIB_TIME( );
00346 
00349     void Decode(unsigned char *pds);
00350 
00352     unsigned char *Encode( );
00353 
00366     void set(int year, int month, int day, int hour, int minute,
00367              t_enum_GRIB_TIMEUNIT tu, t_enum_GRIB_TIMERANGE tr,
00368              int time1, int time2, int nave, int nmiss);
00369 
00376     void set_referencetime(int year, int month, int day, int hour, int minute);
00377 
00379     void set_analysis( );
00380 
00383     void set_forecast_hour(int hforecast);
00384 
00386     std::string Reftime( );
00387 
00389     std::string Reftime2000( );
00390 
00392     std::string TimeString( );
00393 
00396     std::string ValidTime( );
00397 
00399     time_t ForecastSeconds( );
00400 
00402     time_t ForecastSeconds2000( );
00403 
00405     t_enum_GRIB_TIMEUNIT timeunit;
00406 
00408     t_enum_GRIB_TIMERANGE timerange;
00409 
00411     friend std::ostream& operator<< ( std::ostream& os, GRIB_TIME &t );
00412 
00414     std::string reftime;
00415 
00417     std::string timestring;
00418 
00420     int year;
00422     int month;
00424     int day;
00426     int hour;
00428     int minute;
00430     int p1;
00432     int p2;
00434     int p1p2;
00436     int naveraged, nmissing;
00437 
00439   private:
00440     void set_time(t_enum_GRIB_TIMEUNIT tu, t_enum_GRIB_TIMERANGE tr, int time);
00441     void set_time(t_enum_GRIB_TIMEUNIT tu, t_enum_GRIB_TIMERANGE tr,
00442                   int time1, int time2);
00443     void set_time(t_enum_GRIB_TIMEUNIT tu, t_enum_GRIB_TIMERANGE tr,
00444                   int time1, int time2, int nave, int nmiss);
00445     char *timeunitstr( );
00446     void strref( );
00447     void strtime( );
00448 };
00449 
00450 // ############################################################################
00451 // Interface to level definition
00452 // ############################################################################
00453 
00457 class GRIB_LEVEL {
00458   public:
00460     GRIB_LEVEL( );
00461 
00464     void Decode(unsigned char *pds);
00465 
00467     int Encode( );
00468 
00470     t_enum_GRIB_LEVELS type;
00471 
00473     float lv1;
00475     float lv2;
00476 
00478     bool is_LevelPressure( );
00480     bool is_LevelHeight( );
00482     bool is_Surface( );
00484     bool is_MeanSeaLevel( );
00485 
00488     void set_pressure(float plev);
00489 
00492     void set_height(float hgt);
00493 
00496     void set_seadepth(float dpt);
00497 
00500     void set_isentropic(float temp);
00501 
00504     void set_sigma(float sigma);
00505 
00507     void set_surface( );
00508 
00513     void set(t_enum_GRIB_LEVELS type, float lev1, float lev2);
00514 
00516     friend std::ostream& operator<< ( std::ostream& os, GRIB_LEVEL &l );
00517 
00518   private:
00519     void set(t_enum_GRIB_LEVELS type);
00520     void set(t_enum_GRIB_LEVELS type, float lev);
00521     std::string leveldesc( );
00522 };
00523 
00524 // ############################################################################
00525 // Grid definitions
00526 // ############################################################################
00527 
00531 class GRIB_GRID_regular_latlon {
00532   public:
00540     void set(float lat1, float lon1,
00541              float lat2, float lon2,
00542              float dlon, float dlat);
00543 
00544     float lat1;  
00545     float lon1;  
00546     float lat2;  
00547     float lon2;  
00548     float dlat;  
00549     float dlon;  
00550 
00552     friend std::ostream& operator<< ( std::ostream& os,
00553                                       GRIB_GRID_regular_latlon &g );
00554 };
00555 
00559 class GRIB_GRID_gaussian_latlon {
00560   public:
00568     void set(float lat1, float lon1,
00569              float lat2, float lon2,
00570              float dlon, float N);
00571 
00572     float lat1;  
00573     float lon1;  
00574     float lat2;  
00575     float lon2;  
00576     float dlon;  
00577     float N;     
00578 
00580     friend std::ostream& operator<< ( std::ostream& os,
00581                                       GRIB_GRID_gaussian_latlon &g );
00582 };
00583 
00587 class GRIB_GRID_polar_stereographic {
00588   public:
00596     void set(float lat1, float lon1, float lov,
00597              float dx, float dy, bool pole);
00598 
00599     float lat1; 
00600     float lon1; 
00601     float lov;  
00602     float dx;   
00603     float dy;   
00604     bool pole;  
00605 
00607     friend std::ostream& operator<< ( std::ostream& os,
00608                                       GRIB_GRID_polar_stereographic &g );
00609 };
00610 
00614 class GRIB_GRID_lambert_conformal {
00615   public:
00628     void set(float lat1, float lon1, float lov,
00629              float latin1, float latin2,
00630              float latsp, float lonsp,
00631              float dx, float dy,
00632              bool pole, bool bipolar);
00633 
00634     float lat1;    
00635     float lon1;    
00636     float lov;     
00637     float latin1;  
00638     float latin2;  
00639     float latsp;   
00640     float lonsp;   
00641     float dx;      
00642     float dy;      
00643     bool pole;     
00644     bool bipolar;  
00645 
00647     friend std::ostream& operator<< ( std::ostream& os,
00648                                       GRIB_GRID_lambert_conformal &g );
00649 };
00650 
00654 class GRIB_GRID_mercator {
00655   public:
00664     void set(float lat1, float lon1,
00665              float lat2, float lon2,
00666              float dx, float dy, float latin);
00667 
00668     float lat1;   
00669     float lon1;   
00670     float lat2;   
00671     float lon2;   
00672     float dx;     
00673     float dy;     
00674     float latin;  
00675 
00677     friend std::ostream& operator<< ( std::ostream& os,
00678                                       GRIB_GRID_mercator &g );
00679 };
00680 
00684 class GRIB_GRID_spaceview {
00685   public:
00695     void set(float lap, float lop, float dx, float dy,
00696              float Xp, float Yp, float orient, float Nr);
00697 
00698     float lap;     
00699     float lop;     
00700     float dx;      
00701     float dy;      
00702     float Xp;      
00703     float Yp;      
00704     float orient;  
00705     float Nr;      
00706 
00708     friend std::ostream& operator<< ( std::ostream& os,
00709                                       GRIB_GRID_spaceview &g );
00710 };
00711 
00715 class GRIB_GRID_spherical_harmonic {
00716   public:
00723     void set(int J, int K, int M, int rt, int csm);
00724 
00726     enum GRIB_GRID_SPECTRAL_REPRESENTATION
00727     {
00728       SR_associated_legendre_polynomials_first_kind = 1,
00729       SR_spherical_harmonics_complex_packing        = 2
00730     } representation;
00731 
00733     enum GRIB_GRID_COEFFICIENT_STORAGE_METHOD
00734     {
00735       CSM_normal  = 1,
00736       CSM_complex = 2
00737     } storage_method;
00738 
00740     int J;
00742     int K;
00744     int M;
00745 
00747     friend std::ostream& operator<< ( std::ostream& os,
00748                                       GRIB_GRID_spherical_harmonic &g );
00749 };
00750 
00751 // ############################################################################
00752 // Interface to grid definitions
00753 // ############################################################################
00754 
00758 class GRIB_GRID {
00759   public:
00761     GRIB_GRID( );
00762 
00768     void Decode(unsigned char *pds, unsigned char *gds,
00769                 unsigned char *bms, unsigned char *bds);
00770 
00772     unsigned char *Encode( );
00773 
00777     void set_size(int nx, int ny);
00778 
00781     void set_number(int code);
00782 
00790     void set_regular_latlon(float lat1, float lon1,
00791                             float lat2, float lon2,
00792                             float dlat, float dlon);
00793 
00801     void set_gaussian_latlon(float lat1, float lon1,
00802                              float lat2, float lon2,
00803                              float dlon, float N);
00804 
00812     void set_polar_stereo(float lat1, float lon1, float lov,
00813                           float dx, float dy, bool pole);
00814 
00827     void set_lambert_conformal(float lat1, float lon1, float lov,
00828                                float latin1, float latin2,
00829                                float latsp, float lonsp,
00830                                float dx, float dy,
00831                                bool pole, bool bipolar);
00832 
00841     void set_mercator(float lat1, float lon1, float lat2, float lon2,
00842                       float dx, float dy, float latin);
00843 
00853     void set_spaceview(float lap, float lop, float dx, float dy,
00854                        float Xp, float Yp, float orient, float Nr);
00855 
00862     void set_spherical_harmonic(int J, int K, int M, int rt, int csm);
00863     
00865     void set_earth_spheroid( );
00866 
00868     void set_uv_grid( );
00869 
00871     void set_x_negative( );
00872 
00874     void set_y_negative( );
00875 
00877     void set_fortran_indexing( );
00878 
00880     union {
00881       GRIB_GRID_regular_latlon ll;
00882       GRIB_GRID_polar_stereographic ps;
00883       GRIB_GRID_lambert_conformal lc;
00884       GRIB_GRID_gaussian_latlon gl;
00885       GRIB_GRID_mercator mc;
00886       GRIB_GRID_spherical_harmonic sa;
00887       GRIB_GRID_spaceview sp;
00888     };
00889 
00891     t_enum_GRIB_GRIDS type;
00892 
00897     int grid_code;
00898 
00900     bool is_dirincgiven;
00901 
00903     bool is_earth_spheroid;
00904 
00906     bool is_uv_grid;
00907 
00909     bool is_x_negative;
00910 
00912     bool is_y_negative;
00913 
00915     bool is_fortran;
00916 
00918     friend std::ostream& operator<< ( std::ostream& os, GRIB_GRID &g );
00919 
00921     long nxny;
00923     int nx;
00925     int ny;
00926 
00928     unsigned char gds[44];
00929 };
00930 
00931 // ############################################################################
00932 // Interface to GRIB field
00933 // ############################################################################
00934 
00938 class GRIB_FIELD {
00939   public:
00941     GRIB_FIELD( );
00942 
00944     ~GRIB_FIELD( );
00945 
00951     void Decode(unsigned char *pds, unsigned char *bds,
00952                 unsigned char *bms, size_t nxny);
00953 
00959     void set_table(int center, int subcenter, int table, int process);
00960 
00967     void set_field(int varcode, float *values, size_t size,
00968                    float undef_high, float undef_low);
00969 
00972     void set_scale(int scale);
00973 
00975     int center;
00977     int subcenter;
00979     int table;
00981     int process;
00982 
00984     int varcode;
00985 
00987     size_t size;
00989     float *vals;
00990 
00992     std::string VarName( );
00994     std::string VarUnit( );
00996     std::string VarDescription( );
00997 
00999     float undef_high;
01001     float undef_low;
01002 
01004     std::string varname;
01006     std::string varunit;
01008     std::string vardesc;
01009 
01011     int numbits;
01013     float refvalue;
01015     int decimalscale;
01017     int binscale;
01018 };
01019 
01020 // ############################################################################
01021 // Interface to GRIB message
01022 // ############################################################################
01023 
01027 class GRIB_MESSAGE {
01028   public:
01030     GRIB_MESSAGE( );
01031 
01033     ~GRIB_MESSAGE( );
01034 
01038     int Decode(unsigned char *message, size_t reclen);
01039 
01041     void Encode( );
01042 
01045     void set_grid(GRIB_GRID &grid);
01046 
01049     void set_grid(int code);
01050 
01053     void set_time(GRIB_TIME &gtime);
01054 
01057     void set_level(GRIB_LEVEL &level);
01058 
01061     void set_field(GRIB_FIELD &field);
01062 
01064     size_t reclen;
01065 
01067     unsigned char *message;
01068 
01070     GRIB_GRID grid;
01072     GRIB_LEVEL level;
01074     GRIB_TIME gtime;
01076     GRIB_FIELD field;
01077 
01078   private:
01079     unsigned char *pds;
01080     unsigned char *gds;
01081     unsigned char *bms;
01082     unsigned char *bds;
01083 };
01084 
01085 // ############################################################################
01086 // Overall GRIB FILE interface
01087 // ############################################################################
01088 
01092 class GRIB_FILE {
01093   public:
01095     GRIB_FILE();
01096 
01098     ~GRIB_FILE();
01099 
01102     int OpenRead(char *fname);
01103 
01106     int OpenRead(std::string fname);
01107 
01110     int OpenWrite(char *fname);
01111 
01114     int OpenWrite(std::string fname);
01115 
01118     int Append(char *fname);
01119 
01122     int Append(std::string fname);
01123 
01126     int ReadMessage(GRIB_MESSAGE &message);
01127 
01130     int WriteMessage(GRIB_MESSAGE &message);
01131 
01133     int Close( );
01134 
01135   private:
01136     int fd;    // input stream pointer
01137     FILE *fp;  // output stream pointer
01138 
01139     size_t size;  // input total file size
01140     size_t pos;   // position in file size
01141     size_t limit; // last message start
01142 
01143     unsigned char *data; // actual input data
01144 };
01145 
01146 // ############################################################################

Generated on Fri Sep 10 09:52:07 2004 for GRIBLIB by doxygen1.2.18