From 7eb6c3439b338d55abea2e5d65f2f5558dfc7673 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 21 Nov 2019 14:51:37 +0000 Subject: [PATCH 01/17] ECC-1028: Segmentation fault: bufr_dump -d on message with incorrect replication --- src/grib_accessor_class_expanded_descriptors.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/grib_accessor_class_expanded_descriptors.c b/src/grib_accessor_class_expanded_descriptors.c index e0cf65c22..f0236e0ae 100644 --- a/src/grib_accessor_class_expanded_descriptors.c +++ b/src/grib_accessor_class_expanded_descriptors.c @@ -739,18 +739,16 @@ static int pack_long(grib_accessor* a, const long* val, size_t *len) static int value_count(grib_accessor* a,long* rlen) { grib_accessor_expanded_descriptors* self = (grib_accessor_expanded_descriptors*)a; - int ret=0; - grib_context* c=a->context; + int err=0; *rlen=0; - ret=expand(a); - *rlen=BUFR_DESCRIPTORS_ARRAY_USED_SIZE(self->expanded); - if (ret) { - grib_context_log(c,GRIB_LOG_ERROR,"%s unable to compute size",a->name); - return ret; + err=expand(a); + if (err) { + grib_context_log(a->context,GRIB_LOG_ERROR,"%s unable to compute size",a->name); + return err; } - - return ret; + *rlen=BUFR_DESCRIPTORS_ARRAY_USED_SIZE(self->expanded); + return err; } static void destroy(grib_context* c,grib_accessor* a) From b9543befce03110b08639bf7266ad7ef8584a3fc Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 21 Nov 2019 15:36:35 +0000 Subject: [PATCH 02/17] Update from tigge_check: pl levels update for CERRA --- tigge/tigge_check.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/tigge/tigge_check.c b/tigge/tigge_check.c index 615782211..235b42e2f 100755 --- a/tigge/tigge_check.c +++ b/tigge/tigge_check.c @@ -554,7 +554,7 @@ static void pressure_level(grib_handle* h,const parameter* p,double min,double m { long level = get(h,"level"); - if (is_uerra){ + if (is_uerra && !is_crra){ switch(level) { case 1000: @@ -577,7 +577,7 @@ static void pressure_level(grib_handle* h,const parameter* p,double min,double m case 150: case 100: case 70: - case 50: + case 50: case 30: case 20: case 10: @@ -588,6 +588,45 @@ static void pressure_level(grib_handle* h,const parameter* p,double min,double m break; } } + else if (is_uerra && is_crra){ + switch(level) + { + case 1000: + case 975: + case 950: + case 925: + case 900: + case 875: + case 850: + case 825: + case 800: + case 750: + case 700: + case 600: + case 500: + case 400: + case 300: + case 250: + case 200: + case 150: + case 100: + case 70: + case 50: + case 30: + case 20: + case 10: + case 7: + case 5: + case 3: + case 2: + case 1: + break; + default: + printf("%s, field %d [%s]: invalid pressure level %ld\n",file,field,param,level); + error++; + break; + } + } else if (is_s2s){ switch(level) { From 3ae397bc8197709a66076e49d6a05aa0585325ad Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Fri, 22 Nov 2019 10:49:12 +0000 Subject: [PATCH 03/17] Definitions: Add missing tables --- definitions/grib2/tables/22/1.4.table | 13 +++++ definitions/grib2/tables/22/3.15.table | 23 ++++++++ definitions/grib2/tables/22/4.10.table | 16 ++++++ definitions/grib2/tables/22/4.4.table | 17 ++++++ definitions/grib2/tables/22/4.5.table | 72 ++++++++++++++++++++++++++ definitions/grib2/tables/22/4.91.table | 16 ++++++ 6 files changed, 157 insertions(+) create mode 100644 definitions/grib2/tables/22/1.4.table create mode 100644 definitions/grib2/tables/22/3.15.table create mode 100644 definitions/grib2/tables/22/4.10.table create mode 100644 definitions/grib2/tables/22/4.4.table create mode 100644 definitions/grib2/tables/22/4.5.table create mode 100644 definitions/grib2/tables/22/4.91.table diff --git a/definitions/grib2/tables/22/1.4.table b/definitions/grib2/tables/22/1.4.table new file mode 100644 index 000000000..03203d874 --- /dev/null +++ b/definitions/grib2/tables/22/1.4.table @@ -0,0 +1,13 @@ +# Code table 1.4 - Type of data +0 an Analysis products +1 fc Forecast products +2 af Analysis and forecast products +3 cf Control forecast products +4 pf Perturbed forecast products +5 cp Control and perturbed forecast products +6 sa Processed satellite observations +7 ra Processed radar observations +8 ep Event probability +# 9-191 Reserved +# 192-254 Reserved for local use +255 missing Missing diff --git a/definitions/grib2/tables/22/3.15.table b/definitions/grib2/tables/22/3.15.table new file mode 100644 index 000000000..331217ebe --- /dev/null +++ b/definitions/grib2/tables/22/3.15.table @@ -0,0 +1,23 @@ +# Code table 3.15 - Physical meaning of vertical coordinate +# 0-19 Reserved +20 20 Temperature (K) +# 21-99 Reserved +100 100 Pressure (Pa) +101 101 Pressure deviation from mean sea level (Pa) +102 102 Altitude above mean sea level (m) +103 103 Height above ground (m) +104 104 Sigma coordinate +105 105 Hybrid coordinate +106 106 Depth below land surface (m) +107 pt Potential temperature (theta) (K) +108 108 Pressure deviation from ground to level (Pa) +109 pv Potential vorticity (K m-2 kg-1 s-1) +110 110 Geometrical height (m) +111 111 Eta coordinate +112 112 Geopotential height (gpm) +113 113 Logarithmic hybrid coordinate +# 114-159 Reserved +160 160 Depth below sea level (m) +# 161-191 Reserved +# 192-254 Reserved for local use +255 255 Missing diff --git a/definitions/grib2/tables/22/4.10.table b/definitions/grib2/tables/22/4.10.table new file mode 100644 index 000000000..1a92baaf6 --- /dev/null +++ b/definitions/grib2/tables/22/4.10.table @@ -0,0 +1,16 @@ +# Code table 4.10 - Type of statistical processing +0 avg Average +1 accum Accumulation +2 max Maximum +3 min Minimum +4 diff Difference (value at the end of time range minus value at the beginning) +5 rms Root mean square +6 sd Standard deviation +7 cov Covariance (temporal variance) +8 8 Difference (value at the start of time range minus value at the end) +9 ratio Ratio +10 10 Standardized anomaly +11 11 Summation +# 12-191 Reserved +# 192-254 Reserved for local use +255 missing Missing diff --git a/definitions/grib2/tables/22/4.4.table b/definitions/grib2/tables/22/4.4.table new file mode 100644 index 000000000..7087ebddb --- /dev/null +++ b/definitions/grib2/tables/22/4.4.table @@ -0,0 +1,17 @@ +# Code table 4.4 - Indicator of unit of time range +0 m Minute +1 h Hour +2 D Day +3 M Month +4 Y Year +5 10Y Decade (10 years) +6 30Y Normal (30 years) +7 C Century (100 years) +# 8-9 Reserved +10 3h 3 hours +11 6h 6 hours +12 12h 12 hours +13 s Second +# 14-191 Reserved +# 192-254 Reserved for local use +255 255 Missing diff --git a/definitions/grib2/tables/22/4.5.table b/definitions/grib2/tables/22/4.5.table new file mode 100644 index 000000000..35df9e2aa --- /dev/null +++ b/definitions/grib2/tables/22/4.5.table @@ -0,0 +1,72 @@ +# Code table 4.5 - Fixed surface types and units +0 0 Reserved +1 sfc Ground or water surface (-) +2 2 Cloud base level (-) +3 3 Level of cloud tops (-) +4 4 Level of 0 degree C isotherm (-) +5 5 Level of adiabatic condensation lifted from the surface (-) +6 6 Maximum wind level (-) +7 7 Tropopause (-) +8 sfc Nominal top of the atmosphere (-) +9 9 Sea bottom (-) +10 10 Entire atmosphere (-) +11 11 Cumulonimbus [CB] base (m) +12 12 Cumulonimbus [CB] top (m) +13 13 Lowest level where vertically integrated cloud cover exceeds the specified percentage [cloud base for a given percentage cloud cover] (%) +14 14 Level of free convection (LFC) +15 15 Convective condensation level (CCL) +16 16 Level of neutral buoyancy or equilibrium level (LNB) +# 17-19 Reserved +20 20 Isothermal level (K) +21 21 Lowest level where mass density exceeds the specified value [base for a given threshold of mass density] (kg m-3) +22 22 Highest level where mass density exceeds the specified value [top for a given threshold of mass density] (kg m-3) +23 23 Lowest level where air concentration exceeds the specified value [base for a given threshold of air concentration] (Bq m-3) +24 24 Highest level where air concentration exceeds the specified value [top for a given threshold of air concentration] (Bq m-3) +# 25-99 Reserved +100 pl Isobaric surface (Pa) +101 sfc Mean sea level +102 102 Specific altitude above mean sea level (m) +103 sfc Specified height level above ground (m) +104 104 Sigma level (sigma value) +105 ml Hybrid level (-) +106 sfc Depth below land surface (m) +107 pt Isentropic [theta] level (K) +108 108 Level at specified pressure difference from ground to level (Pa) +109 pv Potential vorticity surface (K m2 kg-1 s-1) +110 110 Reserved +111 111 Eta level (-) +112 112 Reserved +113 113 Logarithmic hybrid level +114 114 Snow level (Numeric) +115 115 Sigma height level +# 116 Reserved +117 117 Mixed layer depth (m) +118 hhl Hybrid height level (-) +119 hpl Hybrid pressure level (-) +# 120-149 Reserved +150 150 Generalized vertical height coordinate +151 sol Soil level (Numeric) +# 152-159 Reserved +160 160 Depth below sea level (m) +161 161 Depth below water surface (m) +162 162 Lake or river bottom (-) +163 163 Bottom of sediment layer (-) +164 164 Bottom of thermally active sediment layer (-) +165 165 Bottom of sediment layer penetrated by thermal wave (-) +166 166 Mixing layer (-) +167 167 Bottom of root zone (-) +# 168-173 Reserved +174 174 Top surface of ice on sea, lake or river +175 175 Top surface of ice, under snow cover, on sea, lake or river +176 176 Bottom surface (underside) ice on sea, lake or river +177 sfc Deep soil (of indefinite depth) +# 178 Reserved +179 179 Top surface of glacier ice and inland ice +180 180 Deep inland or glacier ice (of indefinite depth) +181 181 Grid tile land fraction as a model surface +182 182 Grid tile water fraction as a model surface +183 183 Grid tile ice fraction on sea, lake or river as a model surface +184 184 Grid tile glacier ice and inland ice fraction as a model surface +# 185-191 Reserved +# 192-254 Reserved for local use +255 255 Missing diff --git a/definitions/grib2/tables/22/4.91.table b/definitions/grib2/tables/22/4.91.table new file mode 100644 index 000000000..44cf25f44 --- /dev/null +++ b/definitions/grib2/tables/22/4.91.table @@ -0,0 +1,16 @@ +# Code table 4.91 - Type of Interval +0 0 Smaller than first limit +1 1 Greater than second limit +2 2 Between first and second limit. The range includes the first limit but not the second limit +3 3 Greater than first limit +4 4 Smaller than second limit +5 5 Smaller or equal first limit +6 6 Greater or equal second limit +7 7 Between first and second. The range includes the first limit and the second limit +8 8 Greater or equal first limit +9 9 Smaller or equal second limit +10 10 Between first and second limit. The range includes the second limit but not the first limit +11 11 Equal to first limit +# 12-191 Reserved +# 192-254 Reserved for local use +255 missing Missing From e1b99a7f3974ae770d23916650ba12d4e9061981 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 25 Nov 2019 14:18:17 +0000 Subject: [PATCH 04/17] Definitions: remove unnecessary notes from code tables --- definitions/grib2/tables/0/3.15.table | 8 -------- definitions/grib2/tables/0/4.2.1.0.table | 7 ------- definitions/grib2/tables/1/3.15.table | 8 -------- definitions/grib2/tables/1/4.2.1.0.table | 7 ------- definitions/grib2/tables/2/3.15.table | 8 -------- definitions/grib2/tables/2/4.2.1.0.table | 7 ------- definitions/grib2/tables/3/3.15.table | 8 -------- definitions/grib2/tables/3/4.2.1.0.table | 7 ------- definitions/grib2/tables/4/3.15.table | 3 --- definitions/grib2/tables/4/4.2.1.0.table | 5 ----- definitions/grib2/tables/5/3.15.table | 3 --- definitions/grib2/tables/6/3.15.table | 4 ---- definitions/grib2/tables/7/3.15.table | 8 -------- 13 files changed, 83 deletions(-) diff --git a/definitions/grib2/tables/0/3.15.table b/definitions/grib2/tables/0/3.15.table index bb431e14f..d4f7e0ed2 100644 --- a/definitions/grib2/tables/0/3.15.table +++ b/definitions/grib2/tables/0/3.15.table @@ -1,7 +1,5 @@ # CODE TABLE 3.15, Physical meaning of vertical coordinate -# 0-19 Reserved 20 20 Temperature K -# 21-99 Reserved 100 100 Pressure Pa 101 101 Pressure deviation from mean sea level Pa 102 102 Altitude above mean sea level m @@ -15,11 +13,5 @@ 110 110 Geometrical height m 111 111 Eta coordinate (see Note 2) 112 112 Geopotential height gpm -# 113-159 Reserved 160 160 Depth below sea level m -# 161-191 Reserved -# 192-254 Reserved for local use 255 255 Missing -# Notes: -# (1) Negative values associated to this coordinate will indicate depth below ground surface. If values are all below surface, use of entry 106 is recommended, with positive coordinate values instead. -# (2) The Eta vertical coordinate system involves normalizing the pressure at some point on a specific level by the mean sea level pressure at that point. diff --git a/definitions/grib2/tables/0/4.2.1.0.table b/definitions/grib2/tables/0/4.2.1.0.table index 97efaa8cc..828c869de 100644 --- a/definitions/grib2/tables/0/4.2.1.0.table +++ b/definitions/grib2/tables/0/4.2.1.0.table @@ -6,11 +6,4 @@ 4 4 Snow water equivalent percent of normal (%) 5 5 Baseflow-groundwater runoff (kg m-2) 6 6 Storm surface runoff (kg m-2) -# 7-191 Reserved -# 192-254 Reserved for local use 255 255 Missing -# Notes: -# (1) Remotely sensed snow cover is expressed as a field of dimensionless, thematic values. The currently accepted values are for no-snow/no-cloud, 50, for clouds, 100, and for snow, 250. See code table 4.215. -# (2) A data field representing snow coverage by elevation portrays at which elevations there is a snow pack. The elevation values typically range from 0 to 90 in 100 m increments. A value of 253 is used to represent a no-snow/no-cloud data point. A value of 254 is used to represent a data point at which snow elevation could not be estimated because of clouds obscuring the remote sensor (when using aircraft or satellite measurements). -# (3) Snow water equivalent percent of normal is stored in percent of normal units. For example, a value of 110 indicates 110 percent of the normal snow water equivalent for a given depth of snow. - diff --git a/definitions/grib2/tables/1/3.15.table b/definitions/grib2/tables/1/3.15.table index bb431e14f..d4f7e0ed2 100644 --- a/definitions/grib2/tables/1/3.15.table +++ b/definitions/grib2/tables/1/3.15.table @@ -1,7 +1,5 @@ # CODE TABLE 3.15, Physical meaning of vertical coordinate -# 0-19 Reserved 20 20 Temperature K -# 21-99 Reserved 100 100 Pressure Pa 101 101 Pressure deviation from mean sea level Pa 102 102 Altitude above mean sea level m @@ -15,11 +13,5 @@ 110 110 Geometrical height m 111 111 Eta coordinate (see Note 2) 112 112 Geopotential height gpm -# 113-159 Reserved 160 160 Depth below sea level m -# 161-191 Reserved -# 192-254 Reserved for local use 255 255 Missing -# Notes: -# (1) Negative values associated to this coordinate will indicate depth below ground surface. If values are all below surface, use of entry 106 is recommended, with positive coordinate values instead. -# (2) The Eta vertical coordinate system involves normalizing the pressure at some point on a specific level by the mean sea level pressure at that point. diff --git a/definitions/grib2/tables/1/4.2.1.0.table b/definitions/grib2/tables/1/4.2.1.0.table index 97efaa8cc..828c869de 100644 --- a/definitions/grib2/tables/1/4.2.1.0.table +++ b/definitions/grib2/tables/1/4.2.1.0.table @@ -6,11 +6,4 @@ 4 4 Snow water equivalent percent of normal (%) 5 5 Baseflow-groundwater runoff (kg m-2) 6 6 Storm surface runoff (kg m-2) -# 7-191 Reserved -# 192-254 Reserved for local use 255 255 Missing -# Notes: -# (1) Remotely sensed snow cover is expressed as a field of dimensionless, thematic values. The currently accepted values are for no-snow/no-cloud, 50, for clouds, 100, and for snow, 250. See code table 4.215. -# (2) A data field representing snow coverage by elevation portrays at which elevations there is a snow pack. The elevation values typically range from 0 to 90 in 100 m increments. A value of 253 is used to represent a no-snow/no-cloud data point. A value of 254 is used to represent a data point at which snow elevation could not be estimated because of clouds obscuring the remote sensor (when using aircraft or satellite measurements). -# (3) Snow water equivalent percent of normal is stored in percent of normal units. For example, a value of 110 indicates 110 percent of the normal snow water equivalent for a given depth of snow. - diff --git a/definitions/grib2/tables/2/3.15.table b/definitions/grib2/tables/2/3.15.table index bb431e14f..d4f7e0ed2 100644 --- a/definitions/grib2/tables/2/3.15.table +++ b/definitions/grib2/tables/2/3.15.table @@ -1,7 +1,5 @@ # CODE TABLE 3.15, Physical meaning of vertical coordinate -# 0-19 Reserved 20 20 Temperature K -# 21-99 Reserved 100 100 Pressure Pa 101 101 Pressure deviation from mean sea level Pa 102 102 Altitude above mean sea level m @@ -15,11 +13,5 @@ 110 110 Geometrical height m 111 111 Eta coordinate (see Note 2) 112 112 Geopotential height gpm -# 113-159 Reserved 160 160 Depth below sea level m -# 161-191 Reserved -# 192-254 Reserved for local use 255 255 Missing -# Notes: -# (1) Negative values associated to this coordinate will indicate depth below ground surface. If values are all below surface, use of entry 106 is recommended, with positive coordinate values instead. -# (2) The Eta vertical coordinate system involves normalizing the pressure at some point on a specific level by the mean sea level pressure at that point. diff --git a/definitions/grib2/tables/2/4.2.1.0.table b/definitions/grib2/tables/2/4.2.1.0.table index 97efaa8cc..828c869de 100644 --- a/definitions/grib2/tables/2/4.2.1.0.table +++ b/definitions/grib2/tables/2/4.2.1.0.table @@ -6,11 +6,4 @@ 4 4 Snow water equivalent percent of normal (%) 5 5 Baseflow-groundwater runoff (kg m-2) 6 6 Storm surface runoff (kg m-2) -# 7-191 Reserved -# 192-254 Reserved for local use 255 255 Missing -# Notes: -# (1) Remotely sensed snow cover is expressed as a field of dimensionless, thematic values. The currently accepted values are for no-snow/no-cloud, 50, for clouds, 100, and for snow, 250. See code table 4.215. -# (2) A data field representing snow coverage by elevation portrays at which elevations there is a snow pack. The elevation values typically range from 0 to 90 in 100 m increments. A value of 253 is used to represent a no-snow/no-cloud data point. A value of 254 is used to represent a data point at which snow elevation could not be estimated because of clouds obscuring the remote sensor (when using aircraft or satellite measurements). -# (3) Snow water equivalent percent of normal is stored in percent of normal units. For example, a value of 110 indicates 110 percent of the normal snow water equivalent for a given depth of snow. - diff --git a/definitions/grib2/tables/3/3.15.table b/definitions/grib2/tables/3/3.15.table index bb431e14f..d4f7e0ed2 100644 --- a/definitions/grib2/tables/3/3.15.table +++ b/definitions/grib2/tables/3/3.15.table @@ -1,7 +1,5 @@ # CODE TABLE 3.15, Physical meaning of vertical coordinate -# 0-19 Reserved 20 20 Temperature K -# 21-99 Reserved 100 100 Pressure Pa 101 101 Pressure deviation from mean sea level Pa 102 102 Altitude above mean sea level m @@ -15,11 +13,5 @@ 110 110 Geometrical height m 111 111 Eta coordinate (see Note 2) 112 112 Geopotential height gpm -# 113-159 Reserved 160 160 Depth below sea level m -# 161-191 Reserved -# 192-254 Reserved for local use 255 255 Missing -# Notes: -# (1) Negative values associated to this coordinate will indicate depth below ground surface. If values are all below surface, use of entry 106 is recommended, with positive coordinate values instead. -# (2) The Eta vertical coordinate system involves normalizing the pressure at some point on a specific level by the mean sea level pressure at that point. diff --git a/definitions/grib2/tables/3/4.2.1.0.table b/definitions/grib2/tables/3/4.2.1.0.table index 97efaa8cc..828c869de 100644 --- a/definitions/grib2/tables/3/4.2.1.0.table +++ b/definitions/grib2/tables/3/4.2.1.0.table @@ -6,11 +6,4 @@ 4 4 Snow water equivalent percent of normal (%) 5 5 Baseflow-groundwater runoff (kg m-2) 6 6 Storm surface runoff (kg m-2) -# 7-191 Reserved -# 192-254 Reserved for local use 255 255 Missing -# Notes: -# (1) Remotely sensed snow cover is expressed as a field of dimensionless, thematic values. The currently accepted values are for no-snow/no-cloud, 50, for clouds, 100, and for snow, 250. See code table 4.215. -# (2) A data field representing snow coverage by elevation portrays at which elevations there is a snow pack. The elevation values typically range from 0 to 90 in 100 m increments. A value of 253 is used to represent a no-snow/no-cloud data point. A value of 254 is used to represent a data point at which snow elevation could not be estimated because of clouds obscuring the remote sensor (when using aircraft or satellite measurements). -# (3) Snow water equivalent percent of normal is stored in percent of normal units. For example, a value of 110 indicates 110 percent of the normal snow water equivalent for a given depth of snow. - diff --git a/definitions/grib2/tables/4/3.15.table b/definitions/grib2/tables/4/3.15.table index bb431e14f..6a035be56 100644 --- a/definitions/grib2/tables/4/3.15.table +++ b/definitions/grib2/tables/4/3.15.table @@ -20,6 +20,3 @@ # 161-191 Reserved # 192-254 Reserved for local use 255 255 Missing -# Notes: -# (1) Negative values associated to this coordinate will indicate depth below ground surface. If values are all below surface, use of entry 106 is recommended, with positive coordinate values instead. -# (2) The Eta vertical coordinate system involves normalizing the pressure at some point on a specific level by the mean sea level pressure at that point. diff --git a/definitions/grib2/tables/4/4.2.1.0.table b/definitions/grib2/tables/4/4.2.1.0.table index 97efaa8cc..1e867e1cb 100644 --- a/definitions/grib2/tables/4/4.2.1.0.table +++ b/definitions/grib2/tables/4/4.2.1.0.table @@ -9,8 +9,3 @@ # 7-191 Reserved # 192-254 Reserved for local use 255 255 Missing -# Notes: -# (1) Remotely sensed snow cover is expressed as a field of dimensionless, thematic values. The currently accepted values are for no-snow/no-cloud, 50, for clouds, 100, and for snow, 250. See code table 4.215. -# (2) A data field representing snow coverage by elevation portrays at which elevations there is a snow pack. The elevation values typically range from 0 to 90 in 100 m increments. A value of 253 is used to represent a no-snow/no-cloud data point. A value of 254 is used to represent a data point at which snow elevation could not be estimated because of clouds obscuring the remote sensor (when using aircraft or satellite measurements). -# (3) Snow water equivalent percent of normal is stored in percent of normal units. For example, a value of 110 indicates 110 percent of the normal snow water equivalent for a given depth of snow. - diff --git a/definitions/grib2/tables/5/3.15.table b/definitions/grib2/tables/5/3.15.table index bb431e14f..6a035be56 100644 --- a/definitions/grib2/tables/5/3.15.table +++ b/definitions/grib2/tables/5/3.15.table @@ -20,6 +20,3 @@ # 161-191 Reserved # 192-254 Reserved for local use 255 255 Missing -# Notes: -# (1) Negative values associated to this coordinate will indicate depth below ground surface. If values are all below surface, use of entry 106 is recommended, with positive coordinate values instead. -# (2) The Eta vertical coordinate system involves normalizing the pressure at some point on a specific level by the mean sea level pressure at that point. diff --git a/definitions/grib2/tables/6/3.15.table b/definitions/grib2/tables/6/3.15.table index bb431e14f..b3adaeb33 100644 --- a/definitions/grib2/tables/6/3.15.table +++ b/definitions/grib2/tables/6/3.15.table @@ -1,5 +1,4 @@ # CODE TABLE 3.15, Physical meaning of vertical coordinate -# 0-19 Reserved 20 20 Temperature K # 21-99 Reserved 100 100 Pressure Pa @@ -20,6 +19,3 @@ # 161-191 Reserved # 192-254 Reserved for local use 255 255 Missing -# Notes: -# (1) Negative values associated to this coordinate will indicate depth below ground surface. If values are all below surface, use of entry 106 is recommended, with positive coordinate values instead. -# (2) The Eta vertical coordinate system involves normalizing the pressure at some point on a specific level by the mean sea level pressure at that point. diff --git a/definitions/grib2/tables/7/3.15.table b/definitions/grib2/tables/7/3.15.table index eb83c1b42..337bdce96 100644 --- a/definitions/grib2/tables/7/3.15.table +++ b/definitions/grib2/tables/7/3.15.table @@ -1,7 +1,5 @@ # CODE TABLE 3.15, Physical meaning of vertical coordinate -# 0-19 Reserved 20 20 Temperature (K) -# 21-99 Reserved 100 100 Pressure (Pa) 101 101 Pressure deviation from mean sea level (Pa) 102 102 Altitude above mean sea level (m) @@ -15,11 +13,5 @@ 110 110 Geometrical height (m) 111 111 Eta coordinate (see Note 2) 112 112 Geopotential height (gpm) -# 113-159 Reserved 160 160 Depth below sea level (m) -# 161-191 Reserved -# 192-254 Reserved for local use 255 255 Missing -# Notes: -# (1) Negative values associated to this coordinate will indicate depth below ground surface. If values are all below surface, use of entry 106 is recommended, with positive coordinate values instead. -# (2) The Eta vertical coordinate system involves normalizing the pressure at some point on a specific level by the mean sea level pressure at that point. From 76f3cd31713d3e77b360c99dc31ddc3abe571363 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Tue, 26 Nov 2019 10:56:41 +0000 Subject: [PATCH 05/17] ECC-1030: grib_get: Add '-B' option for ordering --- tests/CMakeLists.txt | 1 + tests/grib_ecc-1030.sh | 51 ++++++++++++++++++++++++++++++++++++++++++ tools/grib_get.c | 6 +---- tools/grib_options.c | 6 ++--- 4 files changed, 56 insertions(+), 8 deletions(-) create mode 100755 tests/grib_ecc-1030.sh diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f62ad4a13..36878b44f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -118,6 +118,7 @@ list( APPEND tests_data_reqd grib_ecc-984 grib_ecc-1000 grib_ecc-1001 + grib_ecc-1030 bufr_ecc-556 gts_get gts_ls diff --git a/tests/grib_ecc-1030.sh b/tests/grib_ecc-1030.sh new file mode 100755 index 000000000..96a102110 --- /dev/null +++ b/tests/grib_ecc-1030.sh @@ -0,0 +1,51 @@ +#!/bin/sh +# Copyright 2005-2019 ECMWF. +# +# This software is licensed under the terms of the Apache Licence Version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# +# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by +# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. +# + +. ./include.sh +set -u +# --------------------------------------------------------- +# This is the test for the JIRA issue ECC-1030 +# grib_get with the ordering option '-B' +# --------------------------------------------------------- +label="grib_ecc-1030-test" +tempRef=temp.${label}.ref +tempOut=temp.${label}.out + +# Test 1 +# ------ +input=${data_dir}/pad.grib +${tools_dir}/grib_get -p count,level -B'level:i' $input > $tempOut +cat > $tempRef < $tempOut +cat > $tempRef <integer, d->float, s->string, n->namespace." From 3a2e1dbbcc0d99929c27a0f5de6687aa4512a3cb Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Tue, 26 Nov 2019 15:55:01 +0000 Subject: [PATCH 06/17] Remove the error message. In IFS 1000s of messages are posted. Need to track the guilty party --- src/grib_accessor_class_ascii.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/grib_accessor_class_ascii.c b/src/grib_accessor_class_ascii.c index 6ec67e107..10207e0ed 100644 --- a/src/grib_accessor_class_ascii.c +++ b/src/grib_accessor_class_ascii.c @@ -256,7 +256,7 @@ static int unpack_double (grib_accessor* a, double*v, size_t *len) return GRIB_SUCCESS; } - grib_context_log(a->context,GRIB_LOG_ERROR,"Cannot unpack %s as double. Hint: Try unpacking as string",a->name); + grib_context_log(a->context,GRIB_LOG_WARNING,"Cannot unpack %s as double. Hint: Try unpacking as string",a->name); return GRIB_NOT_IMPLEMENTED; } From 98b3f9ed8520d5d68e540af7c4824c7950d26d42 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Tue, 26 Nov 2019 15:55:24 +0000 Subject: [PATCH 07/17] REVERT ECC-827 and ECC-962 due to regression. See SD-27528 --- tools/grib_to_netcdf.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tools/grib_to_netcdf.c b/tools/grib_to_netcdf.c index d20d45d0c..176c18782 100644 --- a/tools/grib_to_netcdf.c +++ b/tools/grib_to_netcdf.c @@ -1989,11 +1989,14 @@ static void validation_time(request *r) if(ndate) { const char* p = get_value(r, "date", 0); - const char* hdate = get_value(r, "hdate", 0); - /* All hindcast Data. See GRIB-699, GRIB-762 and ECC-962 */ - if (hdate) { - grib_context_log(ctx, GRIB_LOG_DEBUG, "grib_to_netcdf: Hindcast data hdate=%s", hdate); - p = hdate; /* Don't use 'date'. Use the hindcast date instead */ + const char* marsClass = get_value(r, "class", 0); + if (eq_string(marsClass, "s2")) { + /* S2S Data. See GRIB-699 and GRIB-762 */ + const char* hdate = get_value(r, "hdate", 0); + grib_context_log(ctx, GRIB_LOG_DEBUG, "grib_to_netcdf: S2S Data"); + if (hdate) { + p = hdate; /* This is a hindcast */ + } } if(is_number(p)) date = atol(p); From 0a2a1d3afd00c80ec84ed47ca40839fa72fd7afd Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Fri, 10 Jan 2020 14:03:02 +0000 Subject: [PATCH 08/17] Indentation and formatting --- src/grib_accessor_class_box.c | 29 +- src/grib_accessor_class_constant.c | 37 +- ...grib_accessor_class_data_complex_packing.c | 9 +- src/grib_accessor_class_double.c | 19 +- src/grib_accessor_class_evaluate.c | 28 +- src/grib_accessor_class_g1bitmap.c | 18 +- src/grib_accessor_class_g1fcperiod.c | 33 +- src/grib_accessor_class_label.c | 28 +- src/grib_accessor_class_latlon_increment.c | 10 +- src/grib_accessor_class_local_definition.c | 3 +- src/grib_accessor_class_long_vector.c | 123 ++--- src/grib_accessor_class_message.c | 48 +- src/grib_accessor_class_message_copy.c | 39 +- src/grib_accessor_class_nearest.c | 31 +- src/grib_accessor_class_offset_file.c | 47 +- src/grib_accessor_class_pack_bufr_values.c | 63 +-- src/grib_accessor_class_padding.c | 27 +- src/grib_accessor_class_padtoeven.c | 40 +- src/grib_accessor_class_size.c | 27 +- src/grib_dumper_class_grib_encode_C.c | 515 +++++++++--------- src/grib_dumper_class_serialize.c | 489 ++++++++--------- src/grib_expression_class_is_in_list.c | 209 ++++--- src/grib_expression_class_is_integer.c | 131 +++-- 23 files changed, 981 insertions(+), 1022 deletions(-) diff --git a/src/grib_accessor_class_box.c b/src/grib_accessor_class_box.c index dfcb8148c..7ed4bc27f 100644 --- a/src/grib_accessor_class_box.c +++ b/src/grib_accessor_class_box.c @@ -131,31 +131,30 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a,const long l, grib_arguments* args) { - grib_accessor_box* self = (grib_accessor_box*)a; - self->args = args; + grib_accessor_box* self = (grib_accessor_box*)a; + self->args = args; } static void dump(grib_accessor* a,grib_dumper* dumper) { - /* TODO: pass args */ - grib_dump_label(dumper,a,NULL); + /* TODO: pass args */ + grib_dump_label(dumper,a,NULL); } grib_box* grib_box_new(grib_handle* h,int* error) { - grib_accessor* a = NULL; - grib_accessor_box* na =NULL; - grib_box* n =NULL; - *error=GRIB_NOT_IMPLEMENTED; - a = grib_find_accessor(h,"BOX"); - na = (grib_accessor_box*)a; + grib_accessor* a = NULL; + grib_accessor_box* na =NULL; + grib_box* n =NULL; + *error=GRIB_NOT_IMPLEMENTED; + a = grib_find_accessor(h,"BOX"); + na = (grib_accessor_box*)a; - if (!a) return NULL; + if (!a) return NULL; - n = grib_box_factory(h,na->args); + n = grib_box_factory(h,na->args); - if (n) *error=GRIB_SUCCESS; + if (n) *error=GRIB_SUCCESS; - return n; + return n; } - diff --git a/src/grib_accessor_class_constant.c b/src/grib_accessor_class_constant.c index 3f6ef998e..20f8c98a6 100644 --- a/src/grib_accessor_class_constant.c +++ b/src/grib_accessor_class_constant.c @@ -136,40 +136,39 @@ static void init_class(grib_accessor_class* c) /* END_CLASS_IMP */ - -void accessor_constant_set_type(grib_accessor* a,int type) { - grib_accessor_constant* self = (grib_accessor_constant*)a; - self->type=type; -} - -void accessor_constant_set_dval(grib_accessor* a,double dval) { - grib_accessor_constant* self = (grib_accessor_constant*)a; - self->dval=dval; -} - - -static void init(grib_accessor* a, const long len , grib_arguments* arg ) +void accessor_constant_set_type(grib_accessor* a,int type) { - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + grib_accessor_constant* self = (grib_accessor_constant*)a; + self->type=type; +} + +void accessor_constant_set_dval(grib_accessor* a,double dval) +{ + grib_accessor_constant* self = (grib_accessor_constant*)a; + self->dval=dval; +} + +static void init(grib_accessor* a, const long len , grib_arguments* arg) +{ + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; } static int pack_bytes(grib_accessor* a,const unsigned char* val, size_t *len) { - return GRIB_READ_ONLY; + return GRIB_READ_ONLY; } static int pack_double(grib_accessor* a, const double* val,size_t *len) { - return GRIB_READ_ONLY; + return GRIB_READ_ONLY; } static int pack_long(grib_accessor* a, const long* val,size_t *len) { - return GRIB_READ_ONLY; + return GRIB_READ_ONLY; } static int pack_string(grib_accessor* a, const char* val, size_t *len) { - return GRIB_READ_ONLY; + return GRIB_READ_ONLY; } - diff --git a/src/grib_accessor_class_data_complex_packing.c b/src/grib_accessor_class_data_complex_packing.c index 1ed10628d..2339d558a 100644 --- a/src/grib_accessor_class_data_complex_packing.c +++ b/src/grib_accessor_class_data_complex_packing.c @@ -380,11 +380,10 @@ static int unpack_double(grib_accessor* a, double* val, size_t *len) } /* - printf("UNPACKING LAPLACE=%.20f\n",laplacianOperator); - - printf("packed offset=%ld\n",packed_offset); - for(i=0;iflags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) - { - int e=grib_unpack_double(a,&value,&one); - Assert(e == 0); - return value == GRIB_MISSING_DOUBLE; - } - return 0; + if(a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) + { + int e=grib_unpack_double(a,&value,&one); + Assert(e == 0); + return value == GRIB_MISSING_DOUBLE; + } + return 0; } */ diff --git a/src/grib_accessor_class_evaluate.c b/src/grib_accessor_class_evaluate.c index 10974350a..e10d8e91b 100644 --- a/src/grib_accessor_class_evaluate.c +++ b/src/grib_accessor_class_evaluate.c @@ -132,28 +132,24 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a,const long l, grib_arguments* c) { - grib_accessor_evaluate* self = (grib_accessor_evaluate*)a; - self->arg = c; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + grib_accessor_evaluate* self = (grib_accessor_evaluate*)a; + self->arg = c; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -static int pack_long(grib_accessor* a, const long* val, size_t *len){ - - return GRIB_NOT_IMPLEMENTED; - +static int pack_long(grib_accessor* a, const long* val, size_t *len) +{ + return GRIB_NOT_IMPLEMENTED; } - static int unpack_long(grib_accessor* a, long* val, size_t *len) { - int ret=0; - grib_accessor_evaluate* self = (grib_accessor_evaluate*)a; - grib_expression* e = grib_arguments_get_expression(grib_handle_of_accessor(a),self->arg,0); + int ret=0; + grib_accessor_evaluate* self = (grib_accessor_evaluate*)a; + grib_expression* e = grib_arguments_get_expression(grib_handle_of_accessor(a),self->arg,0); + ret = grib_expression_evaluate_long(grib_handle_of_accessor(a),e,val); + *len = 1; - ret = grib_expression_evaluate_long(grib_handle_of_accessor(a),e,val); - *len = 1; - - return ret; + return ret; } - diff --git a/src/grib_accessor_class_g1bitmap.c b/src/grib_accessor_class_g1bitmap.c index e4808bb84..aa685f930 100644 --- a/src/grib_accessor_class_g1bitmap.c +++ b/src/grib_accessor_class_g1bitmap.c @@ -139,19 +139,15 @@ static void init_class(grib_accessor_class* c) static void grib_set_bit_on( unsigned char* p, long *bitp); -static void init(grib_accessor* a, const long len , grib_arguments* arg ) +static void init(grib_accessor* a, const long len , grib_arguments* arg) { - grib_accessor_g1bitmap* self = (grib_accessor_g1bitmap*)a; - self->unusedBits = grib_arguments_get_name(grib_handle_of_accessor(a),arg,4); - } - -static int pack_double(grib_accessor* a, const double* val,size_t *len){ +static int pack_double(grib_accessor* a, const double* val,size_t *len) +{ grib_accessor_g1bitmap* self = (grib_accessor_g1bitmap*)a; - size_t tlen; unsigned char* buf = NULL; @@ -191,7 +187,6 @@ static int pack_double(grib_accessor* a, const double* val,size_t *len){ return GRIB_SUCCESS; } - static int value_count(grib_accessor* a,long* count) { grib_accessor_g1bitmap* self = (grib_accessor_g1bitmap*)a; @@ -201,8 +196,8 @@ static int value_count(grib_accessor* a,long* count) if ((err=grib_get_long_internal(grib_handle_of_accessor(a), self->unusedBits, &tlen)) != GRIB_SUCCESS) grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_class_bitmap.value_count : cannot get %s err=%d",self->unusedBits,err); - *count = (a->length*8)-tlen; - return err; + *count = (a->length*8)-tlen; + return err; } static int unpack_bytes(grib_accessor* a, unsigned char* val, size_t *len) @@ -232,7 +227,8 @@ static int unpack_bytes(grib_accessor* a, unsigned char* val, size_t *len) return GRIB_SUCCESS; } -static void grib_set_bit_on( unsigned char* p, long *bitp){ +static void grib_set_bit_on( unsigned char* p, long *bitp) +{ unsigned char o = 1; p += (*bitp >> 3); o <<= 7-((*bitp)%8); diff --git a/src/grib_accessor_class_g1fcperiod.c b/src/grib_accessor_class_g1fcperiod.c index fe7eaccf8..dad7d2c85 100644 --- a/src/grib_accessor_class_g1fcperiod.c +++ b/src/grib_accessor_class_g1fcperiod.c @@ -138,30 +138,27 @@ static void init_class(grib_accessor_class* c) /* END_CLASS_IMP */ - static int unpack_string(grib_accessor* a, char* val, size_t *len) { - long start = 0, theEnd = 0; - char tmp[1024]; - int err = grib_g1_step_get_steps(a,&start,&theEnd); - size_t l = 0; + long start = 0, theEnd = 0; + char tmp[1024]; + int err = grib_g1_step_get_steps(a,&start,&theEnd); + size_t l = 0; + if(err) return err; - if(err) return err; + sprintf(tmp,"%ld-%ld",start/24,theEnd/24); + /*printf("---- FCPERIOD %s [start:%g, end:%g]",tmp,start,end);*/ - sprintf(tmp,"%ld-%ld",start/24,theEnd/24); - /*printf("---- FCPERIOD %s [start:%g, end:%g]",tmp,start,end);*/ + l = strlen(tmp) + 1; + if(*len < l) + { + *len = l; + return GRIB_BUFFER_TOO_SMALL; + } - l = strlen(tmp) + 1; - if(*len < l) - { *len = l; - return GRIB_BUFFER_TOO_SMALL; - } + strcpy(val,tmp); - *len = l; - strcpy(val,tmp); - - - return GRIB_SUCCESS; + return GRIB_SUCCESS; } diff --git a/src/grib_accessor_class_label.c b/src/grib_accessor_class_label.c index a51fa7616..011c52302 100644 --- a/src/grib_accessor_class_label.c +++ b/src/grib_accessor_class_label.c @@ -129,33 +129,31 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a, const long len , grib_arguments* arg) { - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; - a->length = 0; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; + a->length = 0; } - static void dump(grib_accessor* a, grib_dumper* dumper) { - grib_dump_label(dumper,a,NULL); + grib_dump_label(dumper,a,NULL); } static int get_native_type(grib_accessor* a) { - return GRIB_TYPE_LABEL; + return GRIB_TYPE_LABEL; } - -static int compare(grib_accessor* a, grib_accessor* b) { - return GRIB_SUCCESS; +static int compare(grib_accessor* a, grib_accessor* b) +{ + return GRIB_SUCCESS; } static int unpack_string(grib_accessor* a, char* val, size_t *len) { - size_t vlen=strlen(a->name); - if (vlen > *len) return GRIB_BUFFER_TOO_SMALL; - *len=vlen; - strcpy(val,a->name); - return GRIB_SUCCESS; + size_t vlen=strlen(a->name); + if (vlen > *len) return GRIB_BUFFER_TOO_SMALL; + *len=vlen; + strcpy(val,a->name); + return GRIB_SUCCESS; } - diff --git a/src/grib_accessor_class_latlon_increment.c b/src/grib_accessor_class_latlon_increment.c index 353b64bc7..9b5955169 100644 --- a/src/grib_accessor_class_latlon_increment.c +++ b/src/grib_accessor_class_latlon_increment.c @@ -162,7 +162,7 @@ static void init(grib_accessor* a,const long l, grib_arguments* c) self->isLongitude=grib_arguments_get_long(grib_handle_of_accessor(a), c,n++); } -static int unpack_double (grib_accessor* a, double* val, size_t *len) +static int unpack_double(grib_accessor* a, double* val, size_t *len) { grib_accessor_latlon_increment* self = (grib_accessor_latlon_increment*)a; int ret = 0; @@ -315,8 +315,8 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) } /*ret = grib_set_long_internal(grib_handle_of_accessor(a), self->numberOfPoints,numberOfPoints); - if(ret ) - grib_context_log(a->context, GRIB_LOG_ERROR, "Accessor %s cannot pack value for %s error %d \n", a->name, self->numberOfPoints, ret); + if(ret) + grib_context_log(a->context, GRIB_LOG_ERROR, "Accessor %s cannot pack value for %s error %d \n", a->name, self->numberOfPoints, ret); */ grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints,&codedNumberOfPoints); @@ -342,8 +342,8 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len) return ret; } -static int is_missing(grib_accessor* a){ - +static int is_missing(grib_accessor* a) +{ size_t len=1; double val=0; diff --git a/src/grib_accessor_class_local_definition.c b/src/grib_accessor_class_local_definition.c index 0118fa9f8..9ef251987 100644 --- a/src/grib_accessor_class_local_definition.c +++ b/src/grib_accessor_class_local_definition.c @@ -395,7 +395,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t *len) grib_set_long(hand, self->grib2LocalSectionNumber,*val); - return 0; + return 0; } static int value_count(grib_accessor* a,long* count) @@ -403,4 +403,3 @@ static int value_count(grib_accessor* a,long* count) *count=1; return 0; } - diff --git a/src/grib_accessor_class_long_vector.c b/src/grib_accessor_class_long_vector.c index 8787adf18..7bfc49f3a 100644 --- a/src/grib_accessor_class_long_vector.c +++ b/src/grib_accessor_class_long_vector.c @@ -142,90 +142,91 @@ static void init_class(grib_accessor_class* c) /* END_CLASS_IMP */ typedef struct grib_accessor_abstract_long_vector { - grib_accessor att; - /* Members defined in gen */ - /* Members defined in abstract_long_vector */ - long* v; - long pack_index; - int number_of_elements; + grib_accessor att; + /* Members defined in gen */ + /* Members defined in abstract_long_vector */ + long* v; + long pack_index; + int number_of_elements; } grib_accessor_abstract_long_vector; static void init(grib_accessor* a,const long l, grib_arguments* c) { - grib_accessor_long_vector* self = (grib_accessor_long_vector*)a; - grib_accessor* va=NULL; - grib_accessor_abstract_long_vector* v =NULL; - int n = 0; + grib_accessor_long_vector* self = (grib_accessor_long_vector*)a; + grib_accessor* va=NULL; + grib_accessor_abstract_long_vector* v =NULL; + int n = 0; - self->vector = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); + self->vector = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); - va=(grib_accessor*)grib_find_accessor(grib_handle_of_accessor(a),self->vector); - v=(grib_accessor_abstract_long_vector*)va; + va=(grib_accessor*)grib_find_accessor(grib_handle_of_accessor(a),self->vector); + v=(grib_accessor_abstract_long_vector*)va; - self->index = grib_arguments_get_long(grib_handle_of_accessor(a),c,n++); + self->index = grib_arguments_get_long(grib_handle_of_accessor(a),c,n++); - /* check self->index on init and never change it */ - Assert(self->index < v->number_of_elements && self->index>=0); + /* check self->index on init and never change it */ + Assert(self->index < v->number_of_elements && self->index>=0); - a->length=0; + a->length=0; } -static int unpack_long(grib_accessor* a, long* val, size_t *len) { - size_t size=0; - long* vector; - grib_accessor_long_vector* self = (grib_accessor_long_vector*)a; - grib_accessor* va=NULL; - grib_accessor_abstract_long_vector* v =NULL; - - va=(grib_accessor*)grib_find_accessor(grib_handle_of_accessor(a),self->vector); - v=(grib_accessor_abstract_long_vector*)va; +static int unpack_long(grib_accessor* a, long* val, size_t *len) +{ + size_t size=0; + long* vector; + grib_accessor_long_vector* self = (grib_accessor_long_vector*)a; + grib_accessor* va=NULL; + grib_accessor_abstract_long_vector* v =NULL; - /*TODO implement the dirty mechanism to avoid to unpack every time */ - grib_get_size(grib_handle_of_accessor(a),self->vector,&size); - vector=(long*)grib_context_malloc(a->context,sizeof(long)*size); - grib_unpack_long(va,vector,&size); - grib_context_free(a->context,vector); - + va=(grib_accessor*)grib_find_accessor(grib_handle_of_accessor(a),self->vector); + v=(grib_accessor_abstract_long_vector*)va; - *val = v->v[self->index]; + /*TODO implement the dirty mechanism to avoid to unpack every time */ + grib_get_size(grib_handle_of_accessor(a),self->vector,&size); + vector=(long*)grib_context_malloc(a->context,sizeof(long)*size); + grib_unpack_long(va,vector,&size); + grib_context_free(a->context,vector); - return GRIB_SUCCESS; + *val = v->v[self->index]; + + return GRIB_SUCCESS; } -static int unpack_double(grib_accessor* a, double* val, size_t *len) { - long lval=0; - int err=0; - grib_accessor_long_vector* self = (grib_accessor_long_vector*)a; - grib_accessor* va=NULL; - grib_accessor_abstract_long_vector* v =NULL; - va=(grib_accessor*)grib_find_accessor(grib_handle_of_accessor(a),self->vector); - v=(grib_accessor_abstract_long_vector*)va; - - err=unpack_long(a,&lval,len); +static int unpack_double(grib_accessor* a, double* val, size_t *len) +{ + long lval=0; + int err=0; + grib_accessor_long_vector* self = (grib_accessor_long_vector*)a; + grib_accessor* va=NULL; + grib_accessor_abstract_long_vector* v =NULL; + va=(grib_accessor*)grib_find_accessor(grib_handle_of_accessor(a),self->vector); + v=(grib_accessor_abstract_long_vector*)va; - *val = (double)v->v[self->index]; + err=unpack_long(a,&lval,len); - return err; + *val = (double)v->v[self->index]; + + return err; } -static int pack_long (grib_accessor* a, const long* val, size_t *len) { - int err=0; - grib_accessor_long_vector* self = (grib_accessor_long_vector*)a; - grib_accessor* va=NULL; - grib_accessor_abstract_long_vector* v =NULL; - - va=(grib_accessor*)grib_find_accessor(grib_handle_of_accessor(a),self->vector); - v=(grib_accessor_abstract_long_vector*)va; +static int pack_long(grib_accessor* a, const long* val, size_t *len) +{ + int err=0; + grib_accessor_long_vector* self = (grib_accessor_long_vector*)a; + grib_accessor* va=NULL; + grib_accessor_abstract_long_vector* v =NULL; - v->pack_index=self->index; + va=(grib_accessor*)grib_find_accessor(grib_handle_of_accessor(a),self->vector); + v=(grib_accessor_abstract_long_vector*)va; - err=grib_pack_long(va,val,len); + v->pack_index=self->index; - return err; + err=grib_pack_long(va,val,len); + + return err; } -static int get_native_type(grib_accessor* a){ - return GRIB_TYPE_LONG; +static int get_native_type(grib_accessor* a) +{ + return GRIB_TYPE_LONG; } - - diff --git a/src/grib_accessor_class_message.c b/src/grib_accessor_class_message.c index 7dd2c1e71..0c03cc657 100644 --- a/src/grib_accessor_class_message.c +++ b/src/grib_accessor_class_message.c @@ -136,9 +136,9 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a, const long len, grib_arguments*arg ) { - a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length=grib_handle_of_accessor(a)->buffer->ulength-len-a->offset; + a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->length=grib_handle_of_accessor(a)->buffer->ulength-len-a->offset; } static int compare(grib_accessor* a, grib_accessor* b) @@ -149,43 +149,41 @@ static int compare(grib_accessor* a, grib_accessor* b) static void update_size(grib_accessor* a,size_t new_size) { - /* printf("update_size: grib_accessor_class_message.c %ld %ld %s %s\n", (long)new_size,(long)a->length,a->cclass->name,a->name); */ - a->length = new_size; + /* printf("update_size: grib_accessor_class_message.c %ld %ld %s %s\n", (long)new_size,(long)a->length,a->cclass->name,a->name); */ + a->length = new_size; } static void resize(grib_accessor* a,size_t new_size) { - void* zero = grib_context_malloc_clear(a->context,new_size); - - grib_buffer_replace(a,(const unsigned char*)zero,new_size,1,0); - grib_context_free(a->context,zero); - grib_context_log(a->context,GRIB_LOG_DEBUG,"resize: grib_accessor_class_message.c %ld %ld %s %s\n",(long)new_size,(long)a->length,a->cclass->name,a->name); - Assert(new_size == a->length); + void* zero = grib_context_malloc_clear(a->context,new_size); + grib_buffer_replace(a,(const unsigned char*)zero,new_size,1,0); + grib_context_free(a->context,zero); + grib_context_log(a->context,GRIB_LOG_DEBUG,"resize: grib_accessor_class_message.c %ld %ld %s %s\n",(long)new_size,(long)a->length,a->cclass->name,a->name); + Assert(new_size == a->length); } static int value_count(grib_accessor* a,long* count){ *count=1;return 0;} static int unpack_string(grib_accessor* a, char* val, size_t *len) { + int i = 0; - int i = 0; + if(len[0] < (a->length+1)) + { + grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%d) for %s it contains %d values ", len[0], a->name , a->length+1 ); + len[0] = 0; + return GRIB_ARRAY_TOO_SMALL; + } - if(len[0] < (a->length+1)) - { - grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%d) for %s it contains %d values ", len[0], a->name , a->length+1 ); - len[0] = 0; - return GRIB_ARRAY_TOO_SMALL; - } - - for ( i = 0; i < a->length; i++) - val[i] = grib_handle_of_accessor(a)->buffer->data[a->offset+i]; - val[i] = 0; - len[0] = i; - return GRIB_SUCCESS; + for ( i = 0; i < a->length; i++) + val[i] = grib_handle_of_accessor(a)->buffer->data[a->offset+i]; + val[i] = 0; + len[0] = i; + return GRIB_SUCCESS; } static size_t string_length(grib_accessor* a) { - return a->length; + return a->length; } diff --git a/src/grib_accessor_class_message_copy.c b/src/grib_accessor_class_message_copy.c index 01a04e37e..76f5aaf9a 100644 --- a/src/grib_accessor_class_message_copy.c +++ b/src/grib_accessor_class_message_copy.c @@ -131,42 +131,43 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a, const long length , grib_arguments* args ) { - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length=0; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->length=0; } static void dump(grib_accessor* a, grib_dumper* dumper) { - grib_dump_string(dumper,a,NULL); + grib_dump_string(dumper,a,NULL); } static int get_native_type(grib_accessor* a) { - return GRIB_TYPE_STRING; + return GRIB_TYPE_STRING; } -static int unpack_string (grib_accessor* a, char* val, size_t *len){ - size_t slen=grib_handle_of_accessor(a)->buffer->ulength ; - size_t i; - unsigned char* v=0; +static int unpack_string(grib_accessor* a, char* val, size_t *len) +{ + size_t slen=grib_handle_of_accessor(a)->buffer->ulength ; + size_t i; + unsigned char* v=0; - if (*len < slen) { return GRIB_ARRAY_TOO_SMALL; } - v=grib_handle_of_accessor(a)->buffer->data; - /* replace unprintable characters with space */ - for (i=0;i126) v[i]=32; - memcpy(val,grib_handle_of_accessor(a)->buffer->data,slen); + if (*len < slen) { return GRIB_ARRAY_TOO_SMALL; } + v=grib_handle_of_accessor(a)->buffer->data; + /* replace unprintable characters with space */ + for (i=0;i126) v[i]=32; + memcpy(val,grib_handle_of_accessor(a)->buffer->data,slen); - *len=slen; + *len=slen; - return GRIB_SUCCESS; + return GRIB_SUCCESS; } static size_t string_length(grib_accessor* a) { - return grib_handle_of_accessor(a)->buffer->ulength; + return grib_handle_of_accessor(a)->buffer->ulength; } -static long byte_count(grib_accessor* a) { - return a->length; +static long byte_count(grib_accessor* a) +{ + return a->length; } - diff --git a/src/grib_accessor_class_nearest.c b/src/grib_accessor_class_nearest.c index 2adb1107f..45bf2ac7d 100644 --- a/src/grib_accessor_class_nearest.c +++ b/src/grib_accessor_class_nearest.c @@ -130,32 +130,31 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a,const long l, grib_arguments* args) { - grib_accessor_nearest* self = (grib_accessor_nearest*)a; - self->args = args; + grib_accessor_nearest* self = (grib_accessor_nearest*)a; + self->args = args; } static void dump(grib_accessor* a,grib_dumper* dumper) { - /* TODO: pass args */ - grib_dump_label(dumper,a,NULL); + /* TODO: pass args */ + grib_dump_label(dumper,a,NULL); } grib_nearest* grib_nearest_new(const grib_handle* ch, int* error) { - grib_handle* h = (grib_handle*)ch; - grib_accessor* a = NULL; - grib_accessor_nearest* na =NULL; - grib_nearest* n =NULL; - *error=GRIB_NOT_IMPLEMENTED; - a = grib_find_accessor(h,"NEAREST"); - na = (grib_accessor_nearest*)a; + grib_handle* h = (grib_handle*)ch; + grib_accessor* a = NULL; + grib_accessor_nearest* na =NULL; + grib_nearest* n =NULL; + *error=GRIB_NOT_IMPLEMENTED; + a = grib_find_accessor(h,"NEAREST"); + na = (grib_accessor_nearest*)a; - if (!a) return NULL; + if (!a) return NULL; - n = grib_nearest_factory(h,na->args); + n = grib_nearest_factory(h,na->args); - if (n) *error=GRIB_SUCCESS; + if (n) *error=GRIB_SUCCESS; - return n; + return n; } - diff --git a/src/grib_accessor_class_offset_file.c b/src/grib_accessor_class_offset_file.c index 09d11b5ae..81aedd4e5 100644 --- a/src/grib_accessor_class_offset_file.c +++ b/src/grib_accessor_class_offset_file.c @@ -134,42 +134,39 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a,const long l, grib_arguments* c) { - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length=0; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->length=0; } -static int unpack_double(grib_accessor* a, double* val, size_t *len) +static int unpack_double(grib_accessor* a, double* val, size_t *len) { - *val = (double)grib_handle_of_accessor(a)->offset; - *len =1; - return 0; + *val = (double)grib_handle_of_accessor(a)->offset; + *len =1; + return 0; } -static int unpack_string(grib_accessor*a , char* v, size_t *len){ +static int unpack_string(grib_accessor*a , char* v, size_t *len) +{ + double val = 0; + size_t l = 1; + char repres[1024]; - double val = 0; - size_t l = 1; - char repres[1024]; + grib_unpack_double (a , &val, &l); - grib_unpack_double (a , &val, &l); + sprintf(repres,"%.0f", val); - sprintf(repres,"%.0f", val); + l = strlen(repres)+1; - l = strlen(repres)+1; + if(l >*len ){ + grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_long : unpack_string : Buffer too small for %s ", a->name ); - if(l >*len ){ - grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_long : unpack_string : Buffer too small for %s ", a->name ); + *len = l; + return GRIB_BUFFER_TOO_SMALL; + } + grib_context_log(a->context,GRIB_LOG_DEBUG, "grib_accessor_long: Casting double %s to string ", a->name); *len = l; - return GRIB_BUFFER_TOO_SMALL; - } - grib_context_log(a->context,GRIB_LOG_DEBUG, "grib_accessor_long: Casting double %s to string ", a->name); - - *len = l; - - strcpy(v,repres); - return GRIB_SUCCESS; - + strcpy(v,repres); + return GRIB_SUCCESS; } - diff --git a/src/grib_accessor_class_pack_bufr_values.c b/src/grib_accessor_class_pack_bufr_values.c index da2f0d44b..d77cc61e7 100644 --- a/src/grib_accessor_class_pack_bufr_values.c +++ b/src/grib_accessor_class_pack_bufr_values.c @@ -134,70 +134,67 @@ static void init_class(grib_accessor_class* c) /* END_CLASS_IMP */ -static void init(grib_accessor* a, const long len, grib_arguments* params) { +static void init(grib_accessor* a, const long len, grib_arguments* params) +{ + char* key; + grib_accessor_pack_bufr_values* self = (grib_accessor_pack_bufr_values*)a; + key = (char*)grib_arguments_get_name(grib_handle_of_accessor(a),params,0); + self->data_accessor=grib_find_accessor(grib_handle_of_accessor(a),key); - char* key; - grib_accessor_pack_bufr_values* self = (grib_accessor_pack_bufr_values*)a; - key = (char*)grib_arguments_get_name(grib_handle_of_accessor(a),params,0); - self->data_accessor=grib_find_accessor(grib_handle_of_accessor(a),key); - - a->length = 0; + a->length = 0; } static void dump(grib_accessor* a, grib_dumper* dumper) { - return; } -static int unpack_string_array (grib_accessor* a, char** buffer, size_t *len) +static int unpack_string_array(grib_accessor* a, char** buffer, size_t *len) { - return GRIB_NOT_IMPLEMENTED; + return GRIB_NOT_IMPLEMENTED; } -static int unpack_string (grib_accessor* a, char* buffer, size_t *len) +static int unpack_string(grib_accessor* a, char* buffer, size_t *len) { - return GRIB_NOT_IMPLEMENTED; + return GRIB_NOT_IMPLEMENTED; } -static int unpack_long (grib_accessor* a, long* val, size_t *len) +static int unpack_long(grib_accessor* a, long* val, size_t *len) { - return GRIB_NOT_IMPLEMENTED; + return GRIB_NOT_IMPLEMENTED; } -static int unpack_double (grib_accessor* a, double* val, size_t *len) +static int unpack_double(grib_accessor* a, double* val, size_t *len) { - return GRIB_NOT_IMPLEMENTED; + return GRIB_NOT_IMPLEMENTED; } static int value_count(grib_accessor* a,long* count) { - *count=1; - return 0; + *count=1; + return 0; } static void destroy(grib_context* context,grib_accessor* a) { - return; } -static int get_native_type(grib_accessor* a){ - return GRIB_TYPE_LONG; -} - -static int pack_long (grib_accessor* a, const long* val, size_t *len) +static int get_native_type(grib_accessor* a) { - grib_accessor_pack_bufr_values* self = (grib_accessor_pack_bufr_values*)a; - grib_accessor* data=(grib_accessor*)self->data_accessor; - - return grib_pack_double(data,0,0); + return GRIB_TYPE_LONG; } - -static int pack_double (grib_accessor* a, const double* val, size_t *len) +static int pack_long(grib_accessor* a, const long* val, size_t *len) { - grib_accessor_pack_bufr_values* self = (grib_accessor_pack_bufr_values*)a; - grib_accessor* data=(grib_accessor*)self->data_accessor; + grib_accessor_pack_bufr_values* self = (grib_accessor_pack_bufr_values*)a; + grib_accessor* data=(grib_accessor*)self->data_accessor; - return grib_pack_double(data,0,0); + return grib_pack_double(data,0,0); } +static int pack_double(grib_accessor* a, const double* val, size_t *len) +{ + grib_accessor_pack_bufr_values* self = (grib_accessor_pack_bufr_values*)a; + grib_accessor* data=(grib_accessor*)self->data_accessor; + + return grib_pack_double(data,0,0); +} diff --git a/src/grib_accessor_class_padding.c b/src/grib_accessor_class_padding.c index 48a063666..e391fbed2 100644 --- a/src/grib_accessor_class_padding.c +++ b/src/grib_accessor_class_padding.c @@ -132,33 +132,32 @@ static void init_class(grib_accessor_class* c) /* END_CLASS_IMP */ - static void init(grib_accessor* a, const long len, grib_arguments*arg ) { - a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -static int compare(grib_accessor* a, grib_accessor* b) { - if (a->length != b->length) return GRIB_COUNT_MISMATCH; - return GRIB_SUCCESS; +static int compare(grib_accessor* a, grib_accessor* b) +{ + if (a->length != b->length) return GRIB_COUNT_MISMATCH; + return GRIB_SUCCESS; } static void update_size(grib_accessor* a,size_t new_size) { - /* printf("update_size: grib_accessor_class_padding.c %ld %ld %s %s\n", (long)new_size,(long)a->length,a->cclass->name,a->name); */ - a->length = new_size; + /* printf("update_size: grib_accessor_class_padding.c %ld %ld %s %s\n", (long)new_size,(long)a->length,a->cclass->name,a->name); */ + a->length = new_size; } static void resize(grib_accessor* a,size_t new_size) { - void* zero = grib_context_malloc_clear(a->context,new_size); - - grib_buffer_replace(a,(const unsigned char*)zero,new_size,1,0); - grib_context_free(a->context,zero); - grib_context_log(a->context,GRIB_LOG_DEBUG,"resize: grib_accessor_class_padding.c %ld %ld %s %s\n",(long)new_size,(long)a->length,a->cclass->name,a->name); - Assert(new_size == a->length); + void* zero = grib_context_malloc_clear(a->context,new_size); + grib_buffer_replace(a,(const unsigned char*)zero,new_size,1,0); + grib_context_free(a->context,zero); + grib_context_log(a->context,GRIB_LOG_DEBUG,"resize: grib_accessor_class_padding.c %ld %ld %s %s\n",(long)new_size,(long)a->length,a->cclass->name,a->name); + Assert(new_size == a->length); } static int value_count(grib_accessor* a,long *c){ *c=a->length; return 0;} diff --git a/src/grib_accessor_class_padtoeven.c b/src/grib_accessor_class_padtoeven.c index 7a9a786a9..ddcb97840 100644 --- a/src/grib_accessor_class_padtoeven.c +++ b/src/grib_accessor_class_padtoeven.c @@ -139,38 +139,36 @@ static void init_class(grib_accessor_class* c) static size_t preferred_size(grib_accessor* a,int from_handle) { - grib_accessor_padtoeven* self = (grib_accessor_padtoeven*)a; - long offset = 0; - long length = 0; - long seclen; + grib_accessor_padtoeven* self = (grib_accessor_padtoeven*)a; + long offset = 0; + long length = 0; + long seclen; - grib_get_long_internal(grib_handle_of_accessor(a),self->section_offset,&offset); - grib_get_long_internal(grib_handle_of_accessor(a),self->section_length,&length); + grib_get_long_internal(grib_handle_of_accessor(a),self->section_offset,&offset); + grib_get_long_internal(grib_handle_of_accessor(a),self->section_length,&length); - if((length%2) && from_handle) { + if((length%2) && from_handle) { #if 0 - grib_context_log(a->context, - GRIB_LOG_ERROR,"GRIB message has an odd length section (%ld, %s)", - (long)length,a->name); + grib_context_log(a->context, + GRIB_LOG_ERROR,"GRIB message has an odd length section (%ld, %s)", + (long)length,a->name); #endif - return 0; + return 0; - } + } - /* printf("EVEN %ld %ld\n",(long) a->offset,(long) offset);*/ + /* printf("EVEN %ld %ld\n",(long) a->offset,(long) offset);*/ + seclen = a->offset - offset; - seclen = a->offset - offset; - - return seclen % 2 ? 1 : 0; + return seclen % 2 ? 1 : 0; } static void init(grib_accessor* a, const long len, grib_arguments* args) { - grib_accessor_padtoeven* self = (grib_accessor_padtoeven*)a; + grib_accessor_padtoeven* self = (grib_accessor_padtoeven*)a; - self->section_offset = grib_arguments_get_name(grib_handle_of_accessor(a),args,0); - self->section_length = grib_arguments_get_name(grib_handle_of_accessor(a),args,1); - - a->length = preferred_size(a,1); + self->section_offset = grib_arguments_get_name(grib_handle_of_accessor(a),args,0); + self->section_length = grib_arguments_get_name(grib_handle_of_accessor(a),args,1); + a->length = preferred_size(a,1); } diff --git a/src/grib_accessor_class_size.c b/src/grib_accessor_class_size.c index dd3922761..c495c8993 100644 --- a/src/grib_accessor_class_size.c +++ b/src/grib_accessor_class_size.c @@ -131,21 +131,20 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a,const long l, grib_arguments* c) { - grib_accessor_size* self = (grib_accessor_size*)a; - self->accessor = grib_arguments_get_name(grib_handle_of_accessor(a),c,0); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->length=0; + grib_accessor_size* self = (grib_accessor_size*)a; + self->accessor = grib_arguments_get_name(grib_handle_of_accessor(a),c,0); + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; + a->length=0; } -static int unpack_long(grib_accessor* a, long* val, size_t *len) +static int unpack_long(grib_accessor* a, long* val, size_t *len) { - int ret=0; - size_t size=0; - grib_accessor_size* self = (grib_accessor_size*)a; - ret=grib_get_size(grib_handle_of_accessor(a),self->accessor,&size); - *val=(long)size; - *len =1; - return ret; + int ret=0; + size_t size=0; + grib_accessor_size* self = (grib_accessor_size*)a; + ret=grib_get_size(grib_handle_of_accessor(a),self->accessor,&size); + *val=(long)size; + *len =1; + return ret; } - diff --git a/src/grib_dumper_class_grib_encode_C.c b/src/grib_dumper_class_grib_encode_C.c index bb656ec26..110cf74ae 100644 --- a/src/grib_dumper_class_grib_encode_C.c +++ b/src/grib_dumper_class_grib_encode_C.c @@ -86,69 +86,69 @@ static void init_class (grib_dumper_class* c){} static int init(grib_dumper* d) { - /* grib_dumper_grib_encode_C *self = (grib_dumper_grib_encode_C*)d; */ - return GRIB_SUCCESS; + /* grib_dumper_grib_encode_C *self = (grib_dumper_grib_encode_C*)d; */ + return GRIB_SUCCESS; } static int destroy (grib_dumper* d){ - return GRIB_SUCCESS; + return GRIB_SUCCESS; } static void pcomment(FILE* f,long value,const char* p) { - int cr = 0; - fprintf(f,"\n /* %ld = ",value); + int cr = 0; + fprintf(f,"\n /* %ld = ",value); - while(*p) - { - switch(*p) + while(*p) { - case ';': - fprintf(f,"\n "); - cr = 1; - break; + switch(*p) + { + case ';': + fprintf(f,"\n "); + cr = 1; + break; - case ':': - if(cr) - fprintf(f,"\n See "); - else - fprintf(f,". See "); - break; + case ':': + if(cr) + fprintf(f,"\n See "); + else + fprintf(f,". See "); + break; - default: - fputc(*p,f); - break; + default: + fputc(*p,f); + break; + } + + p++; } - p++; - } - - fprintf(f," */\n"); + fprintf(f," */\n"); } static void dump_long(grib_dumper* d,grib_accessor* a,const char* comment) { - grib_dumper_grib_encode_C *self = (grib_dumper_grib_encode_C*)d; - long value; size_t size = 1; - int err = grib_unpack_long(a,&value,&size); + grib_dumper_grib_encode_C *self = (grib_dumper_grib_encode_C*)d; + long value; size_t size = 1; + int err = grib_unpack_long(a,&value,&size); - if((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY)) - return; + if((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY)) + return; #if 1 - if(comment) pcomment(self->dumper.out,value,comment); + if(comment) pcomment(self->dumper.out,value,comment); #endif - if( ((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && (value == GRIB_MISSING_LONG)) - fprintf(self->dumper.out," GRIB_CHECK(grib_set_missing(h,\"%s\"),%d);\n",a->name,0); - else - fprintf(self->dumper.out," GRIB_CHECK(grib_set_long(h,\"%s\",%ld),%d);\n",a->name,value,0); + if( ((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && (value == GRIB_MISSING_LONG)) + fprintf(self->dumper.out," GRIB_CHECK(grib_set_missing(h,\"%s\"),%d);\n",a->name,0); + else + fprintf(self->dumper.out," GRIB_CHECK(grib_set_long(h,\"%s\",%ld),%d);\n",a->name,value,0); - if(err) - fprintf(self->dumper.out," /* Error accessing %s (%s) */",a->name,grib_get_error_message(err)); + if(err) + fprintf(self->dumper.out," /* Error accessing %s (%s) */",a->name,grib_get_error_message(err)); - if(comment) fprintf(self->dumper.out,"\n"); + if(comment) fprintf(self->dumper.out,"\n"); } @@ -157,302 +157,301 @@ static int test_bit(long a, long b) {return a&(1<flags & GRIB_ACCESSOR_FLAG_READ_ONLY) - return; + if(a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) + return; - if(a->length == 0) - return; + if(a->length == 0) + return; - buf[0] = 0; + buf[0] = 0; - for(i=0;i<(a->length*8);i++) { - if(test_bit(value,a->length*8-i-1)) - strcat(buf,"1"); + for(i=0;i<(a->length*8);i++) { + if(test_bit(value,a->length*8-i-1)) + strcat(buf,"1"); + else + strcat(buf,"0"); + } + + if(comment) { + strcat(buf,";"); + strcat(buf,comment); + } + + pcomment(self->dumper.out,value,buf); + + if(err) + fprintf(self->dumper.out," /* Error accessing %s (%s) */",a->name,grib_get_error_message(err)); else - strcat(buf,"0"); - } + fprintf(self->dumper.out," GRIB_CHECK(grib_set_long(h,\"%s\",%ld),%d);\n",a->name,value,0); - if(comment) { - strcat(buf,";"); - strcat(buf,comment); - } - - pcomment(self->dumper.out,value,buf); - - if(err) - fprintf(self->dumper.out," /* Error accessing %s (%s) */",a->name,grib_get_error_message(err)); - else - fprintf(self->dumper.out," GRIB_CHECK(grib_set_long(h,\"%s\",%ld),%d);\n",a->name,value,0); - - fprintf(self->dumper.out,"\n"); + fprintf(self->dumper.out,"\n"); } static void dump_double(grib_dumper* d,grib_accessor* a,const char* comment) { - grib_dumper_grib_encode_C *self = (grib_dumper_grib_encode_C*)d; - double value; size_t size = 1; - int err = grib_unpack_double(a,&value,&size); - if(a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) - return; + grib_dumper_grib_encode_C *self = (grib_dumper_grib_encode_C*)d; + double value; size_t size = 1; + int err = grib_unpack_double(a,&value,&size); + if(a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) + return; - if(a->length == 0) - return; + if(a->length == 0) + return; #if 0 - if(comment) fprintf(self->dumper.out,"/* %s */\n",comment); + if(comment) fprintf(self->dumper.out,"/* %s */\n",comment); #endif - fprintf(self->dumper.out," GRIB_CHECK(grib_set_double(h,\"%s\",%g),%d);\n",a->name,value,0); + fprintf(self->dumper.out," GRIB_CHECK(grib_set_double(h,\"%s\",%g),%d);\n",a->name,value,0); - if(err) - fprintf(self->dumper.out," /* Error accessing %s (%s) */",a->name,grib_get_error_message(err)); + if(err) + fprintf(self->dumper.out," /* Error accessing %s (%s) */",a->name,grib_get_error_message(err)); } static void dump_string(grib_dumper* d,grib_accessor* a,const char* comment) { - grib_dumper_grib_encode_C *self = (grib_dumper_grib_encode_C*)d; - char value[1024]; size_t size = sizeof(value); - int err = grib_unpack_string(a,value,&size); + grib_dumper_grib_encode_C *self = (grib_dumper_grib_encode_C*)d; + char value[1024]; size_t size = sizeof(value); + int err = grib_unpack_string(a,value,&size); - if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) - return; + if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) + return; - if(a->length == 0) - return; + if(a->length == 0) + return; #if 1 - if(comment) fprintf(self->dumper.out,"/* %s */\n",comment); + if(comment) fprintf(self->dumper.out,"/* %s */\n",comment); #endif - fprintf(self->dumper.out," p = \"%s\";\n",value); - fprintf(self->dumper.out," size = strlen(p);\n"); - fprintf(self->dumper.out," GRIB_CHECK(grib_set_string(h,\"%s\",p,&size),%d);\n",a->name,0); + fprintf(self->dumper.out," p = \"%s\";\n",value); + fprintf(self->dumper.out," size = strlen(p);\n"); + fprintf(self->dumper.out," GRIB_CHECK(grib_set_string(h,\"%s\",p,&size),%d);\n",a->name,0); - if(err) - fprintf(self->dumper.out," /* Error accessing %s (%s) */",a->name,grib_get_error_message(err)); + if(err) + fprintf(self->dumper.out," /* Error accessing %s (%s) */",a->name,grib_get_error_message(err)); } static void dump_bytes(grib_dumper* d,grib_accessor* a,const char* comment) { - grib_dumper_grib_encode_C *self = (grib_dumper_grib_encode_C*)d; - int err =0; - size_t size = a->length; - unsigned char* buf; + grib_dumper_grib_encode_C *self = (grib_dumper_grib_encode_C*)d; + int err =0; + size_t size = a->length; + unsigned char* buf; - if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) - return; + if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) + return; - if(size == 0) - return; + if(size == 0) + return; - buf = (unsigned char*)grib_context_malloc(d->handle->context,size); + buf = (unsigned char*)grib_context_malloc(d->handle->context,size); - if(!buf) - { - fprintf(self->dumper.out,"/* %s: cannot malloc(%ld) */\n",a->name,(long)size); - return; - } + if(!buf) + { + fprintf(self->dumper.out,"/* %s: cannot malloc(%ld) */\n",a->name,(long)size); + return; + } - err = grib_unpack_bytes(a,buf,&size); - if(err){ - grib_context_free(d->handle->context,buf); - fprintf(self->dumper.out," *** ERR=%d (%s) [grib_dumper_grib_encode_C::dump_bytes]\n}",err,grib_get_error_message(err)); - return ; - } + err = grib_unpack_bytes(a,buf,&size); + if(err){ + grib_context_free(d->handle->context,buf); + fprintf(self->dumper.out," *** ERR=%d (%s) [grib_dumper_grib_encode_C::dump_bytes]\n}",err,grib_get_error_message(err)); + return ; + } #if 0 - if(size > 100) { - more = size - 100; - size = 100; - } - - k = 0; - /* if(size > 100) size = 100; */ - while(k < size) - { - int j; - for(i = 0; i < d->depth + 3 ; i++) fprintf(self->dumper.out," "); - for(j = 0; j < 16 && k < size; j++, k++) - { - fprintf(self->dumper.out,"%02x",buf[k]); - if(k != size-1) - fprintf(self->dumper.out,", "); + if(size > 100) { + more = size - 100; + size = 100; + } + + k = 0; + /* if(size > 100) size = 100; */ + while(k < size) + { + int j; + for(i = 0; i < d->depth + 3 ; i++) fprintf(self->dumper.out," "); + for(j = 0; j < 16 && k < size; j++, k++) + { + fprintf(self->dumper.out,"%02x",buf[k]); + if(k != size-1) + fprintf(self->dumper.out,", "); + } + fprintf(self->dumper.out,"\n"); } - fprintf(self->dumper.out,"\n"); - } #endif - grib_context_free(d->handle->context,buf); + grib_context_free(d->handle->context,buf); } static void dump_values(grib_dumper* d,grib_accessor* a) { - grib_dumper_grib_encode_C *self = (grib_dumper_grib_encode_C*)d; - int k,err =0; - double* buf = NULL; - int type=0; - char stype[10]; - size_t size=0; - long count=0; + grib_dumper_grib_encode_C *self = (grib_dumper_grib_encode_C*)d; + int k,err =0; + double* buf = NULL; + int type=0; + char stype[10]; + size_t size=0; + long count=0; - stype[0]='\0'; + stype[0]='\0'; - if((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) - || ((a->flags & GRIB_ACCESSOR_FLAG_DATA) - && (d->option_flags & GRIB_DUMP_FLAG_NO_DATA) ) ) - return; + if((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) + || ((a->flags & GRIB_ACCESSOR_FLAG_DATA) + && (d->option_flags & GRIB_DUMP_FLAG_NO_DATA) ) ) + return; - grib_value_count(a,&count); - size=count; + grib_value_count(a,&count); + size=count; - if(size == 1){ - dump_double(d,a,NULL); - return ; - } + if(size == 1){ + dump_double(d,a,NULL); + return ; + } - type=grib_accessor_get_native_type(a); - switch (type) { - case GRIB_TYPE_LONG: - sprintf(stype,"%s","long"); - break; - case GRIB_TYPE_DOUBLE: - sprintf(stype,"%s","double"); - break; - default: - return; - } + type=grib_accessor_get_native_type(a); + switch (type) { + case GRIB_TYPE_LONG: + sprintf(stype,"%s","long"); + break; + case GRIB_TYPE_DOUBLE: + sprintf(stype,"%s","double"); + break; + default: + return; + } - buf = (double*)grib_context_malloc(d->handle->context,size * sizeof(double)); - if(!buf) - { - fprintf(self->dumper.out,"/* %s: cannot malloc(%ld) */\n",a->name,(long)size); - return; - } + buf = (double*)grib_context_malloc(d->handle->context,size * sizeof(double)); + if(!buf) + { + fprintf(self->dumper.out,"/* %s: cannot malloc(%ld) */\n",a->name,(long)size); + return; + } - err = grib_unpack_double(a,buf,&size); + err = grib_unpack_double(a,buf,&size); + + if(err){ + grib_context_free(d->handle->context,buf); + fprintf(self->dumper.out," /* Error accessing %s (%s) */",a->name,grib_get_error_message(err)); + return ; + } + + fprintf(self->dumper.out," size = %ld;\n",(long)size); + fprintf(self->dumper.out," v%s = (%s*)calloc(size,sizeof(%s));\n",stype,stype,stype); + fprintf(self->dumper.out," if(!v%s) {\n",stype); + fprintf(self->dumper.out," fprintf(stderr,\"failed to allocate %%d bytes\\n\",size*sizeof(%s));\n",stype); + fprintf(self->dumper.out," exit(1);\n"); + fprintf(self->dumper.out," }\n"); + + + fprintf(self->dumper.out,"\n "); + k = 0; + while(k < size) + { + fprintf(self->dumper.out," v%s[%4d] = %7g;",stype,k,buf[k]); + k++; + if(k%4 == 0) fprintf(self->dumper.out,"\n "); + + } + if(size%4) fprintf(self->dumper.out,"\n"); + fprintf(self->dumper.out,"\n"); + fprintf(self->dumper.out," GRIB_CHECK(grib_set_%s_array(h,\"%s\",v%s,size),%d);\n",stype,a->name,stype,0); + fprintf(self->dumper.out," free(v%s);\n",stype); - if(err){ grib_context_free(d->handle->context,buf); - fprintf(self->dumper.out," /* Error accessing %s (%s) */",a->name,grib_get_error_message(err)); - return ; - } - - fprintf(self->dumper.out," size = %ld;\n",(long)size); - fprintf(self->dumper.out," v%s = (%s*)calloc(size,sizeof(%s));\n",stype,stype,stype); - fprintf(self->dumper.out," if(!v%s) {\n",stype); - fprintf(self->dumper.out," fprintf(stderr,\"failed to allocate %%d bytes\\n\",size*sizeof(%s));\n",stype); - fprintf(self->dumper.out," exit(1);\n"); - fprintf(self->dumper.out," }\n"); - - - fprintf(self->dumper.out,"\n "); - k = 0; - while(k < size) - { - fprintf(self->dumper.out," v%s[%4d] = %7g;",stype,k,buf[k]); - k++; - if(k%4 == 0) fprintf(self->dumper.out,"\n "); - - } - if(size%4) fprintf(self->dumper.out,"\n"); - fprintf(self->dumper.out,"\n"); - fprintf(self->dumper.out," GRIB_CHECK(grib_set_%s_array(h,\"%s\",v%s,size),%d);\n",stype,a->name,stype,0); - fprintf(self->dumper.out," free(v%s);\n",stype); - - grib_context_free(d->handle->context,buf); } static void dump_label(grib_dumper* d,grib_accessor* a,const char* comment) { - grib_dumper_grib_encode_C *self = (grib_dumper_grib_encode_C*)d; - fprintf(self->dumper.out,"\n /* %s */\n\n",a->name); + grib_dumper_grib_encode_C *self = (grib_dumper_grib_encode_C*)d; + fprintf(self->dumper.out,"\n /* %s */\n\n",a->name); } static void dump_section(grib_dumper* d,grib_accessor* a,grib_block_of_accessors* block) { - /*grib_dumper_grib_encode_C *self = (grib_dumper_grib_encode_C*)d;*/ - grib_dump_accessors_block(d,block); + /*grib_dumper_grib_encode_C *self = (grib_dumper_grib_encode_C*)d;*/ + grib_dump_accessors_block(d,block); } static void header(grib_dumper* d,grib_handle* h) { - long edition=0; - int ret=0; - grib_dumper_grib_encode_C *self = (grib_dumper_grib_encode_C*)d; + long edition=0; + int ret=0; + grib_dumper_grib_encode_C *self = (grib_dumper_grib_encode_C*)d; ret=grib_get_long(h,"editionNumber",&edition); - if (ret != GRIB_SUCCESS) { - grib_context_log(h->context,GRIB_LOG_ERROR,"Unable to get edition number."); - Assert(0); - } + if (ret != GRIB_SUCCESS) { + grib_context_log(h->context,GRIB_LOG_ERROR,"Unable to get edition number."); + Assert(0); + } - fprintf(self->dumper.out, - "#include \n" - "\n" - "/* This code was generated automatically */\n" - "\n"); + fprintf(self->dumper.out, + "#include \n" + "\n" + "/* This code was generated automatically */\n" + "\n"); - fprintf(self->dumper.out, - "\n" - "int main(int argc,const char** argv)\n" - "{\n" - " grib_handle *h = NULL;\n" - " size_t size = 0;\n" - " double* vdouble = NULL;\n" - " long* vlong = NULL;\n" - " FILE* f = NULL;\n" - " const char* p = NULL;\n" - " const void* buffer = NULL;\n" - "\n" - " if(argc != 2) {\n" - " fprintf(stderr,\"usage: %%s out\\n\",argv[0]);\n" - " exit(1);\n" - " }\n" - "\n" - " h = grib_handle_new_from_samples(NULL,\"GRIB%ld\");\n" - " if(!h) {\n" - " fprintf(stderr,\"Cannot create grib handle\\n\");\n" - " exit(1);\n" - " }\n" - "\n",(long)edition + fprintf(self->dumper.out, + "\n" + "int main(int argc,const char** argv)\n" + "{\n" + " grib_handle *h = NULL;\n" + " size_t size = 0;\n" + " double* vdouble = NULL;\n" + " long* vlong = NULL;\n" + " FILE* f = NULL;\n" + " const char* p = NULL;\n" + " const void* buffer = NULL;\n" + "\n" + " if(argc != 2) {\n" + " fprintf(stderr,\"usage: %%s out\\n\",argv[0]);\n" + " exit(1);\n" + " }\n" + "\n" + " h = grib_handle_new_from_samples(NULL,\"GRIB%ld\");\n" + " if(!h) {\n" + " fprintf(stderr,\"Cannot create grib handle\\n\");\n" + " exit(1);\n" + " }\n" + "\n",(long)edition ); } static void footer(grib_dumper* d,grib_handle* h) { - grib_dumper_grib_encode_C *self = (grib_dumper_grib_encode_C*)d; + grib_dumper_grib_encode_C *self = (grib_dumper_grib_encode_C*)d; - fprintf(self->dumper.out, - - "/* Save the message */\n" - "\n" - " f = fopen(argv[1],\"w\");\n" - " if(!f) {\n" - " perror(argv[1]);\n" - " exit(1);\n" - " }\n" - "\n" - " GRIB_CHECK(grib_get_message(h,&buffer,&size),0);\n" - "\n" - " if(fwrite(buffer,1,size,f) != size) {\n" - " perror(argv[1]);\n" - " exit(1);\n" - " }\n" - "\n" - " if(fclose(f)) {\n" - " perror(argv[1]);\n" - " exit(1);\n" - " }\n" - "\n" - " grib_handle_delete(h);\n" - " return 0;\n" - "}\n" + fprintf(self->dumper.out, + "/* Save the message */\n" + "\n" + " f = fopen(argv[1],\"w\");\n" + " if(!f) {\n" + " perror(argv[1]);\n" + " exit(1);\n" + " }\n" + "\n" + " GRIB_CHECK(grib_get_message(h,&buffer,&size),0);\n" + "\n" + " if(fwrite(buffer,1,size,f) != size) {\n" + " perror(argv[1]);\n" + " exit(1);\n" + " }\n" + "\n" + " if(fclose(f)) {\n" + " perror(argv[1]);\n" + " exit(1);\n" + " }\n" + "\n" + " grib_handle_delete(h);\n" + " return 0;\n" + "}\n" ); } diff --git a/src/grib_dumper_class_serialize.c b/src/grib_dumper_class_serialize.c index 85bbb706b..809d547e7 100644 --- a/src/grib_dumper_class_serialize.c +++ b/src/grib_dumper_class_serialize.c @@ -87,46 +87,46 @@ static void init_class (grib_dumper_class* c){} static int init(grib_dumper* d) { - grib_dumper_serialize *self = (grib_dumper_serialize*)d; - self->format = (char*)d->arg; - return GRIB_SUCCESS; + grib_dumper_serialize *self = (grib_dumper_serialize*)d; + self->format = (char*)d->arg; + return GRIB_SUCCESS; } -static int destroy (grib_dumper* d){ - return GRIB_SUCCESS; +static int destroy (grib_dumper* d) +{ + return GRIB_SUCCESS; } static void dump_long(grib_dumper* d,grib_accessor* a,const char* comment) { - grib_dumper_serialize *self = (grib_dumper_serialize*)d; - long value=0; size_t size = 1; - int err = grib_unpack_long(a,&value,&size); + grib_dumper_serialize *self = (grib_dumper_serialize*)d; + long value=0; size_t size = 1; + int err = grib_unpack_long(a,&value,&size); - if( (a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0 ) - return; + if( (a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0 ) + return; - if( (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && - (d->option_flags & GRIB_DUMP_FLAG_READ_ONLY) == 0 && - (strcmp(a->cclass->name,"lookup") != 0) ) - return; + if( (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && + (d->option_flags & GRIB_DUMP_FLAG_READ_ONLY) == 0 && + (strcmp(a->cclass->name,"lookup") != 0) ) + return; - if( ((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && (value == GRIB_MISSING_LONG)) - fprintf(self->dumper.out,"%s = MISSING", a->name); - else - fprintf(self->dumper.out,"%s = %ld", a->name,value); + if( ((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && (value == GRIB_MISSING_LONG)) + fprintf(self->dumper.out,"%s = MISSING", a->name); + else + fprintf(self->dumper.out,"%s = %ld", a->name,value); - if ( ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) && - (strcmp(a->cclass->name,"lookup") != 0) ) - fprintf(self->dumper.out," (read_only)"); + if ( ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) && + (strcmp(a->cclass->name,"lookup") != 0) ) + fprintf(self->dumper.out," (read_only)"); #if 0 - if(comment) fprintf(self->dumper.out," [%s]",comment); + if(comment) fprintf(self->dumper.out," [%s]",comment); #endif - if(err) - fprintf(self->dumper.out," *** ERR=%d (%s) [grib_dumper_serialize::dump_long]",err,grib_get_error_message(err)); - - fprintf(self->dumper.out,"\n"); + if(err) + fprintf(self->dumper.out," *** ERR=%d (%s) [grib_dumper_serialize::dump_long]",err,grib_get_error_message(err)); + fprintf(self->dumper.out,"\n"); } #if 0 @@ -135,299 +135,292 @@ static int test_bit(long a, long b) {return a&(1<flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0 ) - return; + if( (a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0 ) + return; - if( (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && - (d->option_flags & GRIB_DUMP_FLAG_READ_ONLY) == 0) - return; + if( (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && + (d->option_flags & GRIB_DUMP_FLAG_READ_ONLY) == 0) + return; - fprintf(self->dumper.out,"%s = %ld ", a->name,value); + fprintf(self->dumper.out,"%s = %ld ", a->name,value); #if 0 - fprintf(self->dumper.out,"["); - for(i=0;i<(a->length*8);i++) { - if(test_bit(value,a->length*8-i-1)) - fprintf(self->dumper.out,"1"); + fprintf(self->dumper.out,"["); + for(i=0;i<(a->length*8);i++) { + if(test_bit(value,a->length*8-i-1)) + fprintf(self->dumper.out,"1"); + else + fprintf(self->dumper.out,"0"); + } + + if(comment) + fprintf(self->dumper.out,":%s]",comment); else - fprintf(self->dumper.out,"0"); - } - - if(comment) - fprintf(self->dumper.out,":%s]",comment); - else - fprintf(self->dumper.out,"]"); + fprintf(self->dumper.out,"]"); #endif - if(err) - fprintf(self->dumper.out," *** ERR=%d (%s)",err,grib_get_error_message(err)); - - fprintf(self->dumper.out,"\n"); + if(err) + fprintf(self->dumper.out," *** ERR=%d (%s)",err,grib_get_error_message(err)); + fprintf(self->dumper.out,"\n"); } static void dump_double(grib_dumper* d,grib_accessor* a,const char* comment) { - grib_dumper_serialize *self = (grib_dumper_serialize*)d; - double value; size_t size = 1; - int err = grib_unpack_double(a,&value,&size); + grib_dumper_serialize *self = (grib_dumper_serialize*)d; + double value; size_t size = 1; + int err = grib_unpack_double(a,&value,&size); - if( (a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0 ) - return; + if( (a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0 ) + return; - if( (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && - (d->option_flags & GRIB_DUMP_FLAG_READ_ONLY) == 0) - return; + if( (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && + (d->option_flags & GRIB_DUMP_FLAG_READ_ONLY) == 0) + return; + if( ((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && (value == GRIB_MISSING_DOUBLE)) + fprintf(self->dumper.out,"%s = MISSING", a->name); + else + fprintf(self->dumper.out,"%s = %g",a->name,value); - if( ((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && (value == GRIB_MISSING_DOUBLE)) - fprintf(self->dumper.out,"%s = MISSING", a->name); - else - fprintf(self->dumper.out,"%s = %g",a->name,value); - - if ( (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 ) fprintf(self->dumper.out," (read_only)"); + if ( (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 ) fprintf(self->dumper.out," (read_only)"); #if 0 - if(comment) fprintf(self->dumper.out," [%s]",comment); + if(comment) fprintf(self->dumper.out," [%s]",comment); #endif - if(err) - fprintf(self->dumper.out," *** ERR=%d (%s) [grib_dumper_serialize::dump_double]",err,grib_get_error_message(err)); - fprintf(self->dumper.out,"\n"); - + if(err) + fprintf(self->dumper.out," *** ERR=%d (%s) [grib_dumper_serialize::dump_double]",err,grib_get_error_message(err)); + fprintf(self->dumper.out,"\n"); } static void dump_string(grib_dumper* d,grib_accessor* a,const char* comment) { - grib_dumper_serialize *self = (grib_dumper_serialize*)d; - char value[1024]={0,}; size_t size = sizeof(value); - int err = grib_unpack_string(a,value,&size); - int i; + grib_dumper_serialize *self = (grib_dumper_serialize*)d; + char value[1024]={0,}; size_t size = sizeof(value); + int err = grib_unpack_string(a,value,&size); + int i; - char *p = value; + char *p = value; - if( (a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0 ) - return; + if( (a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0 ) + return; - if( (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && - (d->option_flags & GRIB_DUMP_FLAG_READ_ONLY) == 0) - return; + if( (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && + (d->option_flags & GRIB_DUMP_FLAG_READ_ONLY) == 0) + return; - while(*p) { if(!isprint(*p)) *p = '.'; p++; } + while(*p) { if(!isprint(*p)) *p = '.'; p++; } - for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," "); + for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," "); - - - fprintf(self->dumper.out,"%s = %s", a->name,value); - if ( (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 ) fprintf(self->dumper.out," (read_only)"); + fprintf(self->dumper.out,"%s = %s", a->name,value); + if ( (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 ) fprintf(self->dumper.out," (read_only)"); #if 0 - if(comment) fprintf(self->dumper.out," [%s]",comment); + if(comment) fprintf(self->dumper.out," [%s]",comment); #endif - if(err) - fprintf(self->dumper.out," *** ERR=%d (%s) [grib_dumper_serialize::dump_string]",err,grib_get_error_message(err)); - fprintf(self->dumper.out,"\n"); + if(err) + fprintf(self->dumper.out," *** ERR=%d (%s) [grib_dumper_serialize::dump_string]",err,grib_get_error_message(err)); + fprintf(self->dumper.out,"\n"); } static void dump_bytes(grib_dumper* d,grib_accessor* a,const char* comment) { - grib_dumper_serialize *self = (grib_dumper_serialize*)d; - int i,k,err =0; - int more = 0; - size_t size = a->length; - unsigned char* buf = (unsigned char*)grib_context_malloc(d->handle->context,size); + grib_dumper_serialize *self = (grib_dumper_serialize*)d; + int i,k,err =0; + int more = 0; + size_t size = a->length; + unsigned char* buf = (unsigned char*)grib_context_malloc(d->handle->context,size); - if( (a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0 ) - return; + if( (a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0 ) + return; - if( (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && - (d->option_flags & GRIB_DUMP_FLAG_READ_ONLY) == 0) - return; + if( (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && + (d->option_flags & GRIB_DUMP_FLAG_READ_ONLY) == 0) + return; - for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," "); - fprintf(self->dumper.out,"%s = (%ld) {", a->name,a->length); + for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," "); + fprintf(self->dumper.out,"%s = (%ld) {", a->name,a->length); - if(!buf) - { - if(size == 0) - fprintf(self->dumper.out,"}\n"); - else - fprintf(self->dumper.out," *** ERR cannot malloc(%ld) }\n",(long)size); - return; - } - - fprintf(self->dumper.out,"\n"); - - err = grib_unpack_bytes(a,buf,&size); - if(err){ - grib_context_free(d->handle->context,buf); - fprintf(self->dumper.out," *** ERR=%d (%s) [grib_dumper_serialize::dump_bytes]\n}",err,grib_get_error_message(err)); - return ; - } - - if(size > 100) { - more = size - 100; - size = 100; - } - - k = 0; - /* if(size > 100) size = 100; */ - while(k < size) - { - int j; - for(i = 0; i < d->depth + 3 ; i++) fprintf(self->dumper.out," "); - for(j = 0; j < 16 && k < size; j++, k++) + if(!buf) { - fprintf(self->dumper.out,"%02x",buf[k]); - if(k != size-1) - fprintf(self->dumper.out,", "); + if(size == 0) + fprintf(self->dumper.out,"}\n"); + else + fprintf(self->dumper.out," *** ERR cannot malloc(%ld) }\n",(long)size); + return; } + fprintf(self->dumper.out,"\n"); - } - if(more) - { - for(i = 0; i < d->depth + 3 ; i++) fprintf(self->dumper.out," "); - fprintf(self->dumper.out,"... %d more values\n",more); - } + err = grib_unpack_bytes(a,buf,&size); + if(err){ + grib_context_free(d->handle->context,buf); + fprintf(self->dumper.out," *** ERR=%d (%s) [grib_dumper_serialize::dump_bytes]\n}",err,grib_get_error_message(err)); + return ; + } - for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," "); - fprintf(self->dumper.out,"} # %s %s \n",a->creator->op, a->name); - grib_context_free(d->handle->context,buf); + if(size > 100) { + more = size - 100; + size = 100; + } + + k = 0; + /* if(size > 100) size = 100; */ + while(k < size) + { + int j; + for(i = 0; i < d->depth + 3 ; i++) fprintf(self->dumper.out," "); + for(j = 0; j < 16 && k < size; j++, k++) + { + fprintf(self->dumper.out,"%02x",buf[k]); + if(k != size-1) + fprintf(self->dumper.out,", "); + } + fprintf(self->dumper.out,"\n"); + } + + if(more) + { + for(i = 0; i < d->depth + 3 ; i++) fprintf(self->dumper.out," "); + fprintf(self->dumper.out,"... %d more values\n",more); + } + + for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," "); + fprintf(self->dumper.out,"} # %s %s \n",a->creator->op, a->name); + grib_context_free(d->handle->context,buf); } static void dump_values(grib_dumper* d,grib_accessor* a) { - grib_dumper_serialize *self = (grib_dumper_serialize*)d; - int k,err =0; - double* buf = NULL; - int last=0; - int columns=4; - char* values_format=NULL; - char* default_format="%.16e"; - char* columns_str=NULL; - size_t len=0; - char* pc=NULL; - char* pcf=NULL; - size_t size=0; - long count=0; - values_format=default_format; - - if((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY)) - return; - - grib_value_count(a,&count); - size=count; - - if (self->format) { - if (self->format[0]=='\"') values_format=self->format+1; - else values_format=self->format; - last=strlen(values_format)-1; - if (values_format[last]=='\"') values_format[last]='\0'; - } - - - pc = values_format; - pcf = values_format; - while( *pc!='\0' && *pc != '%') pc++; - if (strlen(pc) > 1 ) { - values_format=pc; - len=pc-pcf; - } else { + grib_dumper_serialize *self = (grib_dumper_serialize*)d; + int k,err =0; + double* buf = NULL; + int last=0; + int columns=4; + char* values_format=NULL; + char* default_format="%.16e"; + char* columns_str=NULL; + size_t len=0; + char* pc=NULL; + char* pcf=NULL; + size_t size=0; + long count=0; values_format=default_format; - len=0; - } - if (len>0) { - columns_str=(char*)malloc((len+1)*sizeof(char)); - Assert(columns_str); - columns_str=(char*)memcpy(columns_str,pcf,len); - columns_str[len]='\0'; - columns=atoi(columns_str); - free(columns_str); - } + if((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY)) + return; - if(size == 1){ - dump_double(d,a,NULL); - return ; - } + grib_value_count(a,&count); + size=count; - if ((d->option_flags & GRIB_DUMP_FLAG_VALUES) == 0 ) return; - - buf = (double*)grib_context_malloc(d->handle->context,size * sizeof(double)); - - fprintf(self->dumper.out,"%s (%ld) {",a->name,(long)size); - - if(!buf) - { - if(size == 0) - fprintf(self->dumper.out,"}\n"); - else - fprintf(self->dumper.out," *** ERR cannot malloc(%ld) }\n",(long)size); - return; - } - - fprintf(self->dumper.out,"\n"); - - err = grib_unpack_double(a,buf,&size); - - if(err){ - grib_context_free(d->handle->context,buf); - fprintf(self->dumper.out," *** ERR=%d (%s) [grib_dumper_serialize::dump_values]\n}",err,grib_get_error_message(err)); - return ; - } - - k = 0; - while(k < size) - { - int j; - for(j = 0; j < columns && k < size; j++, k++) - { - fprintf(self->dumper.out,values_format,buf[k]); - if(k != size-1) - fprintf(self->dumper.out,", "); + if (self->format) { + if (self->format[0]=='\"') values_format=self->format+1; + else values_format=self->format; + last=strlen(values_format)-1; + if (values_format[last]=='\"') values_format[last]='\0'; } + + pc = values_format; + pcf = values_format; + while( *pc!='\0' && *pc != '%') pc++; + if (strlen(pc) > 1 ) { + values_format=pc; + len=pc-pcf; + } else { + values_format=default_format; + len=0; + } + + if (len>0) { + columns_str=(char*)malloc((len+1)*sizeof(char)); + Assert(columns_str); + columns_str=(char*)memcpy(columns_str,pcf,len); + columns_str[len]='\0'; + columns=atoi(columns_str); + free(columns_str); + } + + if(size == 1){ + dump_double(d,a,NULL); + return ; + } + + if ((d->option_flags & GRIB_DUMP_FLAG_VALUES) == 0 ) return; + + buf = (double*)grib_context_malloc(d->handle->context,size * sizeof(double)); + + fprintf(self->dumper.out,"%s (%ld) {",a->name,(long)size); + + if(!buf) + { + if(size == 0) + fprintf(self->dumper.out,"}\n"); + else + fprintf(self->dumper.out," *** ERR cannot malloc(%ld) }\n",(long)size); + return; + } + fprintf(self->dumper.out,"\n"); - } - fprintf(self->dumper.out,"}\n"); - grib_context_free(d->handle->context,buf); + + err = grib_unpack_double(a,buf,&size); + + if(err){ + grib_context_free(d->handle->context,buf); + fprintf(self->dumper.out," *** ERR=%d (%s) [grib_dumper_serialize::dump_values]\n}",err,grib_get_error_message(err)); + return ; + } + + k = 0; + while(k < size) + { + int j; + for(j = 0; j < columns && k < size; j++, k++) + { + fprintf(self->dumper.out,values_format,buf[k]); + if(k != size-1) + fprintf(self->dumper.out,", "); + } + fprintf(self->dumper.out,"\n"); + } + fprintf(self->dumper.out,"}\n"); + grib_context_free(d->handle->context,buf); } static void dump_label(grib_dumper* d,grib_accessor* a,const char* comment) { #if 0 - grib_dumper_serialize *self = (grib_dumper_serialize*)d; - int i; - for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," "); - fprintf(self->dumper.out,"----> %s %s %s\n",a->creator->op, a->name,comment?comment:""); + grib_dumper_serialize *self = (grib_dumper_serialize*)d; + int i; + for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," "); + fprintf(self->dumper.out,"----> %s %s %s\n",a->creator->op, a->name,comment?comment:""); #endif } static void dump_section(grib_dumper* d,grib_accessor* a,grib_block_of_accessors* block) { - const char* secstr="section"; - int len=0; - grib_dumper_serialize *self = (grib_dumper_serialize*)d; + const char* secstr="section"; + int len=0; + grib_dumper_serialize *self = (grib_dumper_serialize*)d; - len=strlen(secstr); + len=strlen(secstr); + + if(a->name[0] == '_'){ + grib_dump_accessors_block(d,block); + return; + } + + if (strncmp(secstr,a->name,len)==0) + fprintf(self->dumper.out,"#------ %s -------\n",a->name); - if(a->name[0] == '_'){ grib_dump_accessors_block(d,block); - return; - } - - if (strncmp(secstr,a->name,len)==0) - fprintf(self->dumper.out,"#------ %s -------\n",a->name); - - - grib_dump_accessors_block(d,block); #if 0 - fprintf(self->dumper.out,"<------ %s %s\n",a->creator->op, a->name); + fprintf(self->dumper.out,"<------ %s %s\n",a->creator->op, a->name); #endif } diff --git a/src/grib_expression_class_is_in_list.c b/src/grib_expression_class_is_in_list.c index 51cf8c057..0fb44b4fb 100644 --- a/src/grib_expression_class_is_in_list.c +++ b/src/grib_expression_class_is_in_list.c @@ -91,167 +91,164 @@ static void init_class(grib_expression_class* c) /* END_CLASS_IMP */ -static grib_trie* load_list(grib_context* c,grib_expression* e, int* err) { +static grib_trie* load_list(grib_context* c,grib_expression* e, int* err) +{ + grib_expression_is_in_list* self = (grib_expression_is_in_list*)e; - grib_expression_is_in_list* self = (grib_expression_is_in_list*)e; + char* filename=NULL; + char line[1024]={0,}; + grib_trie* list=NULL; + FILE* f=NULL; - char* filename=NULL; - char line[1024]={0,}; - grib_trie* list=NULL; - FILE* f=NULL; + *err=GRIB_SUCCESS; - *err=GRIB_SUCCESS; + filename=grib_context_full_defs_path(c,self->list); + if (!filename) { + grib_context_log(c,GRIB_LOG_ERROR,"unable to find def file %s",self->list); + *err=GRIB_FILE_NOT_FOUND; + return NULL; + } else { + grib_context_log(c,GRIB_LOG_DEBUG,"found def file %s",filename); + } + list=(grib_trie*)grib_trie_get(c->lists,filename); + if (list) { + grib_context_log(c,GRIB_LOG_DEBUG,"using list %s from cache",self->list); + return list; + } else { + grib_context_log(c,GRIB_LOG_DEBUG,"using list %s from file %s",self->list,filename); + } - filename=grib_context_full_defs_path(c,self->list); - if (!filename) { - grib_context_log(c,GRIB_LOG_ERROR,"unable to find def file %s",self->list); - *err=GRIB_FILE_NOT_FOUND; - return NULL; - } else { - grib_context_log(c,GRIB_LOG_DEBUG,"found def file %s",filename); - } - list=(grib_trie*)grib_trie_get(c->lists,filename); - if (list) { - grib_context_log(c,GRIB_LOG_DEBUG,"using list %s from cache",self->list); - return list; - } else { - grib_context_log(c,GRIB_LOG_DEBUG,"using list %s from file %s",self->list,filename); - } + f=codes_fopen(filename,"r"); + if (!f) {*err=GRIB_IO_PROBLEM; return NULL;} - f=codes_fopen(filename,"r"); - if (!f) {*err=GRIB_IO_PROBLEM; return NULL;} + list=grib_trie_new(c); - list=grib_trie_new(c); + while(fgets(line,sizeof(line)-1,f)) { + unsigned char* p=(unsigned char*)line; + while (*p!=0) { + if (*p<33) {*p=0; break;} + p++; + } + grib_trie_insert(list,line,line); + } - while(fgets(line,sizeof(line)-1,f)) { - unsigned char* p=(unsigned char*)line; - while (*p!=0) { - if (*p<33) {*p=0; break;} - p++; - } - grib_trie_insert(list,line,line); - } + grib_trie_insert(c->lists,filename,list); - grib_trie_insert(c->lists,filename,list); - - fclose(f); - - return list; + fclose(f); + return list; } static const char* get_name(grib_expression* g) { - grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; - return e->name; + grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; + return e->name; } static int evaluate_long(grib_expression* g,grib_handle *h,long* result) { - grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; - int err=0; - char mybuf[1024]={0,}; - size_t size=1024; + grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; + int err=0; + char mybuf[1024]={0,}; + size_t size=1024; - grib_trie* list=load_list(h->context,g,&err); + grib_trie* list=load_list(h->context,g,&err); - if((err=grib_get_string_internal(h,e->name,mybuf,&size)) != GRIB_SUCCESS) - return err; + if((err=grib_get_string_internal(h,e->name,mybuf,&size)) != GRIB_SUCCESS) + return err; - if (grib_trie_get(list,mybuf)) *result=1; - else *result=0; + if (grib_trie_get(list,mybuf)) *result=1; + else *result=0; - return err; + return err; } static int evaluate_double(grib_expression *g,grib_handle *h,double* result) { - grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; - int err=0; - char mybuf[1024]={0,}; - size_t size=1024; + grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; + int err=0; + char mybuf[1024]={0,}; + size_t size=1024; - grib_trie* list=load_list(h->context,g,&err); + grib_trie* list=load_list(h->context,g,&err); - if((err=grib_get_string_internal(h,e->name,mybuf,&size)) != GRIB_SUCCESS) - return err; + if((err=grib_get_string_internal(h,e->name,mybuf,&size)) != GRIB_SUCCESS) + return err; - if (grib_trie_get(list,mybuf)) *result=1; - else *result=0; + if (grib_trie_get(list,mybuf)) *result=1; + else *result=0; - return err; + return err; } static string evaluate_string(grib_expression* g,grib_handle* h,char* buf,size_t* size,int* err) { - grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; - char mybuf[1024]={0,}; - size_t sizebuf=1024; - long result; + grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; + char mybuf[1024]={0,}; + size_t sizebuf=1024; + long result; - grib_trie* list=load_list(h->context,g,err); + grib_trie* list=load_list(h->context,g,err); - if((*err=grib_get_string_internal(h,e->name,mybuf,&sizebuf)) != GRIB_SUCCESS) - return NULL; + if((*err=grib_get_string_internal(h,e->name,mybuf,&sizebuf)) != GRIB_SUCCESS) + return NULL; - if (grib_trie_get(list,mybuf)) result=1; - else result=0; + if (grib_trie_get(list,mybuf)) result=1; + else result=0; - sprintf(buf,"%ld",result); - *size=strlen(buf); - return buf; + sprintf(buf,"%ld",result); + *size=strlen(buf); + return buf; } static void print(grib_context* c,grib_expression* g,grib_handle* f) { - grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; - printf("access('%s",e->name); - if(f) - { - long s = 0; - grib_get_long(f,e->name,&s); - printf("=%ld",s); - } - printf("')"); + grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; + printf("access('%s",e->name); + if(f) + { + long s = 0; + grib_get_long(f,e->name,&s); + printf("=%ld",s); + } + printf("')"); } static void destroy(grib_context* c,grib_expression* g) { } +static void add_dependency(grib_expression* g, grib_accessor* observer){ + grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; + grib_accessor *observed = grib_find_accessor(grib_handle_of_accessor(observer),e->name); -static void add_dependency(grib_expression* g, grib_accessor* observer){ - grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; - grib_accessor *observed = grib_find_accessor(grib_handle_of_accessor(observer),e->name); + if(!observed) + { + /* grib_context_log(observer->context, GRIB_LOG_ERROR, */ + /* "Error in accessor_add_dependency: cannot find [%s]", e->name); */ + /* Assert(observed); */ + return; + } - if(!observed) - { - /* grib_context_log(observer->context, GRIB_LOG_ERROR, */ - /* "Error in accessor_add_dependency: cannot find [%s]", e->name); */ - /* Assert(observed); */ - return; - } - - grib_dependency_add(observer,observed); + grib_dependency_add(observer,observed); } grib_expression* new_is_in_list_expression(grib_context* c,const char* name,const char* list) { - grib_expression_is_in_list* e = (grib_expression_is_in_list*)grib_context_malloc_clear_persistent(c,sizeof(grib_expression_is_in_list)); - e->base.cclass = grib_expression_class_is_in_list; - e->name = grib_context_strdup_persistent(c,name); - e->list = grib_context_strdup_persistent(c,list); - return (grib_expression*)e; + grib_expression_is_in_list* e = (grib_expression_is_in_list*)grib_context_malloc_clear_persistent(c,sizeof(grib_expression_is_in_list)); + e->base.cclass = grib_expression_class_is_in_list; + e->name = grib_context_strdup_persistent(c,name); + e->list = grib_context_strdup_persistent(c,list); + return (grib_expression*)e; } static int native_type(grib_expression* g,grib_handle *h) { - grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; - int type = 0; - int err; - if((err=grib_get_native_type(h,e->name,&type)) != GRIB_SUCCESS) - grib_context_log(h->context, GRIB_LOG_ERROR, - "Error in native_type %s : %s", e->name,grib_get_error_message(err)); - return type; + grib_expression_is_in_list* e = (grib_expression_is_in_list*)g; + int type = 0; + int err; + if((err=grib_get_native_type(h,e->name,&type)) != GRIB_SUCCESS) + grib_context_log(h->context, GRIB_LOG_ERROR, + "Error in native_type %s : %s", e->name,grib_get_error_message(err)); + return type; } - diff --git a/src/grib_expression_class_is_integer.c b/src/grib_expression_class_is_integer.c index 6933f7365..1eed17568 100644 --- a/src/grib_expression_class_is_integer.c +++ b/src/grib_expression_class_is_integer.c @@ -94,113 +94,112 @@ static void init_class(grib_expression_class* c) static const char* get_name(grib_expression* g) { - grib_expression_is_integer* e = (grib_expression_is_integer*)g; - return e->name; + grib_expression_is_integer* e = (grib_expression_is_integer*)g; + return e->name; } static int evaluate_long(grib_expression* g,grib_handle *h,long* result) { - grib_expression_is_integer* e = (grib_expression_is_integer*)g; - int err=0; - char mybuf[1024]={0,}; - size_t size=1024; - char *p=0; - long val=0; - char* start=0; + grib_expression_is_integer* e = (grib_expression_is_integer*)g; + int err=0; + char mybuf[1024]={0,}; + size_t size=1024; + char *p=0; + long val=0; + char* start=0; - if((err=grib_get_string_internal(h,e->name,mybuf,&size)) != GRIB_SUCCESS) - return err; + if((err=grib_get_string_internal(h,e->name,mybuf,&size)) != GRIB_SUCCESS) + return err; - start=mybuf+e->start; + start=mybuf+e->start; - if (e->length > 0 ) start[e->length]=0; + if (e->length > 0 ) start[e->length]=0; - val=strtol(start,&p,10); + val=strtol(start,&p,10); - if (*p!=0) - *result=0; - else - *result=1; + if (*p!=0) + *result=0; + else + *result=1; - (void)val; - return err; + (void)val; + return err; } static int evaluate_double(grib_expression *g,grib_handle *h,double* result) { - int err=0; - long lresult=0; + int err=0; + long lresult=0; - err=evaluate_long(g,h,&lresult); - *result=lresult; - return err; + err=evaluate_long(g,h,&lresult); + *result=lresult; + return err; } static string evaluate_string(grib_expression* g,grib_handle* h,char* buf,size_t* size,int* err) { - long lresult=0; - double dresult=0.0; + long lresult=0; + double dresult=0.0; - switch (grib_expression_native_type(h, g)) { + switch (grib_expression_native_type(h, g)) { case GRIB_TYPE_LONG: - *err=evaluate_long(g,h,&lresult); - sprintf(buf,"%ld",lresult); - break; + *err=evaluate_long(g,h,&lresult); + sprintf(buf,"%ld",lresult); + break; case GRIB_TYPE_DOUBLE: - *err=evaluate_double(g,h,&dresult); - sprintf(buf,"%g",dresult); - break; - } - return buf; + *err=evaluate_double(g,h,&dresult); + sprintf(buf,"%g",dresult); + break; + } + return buf; } static void print(grib_context* c,grib_expression* g,grib_handle* f) { - grib_expression_is_integer* e = (grib_expression_is_integer*)g; - printf("access('%s",e->name); - if(f) - { - long s = 0; - grib_get_long(f,e->name,&s); - printf("=%ld",s); - } - printf("')"); + grib_expression_is_integer* e = (grib_expression_is_integer*)g; + printf("access('%s",e->name); + if(f) + { + long s = 0; + grib_get_long(f,e->name,&s); + printf("=%ld",s); + } + printf("')"); } static void destroy(grib_context* c,grib_expression* g) { - grib_expression_is_integer* e = (grib_expression_is_integer*)g; - grib_context_free_persistent(c,e->name); + grib_expression_is_integer* e = (grib_expression_is_integer*)g; + grib_context_free_persistent(c,e->name); } -static void add_dependency(grib_expression* g, grib_accessor* observer){ - grib_expression_is_integer* e = (grib_expression_is_integer*)g; - grib_accessor *observed = grib_find_accessor(grib_handle_of_accessor(observer),e->name); +static void add_dependency(grib_expression* g, grib_accessor* observer){ + grib_expression_is_integer* e = (grib_expression_is_integer*)g; + grib_accessor *observed = grib_find_accessor(grib_handle_of_accessor(observer),e->name); - if(!observed) - { - /* grib_context_log(observer->context, GRIB_LOG_ERROR, */ - /* "Error in accessor_add_dependency: cannot find [%s]", e->name); */ - /* Assert(observed); */ - return; - } + if(!observed) + { + /* grib_context_log(observer->context, GRIB_LOG_ERROR, */ + /* "Error in accessor_add_dependency: cannot find [%s]", e->name); */ + /* Assert(observed); */ + return; + } - grib_dependency_add(observer,observed); + grib_dependency_add(observer,observed); } grib_expression* new_is_integer_expression(grib_context* c,const char *name,int start,int length) { - grib_expression_is_integer* e = (grib_expression_is_integer*)grib_context_malloc_clear_persistent(c,sizeof(grib_expression_is_integer)); - e->base.cclass = grib_expression_class_is_integer; - e->name = grib_context_strdup_persistent(c,name); - e->start = start; - e->length = length; - return (grib_expression*)e; + grib_expression_is_integer* e = (grib_expression_is_integer*)grib_context_malloc_clear_persistent(c,sizeof(grib_expression_is_integer)); + e->base.cclass = grib_expression_class_is_integer; + e->name = grib_context_strdup_persistent(c,name); + e->start = start; + e->length = length; + return (grib_expression*)e; } static int native_type(grib_expression* g,grib_handle *h) { - return GRIB_TYPE_LONG; + return GRIB_TYPE_LONG; } - From 205bb2462f8d4fa1872afeb5a04422569428b6df Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Fri, 10 Jan 2020 14:06:45 +0000 Subject: [PATCH 09/17] Indentation --- src/grib_accessor_class_long.c | 22 +++++++++++----------- src/grib_accessor_class_section_length.c | 16 ++++++++-------- src/grib_accessor_class_variable.c | 18 +++++++++--------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/grib_accessor_class_long.c b/src/grib_accessor_class_long.c index 9c1684d85..2ddba18f7 100644 --- a/src/grib_accessor_class_long.c +++ b/src/grib_accessor_class_long.c @@ -186,20 +186,20 @@ static int pack_missing(grib_accessor* a) /* static int is_missing(grib_accessor* a){ - size_t one = 1; - long value = GRIB_MISSING_LONG; - long ret=0; + size_t one = 1; + long value = GRIB_MISSING_LONG; + long ret=0; - if(a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) - { - ret = grib_unpack_long(a,&value,&one); - Assert( ret == 0); - return value == GRIB_MISSING_LONG; - } + if(a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) + { + ret = grib_unpack_long(a,&value,&one); + Assert( ret == 0); + return value == GRIB_MISSING_LONG; + } - return 0; + return 0; } - */ +*/ static int unpack_double(grib_accessor* a, double* val,size_t *len) { diff --git a/src/grib_accessor_class_section_length.c b/src/grib_accessor_class_section_length.c index 291074715..f80a2f895 100644 --- a/src/grib_accessor_class_section_length.c +++ b/src/grib_accessor_class_section_length.c @@ -133,20 +133,20 @@ static void init_class(grib_accessor_class* c) static void init(grib_accessor* a, const long len , grib_arguments* arg ) { - a->parent->aclength = a; - a->length = len; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; - Assert(a->length>=0); + a->parent->aclength = a; + a->length = len; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; + Assert(a->length>=0); } static void dump(grib_accessor* a, grib_dumper* dumper) { - grib_dump_long(dumper,a,NULL); + grib_dump_long(dumper,a,NULL); } static int value_count(grib_accessor* a,long* c) { - *c=1; - return 0; + *c=1; + return 0; } diff --git a/src/grib_accessor_class_variable.c b/src/grib_accessor_class_variable.c index 2cc343faf..19bdb6ccb 100644 --- a/src/grib_accessor_class_variable.c +++ b/src/grib_accessor_class_variable.c @@ -356,16 +356,16 @@ static long byte_count(grib_accessor* a) /* NOT ANY MORE static long byte_count(grib_accessor* a) { - grib_accessor_variable *self = (grib_accessor_variable*)a; - char buf[80]={0,}; + grib_accessor_variable *self = (grib_accessor_variable*)a; + char buf[80]={0,}; - if(self->type == GRIB_TYPE_STRING) { - return strlen(self->cval) +1; - } else { - sprintf(buf,"%g",self->dval); - printf("========> \"%s\"\n",buf); - return strlen(buf)+1; - } + if(self->type == GRIB_TYPE_STRING) { + return strlen(self->cval) +1; + } else { + sprintf(buf,"%g",self->dval); + printf("========> \"%s\"\n",buf); + return strlen(buf)+1; + } } */ From 701a152575b5d3585b605e9a39a2ba9893fa4537 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Fri, 10 Jan 2020 15:40:59 +0000 Subject: [PATCH 10/17] ECC-1018: Reduced size of sample file --- samples/diag.tmpl | Bin 2423 -> 120 bytes tests/diag.sh | 23 ++++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/samples/diag.tmpl b/samples/diag.tmpl index 94b2b629d1ade8f50606e677c63e029ce93be313..e9603d191887997477a7c383d7ab6505f550fc68 100644 GIT binary patch literal 120 zcmZ?qbaZE6kYGq+WMlw=3@&~i1|S>4(_&y?0f_>65Cr1Df%8KKh6V;E-Bbp1AYd?u IOAx^T0JDPyo&W#< literal 2423 zcmYk7yN=sH3`LbklORBfG^ql&>AVXBspZkbgPrw5q%G_sRjPbKJ}sY@OH#w300U>P zE??u3G~|Bny06{uH*Y$*{(SuWsRQfk!`gN4MSa(GZ#&auxn2E_Z~yu)zrJI6!0&mt z`#U9G`WGIThusc*S;mx!OW>1pIyXI?T~CA?TdeTO8Hoa)rfcEbveRq2o&t-Gz&mV8RdS!-T7`2~kW%RSL_U|nE67o=BizQw{EbaK|X~;zR0;e-7I?u~U_Zh?O zbrxj~+?Ru_=w6so)xqu&-4^N@#*6!xGKV z%pTbNHoN&TyIE}Z#%qb3ZGqV*;zv9>G9&mJ_+fu@{b7&Oym^?OoL~1X_H}=By)S~6 z^H7>zrl#k>)7WTm~8z|Vn?fm44Ot3Mrjs=OaYsi1l8nR4Yz%BR4xE9!y% zSb3V046k|`vrJ~p=SyW?w`WB5bG0)w;VjWQoW)~&Q@?NtdRd!Jx>e@4Z8Ns*F_r;q zPTd{Jk2C4Dl((E;}4@7vZ@~bQ PlyiD2<7wvO?kBGQe1t|H diff --git a/tests/diag.sh b/tests/diag.sh index 76b06371a..41509629f 100755 --- a/tests/diag.sh +++ b/tests/diag.sh @@ -25,16 +25,14 @@ sample=$ECCODES_SAMPLES_PATH/diag.tmpl ${tools_dir}/grib_ls $sample > $REDIRECT ${tools_dir}/grib_dump $sample > $REDIRECT -# Check setting keys -# ------------------- +echo "Check setting integer keys..." +# ---------------------------------- echo 'set numberOfIntegers=3; set integerValues={55, 44, 66}; write;' | ${tools_dir}/grib_filter -o $tempOut - $sample ${tools_dir}/grib_dump -p numberOfFloats,numberOfIntegers,floatValues,integerValues $tempOut | sed 1d > $tempTxt cat > $tempRef < $tempTxt cat > $tempRef < $tempRef < $tempTxt @@ -70,6 +72,13 @@ cat > $tempRef < $tempTxt +grep -q "'E', 'C', 'M', 'W', 'F', ' '" $tempTxt + # TODO encoding of characters not fully working. We are using one-byte integers instead #echo 'set numberOfCharacters=4; set charValues={"J","u","m","p"}; write;'| ${tools_dir}/grib_filter -o $tempOut - $sample #res=`${tools_dir}/grib_dump $tempOut | grep charValues | tr -d '\n' | tr -d ' '` From 7162f9efe98893ad2a171166f1cc799122375189 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 27 Apr 2020 12:51:19 +0100 Subject: [PATCH 11/17] Update version number --- .appveyor.yml | 2 +- VERSION.cmake | 2 +- version.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 09ff2b126..6ab28a6e5 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -2,7 +2,7 @@ # general configuration # #---------------------------------# -version: 2.17.0-{build}-{branch} +version: 2.17.1-{build}-{branch} branches: only: diff --git a/VERSION.cmake b/VERSION.cmake index b4cbdd932..18c8f99ec 100644 --- a/VERSION.cmake +++ b/VERSION.cmake @@ -1 +1 @@ -set( ${PROJECT_NAME}_VERSION_STR "2.17.0" ) +set( ${PROJECT_NAME}_VERSION_STR "2.17.1" ) diff --git a/version.sh b/version.sh index aa1f5541e..0accc9930 100644 --- a/version.sh +++ b/version.sh @@ -4,7 +4,7 @@ PACKAGE_NAME='eccodes' # Package version ECCODES_MAJOR_VERSION=2 ECCODES_MINOR_VERSION=17 -ECCODES_REVISION_VERSION=0 +ECCODES_REVISION_VERSION=1 ECCODES_CURRENT=1 ECCODES_REVISION=0 From d0ae5a24393436d358eff856437067d6bcb36744 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 27 Apr 2020 13:08:24 +0100 Subject: [PATCH 12/17] ECC-1090: Create a new MARS type 'eme' for ensemble data assimilation model errors --- definitions/mars/type.table | 1 + src/grib_accessor_class_g2_mars_labeling.c | 1 + 2 files changed, 2 insertions(+) diff --git a/definitions/mars/type.table b/definitions/mars/type.table index c9dd876fa..2f28ede79 100644 --- a/definitions/mars/type.table +++ b/definitions/mars/type.table @@ -37,6 +37,7 @@ 36 pd Probability distribution 37 ci Cluster information 38 sot Shift of Tail +39 eme Ensemble data assimilation model errors 40 im Images 42 sim Simulated images 43 wem Weighted ensemble mean diff --git a/src/grib_accessor_class_g2_mars_labeling.c b/src/grib_accessor_class_g2_mars_labeling.c index d758b4d43..2fb5b9d3c 100644 --- a/src/grib_accessor_class_g2_mars_labeling.c +++ b/src/grib_accessor_class_g2_mars_labeling.c @@ -353,6 +353,7 @@ static int extra_set(grib_accessor* a, long val) case 36: /* Probability distribution (pd) */ case 37: /* Cluster information (ci) */ case 38: /* Shift of Tail (sot) */ + case 39: /* Ensemble data assimilation model errors */ case 40: /* Images (im) */ case 42: /* Simulated images (sim) */ typeOfProcessedData = 255; From 155d753efea1931d8865d846dfe6c2a97291453f Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 27 Apr 2020 13:39:42 +0100 Subject: [PATCH 13/17] ECC-1091: Change shortname of paramId 171055 to mean2t24a --- definitions/grib1/localConcepts/ecmf/cfVarName.def | 2 +- definitions/grib1/localConcepts/ecmf/shortName.def | 2 +- definitions/grib2/localConcepts/ecmf/cfVarName.def | 2 +- definitions/grib2/localConcepts/ecmf/shortName.def | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/definitions/grib1/localConcepts/ecmf/cfVarName.def b/definitions/grib1/localConcepts/ecmf/cfVarName.def index 8d7a0369b..40549c858 100644 --- a/definitions/grib1/localConcepts/ecmf/cfVarName.def +++ b/definitions/grib1/localConcepts/ecmf/cfVarName.def @@ -13910,7 +13910,7 @@ indicatorOfParameter = 54 ; } #Mean 2 metre temperature in the last 24 hours anomaly -'mn2t24a' = { +'mean2t24a' = { table2Version = 171 ; indicatorOfParameter = 55 ; } diff --git a/definitions/grib1/localConcepts/ecmf/shortName.def b/definitions/grib1/localConcepts/ecmf/shortName.def index 01113ad30..c6bbdf88d 100644 --- a/definitions/grib1/localConcepts/ecmf/shortName.def +++ b/definitions/grib1/localConcepts/ecmf/shortName.def @@ -13910,7 +13910,7 @@ indicatorOfParameter = 54 ; } #Mean 2 metre temperature in the last 24 hours anomaly -'mn2t24a' = { +'mean2t24a' = { table2Version = 171 ; indicatorOfParameter = 55 ; } diff --git a/definitions/grib2/localConcepts/ecmf/cfVarName.def b/definitions/grib2/localConcepts/ecmf/cfVarName.def index 75ca27689..5a4b2ab9b 100644 --- a/definitions/grib2/localConcepts/ecmf/cfVarName.def +++ b/definitions/grib2/localConcepts/ecmf/cfVarName.def @@ -17983,7 +17983,7 @@ parameterNumber = 54 ; } #Mean 2 metre temperature in the last 24 hours anomaly -'mn2t24a' = { +'mean2t24a' = { discipline = 192 ; parameterCategory = 171 ; parameterNumber = 55 ; diff --git a/definitions/grib2/localConcepts/ecmf/shortName.def b/definitions/grib2/localConcepts/ecmf/shortName.def index c7d270334..78b8e5e70 100644 --- a/definitions/grib2/localConcepts/ecmf/shortName.def +++ b/definitions/grib2/localConcepts/ecmf/shortName.def @@ -17983,7 +17983,7 @@ parameterNumber = 54 ; } #Mean 2 metre temperature in the last 24 hours anomaly -'mn2t24a' = { +'mean2t24a' = { discipline = 192 ; parameterCategory = 171 ; parameterNumber = 55 ; From 2fa536b111576239749ad4f89352809fa7470e26 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Tue, 23 Jun 2020 13:56:45 +0100 Subject: [PATCH 14/17] SUP-3196: tests fail when compiling eccodes with -DVECTOR --- src/grib_bits_any_endian.c | 2 +- src/grib_bits_any_endian_vector.c | 12 +++++++----- src/grib_bits_fast_big_endian.c | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/grib_bits_any_endian.c b/src/grib_bits_any_endian.c index 1591fd5d1..c614d0a80 100644 --- a/src/grib_bits_any_endian.c +++ b/src/grib_bits_any_endian.c @@ -420,7 +420,7 @@ int grib_encode_size_tb(unsigned char* p, size_t val, long* bitp, long nb) #if OMP_PACKING #include "grib_bits_any_endian_omp.c" #elif VECTOR -#include "grib_bits_any_endian_vector.c" +#include "grib_bits_any_endian_vector.c" /* Experimental */ #else #include "grib_bits_any_endian_simple.c" #endif diff --git a/src/grib_bits_any_endian_vector.c b/src/grib_bits_any_endian_vector.c index 3c3a13582..f8e29af79 100644 --- a/src/grib_bits_any_endian_vector.c +++ b/src/grib_bits_any_endian_vector.c @@ -10,7 +10,7 @@ /*************************************************************************** * Enrico Fucile - 19.06.2007 * - * * + * EXPERIMENTAL CODE - NOT FULLY TESTED * ***************************************************************************/ int grib_decode_long_array(const unsigned char* p, long* bitp, long bitsPerValue, @@ -19,7 +19,8 @@ int grib_decode_long_array(const unsigned char* p, long* bitp, long bitsPerValue long i = 0; unsigned long lvalue = 0; - if (bitsPerValue % 8) { + /* SUP-3196: Thanks to Daniel Tameling */ + if (bitsPerValue % 8 || (*bitp & 7)) { int j = 0; for (i = 0; i < n_vals; i++) { lvalue = 0; @@ -54,7 +55,6 @@ int grib_decode_long_array(const unsigned char* p, long* bitp, long bitsPerValue return 0; } - int grib_decode_double_array(const unsigned char* p, long* bitp, long bitsPerValue, double reference_value, double s, double d, size_t n_vals, double* val) @@ -96,12 +96,14 @@ int grib_decode_double_array(const unsigned char* p, long* bitp, long bitsPerVal return 0; } -int grib_decode_double_array_complex(const unsigned char* p, long* bitp, long nbits, double reference_value, double s, double* d, size_t size, double* val) +int grib_decode_double_array_complex(const unsigned char* p, long* bitp, long nbits, double reference_value, + double s, double* d, size_t size, double* val) { return GRIB_NOT_IMPLEMENTED; } -int grib_encode_double_array(size_t n_vals, const double* val, long bits_per_value, double reference_value, double d, double divisor, unsigned char* p, long* off) +int grib_encode_double_array(size_t n_vals, const double* val, long bits_per_value, double reference_value, + double d, double divisor, unsigned char* p, long* off) { size_t i = 0; unsigned long unsigned_val = 0; diff --git a/src/grib_bits_fast_big_endian.c b/src/grib_bits_fast_big_endian.c index dccd60189..0f1a14cc9 100644 --- a/src/grib_bits_fast_big_endian.c +++ b/src/grib_bits_fast_big_endian.c @@ -186,7 +186,7 @@ int grib_encode_unsigned_longb(unsigned char* p, unsigned long val, long* bitp, } #if VECTOR -#include "grib_bits_fast_big_endian_vector.c" +#include "grib_bits_fast_big_endian_vector.c" /* Experimental */ #elif OMP #include "grib_bits_fast_big_endian_omp.c" #else From efcff6bd0190cba7a6ee470b2fdf1fdd1b98ace2 Mon Sep 17 00:00:00 2001 From: Shinji Suzuki Date: Thu, 30 Jul 2020 01:44:03 +0900 Subject: [PATCH 15/17] Remove redudant conditionals and an assignment. --- src/grib_handle.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/grib_handle.c b/src/grib_handle.c index 92b82cac4..de86b0e4a 100644 --- a/src/grib_handle.c +++ b/src/grib_handle.c @@ -172,7 +172,6 @@ int grib_handle_delete(grib_handle* h) grib_context_log(ct, GRIB_LOG_DEBUG, "grib_handle_delete: deleting handle %p", h); grib_context_free(ct, h); - h = NULL; } return GRIB_SUCCESS; } @@ -1576,16 +1575,12 @@ static grib_multi_support* grib_get_multi_support(grib_context* c, FILE* f) prev = gm; gm = gm->next; } - - if (!gm) { - gm = grib_multi_support_new(c); - if (!c->multi_support) { - c->multi_support = gm; - } - else { - if (prev) - prev->next = gm; - } + gm = grib_multi_support_new(c); + if (prev==NULL) { // equivalent to 'if (!c->multi_support)' + c->multi_support = gm; + } + else { + prev->next = gm; } gm->next = 0; From 14c841b2f781f0afa7bc8df8def6c014d1ba2e18 Mon Sep 17 00:00:00 2001 From: Shinji Suzuki Date: Thu, 30 Jul 2020 02:00:21 +0900 Subject: [PATCH 16/17] Fix buggy implementation of grib_multi_support_reset(). --- src/grib_handle.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/grib_handle.c b/src/grib_handle.c index de86b0e4a..2fe180a8d 100644 --- a/src/grib_handle.c +++ b/src/grib_handle.c @@ -53,6 +53,7 @@ static int grib2_has_next_section(unsigned char* msgbegin, size_t msglen, unsign static void grib2_build_message(grib_context* context, unsigned char* sections[], size_t sections_len[], void** data, size_t* msglen); static grib_multi_support* grib_get_multi_support(grib_context* c, FILE* f); static grib_multi_support* grib_multi_support_new(grib_context* c); +static void grib_multi_support_clear(grib_context* c, grib_multi_support* gm); static grib_handle* grib_handle_new_multi(grib_context* c, unsigned char** idata, size_t* buflen, int* error); /* Note: A fast cut-down version of strcmp which does NOT return -1 */ @@ -1600,23 +1601,14 @@ static grib_multi_support* grib_get_multi_support(grib_context* c, FILE* f) void grib_multi_support_reset(grib_context* c) { grib_multi_support* gm = c->multi_support; - grib_multi_support* next = NULL; - int i = 0; - while (next) { - next = gm->next; - if (gm->file) - fclose(gm->file); - if (gm->message) - grib_context_free(c, gm->message); - gm->message = NULL; - for (i = 0; i < 8; i++) - gm->sections[i] = 0; - if (gm->bitmap_section) - grib_context_free(c, gm->bitmap_section); - gm->bitmap_section = NULL; - grib_context_free(c, gm); - gm = NULL; + grib_multi_support* gm_next = NULL; + while (gm) { + gm_next = gm->next; + grib_multi_support_clear(c, gm); + grib_context_free(c, gm); + gm = gm_next; } + c->multi_support = NULL; } static grib_multi_support* grib_multi_support_new(grib_context* c) @@ -1638,3 +1630,17 @@ static grib_multi_support* grib_multi_support_new(grib_context* c) return gm; } + +static void grib_multi_support_clear(grib_context* c, grib_multi_support *gm) +{ + /* Don't close gm->file. It is supposed to be owned by the client. */ + /* At lease that is the case for cfgrib. */ + if (gm->message) { + grib_context_free(c, gm->message); + gm->message = NULL; + } + if (gm->bitmap_section) { + grib_context_free(c, gm->bitmap_section); + gm->bitmap_section = NULL; + } +} From b5eb81689b4b2465b206bb4ab2cb1a6e9f7cc624 Mon Sep 17 00:00:00 2001 From: Shinji Suzuki Date: Sat, 14 Nov 2020 21:02:09 +0900 Subject: [PATCH 17/17] Reverted non-essential local changes. Replaced a tab with spaces. --- src/grib_bits_any_endian.c | 2 +- src/grib_bits_any_endian_vector.c | 7 +++---- src/grib_handle.c | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/grib_bits_any_endian.c b/src/grib_bits_any_endian.c index c614d0a80..1591fd5d1 100644 --- a/src/grib_bits_any_endian.c +++ b/src/grib_bits_any_endian.c @@ -420,7 +420,7 @@ int grib_encode_size_tb(unsigned char* p, size_t val, long* bitp, long nb) #if OMP_PACKING #include "grib_bits_any_endian_omp.c" #elif VECTOR -#include "grib_bits_any_endian_vector.c" /* Experimental */ +#include "grib_bits_any_endian_vector.c" #else #include "grib_bits_any_endian_simple.c" #endif diff --git a/src/grib_bits_any_endian_vector.c b/src/grib_bits_any_endian_vector.c index 4fe7ce910..c712d98b3 100644 --- a/src/grib_bits_any_endian_vector.c +++ b/src/grib_bits_any_endian_vector.c @@ -53,6 +53,7 @@ int grib_decode_long_array(const unsigned char* p, long* bitp, long bitsPerValue return 0; } + int grib_decode_double_array(const unsigned char* p, long* bitp, long bitsPerValue, double reference_value, double s, double d, size_t n_vals, double* val) @@ -94,14 +95,12 @@ int grib_decode_double_array(const unsigned char* p, long* bitp, long bitsPerVal return 0; } -int grib_decode_double_array_complex(const unsigned char* p, long* bitp, long nbits, double reference_value, - double s, double* d, size_t size, double* val) +int grib_decode_double_array_complex(const unsigned char* p, long* bitp, long nbits, double reference_value, double s, double* d, size_t size, double* val) { return GRIB_NOT_IMPLEMENTED; } -int grib_encode_double_array(size_t n_vals, const double* val, long bits_per_value, double reference_value, - double d, double divisor, unsigned char* p, long* off) +int grib_encode_double_array(size_t n_vals, const double* val, long bits_per_value, double reference_value, double d, double divisor, unsigned char* p, long* off) { size_t i = 0; unsigned long unsigned_val = 0; diff --git a/src/grib_handle.c b/src/grib_handle.c index 8bda087b0..3b4321103 100644 --- a/src/grib_handle.c +++ b/src/grib_handle.c @@ -1612,7 +1612,7 @@ void grib_multi_support_reset(grib_context* c) while (gm) { gm_next = gm->next; grib_multi_support_clear(c, gm); - grib_context_free(c, gm); + grib_context_free(c, gm); gm = gm_next; } c->multi_support = NULL;