Skip to content

Commit

Permalink
GRIB: add support for template 4.48 Optical Properties of Aerosol
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Nov 20, 2019
1 parent 279f488 commit 3ef6b1c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 7 deletions.
Binary file added autotest/gdrivers/data/grib/template_4_48.grb2
Binary file not shown.
16 changes: 16 additions & 0 deletions autotest/gdrivers/grib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1264,3 +1264,19 @@ def test_grib_grib2_derived_forecast_spread():
out_ds = None

gdal.Unlink('/vsimem/out.grb2')



###############################################################################
# Template 4.48 with Optical Properties of Aerosol

def test_grib_grib2_template_4_48():

if gdaltest.grib_drv is None:
pytest.skip()

ds = gdal.Open('data/grib/template_4_48.grb2')
band = ds.GetRasterBand(1)
assert band.GetMetadataItem('GRIB_UNIT') == '[1/kg]'
assert band.GetMetadataItem('GRIB_ELEMENT') == 'ASNCON'
assert band.GetMetadataItem('GRIB_SHORT_NAME') == '0-EATM'
23 changes: 19 additions & 4 deletions gdal/frmts/grib/degrib/degrib/inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,10 @@ enum { GS4_ANALYSIS, GS4_ENSEMBLE, GS4_DERIVED, GS4_PROBABIL_PNT = 5,
&& (templat != GS4_RADAR) && (templat != GS4_SATELLITE)
&& (templat != GS4_SATELLITE_SYNTHETIC)
&& (templat != GS4_DERIVED_INTERVAL)
&& (templat != GS4_ANALYSIS_CHEMICAL) ) {
&& (templat != GS4_ANALYSIS_CHEMICAL)
&& (templat != GS4_OPTICAL_PROPERTIES_AEROSOL) ) {
errSprintf ("This was only designed for templates 0, 1, 2, 5, 6, 7, 8, 9, "
"10, 11, 12, 15, 20, 30, 32, 40. Template found = %d\n", templat);
"10, 11, 12, 15, 20, 30, 32, 40, 48. Template found = %d\n", templat);

inv->validTime = 0;
inv->foreSec = 0;
Expand Down Expand Up @@ -568,6 +569,12 @@ enum { GS4_ANALYSIS, GS4_ENSEMBLE, GS4_DERIVED, GS4_PROBABIL_PNT = 5,
return -8;
genProcess = (*buffer)[14 - 5];
}
else if( templat == GS4_OPTICAL_PROPERTIES_AEROSOL )
{
if( secLen < 36 - 5 + 1 )
return -8;
genProcess = (*buffer)[36 - 5];
}
else
genProcess = (*buffer)[12 - 5];
genID = 0;
Expand All @@ -584,7 +591,11 @@ enum { GS4_ANALYSIS, GS4_ENSEMBLE, GS4_DERIVED, GS4_PROBABIL_PNT = 5,
} else {
int nOffset = 0;
if( templat == GS4_ANALYSIS_CHEMICAL ) {
nOffset = 2;
nOffset = 16 - 14;
}
else if( templat == GS4_OPTICAL_PROPERTIES_AEROSOL )
{
nOffset = 38 - 14;
}
genID = (*buffer)[nOffset + 14 - 5];
/* Compute forecast time. */
Expand Down Expand Up @@ -839,7 +850,11 @@ enum { GS4_ANALYSIS, GS4_ENSEMBLE, GS4_DERIVED, GS4_PROBABIL_PNT = 5,
} else {
unsigned int nOffset = 0;
if( templat == GS4_ANALYSIS_CHEMICAL ) {
nOffset = 2;
nOffset = 16 - 14;
}
else if( templat == GS4_OPTICAL_PROPERTIES_AEROSOL )
{
nOffset = 38 - 14;
}

if( secLen < nOffset + 31 - 5 + 4)
Expand Down
3 changes: 2 additions & 1 deletion gdal/frmts/grib/degrib/degrib/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ enum { GS4_ANALYSIS = 0,
GS4_RADAR = 20,
GS4_SATELLITE = 30,
GS4_SATELLITE_SYNTHETIC = 32,
GS4_ANALYSIS_CHEMICAL = 40
GS4_ANALYSIS_CHEMICAL = 40,
GS4_OPTICAL_PROPERTIES_AEROSOL = 48
};

typedef struct {
Expand Down
16 changes: 14 additions & 2 deletions gdal/frmts/grib/degrib/degrib/metaparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,7 @@ static int ParseSect4 (sInt4 *is4, sInt4 ns4, grib_MetaData *meta)
(is4[7] != GS4_PERCENT_TIME) && (is4[7] != GS4_ENSEMBLE_STAT) &&
(is4[7] != GS4_SATELLITE) && (is4[7] != GS4_SATELLITE_SYNTHETIC) &&
(is4[7] != GS4_DERIVED_INTERVAL) && (is4[7] != GS4_STATISTIC_SPATIAL_AREA) &&
(is4[7] != GS4_ANALYSIS_CHEMICAL)) {
(is4[7] != GS4_ANALYSIS_CHEMICAL) && (is4[7] != GS4_OPTICAL_PROPERTIES_AEROSOL)) {
#ifdef DEBUG
//printf ("Un-supported Template. %d\n", is4[7]);
#endif
Expand All @@ -1595,7 +1595,16 @@ static int ParseSect4 (sInt4 *is4, sInt4 ns4, grib_MetaData *meta)
}
meta->pds2.sect4.cat = (uChar) is4[9];
meta->pds2.sect4.subcat = (uChar) is4[10];
int nOffset = (is4[7] != GS4_ANALYSIS_CHEMICAL) ? 0 : 2;
int nOffset = 0;
if( is4[7] == GS4_ANALYSIS_CHEMICAL ) {
nOffset = 16 - 14;
}
else if( is4[7] == GS4_OPTICAL_PROPERTIES_AEROSOL ) {
nOffset = 38 - 14;
}
if (ns4 < 34 + nOffset) {
return -1;
}
meta->pds2.sect4.genProcess = (uChar) is4[11 + nOffset];

/* Initialize variables prior to parsing the specific templates. */
Expand Down Expand Up @@ -2093,6 +2102,9 @@ static int ParseSect4 (sInt4 *is4, sInt4 ns4, grib_MetaData *meta)
case GS4_ANALYSIS_CHEMICAL: /* 4.40 */
// TODO
break;
case GS4_OPTICAL_PROPERTIES_AEROSOL: /* 4.48 */
// TODO
break;
default:
errSprintf ("Un-supported Template. %ld\n", is4[7]);
return -4;
Expand Down

0 comments on commit 3ef6b1c

Please sign in to comment.