From 7eb6c3439b338d55abea2e5d65f2f5558dfc7673 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 21 Nov 2019 14:51:37 +0000 Subject: [PATCH 01/11] 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/11] 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,10 +577,49 @@ 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: + break; + default: + printf("%s, field %d [%s]: invalid pressure level %ld\n",file,field,param,level); + error++; + 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); From 3ae397bc8197709a66076e49d6a05aa0585325ad Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Fri, 22 Nov 2019 10:49:12 +0000 Subject: [PATCH 03/11] 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/11] 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/11] 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/11] 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/11] 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/11] Indentation and formatting --- src/grib_accessor_class_box.c | 29 +- src/grib_accessor_class_constant.c | 29 +- ...grib_accessor_class_data_complex_packing.c | 9 +- src/grib_accessor_class_double.c | 21 +- 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 | 129 ++--- src/grib_accessor_class_message.c | 52 +- 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 | 59 +- 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 | 535 +++++++++--------- src/grib_dumper_class_serialize.c | 477 ++++++++-------- src/grib_expression_class_is_in_list.c | 227 ++++---- src/grib_expression_class_is_integer.c | 131 +++-- 23 files changed, 994 insertions(+), 1035 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_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; +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 ) +static void init(grib_accessor* a, const long len , grib_arguments* arg) { - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + 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; + size_t one = 1; + double value = GRIB_MISSING_DOUBLE; + + 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; - } - - *len = l; - strcpy(val,tmp); - + 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; - - /*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); - - - *val = v->v[self->index]; - - return GRIB_SUCCESS; -} +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_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); + /*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); - *val = (double)v->v[self->index]; + *val = v->v[self->index]; - return err; + return GRIB_SUCCESS; } -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 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; - v->pack_index=self->index; + err=unpack_long(a,&lval,len); - err=grib_pack_long(va,val,len); + *val = (double)v->v[self->index]; - return err; + return err; } -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) +{ + 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; + v->pack_index=self->index; + + err=grib_pack_long(va,val,len); + + return err; +} + +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; - - 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; + 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; + } + + 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) { - - 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); +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); - 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 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 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) +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; + 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); } - 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; - - 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); + grib_accessor_padtoeven* self = (grib_accessor_padtoeven*)a; - 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; - - case ':': - if(cr) - fprintf(f,"\n See "); - else - fprintf(f,". See "); - break; - - default: - fputc(*p,f); - break; + switch(*p) + { + case ';': + fprintf(f,"\n "); + cr = 1; + break; + + case ':': + if(cr) + fprintf(f,"\n See "); + else + fprintf(f,". See "); + 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"); - else - strcat(buf,"0"); - } + 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); - } + if(comment) { + strcat(buf,";"); + strcat(buf,comment); + } - pcomment(self->dumper.out,value,buf); + 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); + 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++) + if(size > 100) { + more = size - 100; + size = 100; + } + + k = 0; + /* if(size > 100) size = 100; */ + while(k < size) { - fprintf(self->dumper.out,"%02x",buf[k]); - if(k != size-1) - fprintf(self->dumper.out,", "); + 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; - - 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; - - grib_value_count(a,&count); - size=count; - - 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; - } - - 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); - - if(err){ + 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'; + + 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; + + 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; + } + + 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); + + 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); - 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); - } - - 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 + 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, + "\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; - - 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" + 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" ); } 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"); - else - fprintf(self->dumper.out,"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"); + else + fprintf(self->dumper.out,"0"); + } - if(comment) - fprintf(self->dumper.out,":%s]",comment); - else - fprintf(self->dumper.out,"]"); + if(comment) + fprintf(self->dumper.out,":%s]",comment); + else + 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); - - if( (a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0 ) - return; + 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_READ_ONLY) != 0 && - (d->option_flags & GRIB_DUMP_FLAG_READ_ONLY) == 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_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); - - 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; - - 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; - } + 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); - fprintf(self->dumper.out,"\n"); + if( (a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0 ) + 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_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( (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); + + 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 ; + } + + 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"); + } - 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(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; + 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'; + } - buf = (double*)grib_context_malloc(d->handle->context,size * sizeof(double)); + 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; + } - fprintf(self->dumper.out,"%s (%ld) {",a->name,(long)size); + 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(!buf) - { - if(size == 0) - fprintf(self->dumper.out,"}\n"); - else - fprintf(self->dumper.out," *** ERR cannot malloc(%ld) }\n",(long)size); - return; - } + if(size == 1){ + dump_double(d,a,NULL); + return ; + } - fprintf(self->dumper.out,"\n"); + if ((d->option_flags & GRIB_DUMP_FLAG_VALUES) == 0 ) return; - err = grib_unpack_double(a,buf,&size); + buf = (double*)grib_context_malloc(d->handle->context,size * sizeof(double)); - 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,"%s (%ld) {",a->name,(long)size); + + if(!buf) { - fprintf(self->dumper.out,values_format,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"); - } - 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; - - len=strlen(secstr); + const char* secstr="section"; + int len=0; + grib_dumper_serialize *self = (grib_dumper_serialize*)d; - if(a->name[0] == '_'){ - grib_dump_accessors_block(d,block); - return; - } + len=strlen(secstr); - 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); + 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) { - - 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; - - *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); - } - - f=codes_fopen(filename,"r"); - if (!f) {*err=GRIB_IO_PROBLEM; return NULL;} - - 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); - } - - grib_trie_insert(c->lists,filename,list); - - fclose(f); - - return list; - +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; + + char* filename=NULL; + char line[1024]={0,}; + grib_trie* list=NULL; + FILE* f=NULL; + + *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); + } + + f=codes_fopen(filename,"r"); + if (!f) {*err=GRIB_IO_PROBLEM; return NULL;} + + 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); + } + + grib_trie_insert(c->lists,filename,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/11] Indentation --- src/grib_accessor_class_long.c | 26 ++++++++++++------------ src/grib_accessor_class_section_length.c | 16 +++++++-------- src/grib_accessor_class_variable.c | 20 +++++++++--------- 3 files changed, 31 insertions(+), 31 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; - - 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; + 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; + } + + 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,}; - - 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; - } + 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; + } } */ From 701a152575b5d3585b605e9a39a2ba9893fa4537 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Fri, 10 Jan 2020 15:40:59 +0000 Subject: [PATCH 10/11] 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 a9f9aa26cd37edecdffa14cb0b970b61f32a5898 Mon Sep 17 00:00:00 2001 From: Teresa Noviello Date: Wed, 8 Jul 2020 22:38:28 +0200 Subject: [PATCH 11/11] ecCodesMIA B6 version - Reduction of mallocs: introducing static memory area in dynamic arrays. File src/ChangesB6.txt contains version description. File ctest3.out contains automated tests complete report. --- ctest3.out | 557 ++++++++++++++++++ src/ChangesB6.txt | 157 +++++ src/action_class_set_darray.c | 3 +- src/action_class_set_iarray.c | 5 +- src/action_class_set_sarray.c | 3 +- src/action_class_transient_darray.c | 3 +- src/bufr_util.c | 4 +- src/grib_accessor_class_bufr_data_array.c | 274 ++++++--- src/grib_accessor_class_bufr_data_element.c | 167 ++++-- ...accessor_class_bufr_extract_area_subsets.c | 1 + ...ssor_class_bufr_extract_datetime_subsets.c | 1 + src/grib_accessor_class_bufr_string_values.c | 6 +- src/grib_accessor_class_concept.c | 16 +- src/grib_accessor_class_hash_array.c | 3 +- src/grib_accessor_class_long_vector.c | 1 + src/grib_accessor_class_transient_darray.c | 7 +- src/grib_api.h | 2 + src/grib_api_internal.h | 50 +- src/grib_api_prototypes.h | 65 +- src/grib_bufr_descriptors_array.c | 6 +- src/grib_darray.c | 302 +++++++--- src/grib_iarray.c | 370 ++++++------ src/grib_oarray.c | 248 +++++--- src/grib_sarray.c | 289 +++++++-- src/grib_trie_with_rank.c | 3 +- src/grib_value.c | 32 +- src/grib_vdarray.c | 272 ++++++--- src/grib_viarray.c | 222 +++++-- src/grib_vsarray.c | 263 ++++++--- src/makeyacc | 31 +- tests/bufr_dump_samples.sh | 4 +- tools/bufr_compare.c | 5 +- 32 files changed, 2542 insertions(+), 830 deletions(-) create mode 100644 ctest3.out create mode 100644 src/ChangesB6.txt diff --git a/ctest3.out b/ctest3.out new file mode 100644 index 000000000..1781ed535 --- /dev/null +++ b/ctest3.out @@ -0,0 +1,557 @@ +Test project /home/eccuser/eccodes-2.17.0-BUILD.B6 + Start 1: eccodes_t_definitions + 1/266 Test #1: eccodes_t_definitions ....................... Passed 6.72 sec + Start 2: eccodes_t_grib_calendar + 2/266 Test #2: eccodes_t_grib_calendar ..................... Passed 0.58 sec + Start 3: eccodes_t_unit_tests + 3/266 Test #3: eccodes_t_unit_tests ........................ Passed 0.30 sec + Start 4: eccodes_t_md5 +Process not started + /home/eccuser/eccodes-2.17.0-Source/tests/md5.sh +[permission denied] + 4/266 Test #4: eccodes_t_md5 ...............................***Not Run 0.00 sec + Start 5: eccodes_t_grib_uerra + 5/266 Test #5: eccodes_t_grib_uerra ........................ Passed 1.29 sec + Start 6: eccodes_t_grib_2nd_order_numValues + 6/266 Test #6: eccodes_t_grib_2nd_order_numValues .......... Passed 0.14 sec + Start 7: eccodes_t_grib_ecc-136 + 7/266 Test #7: eccodes_t_grib_ecc-136 ...................... Passed 0.26 sec + Start 8: eccodes_t_grib_ecc-967 + 8/266 Test #8: eccodes_t_grib_ecc-967 ...................... Passed 0.09 sec + Start 9: eccodes_t_grib_ecc-1065 + 9/266 Test #9: eccodes_t_grib_ecc-1065 ..................... Passed 0.05 sec + Start 10: eccodes_t_julian + 10/266 Test #10: eccodes_t_julian ............................ Passed 1.61 sec + Start 11: eccodes_t_bufr_dump_samples + 11/266 Test #11: eccodes_t_bufr_dump_samples ................. Passed 0.29 sec + Start 12: eccodes_t_bufr_json_samples + 12/266 Test #12: eccodes_t_bufr_json_samples ................. Passed 0.25 sec + Start 13: eccodes_t_bufr_ecc-359 + 13/266 Test #13: eccodes_t_bufr_ecc-359 ...................... Passed 0.05 sec + Start 14: eccodes_t_bufr_ecc-517 + 14/266 Test #14: eccodes_t_bufr_ecc-517 ...................... Passed 0.11 sec + Start 15: eccodes_t_bufr_rdbSubTypes + 15/266 Test #15: eccodes_t_bufr_rdbSubTypes .................. Passed 0.10 sec + Start 16: eccodes_t_grib_efas + 16/266 Test #16: eccodes_t_grib_efas ......................... Passed 1.34 sec + Start 17: eccodes_t_grib_sh_imag + 17/266 Test #17: eccodes_t_grib_sh_imag ...................... Passed 0.03 sec + Start 18: eccodes_t_diag + 18/266 Test #18: eccodes_t_diag .............................. Passed 0.10 sec + Start 19: eccodes_t_grib_lambert_conformal + 19/266 Test #19: eccodes_t_grib_lambert_conformal ............ Passed 0.66 sec + Start 262: eccodes_download_gribs + 20/266 Test #262: eccodes_download_gribs ...................... Passed 3.98 sec + Start 263: eccodes_download_tigge_gribs + 21/266 Test #263: eccodes_download_tigge_gribs ................ Passed 9.85 sec + Start 264: eccodes_download_bufrs + 22/266 Test #264: eccodes_download_bufrs ...................... Passed 23.06 sec + Start 265: eccodes_download_metars + 23/266 Test #265: eccodes_download_metars ..................... Passed 0.13 sec + Start 266: eccodes_download_gts + 24/266 Test #266: eccodes_download_gts ........................ Passed 0.09 sec + Start 20: eccodes_t_grib_data_quality_checks + 25/266 Test #20: eccodes_t_grib_data_quality_checks .......... Passed 2.64 sec + Start 21: eccodes_t_bpv_limit + 26/266 Test #21: eccodes_t_bpv_limit ......................... Passed 0.13 sec + Start 22: eccodes_t_grib_complex + 27/266 Test #22: eccodes_t_grib_complex ...................... Passed 0.06 sec + Start 23: eccodes_t_grib_double_cmp + 28/266 Test #23: eccodes_t_grib_double_cmp ................... Passed 0.09 sec + Start 24: eccodes_t_grib_change_packing + 29/266 Test #24: eccodes_t_grib_change_packing ............... Passed 0.41 sec + Start 25: eccodes_t_bufr_dump_data + 30/266 Test #25: eccodes_t_bufr_dump_data .................... Passed 0.93 sec + Start 26: eccodes_t_bufr_dump_descriptors + 31/266 Test #26: eccodes_t_bufr_dump_descriptors ............. Passed 4.10 sec + Start 27: eccodes_t_bufr_dump_subset + 32/266 Test #27: eccodes_t_bufr_dump_subset .................. Passed 3.02 sec + Start 28: eccodes_t_bufr_dump_decode_filter + 33/266 Test #28: eccodes_t_bufr_dump_decode_filter ........... Passed 5.33 sec + Start 29: eccodes_t_bufr_dump_encode_filter + 34/266 Test #29: eccodes_t_bufr_dump_encode_filter ...........***Failed 1.64 sec + Start 30: eccodes_t_bufrdc_desc_ref + 35/266 Test #30: eccodes_t_bufrdc_desc_ref ................... Passed 2.45 sec + Start 31: eccodes_t_bufrdc_ref + 36/266 Test #31: eccodes_t_bufrdc_ref ........................ Passed 26.79 sec + Start 32: eccodes_t_bufr_compare + 37/266 Test #32: eccodes_t_bufr_compare ...................... Passed 0.35 sec + Start 33: eccodes_t_bufr_copy + 38/266 Test #33: eccodes_t_bufr_copy ......................... Passed 0.11 sec + Start 34: eccodes_t_bufr_count + 39/266 Test #34: eccodes_t_bufr_count ........................ Passed 0.06 sec + Start 35: eccodes_t_bufr_get + 40/266 Test #35: eccodes_t_bufr_get .......................... Passed 0.13 sec + Start 36: eccodes_t_bufr_filter + 41/266 Test #36: eccodes_t_bufr_filter .......................***Failed 6.21 sec + Start 37: eccodes_t_bufr_filter_extract_datetime + 42/266 Test #37: eccodes_t_bufr_filter_extract_datetime ...... Passed 0.63 sec + Start 38: eccodes_t_bufr_filter_extract_area + 43/266 Test #38: eccodes_t_bufr_filter_extract_area .......... Passed 0.21 sec + Start 39: eccodes_t_bufr_json_data + 44/266 Test #39: eccodes_t_bufr_json_data .................... Passed 10.04 sec + Start 40: eccodes_t_bufr_ls + 45/266 Test #40: eccodes_t_bufr_ls ........................... Passed 0.79 sec + Start 41: eccodes_t_bufr_ls_json + 46/266 Test #41: eccodes_t_bufr_ls_json ...................... Passed 0.77 sec + Start 42: eccodes_t_bufr_change_edition + 47/266 Test #42: eccodes_t_bufr_change_edition ............... Passed 3.87 sec + Start 43: eccodes_t_bufr_keys_iter + 48/266 Test #43: eccodes_t_bufr_keys_iter .................... Passed 0.15 sec + Start 44: eccodes_t_bufr_get_element + 49/266 Test #44: eccodes_t_bufr_get_element .................. Passed 0.04 sec + Start 45: eccodes_t_bufr_wmo_tables + 50/266 Test #45: eccodes_t_bufr_wmo_tables ................... Passed 2.08 sec + Start 46: eccodes_t_bufr_extract_headers + 51/266 Test #46: eccodes_t_bufr_extract_headers .............. Passed 2.10 sec + Start 47: eccodes_t_bufr_ecc-673 + 52/266 Test #47: eccodes_t_bufr_ecc-673 ...................... Passed 0.16 sec + Start 48: eccodes_t_bufr_ecc-428 + 53/266 Test #48: eccodes_t_bufr_ecc-428 ...................... Passed 0.21 sec + Start 49: eccodes_t_bufr_ecc-286 + 54/266 Test #49: eccodes_t_bufr_ecc-286 ...................... Passed 0.14 sec + Start 50: eccodes_t_bufr_ecc-288 + 55/266 Test #50: eccodes_t_bufr_ecc-288 ...................... Passed 0.04 sec + Start 51: eccodes_t_bufr_ecc-313 + 56/266 Test #51: eccodes_t_bufr_ecc-313 ...................... Passed 0.15 sec + Start 52: eccodes_t_bufr_ecc-616 + 57/266 Test #52: eccodes_t_bufr_ecc-616 ...................... Passed 0.09 sec + Start 53: eccodes_t_bufr_ecc-686 + 58/266 Test #53: eccodes_t_bufr_ecc-686 ...................... Passed 0.07 sec + Start 54: eccodes_t_bufr_ecc-690 + 59/266 Test #54: eccodes_t_bufr_ecc-690 ...................... Passed 0.05 sec + Start 55: eccodes_t_bufr_ecc-379 + 60/266 Test #55: eccodes_t_bufr_ecc-379 ...................... Passed 0.18 sec + Start 56: eccodes_t_bufr_ecc-393 + 61/266 Test #56: eccodes_t_bufr_ecc-393 ......................***Failed 0.08 sec + Start 57: eccodes_t_bufr_ecc-433 + 62/266 Test #57: eccodes_t_bufr_ecc-433 ...................... Passed 0.05 sec + Start 58: eccodes_t_bufr_ecc-750 + 63/266 Test #58: eccodes_t_bufr_ecc-750 ...................... Passed 0.08 sec + Start 59: eccodes_t_bufr_ecc-765 + 64/266 Test #59: eccodes_t_bufr_ecc-765 ...................... Passed 0.00 sec + Start 60: eccodes_t_bufr_ecc-875 + 65/266 Test #60: eccodes_t_bufr_ecc-875 ...................... Passed 0.09 sec + Start 61: eccodes_t_bufr_ecc-887 + 66/266 Test #61: eccodes_t_bufr_ecc-887 ...................... Passed 0.03 sec + Start 62: eccodes_t_grib_ecc-490 + 67/266 Test #62: eccodes_t_grib_ecc-490 ...................... Passed 0.07 sec + Start 63: eccodes_t_grib_ecc-756 + 68/266 Test #63: eccodes_t_grib_ecc-756 ...................... Passed 0.43 sec + Start 64: eccodes_t_grib_ecc-873 + 69/266 Test #64: eccodes_t_grib_ecc-873 ...................... Passed 0.22 sec + Start 65: eccodes_t_grib_ecc-600 + 70/266 Test #65: eccodes_t_grib_ecc-600 ...................... Passed 0.10 sec + Start 66: eccodes_t_grib_ecc-923 + 71/266 Test #66: eccodes_t_grib_ecc-923 ...................... Passed 0.12 sec + Start 67: eccodes_t_grib_ecc-979 + 72/266 Test #67: eccodes_t_grib_ecc-979 ...................... Passed 0.16 sec + Start 68: eccodes_t_grib_ecc-984 + 73/266 Test #68: eccodes_t_grib_ecc-984 ...................... Passed 0.04 sec + Start 69: eccodes_t_grib_ecc-1000 + 74/266 Test #69: eccodes_t_grib_ecc-1000 ..................... Passed 0.08 sec + Start 70: eccodes_t_grib_ecc-1001 + 75/266 Test #70: eccodes_t_grib_ecc-1001 ..................... Passed 0.28 sec + Start 71: eccodes_t_grib_ecc-1030 + 76/266 Test #71: eccodes_t_grib_ecc-1030 ..................... Passed 0.04 sec + Start 72: eccodes_t_bufr_ecc-556 + 77/266 Test #72: eccodes_t_bufr_ecc-556 ...................... Passed 0.01 sec + Start 73: eccodes_t_gts_get + 78/266 Test #73: eccodes_t_gts_get ........................... Passed 0.18 sec + Start 74: eccodes_t_gts_ls + 79/266 Test #74: eccodes_t_gts_ls ............................ Passed 0.05 sec + Start 75: eccodes_t_gts_count + 80/266 Test #75: eccodes_t_gts_count ......................... Passed 0.03 sec + Start 76: eccodes_t_gts_compare + 81/266 Test #76: eccodes_t_gts_compare ....................... Passed 0.13 sec + Start 77: eccodes_t_metar_ls + 82/266 Test #77: eccodes_t_metar_ls .......................... Passed 0.23 sec + Start 78: eccodes_t_metar_get + 83/266 Test #78: eccodes_t_metar_get ......................... Passed 0.11 sec + Start 79: eccodes_t_metar_dump + 84/266 Test #79: eccodes_t_metar_dump ........................ Passed 0.17 sec + Start 80: eccodes_t_metar_compare + 85/266 Test #80: eccodes_t_metar_compare ..................... Passed 0.14 sec + Start 81: eccodes_t_bufr_set + 86/266 Test #81: eccodes_t_bufr_set .......................... Passed 0.09 sec + Start 82: eccodes_t_ieee + 87/266 Test #82: eccodes_t_ieee .............................. Passed 0.47 sec + Start 83: eccodes_t_grib_sh_ieee64 + 88/266 Test #83: eccodes_t_grib_sh_ieee64 .................... Passed 0.02 sec + Start 84: eccodes_t_grib_optimize_scaling + 89/266 Test #84: eccodes_t_grib_optimize_scaling ............. Passed 0.14 sec + Start 85: eccodes_t_grib_optimize_scaling_sh + 90/266 Test #85: eccodes_t_grib_optimize_scaling_sh .......... Passed 0.03 sec + Start 86: eccodes_t_grib_lam_bf + 91/266 Test #86: eccodes_t_grib_lam_bf ....................... Passed 0.24 sec + Start 87: eccodes_t_grib_lam_gp + 92/266 Test #87: eccodes_t_grib_lam_gp ....................... Passed 0.11 sec + Start 88: eccodes_t_grib1to2 + 93/266 Test #88: eccodes_t_grib1to2 .......................... Passed 3.16 sec + Start 89: eccodes_t_grib2to1 + 94/266 Test #89: eccodes_t_grib2to1 .......................... Passed 2.58 sec + Start 90: eccodes_t_grib1to3 + 95/266 Test #90: eccodes_t_grib1to3 .......................... Passed 0.30 sec + Start 91: eccodes_t_grib2to3 + 96/266 Test #91: eccodes_t_grib2to3 .......................... Passed 0.11 sec + Start 92: eccodes_t_grib3_templates + 97/266 Test #92: eccodes_t_grib3_templates ................... Passed 0.22 sec + Start 93: eccodes_t_badgrib + 98/266 Test #93: eccodes_t_badgrib ........................... Passed 0.05 sec + Start 94: eccodes_t_grib_ls + 99/266 Test #94: eccodes_t_grib_ls ........................... Passed 1.92 sec + Start 95: eccodes_t_grib_ls_json +100/266 Test #95: eccodes_t_grib_ls_json ...................... Passed 6.80 sec + Start 96: eccodes_t_grib_filter +101/266 Test #96: eccodes_t_grib_filter ....................... Passed 0.56 sec + Start 97: eccodes_t_grib_multi +102/266 Test #97: eccodes_t_grib_multi ........................ Passed 0.13 sec + Start 98: eccodes_t_grib_nearest_test +103/266 Test #98: eccodes_t_grib_nearest_test ................. Passed 0.10 sec + Start 99: eccodes_t_budg +104/266 Test #99: eccodes_t_budg .............................. Passed 0.01 sec + Start 100: eccodes_t_grib_gridType +105/266 Test #100: eccodes_t_grib_gridType ..................... Passed 0.11 sec + Start 101: eccodes_t_grib_octahedral +106/266 Test #101: eccodes_t_grib_octahedral ................... Passed 9.16 sec + Start 102: eccodes_t_grib_global +107/266 Test #102: eccodes_t_grib_global ....................... Passed 0.32 sec + Start 103: eccodes_t_grib_concept +108/266 Test #103: eccodes_t_grib_concept ...................... Passed 0.99 sec + Start 104: eccodes_t_grib_decimalPrecision +109/266 Test #104: eccodes_t_grib_decimalPrecision ............. Passed 0.19 sec + Start 105: eccodes_t_grib_bitsPerValue +110/266 Test #105: eccodes_t_grib_bitsPerValue ................. Passed 2.35 sec + Start 106: eccodes_t_get_fail +111/266 Test #106: eccodes_t_get_fail .......................... Passed 0.01 sec + Start 107: eccodes_t_grib_missing +112/266 Test #107: eccodes_t_grib_missing ...................... Passed 0.09 sec + Start 108: eccodes_t_grib_local +113/266 Test #108: eccodes_t_grib_local ........................ Passed 6.62 sec + Start 109: eccodes_t_grib_step +114/266 Test #109: eccodes_t_grib_step ......................... Passed 0.74 sec + Start 110: eccodes_t_grib_set +115/266 Test #110: eccodes_t_grib_set .......................... Passed 0.26 sec + Start 111: eccodes_t_grib_iterator +116/266 Test #111: eccodes_t_grib_iterator ..................... Passed 1.42 sec + Start 112: eccodes_t_grib_compare +117/266 Test #112: eccodes_t_grib_compare ...................... Passed 0.53 sec + Start 113: eccodes_t_grib_copy +118/266 Test #113: eccodes_t_grib_copy ......................... Passed 0.16 sec + Start 114: eccodes_t_grib_level +119/266 Test #114: eccodes_t_grib_level ........................ Passed 1.33 sec + Start 115: eccodes_t_index +120/266 Test #115: eccodes_t_index ............................. Passed 0.97 sec + Start 116: eccodes_t_grib_bitmap +121/266 Test #116: eccodes_t_grib_bitmap ....................... Passed 0.96 sec + Start 117: eccodes_t_grib_list +122/266 Test #117: eccodes_t_grib_list ......................... Passed 0.04 sec + Start 118: eccodes_t_grib_second_order +123/266 Test #118: eccodes_t_grib_second_order ................. Passed 1.51 sec + Start 119: eccodes_t_grib_multi_from_message +124/266 Test #119: eccodes_t_grib_multi_from_message ........... Passed 0.36 sec + Start 120: eccodes_t_grib_change_scanning +125/266 Test #120: eccodes_t_grib_change_scanning .............. Passed 2.58 sec + Start 121: eccodes_t_grib_statistics +126/266 Test #121: eccodes_t_grib_statistics ................... Passed 1.30 sec + Start 122: eccodes_t_grib_tigge +127/266 Test #122: eccodes_t_grib_tigge ........................ Passed 12.55 sec + Start 123: eccodes_t_read_any +128/266 Test #123: eccodes_t_read_any .......................... Passed 0.16 sec + Start 124: eccodes_t_grib_dump +129/266 Test #124: eccodes_t_grib_dump ......................... Passed 0.91 sec + Start 125: eccodes_t_grib_dump_debug +130/266 Test #125: eccodes_t_grib_dump_debug ................... Passed 14.11 sec + Start 126: eccodes_t_grib_dump_json +131/266 Test #126: eccodes_t_grib_dump_json .................... Passed 16.45 sec + Start 127: eccodes_t_grib_local_MeteoFrance +132/266 Test #127: eccodes_t_grib_local_MeteoFrance ............ Passed 0.05 sec + Start 128: eccodes_t_grib_neg_fctime +133/266 Test #128: eccodes_t_grib_neg_fctime ................... Passed 0.48 sec + Start 129: eccodes_t_codes_split_file +134/266 Test #129: eccodes_t_codes_split_file .................. Passed 1.10 sec + Start 130: eccodes_t_grib_mars_types +135/266 Test #130: eccodes_t_grib_mars_types ................... Passed 8.19 sec + Start 131: eccodes_t_bufr_dump_encode_fortran +136/266 Test #131: eccodes_t_bufr_dump_encode_fortran .......... Passed 3.35 sec + Start 132: eccodes_t_bufr_dump_decode_fortran +137/266 Test #132: eccodes_t_bufr_dump_decode_fortran .......... Passed 2.83 sec + Start 133: eccodes_t_grib_util_set_spec +138/266 Test #133: eccodes_t_grib_util_set_spec ................ Passed 0.51 sec + Start 134: eccodes_t_grib_padding +139/266 Test #134: eccodes_t_grib_padding ...................... Passed 34.67 sec + Start 135: eccodes_t_grib_tigge_conversions +140/266 Test #135: eccodes_t_grib_tigge_conversions ............ Passed 26.25 sec + Start 136: eccodes_t_bufr_dump_encode_C +141/266 Test #136: eccodes_t_bufr_dump_encode_C ................ Passed 3.45 sec + Start 137: eccodes_t_bufr_dump_decode_C +142/266 Test #137: eccodes_t_bufr_dump_decode_C ................ Passed 2.82 sec + Start 138: eccodes_t_bufr_dump_encode_python +143/266 Test #138: eccodes_t_bufr_dump_encode_python ...........***Failed 24.62 sec + Start 139: eccodes_t_bufr_dump_decode_python +144/266 Test #139: eccodes_t_bufr_dump_decode_python ........... Passed 17.22 sec + Start 140: eccodes_t_grib_lamb_az_eq_area +145/266 Test #140: eccodes_t_grib_lamb_az_eq_area .............. Passed 0.16 sec + Start 141: eccodes_t_tools_data_from_stdin +146/266 Test #141: eccodes_t_tools_data_from_stdin ............. Passed 0.03 sec + Start 142: eccodes_t_bufr_ecc-197 +147/266 Test #142: eccodes_t_bufr_ecc-197 ...................... Passed 0.13 sec + Start 143: eccodes_t_grib_check_param_concepts +148/266 Test #143: eccodes_t_grib_check_param_concepts ......... Passed 0.01 sec + Start 144: eccodes_c_grib_multi +149/266 Test #144: eccodes_c_grib_multi ........................ Passed 0.09 sec + Start 145: eccodes_c_grib_set_data +150/266 Test #145: eccodes_c_grib_set_data ..................... Passed 0.01 sec + Start 146: eccodes_c_large_grib1 +151/266 Test #146: eccodes_c_large_grib1 ....................... Passed 0.23 sec + Start 147: eccodes_c_grib_sections_copy +152/266 Test #147: eccodes_c_grib_sections_copy ................ Passed 0.14 sec + Start 148: eccodes_c_get_product_kind_samples +153/266 Test #148: eccodes_c_get_product_kind_samples .......... Passed 0.12 sec + Start 149: eccodes_c_grib_iterator +154/266 Test #149: eccodes_c_grib_iterator ..................... Passed 0.05 sec + Start 150: eccodes_c_grib_get_keys +155/266 Test #150: eccodes_c_grib_get_keys ..................... Passed 0.01 sec + Start 151: eccodes_c_grib_print_data +156/266 Test #151: eccodes_c_grib_print_data ................... Passed 0.10 sec + Start 152: eccodes_c_grib_set_keys +157/266 Test #152: eccodes_c_grib_set_keys ..................... Passed 0.03 sec + Start 153: eccodes_c_grib_keys_iterator +158/266 Test #153: eccodes_c_grib_keys_iterator ................ Passed 0.22 sec + Start 154: eccodes_c_grib_multi_write +159/266 Test #154: eccodes_c_grib_multi_write .................. Passed 0.05 sec + Start 155: eccodes_c_grib_precision +160/266 Test #155: eccodes_c_grib_precision .................... Passed 0.01 sec + Start 156: eccodes_c_grib_clone +161/266 Test #156: eccodes_c_grib_clone ........................ Passed 0.06 sec + Start 157: eccodes_c_grib_copy_message +162/266 Test #157: eccodes_c_grib_copy_message ................. Passed 0.05 sec + Start 158: eccodes_c_grib_ensemble_index +163/266 Test #158: eccodes_c_grib_ensemble_index ............... Passed 0.25 sec + Start 159: eccodes_c_grib_set_pv +164/266 Test #159: eccodes_c_grib_set_pv ....................... Passed 0.03 sec + Start 160: eccodes_c_grib_set_bitmap +165/266 Test #160: eccodes_c_grib_set_bitmap ................... Passed 0.03 sec + Start 161: eccodes_c_grib_list +166/266 Test #161: eccodes_c_grib_list ......................... Passed 0.02 sec + Start 162: eccodes_c_grib_get_data +167/266 Test #162: eccodes_c_grib_get_data ..................... Passed 0.31 sec + Start 163: eccodes_c_grib_nearest_multiple +168/266 Test #163: eccodes_c_grib_nearest_multiple ............. Passed 0.02 sec + Start 164: eccodes_c_set_missing +169/266 Test #164: eccodes_c_set_missing ....................... Passed 0.02 sec + Start 165: eccodes_c_bufr_attributes +170/266 Test #165: eccodes_c_bufr_attributes ................... Passed 0.02 sec + Start 166: eccodes_c_bufr_copy_data +171/266 Test #166: eccodes_c_bufr_copy_data ....................***Failed 0.02 sec + Start 167: eccodes_c_bufr_clone +172/266 Test #167: eccodes_c_bufr_clone ........................ Passed 0.03 sec + Start 168: eccodes_c_bufr_expanded +173/266 Test #168: eccodes_c_bufr_expanded ..................... Passed 0.02 sec + Start 169: eccodes_c_bufr_get_keys +174/266 Test #169: eccodes_c_bufr_get_keys ..................... Passed 0.02 sec + Start 170: eccodes_c_bufr_get_string_array +175/266 Test #170: eccodes_c_bufr_get_string_array ............. Passed 0.02 sec + Start 171: eccodes_c_bufr_keys_iterator +176/266 Test #171: eccodes_c_bufr_keys_iterator ................ Passed 0.02 sec + Start 172: eccodes_c_bufr_missing +177/266 Test #172: eccodes_c_bufr_missing ...................... Passed 0.02 sec + Start 173: eccodes_c_bufr_read_header +178/266 Test #173: eccodes_c_bufr_read_header .................. Passed 0.11 sec + Start 174: eccodes_c_bufr_read_scatterometer +179/266 Test #174: eccodes_c_bufr_read_scatterometer ........... Passed 0.02 sec + Start 175: eccodes_c_bufr_read_synop +180/266 Test #175: eccodes_c_bufr_read_synop ................... Passed 0.02 sec + Start 176: eccodes_c_bufr_read_temp +181/266 Test #176: eccodes_c_bufr_read_temp .................... Passed 0.03 sec + Start 177: eccodes_c_bufr_set_keys +182/266 Test #177: eccodes_c_bufr_set_keys ..................... Passed 0.03 sec + Start 178: eccodes_c_bufr_subset +183/266 Test #178: eccodes_c_bufr_subset ....................... Passed 0.03 sec + Start 179: eccodes_c_get_product_kind +184/266 Test #179: eccodes_c_get_product_kind .................. Passed 0.02 sec + Start 180: eccodes_c_new_sample +185/266 Test #180: eccodes_c_new_sample ........................ Passed 0.02 sec + Start 181: eccodes_f_grib_set_pv +186/266 Test #181: eccodes_f_grib_set_pv ....................... Passed 0.11 sec + Start 182: eccodes_f_grib_set_data +187/266 Test #182: eccodes_f_grib_set_data ..................... Passed 0.02 sec + Start 183: eccodes_f_grib_ecc-671 +188/266 Test #183: eccodes_f_grib_ecc-671 ...................... Passed 0.02 sec + Start 184: eccodes_f_grib_index +189/266 Test #184: eccodes_f_grib_index ........................ Passed 0.90 sec + Start 185: eccodes_f_grib_copy_message +190/266 Test #185: eccodes_f_grib_copy_message ................. Passed 0.12 sec + Start 186: eccodes_f_bufr_copy_message +191/266 Test #186: eccodes_f_bufr_copy_message ................. Passed 0.02 sec + Start 187: eccodes_f_grib_get_keys +192/266 Test #187: eccodes_f_grib_get_keys ..................... Passed 0.03 sec + Start 188: eccodes_f_grib_get_data +193/266 Test #188: eccodes_f_grib_get_data ..................... Passed 0.71 sec + Start 189: eccodes_f_get_pl +194/266 Test #189: eccodes_f_get_pl ............................ Passed 0.02 sec + Start 190: eccodes_f_get_pv +195/266 Test #190: eccodes_f_get_pv ............................ Passed 0.01 sec + Start 191: eccodes_f_grib_keys_iterator +196/266 Test #191: eccodes_f_grib_keys_iterator ................ Passed 0.05 sec + Start 192: eccodes_f_grib_multi_write +197/266 Test #192: eccodes_f_grib_multi_write .................. Passed 0.13 sec + Start 193: eccodes_f_grib_multi +198/266 Test #193: eccodes_f_grib_multi ........................ Passed 0.03 sec + Start 194: eccodes_f_grib_nearest +199/266 Test #194: eccodes_f_grib_nearest ...................... Passed 0.02 sec + Start 195: eccodes_f_grib_precision +200/266 Test #195: eccodes_f_grib_precision .................... Passed 0.02 sec + Start 196: eccodes_f_grib_print_data +201/266 Test #196: eccodes_f_grib_print_data ................... Passed 0.37 sec + Start 197: eccodes_f_grib_set_keys +202/266 Test #197: eccodes_f_grib_set_keys ..................... Passed 0.06 sec + Start 198: eccodes_f_grib_set_bitmap +203/266 Test #198: eccodes_f_grib_set_bitmap ................... Passed 0.03 sec + Start 199: eccodes_f_grib_set_missing +204/266 Test #199: eccodes_f_grib_set_missing .................. Passed 0.02 sec + Start 200: eccodes_f_grib_samples +205/266 Test #200: eccodes_f_grib_samples ...................... Passed 0.04 sec + Start 201: eccodes_f_grib_count_messages +206/266 Test #201: eccodes_f_grib_count_messages ............... Passed 0.04 sec + Start 202: eccodes_f_grib_count_messages_multi +207/266 Test #202: eccodes_f_grib_count_messages_multi ......... Passed 0.04 sec + Start 203: eccodes_f_grib_copy_namespace +208/266 Test #203: eccodes_f_grib_copy_namespace ............... Passed 0.05 sec + Start 204: eccodes_f_read_message +209/266 Test #204: eccodes_f_read_message ...................... Passed 0.38 sec + Start 205: eccodes_f_read_from_file +210/266 Test #205: eccodes_f_read_from_file .................... Passed 0.01 sec + Start 206: eccodes_f_get_set_uuid +211/266 Test #206: eccodes_f_get_set_uuid ...................... Passed 0.05 sec + Start 207: eccodes_f_grib_clone +212/266 Test #207: eccodes_f_grib_clone ........................ Passed 0.03 sec + Start 208: eccodes_f_bufr_attributes +213/266 Test #208: eccodes_f_bufr_attributes ................... Passed 0.04 sec + Start 209: eccodes_f_bufr_copy_data +214/266 Test #209: eccodes_f_bufr_copy_data ....................***Failed 0.04 sec + Start 210: eccodes_f_bufr_clone +215/266 Test #210: eccodes_f_bufr_clone ........................ Passed 0.03 sec + Start 211: eccodes_f_bufr_expanded +216/266 Test #211: eccodes_f_bufr_expanded ..................... Passed 0.02 sec + Start 212: eccodes_f_bufr_get_keys +217/266 Test #212: eccodes_f_bufr_get_keys ..................... Passed 0.02 sec + Start 213: eccodes_f_bufr_get_string_array +218/266 Test #213: eccodes_f_bufr_get_string_array ............. Passed 0.03 sec + Start 214: eccodes_f_bufr_keys_iterator +219/266 Test #214: eccodes_f_bufr_keys_iterator ................ Passed 0.02 sec + Start 215: eccodes_f_bufr_read_header +220/266 Test #215: eccodes_f_bufr_read_header .................. Passed 0.01 sec + Start 216: eccodes_f_bufr_read_scatterometer +221/266 Test #216: eccodes_f_bufr_read_scatterometer ........... Passed 0.05 sec + Start 217: eccodes_f_bufr_read_synop +222/266 Test #217: eccodes_f_bufr_read_synop ................... Passed 0.02 sec + Start 218: eccodes_f_bufr_read_temp +223/266 Test #218: eccodes_f_bufr_read_temp .................... Passed 0.03 sec + Start 219: eccodes_f_bufr_read_tropical_cyclone +224/266 Test #219: eccodes_f_bufr_read_tropical_cyclone ........ Passed 0.04 sec + Start 220: eccodes_f_bufr_set_keys +225/266 Test #220: eccodes_f_bufr_set_keys ..................... Passed 0.05 sec + Start 221: eccodes_f_bufr_copy_keys +226/266 Test #221: eccodes_f_bufr_copy_keys .................... Passed 0.02 sec + Start 222: eccodes_f_bufr_subset +227/266 Test #222: eccodes_f_bufr_subset ....................... Passed 0.03 sec + Start 223: eccodes_f_get_product_kind +228/266 Test #223: eccodes_f_get_product_kind .................. Passed 0.03 sec + Start 224: eccodes_p_grib_set_pv_test +229/266 Test #224: eccodes_p_grib_set_pv_test .................. Passed 0.14 sec + Start 225: eccodes_p_grib_read_sample_test +230/266 Test #225: eccodes_p_grib_read_sample_test ............. Passed 0.18 sec + Start 226: eccodes_p_bufr_read_sample_test +231/266 Test #226: eccodes_p_bufr_read_sample_test ............. Passed 0.19 sec + Start 227: eccodes_p_bufr_ecc-869_test +232/266 Test #227: eccodes_p_bufr_ecc-869_test ................. Passed 0.19 sec + Start 228: eccodes_p_grib_clone_test +233/266 Test #228: eccodes_p_grib_clone_test ................... Passed 0.21 sec + Start 229: eccodes_p_grib_count_messages_test +234/266 Test #229: eccodes_p_grib_count_messages_test .......... Passed 0.15 sec + Start 230: eccodes_p_grib_get_message_offset_test +235/266 Test #230: eccodes_p_grib_get_message_offset_test ...... Passed 0.17 sec + Start 231: eccodes_p_grib_get_keys_test +236/266 Test #231: eccodes_p_grib_get_keys_test ................ Passed 0.19 sec + Start 232: eccodes_p_grib_index_test +237/266 Test #232: eccodes_p_grib_index_test ................... Passed 1.00 sec + Start 233: eccodes_p_grib_iterator_test +238/266 Test #233: eccodes_p_grib_iterator_test ................ Passed 5.61 sec + Start 234: eccodes_p_grib_keys_iterator_test +239/266 Test #234: eccodes_p_grib_keys_iterator_test ........... Passed 0.17 sec + Start 235: eccodes_p_grib_multi_write_test +240/266 Test #235: eccodes_p_grib_multi_write_test ............. Passed 0.09 sec + Start 236: eccodes_p_grib_nearest_test +241/266 Test #236: eccodes_p_grib_nearest_test ................. Passed 0.09 sec + Start 237: eccodes_p_grib_print_data_test +242/266 Test #237: eccodes_p_grib_print_data_test .............. Passed 0.10 sec + Start 238: eccodes_p_grib_samples_test +243/266 Test #238: eccodes_p_grib_samples_test ................. Passed 0.10 sec + Start 239: eccodes_p_grib_set_missing_test +244/266 Test #239: eccodes_p_grib_set_missing_test ............. Passed 0.11 sec + Start 240: eccodes_p_binary_message_test +245/266 Test #240: eccodes_p_binary_message_test ............... Passed 0.27 sec + Start 241: eccodes_p_grib_set_bitmap_test +246/266 Test #241: eccodes_p_grib_set_bitmap_test .............. Passed 0.10 sec + Start 242: eccodes_p_bufr_attributes_test +247/266 Test #242: eccodes_p_bufr_attributes_test .............. Passed 0.10 sec + Start 243: eccodes_p_bufr_clone_test +248/266 Test #243: eccodes_p_bufr_clone_test ................... Passed 0.11 sec + Start 244: eccodes_p_bufr_copy_data_test +249/266 Test #244: eccodes_p_bufr_copy_data_test ...............***Failed 0.11 sec + Start 245: eccodes_p_bufr_expanded_test +250/266 Test #245: eccodes_p_bufr_expanded_test ................ Passed 0.09 sec + Start 246: eccodes_p_bufr_get_keys_test +251/266 Test #246: eccodes_p_bufr_get_keys_test ................ Passed 0.10 sec + Start 247: eccodes_p_bufr_keys_iterator_test +252/266 Test #247: eccodes_p_bufr_keys_iterator_test ........... Passed 0.10 sec + Start 248: eccodes_p_bufr_read_header_test +253/266 Test #248: eccodes_p_bufr_read_header_test ............. Passed 0.32 sec + Start 249: eccodes_p_bufr_read_scatterometer_test +254/266 Test #249: eccodes_p_bufr_read_scatterometer_test ...... Passed 0.10 sec + Start 250: eccodes_p_bufr_read_tropical_cyclone_test +255/266 Test #250: eccodes_p_bufr_read_tropical_cyclone_test ... Passed 0.29 sec + Start 251: eccodes_p_bufr_read_synop_test +256/266 Test #251: eccodes_p_bufr_read_synop_test .............. Passed 0.09 sec + Start 252: eccodes_p_bufr_read_temp_test +257/266 Test #252: eccodes_p_bufr_read_temp_test ............... Passed 0.09 sec + Start 253: eccodes_p_bufr_set_keys_test +258/266 Test #253: eccodes_p_bufr_set_keys_test ................ Passed 0.11 sec + Start 254: eccodes_p_bufr_subset_test +259/266 Test #254: eccodes_p_bufr_subset_test .................. Passed 0.10 sec + Start 255: eccodes_p_get_product_kind_test +260/266 Test #255: eccodes_p_get_product_kind_test ............. Passed 0.10 sec + Start 256: eccodes_p_gts_get_keys_test +261/266 Test #256: eccodes_p_gts_get_keys_test ................. Passed 0.16 sec + Start 257: eccodes_p_metar_get_keys_test +262/266 Test #257: eccodes_p_metar_get_keys_test ............... Passed 0.19 sec + Start 258: eccodes_p_bufr_ecc-448_test +263/266 Test #258: eccodes_p_bufr_ecc-448_test ................. Passed 0.10 sec + Start 259: eccodes_p_high_level_api_test +264/266 Test #259: eccodes_p_high_level_api_test ............... Passed 0.33 sec + Start 260: eccodes_p_grib_set_keys_test +265/266 Test #260: eccodes_p_grib_set_keys_test ................ Passed 0.09 sec + Start 261: eccodes_p_bufr_encode_flight_test +266/266 Test #261: eccodes_p_bufr_encode_flight_test ........... Passed 0.25 sec + +97% tests passed, 8 tests failed out of 266 + +Label Time Summary: +download_data = 37.11 sec*proc (5 tests) +eccodes = 367.44 sec*proc (266 tests) +executable = 0.02 sec*proc (1 test) +script = 330.30 sec*proc (260 tests) + +Total Test time (real) = 368.04 sec + +The following tests FAILED: + 4 - eccodes_t_md5 (BAD_COMMAND) + 29 - eccodes_t_bufr_dump_encode_filter (Failed) + 36 - eccodes_t_bufr_filter (Failed) + 56 - eccodes_t_bufr_ecc-393 (Failed) + 138 - eccodes_t_bufr_dump_encode_python (Failed) + 166 - eccodes_c_bufr_copy_data (Failed) + 209 - eccodes_f_bufr_copy_data (Failed) + 244 - eccodes_p_bufr_copy_data_test (Failed) +Errors while running CTest diff --git a/src/ChangesB6.txt b/src/ChangesB6.txt new file mode 100644 index 000000000..308d6fb15 --- /dev/null +++ b/src/ChangesB6.txt @@ -0,0 +1,157 @@ +Compilation +--------------- +unlink eccodes-2.17.0-Source; unlink eccodes-2.17.0-BUILD; unlink eccodes-2.17.0-INSTALL ; +ln -fs eccodes-2.17.0-Source.B6 eccodes-2.17.0-Source ; ln -fs eccodes-2.17.0-BUILD.B6 eccodes-2.17.0-BUILD ; ln -fs eccodes-2.17.0-INSTALL.B6 eccodes-2.17.0-INSTALL ; + +#DEBUG OFF +rm -rf cmake.out ;cmake3 -DENABLE_NETCDF=OFF -DENABLE_FORTRAN=ON -DCMAKE_INSTALL_PREFIX=/home/eccuser/eccodes-2.17.0-INSTALL.B6 -DENABLE_EXTRA_TESTS=1 /home/eccuser/eccodes-2.17.0-Source >> cmake.out 2>&1 ; egrep -i "error|fail" cmake.out + +#DEBUG ON +rm -rf cmake.out ;cmake3 -DCMAKE_C_FLAGS="-g -O0" -DENABLE_NETCDF=OFF -DENABLE_FORTRAN=ON -DCMAKE_INSTALL_PREFIX=/home/eccuser/eccodes-2.17.0-INSTALL.B6 -DCMAKE_BUILD_TYPE=Debug -DENABLE_EXTRA_TESTS=1 -DDEVELOPER_MODE=1 /home/eccuser/eccodes-2.17.0-Source.B6 >> cmake.out 2>&1 ; egrep -i "error|fail" cmake.out + +rm -rf make.out; make >> make.out 2>&1; egrep -i "error|fail" make.out; + +rm -rf ctest3.out; ctest3 >> ctest3.out 2>&1 ; egrep -i "error|fail" ctest3.out; + +rm -rf make_install.out; make install >> make_install.out 2>&1 ; egrep -i "error|fail" make_install.out; + +Base version +------------- +The base version for this version is B5. + +Differences/Rules +----------------- +The Rule 1,2,3 are applied on the dynamic array structs of: +* grib_darray.c +* grib_iarray.c +* grib_oarray.c +* grib_sarray.c +* grib_vdarray.c +* grib_viarray.c +* grib_vsarray.c + +* Rule 1. Add to a dynamic array struct a static array , which will be filled for first; +* Rule 2. Once the static array is full, proceed to resize the array, allocating the dynamic memory in the dynamic area of the dynamic array struct; +* Rule 3. Tuning all the dynamic arrays getters/setters methods accordingly. + +Corrections +----------- +* Removed unused functions in all the mentioned arrays; + +Examples +---------- +* Rule 1. + +"grib_darray" struct in version B5 was + +struct grib_darray +{ + double* v; + size_t size; + size_t n; + size_t incsize; +}; + +In B6 the same struct is + +struct grib_darray +{ + double sv[DYN_DEFAULT_DARRAY_SIZE_INIT]; + size_t size; + size_t n; + size_t incsize; + double* v; +}; + +Where "sv" is a static array which is allocated at runtime when the malloc for "grib_darray" allocation is called. This space will first be filled and only if completely full, the dynamic area "v" will be allocated, with a consequent malloc/free burden at runtime. +When a new dynamic array is build through the method "new", only one malloc will be called to build it and not two mallocs as in B5. Here an example which clarify the mechanism. +Location: grib_accessor_class_bufr_data_array.c/process_elements +elementsDescriptorsIndex = grib_iarray_new(c, DYN_DEFAULT_IARRAY_SIZE_INIT, DYN_DEFAULT_IARRAY_SIZE_INCR); +The method grib_iarray_new directly instantiates in only one malloc the space for the struct, like this: +grib_iarray* result = NULL; + result = (grib_iarray*)grib_context_malloc(c, sizeof(grib_iarray)); +The dynamic area "v" will be allocated only if the startsize is bigger than the defined value DYN_DEFAULT_IARRAY_SIZE_INIT. This mechanism, already eliminates a malloc call. + +* Rule 2. + +The changed dynamic arrays are quite similar in their structures. As a matter of fact, also the functions which access them have similar signatures. So the allocation of more space is done for all of them in the "resize" method" and it is precisely the method which was changed for all of them. Here it is reported the the resize method for "grib_iarray": +newsize = origin->incsize + origin->size; + if (origin->v != NULL){ + newv = (long*)grib_context_realloc(c, origin->v, (newsize-DYN_DEFAULT_IARRAY_SIZE_INIT) * sizeof(long)); + origin->v=newv; + } else { + newv = (long*)grib_context_malloc(c, (newsize-DYN_DEFAULT_IARRAY_SIZE_INIT ) * sizeof(long) ); + origin->v=newv; + } + origin->size = newsize; + +* Rule 3. + +While in the original version the dynamic array "v", of any of the dynamic structures under exam, was accessed widely through the C access operators "[]", in B6 this was changed. In fact, after the reenginering of the data structures, it is not obvious anymore that an element at index "idx" can be found in v[idx]. In fact the general rule is that if idx is smaller that the default size of the static array, than the element is to be searched in at "sv[idx]". Otherwise, the element will be searched in v[idx-SV_DEFAULT_SIZE]. These calculations are done by setters/getters method like: +long grib_iarray_get(grib_iarray* source, size_t index); +grib_iarray* grib_iarray_push(grib_iarray* source, long val); +Another method whch is important to mention is: +double* grib_darray_get_arrays_by_reference(grib_darray* source); +The method will in fact analyse which is the actual array and will return the correct reference to it. This method is directly used from the accessors in order to unpack the messages, with the help of the parser. + +Differences +------------ +The complete list of differences, due to Rule 1, 2 and 3 and other corrections are here. + +Difference between original code contained in eccodes-2.17.0 and B6: +For Rule 1 and 2, plus removal of unused functions: +grib_api.h +grib_api_internal.h +grib_api_prototypes.h +grib_darray.c +grib_iarray.c +grib_oarray.c +grib_sarray.c +grib_vdarray.c +grib_viarray.c +grib_vsarray.c + +For Rule 3 +action_class_set_darray.c +action_class_set_iarray.c +action_class_set_sarray.c +bufr_util.c +grib_accessor_class_bufr_data_array.c +grib_accessor_class_bufr_data_element.c +grib_accessor_class_bufr_string_values.c +grib_accessor_class_concept.c +grib_accessor_class_hash_array.c +grib_accessor_class_long_vector.c +grib_bufr_descriptors_array.c +grib_accessor_class_transient_darray.c +grib_trie_with_rank.c + +Difference between B5 code and B6: + +./action_class_set_darray.c +./action_class_set_iarray.c +./action_class_set_sarray.c +./grib_accessor_class_bufr_data_array.c +./grib_accessor_class_bufr_data_element.c +./grib_accessor_class_bufr_string_values.c +./grib_accessor_class_concept.c +./grib_accessor_class_hash_array.c +./grib_accessor_class_long_vector.c +./grib_accessor_class_transient_darray.c +./grib_api.h +./grib_api_internal.h +./grib_api_prototypes.h +./grib_darray.c +./grib_iarray.c +./grib_oarray.c +./grib_sarray.c +./grib_trie_with_rank.c +./grib_vdarray.c +./grib_viarray.c +./grib_vsarray.c + +Observations +------------ +* "grib_action* grib_action_create_set_iarray(grib_context* context, const char* name, grib_iarray* iarray)" +in action_class_set_iarray.c is never used + diff --git a/src/action_class_set_darray.c b/src/action_class_set_darray.c index 7b5a9ecf1..2cb023cb3 100644 --- a/src/action_class_set_darray.c +++ b/src/action_class_set_darray.c @@ -107,7 +107,8 @@ static int execute(grib_action* a, grib_handle* h) { grib_action_set_darray* self = (grib_action_set_darray*)a; - return grib_set_double_array(h, self->name, self->darray->v, self->darray->n); + return grib_set_double_array(h, self->name, grib_darray_get_arrays_by_reference(self->darray), self->darray->n); + //return grib_set_double_array(h, self->name, self->darray->v, self->darray->n); } static void dump(grib_action* act, FILE* f, int lvl) diff --git a/src/action_class_set_iarray.c b/src/action_class_set_iarray.c index 08ed7b86b..63078f707 100644 --- a/src/action_class_set_iarray.c +++ b/src/action_class_set_iarray.c @@ -106,8 +106,9 @@ grib_action* grib_action_create_set_iarray(grib_context* context, static int execute(grib_action* a, grib_handle* h) { grib_action_set_iarray* self = (grib_action_set_iarray*)a; - - return grib_set_long_array(h, self->name, self->iarray->v, self->iarray->n); + size_t size = grib_iarray_used_size(self->iarray); + //return grib_set_long_array(h, self->name, self->iarray->v, self->iarray->n); + return grib_set_long_array(h, self->name, grib_iarray_get_arrays_by_reference(self->iarray), size); } static void dump(grib_action* act, FILE* f, int lvl) diff --git a/src/action_class_set_sarray.c b/src/action_class_set_sarray.c index aa811635a..c110a2d58 100644 --- a/src/action_class_set_sarray.c +++ b/src/action_class_set_sarray.c @@ -107,7 +107,8 @@ static int execute(grib_action* a, grib_handle* h) { grib_action_set_sarray* self = (grib_action_set_sarray*)a; - return grib_set_string_array(h, self->name, (const char**)self->sarray->v, self->sarray->n); + //return grib_set_string_array(h, self->name, (const char**)self->sarray->v, self->sarray->n); + return grib_set_string_array(h, self->name, (const char**)grib_sarray_get_arrays_by_reference(self->sarray), self->sarray->n); } static void dump(grib_action* act, FILE* f, int lvl) diff --git a/src/action_class_transient_darray.c b/src/action_class_transient_darray.c index 64606fd69..0d5d7af78 100644 --- a/src/action_class_transient_darray.c +++ b/src/action_class_transient_darray.c @@ -121,7 +121,8 @@ static int execute(grib_action* act, grib_handle* h) if (a->flags & GRIB_ACCESSOR_FLAG_CONSTRAINT) grib_dependency_observe_arguments(a, act->default_value); - return grib_pack_double(a, self->darray->v, &len); + /*return grib_pack_double(a, self->darray->dynA, &len);*/ + return grib_pack_double(a, grib_darray_get_arrays_by_reference(self->darray), &len); } static void dump(grib_action* act, FILE* f, int lvl) diff --git a/src/bufr_util.c b/src/bufr_util.c index 21842a3fe..7fe6ce217 100644 --- a/src/bufr_util.c +++ b/src/bufr_util.c @@ -70,7 +70,9 @@ char** codes_bufr_copy_data_return_copied_keys(grib_handle* hin, grib_handle* ho kiter = codes_bufr_data_section_keys_iterator_new(hin); if (!kiter) return NULL; - k = grib_sarray_new(hin->context, 50, 10); + //magic numbers 50 and 10 are not documented anywhere... + //k = grib_sarray_new(hin->context, 50, 10); + k = grib_sarray_new(hin->context, 50, 60); while (codes_bufr_keys_iterator_next(kiter)) { name = codes_bufr_keys_iterator_get_name(kiter); diff --git a/src/grib_accessor_class_bufr_data_array.c b/src/grib_accessor_class_bufr_data_array.c index 6632ade8b..3a259586c 100644 --- a/src/grib_accessor_class_bufr_data_array.c +++ b/src/grib_accessor_class_bufr_data_array.c @@ -6,6 +6,7 @@ * * 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. + * Modified for Performance Study by: CS GMBH */ #include "grib_api_internal.h" @@ -374,9 +375,6 @@ static void tableB_override_dump(grib_accessor_bufr_data_array *self) } */ -#define DYN_ARRAY_SIZE_INIT 1000 /* Initial size for grib_iarray_new and grib_darray_new */ -#define DYN_ARRAY_SIZE_INCR 1000 /* Increment size for grib_iarray_new and grib_darray_new */ - static void init(grib_accessor* a, const long v, grib_arguments* params) { grib_accessor_bufr_data_array* self = (grib_accessor_bufr_data_array*)a; @@ -562,6 +560,7 @@ static int decode_string_array(grib_context* c, unsigned char* data, long* pos, int* err = &ret; char* sval = 0; int j, modifiedWidth, width; + //grib_sarray* sa = grib_sarray_new(c, self->numberOfSubsets, 10); grib_sarray* sa = grib_sarray_new(c, self->numberOfSubsets, 10); int bufr_multi_element_constant_arrays = c->bufr_multi_element_constant_arrays; @@ -635,7 +634,7 @@ static grib_darray* decode_double_array(grib_context* c, unsigned char* data, lo dval = GRIB_MISSING_DOUBLE; lval = 0; grib_context_log(c, GRIB_LOG_DEBUG, " modifiedWidth=%ld lval=%ld dval=%g", modifiedWidth, lval, dval); - ret = grib_darray_new(c, DYN_ARRAY_SIZE_INIT, DYN_ARRAY_SIZE_INCR); + ret = grib_darray_new(c, DYN_DEFAULT_DARRAY_SIZE_INIT, DYN_DEFAULT_DARRAY_SIZE_INCR); grib_darray_push(c, ret, dval); *err = 0; return ret; @@ -644,14 +643,15 @@ static grib_darray* decode_double_array(grib_context* c, unsigned char* data, lo localReference = (long)lval + modifiedReference; localWidth = grib_decode_unsigned_long(data, pos, 6); grib_context_log(c, GRIB_LOG_DEBUG, "BUFR data decoding: \tlocalWidth=%ld", localWidth); - ret = grib_darray_new(c, self->numberOfSubsets, 50); + //ret = grib_darray_new(c, self->numberOfSubsets, 50); + ret = grib_darray_new(c, self->numberOfSubsets, self->numberOfSubsets); if (localWidth) { CHECK_END_DATA_RETURN(c, self, localWidth * self->numberOfSubsets, NULL); if (*err) { dval = GRIB_MISSING_DOUBLE; lval = 0; grib_context_log(c, GRIB_LOG_DEBUG, " modifiedWidth=%ld lval=%ld dval=%g", modifiedWidth, lval, dval); - ret = grib_darray_new(c, DYN_ARRAY_SIZE_INIT, DYN_ARRAY_SIZE_INCR); + ret = grib_darray_new(c, DYN_DEFAULT_DARRAY_SIZE_INIT, DYN_DEFAULT_DARRAY_SIZE_INCR); grib_darray_push(c, ret, dval); *err = 0; return ret; @@ -717,7 +717,8 @@ static int encode_string_array(grib_context* c, grib_buffer* buff, long* pos, bu ival = 0; } else { - ival = self->iss_list->v[0]; + //ival = self->iss_list->v[0]; + ival = grib_iarray_get(self->iss_list, 0); } if (n > grib_sarray_used_size(stringValues)) @@ -726,7 +727,8 @@ static int encode_string_array(grib_context* c, grib_buffer* buff, long* pos, bu modifiedWidth = bd->width; grib_buffer_set_ulength_bits(c, buff, buff->ulength_bits + modifiedWidth); - grib_encode_string(buff->data, pos, modifiedWidth / 8, stringValues->v[ival]); + /*grib_encode_string(buff->data, pos, modifiedWidth / 8, stringValues->dynA[ival]);*/ + grib_encode_string(buff->data, pos, modifiedWidth / 8, grib_sarray_get(stringValues,ival) ); width = n > 1 ? modifiedWidth : 0; grib_buffer_set_ulength_bits(c, buff, buff->ulength_bits + 6); @@ -734,8 +736,10 @@ static int encode_string_array(grib_context* c, grib_buffer* buff, long* pos, bu if (width) { grib_buffer_set_ulength_bits(c, buff, buff->ulength_bits + width * n); for (j = 0; j < n; j++) { - k = self->iss_list->v[j]; - grib_encode_string(buff->data, pos, width / 8, stringValues->v[k]); + //k = self->iss_list->v[j]; + k = grib_iarray_get(self->iss_list, j); + /* grib_encode_string(buff->data, pos, width / 8, stringValues->dynA[k]); */ + grib_encode_string(buff->data, pos, width / 8, grib_sarray_get(stringValues,k) ); } } return err; @@ -745,8 +749,10 @@ static void set_missing_long_to_double(grib_darray* dvalues) { size_t i, n = grib_darray_used_size(dvalues); for (i = 0; i < n; i++) { - if (dvalues->v[i] == GRIB_MISSING_LONG) - dvalues->v[i] = GRIB_MISSING_DOUBLE; + //if (dvalues->v[i] == GRIB_MISSING_LONG) + // dvalues->v[i] = GRIB_MISSING_DOUBLE; + if ( grib_darray_get(dvalues, i) == GRIB_MISSING_LONG) + grib_darray_put(dvalues, i, GRIB_MISSING_DOUBLE); } } @@ -775,7 +781,7 @@ static int encode_double_array(grib_context* c, grib_buffer* buff, long* pos, bu size_t ii, index_of_min, index_of_max; int nvals = 0; double min = 0, max = 0, maxAllowed, minAllowed; - double* v = NULL; + double* v = NULL; /* ATTEMPT: double value = 0.0; double* dvaluesPtr = NULL;*/ double* values = NULL; int thereIsAMissing = 0; int is_constant; @@ -801,32 +807,32 @@ static int encode_double_array(grib_context* c, grib_buffer* buff, long* pos, bu set_missing_long_to_double(dvalues); - v = dvalues->v; + v = grib_darray_get_arrays_by_reference(dvalues);/* ATTEMPT: v = dvalues->v; value = grib_darray_get(dvalues,0); */ /* is constant */ if (grib_darray_is_constant(dvalues, modifiedFactor * .5)) { localWidth = 0; grib_buffer_set_ulength_bits(c, buff, buff->ulength_bits + modifiedWidth); - if (*v == GRIB_MISSING_DOUBLE) { + if (*v == GRIB_MISSING_DOUBLE) { /* ATTEMPT: if (value == GRIB_MISSING_DOUBLE) */ grib_set_bits_on(buff->data, pos, modifiedWidth); } else { - if (*v > maxAllowed || *v < minAllowed) { + if (*v > maxAllowed || *v < minAllowed) { /* ATTEMPT: if (value > maxAllowed || value < minAllowed) */ if (dont_fail_if_out_of_range) { fprintf(stderr, "ECCODES WARNING : encode_double_array: %s. Value (%g) out of range (minAllowed=%g, maxAllowed=%g)." " Setting it to missing value\n", - bd->shortName, *v, minAllowed, maxAllowed); + bd->shortName, *v, minAllowed, maxAllowed); /* ATTEMPT: bd->shortName, value, minAllowed, maxAllowed); */ grib_set_bits_on(buff->data, pos, modifiedWidth); } else { grib_context_log(c, GRIB_LOG_ERROR, "encode_double_array: %s. Value (%g) out of range (minAllowed=%g, maxAllowed=%g).", - bd->shortName, *v, minAllowed, maxAllowed); + bd->shortName, *v, minAllowed, maxAllowed); /* ATTEMPT: bd->shortName, value, minAllowed, maxAllowed); */ return GRIB_OUT_OF_RANGE; /* ECC-611 */ } } else { - lval = round(*v * inverseFactor) - modifiedReference; + lval = round(*v * inverseFactor) - modifiedReference; /* ATTEMPT: lval = round(value * inverseFactor) - modifiedReference; */ grib_encode_size_tb(buff->data, lval, pos, modifiedWidth); } } @@ -838,14 +844,14 @@ static int encode_double_array(grib_context* c, grib_buffer* buff, long* pos, bu if (nvals > grib_darray_used_size(dvalues)) return GRIB_ARRAY_TOO_SMALL; values = (double*)grib_context_malloc_clear(c, sizeof(double) * nvals); - val0 = dvalues->v[self->iss_list->v[0]]; + val0 = grib_darray_get(dvalues, grib_iarray_get(self->iss_list, 0) ); /* ORIGINAL: val0 = dvalues->v[self->iss_list->v[0]]; */ is_constant = 1; for (i = 0; i < nvals; i++) { - values[i] = dvalues->v[self->iss_list->v[i]]; + values[i] = grib_darray_get(dvalues, grib_iarray_get(self->iss_list, i)); /* ORIGINAL: values[i] = dvalues->v[self->iss_list->v[i]]; */ if (val0 != values[i]) is_constant = 0; } - v = values; + v = values; /*ATTEMPT: dvaluesPtr = values;*/ /* encoding a range with constant values*/ if (is_constant == 1) { @@ -895,7 +901,7 @@ static int encode_double_array(grib_context* c, grib_buffer* buff, long* pos, bu } ii = 0; index_of_min = index_of_max = 0; - v = values; + v = values; while (ii < nvals) { if (*v < min && *v != GRIB_MISSING_DOUBLE) { min = *v; @@ -1124,6 +1130,7 @@ static int decode_element(grib_context* c, grib_accessor_bufr_data_array* self, if (self->compressedData) { err = decode_string_array(c, data, pos, bd, self); index = grib_vsarray_used_size(self->stringValues); + /* dar = grib_darray_new(c, self->numberOfSubsets, 10); */ dar = grib_darray_new(c, self->numberOfSubsets, 10); index = self->numberOfSubsets * (index - 1); for (ii = 1; ii <= self->numberOfSubsets; ii++) { @@ -1141,7 +1148,8 @@ static int decode_element(grib_context* c, grib_accessor_bufr_data_array* self, stringValuesLen = grib_vsarray_used_size(self->stringValues); index = 0; for (ii = 0; ii < stringValuesLen; ii++) { - index += grib_sarray_used_size(self->stringValues->v[ii]); + //index += grib_sarray_used_size(self->stringValues->v[ii]); + index += grib_sarray_used_size( grib_vsarray_get (self->stringValues, ii) ); } cdval = index * 1000 + bd->width / 8; grib_darray_push(c, dval, cdval); @@ -1220,7 +1228,8 @@ static int decode_replication(grib_context* c, grib_accessor_bufr_data_array* se } } if (self->compressedData) { - dval = grib_darray_new(c, 1, 100); + //dval = grib_darray_new(c, 1, 100); + dval = grib_darray_new(c, self->numberOfSubsets, self->numberOfSubsets); if (c->bufr_multi_element_constant_arrays) { long j; for (j = 0; j < self->numberOfSubsets; j++) { @@ -1421,6 +1430,7 @@ static int encode_new_replication(grib_context* c, grib_accessor_bufr_data_array return err; } +/* dval and sval are not used!!!! */ static int encode_element(grib_context* c, grib_accessor_bufr_data_array* self, int subsetIndex, grib_buffer* buff, unsigned char* data, long* pos, int i, bufr_descriptor* descriptor, long elementIndex, grib_darray* dval, grib_sarray* sval) @@ -1444,43 +1454,59 @@ static int encode_element(grib_context* c, grib_accessor_bufr_data_array* self, /* grib_context_log(c, GRIB_LOG_DEBUG,"BUFR data encoding: \t %s = %s", bd->shortName,csval); */ if (self->compressedData) { - idx = ((int)self->numericValues->v[elementIndex]->v[0] / 1000 - 1) / self->numberOfSubsets; - err = encode_string_array(c, buff, pos, bd, self, self->stringValues->v[idx]); + //idx = ((int)self->numericValues->v[elementIndex]->v[0] / 1000 - 1) / self->numberOfSubsets; + //idx = ((int) grib_darray_get ( self->numericValues->v[elementIndex], 0) / 1000 - 1) / self->numberOfSubsets; + idx = ((((int)(grib_darray_get ( grib_vdarray_get (self->numericValues, elementIndex), 0)))/1000) -1) / self->numberOfSubsets; + //err = encode_string_array(c, buff, pos, bd, self, self->stringValues->v[idx]); + err = encode_string_array(c, buff, pos, bd, self, grib_vsarray_get ( self->stringValues, idx) ); } else { - if (self->numericValues->v[subsetIndex] == NULL) { - grib_context_log(c, GRIB_LOG_ERROR, "Invalid subset index %d (number of subsets=%ld)", subsetIndex, self->numberOfSubsets); + //if (self->numericValues->v[subsetIndex] == NULL) { + if (grib_vdarray_get (self->numericValues, subsetIndex) == NULL) { + grib_context_log(c, GRIB_LOG_ERROR, "Invalid subset index %d (number of subsets=%ld)", subsetIndex, self->numberOfSubsets); return GRIB_INVALID_ARGUMENT; } - idx = (int)self->numericValues->v[subsetIndex]->v[elementIndex] / 1000 - 1; - if (idx < 0 || idx >= self->stringValues->n) { + //idx = (int)self->numericValues->v[subsetIndex]->v[elementIndex] / 1000 - 1; + //idx = ( ( (int) grib_darray_get ( self->numericValues->v[subsetIndex], elementIndex) ) / 1000 ) -1; + idx = (((int) grib_darray_get ( grib_vdarray_get (self->numericValues, subsetIndex), elementIndex))/1000) -1 ; + + if (idx < 0 || idx >= grib_vsarray_used_size(self->stringValues)) { grib_context_log(c, GRIB_LOG_ERROR, "encode_element: %s: Invalid index %d", bd->shortName, idx); return GRIB_INVALID_ARGUMENT; } - err = encode_string_value(c, buff, pos, bd, self, self->stringValues->v[idx]->v[0]); + //err = encode_string_value(c, buff, pos, bd, self, self->stringValues->v[idx]->v[0]); + err = encode_string_value(c, buff, pos, bd, self, grib_sarray_get ( grib_vsarray_get ( self->stringValues, idx), 0)); } } else { /* numeric or codetable or flagtable */ if (self->compressedData) { - err = encode_double_array(c, buff, pos, bd, self, self->numericValues->v[elementIndex]); + //err = encode_double_array(c, buff, pos, bd, self, self->numericValues->v[elementIndex]); + err = encode_double_array(c, buff, pos, bd, self, grib_vdarray_get (self->numericValues, elementIndex) ); if (err) { grib_context_log(c, GRIB_LOG_ERROR, "encoding %s ( code=%6.6ld width=%ld scale=%ld reference=%ld )", bd->shortName, bd->code, bd->width, bd->scale, bd->reference); - for (j = 0; j < grib_darray_used_size(self->numericValues->v[elementIndex]); j++) - grib_context_log(c, GRIB_LOG_ERROR, "value[%d]\t= %g", j, self->numericValues->v[elementIndex]->v[j]); + //for (j = 0; j < grib_darray_used_size(self->numericValues->v[elementIndex]); j++) + for (j = 0; j < grib_darray_used_size( grib_vdarray_get (self->numericValues, elementIndex) ); j++) + //grib_context_log(c, GRIB_LOG_ERROR, "value[%d]\t= %g", j, self->numericValues->v[elementIndex]->v[j]); + //grib_context_log(c, GRIB_LOG_ERROR, "value[%d]\t= %g", j, grib_darray_get (self->numericValues->v[elementIndex], j) ); + grib_context_log(c, GRIB_LOG_ERROR, "value[%d]\t= %g", j, grib_darray_get (grib_vdarray_get (self->numericValues, elementIndex), j) ); } } else { - if (self->numericValues->v[subsetIndex] == NULL) { + //if (self->numericValues->v[subsetIndex] == NULL) { + if ( grib_vdarray_get (self->numericValues, subsetIndex) == NULL) { grib_context_log(c, GRIB_LOG_ERROR, "Invalid subset index %d (number of subsets=%ld)", subsetIndex, self->numberOfSubsets); return GRIB_INVALID_ARGUMENT; } - err = encode_double_value(c, buff, pos, bd, self, self->numericValues->v[subsetIndex]->v[elementIndex]); + //err = encode_double_value(c, buff, pos, bd, self, self->numericValues->v[subsetIndex]->v[elementIndex]); + err = encode_double_value(c, buff, pos, bd, self, grib_darray_get ( grib_vdarray_get (self->numericValues, subsetIndex) , elementIndex) ); + if (err) { grib_context_log(c, GRIB_LOG_ERROR, "Cannot encode %s=%g (subset=%d)", /*subsetIndex starts from 0*/ - bd->shortName, self->numericValues->v[subsetIndex]->v[elementIndex], subsetIndex + 1); + bd->shortName, grib_darray_get( grib_vdarray_get (self->numericValues, subsetIndex), elementIndex ), subsetIndex + 1); + // bd->shortName, self->numericValues->v[subsetIndex]->v[elementIndex], subsetIndex + 1); } } } @@ -1492,11 +1518,16 @@ static int encode_replication(grib_context* c, grib_accessor_bufr_data_array* se { /* Assert( buff->data == data); */ if (self->compressedData) { - DebugAssert(grib_darray_used_size(self->numericValues->v[elementIndex]) == 1); - *numberOfRepetitions = self->numericValues->v[elementIndex]->v[0]; + //DebugAssert(grib_darray_used_size(self->numericValues->v[elementIndex]) == 1); + DebugAssert(grib_darray_used_size(grib_vdarray_get (self->numericValues, elementIndex)) == 1); + //*numberOfRepetitions = self->numericValues->v[elementIndex]->v[0]; + //*numberOfRepetitions = grib_darray_get (self->numericValues->v[elementIndex], 0); + *numberOfRepetitions = grib_darray_get (grib_vdarray_get (self->numericValues, elementIndex), 0); } else { - *numberOfRepetitions = self->numericValues->v[subsetIndex]->v[elementIndex]; + //*numberOfRepetitions = self->numericValues->v[subsetIndex]->v[elementIndex]; + //*numberOfRepetitions = grib_darray_get (self->numericValues->v[subsetIndex], elementIndex); + *numberOfRepetitions = grib_darray_get (grib_vdarray_get (self->numericValues, subsetIndex), elementIndex); } return encode_element(c, self, subsetIndex, buff, data, pos, i, 0, elementIndex, dval, 0); @@ -1510,7 +1541,8 @@ static int build_bitmap(grib_accessor_bufr_data_array* self, unsigned char* data grib_accessor* a = (grib_accessor*)self; grib_context* c = a->context; bufr_descriptor** descriptors = self->expanded->v; - long* edi = elementsDescriptorsIndex->v; + //long* edi = elementsDescriptorsIndex->v; + long descriptorVal = 0; /* int iel=grib_iarray_used_size(elementsDescriptorsIndex)-1; */ int err = 0; @@ -1522,11 +1554,14 @@ static int build_bitmap(grib_accessor_bufr_data_array* self, unsigned char* data if (iel < 0) { return GRIB_ENCODING_ERROR; } - while (descriptors[edi[iel]]->code >= 100000 || iel == 0) { + descriptorVal = grib_iarray_get(elementsDescriptorsIndex,iel); + //while (descriptors[edi[iel]]->code >= 100000 || iel == 0) { + while (descriptors[descriptorVal]->code >= 100000 || iel == 0) { iel--; if (iel < 0) { return GRIB_ENCODING_ERROR; } + descriptorVal = grib_iarray_get(elementsDescriptorsIndex,iel); } bitmapEndElementsDescriptorsIndex = iel; /*looking for another bitmap and pointing before it. @@ -1534,11 +1569,17 @@ static int build_bitmap(grib_accessor_bufr_data_array* self, unsigned char* data ECC-243 */ while (iel > 0) { - while (descriptors[edi[iel]]->code != 236000 && descriptors[edi[iel]]->code != 222000 && descriptors[edi[iel]]->code != 223000 && iel != 0) + descriptorVal = grib_iarray_get(elementsDescriptorsIndex,iel); + //while (descriptors[edi[iel]]->code != 236000 && descriptors[edi[iel]]->code != 222000 && descriptors[edi[iel]]->code != 223000 && iel != 0) + while (descriptors[descriptorVal]->code != 236000 && descriptors[descriptorVal]->code != 222000 && descriptors[descriptorVal]->code != 223000 && iel != 0) iel--; if (iel != 0) { - while (descriptors[edi[iel]]->code >= 100000 && iel != 0) + descriptorVal = grib_iarray_get(elementsDescriptorsIndex,iel); + //while (descriptors[edi[iel]]->code >= 100000 && iel != 0) + while (descriptors[descriptorVal]->code >= 100000 && iel != 0) { iel--; + descriptorVal = grib_iarray_get(elementsDescriptorsIndex,iel); + } bitmapEndElementsDescriptorsIndex = iel; } } @@ -1584,7 +1625,9 @@ static int build_bitmap(grib_accessor_bufr_data_array* self, unsigned char* data iel = bitmapEndElementsDescriptorsIndex; n = bitmapSize - 1; while (n > 0 && iel >= 0) { - if (descriptors[edi[iel]]->code < 100000) + descriptorVal = grib_iarray_get(elementsDescriptorsIndex,iel); + //if (descriptors[edi[iel]]->code < 100000) + if (descriptors[descriptorVal]->code < 100000) n--; iel--; } @@ -1638,20 +1681,26 @@ static int build_bitmap_new_data(grib_accessor_bufr_data_array* self, unsigned c grib_accessor* a = (grib_accessor*)self; grib_context* c = a->context; bufr_descriptor** descriptors = self->expanded->v; - long* edi = elementsDescriptorsIndex->v; + //long* edi = elementsDescriptorsIndex->v; + long descriptorVal = 0; switch (descriptors[iBitmapOperator]->code) { case 222000: case 223000: case 236000: + if (iel < 0) { return GRIB_ENCODING_ERROR; } - while (descriptors[edi[iel]]->code >= 100000) { + + descriptorVal = grib_iarray_get(elementsDescriptorsIndex,iel); + //while (descriptors[edi[iel]]->code >= 100000) { + while (descriptors[descriptorVal]->code >= 100000) { iel--; if (iel < 0) { return GRIB_ENCODING_ERROR; } + descriptorVal = grib_iarray_get(elementsDescriptorsIndex,iel); } bitmapEndElementsDescriptorsIndex = iel; /*looking for another bitmap and pointing before it. @@ -1659,11 +1708,16 @@ static int build_bitmap_new_data(grib_accessor_bufr_data_array* self, unsigned c ECC-243 */ while (iel > 0) { - while (descriptors[edi[iel]]->code != 236000 && descriptors[edi[iel]]->code != 222000 && descriptors[edi[iel]]->code != 223000 && iel != 0) + descriptorVal = grib_iarray_get(elementsDescriptorsIndex,iel); + //while (descriptors[edi[iel]]->code != 236000 && descriptors[edi[iel]]->code != 222000 && descriptors[edi[iel]]->code != 223000 && iel != 0) + while (descriptors[descriptorVal]->code != 236000 && descriptors[descriptorVal]->code != 222000 && descriptors[descriptorVal]->code != 223000 && iel != 0) iel--; if (iel != 0) { - while (descriptors[edi[iel]]->code >= 100000 && iel != 0) + descriptorVal = grib_iarray_get(elementsDescriptorsIndex,iel); + while (descriptors[descriptorVal]->code >= 100000 && iel != 0){ iel--; + descriptorVal = grib_iarray_get(elementsDescriptorsIndex,iel); + } bitmapEndElementsDescriptorsIndex = iel; } } @@ -1700,7 +1754,9 @@ static int build_bitmap_new_data(grib_accessor_bufr_data_array* self, unsigned c iel = bitmapEndElementsDescriptorsIndex; n = bitmapSize - 1; while (n > 0 && iel >= 0) { - if (descriptors[edi[iel]]->code < 100000) + descriptorVal = grib_iarray_get(elementsDescriptorsIndex,iel); + //if (descriptors[edi[iel]]->code < 100000) + if (descriptors[descriptorVal]->code < 100000) n--; iel--; } @@ -1731,7 +1787,8 @@ static int get_next_bitmap_descriptor_index_new_bitmap(grib_accessor_bufr_data_a while (self->inputBitmap[i] == 1) { self->bitmapCurrent++; self->bitmapCurrentElementsDescriptorsIndex++; - while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]]->code > 100000) + //while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]]->code > 100000) + while (descriptors[ grib_iarray_get(elementsDescriptorsIndex, self->bitmapCurrentElementsDescriptorsIndex) ]->code > 100000) self->bitmapCurrentElementsDescriptorsIndex++; i++; } @@ -1742,14 +1799,17 @@ static int get_next_bitmap_descriptor_index_new_bitmap(grib_accessor_bufr_data_a while (self->inputBitmap[i] == 1) { self->bitmapCurrent++; self->bitmapCurrentElementsDescriptorsIndex++; - while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]]->code > 100000) + //while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]]->code > 100000) + while (descriptors[ grib_iarray_get(elementsDescriptorsIndex, self->bitmapCurrentElementsDescriptorsIndex) ]->code > 100000) self->bitmapCurrentElementsDescriptorsIndex++; i++; } } - while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]]->code > 100000) + //while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]]->code > 100000) + while (descriptors[ grib_iarray_get(elementsDescriptorsIndex, self->bitmapCurrentElementsDescriptorsIndex) ]->code > 100000) self->bitmapCurrentElementsDescriptorsIndex++; - return elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]; + //return elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]; + return grib_iarray_get(elementsDescriptorsIndex, self->bitmapCurrentElementsDescriptorsIndex) ; } static int get_next_bitmap_descriptor_index(grib_accessor_bufr_data_array* self, grib_iarray* elementsDescriptorsIndex, grib_darray* numericValues) @@ -1758,17 +1818,22 @@ static int get_next_bitmap_descriptor_index(grib_accessor_bufr_data_array* self, bufr_descriptor** descriptors = self->expanded->v; if (self->compressedData) { - if (self->numericValues->n == 0) + //if (self->numericValues->n == 0) + if (grib_vdarray_used_size (self->numericValues) == 0) return get_next_bitmap_descriptor_index_new_bitmap(self, elementsDescriptorsIndex, 1); self->bitmapCurrent++; self->bitmapCurrentElementsDescriptorsIndex++; i = self->bitmapCurrent + self->bitmapStart; - DebugAssert(i < self->numericValues->n); - while (self->numericValues->v[i]->v[0] == 1) { + //DebugAssert(i < self->numericValues->n); + DebugAssert(i < grib_vdarray_used_size (self->numericValues)); + //while (self->numericValues->v[i]->v[0] == 1) { + //while ( grib_darray_get (self->numericValues->v[i], 0) == 1) { + while ( grib_darray_get (grib_vdarray_get (self->numericValues, i), 0) == 1) { self->bitmapCurrent++; self->bitmapCurrentElementsDescriptorsIndex++; - while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]]->code > 100000) + //while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]]->code > 100000) + while (descriptors[ grib_iarray_get(elementsDescriptorsIndex, self->bitmapCurrentElementsDescriptorsIndex) ]->code > 100000) self->bitmapCurrentElementsDescriptorsIndex++; i++; } @@ -1780,18 +1845,23 @@ static int get_next_bitmap_descriptor_index(grib_accessor_bufr_data_array* self, self->bitmapCurrent++; self->bitmapCurrentElementsDescriptorsIndex++; i = self->bitmapCurrent + self->bitmapStart; - DebugAssert(i < numericValues->n); - while (numericValues->v[i] == 1) { + DebugAssert(i < grib_vdarray_used_size (self->numericValues)); + //while (numericValues->v[i] == 1) { + while ( grib_darray_get(numericValues,i) == 1){ self->bitmapCurrent++; self->bitmapCurrentElementsDescriptorsIndex++; - while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]]->code > 100000) + //while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]]->code > 100000) + while (descriptors[ grib_iarray_get(elementsDescriptorsIndex, self->bitmapCurrentElementsDescriptorsIndex) ]->code > 100000) self->bitmapCurrentElementsDescriptorsIndex++; i++; } } - while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]]->code > 100000) + //while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]]->code > 100000) { + while (descriptors [ grib_iarray_get(elementsDescriptorsIndex, self->bitmapCurrentElementsDescriptorsIndex) ]->code > 100000) { self->bitmapCurrentElementsDescriptorsIndex++; - return elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]; + } + //return elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]; + return grib_iarray_get(elementsDescriptorsIndex, self->bitmapCurrentElementsDescriptorsIndex) ; } static void push_zero_element(grib_accessor_bufr_data_array* self, grib_darray* dval) @@ -1956,7 +2026,11 @@ static grib_accessor* create_accessor_from_descriptor(grib_accessor* a, grib_acc operatorCreator.flags |= GRIB_ACCESSOR_FLAG_DUMP; } - idx = self->compressedData ? self->elementsDescriptorsIndex->v[0]->v[ide] : self->elementsDescriptorsIndex->v[subset]->v[ide]; + //idx = self->compressedData ? self->elementsDescriptorsIndex->v[0]->v[ide] : self->elementsDescriptorsIndex->v[subset]->v[ide]; + //idx = self->compressedData ? (grib_iarray_get(self->elementsDescriptorsIndex->v[0],ide)) : (grib_iarray_get(self->elementsDescriptorsIndex->v[subset],ide)); + idx = self->compressedData ? + (grib_iarray_get( grib_viarray_get (self->elementsDescriptorsIndex, 0),ide)) : + (grib_iarray_get( grib_viarray_get (self->elementsDescriptorsIndex, subset),ide)); switch (self->expanded->v[idx]->F) { case 0: @@ -2193,7 +2267,8 @@ static void grib_convert_to_attribute(grib_accessor* a) static grib_iarray* set_subset_list(grib_context* c, grib_accessor_bufr_data_array* self, long onlySubset, long startSubset, long endSubset, long* subsetList, size_t subsetListSize) { - grib_iarray* list = grib_iarray_new(c, self->numberOfSubsets, 10); + //grib_iarray* list = grib_iarray_new(c, self->numberOfSubsets, 10); + grib_iarray* list = grib_iarray_new(c, self->numberOfSubsets, self->numberOfSubsets); long s; if (startSubset > 0) { @@ -2450,7 +2525,8 @@ static int create_keys(grib_accessor* a, long onlySubset, long startSubset, long grib_sarray_delete(c, self->tempStrings); self->tempStrings = NULL; } - self->tempStrings = grib_sarray_new(c, self->numberOfSubsets, 500); + //magic number 500 is not even documented anywhere... + self->tempStrings = grib_sarray_new(c, self->numberOfSubsets, DYN_DEFAULT_SARRAY_SIZE_INCR); end = self->compressedData ? 1 : self->numberOfSubsets; groupNumber = 1; @@ -2477,7 +2553,9 @@ static int create_keys(grib_accessor* a, long onlySubset, long startSubset, long for (iss = 0; iss < end; iss++) { qualityPresent = 0; /*forceGroupClosure=0;*/ - elementsInSubset = self->compressedData ? grib_iarray_used_size(self->elementsDescriptorsIndex->v[0]) : grib_iarray_used_size(self->elementsDescriptorsIndex->v[iss]); + //elementsInSubset = self->compressedData ? grib_iarray_used_size(self->elementsDescriptorsIndex->v[0]) : grib_iarray_used_size(self->elementsDescriptorsIndex->v[iss]); + elementsInSubset = self->compressedData ? (grib_iarray_used_size (grib_viarray_get(self->elementsDescriptorsIndex,0))) : (grib_iarray_used_size(grib_viarray_get(self->elementsDescriptorsIndex,iss))); + /*if (associatedFieldAccessor) grib_accessor_delete(c, associatedFieldAccessor);*/ associatedFieldAccessor = NULL; if (associatedFieldSignificanceAccessor) { @@ -2485,7 +2563,11 @@ static int create_keys(grib_accessor* a, long onlySubset, long startSubset, long associatedFieldSignificanceAccessor = NULL; } for (ide = 0; ide < elementsInSubset; ide++) { - idx = self->compressedData ? self->elementsDescriptorsIndex->v[0]->v[ide] : self->elementsDescriptorsIndex->v[iss]->v[ide]; + //idx = self->compressedData ? self->elementsDescriptorsIndex->v[0]->v[ide] : self->elementsDescriptorsIndex->v[iss]->v[ide]; + //idx = self->compressedData ? (grib_iarray_get(self->elementsDescriptorsIndex->v[0],ide)) : (grib_iarray_get(self->elementsDescriptorsIndex->v[iss],ide)); + idx = self->compressedData ? + grib_iarray_get ( grib_viarray_get (self->elementsDescriptorsIndex, 0), ide) : + grib_iarray_get ( grib_viarray_get (self->elementsDescriptorsIndex, iss), ide); descriptor = self->expanded->v[idx]; if (descriptor->nokey == 1) { @@ -2801,7 +2883,7 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st bufr_descriptor** descriptors = 0; long icount; int decoding = 0, do_clean = 1; - grib_buffer* buffer = NULL; + grib_buffer* buffer = NULL; // @suppress("Symbol is not resolved") codec_element_proc codec_element; codec_replication_proc codec_replication; grib_accessor* dataAccessor = NULL; @@ -2887,12 +2969,14 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st } if (flag != PROCESS_ENCODE) { - self->numericValues = grib_vdarray_new(c, 1000, 1000); - self->stringValues = grib_vsarray_new(c, 10, 10); + //self->numericValues = grib_vdarray_new(c, 1000, 1000); + self->numericValues = grib_vdarray_new(c, (DYN_DEFAULT_VDARRAY_SIZE_INIT*2), (DYN_DEFAULT_VDARRAY_SIZE_INCR*2)); + //self->stringValues = grib_vsarray_new(c, 10, 10); + self->stringValues = grib_vsarray_new(c, DYN_DEFAULT_VSARRAY_SIZE_INIT, DYN_DEFAULT_VSARRAY_SIZE_INCR); if (self->elementsDescriptorsIndex) grib_viarray_delete(c, self->elementsDescriptorsIndex); - self->elementsDescriptorsIndex = grib_viarray_new(c, 100, 100); + self->elementsDescriptorsIndex = grib_viarray_new(c, DYN_DEFAULT_VIARRAY_SIZE_INIT, DYN_DEFAULT_VIARRAY_SIZE_INCR); } if (flag != PROCESS_DECODE) { /* Operator 203YYY: key OVERRIDDEN_REFERENCE_VALUES_KEY */ @@ -2925,7 +3009,8 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st for (iiss = 0; iiss < end; iiss++) { icount = 1; if (self->compressedData == 0 && self->iss_list) { - iss = self->iss_list->v[iiss]; + //iss = self->iss_list->v[iiss]; + iss = grib_iarray_get(self->iss_list, iiss); } else { iss = iiss; @@ -2935,18 +3020,20 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st self->refValIndex = 0; if (flag != PROCESS_ENCODE) { - elementsDescriptorsIndex = grib_iarray_new(c, DYN_ARRAY_SIZE_INIT, DYN_ARRAY_SIZE_INCR); + elementsDescriptorsIndex = grib_iarray_new(c, DYN_DEFAULT_IARRAY_SIZE_INIT, DYN_DEFAULT_IARRAY_SIZE_INCR); if (!self->compressedData) { - dval = grib_darray_new(c, DYN_ARRAY_SIZE_INIT, DYN_ARRAY_SIZE_INCR); - /* sval=grib_sarray_new(c,10,10); */ + dval = grib_darray_new(c, DYN_DEFAULT_DARRAY_SIZE_INIT, DYN_DEFAULT_DARRAY_SIZE_INCR); + /* THIS CODE WA ALREADY COMMENTED OUT IN THE ORIGINAL CODE sval=grib_sarray_new(c,10,10); */ } } else { if (self->elementsDescriptorsIndex == NULL) { return GRIB_ENCODING_ERROR; /* See ECC-359 */ } - elementsDescriptorsIndex = self->elementsDescriptorsIndex->v[iss]; - dval = self->numericValues->v[iss]; + //elementsDescriptorsIndex = self->elementsDescriptorsIndex->v[iss]; + elementsDescriptorsIndex = grib_viarray_get(self->elementsDescriptorsIndex, iss); + //dval = self->numericValues->v[iss]; + dval = grib_vdarray_get(self->numericValues, iss); } elementIndex = 0; @@ -2960,7 +3047,7 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st if (flag != PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex, i); if (descriptors[i]->code == 31031 && !is_bitmap_start_defined(self)) { - /* self->bitmapStart=grib_iarray_used_size(elementsDescriptorsIndex)-1; */ + /* THIS CODE WA ALREADY COMMENTED OUT IN THE ORIGINAL CODE self->bitmapStart=grib_iarray_used_size(elementsDescriptorsIndex)-1; */ self->bitmapStart = elementIndex; } @@ -3117,7 +3204,7 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st err = codec_element(c, self, iss, buffer, data, &pos, index, 0, elementIndex, dval, sval); if (err) return err; - /* self->expanded->v[index] */ + /* THIS CODE WA ALREADY COMMENTED OUT IN THE ORIGINAL CODE self->expanded->v[index] */ if (flag != PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex, i); elementIndex++; @@ -3137,7 +3224,7 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st err = codec_element(c, self, iss, buffer, data, &pos, index, 0, elementIndex, dval, sval); if (err) return err; - /* self->expanded->v[index] */ + /* THIS CODE WA ALREADY COMMENTED OUT IN THE ORIGINAL CODE self->expanded->v[index] */ if (flag != PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex, i); elementIndex++; @@ -3179,7 +3266,7 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st grib_bufr_descriptor_delete(bd); if (err) return err; - /* self->expanded->v[index] */ + /* THIS CODE WA ALREADY COMMENTED OUT IN THE ORIGINAL CODE self->expanded->v[index] */ if (flag != PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex, i); elementIndex++; @@ -3349,8 +3436,10 @@ static int value_count(grib_accessor* a, long* count) } else { *count = 0; - for (i = 0; i < self->numberOfSubsets; i++) - *count += grib_iarray_used_size(self->elementsDescriptorsIndex->v[i]); + for (i = 0; i < self->numberOfSubsets; i++) { + //*count += grib_iarray_used_size(self->elementsDescriptorsIndex->v[i]); + *count += grib_iarray_used_size( grib_viarray_get (self->elementsDescriptorsIndex, i) ); + } } return err; @@ -3386,16 +3475,25 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) ii = 0; for (k = 0; k < numberOfSubsets; k++) { for (i = 0; i < l; i++) { - val[ii++] = self->numericValues->v[i]->n > 1 ? self->numericValues->v[i]->v[k] : self->numericValues->v[i]->v[0]; + //val[ii++] = self->numericValues->v[i]->n > 1 ? self->numericValues->v[i]->v[k] : self->numericValues->v[i]->v[0]; +// val[ii++] = self->numericValues->v[i]->n > 1 ? +// grib_darray_get (self->numericValues->v[i], k) : +// grib_darray_get (self->numericValues->v[i], 0); + val[ii++] = grib_darray_used_size(grib_vdarray_get (self->numericValues, i)) > 1 ? + grib_darray_get (grib_vdarray_get (self->numericValues, i), k) : + grib_darray_get (grib_vdarray_get (self->numericValues, i), 0); } } } else { ii = 0; for (k = 0; k < numberOfSubsets; k++) { - elementsInSubset = grib_iarray_used_size(self->elementsDescriptorsIndex->v[k]); + //elementsInSubset = grib_iarray_used_size(self->elementsDescriptorsIndex->v[k]); + elementsInSubset = grib_iarray_used_size( grib_viarray_get (self->elementsDescriptorsIndex, k) ); for (i = 0; i < elementsInSubset; i++) { - val[ii++] = self->numericValues->v[k]->v[i]; + //val[ii++] = self->numericValues->v[k]->v[i]; + //val[ii++] = grib_darray_get (self->numericValues->v[k], i); + val[ii++] = grib_darray_get (grib_vdarray_get (self->numericValues, k), i); } } } diff --git a/src/grib_accessor_class_bufr_data_element.c b/src/grib_accessor_class_bufr_data_element.c index a3fa0efca..94ec346ae 100644 --- a/src/grib_accessor_class_bufr_data_element.c +++ b/src/grib_accessor_class_bufr_data_element.c @@ -10,6 +10,7 @@ /***************************************** * Enrico Fucile + * Modified for Performance Study by: CS GMBH ****************************************/ #include "grib_api_internal.h" @@ -295,20 +296,30 @@ static int unpack_string_array(grib_accessor* a, char** val, size_t* len) grib_context* c = a->context; if (self->compressedData) { - DebugAssert(self->index < self->numericValues->n); - idx = ((int)self->numericValues->v[self->index]->v[0] / 1000 - 1) / self->numberOfSubsets; - DebugAssert(idx < self->stringValues->n); - count = grib_sarray_used_size(self->stringValues->v[idx]); + //DebugAssert(self->index < self->numericValues->n); + DebugAssert(self->index < grib_vdarray_used_size (self->numericValues)); + //idx = ((int)self->numericValues->v[self->index]->v[0] / 1000 - 1) / self->numberOfSubsets; + //idx = ( (int) grib_darray_get (self->numericValues->v[self->index], 0) / 1000 - 1) / self->numberOfSubsets; + idx = ( (int) grib_darray_get (grib_vdarray_get (self->numericValues, self->index), 0) / 1000 - 1) / self->numberOfSubsets; + //DebugAssert(idx < self->stringValues->n); + DebugAssert(idx < grib_vsarray_used_size(self->stringValues)); + //count = grib_sarray_used_size(self->stringValues->v[idx]); + count = grib_sarray_used_size(grib_vsarray_get(self->stringValues,idx)); for (i = 0; i < count; i++) { - val[i] = grib_context_strdup(c, self->stringValues->v[idx]->v[i]); + //val[i] = grib_context_strdup(c, self->stringValues->v[idx]->v[i]); + val[i] = grib_context_strdup(c, grib_sarray_get(grib_vsarray_get(self->stringValues,idx),i)); } *len = count; } else { - DebugAssert(self->subsetNumber < self->numericValues->n); - DebugAssert(self->index < self->numericValues->v[self->subsetNumber]->n); - idx = (int)self->numericValues->v[self->subsetNumber]->v[self->index] / 1000 - 1; - val[0] = grib_context_strdup(c, self->stringValues->v[idx]->v[0]); + DebugAssert(self->subsetNumber < grib_vdarray_used_size (self->numericValues)); + DebugAssert(self->index < grib_darray_used_size(grib_vdarray_get (self->numericValues, self->subsetNumber)) ); + //idx = (int)self->numericValues->v[self->subsetNumber]->v[self->index] / 1000 - 1; + //idx = (int) grib_darray_get ( self->numericValues->v[self->subsetNumber], self->index) / 1000 - 1; + idx = (int) grib_darray_get ( grib_vdarray_get (self->numericValues, self->subsetNumber), self->index) / 1000 - 1; + //val[0] = grib_context_strdup(c, self->stringValues->v[idx]->v[0]); + //val[0] = grib_context_strdup(c, grib_sarray_get(self->stringValues->v[idx],0)); + val[0] = grib_context_strdup(c, grib_sarray_get(grib_vsarray_get(self->stringValues,idx),0)); *len = 1; } @@ -324,17 +335,21 @@ static int pack_string_array(grib_accessor* a, const char** v, size_t* len) grib_context* c = a->context; if (self->compressedData) { - idx = ((int)self->numericValues->v[self->index]->v[0] / 1000 - 1) / self->numberOfSubsets; + //idx = ((int)self->numericValues->v[self->index]->v[0] / 1000 - 1) / self->numberOfSubsets; + idx = ((int) grib_darray_get (grib_vdarray_get (self->numericValues, self->index), 0 ) / 1000 - 1) / self->numberOfSubsets; if (*len != 1 && *len != self->numberOfSubsets) { grib_context_log(c, GRIB_LOG_ERROR, "Number of values mismatch for '%s': %ld strings provided but expected %ld (=number of subsets)", - self->descriptors->v[self->elementsDescriptorsIndex->v[0]->v[idx]]->shortName, *len, self->numberOfSubsets); + // self->descriptors->v[self->elementsDescriptorsIndex->v[0]->v[idx]]->shortName, *len, self->numberOfSubsets); + self->descriptors->v[ grib_iarray_get ( grib_viarray_get (self->elementsDescriptorsIndex, 0), idx) ]->shortName, *len, self->numberOfSubsets); return GRIB_ARRAY_TOO_SMALL; } - grib_sarray_delete(c, self->stringValues->v[idx]); - self->stringValues->v[idx] = grib_sarray_new(c, *len, 1); + grib_sarray_delete(c, grib_vsarray_get(self->stringValues,idx)); + //self->stringValues->v[idx] = grib_sarray_new(c, *len, 1); + //self->stringValues->v[idx] = grib_sarray_new(c, *len, *len ); + grib_vsarray_put ( self->stringValues, idx, grib_sarray_new(c, *len, *len )); for (i = 0; i < *len; i++) { s = grib_context_strdup(c, v[i]); - grib_sarray_push(c, self->stringValues->v[idx], s); + grib_sarray_push(c, grib_vsarray_get(self->stringValues,idx), s); } } else { @@ -368,19 +383,25 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len) } if (self->compressedData) { - DebugAssert(self->index < self->numericValues->n); - idx = ((int)self->numericValues->v[self->index]->v[0] / 1000 - 1) / self->numberOfSubsets; + DebugAssert(self->index < grib_vdarray_used_size (self->numericValues)); + //idx = ((int)self->numericValues->v[self->index]->v[0] / 1000 - 1) / self->numberOfSubsets; + idx = ((int) grib_darray_get (grib_vdarray_get (self->numericValues, self->index), 0) / 1000 - 1) / self->numberOfSubsets; if (idx < 0) return GRIB_INTERNAL_ERROR; - str = grib_context_strdup(c, self->stringValues->v[idx]->v[0]); + //str = grib_context_strdup(c, self->stringValues->v[idx]->v[0]); + //str = grib_context_strdup(c, grib_sarray_get(self->stringValues->v[idx],0)); + str = grib_context_strdup(c, grib_sarray_get( grib_vsarray_get(self->stringValues,idx),0)); } else { - DebugAssert(self->subsetNumber < self->numericValues->n); - idx = (int)self->numericValues->v[self->subsetNumber]->v[self->index] / 1000 - 1; + DebugAssert(self->subsetNumber < grib_vdarray_used_size (self->numericValues)); + //idx = (int)self->numericValues->v[self->subsetNumber]->v[self->index] / 1000 - 1; + idx = (int) grib_darray_get (grib_vdarray_get (self->numericValues, self->subsetNumber), self->index) / 1000 - 1; if (idx < 0) return GRIB_INTERNAL_ERROR; - DebugAssert(idx < self->stringValues->n); - str = grib_context_strdup(c, self->stringValues->v[idx]->v[0]); + //DebugAssert(idx < self->stringValues->n); + DebugAssert(idx < grib_vsarray_used_size(self->stringValues)); + //str = grib_context_strdup(c, self->stringValues->v[idx]->v[0]); + str = grib_context_strdup(c, grib_sarray_get(grib_vsarray_get(self->stringValues,idx),0)); } if (str == 0 || strlen(str) == 0) { @@ -420,15 +441,20 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len) grib_context* c = a->context; if (self->compressedData) { - idx = ((int)self->numericValues->v[self->index]->v[0] / 1000 - 1) / self->numberOfSubsets; + // idx = ((int)self->numericValues->v[self->index]->v[0] / 1000 - 1) / self->numberOfSubsets; + idx = ((int) grib_darray_get ( grib_vdarray_get (self->numericValues, self->index), 0) / 1000 - 1) / self->numberOfSubsets; } else { - idx = (int)self->numericValues->v[self->subsetNumber]->v[self->index] / 1000 - 1; + //idx = (int)self->numericValues->v[self->subsetNumber]->v[self->index] / 1000 - 1; + idx = (int) grib_darray_get ( grib_vdarray_get (self->numericValues, self->subsetNumber), self->index) / 1000 - 1; } - grib_sarray_delete(c, self->stringValues->v[idx]); - self->stringValues->v[idx] = grib_sarray_new(c, 1, 1); + //grib_sarray_delete(c, self->stringValues->v[idx]); + grib_sarray_delete(c, grib_vsarray_get(self->stringValues,idx)); + //self->stringValues->v[idx] = grib_sarray_new(c, 1, 1); + grib_vsarray_put(self->stringValues, idx, grib_sarray_new(c, 1, 1)); s = grib_context_strdup(c, val); - grib_sarray_push(c, self->stringValues->v[idx], s); + //grib_sarray_push(c, self->stringValues->v[idx], s); + grib_sarray_push(c, grib_vsarray_get(self->stringValues, idx), s); return ret; } @@ -446,16 +472,27 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) if (self->compressedData) { for (i = 0; i < count; i++) { - DebugAssert(self->index < self->numericValues->n); - DebugAssert(i < self->numericValues->v[self->index]->n); - val[i] = self->numericValues->v[self->index]->v[i] == GRIB_MISSING_DOUBLE ? GRIB_MISSING_LONG : (long)self->numericValues->v[self->index]->v[i]; + //DebugAssert(self->index < self->numericValues->n); + DebugAssert(self->index < grib_vdarray_used_size (self->numericValues) ); + //DebugAssert(i < self->numericValues->v[self->index]->n); + DebugAssert(i < grib_darray_used_size (grib_vdarray_get (self->numericValues, self->index)) ); + //val[i] = self->numericValues->v[self->index]->v[i] == GRIB_MISSING_DOUBLE ? GRIB_MISSING_LONG : (long)self->numericValues->v[self->index]->v[i]; + val[i] = (grib_darray_get (grib_vdarray_get (self->numericValues, self->index), i) == GRIB_MISSING_DOUBLE ) ? + GRIB_MISSING_LONG : + (long) grib_darray_get ( grib_vdarray_get (self->numericValues, self->index), i); } *len = count; } else { - DebugAssert(self->subsetNumber < self->numericValues->n); - DebugAssert(self->index < self->numericValues->v[self->subsetNumber]->n); - val[0] = self->numericValues->v[self->subsetNumber]->v[self->index] == GRIB_MISSING_DOUBLE ? GRIB_MISSING_LONG : (long)self->numericValues->v[self->subsetNumber]->v[self->index]; + //DebugAssert(self->subsetNumber < self->numericValues->n); + DebugAssert(self->subsetNumber < grib_vdarray_used_size (self->numericValues) ); + //DebugAssert(self->index < self->numericValues->v[self->subsetNumber]->n); + DebugAssert(self->index < grib_darray_used_size (grib_vdarray_get (self->numericValues, self->subsetNumber)) ); + + //val[0] = self->numericValues->v[self->subsetNumber]->v[self->index] == GRIB_MISSING_DOUBLE ? GRIB_MISSING_LONG : (long)self->numericValues->v[self->subsetNumber]->v[self->index]; + val[0] = ( grib_darray_get (grib_vdarray_get (self->numericValues, self->subsetNumber), self->index ) == GRIB_MISSING_DOUBLE ) ? + GRIB_MISSING_LONG : + (long) grib_darray_get ( grib_vdarray_get (self->numericValues, self->subsetNumber), self->index ); *len = 1; } @@ -475,16 +512,24 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) if (self->compressedData) { for (i = 0; i < count; i++) { - DebugAssert(self->index < self->numericValues->n); - DebugAssert(i < self->numericValues->v[self->index]->n); - val[i] = self->numericValues->v[self->index]->v[i]; + //DebugAssert(self->index < self->numericValues->n); + //DebugAssert(i < self->numericValues->v[self->index]->n); + DebugAssert(self->index < grib_vdarray_used_size (self->numericValues)); + DebugAssert(i < grib_darray_used_size (grib_vdarray_get (self->numericValues, self->index)) ); + + //val[i] = self->numericValues->v[self->index]->v[i]; + val[i] = grib_darray_get ( grib_vdarray_get (self->numericValues, self->index) , i ); } *len = count; } else { - DebugAssert(self->subsetNumber < self->numericValues->n); - DebugAssert(self->index < self->numericValues->v[self->subsetNumber]->n); - val[0] = self->numericValues->v[self->subsetNumber]->v[self->index]; + //DebugAssert(self->subsetNumber < self->numericValues->n); + //DebugAssert(self->index < self->numericValues->v[self->subsetNumber]->n); + DebugAssert(self->subsetNumber < grib_vdarray_used_size (self->numericValues)); + DebugAssert(self->index < grib_darray_used_size (grib_vdarray_get (self->numericValues, self->subsetNumber))); + + //val[0] = self->numericValues->v[self->subsetNumber]->v[self->index]; + val[0] = grib_darray_get ( grib_vdarray_get (self->numericValues, self->subsetNumber), self->index ); *len = 1; } @@ -502,20 +547,23 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) count = *len; if (count != 1 && count != self->numberOfSubsets) { grib_context_log(c, GRIB_LOG_ERROR, "Number of values mismatch for '%s': %ld doubles provided but expected %ld (=number of subsets)", - self->descriptors->v[self->elementsDescriptorsIndex->v[0]->v[self->index]]->shortName, count, self->numberOfSubsets); + //self->descriptors->v[self->elementsDescriptorsIndex->v[0]->v[self->index]]->shortName, count, self->numberOfSubsets); + self->descriptors->v[ grib_iarray_get ( grib_viarray_get (self->elementsDescriptorsIndex, 0), self->index) ]->shortName, count, self->numberOfSubsets); return GRIB_ARRAY_TOO_SMALL; } - grib_darray_delete(a->context, self->numericValues->v[self->index]); - self->numericValues->v[self->index] = grib_darray_new(a->context, count, 1); + grib_darray_delete(a->context, grib_vdarray_get (self->numericValues, self->index) ); + //self->numericValues->v[self->index] = grib_darray_new(a->context, count, 1); + grib_vdarray_put (self->numericValues, self->index, grib_darray_new(a->context, count, 1)); for (i = 0; i < count; i++) - grib_darray_push(a->context, self->numericValues->v[self->index], val[i]); + grib_darray_push(a->context, grib_vdarray_get (self->numericValues, self->index), val[i]); *len = count; } else { - self->numericValues->v[self->subsetNumber]->v[self->index] = val[0]; - *len = 1; + //self->numericValues->v[self->subsetNumber]->v[self->index] = val[0]; + grib_darray_put(grib_vdarray_get (self->numericValues, self->subsetNumber), self->index, val[0]); + *len = 1; } return ret; @@ -532,20 +580,24 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) count = *len; if (count != 1 && count != self->numberOfSubsets) { grib_context_log(c, GRIB_LOG_ERROR, "Number of values mismatch for '%s': %ld integers provided but expected %ld (=number of subsets)", - self->descriptors->v[self->elementsDescriptorsIndex->v[0]->v[self->index]]->shortName, count, self->numberOfSubsets); + //self->descriptors->v[self->elementsDescriptorsIndex->v[0]->v[self->index]]->shortName, count, self->numberOfSubsets); + self->descriptors->v[ grib_iarray_get ( grib_viarray_get (self->elementsDescriptorsIndex, 0), self->index) ]->shortName, count, self->numberOfSubsets); return GRIB_ARRAY_TOO_SMALL; } - grib_darray_delete(a->context, self->numericValues->v[self->index]); - self->numericValues->v[self->index] = grib_darray_new(a->context, count, 1); + grib_darray_delete(a->context, grib_vdarray_get (self->numericValues, self->index)); + //self->numericValues->v[self->index] = grib_darray_new(a->context, count, 1); + //self->numericValues->v[self->index] = grib_darray_new(a->context, count, count); + grib_vdarray_put (self->numericValues, self->index, grib_darray_new(a->context, count, count)); for (i = 0; i < count; i++) { - grib_darray_push(a->context, self->numericValues->v[self->index], val[i] == GRIB_MISSING_LONG ? GRIB_MISSING_DOUBLE : val[i]); + grib_darray_push(a->context, grib_vdarray_get (self->numericValues, self->index), ( (val[i] == GRIB_MISSING_LONG) ? GRIB_MISSING_DOUBLE : val[i] ) ); } *len = count; } else { - self->numericValues->v[self->subsetNumber]->v[self->index] = val[0] == GRIB_MISSING_LONG ? GRIB_MISSING_DOUBLE : val[0]; - *len = 1; + // self->numericValues->v[self->subsetNumber]->v[self->index] = val[0] == GRIB_MISSING_LONG ? GRIB_MISSING_DOUBLE : val[0]; + grib_darray_put (grib_vdarray_get (self->numericValues, self->subsetNumber), self->index, ( (val[0] == GRIB_MISSING_LONG ) ? GRIB_MISSING_DOUBLE : val[0] ) ); + *len = 1; } return ret; @@ -563,13 +615,15 @@ static int value_count(grib_accessor* a, long* count) type = get_native_type(a); if (type == GRIB_TYPE_STRING) { - DebugAssert(self->index < self->numericValues->n); - idx = ((int)self->numericValues->v[self->index]->v[0] / 1000 - 1) / self->numberOfSubsets; - size = grib_sarray_used_size(self->stringValues->v[idx]); + DebugAssert(self->index < grib_vdarray_used_size (self->numericValues)); + //idx = ((int)self->numericValues->v[self->index]->v[0] / 1000 - 1) / self->numberOfSubsets; + idx = ( (int)(grib_darray_get (grib_vdarray_get (self->numericValues, self->index), 0 )) / 1000 - 1) / self->numberOfSubsets; + //size = grib_sarray_used_size(self->stringValues->v[idx]); + size = grib_sarray_used_size( grib_vsarray_get(self->stringValues, idx) ); } else { - DebugAssert(self->index < self->numericValues->n); - size = grib_darray_used_size(self->numericValues->v[self->index]); + DebugAssert(self->index < grib_vdarray_used_size (self->numericValues)); + size = grib_darray_used_size(grib_vdarray_get (self->numericValues, self->index)); } *count = size == 1 ? 1 : self->numberOfSubsets; @@ -590,7 +644,8 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) } if (self->compressedData) { - *val = self->numericValues->v[self->index]->v[idx]; + //*val = self->numericValues->v[self->index]->v[idx]; + *val = grib_darray_get ( grib_vdarray_get (self->numericValues, self->index), idx); } else { ret = GRIB_NOT_IMPLEMENTED; diff --git a/src/grib_accessor_class_bufr_extract_area_subsets.c b/src/grib_accessor_class_bufr_extract_area_subsets.c index 6de896c93..fb7deb28b 100644 --- a/src/grib_accessor_class_bufr_extract_area_subsets.c +++ b/src/grib_accessor_class_bufr_extract_area_subsets.c @@ -324,6 +324,7 @@ static int select_area(grib_accessor* a) grib_context_free(c, lat); grib_context_free(c, lon); grib_iarray_delete(subsets); + /*grib_iarray_delete(subsets_ar);*//* CSGMB: deallocate array after the set ?*/ subsets = 0; return ret; diff --git a/src/grib_accessor_class_bufr_extract_datetime_subsets.c b/src/grib_accessor_class_bufr_extract_datetime_subsets.c index a8dd2ffb0..c72eccad5 100644 --- a/src/grib_accessor_class_bufr_extract_datetime_subsets.c +++ b/src/grib_accessor_class_bufr_extract_datetime_subsets.c @@ -458,6 +458,7 @@ static int select_datetime(grib_accessor* a) grib_context_free(c, minute); grib_context_free(c, second); grib_iarray_delete(subsets); + grib_iarray_delete(subsets_ar);/* CSGMB: deallocate array after the set ?*/ subsets = 0; return ret; diff --git a/src/grib_accessor_class_bufr_string_values.c b/src/grib_accessor_class_bufr_string_values.c index 0953ecff1..a2b21c722 100644 --- a/src/grib_accessor_class_bufr_string_values.c +++ b/src/grib_accessor_class_bufr_string_values.c @@ -188,14 +188,16 @@ static int unpack_string_array(grib_accessor* a, char** buffer, size_t* len) tl = 0; for (j = 0; j < n; j++) { - l = grib_sarray_used_size(stringValues->v[j]); + //l = grib_sarray_used_size(stringValues->v[j]); + l = grib_sarray_used_size(grib_vsarray_get (stringValues, j) ); tl += l; if (tl > *len) return GRIB_ARRAY_TOO_SMALL; for (i = 0; i < l; i++) { - *(b++) = grib_context_strdup(c, stringValues->v[j]->v[i]); + //*(b++) = grib_context_strdup(c, stringValues->v[j]->v[i]); + *(b++) = grib_context_strdup(c, grib_sarray_get ( grib_vsarray_get (stringValues, j), i) ); } } *len = tl; diff --git a/src/grib_accessor_class_concept.c b/src/grib_accessor_class_concept.c index 00c6e0b20..4342ee745 100644 --- a/src/grib_accessor_class_concept.c +++ b/src/grib_accessor_class_concept.c @@ -11,6 +11,7 @@ /******************************************************* * Enrico Fucile + * Modified for Performance Study by: CS GMBH ******************************************************/ #include "grib_api_internal.h" @@ -226,7 +227,7 @@ static int concept_condition_iarray_true(grib_handle* h, grib_concept_condition* ret = 1; for (i = 0; i < size; i++) { - if (val[i] != c->iarray->v[i]) { + if (val[i] != grib_iarray_get(c->iarray, i) ) { ret = 0; break; } @@ -299,8 +300,10 @@ static int concept_conditions_expression_apply(grib_handle* h, grib_concept_cond values[count].double_value = dres; break; case GRIB_TYPE_STRING: - size = sizeof(sa->v[count]); - values[count].string_value = grib_expression_evaluate_string(h, e->expression, sa->v[count], &size, &err); + //size = sizeof(sa->v[count]); + size = sizeof(grib_sarray_get(sa,count)); + //values[count].string_value = grib_expression_evaluate_string(h, e->expression, sa->v[count], &size, &err); + values[count].string_value = grib_expression_evaluate_string(h, e->expression, grib_sarray_get(sa,count), &size, &err); break; default: return GRIB_NOT_IMPLEMENTED; @@ -313,7 +316,8 @@ static int concept_conditions_expression_apply(grib_handle* h, grib_concept_cond static int concept_conditions_iarray_apply(grib_handle* h, grib_concept_condition* c) { size_t size = grib_iarray_used_size(c->iarray); - return grib_set_long_array(h, c->name, c->iarray->v, size); + return grib_set_long_array(h, c->name, grib_iarray_get_arrays_by_reference(c->iarray), size ); + /*return grib_set_long_array(h, c->name, c->iarray->dynA, size);*/ } static int concept_conditions_apply(grib_handle* h, grib_concept_condition* c, grib_values* values, grib_sarray* sa, int* n) @@ -399,7 +403,9 @@ static int grib_concept_apply(grib_accessor* a, const char* name) return err; } e = c->conditions; - sa = grib_sarray_new(h->context, 10, 10); + //magic number 10 is not documented anywhere... + //sa = grib_sarray_new(h->context, 10, 10); + sa = grib_sarray_new(h->context, DYN_DEFAULT_SARRAY_SIZE_INIT, DYN_DEFAULT_SARRAY_SIZE_INCR); while (e) { concept_conditions_apply(h, e, values, sa, &count); e = e->next; diff --git a/src/grib_accessor_class_hash_array.c b/src/grib_accessor_class_hash_array.c index 9c8022310..b80109d75 100644 --- a/src/grib_accessor_class_hash_array.c +++ b/src/grib_accessor_class_hash_array.c @@ -251,7 +251,8 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) } *len = self->ha->iarray->n; for (i = 0; i < *len; i++) - val[i] = self->ha->iarray->v[i]; + //val[i] = self->ha->iarray->v[i]; + val[i] = grib_iarray_get (self->ha->iarray, i ); break; default: diff --git a/src/grib_accessor_class_long_vector.c b/src/grib_accessor_class_long_vector.c index 5068ba97e..22c349d58 100644 --- a/src/grib_accessor_class_long_vector.c +++ b/src/grib_accessor_class_long_vector.c @@ -10,6 +10,7 @@ /************************************** * Enrico Fucile + * Modified for Performance Study by: CS GMBH **************************************/ diff --git a/src/grib_accessor_class_transient_darray.c b/src/grib_accessor_class_transient_darray.c index aba724df8..859f61ffc 100644 --- a/src/grib_accessor_class_transient_darray.c +++ b/src/grib_accessor_class_transient_darray.c @@ -196,7 +196,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) *len = count; for (i = 0; i < *len; i++) - val[i] = self->arr->v[i]; + //val[i] = self->arr->v[i]; + val[i] = grib_darray_get ( self->arr, i ); return GRIB_SUCCESS; @@ -216,8 +217,8 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) *len = count; for (i = 0; i < *len; i++) - val[i] = (long)self->arr->v[i]; - + //val[i] = (long)self->arr->v[i]; + val[i] = ( (long) (grib_darray_get ( self->arr, i )) ); return GRIB_SUCCESS; } diff --git a/src/grib_api.h b/src/grib_api.h index 44b0e7ebd..a0bd19eec 100644 --- a/src/grib_api.h +++ b/src/grib_api.h @@ -6,6 +6,8 @@ * * 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. + * + * Modified for Performance Study by: CS GMBH */ /*! \file grib_api.h diff --git a/src/grib_api_internal.h b/src/grib_api_internal.h index 48d3fd279..8391a0b83 100644 --- a/src/grib_api_internal.h +++ b/src/grib_api_internal.h @@ -6,6 +6,8 @@ * * 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. + * + * Modified for Performance Study by: CS GMBH */ /** @@ -728,69 +730,89 @@ typedef struct grib_trie_with_rank_list grib_trie_with_rank_list; typedef struct grib_trie_with_rank grib_trie_with_rank; typedef struct grib_itrie grib_itrie; +#define DYN_DEFAULT_SARRAY_SIZE_INIT 500 /* Initial size for the dynamic array */ +#define DYN_DEFAULT_SARRAY_SIZE_INCR 600 /* Increment size for the dynamic array */ struct grib_sarray { - char** v; + char * stA[DYN_DEFAULT_SARRAY_SIZE_INIT]; size_t size; size_t n; size_t incsize; - grib_context* context; + char** dynA; }; +#define DYN_DEFAULT_OARRAY_SIZE_INIT 500 /* Initial size for the dynamic array */ +#define DYN_DEFAULT_OARRAY_SIZE_INCR 600 /* Increment size for the dynamic array */ + struct grib_oarray { - void** v; + void* stA[DYN_DEFAULT_OARRAY_SIZE_INIT]; size_t size; size_t n; size_t incsize; - grib_context* context; + void** dynA; }; +#define DYN_DEFAULT_DARRAY_SIZE_INIT 500 /* Initial size for the double dynamic array */ +#define DYN_DEFAULT_DARRAY_SIZE_INCR 600 /* Increment size for the double dynamic array */ + struct grib_darray { - double* v; + double stA[DYN_DEFAULT_DARRAY_SIZE_INIT]; size_t size; size_t n; size_t incsize; - grib_context* context; + double* dynA; }; +#define DYN_DEFAULT_IARRAY_SIZE_INIT 5000 +#define DYN_DEFAULT_IARRAY_SIZE_INCR 6000 + struct grib_iarray { - long* v; + long stA[DYN_DEFAULT_IARRAY_SIZE_INIT]; size_t size; size_t n; size_t incsize; - size_t number_of_pop_front; grib_context* context; + long* dynA; }; +#define DYN_DEFAULT_VDARRAY_SIZE_INIT 500 /* Initial size for the dynamic array */ +#define DYN_DEFAULT_VDARRAY_SIZE_INCR 600 /* Increment size for the dynamic array */ + struct grib_vdarray { - grib_darray** v; + grib_darray* stA[DYN_DEFAULT_VDARRAY_SIZE_INIT]; size_t size; size_t n; size_t incsize; - grib_context* context; + grib_darray** dynA; }; +#define DYN_DEFAULT_VSARRAY_SIZE_INIT 500 /* Initial size for the dynamic array */ +#define DYN_DEFAULT_VSARRAY_SIZE_INCR 600 /* Increment size for the dynamic array */ + struct grib_vsarray { - grib_sarray** v; + grib_sarray* stA[DYN_DEFAULT_VSARRAY_SIZE_INIT]; size_t size; size_t n; size_t incsize; - grib_context* context; + grib_sarray** dynA; }; +#define DYN_DEFAULT_VIARRAY_SIZE_INIT 500 /* Initial size for the dynamic array VIARRAY */ +#define DYN_DEFAULT_VIARRAY_SIZE_INCR 600 /* Increment size for the dynamic array VIARRAY */ + struct grib_viarray { - grib_iarray** v; + grib_iarray* stA[DYN_DEFAULT_VIARRAY_SIZE_INIT]; size_t size; size_t n; size_t incsize; - grib_context* context; + grib_iarray** dynA; }; /* types of BUFR descriptors used in bufr_descriptor->type*/ diff --git a/src/grib_api_prototypes.h b/src/grib_api_prototypes.h index 7eefcc17a..686a3b8ec 100644 --- a/src/grib_api_prototypes.h +++ b/src/grib_api_prototypes.h @@ -1,4 +1,14 @@ - +/* + * (C) Copyright 2005- 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. + * + * Modified for Performance Study by: CS GMBH + */ /* action.c */ void grib_dump(grib_action* a, FILE* f, int l); void grib_xref(grib_action* a, FILE* f, const char* path); @@ -80,7 +90,7 @@ grib_action* grib_action_create_set(grib_context* context, const char* name, gri grib_action* grib_action_create_set_darray(grib_context* context, const char* name, grib_darray* darray); /* action_class_set_iarray.c */ -grib_action* grib_action_create_set_iarray(grib_context* context, const char* name, grib_iarray* iarray); +grib_action* grib_action_create_set_iarray(grib_context* context, const char* name, grib_iarray* source); /* action_class_set_sarray.c */ grib_action* grib_action_create_set_sarray(grib_context* context, const char* name, grib_sarray* sarray); @@ -162,7 +172,7 @@ void grib_accessors_list_delete(grib_context* c, grib_accessors_list* al); /* grib_concept.c */ grib_concept_value* grib_concept_value_new(grib_context* c, const char* name, grib_concept_condition* conditions); void grib_concept_value_delete(grib_context* c, grib_concept_value* v); -grib_concept_condition* grib_concept_condition_new(grib_context* c, const char* name, grib_expression* expression, grib_iarray* iarray); +grib_concept_condition* grib_concept_condition_new(grib_context* c, const char* name, grib_expression* expression, grib_iarray* source); void grib_concept_condition_delete(grib_context* c, grib_concept_condition* v); /* grib_hash_array.c */ @@ -202,6 +212,9 @@ grib_darray* grib_darray_new_from_array(grib_context* c, double* a, size_t size) grib_darray* grib_darray_new(grib_context* c, size_t size, size_t incsize); grib_darray* grib_darray_resize(grib_context* c, grib_darray* v); grib_darray* grib_darray_push(grib_context* c, grib_darray* v, double val); +double grib_darray_get(grib_darray* source, size_t index); +double* grib_darray_get_arrays_by_reference(grib_darray* source); +int grib_darray_put (grib_darray* source, size_t index, double val); void grib_darray_delete(grib_context* c, grib_darray* v); double* grib_darray_get_array(grib_context* c, grib_darray* v); int grib_darray_is_constant(grib_darray* v, double eps); @@ -211,6 +224,9 @@ size_t grib_darray_used_size(grib_darray* v); grib_sarray* grib_sarray_new(grib_context* c, size_t size, size_t incsize); grib_sarray* grib_sarray_resize(grib_context* c, grib_sarray* v); grib_sarray* grib_sarray_push(grib_context* c, grib_sarray* v, char* val); +char* grib_sarray_get(grib_sarray* source, size_t index); +char** grib_sarray_get_arrays_by_reference(grib_sarray* source); +int grib_sarray_put (grib_sarray* source, size_t index, char* val); void grib_sarray_delete(grib_context* c, grib_sarray* v); void grib_sarray_delete_content(grib_context* c, grib_sarray* v); char** grib_sarray_get_array(grib_context* c, grib_sarray* v); @@ -218,38 +234,31 @@ size_t grib_sarray_used_size(grib_sarray* v); /* grib_oarray.c */ grib_oarray* grib_oarray_new(grib_context* c, size_t size, size_t incsize); -grib_oarray* grib_oarray_resize(grib_context* c, grib_oarray* v); -grib_oarray* grib_oarray_push(grib_context* c, grib_oarray* v, void* val); -void grib_oarray_delete(grib_context* c, grib_oarray* v); -void grib_oarray_delete_content(grib_context* c, grib_oarray* v); -void** grib_oarray_get_array(grib_context* c, grib_oarray* v); -void* grib_oarray_get(grib_oarray* v, int i); -size_t grib_oarray_used_size(grib_oarray* v); +grib_oarray* grib_oarray_resize(grib_context* c, grib_oarray* origin); +grib_oarray* grib_oarray_push(grib_context* c, grib_oarray* source, void* val); +void* grib_oarray_get(grib_oarray* source, size_t index); +int grib_oarray_put (grib_oarray* source, size_t index, void* val); +void grib_oarray_delete(grib_context* c, grib_oarray* source); +void grib_oarray_delete_content(grib_context* c, grib_oarray* source); +size_t grib_oarray_used_size(grib_oarray* source); /* grib_iarray.c */ -void grib_iarray_print(const char* title, const grib_iarray* iarray); -grib_iarray* grib_iarray_new_from_array(grib_context* c, long* a, size_t size); +void grib_iarray_print(const char* title, const grib_iarray* source); grib_iarray* grib_iarray_new(grib_context* c, size_t size, size_t incsize); -long grib_iarray_pop(grib_iarray* a); -long grib_iarray_pop_front(grib_iarray* a); -grib_iarray* grib_iarray_resize_to(grib_iarray* v, size_t newsize); -grib_iarray* grib_iarray_resize(grib_iarray* v); -grib_iarray* grib_iarray_push(grib_iarray* v, long val); -grib_iarray* grib_iarray_push_front(grib_iarray* v, long val); -grib_iarray* grib_iarray_push_array(grib_iarray* v, long* val, size_t size); -long grib_iarray_get(grib_iarray* a, size_t i); -void grib_iarray_set(grib_iarray* a, size_t i, long v); -void grib_iarray_delete(grib_iarray* v); -void grib_iarray_delete_array(grib_iarray* v); -long* grib_iarray_get_array(grib_iarray* v); -size_t grib_iarray_used_size(grib_iarray* v); -int grib_iarray_is_constant(grib_iarray* v); +grib_iarray* grib_iarray_push(grib_iarray* source, long val); +long grib_iarray_get(grib_iarray* source, size_t index); +long* grib_iarray_get_arrays_by_reference(grib_iarray* source); +void grib_iarray_delete(grib_iarray* source); +long* grib_iarray_get_array(grib_iarray* source); +size_t grib_iarray_used_size(grib_iarray* source); /* grib_vdarray.c */ void grib_vdarray_print(const char* title, const grib_vdarray* vdarray); grib_vdarray* grib_vdarray_new(grib_context* c, size_t size, size_t incsize); grib_vdarray* grib_vdarray_resize(grib_context* c, grib_vdarray* v); grib_vdarray* grib_vdarray_push(grib_context* c, grib_vdarray* v, grib_darray* val); +grib_darray* grib_vdarray_get(grib_vdarray* source, size_t index); +int grib_vdarray_put (grib_vdarray* source, size_t index, grib_darray* val); void grib_vdarray_delete(grib_context* c, grib_vdarray* v); void grib_vdarray_delete_content(grib_context* c, grib_vdarray* v); grib_darray** grib_vdarray_get_array(grib_context* c, grib_vdarray* v); @@ -259,15 +268,19 @@ size_t grib_vdarray_used_size(grib_vdarray* v); grib_vsarray* grib_vsarray_new(grib_context* c, size_t size, size_t incsize); grib_vsarray* grib_vsarray_resize(grib_context* c, grib_vsarray* v); grib_vsarray* grib_vsarray_push(grib_context* c, grib_vsarray* v, grib_sarray* val); +grib_sarray* grib_vsarray_get(grib_vsarray* source, size_t index); +int grib_vsarray_put (grib_vsarray* source, size_t index, grib_sarray* val); void grib_vsarray_delete(grib_context* c, grib_vsarray* v); void grib_vsarray_delete_content(grib_context* c, grib_vsarray* v); grib_sarray** grib_vsarray_get_array(grib_context* c, grib_vsarray* v); size_t grib_vsarray_used_size(grib_vsarray* v); /* grib_viarray.c */ +void grib_viarray_print(const char* title, const grib_viarray* source); grib_viarray* grib_viarray_new(grib_context* c, size_t size, size_t incsize); grib_viarray* grib_viarray_resize(grib_context* c, grib_viarray* v); grib_viarray* grib_viarray_push(grib_context* c, grib_viarray* v, grib_iarray* val); +grib_iarray* grib_viarray_get(grib_viarray* source, size_t index); void grib_viarray_delete(grib_context* c, grib_viarray* v); void grib_viarray_delete_content(grib_context* c, grib_viarray* v); grib_iarray** grib_viarray_get_array(grib_context* c, grib_viarray* v); diff --git a/src/grib_bufr_descriptors_array.c b/src/grib_bufr_descriptors_array.c index 3dd940ab5..8e651708b 100644 --- a/src/grib_bufr_descriptors_array.c +++ b/src/grib_bufr_descriptors_array.c @@ -10,8 +10,10 @@ #include "grib_api_internal.h" -#define DYN_ARRAY_SIZE_INIT 200 /* Initial size for grib_bufr_descriptors_array_new */ -#define DYN_ARRAY_SIZE_INCR 400 /* Increment size for the above */ +//#define DYN_ARRAY_SIZE_INIT 200 /* Initial size for grib_bufr_descriptors_array_new */ +//#define DYN_ARRAY_SIZE_INCR 400 /* Increment size for the above */ +#define DYN_ARRAY_SIZE_INIT 1000 /* Initial size for grib_bufr_descriptors_array_new */ +#define DYN_ARRAY_SIZE_INCR 1200 /* Increment size for the above */ bufr_descriptors_array* grib_bufr_descriptors_array_new(grib_context* c, size_t size, size_t incsize) { diff --git a/src/grib_darray.c b/src/grib_darray.c index af3c189a4..206e47984 100644 --- a/src/grib_darray.c +++ b/src/grib_darray.c @@ -11,132 +11,280 @@ /*************************************************************************** * * Enrico Fucile + * Modified for Performance Study by: CS GMBH * ***************************************************************************/ #include "grib_api_internal.h" /* For debugging purposes */ -void grib_darray_print(const char* title, const grib_darray* darray) +void grib_darray_print(const char* title, const grib_darray* source) { size_t i; - Assert(darray); - printf("%s: darray.n=%lu \t", title, (unsigned long)darray->n); - for (i = 0; i < darray->n; i++) { - printf("darray[%lu]=%g\t", (unsigned long)i, darray->v[i]); + Assert(source); + printf("%s: darray.n=%lu \t", title, (unsigned long)source->n); + for (i = 0; i < source->n; i++) { + if( i<= (DYN_DEFAULT_DARRAY_SIZE_INIT - 1)) { + printf("darray[%lu]=%ld\t", (unsigned long)i, source->stA[i]); + } else { + printf("darray[%lu]=%ld\t", (unsigned long)i, source->dynA[(i-(DYN_DEFAULT_DARRAY_SIZE_INIT))]); + } } printf("\n"); } -grib_darray* grib_darray_new_from_array(grib_context* c, double* a, size_t size) +grib_darray* grib_darray_new(grib_context* c, size_t size, size_t incsize) { - size_t i; - grib_darray* v; + grib_darray* result = NULL; if (!c) c = grib_context_get_default(); - v = grib_darray_new(c, size, 100); - for (i = 0; i < size; i++) - v->v[i] = a[i]; - v->n = size; - v->context = c; - return v; + result = (grib_darray*)grib_context_malloc_clear(c, sizeof(grib_darray)); + if (!result) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_darray_new unable to allocate %d bytes\n", sizeof(grib_darray)); + return NULL; + } + + if(size > DYN_DEFAULT_DARRAY_SIZE_INIT) { + + result->dynA = (double*)grib_context_malloc_clear(c, sizeof(double) * (size-DYN_DEFAULT_DARRAY_SIZE_INIT) ); + if (!result->dynA) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_darray_new unable to allocate %d bytes\n", sizeof(double) * (size-DYN_DEFAULT_DARRAY_SIZE_INIT) ); + return NULL; + } + + result->size = size; + if (incsize > 0) + result->incsize = incsize; + else + result->incsize = DYN_DEFAULT_DARRAY_SIZE_INCR; + + } else { + + result->dynA = NULL; + result->size = DYN_DEFAULT_DARRAY_SIZE_INIT; + result->incsize = DYN_DEFAULT_DARRAY_SIZE_INCR; + + } + + result->n = 0; + + return result; } -grib_darray* grib_darray_new(grib_context* c, size_t size, size_t incsize) +grib_darray* grib_darray_resize(grib_context* c, grib_darray* origin) { - grib_darray* v = NULL; - if (!c) - c = grib_context_get_default(); - v = (grib_darray*)grib_context_malloc_clear(c, sizeof(grib_darray)); - if (!v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_darray_new unable to allocate %d bytes\n", sizeof(grib_darray)); - return NULL; + int newsize; + + if (origin == NULL) + { + return origin; + } + + newsize = origin->incsize + origin->size; + + if (!c) + c = grib_context_get_default(); + + if (origin->dynA != NULL){ + + origin->dynA = (double*)grib_context_realloc(c, origin->dynA, (newsize-DYN_DEFAULT_DARRAY_SIZE_INIT) * sizeof(double)); + if (!origin->dynA) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_darray_resize unable to allocate %d bytes\n", sizeof(double) * (newsize-DYN_DEFAULT_DARRAY_SIZE_INIT) ); + return NULL; + } + + } + else { + + origin->dynA = (double*)grib_context_malloc(c, (newsize-DYN_DEFAULT_DARRAY_SIZE_INIT) * sizeof(double)); + if (!origin->dynA) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_darray_resize unable to allocate %d bytes\n", sizeof(double) * (newsize-DYN_DEFAULT_DARRAY_SIZE_INIT) ); + return NULL; + } + + } + + origin->size = newsize; + + return origin; +} + +grib_darray* grib_darray_push(grib_context* c, grib_darray* source, double val) +{ + + size_t start_size = DYN_DEFAULT_DARRAY_SIZE_INIT; + size_t start_incsize = DYN_DEFAULT_DARRAY_SIZE_INCR; + + //If the target is empty, initialize it + if (!source) + source = grib_darray_new(c, start_size, start_incsize); + + //If the actual used size of the target is equal to the allowed size, resize the array + if (source->n == source->size) { + + source = grib_darray_resize(c, source); + + //Check if REALLOC WAS POSSIBLE, otherwise it is not possible to insert a new value! + if (source == NULL) + { + return source; + } + + //insertion in new allocated dynamic array + source->dynA[ (source->n-(DYN_DEFAULT_DARRAY_SIZE_INIT)) ] = val; + source->n++; + return source; + + } + + //insertion in static array + if (source->n <= (DYN_DEFAULT_DARRAY_SIZE_INIT - 1) ) + { + source->stA[source->n] = val; } - v->size = size; - v->n = 0; - v->incsize = incsize; - v->v = (double*)grib_context_malloc_clear(c, sizeof(double) * size); - if (!v->v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_darray_new unable to allocate %d bytes\n", sizeof(double) * size); - return NULL; + else { + //insertion in dynamic array + source->dynA[ (source->n-(DYN_DEFAULT_DARRAY_SIZE_INIT)) ] = val; } - return v; + + source->n++; + return source; } -grib_darray* grib_darray_resize(grib_context* c, grib_darray* v) +/** + * Return the double value at index 'index' for grib_darray 'source' + */ +double grib_darray_get(grib_darray* source, size_t index) { - int newsize = v->incsize + v->size; - if (!c) - c = grib_context_get_default(); + if (!source) + return 0; + if (index < 0) + return 0; + if (index < DYN_DEFAULT_DARRAY_SIZE_INIT) { + return source->stA[index]; + } else { + if (source->dynA != NULL) { + return source->dynA[(index-DYN_DEFAULT_DARRAY_SIZE_INIT)]; + } + } - v->v = (double*)grib_context_realloc(c, v->v, newsize * sizeof(double)); - v->size = newsize; - if (!v->v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_darray_resize unable to allocate %d bytes\n", sizeof(double) * newsize); - return NULL; - } - return v; + return 0; } -grib_darray* grib_darray_push(grib_context* c, grib_darray* v, double val) +/** + * The method returns the array currently in use. If the given grib_darray structure pointer is null, it returns NULL. + */ +double* grib_darray_get_arrays_by_reference(grib_darray* source) { - size_t start_size = 100; - size_t start_incsize = 100; - if (!v) - v = grib_darray_new(c, start_size, start_incsize); - - if (v->n >= v->size) - v = grib_darray_resize(c, v); - v->v[v->n] = val; - v->n++; - return v; + if(!source) + return NULL; + + return source->stA; + + /* + * PREVIOUS ATTEMPT + if (source->n < DYN_DEFAULT_DARRAY_SIZE_INIT) { + return source->stA;// stA is the static array + } else { + if (source->dynA != NULL) { + return source->dynA; // dynA is the dynamic array + } + } + return NULL; + */ + } -void grib_darray_delete(grib_context* c, grib_darray* v) +/** + * Sets the double value 'val' at index 'index' for grib_darray 'source'. + * The method overwrites the existing value, if any. + * The method returns 1 if the writing operation occurred, otherwise 0. + */ +int grib_darray_put (grib_darray* source, size_t index, double val) { - if (!v) + if (!source) + return 0; + if (index < 0) + return 0; + if (index < DYN_DEFAULT_DARRAY_SIZE_INIT) { + source->stA[index] = val; + + } else { + if (source->dynA != NULL) { + source->dynA[(index-DYN_DEFAULT_DARRAY_SIZE_INIT)] = val; + } + } + + return 1; +} + +void grib_darray_delete(grib_context* c, grib_darray* source) +{ + if (!source) return; if (!c) grib_context_get_default(); - if (v->v) - grib_context_free(c, v->v); - grib_context_free(c, v); + + if (source->dynA) + grib_context_free(c, source->dynA); + + grib_context_free(c, source); } -double* grib_darray_get_array(grib_context* c, grib_darray* v) +/** + * The method returns an array of double of size source->n containing all the values contained in the 'source' grib_darray, starting to copy from the static array 'sv' and then copying the dynamic array 'v'. + * Data in the result: + * 1. From index 0 until index (DYN_DEFAULT_DARRAY_SIZE_INIT -1), data located at the same index in source->sv; + * 2. From index DYN_DEFAULT_DARRAY_SIZE_INIT until ( source->n ), data located at index (index - DYN_DEFAULT_DARRAY_SIZE_INIT) in source->v; + */ +double* grib_darray_get_array(grib_context* c, grib_darray* source) { - double* ret; - int i; - if (!v) - return NULL; - ret = (double*)grib_context_malloc_clear(c, sizeof(double) * v->n); - for (i = 0; i < v->n; i++) - ret[i] = v->v[i]; - return ret; + double* result; + size_t i; + + result = (double*)grib_context_malloc_clear(c, sizeof(double) * source->n); + + for (i = 0; i < source->n; i++) { + if( i<= (DYN_DEFAULT_DARRAY_SIZE_INIT - 1)) { + result[i] = source->stA[i]; + } else { + result[i] = source->dynA[(i-(DYN_DEFAULT_DARRAY_SIZE_INIT))]; + } + } + + return result; } -int grib_darray_is_constant(grib_darray* v, double eps) +int grib_darray_is_constant(grib_darray* source, double eps) { int i; double val; - if (v->n == 1) + if (source->n == 1) return 1; - val = v->v[0]; - for (i = 1; i < v->n; i++) { - if (fabs(val - v->v[i]) > eps) - return 0; + val = source->stA[0]; + + for (i = 0; i < source->n; i++) { + if( i<= (DYN_DEFAULT_DARRAY_SIZE_INIT - 1)) { + if (fabs(val - source->stA[i]) > eps) + return 0; + } else { + if (fabs(val - source->dynA[(i-(DYN_DEFAULT_DARRAY_SIZE_INIT))]) > eps) + return 0; + } } + return 1; } -size_t grib_darray_used_size(grib_darray* v) +size_t grib_darray_used_size(grib_darray* source) { - return v->n; + return source == NULL ? 0 : source->n; } diff --git a/src/grib_iarray.c b/src/grib_iarray.c index 4ab9eb9cd..478fa79c0 100644 --- a/src/grib_iarray.c +++ b/src/grib_iarray.c @@ -11,251 +11,239 @@ /*************************************************************************** * * Enrico Fucile + * Modified for Performance Study by: CS GMBH * ***************************************************************************/ #include "grib_api_internal.h" /* For debugging purposes */ -void grib_iarray_print(const char* title, const grib_iarray* iarray) +void grib_iarray_print(const char* title, const grib_iarray* source) { - size_t i; - Assert(iarray); - printf("%s: iarray.n=%lu \t", title, (unsigned long)iarray->n); - for (i = 0; i < iarray->n; i++) { - printf("iarray[%lu]=%ld\t", (unsigned long)i, iarray->v[i]); - } - printf("\n"); -} - -grib_iarray* grib_iarray_new_from_array(grib_context* c, long* a, size_t size) -{ - size_t i; - grib_iarray* v; - - if (!c) - c = grib_context_get_default(); - - v = grib_iarray_new(c, size, 100); - for (i = 0; i < size; i++) - v->v[i] = a[i]; - v->n = size; - v->number_of_pop_front = 0; - v->context = c; - return v; + size_t i; + Assert(source); + printf("%s: iarray.n=%lu \t", title, (unsigned long)source->n); + for (i = 0; i < source->n; i++) { + if( i<= (DYN_DEFAULT_IARRAY_SIZE_INIT - 1)) { + printf("iarray[%lu]=%ld\t", (unsigned long)i, source->stA[i]); + } else { + printf("iarray[%lu]=%ld\t", (unsigned long)i, source->dynA[(i-(DYN_DEFAULT_IARRAY_SIZE_INIT))]); + } + } + printf("\n"); } grib_iarray* grib_iarray_new(grib_context* c, size_t size, size_t incsize) { - grib_iarray* v = NULL; - - if (!c) - c = grib_context_get_default(); - - v = (grib_iarray*)grib_context_malloc(c, sizeof(grib_iarray)); - if (!v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_iarray_new unable to allocate %d bytes\n", sizeof(grib_iarray)); - return NULL; - } - v->context = c; - v->size = size; - v->n = 0; - v->incsize = incsize; - v->v = (long*)grib_context_malloc(c, sizeof(long) * size); - v->number_of_pop_front = 0; - if (!v->v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_iarray_new unable to allocate %d bytes\n", sizeof(long) * size); - return NULL; - } - return v; -} + grib_iarray* result = NULL; -long grib_iarray_pop(grib_iarray* a) -{ - a->n -= 1; - return a->v[a->n]; -} + if (!c) + c = grib_context_get_default(); -long grib_iarray_pop_front(grib_iarray* a) -{ - long v = a->v[0]; - /* size_t i=0; */ - if (a->n == 0) - Assert(0); - a->n--; - a->v++; - a->number_of_pop_front++; - /* for (i=0;in;i++) a->v[i]=a->v[i+1]; */ - - return v; -} + result = (grib_iarray*)grib_context_malloc(c, sizeof(grib_iarray)); + if (!result) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_iarray_new unable to allocate %d bytes\n", sizeof(grib_iarray)); + return NULL; + } + result->context = c; -grib_iarray* grib_iarray_resize_to(grib_iarray* v, size_t newsize) -{ - long* newv; - size_t i; - grib_context* c = v->context; + if(size > DYN_DEFAULT_IARRAY_SIZE_INIT) { + + result->dynA = (long*)grib_context_malloc(c, (sizeof(long) * (size-DYN_DEFAULT_IARRAY_SIZE_INIT)) ); - if (newsize < v->size) - return v; + if (!result->dynA) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_iarray_new unable to allocate %d bytes\n", (sizeof(long) * (size-DYN_DEFAULT_IARRAY_SIZE_INIT)) ); + return NULL; + } - if (!c) - c = grib_context_get_default(); + result->size = size; + if (incsize > 0) + result->incsize = incsize; + else + result->incsize = DYN_DEFAULT_IARRAY_SIZE_INCR; - newv = (long*)grib_context_malloc_clear(c, newsize * sizeof(long)); - if (!newv) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_iarray_resize unable to allocate %d bytes\n", sizeof(long) * newsize); - return NULL; - } + } else { - for (i = 0; i < v->n; i++) - newv[i] = v->v[i]; + result->dynA = NULL; + result->size = DYN_DEFAULT_IARRAY_SIZE_INIT; + result->incsize = DYN_DEFAULT_IARRAY_SIZE_INCR; - v->v -= v->number_of_pop_front; - grib_context_free(c, v->v); + } - v->v = newv; - v->size = newsize; - v->number_of_pop_front = 0; + result->n = 0; - return v; + return result; } -grib_iarray* grib_iarray_resize(grib_iarray* v) +grib_iarray* grib_iarray_resize(grib_iarray* origin) { - int newsize = v->incsize + v->size; + long* newv; + grib_context* c; + int newsize; - return grib_iarray_resize_to(v, newsize); -} + if (origin == NULL) + { + return origin; + } -grib_iarray* grib_iarray_push(grib_iarray* v, long val) -{ - size_t start_size = 100; - size_t start_incsize = 100; + newsize = origin->incsize + origin->size; + c = origin->context; - if (!v) - v = grib_iarray_new(0, start_size, start_incsize); + if (!c) + c = grib_context_get_default(); - if (v->n >= v->size - v->number_of_pop_front) - v = grib_iarray_resize(v); + if (origin->dynA != NULL){ - v->v[v->n] = val; - v->n++; - return v; -} + newv = (long*)grib_context_realloc(c, origin->dynA, (newsize-DYN_DEFAULT_IARRAY_SIZE_INIT) * sizeof(long)); -grib_iarray* grib_iarray_push_front(grib_iarray* v, long val) -{ - size_t start_size = 100; - size_t start_incsize = 100; - int i; - if (!v) - v = grib_iarray_new(0, start_size, start_incsize); - - if (v->number_of_pop_front) { - v->v--; - v->number_of_pop_front--; - } - else { - if (v->n >= v->size) - v = grib_iarray_resize(v); - for (i = v->n; i > 0; i--) - v[i] = v[i - 1]; - } - v->v[0] = val; - v->n++; - - return v; -} + if (!newv) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_iarray_resize unable to allocate %d bytes\n", sizeof(long) * newsize); + return NULL; + } -grib_iarray* grib_iarray_push_array(grib_iarray* v, long* val, size_t size) -{ - size_t start_size = size; - size_t start_incsize = 100; - long* vp = 0; - long* valp = val; - if (!v) - v = grib_iarray_new(0, start_size, start_incsize); - - v = grib_iarray_resize_to(v, size + v->n); - vp = v->v + v->n + v->number_of_pop_front; - v->n += size; - while (size) { - *(vp++) = *(valp++); - size--; - } - return v; -} + origin->dynA=newv; -long grib_iarray_get(grib_iarray* a, size_t i) -{ - return a->v[i]; + } + else { + + newv = (long*)grib_context_malloc(c, (newsize-DYN_DEFAULT_IARRAY_SIZE_INIT ) * sizeof(long) ); + + if (!newv) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_iarray_resize unable to allocate %d bytes\n", sizeof(long) * newsize); + return NULL; + } + + origin->dynA=newv; + + } + + origin->size = newsize; + + return origin; } -void grib_iarray_set(grib_iarray* a, size_t i, long v) +grib_iarray* grib_iarray_push(grib_iarray* source, long val) { - a->v[i] = v; + size_t start_size = DYN_DEFAULT_IARRAY_SIZE_INIT; + size_t start_incsize = DYN_DEFAULT_IARRAY_SIZE_INCR; + + //If the target is empty, initialize it + if (!source) + source = grib_iarray_new(0, start_size, start_incsize); + + //If the actual used size of the target is equal to the allowed size, resize the array + if (source->n == source->size) { + + source = grib_iarray_resize(source); + + //Check if REALLOC WAS POSSIBLE, otherwise it is not possible to insert a new value! + if (source == NULL) + { + return source; + } + + //insertion in new allocated dynamic array + source->dynA[ (source->n-(DYN_DEFAULT_IARRAY_SIZE_INIT)) ] = val; + source->n++; + return source; + + } + + //insertion in static array + if (source->n <= (DYN_DEFAULT_IARRAY_SIZE_INIT - 1) ) + { + source->stA[source->n] = val; + } + else { + //insertion in dynamic array + source->dynA[ (source->n-(DYN_DEFAULT_IARRAY_SIZE_INIT)) ] = val; + } + + source->n++; + return source; } -void grib_iarray_delete(grib_iarray* v) +long grib_iarray_get(grib_iarray* source, size_t index) { - grib_context* c; - - if (!v) - return; - c = v->context; - grib_iarray_delete_array(v); + if (!source) + return 0; + if (index < 0) + return 0; + if (index < DYN_DEFAULT_IARRAY_SIZE_INIT) { + return source->stA[index]; + } else { + if (source->dynA != NULL) { + return source->dynA[index-DYN_DEFAULT_IARRAY_SIZE_INIT]; + } + } - grib_context_free(c, v); + return 0; } -void grib_iarray_delete_array(grib_iarray* v) +/** + * The method returns the array currently in use. If the given grib_iarray structure pointer is null, it returns NULL. + */ +long* grib_iarray_get_arrays_by_reference(grib_iarray* source) { - grib_context* c; - if (!v) - return; - c = v->context; + if(!source) + return NULL; + + return source->stA; - if (v->v) { - long* vv = v->v - v->number_of_pop_front; - grib_context_free(c, vv); - } + /* + * PREVIOUS ATTEMPT + if (source->n < DYN_DEFAULT_IARRAY_SIZE_INIT) { + return source->stA;//stA is the static array + } else { + if (source->dynA != NULL) { + return source->dynA;//dynA is the dynamic array + } + } + + return NULL; + */ } -long* grib_iarray_get_array(grib_iarray* v) +void grib_iarray_delete(grib_iarray* source) { - long* vv; - size_t i; - grib_context* c = grib_context_get_default(); + grib_context* c; + + if (!source) + return; + c = source->context; - vv = (long*)grib_context_malloc_clear(c, sizeof(long) * v->n); - for (i = 0; i < v->n; i++) - vv[i] = v->v[i]; + if (source->dynA) { + grib_context_free(c, source->dynA); + } - return vv; + grib_context_free(c, source); } -size_t grib_iarray_used_size(grib_iarray* v) +long* grib_iarray_get_array(grib_iarray* source) { - return v == NULL ? 0 : v->n; + long* vv; + size_t i; + grib_context* c = grib_context_get_default(); + + vv = (long*)grib_context_malloc_clear(c, sizeof(long) * source->n); + for (i = 0; i < source->n; i++) { + if( i<= (DYN_DEFAULT_IARRAY_SIZE_INIT - 1)) { + vv[i] = source->stA[i]; + } else { + vv[i] = source->dynA[(i-(DYN_DEFAULT_IARRAY_SIZE_INIT))]; + } + } + + return vv; } -int grib_iarray_is_constant(grib_iarray* v) +size_t grib_iarray_used_size(grib_iarray* source) { - int i; - long val; - if (v->n == 1) - return 1; - - val = v->v[0]; - for (i = 1; i < v->n; i++) { - if (val != v->v[i]) - return 0; - } - return 1; + return source == NULL ? 0 : source->n; } diff --git a/src/grib_oarray.c b/src/grib_oarray.c index 8d2958479..5e6cdb5b2 100644 --- a/src/grib_oarray.c +++ b/src/grib_oarray.c @@ -11,111 +11,221 @@ /*************************************************************************** * * Enrico Fucile + * Modified for Performance Study by: CS GMBH * ***************************************************************************/ #include "grib_api_internal.h" + grib_oarray* grib_oarray_new(grib_context* c, size_t size, size_t incsize) { - grib_oarray* v = NULL; + grib_oarray* result = NULL; + if (!c) c = grib_context_get_default(); - v = (grib_oarray*)grib_context_malloc_clear(c, sizeof(grib_oarray)); - if (!v) { + + result = (grib_oarray*)grib_context_malloc_clear(c, sizeof(grib_oarray)); + if (!result) { grib_context_log(c, GRIB_LOG_ERROR, "grib_oarray_new unable to allocate %d bytes\n", sizeof(grib_oarray)); return NULL; } - v->size = size; - v->n = 0; - v->incsize = incsize; - v->v = (void**)grib_context_malloc_clear(c, sizeof(char*) * size); - if (!v->v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_oarray_new unable to allocate %d bytes\n", sizeof(char*) * size); - return NULL; + + if(size > DYN_DEFAULT_OARRAY_SIZE_INIT) { + + result->dynA = (void**)grib_context_malloc_clear(c, sizeof(char *) * (size-DYN_DEFAULT_OARRAY_SIZE_INIT) ); + if (!result->dynA) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_oarray_new unable to allocate %d bytes\n", sizeof(char *) * (size-DYN_DEFAULT_OARRAY_SIZE_INIT) ); + return NULL; + } + + result->size = size; + if (incsize > 0) + result->incsize = incsize; + else + result->incsize = DYN_DEFAULT_OARRAY_SIZE_INIT; + + } else { + + result->dynA = NULL; + result->size = DYN_DEFAULT_OARRAY_SIZE_INIT; + result->incsize = DYN_DEFAULT_OARRAY_SIZE_INCR; + } - return v; + + result->n = 0; + + return result; } -grib_oarray* grib_oarray_resize(grib_context* c, grib_oarray* v) +grib_oarray* grib_oarray_resize(grib_context* c, grib_oarray* origin) { - int newsize = v->incsize + v->size; + int newsize; - if (!c) - c = grib_context_get_default(); + if (origin == NULL) + { + return origin; + } - v->v = (void**)grib_context_realloc(c, v->v, newsize * sizeof(char*)); - v->size = newsize; - if (!v->v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_oarray_resize unable to allocate %d bytes\n", sizeof(char*) * newsize); - return NULL; - } - return v; + newsize = origin->incsize + origin->size; + + if (!c) + c = grib_context_get_default(); + + if (origin->dynA != NULL){ + + origin->dynA = (void**)grib_context_realloc(c, origin->dynA, (newsize-DYN_DEFAULT_OARRAY_SIZE_INIT) * sizeof(char*)); + if (!origin->dynA) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_oarray_resize unable to allocate %d bytes\n", sizeof(char*) * (newsize-DYN_DEFAULT_OARRAY_SIZE_INIT) ); + return NULL; + } + + } + else { + + origin->dynA = (void**)grib_context_malloc(c, (newsize-DYN_DEFAULT_SARRAY_SIZE_INIT) * sizeof(char*)); + if (!origin->dynA) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_oarray_resize unable to allocate %d bytes\n", sizeof(char*) * (newsize-DYN_DEFAULT_OARRAY_SIZE_INIT) ); + return NULL; + } + + } + + origin->size = newsize; + + return origin; } -grib_oarray* grib_oarray_push(grib_context* c, grib_oarray* v, void* val) +grib_oarray* grib_oarray_push(grib_context* c, grib_oarray* source, void* val) { - size_t start_size = 100; - size_t start_incsize = 100; - if (!v) - v = grib_oarray_new(c, start_size, start_incsize); - - if (v->n >= v->size) - v = grib_oarray_resize(c, v); - v->v[v->n] = val; - v->n++; - return v; + size_t start_size = DYN_DEFAULT_OARRAY_SIZE_INIT; + size_t start_incsize = DYN_DEFAULT_OARRAY_SIZE_INCR; + + //If the target is empty, initialize it + if (!source) + source = grib_oarray_new(c, start_size, start_incsize); + + //If the actual used size of the target is equal to the allowed size, resize the array + if (source->n == source->size) { + + source = grib_oarray_resize(c, source); + + //Check if REALLOC WAS POSSIBLE, otherwise it is not possible to insert a new value! + if (source == NULL) + { + return source; + } + + //insertion in new allocated dynamic array + source->dynA[ (source->n-(DYN_DEFAULT_OARRAY_SIZE_INIT)) ] = val; + source->n++; + return source; + + } + + //insertion in static array + if (source->n <= (DYN_DEFAULT_OARRAY_SIZE_INIT - 1) ) + { + source->stA[source->n] = val; + } + else { + //insertion in dynamic array + source->dynA[ (source->n-(DYN_DEFAULT_OARRAY_SIZE_INIT)) ] = val; + } + + source->n++; + return source; } -void grib_oarray_delete(grib_context* c, grib_oarray* v) +/** + * Return the void* value at index 'index' for grib_oarray 'source' + */ +void* grib_oarray_get(grib_oarray* source, size_t index) { - if (!v) - return; - if (!c) - grib_context_get_default(); - if (v->v) - grib_context_free(c, v->v); - grib_context_free(c, v); + if (!source) + return; + + if (index < 0) + return; + + if (index < DYN_DEFAULT_OARRAY_SIZE_INIT) { + return source->stA[index]; + } else { + if (source->dynA != NULL) { + return source->dynA[(index-DYN_DEFAULT_OARRAY_SIZE_INIT)]; + } + } + + return; } -void grib_oarray_delete_content(grib_context* c, grib_oarray* v) +/** + * Sets the void* value 'val' at index 'index' for grib_oarray 'source'. + * The method overwrites the existing value, if any. + * The method returns 1 if the writing operation occurred, otherwise 0. + */ +int grib_oarray_put (grib_oarray* source, size_t index, void* val) { - int i; - if (!v || !v->v) + if (!source) + return 0; + if (index < 0) + return 0; + if (index < DYN_DEFAULT_OARRAY_SIZE_INIT) { + source->stA[index] = val; + + } else { + if (source->dynA != NULL) { + source->dynA[(index-DYN_DEFAULT_OARRAY_SIZE_INIT)] = val; + } + } + + return 1; +} + +void grib_oarray_delete(grib_context* c, grib_oarray* source) +{ + if (!source) return; + if (!c) grib_context_get_default(); - for (i = 0; i < v->n; i++) { - if (v->v[i]) - grib_context_free(c, v->v[i]); - v->v[i] = 0; - } - v->n = 0; -} -void** grib_oarray_get_array(grib_context* c, grib_oarray* v) -{ - void** ret; - int i; - if (!v) - return NULL; - ret = (void**)grib_context_malloc_clear(c, sizeof(char*) * v->n); - for (i = 0; i < v->n; i++) - ret[i] = v->v[i]; - return ret; + if (source->dynA) + grib_context_free(c, source->dynA); + + grib_context_free(c, source); } -void* grib_oarray_get(grib_oarray* v, int i) +void grib_oarray_delete_content(grib_context* c, grib_oarray* source) { - if (v == NULL || i > v->n - 1) - return NULL; - return v->v[i]; + int i; + + if (!source) + return; + + if (!c) + grib_context_get_default(); + + //If the actual used size of the target is greater than the allowed size, it is a resized array + if (source->n > source->size && ( source->dynA != NULL ) ) { + for (i = 0; i < (source->n - DYN_DEFAULT_OARRAY_SIZE_INIT); i++) { + grib_sarray_delete(c,source->dynA[i]); + source->dynA[i] = 0; + } + } + + for (i = 0; i < (DYN_DEFAULT_OARRAY_SIZE_INIT); i++) { + source->stA[i] = 0; + } + + source->n = 0; } -size_t grib_oarray_used_size(grib_oarray* v) +size_t grib_oarray_used_size(grib_oarray* source) { - return v->n; + return source == NULL ? 0 : source->n; } diff --git a/src/grib_sarray.c b/src/grib_sarray.c index 90904eafd..6f7a3a7a1 100644 --- a/src/grib_sarray.c +++ b/src/grib_sarray.c @@ -11,6 +11,7 @@ /*************************************************************************** * * Enrico Fucile + * Modified for Performance Study by: CS GMBH * ***************************************************************************/ @@ -18,97 +19,261 @@ grib_sarray* grib_sarray_new(grib_context* c, size_t size, size_t incsize) { - grib_sarray* v = NULL; + grib_sarray* result = NULL; + if (!c) c = grib_context_get_default(); - v = (grib_sarray*)grib_context_malloc_clear(c, sizeof(grib_sarray)); - if (!v) { + + result = (grib_sarray*)grib_context_malloc_clear(c, sizeof(grib_sarray)); + if (!result) { grib_context_log(c, GRIB_LOG_ERROR, "grib_sarray_new unable to allocate %d bytes\n", sizeof(grib_sarray)); return NULL; } - v->size = size; - v->n = 0; - v->incsize = incsize; - v->v = (char**)grib_context_malloc_clear(c, sizeof(char*) * size); - if (!v->v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_sarray_new unable to allocate %d bytes\n", sizeof(char*) * size); - return NULL; + + if(size > DYN_DEFAULT_SARRAY_SIZE_INIT) { + + result->dynA = (char**)grib_context_malloc_clear(c, sizeof(char *) * (size-DYN_DEFAULT_SARRAY_SIZE_INIT) ); + if (!result->dynA) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_sarray_new unable to allocate %d bytes\n", sizeof(char *) * (size-DYN_DEFAULT_SARRAY_SIZE_INIT) ); + return NULL; + } + + result->size = size; + if (incsize > 0) + result->incsize = incsize; + else + result->incsize = DYN_DEFAULT_SARRAY_SIZE_INCR; + + } else { + + result->dynA = NULL; + result->size = DYN_DEFAULT_SARRAY_SIZE_INIT; + result->incsize = DYN_DEFAULT_SARRAY_SIZE_INCR; + } - return v; + + result->n = 0; + + return result; } -grib_sarray* grib_sarray_resize(grib_context* c, grib_sarray* v) +grib_sarray* grib_sarray_resize(grib_context* c, grib_sarray* origin) { - int newsize = v->incsize + v->size; + int newsize; - if (!c) - c = grib_context_get_default(); + if (origin == NULL) + { + return origin; + } - v->v = (char**)grib_context_realloc(c, v->v, newsize * sizeof(char*)); - v->size = newsize; - if (!v->v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_sarray_resize unable to allocate %d bytes\n", sizeof(char*) * newsize); - return NULL; + newsize = origin->incsize + origin->size; + + if (!c) + c = grib_context_get_default(); + + if (origin->dynA != NULL){ + + origin->dynA = (char**)grib_context_realloc(c, origin->dynA, (newsize-DYN_DEFAULT_SARRAY_SIZE_INIT) * sizeof(char*)); + if (!origin->dynA) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_sarray_resize unable to allocate %d bytes\n", sizeof(char*) * (newsize-DYN_DEFAULT_SARRAY_SIZE_INIT) ); + return NULL; + } + + } + else { + + origin->dynA = (char**)grib_context_malloc(c, (newsize-DYN_DEFAULT_SARRAY_SIZE_INIT) * sizeof(char*)); + if (!origin->dynA) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_sarray_resize unable to allocate %d bytes\n", sizeof(char*) * (newsize-DYN_DEFAULT_SARRAY_SIZE_INIT) ); + return NULL; + } + + } + + origin->size = newsize; + + return origin; +} + +grib_sarray* grib_sarray_push(grib_context* c, grib_sarray* source, char* val) +{ + size_t start_size = DYN_DEFAULT_SARRAY_SIZE_INIT; + size_t start_incsize = DYN_DEFAULT_SARRAY_SIZE_INCR; + + //If the target is empty, initialize it + if (!source) + source = grib_sarray_new(c, start_size, start_incsize); + + //If the actual used size of the target is equal to the allowed size, resize the array + if (source->n == source->size) { + + source = grib_sarray_resize(c, source); + + //Check if REALLOC WAS POSSIBLE, otherwise it is not possible to insert a new value! + if (source == NULL) + { + return source; + } + + //insertion in new allocated dynamic array + source->dynA[ (source->n-(DYN_DEFAULT_SARRAY_SIZE_INIT)) ] = val; + source->n++; + return source; + + } + + //insertion in static array + if (source->n <= (DYN_DEFAULT_SARRAY_SIZE_INIT - 1) ) + { + source->stA[source->n] = val; } - return v; + else { + //insertion in dynamic array + source->dynA[ (source->n-(DYN_DEFAULT_SARRAY_SIZE_INIT)) ] = val; + } + + source->n++; + return source; } -grib_sarray* grib_sarray_push(grib_context* c, grib_sarray* v, char* val) +/** + * Return the char* value at index 'index' for grib_sarray 'source' + */ +char* grib_sarray_get(grib_sarray* source, size_t index) { - size_t start_size = 100; - size_t start_incsize = 100; - if (!v) - v = grib_sarray_new(c, start_size, start_incsize); - - if (v->n >= v->size) - v = grib_sarray_resize(c, v); - v->v[v->n] = val; - v->n++; - return v; + + if (!source) + return NULL; + if (index < 0) + return NULL; + if (index < DYN_DEFAULT_SARRAY_SIZE_INIT) { + return source->stA[index]; + } else { + if (source->dynA != NULL) { + return source->dynA[(index-DYN_DEFAULT_SARRAY_SIZE_INIT)]; + } + } + + return NULL; } -void grib_sarray_delete(grib_context* c, grib_sarray* v) +/** + * The method returns the array currently in use. If the given grib_sarray structure pointer is null, it returns NULL. + */ +char** grib_sarray_get_arrays_by_reference(grib_sarray* source) { - if (!v) - return; - if (!c) - grib_context_get_default(); - if (v->v) - grib_context_free(c, v->v); - grib_context_free(c, v); + if(!source) + return NULL; + + return source->stA; + + /* PREVIOUS ATTEMPT + if (source->n < DYN_DEFAULT_SARRAY_SIZE_INIT) { + return source->stA;//sv is the static array + } else { + if (source->dynA != NULL) { + return source->dynA;//v is the dynamic array + } + } + + return NULL; + */ +} + +/** + * Sets the char* value 'val' at index 'index' for grib_sarray 'source'. + * The method overwrites the existing value, if any. + * The method returns 1 if the writing operation occurred, otherwise 0. + */ +int grib_sarray_put (grib_sarray* source, size_t index, char* val) +{ + if (!source) + return 0; + if (index < 0) + return 0; + if (index < DYN_DEFAULT_SARRAY_SIZE_INIT) { + source->stA[index] = val; + + } else { + if (source->dynA != NULL) { + source->dynA[(index-DYN_DEFAULT_SARRAY_SIZE_INIT)] = val; + } + } + + return 1; +} + +void grib_sarray_delete(grib_context* c, grib_sarray* source) +{ + if (!source) + return; + if (!c) + grib_context_get_default(); + + if (source->dynA) + grib_context_free(c, source->dynA); + + grib_context_free(c, source); } -void grib_sarray_delete_content(grib_context* c, grib_sarray* v) +void grib_sarray_delete_content(grib_context* c, grib_sarray* source) { int i; - if (!v || !v->v) - return; + + if (!source) + return; + + /* This is not needed: the grib_sarray_delete is already always called after the function grib_sarray_delete_content if (!c) - grib_context_get_default(); - for (i = 0; i < v->n; i++) { - if (v->v[i]) - grib_context_free(c, v->v[i]); - v->v[i] = 0; + grib_context_get_default(); + */ + + //If the actual used size of the target is greater than the allowed size, it is a resized array + if (source->n > source->size && ( source->dynA != NULL ) ) { + for (i = 0; i < (source->n - DYN_DEFAULT_SARRAY_SIZE_INIT); i++) { + /* This is not needed: the grib_sarray_delete is already always called after the function grib_sarray_delete_content + * grib_sarray_delete(c,source->dynA[i]); + */ + source->dynA[i] = 0; + } + } + + for (i = 0; i < (DYN_DEFAULT_SARRAY_SIZE_INIT); i++) { + source->stA[i] = 0; } - v->n = 0; + + source->n = 0; } -char** grib_sarray_get_array(grib_context* c, grib_sarray* v) +/** + * The method returns an array of char* of size source->n containing all the values contained in the 'source' grib_sarray, starting to copy from the static array 'sv' and then copying the dynamic array 'v'. + * Data in the result: + * 1. From index 0 until index (DYN_DEFAULT_SARRAY_SIZE_INIT -1), data located at the same index in source->sv; + * 2. From index DYN_DEFAULT_SARRAY_SIZE_INIT until ( source->n ), data located at index (index - DYN_DEFAULT_SARRAY_SIZE_INIT) in source->v; + */ +char** grib_sarray_get_array(grib_context* c, grib_sarray* source) { - char** ret; - int i; - if (!v) - return NULL; - ret = (char**)grib_context_malloc_clear(c, sizeof(char*) * v->n); - for (i = 0; i < v->n; i++) - ret[i] = v->v[i]; - return ret; + char** result; + size_t i; + + result = (char**)grib_context_malloc_clear(c, sizeof(char*) * source->n); + + for (i = 0; i < source->n; i++) { + if( i<= (DYN_DEFAULT_SARRAY_SIZE_INIT - 1)) { + result[i] = source->stA[i]; + } else { + result[i] = source->dynA[(i-(DYN_DEFAULT_SARRAY_SIZE_INIT))]; + } + } + + return result; } -size_t grib_sarray_used_size(grib_sarray* v) +size_t grib_sarray_used_size(grib_sarray* source) { - return v->n; + return source == NULL ? 0 : source->n; } diff --git a/src/grib_trie_with_rank.c b/src/grib_trie_with_rank.c index 93859a9a7..12056a115 100644 --- a/src/grib_trie_with_rank.c +++ b/src/grib_trie_with_rank.c @@ -483,7 +483,8 @@ int grib_trie_with_rank_insert(grib_trie_with_rank* t, const char* key, void* da } } if (t->objs == NULL) - t->objs = grib_oarray_new(t->context, 100, 1000); + t->objs = grib_oarray_new(t->context, DYN_DEFAULT_OARRAY_SIZE_INIT, DYN_DEFAULT_OARRAY_SIZE_INCR); + //t->objs = grib_oarray_new(t->context, 100, 1000); grib_oarray_push(t->context, t->objs, data); /* grib_trie_with_rank_insert_in_list(t,data); */ GRIB_MUTEX_UNLOCK(&mutex); diff --git a/src/grib_value.c b/src/grib_value.c index 3f8a30cca..85f8558d1 100644 --- a/src/grib_value.c +++ b/src/grib_value.c @@ -799,18 +799,18 @@ int grib_set_double_array(grib_handle* h, const char* name, const double* val, s return __grib_set_double_array(h, name, val, length, /*check=*/1); } -static int _grib_set_long_array_internal(grib_handle* h, grib_accessor* a, const long* val, size_t buffer_len, size_t* encoded_length, int check) +static int _grib_set_long_array_internal(grib_handle* h, grib_accessor* a, const long* iarrayval, size_t iarraysize, size_t* encoded_length, int check) { if (a) { - int err = _grib_set_long_array_internal(h, a->same, val, buffer_len, encoded_length, check); + int err = _grib_set_long_array_internal(h, a->same, iarrayval, iarraysize, encoded_length, check); if (check && (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY)) return GRIB_READ_ONLY; if (err == GRIB_SUCCESS) { - size_t len = buffer_len - *encoded_length; + size_t len = iarraysize - *encoded_length; if (len) { - err = grib_pack_long(a, val + *encoded_length, &len); + err = grib_pack_long(a, iarrayval + *encoded_length, &len); *encoded_length += len; } else { @@ -826,7 +826,7 @@ static int _grib_set_long_array_internal(grib_handle* h, grib_accessor* a, const } } -static int _grib_set_long_array(grib_handle* h, const char* name, const long* val, size_t length, int check) +static int _grib_set_long_array(grib_handle* h, const char* name, const long* iarrayval, size_t iarraysize, int check) { size_t encoded = 0; grib_accessor* a = grib_find_accessor(h, name); @@ -838,12 +838,12 @@ static int _grib_set_long_array(grib_handle* h, const char* name, const long* va if (h->context->debug) { size_t i = 0; size_t N = 5; - if (length <= N) - N = length; - fprintf(stderr, "ECCODES DEBUG _grib_set_long_array key=%s %ld values (", name, (long)length); + if (iarraysize <= N) + N = iarraysize; + fprintf(stderr, "ECCODES DEBUG _grib_set_long_array key=%s %ld values (", name, (long)iarraysize); for (i = 0; i < N; ++i) - fprintf(stderr, " %ld,", val[i]); - if (N >= length) + fprintf(stderr, " %ld,", iarrayval[i]); + if (N >= iarraysize) fprintf(stderr, " )\n"); else fprintf(stderr, " ... )\n"); @@ -852,13 +852,13 @@ static int _grib_set_long_array(grib_handle* h, const char* name, const long* va if (name[0] == '/' || name[0] == '#') { if (check && (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY)) return GRIB_READ_ONLY; - err = grib_pack_long(a, val, &length); - encoded = length; + err = grib_pack_long(a, iarrayval, &iarraysize); + encoded = iarraysize; } else - err = _grib_set_long_array_internal(h, a, val, length, &encoded, check); + err = _grib_set_long_array_internal(h, a, iarrayval, iarraysize, &encoded, check); - if (err == GRIB_SUCCESS && length > encoded) + if (err == GRIB_SUCCESS && iarraysize > encoded) err = GRIB_ARRAY_TOO_SMALL; if (err == GRIB_SUCCESS) @@ -876,9 +876,9 @@ int grib_set_long_array_internal(grib_handle* h, const char* name, const long* v return ret; } -int grib_set_long_array(grib_handle* h, const char* name, const long* val, size_t length) +int grib_set_long_array(grib_handle* h, const char* name, const long* iarrayval, size_t iarraysize) { - return _grib_set_long_array(h, name, val, length, 1); + return _grib_set_long_array(h, name, iarrayval, iarraysize, 1); } int grib_get_long_internal(grib_handle* h, const char* name, long* val) diff --git a/src/grib_vdarray.c b/src/grib_vdarray.c index b77d4a61d..80fa3b377 100644 --- a/src/grib_vdarray.c +++ b/src/grib_vdarray.c @@ -11,117 +11,239 @@ /*************************************************************************** * * Enrico Fucile + * Modified for Performance Study by: CS GMBH * ***************************************************************************/ #include "grib_api_internal.h" /* For debugging purposes */ -void grib_vdarray_print(const char* title, const grib_vdarray* vdarray) +void grib_vdarray_print(const char* title, const grib_vdarray* source) { size_t i; char text[100] = {0,}; - Assert(vdarray); - printf("%s: vdarray.n=%lu\n", title, (unsigned long)vdarray->n); - for (i = 0; i < vdarray->n; i++) { + Assert(source); + printf("%s: vdarray.n=%lu\n", title, (unsigned long)source->n); + for (i = 0; i < source->n; i++) { sprintf(text, " vdarray->v[%lu]", (unsigned long)i); - grib_darray_print(text, vdarray->v[i]); + //grib_darray_print(text, source->v[i]); + if( i<= (DYN_DEFAULT_VDARRAY_SIZE_INIT - 1)) { + grib_darray_print(text, source->stA[i]); + } else { + grib_darray_print(text, source->dynA[(i-(DYN_DEFAULT_VDARRAY_SIZE_INIT))]); + } } printf("\n"); } grib_vdarray* grib_vdarray_new(grib_context* c, size_t size, size_t incsize) { - grib_vdarray* v = NULL; - if (!c) - c = grib_context_get_default(); - v = (grib_vdarray*)grib_context_malloc_clear(c, sizeof(grib_vdarray)); - if (!v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_vdarray_new unable to allocate %d bytes\n", sizeof(grib_vdarray)); - return NULL; - } - v->size = size; - v->n = 0; - v->incsize = incsize; - v->v = (grib_darray**)grib_context_malloc_clear(c, sizeof(grib_darray*) * size); - if (!v->v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_vdarray_new unable to allocate %d bytes\n", sizeof(grib_darray*) * size); - return NULL; - } - return v; + grib_vdarray* result = NULL; + + if (!c) + c = grib_context_get_default(); + + result = (grib_vdarray*)grib_context_malloc_clear(c, sizeof(grib_vdarray)); + if (!result) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_vdarray_new unable to allocate %d bytes\n", sizeof(grib_vdarray)); + return NULL; + } + + if(size > DYN_DEFAULT_VDARRAY_SIZE_INIT) { + + result->dynA = (grib_darray**)grib_context_malloc_clear(c, sizeof(grib_darray*) * (size-DYN_DEFAULT_VDARRAY_SIZE_INIT) ); + + if (!result->dynA) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_vdarray_new unable to allocate %d bytes\n", sizeof(grib_darray*) * (size-DYN_DEFAULT_VDARRAY_SIZE_INIT) ); + return NULL; + } + result->size = size; + + if (incsize > 0) + result->incsize = incsize; + else + result->incsize = DYN_DEFAULT_VDARRAY_SIZE_INCR; + + } else { + + result->dynA = NULL; + result->size = DYN_DEFAULT_VDARRAY_SIZE_INIT; + result->incsize = DYN_DEFAULT_VDARRAY_SIZE_INCR; + + } + + result->n = 0; + + return result; } -grib_vdarray* grib_vdarray_resize(grib_context* c, grib_vdarray* v) +grib_vdarray* grib_vdarray_resize(grib_context* c, grib_vdarray* origin) { - int newsize = v->incsize + v->size; + int newsize; - if (!c) - c = grib_context_get_default(); - - v->v = (grib_darray**)grib_context_realloc(c, v->v, newsize * sizeof(grib_darray*)); - v->size = newsize; - if (!v->v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_vdarray_resize unable to allocate %d bytes\n", sizeof(grib_darray*) * newsize); - return NULL; - } - return v; + if (origin == NULL) + { + return origin; + } + if (!c) + c = grib_context_get_default(); + + newsize = origin->incsize + origin->size; + + if (origin->dynA != NULL){ + + origin->dynA = (grib_darray**)grib_context_realloc(c, origin->dynA, sizeof(grib_darray*) * (newsize-DYN_DEFAULT_VDARRAY_SIZE_INIT) ); + + if (!origin->dynA) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_vdarray_resize unable to allocate %d bytes\n", sizeof(grib_darray*) * (newsize-DYN_DEFAULT_VDARRAY_SIZE_INIT) ); + return NULL; + } + + } + else { + + origin->dynA = (grib_darray**)grib_context_malloc(c, sizeof(grib_darray*) * (newsize-DYN_DEFAULT_VDARRAY_SIZE_INIT) ); + + if (!origin->dynA) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_vdarray_resize unable to allocate %d bytes\n", sizeof(grib_darray*) * (newsize-DYN_DEFAULT_VDARRAY_SIZE_INIT ) ); + return NULL; + } + + } + + origin->size = newsize; + + return origin; } -grib_vdarray* grib_vdarray_push(grib_context* c, grib_vdarray* v, grib_darray* val) +grib_vdarray* grib_vdarray_push(grib_context* c, grib_vdarray* source, grib_darray* val) { - size_t start_size = 100; - size_t start_incsize = 100; - if (!v) - v = grib_vdarray_new(c, start_size, start_incsize); - - if (v->n >= v->size) - v = grib_vdarray_resize(c, v); - v->v[v->n] = val; - v->n++; - return v; + + size_t start_size = DYN_DEFAULT_VDARRAY_SIZE_INIT; + size_t start_incsize = DYN_DEFAULT_VDARRAY_SIZE_INCR; + + if (!source) + source = grib_vdarray_new(c, start_size, start_incsize); + + //If the actual used size of the target is equal to the allowed size, resize the array + if (source->n == source->size) { + + source = grib_vdarray_resize(c, source); + + //Check if REALLOC WAS POSSIBLE, otherwise it is not possible to insert a new value! + if (source == NULL) + { + return source; + } + + //insertion in new allocated dynamic array + source->dynA[ (source->n-(DYN_DEFAULT_VDARRAY_SIZE_INIT)) ] = val; + source->n++; + return source; + + } + + //insertion in static array + if (source->n <= (DYN_DEFAULT_VDARRAY_SIZE_INIT - 1) ) + { + source->stA[source->n] = val; + } + else { + //insertion in dynamic array + source->dynA[ (source->n-(DYN_DEFAULT_VDARRAY_SIZE_INIT)) ] = val; + } + + source->n++; + return source; } -void grib_vdarray_delete(grib_context* c, grib_vdarray* v) +/** + * Return the grib_darray* value at index 'index' for grib_vdarray 'source' + */ +grib_darray* grib_vdarray_get(grib_vdarray* source, size_t index) { - if (!v) - return; - if (!c) - grib_context_get_default(); - if (v->v) - grib_context_free(c, v->v); - grib_context_free(c, v); + if (!source) + return NULL; + if (index < 0) + return NULL; + if (index < DYN_DEFAULT_VDARRAY_SIZE_INIT) { + return source->stA[index]; + } else { + if (source->dynA != NULL) { + return source->dynA[(index-DYN_DEFAULT_VDARRAY_SIZE_INIT)]; + } + } + + return NULL; +} + +/** + * Sets the grib_darray* value 'val' at index 'index' for grib_vdarray 'source'. + * The method overwrites the existing value, if any. + * The method returns 1 if the writing operation occurred, otherwise 0. + */ +int grib_vdarray_put (grib_vdarray* source, size_t index, grib_darray* val) +{ + if (!source) + return 0; + if (index < 0) + return 0; + if (index < DYN_DEFAULT_VDARRAY_SIZE_INIT) { + source->stA[index] = val; + + } else { + if (source->dynA != NULL) { + source->dynA[(index-DYN_DEFAULT_VDARRAY_SIZE_INIT)] = val; + } + } + + return 1; } -void grib_vdarray_delete_content(grib_context* c, grib_vdarray* v) +void grib_vdarray_delete(grib_context* c, grib_vdarray* source) { - int i; - if (!v || !v->v) + if (!source) return; if (!c) grib_context_get_default(); - for (i = 0; i < v->n; i++) { - grib_darray_delete(c, v->v[i]); - v->v[i] = 0; - } - v->n = 0; + if (source->dynA) + grib_context_free(c, source->dynA); + grib_context_free(c, source); } -grib_darray** grib_vdarray_get_array(grib_context* c, grib_vdarray* v) +void grib_vdarray_delete_content(grib_context* c, grib_vdarray* source) { - grib_darray** ret; - int i; - if (!v) - return NULL; - ret = (grib_darray**)grib_context_malloc_clear(c, sizeof(grib_darray*) * v->n); - for (i = 0; i < v->n; i++) - ret[i] = v->v[i]; - return ret; + int i; + + if (!source) + return; + /* Not needed: the grib_vdarray_delete is always called already, after grib_vdarray_delete_content + if (!c) + grib_context_get_default(); + */ + + //If the actual used size of the target is greater than the allowed size, it is a resized array + if ( (source->n > source->size) && ( source->dynA != NULL ) ) { + for (i = 0; i < (source->n - DYN_DEFAULT_VDARRAY_SIZE_INIT); i++) { + /* Not needed: the grib_vdarray_delete is always called already, after grib_vdarray_delete_content + * grib_vdarray_delete(c, source->dynA[i]); + */ + source->dynA[i] = 0; + } + } + + for (i = 0; i < (DYN_DEFAULT_VDARRAY_SIZE_INIT); i++) { + source->stA[i] = 0; + } + + source->n = 0; } -size_t grib_vdarray_used_size(grib_vdarray* v) +size_t grib_vdarray_used_size(grib_vdarray* source) { - return v->n; + return source == NULL ? 0 : source->n; } diff --git a/src/grib_viarray.c b/src/grib_viarray.c index 8033ca669..ed3835a1b 100644 --- a/src/grib_viarray.c +++ b/src/grib_viarray.c @@ -11,103 +11,209 @@ /*************************************************************************** * * Enrico Fucile + * Modified for Performance Study by: CS GMBH * ***************************************************************************/ #include "grib_api_internal.h" +/* For debugging purposes */ +void grib_viarray_print(const char* title, const grib_viarray* source) +{ + size_t i; + char text[100] = {0,}; + Assert(source); + printf("%s: viarray.n=%lu\n", title, (unsigned long)source->n); + for (i = 0; i < source->n; i++) { + sprintf(text, " viarray->v[%lu]", (unsigned long)i); + if( i<= (DYN_DEFAULT_VIARRAY_SIZE_INIT - 1)) { + grib_iarray_print(text, source->stA[i]); + } else { + grib_iarray_print(text, source->dynA[(i-(DYN_DEFAULT_VIARRAY_SIZE_INIT))]); + } + } + printf("\n"); +} + grib_viarray* grib_viarray_new(grib_context* c, size_t size, size_t incsize) { - grib_viarray* v = NULL; + grib_viarray* result = NULL; + if (!c) c = grib_context_get_default(); - v = (grib_viarray*)grib_context_malloc_clear(c, sizeof(grib_viarray)); - if (!v) { + + result = (grib_viarray*)grib_context_malloc_clear(c, sizeof(grib_viarray)); + if (!result) { grib_context_log(c, GRIB_LOG_ERROR, "grib_viarray_new unable to allocate %d bytes\n", sizeof(grib_viarray)); return NULL; } - v->size = size; - v->n = 0; - v->incsize = incsize; - v->v = (grib_iarray**)grib_context_malloc_clear(c, sizeof(grib_iarray*) * size); - if (!v->v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_viarray_new unable to allocate %d bytes\n", sizeof(grib_iarray*) * size); - return NULL; + + if(size > DYN_DEFAULT_VIARRAY_SIZE_INIT) { + + result->dynA = (grib_iarray**)grib_context_malloc_clear(c, sizeof(grib_iarray*) * (size-DYN_DEFAULT_VIARRAY_SIZE_INIT) ); + + if (!result->dynA) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_viarray_new unable to allocate %d bytes\n", sizeof(grib_iarray*) * (size-DYN_DEFAULT_VIARRAY_SIZE_INIT) ); + return NULL; + } + result->size = size; + + if (incsize > 0) + result->incsize = incsize; + else + result->incsize = DYN_DEFAULT_VIARRAY_SIZE_INCR; + + } else { + + result->dynA = NULL; + result->size = DYN_DEFAULT_VIARRAY_SIZE_INIT; + result->incsize = DYN_DEFAULT_VIARRAY_SIZE_INCR; + } - return v; + + result->n = 0; + + return result; } -grib_viarray* grib_viarray_resize(grib_context* c, grib_viarray* v) +grib_viarray* grib_viarray_resize(grib_context* c, grib_viarray* origin) { - int newsize = v->incsize + v->size; + int newsize; - if (!c) - c = grib_context_get_default(); + if (origin == NULL) + { + return origin; + } + if (!c) + c = grib_context_get_default(); - v->v = (grib_iarray**)grib_context_realloc(c, v->v, newsize * sizeof(grib_iarray*)); - v->size = newsize; - if (!v->v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_viarray_resize unable to allocate %d bytes\n", sizeof(grib_iarray*) * newsize); - return NULL; + newsize = origin->incsize + origin->size; + + if (origin->dynA != NULL){ + + origin->dynA = (grib_iarray**)grib_context_realloc(c, origin->dynA, sizeof(grib_iarray*) * (newsize-DYN_DEFAULT_VIARRAY_SIZE_INIT) ); + + if (!origin->dynA) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_viarray_resize unable to allocate %d bytes\n", sizeof(grib_iarray*) * (newsize-DYN_DEFAULT_VIARRAY_SIZE_INIT) ); + return NULL; + } + + } + else { + + origin->dynA = (grib_iarray**)grib_context_malloc(c, sizeof(grib_iarray*) * (newsize-DYN_DEFAULT_VIARRAY_SIZE_INIT) ); + + if (!origin->dynA) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_viarray_resize unable to allocate %d bytes\n", sizeof(grib_iarray*) * (newsize-DYN_DEFAULT_VIARRAY_SIZE_INIT ) ); + return NULL; + } + + } + + origin->size = newsize; + + return origin; +} + +grib_viarray* grib_viarray_push(grib_context* c, grib_viarray* source, grib_iarray* val) +{ + size_t start_size = DYN_DEFAULT_VIARRAY_SIZE_INIT; + size_t start_incsize = DYN_DEFAULT_VIARRAY_SIZE_INCR; + + //If the target is empty, initialize it + if (!source) + source = grib_viarray_new(c, start_size, start_incsize); + + //If the actual used size of the target is equal to the allowed size, resize the array + if (source->n == source->size) { + + source = grib_viarray_resize(c, source); + + //Check if REALLOC WAS POSSIBLE, otherwise it is not possible to insert a new value! + if (source == NULL) + { + return source; + } + + //insertion in new allocated dynamic array + source->dynA[ (source->n-(DYN_DEFAULT_VIARRAY_SIZE_INIT)) ] = val; + source->n++; + return source; + + } + + //insertion in static array + if (source->n <= (DYN_DEFAULT_VIARRAY_SIZE_INIT - 1) ) + { + source->stA[source->n] = val; + } + else { + //insertion in dynamic array + source->dynA[ (source->n-(DYN_DEFAULT_VIARRAY_SIZE_INIT)) ] = val; } - return v; + + source->n++; + return source; } -grib_viarray* grib_viarray_push(grib_context* c, grib_viarray* v, grib_iarray* val) +grib_iarray* grib_viarray_get(grib_viarray* source, size_t index) { - size_t start_size = 100; - size_t start_incsize = 100; - if (!v) - v = grib_viarray_new(c, start_size, start_incsize); - - if (v->n >= v->size) - v = grib_viarray_resize(c, v); - v->v[v->n] = val; - v->n++; - return v; + if (!source) + return NULL; + if (index < 0) + return NULL; + if (index < DYN_DEFAULT_VIARRAY_SIZE_INIT) { + return source->stA[index]; + } else { + if (source->dynA != NULL) { + return source->dynA[(index-DYN_DEFAULT_VIARRAY_SIZE_INIT)]; + } + } + + return NULL; } -void grib_viarray_delete(grib_context* c, grib_viarray* v) +void grib_viarray_delete(grib_context* c, grib_viarray* source) { - if (!v) + if (!source) return; if (!c) grib_context_get_default(); - if (v->v) - grib_context_free(c, v->v); - grib_context_free(c, v); + if (source->dynA) + grib_context_free(c, source->dynA); + grib_context_free(c, source); } -void grib_viarray_delete_content(grib_context* c, grib_viarray* v) +void grib_viarray_delete_content(grib_context* c, grib_viarray* source) { int i; - if (!v || !v->v) + + if (!source) return; + if (!c) grib_context_get_default(); - for (i = 0; i < v->n; i++) { - grib_iarray_delete(v->v[i]); - v->v[i] = 0; + + //If the actual used size of the target is greater than the allowed size, it is a resized array + if ( (source->n > source->size) && ( source->dynA != NULL ) ) { + for (i = 0; i < (source->n - DYN_DEFAULT_VIARRAY_SIZE_INIT); i++) { + grib_iarray_delete(source->dynA[i]); + source->dynA[i] = 0; + } } - v->n = 0; -} -grib_iarray** grib_viarray_get_array(grib_context* c, grib_viarray* v) -{ - grib_iarray** ret; - int i; - if (!v) - return NULL; - ret = (grib_iarray**)grib_context_malloc_clear(c, sizeof(grib_iarray*) * v->n); - for (i = 0; i < v->n; i++) - ret[i] = v->v[i]; - return ret; + for (i = 0; i < (DYN_DEFAULT_VIARRAY_SIZE_INIT); i++) { + source->stA[i] = 0; + } + + source->n = 0; } -size_t grib_viarray_used_size(grib_viarray* v) +size_t grib_viarray_used_size(grib_viarray* source) { - return v->n; + return source == NULL ? 0 : source->n; } diff --git a/src/grib_vsarray.c b/src/grib_vsarray.c index 237e42797..b5a7b97c1 100644 --- a/src/grib_vsarray.c +++ b/src/grib_vsarray.c @@ -11,6 +11,7 @@ /*************************************************************************** * * Enrico Fucile + * Modified for Performance Study by: CS GMBH * ***************************************************************************/ @@ -18,97 +19,215 @@ grib_vsarray* grib_vsarray_new(grib_context* c, size_t size, size_t incsize) { - grib_vsarray* v = NULL; - if (!c) - c = grib_context_get_default(); - v = (grib_vsarray*)grib_context_malloc_clear(c, sizeof(grib_vsarray)); - if (!v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_vsarray_new unable to allocate %d bytes\n", sizeof(grib_vsarray)); - return NULL; - } - v->size = size; - v->n = 0; - v->incsize = incsize; - v->v = (grib_sarray**)grib_context_malloc_clear(c, sizeof(grib_sarray*) * size); - if (!v->v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_vsarray_new unable to allocate %d bytes\n", sizeof(grib_sarray*) * size); - return NULL; - } - return v; + grib_vsarray* result = NULL; + + if (!c) + c = grib_context_get_default(); + + result = (grib_vsarray*)grib_context_malloc_clear(c, sizeof(grib_vsarray)); + + if (!result) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_vsarray_new unable to allocate %d bytes\n", sizeof(grib_vsarray)); + return NULL; + } + + if(size > DYN_DEFAULT_VSARRAY_SIZE_INIT) { + + result->dynA = (grib_sarray**)grib_context_malloc_clear(c, sizeof(grib_sarray*) * (size-DYN_DEFAULT_VSARRAY_SIZE_INIT) ); + + if (!result->dynA) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_vsarray_new unable to allocate %d bytes\n", sizeof(grib_sarray*) * (size-DYN_DEFAULT_VSARRAY_SIZE_INIT) ); + return NULL; + } + result->size = size; + + if (incsize > 0) + result->incsize = incsize; + else + result->incsize = DYN_DEFAULT_VSARRAY_SIZE_INCR; + + } else { + + result->dynA = NULL; + result->size = DYN_DEFAULT_VSARRAY_SIZE_INIT; + result->incsize = DYN_DEFAULT_VSARRAY_SIZE_INCR; + + } + + result->n = 0; + + return result; +} + +grib_vsarray* grib_vsarray_resize(grib_context* c, grib_vsarray* origin) +{ + int newsize; + + if (origin == NULL) + { + return origin; + } + + newsize = origin->incsize + origin->size; + + if (!c) + c = grib_context_get_default(); + + if (origin->dynA != NULL){ + + origin->dynA = (grib_sarray**)grib_context_realloc(c, origin->dynA, (newsize-DYN_DEFAULT_VSARRAY_SIZE_INIT) * sizeof(grib_sarray*)); + if (!origin->dynA) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_vsarray_resize unable to allocate %d bytes\n", sizeof(grib_sarray*) * (newsize-DYN_DEFAULT_VSARRAY_SIZE_INIT) ); + return NULL; + } + + } + else { + + origin->dynA = (grib_sarray**)grib_context_malloc(c, (newsize-DYN_DEFAULT_VSARRAY_SIZE_INIT) * sizeof(grib_sarray*)); + if (!origin->dynA) { + grib_context_log(c, GRIB_LOG_ERROR, + "grib_sarray_resize unable to allocate %d bytes\n", sizeof(grib_sarray*) * (newsize-DYN_DEFAULT_SARRAY_SIZE_INIT) ); + return NULL; + } + + } + + origin->size = newsize; + + return origin; } -grib_vsarray* grib_vsarray_resize(grib_context* c, grib_vsarray* v) +grib_vsarray* grib_vsarray_push(grib_context* c, grib_vsarray* source, grib_sarray* val) { - int newsize = v->incsize + v->size; + size_t start_size = DYN_DEFAULT_VSARRAY_SIZE_INIT; + size_t start_incsize = DYN_DEFAULT_VSARRAY_SIZE_INCR; + + //If the target is empty, initialize it + if (!source) + source = grib_vsarray_new(c, start_size, start_incsize); + + //If the actual used size of the target is equal to the allowed size, resize the array + if (source->n == source->size) { - if (!c) - c = grib_context_get_default(); + source = grib_vsarray_resize(c, source); + + //Check if REALLOC WAS POSSIBLE, otherwise it is not possible to insert a new value! + if (source == NULL) + { + return source; + } + + //insertion in new allocated dynamic array + source->dynA[ (source->n-(DYN_DEFAULT_VSARRAY_SIZE_INIT)) ] = val; + source->n++; + return source; - v->v = (grib_sarray**)grib_context_realloc(c, v->v, newsize * sizeof(grib_sarray*)); - v->size = newsize; - if (!v->v) { - grib_context_log(c, GRIB_LOG_ERROR, - "grib_vsarray_resize unable to allocate %d bytes\n", sizeof(grib_sarray*) * newsize); - return NULL; } - return v; + + //insertion in static array + if (source->n <= (DYN_DEFAULT_VSARRAY_SIZE_INIT - 1) ) + { + source->stA[source->n] = val; + } + else { + //insertion in dynamic array + source->dynA[ (source->n-(DYN_DEFAULT_VSARRAY_SIZE_INIT)) ] = val; + } + + source->n++; + + return source; } -grib_vsarray* grib_vsarray_push(grib_context* c, grib_vsarray* v, grib_sarray* val) +/** + * Return the grib_sarray* value at index 'index' for grib_vsarray 'source' + */ +grib_sarray* grib_vsarray_get(grib_vsarray* source, size_t index) { - size_t start_size = 100; - size_t start_incsize = 100; - if (!v) - v = grib_vsarray_new(c, start_size, start_incsize); - - if (v->n >= v->size) - v = grib_vsarray_resize(c, v); - v->v[v->n] = val; - v->n++; - return v; + + if (!source) + return NULL; + if (index < 0) + return NULL; + if (index < DYN_DEFAULT_VSARRAY_SIZE_INIT) { + return source->stA[index]; + } else { + if (source->dynA != NULL) { + return source->dynA[(index-DYN_DEFAULT_VSARRAY_SIZE_INIT)]; + } + } + + return NULL; } -void grib_vsarray_delete(grib_context* c, grib_vsarray* v) +/** + * Sets the grib_sarray* value 'val' at index 'index' for grib_vsarray 'source'. + * The method overwrites the existing value, if any. + * The method returns 1 if the writing operation occurred, otherwise 0. + */ +int grib_vsarray_put (grib_vsarray* source, size_t index, grib_sarray* val) { - if (!v) - return; - if (!c) - grib_context_get_default(); - if (v->v) - grib_context_free(c, v->v); - grib_context_free(c, v); + if (!source) + return 0; + if (index < 0) + return 0; + if (index < DYN_DEFAULT_VSARRAY_SIZE_INIT) { + source->stA[index] = val; + + } else { + if (source->dynA != NULL) { + source->dynA[(index-DYN_DEFAULT_VSARRAY_SIZE_INIT)] = val; + } + } + + return 1; } -void grib_vsarray_delete_content(grib_context* c, grib_vsarray* v) +void grib_vsarray_delete(grib_context* c, grib_vsarray* source) { - int i; - if (!v || !v->v) - return; - if (!c) - grib_context_get_default(); - for (i = 0; i < v->n; i++) { - grib_sarray_delete_content(c, v->v[i]); - grib_sarray_delete(c, v->v[i]); - v->v[i] = 0; - } - v->n = 0; + if (!source) + return; + if (!c) + grib_context_get_default(); + + if (source->dynA) + grib_context_free(c, source->dynA); + + grib_context_free(c, source); } -grib_sarray** grib_vsarray_get_array(grib_context* c, grib_vsarray* v) +void grib_vsarray_delete_content(grib_context* c, grib_vsarray* source) { - grib_sarray** ret; - int i; - if (!v) - return NULL; - ret = (grib_sarray**)grib_context_malloc_clear(c, sizeof(grib_sarray*) * v->n); - for (i = 0; i < v->n; i++) - ret[i] = v->v[i]; - return ret; + int i; + + if (!source) + return; + + /* + if (!c) + grib_context_get_default(); + */ + + //If the actual used size of the target is greater than the allowed size, it is a resized array + if (source->n > source->size && ( source->dynA != NULL ) ) { + for (i = 0; i < (source->n - DYN_DEFAULT_VSARRAY_SIZE_INIT); i++) { + /* grib_vsarray_delete(c, source->dynA[i]); */ + source->dynA[i] = 0; + } + } + + for (i = 0; i < (DYN_DEFAULT_VSARRAY_SIZE_INIT); i++) { + source->stA[i] = 0; + } + + source->n = 0; } -size_t grib_vsarray_used_size(grib_vsarray* v) +size_t grib_vsarray_used_size(grib_vsarray* source) { - return v->n; + return source == NULL ? 0 : source->n; } diff --git a/src/makeyacc b/src/makeyacc index 3d406fcfe..545ffc5f4 100755 --- a/src/makeyacc +++ b/src/makeyacc @@ -1,17 +1,40 @@ set -xe +yacc --version | head -1 | grep 'bison' >> /dev/null 2>&1 + +rm -rf ../profiling_parser/ >> /dev/null 2>&1 ; +#The original grib_lex.c contains adjustements made from eccodes developers: keep them! +mv grib_lex.c grib_lex.c.orig + +mkdir ../profiling_parser/ >> /dev/null 2>&1 ; export LEX=flex export LEX_OUT=gribl.c $LEX -o gribl.c gribl.l sed 's/yy/grib_yy/g' < $LEX_OUT | sed 's/static void grib_yyunput/void grib_yyunput/' > grib_lex1.c sed 's/fgetc/getc/g' < grib_lex1.c > grib_lex.c -rm -f grib_lex1.c -rm -f $LEX_OUT + +#rm -f grib_lex1.c +mv grib_lex1.c ../profiling_parser/ +#rm -f $LEX_OUT +mv $LEX_OUT ../profiling_parser/ +cp -rp grib_lex.c ../profiling_parser/ +cp -rp grib_lex.c.orig ../profiling_parser/ + +#Remember to re-establish the original grib_lex.c +mv grib_lex.c.orig grib_lex.c yacc -v -d griby.y sed 's/yy/grib_yy/g' < y.tab.c > grib_yacc1.c sed 's/fgetc/getc/g' < grib_yacc1.c > grib_yacc.c -rm -f grib_yacc1.c + +#rm -f grib_yacc1.c +mv grib_yacc1.c ../profiling_parser/ + sed 's/yy/grib_yy/g' < y.tab.h > grib_yacc.h -rm -f y.tab.c y.tab.h + +#rm -f y.tab.c y.tab.h +mv y.tab.c ../profiling_parser/ ; mv y.tab.h ../profiling_parser/ ; + +mv y.output ../profiling_parser/ ; + echo echo ALL OK diff --git a/tests/bufr_dump_samples.sh b/tests/bufr_dump_samples.sh index 41a341218..3a4eae3b8 100755 --- a/tests/bufr_dump_samples.sh +++ b/tests/bufr_dump_samples.sh @@ -22,9 +22,11 @@ touch $fLog fJsonTmp=${label}".json.tmp" # Test sample BUFR files +echo "ECCODES_SAMPLES_PATH: \""$ECCODES_SAMPLES_PATH"\" "; +echo "fLog: \""$fLog"\" "; for file in $ECCODES_SAMPLES_PATH/BUFR*.tmpl; do ${tools_dir}/bufr_dump -O $file >/dev/null ${tools_dir}/bufr_dump -d $file >/dev/null done -rm -f $fLog +#rm -f $fLog diff --git a/tools/bufr_compare.c b/tools/bufr_compare.c index 8c2cae0de..177eceb00 100644 --- a/tools/bufr_compare.c +++ b/tools/bufr_compare.c @@ -899,8 +899,10 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g int ii; countdiff = 0; for (ii = 0; ii < len1; ii++) - if (lval1[ii] != lval2[ii]) + if (lval1[ii] != lval2[ii]) { + printf("DIFF!!! long [%s][%d]: [%ld] != [%ld]\n", name, ii, lval1[ii], lval2[ii]); countdiff++; + } if (countdiff) { printInfo(handle1); @@ -1037,6 +1039,7 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g printf(" (%d values) tolerance=%g\n", (int)len1, value_tolerance); for (i = 0; i < len1; i++) { if ((diff = compare_double(pv1++, pv2++, &value_tolerance)) != 0) { + printf("DIFF!!! double [%s][%d]: [%ld] != [%ld]\n", name, i, *pv1, *pv2); countdiff++; if (maxdiff < diff) { maxdiff = diff;