33#define DEBUG_INFO false
34#define DEBUG_ERROR true
35#define grib_debug(format, ...) \
38 fprintf(stderr, format, __VA_ARGS__); \
39 fprintf(stderr, "\n"); \
42#define erreur(format, ...) \
45 fprintf(stderr, "Grib ERROR: "); \
46 fprintf(stderr, format, __VA_ARGS__); \
47 fprintf(stderr, "\n"); \
51#define zuint unsigned int
52#define zuchar unsigned char
54#define GRIB_NOTDEF -999999999
60#define GRB_GEOPOT_HGT 7
65#define GRB_DEWPOINT 17
67#define GRB_WIND_DIR 31
68#define GRB_WIND_SPEED 32
73#define GRB_CUR_SPEED 48
77#define GRB_HUMID_SPEC 51
78#define GRB_HUMID_REL 52
79#define GRB_PRECIP_RATE 59
80#define GRB_PRECIP_TOT 61
81#define GRB_SNOW_DEPTH 66
82#define GRB_CLOUD_TOT 71
85#define GRB_COMP_REFL 212
101#define GRB_FRZRAIN_CATEG 141
102#define GRB_SNOW_CATEG 143
107#define GRB_WIND_GUST 180
108#define GRB_WIND_GUST_VX 181
109#define GRB_WIND_GUST_VY 182
114#define GRB_WIND_XY2D 250
115#define GRB_DIFF_TEMPDEW 251
121#define LV_ISOTHERM0 4
122#define LV_ISOBARIC 100
124#define LV_ABOV_MSL 103
125#define LV_ABOV_GND 105
127#define LV_ATMOS_ENT 10
128#define LV_ATMOS_ALL 200
130enum DataCenterModel {
147 static zuint makeCode(zuchar dataType, zuchar levelType, zuint levelValue) {
148 return ((levelValue & 0xFFFF) << 16) + ((levelType & 0xFF) << 8) + dataType;
150 static zuchar getDataType(zuint code) {
return code & 0xFF; }
151 static zuchar getLevelType(zuint code) {
return (code >> 8) & 0xFF; }
152 static zuint getLevelValue(zuint code) {
return (code >> 16) & 0xFFFF; }
273 void multiplyAllData(
double k);
274 void Substract(
const GribRecord &rec,
bool positive =
true);
277 bool isOk()
const {
return ok; };
278 bool isDataKnown()
const {
return knownData; };
279 bool isEof()
const {
return eof; };
299 void setDataType(
const zuchar t);
390 std::string getKey()
const {
return dataKey; }
480 double getValue(
int i,
int j)
const {
return data[j * Ni + i]; }
482 void setValue(zuint i, zuint j,
double v) {
483 if (i < Ni && j < Nj) data[j * Ni + i] = v;
500 bool numericalInterpolation =
true,
501 bool dir =
false)
const;
529 bool numericalInterpolation =
true);
540 inline double getX(
int i)
const {
return Lo1 + i * Di; }
551 inline double getY(
int j)
const {
return La1 + j * Dj; }
562 void getXY(
int i,
int j,
double *x,
double *y)
const {
567 double getLatMin()
const {
return latMin; }
568 double getLonMin()
const {
return lonMin; }
569 double getLatMax()
const {
return latMax; }
570 double getLonMax()
const {
return lonMax; }
573 inline bool hasValue(
int i,
int j)
const;
575 inline bool isDefined(
int i,
int j)
const {
576 return hasValue(i, j) &&
getValue(i, j) != GRIB_NOTDEF;
580 time_t getRecordRefDate()
const {
return refDate; }
581 const char *getStrRecordRefDate()
const {
return strRefDate; }
584 time_t getRecordCurrentDate()
const {
return curDate; }
585 const char *getStrRecordCurDate()
const {
return strCurDate; }
586 void setRecordCurrentDate(time_t t);
589 void setFilled(
bool val =
true) {
m_bfilled = val; }
593 inline bool isPointInMap(
double x,
double y)
const;
594 inline bool isXInMap(
double x)
const;
595 inline bool isYInMap(
double y)
const;
599 static bool GetInterpolatedParameters(
const GribRecord &rec1,
601 double &
Lo1,
double &La2,
double &
Lo2,
602 double &Di,
double &Dj,
int &im1,
603 int &jm1,
int &im2,
int &jm2,
int &Ni,
604 int &Nj,
int &rec1offi,
int &rec1offj,
605 int &rec2offi,
int &rec2offj);
721 zuint
refyear, refmonth, refday, refhour, refminute;
753 double latMin, lonMin, latMax, lonMax;
755 zuchar resolFlags, scanFlags;
759 bool isScanIpositive;
760 bool isScanJpositive;
769 time_t makeDate(zuint year, zuint month, zuint day, zuint hour, zuint min,
776inline bool GribRecord::hasValue(
int i,
int j)
const {
787 zuchar c = BMSbits[bit / 8];
788 zuchar m = (zuchar)128 >> (bit % 8);
793inline bool GribRecord::isPointInMap(
double x,
double y)
const {
794 return isXInMap(x) && isYInMap(y);
801inline bool GribRecord::isXInMap(
double x)
const {
808 return x >=
Lo1 && x <= maxLo;
813 return x >=
Lo2 && x <= maxLo;
817inline bool GribRecord::isYInMap(
double y)
const {
819 return y <= La1 && y >= La2;
821 return y >= La1 && y <= La2;
Represents a meteorological data grid from a GRIB (Gridded Binary) file.
zuchar getTimeRange() const
Returns the time range indicator that defines how P1 and P2 should be interpreted.
bool eof
Signals when the end of the GRIB file has been reached during parsing.
zuint periodsec
Forecast period in seconds.
static void Polar2UV(GribRecord *pDIR, GribRecord *pSPEED)
Converts wind or current values from polar (direction/speed) to cartesian (U/V) components.
int getPeriodP1() const
Returns the start of the period (P1) used for this record.
zuchar dataType
Parameter identifier as defined by GRIB tables.
double getDi() const
Returns the grid spacing in longitude (i) direction in degrees.
zuchar editionNumber
GRIB edition number, indicating the version of the GRIB specification used.
bool knownData
Indicates whether the data type in this record is recognized by the parser.
zuchar levelType
Vertical level type indicator.
void getXY(int i, int j, double *x, double *y) const
Converts grid indices to longitude/latitude coordinates.
double Lo2
Grid end coordinates.
double getDj() const
Returns the grid spacing in latitude (j) direction in degrees.
zuchar getIdModel() const
Returns the model/process ID within the originating center.
double Lo1
Grid origin coordinates.
zuint getPeriodSec() const
Returns the forecast period in seconds from reference time.
time_t curDate
Unix timestamp of when this forecast is valid.
int getPeriodP2() const
Returns the end of the period (P2) used for this record.
static GribRecord * Interpolated2DRecord(GribRecord *&rety, const GribRecord &rec1x, const GribRecord &rec1y, const GribRecord &rec2x, const GribRecord &rec2y, double d)
Creates temporally interpolated records for vector fields (wind, currents).
bool waveData
Differentiates wave-related parameters (height, direction, period) from other meteorological data for...
zuchar timeRange
Statistical processing indicator.
zuint getDataCenterModel() const
Returns the numerical weather prediction model/center that produced this data.
double getInterpolatedValue(double px, double py, bool numericalInterpolation=true, bool dir=false) const
Get spatially interpolated value at exact lat/lon position.
bool IsDuplicated
Indicates if this record was created through copying rather than direct reading.
zuchar idCenter
Originating center ID as defined by WMO common table C-1.
static GribRecord * InterpolatedRecord(const GribRecord &rec1, const GribRecord &rec2, double d, bool dir=false)
Creates a new GribRecord by temporally interpolating between two time points.
bool ok
Indicates record validity.
int getNi() const
Returns the number of points in the longitude (i) direction of the grid.
zuchar idGrid
Grid identifier used by the originating center.
zuint periodP1
Time range indicators for this forecast step.
double getX(int i) const
Converts grid index i to longitude in degrees.
int getNj() const
Returns the number of points in the latitude (j) direction of the grid.
time_t refDate
Unix timestamp of model initialization time.
int id
Unique identifier for this record.
bool hasBMS
Indicates presence of a bitmap section.
static bool getInterpolatedValues(double &M, double &A, const GribRecord *GRX, const GribRecord *GRY, double px, double py, bool numericalInterpolation=true)
Gets spatially interpolated wind or current vector values at a specific latitude/longitude point.
int dataCenterModel
Identifies the numerical weather model that produced this data.
double getY(int j) const
Converts grid index j to latitude in degrees.
zuchar getIdGrid() const
Returns the grid definition template number.
double getValue(int i, int j) const
Returns the data value at a specific grid point.
bool m_bfilled
Indicates whether the data array has been populated.
zuint refyear
Components of the reference time for this forecast.
zuint levelValue
Numeric value associated with levelType.
zuint getLevelValue() const
Returns the numeric value associated with the level type.
zuchar getLevelType() const
Returns the type of vertical level for this grid's data.
zuchar idModel
Model identifier within the originating center.
zuchar getDataType() const
Returns the type of meteorological parameter stored in this grid.
zuchar getIdCenter() const
Returns the originating center ID as defined by WMO (World Meteorological Organization).
std::string dataKey
Unique string identifier constructed from data type, level type, and level value.