diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 16c400bec..17873147b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,7 +82,7 @@ jobs: - private-downstream-ci - downstream-ci-hpc - private-downstream-ci-hpc - if: always() && ${{ !github.event.pull_request.head.repo.fork && github.event.action != 'labeled' || github.event.label.name == 'approved-for-ci' }} + if: ${{ always() && !github.event.pull_request.head.repo.fork && github.event.action != 'labeled' || github.event.label.name == 'approved-for-ci' }} steps: - name: Trigger Teams notification uses: ecmwf-actions/notify-teams@v1 diff --git a/.gitignore b/.gitignore index bfdfd9434..8791994fc 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,8 @@ grib_api.pc grib_api_f90.pc *.analyzerinfo *.snalyzerinfo +tags +src/convert_*.sh # compiled source # ################### @@ -72,3 +74,4 @@ data/bufr/*test build/ *.back +trash diff --git a/definitions/bufr/section.1.3.def b/definitions/bufr/section.1.3.def index 84ac947b0..811b0955a 100644 --- a/definitions/bufr/section.1.3.def +++ b/definitions/bufr/section.1.3.def @@ -20,7 +20,8 @@ unsigned[1] localTablesVersionNumber : dump; transient typicalCentury=21; unsigned[1] typicalYearOfCentury : dump; -transient typicalYear = (typicalCentury - 1) * 100 + typicalYearOfCentury : no_copy; +# ECC-1840: Use the 'evaluate' accessor so typicalYear is updated if user changes typicalCentury +meta typicalYear evaluate( (typicalCentury - 1) * 100 + typicalYearOfCentury ) : no_copy; unsigned[1] typicalMonth : dump; unsigned[1] typicalDay : dump; diff --git a/definitions/common/c-11.table b/definitions/common/c-11.table index 778001045..6750fda58 100644 --- a/definitions/common/c-11.table +++ b/definitions/common/c-11.table @@ -23,6 +23,7 @@ 22 22 ACMAD 23 23 Mozambique (NMC) 24 fapr Pretoria (RSMC) +25 25 La Reunion (RSMC) 26 26 Khabarovsk (RSMC) 28 vabb New Delhi (IMD) 29 dems New Delhi (NCMRWF) @@ -58,12 +59,14 @@ 64 64 Honolulu 65 65 Darwin (RSMC) 67 67 Melbourne (RSMC) +# 68 Reserved 69 nzkl Wellington (RSMC/RAFC) 71 71 Nadi (RSMC) 72 72 Singapore 73 73 Malaysia (NMC) 74 egrr U.K. Met Office - Exeter 76 76 Moscow (RSMC/RAFC) +# 77 Reserved 78 edzw Offenbach (RSMC) 80 cnmc Rome (RSMC) 82 eswi Norrkoping @@ -93,15 +96,68 @@ 107 107 Uganda (NMC) 108 108 United Republic of Tanzania (NMC) 109 109 Zimbabwe (NMC) -110 110 Hong-Kong +110 110 Hong Kong +111 111 Afghanistan (NMC) +112 112 Bahrain (NMC) +113 113 Bangladesh (NMC) +114 114 Bhutan (NMC) +115 115 Cambodia (NMC) +116 116 Democratic People's Republic of Korea (NMC) +117 117 Islamic Republic of Iran (NMC) +118 118 Iraq (NMC) +119 119 Kazakhstan (NMC) +120 120 Kuwait (NMC) +121 121 Kyrgyzstan (NMC) +122 122 Lao People's Democratic Republic (NMC) +123 123 "Macao China" +124 124 Maldives (NMC) +125 125 Myanmar (NMC) +126 126 Nepal (NMC) +127 127 Oman (NMC) +128 128 Pakistan (NMC) +129 129 Qatar (NMC) +130 130 Yemen (NMC) +131 131 Sri Lanka (NMC) +132 132 Tajikistan (NMC) +133 133 Turkmenistan (NMC) +134 134 United Arab Emirates (NMC) +135 135 Uzbekistan (NMC) +136 136 Viet Nam (NMC) +# 137-139 Reserved for other centres +140 140 Bolivia (Plurinational State of) (NMC) +141 141 Guyana (NMC) +142 142 Paraguay (NMC) +143 143 Suriname (NMC) +144 144 Uruguay (NMC) 145 145 French Guiana 146 146 Brazilian Navy Hydrographic Centre 147 147 National Commission on Space Activities (CONAE) - Argentina 148 148 Brazilian Department of Airspace Control - DECEA +# 149 Reserved for other centres +150 150 Antigua and Barbuda (NMC) +151 151 Bahamas (NMC) +152 152 Barbados (NMC) +153 153 Belize (NMC) +154 154 British Caribbean Territories Centre +155 155 San Jose +156 156 Cuba (NMC) +157 157 Dominica (NMC) +158 158 Dominican Republic (NMC) +159 159 El Salvador (NMC) 160 160 US NOAA/NESDIS 161 161 US NOAA Office of Oceanic and Atmospheric Research +162 162 Guatemala (NMC) +163 163 Haiti (NMC) +164 164 Honduras (NMC) +165 165 Jamaica (NMC) +166 166 Mexico +167 167 Curacao and Sint Maarten (NMC) +168 168 Nicaragua (NMC) +169 169 Panama (NMC) +170 170 Saint Lucia (NMC) +171 171 Trinidad and Tobago (NMC) +172 172 French Departments in RA IV 173 nasa US National Aeronautics and Space Administration (NASA) - 174 174 Integrated Science Data Management/Marine Environmental Data Service (ISDM/MEDS - Canada) 175 175 University Corporation for Atmospheric Research (UCAR) - United States 176 176 Cooperative Institute for Meteorological Satellite Studies (CIMSS) - United States @@ -110,9 +166,23 @@ 179 179 GeoOptics, Inc. 180 180 PlanetiQ 181 181 Atmospheric and Environmental Research (AER) - +# 182-189 Reserved for other centres +190 190 Cook Islands (NMC) +191 191 French Polynesia (NMC) +192 192 Tonga (NMC) +193 193 Vanuatu (NMC) +194 194 Brunei Darussalam (NMC) 195 wiix Indonesia (NMC) +196 196 Kiribati (NMC) +197 197 Federated States of Micronesia (NMC) +198 198 New Caledonia (NMC) +199 199 Niue +200 200 Papua New Guinea (NMC) +201 201 Philippines (NMC) +202 202 Samoa (NMC) +203 203 Solomon Islands (NMC) 204 niwa National Institute of Water and Atmospheric Research (NIWA - New Zealand) +# 205-209 Reserved for other centres 210 210 Frascati (ESA/ESRIN) 211 211 Lannion 212 212 Lisboa @@ -139,18 +209,24 @@ 233 eidb Dublin 234 234 Israel (NMC) 235 ingv INGV +236 236 Latvia (NMC) +237 237 Lebanon (NMC) 238 238 Lithuania (NMC) 239 crfc CERFAX 240 240 Malta (NMC) 241 241 Monaco 242 242 Romania (NMC) +243 243 Syrian Arab Republic (NMC) 244 vuwien VUWien 245 knmi KNMI 246 ifmk IfM-Kiel 247 hadc Hadley Centre +248 248 Montenegro (NMC) +249 249 Barcelona Dust Forecast Center 250 cosmo COnsortium for Small scale MOdelling (COSMO) 251 251 Meteorological Cooperation on Operational NWP (MetCoOp) 252 mpim Max Planck Institute for Meteorology (MPI-M) +253 253 Alfred Wegener Institute (AWI) 254 eums EUMETSAT Operation Centre 255 consensus Consensus 256 256 Angola (NMC) @@ -184,9 +260,10 @@ 284 284 Sierra Leone (NMC) 285 285 Somalia (NMC) 286 286 Sudan (NMC) -287 287 Swaziland (NMC) +287 287 Eswatini (NMC) 288 288 Togo (NMC) 289 289 Zambia (NMC) +290 290 EUMETNET E-Profile 291 anso Alliance of International Science Organizations (Beijing, China) 292 ufz Helmholtz Centre for Environmental Research 293 293 University of Bremen @@ -196,4 +273,28 @@ 297 297 The Nanjing Institute of Environmental Sciences (NIES) 298 298 Dynamic Meteorology Laboratory (LMD) 299 299 The Rutherford Appleton Laboratory (RAL) +300 300 Greek Atomic Energy Commission (Greece) +301 301 United Stated Environmental Protection Agency (USA) +302 302 Autralian Radiation Protection and Nuclear Safety (Australia) +303 303 Authority for Nuclear Safety and Radiation Protection (The Netherlands) +304 304 Autorite de Surete Nucleaire (France) +305 305 Bundesamt für Strahlenschutz (Germany) +306 306 National Commission for Nuclear Activities Control (Romania) +307 307 Consejo de Seguridad Nuclear (Spain) +308 308 Danish Emergency Management Agency (Denmark) +309 309 Norwegian Radiation Protection Agency (Norway) +310 310 Federal Agency for Nuclear Control (Belgium) +311 311 Institute of Radiation Protection and Dosimetry (Brazil) +312 312 National Inspectorate for Nuclear Safety and Radiation Protection (Italy) +313 313 Nuclear Regulatory Authority (Turkiye) +314 314 Nuclear Regulation Authority (Japan) +315 315 Nuclear Regulatory Agency (Bulgaria) +316 316 Ukrainian Radiation Protection Institute (Ukriane) +317 317 Health Canada Radio Protection Bureau (Canada) +318 318 Portuguese Society for Radiation Protection (Portugal) +319 319 Swedish Radiation Safety Authority (Sweden) +320 320 Radiation and Nuclear Safety Authority (Finland) +321 321 State Office for Nuclear Safety (Czechia) +322 322 Nuclear Regulation Authority (Slovakia) +# 323-65534 Reserved for other centres 65535 65535 Missing value diff --git a/definitions/grib1/localConcepts/ecmf/units.def b/definitions/grib1/localConcepts/ecmf/units.def index 193a0e3c6..bc63e7cd7 100644 --- a/definitions/grib1/localConcepts/ecmf/units.def +++ b/definitions/grib1/localConcepts/ecmf/units.def @@ -195,12 +195,12 @@ indicatorOfParameter = 28 ; } #Type of low vegetation -'(code table 4.234)' = { +'(Code table 4.234)' = { table2Version = 128 ; indicatorOfParameter = 29 ; } #Type of high vegetation -'(code table 4.234)' = { +'(Code table 4.234)' = { table2Version = 128 ; indicatorOfParameter = 30 ; } @@ -265,7 +265,7 @@ indicatorOfParameter = 42 ; } #Soil type -'~' = { +'(Code table 4.213)' = { table2Version = 128 ; indicatorOfParameter = 43 ; } diff --git a/definitions/grib1/localConcepts/rjtd/units.def b/definitions/grib1/localConcepts/rjtd/units.def index 05a2a7758..8e177dd35 100644 --- a/definitions/grib1/localConcepts/rjtd/units.def +++ b/definitions/grib1/localConcepts/rjtd/units.def @@ -486,7 +486,7 @@ indicatorOfParameter = 253 ; } #Type of vegetation -'Code Table JMA-252' = { +'(Code table JMA-252)' = { table2Version = 200 ; indicatorOfParameter = 252 ; } diff --git a/definitions/grib2/cfVarName.def b/definitions/grib2/cfVarName.def index df89f8260..e3112f355 100644 --- a/definitions/grib2/cfVarName.def +++ b/definitions/grib2/cfVarName.def @@ -4836,28 +4836,28 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean snow density -'mrsn' = { +'avg_rsn' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 61 ; typeOfStatisticalProcessing = 0 ; } #Time-mean low vegetation cover -'mcvl' = { +'avg_cvl' = { discipline = 2 ; parameterCategory = 0 ; parameterNumber = 53 ; typeOfStatisticalProcessing = 0 ; } #Time-mean high vegetation cover -'mcvh' = { +'avg_cvh' = { discipline = 2 ; parameterCategory = 0 ; parameterNumber = 54 ; typeOfStatisticalProcessing = 0 ; } #Time-mean sea ice area fraction -'mci' = { +'avg_ci' = { discipline = 10 ; parameterCategory = 2 ; parameterNumber = 0 ; @@ -4865,7 +4865,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean sea surface temperature -'msst' = { +'avg_sst' = { discipline = 10 ; parameterCategory = 3 ; parameterNumber = 0 ; @@ -4873,21 +4873,21 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean leaf area index, low vegetation -'mlai_lv' = { +'avg_lai_lv' = { discipline = 2 ; parameterCategory = 0 ; parameterNumber = 55 ; typeOfStatisticalProcessing = 0 ; } #Time-mean leaf area index, high vegetation -'mlai_hv' = { +'avg_lai_hv' = { discipline = 2 ; parameterCategory = 0 ; parameterNumber = 56 ; typeOfStatisticalProcessing = 0 ; } #Time-mean total column liquid water -'mtclw' = { +'avg_tclw' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 69 ; @@ -4896,7 +4896,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean total column cloud ice water -'mtciw' = { +'avg_tciw' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 70 ; @@ -4905,7 +4905,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean 2 metre specific humidity -'m2sh' = { +'avg_2sh' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 0 ; @@ -4916,7 +4916,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean lake mix-layer temperature -'mlmlt' = { +'avg_lmlt' = { discipline = 1 ; parameterCategory = 2 ; parameterNumber = 1 ; @@ -4925,7 +4925,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean lake mix-layer depth -'mlmld' = { +'avg_lmld' = { discipline = 1 ; parameterCategory = 2 ; parameterNumber = 0 ; @@ -4934,7 +4934,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean 2 metre relative humidity -'m2r' = { +'avg_2r' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 1 ; @@ -4944,70 +4944,98 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean fraction of snow cover -'mfscov' = { +'avg_fscov' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 121 ; typeOfStatisticalProcessing = 0 ; } #Time-mean soil temperature -'msot' = { +'avg_sot' = { discipline = 2 ; parameterCategory = 3 ; parameterNumber = 18 ; typeOfStatisticalProcessing = 0 ; } -#Time-mean snow depth -'msde' = { +#Time-mean wind speed +'avg_ws' = { discipline = 0 ; - parameterCategory = 1 ; - parameterNumber = 11 ; + parameterCategory = 2 ; + parameterNumber = 1 ; typeOfStatisticalProcessing = 0 ; } -#Time-mean snow cover -'msnowc' = { +#Time-mean pressure +'avg_pres' = { + discipline = 0 ; + parameterCategory = 3 ; + parameterNumber = 0 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean potential vorticity +'avg_pv' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 14 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean specific rain water content +'avg_crwc' = { discipline = 0 ; parameterCategory = 1 ; - parameterNumber = 42 ; + parameterNumber = 85 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean specific snow water content +'avg_cswc' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 86 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean eta-coordinate vertical velocity +'avg_etadot' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 32 ; typeOfStatisticalProcessing = 0 ; } #Time-mean geopotential -'mz' = { +'avg_z' = { discipline = 0 ; parameterCategory = 3 ; parameterNumber = 4 ; typeOfStatisticalProcessing = 0 ; } #Time-mean temperature -'mt' = { +'avg_t' = { discipline = 0 ; parameterCategory = 0 ; parameterNumber = 0 ; typeOfStatisticalProcessing = 0 ; } #Time-mean U component of wind -'mu' = { +'avg_u' = { discipline = 0 ; parameterCategory = 2 ; parameterNumber = 2 ; typeOfStatisticalProcessing = 0 ; } #Time-mean V component of wind -'mv' = { +'avg_v' = { discipline = 0 ; parameterCategory = 2 ; parameterNumber = 3 ; typeOfStatisticalProcessing = 0 ; } #Time-mean specific humidity -'mq' = { +'avg_q' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 0 ; typeOfStatisticalProcessing = 0 ; } #Time-mean surface pressure -'msp' = { +'avg_sp' = { discipline = 0 ; parameterCategory = 3 ; parameterNumber = 0 ; @@ -5015,14 +5043,14 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean vertical velocity -'mw' = { +'avg_w' = { discipline = 0 ; parameterCategory = 2 ; parameterNumber = 8 ; typeOfStatisticalProcessing = 0 ; } #Time-mean total column water -'mtcw' = { +'avg_tcw' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 51 ; @@ -5031,7 +5059,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean total column vertically-integrated water vapour -'mtcwv' = { +'avg_tcwv' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 64 ; @@ -5039,30 +5067,44 @@ typeOfSecondFixedSurface = 8 ; typeOfStatisticalProcessing = 0 ; } +#Time-mean vorticity (relative) +'avg_vo' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 12 ; + typeOfStatisticalProcessing = 0 ; + } #Time-mean mean sea level pressure -'mmsl' = { +'avg_msl' = { discipline = 0 ; parameterCategory = 3 ; parameterNumber = 0 ; typeOfFirstFixedSurface = 101 ; typeOfStatisticalProcessing = 0 ; } +#Time-mean divergence +'avg_d' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 13 ; + typeOfStatisticalProcessing = 0 ; + } #Time-mean relative humidity -'mr' = { +'avg_r' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 1 ; typeOfStatisticalProcessing = 0 ; } #Time-mean boundary layer height -'mblh' = { +'avg_blh' = { discipline = 0 ; parameterCategory = 3 ; parameterNumber = 18 ; typeOfStatisticalProcessing = 0 ; } #Time-mean 10 metre U wind component -'m10u' = { +'avg_10u' = { discipline = 0 ; parameterCategory = 2 ; parameterNumber = 2 ; @@ -5072,7 +5114,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean 10 metre V wind component -'m10v' = { +'avg_10v' = { discipline = 0 ; parameterCategory = 2 ; parameterNumber = 3 ; @@ -5082,7 +5124,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean 2 metre dewpoint temperature -'m2d' = { +'avg_2d' = { discipline = 0 ; parameterCategory = 0 ; parameterNumber = 6 ; @@ -5091,15 +5133,22 @@ scaleFactorOfFirstFixedSurface = 0 ; typeOfStatisticalProcessing = 0 ; } +#Time-mean ozone mass mixing ratio +'avg_o3' = { + discipline = 0 ; + parameterCategory = 14 ; + parameterNumber = 1 ; + typeOfStatisticalProcessing = 0 ; + } #Time-mean temperature of snow layer -'mtsn' = { +'avg_tsn' = { discipline = 2 ; parameterCategory = 3 ; parameterNumber = 28 ; typeOfStatisticalProcessing = 0 ; } #Time-mean forecast surface roughness -'mfsr' = { +'avg_fsr' = { discipline = 2 ; parameterCategory = 0 ; parameterNumber = 1 ; @@ -5107,13 +5156,138 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean forecast logarithm of surface roughness for heat -'mflsr' = { +'avg_flsr' = { discipline = 0 ; parameterCategory = 2 ; parameterNumber = 54 ; typeOfFirstFixedSurface = 1 ; typeOfStatisticalProcessing = 0 ; } +#Time-mean specific cloud liquid water content +'avg_clwc' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 83 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean specific cloud ice water content +'avg_ciwc' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 84 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean fraction of cloud cover +'avg_cc' = { + discipline = 0 ; + parameterCategory = 6 ; + parameterNumber = 32 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean K index +'avg_kx' = { + discipline = 0 ; + parameterCategory = 7 ; + parameterNumber = 2 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean total totals index +'avg_totalx' = { + discipline = 0 ; + parameterCategory = 7 ; + parameterNumber = 4 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean clear air turbulence (CAT) +'avg_cat' = { + discipline = 0 ; + parameterCategory = 19 ; + parameterNumber = 29 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean discharge from rivers or streams +'avg_dis' = { + discipline = 1 ; + parameterCategory = 0 ; + parameterNumber = 7 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean soil wetness index (total layer) +'avg_swit' = { + discipline = 2 ; + parameterCategory = 3 ; + parameterNumber = 30 ; + typeOfFirstFixedSurface = 1 ; + typeOfSecondFixedSurface = 151 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean soil wetness index (root zone) +'avg_swir' = { + discipline = 2 ; + parameterCategory = 3 ; + parameterNumber = 30 ; + typeOfFirstFixedSurface = 1 ; + typeOfSecondFixedSurface = 167 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean soil wetness index(layer) +'avg_swil' = { + discipline = 2 ; + parameterCategory = 3 ; + parameterNumber = 30 ; + typeOfFirstFixedSurface = 151 ; + typeOfSecondFixedSurface = 151 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean floodplain depth +'avg_flddep' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 17 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean floodplain flooded fraction +'avg_fldffr' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 18 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean floodplain flooded area +'avg_fldfar' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 19 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean river fraction +'avg_rivfr' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 20 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean river area +'avg_rivar' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 21 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean fraction of river coverage plus river related flooding +'avg_rivcffr' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 22 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean area of river coverage plus river related flooding +'avg_rivcfar' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 23 ; + typeOfStatisticalProcessing = 0 ; + } #Cross sectional area of flow in channel 'chcross' = { discipline = 1 ; @@ -5174,26 +5348,6 @@ parameterCategory = 0 ; parameterNumber = 15 ; } -#Mean discharge in the last 6 hours -'dis06' = { - discipline = 1 ; - parameterCategory = 0 ; - parameterNumber = 7 ; - typeOfFirstFixedSurface = 1 ; - indicatorOfUnitForTimeRange = 1 ; - typeOfStatisticalProcessing = 0 ; - lengthOfTimeRange = 6 ; - } -#Mean discharge in the last 24 hours -'dis24' = { - discipline = 1 ; - parameterCategory = 0 ; - parameterNumber = 7 ; - typeOfFirstFixedSurface = 1 ; - indicatorOfUnitForTimeRange = 1 ; - typeOfStatisticalProcessing = 0 ; - lengthOfTimeRange = 24 ; - } #Snow depth at elevation bands 'sd_elev' = { discipline = 2 ; @@ -5246,6 +5400,48 @@ parameterCategory = 0 ; parameterNumber = 19 ; } +#Floodplain depth +'flddep' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 17 ; + } +#Floodplain flooded fraction +'fldffr' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 18 ; + } +#Floodplain flooded area +'fldfar' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 19 ; + } +#River fraction +'rivfr' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 20 ; + } +#River area +'rivar' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 21 ; + } +#Fraction of river coverage plus river related flooding +'rivcffr' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 22 ; + } +#Area of river coverage plus river related flooding +'rivcfar' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 23 ; + } #Latitude 'lat' = { discipline = 0 ; @@ -7203,6 +7399,48 @@ typeOfFirstFixedSurface = 1 ; typeOfSecondFixedSurface = 8 ; } +#Standardised Precipitation Index (SPI) +'spi' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 0 ; + } +#Standardised Precipitation Evapotranspiration Index (SPEI) +'spei' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 1 ; + } +#Standardised Streamflow Index (SSFI) +'ssfi' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 2 ; + } +#Standardised Reservoir Supply Index (SRSI) +'srsi' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 3 ; + } +#Standardised Water-level Index (SWI) +'swi' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 4 ; + } +#Standardised Snowmelt and Rain Index (SMRI) +'smri' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 5 ; + } +#Streamflow Drought Index (SDI) +'sdi' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 6 ; + } #Universal thermal climate index 'utci' = { discipline = 20 ; @@ -7340,12 +7578,6 @@ discipline = 10 ; parameterCategory = 2 ; parameterNumber = 1 ; - typeOfFirstFixedSurface = 174 ; - typeOfSecondFixedSurface = 176 ; - scaledValueOfFirstFixedSurface = missing() ; - scaleFactorOfFirstFixedSurface = missing() ; - scaledValueOfSecondFixedSurface = missing() ; - scaleFactorOfSecondFixedSurface = missing() ; } #Sea ice area fraction 'siconc' = { @@ -8450,12 +8682,6 @@ discipline = 10 ; parameterCategory = 2 ; parameterNumber = 1 ; - typeOfFirstFixedSurface = 174 ; - typeOfSecondFixedSurface = 176 ; - scaledValueOfFirstFixedSurface = missing() ; - scaleFactorOfFirstFixedSurface = missing() ; - scaledValueOfSecondFixedSurface = missing() ; - scaleFactorOfSecondFixedSurface = missing() ; typeOfStatisticalProcessing = 0 ; } #Time-mean sea ice area fraction @@ -10047,6 +10273,44 @@ is_chemical_srcsink = 1 ; sourceSinkChemicalPhysicalProcess = 7 ; } +#Aerosol optical depth +'aod' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 102 ; + } +#Single scattering albedo +'ssa' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 103 ; + } +#Asymmetry Factor +'asymf' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 104 ; + } +#Aerosol backscatter from top of atmosphere +'aerbscattoa' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 107 ; + typeOfFirstFixedSurface = 8 ; + } +#Aerosol backscatter from ground +'aerbscatgnd' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 108 ; + typeOfFirstFixedSurface = 1 ; + } +#Aerosol extinction coefficient +'aerext' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 105 ; + } #Pressure tendency 'ptend' = { discipline = 0 ; @@ -10575,6 +10839,12 @@ parameterCategory = 0 ; parameterNumber = 44 ; } +#Wave spectral peakedness +'wsp' = { + discipline = 10 ; + parameterCategory = 0 ; + parameterNumber = 98 ; + } #Skin reservoir content 'srcrea' = { discipline = 2 ; diff --git a/definitions/grib2/localConcepts/cerise/cfVarName.def b/definitions/grib2/localConcepts/cerise/cfVarName.def index 0ccc6c90f..9d88fb46e 100644 --- a/definitions/grib2/localConcepts/cerise/cfVarName.def +++ b/definitions/grib2/localConcepts/cerise/cfVarName.def @@ -153,7 +153,21 @@ typeOfStatisticalProcessing = 1 ; } #Time-mean snow depth -'msd_m' = { +'avg_sde' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 11 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean snow cover +'avg_snowc' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 42 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean snow depth +'avg_sd_m' = { localTablesVersion = 1 ; discipline = 0 ; parameterCategory = 1 ; @@ -161,7 +175,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean low cloud cover -'mlcc_frac' = { +'avg_lcc_frac' = { localTablesVersion = 1 ; discipline = 0 ; parameterCategory = 6 ; @@ -169,7 +183,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean medium cloud cover -'mmcc_frac' = { +'avg_mcc_frac' = { localTablesVersion = 1 ; discipline = 0 ; parameterCategory = 6 ; @@ -177,7 +191,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean high cloud cover -'mhcc_frac' = { +'avg_hcc_frac' = { localTablesVersion = 1 ; discipline = 0 ; parameterCategory = 6 ; @@ -185,7 +199,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean forecast albedo -'mfal_frac' = { +'avg_fal_frac' = { localTablesVersion = 1 ; discipline = 0 ; parameterCategory = 19 ; diff --git a/definitions/grib2/localConcepts/cerise/name.def b/definitions/grib2/localConcepts/cerise/name.def index cac36cdea..3d758e137 100644 --- a/definitions/grib2/localConcepts/cerise/name.def +++ b/definitions/grib2/localConcepts/cerise/name.def @@ -153,6 +153,20 @@ typeOfStatisticalProcessing = 1 ; } #Time-mean snow depth +'Time-mean snow depth' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 11 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean snow cover +'Time-mean snow cover' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 42 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean snow depth 'Time-mean snow depth' = { localTablesVersion = 1 ; discipline = 0 ; diff --git a/definitions/grib2/localConcepts/cerise/paramId.def b/definitions/grib2/localConcepts/cerise/paramId.def index c4af1e971..a3f2a3407 100644 --- a/definitions/grib2/localConcepts/cerise/paramId.def +++ b/definitions/grib2/localConcepts/cerise/paramId.def @@ -153,6 +153,20 @@ typeOfStatisticalProcessing = 1 ; } #Time-mean snow depth +'235095' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 11 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean snow cover +'235096' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 42 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean snow depth '235141' = { localTablesVersion = 1 ; discipline = 0 ; diff --git a/definitions/grib2/localConcepts/cerise/shortName.def b/definitions/grib2/localConcepts/cerise/shortName.def index 0ccc6c90f..9d88fb46e 100644 --- a/definitions/grib2/localConcepts/cerise/shortName.def +++ b/definitions/grib2/localConcepts/cerise/shortName.def @@ -153,7 +153,21 @@ typeOfStatisticalProcessing = 1 ; } #Time-mean snow depth -'msd_m' = { +'avg_sde' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 11 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean snow cover +'avg_snowc' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 42 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean snow depth +'avg_sd_m' = { localTablesVersion = 1 ; discipline = 0 ; parameterCategory = 1 ; @@ -161,7 +175,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean low cloud cover -'mlcc_frac' = { +'avg_lcc_frac' = { localTablesVersion = 1 ; discipline = 0 ; parameterCategory = 6 ; @@ -169,7 +183,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean medium cloud cover -'mmcc_frac' = { +'avg_mcc_frac' = { localTablesVersion = 1 ; discipline = 0 ; parameterCategory = 6 ; @@ -177,7 +191,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean high cloud cover -'mhcc_frac' = { +'avg_hcc_frac' = { localTablesVersion = 1 ; discipline = 0 ; parameterCategory = 6 ; @@ -185,7 +199,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean forecast albedo -'mfal_frac' = { +'avg_fal_frac' = { localTablesVersion = 1 ; discipline = 0 ; parameterCategory = 19 ; diff --git a/definitions/grib2/localConcepts/cerise/units.def b/definitions/grib2/localConcepts/cerise/units.def index afc663307..d5215c398 100644 --- a/definitions/grib2/localConcepts/cerise/units.def +++ b/definitions/grib2/localConcepts/cerise/units.def @@ -153,6 +153,20 @@ typeOfStatisticalProcessing = 1 ; } #Time-mean snow depth +'m' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 11 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean snow cover +'%' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 42 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean snow depth 'm of water equivalent' = { localTablesVersion = 1 ; discipline = 0 ; diff --git a/definitions/grib2/localConcepts/cnmc/modelName.def b/definitions/grib2/localConcepts/cnmc/modelName.def deleted file mode 100644 index e7a85ed1f..000000000 --- a/definitions/grib2/localConcepts/cnmc/modelName.def +++ /dev/null @@ -1,7 +0,0 @@ -# modelName: Contribution from Daniel Lee @ DWD - -# defintions for Roma (COSMO LEPS) -'cosmo-leps' = { - subCentre=98; - grib2LocalSectionNumber=28; -} diff --git a/definitions/grib2/localConcepts/ecmf/cfVarName.def b/definitions/grib2/localConcepts/ecmf/cfVarName.def index a6d9ac00a..328fc93df 100644 --- a/definitions/grib2/localConcepts/ecmf/cfVarName.def +++ b/definitions/grib2/localConcepts/ecmf/cfVarName.def @@ -13798,7 +13798,7 @@ typeOfStatisticalProcessing = 1 ; } #Time-mean snow depth -'msd_m' = { +'avg_sd_m' = { localTablesVersion = 1 ; discipline = 0 ; parameterCategory = 1 ; @@ -13814,7 +13814,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean low cloud cover -'mlcc_frac' = { +'avg_lcc_frac' = { localTablesVersion = 1 ; discipline = 0 ; parameterCategory = 6 ; @@ -13822,7 +13822,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean medium cloud cover -'mmcc_frac' = { +'avg_mcc_frac' = { localTablesVersion = 1 ; discipline = 0 ; parameterCategory = 6 ; @@ -13830,7 +13830,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean high cloud cover -'mhcc_frac' = { +'avg_hcc_frac' = { localTablesVersion = 1 ; discipline = 0 ; parameterCategory = 6 ; @@ -13838,7 +13838,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean forecast albedo -'mfal_frac' = { +'avg_fal_frac' = { localTablesVersion = 1 ; discipline = 0 ; parameterCategory = 19 ; diff --git a/definitions/grib2/localConcepts/ecmf/cfVarName.legacy.def b/definitions/grib2/localConcepts/ecmf/cfVarName.legacy.def index c1c9099b5..cb38cc6e2 100644 --- a/definitions/grib2/localConcepts/ecmf/cfVarName.legacy.def +++ b/definitions/grib2/localConcepts/ecmf/cfVarName.legacy.def @@ -1771,3 +1771,9 @@ parameterCategory = 172 ; parameterNumber = 212 ; } +#Wave spectral peakedness +'wsp' = { + discipline = 192 ; + parameterCategory = 140 ; + parameterNumber = 254 ; +} diff --git a/definitions/grib2/localConcepts/ecmf/name.legacy.def b/definitions/grib2/localConcepts/ecmf/name.legacy.def index 7a451911c..28b2586ef 100644 --- a/definitions/grib2/localConcepts/ecmf/name.legacy.def +++ b/definitions/grib2/localConcepts/ecmf/name.legacy.def @@ -1771,3 +1771,9 @@ parameterCategory = 172 ; parameterNumber = 212 ; } +#Wave spectral peakedness +'Wave spectral peakedness' = { + discipline = 192 ; + parameterCategory = 140 ; + parameterNumber = 254 ; +} diff --git a/definitions/grib2/localConcepts/ecmf/paramId.legacy.def b/definitions/grib2/localConcepts/ecmf/paramId.legacy.def index 4413e87b9..df813254f 100644 --- a/definitions/grib2/localConcepts/ecmf/paramId.legacy.def +++ b/definitions/grib2/localConcepts/ecmf/paramId.legacy.def @@ -1771,3 +1771,9 @@ parameterCategory = 172 ; parameterNumber = 212 ; } +#Wave spectral peakedness +'140254' = { + discipline = 192 ; + parameterCategory = 140 ; + parameterNumber = 254 ; +} diff --git a/definitions/grib2/localConcepts/ecmf/shortName.legacy.def b/definitions/grib2/localConcepts/ecmf/shortName.legacy.def index 1a5608823..498f6a3c1 100644 --- a/definitions/grib2/localConcepts/ecmf/shortName.legacy.def +++ b/definitions/grib2/localConcepts/ecmf/shortName.legacy.def @@ -1771,3 +1771,9 @@ parameterCategory = 172 ; parameterNumber = 212 ; } +#Wave spectral peakedness +'wsp' = { + discipline = 192 ; + parameterCategory = 140 ; + parameterNumber = 254 ; +} diff --git a/definitions/grib2/localConcepts/ecmf/units.legacy.def b/definitions/grib2/localConcepts/ecmf/units.legacy.def index b6a28f51b..d7675c4d6 100644 --- a/definitions/grib2/localConcepts/ecmf/units.legacy.def +++ b/definitions/grib2/localConcepts/ecmf/units.legacy.def @@ -1771,3 +1771,9 @@ parameterCategory = 172 ; parameterNumber = 212 ; } +#Wave spectral peakedness +'dimensionless' = { + discipline = 192 ; + parameterCategory = 140 ; + parameterNumber = 254 ; +} diff --git a/definitions/grib2/localConcepts/edzw/modelName.def b/definitions/grib2/localConcepts/edzw/modelName.def deleted file mode 100644 index 5af6fb6e6..000000000 --- a/definitions/grib2/localConcepts/edzw/modelName.def +++ /dev/null @@ -1,107 +0,0 @@ -# modelName: Contribution from Daniel Lee @ DWD - -# definitions for Offenbach -'cosmo_eu' = { - generatingProcessIdentifier=131; -} -'cosmo_eu' = { - generatingProcessIdentifier=132; -} -'cosmo_eu' = { - generatingProcessIdentifier=134; -} -'cosmo_eu' = { - generatingProcessIdentifier=135; -} -'cosmo_de' = { - generatingProcessIdentifier=137; -} -'cosmo_de' = { - generatingProcessIdentifier=138; -} -'cosmo_de-eps' = { - generatingProcessIdentifier=137; - typeOfEnsembleForecast=192; -} -'cosmo_de-eps' = { - generatingProcessIdentifier=138; - typeOfEnsembleForecast=192; -} - -#DWD model names for ICON -'icogl' = { - gridDefinitionTemplateNumber=101; - generatingProcessIdentifier=1; -} -'icogl130' = { - numberOfGridUsed=26; - generatingProcessIdentifier=1; -} -'icogl130l90' = { - numberOfGridUsed=26; - nlev=91; - generatingProcessIdentifier=1; -} -'icogl130p' = { - numberOfGridUsed=26; - typeOfFirstFixedSurface=100; - generatingProcessIdentifier=1; -} -'icoeu'= { - gridDefinitionTemplateNumber=101; - generatingProcessIdentifier=2; -} -'icoeu065' = { - numberOfGridUsed=27; - generatingProcessIdentifier=2; -} -'icoeu065l60' = { - numberOfGridUsed=27; - nlev=61; - generatingProcessIdentifier=2; -} -'icreu' = { - gridDefinitionTemplateNumber=0; - generatingProcessIdentifier=2; -} -'icreu_0.625' = { - gridDefinitionTemplateNumber=0; - Dx=62500; - Dy=62500; - generatingProcessIdentifier=2; -} -'icreu_0.625l60' = { - gridDefinitionTemplateNumber=0; - Dx=62500; - Dy=62500; - nlev=61; - generatingProcessIdentifier=2; -} -'icreu_0.625p' = { - gridDefinitionTemplateNumber=0; - Dx=62500; - Dy=62500; - typeOfFirstFixedSurface=100; - generatingProcessIdentifier=2; -} -'icreu_0.625z' = { - gridDefinitionTemplateNumber=0; - Dx=62500; - Dy=62500; - typeOfFirstFixedSurface=102; - generatingProcessIdentifier=2; -} -'icrde' = { - gridDefinitionTemplateNumber=0; - generatingProcessIdentifier=3; -} -'icrgl' = { - gridDefinitionTemplateNumber=0; - generatingProcessIdentifier=1; -} -'icrgl_0.25' = { - gridDefinitionTemplateNumber=0; - Dx=250000; - Dy=250000; - generatingProcessIdentifier=1; -} diff --git a/definitions/grib2/localConcepts/era/cfName.def b/definitions/grib2/localConcepts/era/cfName.def index f4a8abea5..8292efdd2 100644 --- a/definitions/grib2/localConcepts/era/cfName.def +++ b/definitions/grib2/localConcepts/era/cfName.def @@ -27,6 +27,27 @@ parameterNumber = 8 ; typeOfStatisticalProcessing = 0 ; } +#Vorticity (relative) +'atmosphere_relative_vorticity' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 12 ; + typeOfStatisticalProcessing = 0 ; + } +#Divergence +'divergence_of_wind' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 13 ; + typeOfStatisticalProcessing = 0 ; + } +#Ozone mass mixing ratio +'mass_fraction_of_ozone_in_air' = { + discipline = 0 ; + parameterCategory = 14 ; + parameterNumber = 1 ; + typeOfStatisticalProcessing = 0 ; + } #Snow depth 'lwe_thickness_of_surface_snow_amount' = { discipline = 0 ; diff --git a/definitions/grib2/localConcepts/era/name.def b/definitions/grib2/localConcepts/era/name.def index 78a476de6..82944f3b2 100644 --- a/definitions/grib2/localConcepts/era/name.def +++ b/definitions/grib2/localConcepts/era/name.def @@ -1,4 +1,25 @@ # Automatically generated by ./create_def.pl, do not edit +#Specific rain water content +'Specific rain water content' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 85 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific snow water content +'Specific snow water content' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 86 ; + typeOfStatisticalProcessing = 0 ; + } +#Eta-coordinate vertical velocity +'Eta-coordinate vertical velocity' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 32 ; + typeOfStatisticalProcessing = 0 ; + } #Geopotential 'Geopotential' = { discipline = 0 ; @@ -27,6 +48,13 @@ parameterNumber = 8 ; typeOfStatisticalProcessing = 0 ; } +#Vorticity (relative) +'Vorticity (relative)' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 12 ; + typeOfStatisticalProcessing = 0 ; + } #Logarithm of surface pressure 'Logarithm of surface pressure' = { discipline = 0 ; @@ -34,6 +62,49 @@ parameterNumber = 25 ; typeOfFirstFixedSurface = 105 ; } +#Logarithm of surface pressure +'Logarithm of surface pressure' = { + discipline = 0 ; + parameterCategory = 3 ; + parameterNumber = 25 ; + typeOfFirstFixedSurface = 105 ; + typeOfStatisticalProcessing = 0 ; + } +#Divergence +'Divergence' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 13 ; + typeOfStatisticalProcessing = 0 ; + } +#Ozone mass mixing ratio +'Ozone mass mixing ratio' = { + discipline = 0 ; + parameterCategory = 14 ; + parameterNumber = 1 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific cloud liquid water content +'Specific cloud liquid water content' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 83 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific cloud ice water content +'Specific cloud ice water content' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 84 ; + typeOfStatisticalProcessing = 0 ; + } +#Fraction of cloud cover +'Fraction of cloud cover' = { + discipline = 0 ; + parameterCategory = 6 ; + parameterNumber = 32 ; + typeOfStatisticalProcessing = 0 ; + } #Temperature difference 'Temperature difference' = { discipline = 192 ; @@ -479,6 +550,13 @@ parameterCategory = 228 ; parameterNumber = 103 ; } +#Precipitation type +'Precipitation type' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 19 ; + typeOfStatisticalProcessing = 0 ; + } #Snow cover 'Snow cover' = { discipline = 0 ; @@ -486,6 +564,20 @@ parameterNumber = 42 ; typeOfStatisticalProcessing = 0 ; } +#K index +'K index' = { + discipline = 0 ; + parameterCategory = 7 ; + parameterNumber = 2 ; + typeOfStatisticalProcessing = 0 ; + } +#Total totals index +'Total totals index' = { + discipline = 0 ; + parameterCategory = 7 ; + parameterNumber = 4 ; + typeOfStatisticalProcessing = 0 ; + } #Sea water potential temperature 'Sea water potential temperature' = { discipline = 192 ; diff --git a/definitions/grib2/localConcepts/era/paramId.def b/definitions/grib2/localConcepts/era/paramId.def index 31219cfa9..b4c978e14 100644 --- a/definitions/grib2/localConcepts/era/paramId.def +++ b/definitions/grib2/localConcepts/era/paramId.def @@ -1,4 +1,25 @@ # Automatically generated by ./create_def.pl, do not edit +#Specific rain water content +'75' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 85 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific snow water content +'76' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 86 ; + typeOfStatisticalProcessing = 0 ; + } +#Eta-coordinate vertical velocity +'77' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 32 ; + typeOfStatisticalProcessing = 0 ; + } #Geopotential '129' = { discipline = 0 ; @@ -27,6 +48,13 @@ parameterNumber = 8 ; typeOfStatisticalProcessing = 0 ; } +#Vorticity (relative) +'138' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 12 ; + typeOfStatisticalProcessing = 0 ; + } #Logarithm of surface pressure '152' = { discipline = 0 ; @@ -34,6 +62,49 @@ parameterNumber = 25 ; typeOfFirstFixedSurface = 105 ; } +#Logarithm of surface pressure +'152' = { + discipline = 0 ; + parameterCategory = 3 ; + parameterNumber = 25 ; + typeOfFirstFixedSurface = 105 ; + typeOfStatisticalProcessing = 0 ; + } +#Divergence +'155' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 13 ; + typeOfStatisticalProcessing = 0 ; + } +#Ozone mass mixing ratio +'203' = { + discipline = 0 ; + parameterCategory = 14 ; + parameterNumber = 1 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific cloud liquid water content +'246' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 83 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific cloud ice water content +'247' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 84 ; + typeOfStatisticalProcessing = 0 ; + } +#Fraction of cloud cover +'248' = { + discipline = 0 ; + parameterCategory = 6 ; + parameterNumber = 32 ; + typeOfStatisticalProcessing = 0 ; + } #Temperature difference '200130' = { discipline = 192 ; @@ -479,6 +550,13 @@ parameterCategory = 228 ; parameterNumber = 103 ; } +#Precipitation type +'260015' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 19 ; + typeOfStatisticalProcessing = 0 ; + } #Snow cover '260038' = { discipline = 0 ; @@ -486,6 +564,20 @@ parameterNumber = 42 ; typeOfStatisticalProcessing = 0 ; } +#K index +'260121' = { + discipline = 0 ; + parameterCategory = 7 ; + parameterNumber = 2 ; + typeOfStatisticalProcessing = 0 ; + } +#Total totals index +'260123' = { + discipline = 0 ; + parameterCategory = 7 ; + parameterNumber = 4 ; + typeOfStatisticalProcessing = 0 ; + } #Sea water potential temperature '151129' = { discipline = 192 ; diff --git a/definitions/grib2/localConcepts/era/shortName.def b/definitions/grib2/localConcepts/era/shortName.def index beb0f3d79..088ae3b62 100644 --- a/definitions/grib2/localConcepts/era/shortName.def +++ b/definitions/grib2/localConcepts/era/shortName.def @@ -1,4 +1,25 @@ # Automatically generated by ./create_def.pl, do not edit +#Specific rain water content +'crwc' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 85 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific snow water content +'cswc' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 86 ; + typeOfStatisticalProcessing = 0 ; + } +#Eta-coordinate vertical velocity +'etadot' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 32 ; + typeOfStatisticalProcessing = 0 ; + } #Geopotential 'z' = { discipline = 0 ; @@ -27,6 +48,13 @@ parameterNumber = 8 ; typeOfStatisticalProcessing = 0 ; } +#Vorticity (relative) +'vo' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 12 ; + typeOfStatisticalProcessing = 0 ; + } #Logarithm of surface pressure 'lnsp' = { discipline = 0 ; @@ -34,6 +62,49 @@ parameterNumber = 25 ; typeOfFirstFixedSurface = 105 ; } +#Logarithm of surface pressure +'lnsp' = { + discipline = 0 ; + parameterCategory = 3 ; + parameterNumber = 25 ; + typeOfFirstFixedSurface = 105 ; + typeOfStatisticalProcessing = 0 ; + } +#Divergence +'d' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 13 ; + typeOfStatisticalProcessing = 0 ; + } +#Ozone mass mixing ratio +'o3' = { + discipline = 0 ; + parameterCategory = 14 ; + parameterNumber = 1 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific cloud liquid water content +'clwc' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 83 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific cloud ice water content +'ciwc' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 84 ; + typeOfStatisticalProcessing = 0 ; + } +#Fraction of cloud cover +'cc' = { + discipline = 0 ; + parameterCategory = 6 ; + parameterNumber = 32 ; + typeOfStatisticalProcessing = 0 ; + } #Temperature difference 'tdiff' = { discipline = 192 ; @@ -479,6 +550,13 @@ parameterCategory = 228 ; parameterNumber = 103 ; } +#Precipitation type +'ptype' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 19 ; + typeOfStatisticalProcessing = 0 ; + } #Snow cover 'snowc' = { discipline = 0 ; @@ -486,6 +564,20 @@ parameterNumber = 42 ; typeOfStatisticalProcessing = 0 ; } +#K index +'kx' = { + discipline = 0 ; + parameterCategory = 7 ; + parameterNumber = 2 ; + typeOfStatisticalProcessing = 0 ; + } +#Total totals index +'totalx' = { + discipline = 0 ; + parameterCategory = 7 ; + parameterNumber = 4 ; + typeOfStatisticalProcessing = 0 ; + } #Sea water potential temperature 'thetao' = { discipline = 192 ; diff --git a/definitions/grib2/localConcepts/era/units.def b/definitions/grib2/localConcepts/era/units.def index 95c5b4af8..28ac983af 100644 --- a/definitions/grib2/localConcepts/era/units.def +++ b/definitions/grib2/localConcepts/era/units.def @@ -1,4 +1,25 @@ # Automatically generated by ./create_def.pl, do not edit +#Specific rain water content +'kg kg**-1' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 85 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific snow water content +'kg kg**-1' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 86 ; + typeOfStatisticalProcessing = 0 ; + } +#Eta-coordinate vertical velocity +'s**-1' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 32 ; + typeOfStatisticalProcessing = 0 ; + } #Geopotential 'm**2 s**-2' = { discipline = 0 ; @@ -27,6 +48,13 @@ parameterNumber = 8 ; typeOfStatisticalProcessing = 0 ; } +#Vorticity (relative) +'s**-1' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 12 ; + typeOfStatisticalProcessing = 0 ; + } #Logarithm of surface pressure 'Numeric' = { discipline = 0 ; @@ -34,6 +62,49 @@ parameterNumber = 25 ; typeOfFirstFixedSurface = 105 ; } +#Logarithm of surface pressure +'Numeric' = { + discipline = 0 ; + parameterCategory = 3 ; + parameterNumber = 25 ; + typeOfFirstFixedSurface = 105 ; + typeOfStatisticalProcessing = 0 ; + } +#Divergence +'s**-1' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 13 ; + typeOfStatisticalProcessing = 0 ; + } +#Ozone mass mixing ratio +'kg kg**-1' = { + discipline = 0 ; + parameterCategory = 14 ; + parameterNumber = 1 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific cloud liquid water content +'kg kg**-1' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 83 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific cloud ice water content +'kg kg**-1' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 84 ; + typeOfStatisticalProcessing = 0 ; + } +#Fraction of cloud cover +'(0 - 1)' = { + discipline = 0 ; + parameterCategory = 6 ; + parameterNumber = 32 ; + typeOfStatisticalProcessing = 0 ; + } #Temperature difference 'K' = { discipline = 192 ; @@ -479,6 +550,13 @@ parameterCategory = 228 ; parameterNumber = 103 ; } +#Precipitation type +'(Code table 4.201)' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 19 ; + typeOfStatisticalProcessing = 0 ; + } #Snow cover '%' = { discipline = 0 ; @@ -486,6 +564,20 @@ parameterNumber = 42 ; typeOfStatisticalProcessing = 0 ; } +#K index +'K' = { + discipline = 0 ; + parameterCategory = 7 ; + parameterNumber = 2 ; + typeOfStatisticalProcessing = 0 ; + } +#Total totals index +'K' = { + discipline = 0 ; + parameterCategory = 7 ; + parameterNumber = 4 ; + typeOfStatisticalProcessing = 0 ; + } #Sea water potential temperature 'deg C' = { discipline = 192 ; diff --git a/definitions/grib2/localConcepts/era6/cfName.def b/definitions/grib2/localConcepts/era6/cfName.def index 04675741a..e86ee85d4 100644 --- a/definitions/grib2/localConcepts/era6/cfName.def +++ b/definitions/grib2/localConcepts/era6/cfName.def @@ -1,4 +1,40 @@ # Automatically generated by ./create_def.pl, do not edit +#U component of wind +'eastward_wind' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 2 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 100 ; + scaleFactorOfFirstFixedSurface = 0 ; + } +#U component of wind +'eastward_wind' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 2 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 200 ; + scaleFactorOfFirstFixedSurface = 0 ; + } +#V component of wind +'northward_wind' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 3 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 100 ; + scaleFactorOfFirstFixedSurface = 0 ; + } +#V component of wind +'northward_wind' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 3 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 200 ; + scaleFactorOfFirstFixedSurface = 0 ; + } #Snow depth 'lwe_thickness_of_surface_snow_amount' = { localTablesVersion = 1 ; diff --git a/definitions/grib2/localConcepts/era6/name.def b/definitions/grib2/localConcepts/era6/name.def index b5c4fefb8..af79f7845 100644 --- a/definitions/grib2/localConcepts/era6/name.def +++ b/definitions/grib2/localConcepts/era6/name.def @@ -17,6 +17,24 @@ typeOfFirstFixedSurface = 1 ; typeOfStatisticalProcessing = 1 ; } +#Wind speed +'Wind speed' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 1 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 100 ; + scaleFactorOfFirstFixedSurface = 0 ; + } +#Wind speed +'Wind speed' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 1 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 200 ; + scaleFactorOfFirstFixedSurface = 0 ; + } #UV visible albedo for direct radiation (climatological) 'UV visible albedo for direct radiation (climatological)' = { localTablesVersion = 1 ; @@ -74,6 +92,42 @@ typeOfFirstFixedSurface = 1 ; typeOfStatisticalProcessing = 1 ; } +#U component of wind +'U component of wind' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 2 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 100 ; + scaleFactorOfFirstFixedSurface = 0 ; + } +#U component of wind +'U component of wind' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 2 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 200 ; + scaleFactorOfFirstFixedSurface = 0 ; + } +#V component of wind +'V component of wind' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 3 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 100 ; + scaleFactorOfFirstFixedSurface = 0 ; + } +#V component of wind +'V component of wind' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 3 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 200 ; + scaleFactorOfFirstFixedSurface = 0 ; + } #Snow depth 'Snow depth' = { localTablesVersion = 1 ; @@ -408,4 +462,12 @@ constituentType = 3 ; typeOfStatisticalProcessing = 0 ; is_chemical = 1 ; + } +#Time-mean logarithm of surface pressure +'Time-mean logarithm of surface pressure' = { + discipline = 0 ; + parameterCategory = 3 ; + parameterNumber = 25 ; + typeOfFirstFixedSurface = 105 ; + typeOfStatisticalProcessing = 0 ; } diff --git a/definitions/grib2/localConcepts/era6/paramId.def b/definitions/grib2/localConcepts/era6/paramId.def index 85dc31997..efa120d15 100644 --- a/definitions/grib2/localConcepts/era6/paramId.def +++ b/definitions/grib2/localConcepts/era6/paramId.def @@ -17,6 +17,24 @@ typeOfFirstFixedSurface = 1 ; typeOfStatisticalProcessing = 1 ; } +#Wind speed +'10' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 1 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 100 ; + scaleFactorOfFirstFixedSurface = 0 ; + } +#Wind speed +'10' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 1 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 200 ; + scaleFactorOfFirstFixedSurface = 0 ; + } #UV visible albedo for direct radiation (climatological) '15' = { localTablesVersion = 1 ; @@ -74,6 +92,42 @@ typeOfFirstFixedSurface = 1 ; typeOfStatisticalProcessing = 1 ; } +#U component of wind +'131' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 2 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 100 ; + scaleFactorOfFirstFixedSurface = 0 ; + } +#U component of wind +'131' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 2 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 200 ; + scaleFactorOfFirstFixedSurface = 0 ; + } +#V component of wind +'132' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 3 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 100 ; + scaleFactorOfFirstFixedSurface = 0 ; + } +#V component of wind +'132' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 3 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 200 ; + scaleFactorOfFirstFixedSurface = 0 ; + } #Snow depth '141' = { localTablesVersion = 1 ; @@ -408,4 +462,12 @@ constituentType = 3 ; typeOfStatisticalProcessing = 0 ; is_chemical = 1 ; + } +#Time-mean logarithm of surface pressure +'235152' = { + discipline = 0 ; + parameterCategory = 3 ; + parameterNumber = 25 ; + typeOfFirstFixedSurface = 105 ; + typeOfStatisticalProcessing = 0 ; } diff --git a/definitions/grib2/localConcepts/era6/shortName.def b/definitions/grib2/localConcepts/era6/shortName.def index 0b9c836b9..118656c0f 100644 --- a/definitions/grib2/localConcepts/era6/shortName.def +++ b/definitions/grib2/localConcepts/era6/shortName.def @@ -17,6 +17,24 @@ typeOfFirstFixedSurface = 1 ; typeOfStatisticalProcessing = 1 ; } +#Wind speed +'ws' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 1 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 100 ; + scaleFactorOfFirstFixedSurface = 0 ; + } +#Wind speed +'ws' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 1 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 200 ; + scaleFactorOfFirstFixedSurface = 0 ; + } #UV visible albedo for direct radiation (climatological) 'aluvp' = { localTablesVersion = 1 ; @@ -74,6 +92,42 @@ typeOfFirstFixedSurface = 1 ; typeOfStatisticalProcessing = 1 ; } +#U component of wind +'u' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 2 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 100 ; + scaleFactorOfFirstFixedSurface = 0 ; + } +#U component of wind +'u' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 2 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 200 ; + scaleFactorOfFirstFixedSurface = 0 ; + } +#V component of wind +'v' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 3 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 100 ; + scaleFactorOfFirstFixedSurface = 0 ; + } +#V component of wind +'v' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 3 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 200 ; + scaleFactorOfFirstFixedSurface = 0 ; + } #Snow depth 'sd' = { localTablesVersion = 1 ; @@ -408,4 +462,12 @@ constituentType = 3 ; typeOfStatisticalProcessing = 0 ; is_chemical = 1 ; + } +#Time-mean logarithm of surface pressure +'avg_lnsp' = { + discipline = 0 ; + parameterCategory = 3 ; + parameterNumber = 25 ; + typeOfFirstFixedSurface = 105 ; + typeOfStatisticalProcessing = 0 ; } diff --git a/definitions/grib2/localConcepts/era6/units.def b/definitions/grib2/localConcepts/era6/units.def index 699b0c19a..edd86225f 100644 --- a/definitions/grib2/localConcepts/era6/units.def +++ b/definitions/grib2/localConcepts/era6/units.def @@ -17,6 +17,24 @@ typeOfFirstFixedSurface = 1 ; typeOfStatisticalProcessing = 1 ; } +#Wind speed +'m s**-1' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 1 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 100 ; + scaleFactorOfFirstFixedSurface = 0 ; + } +#Wind speed +'m s**-1' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 1 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 200 ; + scaleFactorOfFirstFixedSurface = 0 ; + } #UV visible albedo for direct radiation (climatological) '(0 - 1)' = { localTablesVersion = 1 ; @@ -74,6 +92,42 @@ typeOfFirstFixedSurface = 1 ; typeOfStatisticalProcessing = 1 ; } +#U component of wind +'m s**-1' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 2 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 100 ; + scaleFactorOfFirstFixedSurface = 0 ; + } +#U component of wind +'m s**-1' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 2 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 200 ; + scaleFactorOfFirstFixedSurface = 0 ; + } +#V component of wind +'m s**-1' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 3 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 100 ; + scaleFactorOfFirstFixedSurface = 0 ; + } +#V component of wind +'m s**-1' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 3 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 200 ; + scaleFactorOfFirstFixedSurface = 0 ; + } #Snow depth 'm of water equivalent' = { localTablesVersion = 1 ; @@ -408,4 +462,12 @@ constituentType = 3 ; typeOfStatisticalProcessing = 0 ; is_chemical = 1 ; + } +#Time-mean logarithm of surface pressure +'Numeric' = { + discipline = 0 ; + parameterCategory = 3 ; + parameterNumber = 25 ; + typeOfFirstFixedSurface = 105 ; + typeOfStatisticalProcessing = 0 ; } diff --git a/definitions/grib2/localConcepts/hydro/cfVarName.def b/definitions/grib2/localConcepts/hydro/cfVarName.def index 19b565498..a0f1b1f69 100644 --- a/definitions/grib2/localConcepts/hydro/cfVarName.def +++ b/definitions/grib2/localConcepts/hydro/cfVarName.def @@ -1,4 +1,24 @@ # Automatically generated by ./create_def.pl, do not edit +#Mean discharge in the last 6 hours +'dis06' = { + discipline = 1 ; + parameterCategory = 0 ; + parameterNumber = 7 ; + typeOfFirstFixedSurface = 1 ; + indicatorOfUnitForTimeRange = 1 ; + typeOfStatisticalProcessing = 0 ; + lengthOfTimeRange = 6 ; + } +#Mean discharge in the last 24 hours +'dis24' = { + discipline = 1 ; + parameterCategory = 0 ; + parameterNumber = 7 ; + typeOfFirstFixedSurface = 1 ; + indicatorOfUnitForTimeRange = 1 ; + typeOfStatisticalProcessing = 0 ; + lengthOfTimeRange = 24 ; + } #Total precipitation in the last 6 hours 'tp06' = { discipline = 0 ; diff --git a/definitions/grib2/localConcepts/hydro/name.def b/definitions/grib2/localConcepts/hydro/name.def index 5390805f1..8becdbb9b 100644 --- a/definitions/grib2/localConcepts/hydro/name.def +++ b/definitions/grib2/localConcepts/hydro/name.def @@ -1,4 +1,24 @@ # Automatically generated by ./create_def.pl, do not edit +#Mean discharge in the last 6 hours +'Mean discharge in the last 6 hours' = { + discipline = 1 ; + parameterCategory = 0 ; + parameterNumber = 7 ; + typeOfFirstFixedSurface = 1 ; + indicatorOfUnitForTimeRange = 1 ; + typeOfStatisticalProcessing = 0 ; + lengthOfTimeRange = 6 ; + } +#Mean discharge in the last 24 hours +'Mean discharge in the last 24 hours' = { + discipline = 1 ; + parameterCategory = 0 ; + parameterNumber = 7 ; + typeOfFirstFixedSurface = 1 ; + indicatorOfUnitForTimeRange = 1 ; + typeOfStatisticalProcessing = 0 ; + lengthOfTimeRange = 24 ; + } #Total precipitation in the last 6 hours 'Total precipitation in the last 6 hours' = { discipline = 0 ; diff --git a/definitions/grib2/localConcepts/hydro/paramId.def b/definitions/grib2/localConcepts/hydro/paramId.def index dfd704793..6f29e63ed 100644 --- a/definitions/grib2/localConcepts/hydro/paramId.def +++ b/definitions/grib2/localConcepts/hydro/paramId.def @@ -1,4 +1,24 @@ # Automatically generated by ./create_def.pl, do not edit +#Mean discharge in the last 6 hours +'240023' = { + discipline = 1 ; + parameterCategory = 0 ; + parameterNumber = 7 ; + typeOfFirstFixedSurface = 1 ; + indicatorOfUnitForTimeRange = 1 ; + typeOfStatisticalProcessing = 0 ; + lengthOfTimeRange = 6 ; + } +#Mean discharge in the last 24 hours +'240024' = { + discipline = 1 ; + parameterCategory = 0 ; + parameterNumber = 7 ; + typeOfFirstFixedSurface = 1 ; + indicatorOfUnitForTimeRange = 1 ; + typeOfStatisticalProcessing = 0 ; + lengthOfTimeRange = 24 ; + } #Total precipitation in the last 6 hours '260267' = { discipline = 0 ; diff --git a/definitions/grib2/localConcepts/hydro/shortName.def b/definitions/grib2/localConcepts/hydro/shortName.def index 19b565498..a0f1b1f69 100644 --- a/definitions/grib2/localConcepts/hydro/shortName.def +++ b/definitions/grib2/localConcepts/hydro/shortName.def @@ -1,4 +1,24 @@ # Automatically generated by ./create_def.pl, do not edit +#Mean discharge in the last 6 hours +'dis06' = { + discipline = 1 ; + parameterCategory = 0 ; + parameterNumber = 7 ; + typeOfFirstFixedSurface = 1 ; + indicatorOfUnitForTimeRange = 1 ; + typeOfStatisticalProcessing = 0 ; + lengthOfTimeRange = 6 ; + } +#Mean discharge in the last 24 hours +'dis24' = { + discipline = 1 ; + parameterCategory = 0 ; + parameterNumber = 7 ; + typeOfFirstFixedSurface = 1 ; + indicatorOfUnitForTimeRange = 1 ; + typeOfStatisticalProcessing = 0 ; + lengthOfTimeRange = 24 ; + } #Total precipitation in the last 6 hours 'tp06' = { discipline = 0 ; diff --git a/definitions/grib2/localConcepts/hydro/units.def b/definitions/grib2/localConcepts/hydro/units.def index 60d462f2d..11078673a 100644 --- a/definitions/grib2/localConcepts/hydro/units.def +++ b/definitions/grib2/localConcepts/hydro/units.def @@ -1,4 +1,24 @@ # Automatically generated by ./create_def.pl, do not edit +#Mean discharge in the last 6 hours +'m**3 s**-1' = { + discipline = 1 ; + parameterCategory = 0 ; + parameterNumber = 7 ; + typeOfFirstFixedSurface = 1 ; + indicatorOfUnitForTimeRange = 1 ; + typeOfStatisticalProcessing = 0 ; + lengthOfTimeRange = 6 ; + } +#Mean discharge in the last 24 hours +'m**3 s**-1' = { + discipline = 1 ; + parameterCategory = 0 ; + parameterNumber = 7 ; + typeOfFirstFixedSurface = 1 ; + indicatorOfUnitForTimeRange = 1 ; + typeOfStatisticalProcessing = 0 ; + lengthOfTimeRange = 24 ; + } #Total precipitation in the last 6 hours 'kg m**-2' = { discipline = 0 ; diff --git a/definitions/grib2/localConcepts/lssw/modelName.def b/definitions/grib2/localConcepts/lssw/modelName.def deleted file mode 100644 index 6413c0d1c..000000000 --- a/definitions/grib2/localConcepts/lssw/modelName.def +++ /dev/null @@ -1,17 +0,0 @@ -# modelName: Contribution from Daniel Lee @ DWD -# definitions for Zurich -'cosmo-1' = { - generatingProcessIdentifier=101; -} -'cosmo-2' = { - generatingProcessIdentifier=102; -} -'cosmo-7' = { - generatingProcessIdentifier=107; -} -'cosmo-e' = { - generatingProcessIdentifier=103; -} -'cosmo-e' = { - generatingProcessIdentifier=130; -} diff --git a/definitions/grib2/localConcepts/uerra/cfVarName.def b/definitions/grib2/localConcepts/uerra/cfVarName.def index 2242d96a0..f7f2d915c 100644 --- a/definitions/grib2/localConcepts/uerra/cfVarName.def +++ b/definitions/grib2/localConcepts/uerra/cfVarName.def @@ -17,6 +17,33 @@ scaledValueOfFirstFixedSurface = 200 ; scaleFactorOfFirstFixedSurface = 0 ; } +#Wind speed +'ws' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 1 ; + typeOfStatisticalProcessing = 0 ; + } +#Wind speed +'ws' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 1 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 100 ; + scaleFactorOfFirstFixedSurface = 0 ; + typeOfStatisticalProcessing = 0 ; + } +#Wind speed +'ws' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 1 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 200 ; + scaleFactorOfFirstFixedSurface = 0 ; + typeOfStatisticalProcessing = 0 ; + } #Sea ice area fraction 'ci' = { discipline = 10 ; @@ -75,6 +102,34 @@ indicatorOfUnitForTimeRange = 1 ; typeOfStatisticalProcessing = 2 ; } +#Pressure +'pres' = { + discipline = 0 ; + parameterCategory = 3 ; + parameterNumber = 0 ; + typeOfStatisticalProcessing = 0 ; + } +#Potential vorticity +'pv' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 14 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific rain water content +'crwc' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 85 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific snow water content +'cswc' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 86 ; + typeOfStatisticalProcessing = 0 ; + } #Total column cloud liquid water 'tclw' = { discipline = 0 ; @@ -287,6 +342,20 @@ typeOfFirstFixedSurface = 1 ; typeOfStatisticalProcessing = 0 ; } +#Specific cloud liquid water content +'clwc' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 83 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific cloud ice water content +'ciwc' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 84 ; + typeOfStatisticalProcessing = 0 ; + } #2 metre specific humidity 'sh2' = { discipline = 0 ; @@ -298,6 +367,13 @@ scaleFactorOfFirstFixedSurface = 0 ; typeOfStatisticalProcessing = 0 ; } +#Precipitation type +'ptype' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 19 ; + typeOfStatisticalProcessing = 0 ; + } #Total column integrated water vapour 'tciwv' = { discipline = 0 ; diff --git a/definitions/grib2/localConcepts/uerra/name.def b/definitions/grib2/localConcepts/uerra/name.def index 59a55bdf5..da1a828b1 100644 --- a/definitions/grib2/localConcepts/uerra/name.def +++ b/definitions/grib2/localConcepts/uerra/name.def @@ -17,6 +17,33 @@ scaledValueOfFirstFixedSurface = 200 ; scaleFactorOfFirstFixedSurface = 0 ; } +#Wind speed +'Wind speed' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 1 ; + typeOfStatisticalProcessing = 0 ; + } +#Wind speed +'Wind speed' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 1 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 100 ; + scaleFactorOfFirstFixedSurface = 0 ; + typeOfStatisticalProcessing = 0 ; + } +#Wind speed +'Wind speed' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 1 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 200 ; + scaleFactorOfFirstFixedSurface = 0 ; + typeOfStatisticalProcessing = 0 ; + } #Sea ice area fraction 'Sea ice area fraction' = { discipline = 10 ; @@ -75,6 +102,34 @@ indicatorOfUnitForTimeRange = 1 ; typeOfStatisticalProcessing = 2 ; } +#Pressure +'Pressure' = { + discipline = 0 ; + parameterCategory = 3 ; + parameterNumber = 0 ; + typeOfStatisticalProcessing = 0 ; + } +#Potential vorticity +'Potential vorticity' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 14 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific rain water content +'Specific rain water content' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 85 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific snow water content +'Specific snow water content' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 86 ; + typeOfStatisticalProcessing = 0 ; + } #Total column cloud liquid water 'Total column cloud liquid water' = { discipline = 0 ; @@ -287,6 +342,20 @@ typeOfFirstFixedSurface = 1 ; typeOfStatisticalProcessing = 0 ; } +#Specific cloud liquid water content +'Specific cloud liquid water content' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 83 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific cloud ice water content +'Specific cloud ice water content' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 84 ; + typeOfStatisticalProcessing = 0 ; + } #2 metre specific humidity '2 metre specific humidity' = { discipline = 0 ; @@ -298,6 +367,13 @@ scaleFactorOfFirstFixedSurface = 0 ; typeOfStatisticalProcessing = 0 ; } +#Precipitation type +'Precipitation type' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 19 ; + typeOfStatisticalProcessing = 0 ; + } #Total column integrated water vapour 'Total column integrated water vapour' = { discipline = 0 ; diff --git a/definitions/grib2/localConcepts/uerra/paramId.def b/definitions/grib2/localConcepts/uerra/paramId.def index 8db696b0d..729478df6 100644 --- a/definitions/grib2/localConcepts/uerra/paramId.def +++ b/definitions/grib2/localConcepts/uerra/paramId.def @@ -17,6 +17,33 @@ scaledValueOfFirstFixedSurface = 200 ; scaleFactorOfFirstFixedSurface = 0 ; } +#Wind speed +'10' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 1 ; + typeOfStatisticalProcessing = 0 ; + } +#Wind speed +'10' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 1 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 100 ; + scaleFactorOfFirstFixedSurface = 0 ; + typeOfStatisticalProcessing = 0 ; + } +#Wind speed +'10' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 1 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 200 ; + scaleFactorOfFirstFixedSurface = 0 ; + typeOfStatisticalProcessing = 0 ; + } #Sea ice area fraction '31' = { discipline = 10 ; @@ -75,6 +102,34 @@ indicatorOfUnitForTimeRange = 1 ; typeOfStatisticalProcessing = 2 ; } +#Pressure +'54' = { + discipline = 0 ; + parameterCategory = 3 ; + parameterNumber = 0 ; + typeOfStatisticalProcessing = 0 ; + } +#Potential vorticity +'60' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 14 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific rain water content +'75' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 85 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific snow water content +'76' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 86 ; + typeOfStatisticalProcessing = 0 ; + } #Total column cloud liquid water '78' = { discipline = 0 ; @@ -287,6 +342,20 @@ typeOfFirstFixedSurface = 1 ; typeOfStatisticalProcessing = 0 ; } +#Specific cloud liquid water content +'246' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 83 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific cloud ice water content +'247' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 84 ; + typeOfStatisticalProcessing = 0 ; + } #2 metre specific humidity '174096' = { discipline = 0 ; @@ -298,6 +367,13 @@ scaleFactorOfFirstFixedSurface = 0 ; typeOfStatisticalProcessing = 0 ; } +#Precipitation type +'260015' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 19 ; + typeOfStatisticalProcessing = 0 ; + } #Total column integrated water vapour '260057' = { discipline = 0 ; diff --git a/definitions/grib2/localConcepts/uerra/shortName.def b/definitions/grib2/localConcepts/uerra/shortName.def index 9eefdd1fe..b16b48100 100644 --- a/definitions/grib2/localConcepts/uerra/shortName.def +++ b/definitions/grib2/localConcepts/uerra/shortName.def @@ -17,6 +17,33 @@ scaledValueOfFirstFixedSurface = 200 ; scaleFactorOfFirstFixedSurface = 0 ; } +#Wind speed +'ws' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 1 ; + typeOfStatisticalProcessing = 0 ; + } +#Wind speed +'ws' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 1 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 100 ; + scaleFactorOfFirstFixedSurface = 0 ; + typeOfStatisticalProcessing = 0 ; + } +#Wind speed +'ws' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 1 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 200 ; + scaleFactorOfFirstFixedSurface = 0 ; + typeOfStatisticalProcessing = 0 ; + } #Sea ice area fraction 'ci' = { discipline = 10 ; @@ -75,6 +102,34 @@ indicatorOfUnitForTimeRange = 1 ; typeOfStatisticalProcessing = 2 ; } +#Pressure +'pres' = { + discipline = 0 ; + parameterCategory = 3 ; + parameterNumber = 0 ; + typeOfStatisticalProcessing = 0 ; + } +#Potential vorticity +'pv' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 14 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific rain water content +'crwc' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 85 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific snow water content +'cswc' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 86 ; + typeOfStatisticalProcessing = 0 ; + } #Total column cloud liquid water 'tclw' = { discipline = 0 ; @@ -287,6 +342,20 @@ typeOfFirstFixedSurface = 1 ; typeOfStatisticalProcessing = 0 ; } +#Specific cloud liquid water content +'clwc' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 83 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific cloud ice water content +'ciwc' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 84 ; + typeOfStatisticalProcessing = 0 ; + } #2 metre specific humidity '2sh' = { discipline = 0 ; @@ -298,6 +367,13 @@ scaleFactorOfFirstFixedSurface = 0 ; typeOfStatisticalProcessing = 0 ; } +#Precipitation type +'ptype' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 19 ; + typeOfStatisticalProcessing = 0 ; + } #Total column integrated water vapour 'tciwv' = { discipline = 0 ; diff --git a/definitions/grib2/localConcepts/uerra/units.def b/definitions/grib2/localConcepts/uerra/units.def index 1abfdfd20..f86099f59 100644 --- a/definitions/grib2/localConcepts/uerra/units.def +++ b/definitions/grib2/localConcepts/uerra/units.def @@ -17,6 +17,33 @@ scaledValueOfFirstFixedSurface = 200 ; scaleFactorOfFirstFixedSurface = 0 ; } +#Wind speed +'m s**-1' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 1 ; + typeOfStatisticalProcessing = 0 ; + } +#Wind speed +'m s**-1' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 1 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 100 ; + scaleFactorOfFirstFixedSurface = 0 ; + typeOfStatisticalProcessing = 0 ; + } +#Wind speed +'m s**-1' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 1 ; + typeOfFirstFixedSurface = 103 ; + scaledValueOfFirstFixedSurface = 200 ; + scaleFactorOfFirstFixedSurface = 0 ; + typeOfStatisticalProcessing = 0 ; + } #Sea ice area fraction '(0 - 1)' = { discipline = 10 ; @@ -75,6 +102,34 @@ indicatorOfUnitForTimeRange = 1 ; typeOfStatisticalProcessing = 2 ; } +#Pressure +'Pa' = { + discipline = 0 ; + parameterCategory = 3 ; + parameterNumber = 0 ; + typeOfStatisticalProcessing = 0 ; + } +#Potential vorticity +'K m**2 kg**-1 s**-1' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 14 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific rain water content +'kg kg**-1' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 85 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific snow water content +'kg kg**-1' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 86 ; + typeOfStatisticalProcessing = 0 ; + } #Total column cloud liquid water 'kg m**-2' = { discipline = 0 ; @@ -287,6 +342,20 @@ typeOfFirstFixedSurface = 1 ; typeOfStatisticalProcessing = 0 ; } +#Specific cloud liquid water content +'kg kg**-1' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 83 ; + typeOfStatisticalProcessing = 0 ; + } +#Specific cloud ice water content +'kg kg**-1' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 84 ; + typeOfStatisticalProcessing = 0 ; + } #2 metre specific humidity 'kg kg**-1' = { discipline = 0 ; @@ -298,6 +367,13 @@ scaleFactorOfFirstFixedSurface = 0 ; typeOfStatisticalProcessing = 0 ; } +#Precipitation type +'(Code table 4.201)' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 19 ; + typeOfStatisticalProcessing = 0 ; + } #Total column integrated water vapour 'kg m**-2' = { discipline = 0 ; diff --git a/definitions/grib2/modelName.def b/definitions/grib2/modelName.def deleted file mode 100644 index 25b89c3d1..000000000 --- a/definitions/grib2/modelName.def +++ /dev/null @@ -1,43 +0,0 @@ -# modelName: Contribution from Daniel Lee @ DWD - -# COSMO -# general definition -'cosmo' = { originatingCentre=250; } -'cosmo' = { subCentre=250; } - -# definitions for ARPA-SIMC -'cosmo-i2' = { originatingCentre=200; - generatingProcessIdentifier=36; } -'cosmo-i2' = { originatingCentre=200; - generatingProcessIdentifier=139; } -'cosmo-i2' = { originatingCentre=200; - generatingProcessIdentifier=144; } -'cosmo-i2' = { originatingCentre=200; - generatingProcessIdentifier=148; } -'cosmo-i7' = { originatingCentre=200; - generatingProcessIdentifier=31; } -'cosmo-i7' = { originatingCentre=200; - generatingProcessIdentifier=32; } -'cosmo-i7' = { originatingCentre=200; - generatingProcessIdentifier=34; } -'cosmo-i7' = { originatingCentre=200; - generatingProcessIdentifier=38; } -'cosmo-i7' = { originatingCentre=200; - generatingProcessIdentifier=42; } -'cosmo-i7' = { originatingCentre=200; - generatingProcessIdentifier=46; } -'cosmo-i7' = { originatingCentre=200; - generatingProcessIdentifier=131; } -# definitions for Moscow -'cosmo_ru' = { originatingCentre=76; - generatingProcessIdentifier=135; } -'cosmo_ru-eps' = { originatingCentre=76; - generatingProcessIdentifier=235;} - -# definitions for Athens -'cosmo-greece' = { originatingCentre=96;} -# definitions for Warsaw / Poland -'cosmo-poland' = { originatingCentre=220;} -# definitions for Romania -'cosmo-romania' = { originatingCentre=242;} - diff --git a/definitions/grib2/name.def b/definitions/grib2/name.def index 25eb97ab5..2b00af2d9 100644 --- a/definitions/grib2/name.def +++ b/definitions/grib2/name.def @@ -4957,18 +4957,46 @@ parameterNumber = 18 ; typeOfStatisticalProcessing = 0 ; } -#Time-mean snow depth -'Time-mean snow depth' = { +#Time-mean wind speed +'Time-mean wind speed' = { discipline = 0 ; - parameterCategory = 1 ; - parameterNumber = 11 ; + parameterCategory = 2 ; + parameterNumber = 1 ; typeOfStatisticalProcessing = 0 ; } -#Time-mean snow cover -'Time-mean snow cover' = { +#Time-mean pressure +'Time-mean pressure' = { + discipline = 0 ; + parameterCategory = 3 ; + parameterNumber = 0 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean potential vorticity +'Time-mean potential vorticity' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 14 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean specific rain water content +'Time-mean specific rain water content' = { discipline = 0 ; parameterCategory = 1 ; - parameterNumber = 42 ; + parameterNumber = 85 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean specific snow water content +'Time-mean specific snow water content' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 86 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean eta-coordinate vertical velocity +'Time-mean eta-coordinate vertical velocity' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 32 ; typeOfStatisticalProcessing = 0 ; } #Time-mean geopotential @@ -5039,6 +5067,13 @@ typeOfSecondFixedSurface = 8 ; typeOfStatisticalProcessing = 0 ; } +#Time-mean vorticity (relative) +'Time-mean vorticity (relative)' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 12 ; + typeOfStatisticalProcessing = 0 ; + } #Time-mean mean sea level pressure 'Time-mean mean sea level pressure' = { discipline = 0 ; @@ -5047,6 +5082,13 @@ typeOfFirstFixedSurface = 101 ; typeOfStatisticalProcessing = 0 ; } +#Time-mean divergence +'Time-mean divergence' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 13 ; + typeOfStatisticalProcessing = 0 ; + } #Time-mean relative humidity 'Time-mean relative humidity' = { discipline = 0 ; @@ -5091,6 +5133,13 @@ scaleFactorOfFirstFixedSurface = 0 ; typeOfStatisticalProcessing = 0 ; } +#Time-mean ozone mass mixing ratio +'Time-mean ozone mass mixing ratio' = { + discipline = 0 ; + parameterCategory = 14 ; + parameterNumber = 1 ; + typeOfStatisticalProcessing = 0 ; + } #Time-mean temperature of snow layer 'Time-mean temperature of snow layer' = { discipline = 2 ; @@ -5114,6 +5163,131 @@ typeOfFirstFixedSurface = 1 ; typeOfStatisticalProcessing = 0 ; } +#Time-mean specific cloud liquid water content +'Time-mean specific cloud liquid water content' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 83 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean specific cloud ice water content +'Time-mean specific cloud ice water content' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 84 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean fraction of cloud cover +'Time-mean fraction of cloud cover' = { + discipline = 0 ; + parameterCategory = 6 ; + parameterNumber = 32 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean K index +'Time-mean K index' = { + discipline = 0 ; + parameterCategory = 7 ; + parameterNumber = 2 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean total totals index +'Time-mean total totals index' = { + discipline = 0 ; + parameterCategory = 7 ; + parameterNumber = 4 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean clear air turbulence (CAT) +'Time-mean clear air turbulence (CAT)' = { + discipline = 0 ; + parameterCategory = 19 ; + parameterNumber = 29 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean discharge from rivers or streams +'Time-mean discharge from rivers or streams' = { + discipline = 1 ; + parameterCategory = 0 ; + parameterNumber = 7 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean soil wetness index (total layer) +'Time-mean soil wetness index (total layer)' = { + discipline = 2 ; + parameterCategory = 3 ; + parameterNumber = 30 ; + typeOfFirstFixedSurface = 1 ; + typeOfSecondFixedSurface = 151 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean soil wetness index (root zone) +'Time-mean soil wetness index (root zone)' = { + discipline = 2 ; + parameterCategory = 3 ; + parameterNumber = 30 ; + typeOfFirstFixedSurface = 1 ; + typeOfSecondFixedSurface = 167 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean soil wetness index(layer) +'Time-mean soil wetness index(layer)' = { + discipline = 2 ; + parameterCategory = 3 ; + parameterNumber = 30 ; + typeOfFirstFixedSurface = 151 ; + typeOfSecondFixedSurface = 151 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean floodplain depth +'Time-mean floodplain depth' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 17 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean floodplain flooded fraction +'Time-mean floodplain flooded fraction' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 18 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean floodplain flooded area +'Time-mean floodplain flooded area' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 19 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean river fraction +'Time-mean river fraction' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 20 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean river area +'Time-mean river area' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 21 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean fraction of river coverage plus river related flooding +'Time-mean fraction of river coverage plus river related flooding' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 22 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean area of river coverage plus river related flooding +'Time-mean area of river coverage plus river related flooding' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 23 ; + typeOfStatisticalProcessing = 0 ; + } #Cross sectional area of flow in channel 'Cross sectional area of flow in channel' = { discipline = 1 ; @@ -5174,26 +5348,6 @@ parameterCategory = 0 ; parameterNumber = 15 ; } -#Mean discharge in the last 6 hours -'Mean discharge in the last 6 hours' = { - discipline = 1 ; - parameterCategory = 0 ; - parameterNumber = 7 ; - typeOfFirstFixedSurface = 1 ; - indicatorOfUnitForTimeRange = 1 ; - typeOfStatisticalProcessing = 0 ; - lengthOfTimeRange = 6 ; - } -#Mean discharge in the last 24 hours -'Mean discharge in the last 24 hours' = { - discipline = 1 ; - parameterCategory = 0 ; - parameterNumber = 7 ; - typeOfFirstFixedSurface = 1 ; - indicatorOfUnitForTimeRange = 1 ; - typeOfStatisticalProcessing = 0 ; - lengthOfTimeRange = 24 ; - } #Snow depth at elevation bands 'Snow depth at elevation bands' = { discipline = 2 ; @@ -5246,6 +5400,48 @@ parameterCategory = 0 ; parameterNumber = 19 ; } +#Floodplain depth +'Floodplain depth' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 17 ; + } +#Floodplain flooded fraction +'Floodplain flooded fraction' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 18 ; + } +#Floodplain flooded area +'Floodplain flooded area' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 19 ; + } +#River fraction +'River fraction' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 20 ; + } +#River area +'River area' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 21 ; + } +#Fraction of river coverage plus river related flooding +'Fraction of river coverage plus river related flooding' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 22 ; + } +#Area of river coverage plus river related flooding +'Area of river coverage plus river related flooding' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 23 ; + } #Latitude 'Latitude' = { discipline = 0 ; @@ -7203,6 +7399,48 @@ typeOfFirstFixedSurface = 1 ; typeOfSecondFixedSurface = 8 ; } +#Standardised Precipitation Index (SPI) +'Standardised Precipitation Index (SPI)' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 0 ; + } +#Standardised Precipitation Evapotranspiration Index (SPEI) +'Standardised Precipitation Evapotranspiration Index (SPEI)' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 1 ; + } +#Standardised Streamflow Index (SSFI) +'Standardised Streamflow Index (SSFI)' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 2 ; + } +#Standardised Reservoir Supply Index (SRSI) +'Standardised Reservoir Supply Index (SRSI)' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 3 ; + } +#Standardised Water-level Index (SWI) +'Standardised Water-level Index (SWI)' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 4 ; + } +#Standardised Snowmelt and Rain Index (SMRI) +'Standardised Snowmelt and Rain Index (SMRI)' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 5 ; + } +#Streamflow Drought Index (SDI) +'Streamflow Drought Index (SDI)' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 6 ; + } #Universal thermal climate index 'Universal thermal climate index' = { discipline = 20 ; @@ -7340,12 +7578,6 @@ discipline = 10 ; parameterCategory = 2 ; parameterNumber = 1 ; - typeOfFirstFixedSurface = 174 ; - typeOfSecondFixedSurface = 176 ; - scaledValueOfFirstFixedSurface = missing() ; - scaleFactorOfFirstFixedSurface = missing() ; - scaledValueOfSecondFixedSurface = missing() ; - scaleFactorOfSecondFixedSurface = missing() ; } #Sea ice area fraction 'Sea ice area fraction' = { @@ -8450,12 +8682,6 @@ discipline = 10 ; parameterCategory = 2 ; parameterNumber = 1 ; - typeOfFirstFixedSurface = 174 ; - typeOfSecondFixedSurface = 176 ; - scaledValueOfFirstFixedSurface = missing() ; - scaleFactorOfFirstFixedSurface = missing() ; - scaledValueOfSecondFixedSurface = missing() ; - scaleFactorOfSecondFixedSurface = missing() ; typeOfStatisticalProcessing = 0 ; } #Time-mean sea ice area fraction @@ -10047,6 +10273,44 @@ is_chemical_srcsink = 1 ; sourceSinkChemicalPhysicalProcess = 7 ; } +#Aerosol optical depth +'Aerosol optical depth' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 102 ; + } +#Single scattering albedo +'Single scattering albedo' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 103 ; + } +#Asymmetry Factor +'Asymmetry Factor' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 104 ; + } +#Aerosol backscatter from top of atmosphere +'Aerosol backscatter from top of atmosphere' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 107 ; + typeOfFirstFixedSurface = 8 ; + } +#Aerosol backscatter from ground +'Aerosol backscatter from ground' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 108 ; + typeOfFirstFixedSurface = 1 ; + } +#Aerosol extinction coefficient +'Aerosol extinction coefficient' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 105 ; + } #Pressure tendency 'Pressure tendency' = { discipline = 0 ; @@ -10575,6 +10839,12 @@ parameterCategory = 0 ; parameterNumber = 44 ; } +#Wave spectral peakedness +'Wave spectral peakedness' = { + discipline = 10 ; + parameterCategory = 0 ; + parameterNumber = 98 ; + } #Skin reservoir content 'Skin reservoir content' = { discipline = 2 ; diff --git a/definitions/grib2/paramId.def b/definitions/grib2/paramId.def index 4483d9fbd..92bba522a 100644 --- a/definitions/grib2/paramId.def +++ b/definitions/grib2/paramId.def @@ -4957,18 +4957,46 @@ parameterNumber = 18 ; typeOfStatisticalProcessing = 0 ; } -#Time-mean snow depth -'235095' = { +#Time-mean wind speed +'235097' = { discipline = 0 ; - parameterCategory = 1 ; - parameterNumber = 11 ; + parameterCategory = 2 ; + parameterNumber = 1 ; typeOfStatisticalProcessing = 0 ; } -#Time-mean snow cover -'235096' = { +#Time-mean pressure +'235098' = { + discipline = 0 ; + parameterCategory = 3 ; + parameterNumber = 0 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean potential vorticity +'235100' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 14 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean specific rain water content +'235101' = { discipline = 0 ; parameterCategory = 1 ; - parameterNumber = 42 ; + parameterNumber = 85 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean specific snow water content +'235102' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 86 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean eta-coordinate vertical velocity +'235103' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 32 ; typeOfStatisticalProcessing = 0 ; } #Time-mean geopotential @@ -5039,6 +5067,13 @@ typeOfSecondFixedSurface = 8 ; typeOfStatisticalProcessing = 0 ; } +#Time-mean vorticity (relative) +'235138' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 12 ; + typeOfStatisticalProcessing = 0 ; + } #Time-mean mean sea level pressure '235151' = { discipline = 0 ; @@ -5047,6 +5082,13 @@ typeOfFirstFixedSurface = 101 ; typeOfStatisticalProcessing = 0 ; } +#Time-mean divergence +'235155' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 13 ; + typeOfStatisticalProcessing = 0 ; + } #Time-mean relative humidity '235157' = { discipline = 0 ; @@ -5091,6 +5133,13 @@ scaleFactorOfFirstFixedSurface = 0 ; typeOfStatisticalProcessing = 0 ; } +#Time-mean ozone mass mixing ratio +'235203' = { + discipline = 0 ; + parameterCategory = 14 ; + parameterNumber = 1 ; + typeOfStatisticalProcessing = 0 ; + } #Time-mean temperature of snow layer '235238' = { discipline = 2 ; @@ -5114,6 +5163,131 @@ typeOfFirstFixedSurface = 1 ; typeOfStatisticalProcessing = 0 ; } +#Time-mean specific cloud liquid water content +'235246' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 83 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean specific cloud ice water content +'235247' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 84 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean fraction of cloud cover +'235248' = { + discipline = 0 ; + parameterCategory = 6 ; + parameterNumber = 32 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean K index +'235257' = { + discipline = 0 ; + parameterCategory = 7 ; + parameterNumber = 2 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean total totals index +'235258' = { + discipline = 0 ; + parameterCategory = 7 ; + parameterNumber = 4 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean clear air turbulence (CAT) +'235262' = { + discipline = 0 ; + parameterCategory = 19 ; + parameterNumber = 29 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean discharge from rivers or streams +'235270' = { + discipline = 1 ; + parameterCategory = 0 ; + parameterNumber = 7 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean soil wetness index (total layer) +'235271' = { + discipline = 2 ; + parameterCategory = 3 ; + parameterNumber = 30 ; + typeOfFirstFixedSurface = 1 ; + typeOfSecondFixedSurface = 151 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean soil wetness index (root zone) +'235272' = { + discipline = 2 ; + parameterCategory = 3 ; + parameterNumber = 30 ; + typeOfFirstFixedSurface = 1 ; + typeOfSecondFixedSurface = 167 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean soil wetness index(layer) +'235273' = { + discipline = 2 ; + parameterCategory = 3 ; + parameterNumber = 30 ; + typeOfFirstFixedSurface = 151 ; + typeOfSecondFixedSurface = 151 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean floodplain depth +'235274' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 17 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean floodplain flooded fraction +'235275' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 18 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean floodplain flooded area +'235276' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 19 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean river fraction +'235277' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 20 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean river area +'235278' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 21 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean fraction of river coverage plus river related flooding +'235279' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 22 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean area of river coverage plus river related flooding +'235280' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 23 ; + typeOfStatisticalProcessing = 0 ; + } #Cross sectional area of flow in channel '240011' = { discipline = 1 ; @@ -5174,26 +5348,6 @@ parameterCategory = 0 ; parameterNumber = 15 ; } -#Mean discharge in the last 6 hours -'240023' = { - discipline = 1 ; - parameterCategory = 0 ; - parameterNumber = 7 ; - typeOfFirstFixedSurface = 1 ; - indicatorOfUnitForTimeRange = 1 ; - typeOfStatisticalProcessing = 0 ; - lengthOfTimeRange = 6 ; - } -#Mean discharge in the last 24 hours -'240024' = { - discipline = 1 ; - parameterCategory = 0 ; - parameterNumber = 7 ; - typeOfFirstFixedSurface = 1 ; - indicatorOfUnitForTimeRange = 1 ; - typeOfStatisticalProcessing = 0 ; - lengthOfTimeRange = 24 ; - } #Snow depth at elevation bands '240026' = { discipline = 2 ; @@ -5246,6 +5400,48 @@ parameterCategory = 0 ; parameterNumber = 19 ; } +#Floodplain depth +'240035' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 17 ; + } +#Floodplain flooded fraction +'240036' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 18 ; + } +#Floodplain flooded area +'240037' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 19 ; + } +#River fraction +'240038' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 20 ; + } +#River area +'240039' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 21 ; + } +#Fraction of river coverage plus river related flooding +'240040' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 22 ; + } +#Area of river coverage plus river related flooding +'240041' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 23 ; + } #Latitude '250001' = { discipline = 0 ; @@ -7203,6 +7399,48 @@ typeOfFirstFixedSurface = 1 ; typeOfSecondFixedSurface = 8 ; } +#Standardised Precipitation Index (SPI) +'260658' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 0 ; + } +#Standardised Precipitation Evapotranspiration Index (SPEI) +'260659' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 1 ; + } +#Standardised Streamflow Index (SSFI) +'260660' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 2 ; + } +#Standardised Reservoir Supply Index (SRSI) +'260661' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 3 ; + } +#Standardised Water-level Index (SWI) +'260662' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 4 ; + } +#Standardised Snowmelt and Rain Index (SMRI) +'260663' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 5 ; + } +#Streamflow Drought Index (SDI) +'260664' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 6 ; + } #Universal thermal climate index '261001' = { discipline = 20 ; @@ -7340,12 +7578,6 @@ discipline = 10 ; parameterCategory = 2 ; parameterNumber = 1 ; - typeOfFirstFixedSurface = 174 ; - typeOfSecondFixedSurface = 176 ; - scaledValueOfFirstFixedSurface = missing() ; - scaleFactorOfFirstFixedSurface = missing() ; - scaledValueOfSecondFixedSurface = missing() ; - scaleFactorOfSecondFixedSurface = missing() ; } #Sea ice area fraction '262001' = { @@ -8450,12 +8682,6 @@ discipline = 10 ; parameterCategory = 2 ; parameterNumber = 1 ; - typeOfFirstFixedSurface = 174 ; - typeOfSecondFixedSurface = 176 ; - scaledValueOfFirstFixedSurface = missing() ; - scaleFactorOfFirstFixedSurface = missing() ; - scaledValueOfSecondFixedSurface = missing() ; - scaleFactorOfSecondFixedSurface = missing() ; typeOfStatisticalProcessing = 0 ; } #Time-mean sea ice area fraction @@ -10047,6 +10273,44 @@ is_chemical_srcsink = 1 ; sourceSinkChemicalPhysicalProcess = 7 ; } +#Aerosol optical depth +'457000' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 102 ; + } +#Single scattering albedo +'458000' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 103 ; + } +#Asymmetry Factor +'459000' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 104 ; + } +#Aerosol backscatter from top of atmosphere +'460000' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 107 ; + typeOfFirstFixedSurface = 8 ; + } +#Aerosol backscatter from ground +'461000' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 108 ; + typeOfFirstFixedSurface = 1 ; + } +#Aerosol extinction coefficient +'462000' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 105 ; + } #Pressure tendency '3003' = { discipline = 0 ; @@ -10575,6 +10839,12 @@ parameterCategory = 0 ; parameterNumber = 44 ; } +#Wave spectral peakedness +'140254' = { + discipline = 10 ; + parameterCategory = 0 ; + parameterNumber = 98 ; + } #Skin reservoir content '160198' = { discipline = 2 ; diff --git a/definitions/grib2/parameters.def b/definitions/grib2/parameters.def index 02f5993c9..3ab4b548c 100644 --- a/definitions/grib2/parameters.def +++ b/definitions/grib2/parameters.def @@ -61,9 +61,6 @@ if (!chemId is "unknown"){ alias parameter.chemShortName = chemShortName; } -# modelName: Contribution from Daniel Lee @ DWD -concept modelName (defaultName,"modelName.def",conceptsDir2,conceptsDir1): no_copy,dump,read_only; - template_nofail names "grib2/products_[productionStatusOfProcessedData].def"; meta ifsParam ifs_param(paramId,type); diff --git a/definitions/grib2/shortName.def b/definitions/grib2/shortName.def index e44ebbc99..94b48873f 100644 --- a/definitions/grib2/shortName.def +++ b/definitions/grib2/shortName.def @@ -4836,28 +4836,28 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean snow density -'mrsn' = { +'avg_rsn' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 61 ; typeOfStatisticalProcessing = 0 ; } #Time-mean low vegetation cover -'mcvl' = { +'avg_cvl' = { discipline = 2 ; parameterCategory = 0 ; parameterNumber = 53 ; typeOfStatisticalProcessing = 0 ; } #Time-mean high vegetation cover -'mcvh' = { +'avg_cvh' = { discipline = 2 ; parameterCategory = 0 ; parameterNumber = 54 ; typeOfStatisticalProcessing = 0 ; } #Time-mean sea ice area fraction -'mci' = { +'avg_ci' = { discipline = 10 ; parameterCategory = 2 ; parameterNumber = 0 ; @@ -4865,7 +4865,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean sea surface temperature -'msst' = { +'avg_sst' = { discipline = 10 ; parameterCategory = 3 ; parameterNumber = 0 ; @@ -4873,21 +4873,21 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean leaf area index, low vegetation -'mlai_lv' = { +'avg_lai_lv' = { discipline = 2 ; parameterCategory = 0 ; parameterNumber = 55 ; typeOfStatisticalProcessing = 0 ; } #Time-mean leaf area index, high vegetation -'mlai_hv' = { +'avg_lai_hv' = { discipline = 2 ; parameterCategory = 0 ; parameterNumber = 56 ; typeOfStatisticalProcessing = 0 ; } #Time-mean total column liquid water -'mtclw' = { +'avg_tclw' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 69 ; @@ -4896,7 +4896,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean total column cloud ice water -'mtciw' = { +'avg_tciw' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 70 ; @@ -4905,7 +4905,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean 2 metre specific humidity -'m2sh' = { +'avg_2sh' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 0 ; @@ -4916,7 +4916,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean lake mix-layer temperature -'mlmlt' = { +'avg_lmlt' = { discipline = 1 ; parameterCategory = 2 ; parameterNumber = 1 ; @@ -4925,7 +4925,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean lake mix-layer depth -'mlmld' = { +'avg_lmld' = { discipline = 1 ; parameterCategory = 2 ; parameterNumber = 0 ; @@ -4934,7 +4934,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean 2 metre relative humidity -'m2r' = { +'avg_2r' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 1 ; @@ -4944,70 +4944,98 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean fraction of snow cover -'mfscov' = { +'avg_fscov' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 121 ; typeOfStatisticalProcessing = 0 ; } #Time-mean soil temperature -'msot' = { +'avg_sot' = { discipline = 2 ; parameterCategory = 3 ; parameterNumber = 18 ; typeOfStatisticalProcessing = 0 ; } -#Time-mean snow depth -'msde' = { +#Time-mean wind speed +'avg_ws' = { discipline = 0 ; - parameterCategory = 1 ; - parameterNumber = 11 ; + parameterCategory = 2 ; + parameterNumber = 1 ; typeOfStatisticalProcessing = 0 ; } -#Time-mean snow cover -'msnowc' = { +#Time-mean pressure +'avg_pres' = { + discipline = 0 ; + parameterCategory = 3 ; + parameterNumber = 0 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean potential vorticity +'avg_pv' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 14 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean specific rain water content +'avg_crwc' = { discipline = 0 ; parameterCategory = 1 ; - parameterNumber = 42 ; + parameterNumber = 85 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean specific snow water content +'avg_cswc' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 86 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean eta-coordinate vertical velocity +'avg_etadot' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 32 ; typeOfStatisticalProcessing = 0 ; } #Time-mean geopotential -'mz' = { +'avg_z' = { discipline = 0 ; parameterCategory = 3 ; parameterNumber = 4 ; typeOfStatisticalProcessing = 0 ; } #Time-mean temperature -'mt' = { +'avg_t' = { discipline = 0 ; parameterCategory = 0 ; parameterNumber = 0 ; typeOfStatisticalProcessing = 0 ; } #Time-mean U component of wind -'mu' = { +'avg_u' = { discipline = 0 ; parameterCategory = 2 ; parameterNumber = 2 ; typeOfStatisticalProcessing = 0 ; } #Time-mean V component of wind -'mv' = { +'avg_v' = { discipline = 0 ; parameterCategory = 2 ; parameterNumber = 3 ; typeOfStatisticalProcessing = 0 ; } #Time-mean specific humidity -'mq' = { +'avg_q' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 0 ; typeOfStatisticalProcessing = 0 ; } #Time-mean surface pressure -'msp' = { +'avg_sp' = { discipline = 0 ; parameterCategory = 3 ; parameterNumber = 0 ; @@ -5015,14 +5043,14 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean vertical velocity -'mw' = { +'avg_w' = { discipline = 0 ; parameterCategory = 2 ; parameterNumber = 8 ; typeOfStatisticalProcessing = 0 ; } #Time-mean total column water -'mtcw' = { +'avg_tcw' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 51 ; @@ -5031,7 +5059,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean total column vertically-integrated water vapour -'mtcwv' = { +'avg_tcwv' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 64 ; @@ -5039,30 +5067,44 @@ typeOfSecondFixedSurface = 8 ; typeOfStatisticalProcessing = 0 ; } +#Time-mean vorticity (relative) +'avg_vo' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 12 ; + typeOfStatisticalProcessing = 0 ; + } #Time-mean mean sea level pressure -'mmsl' = { +'avg_msl' = { discipline = 0 ; parameterCategory = 3 ; parameterNumber = 0 ; typeOfFirstFixedSurface = 101 ; typeOfStatisticalProcessing = 0 ; } +#Time-mean divergence +'avg_d' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 13 ; + typeOfStatisticalProcessing = 0 ; + } #Time-mean relative humidity -'mr' = { +'avg_r' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 1 ; typeOfStatisticalProcessing = 0 ; } #Time-mean boundary layer height -'mblh' = { +'avg_blh' = { discipline = 0 ; parameterCategory = 3 ; parameterNumber = 18 ; typeOfStatisticalProcessing = 0 ; } #Time-mean 10 metre U wind component -'m10u' = { +'avg_10u' = { discipline = 0 ; parameterCategory = 2 ; parameterNumber = 2 ; @@ -5072,7 +5114,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean 10 metre V wind component -'m10v' = { +'avg_10v' = { discipline = 0 ; parameterCategory = 2 ; parameterNumber = 3 ; @@ -5082,7 +5124,7 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean 2 metre dewpoint temperature -'m2d' = { +'avg_2d' = { discipline = 0 ; parameterCategory = 0 ; parameterNumber = 6 ; @@ -5091,15 +5133,22 @@ scaleFactorOfFirstFixedSurface = 0 ; typeOfStatisticalProcessing = 0 ; } +#Time-mean ozone mass mixing ratio +'avg_o3' = { + discipline = 0 ; + parameterCategory = 14 ; + parameterNumber = 1 ; + typeOfStatisticalProcessing = 0 ; + } #Time-mean temperature of snow layer -'mtsn' = { +'avg_tsn' = { discipline = 2 ; parameterCategory = 3 ; parameterNumber = 28 ; typeOfStatisticalProcessing = 0 ; } #Time-mean forecast surface roughness -'mfsr' = { +'avg_fsr' = { discipline = 2 ; parameterCategory = 0 ; parameterNumber = 1 ; @@ -5107,13 +5156,138 @@ typeOfStatisticalProcessing = 0 ; } #Time-mean forecast logarithm of surface roughness for heat -'mflsr' = { +'avg_flsr' = { discipline = 0 ; parameterCategory = 2 ; parameterNumber = 54 ; typeOfFirstFixedSurface = 1 ; typeOfStatisticalProcessing = 0 ; } +#Time-mean specific cloud liquid water content +'avg_clwc' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 83 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean specific cloud ice water content +'avg_ciwc' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 84 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean fraction of cloud cover +'avg_cc' = { + discipline = 0 ; + parameterCategory = 6 ; + parameterNumber = 32 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean K index +'avg_kx' = { + discipline = 0 ; + parameterCategory = 7 ; + parameterNumber = 2 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean total totals index +'avg_totalx' = { + discipline = 0 ; + parameterCategory = 7 ; + parameterNumber = 4 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean clear air turbulence (CAT) +'avg_cat' = { + discipline = 0 ; + parameterCategory = 19 ; + parameterNumber = 29 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean discharge from rivers or streams +'avg_dis' = { + discipline = 1 ; + parameterCategory = 0 ; + parameterNumber = 7 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean soil wetness index (total layer) +'avg_swit' = { + discipline = 2 ; + parameterCategory = 3 ; + parameterNumber = 30 ; + typeOfFirstFixedSurface = 1 ; + typeOfSecondFixedSurface = 151 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean soil wetness index (root zone) +'avg_swir' = { + discipline = 2 ; + parameterCategory = 3 ; + parameterNumber = 30 ; + typeOfFirstFixedSurface = 1 ; + typeOfSecondFixedSurface = 167 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean soil wetness index(layer) +'avg_swil' = { + discipline = 2 ; + parameterCategory = 3 ; + parameterNumber = 30 ; + typeOfFirstFixedSurface = 151 ; + typeOfSecondFixedSurface = 151 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean floodplain depth +'avg_flddep' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 17 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean floodplain flooded fraction +'avg_fldffr' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 18 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean floodplain flooded area +'avg_fldfar' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 19 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean river fraction +'avg_rivfr' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 20 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean river area +'avg_rivar' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 21 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean fraction of river coverage plus river related flooding +'avg_rivcffr' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 22 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean area of river coverage plus river related flooding +'avg_rivcfar' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 23 ; + typeOfStatisticalProcessing = 0 ; + } #Cross sectional area of flow in channel 'chcross' = { discipline = 1 ; @@ -5174,26 +5348,6 @@ parameterCategory = 0 ; parameterNumber = 15 ; } -#Mean discharge in the last 6 hours -'dis06' = { - discipline = 1 ; - parameterCategory = 0 ; - parameterNumber = 7 ; - typeOfFirstFixedSurface = 1 ; - indicatorOfUnitForTimeRange = 1 ; - typeOfStatisticalProcessing = 0 ; - lengthOfTimeRange = 6 ; - } -#Mean discharge in the last 24 hours -'dis24' = { - discipline = 1 ; - parameterCategory = 0 ; - parameterNumber = 7 ; - typeOfFirstFixedSurface = 1 ; - indicatorOfUnitForTimeRange = 1 ; - typeOfStatisticalProcessing = 0 ; - lengthOfTimeRange = 24 ; - } #Snow depth at elevation bands 'sd_elev' = { discipline = 2 ; @@ -5246,6 +5400,48 @@ parameterCategory = 0 ; parameterNumber = 19 ; } +#Floodplain depth +'flddep' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 17 ; + } +#Floodplain flooded fraction +'fldffr' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 18 ; + } +#Floodplain flooded area +'fldfar' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 19 ; + } +#River fraction +'rivfr' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 20 ; + } +#River area +'rivar' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 21 ; + } +#Fraction of river coverage plus river related flooding +'rivcffr' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 22 ; + } +#Area of river coverage plus river related flooding +'rivcfar' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 23 ; + } #Latitude 'lat' = { discipline = 0 ; @@ -7203,6 +7399,48 @@ typeOfFirstFixedSurface = 1 ; typeOfSecondFixedSurface = 8 ; } +#Standardised Precipitation Index (SPI) +'spi' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 0 ; + } +#Standardised Precipitation Evapotranspiration Index (SPEI) +'spei' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 1 ; + } +#Standardised Streamflow Index (SSFI) +'ssfi' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 2 ; + } +#Standardised Reservoir Supply Index (SRSI) +'srsi' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 3 ; + } +#Standardised Water-level Index (SWI) +'swi' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 4 ; + } +#Standardised Snowmelt and Rain Index (SMRI) +'smri' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 5 ; + } +#Streamflow Drought Index (SDI) +'sdi' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 6 ; + } #Universal thermal climate index 'utci' = { discipline = 20 ; @@ -7340,12 +7578,6 @@ discipline = 10 ; parameterCategory = 2 ; parameterNumber = 1 ; - typeOfFirstFixedSurface = 174 ; - typeOfSecondFixedSurface = 176 ; - scaledValueOfFirstFixedSurface = missing() ; - scaleFactorOfFirstFixedSurface = missing() ; - scaledValueOfSecondFixedSurface = missing() ; - scaleFactorOfSecondFixedSurface = missing() ; } #Sea ice area fraction 'siconc' = { @@ -8450,12 +8682,6 @@ discipline = 10 ; parameterCategory = 2 ; parameterNumber = 1 ; - typeOfFirstFixedSurface = 174 ; - typeOfSecondFixedSurface = 176 ; - scaledValueOfFirstFixedSurface = missing() ; - scaleFactorOfFirstFixedSurface = missing() ; - scaledValueOfSecondFixedSurface = missing() ; - scaleFactorOfSecondFixedSurface = missing() ; typeOfStatisticalProcessing = 0 ; } #Time-mean sea ice area fraction @@ -10047,6 +10273,44 @@ is_chemical_srcsink = 1 ; sourceSinkChemicalPhysicalProcess = 7 ; } +#Aerosol optical depth +'aod' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 102 ; + } +#Single scattering albedo +'ssa' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 103 ; + } +#Asymmetry Factor +'asymf' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 104 ; + } +#Aerosol backscatter from top of atmosphere +'aerbscattoa' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 107 ; + typeOfFirstFixedSurface = 8 ; + } +#Aerosol backscatter from ground +'aerbscatgnd' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 108 ; + typeOfFirstFixedSurface = 1 ; + } +#Aerosol extinction coefficient +'aerext' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 105 ; + } #Pressure tendency 'ptend' = { discipline = 0 ; @@ -10575,6 +10839,12 @@ parameterCategory = 0 ; parameterNumber = 44 ; } +#Wave spectral peakedness +'wsp' = { + discipline = 10 ; + parameterCategory = 0 ; + parameterNumber = 98 ; + } #Skin reservoir content 'srcrea' = { discipline = 2 ; diff --git a/definitions/grib2/template.4.124.def b/definitions/grib2/template.4.124.def new file mode 100644 index 000000000..a3b83980e --- /dev/null +++ b/definitions/grib2/template.4.124.def @@ -0,0 +1,12 @@ +# (C) Copyright 2005- ECMWF. + +# TEMPLATE 4.124, Analysis or forecast at a horizontal level or in a horizontal layer at a point in time for radionuclides + +include "grib2/template.4.parameter.def" +include "grib2/template.4.chemical.def" +include "grib2/template.4.source.def" +include "grib2/template.4.radionuclides.def" +include "grib2/template.4.generating_process.def" +include "grib2/template.4.forecast_time.def" +include "grib2/template.4.point_in_time.def" +include "grib2/template.4.horizontal.def" diff --git a/definitions/grib2/template.4.125.def b/definitions/grib2/template.4.125.def new file mode 100644 index 000000000..88ebd7894 --- /dev/null +++ b/definitions/grib2/template.4.125.def @@ -0,0 +1,13 @@ +# (C) Copyright 2005- ECMWF. + +# TEMPLATE 4.125, Individual ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer at a point in time for radionuclides + +include "grib2/template.4.parameter.def" +include "grib2/template.4.chemical.def" +include "grib2/template.4.source.def" +include "grib2/template.4.radionuclides.def" +include "grib2/template.4.generating_process.def" +include "grib2/template.4.forecast_time.def" +include "grib2/template.4.point_in_time.def" +include "grib2/template.4.horizontal.def" +include "grib2/template.4.eps.def" diff --git a/definitions/grib2/template.4.126.def b/definitions/grib2/template.4.126.def new file mode 100644 index 000000000..fed3fbac1 --- /dev/null +++ b/definitions/grib2/template.4.126.def @@ -0,0 +1,12 @@ +# (C) Copyright 2005- ECMWF. + +# TEMPLATE 4.126, Average, accumulation, and/or extreme values or other statistically processed values at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval for radionuclides + +include "grib2/template.4.parameter.def" +include "grib2/template.4.chemical.def" +include "grib2/template.4.source.def" +include "grib2/template.4.radionuclides.def" +include "grib2/template.4.generating_process.def" +include "grib2/template.4.forecast_time.def" +include "grib2/template.4.horizontal.def" +include "grib2/template.4.statistical.def" diff --git a/definitions/grib2/template.4.127.def b/definitions/grib2/template.4.127.def new file mode 100644 index 000000000..baa754fca --- /dev/null +++ b/definitions/grib2/template.4.127.def @@ -0,0 +1,14 @@ +# (C) Copyright 2005- ECMWF. + +# TEMPLATE 4.127, Individual ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval for radionuclides + +include "grib2/template.4.parameter.def" +include "grib2/template.4.chemical.def" +include "grib2/template.4.source.def" +include "grib2/template.4.radionuclides.def" +include "grib2/template.4.generating_process.def" +include "grib2/template.4.forecast_time.def" +include "grib2/template.4.horizontal.def" +include "grib2/template.4.eps.def" +include "grib2/template.4.statistical.def" + diff --git a/definitions/grib2/template.4.20.def b/definitions/grib2/template.4.20.def index b739bf6bb..882691250 100644 --- a/definitions/grib2/template.4.20.def +++ b/definitions/grib2/template.4.20.def @@ -1,60 +1,60 @@ # (C) Copyright 2005- ECMWF. # TEMPLATE 4.20, Radar product -codetable[1] parameterCategory ('4.1.[discipline:l].table',masterDir,localDir) : dump; +codetable[1] parameterCategory('4.1.[discipline:l].table',masterDir,localDir) : dump; # Parameter number -codetable[1] parameterNumber ('4.2.[discipline:l].[parameterCategory:l].table',masterDir,localDir) : dump; +codetable[1] parameterNumber('4.2.[discipline:l].[parameterCategory:l].table',masterDir,localDir) : dump; meta parameterUnits codetable_units(parameterNumber) : dump; meta parameterName codetable_title(parameterNumber) : dump; -codetable[1] typeOfGeneratingProcess ('4.3.table',masterDir,localDir) : dump; +codetable[1] typeOfGeneratingProcess('4.3.table',masterDir,localDir) : dump; # Number of radar sites used -unsigned[1] numberOfRadarSitesUsed : dump; +unsigned[1] numberOfRadarSitesUsed : dump; -codetable[1] indicatorOfUnitOfTimeRange ('4.4.table',masterDir,localDir) : dump; -alias indicatorOfUnitForForecastTime = indicatorOfUnitOfTimeRange; +codetable[1] indicatorOfUnitForForecastTime('4.4.table',masterDir,localDir) : dump; +alias indicatorOfUnitOfTimeRange = indicatorOfUnitForForecastTime; include "grib2/stepUnits.def" # Site latitude (in microdegrees) -unsigned[4] siteLatitude : dump; +unsigned[4] siteLatitude : dump; # Site longitude (in microdegrees) -unsigned[4] siteLongitude : dump; +unsigned[4] siteLongitude : dump; # Site elevation (meters) -unsigned[2] siteElevation : dump; +unsigned[2] siteElevation : dump; # Site ID (alphanumeric) -unsigned[4] siteId : dump; +unsigned[4] siteId : dump; # Site ID (numeric) -unsigned[2] siteId : dump; +unsigned[2] siteId : dump; # Operating mode -codetable[1] operatingMode ('4.12.table',masterDir,localDir) : dump; +codetable[1] operatingMode('4.12.table',masterDir,localDir) : dump; # Reflectivity calibration constant (tenths of dB) -unsigned[1] reflectivityCalibrationConstant : dump; +unsigned[1] reflectivityCalibrationConstant : dump; # Quality control indicator -codetable[1] qualityControlIndicator ('4.13.table',masterDir,localDir) : dump; +codetable[1] qualityControlIndicator('4.13.table',masterDir,localDir) : dump; # Clutter filter indicator -codetable[1] clutterFilterIndicator ('4.14.table',masterDir,localDir) : dump; +codetable[1] clutterFilterIndicator('4.14.table',masterDir,localDir) : dump; # Constant antenna elevation angle (tenths of degree true) -unsigned[1] constantAntennaElevationAngle : dump; +unsigned[1] constantAntennaElevationAngle : dump; # Accumulation interval (minutes) -unsigned[2] accumulationInterval : dump; +unsigned[2] accumulationInterval : dump; # Reference reflectivity for echo top (dB) -unsigned[1] referenceReflectivityForEchoTop : dump; +unsigned[1] referenceReflectivityForEchoTop : dump; # Range bin spacing (meters) -unsigned[3] rangeBinSpacing : dump; +unsigned[3] rangeBinSpacing : dump; # Radial angular spacing (tenths of degree true) -unsigned[2] radialAngularSpacing : dump; +unsigned[2] radialAngularSpacing : dump; diff --git a/definitions/grib2/template.4.focalStatistics.def b/definitions/grib2/template.4.focalStatistics.def index 8aa8d2a33..490919bbc 100644 --- a/definitions/grib2/template.4.focalStatistics.def +++ b/definitions/grib2/template.4.focalStatistics.def @@ -1,3 +1,4 @@ +# (C) Copyright 2005- ECMWF. codetable[1] spatialVicinityType ('4.103.table',masterDir,localDir)=255 ; unsigned[1] numberOfSpatialVicinityValues = 1 : edition_specific; diff --git a/definitions/grib2/template.4.forecast_time.def b/definitions/grib2/template.4.forecast_time.def index c12da70e3..e1c2822d9 100644 --- a/definitions/grib2/template.4.forecast_time.def +++ b/definitions/grib2/template.4.forecast_time.def @@ -9,8 +9,8 @@ unsigned[1] minutesAfterDataCutoff = missing() : edition_specific,can_be_missin alias minutesAfterReferenceTimeOfDataCutoff=minutesAfterDataCutoff; # Indicator of unit for forecastTime (ECC-1709) -codetable[1] indicatorOfUnitOfTimeRange ('4.4.table',masterDir,localDir) : dump; -alias indicatorOfUnitForForecastTime = indicatorOfUnitOfTimeRange; +codetable[1] indicatorOfUnitForForecastTime ('4.4.table',masterDir,localDir) : dump; +alias indicatorOfUnitOfTimeRange = indicatorOfUnitForForecastTime; include "grib2/stepUnits.def" diff --git a/definitions/grib2/template.4.forecast_time_44.def b/definitions/grib2/template.4.forecast_time_44.def index 0b4ad445b..30723622e 100644 --- a/definitions/grib2/template.4.forecast_time_44.def +++ b/definitions/grib2/template.4.forecast_time_44.def @@ -11,8 +11,8 @@ unsigned[1] minutesAfterDataCutoff = missing() : edition_specific,can_be_missin alias minutesAfterReferenceTimeOfDataCutoff=minutesAfterDataCutoff; # Indicator of unit for forecastTime (ECC-1709) -codetable[1] indicatorOfUnitOfTimeRange ('4.4.table',masterDir,localDir) : dump; -alias indicatorOfUnitForForecastTime = indicatorOfUnitOfTimeRange; +codetable[1] indicatorOfUnitForForecastTime ('4.4.table',masterDir,localDir) : dump; +alias indicatorOfUnitOfTimeRange = indicatorOfUnitForForecastTime; include "grib2/stepUnits.def" diff --git a/definitions/grib2/template.4.localtime.def b/definitions/grib2/template.4.localtime.def index 96d655d68..336d90068 100644 --- a/definitions/grib2/template.4.localtime.def +++ b/definitions/grib2/template.4.localtime.def @@ -34,7 +34,7 @@ localTimeForecastList list(numberOfForecastsUsedInLocalTime) unsigned[1] secondOfForecastUsedInLocalTime=0 : dump, edition_specific; # Indicator of unit of time for ForecastTime - codetable[1] indicatorOfUnitForForecastTime ('4.4.table',masterDir,localDir)=1 : dump; + codetable[1] indicatorOfUnitForForecastTime('4.4.table',masterDir,localDir)=1 : dump; # Length of the time range over which statistical processing is done, in units defined by the previous octet unsigned[4] forecastTime=0 : dump; @@ -43,7 +43,7 @@ localTimeForecastList list(numberOfForecastsUsedInLocalTime) unsigned[1] numberOfTimeIncrementsOfForecastsUsedInLocalTime=1 : dump; # Indicator of unit of time for the increment between the successive steps used - codetable[1] indicatorOfUnitForTimeIncrement ('4.4.table',masterDir,localDir)=255 : dump; + codetable[1] indicatorOfUnitForTimeIncrement('4.4.table',masterDir,localDir)=255 : dump; # Time increment between successive fields, in units defined by the previous octet unsigned[4] timeIncrement=0 : dump; diff --git a/definitions/grib2/template.4.radionuclides.def b/definitions/grib2/template.4.radionuclides.def new file mode 100644 index 000000000..c51ffa6c1 --- /dev/null +++ b/definitions/grib2/template.4.radionuclides.def @@ -0,0 +1,23 @@ +# (C) Copyright 2005- ECMWF + +codetable[2] transportModelUsed ('4.333.table',masterDir,localDir) = 255 : dump; + +codetable[2] requestedByEntity 'common/c-11.table' : dump,string_type; + +codetable[2] scenarioOrigin ('4.335.table',masterDir,localDir) = 255 : dump; + +codetable[2] NWPused ('4.336.table',masterDir,localDir) = 255 : dump; + +unsigned[2] releaseStartYear : dump; +unsigned[1] releaseStartMonth : dump; +unsigned[1] releaseStartDay : dump; +unsigned[1] releaseStartHour : dump; +unsigned[1] releaseStartMinute : dump; +unsigned[1] releaseStartSecond : dump; + +unsigned[2] wallClockInitialTimeOfExecutionYear : dump; +unsigned[1] wallClockInitialTimeOfExecutionMonth : dump; +unsigned[1] wallClockInitialTimeOfExecutionDay : dump; +unsigned[1] wallClockInitialTimeOfExecutionHour : dump; +unsigned[1] wallClockInitialTimeOfExecutionMinute : dump; +unsigned[1] wallClockInitialTimeOfExecutionSecond : dump; diff --git a/definitions/grib2/template.4.referenceperiod.def b/definitions/grib2/template.4.referenceperiod.def index 90c05351f..49a45d571 100644 --- a/definitions/grib2/template.4.referenceperiod.def +++ b/definitions/grib2/template.4.referenceperiod.def @@ -1,10 +1,11 @@ -# Type of reference dataset +# (C) Copyright 2005- ECMWF. +# Type of reference dataset codetable[1] typeOfReferenceDataset ('4.100.table',masterDir,localDir) = 255 : dump,edition_specific; -# Type of relation to reference dataset +# Type of relation to reference dataset codetable[1] typeOfRelationToReferenceDataset ('4.101.table',masterDir,localDir) = 255 : dump,edition_specific; -# number of additional parameters +# Number of additional parameters unsigned[1] numberOfAdditionalParametersForReferencePeriod=0 ; additionalParameter list(numberOfAdditionalParametersForReferencePeriod) { @@ -32,7 +33,7 @@ meta startDateOfReferencePeriod g2date(yearOfStartOfReferencePeriod,monthOfStart unsigned[4] sampleSizeOfReferencePeriod = 0; -# n - number of time range specifications describing the time intervals used to calculate the statistically-processed field +# Number of time range specifications describing the time intervals used to calculate the statistically-processed field unsigned[1] numberOfReferencePeriodTimeRanges = 1 : edition_specific; alias nref = numberOfReferencePeriodTimeRanges; diff --git a/definitions/grib2/template.4.reforecast.def b/definitions/grib2/template.4.reforecast.def index f415ce80a..a8a431936 100644 --- a/definitions/grib2/template.4.reforecast.def +++ b/definitions/grib2/template.4.reforecast.def @@ -1,3 +1,4 @@ +# (C) Copyright 2005- ECMWF. # The Model Version Date # This is the date when the reforecast is produced with a particular version of the model diff --git a/definitions/grib2/template.4.wave.def b/definitions/grib2/template.4.wave.def index 37c3f4523..742c0ece4 100644 --- a/definitions/grib2/template.4.wave.def +++ b/definitions/grib2/template.4.wave.def @@ -1,3 +1,4 @@ +# (C) Copyright 2005- ECMWF. # Template for wave parameters ## Direction part diff --git a/definitions/grib2/template.4.wave_period_range.def b/definitions/grib2/template.4.wave_period_range.def index 3bd02fa4f..278ddf689 100644 --- a/definitions/grib2/template.4.wave_period_range.def +++ b/definitions/grib2/template.4.wave_period_range.def @@ -1,3 +1,4 @@ +# (C) Copyright 2005- ECMWF. # Template for wave parameters defined on a certain period range # Type of period interval diff --git a/definitions/grib2/template.4.wave_spectra_formula.def b/definitions/grib2/template.4.wave_spectra_formula.def index a773fd48e..7127024af 100644 --- a/definitions/grib2/template.4.wave_spectra_formula.def +++ b/definitions/grib2/template.4.wave_spectra_formula.def @@ -1,3 +1,4 @@ +# (C) Copyright 2005- ECMWF. # Template for wave spectra defined using a formula for frequency and direction ## Direction part diff --git a/definitions/grib2/template.4.wave_spectra_list.def b/definitions/grib2/template.4.wave_spectra_list.def index f67175a80..64a781b95 100644 --- a/definitions/grib2/template.4.wave_spectra_list.def +++ b/definitions/grib2/template.4.wave_spectra_list.def @@ -1,3 +1,5 @@ +# (C) Copyright 2005- ECMWF. + # Template for wave spectra defined using an array of frequencies and directions ## Direction part diff --git a/definitions/grib2/units.def b/definitions/grib2/units.def index 483330827..a519d8ac5 100644 --- a/definitions/grib2/units.def +++ b/definitions/grib2/units.def @@ -200,13 +200,13 @@ parameterNumber = 54 ; } #Type of low vegetation -'(code table 4.234)' = { +'(Code table 4.234)' = { discipline = 2 ; parameterCategory = 0 ; parameterNumber = 57 ; } #Type of high vegetation -'(code table 4.234)' = { +'(Code table 4.234)' = { discipline = 2 ; parameterCategory = 0 ; parameterNumber = 58 ; @@ -232,7 +232,7 @@ typeOfFirstFixedSurface = 1 ; } #Soil type -'~' = { +'(Code table 4.213)' = { discipline = 2 ; parameterCategory = 3 ; parameterNumber = 0 ; @@ -3418,7 +3418,7 @@ parameterNumber = 45 ; } #Wetland type -'Code table 4.239' = { +'(Code table 4.239)' = { discipline = 2 ; parameterCategory = 0 ; parameterNumber = 46 ; @@ -4957,18 +4957,46 @@ parameterNumber = 18 ; typeOfStatisticalProcessing = 0 ; } -#Time-mean snow depth -'m' = { +#Time-mean wind speed +'m s**-1' = { discipline = 0 ; - parameterCategory = 1 ; - parameterNumber = 11 ; + parameterCategory = 2 ; + parameterNumber = 1 ; typeOfStatisticalProcessing = 0 ; } -#Time-mean snow cover -'%' = { +#Time-mean pressure +'Pa' = { + discipline = 0 ; + parameterCategory = 3 ; + parameterNumber = 0 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean potential vorticity +'K m**2 kg**-1 s**-1' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 14 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean specific rain water content +'kg kg**-1' = { discipline = 0 ; parameterCategory = 1 ; - parameterNumber = 42 ; + parameterNumber = 85 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean specific snow water content +'kg kg**-1' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 86 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean eta-coordinate vertical velocity +'s**-1' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 32 ; typeOfStatisticalProcessing = 0 ; } #Time-mean geopotential @@ -5039,6 +5067,13 @@ typeOfSecondFixedSurface = 8 ; typeOfStatisticalProcessing = 0 ; } +#Time-mean vorticity (relative) +'s**-1' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 12 ; + typeOfStatisticalProcessing = 0 ; + } #Time-mean mean sea level pressure 'Pa' = { discipline = 0 ; @@ -5047,6 +5082,13 @@ typeOfFirstFixedSurface = 101 ; typeOfStatisticalProcessing = 0 ; } +#Time-mean divergence +'s**-1' = { + discipline = 0 ; + parameterCategory = 2 ; + parameterNumber = 13 ; + typeOfStatisticalProcessing = 0 ; + } #Time-mean relative humidity '%' = { discipline = 0 ; @@ -5091,6 +5133,13 @@ scaleFactorOfFirstFixedSurface = 0 ; typeOfStatisticalProcessing = 0 ; } +#Time-mean ozone mass mixing ratio +'kg kg**-1' = { + discipline = 0 ; + parameterCategory = 14 ; + parameterNumber = 1 ; + typeOfStatisticalProcessing = 0 ; + } #Time-mean temperature of snow layer 'K' = { discipline = 2 ; @@ -5114,6 +5163,131 @@ typeOfFirstFixedSurface = 1 ; typeOfStatisticalProcessing = 0 ; } +#Time-mean specific cloud liquid water content +'kg kg**-1' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 83 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean specific cloud ice water content +'kg kg**-1' = { + discipline = 0 ; + parameterCategory = 1 ; + parameterNumber = 84 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean fraction of cloud cover +'(0 - 1)' = { + discipline = 0 ; + parameterCategory = 6 ; + parameterNumber = 32 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean K index +'K' = { + discipline = 0 ; + parameterCategory = 7 ; + parameterNumber = 2 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean total totals index +'K' = { + discipline = 0 ; + parameterCategory = 7 ; + parameterNumber = 4 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean clear air turbulence (CAT) +'m**2/3 s**-1' = { + discipline = 0 ; + parameterCategory = 19 ; + parameterNumber = 29 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean discharge from rivers or streams +'m**3 s**-1' = { + discipline = 1 ; + parameterCategory = 0 ; + parameterNumber = 7 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean soil wetness index (total layer) +'Numeric' = { + discipline = 2 ; + parameterCategory = 3 ; + parameterNumber = 30 ; + typeOfFirstFixedSurface = 1 ; + typeOfSecondFixedSurface = 151 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean soil wetness index (root zone) +'Numeric' = { + discipline = 2 ; + parameterCategory = 3 ; + parameterNumber = 30 ; + typeOfFirstFixedSurface = 1 ; + typeOfSecondFixedSurface = 167 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean soil wetness index(layer) +'Numeric' = { + discipline = 2 ; + parameterCategory = 3 ; + parameterNumber = 30 ; + typeOfFirstFixedSurface = 151 ; + typeOfSecondFixedSurface = 151 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean floodplain depth +'m' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 17 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean floodplain flooded fraction +'Proportion' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 18 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean floodplain flooded area +'m**2' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 19 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean river fraction +'Proportion' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 20 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean river area +'m**2' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 21 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean fraction of river coverage plus river related flooding +'Proportion' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 22 ; + typeOfStatisticalProcessing = 0 ; + } +#Time-mean area of river coverage plus river related flooding +'m**2' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 23 ; + typeOfStatisticalProcessing = 0 ; + } #Cross sectional area of flow in channel 'm**2' = { discipline = 1 ; @@ -5174,26 +5348,6 @@ parameterCategory = 0 ; parameterNumber = 15 ; } -#Mean discharge in the last 6 hours -'m**3 s**-1' = { - discipline = 1 ; - parameterCategory = 0 ; - parameterNumber = 7 ; - typeOfFirstFixedSurface = 1 ; - indicatorOfUnitForTimeRange = 1 ; - typeOfStatisticalProcessing = 0 ; - lengthOfTimeRange = 6 ; - } -#Mean discharge in the last 24 hours -'m**3 s**-1' = { - discipline = 1 ; - parameterCategory = 0 ; - parameterNumber = 7 ; - typeOfFirstFixedSurface = 1 ; - indicatorOfUnitForTimeRange = 1 ; - typeOfStatisticalProcessing = 0 ; - lengthOfTimeRange = 24 ; - } #Snow depth at elevation bands 'kg m**-2' = { discipline = 2 ; @@ -5246,6 +5400,48 @@ parameterCategory = 0 ; parameterNumber = 19 ; } +#Floodplain depth +'m' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 17 ; + } +#Floodplain flooded fraction +'Proportion' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 18 ; + } +#Floodplain flooded area +'m**2' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 19 ; + } +#River fraction +'Proportion' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 20 ; + } +#River area +'m**2' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 21 ; + } +#Fraction of river coverage plus river related flooding +'Proportion' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 22 ; + } +#Area of river coverage plus river related flooding +'m**2' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 23 ; + } #Latitude 'Degree N' = { discipline = 0 ; @@ -5419,7 +5615,7 @@ parameterNumber = 18 ; } #Precipitation type -'code table (4.201)' = { +'(Code table 4.201)' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 19 ; @@ -5487,7 +5683,7 @@ typeOfStatisticalProcessing = 1 ; } #Precipitable water category -'code table (4.202)' = { +'(Code table 4.202)' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 30 ; @@ -5904,7 +6100,7 @@ parameterNumber = 7 ; } #Cloud type -'code table (4.203)' = { +'(Code table 4.203)' = { discipline = 0 ; parameterCategory = 6 ; parameterNumber = 8 ; @@ -5916,7 +6112,7 @@ parameterNumber = 9 ; } #Thunderstorm coverage -'code table (4.204)' = { +'(Code table 4.204)' = { discipline = 0 ; parameterCategory = 6 ; parameterNumber = 10 ; @@ -6048,7 +6244,7 @@ parameterNumber = 11 ; } #Aerosol type -'code table (4.205)' = { +'(Code table 4.205)' = { discipline = 0 ; parameterCategory = 13 ; parameterNumber = 0 ; @@ -6158,7 +6354,7 @@ parameterNumber = 8 ; } #Volcanic ash -'code table (4.206)' = { +'(Code table 4.206)' = { discipline = 0 ; parameterCategory = 19 ; parameterNumber = 4 ; @@ -6176,7 +6372,7 @@ parameterNumber = 6 ; } #Icing -'code table (4.207)' = { +'(Code table 4.207)' = { discipline = 0 ; parameterCategory = 19 ; parameterNumber = 7 ; @@ -6194,7 +6390,7 @@ parameterNumber = 9 ; } #Turbulence -'code table (4.208)' = { +'(Code table 4.208)' = { discipline = 0 ; parameterCategory = 19 ; parameterNumber = 10 ; @@ -6206,19 +6402,19 @@ parameterNumber = 11 ; } #Planetary boundary layer regime -'code table (4.209)' = { +'(Code table 4.209)' = { discipline = 0 ; parameterCategory = 19 ; parameterNumber = 12 ; } #Contrail intensity -'code table (4.210)' = { +'(Code table 4.210)' = { discipline = 0 ; parameterCategory = 19 ; parameterNumber = 13 ; } #Contrail engine type -'code table (4.211)' = { +'(Code table 4.211)' = { discipline = 0 ; parameterCategory = 19 ; parameterNumber = 14 ; @@ -6296,13 +6492,13 @@ parameterNumber = 1 ; } #Remotely sensed snow cover -'(code table 4.215)' = { +'(Code table 4.215)' = { discipline = 1 ; parameterCategory = 0 ; parameterNumber = 2 ; } #Elevation of snow covered terrain -'(code table 4.216)' = { +'(Code table 4.216)' = { discipline = 1 ; parameterCategory = 0 ; parameterNumber = 3 ; @@ -6368,7 +6564,7 @@ parameterNumber = 7 ; } #Land use -'code table (4.212)' = { +'(Code table 4.212)' = { discipline = 2 ; parameterCategory = 0 ; parameterNumber = 8 ; @@ -6536,7 +6732,7 @@ parameterNumber = 2 ; } #Cloud top height quality indicator -'Code table 4.219' = { +'(Code table 4.219)' = { discipline = 3 ; parameterCategory = 1 ; parameterNumber = 3 ; @@ -6742,7 +6938,7 @@ parameterNumber = 0 ; } #Precipitation type (most severe) in the last 1 hour -'code table (4.201)' = { +'(Code table 4.201)' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 19 ; @@ -6751,7 +6947,7 @@ lengthOfTimeRange = 1 ; } #Precipitation type (most severe) in the last 3 hours -'code table (4.201)' = { +'(Code table 4.201)' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 19 ; @@ -6760,7 +6956,7 @@ lengthOfTimeRange = 3 ; } #Precipitation type (most frequent) in the last 1 hour -'code table (4.201)' = { +'(Code table 4.201)' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 19 ; @@ -6769,7 +6965,7 @@ lengthOfTimeRange = 1 ; } #Precipitation type (most frequent) in the last 3 hours -'code table (4.201)' = { +'(Code table 4.201)' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 19 ; @@ -6778,7 +6974,7 @@ lengthOfTimeRange = 3 ; } #Precipitation type (most severe) in the last 6 hours -'code table (4.201)' = { +'(Code table 4.201)' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 19 ; @@ -6787,7 +6983,7 @@ lengthOfTimeRange = 6 ; } #Precipitation type (most frequent) in the last 6 hours -'code table (4.201)' = { +'(Code table 4.201)' = { discipline = 0 ; parameterCategory = 1 ; parameterNumber = 19 ; @@ -6963,19 +7159,19 @@ parameterNumber = 6 ; } #Cloud mask -'Code table 4.217' = { +'(Code table 4.217)' = { discipline = 3 ; parameterCategory = 0 ; parameterNumber = 7 ; } #Pixel scene type -'Code table 4.218' = { +'(Code table 4.218)' = { discipline = 3 ; parameterCategory = 0 ; parameterNumber = 8 ; } #Fire detection indicator -'Code table 4.223' = { +'(Code table 4.223)' = { discipline = 3 ; parameterCategory = 0 ; parameterNumber = 9 ; @@ -7203,6 +7399,48 @@ typeOfFirstFixedSurface = 1 ; typeOfSecondFixedSurface = 8 ; } +#Standardised Precipitation Index (SPI) +'Numeric' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 0 ; + } +#Standardised Precipitation Evapotranspiration Index (SPEI) +'Numeric' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 1 ; + } +#Standardised Streamflow Index (SSFI) +'Numeric' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 2 ; + } +#Standardised Reservoir Supply Index (SRSI) +'Numeric' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 3 ; + } +#Standardised Water-level Index (SWI) +'Numeric' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 4 ; + } +#Standardised Snowmelt and Rain Index (SMRI) +'Numeric' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 5 ; + } +#Streamflow Drought Index (SDI) +'Numeric' = { + discipline = 0 ; + parameterCategory = 22 ; + parameterNumber = 6 ; + } #Universal thermal climate index 'K' = { discipline = 20 ; @@ -7340,12 +7578,6 @@ discipline = 10 ; parameterCategory = 2 ; parameterNumber = 1 ; - typeOfFirstFixedSurface = 174 ; - typeOfSecondFixedSurface = 176 ; - scaledValueOfFirstFixedSurface = missing() ; - scaleFactorOfFirstFixedSurface = missing() ; - scaledValueOfSecondFixedSurface = missing() ; - scaleFactorOfSecondFixedSurface = missing() ; } #Sea ice area fraction 'Fraction' = { @@ -8450,12 +8682,6 @@ discipline = 10 ; parameterCategory = 2 ; parameterNumber = 1 ; - typeOfFirstFixedSurface = 174 ; - typeOfSecondFixedSurface = 176 ; - scaledValueOfFirstFixedSurface = missing() ; - scaleFactorOfFirstFixedSurface = missing() ; - scaledValueOfSecondFixedSurface = missing() ; - scaleFactorOfSecondFixedSurface = missing() ; typeOfStatisticalProcessing = 0 ; } #Time-mean sea ice area fraction @@ -10047,6 +10273,44 @@ is_chemical_srcsink = 1 ; sourceSinkChemicalPhysicalProcess = 7 ; } +#Aerosol optical depth +'Numeric' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 102 ; + } +#Single scattering albedo +'(0 - 1)' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 103 ; + } +#Asymmetry Factor +'Numeric' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 104 ; + } +#Aerosol backscatter from top of atmosphere +'m**-1 sr**-1' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 107 ; + typeOfFirstFixedSurface = 8 ; + } +#Aerosol backscatter from ground +'m**-1 sr**-1' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 108 ; + typeOfFirstFixedSurface = 1 ; + } +#Aerosol extinction coefficient +'m**-1' = { + discipline = 0 ; + parameterCategory = 20 ; + parameterNumber = 105 ; + } #Pressure tendency 'Pa s**-1' = { discipline = 0 ; @@ -10575,6 +10839,12 @@ parameterCategory = 0 ; parameterNumber = 44 ; } +#Wave spectral peakedness +'dimensionless' = { + discipline = 10 ; + parameterCategory = 0 ; + parameterNumber = 98 ; + } #Skin reservoir content 'kg m**-2' = { discipline = 2 ; diff --git a/definitions/grib3/modelName.def b/definitions/grib3/modelName.def deleted file mode 100644 index 25b89c3d1..000000000 --- a/definitions/grib3/modelName.def +++ /dev/null @@ -1,43 +0,0 @@ -# modelName: Contribution from Daniel Lee @ DWD - -# COSMO -# general definition -'cosmo' = { originatingCentre=250; } -'cosmo' = { subCentre=250; } - -# definitions for ARPA-SIMC -'cosmo-i2' = { originatingCentre=200; - generatingProcessIdentifier=36; } -'cosmo-i2' = { originatingCentre=200; - generatingProcessIdentifier=139; } -'cosmo-i2' = { originatingCentre=200; - generatingProcessIdentifier=144; } -'cosmo-i2' = { originatingCentre=200; - generatingProcessIdentifier=148; } -'cosmo-i7' = { originatingCentre=200; - generatingProcessIdentifier=31; } -'cosmo-i7' = { originatingCentre=200; - generatingProcessIdentifier=32; } -'cosmo-i7' = { originatingCentre=200; - generatingProcessIdentifier=34; } -'cosmo-i7' = { originatingCentre=200; - generatingProcessIdentifier=38; } -'cosmo-i7' = { originatingCentre=200; - generatingProcessIdentifier=42; } -'cosmo-i7' = { originatingCentre=200; - generatingProcessIdentifier=46; } -'cosmo-i7' = { originatingCentre=200; - generatingProcessIdentifier=131; } -# definitions for Moscow -'cosmo_ru' = { originatingCentre=76; - generatingProcessIdentifier=135; } -'cosmo_ru-eps' = { originatingCentre=76; - generatingProcessIdentifier=235;} - -# definitions for Athens -'cosmo-greece' = { originatingCentre=96;} -# definitions for Warsaw / Poland -'cosmo-poland' = { originatingCentre=220;} -# definitions for Romania -'cosmo-romania' = { originatingCentre=242;} - diff --git a/definitions/grib3/parameters.def b/definitions/grib3/parameters.def index 907431c7b..322d0cd21 100644 --- a/definitions/grib3/parameters.def +++ b/definitions/grib3/parameters.def @@ -23,9 +23,6 @@ concept cfName (cfNameECMF,"cfName.def",conceptsMasterDir,conceptsLocalDirAll) : concept cfVarNameECMF (defaultShortName,"cfVarName.def",conceptsMasterDir,conceptsLocalDirECMF) : no_copy,dump; concept cfVarName (cfVarNameECMF,"cfVarName.def",conceptsMasterDir,conceptsLocalDirAll) : no_copy,dump; -# modelName: Contribution from Daniel Lee @ DWD -concept modelName (defaultName,"modelName.def",conceptsMasterDir,conceptsLocalDirAll): no_copy,dump,read_only; - template_nofail names "grib3/products_[productionStatusOfProcessedData].def"; meta ifsParam ifs_param(paramId,type); diff --git a/definitions/mars/grib.mmsf.an.def b/definitions/mars/grib.mmsf.an.def new file mode 100644 index 000000000..0a489319c --- /dev/null +++ b/definitions/mars/grib.mmsf.an.def @@ -0,0 +1,23 @@ +#no step in type an +unalias mars.step; + +if (class is "od") { alias mars.system = systemNumber; } +if (class is "me") { alias mars.system = systemNumber; } +if (class is "en") { alias mars.system = systemNumber; } +if (class is "c3") { alias mars.system = systemNumber; } +if (class is "ci") { alias mars.system = systemNumber; } +alias mars.number = perturbationNumber; +alias mars.method = methodNumber; + +if (!(class is "gw")) { # ECC-1448 + alias mars.origin = centre; +} + +# See ECC-624 +if (centre == 80 && subCentre == 98 && class is "c3") { + constant cnmc_cmcc = 'cmcc'; + alias mars.origin = cnmc_cmcc; +} + +if (class is "ci") { unalias mars.method; } + diff --git a/definitions/mars/grib.oper.efi.def b/definitions/mars/grib.oper.efi.def new file mode 100644 index 000000000..a4cef5d68 --- /dev/null +++ b/definitions/mars/grib.oper.efi.def @@ -0,0 +1 @@ +alias mars.step = stepRange; diff --git a/definitions/mars/grib.oper.em.def b/definitions/mars/grib.oper.em.def new file mode 100644 index 000000000..a4cef5d68 --- /dev/null +++ b/definitions/mars/grib.oper.em.def @@ -0,0 +1 @@ +alias mars.step = stepRange; diff --git a/definitions/mars/grib.oper.es.def b/definitions/mars/grib.oper.es.def new file mode 100644 index 000000000..a4cef5d68 --- /dev/null +++ b/definitions/mars/grib.oper.es.def @@ -0,0 +1 @@ +alias mars.step = stepRange; diff --git a/definitions/mars/grib.oper.pf.def b/definitions/mars/grib.oper.pf.def new file mode 100644 index 000000000..48f64b0d4 --- /dev/null +++ b/definitions/mars/grib.oper.pf.def @@ -0,0 +1,7 @@ +if (levtype is "o2d" || levtype is "o3d") { + alias mars.step = stepRange; +} else { + alias mars.step = endStep; +} + +alias mars.number = perturbationNumber; \ No newline at end of file diff --git a/examples/C/grib_pthreads.c b/examples/C/grib_pthreads.c index 2dce9a4cd..eab0a5e74 100644 --- a/examples/C/grib_pthreads.c +++ b/examples/C/grib_pthreads.c @@ -9,11 +9,22 @@ */ #include -#include "grib_api_internal.h" +#include +#include +/*#include "grib_api_internal.h"*/ #include "eccodes.h" #define NUM_THREADS 4 +void Assert(int condition) +{ + if (!condition) { + printf("Assertion failed\n"); + exit(1); + } +} + + /* Return 0 if numbers considered equal, otherwise 1 */ static int compare_doubles(double a, double b, double tolerance) { @@ -40,7 +51,7 @@ static void* process_grib(void* threadID) ProductKind prod_kind = 0; codes_handle* h = codes_grib_handle_new_from_samples(0, "regular_ll_pl_grib2"); - Assert(h); + Assert(h != NULL); CODES_CHECK(codes_get_product_kind(h, &prod_kind), 0); Assert(prod_kind == PRODUCT_GRIB); printf("Thread %ld running\n", tid); diff --git a/fortran/CMakeLists.txt b/fortran/CMakeLists.txt index 979ad0652..66b6e598f 100644 --- a/fortran/CMakeLists.txt +++ b/fortran/CMakeLists.txt @@ -42,7 +42,7 @@ if( HAVE_FORTRAN ) # Note: $ will be present only while building (for the whole bundle), # whereas $ is only present once you install the package / bundle ecbuild_add_library( TARGET eccodes_f90 - SOURCES grib_fortran.c grib_f90.f90 eccodes_f90.f90 grib_kinds.h + SOURCES grib_fortran.cc grib_f90.f90 eccodes_f90.f90 grib_kinds.h GENERATED grib_f90.f90 eccodes_f90.f90 PUBLIC_INCLUDES $ $ diff --git a/fortran/grib_fortran.c b/fortran/grib_fortran.cc similarity index 99% rename from fortran/grib_fortran.c rename to fortran/grib_fortran.cc index 3cb17739a..972118384 100644 --- a/fortran/grib_fortran.c +++ b/fortran/grib_fortran.cc @@ -9,6 +9,7 @@ */ #include "grib_api_internal.h" +#include "grib_fortran_prototypes.h" #if HAVE_SYS_TYPES_H # include @@ -986,7 +987,7 @@ void grib_f_write_on_fail(int* gid) { file_count++; GRIB_MUTEX_UNLOCK(&handle_mutex) - sprintf(filename,"%ld_%d_error.grib",(long)pid,file_count); + snprintf(filename, sizeof(filename), "%ld_%d_error.grib",(long)pid,file_count); h=get_handle(*gid); if (h) grib_write_message(h,filename,"w"); @@ -1249,7 +1250,7 @@ int grib_f_keys_iterator_get_name_(int* iterid,char* name,int len) fort_char_clean(name, len); - sprintf(buf,"%s",grib_keys_iterator_get_name(kiter)); + snprintf(buf, sizeof(buf), "%s",grib_keys_iterator_get_name(kiter)); lsize = strlen(buf); if (input_len < lsize) return GRIB_ARRAY_TOO_SMALL; @@ -1321,7 +1322,7 @@ int codes_f_bufr_keys_iterator_get_name_(int* iterid, char* name, int len) fort_char_clean(name, len); - sprintf(buf, "%s", codes_bufr_keys_iterator_get_name(kiter)); + snprintf(buf, sizeof(buf), "%s", codes_bufr_keys_iterator_get_name(kiter)); lsize = strlen(buf); if (input_len < lsize) return GRIB_ARRAY_TOO_SMALL; diff --git a/fortran/grib_fortran_prototypes.h b/fortran/grib_fortran_prototypes.h new file mode 100644 index 000000000..4eb0a313d --- /dev/null +++ b/fortran/grib_fortran_prototypes.h @@ -0,0 +1,332 @@ +/* + * Copyright 2005-2018 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. + */ + +/* grib_fortran.c */ +#ifdef __cplusplus +extern "C" { +#endif + +int grib_f_read_any_headers_only_from_file_(int *fid, char *buffer, size_t *nbytes); +int grib_f_write_file_(int* fid, void* buffer, size_t* nbytes); +int any_f_new_from_loaded_(int* msgid, int* gid); +int codes_f_bufr_copy_data_(int* gid1,int* gid2); +int grib_f_get_string_array_(int* gid, char* key, char* val,int* nvals,int* slen, int len); +int codes_f_bufr_keys_iterator_rewind_(int* kiter); +int any_f_scan_file_(int* fid, int* n); +int grib_f_new_from_message_int_(int* gid, int* buffer , size_t* bufsize); +int grib_f_copy_key_(int* gidsrc, char* key, int* giddest, int len); +int grib_f_set_samples_path_(char* path, int len); + +int grib_f_read_file(int *fid, char *buffer, size_t *nbytes); +int grib_f_open_file_(int *fid, char *name, char *op, int lname, int lop); +int grib_f_open_file__(int *fid, char *name, char *op, int lname, int lop); +int grib_f_open_file(int *fid, char *name, char *op, int lname, int lop); +int grib_f_close_file_(int *fid); +int grib_f_close_file__(int *fid); +int grib_f_close_file(int *fid); +void grib_f_write_on_fail(int *gid); +void grib_f_write_on_fail_(int* gid); +void grib_f_write_on_fail__(int* gid); +int grib_f_multi_support_on_(void); +int grib_f_multi_support_on__(void); +int grib_f_multi_support_on(void); +int grib_f_multi_support_off_(void); +int grib_f_multi_support_off__(void); +int grib_f_multi_support_off(void); +int grib_f_iterator_new_(int *gid, int *iterid, int *mode); +int grib_f_iterator_new__(int *gid, int *iterid, int *mode); +int grib_f_iterator_new(int *gid, int *iterid, int *mode); +int grib_f_iterator_next_(int *iterid, double *lat, double *lon, double *value); +int grib_f_iterator_next__(int *iterid, double *lat, double *lon, double *value); +int grib_f_iterator_next(int *iterid, double *lat, double *lon, double *value); +int grib_f_iterator_delete_(int *iterid); +int grib_f_iterator_delete__(int *iterid); +int grib_f_iterator_delete(int *iterid); +int grib_f_keys_iterator_new_(int *gid, int *iterid, char *name_space, int len); +int grib_f_keys_iterator_new__(int *gid, int *iterid, char *name_space, int len); +int grib_f_keys_iterator_new(int *gid, int *iterid, char *name_space, int len); +int grib_f_keys_iterator_next_(int *iterid); +int grib_f_keys_iterator_next__(int *iterid); +int grib_f_keys_iterator_next(int *iterid); +int grib_f_keys_iterator_delete_(int *iterid); +int grib_f_keys_iterator_delete__(int *iterid); +int grib_f_keys_iterator_delete(int *iterid); +int grib_f_gribex_mode_on_(void); +int grib_f_gribex_mode_on__(void); +int grib_f_gribex_mode_on(void); +int grib_f_gribex_mode_off_(void); +int grib_f_gribex_mode_off__(void); +int grib_f_gribex_mode_off(void); +int grib_f_skip_computed_(int *iterid); +int grib_f_skip_computed__(int *iterid); +int grib_f_skip_computed(int *iterid); +int grib_f_skip_coded_(int *iterid); +int grib_f_skip_coded__(int *iterid); +int grib_f_skip_coded(int *iterid); +int grib_f_skip_edition_specific_(int *iterid); +int grib_f_skip_edition_specific__(int *iterid); +int grib_f_skip_edition_specific(int *iterid); +int grib_f_skip_duplicates_(int *iterid); +int grib_f_skip_duplicates__(int *iterid); +int grib_f_skip_duplicates(int *iterid); +int grib_f_skip_read_only_(int *iterid); +int grib_f_skip_read_only__(int *iterid); +int grib_f_skip_read_only(int *iterid); +int grib_f_skip_function_(int *iterid); +int grib_f_skip_function__(int *iterid); +int grib_f_skip_function(int *iterid); +int grib_f_keys_iterator_get_name_(int *iterid, char *name, int len); +int grib_f_keys_iterator_get_name__(int *kiter, char *name, int len); +int grib_f_keys_iterator_get_name(int *kiter, char *name, int len); +int grib_f_keys_iterator_rewind_(int *kiter); +int grib_f_keys_iterator_rewind__(int *kiter); +int grib_f_keys_iterator_rewind(int *kiter); +int grib_f_new_from_message_(int *gid, void *buffer, size_t *bufsize); +int grib_f_new_from_message__(int *gid, void *buffer, size_t *bufsize); +int grib_f_new_from_message(int *gid, void *buffer, size_t *bufsize); +int grib_f_new_from_message_copy_(int *gid, void *buffer, size_t *bufsize); +int grib_f_new_from_message_copy__(int *gid, void *buffer, size_t *bufsize); +int grib_f_new_from_message_copy(int *gid, void *buffer, size_t *bufsize); +int grib_f_new_from_samples_(int *gid, char *name, int lname); +int grib_f_new_from_samples__(int *gid, char *name, int lname); +int grib_f_new_from_samples(int *gid, char *name, int lname); +int grib_f_new_from_template_(int *gid, char *name, int lname); +int grib_f_new_from_template__(int *gid, char *name, int lname); +int grib_f_new_from_template(int *gid, char *name, int lname); +int grib_f_clone_(int *gidsrc, int *giddest); +int grib_f_clone__(int *gidsrc, int *giddest); +int grib_f_clone(int *gidsrc, int *giddest); +int grib_f_util_sections_copy_(int *gidfrom, int *gidto, int *what, int *gidout); +int grib_f_util_sections_copy__(int *gidfrom, int *gidto, int *what, int *gidout); +int grib_f_util_sections_copy(int *gidfrom, int *gidto, int *what, int *gidout); +int grib_f_copy_namespace_(int *gidsrc, char *name, int *giddest, int len); +int grib_f_copy_namespace__(int *gidsrc, char *name, int *giddest, int len); +int grib_f_copy_namespace(int *gidsrc, char *name, int *giddest, int len); +int grib_f_count_in_file(int *fid, int *n); +int grib_f_count_in_file_(int *fid, int *n); +int grib_f_count_in_file__(int *fid, int *n); +int grib_f_new_from_file_(int *fid, int *gid); +int grib_f_new_from_file__(int *fid, int *gid); +int grib_f_new_from_file(int *fid, int *gid); +int grib_f_headers_only_new_from_file_(int *fid, int *gid); +int grib_f_headers_only_new_from_file__(int *fid, int *gid); +int grib_f_headers_only_new_from_file(int *fid, int *gid); +int grib_f_new_from_index_(int *iid, int *gid); +int grib_f_new_from_index__(int *iid, int *gid); +int grib_f_new_from_index(int *iid, int *gid); +int grib_f_index_new_from_file_(char *file, char *keys, int *gid, int lfile, int lkeys); +int grib_f_index_new_from_file__(char *file, char *keys, int *gid, int lfile, int lkeys); +int grib_f_index_new_from_file(char *file, char *keys, int *gid, int lfile, int lkeys); +int grib_f_index_add_file_(int* iid, char* file, int lfile); +int grib_f_index_add_file__(int* iid, char* file, int lfile); +int grib_f_index_add_file(int* iid, char* file, int lfile); +int grib_f_index_read_(char *file, int *gid, int lfile); +int grib_f_index_read__(char *file, int *gid, int lfile); +int grib_f_index_read(char *file, int *gid, int lfile); +int grib_f_index_write_(int *gid, char *file, int lfile); +int grib_f_index_write__(int *gid, char *file, int lfile); +int grib_f_index_write(int *gid, char *file, int lfile); +int grib_f_index_release_(int *hid); +int grib_f_index_release__(int *hid); +int grib_f_index_release(int *hid); +int grib_f_multi_handle_release_(int *hid); +int grib_f_multi_handle_release__(int *hid); +int grib_f_multi_handle_release(int *hid); +int grib_f_release_(int *hid); +int grib_f_release__(int *hid); +int grib_f_release(int *hid); +int grib_f_dump_(int *gid); +int grib_f_dump__(int *gid); +int grib_f_dump(int *gid); +int grib_f_print_(int *gid, char *key, int len); +int grib_f_print__(int *gid, char *key, int len); +int grib_f_print(int *gid, char *key, int len); +int grib_f_get_error_string_(int *err, char *buf, int len); +int grib_f_get_error_string__(int *err, char *buf, int len); +int grib_f_get_error_string(int *err, char *buf, int len); +int grib_f_get_size_int_(int *gid, char *key, int *val, int len); +int grib_f_get_size_int__(int *gid, char *key, int *val, int len); +int grib_f_get_size_int(int *gid, char *key, int *val, int len); +int grib_f_get_size_long_(int *gid, char *key, long *val, int len); +int grib_f_get_size_long__(int *gid, char *key, long *val, int len); +int grib_f_get_size_long(int *gid, char *key, long *val, int len); +int grib_f_index_get_size_int_(int *gid, char *key, int *val, int len); +int grib_f_index_get_size_int__(int *gid, char *key, int *val, int len); +int grib_f_index_get_size_int(int *gid, char *key, int *val, int len); +int grib_f_index_get_size_long_(int *gid, char *key, long *val, int len); +int grib_f_index_get_size_long__(int *gid, char *key, long *val, int len); +int grib_f_index_get_size_long(int *gid, char *key, long *val, int len); +int grib_f_get_int_(int *gid, char *key, int *val, int len); +int grib_f_get_int__(int *gid, char *key, int *val, int len); +int grib_f_get_int(int *gid, char *key, int *val, int len); +int grib_f_get_long_(int *gid, char *key, long *val, int len); +int grib_f_get_long__(int *gid, char *key, long *val, int len); +int grib_f_get_long(int *gid, char *key, long *val, int len); +int grib_f_get_int_array_(int *gid, char *key, int *val, int *size, int len); +int grib_f_get_int_array__(int *gid, char *key, int *val, int *size, int len); +int grib_f_get_int_array(int *gid, char *key, int *val, int *size, int len); +int grib_f_get_long_array_(int *gid, char *key, long *val, int *size, int len); +int grib_f_get_long_array__(int *gid, char *key, long *val, int *size, int len); +int grib_f_get_long_array(int *gid, char *key, long *val, int *size, int len); +int grib_f_get_byte_array_(int* gid, char* key, unsigned char *val, int* size, int len, int lenv); +int grib_f_get_byte_array__(int* gid, char* key, unsigned char *val, int* size, int len, int lenv); +int grib_f_get_byte_array(int* gid, char* key, unsigned char *val, int* size, int len, int lenv); +int grib_f_index_get_string_(int *gid, char *key, char *val, int *eachsize, int *size, int len); +int grib_f_index_get_string__(int *gid, char *key, char *val, int *eachsize, int *size, int len); +int grib_f_index_get_string(int *gid, char *key, char *val, int *eachsize, int *size, int len); +int grib_f_index_get_long_(int *gid, char *key, long *val, int *size, int len); +int grib_f_index_get_long__(int *gid, char *key, long *val, int *size, int len); +int grib_f_index_get_long(int *gid, char *key, long *val, int *size, int len); +int grib_f_index_get_int_(int *gid, char *key, int *val, int *size, int len); +int grib_f_index_get_int__(int *gid, char *key, int *val, int *size, int len); +int grib_f_index_get_int(int *gid, char *key, int *val, int *size, int len); +int grib_f_index_get_real8_(int *gid, char *key, double *val, int *size, int len); +int grib_f_index_get_real8__(int *gid, char *key, double *val, int *size, int len); +int grib_f_index_get_real8(int *gid, char *key, double *val, int *size, int len); +int grib_f_set_int_array_(int *gid, char *key, int *val, int *size, int len); +int grib_f_set_int_array__(int *gid, char *key, int *val, int *size, int len); +int grib_f_set_int_array(int *gid, char *key, int *val, int *size, int len); +int grib_f_set_long_array_(int *gid, char *key, long *val, int *size, int len); +int grib_f_set_long_array__(int *gid, char *key, long *val, int *size, int len); +int grib_f_set_long_array(int *gid, char *key, long *val, int *size, int len); +int grib_f_set_byte_array_(int* gid, char* key, unsigned char *val, int* size, int len, int lenv); +int grib_f_set_byte_array__(int* gid, char* key, unsigned char *val, int* size, int len, int lenv); +int grib_f_set_byte_array(int* gid, char* key, unsigned char *val, int* size, int len, int lenv); +int grib_f_set_int_(int *gid, char *key, int *val, int len); +int grib_f_set_int__(int *gid, char *key, int *val, int len); +int grib_f_set_int(int *gid, char *key, int *val, int len); +int grib_f_set_long_(int *gid, char *key, long *val, int len); +int grib_f_set_long__(int *gid, char *key, long *val, int len); +int grib_f_set_long(int *gid, char *key, long *val, int len); +int grib_f_set_missing_(int *gid, char *key, int len); +int grib_f_set_missing__(int *gid, char *key, int len); +int grib_f_set_missing(int *gid, char *key, int len); +int grib_f_is_missing_(int *gid, char *key, int *isMissing, int len); +int grib_f_is_defined_(int *gid, char *key, int *isDefined, int len); +int grib_f_is_missing__(int *gid, char *key, int *isMissing, int len); +int grib_f_is_missing(int *gid, char *key, int *isMissing, int len); +int grib_f_set_real4_(int *gid, char *key, float *val, int len); +int grib_f_set_real4__(int *gid, char *key, float *val, int len); +int grib_f_set_real4(int *gid, char *key, float *val, int len); +int grib_f_get_real4_element_(int *gid, char *key, int *index, float *val, int len); +int grib_f_get_real4_element__(int *gid, char *key, int *index, float *val, int len); +int grib_f_get_real4_element(int *gid, char *key, int *index, float *val, int len); +int grib_f_get_real4_elements_(int *gid, char *key, int *index, float *val, int *size, int len); +int grib_f_get_real4_elements__(int *gid, char *key, int *index, float *val, int *len, int size); +int grib_f_get_real4_elements(int *gid, char *key, int *index, float *val, int *len, int size); +int grib_f_get_real4_(int *gid, char *key, float *val, int len); +int grib_f_get_real4__(int *gid, char *key, float *val, int len); +int grib_f_get_real4(int *gid, char *key, float *val, int len); +int grib_f_get_real4_array_(int *gid, char *key, float *val, int *size, int len); +int grib_f_get_real4_array__(int *gid, char *key, float *val, int *size, int len); +int grib_f_get_real4_array(int *gid, char *key, float *val, int *size, int len); +int grib_f_set_real4_array_(int *gid, char *key, float *val, int *size, int len); +int grib_f_set_real4_array__(int *gid, char *key, float *val, int *size, int len); +int grib_f_set_real4_array(int *gid, char *key, float *val, int *size, int len); +int grib_f_set_force_real4_array_(int *gid, char *key, float *val, int *size, int len); +int grib_f_set_force_real4_array__(int *gid, char *key, float *val, int *size, int len); +int grib_f_set_force_real4_array(int *gid, char *key, float *val, int *size, int len); +int grib_f_index_select_real8_(int *gid, char *key, double *val, int len); +int grib_f_index_select_real8__(int *gid, char *key, double *val, int len); +int grib_f_index_select_real8(int *gid, char *key, double *val, int len); +int grib_f_index_select_string_(int *gid, char *key, char *val, int len, int vallen); +int grib_f_index_select_string__(int *gid, char *key, char *val, int len, int vallen); +int grib_f_index_select_string(int *gid, char *key, char *val, int len, int vallen); +int grib_f_index_select_int_(int *gid, char *key, int *val, int len); +int grib_f_index_select_int__(int *gid, char *key, int *val, int len); +int grib_f_index_select_int(int *gid, char *key, int *val, int len); +int grib_f_index_select_long_(int *gid, char *key, long *val, int len); +int grib_f_index_select_long__(int *gid, char *key, long *val, int len); +int grib_f_index_select_long(int *gid, char *key, long *val, int len); +int grib_f_set_real8_(int *gid, char *key, double *val, int len); +int grib_f_set_real8__(int *gid, char *key, double *val, int len); +int grib_f_set_real8(int *gid, char *key, double *val, int len); +int grib_f_get_real8_(int *gid, char *key, double *val, int len); +int grib_f_get_real8__(int *gid, char *key, double *val, int len); +int grib_f_get_real8(int *gid, char *key, double *val, int len); +int grib_f_get_real8_element_(int *gid, char *key, int *index, double *val, int len); +int grib_f_get_real8_element__(int *gid, char *key, int *index, double *val, int len); +int grib_f_get_real8_element(int *gid, char *key, int *index, double *val, int len); +int grib_f_get_real8_elements_(int *gid, char *key, int *index, double *val, int *size, int len); +int grib_f_get_real8_elements__(int *gid, char *key, int *index, double *val, int *len, int size); +int grib_f_get_real8_elements(int *gid, char *key, int *index, double *val, int *len, int size); +int grib_f_find_nearest_four_single_(int *gid, int *is_lsm, double *inlat, double *inlon, double *outlats, double *outlons, double *values, double *distances, int *indexes); +int grib_f_find_nearest_four_single__(int *gid, int *is_lsm, double *inlats, double *inlons, double *outlats, double *outlons, double *values, double *distances, int *indexes); +int grib_f_find_nearest_four_single(int *gid, int *is_lsm, double *inlats, double *inlons, double *outlats, double *outlons, double *values, double *distances, int *indexes); +int grib_f_find_nearest_single_(int *gid, int *is_lsm, double *inlats, double *inlons, double *outlats, double *outlons, double *values, double *distances, int *indexes); +int grib_f_find_nearest_single__(int *gid, int *is_lsm, double *inlats, double *inlons, double *outlats, double *outlons, double *values, double *distances, int *indexes); +int grib_f_find_nearest_single(int *gid, int *is_lsm, double *inlats, double *inlons, double *outlats, double *outlons, double *values, double *distances, int *indexes); +int grib_f_find_nearest_multiple_(int *gid, int *is_lsm, double *inlats, double *inlons, double *outlats, double *outlons, double *values, double *distances, int *indexes, int *npoints); +int grib_f_find_nearest_multiple__(int *gid, int *is_lsm, double *inlats, double *inlons, double *outlats, double *outlons, double *values, double *distances, int *indexes, int *npoints); +int grib_f_find_nearest_multiple(int *gid, int *is_lsm, double *inlats, double *inlons, double *outlats, double *outlons, double *values, double *distances, int *indexes, int *npoints); +int grib_f_get_real8_array_(int *gid, char *key, double *val, int *size, int len); +int grib_f_get_real8_array__(int *gid, char *key, double *val, int *size, int len); +int grib_f_get_real8_array(int *gid, char *key, double *val, int *size, int len); +int grib_f_set_real8_array_(int *gid, char *key, double *val, int *size, int len); +int grib_f_set_real8_array__(int *gid, char *key, double *val, int *size, int len); +int grib_f_set_real8_array(int *gid, char *key, double *val, int *size, int len); +int grib_f_set_force_real8_array_(int *gid, char *key, double *val, int *size, int len); +int grib_f_set_force_real8_array__(int *gid, char *key, double *val, int *size, int len); +int grib_f_set_force_real8_array(int *gid, char *key, double *val, int *size, int len); +int grib_f_get_string_(int *gid, char *key, char *val, int len, int len2); +int grib_f_get_string__(int *gid, char *key, char *val, int len, int len2); +int grib_f_get_string(int *gid, char *key, char *val, int len, int len2); +int grib_f_set_string_(int *gid, char *key, char *val, int len, int len2); +int grib_f_set_string__(int *gid, char *key, char *val, int len, int len2); +int grib_f_set_string(int *gid, char *key, char *val, int len, int len2); +int grib_f_get_data_real4_(int *gid, float *lats, float *lons, float *values, size_t *size); +int grib_f_get_data_real4__(int *gid, float *lats, float *lons, float *values, size_t *size); +int grib_f_get_data_real4(int *gid, float *lats, float *lons, float *values, size_t *size); +int grib_f_get_data_real8_(int *gid, double *lats, double *lons, double *values, size_t *size); +int grib_f_get_data_real8__(int *gid, double *lats, double *lons, double *values, size_t *size); +int grib_f_get_data_real8(int *gid, double *lats, double *lons, double *values, size_t *size); +int grib_f_get_message_size_(int *gid, size_t *len); +int grib_f_get_message_size__(int *gid, size_t *len); +int grib_f_get_message_size(int *gid, size_t *len); +int grib_f_copy_message_(int *gid, void *mess, size_t *len); +int grib_f_copy_message__(int *gid, void *mess, size_t *len); +int grib_f_copy_message(int *gid, void *mess, size_t *len); +void grib_f_check_(int *err, char *call, char *str, int lencall, int lenstr); +void grib_f_check__(int *err, char *call, char *key, int lencall, int lenkey); +void grib_f_check(int *err, char *call, char *key, int lencall, int lenkey); +int grib_f_write_(int *gid, int *fid); +int grib_f_write__(int *gid, int *fid); +int grib_f_write(int *gid, int *fid); +int grib_f_multi_write_(int *gid, int *fid); +int grib_f_multi_write__(int *gid, int *fid); +int grib_f_multi_write(int *gid, int *fid); +int grib_f_multi_append_(int *ingid, int *sec, int *mgid); +int grib_f_multi_append(int *ingid, int *sec, int *mgid); +int grib_f_multi_append__(int *ingid, int *sec, int *mgid); + +int codes_f_bufr_keys_iterator_new_(int* gid,int* iterid); +int grib_f_read_file_(int* fid, void* buffer, size_t* nbytes); +int codes_f_bufr_keys_iterator_delete_(int* iterid); +int grib_f_set_definitions_path_(char* path, int len); +int grib_f_read_any_from_file_(int* fid, void* buffer, size_t* nbytes); +int any_f_new_from_file_(int* fid, int* gid); +int grib_f_get_native_type_(int* gid, char* key, int* val, int len); +int grib_f_get_api_version_(int* apiVersion,int len); +int codes_bufr_f_new_from_samples_(int* gid, char* name, int lname); +int any_f_load_all_from_file_(int* fid, int* n); +int codes_f_bufr_multi_element_constant_arrays_on_(); +int bufr_f_new_from_file_(int* fid, int* gid); +int grib_f_julian_to_datetime_(double* jd,long* year,long* month,long* day,long *hour,long *minute,long *second); +int any_f_new_from_scanned_file_(int* fid, int* msgid, int* gid); +int codes_f_bufr_keys_iterator_next_(int* iterid); +int grib_f_datetime_to_julian_(long* year,long* month,long* day, long* hour,long* minute,long* second,double* jd); +int grib_f_set_string_array_(int* gid, char* key, char* val,int* nvals,int* slen, int len); +int codes_f_bufr_keys_iterator_get_name_(int* iterid, char* name, int len); +int codes_f_bufr_multi_element_constant_arrays_off_(); + + +#ifdef __cplusplus +} +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 97cd81dfc..fce6d88d8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,6 +9,10 @@ # nor does it submit to any jurisdiction. # list( APPEND eccodes_src_files + accessor/grib_accessor.cc + accessor/grib_accessors_list.cc + grib_accessor_class.cc + shared_functions.cc step_unit.cc step.cc step_utilities.cc @@ -20,9 +24,9 @@ list( APPEND eccodes_src_files action_class_gen.cc action_class_if.cc action_class_switch.cc - grib_accessor_class_g1fcperiod.cc - grib_accessor_class_g1end_of_interval_monthly.cc - grib_accessor_class_mars_param.cc + accessor/grib_accessor_class_g1fcperiod.cc + accessor/grib_accessor_class_g1end_of_interval_monthly.cc + accessor/grib_accessor_class_mars_param.cc action_class_section.cc action_class_list.cc action_class_while.cc @@ -47,7 +51,6 @@ list( APPEND eccodes_src_files action_class_modify.cc action_class_transient_darray.cc eccodes.cc - grib_accessor.cc grib_concept.cc grib_hash_array.cc grib_bufr_descriptor.cc @@ -60,208 +63,207 @@ list( APPEND eccodes_src_files grib_iarray.cc grib_viarray.cc codes_memfs.cc - grib_accessor_class_ascii.cc - grib_accessor_class_bit.cc - grib_accessor_class_bitmap.cc - grib_accessor_class_bits.cc - grib_accessor_class_bits_per_value.cc - grib_accessor_class_bufr_elements_table.cc - grib_accessor_class_bufr_data_array.cc - grib_accessor_class_bufr_data_element.cc - grib_accessor_class_bufr_group.cc - grib_accessor_class_bufr_string_values.cc - grib_accessor_class_pack_bufr_values.cc - grib_accessor_class_unpack_bufr_values.cc - grib_accessor_class_group.cc - grib_accessor_class_non_alpha.cc - grib_accessor_class_g1bitmap.cc - grib_accessor_class_g2bitmap.cc - grib_accessor_class_concept.cc - grib_accessor_class_hash_array.cc - grib_accessor_class_decimal_precision.cc - grib_accessor_class_divdouble.cc - grib_accessor_class_multdouble.cc - grib_accessor_class_budgdate.cc - grib_accessor_class_validity_date.cc - grib_accessor_class_validity_time.cc - grib_accessor_class_bytes.cc - grib_accessor_class.cc - grib_accessor_class_change_alternative_row_scanning.cc - grib_accessor_class_change_scanning_direction.cc - grib_accessor_class_check_internal_version.cc - grib_accessor_class_codeflag.cc - grib_accessor_class_smart_table.cc - grib_accessor_class_smart_table_column.cc - grib_accessor_class_codetable.cc - grib_accessor_class_codetable_units.cc - grib_accessor_class_codetable_title.cc - grib_accessor_class_step_human_readable.cc - grib_accessor_class_count_file.cc - grib_accessor_class_count_total.cc - grib_accessor_class_double.cc - grib_accessor_class_element.cc - grib_accessor_class_evaluate.cc - grib_accessor_class_g1date.cc - grib_accessor_class_g1monthlydate.cc - grib_accessor_class_library_version.cc - grib_accessor_class_when.cc - grib_accessor_class_g1verificationdate.cc - grib_accessor_class_g1day_of_the_year_date.cc - grib_accessor_class_g1_half_byte_codeflag.cc - grib_accessor_class_g1forecastmonth.cc - grib_accessor_class_g1step_range.cc - grib_accessor_class_g2step_range.cc - grib_accessor_class_data_g22order_packing.cc - grib_accessor_class_mars_step.cc - grib_accessor_class_message_copy.cc - grib_accessor_class_dictionary.cc - grib_accessor_class_latlon_increment.cc - grib_accessor_class_g2date.cc - grib_accessor_class_g2level.cc - grib_accessor_class_g2end_step.cc - grib_accessor_class_g2latlon.cc - grib_accessor_class_g2lon.cc - grib_accessor_class_global_gaussian.cc - grib_accessor_class_gaussian_grid_name.cc - grib_accessor_class_gen.cc - grib_accessor_class_getenv.cc - grib_accessor_class_gts_header.cc - grib_accessor_class_ifs_param.cc - grib_accessor_class_julian_day.cc - grib_accessor_class_julian_date.cc - grib_accessor_class_closest_date.cc - grib_accessor_class_latlonvalues.cc - grib_accessor_class_latitudes.cc - grib_accessor_class_longitudes.cc - grib_accessor_class_offset_file.cc - grib_accessor_class_scale.cc - grib_accessor_class_from_scale_factor_scaled_value.cc - grib_accessor_class_g2bitmap_present.cc - grib_accessor_class_ibmfloat.cc - grib_accessor_class_ieeefloat.cc - grib_accessor_class_constant.cc - grib_accessor_class_iterator.cc - grib_accessor_class_message.cc - grib_accessor_class_nearest.cc - grib_accessor_class_ksec1expver.cc - grib_accessor_class_label.cc - grib_accessor_class_long.cc - grib_accessor_class_lookup.cc - grib_accessor_class_octahedral_gaussian.cc - grib_accessor_class_octet_number.cc - grib_accessor_class_headers_only.cc - grib_accessor_class_padding.cc - grib_accessor_class_pad.cc - grib_accessor_class_padto.cc - grib_accessor_class_padtoeven.cc - grib_accessor_class_padtomultiple.cc - grib_accessor_class_section_padding.cc - grib_accessor_class_packing_type.cc - grib_accessor_class_section_pointer.cc - grib_accessor_class_position.cc - grib_accessor_class_signed.cc - grib_accessor_class_signed_bits.cc - grib_accessor_class_section.cc - grib_accessor_class_step_in_units.cc - grib_accessor_class_optimal_step_units.cc - grib_accessor_class_section_length.cc - grib_accessor_class_g1_message_length.cc - grib_accessor_class_g1_section4_length.cc - grib_accessor_class_size.cc - grib_accessor_class_rdbtime_guess_date.cc - grib_accessor_class_scale_values.cc - grib_accessor_class_offset_values.cc - grib_accessor_class_sprintf.cc - grib_accessor_class_round.cc - grib_accessor_class_spectral_truncation.cc - grib_accessor_class_time.cc - grib_accessor_class_transient.cc - grib_accessor_class_trim.cc - grib_accessor_class_transient_darray.cc - grib_accessor_class_values.cc - grib_accessor_class_simple_packing_error.cc - grib_accessor_class_data_simple_packing.cc - grib_accessor_class_count_missing.cc - grib_accessor_class_data_sh_packed.cc - grib_accessor_class_data_sh_unpacked.cc - grib_accessor_class_number_of_values_data_raw_packing.cc - grib_accessor_class_data_g1simple_packing.cc - grib_accessor_class_data_g1shsimple_packing.cc - grib_accessor_class_data_shsimple_packing.cc - grib_accessor_class_data_dummy_field.cc - grib_accessor_class_variable.cc - grib_accessor_class_second_order_bits_per_value.cc - grib_accessor_class_data_g2simple_packing.cc - grib_accessor_class_data_g2simple_packing_with_preprocessing.cc - grib_accessor_class_data_g2shsimple_packing.cc - grib_accessor_class_data_g2complex_packing.cc - grib_accessor_class_data_g1second_order_row_by_row_packing.cc - grib_accessor_class_data_g1second_order_constant_width_packing.cc - grib_accessor_class_data_g1second_order_general_packing.cc - grib_accessor_class_data_g1second_order_general_extended_packing.cc - grib_accessor_class_g2grid.cc - grib_accessor_class_unexpanded_descriptors.cc - grib_accessor_class_expanded_descriptors.cc - grib_accessor_class_bufrdc_expanded_descriptors.cc - grib_accessor_class_data_apply_bitmap.cc - grib_accessor_class_data_apply_boustrophedonic.cc - grib_accessor_class_data_apply_boustrophedonic_bitmap.cc - grib_accessor_class_data_secondary_bitmap.cc - grib_accessor_class_data_g1secondary_bitmap.cc - grib_accessor_class_data_g2secondary_bitmap.cc - grib_accessor_class_data_jpeg2000_packing.cc - grib_accessor_class_data_png_packing.cc - grib_accessor_class_data_ccsds_packing.cc - grib_accessor_class_data_raw_packing.cc - grib_accessor_class_data_complex_packing.cc - grib_accessor_class_data_g1complex_packing.cc - grib_accessor_class_gds_not_present_bitmap.cc - grib_accessor_class_gds_is_present.cc - grib_accessor_class_select_step_template.cc - grib_accessor_class_local_definition.cc - grib_accessor_class_g2_eps.cc - grib_accessor_class_g2_aerosol.cc - grib_accessor_class_g2_chemical.cc - grib_accessor_class_g2_mars_labeling.cc - grib_accessor_class_md5.cc - grib_accessor_class_proj_string.cc + accessor/grib_accessor_class_gen.cc + accessor/grib_accessor_class_ascii.cc + accessor/grib_accessor_class_bit.cc + accessor/grib_accessor_class_bitmap.cc + accessor/grib_accessor_class_bits.cc + accessor/grib_accessor_class_bits_per_value.cc + accessor/grib_accessor_class_bufr_elements_table.cc + accessor/grib_accessor_class_bufr_data_array.cc + accessor/grib_accessor_class_bufr_data_element.cc + accessor/grib_accessor_class_bufr_group.cc + accessor/grib_accessor_class_bufr_string_values.cc + accessor/grib_accessor_class_pack_bufr_values.cc + accessor/grib_accessor_class_unpack_bufr_values.cc + accessor/grib_accessor_class_group.cc + accessor/grib_accessor_class_non_alpha.cc + accessor/grib_accessor_class_g1bitmap.cc + accessor/grib_accessor_class_g2bitmap.cc + accessor/grib_accessor_class_concept.cc + accessor/grib_accessor_class_hash_array.cc + accessor/grib_accessor_class_decimal_precision.cc + accessor/grib_accessor_class_divdouble.cc + accessor/grib_accessor_class_multdouble.cc + accessor/grib_accessor_class_budgdate.cc + accessor/grib_accessor_class_validity_date.cc + accessor/grib_accessor_class_validity_time.cc + accessor/grib_accessor_class_bytes.cc + accessor/grib_accessor_class_change_alternative_row_scanning.cc + accessor/grib_accessor_class_change_scanning_direction.cc + accessor/grib_accessor_class_check_internal_version.cc + accessor/grib_accessor_class_codeflag.cc + accessor/grib_accessor_class_smart_table.cc + accessor/grib_accessor_class_smart_table_column.cc + accessor/grib_accessor_class_codetable.cc + accessor/grib_accessor_class_codetable_units.cc + accessor/grib_accessor_class_codetable_title.cc + accessor/grib_accessor_class_step_human_readable.cc + accessor/grib_accessor_class_count_file.cc + accessor/grib_accessor_class_count_total.cc + accessor/grib_accessor_class_double.cc + accessor/grib_accessor_class_element.cc + accessor/grib_accessor_class_evaluate.cc + accessor/grib_accessor_class_g1date.cc + accessor/grib_accessor_class_g1monthlydate.cc + accessor/grib_accessor_class_library_version.cc + accessor/grib_accessor_class_when.cc + accessor/grib_accessor_class_g1verificationdate.cc + accessor/grib_accessor_class_g1day_of_the_year_date.cc + accessor/grib_accessor_class_g1_half_byte_codeflag.cc + accessor/grib_accessor_class_g1forecastmonth.cc + accessor/grib_accessor_class_g1step_range.cc + accessor/grib_accessor_class_g2step_range.cc + accessor/grib_accessor_class_data_g22order_packing.cc + accessor/grib_accessor_class_mars_step.cc + accessor/grib_accessor_class_message_copy.cc + accessor/grib_accessor_class_dictionary.cc + accessor/grib_accessor_class_latlon_increment.cc + accessor/grib_accessor_class_g2date.cc + accessor/grib_accessor_class_g2level.cc + accessor/grib_accessor_class_g2end_step.cc + accessor/grib_accessor_class_g2latlon.cc + accessor/grib_accessor_class_g2lon.cc + accessor/grib_accessor_class_global_gaussian.cc + accessor/grib_accessor_class_gaussian_grid_name.cc + accessor/grib_accessor_class_getenv.cc + accessor/grib_accessor_class_gts_header.cc + accessor/grib_accessor_class_ifs_param.cc + accessor/grib_accessor_class_julian_day.cc + accessor/grib_accessor_class_julian_date.cc + accessor/grib_accessor_class_closest_date.cc + accessor/grib_accessor_class_latlonvalues.cc + accessor/grib_accessor_class_latitudes.cc + accessor/grib_accessor_class_longitudes.cc + accessor/grib_accessor_class_offset_file.cc + accessor/grib_accessor_class_scale.cc + accessor/grib_accessor_class_from_scale_factor_scaled_value.cc + accessor/grib_accessor_class_g2bitmap_present.cc + accessor/grib_accessor_class_ibmfloat.cc + accessor/grib_accessor_class_ieeefloat.cc + accessor/grib_accessor_class_constant.cc + accessor/grib_accessor_class_iterator.cc + accessor/grib_accessor_class_message.cc + accessor/grib_accessor_class_nearest.cc + accessor/grib_accessor_class_ksec1expver.cc + accessor/grib_accessor_class_label.cc + accessor/grib_accessor_class_long.cc + accessor/grib_accessor_class_lookup.cc + accessor/grib_accessor_class_octahedral_gaussian.cc + accessor/grib_accessor_class_octet_number.cc + accessor/grib_accessor_class_headers_only.cc + accessor/grib_accessor_class_padding.cc + accessor/grib_accessor_class_pad.cc + accessor/grib_accessor_class_padto.cc + accessor/grib_accessor_class_padtoeven.cc + accessor/grib_accessor_class_padtomultiple.cc + accessor/grib_accessor_class_section_padding.cc + accessor/grib_accessor_class_packing_type.cc + accessor/grib_accessor_class_section_pointer.cc + accessor/grib_accessor_class_position.cc + accessor/grib_accessor_class_signed.cc + accessor/grib_accessor_class_signed_bits.cc + accessor/grib_accessor_class_section.cc + accessor/grib_accessor_class_step_in_units.cc + accessor/grib_accessor_class_optimal_step_units.cc + accessor/grib_accessor_class_section_length.cc + accessor/grib_accessor_class_g1_message_length.cc + accessor/grib_accessor_class_g1_section4_length.cc + accessor/grib_accessor_class_size.cc + accessor/grib_accessor_class_rdbtime_guess_date.cc + accessor/grib_accessor_class_scale_values.cc + accessor/grib_accessor_class_offset_values.cc + accessor/grib_accessor_class_sprintf.cc + accessor/grib_accessor_class_round.cc + accessor/grib_accessor_class_spectral_truncation.cc + accessor/grib_accessor_class_time.cc + accessor/grib_accessor_class_transient.cc + accessor/grib_accessor_class_trim.cc + accessor/grib_accessor_class_transient_darray.cc + accessor/grib_accessor_class_values.cc + accessor/grib_accessor_class_simple_packing_error.cc + accessor/grib_accessor_class_data_simple_packing.cc + accessor/grib_accessor_class_count_missing.cc + accessor/grib_accessor_class_data_sh_packed.cc + accessor/grib_accessor_class_data_sh_unpacked.cc + accessor/grib_accessor_class_number_of_values_data_raw_packing.cc + accessor/grib_accessor_class_data_g1simple_packing.cc + accessor/grib_accessor_class_data_g1shsimple_packing.cc + accessor/grib_accessor_class_data_shsimple_packing.cc + accessor/grib_accessor_class_data_dummy_field.cc + accessor/grib_accessor_class_variable.cc + accessor/grib_accessor_class_second_order_bits_per_value.cc + accessor/grib_accessor_class_data_g2simple_packing.cc + accessor/grib_accessor_class_data_g2simple_packing_with_preprocessing.cc + accessor/grib_accessor_class_data_g2shsimple_packing.cc + accessor/grib_accessor_class_data_g2complex_packing.cc + accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.cc + accessor/grib_accessor_class_data_g1second_order_constant_width_packing.cc + accessor/grib_accessor_class_data_g1second_order_general_packing.cc + accessor/grib_accessor_class_data_g1second_order_general_extended_packing.cc + accessor/grib_accessor_class_g2grid.cc + accessor/grib_accessor_class_unexpanded_descriptors.cc + accessor/grib_accessor_class_expanded_descriptors.cc + accessor/grib_accessor_class_bufrdc_expanded_descriptors.cc + accessor/grib_accessor_class_data_apply_bitmap.cc + accessor/grib_accessor_class_data_apply_boustrophedonic.cc + accessor/grib_accessor_class_data_apply_boustrophedonic_bitmap.cc + accessor/grib_accessor_class_data_secondary_bitmap.cc + accessor/grib_accessor_class_data_g1secondary_bitmap.cc + accessor/grib_accessor_class_data_g2secondary_bitmap.cc + accessor/grib_accessor_class_data_jpeg2000_packing.cc + accessor/grib_accessor_class_data_png_packing.cc + accessor/grib_accessor_class_data_ccsds_packing.cc + accessor/grib_accessor_class_data_raw_packing.cc + accessor/grib_accessor_class_data_complex_packing.cc + accessor/grib_accessor_class_data_g1complex_packing.cc + accessor/grib_accessor_class_gds_not_present_bitmap.cc + accessor/grib_accessor_class_gds_is_present.cc + accessor/grib_accessor_class_select_step_template.cc + accessor/grib_accessor_class_local_definition.cc + accessor/grib_accessor_class_g2_eps.cc + accessor/grib_accessor_class_g2_aerosol.cc + accessor/grib_accessor_class_g2_chemical.cc + accessor/grib_accessor_class_g2_mars_labeling.cc + accessor/grib_accessor_class_md5.cc + accessor/grib_accessor_class_proj_string.cc grib_jasper_encoding.cc grib_openjpeg_encoding.cc action_class_set_missing.cc - grib_accessor_class_number_of_points.cc - grib_accessor_class_suppressed.cc + accessor/grib_accessor_class_number_of_points.cc + accessor/grib_accessor_class_suppressed.cc grib_index.cc - grib_accessor_class_number_of_points_gaussian.cc - grib_accessor_class_number_of_values.cc - grib_accessor_class_number_of_coded_values.cc - grib_accessor_class_g1number_of_coded_values_sh_complex.cc - grib_accessor_class_g1number_of_coded_values_sh_simple.cc - grib_accessor_class_dirty.cc - grib_accessor_class_statistics.cc - grib_accessor_class_statistics_spectral.cc - grib_accessor_class_unsigned.cc - grib_accessor_class_unsigned_bits.cc - grib_accessor_class_raw.cc - grib_accessor_class_bufr_simple_thinning.cc - grib_accessor_class_bufr_extract_subsets.cc - grib_accessor_class_bufr_extract_area_subsets.cc - grib_accessor_class_bufr_extract_datetime_subsets.cc - grib_accessor_class_spd.cc - grib_accessor_class_sum.cc - grib_accessor_class_to_integer.cc - grib_accessor_class_to_double.cc - grib_accessor_class_to_string.cc - grib_accessor_class_sexagesimal2decimal.cc - grib_accessor_class_vector.cc - grib_accessor_class_long_vector.cc + accessor/grib_accessor_class_number_of_points_gaussian.cc + accessor/grib_accessor_class_number_of_values.cc + accessor/grib_accessor_class_number_of_coded_values.cc + accessor/grib_accessor_class_g1number_of_coded_values_sh_complex.cc + accessor/grib_accessor_class_g1number_of_coded_values_sh_simple.cc + accessor/grib_accessor_class_dirty.cc + accessor/grib_accessor_class_statistics.cc + accessor/grib_accessor_class_statistics_spectral.cc + accessor/grib_accessor_class_unsigned.cc + accessor/grib_accessor_class_unsigned_bits.cc + accessor/grib_accessor_class_raw.cc + accessor/grib_accessor_class_bufr_simple_thinning.cc + accessor/grib_accessor_class_bufr_extract_subsets.cc + accessor/grib_accessor_class_bufr_extract_area_subsets.cc + accessor/grib_accessor_class_bufr_extract_datetime_subsets.cc + accessor/grib_accessor_class_spd.cc + accessor/grib_accessor_class_sum.cc + accessor/grib_accessor_class_to_integer.cc + accessor/grib_accessor_class_to_double.cc + accessor/grib_accessor_class_to_string.cc + accessor/grib_accessor_class_sexagesimal2decimal.cc + accessor/grib_accessor_class_vector.cc + accessor/grib_accessor_class_long_vector.cc grib_gaussian_reduced.cc - grib_accessor_class_abstract_vector.cc - grib_accessor_class_abstract_long_vector.cc + accessor/grib_accessor_class_abstract_vector.cc + accessor/grib_accessor_class_abstract_long_vector.cc grib_loader_from_handle.cc grib_bits.cc grib_ibmfloat.cc grib_ieeefloat.cc - grib_accessor_class_reference_value_error.cc + accessor/grib_accessor_class_reference_value_error.cc grib_memory.cc grib_buffer.cc grib_dumper.cc @@ -364,16 +366,16 @@ list( APPEND eccodes_src_files grib_yacc.h md5.h md5.cc - grib_accessor_class_uint16.cc - grib_accessor_class_uint32.cc - grib_accessor_class_uint32_little_endian.cc - grib_accessor_class_uint64.cc - grib_accessor_class_uint64_little_endian.cc - grib_accessor_class_uint8.cc - grib_accessor_class_blob.cc + accessor/grib_accessor_class_uint16.cc + accessor/grib_accessor_class_uint32.cc + accessor/grib_accessor_class_uint32_little_endian.cc + accessor/grib_accessor_class_uint64.cc + accessor/grib_accessor_class_uint64_little_endian.cc + accessor/grib_accessor_class_uint8.cc + accessor/grib_accessor_class_blob.cc grib_optimize_decimal_factor.cc - grib_accessor_class_data_g2bifourier_packing.cc - grib_accessor_class_data_run_length_packing.cc + accessor/grib_accessor_class_data_g2bifourier_packing.cc + accessor/grib_accessor_class_data_run_length_packing.cc eccodes_windef.h # We ship our own generated lex/yacc C files grib_yacc.cc grib_lex.cc ) diff --git a/src/accessor/grib_accessor.cc b/src/accessor/grib_accessor.cc new file mode 100644 index 000000000..23c52c888 --- /dev/null +++ b/src/accessor/grib_accessor.cc @@ -0,0 +1,135 @@ +/* + * (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. + */ + +/*************************************************************************** + * Jean Baptiste Filippi - 01.11.2005 + ***************************************************************************/ + +#include "grib_accessor.h" +#include + +// Note: A fast cut-down version of strcmp which does NOT return -1 +// 0 means input strings are equal and 1 means not equal +GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b) +{ + if (*a != *b) + return 1; + while ((*a != 0 && *b != 0) && *(a) == *(b)) { + a++; + b++; + } + return (*a == 0 && *b == 0) ? 0 : 1; +} + +int grib_accessor::compare_accessors(grib_accessor* a2, int compare_flags) +{ + int ret = 0; + long type1 = 0; + long type2 = 0; + int type_mismatch = 0; + grib_accessor_class* c1 = NULL; + grib_accessor* a1 = this; + + if ((compare_flags & GRIB_COMPARE_NAMES) && grib_inline_strcmp(a1->name, a2->name)) + return GRIB_NAME_MISMATCH; + + if (compare_flags & GRIB_COMPARE_TYPES) { + type1 = a1->get_native_type(); + type2 = a2->get_native_type(); + + type_mismatch = type1 != type2 ? 1 : 0; + } + + // ret = GRIB_UNABLE_TO_COMPARE_ACCESSORS; + c1 = a1->cclass; + ret = c1->compare(a1, a2); + + if (ret == GRIB_VALUE_MISMATCH && type_mismatch) + ret = GRIB_TYPE_AND_VALUE_MISMATCH; + + return ret; +} + +int grib_accessor::add_attribute(grib_accessor* attr, int nest_if_clash) +{ + int id = 0; + int idx = 0; + grib_accessor* pSame = NULL; + grib_accessor* pAloc = this; + + if (this->has_attributes()) { + pSame = this->get_attribute_index(attr->name, &id); + } + + if (pSame) { + if (nest_if_clash == 0) + return GRIB_ATTRIBUTE_CLASH; + pAloc = pSame; + } + + for (id = 0; id < MAX_ACCESSOR_ATTRIBUTES; id++) { + if (pAloc->attributes[id] == NULL) { + // attr->parent=a->parent; + pAloc->attributes[id] = attr; + attr->parent_as_attribute = pAloc; + if (pAloc->same) + attr->same = pAloc->same->get_attribute_index(attr->name, &idx); + + grib_context_log(this->context, GRIB_LOG_DEBUG, "added attribute %s->%s", this->name, attr->name); + return GRIB_SUCCESS; + } + } + return GRIB_TOO_MANY_ATTRIBUTES; +} + +grib_accessor* grib_accessor::get_attribute_index(const char* name, int* index) +{ + int i = 0; + while (i < MAX_ACCESSOR_ATTRIBUTES && this->attributes[i]) { + if (!grib_inline_strcmp(this->attributes[i]->name, name)) { + *index = i; + return this->attributes[i]; + } + i++; + } + return NULL; +} + +int grib_accessor::has_attributes() +{ + return this->attributes[0] ? 1 : 0; +} + +grib_accessor* grib_accessor::get_attribute(const char* name) +{ + int index = 0; + const char* p = 0; + char* basename = NULL; + const char* attribute_name = NULL; + grib_accessor* acc = NULL; + p = name; + while (*(p + 1) != '\0' && (*p != '-' || *(p + 1) != '>')) + p++; + if (*(p + 1) == '\0') { + return this->get_attribute_index(name, &index); + } + else { + size_t size = p - name; + attribute_name = p + 2; + basename = (char*)grib_context_malloc_clear(this->context, size + 1); + basename = (char*)memcpy(basename, name, size); + acc = this->get_attribute_index(basename, &index); + grib_context_free(this->context, basename); + if (acc) + return acc->get_attribute(attribute_name); + else + return NULL; + } +} diff --git a/src/accessor/grib_accessor.h b/src/accessor/grib_accessor.h new file mode 100644 index 000000000..7fe8aad19 --- /dev/null +++ b/src/accessor/grib_accessor.h @@ -0,0 +1,147 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_api_internal.h" +#include "grib_value.h" + +class grib_accessor +{ +public: + grib_accessor() : + name(nullptr), name_space(nullptr), context(nullptr), h(nullptr), creator(nullptr), + length(0), offset(0), parent(nullptr), next_(nullptr), previous_(nullptr), cclass(nullptr), + flags(0), sub_section(nullptr), dirty(0), same(nullptr), loop(0), vvalue(nullptr), + set(nullptr), parent_as_attribute(nullptr) {} + virtual ~grib_accessor() {} + + virtual void init_accessor(const long, grib_arguments*) = 0; + virtual void dump(grib_dumper* f) = 0; + virtual int pack_missing() = 0; + //virtual int grib_pack_zero(grib_accessor* a) = 0; + virtual int is_missing_internal() = 0; + virtual int pack_double(const double* v, size_t* len) = 0; + virtual int pack_float(const float* v, size_t* len) = 0; + virtual int pack_expression(grib_expression* e) = 0; + virtual int pack_string(const char* v, size_t* len) = 0; + virtual int pack_string_array(const char** v, size_t* len) = 0; + virtual int pack_long(const long* v, size_t* len) = 0; + virtual int pack_bytes(const unsigned char* v, size_t* len) = 0; + virtual int unpack_bytes(unsigned char* v, size_t* len) = 0; + virtual int unpack_double_subarray(double* v, size_t start, size_t len) = 0; + virtual int unpack_double(double* v, size_t* len) = 0; + virtual int unpack_float(float* v, size_t* len) = 0; + virtual int unpack_double_element(size_t i, double* v) = 0; + virtual int unpack_float_element(size_t i, float* v) = 0; + virtual int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) = 0; + virtual int unpack_float_element_set(const size_t* index_array, size_t len, float* val_array) = 0; + virtual int unpack_string(char* v, size_t* len) = 0; + virtual int unpack_string_array(char** v, size_t* len) = 0; + virtual int unpack_long(long* v, size_t* len) = 0; + virtual long get_native_type() = 0; + virtual long get_next_position_offset() = 0; + virtual long string_length() = 0; + virtual long byte_offset() = 0; + virtual long byte_count() = 0; + virtual int value_count(long* count) = 0; + virtual int notify_change(grib_accessor* changed) = 0; + virtual grib_accessor* clone(grib_section* s, int* err) = 0; + virtual void update_size(size_t len) = 0; + virtual int nearest_smaller_value(double val, double* nearest) = 0; + virtual size_t preferred_size(int from_handle) = 0; + virtual grib_accessor* next_accessor() = 0; + virtual void resize(size_t new_size) = 0; + virtual void destroy(grib_context* ct) = 0; + + virtual int compare_accessors(grib_accessor* a2, int compare_flags); + virtual int add_attribute(grib_accessor* attr, int nest_if_clash); + virtual grib_accessor* get_attribute_index(const char* name, int* index); + virtual int has_attributes(); + virtual grib_accessor* get_attribute(const char* name); + + + const char* name; /** < name of the accessor */ + const char* name_space; /** < namespace to which the accessor belongs */ + grib_context* context; + grib_handle* h; + grib_action* creator; /** < action that created the accessor */ + long length; /** < byte length of the accessor */ + long offset; /** < offset of the data in the buffer */ + grib_section* parent; /** < section to which the accessor is attached */ + grib_accessor* next_; /** < next accessor in list */ + grib_accessor* previous_; /** < next accessor in list */ + grib_accessor_class* cclass; /** < behaviour of the accessor */ + unsigned long flags; /** < Various flags */ + grib_section* sub_section; + + const char* all_names[MAX_ACCESSOR_NAMES]= {0,}; /** < name of the accessor */ + const char* all_name_spaces[MAX_ACCESSOR_NAMES] = {0,}; /** < namespace to which the accessor belongs */ + int dirty; + + grib_accessor* same; /** < accessors with the same name */ + long loop; /** < used in lists */ + grib_virtual_value* vvalue; /** < virtual value used when transient flag on **/ + const char* set; + grib_accessor* attributes[MAX_ACCESSOR_ATTRIBUTES] = {0,}; /** < attributes are accessors */ + grib_accessor* parent_as_attribute; +}; + + +class grib_accessor_class +{ +public: + const char* name; + + grib_accessor_class(const char* name) : name(name){} + virtual ~grib_accessor_class(){} + + virtual grib_accessor* create_empty_accessor() = 0; + virtual grib_section* sub_section(grib_accessor* a) = 0; + virtual int get_native_type(grib_accessor*) = 0; + virtual int pack_missing(grib_accessor*) = 0; + virtual int is_missing(grib_accessor*) = 0; + virtual int pack_bytes(grib_accessor*, const unsigned char*, size_t* len) = 0; + virtual int pack_double(grib_accessor*, const double* val, size_t* len) = 0; + virtual int pack_float(grib_accessor*, const float* val, size_t* len) = 0; + virtual int pack_long(grib_accessor*, const long* val, size_t* len) = 0; + virtual int pack_string(grib_accessor*, const char*, size_t* len) = 0; + virtual int pack_string_array(grib_accessor*, const char**, size_t* len) = 0; + virtual int pack_expression(grib_accessor*, grib_expression*) = 0; + virtual int unpack_bytes(grib_accessor*, unsigned char*, size_t* len) = 0; + virtual int unpack_double(grib_accessor*, double* val, size_t* len) = 0; + virtual int unpack_float(grib_accessor*, float* val, size_t* len) = 0; + virtual int unpack_long(grib_accessor*, long* val, size_t* len) = 0; + virtual int unpack_string(grib_accessor*, char*, size_t* len) = 0; + virtual int unpack_string_array(grib_accessor*, char**, size_t* len) = 0; + virtual size_t string_length(grib_accessor*) = 0; + virtual long byte_count(grib_accessor*) = 0; + virtual long byte_offset(grib_accessor*) = 0; + virtual long next_offset(grib_accessor*) = 0; + virtual int value_count(grib_accessor*, long*) = 0; + virtual void destroy(grib_context*, grib_accessor*) = 0; + virtual void dump(grib_accessor*, grib_dumper*) = 0; + virtual void init(grib_accessor*, const long, grib_arguments*) = 0; + virtual void post_init(grib_accessor*) = 0; + virtual int notify_change(grib_accessor*, grib_accessor*) = 0; + virtual void update_size(grib_accessor*, size_t) = 0; + virtual size_t preferred_size(grib_accessor*, int) = 0; + virtual void resize(grib_accessor*,size_t) = 0; + virtual int nearest_smaller_value (grib_accessor*, double, double*) = 0; + virtual grib_accessor* next(grib_accessor*, int) = 0; + virtual int compare(grib_accessor*, grib_accessor*) = 0; + virtual int unpack_double_element(grib_accessor*, size_t i, double* val) = 0; + virtual int unpack_float_element(grib_accessor*, size_t i, float* val) = 0; + virtual int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) = 0; + virtual int unpack_float_element_set(grib_accessor*, const size_t* index_array, size_t len, float* val_array) = 0; + virtual int unpack_double_subarray(grib_accessor*, double* val, size_t start, size_t len) = 0; + virtual int clear(grib_accessor*) = 0; + virtual grib_accessor* make_clone(grib_accessor*, grib_section*, int*) = 0; +}; diff --git a/src/accessor/grib_accessor_class_abstract_long_vector.cc b/src/accessor/grib_accessor_class_abstract_long_vector.cc new file mode 100644 index 000000000..0f4514aa1 --- /dev/null +++ b/src/accessor/grib_accessor_class_abstract_long_vector.cc @@ -0,0 +1,15 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_abstract_long_vector.h" + +grib_accessor_class_abstract_long_vector_t _grib_accessor_class_abstract_long_vector{"abstract_long_vector"}; +grib_accessor_class* grib_accessor_class_abstract_long_vector = &_grib_accessor_class_abstract_long_vector; diff --git a/src/accessor/grib_accessor_class_abstract_long_vector.h b/src/accessor/grib_accessor_class_abstract_long_vector.h new file mode 100644 index 000000000..94ed9d636 --- /dev/null +++ b/src/accessor/grib_accessor_class_abstract_long_vector.h @@ -0,0 +1,30 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_abstract_long_vector_t : public grib_accessor_gen_t +{ +public: + /* Members defined in abstract_long_vector */ + long* v; + long pack_index; + int number_of_elements; +}; + +class grib_accessor_class_abstract_long_vector_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_abstract_long_vector_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_abstract_long_vector_t{}; } +}; diff --git a/src/grib_accessor.h b/src/accessor/grib_accessor_class_abstract_vector.cc similarity index 62% rename from src/grib_accessor.h rename to src/accessor/grib_accessor_class_abstract_vector.cc index 10fa228f7..2ee141e8f 100644 --- a/src/grib_accessor.h +++ b/src/accessor/grib_accessor_class_abstract_vector.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,8 +9,7 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#pragma once +#include "grib_accessor_class_abstract_vector.h" -#include "grib_api_internal.h" - -template int grib_unpack(grib_accessor* a, T* v, size_t* len); +grib_accessor_class_abstract_vector_t _grib_accessor_class_abstract_vector{"abstract_vector"}; +grib_accessor_class* grib_accessor_class_abstract_vector = &_grib_accessor_class_abstract_vector; diff --git a/src/accessor/grib_accessor_class_abstract_vector.h b/src/accessor/grib_accessor_class_abstract_vector.h new file mode 100644 index 000000000..b721a3adb --- /dev/null +++ b/src/accessor/grib_accessor_class_abstract_vector.h @@ -0,0 +1,29 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_double.h" + +class grib_accessor_abstract_vector_t : public grib_accessor_double_t +{ +public: + /* Members defined in abstract_vector */ + double* v; + int number_of_elements; +}; + +class grib_accessor_class_abstract_vector_t : public grib_accessor_class_double_t +{ +public: + grib_accessor_class_abstract_vector_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_abstract_vector_t{}; } +}; diff --git a/src/accessor/grib_accessor_class_ascii.cc b/src/accessor/grib_accessor_class_ascii.cc new file mode 100644 index 000000000..b3e9f6a8a --- /dev/null +++ b/src/accessor/grib_accessor_class_ascii.cc @@ -0,0 +1,179 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_ascii.h" + +grib_accessor_class_ascii_t _grib_accessor_class_ascii{ "ascii" }; +grib_accessor_class* grib_accessor_class_ascii = &_grib_accessor_class_ascii; + + +void grib_accessor_class_ascii_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ + grib_accessor_class_gen_t::init(a, len, arg); + a->length = len; + Assert(a->length >= 0); +} + +int grib_accessor_class_ascii_t::value_count(grib_accessor* a, long* count) +{ + *count = 1; + return 0; +} + +size_t grib_accessor_class_ascii_t::string_length(grib_accessor* a) +{ + return a->length; +} + +void grib_accessor_class_ascii_t::dump(grib_accessor* a, grib_dumper* dumper) +{ + grib_dump_string(dumper, a, NULL); +} + +int grib_accessor_class_ascii_t::get_native_type(grib_accessor* a) +{ + return GRIB_TYPE_STRING; +} + +int grib_accessor_class_ascii_t::unpack_string(grib_accessor* a, char* val, size_t* len) +{ + grib_handle* hand = grib_handle_of_accessor(a); + const size_t alen = a->length; + + if (*len < (alen + 1)) { + const char* cclass_name = a->cclass->name; + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", + cclass_name, a->name, alen + 1, *len); + *len = alen + 1; + return GRIB_BUFFER_TOO_SMALL; + } + + size_t i = 0; + for (i = 0; i < alen; i++) + val[i] = hand->buffer->data[a->offset + i]; + val[i] = 0; + *len = i; + return GRIB_SUCCESS; +} + +int grib_accessor_class_ascii_t::pack_string(grib_accessor* a, const char* val, size_t* len) +{ + grib_handle* hand = grib_handle_of_accessor(a); + const size_t alen = a->length; + if (len[0] > (alen + 1)) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "pack_string: Wrong size (%zu) for %s, it contains %ld values", + len[0], a->name, a->length + 1); + len[0] = 0; + return GRIB_BUFFER_TOO_SMALL; + } + + for (size_t i = 0; i < alen; i++) { + if (i < len[0]) + hand->buffer->data[a->offset + i] = val[i]; + else + hand->buffer->data[a->offset + i] = 0; + } + + return GRIB_SUCCESS; +} + +int grib_accessor_class_ascii_t::pack_long(grib_accessor* a, const long* v, size_t* len) +{ + grib_context_log(a->context, GRIB_LOG_ERROR, "Should not pack %s as long (It's a string)", a->name); + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_class_ascii_t::pack_double(grib_accessor* a, const double* v, size_t* len) +{ + grib_context_log(a->context, GRIB_LOG_ERROR, "Should not pack %s as double (It's a string)", a->name); + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_class_ascii_t::unpack_long(grib_accessor* a, long* v, size_t* len) +{ + char val[1024] = {0,}; + size_t l = sizeof(val); + size_t i = 0; + char* last = NULL; + int err = a->unpack_string(val, &l); + if (err) + return err; + + i = 0; + while (i < l - 1 && val[i] == ' ') + i++; + + if (val[i] == 0) { + *v = 0; + return 0; + } + if (val[i + 1] == ' ' && i < l - 2) + val[i + 1] = 0; + + *v = strtol(val, &last, 10); + + grib_context_log(a->context, GRIB_LOG_DEBUG, " Casting string %s to long", a->name); + return GRIB_SUCCESS; +} + +int grib_accessor_class_ascii_t::unpack_double(grib_accessor* a, double* v, size_t* len) +{ + char val[1024]; + size_t l = sizeof(val); + char* last = NULL; + + int err = a->unpack_string(val, &l); + if (err) return err; + + *v = strtod(val, &last); + + if (*last == 0) { + grib_context_log(a->context, GRIB_LOG_DEBUG, " Casting string %s to long", a->name); + return GRIB_SUCCESS; + } + + grib_context_log(a->context, GRIB_LOG_WARNING, "Cannot unpack %s as double. Hint: Try unpacking as string", a->name); + + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_class_ascii_t::compare(grib_accessor* a, grib_accessor* b) +{ + int retval = 0; + char* aval = 0; + char* bval = 0; + int err = 0; + + size_t alen = a->length + 1; + size_t blen = b->length + 1; + + if (alen != blen) + return GRIB_COUNT_MISMATCH; + + aval = (char*)grib_context_malloc(a->context, alen * sizeof(char)); + bval = (char*)grib_context_malloc(b->context, blen * sizeof(char)); + + err = a->unpack_string(aval, &alen); + if (err) return err; + err = b->unpack_string(bval, &blen); + if (err) return err; + + retval = GRIB_SUCCESS; + if (!STR_EQUAL(aval, bval)) + retval = GRIB_STRING_VALUE_MISMATCH; + + grib_context_free(a->context, aval); + grib_context_free(b->context, bval); + + return retval; +} diff --git a/src/accessor/grib_accessor_class_ascii.h b/src/accessor/grib_accessor_class_ascii.h new file mode 100644 index 000000000..8bef5eaac --- /dev/null +++ b/src/accessor/grib_accessor_class_ascii.h @@ -0,0 +1,39 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_ascii_t : public grib_accessor_gen_t +{ +public: + /* Members defined in ascii */ +}; + +class grib_accessor_class_ascii_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_ascii_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_ascii_t{}; } + int get_native_type(grib_accessor*) override; + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int pack_string(grib_accessor*, const char*, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + size_t string_length(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + int compare(grib_accessor*, grib_accessor*) override; +}; diff --git a/src/accessor/grib_accessor_class_bit.cc b/src/accessor/grib_accessor_class_bit.cc new file mode 100644 index 000000000..c1efac202 --- /dev/null +++ b/src/accessor/grib_accessor_class_bit.cc @@ -0,0 +1,82 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_bit.h" + +grib_accessor_class_bit_t _grib_accessor_class_bit{ "bit" }; +grib_accessor_class* grib_accessor_class_bit = &_grib_accessor_class_bit; + + +void grib_accessor_class_bit_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ + grib_accessor_class_long_t::init(a, len, arg); + grib_accessor_bit_t* self = (grib_accessor_bit_t*)a; + a->length = 0; + self->owner = grib_arguments_get_name(grib_handle_of_accessor(a), arg, 0); + self->bit_index = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 1); +} + +int grib_accessor_class_bit_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ + grib_accessor_bit_t* self = (grib_accessor_bit_t*)a; + int ret = 0; + long data = 0; + + if (*len < 1) { + grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_bit_t: unpack_long: Wrong size for %s, it contains %d values ", a->name, 1); + *len = 1; + return GRIB_ARRAY_TOO_SMALL; + } + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->owner, &data)) != GRIB_SUCCESS) { + *len = 0; + return ret; + } + + if (data & (1 << self->bit_index)) + *val = 1; + else + *val = 0; + + *len = 1; + return GRIB_SUCCESS; +} + +int grib_accessor_class_bit_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ + grib_accessor_bit_t* self = (grib_accessor_bit_t*)a; + + if (*len < 1) { + grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_bit_t: pack_long: At least one value to pack for %s", a->name); + *len = 1; + return GRIB_ARRAY_TOO_SMALL; + } + + grib_accessor* owner = grib_find_accessor(grib_handle_of_accessor(a), self->owner); + if (!owner) { + grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_bit_t: Cannot get the owner %s for computing the bit value of %s", + self->owner, a->name); + *len = 0; + return GRIB_NOT_FOUND; + } + + unsigned char* mdata = grib_handle_of_accessor(a)->buffer->data; + mdata += owner->byte_offset(); + /* Note: In the definitions, flagbit numbers go from 7 to 0 (the bit_index), while WMO convention is from 1 to 8 */ + if (a->context->debug) { + /* Print bit positions from 1 (MSB) */ + fprintf(stderr, "ECCODES DEBUG Setting bit %d in %s to %d\n", 8 - self->bit_index, owner->name, (*val > 0)); + } + grib_set_bit(mdata, 7 - self->bit_index, *val > 0); + + *len = 1; + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_bit.h b/src/accessor/grib_accessor_class_bit.h new file mode 100644 index 000000000..188d5e370 --- /dev/null +++ b/src/accessor/grib_accessor_class_bit.h @@ -0,0 +1,32 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_bit_t : public grib_accessor_long_t +{ +public: + /* Members defined in bit */ + const char* owner; + int bit_index; +}; + +class grib_accessor_class_bit_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_bit_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_bit_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_bitmap.cc b/src/accessor/grib_accessor_class_bitmap.cc new file mode 100644 index 000000000..05d9db3bf --- /dev/null +++ b/src/accessor/grib_accessor_class_bitmap.cc @@ -0,0 +1,189 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_bitmap.h" + +grib_accessor_class_bitmap_t _grib_accessor_class_bitmap{ "bitmap" }; +grib_accessor_class* grib_accessor_class_bitmap = &_grib_accessor_class_bitmap; + +static void compute_size(grib_accessor* a) +{ + long slen = 0; + long off = 0; + grib_handle* hand = grib_handle_of_accessor(a); + + grib_accessor_bitmap_t* self = (grib_accessor_bitmap_t*)a; + grib_get_long_internal(hand, self->offsetbsec, &off); + grib_get_long_internal(hand, self->sLength, &slen); + + if (slen == 0) { + grib_accessor* seclen; + size_t size; + /* Assume reparsing */ + Assert(hand->loader != 0); + if (hand->loader != 0) { + seclen = grib_find_accessor(hand, self->sLength); + Assert(seclen); + grib_get_block_length(seclen->parent, &size); + slen = size; + } + } + + // printf("compute_size off=%ld slen=%ld a->offset=%ld\n", (long)off,(long)slen,(long)a->offset); + + a->length = off + (slen - a->offset); + + if (a->length < 0) { + /* Assume reparsing */ + /*Assert(hand->loader != 0);*/ + a->length = 0; + } + + Assert(a->length >= 0); +} + +void grib_accessor_class_bitmap_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ + grib_accessor_class_bytes_t::init(a, len, arg); + grib_accessor_bitmap_t* self = (grib_accessor_bitmap_t*)a; + grib_handle* hand = grib_handle_of_accessor(a); + int n = 0; + + self->tableReference = grib_arguments_get_name(hand, arg, n++); + self->missing_value = grib_arguments_get_name(hand, arg, n++); + self->offsetbsec = grib_arguments_get_name(hand, arg, n++); + self->sLength = grib_arguments_get_name(hand, arg, n++); + + compute_size(a); +} + +long grib_accessor_class_bitmap_t::next_offset(grib_accessor* a) +{ + return a->byte_offset() + a->byte_count(); +} + +void grib_accessor_class_bitmap_t::dump(grib_accessor* a, grib_dumper* dumper) +{ + long len = 0; + char label[1024]; + + a->value_count(&len); + snprintf(label, sizeof(label), "Bitmap of %ld values", len); + grib_dump_bytes(dumper, a, label); +} + +int grib_accessor_class_bitmap_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ + long pos = a->offset * 8; + long tlen = 0; + const grib_handle* hand = grib_handle_of_accessor(a); + + int err = a->value_count(&tlen); + if (err) + return err; + + if (*len < tlen) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %ld values", a->name, tlen); + *len = tlen; + return GRIB_ARRAY_TOO_SMALL; + } + + for (long i = 0; i < tlen; i++) { + val[i] = (long)grib_decode_unsigned_long(hand->buffer->data, &pos, 1); + } + *len = tlen; + return GRIB_SUCCESS; +} + +template +static int unpack(grib_accessor* a, T* val, size_t* len) +{ + static_assert(std::is_floating_point::value, "Requires floating points numbers"); + long pos = a->offset * 8; + long tlen; + grib_handle* hand = grib_handle_of_accessor(a); + + int err = a->value_count(&tlen); + if (err) + return err; + + if (*len < tlen) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %ld values", a->name, tlen); + *len = tlen; + return GRIB_ARRAY_TOO_SMALL; + } + + for (long i = 0; i < tlen; i++) { + val[i] = (T)grib_decode_unsigned_long(hand->buffer->data, &pos, 1); + } + *len = tlen; + return GRIB_SUCCESS; +} + +int grib_accessor_class_bitmap_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ + return unpack(a, val, len); +} + +int grib_accessor_class_bitmap_t::unpack_float(grib_accessor* a, float* val, size_t* len) +{ + return unpack(a, val, len); +} + +int grib_accessor_class_bitmap_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) +{ + long pos = a->offset * 8; + + pos += idx; + *val = (double)grib_decode_unsigned_long(grib_handle_of_accessor(a)->buffer->data, &pos, 1); + + return GRIB_SUCCESS; +} +int grib_accessor_class_bitmap_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) +{ + for (size_t i = 0; i < len; ++i) { + unpack_double_element(a, index_array[i], val_array + i); + } + return GRIB_SUCCESS; +} + +void grib_accessor_class_bitmap_t::update_size(grib_accessor* a, size_t s) +{ + a->length = s; +} + +size_t grib_accessor_class_bitmap_t::string_length(grib_accessor* a) +{ + return a->length; +} + +int grib_accessor_class_bitmap_t::unpack_string(grib_accessor* a, char* val, size_t* len) +{ + grib_handle* hand = grib_handle_of_accessor(a); + const size_t l = a->length; + + if (*len < l) { + const char* cclass_name = a->cclass->name; + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", + cclass_name, a->name, l, *len); + *len = l; + return GRIB_BUFFER_TOO_SMALL; + } + + for (long i = 0; i < a->length; i++) { + val[i] = hand->buffer->data[a->offset + i]; + } + + *len = a->length; + + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_bitmap.h b/src/accessor/grib_accessor_class_bitmap.h new file mode 100644 index 000000000..4f07f3a6c --- /dev/null +++ b/src/accessor/grib_accessor_class_bitmap.h @@ -0,0 +1,42 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_bytes.h" + +class grib_accessor_bitmap_t : public grib_accessor_bytes_t +{ +public: + /* Members defined in bitmap */ + const char* tableReference; + const char* missing_value; + const char* offsetbsec; + const char* sLength; +}; + +class grib_accessor_class_bitmap_t : public grib_accessor_class_bytes_t +{ +public: + grib_accessor_class_bitmap_t(const char* name) : grib_accessor_class_bytes_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_bitmap_t{}; } + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_float(grib_accessor*, float* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + size_t string_length(grib_accessor*) override; + long next_offset(grib_accessor*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + void update_size(grib_accessor*, size_t) override; + int unpack_double_element(grib_accessor*, size_t i, double* val) override; + int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override; +}; diff --git a/src/grib_accessor_class_bits.cc b/src/accessor/grib_accessor_class_bits.cc similarity index 50% rename from src/grib_accessor_class_bits.cc rename to src/accessor/grib_accessor_class_bits.cc index 5e86e2fef..e0a9e7d8d 100644 --- a/src/grib_accessor_class_bits.cc +++ b/src/accessor/grib_accessor_class_bits.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,127 +9,15 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -/************************************** - * Enrico Fucile - **************************************/ - - -#include "grib_api_internal.h" - - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = get_native_type - IMPLEMENTS = unpack_long; pack_long - IMPLEMENTS = unpack_bytes; byte_count - IMPLEMENTS = unpack_double; pack_double - IMPLEMENTS = unpack_string - IMPLEMENTS = init - MEMBERS=const char* argument - MEMBERS=long start - MEMBERS=long len - MEMBERS=double referenceValue - MEMBERS=double referenceValuePresent - MEMBERS=double scale - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_bytes(grib_accessor*, unsigned char*, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static long byte_count(grib_accessor*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_bits -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in bits */ - const char* argument; - long start; - long len; - double referenceValue; - double referenceValuePresent; - double scale; -} grib_accessor_bits; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_bits = { - &grib_accessor_class_gen, /* super */ - "bits", /* name */ - sizeof(grib_accessor_bits), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - &byte_count, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - &unpack_bytes, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_bits.h" +grib_accessor_class_bits_t _grib_accessor_class_bits{"bits"}; grib_accessor_class* grib_accessor_class_bits = &_grib_accessor_class_bits; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_bits* self = (grib_accessor_bits*)a; +void grib_accessor_class_bits_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_gen_t::init(a, l, c); + grib_accessor_bits_t* self = (grib_accessor_bits_t*)a; grib_handle* hand = grib_handle_of_accessor(a); grib_expression* e = NULL; int n = 0; @@ -154,9 +43,8 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) a->length = 0; } -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_bits* self = (grib_accessor_bits*)a; +int grib_accessor_class_bits_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_accessor_bits_t* self = (grib_accessor_bits_t*)a; grib_accessor* x = NULL; unsigned char* p = NULL; grib_handle* h = grib_handle_of_accessor(a); @@ -173,17 +61,15 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) if (!x) return GRIB_NOT_FOUND; - p = h->buffer->data + grib_byte_offset(x); - *val = grib_decode_unsigned_long(p, &start, length); + p = h->buffer->data + x->byte_offset(); *val = grib_decode_unsigned_long(p, &start, length); *len = 1; return ret; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_bits* self = (grib_accessor_bits*)a; +int grib_accessor_class_bits_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + grib_accessor_bits_t* self = (grib_accessor_bits_t*)a; grib_accessor* x = NULL; unsigned char* p = NULL; grib_handle* h = grib_handle_of_accessor(a); @@ -200,8 +86,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) if (!x) return GRIB_NOT_FOUND; - p = h->buffer->data + grib_byte_offset(x); - *val = grib_decode_unsigned_long(p, &start, length); + p = h->buffer->data + x->byte_offset(); *val = grib_decode_unsigned_long(p, &start, length); *val = ((long)*val + self->referenceValue) / self->scale; @@ -210,9 +95,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) return ret; } -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_bits* self = (grib_accessor_bits*)a; +int grib_accessor_class_bits_t::pack_double(grib_accessor* a, const double* val, size_t* len){ + grib_accessor_bits_t* self = (grib_accessor_bits_t*)a; grib_accessor* x = NULL; grib_handle* h = grib_handle_of_accessor(a); unsigned char* p = NULL; @@ -228,15 +112,13 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) if (!x) return GRIB_NOT_FOUND; - p = h->buffer->data + grib_byte_offset(x); - + p = h->buffer->data + x->byte_offset(); lval = round(*val * self->scale) - self->referenceValue; return grib_encode_unsigned_longb(p, lval, &start, length); } -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - grib_accessor_bits* self = (grib_accessor_bits*)a; +int grib_accessor_class_bits_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + grib_accessor_bits_t* self = (grib_accessor_bits_t*)a; grib_accessor* x = NULL; grib_handle* h = grib_handle_of_accessor(a); unsigned char* p = NULL; @@ -285,14 +167,12 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) return GRIB_ENCODING_ERROR; } - p = h->buffer->data + grib_byte_offset(x); - return grib_encode_unsigned_longb(p, *val, &start, length); + p = h->buffer->data + x->byte_offset(); return grib_encode_unsigned_longb(p, *val, &start, length); } -static int get_native_type(grib_accessor* a) -{ +int grib_accessor_class_bits_t::get_native_type(grib_accessor* a){ int type = GRIB_TYPE_BYTES; - grib_accessor_bits* self = (grib_accessor_bits*)a; + grib_accessor_bits_t* self = (grib_accessor_bits_t*)a; if (a->flags & GRIB_ACCESSOR_FLAG_STRING_TYPE) type = GRIB_TYPE_STRING; @@ -306,13 +186,11 @@ static int get_native_type(grib_accessor* a) return type; } -static int unpack_string(grib_accessor* a, char* v, size_t* len) -{ +int grib_accessor_class_bits_t::unpack_string(grib_accessor* a, char* v, size_t* len){ int ret = 0; double dval = 0; long lval = 0; size_t llen = 1; - grib_accessor_class* super = NULL; switch (get_native_type(a)) { case GRIB_TYPE_LONG: @@ -328,20 +206,17 @@ static int unpack_string(grib_accessor* a, char* v, size_t* len) break; default: - super = *(a->cclass->super); - ret = super->unpack_string(a, v, len); + ret = grib_accessor_class_gen_t::unpack_string(a, v, len); } return ret; } -static long byte_count(grib_accessor* a) -{ +long grib_accessor_class_bits_t::byte_count(grib_accessor* a){ grib_context_log(a->context, GRIB_LOG_DEBUG, "byte_count of %s = %ld", a->name, a->length); return a->length; } -static int unpack_bytes(grib_accessor* a, unsigned char* buffer, size_t* len) -{ +int grib_accessor_class_bits_t::unpack_bytes(grib_accessor* a, unsigned char* buffer, size_t* len){ if (*len < a->length) { *len = a->length; return GRIB_ARRAY_TOO_SMALL; diff --git a/src/accessor/grib_accessor_class_bits.h b/src/accessor/grib_accessor_class_bits.h new file mode 100644 index 000000000..19ec26b35 --- /dev/null +++ b/src/accessor/grib_accessor_class_bits.h @@ -0,0 +1,42 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_bits_t : public grib_accessor_gen_t +{ +public: + /* Members defined in bits */ + const char* argument; + long start; + long len; + double referenceValue; + double referenceValuePresent; + double scale; +}; + +class grib_accessor_class_bits_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_bits_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_bits_t{}; } + int get_native_type(grib_accessor*) override; + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_bytes(grib_accessor*, unsigned char*, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + long byte_count(grib_accessor*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_bits_per_value.cc b/src/accessor/grib_accessor_class_bits_per_value.cc new file mode 100644 index 000000000..dbdef54cb --- /dev/null +++ b/src/accessor/grib_accessor_class_bits_per_value.cc @@ -0,0 +1,78 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_bits_per_value.h" + +grib_accessor_class_bits_per_value_t _grib_accessor_class_bits_per_value{ "bits_per_value" }; +grib_accessor_class* grib_accessor_class_bits_per_value = &_grib_accessor_class_bits_per_value; + + +void grib_accessor_class_bits_per_value_t::init(grib_accessor* a, const long l, grib_arguments* args) +{ + grib_accessor_class_long_t::init(a, l, args); + int n = 0; + grib_accessor_bits_per_value_t* self = (grib_accessor_bits_per_value_t*)a; + self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + self->bits_per_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; + a->length = 0; +} + +int grib_accessor_class_bits_per_value_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ + grib_accessor_bits_per_value_t* self = (grib_accessor_bits_per_value_t*)a; + + int ret = 0; + grib_handle* h = grib_handle_of_accessor(a); + + if ((ret = grib_get_long_internal(h, self->bits_per_value, val)) != GRIB_SUCCESS) + return ret; + + *len = 1; + return ret; +} + +int grib_accessor_class_bits_per_value_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ + grib_accessor_bits_per_value_t* self = (grib_accessor_bits_per_value_t*)a; + + double* values = NULL; + size_t size = 0; + int ret = 0; + grib_context* c = a->context; + grib_handle* h = grib_handle_of_accessor(a); + + if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) + return ret; + + values = (double*)grib_context_malloc(c, size * sizeof(double)); + if (!values) + return GRIB_OUT_OF_MEMORY; + + if ((ret = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) { + grib_context_free(c, values); + return ret; + } + + if ((ret = grib_set_long_internal(h, self->bits_per_value, *val)) != GRIB_SUCCESS) { + grib_context_free(c, values); + return ret; + } + + if ((ret = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) { + grib_context_free(c, values); + return ret; + } + + grib_context_free(c, values); + + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_bits_per_value.h b/src/accessor/grib_accessor_class_bits_per_value.h new file mode 100644 index 000000000..741ecd0e5 --- /dev/null +++ b/src/accessor/grib_accessor_class_bits_per_value.h @@ -0,0 +1,32 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_bits_per_value_t : public grib_accessor_long_t +{ +public: + /* Members defined in bits_per_value */ + const char* values; + const char* bits_per_value; +}; + +class grib_accessor_class_bits_per_value_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_bits_per_value_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_bits_per_value_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_blob.cc b/src/accessor/grib_accessor_class_blob.cc new file mode 100644 index 000000000..4629de93a --- /dev/null +++ b/src/accessor/grib_accessor_class_blob.cc @@ -0,0 +1,47 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_blob.h" + +grib_accessor_class_blob_t _grib_accessor_class_blob{ "blob" }; +grib_accessor_class* grib_accessor_class_blob = &_grib_accessor_class_blob; + + +void grib_accessor_class_blob_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ + grib_accessor_class_gen_t::init(a, len, arg); + grib_get_long_internal(grib_handle_of_accessor(a), + grib_arguments_get_name(a->parent->h, arg, 0), &a->length); + Assert(a->length >= 0); +} + +int grib_accessor_class_blob_t::get_native_type(grib_accessor* a) +{ + return GRIB_TYPE_BYTES; +} + +int grib_accessor_class_blob_t::unpack_bytes(grib_accessor* a, unsigned char* buffer, size_t* len) +{ + if (*len < (size_t)a->length) { + *len = a->length; + return GRIB_ARRAY_TOO_SMALL; + } + *len = a->length; + + memcpy(buffer, grib_handle_of_accessor(a)->buffer->data + a->offset, *len); + + return GRIB_SUCCESS; +} + +void grib_accessor_class_blob_t::dump(grib_accessor* a, grib_dumper* dumper) +{ + grib_dump_bytes(dumper, a, NULL); +} diff --git a/src/accessor/grib_accessor_class_blob.h b/src/accessor/grib_accessor_class_blob.h new file mode 100644 index 000000000..10dad4b7b --- /dev/null +++ b/src/accessor/grib_accessor_class_blob.h @@ -0,0 +1,31 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_blob_t : public grib_accessor_gen_t +{ +public: + /* Members defined in blob */ +}; + +class grib_accessor_class_blob_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_blob_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_blob_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_bytes(grib_accessor*, unsigned char*, size_t* len) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_budgdate.cc b/src/accessor/grib_accessor_class_budgdate.cc new file mode 100644 index 000000000..4c58c20f2 --- /dev/null +++ b/src/accessor/grib_accessor_class_budgdate.cc @@ -0,0 +1,82 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_budgdate.h" + +grib_accessor_class_budgdate_t _grib_accessor_class_budgdate{"budgdate"}; +grib_accessor_class* grib_accessor_class_budgdate = &_grib_accessor_class_budgdate; + + +void grib_accessor_class_budgdate_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_long_t::init(a, l, c); + grib_accessor_budgdate_t* self = (grib_accessor_budgdate_t*)a; + int n = 0; + + self->year = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->month = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->day = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); +} + +int grib_accessor_class_budgdate_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + int ret = 0; + grib_accessor_budgdate_t* self = (grib_accessor_budgdate_t*)a; + + long year = 0; + long month = 0; + long day = 0; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->day, &day)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->month, &month)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->year, &year)) != GRIB_SUCCESS) + return ret; + + if (*len < 1) + return GRIB_WRONG_ARRAY_SIZE; + + val[0] = (1900 + year) * 10000 + month * 100 + day; + + return ret; +} + +/* TODO: Check for a valid date */ +int grib_accessor_class_budgdate_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + int ret = 0; + long v = val[0]; + grib_accessor_budgdate_t* self = (grib_accessor_budgdate_t*)a; + + long year = 0; + long month = 0; + long day = 0; + + if (*len != 1) + return GRIB_WRONG_ARRAY_SIZE; + + year = v / 10000; + v %= 10000; + month = v / 100; + v %= 100; + day = v; + + year -= 1900; + + Assert(year < 255); + + if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->day, day)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->month, month)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->year, year)) != GRIB_SUCCESS) + return ret; + + return ret; +} diff --git a/src/accessor/grib_accessor_class_budgdate.h b/src/accessor/grib_accessor_class_budgdate.h new file mode 100644 index 000000000..ee18250e2 --- /dev/null +++ b/src/accessor/grib_accessor_class_budgdate.h @@ -0,0 +1,33 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_budgdate_t : public grib_accessor_long_t +{ +public: + /* Members defined in budgdate */ + const char* year; + const char* month; + const char* day; +}; + +class grib_accessor_class_budgdate_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_budgdate_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_budgdate_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_bufr_data_array.cc b/src/accessor/grib_accessor_class_bufr_data_array.cc similarity index 89% rename from src/grib_accessor_class_bufr_data_array.cc rename to src/accessor/grib_accessor_class_bufr_data_array.cc index 3d044835a..e0c998950 100644 --- a/src/grib_accessor_class_bufr_data_array.cc +++ b/src/accessor/grib_accessor_class_bufr_data_array.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -9,203 +10,11 @@ */ #include "grib_scaling.h" -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init - IMPLEMENTS = dump;destroy - IMPLEMENTS = next_offset - IMPLEMENTS = byte_count; value_count - IMPLEMENTS = byte_offset; unpack_double - IMPLEMENTS = get_native_type - IMPLEMENTS = pack_long; unpack_double; pack_double - MEMBERS = const char* bufrDataEncodedName - MEMBERS = const char* numberOfSubsetsName - MEMBERS = const char* expandedDescriptorsName - MEMBERS = const char* flagsName - MEMBERS = const char* unitsName - MEMBERS = const char* elementsDescriptorsIndexName - MEMBERS = const char* compressedDataName - MEMBERS = bufr_descriptors_array* expanded - MEMBERS = grib_accessor* expandedAccessor - MEMBERS = int* canBeMissing - MEMBERS = long numberOfSubsets - MEMBERS = long compressedData - MEMBERS = grib_vdarray* numericValues - MEMBERS = grib_vsarray* stringValues - MEMBERS = grib_viarray* elementsDescriptorsIndex - MEMBERS = int do_decode - MEMBERS = int bitmapStartElementsDescriptorsIndex - MEMBERS = int bitmapCurrentElementsDescriptorsIndex - MEMBERS = int bitmapSize - MEMBERS = int bitmapStart - MEMBERS = int bitmapCurrent - MEMBERS = grib_accessors_list* dataAccessors - MEMBERS = int unpackMode - MEMBERS = int bitsToEndData - MEMBERS = grib_section* dataKeys - MEMBERS = double* inputBitmap - MEMBERS = int nInputBitmap - MEMBERS = int iInputBitmap - MEMBERS = long* inputReplications - MEMBERS = int nInputReplications - MEMBERS = int iInputReplications - MEMBERS = long* inputExtendedReplications - MEMBERS = int nInputExtendedReplications - MEMBERS = int iInputExtendedReplications - MEMBERS = long* inputShortReplications - MEMBERS = int nInputShortReplications - MEMBERS = int iInputShortReplications - MEMBERS = grib_iarray* iss_list - MEMBERS = grib_trie_with_rank* dataAccessorsTrie - MEMBERS = grib_sarray* tempStrings - MEMBERS = grib_vdarray* tempDoubleValues - MEMBERS = int change_ref_value_operand - MEMBERS = size_t refValListSize - MEMBERS = long* refValList - MEMBERS = long refValIndex - MEMBERS = bufr_tableb_override* tableb_override - MEMBERS = int set_to_missing_if_out_of_range - - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static long byte_count(grib_accessor*); -static long byte_offset(grib_accessor*); -static long next_offset(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void destroy(grib_context*, grib_accessor*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_bufr_data_array -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in bufr_data_array */ - const char* bufrDataEncodedName; - const char* numberOfSubsetsName; - const char* expandedDescriptorsName; - const char* flagsName; - const char* unitsName; - const char* elementsDescriptorsIndexName; - const char* compressedDataName; - bufr_descriptors_array* expanded; - grib_accessor* expandedAccessor; - int* canBeMissing; - long numberOfSubsets; - long compressedData; - grib_vdarray* numericValues; - grib_vsarray* stringValues; - grib_viarray* elementsDescriptorsIndex; - int do_decode; - int bitmapStartElementsDescriptorsIndex; - int bitmapCurrentElementsDescriptorsIndex; - int bitmapSize; - int bitmapStart; - int bitmapCurrent; - grib_accessors_list* dataAccessors; - int unpackMode; - int bitsToEndData; - grib_section* dataKeys; - double* inputBitmap; - int nInputBitmap; - int iInputBitmap; - long* inputReplications; - int nInputReplications; - int iInputReplications; - long* inputExtendedReplications; - int nInputExtendedReplications; - int iInputExtendedReplications; - long* inputShortReplications; - int nInputShortReplications; - int iInputShortReplications; - grib_iarray* iss_list; - grib_trie_with_rank* dataAccessorsTrie; - grib_sarray* tempStrings; - grib_vdarray* tempDoubleValues; - int change_ref_value_operand; - size_t refValListSize; - long* refValList; - long refValIndex; - bufr_tableb_override* tableb_override; - int set_to_missing_if_out_of_range; -} grib_accessor_bufr_data_array; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_bufr_data_array = { - &grib_accessor_class_gen, /* super */ - "bufr_data_array", /* name */ - sizeof(grib_accessor_bufr_data_array), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - &destroy, /* destroy */ - &dump, /* dump */ - &next_offset, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - &byte_count, /* get number of bytes */ - &byte_offset, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_bufr_data_array.h" +grib_accessor_class_bufr_data_array_t _grib_accessor_class_bufr_data_array{"bufr_data_array"}; grib_accessor_class* grib_accessor_class_bufr_data_array = &_grib_accessor_class_bufr_data_array; -/* END_CLASS_IMP */ #define MAX_NESTED_REPLICATIONS 8 @@ -226,33 +35,31 @@ grib_accessor_class* grib_accessor_class_bufr_data_array = &_grib_accessor_class } static int process_elements(grib_accessor* a, int flag, long onlySubset, long startSubset, long endSubset); +typedef int (*codec_element_proc)(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, grib_buffer* b, unsigned char* data, long* pos, int i, bufr_descriptor* descriptor, long elementIndex, grib_darray* dval, grib_sarray* sval); +typedef int (*codec_replication_proc)(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, grib_buffer* buff, unsigned char* data, long* pos, int i, long elementIndex, grib_darray* dval, long* numberOfRepetitions); +static int create_keys(const grib_accessor* a, long onlySubset, long startSubset, long endSubset); -typedef int (*codec_element_proc)(grib_context* c, grib_accessor_bufr_data_array* self, int subsetIndex, grib_buffer* b, unsigned char* data, long* pos, int i, bufr_descriptor* descriptor, long elementIndex, grib_darray* dval, grib_sarray* sval); -typedef int (*codec_replication_proc)(grib_context* c, grib_accessor_bufr_data_array* self, int subsetIndex, grib_buffer* buff, unsigned char* data, long* pos, int i, long elementIndex, grib_darray* dval, long* numberOfRepetitions); - -static int create_keys(const grib_accessor* a, long onlySubset, long startSubset, long endSubset); - -static void restart_bitmap(grib_accessor_bufr_data_array* self) +static void restart_bitmap(grib_accessor_bufr_data_array_t* self) { self->bitmapCurrent = -1; self->bitmapCurrentElementsDescriptorsIndex = self->bitmapStartElementsDescriptorsIndex - 1; } -static void cancel_bitmap(grib_accessor_bufr_data_array* self) +static void cancel_bitmap(grib_accessor_bufr_data_array_t* self) { self->bitmapCurrent = -1; self->bitmapStart = -1; } -static int is_bitmap_start_defined(grib_accessor_bufr_data_array* self) +static int is_bitmap_start_defined(grib_accessor_bufr_data_array_t* self) { return self->bitmapStart == -1 ? 0 : 1; } -static size_t get_length(grib_accessor* a) +size_t get_length(grib_accessor* a) { - grib_accessor_bufr_data_array* self = (grib_accessor_bufr_data_array*)a; - size_t len = 0; + grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; + size_t len = 0; const grib_handle* h = grib_handle_of_accessor(a); @@ -262,7 +69,7 @@ static size_t get_length(grib_accessor* a) } /* Operator 203YYY: Store the TableB code and changed reference value in linked list */ -static void tableB_override_store_ref_val(grib_context* c, grib_accessor_bufr_data_array* self, int code, long new_ref_val) +static void tableB_override_store_ref_val(grib_context* c, grib_accessor_bufr_data_array_t* self, int code, long new_ref_val) { bufr_tableb_override* tb = (bufr_tableb_override*)grib_context_malloc_clear(c, sizeof(bufr_tableb_override)); tb->code = code; @@ -280,7 +87,7 @@ static void tableB_override_store_ref_val(grib_context* c, grib_accessor_bufr_da } /* Operator 203YYY: Retrieve changed reference value from linked list */ -static int tableB_override_get_ref_val(grib_accessor_bufr_data_array* self, int code, long* out_ref_val) +static int tableB_override_get_ref_val(grib_accessor_bufr_data_array_t* self, int code, long* out_ref_val) { bufr_tableb_override* p = self->tableb_override; while (p) { @@ -294,7 +101,7 @@ static int tableB_override_get_ref_val(grib_accessor_bufr_data_array* self, int } /* Operator 203YYY: Clear and free linked list */ -static void tableB_override_clear(grib_context* c, grib_accessor_bufr_data_array* self) +void tableB_override_clear(grib_context* c, grib_accessor_bufr_data_array_t* self) { bufr_tableb_override* tb = self->tableb_override; while (tb) { @@ -306,7 +113,7 @@ static void tableB_override_clear(grib_context* c, grib_accessor_bufr_data_array } /* Operator 203YYY: Copy contents of linked list to the transient array key */ -static int tableB_override_set_key(grib_handle* h, grib_accessor_bufr_data_array* self) +int tableB_override_set_key(grib_handle* h, grib_accessor_bufr_data_array_t* self) { int err = GRIB_SUCCESS; size_t size = 0; @@ -343,7 +150,7 @@ static int check_overridden_reference_values(const grib_context* c, long* refVal return GRIB_SUCCESS; } -// static void tableB_override_dump(grib_accessor_bufr_data_array *self) +// void tableB_override_dump(grib_accessor_bufr_data_array_t *self) // { // bufr_tableb_override* p = self->tableb_override; // int i = 1; @@ -357,9 +164,9 @@ static int check_overridden_reference_values(const grib_context* c, long* refVal #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; +void grib_accessor_class_bufr_data_array_t::init(grib_accessor* a, const long v, grib_arguments* params){ + grib_accessor_class_gen_t::init(a, v, params); + grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; int n = 0; const char* dataKeysName = NULL; grib_accessor* dataKeysAcc = NULL; @@ -397,7 +204,7 @@ static void init(grib_accessor* a, const long v, grib_arguments* params) /* Assert(a->length>=0); */ } -// static void clean_string(char* s,int len) +// void clean_string(char* s,int len) // { // int i=len-1; // while (i) { @@ -407,7 +214,7 @@ static void init(grib_accessor* a, const long v, grib_arguments* params) // } // } -static int check_end_data(grib_context* c, bufr_descriptor* bd, grib_accessor_bufr_data_array* self, int size) +static int check_end_data(grib_context* c, bufr_descriptor* bd, grib_accessor_bufr_data_array_t* self, int size) { const int saved_bitsToEndData = self->bitsToEndData; if (c->debug == 1) @@ -422,8 +229,7 @@ static int check_end_data(grib_context* c, bufr_descriptor* bd, grib_accessor_bu return 0; } -static void self_clear(grib_context* c, grib_accessor_bufr_data_array* self) -{ +void self_clear(grib_context* c, grib_accessor_bufr_data_array_t* self){ grib_context_free(c, self->canBeMissing); grib_vdarray_delete_content(c, self->numericValues); grib_vdarray_delete(c, self->numericValues); @@ -452,69 +258,63 @@ static void self_clear(grib_context* c, grib_accessor_bufr_data_array* self) if (self->inputBitmap) grib_context_free(c, self->inputBitmap); } -static int get_native_type(grib_accessor* a) -{ +int grib_accessor_class_bufr_data_array_t::get_native_type(grib_accessor* a){ return GRIB_TYPE_DOUBLE; } -static long byte_count(grib_accessor* a) -{ +long grib_accessor_class_bufr_data_array_t::byte_count(grib_accessor* a){ return 0; } -static long byte_offset(grib_accessor* a) -{ +long grib_accessor_class_bufr_data_array_t::byte_offset(grib_accessor* a){ return a->offset; } -static long next_offset(grib_accessor* a) -{ +long grib_accessor_class_bufr_data_array_t::next_offset(grib_accessor* a){ return a->offset; } -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - grib_accessor_bufr_data_array* self = (grib_accessor_bufr_data_array*)a; +int grib_accessor_class_bufr_data_array_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; self->do_decode = 1; return GRIB_NOT_IMPLEMENTED; } -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_bufr_data_array* self = (grib_accessor_bufr_data_array*)a; +int grib_accessor_class_bufr_data_array_t::pack_double(grib_accessor* a, const double* val, size_t* len){ + grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; self->do_decode = 1; return process_elements(a, PROCESS_ENCODE, 0, 0, 0); } grib_vsarray* accessor_bufr_data_array_get_stringValues(grib_accessor* a) { - grib_accessor_bufr_data_array* self = (grib_accessor_bufr_data_array*)a; + grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; process_elements(a, PROCESS_DECODE, 0, 0, 0); return self->stringValues; } grib_accessors_list* accessor_bufr_data_array_get_dataAccessors(grib_accessor* a) { - grib_accessor_bufr_data_array* self = (grib_accessor_bufr_data_array*)a; + grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; return self->dataAccessors; } grib_trie_with_rank* accessor_bufr_data_array_get_dataAccessorsTrie(grib_accessor* a) { - grib_accessor_bufr_data_array* self = (grib_accessor_bufr_data_array*)a; + grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; return self->dataAccessorsTrie; } void accessor_bufr_data_array_set_unpackMode(grib_accessor* a, int unpackMode) { - grib_accessor_bufr_data_array* self = (grib_accessor_bufr_data_array*)a; + grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; self->unpackMode = unpackMode; } static int get_descriptors(grib_accessor* a) { - grib_accessor_bufr_data_array* self = (grib_accessor_bufr_data_array*)a; + grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; int ret = 0, i, numberOfDescriptors; grib_handle* h = grib_handle_of_accessor(a); grib_context* c = a->context; @@ -540,7 +340,7 @@ static int get_descriptors(grib_accessor* a) } static int decode_string_array(grib_context* c, unsigned char* data, long* pos, bufr_descriptor* bd, - grib_accessor_bufr_data_array* self) + grib_accessor_bufr_data_array_t* self) { int ret = 0; int* err = &ret; @@ -597,9 +397,9 @@ static int decode_string_array(grib_context* c, unsigned char* data, long* pos, return ret; } -static grib_darray* decode_double_array(grib_context* c, unsigned char* data, long* pos, +grib_darray* decode_double_array(grib_context* c, unsigned char* data, long* pos, bufr_descriptor* bd, int canBeMissing, - grib_accessor_bufr_data_array* self, int* err) + grib_accessor_bufr_data_array_t* self, int* err) { grib_darray* ret = NULL; int j; @@ -681,7 +481,7 @@ static grib_darray* decode_double_array(grib_context* c, unsigned char* data, lo } static int encode_string_array(grib_context* c, grib_buffer* buff, long* pos, bufr_descriptor* bd, - grib_accessor_bufr_data_array* self, grib_sarray* stringValues) + grib_accessor_bufr_data_array_t* self, grib_sarray* stringValues) { int err = 0, n, ival; int k, j, modifiedWidth, width; @@ -737,8 +537,7 @@ static int encode_string_array(grib_context* c, grib_buffer* buff, long* pos, bu return err; } -static void set_missing_long_to_double(grib_darray* dvalues) -{ +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) @@ -764,7 +563,7 @@ static int descriptor_get_min_max(bufr_descriptor* bd, long width, long referenc } static int encode_double_array(grib_context* c, grib_buffer* buff, long* pos, bufr_descriptor* bd, - grib_accessor_bufr_data_array* self, grib_darray* dvalues) + grib_accessor_bufr_data_array_t* self, grib_darray* dvalues) { int err = 0; int j, i; @@ -982,7 +781,7 @@ static int encode_double_array(grib_context* c, grib_buffer* buff, long* pos, bu } static int encode_double_value(grib_context* c, grib_buffer* buff, long* pos, bufr_descriptor* bd, - grib_accessor_bufr_data_array* self, double value) + grib_accessor_bufr_data_array_t* self, double value) { size_t lval; double maxAllowed, minAllowed; @@ -1029,7 +828,7 @@ static int encode_double_value(grib_context* c, grib_buffer* buff, long* pos, bu } static int encode_string_value(grib_context* c, grib_buffer* buff, long* pos, bufr_descriptor* bd, - grib_accessor_bufr_data_array* self, char* sval) + grib_accessor_bufr_data_array_t* self, char* sval) { int err = 0; int len; @@ -1045,7 +844,7 @@ static int encode_string_value(grib_context* c, grib_buffer* buff, long* pos, bu } static char* decode_string_value(grib_context* c, unsigned char* data, long* pos, bufr_descriptor* bd, - grib_accessor_bufr_data_array* self, int* err) + grib_accessor_bufr_data_array_t* self, int* err) { char* sval = 0; int len; @@ -1069,7 +868,7 @@ static char* decode_string_value(grib_context* c, unsigned char* data, long* pos static double decode_double_value(grib_context* c, unsigned char* data, long* pos, bufr_descriptor* bd, int canBeMissing, - grib_accessor_bufr_data_array* self, int* err) + grib_accessor_bufr_data_array_t* self, int* err) { size_t lval; int modifiedWidth, modifiedReference; @@ -1098,7 +897,7 @@ static double decode_double_value(grib_context* c, unsigned char* data, long* po return dval; } -static int decode_element(grib_context* c, grib_accessor_bufr_data_array* self, int subsetIndex, +static int decode_element(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, grib_buffer* b, unsigned char* data, long* pos, int i, bufr_descriptor* descriptor, long elementIndex, grib_darray* dval, grib_sarray* sval) { @@ -1180,7 +979,7 @@ static int decode_element(grib_context* c, grib_accessor_bufr_data_array* self, return err; } -static int decode_replication(grib_context* c, grib_accessor_bufr_data_array* self, int subsetIndex, +static int decode_replication(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, grib_buffer* buff, unsigned char* data, long* pos, int i, long elementIndex, grib_darray* dval, long* numberOfRepetitions) { int ret = 0; @@ -1245,7 +1044,7 @@ static int decode_replication(grib_context* c, grib_accessor_bufr_data_array* se return ret; } -static int encode_new_bitmap(grib_context* c, grib_buffer* buff, long* pos, int idx, grib_accessor_bufr_data_array* self) +static int encode_new_bitmap(grib_context* c, grib_buffer* buff, long* pos, int idx, grib_accessor_bufr_data_array_t* self) { grib_darray* doubleValues = NULL; int err = 0; @@ -1268,7 +1067,7 @@ static int encode_new_bitmap(grib_context* c, grib_buffer* buff, long* pos, int } /* Operator 203YYY: Change Reference Values: Encoding definition phase */ -static int encode_overridden_reference_value(grib_context* c, grib_accessor_bufr_data_array* self, +static int encode_overridden_reference_value(grib_context* c, grib_accessor_bufr_data_array_t* self, grib_buffer* buff, long* pos, bufr_descriptor* bd) { int err = 0; @@ -1307,7 +1106,7 @@ static int encode_overridden_reference_value(grib_context* c, grib_accessor_bufr return err; } -static int encode_new_element(grib_context* c, grib_accessor_bufr_data_array* self, int subsetIndex, +static int encode_new_element(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, grib_buffer* buff, unsigned char* data, long* pos, int i, bufr_descriptor* descriptor, long elementIndex, grib_darray* dval, grib_sarray* sval) { @@ -1367,7 +1166,7 @@ static int encode_new_element(grib_context* c, grib_accessor_bufr_data_array* se return err; } -static int encode_new_replication(grib_context* c, grib_accessor_bufr_data_array* self, int subsetIndex, +static int encode_new_replication(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, grib_buffer* buff, unsigned char* data, long* pos, int i, long elementIndex, grib_darray* dval, long* numberOfRepetitions) { int err = 0; @@ -1430,7 +1229,7 @@ static int encode_new_replication(grib_context* c, grib_accessor_bufr_data_array return err; } -static int encode_element(grib_context* c, grib_accessor_bufr_data_array* self, int subsetIndex, +static int encode_element(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, grib_buffer* buff, unsigned char* data, long* pos, int i, bufr_descriptor* descriptor, long elementIndex, grib_darray* dval, grib_sarray* sval) { @@ -1501,7 +1300,7 @@ static int encode_element(grib_context* c, grib_accessor_bufr_data_array* self, return err; } -static int encode_replication(grib_context* c, grib_accessor_bufr_data_array* self, int subsetIndex, +static int encode_replication(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, grib_buffer* buff, unsigned char* data, long* pos, int i, long elementIndex, grib_darray* dval, long* numberOfRepetitions) { @@ -1517,7 +1316,7 @@ static int encode_replication(grib_context* c, grib_accessor_bufr_data_array* se return encode_element(c, self, subsetIndex, buff, data, pos, i, 0, elementIndex, dval, 0); } -static int build_bitmap(grib_accessor_bufr_data_array* self, unsigned char* data, long* pos, +static int build_bitmap(grib_accessor_bufr_data_array_t* self, unsigned char* data, long* pos, int iel, grib_iarray* elementsDescriptorsIndex, int iBitmapOperator) { int bitmapSize = 0, iDelayedReplication = 0; @@ -1615,7 +1414,7 @@ static int build_bitmap(grib_accessor_bufr_data_array* self, unsigned char* data return GRIB_SUCCESS; } -static int consume_bitmap(grib_accessor_bufr_data_array* self, int iBitmapOperator) +static int consume_bitmap(grib_accessor_bufr_data_array_t* self, int iBitmapOperator) { int bitmapSize = 0, iDelayedReplication; int i; @@ -1646,7 +1445,7 @@ static int consume_bitmap(grib_accessor_bufr_data_array* self, int iBitmapOperat return GRIB_SUCCESS; } -static int build_bitmap_new_data(grib_accessor_bufr_data_array* self, unsigned char* data, long* pos, +static int build_bitmap_new_data(grib_accessor_bufr_data_array_t* self, unsigned char* data, long* pos, int iel, grib_iarray* elementsDescriptorsIndex, int iBitmapOperator) { int bitmapSize = 0, iDelayedReplication = 0; @@ -1733,7 +1532,7 @@ static int build_bitmap_new_data(grib_accessor_bufr_data_array* self, unsigned c } /* ECC-1304: Will return an index if successful. In case of an error, a negative number is returned e.g. GRIB_WRONG_BITMAP_SIZE */ -static int get_next_bitmap_descriptor_index_new_bitmap(grib_accessor_bufr_data_array* self, grib_iarray* elementsDescriptorsIndex, int compressedData) +static int get_next_bitmap_descriptor_index_new_bitmap(grib_accessor_bufr_data_array_t* self, grib_iarray* elementsDescriptorsIndex, int compressedData) { int i; bufr_descriptor** descriptors = self->expanded->v; @@ -1771,7 +1570,7 @@ static int get_next_bitmap_descriptor_index_new_bitmap(grib_accessor_bufr_data_a } /* ECC-1304: Will return an index if successful. In case of an error, a negative number is returned e.g. GRIB_WRONG_BITMAP_SIZE */ -static int get_next_bitmap_descriptor_index(grib_accessor_bufr_data_array* self, grib_iarray* elementsDescriptorsIndex, grib_darray* numericValues) +static int get_next_bitmap_descriptor_index(grib_accessor_bufr_data_array_t* self, grib_iarray* elementsDescriptorsIndex, grib_darray* numericValues) { int i; bufr_descriptor** descriptors = self->expanded->v; @@ -1813,7 +1612,7 @@ static int get_next_bitmap_descriptor_index(grib_accessor_bufr_data_array* self, return elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]; } -static void push_zero_element(grib_accessor_bufr_data_array* self, grib_darray* dval) +static void push_zero_element(grib_accessor_bufr_data_array_t* self, grib_darray* dval) { grib_darray* d = 0; grib_accessor* a = (grib_accessor*)self; @@ -1846,19 +1645,16 @@ static grib_accessor* create_attribute_variable(const char* name, grib_section* len = 1; switch (type) { case GRIB_TYPE_LONG: - grib_pack_long(a, &lval, &len); - break; + a->pack_long(&lval, &len); break; case GRIB_TYPE_DOUBLE: - grib_pack_double(a, &dval, &len); - break; + a->pack_double(&dval, &len); break; case GRIB_TYPE_STRING: if (!sval) return NULL; /* Performance: No need for len=strlen(sval). It's not used. */ /* See grib_accessor_class_variable.c, pack_string() */ len = 0; - grib_pack_string(a, sval, &len); - break; + a->pack_string(sval, &len); break; } return a; @@ -1951,7 +1747,7 @@ static grib_accessor* create_accessor_from_descriptor(const grib_accessor* a, gr long ide, long subset, int add_dump_flag, int add_coord_flag, int count, int add_extra_attributes) { - grib_accessor_bufr_data_array* self = (grib_accessor_bufr_data_array*)a; + grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; char code[10] = {0,}; char* temp_str = NULL; int idx = 0; @@ -2014,13 +1810,13 @@ static grib_accessor* create_accessor_from_descriptor(const grib_accessor* a, gr if (attribute->attributes[i]) attribute->attributes[i]->parent=elementAccessor->parent; } */ - grib_accessor_add_attribute(elementAccessor, attribute, 0); + elementAccessor->add_attribute(attribute, 0); } attribute = create_attribute_variable("index", section, GRIB_TYPE_LONG, 0, 0, count, flags); if (!attribute) return NULL; - grib_accessor_add_attribute(elementAccessor, attribute, 0); + elementAccessor->add_attribute(attribute, 0); snprintf(code, sizeof(code), "%06ld", self->expanded->v[idx]->code); temp_str = grib_context_strdup(a->context, code); @@ -2028,28 +1824,28 @@ static grib_accessor* create_accessor_from_descriptor(const grib_accessor* a, gr if (!attribute) return NULL; grib_sarray_push(a->context, self->tempStrings, temp_str); /* ECC-325: store alloc'd string (due to strdup) for clean up later */ - grib_accessor_add_attribute(elementAccessor, attribute, 0); + elementAccessor->add_attribute(attribute, 0); if (add_extra_attributes) { attribute = create_attribute_variable("units", section, GRIB_TYPE_STRING, self->expanded->v[idx]->units, 0, 0, GRIB_ACCESSOR_FLAG_DUMP | flags); if (!attribute) return NULL; - grib_accessor_add_attribute(elementAccessor, attribute, 0); + elementAccessor->add_attribute(attribute, 0); attribute = create_attribute_variable("scale", section, GRIB_TYPE_LONG, 0, 0, self->expanded->v[idx]->scale, flags); if (!attribute) return NULL; - grib_accessor_add_attribute(elementAccessor, attribute, 0); + elementAccessor->add_attribute(attribute, 0); attribute = create_attribute_variable("reference", section, GRIB_TYPE_DOUBLE, 0, self->expanded->v[idx]->reference, 0, flags); if (!attribute) return NULL; - grib_accessor_add_attribute(elementAccessor, attribute, 0); + elementAccessor->add_attribute(attribute, 0); attribute = create_attribute_variable("width", section, GRIB_TYPE_LONG, 0, 0, self->expanded->v[idx]->width, flags); if (!attribute) return NULL; - grib_accessor_add_attribute(elementAccessor, attribute, 0); + elementAccessor->add_attribute(attribute, 0); } break; case 2: @@ -2071,7 +1867,7 @@ static grib_accessor* create_accessor_from_descriptor(const grib_accessor* a, gr attribute = create_attribute_variable("index", section, GRIB_TYPE_LONG, 0, 0, count, flags); if (!attribute) return NULL; - grib_accessor_add_attribute(elementAccessor, attribute, 0); + elementAccessor->add_attribute(attribute, 0); } else { elementAccessor = grib_accessor_factory(section, &operatorCreator, 0, NULL); @@ -2080,13 +1876,13 @@ static grib_accessor* create_accessor_from_descriptor(const grib_accessor* a, gr attribute = create_attribute_variable("index", section, GRIB_TYPE_LONG, 0, 0, count, flags); if (!attribute) return NULL; - grib_accessor_add_attribute(elementAccessor, attribute, 0); + elementAccessor->add_attribute(attribute, 0); snprintf(code, sizeof(code), "%06ld", self->expanded->v[idx]->code); attribute = create_attribute_variable("code", section, GRIB_TYPE_STRING, code, 0, 0, flags); if (!attribute) return NULL; - grib_accessor_add_attribute(elementAccessor, attribute, 0); + elementAccessor->add_attribute(attribute, 0); } self->expanded->v[idx]->a = elementAccessor; break; @@ -2106,34 +1902,34 @@ static grib_accessor* create_accessor_from_descriptor(const grib_accessor* a, gr attribute = create_attribute_variable("index", section, GRIB_TYPE_LONG, 0, 0, count, flags); if (!attribute) return NULL; - grib_accessor_add_attribute(elementAccessor, attribute, 0); + elementAccessor->add_attribute(attribute, 0); snprintf(code, sizeof(code), "%06ld", self->expanded->v[idx]->code); attribute = create_attribute_variable("code", section, GRIB_TYPE_STRING, code, 0, 0, flags); if (!attribute) return NULL; - grib_accessor_add_attribute(elementAccessor, attribute, 0); + elementAccessor->add_attribute(attribute, 0); if (add_extra_attributes) { attribute = create_attribute_variable("units", section, GRIB_TYPE_STRING, self->expanded->v[idx]->units, 0, 0, GRIB_ACCESSOR_FLAG_DUMP); if (!attribute) return NULL; - grib_accessor_add_attribute(elementAccessor, attribute, 0); + elementAccessor->add_attribute(attribute, 0); attribute = create_attribute_variable("scale", section, GRIB_TYPE_LONG, 0, 0, self->expanded->v[idx]->scale, flags); if (!attribute) return NULL; - grib_accessor_add_attribute(elementAccessor, attribute, 0); + elementAccessor->add_attribute(attribute, 0); attribute = create_attribute_variable("reference", section, GRIB_TYPE_DOUBLE, 0, self->expanded->v[idx]->reference, 0, flags); if (!attribute) return NULL; - grib_accessor_add_attribute(elementAccessor, attribute, 0); + elementAccessor->add_attribute(attribute, 0); attribute = create_attribute_variable("width", section, GRIB_TYPE_LONG, 0, 0, self->expanded->v[idx]->width, flags); if (!attribute) return NULL; - grib_accessor_add_attribute(elementAccessor, attribute, 0); + elementAccessor->add_attribute(attribute, 0); } break; } @@ -2179,19 +1975,18 @@ static grib_accessor* get_element_from_bitmap(const grib_accessor* a, bitmap_s* while (bitmapVal) { len = 1; if (bitmap->cursor && bitmap->cursor->accessor) { - ret = grib_unpack_long(bitmap->cursor->accessor, &bitmapVal, &len); - } + ret = bitmap->cursor->accessor->unpack_long(&bitmapVal, &len); } else { return NULL; } if (ret != 0) return NULL; - bitmap->cursor = bitmap->cursor->next; + bitmap->cursor = bitmap->cursor->next_; if (bitmap->referredElement) - bitmap->referredElement = bitmap->referredElement->next; + bitmap->referredElement = bitmap->referredElement->next_; } - return bitmap->referredElement ? bitmap->referredElement->prev->accessor : NULL; + return bitmap->referredElement ? bitmap->referredElement->prev_->accessor : NULL; } // static GRIB_INLINE void reset_qualifiers(grib_accessor* significanceQualifierGroup[]) @@ -2211,7 +2006,7 @@ static void grib_convert_to_attribute(grib_accessor* a) /* subsetList can be NULL in which case subsetListSize will be 0 */ static grib_iarray* set_subset_list( - grib_context* c, grib_accessor_bufr_data_array* self, + grib_context* c, grib_accessor_bufr_data_array_t* self, long onlySubset, long startSubset, long endSubset, const long* subsetList, size_t subsetListSize) { grib_iarray* list = grib_iarray_new(c, self->numberOfSubsets, 10); @@ -2258,11 +2053,10 @@ static int bitmap_ref_skip(grib_accessors_list* al, int* err) if (!al || !al->accessor) return 0; - acode = grib_accessor_get_attribute(al->accessor, "code"); + acode = al->accessor->get_attribute("code"); if (acode) - *err = grib_unpack_long(acode, code, &l); - else + *err = acode->unpack_long(code, &l); else return 1; switch (code[0]) { @@ -2291,9 +2085,9 @@ static int is_bitmap_start_descriptor(grib_accessors_list* al, int* err) if (!al || !al->accessor) return 0; - acode = grib_accessor_get_attribute(al->accessor, "code"); + acode = al->accessor->get_attribute("code"); if (acode) - *err = grib_unpack_long(acode, code, &l); + *err = acode->unpack_long(code, &l); else return 1; @@ -2309,7 +2103,7 @@ static int is_bitmap_start_descriptor(grib_accessors_list* al, int* err) { //long index[1]; //grib_accessor* anindex=grib_accessor_get_attribute(al->accessor,"index"); - //grib_unpack_long(anindex,index,&l); + //anindex->unpack_long(index,&l); return 1; } } @@ -2320,7 +2114,7 @@ static void print_bitmap_debug_info(grib_context* c, bitmap_s* bitmap, grib_acce { int i = 0, ret = 0; fprintf(stderr, "ECCODES DEBUG: bitmap_init: bitmapSize=%d\n", bitmapSize); - bitmap->cursor = bitmapStart->next; + bitmap->cursor = bitmapStart->next_; bitmap->referredElement = bitmapStart; while (bitmap_ref_skip(bitmap->referredElement, &ret)) { @@ -2328,7 +2122,7 @@ static void print_bitmap_debug_info(grib_context* c, bitmap_s* bitmap, grib_acce if (is_bitmap_start_descriptor(bitmap->referredElement, &ret)) { is_bmp = 1; } - bitmap->referredElement = bitmap->referredElement->prev; + bitmap->referredElement = bitmap->referredElement->prev_; if (is_bmp) { break; } @@ -2337,7 +2131,7 @@ static void print_bitmap_debug_info(grib_context* c, bitmap_s* bitmap, grib_acce for (i = 1; i < bitmapSize; i++) { if (bitmap->referredElement) { fprintf(stderr, "ECCODES DEBUG:\t bitmap_init: i=%d |%s|\n", i, bitmap->referredElement->accessor->name); - bitmap->referredElement = bitmap->referredElement->prev; + bitmap->referredElement = bitmap->referredElement->prev_; } } } @@ -2346,13 +2140,13 @@ static int bitmap_init(grib_context* c, bitmap_s* bitmap, grib_accessors_list* bitmapStart, int bitmapSize, grib_accessors_list* lastAccessorInList) { int ret = 0, i; - bitmap->cursor = bitmapStart->next; + bitmap->cursor = bitmapStart->next_; if (bitmap->referredElementStart != NULL) { bitmap->referredElement = bitmap->referredElementStart; return ret; } bitmap->referredElement = bitmapStart; - /*while (bitmap_ref_skip(bitmap->referredElement,&ret)) bitmap->referredElement=bitmap->referredElement->prev;*/ + /*while (bitmap_ref_skip(bitmap->referredElement,&ret)) bitmap->referredElement=bitmap->referredElement->prev_;*/ /* See ECC-869 * We have to INCLUDE the replication factors that come after the bitmap operators */ @@ -2361,7 +2155,7 @@ static int bitmap_init(grib_context* c, bitmap_s* bitmap, if (is_bitmap_start_descriptor(bitmap->referredElement, &ret)) { is_bmp = 1; } - bitmap->referredElement = bitmap->referredElement->prev; + bitmap->referredElement = bitmap->referredElement->prev_; if (is_bmp) { break; } @@ -2375,7 +2169,7 @@ static int bitmap_init(grib_context* c, bitmap_s* bitmap, return GRIB_INTERNAL_ERROR; } /*printf(" bitmap_init: i=%d |%s|\n", i,bitmap->referredElement->accessor->name);*/ - bitmap->referredElement = bitmap->referredElement->prev; + bitmap->referredElement = bitmap->referredElement->prev_; } bitmap->referredElementStart = bitmap->referredElement; return ret; @@ -2383,13 +2177,13 @@ static int bitmap_init(grib_context* c, bitmap_s* bitmap, static grib_accessor* accessor_or_attribute_with_same_name(grib_accessor* a, const char* name) { - if (grib_accessor_has_attributes(a) == 0) { + if (a->has_attributes() == 0) { return a; } else { grib_accessor* ok = a; grib_accessor* next; - while ((next = grib_accessor_get_attribute(ok, name)) != NULL) { + while ((next = ok->get_attribute(name)) != NULL) { ok = next; } return ok; @@ -2408,14 +2202,14 @@ static grib_accessor* accessor_or_attribute_with_same_name(grib_accessor* a, con // return *r; // } -static int grib_data_accessors_trie_push(grib_trie_with_rank* accessorsTrie, grib_accessor* a) +int grib_data_accessors_trie_push(grib_trie_with_rank* accessorsTrie, grib_accessor* a) { return grib_trie_with_rank_insert(accessorsTrie, a->name, a); } static int create_keys(const grib_accessor* a, long onlySubset, long startSubset, long endSubset) { - grib_accessor_bufr_data_array* self = (grib_accessor_bufr_data_array*)a; + grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; int err = 0; int rank; grib_accessor* elementAccessor = 0; @@ -2509,7 +2303,7 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset /*if (associatedFieldAccessor) grib_accessor_delete(c, associatedFieldAccessor);*/ associatedFieldAccessor = NULL; if (associatedFieldSignificanceAccessor) { - grib_accessor_delete(c, associatedFieldSignificanceAccessor); + associatedFieldSignificanceAccessor->destroy(c); associatedFieldSignificanceAccessor = NULL; } for (ide = 0; ide < elementsInSubset; ide++) { @@ -2577,7 +2371,7 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset //return err; bitmapIndex--; } - bitmapStart[bitmapIndex] = grib_accessors_list_last(self->dataAccessors); + bitmapStart[bitmapIndex] = self->dataAccessors->last(); bitmapSize[bitmapIndex] = 1; if (self->expanded->v[idx - 1]->code == 31002 || self->expanded->v[idx - 1]->code == 31001) extraElement += 1; @@ -2659,11 +2453,10 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset creatorsn.name = (char*)"subsetNumber"; asn = grib_accessor_factory(section, &creatorsn, 0, NULL); accessor_variable_set_type(asn, GRIB_TYPE_LONG); - grib_pack_long(asn, &subsetNumber, &len); - + asn->pack_long(&subsetNumber, &len); grib_push_accessor(asn, section->block); rank = grib_data_accessors_trie_push(self->dataAccessorsTrie, asn); - grib_accessors_list_push(self->dataAccessors, asn, rank); + self->dataAccessors->push(asn, rank); } count++; elementAccessor = create_accessor_from_descriptor(a, associatedFieldAccessor, section, ide, iss, @@ -2681,16 +2474,17 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset if (elementFromBitmap && self->unpackMode == CODES_BUFR_UNPACK_STRUCTURE) { if (descriptor->code != 33007 && descriptor->code != 223255) { char* aname = grib_context_strdup(c, elementFromBitmap->name); - grib_accessor* newAccessor = grib_accessor_clone(elementAccessor, section, &err); + grib_accessor* newAccessor = elementAccessor->clone(section, &err); newAccessor->parent = groupSection; newAccessor->name = aname; grib_sarray_push(a->context, self->tempStrings, aname); grib_push_accessor(newAccessor, groupSection->block); rank = grib_data_accessors_trie_push(self->dataAccessorsTrie, newAccessor); - grib_accessors_list_push(self->dataAccessors, newAccessor, rank); + self->dataAccessors->push(newAccessor, rank); } - err = grib_accessor_add_attribute(accessor_or_attribute_with_same_name(elementFromBitmap, elementAccessor->name), elementAccessor, 1); + //err = grib_accessor_add_attribute(accessor_or_attribute_with_same_name(elementFromBitmap, elementAccessor->name), elementAccessor, 1); + err = accessor_or_attribute_with_same_name(elementFromBitmap, elementAccessor->name)->add_attribute( elementAccessor, 1); } else if (elementAccessor) { int add_key = 1; @@ -2700,17 +2494,17 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset associatedFieldAccessor = elementAccessor; grib_convert_to_attribute(associatedFieldAccessor); if (associatedFieldSignificanceAccessor) { - grib_accessor* newAccessor = grib_accessor_clone(associatedFieldSignificanceAccessor, section, &err); + grib_accessor* newAccessor = associatedFieldSignificanceAccessor->clone(section, &err); if (err) { grib_context_log(a->context, GRIB_LOG_ERROR,"Unable to clone accessor '%s'\n", associatedFieldSignificanceAccessor->name); return err; } - grib_accessor_add_attribute(associatedFieldAccessor, newAccessor, 1); + associatedFieldAccessor->add_attribute(newAccessor, 1); } break; case 31021: if (associatedFieldSignificanceAccessor) - grib_accessor_delete(c, associatedFieldSignificanceAccessor); + associatedFieldSignificanceAccessor->destroy(c); associatedFieldSignificanceAccessor = elementAccessor; break; /*case 33007:*/ @@ -2728,8 +2522,8 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset if (add_key) { grib_push_accessor(elementAccessor, section->block); rank = grib_data_accessors_trie_push(self->dataAccessorsTrie, elementAccessor); - grib_accessors_list_push(self->dataAccessors, elementAccessor, rank); - lastAccessorInList = grib_accessors_list_last(self->dataAccessors); + self->dataAccessors->push(elementAccessor, rank); + lastAccessorInList = self->dataAccessors->last(); } } } @@ -2739,7 +2533,7 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset return err; } -static void set_input_replications(grib_handle* h, grib_accessor_bufr_data_array* self) +static void set_input_replications(grib_handle* h, grib_accessor_bufr_data_array_t* self) { size_t nInputReplications; size_t nInputExtendedReplications; @@ -2785,7 +2579,7 @@ static void set_input_replications(grib_handle* h, grib_accessor_bufr_data_array } } -static void set_input_bitmap(grib_handle* h, grib_accessor_bufr_data_array* self) +static void set_input_bitmap(grib_handle* h, grib_accessor_bufr_data_array_t* self) { size_t nInputBitmap; self->nInputBitmap = -1; @@ -2846,7 +2640,7 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st grib_darray* dval = NULL; grib_sarray* sval = NULL; - grib_accessor_bufr_data_array* self = (grib_accessor_bufr_data_array*)a; + grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; grib_handle* h = grib_handle_of_accessor(a); grib_context* c = h->context; @@ -3373,19 +3167,17 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st return err; } -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - // grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a; +void grib_accessor_class_bufr_data_array_t::dump(grib_accessor* a, grib_dumper* dumper){ + // grib_accessor_bufr_data_array_t *self =(grib_accessor_bufr_data_array_t*)a; // int err=process_elements(a,PROCESS_DECODE); // grib_dump_section(dumper,a,self->dataKeys->block); return; } -static int value_count(grib_accessor* a, long* count) -{ +int grib_accessor_class_bufr_data_array_t::value_count(grib_accessor* a, long* count){ int err = 0, l; long i; - grib_accessor_bufr_data_array* self = (grib_accessor_bufr_data_array*)a; + grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; err = process_elements(a, PROCESS_DECODE, 0, 0, 0); if (err) @@ -3405,13 +3197,12 @@ static int value_count(grib_accessor* a, long* count) return err; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ +int grib_accessor_class_bufr_data_array_t::unpack_double(grib_accessor* a, double* val, size_t* len){ int err = 0, i, k, ii; int proc_flag = PROCESS_DECODE; size_t l = 0, elementsInSubset; long numberOfSubsets = 0; - grib_accessor_bufr_data_array* self = (grib_accessor_bufr_data_array*)a; + grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; if (self->unpackMode == CODES_BUFR_NEW_DATA) proc_flag = PROCESS_NEW_DATA; @@ -3459,9 +3250,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) return GRIB_SUCCESS; } -static void destroy(grib_context* c, grib_accessor* a) -{ - grib_accessor_bufr_data_array* self = (grib_accessor_bufr_data_array*)a; +void grib_accessor_class_bufr_data_array_t::destroy(grib_context* c, grib_accessor* a){ + grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; self_clear(c, self); if (self->dataAccessors) grib_accessors_list_delete(c, self->dataAccessors); @@ -3481,4 +3271,5 @@ static void destroy(grib_context* c, grib_accessor* a) } grib_iarray_delete(self->iss_list); + grib_accessor_class_gen_t::destroy(c, a); } diff --git a/src/accessor/grib_accessor_class_bufr_data_array.h b/src/accessor/grib_accessor_class_bufr_data_array.h new file mode 100644 index 000000000..75d02b9b4 --- /dev/null +++ b/src/accessor/grib_accessor_class_bufr_data_array.h @@ -0,0 +1,89 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_bufr_data_array_t : public grib_accessor_gen_t +{ +public: + const char* bufrDataEncodedName; + const char* numberOfSubsetsName; + const char* expandedDescriptorsName; + const char* flagsName; + const char* unitsName; + const char* elementsDescriptorsIndexName; + const char* compressedDataName; + bufr_descriptors_array* expanded; + grib_accessor* expandedAccessor; + int* canBeMissing; + long numberOfSubsets; + long compressedData; + grib_vdarray* numericValues; + grib_vsarray* stringValues; + grib_viarray* elementsDescriptorsIndex; + int do_decode; + int bitmapStartElementsDescriptorsIndex; + int bitmapCurrentElementsDescriptorsIndex; + int bitmapSize; + int bitmapStart; + int bitmapCurrent; + grib_accessors_list* dataAccessors; + int unpackMode; + int bitsToEndData; + grib_section* dataKeys; + double* inputBitmap; + int nInputBitmap; + int iInputBitmap; + long* inputReplications; + int nInputReplications; + int iInputReplications; + long* inputExtendedReplications; + int nInputExtendedReplications; + int iInputExtendedReplications; + long* inputShortReplications; + int nInputShortReplications; + int iInputShortReplications; + grib_iarray* iss_list; + grib_trie_with_rank* dataAccessorsTrie; + grib_sarray* tempStrings; + grib_vdarray* tempDoubleValues; + int change_ref_value_operand; + size_t refValListSize; + long* refValList; + long refValIndex; + bufr_tableb_override* tableb_override; + int set_to_missing_if_out_of_range; +}; + +class grib_accessor_class_bufr_data_array_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_bufr_data_array_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_data_array_t{}; } + int get_native_type(grib_accessor*) override; + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + long byte_count(grib_accessor*) override; + long byte_offset(grib_accessor*) override; + long next_offset(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void destroy(grib_context*, grib_accessor*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; + +grib_vsarray* accessor_bufr_data_array_get_stringValues(grib_accessor* a); +grib_accessors_list* accessor_bufr_data_array_get_dataAccessors(grib_accessor* a); +grib_trie_with_rank* accessor_bufr_data_array_get_dataAccessorsTrie(grib_accessor* a); +void accessor_bufr_data_array_set_unpackMode(grib_accessor* a, int unpackMode); + diff --git a/src/grib_accessor_class_bufr_data_element.cc b/src/accessor/grib_accessor_class_bufr_data_element.cc similarity index 62% rename from src/grib_accessor_class_bufr_data_element.cc rename to src/accessor/grib_accessor_class_bufr_data_element.cc index 3301eb10f..8d483b96d 100644 --- a/src/grib_accessor_class_bufr_data_element.cc +++ b/src/accessor/grib_accessor_class_bufr_data_element.cc @@ -8,147 +8,22 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -/***************************************** - * Enrico Fucile - ****************************************/ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init;dump - IMPLEMENTS = unpack_string;unpack_string_array;unpack_long; unpack_double - IMPLEMENTS = unpack_double_element ; is_missing - IMPLEMENTS = pack_long; pack_double ; pack_string_array; pack_string; pack_missing - IMPLEMENTS = value_count; get_native_type; make_clone; destroy - MEMBERS = long index - MEMBERS = int type - MEMBERS = long compressedData - MEMBERS = long subsetNumber - MEMBERS = long numberOfSubsets - MEMBERS = bufr_descriptors_array* descriptors - MEMBERS = grib_vdarray* numericValues - MEMBERS = grib_vsarray* stringValues - MEMBERS = grib_viarray* elementsDescriptorsIndex - MEMBERS = char* cname - - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_missing(grib_accessor*); -static int is_missing(grib_accessor*); -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int pack_string(grib_accessor*, const char*, size_t* len); -static int pack_string_array(grib_accessor*, const char**, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static int unpack_string_array(grib_accessor*, char**, size_t* len); -static int value_count(grib_accessor*, long*); -static void destroy(grib_context*, grib_accessor*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); -static int unpack_double_element(grib_accessor*, size_t i, double* val); -static grib_accessor* make_clone(grib_accessor*, grib_section*, int*); - -typedef struct grib_accessor_bufr_data_element -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in bufr_data_element */ - long index; - int type; - long compressedData; - long subsetNumber; - long numberOfSubsets; - bufr_descriptors_array* descriptors; - grib_vdarray* numericValues; - grib_vsarray* stringValues; - grib_viarray* elementsDescriptorsIndex; - char* cname; -} grib_accessor_bufr_data_element; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_bufr_data_element = { - &grib_accessor_class_gen, /* super */ - "bufr_data_element", /* name */ - sizeof(grib_accessor_bufr_data_element), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - &destroy, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - &pack_missing, /* pack_missing */ - &is_missing, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - &pack_string, /* pack_string */ - &unpack_string, /* unpack_string */ - &pack_string_array, /* pack_string_array */ - &unpack_string_array, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - &unpack_double_element, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - &make_clone, /* clone accessor */ -}; - +#include "grib_accessor_class_bufr_data_element.h" +grib_accessor_class_bufr_data_element_t _grib_accessor_class_bufr_data_element{ "bufr_data_element" }; grib_accessor_class* grib_accessor_class_bufr_data_element = &_grib_accessor_class_bufr_data_element; -/* END_CLASS_IMP */ - -static grib_accessor* make_clone(grib_accessor* a, grib_section* s, int* err) +grib_accessor* grib_accessor_class_bufr_data_element_t::make_clone(grib_accessor* a, grib_section* s, int* err) { grib_accessor* the_clone = NULL; grib_accessor* attribute = NULL; - grib_accessor_bufr_data_element* elementAccessor; - grib_accessor_bufr_data_element* self; + grib_accessor_bufr_data_element_t* elementAccessor; + grib_accessor_bufr_data_element_t* self; char* copied_name = NULL; int i; - grib_action creator = {0,}; + grib_action creator = { + 0, + }; creator.op = (char*)"bufr_data_element"; creator.name_space = (char*)""; creator.set = 0; @@ -161,8 +36,8 @@ static grib_accessor* make_clone(grib_accessor* a, grib_section* s, int* err) the_clone = grib_accessor_factory(s, &creator, 0, NULL); copied_name = grib_context_strdup(a->context, a->name); the_clone->name = copied_name; - elementAccessor = (grib_accessor_bufr_data_element*)the_clone; - self = (grib_accessor_bufr_data_element*)a; + elementAccessor = (grib_accessor_bufr_data_element_t*)the_clone; + self = (grib_accessor_bufr_data_element_t*)a; the_clone->flags = a->flags; the_clone->parent = NULL; the_clone->h = s->h; @@ -179,9 +54,9 @@ static grib_accessor* make_clone(grib_accessor* a, grib_section* s, int* err) i = 0; while (a->attributes[i]) { - attribute = grib_accessor_clone(a->attributes[i], s, err); + attribute = a->attributes[i]->clone(s, err); /* attribute->parent=a->parent; */ - grib_accessor_add_attribute(the_clone, attribute, 0); + the_clone->add_attribute(attribute, 0); i++; } @@ -190,68 +65,69 @@ static grib_accessor* make_clone(grib_accessor* a, grib_section* s, int* err) void accessor_bufr_data_element_set_index(grib_accessor* a, long index) { - grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - self->index = index; + grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; + self->index = index; } void accessor_bufr_data_element_set_type(grib_accessor* a, int type) { - grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - self->type = type; + grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; + self->type = type; } void accessor_bufr_data_element_set_numberOfSubsets(grib_accessor* a, long numberOfSubsets) { - grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - self->numberOfSubsets = numberOfSubsets; + grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; + self->numberOfSubsets = numberOfSubsets; } void accessor_bufr_data_element_set_subsetNumber(grib_accessor* a, long subsetNumber) { - grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - self->subsetNumber = subsetNumber; + grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; + self->subsetNumber = subsetNumber; } void accessor_bufr_data_element_set_compressedData(grib_accessor* a, int compressedData) { - grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - self->compressedData = compressedData; + grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; + self->compressedData = compressedData; } void accessor_bufr_data_element_set_descriptors(grib_accessor* a, bufr_descriptors_array* descriptors) { - grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - self->descriptors = descriptors; + grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; + self->descriptors = descriptors; } void accessor_bufr_data_element_set_numericValues(grib_accessor* a, grib_vdarray* numericValues) { - grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - self->numericValues = numericValues; + grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; + self->numericValues = numericValues; } void accessor_bufr_data_element_set_stringValues(grib_accessor* a, grib_vsarray* stringValues) { - grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - self->stringValues = stringValues; + grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; + self->stringValues = stringValues; } void accessor_bufr_data_element_set_elementsDescriptorsIndex(grib_accessor* a, grib_viarray* elementsDescriptorsIndex) { - grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - self->elementsDescriptorsIndex = elementsDescriptorsIndex; + grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; + self->elementsDescriptorsIndex = elementsDescriptorsIndex; } -static void init(grib_accessor* a, const long len, grib_arguments* params) +void grib_accessor_class_bufr_data_element_t::init(grib_accessor* a, const long len, grib_arguments* params) { - grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - a->length = 0; + grib_accessor_class_gen_t::init(a, len, params); + grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; + a->length = 0; a->flags |= GRIB_ACCESSOR_FLAG_BUFR_DATA; /* a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; */ self->cname = NULL; } -static void dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_class_bufr_data_element_t::dump(grib_accessor* a, grib_dumper* dumper) { int type = get_native_type(a); @@ -268,9 +144,9 @@ static void dump(grib_accessor* a, grib_dumper* dumper) } } -static int unpack_string_array(grib_accessor* a, char** val, size_t* len) +int grib_accessor_class_bufr_data_element_t::unpack_string_array(grib_accessor* a, char** val, size_t* len) { - grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; + grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; int ret = 0, idx = 0; size_t count = 0, i = 0; @@ -289,7 +165,7 @@ static int unpack_string_array(grib_accessor* a, char** val, size_t* len) else { DEBUG_ASSERT(self->subsetNumber < self->numericValues->n); DEBUG_ASSERT(self->index < self->numericValues->v[self->subsetNumber]->n); - idx = (int)self->numericValues->v[self->subsetNumber]->v[self->index] / 1000 - 1; + idx = (int)self->numericValues->v[self->subsetNumber]->v[self->index] / 1000 - 1; val[0] = grib_context_strdup(c, self->stringValues->v[idx]->v[0]); *len = 1; } @@ -297,13 +173,13 @@ static int unpack_string_array(grib_accessor* a, char** val, size_t* len) return ret; } -static int pack_string_array(grib_accessor* a, const char** v, size_t* len) +int grib_accessor_class_bufr_data_element_t::pack_string_array(grib_accessor* a, const char** v, size_t* len) { - grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; + grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; int ret = GRIB_SUCCESS, idx = 0; - size_t i = 0; - char* s = NULL; + size_t i = 0; + char* s = NULL; grib_context* c = a->context; if (self->compressedData) { @@ -322,32 +198,32 @@ static int pack_string_array(grib_accessor* a, const char** v, size_t* len) } } else { - //ECC-1623 + // ECC-1623 if (*len != (size_t)self->numberOfSubsets) { grib_context_log(c, GRIB_LOG_ERROR, - "Number of values mismatch for '%s': %zu strings provided but expected %ld (=number of subsets)", - a->name, *len, self->numberOfSubsets); + "Number of values mismatch for '%s': %zu strings provided but expected %ld (=number of subsets)", + a->name, *len, self->numberOfSubsets); return GRIB_WRONG_ARRAY_SIZE; } for (i = 0; i < *len; i++) { - //idx = (int)self->numericValues->v[self->subsetNumber]->v[self->index] / 1000 - 1; - idx = (int)self->numericValues->v[i]->v[self->index] / 1000 - 1; + // idx = (int)self->numericValues->v[self->subsetNumber]->v[self->index] / 1000 - 1; + idx = (int)self->numericValues->v[i]->v[self->index] / 1000 - 1; self->stringValues->v[idx]->v[0] = strdup(v[i]); } - *len=1; + *len = 1; } return ret; } -static int unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_class_bufr_data_element_t::unpack_string(grib_accessor* a, char* val, size_t* len) { - grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - char* str = NULL; - char* p = 0; - size_t slen = 0; - double dval = 0; - size_t dlen = 1; + grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; + char* str = NULL; + char* p = 0; + size_t slen = 0; + double dval = 0; + size_t dlen = 1; int idx = 0, err = 0; grib_context* c = a->context; @@ -409,12 +285,12 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len) return GRIB_SUCCESS; } -static int pack_string(grib_accessor* a, const char* val, size_t* len) +int grib_accessor_class_bufr_data_element_t::pack_string(grib_accessor* a, const char* val, size_t* len) { - grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; + grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; int ret = GRIB_SUCCESS, idx = 0; - char* s = NULL; + char* s = NULL; grib_context* c = a->context; if (self->compressedData) { @@ -426,16 +302,16 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len) grib_sarray_delete_content(c, self->stringValues->v[idx]); /* ECC-1172 */ grib_sarray_delete(c, self->stringValues->v[idx]); self->stringValues->v[idx] = grib_sarray_new(c, 1, 1); - s = grib_context_strdup(c, val); + s = grib_context_strdup(c, val); grib_sarray_push(c, self->stringValues->v[idx], s); return ret; } -static int unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_class_bufr_data_element_t::unpack_long(grib_accessor* a, long* val, size_t* len) { - grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - int ret = GRIB_SUCCESS; + grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; + int ret = GRIB_SUCCESS; long count = 0, i = 0; value_count(a, &count); @@ -461,10 +337,10 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) return ret; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_class_bufr_data_element_t::unpack_double(grib_accessor* a, double* val, size_t* len) { - grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - int ret = GRIB_SUCCESS; + grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; + int ret = GRIB_SUCCESS; long count = 0, i = 0; value_count(a, &count); @@ -490,10 +366,10 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) return ret; } -static int pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_class_bufr_data_element_t::pack_double(grib_accessor* a, const double* val, size_t* len) { - grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - int ret = GRIB_SUCCESS; + grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; + int ret = GRIB_SUCCESS; size_t count = 1, i = 0; grib_context* c = a->context; @@ -514,16 +390,16 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) } else { self->numericValues->v[self->subsetNumber]->v[self->index] = val[0]; - *len = 1; + *len = 1; } return ret; } -static int pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_class_bufr_data_element_t::pack_long(grib_accessor* a, const long* val, size_t* len) { - grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - int ret = 0; + grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; + int ret = 0; size_t count = 1, i = 0; grib_context* c = a->context; @@ -544,17 +420,17 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) } else { self->numericValues->v[self->subsetNumber]->v[self->index] = val[0] == GRIB_MISSING_LONG ? GRIB_MISSING_DOUBLE : val[0]; - *len = 1; + *len = 1; } return ret; } -static int value_count(grib_accessor* a, long* count) +int grib_accessor_class_bufr_data_element_t::value_count(grib_accessor* a, long* count) { int ret = 0, type = 0, idx = 0; - size_t size = 0; - grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; + size_t size = 0; + grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; if (!self->compressedData) { *count = 1; @@ -577,12 +453,12 @@ static int value_count(grib_accessor* a, long* count) return ret; } -static int unpack_double_element(grib_accessor* a, size_t idx, double* val) +int grib_accessor_class_bufr_data_element_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) { /* ECC-415 */ - grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - int ret = GRIB_SUCCESS; - long count = 0; + grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; + int ret = GRIB_SUCCESS; + long count = 0; value_count(a, &count); if (idx >= (size_t)count) { @@ -598,10 +474,10 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) return ret; } -static int get_native_type(grib_accessor* a) +int grib_accessor_class_bufr_data_element_t::get_native_type(grib_accessor* a) { - grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - int ret = GRIB_TYPE_DOUBLE; + grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; + int ret = GRIB_TYPE_DOUBLE; DEBUG_ASSERT(self); switch (self->type) { case BUFR_DESCRIPTOR_TYPE_STRING: @@ -624,24 +500,25 @@ static int get_native_type(grib_accessor* a) return ret; } -static void destroy(grib_context* ct, grib_accessor* a) +void grib_accessor_class_bufr_data_element_t::destroy(grib_context* ct, grib_accessor* a) { - grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a; - int i = 0; + grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; + int i = 0; if (self->cname) grib_context_free(ct, self->cname); /* ECC-765 */ while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes[i]) { /*grib_context_log(ct,GRIB_LOG_DEBUG,"deleting attribute %s->%s",a->name,a->attributes[i]->name);*/ /*printf("bufr_data_element destroy %s %p\n", a->attributes[i]->name, (void*)a->attributes[i]);*/ - grib_accessor_delete(ct, a->attributes[i]); + a->attributes[i]->destroy(ct); a->attributes[i] = NULL; i++; } + grib_accessor_class_gen_t::destroy(ct, a); } #define MAX_STRING_SIZE 4096 /* Return 1 if BUFR element(s) is/are missing, 0 otherwise. In case of decoding errors, also return 0 */ -static int is_missing(grib_accessor* a) +int grib_accessor_class_bufr_data_element_t::is_missing(grib_accessor* a) { const int ktype = get_native_type(a); int err = 0, result = 1; /* default: assume all are missing */ @@ -651,16 +528,16 @@ static int is_missing(grib_accessor* a) if (ktype == GRIB_TYPE_LONG) { long* values = NULL; - long value = 0; + long value = 0; value_count(a, &count); size = size2 = count; if (size > 1) { values = (long*)grib_context_malloc_clear(c, sizeof(long) * size); - err = grib_unpack_long(a, values, &size2); + err = a->unpack_long(values, &size2); } else { - err = grib_unpack_long(a, &value, &size2); + err = a->unpack_long(&value, &size2); } if (err) return 0; /* TODO: no way of propagating the error up */ Assert(size2 == size); @@ -672,22 +549,23 @@ static int is_missing(grib_accessor* a) } } grib_context_free(c, values); - } else { + } + else { result = grib_is_missing_long(a, value); } } else if (ktype == GRIB_TYPE_DOUBLE) { - double value = 0; + double value = 0; double* values = NULL; value_count(a, &count); size = size2 = count; if (size > 1) { values = (double*)grib_context_malloc_clear(c, sizeof(double) * size); - err = grib_unpack_double(a, values, &size2); + err = a->unpack_double(values, &size2); } else { - err = grib_unpack_double(a, &value, &size2); + err = a->unpack_double(&value, &size2); } if (err) return 0; /* TODO: no way of propagating the error up */ Assert(size2 == size); @@ -710,7 +588,7 @@ static int is_missing(grib_accessor* a) size = count; if (size > 1) { values = (char**)grib_context_malloc_clear(a->context, size * sizeof(char*)); - err = grib_unpack_string_array(a, values, &size); + err = a->unpack_string_array(values, &size); if (err) return 0; /* TODO: no way of propagating the error up */ for (i = 0; i < size; i++) { if (!grib_is_missing_string(a, (unsigned char*)values[i], size)) { @@ -718,12 +596,14 @@ static int is_missing(grib_accessor* a) break; } } - for (i = 0; i < size; i++) grib_context_free(c, values[i]); + for (i = 0; i < size; i++) + grib_context_free(c, values[i]); grib_context_free(c, values); - } else { + } + else { char value[MAX_STRING_SIZE] = {0,}; /* See ECC-710 */ size = MAX_STRING_SIZE; - err = grib_unpack_string(a, value, &size); + err = a->unpack_string(value, &size); if (err) return 0; /* TODO: no way of propagating the error up */ result = grib_is_missing_string(a, (unsigned char*)value, size); } @@ -734,11 +614,11 @@ static int is_missing(grib_accessor* a) return result; } -static int pack_missing(grib_accessor* a) +int grib_accessor_class_bufr_data_element_t::pack_missing(grib_accessor* a) { - int ktype = GRIB_TYPE_UNDEFINED; - int err = 0; - size_t size = 1; + int ktype = GRIB_TYPE_UNDEFINED; + int err = 0; + size_t size = 1; const int can_be_missing = (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING); if (!can_be_missing) return GRIB_VALUE_CANNOT_BE_MISSING; @@ -746,11 +626,11 @@ static int pack_missing(grib_accessor* a) ktype = get_native_type(a); if (ktype == GRIB_TYPE_LONG) { long missing = GRIB_MISSING_LONG; - err = pack_long(a, &missing, &size); + err = pack_long(a, &missing, &size); } else if (ktype == GRIB_TYPE_DOUBLE) { double missing = GRIB_MISSING_DOUBLE; - err = pack_double(a, &missing, &size); + err = pack_double(a, &missing, &size); } else if (ktype == GRIB_TYPE_STRING) { err = pack_string(a, "", &size); diff --git a/src/accessor/grib_accessor_class_bufr_data_element.h b/src/accessor/grib_accessor_class_bufr_data_element.h new file mode 100644 index 000000000..bbed1785b --- /dev/null +++ b/src/accessor/grib_accessor_class_bufr_data_element.h @@ -0,0 +1,54 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_bufr_data_element_t : public grib_accessor_gen_t +{ +public: + /* Members defined in bufr_data_element */ + long index; + int type; + long compressedData; + long subsetNumber; + long numberOfSubsets; + bufr_descriptors_array* descriptors; + grib_vdarray* numericValues; + grib_vsarray* stringValues; + grib_viarray* elementsDescriptorsIndex; + char* cname; +}; + +class grib_accessor_class_bufr_data_element_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_bufr_data_element_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_data_element_t{}; } + int get_native_type(grib_accessor*) override; + int pack_missing(grib_accessor*) override; + int is_missing(grib_accessor*) override; + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int pack_string(grib_accessor*, const char*, size_t* len) override; + int pack_string_array(grib_accessor*, const char**, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + int unpack_string_array(grib_accessor*, char**, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void destroy(grib_context*, grib_accessor*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_double_element(grib_accessor*, size_t i, double* val) override; + grib_accessor* make_clone(grib_accessor*, grib_section*, int*) override; +}; diff --git a/src/grib_accessor_class_bufr_elements_table.cc b/src/accessor/grib_accessor_class_bufr_elements_table.cc similarity index 63% rename from src/grib_accessor_class_bufr_elements_table.cc rename to src/accessor/grib_accessor_class_bufr_elements_table.cc index 4858ff63d..ddd055544 100644 --- a/src/grib_accessor_class_bufr_elements_table.cc +++ b/src/accessor/grib_accessor_class_bufr_elements_table.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,12 +9,8 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -/***************************************** - * Enrico Fucile - ****************************************/ - +#include "grib_accessor_class_bufr_elements_table.h" #include "grib_scaling.h" -#include "grib_api_internal.h" #if GRIB_PTHREADS static pthread_once_t once = PTHREAD_ONCE_INIT; @@ -31,7 +28,7 @@ static void thread_init() static int once = 0; static omp_nest_lock_t mutex1; -static void thread_init() +void thread_init() { GRIB_OMP_CRITICAL(lock_grib_accessor_class_bufr_elements_table_c) { @@ -43,107 +40,16 @@ static void thread_init() } #endif -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init;unpack_string;unpack_long;unpack_double - IMPLEMENTS = value_count; get_native_type; - MEMBERS = const char* dictionary - MEMBERS = const char* masterDir - MEMBERS = const char* localDir - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_bufr_elements_table -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in bufr_elements_table */ - const char* dictionary; - const char* masterDir; - const char* localDir; -} grib_accessor_bufr_elements_table; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_bufr_elements_table = { - &grib_accessor_class_gen, /* super */ - "bufr_elements_table", /* name */ - sizeof(grib_accessor_bufr_elements_table), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +grib_accessor_class_bufr_elements_table_t _grib_accessor_class_bufr_elements_table{ "bufr_elements_table" }; grib_accessor_class* grib_accessor_class_bufr_elements_table = &_grib_accessor_class_bufr_elements_table; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long len, grib_arguments* params) +void grib_accessor_class_bufr_elements_table_t::init(grib_accessor* a, const long len, grib_arguments* params) { - int n = 0; - grib_accessor_bufr_elements_table* self = (grib_accessor_bufr_elements_table*)a; + grib_accessor_class_gen_t::init(a, len, params); + int n = 0; + grib_accessor_bufr_elements_table_t* self = (grib_accessor_bufr_elements_table_t*)a; self->dictionary = grib_arguments_get_string(grib_handle_of_accessor(a), params, n++); self->masterDir = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++); @@ -155,7 +61,7 @@ static void init(grib_accessor* a, const long len, grib_arguments* params) static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err) { - grib_accessor_bufr_elements_table* self = (grib_accessor_bufr_elements_table*)a; + grib_accessor_bufr_elements_table_t* self = (grib_accessor_bufr_elements_table_t*)a; char* filename = NULL; char line[1024] = {0,}; @@ -163,7 +69,9 @@ static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err) char localDir[1024] = {0,}; char dictName[1024] = {0,}; char masterRecomposed[1024] = {0,}; /*e.g. bufr/tables/0/wmo/36/element.table */ - char localRecomposed[1024] = {0,}; /*e.g. bufr/tables/0/local/0/98/0/element.table */ + char localRecomposed[1024] = { + 0, + }; /*e.g. bufr/tables/0/local/0/98/0/element.table */ char* localFilename = 0; char** list = 0; char** cached_list = 0; @@ -208,9 +116,9 @@ static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err) if (!filename) { grib_context_log(c, GRIB_LOG_ERROR, "Unable to find definition file %s", self->dictionary); - if (strlen(masterRecomposed) > 0) grib_context_log(c, GRIB_LOG_DEBUG,"master path=%s", masterRecomposed); + if (strlen(masterRecomposed) > 0) grib_context_log(c, GRIB_LOG_DEBUG, "master path=%s", masterRecomposed); if (strlen(localRecomposed) > 0) grib_context_log(c, GRIB_LOG_DEBUG, "local path=%s", localRecomposed); - *err = GRIB_FILE_NOT_FOUND; + *err = GRIB_FILE_NOT_FOUND; dictionary = NULL; goto the_end; } @@ -234,7 +142,7 @@ static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err) dictionary = grib_trie_new(c); while (fgets(line, sizeof(line) - 1, f)) { - DEBUG_ASSERT( strlen(line) > 0 ); + DEBUG_ASSERT(strlen(line) > 0); if (line[0] == '#') continue; /* Ignore first line with column titles */ list = string_split(line, "|"); grib_trie_insert(dictionary, list[0], list); @@ -251,14 +159,15 @@ static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err) } while (fgets(line, sizeof(line) - 1, f)) { - DEBUG_ASSERT( strlen(line) > 0 ); - if (line[0] == '#') continue; /* Ignore first line with column titles */ + DEBUG_ASSERT(strlen(line) > 0); + if (line[0] == '#') continue; /* Ignore first line with column titles */ list = string_split(line, "|"); /* Look for the descriptor code in the trie. It might be there from before */ cached_list = (char**)grib_trie_get(dictionary, list[0]); if (cached_list) { /* If found, we are about to overwrite it. So free memory */ int i; - for (i = 0; cached_list[i] != NULL; ++i) free(cached_list[i]); + for (i = 0; cached_list[i] != NULL; ++i) + free(cached_list[i]); free(cached_list); } grib_trie_insert(dictionary, list[0], list); @@ -304,17 +213,18 @@ static int convert_type(const char* stype) return ret; } -static long atol_fast(const char* input) +long atol_fast(const char* input) { if (strcmp(input, "0") == 0) return 0; return atol(input); } -static int bufr_get_from_table(grib_accessor* a, bufr_descriptor* v) + +int bufr_get_from_table(grib_accessor* a, bufr_descriptor* v) { - int ret = 0; - char** list = 0; - char code[7] = { 0 }; + int ret = 0; + char** list = 0; + char code[7] = { 0 }; const size_t codeLen = sizeof(code); grib_trie* table = load_bufr_elements_table(a, &ret); @@ -332,8 +242,8 @@ static int bufr_get_from_table(grib_accessor* a, bufr_descriptor* v) /* ECC-1137: check descriptor key name and unit lengths */ const size_t maxlen_shortName = sizeof(v->shortName); const size_t maxlen_units = sizeof(v->units); - Assert( strlen(list[1]) < maxlen_shortName ); - Assert( strlen(list[4]) < maxlen_units ); + Assert(strlen(list[1]) < maxlen_shortName); + Assert(strlen(list[4]) < maxlen_units); } #endif @@ -407,28 +317,28 @@ bufr_descriptor* accessor_bufr_elements_table_get_descriptor(grib_accessor* a, i return v; } -static int unpack_string(grib_accessor* a, char* buffer, size_t* len) +int grib_accessor_class_bufr_elements_table_t::unpack_string(grib_accessor* a, char* buffer, size_t* len) { return GRIB_NOT_IMPLEMENTED; } -static int value_count(grib_accessor* a, long* count) +int grib_accessor_class_bufr_elements_table_t::value_count(grib_accessor* a, long* count) { *count = 1; return 0; } -static int get_native_type(grib_accessor* a) +int grib_accessor_class_bufr_elements_table_t::get_native_type(grib_accessor* a) { return GRIB_TYPE_STRING; } -static int unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_class_bufr_elements_table_t::unpack_long(grib_accessor* a, long* val, size_t* len) { return GRIB_NOT_IMPLEMENTED; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_class_bufr_elements_table_t::unpack_double(grib_accessor* a, double* val, size_t* len) { return GRIB_NOT_IMPLEMENTED; } diff --git a/src/accessor/grib_accessor_class_bufr_elements_table.h b/src/accessor/grib_accessor_class_bufr_elements_table.h new file mode 100644 index 000000000..4f133c9e4 --- /dev/null +++ b/src/accessor/grib_accessor_class_bufr_elements_table.h @@ -0,0 +1,36 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_bufr_elements_table_t : public grib_accessor_gen_t +{ +public: + /* Members defined in bufr_elements_table */ + const char* dictionary; + const char* masterDir; + const char* localDir; +}; + +class grib_accessor_class_bufr_elements_table_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_bufr_elements_table_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_elements_table_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_bufr_extract_area_subsets.cc b/src/accessor/grib_accessor_class_bufr_extract_area_subsets.cc similarity index 55% rename from src/grib_accessor_class_bufr_extract_area_subsets.cc rename to src/accessor/grib_accessor_class_bufr_extract_area_subsets.cc index 473a5148d..91a34c72c 100644 --- a/src/grib_accessor_class_bufr_extract_area_subsets.cc +++ b/src/accessor/grib_accessor_class_bufr_extract_area_subsets.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,120 +9,18 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init; get_native_type - IMPLEMENTS = pack_long; - MEMBERS = const char* doExtractSubsets - MEMBERS = const char* numberOfSubsets - MEMBERS = const char* extractSubsetList - MEMBERS = const char* extractAreaWestLongitude - MEMBERS = const char* extractAreaEastLongitude - MEMBERS = const char* extractAreaNorthLatitude - MEMBERS = const char* extractAreaSouthLatitude - MEMBERS = const char* extractAreaLongitudeRank - MEMBERS = const char* extractAreaLatitudeRank - MEMBERS = const char* extractedAreaNumberOfSubsets - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_bufr_extract_area_subsets -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in bufr_extract_area_subsets */ - const char* doExtractSubsets; - const char* numberOfSubsets; - const char* extractSubsetList; - const char* extractAreaWestLongitude; - const char* extractAreaEastLongitude; - const char* extractAreaNorthLatitude; - const char* extractAreaSouthLatitude; - const char* extractAreaLongitudeRank; - const char* extractAreaLatitudeRank; - const char* extractedAreaNumberOfSubsets; -} grib_accessor_bufr_extract_area_subsets; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_bufr_extract_area_subsets = { - &grib_accessor_class_gen, /* super */ - "bufr_extract_area_subsets", /* name */ - sizeof(grib_accessor_bufr_extract_area_subsets), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_bufr_extract_area_subsets.h" +grib_accessor_class_bufr_extract_area_subsets_t _grib_accessor_class_bufr_extract_area_subsets{ "bufr_extract_area_subsets" }; grib_accessor_class* grib_accessor_class_bufr_extract_area_subsets = &_grib_accessor_class_bufr_extract_area_subsets; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_class_bufr_extract_area_subsets_t::init(grib_accessor* a, const long len, grib_arguments* arg) { - grib_accessor_bufr_extract_area_subsets* self = (grib_accessor_bufr_extract_area_subsets*)a; - grib_handle* h = grib_handle_of_accessor(a); - int n = 0; + grib_accessor_class_gen_t::init(a, len, arg); + grib_accessor_bufr_extract_area_subsets_t* self = (grib_accessor_bufr_extract_area_subsets_t*)a; + grib_handle* h = grib_handle_of_accessor(a); + int n = 0; a->length = 0; self->doExtractSubsets = grib_arguments_get_name(h, arg, n++); @@ -138,7 +37,7 @@ static void init(grib_accessor* a, const long len, grib_arguments* arg) a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; } -static int get_native_type(grib_accessor* a) +int grib_accessor_class_bufr_extract_area_subsets_t::get_native_type(grib_accessor* a) { return GRIB_TYPE_LONG; } @@ -153,11 +52,11 @@ static void fill_in(double a[], long length) static int select_area(grib_accessor* a) { - grib_accessor_bufr_extract_area_subsets* self = (grib_accessor_bufr_extract_area_subsets*)a; + grib_accessor_bufr_extract_area_subsets_t* self = (grib_accessor_bufr_extract_area_subsets_t*)a; - int ret = 0; + int ret = 0; long compressed = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(a); grib_context* c = h->context; double* lat = NULL; @@ -166,8 +65,8 @@ static int select_area(grib_accessor* a) double lonWest, lonEast, latNorth, latSouth; long numberOfSubsets, i, latRank, lonRank; grib_iarray* subsets = NULL; - size_t nsubsets = 0; - char latstr[32] = {0,}; + size_t nsubsets = 0; + char latstr[32] = {0,}; char lonstr[32] = {0,}; ret = grib_get_long(h, "compressedData", &compressed); @@ -265,7 +164,7 @@ static int select_area(grib_accessor* a) if (nsubsets != 0) { long* subsets_ar = grib_iarray_get_array(subsets); - ret = grib_set_long_array(h, self->extractSubsetList, subsets_ar, nsubsets); + ret = grib_set_long_array(h, self->extractSubsetList, subsets_ar, nsubsets); grib_context_free(c, subsets_ar); if (ret) return ret; @@ -281,9 +180,9 @@ static int select_area(grib_accessor* a) return ret; } -static int pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_class_bufr_extract_area_subsets_t::pack_long(grib_accessor* a, const long* val, size_t* len) { - /*grib_accessor_bufr_extract_area_subsets *self =(grib_accessor_bufr_extract_area_subsets*)a;*/ + /*grib_accessor_bufr_extract_area_subsets_t *self =(grib_accessor_bufr_extract_area_subsets_t*)a;*/ if (*len == 0) return GRIB_SUCCESS; diff --git a/src/accessor/grib_accessor_class_bufr_extract_area_subsets.h b/src/accessor/grib_accessor_class_bufr_extract_area_subsets.h new file mode 100644 index 000000000..941f38ac0 --- /dev/null +++ b/src/accessor/grib_accessor_class_bufr_extract_area_subsets.h @@ -0,0 +1,40 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_bufr_extract_area_subsets_t : public grib_accessor_gen_t +{ +public: + /* Members defined in bufr_extract_area_subsets */ + const char* doExtractSubsets; + const char* numberOfSubsets; + const char* extractSubsetList; + const char* extractAreaWestLongitude; + const char* extractAreaEastLongitude; + const char* extractAreaNorthLatitude; + const char* extractAreaSouthLatitude; + const char* extractAreaLongitudeRank; + const char* extractAreaLatitudeRank; + const char* extractedAreaNumberOfSubsets; +}; + +class grib_accessor_class_bufr_extract_area_subsets_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_bufr_extract_area_subsets_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_extract_area_subsets_t{}; } + int get_native_type(grib_accessor*) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_bufr_extract_datetime_subsets.cc b/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.cc similarity index 71% rename from src/grib_accessor_class_bufr_extract_datetime_subsets.cc rename to src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.cc index d5ec98bf6..d47652984 100644 --- a/src/grib_accessor_class_bufr_extract_datetime_subsets.cc +++ b/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,105 +9,17 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init; get_native_type - IMPLEMENTS = pack_long; - MEMBERS = const char* doExtractSubsets - MEMBERS = const char* numberOfSubsets - MEMBERS = const char* extractSubsetList - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_bufr_extract_datetime_subsets -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in bufr_extract_datetime_subsets */ - const char* doExtractSubsets; - const char* numberOfSubsets; - const char* extractSubsetList; -} grib_accessor_bufr_extract_datetime_subsets; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_bufr_extract_datetime_subsets = { - &grib_accessor_class_gen, /* super */ - "bufr_extract_datetime_subsets", /* name */ - sizeof(grib_accessor_bufr_extract_datetime_subsets), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_bufr_extract_datetime_subsets.h" +grib_accessor_class_bufr_extract_datetime_subsets_t _grib_accessor_class_bufr_extract_datetime_subsets{ "bufr_extract_datetime_subsets" }; grib_accessor_class* grib_accessor_class_bufr_extract_datetime_subsets = &_grib_accessor_class_bufr_extract_datetime_subsets; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_class_bufr_extract_datetime_subsets_t::init(grib_accessor* a, const long len, grib_arguments* arg) { - int n = 0; - grib_accessor_bufr_extract_datetime_subsets* self = (grib_accessor_bufr_extract_datetime_subsets*)a; + grib_accessor_class_gen_t::init(a, len, arg); + int n = 0; + grib_accessor_bufr_extract_datetime_subsets_t* self = (grib_accessor_bufr_extract_datetime_subsets_t*)a; a->length = 0; self->doExtractSubsets = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); @@ -116,13 +29,13 @@ static void init(grib_accessor* a, const long len, grib_arguments* arg) a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; } -static int get_native_type(grib_accessor* a) +int grib_accessor_class_bufr_extract_datetime_subsets_t::get_native_type(grib_accessor* a) { return GRIB_TYPE_LONG; } /* Convert input date to Julian number. If date is invalid, return -1 */ -static double date_to_julian(long year, long month, long day, long hour, long minute, double second) +double date_to_julian(long year, long month, long day, long hour, long minute, double second) { double result = 0; /* Julian number in units of days */ @@ -175,7 +88,9 @@ static int build_long_array(grib_context* c, grib_handle* h, int compressed, } else { /* uncompressed */ - char keystr[32] = {0,}; + char keystr[32] = { + 0, + }; size_t values_len = 0; for (i = 0; i < numberOfSubsets; ++i) { long lVal = 0; @@ -196,14 +111,22 @@ static int build_long_array(grib_context* c, grib_handle* h, int compressed, static int select_datetime(grib_accessor* a) { - int ret = 0; - long compressed = 0; - grib_accessor_bufr_extract_datetime_subsets* self = (grib_accessor_bufr_extract_datetime_subsets*)a; - grib_handle* h = grib_handle_of_accessor(a); - grib_context* c = h->context; + int ret = 0; + long compressed = 0; + grib_accessor_bufr_extract_datetime_subsets_t* self = (grib_accessor_bufr_extract_datetime_subsets_t*)a; + grib_handle* h = grib_handle_of_accessor(a); + grib_context* c = h->context; size_t n; double julianStart = 0, julianEnd = 0, julianDT = 0; - char start_str[80] = {0,}, end_str[80] = {0,}, datetime_str[80] = {0,}; + char start_str[80] = { + 0, + }, + end_str[80] = { + 0, + }, + datetime_str[80] = { + 0, + }; long yearRank, monthRank, dayRank, hourRank, minuteRank, secondRank; long yearStart, monthStart, dayStart, hourStart, minuteStart, secondStart; long yearEnd, monthEnd, dayEnd, hourEnd, minuteEnd, secondEnd; @@ -211,13 +134,13 @@ static int select_datetime(grib_accessor* a) double* second = NULL; long numberOfSubsets, i; grib_iarray* subsets = NULL; - size_t nsubsets = 0; - char yearstr[32] = "year"; - char monthstr[32] = "month"; - char daystr[32] = "day"; - char hourstr[32] = "hour"; - char minutestr[32] = "minute"; - char secondstr[32] = "second"; + size_t nsubsets = 0; + char yearstr[32] = "year"; + char monthstr[32] = "month"; + char daystr[32] = "day"; + char hourstr[32] = "hour"; + char minutestr[32] = "minute"; + char secondstr[32] = "second"; ret = grib_get_long(h, "compressedData", &compressed); if (ret) return ret; @@ -356,7 +279,7 @@ static int select_datetime(grib_accessor* a) if (ret) secondEnd = 0; snprintf(end_str, sizeof(end_str), "%04ld/%02ld/%02ld %02ld:%02ld:%02ld", - yearEnd, monthEnd, dayEnd, hourEnd, minuteEnd, secondEnd); + yearEnd, monthEnd, dayEnd, hourEnd, minuteEnd, secondEnd); if (c->debug) fprintf(stderr, "ECCODES DEBUG bufr_extract_datetime_subsets: end =%s\n", end_str); julianEnd = date_to_julian(yearEnd, monthEnd, dayEnd, hourEnd, minuteEnd, secondEnd); if (julianEnd == -1) { @@ -402,7 +325,7 @@ static int select_datetime(grib_accessor* a) if (nsubsets != 0) { long* subsets_ar = grib_iarray_get_array(subsets); - ret = grib_set_long_array(h, self->extractSubsetList, subsets_ar, nsubsets); + ret = grib_set_long_array(h, self->extractSubsetList, subsets_ar, nsubsets); grib_context_free(c, subsets_ar); if (ret) return ret; @@ -423,9 +346,9 @@ cleanup: return ret; } -static int pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_class_bufr_extract_datetime_subsets_t::pack_long(grib_accessor* a, const long* val, size_t* len) { - /*grib_accessor_bufr_extract_datetime_subsets *self =(grib_accessor_bufr_extract_datetime_subsets*)a;*/ + /*grib_accessor_bufr_extract_datetime_subsets_t *self =(grib_accessor_bufr_extract_datetime_subsets_t*)a;*/ if (*len == 0) return GRIB_SUCCESS; diff --git a/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.h b/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.h new file mode 100644 index 000000000..765786cd2 --- /dev/null +++ b/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.h @@ -0,0 +1,33 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_bufr_extract_datetime_subsets_t : public grib_accessor_gen_t +{ +public: + /* Members defined in bufr_extract_datetime_subsets */ + const char* doExtractSubsets; + const char* numberOfSubsets; + const char* extractSubsetList; +}; + +class grib_accessor_class_bufr_extract_datetime_subsets_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_bufr_extract_datetime_subsets_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_extract_datetime_subsets_t{}; } + int get_native_type(grib_accessor*) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_bufr_extract_subsets.cc b/src/accessor/grib_accessor_class_bufr_extract_subsets.cc new file mode 100644 index 000000000..7d5a23652 --- /dev/null +++ b/src/accessor/grib_accessor_class_bufr_extract_subsets.cc @@ -0,0 +1,58 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_bufr_extract_subsets.h" + +grib_accessor_class_bufr_extract_subsets_t _grib_accessor_class_bufr_extract_subsets{"bufr_extract_subsets"}; +grib_accessor_class* grib_accessor_class_bufr_extract_subsets = &_grib_accessor_class_bufr_extract_subsets; + + +void get_accessors(grib_accessor* a){ + grib_accessor_bufr_extract_subsets_t* self = (grib_accessor_bufr_extract_subsets_t*)a; + const grib_handle* h = grib_handle_of_accessor(a); + + if (self->packAccessor) + return; + self->numericValuesAccessor = grib_find_accessor(h, self->numericValues); + self->packAccessor = grib_find_accessor(h, self->pack); +} + +void grib_accessor_class_bufr_extract_subsets_t::init(grib_accessor* a, const long len, grib_arguments* arg){ + grib_accessor_class_gen_t::init(a, len, arg); + int n = 0; + grib_accessor_bufr_extract_subsets_t* self = (grib_accessor_bufr_extract_subsets_t*)a; + + a->length = 0; + self->numericValues = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); + self->pack = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); + a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; +} + +int grib_accessor_class_bufr_extract_subsets_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_LONG; +} + +int grib_accessor_class_bufr_extract_subsets_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + grib_accessor_bufr_extract_subsets_t* self = (grib_accessor_bufr_extract_subsets_t*)a; + size_t l = 1; + long v[1]; + + get_accessors(a); + + v[0] = 1; + int err = self->packAccessor->pack_long(v, &l); if (err) { + if (err == GRIB_ENCODING_ERROR) + grib_context_log(a->context, GRIB_LOG_ERROR, "Could not extract subset(s).\n\tHint: Did you forget to set unpack=1?"); + return err; + } + + return err; +} diff --git a/src/accessor/grib_accessor_class_bufr_extract_subsets.h b/src/accessor/grib_accessor_class_bufr_extract_subsets.h new file mode 100644 index 000000000..3015d87ae --- /dev/null +++ b/src/accessor/grib_accessor_class_bufr_extract_subsets.h @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_bufr_extract_subsets_t : public grib_accessor_gen_t +{ +public: + /* Members defined in bufr_extract_subsets */ + const char* numericValues; + const char* pack; + grib_accessor* numericValuesAccessor; + grib_accessor* packAccessor; +}; + +class grib_accessor_class_bufr_extract_subsets_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_bufr_extract_subsets_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_extract_subsets_t{}; } + int get_native_type(grib_accessor*) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_bufr_group.cc b/src/accessor/grib_accessor_class_bufr_group.cc new file mode 100644 index 000000000..71249f70d --- /dev/null +++ b/src/accessor/grib_accessor_class_bufr_group.cc @@ -0,0 +1,38 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_bufr_group.h" + +grib_accessor_class_bufr_group_t _grib_accessor_class_bufr_group{"bufr_group"}; +grib_accessor_class* grib_accessor_class_bufr_group = &_grib_accessor_class_bufr_group; + + +void grib_accessor_class_bufr_group_t::dump(grib_accessor* a, grib_dumper* dumper){ + grib_dump_section(dumper, a, a->sub_section->block); +} + +grib_accessor* grib_accessor_class_bufr_group_t::next(grib_accessor* a, int explore) +{ + grib_accessor* next = NULL; + if (explore) { + next = a->sub_section->block->first; + if (!next) + next = a->next_; + } + else { + next = a->next_; + } + if (!next) { + if (a->parent->owner) + next = a->parent->owner->cclass->next(a->parent->owner, 0); + } + return next; +} diff --git a/src/accessor/grib_accessor_class_bufr_group.h b/src/accessor/grib_accessor_class_bufr_group.h new file mode 100644 index 000000000..758c5c772 --- /dev/null +++ b/src/accessor/grib_accessor_class_bufr_group.h @@ -0,0 +1,29 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_variable.h" + +class grib_accessor_bufr_group_t : public grib_accessor_variable_t +{ +public: + /* Members defined in bufr_group */ +}; + +class grib_accessor_class_bufr_group_t : public grib_accessor_class_variable_t +{ +public: + grib_accessor_class_bufr_group_t(const char* name) : grib_accessor_class_variable_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_group_t{}; } + void dump(grib_accessor*, grib_dumper*) override; + grib_accessor* next(grib_accessor* a, int explore) override; +}; diff --git a/src/accessor/grib_accessor_class_bufr_simple_thinning.cc b/src/accessor/grib_accessor_class_bufr_simple_thinning.cc new file mode 100644 index 000000000..a74d7a74c --- /dev/null +++ b/src/accessor/grib_accessor_class_bufr_simple_thinning.cc @@ -0,0 +1,118 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_bufr_simple_thinning.h" + +grib_accessor_class_bufr_simple_thinning_t _grib_accessor_class_bufr_simple_thinning{ "bufr_simple_thinning" }; +grib_accessor_class* grib_accessor_class_bufr_simple_thinning = &_grib_accessor_class_bufr_simple_thinning; + + +void grib_accessor_class_bufr_simple_thinning_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ + grib_accessor_class_gen_t::init(a, len, arg); + grib_accessor_bufr_simple_thinning_t* self = (grib_accessor_bufr_simple_thinning_t*)a; + grib_handle* h = grib_handle_of_accessor(a); + int n = 0; + + a->length = 0; + self->doExtractSubsets = grib_arguments_get_name(h, arg, n++); + self->numberOfSubsets = grib_arguments_get_name(h, arg, n++); + self->extractSubsetList = grib_arguments_get_name(h, arg, n++); + self->simpleThinningStart = grib_arguments_get_name(h, arg, n++); + self->simpleThinningMissingRadius = grib_arguments_get_name(h, arg, n++); + self->simpleThinningSkip = grib_arguments_get_name(h, arg, n++); + + a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; +} + +int grib_accessor_class_bufr_simple_thinning_t::get_native_type(grib_accessor* a) +{ + return GRIB_TYPE_LONG; +} + +static int apply_thinning(grib_accessor* a) +{ + const grib_accessor_bufr_simple_thinning_t* self = (grib_accessor_bufr_simple_thinning_t*)a; + + long skip; + grib_handle* h = grib_handle_of_accessor(a); + grib_context* c = h->context; + long compressed = 0, nsubsets; + grib_iarray* subsets; + long* subsets_ar = 0; + long start = 0, radius = 0; + + int ret = grib_get_long(h, "compressedData", &compressed); + if (ret) + return ret; + if (compressed) { + long numberOfSubsets = 0; + ret = grib_get_long(h, self->numberOfSubsets, &numberOfSubsets); + if (ret) + return ret; + + ret = grib_get_long(h, self->simpleThinningStart, &start); + if (ret) + return ret; + + ret = grib_get_long(h, self->simpleThinningSkip, &skip); + if (ret) + return ret; + if (skip <= 0) + return GRIB_INVALID_KEY_VALUE; + + ret = grib_get_long(h, self->simpleThinningMissingRadius, &radius); + if (ret) + return ret; + + subsets = grib_iarray_new(c, numberOfSubsets / skip + 1, 10); + for (long i = 0; i < numberOfSubsets; i += skip + 1) { + grib_iarray_push(subsets, i + 1); + } + + nsubsets = grib_iarray_used_size(subsets); + + if (nsubsets != 0) { + subsets_ar = grib_iarray_get_array(subsets); + ret = grib_set_long_array(h, self->extractSubsetList, subsets_ar, nsubsets); + grib_context_free(c, subsets_ar); + if (ret) + return ret; + + ret = grib_set_long(h, "unpack", 1); + if (ret) + return ret; + + ret = grib_set_long(h, self->doExtractSubsets, 1); + if (ret) + return ret; + } + grib_iarray_delete(subsets); + } + else { + return GRIB_NOT_IMPLEMENTED; + } + + return ret; +} + +int grib_accessor_class_bufr_simple_thinning_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ + const grib_accessor_bufr_simple_thinning_t* self = (grib_accessor_bufr_simple_thinning_t*)a; + + if (*len == 0) + return GRIB_SUCCESS; + int err = apply_thinning(a); + if (err) + return err; + + return grib_set_long(a->parent->h, self->doExtractSubsets, 1); +} diff --git a/src/accessor/grib_accessor_class_bufr_simple_thinning.h b/src/accessor/grib_accessor_class_bufr_simple_thinning.h new file mode 100644 index 000000000..9b7467914 --- /dev/null +++ b/src/accessor/grib_accessor_class_bufr_simple_thinning.h @@ -0,0 +1,36 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_bufr_simple_thinning_t : public grib_accessor_gen_t +{ +public: + /* Members defined in bufr_simple_thinning */ + const char* doExtractSubsets; + const char* numberOfSubsets; + const char* extractSubsetList; + const char* simpleThinningStart; + const char* simpleThinningMissingRadius; + const char* simpleThinningSkip; +}; + +class grib_accessor_class_bufr_simple_thinning_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_bufr_simple_thinning_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_simple_thinning_t{}; } + int get_native_type(grib_accessor*) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_bufr_string_values.cc b/src/accessor/grib_accessor_class_bufr_string_values.cc new file mode 100644 index 000000000..31e616b6f --- /dev/null +++ b/src/accessor/grib_accessor_class_bufr_string_values.cc @@ -0,0 +1,92 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_bufr_string_values.h" +#include "grib_accessor_class_bufr_data_array.h" + +grib_accessor_class_bufr_string_values_t _grib_accessor_class_bufr_string_values{ "bufr_string_values" }; +grib_accessor_class* grib_accessor_class_bufr_string_values = &_grib_accessor_class_bufr_string_values; + + +void grib_accessor_class_bufr_string_values_t::init(grib_accessor* a, const long len, grib_arguments* args) +{ + grib_accessor_class_ascii_t::init(a, len, args); + grib_accessor_bufr_string_values_t* self = (grib_accessor_bufr_string_values_t*)a; + int n = 0; + self->dataAccessorName = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + self->dataAccessor = NULL; + a->length = 0; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; +} + +void grib_accessor_class_bufr_string_values_t::dump(grib_accessor* a, grib_dumper* dumper) +{ + grib_dump_string_array(dumper, a, NULL); +} + +static grib_accessor* get_accessor(grib_accessor* a) +{ + grib_accessor_bufr_string_values_t* self = (grib_accessor_bufr_string_values_t*)a; + if (!self->dataAccessor) { + self->dataAccessor = grib_find_accessor(grib_handle_of_accessor(a), self->dataAccessorName); + } + return self->dataAccessor; +} + +int grib_accessor_class_bufr_string_values_t::unpack_string_array(grib_accessor* a, char** buffer, size_t* len) +{ + grib_accessor* data = 0; + grib_context* c = a->context; + grib_vsarray* stringValues = NULL; + size_t l = 0, tl; + size_t i, j, n = 0; + char** b = buffer; + + data = get_accessor(a); + if (!data) + return GRIB_NOT_FOUND; + + stringValues = accessor_bufr_data_array_get_stringValues(data); + + n = grib_vsarray_used_size(stringValues); + + tl = 0; + for (j = 0; j < n; j++) { + l = grib_sarray_used_size(stringValues->v[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]); + } + } + *len = tl; + + return GRIB_SUCCESS; +} + +int grib_accessor_class_bufr_string_values_t::unpack_string(grib_accessor* a, char* val, size_t* len) +{ + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_class_bufr_string_values_t::value_count(grib_accessor* a, long* rlen) +{ + grib_accessor* descriptors = get_accessor(a); + return descriptors->value_count(rlen); +} + +void grib_accessor_class_bufr_string_values_t::destroy(grib_context* c, grib_accessor* a) +{ + grib_accessor_class_ascii_t::destroy(c, a); +} diff --git a/src/accessor/grib_accessor_class_bufr_string_values.h b/src/accessor/grib_accessor_class_bufr_string_values.h new file mode 100644 index 000000000..fe6c2acb7 --- /dev/null +++ b/src/accessor/grib_accessor_class_bufr_string_values.h @@ -0,0 +1,35 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_ascii.h" + +class grib_accessor_bufr_string_values_t : public grib_accessor_ascii_t +{ +public: + /* Members defined in bufr_string_values */ + const char* dataAccessorName; + grib_accessor* dataAccessor; +}; + +class grib_accessor_class_bufr_string_values_t : public grib_accessor_class_ascii_t +{ +public: + grib_accessor_class_bufr_string_values_t(const char* name) : grib_accessor_class_ascii_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_string_values_t{}; } + int unpack_string(grib_accessor*, char*, size_t* len) override; + int unpack_string_array(grib_accessor*, char**, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void destroy(grib_context*, grib_accessor*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.cc b/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.cc new file mode 100644 index 000000000..bd411d510 --- /dev/null +++ b/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.cc @@ -0,0 +1,99 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_bufrdc_expanded_descriptors.h" + +grib_accessor_class_bufrdc_expanded_descriptors_t _grib_accessor_class_bufrdc_expanded_descriptors{"bufrdc_expanded_descriptors"}; +grib_accessor_class* grib_accessor_class_bufrdc_expanded_descriptors = &_grib_accessor_class_bufrdc_expanded_descriptors; + + +void grib_accessor_class_bufrdc_expanded_descriptors_t::init(grib_accessor* a, const long len, grib_arguments* args){ + grib_accessor_class_long_t::init(a, len, args); + grib_accessor_bufrdc_expanded_descriptors_t* self = (grib_accessor_bufrdc_expanded_descriptors_t*)a; + int n = 0; + self->expandedDescriptors = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + self->expandedDescriptorsAccessor = 0; + a->length = 0; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; +} + +static grib_accessor* get_accessor(grib_accessor* a) +{ + grib_accessor_bufrdc_expanded_descriptors_t* self = (grib_accessor_bufrdc_expanded_descriptors_t*)a; + if (!self->expandedDescriptorsAccessor) { + self->expandedDescriptorsAccessor = grib_find_accessor(grib_handle_of_accessor(a), self->expandedDescriptors); + } + return self->expandedDescriptorsAccessor; +} + +int grib_accessor_class_bufrdc_expanded_descriptors_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_accessor* descriptors = 0; + size_t rlen = 0, l; + long lenall = 0; + size_t i = 0; + long* v = 0; + grib_context* c = a->context; + + descriptors = get_accessor(a); + if (!descriptors) return GRIB_NOT_FOUND; + + a->value_count(&lenall); v = (long*)grib_context_malloc_clear(c, sizeof(long) * lenall); + l = lenall; + descriptors->unpack_long(v, &l); + rlen = 0; + for (i = 0; i < l; i++) { + if ((v[i] < 100000 || v[i] > 221999)) + val[rlen++] = v[i]; + } + *len = rlen; + grib_context_free(c,v); + + return GRIB_SUCCESS; +} + +int grib_accessor_class_bufrdc_expanded_descriptors_t::unpack_string_array(grib_accessor* a, char** buffer, size_t* len){ + int err = 0; + grib_accessor* descriptors = 0; + size_t l = 0; + long lenall = 0; + size_t i = 0; + long* v = 0; + char buf[25] = {0,}; + grib_context* c = a->context; + + descriptors = get_accessor(a); + if (!descriptors) return GRIB_NOT_FOUND; + + err = a->value_count(&lenall); if (err) return err; + l = lenall; + if (l > *len) return GRIB_ARRAY_TOO_SMALL; + + v = (long*)grib_context_malloc_clear(c, sizeof(long) * l); + err = descriptors->unpack_long(v, &l); if (err) return err; + + for (i = 0; i < l; i++) { + snprintf(buf, sizeof(buf), "%06ld", v[i]); + buffer[i] = grib_context_strdup(c, buf); + } + *len = l; + grib_context_free(c,v); + + return GRIB_SUCCESS; +} + +int grib_accessor_class_bufrdc_expanded_descriptors_t::value_count(grib_accessor* a, long* rlen){ + grib_accessor* descriptors = get_accessor(a); + + return descriptors->value_count(rlen);} + +void grib_accessor_class_bufrdc_expanded_descriptors_t::destroy(grib_context* c, grib_accessor* a){ + grib_accessor_class_long_t::destroy(c, a); +} diff --git a/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.h b/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.h new file mode 100644 index 000000000..92cf595ad --- /dev/null +++ b/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.h @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_bufrdc_expanded_descriptors_t : public grib_accessor_long_t +{ +public: + /* Members defined in bufrdc_expanded_descriptors */ + const char* expandedDescriptors; + grib_accessor* expandedDescriptorsAccessor; +}; + +class grib_accessor_class_bufrdc_expanded_descriptors_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_bufrdc_expanded_descriptors_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_bufrdc_expanded_descriptors_t{}; } + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string_array(grib_accessor*, char**, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void destroy(grib_context*, grib_accessor*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_bytes.cc b/src/accessor/grib_accessor_class_bytes.cc new file mode 100644 index 000000000..47c8713ae --- /dev/null +++ b/src/accessor/grib_accessor_class_bytes.cc @@ -0,0 +1,99 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_bytes.h" + +grib_accessor_class_bytes_t _grib_accessor_class_bytes{"bytes"}; +grib_accessor_class* grib_accessor_class_bytes = &_grib_accessor_class_bytes; + + +void grib_accessor_class_bytes_t::init(grib_accessor* a, const long len, grib_arguments* arg){ + grib_accessor_class_gen_t::init(a, len, arg); + /*grib_accessor_signed* self = (grib_accessor_signed*)a; */ + a->length = len; + Assert(a->length >= 0); +} + +int grib_accessor_class_bytes_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_BYTES; +} + +int grib_accessor_class_bytes_t::compare(grib_accessor* a, grib_accessor* b){ + int retval = GRIB_SUCCESS; + + size_t alen = (size_t)a->byte_count(); size_t blen = (size_t)b->byte_count(); + if (alen != blen) + return GRIB_COUNT_MISMATCH; + + return retval; +} + +int grib_accessor_class_bytes_t::unpack_string(grib_accessor* a, char* v, size_t* len){ + unsigned char* p = NULL; + char* s = v; + long i = 0; + const long length = a->byte_count(); const long slength = 2 * length; + + if (*len < (size_t)slength) { + *len = slength; + return GRIB_BUFFER_TOO_SMALL; + } + + p = grib_handle_of_accessor(a)->buffer->data + a->byte_offset(); + for (i = 0; i < length; i++) { + snprintf(s, INT_MAX, "%02x", *(p++)); + s += 2; + } + + *len = slength; + + return GRIB_SUCCESS; +} + +int grib_accessor_class_bytes_t::pack_string(grib_accessor* a, const char* val, size_t* len){ + /* The string representation (val) of the byte array will have two chars + * per byte e.g. 4C5B means the 2 bytes 0114 and 0133 in octal + * so has to be twice the length of the byte array + */ + int err = 0; + grib_context* c = a->context; + size_t nbytes = a->length; + const size_t expected_blen = nbytes; + const size_t expected_slen = 2 * expected_blen; + unsigned char* bytearray = NULL; + size_t i = 0, slen = strlen(val); + + if (slen != expected_slen || *len != expected_slen) { + grib_context_log(c, GRIB_LOG_ERROR, + "%s: Key %s is %lu bytes. Expected a string with %lu characters (actual length=%zu)", + __func__, a->name, expected_blen, expected_slen, *len); + return GRIB_WRONG_ARRAY_SIZE; + } + + bytearray = (unsigned char*)grib_context_malloc(c, nbytes * (sizeof(unsigned char))); + if (!bytearray) return GRIB_OUT_OF_MEMORY; + + for (i = 0; i < (slen/2); i++) { + unsigned int byteVal = 0; + if (sscanf(val + 2*i, "%02x", &byteVal) != 1) { + grib_context_log(c, GRIB_LOG_ERROR,"%s: Invalid hex byte specfication '%.2s'", __func__, val + 2*i); + grib_context_free(c, bytearray); + return GRIB_INVALID_KEY_VALUE; + } + Assert(byteVal < 256); + bytearray[i] = (int)byteVal; + } + + /* Forward to base class to pack the byte array */ + err = grib_accessor_class_gen_t::pack_bytes(a, bytearray, &nbytes); + grib_context_free(c, bytearray); + return err; +} diff --git a/src/accessor/grib_accessor_class_bytes.h b/src/accessor/grib_accessor_class_bytes.h new file mode 100644 index 000000000..676cf55c4 --- /dev/null +++ b/src/accessor/grib_accessor_class_bytes.h @@ -0,0 +1,32 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_bytes_t : public grib_accessor_gen_t +{ +public: + /* Members defined in bytes */ +}; + +class grib_accessor_class_bytes_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_bytes_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_bytes_t{}; } + int get_native_type(grib_accessor*) override; + int pack_string(grib_accessor*, const char*, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; + int compare(grib_accessor*, grib_accessor*) override; +}; diff --git a/src/accessor/grib_accessor_class_change_alternative_row_scanning.cc b/src/accessor/grib_accessor_class_change_alternative_row_scanning.cc new file mode 100644 index 000000000..50475b6a6 --- /dev/null +++ b/src/accessor/grib_accessor_class_change_alternative_row_scanning.cc @@ -0,0 +1,117 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_change_alternative_row_scanning.h" + +grib_accessor_class_change_alternative_row_scanning_t _grib_accessor_class_change_alternative_row_scanning{"change_alternative_row_scanning"}; +grib_accessor_class* grib_accessor_class_change_alternative_row_scanning = &_grib_accessor_class_change_alternative_row_scanning; + + +void grib_accessor_class_change_alternative_row_scanning_t::init(grib_accessor* a, const long len, grib_arguments* args){ + grib_accessor_class_gen_t::init(a, len, args); + int n = 0; + grib_accessor_change_alternative_row_scanning_t* self = (grib_accessor_change_alternative_row_scanning_t*)a; + + self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + self->Ni = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + self->Nj = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + self->alternativeRowScanning = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + + a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; + a->length = 0; +} + +int grib_accessor_class_change_alternative_row_scanning_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + int err = 0; + grib_accessor_change_alternative_row_scanning_t* self = (grib_accessor_change_alternative_row_scanning_t*)a; + const grib_context* c = a->context; + grib_handle* h = grib_handle_of_accessor(a); + long i, j, jr, theEnd, Ni, Nj, k, kp, alternativeRowScanning; + size_t size = 0; + double* values = NULL; + double tmp = 0.0; + + if (*val == 0) + return 0; + + /* Make sure Ni / Nj are not missing */ + if (grib_is_missing(h, self->Ni, &err) && !err) { + grib_context_log(c, GRIB_LOG_ERROR, "change_alternative_row_scanning: Key %s cannot be 'missing'!", self->Ni); + return GRIB_WRONG_GRID; + } + if (grib_is_missing(h, self->Nj, &err) && !err) { + grib_context_log(c, GRIB_LOG_ERROR, "change_alternative_row_scanning: Key %s cannot be 'missing'!", self->Nj); + return GRIB_WRONG_GRID; + } + + if ((err = grib_get_long_internal(h, self->Ni, &Ni)) != GRIB_SUCCESS) + return err; + if ((err = grib_get_long_internal(h, self->Nj, &Nj)) != GRIB_SUCCESS) + return err; + if ((err = grib_get_long_internal(h, self->alternativeRowScanning, &alternativeRowScanning)) != GRIB_SUCCESS) + return err; + + if ((err = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) + return err; + + if ( size > (size_t)(Ni * Nj) ) { + grib_context_log(c, GRIB_LOG_ERROR, "change_alternative_row_scanning: wrong values size!=Ni*Nj (%zu!=%ld*%ld)", size, Ni, Nj); + return GRIB_WRONG_ARRAY_SIZE; + } + + values = (double*)grib_context_malloc(c, size * sizeof(double)); + if (!values) + return GRIB_OUT_OF_MEMORY; + + if ((err = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) { + grib_context_free(c, values); + return err; + } + + theEnd = Ni / 2; + for (j = 0; j < Nj; j++) { + jr = Ni * j; + for (i = 0; i < theEnd; i++) { + if (j % 2 == 1) { + /* Swap first and last value on every odd row */ + k = jr + i; + kp = jr + Ni - i - 1; + tmp = values[k]; + values[k] = values[kp]; + values[kp] = tmp; + } + } + } + alternativeRowScanning = !alternativeRowScanning; + if ((err = grib_set_long_internal(h, self->alternativeRowScanning, alternativeRowScanning)) != GRIB_SUCCESS) { + grib_context_free(c, values); + return err; + } + + if ((err = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) { + grib_context_free(c, values); + return err; + } + + grib_context_free(c, values); + + return GRIB_SUCCESS; +} + +int grib_accessor_class_change_alternative_row_scanning_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_LONG; +} + +int grib_accessor_class_change_alternative_row_scanning_t::unpack_long(grib_accessor* a, long* v, size_t* len){ + /* Decoding this accessor doesn't make sense so we return a dummy value */ + *v = -1; + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_change_alternative_row_scanning.h b/src/accessor/grib_accessor_class_change_alternative_row_scanning.h new file mode 100644 index 000000000..f889931a0 --- /dev/null +++ b/src/accessor/grib_accessor_class_change_alternative_row_scanning.h @@ -0,0 +1,35 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_change_alternative_row_scanning_t : public grib_accessor_gen_t +{ +public: + /* Members defined in change_alternative_row_scanning */ + const char* values; + const char* Ni; + const char* Nj; + const char* alternativeRowScanning; +}; + +class grib_accessor_class_change_alternative_row_scanning_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_change_alternative_row_scanning_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_change_alternative_row_scanning_t{}; } + int get_native_type(grib_accessor*) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_change_scanning_direction.cc b/src/accessor/grib_accessor_class_change_scanning_direction.cc similarity index 56% rename from src/grib_accessor_class_change_scanning_direction.cc rename to src/accessor/grib_accessor_class_change_scanning_direction.cc index f951c9083..e3b6144c9 100644 --- a/src/grib_accessor_class_change_scanning_direction.cc +++ b/src/accessor/grib_accessor_class_change_scanning_direction.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,116 +9,15 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = pack_long; - IMPLEMENTS = unpack_long - IMPLEMENTS = init;get_native_type - MEMBERS = const char* values - MEMBERS = const char* Ni - MEMBERS = const char* Nj - MEMBERS = const char* i_scans_negatively - MEMBERS = const char* j_scans_positively - MEMBERS = const char* first - MEMBERS = const char* last - MEMBERS = const char* axis - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_change_scanning_direction -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in change_scanning_direction */ - const char* values; - const char* Ni; - const char* Nj; - const char* i_scans_negatively; - const char* j_scans_positively; - const char* first; - const char* last; - const char* axis; -} grib_accessor_change_scanning_direction; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_change_scanning_direction = { - &grib_accessor_class_gen, /* super */ - "change_scanning_direction", /* name */ - sizeof(grib_accessor_change_scanning_direction), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_change_scanning_direction.h" +grib_accessor_class_change_scanning_direction_t _grib_accessor_class_change_scanning_direction{"change_scanning_direction"}; grib_accessor_class* grib_accessor_class_change_scanning_direction = &_grib_accessor_class_change_scanning_direction; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long len, grib_arguments* args) -{ - grib_accessor_change_scanning_direction* self = (grib_accessor_change_scanning_direction*)a; +void grib_accessor_class_change_scanning_direction_t::init(grib_accessor* a, const long len, grib_arguments* args){ + grib_accessor_class_gen_t::init(a, len, args); + grib_accessor_change_scanning_direction_t* self = (grib_accessor_change_scanning_direction_t*)a; grib_handle* h = grib_handle_of_accessor(a); int n = 0; @@ -134,8 +34,7 @@ static void init(grib_accessor* a, const long len, grib_arguments* args) a->length = 0; } -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ +int grib_accessor_class_change_scanning_direction_t::pack_long(grib_accessor* a, const long* val, size_t* len){ int err = 0; long i, j, jr, theEnd, Ni, Nj, k, kp; double tmp; @@ -145,7 +44,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) double last = 0; size_t size = 0; double* values = NULL; - grib_accessor_change_scanning_direction* self = (grib_accessor_change_scanning_direction*)a; + grib_accessor_change_scanning_direction_t* self = (grib_accessor_change_scanning_direction_t*)a; const grib_context* c = a->context; grib_handle* h = grib_handle_of_accessor(a); const char* cclass_name = a->cclass->name; @@ -248,13 +147,11 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) return GRIB_SUCCESS; } -static int get_native_type(grib_accessor* a) -{ +int grib_accessor_class_change_scanning_direction_t::get_native_type(grib_accessor* a){ return GRIB_TYPE_LONG; } -static int unpack_long(grib_accessor* a, long* v, size_t* len) -{ +int grib_accessor_class_change_scanning_direction_t::unpack_long(grib_accessor* a, long* v, size_t* len){ /* ECC-976: decoding this accessor doesn't make sense so we return a dummy value */ *v = -1; return GRIB_SUCCESS; diff --git a/src/accessor/grib_accessor_class_change_scanning_direction.h b/src/accessor/grib_accessor_class_change_scanning_direction.h new file mode 100644 index 000000000..ead274485 --- /dev/null +++ b/src/accessor/grib_accessor_class_change_scanning_direction.h @@ -0,0 +1,39 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_change_scanning_direction_t : public grib_accessor_gen_t +{ +public: + /* Members defined in change_scanning_direction */ + const char* values; + const char* Ni; + const char* Nj; + const char* i_scans_negatively; + const char* j_scans_positively; + const char* first; + const char* last; + const char* axis; +}; + +class grib_accessor_class_change_scanning_direction_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_change_scanning_direction_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_change_scanning_direction_t{}; } + int get_native_type(grib_accessor*) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_check_internal_version.cc b/src/accessor/grib_accessor_class_check_internal_version.cc new file mode 100644 index 000000000..f8ceb1896 --- /dev/null +++ b/src/accessor/grib_accessor_class_check_internal_version.cc @@ -0,0 +1,51 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_check_internal_version.h" + +grib_accessor_class_check_internal_version_t _grib_accessor_class_check_internal_version{"check_internal_version"}; +grib_accessor_class* grib_accessor_class_check_internal_version = &_grib_accessor_class_check_internal_version; + + +/* This is the internal engine version number */ +/* We check this against the version number found in the definitions boot.def file */ +/* See the key "internalVersion" */ +#define LATEST_ENGINE_VERSION 30 + +void grib_accessor_class_check_internal_version_t::init(grib_accessor* a, const long l, grib_arguments* args){ + grib_accessor_class_ascii_t::init(a, l, args); + /* Check version of definition files is compatible with the engine */ + int err = 0; + long defs_file_version = 0; + grib_handle* h = grib_handle_of_accessor(a); + const char* s_defn_version = grib_arguments_get_name(h, args, 0); + Assert(s_defn_version); + + err = grib_get_long_internal(h, s_defn_version, &defs_file_version); + if (!err) { + if (defs_file_version > LATEST_ENGINE_VERSION) { + grib_context_log(h->context, GRIB_LOG_FATAL, + "Definition files version (%d) is greater than engine version (%d)!\n" + " " /* indent for 2nd line */ + "These definition files are for a later version of the ecCodes engine.", + defs_file_version, LATEST_ENGINE_VERSION); + } + } +} + +int grib_accessor_class_check_internal_version_t::value_count(grib_accessor* a, long* count){ + *count = 1; + return 0; +} + +size_t grib_accessor_class_check_internal_version_t::string_length(grib_accessor* a){ + return 255; +} diff --git a/src/accessor/grib_accessor_class_check_internal_version.h b/src/accessor/grib_accessor_class_check_internal_version.h new file mode 100644 index 000000000..d37b57282 --- /dev/null +++ b/src/accessor/grib_accessor_class_check_internal_version.h @@ -0,0 +1,30 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_ascii.h" + +class grib_accessor_check_internal_version_t : public grib_accessor_ascii_t +{ +public: + /* Members defined in check_internal_version */ +}; + +class grib_accessor_class_check_internal_version_t : public grib_accessor_class_ascii_t +{ +public: + grib_accessor_class_check_internal_version_t(const char* name) : grib_accessor_class_ascii_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_check_internal_version_t{}; } + size_t string_length(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_closest_date.cc b/src/accessor/grib_accessor_class_closest_date.cc similarity index 57% rename from src/grib_accessor_class_closest_date.cc rename to src/accessor/grib_accessor_class_closest_date.cc index 08ba9f333..b0b3bb512 100644 --- a/src/grib_accessor_class_closest_date.cc +++ b/src/accessor/grib_accessor_class_closest_date.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,122 +9,16 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" +#include "grib_accessor_class_closest_date.h" #include -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_double - IMPLEMENTS = unpack_long - IMPLEMENTS = unpack_double - IMPLEMENTS = dump - IMPLEMENTS = init - MEMBERS = const char *dateLocal - MEMBERS = const char *timeLocal - MEMBERS = const char *numForecasts - MEMBERS = const char *year - MEMBERS = const char *month - MEMBERS = const char *day - MEMBERS = const char *hour - MEMBERS = const char *minute - MEMBERS = const char *second - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_closest_date -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in closest_date */ - const char *dateLocal; - const char *timeLocal; - const char *numForecasts; - const char *year; - const char *month; - const char *day; - const char *hour; - const char *minute; - const char *second; -} grib_accessor_closest_date; - -extern grib_accessor_class* grib_accessor_class_double; - -static grib_accessor_class _grib_accessor_class_closest_date = { - &grib_accessor_class_double, /* super */ - "closest_date", /* name */ - sizeof(grib_accessor_closest_date), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - +grib_accessor_class_closest_date_t _grib_accessor_class_closest_date{"closest_date"}; grib_accessor_class* grib_accessor_class_closest_date = &_grib_accessor_class_closest_date; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_closest_date* self = (grib_accessor_closest_date*)a; +void grib_accessor_class_closest_date_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_double_t::init(a, l, c); + grib_accessor_closest_date_t* self = (grib_accessor_closest_date_t*)a; grib_handle* h = grib_handle_of_accessor(a); int n = 0; @@ -140,13 +35,11 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) a->length = 0; } -static void dump(grib_accessor* a, grib_dumper* dumper) -{ +void grib_accessor_class_closest_date_t::dump(grib_accessor* a, grib_dumper* dumper){ grib_dump_string(dumper, a, NULL); } -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ +int grib_accessor_class_closest_date_t::unpack_long(grib_accessor* a, long* val, size_t* len){ int ret = 0; double v = 0; @@ -157,9 +50,8 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) } /* Sets val to the 'index' of the closes date */ -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - const grib_accessor_closest_date* self = (grib_accessor_closest_date*)a; +int grib_accessor_class_closest_date_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + const grib_accessor_closest_date_t* self = (grib_accessor_closest_date_t*)a; int err = 0; long num_forecasts = 0; /* numberOfForecastsUsedInLocalTime */ diff --git a/src/accessor/grib_accessor_class_closest_date.h b/src/accessor/grib_accessor_class_closest_date.h new file mode 100644 index 000000000..ebd3cb6d4 --- /dev/null +++ b/src/accessor/grib_accessor_class_closest_date.h @@ -0,0 +1,40 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_double.h" + +class grib_accessor_closest_date_t : public grib_accessor_double_t +{ +public: + /* Members defined in closest_date */ + const char *dateLocal; + const char *timeLocal; + const char *numForecasts; + const char *year; + const char *month; + const char *day; + const char *hour; + const char *minute; + const char *second; +}; + +class grib_accessor_class_closest_date_t : public grib_accessor_class_double_t +{ +public: + grib_accessor_class_closest_date_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_closest_date_t{}; } + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_codeflag.cc b/src/accessor/grib_accessor_class_codeflag.cc new file mode 100644 index 000000000..6cfda6942 --- /dev/null +++ b/src/accessor/grib_accessor_class_codeflag.cc @@ -0,0 +1,124 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_codeflag.h" + +grib_accessor_class_codeflag_t _grib_accessor_class_codeflag{ "codeflag" }; +grib_accessor_class* grib_accessor_class_codeflag = &_grib_accessor_class_codeflag; + + +void grib_accessor_class_codeflag_t::init(grib_accessor* a, const long len, grib_arguments* param) +{ + grib_accessor_class_unsigned_t::init(a, len, param); + grib_accessor_codeflag_t* self = (grib_accessor_codeflag_t*)a; + a->length = len; + self->tablename = grib_arguments_get_string(grib_handle_of_accessor(a), param, 0); + Assert(a->length >= 0); +} + +static int test_bit(long a, long b) +{ + DEBUG_ASSERT(b >= 0); + return a & (1 << b); +} + +static int grib_get_codeflag(grib_accessor* a, long code, char* codename) +{ + const grib_accessor_codeflag_t* self = (grib_accessor_codeflag_t*)a; + FILE* f = NULL; + char fname[1024]; + char bval[50]; + char num[50]; + char* filename = 0; + char line[1024]; + size_t i = 0; + int j = 0; + int err = 0; + + err = grib_recompose_name(grib_handle_of_accessor(a), NULL, self->tablename, fname, 1); + if (err) { + strncpy(fname, self->tablename, sizeof(fname) - 1); + fname[sizeof(fname) - 1] = '\0'; + } + + if ((filename = grib_context_full_defs_path(a->context, fname)) == NULL) { + grib_context_log(a->context, GRIB_LOG_WARNING, "Cannot open flag table %s", filename); + strcpy(codename, "Cannot open flag table"); + return GRIB_FILE_NOT_FOUND; + } + + f = codes_fopen(filename, "r"); + if (!f) { + grib_context_log(a->context, (GRIB_LOG_WARNING) | (GRIB_LOG_PERROR), "Cannot open flag table %s", filename); + strcpy(codename, "Cannot open flag table"); + return GRIB_FILE_NOT_FOUND; + } + + // strcpy(codename, self->tablename); + // strcat(codename,": "); + // j = strlen(codename); + + while (fgets(line, sizeof(line) - 1, f)) { + sscanf(line, "%49s %49s", num, bval); + + if (num[0] != '#') { + if ((test_bit(code, a->length * 8 - atol(num)) > 0) == atol(bval)) { + size_t linelen = strlen(line); + codename[j++] = '('; + codename[j++] = num[0]; + codename[j++] = '='; + codename[j++] = bval[0]; + codename[j++] = ')'; + codename[j++] = ' '; + if (j) + codename[j++] = ' '; + + for (i = (strlen(num) + strlen(bval) + 2); i < linelen - 1; i++) + codename[j++] = line[i]; + if (line[i] != '\n') + codename[j++] = line[i]; + codename[j++] = ';'; + } + } + } + + if (j > 1 && codename[j - 1] == ';') + j--; + codename[j] = 0; + + strcat(codename, ":"); + strcat(codename, fname); + + fclose(f); + return GRIB_SUCCESS; +} + +int grib_accessor_class_codeflag_t::value_count(grib_accessor* a, long* count) +{ + *count = 1; + return 0; +} + +void grib_accessor_class_codeflag_t::dump(grib_accessor* a, grib_dumper* dumper) +{ + const grib_accessor_codeflag_t* self = (grib_accessor_codeflag_t*)a; + long v = 0; + char flagname[1024] = {0,}; + char fname[1024] = {0,}; + + size_t llen = 1; + + grib_recompose_name(grib_handle_of_accessor(a), NULL, self->tablename, fname, 1); + a->unpack_long(&v, &llen); + grib_get_codeflag(a, v, flagname); + + grib_dump_bits(dumper, a, flagname); +} diff --git a/src/accessor/grib_accessor_class_codeflag.h b/src/accessor/grib_accessor_class_codeflag.h new file mode 100644 index 000000000..82c8cc77b --- /dev/null +++ b/src/accessor/grib_accessor_class_codeflag.h @@ -0,0 +1,31 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_unsigned.h" + +class grib_accessor_codeflag_t : public grib_accessor_unsigned_t +{ +public: + /* Members defined in codeflag */ + const char* tablename; +}; + +class grib_accessor_class_codeflag_t : public grib_accessor_class_unsigned_t +{ +public: + grib_accessor_class_codeflag_t(const char* name) : grib_accessor_class_unsigned_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_codeflag_t{}; } + int value_count(grib_accessor*, long*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_codetable.cc b/src/accessor/grib_accessor_class_codetable.cc similarity index 80% rename from src/grib_accessor_class_codetable.cc rename to src/accessor/grib_accessor_class_codetable.cc index 9e39ed633..f21ef0f86 100644 --- a/src/grib_accessor_class_codetable.cc +++ b/src/accessor/grib_accessor_class_codetable.cc @@ -8,18 +8,19 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -/***************************************** - * Enrico Fucile - ****************************************/ - -#include "grib_api_internal.h" +#include "grib_accessor_class_codetable.h" #include + +grib_accessor_class_codetable_t _grib_accessor_class_codetable("codetable"); +grib_accessor_class* grib_accessor_class_codetable = &_grib_accessor_class_codetable; + + #if GRIB_PTHREADS static pthread_once_t once = PTHREAD_ONCE_INIT; static pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; -static void thread_init() +void thread_init() { pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); @@ -31,7 +32,7 @@ static void thread_init() static int once = 0; static omp_nest_lock_t mutex1; -static void thread_init() +void thread_init() { GRIB_OMP_CRITICAL(lock_grib_accessor_class_codetable_c) { @@ -43,123 +44,16 @@ static void thread_init() } #endif -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_unsigned - IMPLEMENTS = init;dump;unpack_string;pack_expression;unpack_long - IMPLEMENTS = value_count;pack_string; destroy; get_native_type;pack_missing - MEMBERS = const char* tablename - MEMBERS = const char* masterDir - MEMBERS = const char* localDir - MEMBERS = grib_codetable* table - MEMBERS = int table_loaded - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_missing(grib_accessor*); -static int pack_string(grib_accessor*, const char*, size_t* len); -static int pack_expression(grib_accessor*, grib_expression*); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static int value_count(grib_accessor*, long*); -static void destroy(grib_context*, grib_accessor*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_codetable -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in unsigned */ - long nbytes; - grib_arguments* arg; - /* Members defined in codetable */ - const char* tablename; - const char* masterDir; - const char* localDir; - grib_codetable* table; - int table_loaded; -} grib_accessor_codetable; - -extern grib_accessor_class* grib_accessor_class_unsigned; - -static grib_accessor_class _grib_accessor_class_codetable = { - &grib_accessor_class_unsigned, /* super */ - "codetable", /* name */ - sizeof(grib_accessor_codetable), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - &destroy, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - &pack_missing, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - &pack_string, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - &pack_expression, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_codetable = &_grib_accessor_class_codetable; - -/* END_CLASS_IMP */ - static int grib_load_codetable(grib_context* c, const char* filename, const char* recomposed_name, size_t size, grib_codetable* t); -static void init(grib_accessor* a, const long len, grib_arguments* params) +void grib_accessor_class_codetable_t::init(grib_accessor* a, const long len, grib_arguments* params) { + grib_accessor_class_unsigned_t::init(a, len, params); + int n = 0; long new_len = len; grib_handle* hand = grib_handle_of_accessor(a); - grib_accessor_codetable* self = (grib_accessor_codetable*)a; + grib_accessor_codetable_t* self = (grib_accessor_codetable_t*)a; grib_action* act = (grib_action*)(a->creator); DEBUG_ASSERT(len == self->nbytes); @@ -195,7 +89,7 @@ static void init(grib_accessor* a, const long len, grib_arguments* params) a->length = 0; if (!a->vvalue) a->vvalue = (grib_virtual_value*)grib_context_malloc_clear(a->context, sizeof(grib_virtual_value)); - a->vvalue->type = grib_accessor_get_native_type(a); + a->vvalue->type = a->get_native_type(); a->vvalue->length = new_len; if (act->default_value != NULL) { const char* p = 0; @@ -209,12 +103,12 @@ static void init(grib_accessor* a, const long len, grib_arguments* params) switch (type) { case GRIB_TYPE_DOUBLE: grib_expression_evaluate_double(hand, expression, &d); - grib_pack_double(a, &d, &s_len); + a->pack_double(&d, &s_len); break; case GRIB_TYPE_LONG: grib_expression_evaluate_long(grib_handle_of_accessor(a), expression, &l); - grib_pack_long(a, &l, &s_len); + a->pack_long(&l, &s_len); break; default: @@ -248,6 +142,7 @@ GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b) return (*a == 0 && *b == 0) ? 0 : 1; } +// Cater for parameters being NULL static int str_eq(const char* a, const char* b) { if (a && b && (grib_inline_strcmp(a, b) == 0)) @@ -271,7 +166,7 @@ static void dump_codetable(grib_codetable* atable) #endif static grib_codetable* load_table(grib_accessor* a) { - grib_accessor_codetable* self = (grib_accessor_codetable*)a; + grib_accessor_codetable_t* self = (grib_accessor_codetable_t*)a; size_t size = 0; grib_handle* h = ((grib_accessor*)self)->parent->h; grib_context* c = h->context; @@ -342,7 +237,7 @@ static grib_codetable* load_table(grib_accessor* a) size = a->vvalue->length * 8; } else { - size = grib_byte_count((grib_accessor*)self) * 8; + size = ((grib_accessor*)self)->byte_count() * 8; } size = (1ULL << size); /* 2^size - 64bits */ @@ -538,10 +433,10 @@ int codes_codetable_get_contents_malloc(const grib_handle* h, const char* key, c return GRIB_INVALID_ARGUMENT; // key is not a codetable } - const grib_accessor_codetable* ca = (const grib_accessor_codetable*)aa; // could be dynamic_cast + const grib_accessor_codetable_t* ca = (const grib_accessor_codetable_t*)aa; // could be dynamic_cast // Decode the key itself. This will either fetch it from the cache or place it there - if ((err = grib_unpack_long(aa, &lvalue, &size)) != GRIB_SUCCESS) { + if ((err = aa->unpack_long(&lvalue, &size)) != GRIB_SUCCESS) { return err; } @@ -612,9 +507,9 @@ int codes_codetable_check_abbreviation(const grib_handle* h, const char* key, co return err; } -static void dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_class_codetable_t::dump(grib_accessor* a, grib_dumper* dumper) { - grib_accessor_codetable* self = (grib_accessor_codetable*)a; + grib_accessor_codetable_t* self = (grib_accessor_codetable_t*)a; char comment[2048]; grib_codetable* table; @@ -627,7 +522,7 @@ static void dump(grib_accessor* a, grib_dumper* dumper) } table = self->table; - grib_unpack_long(a, &value, &llen); + a->unpack_long(&value, &llen); if (value == GRIB_MISSING_LONG) { if (a->length < 4) { @@ -670,9 +565,9 @@ static void dump(grib_accessor* a, grib_dumper* dumper) grib_dump_long(dumper, a, comment); } -static int unpack_string(grib_accessor* a, char* buffer, size_t* len) +int grib_accessor_class_codetable_t::unpack_string(grib_accessor* a, char* buffer, size_t* len) { - grib_accessor_codetable* self = (grib_accessor_codetable*)a; + grib_accessor_codetable_t* self = (grib_accessor_codetable_t*)a; grib_codetable* table = NULL; size_t size = 1; @@ -681,7 +576,7 @@ static int unpack_string(grib_accessor* a, char* buffer, size_t* len) char tmp[1024]; size_t l = 0; - if ((err = grib_unpack_long(a, &value, &size)) != GRIB_SUCCESS) + if ((err = a->unpack_long(&value, &size)) != GRIB_SUCCESS) return err; if (!self->table_loaded) { @@ -714,14 +609,14 @@ static int unpack_string(grib_accessor* a, char* buffer, size_t* len) return GRIB_SUCCESS; } -static int value_count(grib_accessor* a, long* count) +int grib_accessor_class_codetable_t::value_count(grib_accessor* a, long* count) { *count = 1; return 0; } // Return true if the input is an integer (non-negative) -static bool is_number(const char* s) +bool is_number(const char* s) { while (*s) { if (!isdigit(*s)) @@ -731,27 +626,27 @@ static bool is_number(const char* s) return true; } -static bool strings_equal(const char* s1, const char* s2, bool case_sensitive) +bool strings_equal(const char* s1, const char* s2, bool case_sensitive) { if (case_sensitive) return (strcmp(s1, s2) == 0); return (strcmp_nocase(s1, s2) == 0); } -static int pack_string(grib_accessor* a, const char* buffer, size_t* len) +int grib_accessor_class_codetable_t::pack_string(grib_accessor* a, const char* buffer, size_t* len) { long lValue = 0; Assert(buffer); if (is_number(buffer) && string_to_long(buffer, &lValue, 1) == GRIB_SUCCESS) { // ECC-1654: If value is a pure number, just pack as long size_t l = 1; - return grib_pack_long(a, &lValue, &l); + return a->pack_long(&lValue, &l); } if (STR_EQUAL_NOCASE(buffer, "missing")) { return pack_missing(a); } - grib_accessor_codetable* self = (grib_accessor_codetable*)a; + grib_accessor_codetable_t* self = (grib_accessor_codetable_t*)a; grib_codetable* table = NULL; long i = 0; size_t size = 1; @@ -779,7 +674,7 @@ static int pack_string(grib_accessor* a, const char* buffer, size_t* len) for (i = 0; i < table->size; i++) { if (table->entries[i].abbreviation) { if (strings_equal(table->entries[i].abbreviation, buffer, case_sensitive)) { - return grib_pack_long(a, &i, &size); + return a->pack_long(&i, &size); } } } @@ -798,12 +693,12 @@ static int pack_string(grib_accessor* a, const char* buffer, size_t* len) switch (type) { case GRIB_TYPE_DOUBLE: grib_expression_evaluate_double(grib_handle_of_accessor(a), expression, &d); - grib_pack_double(a, &d, &s_len); + a->pack_double(&d, &s_len); break; case GRIB_TYPE_LONG: grib_expression_evaluate_long(grib_handle_of_accessor(a), expression, &l); - grib_pack_long(a, &l, &s_len); + a->pack_long(&l, &s_len); break; default: @@ -837,7 +732,7 @@ static int pack_string(grib_accessor* a, const char* buffer, size_t* len) return GRIB_ENCODING_ERROR; } -static int pack_expression(grib_accessor* a, grib_expression* e) +int grib_accessor_class_codetable_t::pack_expression(grib_accessor* a, grib_expression* e) { const char* cval = NULL; int ret = 0; @@ -848,7 +743,7 @@ static int pack_expression(grib_accessor* a, grib_expression* e) if (strcmp(e->cclass->name, "long") == 0) { grib_expression_evaluate_long(hand, e, &lval); /* TODO: check return value */ //if (hand->context->debug) printf("ECCODES DEBUG grib_accessor_class_codetable::pack_expression %s %ld\n", a->name,lval); - ret = grib_pack_long(a, &lval, &len); + ret = a->pack_long(&lval, &len); } else { char tmp[1024]; @@ -863,20 +758,21 @@ static int pack_expression(grib_accessor* a, grib_expression* e) len = strlen(cval) + 1; //if (hand->context->debug) // printf("ECCODES DEBUG grib_accessor_class_codetable::pack_expression %s %s\n", a->name, cval); - ret = grib_pack_string(a, cval, &len); + ret = a->pack_string(cval, &len); } return ret; } -static void destroy(grib_context* context, grib_accessor* a) +void grib_accessor_class_codetable_t::destroy(grib_context* context, grib_accessor* a) { if (a->vvalue != NULL) { grib_context_free(context, a->vvalue); a->vvalue = NULL; } + grib_accessor_class_unsigned_t::destroy(context, a); } -static int get_native_type(grib_accessor* a) +int grib_accessor_class_codetable_t::get_native_type(grib_accessor* a) { int type = GRIB_TYPE_LONG; /*printf("---------- %s flags=%ld GRIB_ACCESSOR_FLAG_STRING_TYPE=%d\n", @@ -886,16 +782,16 @@ static int get_native_type(grib_accessor* a) return type; } -static int unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_class_codetable_t::unpack_long(grib_accessor* a, long* val, size_t* len) { - grib_accessor_codetable* self = (grib_accessor_codetable*)a; + grib_accessor_codetable_t* self = (grib_accessor_codetable_t*)a; long rlen = 0, i = 0; long pos = a->offset * 8; grib_handle* hand = NULL; #ifdef DEBUG { - int err = grib_value_count(a, &rlen); + int err = a->value_count(&rlen); Assert(!err); Assert(rlen == 1); } @@ -908,9 +804,9 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) } if (*len < rlen) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size (%zu) for %s, it contains %ld values", + grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size (%lu) for %s, it contains %ld values", *len, a->name, rlen); - *len = rlen; + *len = 0; return GRIB_ARRAY_TOO_SMALL; } @@ -934,12 +830,12 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) return GRIB_SUCCESS; } -static int pack_missing(grib_accessor* a) +int grib_accessor_class_codetable_t::pack_missing(grib_accessor* a) { // Many of the code tables do have a 'Missing' entry (all bits = 1) // So it is more user-friendly to allow setting codetable keys to // missing. For tables that do not have such an entry, an error is issued - grib_accessor_codetable* self = (grib_accessor_codetable*)a; + grib_accessor_codetable_t* self = (grib_accessor_codetable_t*)a; grib_handle* h = grib_handle_of_accessor(a); const long nbytes = a->length; @@ -949,7 +845,7 @@ static int pack_missing(grib_accessor* a) int err = codes_codetable_check_code_figure(h, a->name, maxVal); if (!err) { size_t l = 1; - return grib_pack_long(a, &maxVal, &l); + return a->pack_long(&maxVal, &l); } grib_context_log(a->context, GRIB_LOG_ERROR, "There is no 'missing' entry in Code Table %s (%s)", diff --git a/src/accessor/grib_accessor_class_codetable.h b/src/accessor/grib_accessor_class_codetable.h new file mode 100644 index 000000000..8a16d9113 --- /dev/null +++ b/src/accessor/grib_accessor_class_codetable.h @@ -0,0 +1,41 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_unsigned.h" +#include + +class grib_accessor_codetable_t : public grib_accessor_unsigned_t +{ +public: + const char* tablename; + const char* masterDir; + const char* localDir; + grib_codetable* table; + int table_loaded; +}; + +class grib_accessor_class_codetable_t : public grib_accessor_class_unsigned_t +{ +public: + grib_accessor* create_empty_accessor() override { return new grib_accessor_codetable_t{}; } + grib_accessor_class_codetable_t(const char* name) : grib_accessor_class_unsigned_t(name) {} + int get_native_type(grib_accessor*) override; + int pack_missing(grib_accessor*) override; + int pack_string(grib_accessor*, const char*, size_t* len) override; + int pack_expression(grib_accessor*, grib_expression*) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void destroy(grib_context*, grib_accessor*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_codetable_title.cc b/src/accessor/grib_accessor_class_codetable_title.cc new file mode 100644 index 000000000..2bcdfd215 --- /dev/null +++ b/src/accessor/grib_accessor_class_codetable_title.cc @@ -0,0 +1,72 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_codetable_title.h" +#include "grib_accessor_class_codetable.h" + +grib_accessor_class_codetable_title_t _grib_accessor_class_codetable_title{ "codetable_title" }; +grib_accessor_class* grib_accessor_class_codetable_title = &_grib_accessor_class_codetable_title; + +void grib_accessor_class_codetable_title_t::init(grib_accessor* a, const long len, grib_arguments* params) +{ + grib_accessor_class_gen_t::init(a, len, params); + grib_accessor_codetable_title_t* self = (grib_accessor_codetable_title_t*)a; + int n = 0; + self->codetable = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++); + a->length = 0; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; +} + +int grib_accessor_class_codetable_title_t::get_native_type(grib_accessor* a) +{ + return GRIB_TYPE_STRING; +} + +int grib_accessor_class_codetable_title_t::unpack_string(grib_accessor* a, char* buffer, size_t* len) +{ + grib_accessor_codetable_title_t* self = (grib_accessor_codetable_title_t*)a; + grib_codetable* table = NULL; + + size_t size = 1; + long value; + int err = GRIB_SUCCESS; + char tmp[1024]; + size_t l = 1024; + grib_accessor_codetable_t* ca = (grib_accessor_codetable_t*)grib_find_accessor(grib_handle_of_accessor(a), self->codetable); + + if ((err = ((grib_accessor*)ca)->unpack_long(&value, &size)) != GRIB_SUCCESS) + return err; + + table = ca->table; + + if (table && (value >= 0) && (value < table->size) && table->entries[value].title) { + strcpy(tmp, table->entries[value].title); + } + else { + snprintf(tmp, sizeof(tmp), "%d", (int)value); + } + + l = strlen(tmp) + 1; + + if (*len < l) { + const char* cclass_name = a->cclass->name; + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", + cclass_name, a->name, l, *len); + *len = l; + return GRIB_BUFFER_TOO_SMALL; + } + + strcpy(buffer, tmp); + *len = l; + + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_codetable_title.h b/src/accessor/grib_accessor_class_codetable_title.h new file mode 100644 index 000000000..f820c585c --- /dev/null +++ b/src/accessor/grib_accessor_class_codetable_title.h @@ -0,0 +1,31 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_codetable_title_t : public grib_accessor_gen_t +{ +public: + /* Members defined in codetable_title */ + const char* codetable; +}; + +class grib_accessor_class_codetable_title_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_codetable_title_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_codetable_title_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_codetable_units.cc b/src/accessor/grib_accessor_class_codetable_units.cc new file mode 100644 index 000000000..cc91ae2e2 --- /dev/null +++ b/src/accessor/grib_accessor_class_codetable_units.cc @@ -0,0 +1,73 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_codetable_units.h" +#include "grib_accessor_class_codetable.h" + +grib_accessor_class_codetable_units_t _grib_accessor_class_codetable_units{ "codetable_units" }; +grib_accessor_class* grib_accessor_class_codetable_units = &_grib_accessor_class_codetable_units; + +void grib_accessor_class_codetable_units_t::init(grib_accessor* a, const long len, grib_arguments* params) +{ + grib_accessor_class_gen_t::init(a, len, params); + grib_accessor_codetable_units_t* self = (grib_accessor_codetable_units_t*)a; + + int n = 0; + self->codetable = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++); + a->length = 0; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; +} + +int grib_accessor_class_codetable_units_t::get_native_type(grib_accessor* a) +{ + return GRIB_TYPE_STRING; +} + +int grib_accessor_class_codetable_units_t::unpack_string(grib_accessor* a, char* buffer, size_t* len) +{ + grib_accessor_codetable_units_t* self = (grib_accessor_codetable_units_t*)a; + grib_codetable* table = NULL; + + size_t size = 1; + long value; + int err = GRIB_SUCCESS; + char tmp[1024]; + size_t l = sizeof(tmp); + grib_accessor_codetable_t* ca = (grib_accessor_codetable_t*)grib_find_accessor(grib_handle_of_accessor(a), self->codetable); + + if ((err = ((grib_accessor*)ca)->unpack_long(&value, &size)) != GRIB_SUCCESS) + return err; + + table = ca->table; + + if (table && (value >= 0) && (value < table->size) && table->entries[value].units) { + strcpy(tmp, table->entries[value].units); + } + else { + snprintf(tmp, sizeof(tmp), "%d", (int)value); + } + + l = strlen(tmp) + 1; + + if (*len < l) { + const char* cclass_name = a->cclass->name; + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", + cclass_name, a->name, l, *len); + *len = l; + return GRIB_BUFFER_TOO_SMALL; + } + + strcpy(buffer, tmp); + *len = l; + + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_codetable_units.h b/src/accessor/grib_accessor_class_codetable_units.h new file mode 100644 index 000000000..0a8c9389d --- /dev/null +++ b/src/accessor/grib_accessor_class_codetable_units.h @@ -0,0 +1,31 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_codetable_units_t : public grib_accessor_gen_t +{ +public: + /* Members defined in codetable_units */ + const char* codetable; +}; + +class grib_accessor_class_codetable_units_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_codetable_units_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_codetable_units_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_concept.cc b/src/accessor/grib_accessor_class_concept.cc similarity index 70% rename from src/grib_accessor_class_concept.cc rename to src/accessor/grib_accessor_class_concept.cc index 1462afcfc..98f0fb35c 100644 --- a/src/grib_accessor_class_concept.cc +++ b/src/accessor/grib_accessor_class_concept.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,113 +9,11 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_accessor_class_concept.h" -/******************************************************* - * Enrico Fucile - ******************************************************/ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = unpack_double;pack_double - IMPLEMENTS = unpack_string;pack_string;string_length - IMPLEMENTS = unpack_long;pack_long;destroy - IMPLEMENTS = init;dump;value_count;get_native_type - IMPLEMENTS = compare - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int pack_string(grib_accessor*, const char*, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static size_t string_length(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void destroy(grib_context*, grib_accessor*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); -static int compare(grib_accessor*, grib_accessor*); - -typedef struct grib_accessor_concept -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in concept */ -} grib_accessor_concept; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_concept = { - &grib_accessor_class_gen, /* super */ - "concept", /* name */ - sizeof(grib_accessor_concept), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - &destroy, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - &string_length, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - &pack_string, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - &compare, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - +grib_accessor_class_concept_t _grib_accessor_class_concept{ "concept" }; grib_accessor_class* grib_accessor_class_concept = &_grib_accessor_class_concept; -/* END_CLASS_IMP */ #define MAX_CONCEPT_STRING_LENGTH 255 @@ -134,12 +33,13 @@ GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b) return (*a == 0 && *b == 0) ? 0 : 1; } -static void init(grib_accessor* a, const long len, grib_arguments* args) +void grib_accessor_class_concept_t::init(grib_accessor* a, const long len, grib_arguments* args) { + grib_accessor_class_gen_t::init(a, len, args); a->length = 0; } -static void dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_class_concept_t::dump(grib_accessor* a, grib_dumper* dumper) { grib_dump_string(dumper, a, NULL); } @@ -192,7 +92,7 @@ static int concept_condition_expression_true(grib_handle* h, grib_concept_condit /* Return 1 (=True) or 0 (=False) */ static int concept_condition_iarray_true(grib_handle* h, grib_concept_condition* c) { - long* val = NULL; + long* val = NULL; size_t size = 0, i; int ret; /* Boolean */ int err = 0; @@ -263,7 +163,6 @@ static const char* concept_evaluate(grib_accessor* a) } #define MAX_NUM_CONCEPT_VALUES 40 - static int concept_conditions_expression_apply(grib_handle* h, grib_concept_condition* e, grib_values* values, grib_sarray* sa, int* n) { long lres = 0; @@ -318,9 +217,9 @@ static int cmpstringp(const void* p1, const void* p2) return strcmp(*(char* const*)p1, *(char* const*)p2); } -static bool blacklisted(grib_handle* h, long edition, const char* concept_name, const char* concept_value) +bool blacklisted(grib_handle* h, long edition, const char* concept_name, const char* concept_value) { - if ( strcmp(concept_name, "packingType")==0 ) { + if (strcmp(concept_name, "packingType") == 0) { char input_packing_type[100]; size_t len = sizeof(input_packing_type); if (strstr(concept_value, "SPD")) { @@ -336,10 +235,10 @@ static bool blacklisted(grib_handle* h, long edition, const char* concept_name, return true; } grib_get_string(h, "packingType", input_packing_type, &len); - if (strstr(input_packing_type,"grid_") && !strstr(concept_value,"grid_")) { + if (strstr(input_packing_type, "grid_") && !strstr(concept_value, "grid_")) { return true; } - if (strstr(input_packing_type,"spectral_") && !strstr(concept_value,"spectral_")) { + if (strstr(input_packing_type, "spectral_") && !strstr(concept_value, "spectral_")) { return true; } } @@ -372,8 +271,10 @@ static int grib_concept_apply(grib_accessor* a, const char* name) size_t i = 0, concept_count = 0; long dummy = 0, editionNumber = 0; char centre_s[32] = {0,}; - size_t centre_len = sizeof(centre_s); - char* all_concept_vals[MAX_NUM_CONCEPT_VALUES] = {NULL,}; /* sorted array containing concept values */ + size_t centre_len = sizeof(centre_s); + char* all_concept_vals[MAX_NUM_CONCEPT_VALUES] = { + NULL, + }; /* sorted array containing concept values */ grib_concept_value* pCon = concepts; grib_context_log(h->context, GRIB_LOG_ERROR, "concept: no match for %s=%s", act->name, name); @@ -390,11 +291,12 @@ static int grib_concept_apply(grib_accessor* a, const char* name) if (string_to_long(name, &dummy, 1) == GRIB_SUCCESS) { // The paramId value is an integer. Show them the param DB grib_context_log(h->context, GRIB_LOG_ERROR, - "Please check the Parameter Database 'https://codes.ecmwf.int/grib/param-db/?id=%s'", name); - } else { + "Please check the Parameter Database 'https://codes.ecmwf.int/grib/param-db/?id=%s'", name); + } + else { // paramId being set to a non-integer grib_context_log(h->context, GRIB_LOG_ERROR, - "The paramId value should be an integer. Are you trying to set the shortName?"); + "The paramId value should be an integer. Are you trying to set the shortName?"); } } if (strcmp(act->name, "shortName") == 0) { @@ -446,31 +348,31 @@ static int grib_concept_apply(grib_accessor* a, const char* name) return err; } -static int pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_class_concept_t::pack_double(grib_accessor* a, const double* val, size_t* len) { return GRIB_NOT_IMPLEMENTED; } -static int pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_class_concept_t::pack_long(grib_accessor* a, const long* val, size_t* len) { char buf[80]; size_t s; snprintf(buf, sizeof(buf), "%ld", *val); - //if(*len > 1) - // return GRIB_NOT_IMPLEMENTED; + // if(*len > 1) + // return GRIB_NOT_IMPLEMENTED; // ECC-1806: GRIB: Change of paramId in conversion from GRIB1 to GRIB2 if (STR_EQUAL(a->name, "paramId")) { grib_handle* h = grib_handle_of_accessor(a); - long edition = 0; + long edition = 0; if (grib_get_long(h, "edition", &edition) == GRIB_SUCCESS && edition == 2) { long newParamId = 0; if (grib_get_long(h, "paramIdForConversion", &newParamId) == GRIB_SUCCESS && newParamId > 0) { if (a->context->debug) { const char* cclass_name = a->cclass->name; fprintf(stderr, "ECCODES DEBUG %s::%s: Changing %s from %ld to %ld\n", - cclass_name, __func__, a->name, *val, newParamId); + cclass_name, __func__, a->name, *val, newParamId); } snprintf(buf, sizeof(buf), "%ld", newParamId); } @@ -481,7 +383,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) return pack_string(a, buf, &s); } -static int unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_class_concept_t::unpack_double(grib_accessor* a, double* val, size_t* len) { /* * If we want to have a condition which contains tests for paramId as well @@ -514,7 +416,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) return ret; } -static int unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_class_concept_t::unpack_long(grib_accessor* a, long* val, size_t* len) { const char* p = concept_evaluate(a); @@ -534,14 +436,14 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) * Keep this check in DEBUG mode only */ { - char *endptr; + char* endptr; *val = strtol(p, &endptr, 10); if (endptr == p || *endptr != '\0') { /* Failed to convert string into integer */ int type = GRIB_TYPE_UNDEFINED; - grib_context_log(a->context,GRIB_LOG_ERROR,"Cannot unpack %s as long",a->name); + grib_context_log(a->context, GRIB_LOG_ERROR, "Cannot unpack %s as long", a->name); if (grib_get_native_type(grib_handle_of_accessor(a), a->name, &type) == GRIB_SUCCESS) { - grib_context_log(a->context,GRIB_LOG_ERROR,"Hint: Try unpacking as %s", grib_get_type_name(type)); + grib_context_log(a->context, GRIB_LOG_ERROR, "Hint: Try unpacking as %s", grib_get_type_name(type)); } return GRIB_DECODING_ERROR; } @@ -550,7 +452,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) return GRIB_SUCCESS; } -static int get_native_type(grib_accessor* a) +int grib_accessor_class_concept_t::get_native_type(grib_accessor* a) { int type = GRIB_TYPE_STRING; if (a->flags & GRIB_ACCESSOR_FLAG_LONG_TYPE) @@ -559,13 +461,14 @@ static int get_native_type(grib_accessor* a) return type; } -static void destroy(grib_context* c, grib_accessor* a) +void grib_accessor_class_concept_t::destroy(grib_context* c, grib_accessor* a) { - //grib_accessor_concept *self = (grib_accessor_concept*)a; - //grib_context_free(c,self->cval); + // grib_accessor_concept_t *self = (grib_accessor_concept_t*)a; + // grib_context_free(c,self->cval); + grib_accessor_class_gen_t::destroy(c, a); } -static int unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_class_concept_t::unpack_string(grib_accessor* a, char* val, size_t* len) { size_t slen; const char* p = concept_evaluate(a); @@ -581,7 +484,7 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len) slen = strlen(p) + 1; if (*len < slen) { grib_context_log(a->context, GRIB_LOG_ERROR, - "Concept unpack_string. Buffer too small for %s, value='%s' which requires %lu bytes (len=%lu)", + "Concept unpack_string. Buffer too small for %s, value='%s' which requires %lu bytes (len=%lu)", a->name, p, slen, *len); *len = slen; return GRIB_BUFFER_TOO_SMALL; @@ -589,33 +492,33 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len) strcpy(val, p); /* NOLINT: CWE-119 clang-analyzer-security.insecureAPI.strcpy */ *len = slen; -// if (a->context->debug==1) { -// int err = 0; -// char result[1024] = {0,}; -// err = get_concept_condition_string(grib_handle_of_accessor(a), a->name, val, result); -// if (!err) fprintf(stderr, "ECCODES DEBUG concept name=%s, value=%s, conditions=%s\n", a->name, val, result); -// } + // if (a->context->debug==1) { + // int err = 0; + // char result[1024] = {0,}; + // err = get_concept_condition_string(grib_handle_of_accessor(a), a->name, val, result); + // if (!err) fprintf(stderr, "ECCODES DEBUG concept name=%s, value=%s, conditions=%s\n", a->name, val, result); + // } return GRIB_SUCCESS; } -static int pack_string(grib_accessor* a, const char* val, size_t* len) +int grib_accessor_class_concept_t::pack_string(grib_accessor* a, const char* val, size_t* len) { return grib_concept_apply(a, val); } -static size_t string_length(grib_accessor* a) +size_t grib_accessor_class_concept_t::string_length(grib_accessor* a) { return MAX_CONCEPT_STRING_LENGTH; } -static int value_count(grib_accessor* a, long* count) +int grib_accessor_class_concept_t::value_count(grib_accessor* a, long* count) { *count = 1; return 0; } -static int compare(grib_accessor* a, grib_accessor* b) +int grib_accessor_class_concept_t::compare(grib_accessor* a, grib_accessor* b) { int retval = 0; char* aval = 0; @@ -626,11 +529,11 @@ static int compare(grib_accessor* a, grib_accessor* b) int err = 0; long count = 0; - err = grib_value_count(a, &count); + err = a->value_count(&count); if (err) return err; alen = count; - err = grib_value_count(b, &count); + err = b->value_count(&count); if (err) return err; blen = count; @@ -642,9 +545,9 @@ static int compare(grib_accessor* a, grib_accessor* b) aval = (char*)grib_context_malloc(a->context, alen * sizeof(char)); bval = (char*)grib_context_malloc(b->context, blen * sizeof(char)); - err = grib_unpack_string(a, aval, &alen); + err = a->unpack_string(aval, &alen); if (err) return err; - err = grib_unpack_string(b, bval, &blen); + err = b->unpack_string(bval, &blen); if (err) return err; retval = GRIB_SUCCESS; diff --git a/src/accessor/grib_accessor_class_concept.h b/src/accessor/grib_accessor_class_concept.h new file mode 100644 index 000000000..7b9ea11d0 --- /dev/null +++ b/src/accessor/grib_accessor_class_concept.h @@ -0,0 +1,40 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_concept_t : public grib_accessor_gen_t +{ +public: + /* Members defined in concept */ +}; + +class grib_accessor_class_concept_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_concept_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_concept_t{}; } + int get_native_type(grib_accessor*) override; + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int pack_string(grib_accessor*, const char*, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + size_t string_length(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void destroy(grib_context*, grib_accessor*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + int compare(grib_accessor*, grib_accessor*) override; +}; diff --git a/src/accessor/grib_accessor_class_constant.cc b/src/accessor/grib_accessor_class_constant.cc new file mode 100644 index 000000000..ed30a6365 --- /dev/null +++ b/src/accessor/grib_accessor_class_constant.cc @@ -0,0 +1,20 @@ +/* + * (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. + */ + +#include "grib_accessor_class_constant.h" + +grib_accessor_class_constant_t _grib_accessor_class_constant{"constant"}; +grib_accessor_class* grib_accessor_class_constant = &_grib_accessor_class_constant; + +void grib_accessor_class_constant_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ + grib_accessor_class_variable_t::init(a, len, arg); + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; +} diff --git a/src/accessor/grib_accessor_class_constant.h b/src/accessor/grib_accessor_class_constant.h new file mode 100644 index 000000000..916df88e9 --- /dev/null +++ b/src/accessor/grib_accessor_class_constant.h @@ -0,0 +1,21 @@ +/* + * (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. + */ + +#include "grib_accessor_class_variable.h" + +class grib_accessor_constant_t : public grib_accessor_variable_t {}; + +class grib_accessor_class_constant_t : public grib_accessor_class_variable_t +{ +public: + grib_accessor_class_constant_t(const char* name) : grib_accessor_class_variable_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_constant_t{}; } + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_count_file.cc b/src/accessor/grib_accessor_class_count_file.cc new file mode 100644 index 000000000..268ba8051 --- /dev/null +++ b/src/accessor/grib_accessor_class_count_file.cc @@ -0,0 +1,30 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_count_file.h" + +grib_accessor_class_count_file_t _grib_accessor_class_count_file{ "count_file" }; +grib_accessor_class* grib_accessor_class_count_file = &_grib_accessor_class_count_file; + + +void grib_accessor_class_count_file_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ + grib_accessor_class_long_t::init(a, l, c); + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->length = 0; +} + +int grib_accessor_class_count_file_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ + *val = grib_context_get_handle_file_count(a->context); + *len = 1; + return 0; +} diff --git a/src/accessor/grib_accessor_class_count_file.h b/src/accessor/grib_accessor_class_count_file.h new file mode 100644 index 000000000..25092b0a4 --- /dev/null +++ b/src/accessor/grib_accessor_class_count_file.h @@ -0,0 +1,29 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_count_file_t : public grib_accessor_long_t +{ +public: + /* Members defined in count_file */ +}; + +class grib_accessor_class_count_file_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_count_file_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_count_file_t{}; } + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_count_missing.cc b/src/accessor/grib_accessor_class_count_missing.cc similarity index 50% rename from src/grib_accessor_class_count_missing.cc rename to src/accessor/grib_accessor_class_count_missing.cc index a4ed76841..7a3232175 100644 --- a/src/grib_accessor_class_count_missing.cc +++ b/src/accessor/grib_accessor_class_count_missing.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,104 +9,11 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long - IMPLEMENTS = init; - IMPLEMENTS = value_count - MEMBERS = const char* bitmap - MEMBERS = const char* unusedBitsInBitmap - MEMBERS = const char* numberOfDataPoints - MEMBERS = const char* missingValueManagementUsed - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_count_missing -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in count_missing */ - const char* bitmap; - const char* unusedBitsInBitmap; - const char* numberOfDataPoints; - const char* missingValueManagementUsed; -} grib_accessor_count_missing; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_count_missing = { - &grib_accessor_class_long, /* super */ - "count_missing", /* name */ - sizeof(grib_accessor_count_missing), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_count_missing.h" +grib_accessor_class_count_missing_t _grib_accessor_class_count_missing{ "count_missing" }; grib_accessor_class* grib_accessor_class_count_missing = &_grib_accessor_class_count_missing; -/* END_CLASS_IMP */ static const unsigned char bitsoff[] = { 8, 7, 7, 6, 7, 6, 6, 5, 7, 6, 6, 5, 6, 5, 5, 4, 7, @@ -126,16 +34,17 @@ static const unsigned char bitsoff[] = { 0 }; -static void init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_class_count_missing_t::init(grib_accessor* a, const long len, grib_arguments* arg) { - int n = 0; - grib_accessor_count_missing* self = (grib_accessor_count_missing*)a; - grib_handle* h = grib_handle_of_accessor(a); - a->length = 0; + grib_accessor_class_long_t::init(a, len, arg); + int n = 0; + grib_accessor_count_missing_t* self = (grib_accessor_count_missing_t*)a; + grib_handle* h = grib_handle_of_accessor(a); + a->length = 0; a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - self->bitmap = grib_arguments_get_name(h, arg, n++); - self->unusedBitsInBitmap = grib_arguments_get_name(h, arg, n++); - self->numberOfDataPoints = grib_arguments_get_name(h, arg, n++); + self->bitmap = grib_arguments_get_name(h, arg, n++); + self->unusedBitsInBitmap = grib_arguments_get_name(h, arg, n++); + self->numberOfDataPoints = grib_arguments_get_name(h, arg, n++); self->missingValueManagementUsed = grib_arguments_get_name(h, arg, n++); /* Can be NULL */ } @@ -165,9 +74,9 @@ static int get_count_of_missing_values(grib_handle* h, long* p_count_of_missing) return GRIB_SUCCESS; } -static int unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_class_count_missing_t::unpack_long(grib_accessor* a, long* val, size_t* len) { - grib_accessor_count_missing* self = (grib_accessor_count_missing*)a; + grib_accessor_count_missing_t* self = (grib_accessor_count_missing_t*)a; unsigned char* p; int i; long size = 0; @@ -182,11 +91,10 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) if (!bitmap) { long mvmu = 0; if (self->missingValueManagementUsed && - grib_get_long(h, self->missingValueManagementUsed, &mvmu) == GRIB_SUCCESS && mvmu != 0) - { + grib_get_long(h, self->missingValueManagementUsed, &mvmu) == GRIB_SUCCESS && mvmu != 0) { /* ECC-523: No bitmap. Missing values are encoded in the Data Section. * So we must decode all the data values and count how many are missing - */ + */ long count_of_missing = 0; if (get_count_of_missing_values(h, &count_of_missing) == GRIB_SUCCESS) { *val = count_of_missing; @@ -195,9 +103,8 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) return GRIB_SUCCESS; } - size = grib_byte_count(bitmap); - offset = grib_byte_offset(bitmap); - + size = bitmap->byte_count(); + offset = bitmap->byte_offset(); if (grib_get_long(h, self->unusedBitsInBitmap, &unusedBitsInBitmap) != GRIB_SUCCESS) { if (grib_get_long(h, self->numberOfDataPoints, &numberOfDataPoints) != GRIB_SUCCESS) { grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to count missing values"); @@ -206,7 +113,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) unusedBitsInBitmap = size * 8 - numberOfDataPoints; if (unusedBitsInBitmap < 0) { grib_context_log(a->context, GRIB_LOG_ERROR, "Inconsistent number of bitmap points: Check the bitmap and data sections!"); - grib_context_log(a->context, GRIB_LOG_ERROR, "Bitmap size=%ld, numberOfDataPoints=%ld", size*8, numberOfDataPoints); + grib_context_log(a->context, GRIB_LOG_ERROR, "Bitmap size=%ld, numberOfDataPoints=%ld", size * 8, numberOfDataPoints); return GRIB_DECODING_ERROR; } } @@ -224,7 +131,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) return GRIB_SUCCESS; } -static int value_count(grib_accessor* a, long* count) +int grib_accessor_class_count_missing_t::value_count(grib_accessor* a, long* count) { *count = 1; return 0; diff --git a/src/accessor/grib_accessor_class_count_missing.h b/src/accessor/grib_accessor_class_count_missing.h new file mode 100644 index 000000000..3e2cf7330 --- /dev/null +++ b/src/accessor/grib_accessor_class_count_missing.h @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_count_missing_t : public grib_accessor_long_t +{ +public: + /* Members defined in count_missing */ + const char* bitmap; + const char* unusedBitsInBitmap; + const char* numberOfDataPoints; + const char* missingValueManagementUsed; +}; + +class grib_accessor_class_count_missing_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_count_missing_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_count_missing_t{}; } + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_count_total.cc b/src/accessor/grib_accessor_class_count_total.cc new file mode 100644 index 000000000..dc708b4b6 --- /dev/null +++ b/src/accessor/grib_accessor_class_count_total.cc @@ -0,0 +1,30 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_count_total.h" + +grib_accessor_class_count_total_t _grib_accessor_class_count_total{ "count_total" }; +grib_accessor_class* grib_accessor_class_count_total = &_grib_accessor_class_count_total; + + +void grib_accessor_class_count_total_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ + grib_accessor_class_long_t::init(a, l, c); + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->length = 0; +} + +int grib_accessor_class_count_total_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ + *val = grib_context_get_handle_total_count(a->context); + *len = 1; + return 0; +} diff --git a/src/accessor/grib_accessor_class_count_total.h b/src/accessor/grib_accessor_class_count_total.h new file mode 100644 index 000000000..6fa89df0e --- /dev/null +++ b/src/accessor/grib_accessor_class_count_total.h @@ -0,0 +1,29 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_count_total_t : public grib_accessor_long_t +{ +public: + /* Members defined in count_total */ +}; + +class grib_accessor_class_count_total_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_count_total_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_count_total_t{}; } + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_data_apply_bitmap.cc b/src/accessor/grib_accessor_class_data_apply_bitmap.cc similarity index 58% rename from src/grib_accessor_class_data_apply_bitmap.cc rename to src/accessor/grib_accessor_class_data_apply_bitmap.cc index 675e7b3de..cf3d5f4a5 100644 --- a/src/grib_accessor_class_data_apply_bitmap.cc +++ b/src/accessor/grib_accessor_class_data_apply_bitmap.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,123 +9,17 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_value.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init - IMPLEMENTS = unpack_double;unpack_double_element;unpack_double_element_set - IMPLEMENTS = unpack_float - IMPLEMENTS = pack_double - IMPLEMENTS = value_count - IMPLEMENTS = dump;get_native_type - IMPLEMENTS = compare - MEMBERS=const char* coded_values - MEMBERS=const char* bitmap - MEMBERS=const char* missing_value - MEMBERS=const char* number_of_data_points - MEMBERS=const char* number_of_values - MEMBERS=const char* binary_scale_factor - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_float(grib_accessor*, float* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); -static int compare(grib_accessor*, grib_accessor*); -static int unpack_double_element(grib_accessor*, size_t i, double* val); -static int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array); - -typedef struct grib_accessor_data_apply_bitmap -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in data_apply_bitmap */ - const char* coded_values; - const char* bitmap; - const char* missing_value; - const char* number_of_data_points; - const char* number_of_values; - const char* binary_scale_factor; -} grib_accessor_data_apply_bitmap; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_data_apply_bitmap = { - &grib_accessor_class_gen, /* super */ - "data_apply_bitmap", /* name */ - sizeof(grib_accessor_data_apply_bitmap), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - &unpack_float, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - &compare, /* compare vs. another accessor */ - &unpack_double_element, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - &unpack_double_element_set, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_data_apply_bitmap.h" +grib_accessor_class_data_apply_bitmap_t _grib_accessor_class_data_apply_bitmap{ "data_apply_bitmap" }; grib_accessor_class* grib_accessor_class_data_apply_bitmap = &_grib_accessor_class_data_apply_bitmap; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_class_data_apply_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args) { - int n = 0; - grib_accessor_data_apply_bitmap* self = (grib_accessor_data_apply_bitmap*)a; + grib_accessor_class_gen_t::init(a, v, args); + int n = 0; + grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a; self->coded_values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); self->bitmap = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); @@ -135,16 +30,16 @@ static void init(grib_accessor* a, const long v, grib_arguments* args) a->length = 0; } -static void dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_class_data_apply_bitmap_t::dump(grib_accessor* a, grib_dumper* dumper) { grib_dump_values(dumper, a); } -static int value_count(grib_accessor* a, long* count) +int grib_accessor_class_data_apply_bitmap_t::value_count(grib_accessor* a, long* count) { - grib_accessor_data_apply_bitmap* self = (grib_accessor_data_apply_bitmap*)a; - size_t len = 0; - int ret = 0; + grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a; + size_t len = 0; + int ret = GRIB_SUCCESS; if (grib_find_accessor(grib_handle_of_accessor(a), self->bitmap)) ret = grib_get_size(grib_handle_of_accessor(a), self->bitmap, &len); @@ -156,18 +51,17 @@ static int value_count(grib_accessor* a, long* count) return ret; } -static int unpack_double_element(grib_accessor* a, size_t idx, double* val) +int grib_accessor_class_data_apply_bitmap_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) { - grib_accessor_data_apply_bitmap* self = (grib_accessor_data_apply_bitmap*)a; - grib_handle* gh = grib_handle_of_accessor(a); - int err = 0, i = 0; - size_t cidx = 0; + grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a; + grib_handle* gh = grib_handle_of_accessor(a); + size_t i = 0, cidx = 0; double missing_value = 0; double* bvals = NULL; size_t n_vals = 0; long nn = 0; - err = grib_value_count(a, &nn); + int err = a->value_count(&nn); n_vals = nn; if (err) return err; @@ -203,20 +97,20 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) return grib_get_double_element_internal(gh, self->coded_values, cidx, val); } -static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) +int grib_accessor_class_data_apply_bitmap_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) { - grib_accessor_data_apply_bitmap* self = (grib_accessor_data_apply_bitmap*)a; - grib_handle* gh = grib_handle_of_accessor(a); + grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a; + grib_handle* gh = grib_handle_of_accessor(a); int err = 0, all_missing = 1; - size_t cidx = 0; /* index into the coded_values array */ - size_t* cidx_array = NULL; /* array of indexes into the coded_values */ - double* cval_array = NULL; /* array of values of the coded_values */ + size_t cidx = 0; /* index into the coded_values array */ + size_t* cidx_array = NULL; /* array of indexes into the coded_values */ + double* cval_array = NULL; /* array of values of the coded_values */ double missing_value = 0; double* bvals = NULL; size_t n_vals = 0, i = 0, j = 0, idx = 0, count_1s = 0, ci = 0; long nn = 0; - err = grib_value_count(a, &nn); + err = a->value_count(&nn); n_vals = nn; if (err) return err; @@ -231,7 +125,8 @@ static int unpack_double_element_set(grib_accessor* a, const size_t* index_array for (i = 0; i < len; i++) { if (val_array[i] == 0) { val_array[i] = missing_value; - } else { + } + else { all_missing = 0; count_1s++; } @@ -256,7 +151,7 @@ static int unpack_double_element_set(grib_accessor* a, const size_t* index_array ci = 0; for (i = 0; i < len; i++) { if (val_array[i] == 1) { - idx = index_array[i]; + idx = index_array[i]; cidx = 0; for (j = 0; j < idx; j++) { cidx += bvals[j]; @@ -283,18 +178,18 @@ static int unpack_double_element_set(grib_accessor* a, const size_t* index_array return GRIB_SUCCESS; } -static int pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_class_data_apply_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len) { - grib_accessor_data_apply_bitmap* self = (grib_accessor_data_apply_bitmap*)a; - int err = 0; - size_t bmaplen = *len; - long coded_n_vals = 0; - double* coded_vals = NULL; - long i = 0; - long j = 0; - double missing_value = 0; - grib_handle* hand = grib_handle_of_accessor(a); - grib_context* ctxt = a->context; + grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a; + int err = 0; + size_t bmaplen = *len; + long coded_n_vals = 0; + double* coded_vals = NULL; + long i = 0; + long j = 0; + double missing_value = 0; + grib_handle* hand = grib_handle_of_accessor(a); + grib_context* ctxt = a->context; if (*len == 0) return GRIB_NO_VALUES; @@ -343,22 +238,22 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) return err; } + template static int unpack(grib_accessor* a, T* val, size_t* len) { static_assert(std::is_floating_point::value, "Requires floating point numbers"); - grib_accessor_data_apply_bitmap* self = (grib_accessor_data_apply_bitmap*)a; + grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a; size_t i = 0; size_t j = 0; size_t n_vals = 0; long nn = 0; - int err = 0; size_t coded_n_vals = 0; - T* coded_vals = NULL; + T* coded_vals = NULL; double missing_value = 0; - err = grib_value_count(a, &nn); + int err = a->value_count(&nn); n_vals = nn; if (err) return err; @@ -399,8 +294,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) grib_context_log(a->context, GRIB_LOG_DEBUG, "grib_accessor_class_data_apply_bitmap: %s : creating %s, %d values", - __func__, - a->name, n_vals); + __func__, a->name, n_vals); for (i = 0; i < n_vals; i++) { if (val[i] == 0) { @@ -426,25 +320,24 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return err; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_class_data_apply_bitmap_t::unpack_double(grib_accessor* a, double* val, size_t* len) { return unpack(a, val, len); } -static int unpack_float(grib_accessor* a, float* val, size_t* len) +int grib_accessor_class_data_apply_bitmap_t::unpack_float(grib_accessor* a, float* val, size_t* len) { return unpack(a, val, len); } -static int get_native_type(grib_accessor* a) +int grib_accessor_class_data_apply_bitmap_t::get_native_type(grib_accessor* a) { - //grib_accessor_data_apply_bitmap* self = (grib_accessor_data_apply_bitmap*)a; - //return grib_accessor_get_native_type(grib_find_accessor(grib_handle_of_accessor(a),self->coded_values)); - + // grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a; + // return grib_accessor_get_native_type(grib_find_accessor(grib_handle_of_accessor(a),self->coded_values)); return GRIB_TYPE_DOUBLE; } -static int compare(grib_accessor* a, grib_accessor* b) +int grib_accessor_class_data_apply_bitmap_t::compare(grib_accessor* a, grib_accessor* b) { int retval = GRIB_SUCCESS; double* aval = 0; @@ -455,12 +348,12 @@ static int compare(grib_accessor* a, grib_accessor* b) int err = 0; long count = 0; - err = grib_value_count(a, &count); + err = a->value_count(&count); if (err) return err; alen = count; - err = grib_value_count(b, &count); + err = b->value_count(&count); if (err) return err; blen = count; @@ -471,11 +364,10 @@ static int compare(grib_accessor* a, grib_accessor* b) aval = (double*)grib_context_malloc(a->context, alen * sizeof(double)); bval = (double*)grib_context_malloc(b->context, blen * sizeof(double)); - grib_unpack_double(a, aval, &alen); - grib_unpack_double(b, bval, &blen); - + a->unpack_double(aval, &alen); + b->unpack_double(bval, &blen); retval = GRIB_SUCCESS; - for (size_t i=0; ivalues = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); self->numberOfRows = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); self->numberOfColumns = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); @@ -130,26 +29,23 @@ static void init(grib_accessor* a, const long v, grib_arguments* args) a->length = 0; } -static void dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_class_data_apply_boustrophedonic_t::dump(grib_accessor* a, grib_dumper* dumper) { grib_dump_values(dumper, a); } -static int value_count(grib_accessor* a, long* numberOfPoints) +int grib_accessor_class_data_apply_boustrophedonic_t::value_count(grib_accessor* a, long* numberOfPoints) { - grib_accessor_data_apply_boustrophedonic* self = (grib_accessor_data_apply_boustrophedonic*)a; - int ret = 0; + grib_accessor_data_apply_boustrophedonic_t* self = (grib_accessor_data_apply_boustrophedonic_t*)a; *numberOfPoints = 0; - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints, numberOfPoints); - - return ret; + return grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints, numberOfPoints); } template static int unpack(grib_accessor* a, T* val, size_t* len) { - grib_accessor_data_apply_boustrophedonic* self = (grib_accessor_data_apply_boustrophedonic*)a; + grib_accessor_data_apply_boustrophedonic_t* self = (grib_accessor_data_apply_boustrophedonic_t*)a; size_t plSize = 0; long* pl = 0; @@ -242,24 +138,23 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return GRIB_SUCCESS; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_class_data_apply_boustrophedonic_t::unpack_double(grib_accessor* a, double* val, size_t* len) { return unpack(a, val, len); } -static int unpack_float(grib_accessor* a, float* val, size_t* len) +int grib_accessor_class_data_apply_boustrophedonic_t::unpack_float(grib_accessor* a, float* val, size_t* len) { return unpack(a, val, len); } -static int unpack_double_element(grib_accessor* a, size_t idx, double* val) +int grib_accessor_class_data_apply_boustrophedonic_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) { size_t size; double* values; - int err = 0; /* GRIB-564: The index idx relates to codedValues NOT values! */ - err = grib_get_size(a->parent->h, "codedValues", &size); + int err = grib_get_size(a->parent->h, "codedValues", &size); if (err) return err; if (idx > size) @@ -276,7 +171,7 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) return GRIB_SUCCESS; } -static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) +int grib_accessor_class_data_apply_boustrophedonic_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) { size_t size = 0, i = 0; double* values; @@ -304,9 +199,9 @@ static int unpack_double_element_set(grib_accessor* a, const size_t* index_array return GRIB_SUCCESS; } -static int pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_class_data_apply_boustrophedonic_t::pack_double(grib_accessor* a, const double* val, size_t* len) { - grib_accessor_data_apply_boustrophedonic* self = (grib_accessor_data_apply_boustrophedonic*)a; + grib_accessor_data_apply_boustrophedonic_t* self = (grib_accessor_data_apply_boustrophedonic_t*)a; size_t plSize = 0; long* pl = 0; @@ -315,10 +210,9 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) double* pval = 0; size_t valuesSize = 0; long i, j; - int ret; long numberOfPoints, numberOfRows, numberOfColumns; - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints, &numberOfPoints); + int ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints, &numberOfPoints); if (ret) return ret; @@ -388,7 +282,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) return GRIB_SUCCESS; } -static int get_native_type(grib_accessor* a) +int grib_accessor_class_data_apply_boustrophedonic_t::get_native_type(grib_accessor* a) { return GRIB_TYPE_DOUBLE; } diff --git a/src/accessor/grib_accessor_class_data_apply_boustrophedonic.h b/src/accessor/grib_accessor_class_data_apply_boustrophedonic.h new file mode 100644 index 000000000..97987d217 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_apply_boustrophedonic.h @@ -0,0 +1,40 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_data_apply_boustrophedonic_t : public grib_accessor_gen_t +{ +public: + /* Members defined in data_apply_boustrophedonic */ + const char* values; + const char* numberOfRows; + const char* numberOfColumns; + const char* numberOfPoints; + const char* pl; +}; + +class grib_accessor_class_data_apply_boustrophedonic_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_data_apply_boustrophedonic_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_apply_boustrophedonic_t{}; } + int get_native_type(grib_accessor*) override; + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_float(grib_accessor*, float* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_double_element(grib_accessor*, size_t i, double* val) override; + int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override; +}; diff --git a/src/grib_accessor_class_data_apply_boustrophedonic_bitmap.cc b/src/accessor/grib_accessor_class_data_apply_boustrophedonic_bitmap.cc similarity index 69% rename from src/grib_accessor_class_data_apply_boustrophedonic_bitmap.cc rename to src/accessor/grib_accessor_class_data_apply_boustrophedonic_bitmap.cc index b68e362db..f796cfb02 100644 --- a/src/grib_accessor_class_data_apply_boustrophedonic_bitmap.cc +++ b/src/accessor/grib_accessor_class_data_apply_boustrophedonic_bitmap.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,122 +9,16 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init - IMPLEMENTS = unpack_double;unpack_double_element;unpack_double_element_set - IMPLEMENTS = pack_double - IMPLEMENTS = value_count - IMPLEMENTS = dump;get_native_type - MEMBERS=const char* coded_values - MEMBERS=const char* bitmap - MEMBERS=const char* missing_value - MEMBERS=const char* binary_scale_factor - MEMBERS=const char* numberOfRows - MEMBERS=const char* numberOfColumns - MEMBERS=const char* numberOfPoints - - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); -static int unpack_double_element(grib_accessor*, size_t i, double* val); -static int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array); - -typedef struct grib_accessor_data_apply_boustrophedonic_bitmap -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in data_apply_boustrophedonic_bitmap */ - const char* coded_values; - const char* bitmap; - const char* missing_value; - const char* binary_scale_factor; - const char* numberOfRows; - const char* numberOfColumns; - const char* numberOfPoints; -} grib_accessor_data_apply_boustrophedonic_bitmap; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_data_apply_boustrophedonic_bitmap = { - &grib_accessor_class_gen, /* super */ - "data_apply_boustrophedonic_bitmap", /* name */ - sizeof(grib_accessor_data_apply_boustrophedonic_bitmap), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - &unpack_double_element, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - &unpack_double_element_set, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_data_apply_boustrophedonic_bitmap.h" +grib_accessor_class_data_apply_boustrophedonic_bitmap_t _grib_accessor_class_data_apply_boustrophedonic_bitmap{"data_apply_boustrophedonic_bitmap"}; grib_accessor_class* grib_accessor_class_data_apply_boustrophedonic_bitmap = &_grib_accessor_class_data_apply_boustrophedonic_bitmap; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long v, grib_arguments* args) -{ +void grib_accessor_class_data_apply_boustrophedonic_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args){ + grib_accessor_class_gen_t::init(a, v, args); int n = 0; - grib_accessor_data_apply_boustrophedonic_bitmap* self = (grib_accessor_data_apply_boustrophedonic_bitmap*)a; + grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a; grib_handle* gh = grib_handle_of_accessor(a); self->coded_values = grib_arguments_get_name(gh, args, n++); @@ -138,14 +33,12 @@ static void init(grib_accessor* a, const long v, grib_arguments* args) a->length = 0; } -static void dump(grib_accessor* a, grib_dumper* dumper) -{ +void grib_accessor_class_data_apply_boustrophedonic_bitmap_t::dump(grib_accessor* a, grib_dumper* dumper){ grib_dump_values(dumper, a); } -static int value_count(grib_accessor* a, long* count) -{ - grib_accessor_data_apply_boustrophedonic_bitmap* self = (grib_accessor_data_apply_boustrophedonic_bitmap*)a; +int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::value_count(grib_accessor* a, long* count){ + grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a; grib_handle* gh = grib_handle_of_accessor(a); size_t len = 0; int ret = 0; @@ -158,9 +51,8 @@ static int value_count(grib_accessor* a, long* count) return ret; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_data_apply_boustrophedonic_bitmap* self = (grib_accessor_data_apply_boustrophedonic_bitmap*)a; +int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a; grib_handle* gh = grib_handle_of_accessor(a); size_t i = 0, j = 0, n_vals = 0, irow = 0; @@ -171,8 +63,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) double missing_value = 0; long numberOfPoints, numberOfRows, numberOfColumns; - err = grib_value_count(a, &nn); - n_vals = nn; + err = a->value_count(&nn); n_vals = nn; if (err) return err; @@ -268,9 +159,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) return err; } -static int unpack_double_element(grib_accessor* a, size_t idx, double* val) -{ - grib_accessor_data_apply_boustrophedonic_bitmap* self = (grib_accessor_data_apply_boustrophedonic_bitmap*)a; +int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_element(grib_accessor* a, size_t idx, double* val){ + grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a; grib_handle* gh = grib_handle_of_accessor(a); int err = 0, i = 0; size_t cidx = 0; @@ -279,8 +169,7 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) size_t n_vals = 0; long nn = 0; - err = grib_value_count(a, &nn); - n_vals = nn; + err = a->value_count(&nn); n_vals = nn; if (err) return err; @@ -315,9 +204,8 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) return grib_get_double_element_internal(gh, self->coded_values, cidx, val); } -static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) -{ - grib_accessor_data_apply_boustrophedonic_bitmap* self = (grib_accessor_data_apply_boustrophedonic_bitmap*)a; +int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array){ + grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a; grib_handle* gh = grib_handle_of_accessor(a); int err = 0, all_missing = 1; size_t cidx = 0; /* index into the coded_values array */ @@ -328,8 +216,7 @@ static int unpack_double_element_set(grib_accessor* a, const size_t* index_array size_t n_vals = 0, i = 0, j = 0, idx = 0, count_1s = 0, ci = 0; long nn = 0; - err = grib_value_count(a, &nn); - n_vals = nn; + err = a->value_count(&nn); n_vals = nn; if (err) return err; if (!grib_find_accessor(gh, self->bitmap)) @@ -395,9 +282,8 @@ static int unpack_double_element_set(grib_accessor* a, const size_t* index_array return GRIB_SUCCESS; } -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_data_apply_boustrophedonic_bitmap* self = (grib_accessor_data_apply_boustrophedonic_bitmap*)a; +int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len){ + grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a; grib_handle* gh = grib_handle_of_accessor(a); int err = 0; size_t bmaplen = *len; @@ -495,9 +381,8 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) return err; } -static int get_native_type(grib_accessor* a) -{ - //grib_accessor_data_apply_boustrophedonic_bitmap* self = (grib_accessor_data_apply_boustrophedonic_bitmap*)a; +int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::get_native_type(grib_accessor* a){ + //grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a; //return grib_accessor_get_native_type(grib_find_accessor(grib_handle_of_accessor(a),self->coded_values)); return GRIB_TYPE_DOUBLE; diff --git a/src/accessor/grib_accessor_class_data_apply_boustrophedonic_bitmap.h b/src/accessor/grib_accessor_class_data_apply_boustrophedonic_bitmap.h new file mode 100644 index 000000000..fee603876 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_apply_boustrophedonic_bitmap.h @@ -0,0 +1,41 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_data_apply_boustrophedonic_bitmap_t : public grib_accessor_gen_t +{ +public: + /* Members defined in data_apply_boustrophedonic_bitmap */ + const char* coded_values; + const char* bitmap; + const char* missing_value; + const char* binary_scale_factor; + const char* numberOfRows; + const char* numberOfColumns; + const char* numberOfPoints; +}; + +class grib_accessor_class_data_apply_boustrophedonic_bitmap_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_data_apply_boustrophedonic_bitmap_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_apply_boustrophedonic_bitmap_t{}; } + int get_native_type(grib_accessor*) override; + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_double_element(grib_accessor*, size_t i, double* val) override; + int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override; +}; diff --git a/src/grib_accessor_class_data_ccsds_packing.cc b/src/accessor/grib_accessor_class_data_ccsds_packing.cc similarity index 67% rename from src/grib_accessor_class_data_ccsds_packing.cc rename to src/accessor/grib_accessor_class_data_ccsds_packing.cc index ccfd48c03..5b0813bfd 100644 --- a/src/grib_accessor_class_data_ccsds_packing.cc +++ b/src/accessor/grib_accessor_class_data_ccsds_packing.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,138 +9,26 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_bits_any_endian_simple.h" -#include "grib_scaling.h" -#include -#include +#include "grib_accessor_class_data_ccsds_packing.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_values - IMPLEMENTS = init - IMPLEMENTS = unpack_double - IMPLEMENTS = unpack_float - IMPLEMENTS = pack_double - IMPLEMENTS = unpack_double_element;unpack_double_element_set - IMPLEMENTS = value_count - MEMBERS=const char* number_of_values - MEMBERS=const char* reference_value - MEMBERS=const char* binary_scale_factor - MEMBERS=const char* decimal_scale_factor - MEMBERS=const char* optimize_scaling_factor - MEMBERS=const char* bits_per_value - MEMBERS=const char* number_of_data_points - MEMBERS=const char* ccsds_flags - MEMBERS=const char* ccsds_block_size - MEMBERS=const char* ccsds_rsi - - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_float(grib_accessor*, float* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); -static int unpack_double_element(grib_accessor*, size_t i, double* val); -static int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array); - -typedef struct grib_accessor_data_ccsds_packing -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in values */ - int carg; - const char* seclen; - const char* offsetdata; - const char* offsetsection; - int dirty; - /* Members defined in data_ccsds_packing */ - const char* number_of_values; - const char* reference_value; - const char* binary_scale_factor; - const char* decimal_scale_factor; - const char* optimize_scaling_factor; - const char* bits_per_value; - const char* number_of_data_points; - const char* ccsds_flags; - const char* ccsds_block_size; - const char* ccsds_rsi; -} grib_accessor_data_ccsds_packing; - -extern grib_accessor_class* grib_accessor_class_values; - -static grib_accessor_class _grib_accessor_class_data_ccsds_packing = { - &grib_accessor_class_values, /* super */ - "data_ccsds_packing", /* name */ - sizeof(grib_accessor_data_ccsds_packing), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - &unpack_float, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - &unpack_double_element, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - &unpack_double_element_set, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; +#if defined(HAVE_LIBAEC) || defined(HAVE_AEC) + #include + #ifndef LIBAEC_DLL_EXPORTED + #error Version of libaec appears to be too old. Please upgrade. + #endif +#endif +grib_accessor_class_data_ccsds_packing_t _grib_accessor_class_data_ccsds_packing{ "data_ccsds_packing" }; grib_accessor_class* grib_accessor_class_data_ccsds_packing = &_grib_accessor_class_data_ccsds_packing; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_class_data_ccsds_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) { - grib_accessor_data_ccsds_packing* self = (grib_accessor_data_ccsds_packing*)a; - grib_handle* h = grib_handle_of_accessor(a); + grib_accessor_class_values_t::init(a, v, args); + grib_accessor_data_ccsds_packing_t* self = (grib_accessor_data_ccsds_packing_t*)a; + + grib_handle* h = grib_handle_of_accessor(a); self->number_of_values = grib_arguments_get_name(h, args, self->carg++); self->reference_value = grib_arguments_get_name(h, args, self->carg++); @@ -155,24 +44,18 @@ static void init(grib_accessor* a, const long v, grib_arguments* args) a->flags |= GRIB_ACCESSOR_FLAG_DATA; } -static int value_count(grib_accessor* a, long* count) +int grib_accessor_class_data_ccsds_packing_t::value_count(grib_accessor* a, long* count) { - grib_accessor_data_ccsds_packing* self = (grib_accessor_data_ccsds_packing*)a; + grib_accessor_data_ccsds_packing_t* self = (grib_accessor_data_ccsds_packing_t*)a; *count = 0; return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, count); } #if defined(HAVE_LIBAEC) || defined(HAVE_AEC) -#include - -#ifndef LIBAEC_DLL_EXPORTED - #error Version of libaec appears to be too old. Please upgrade. -#endif - static bool is_big_endian() { - unsigned char is_big_endian = 0; + unsigned char is_big_endian = 0; unsigned short endianess_test = 1; return reinterpret_cast(&endianess_test)[0] == is_big_endian; } @@ -182,38 +65,38 @@ static void modify_aec_flags(long* flags) // ECC-1602: Performance improvement: enabled the use of native data types *flags &= ~AEC_DATA_3BYTE; // disable support for 3-bytes per value if (is_big_endian()) - *flags |= AEC_DATA_MSB; // enable big-endian + *flags |= AEC_DATA_MSB; // enable big-endian else *flags &= ~AEC_DATA_MSB; // enable little-endian } static const char* aec_get_error_message(int code) { - if (code == AEC_MEM_ERROR) return "AEC_MEM_ERROR"; - if (code == AEC_DATA_ERROR) return "AEC_DATA_ERROR"; + if (code == AEC_MEM_ERROR) return "AEC_MEM_ERROR"; + if (code == AEC_DATA_ERROR) return "AEC_DATA_ERROR"; if (code == AEC_STREAM_ERROR) return "AEC_STREAM_ERROR"; - if (code == AEC_CONF_ERROR) return "AEC_CONF_ERROR"; - if (code == AEC_OK) return "AEC_OK"; + if (code == AEC_CONF_ERROR) return "AEC_CONF_ERROR"; + if (code == AEC_OK) return "AEC_OK"; return "Unknown error code"; } static void print_aec_stream_info(struct aec_stream* strm, const char* func) { - fprintf(stderr, "ECCODES DEBUG CCSDS %s aec_stream.flags=%u\n", func, strm->flags); + fprintf(stderr, "ECCODES DEBUG CCSDS %s aec_stream.flags=%u\n", func, strm->flags); fprintf(stderr, "ECCODES DEBUG CCSDS %s aec_stream.bits_per_sample=%u\n", func, strm->bits_per_sample); - fprintf(stderr, "ECCODES DEBUG CCSDS %s aec_stream.block_size=%u\n", func, strm->block_size); - fprintf(stderr, "ECCODES DEBUG CCSDS %s aec_stream.rsi=%u\n", func, strm->rsi); - fprintf(stderr, "ECCODES DEBUG CCSDS %s aec_stream.avail_out=%lu\n", func, strm->avail_out); - fprintf(stderr, "ECCODES DEBUG CCSDS %s aec_stream.avail_in=%lu\n", func, strm->avail_in); + fprintf(stderr, "ECCODES DEBUG CCSDS %s aec_stream.block_size=%u\n", func, strm->block_size); + fprintf(stderr, "ECCODES DEBUG CCSDS %s aec_stream.rsi=%u\n", func, strm->rsi); + fprintf(stderr, "ECCODES DEBUG CCSDS %s aec_stream.avail_out=%lu\n", func, strm->avail_out); + fprintf(stderr, "ECCODES DEBUG CCSDS %s aec_stream.avail_in=%lu\n", func, strm->avail_in); } -static int pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_class_data_ccsds_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len) { - grib_accessor_data_ccsds_packing* self = (grib_accessor_data_ccsds_packing*)a; + grib_accessor_data_ccsds_packing_t* self = (grib_accessor_data_ccsds_packing_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(a); const char* cclass_name = a->cclass->name; - int err = GRIB_SUCCESS; + int err = GRIB_SUCCESS; size_t buflen = 0, i = 0; bool is_constant_field = false; @@ -223,9 +106,9 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) long binary_scale_factor = 0; long decimal_scale_factor = 0; - //long optimize_scaling_factor = 0; - double reference_value = 0; - long bits_per_value = 0; + // long optimize_scaling_factor = 0; + double reference_value = 0; + long bits_per_value = 0; double max, min, d, divisor; long number_of_data_points; @@ -249,8 +132,8 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) if ((err = grib_get_long_internal(hand, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) return err; - //if ((err = grib_get_long_internal(gh, self->optimize_scaling_factor, &optimize_scaling_factor)) != GRIB_SUCCESS) - // return err; + // if ((err = grib_get_long_internal(gh, self->optimize_scaling_factor, &optimize_scaling_factor)) != GRIB_SUCCESS) + // return err; if ((err = grib_get_long_internal(hand, self->ccsds_flags, &ccsds_flags)) != GRIB_SUCCESS) return err; @@ -270,8 +153,10 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) max = val[0]; min = max; for (i = 1; i < n_vals; i++) { - if (val[i] > max) max = val[i]; - else if (val[i] < min) min = val[i]; + if (val[i] > max) + max = val[i]; + else if (val[i] < min) + min = val[i]; } if ((err = grib_check_data_values_minmax(hand, min, max)) != GRIB_SUCCESS) { @@ -280,10 +165,11 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) if (min == max) { is_constant_field = true; - } else { + } + else { if (bits_per_value == 0) { // ECC-1202: A non-constant field with bitsPerValue==0! - bits_per_value = 24; //Set sane value + bits_per_value = 24; // Set sane value } } @@ -303,7 +189,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) if ((err = grib_set_long_internal(hand, self->number_of_values, n_vals)) != GRIB_SUCCESS) return err; - bits_per_value = 0; // ECC-1387 + bits_per_value = 0; // ECC-1387 if ((err = grib_set_long_internal(hand, self->bits_per_value, bits_per_value)) != GRIB_SUCCESS) return err; @@ -322,25 +208,25 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) if (grib_get_nearest_smaller_value(hand, self->reference_value, min, &reference_value) != GRIB_SUCCESS) { grib_context_log(a->context, GRIB_LOG_ERROR, - "%s %s: Unable to find nearest_smaller_value of %g for %s", cclass_name, __func__, min, self->reference_value); + "%s %s: Unable to find nearest_smaller_value of %g for %s", cclass_name, __func__, min, self->reference_value); return GRIB_INTERNAL_ERROR; } if (reference_value > min) { grib_context_log(a->context, GRIB_LOG_ERROR, - "%s %s: reference_value=%g min_value=%g diff=%g", cclass_name, __func__, reference_value, min, reference_value - min); + "%s %s: reference_value=%g min_value=%g diff=%g", cclass_name, __func__, reference_value, min, reference_value - min); DEBUG_ASSERT(reference_value <= min); return GRIB_INTERNAL_ERROR; } } else { - int last = 127; // last must be a parameter coming from the def file - double range = 0; + int last = 127; // last must be a parameter coming from the def file + double range = 0; double minrange = 0, maxrange = 0; double unscaled_max = 0; double unscaled_min = 0; - double f = 0; - double decimal = 1; + double f = 0; + double decimal = 1; decimal_scale_factor = 0; range = (max - min); @@ -423,17 +309,17 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) } break; default: - grib_context_log(a->context, GRIB_LOG_ERROR,"%s pack_double: packing %s, bits_per_value=%ld (max 32)", - cclass_name, a->name, bits_per_value); + grib_context_log(a->context, GRIB_LOG_ERROR, "%s pack_double: packing %s, bits_per_value=%ld (max 32)", + cclass_name, a->name, bits_per_value); err = GRIB_INVALID_BPV; goto cleanup; } - grib_context_log(a->context, GRIB_LOG_DEBUG,"%s pack_double: packing %s, %zu values", cclass_name, a->name, n_vals); + grib_context_log(a->context, GRIB_LOG_DEBUG, "%s pack_double: packing %s, %zu values", cclass_name, a->name, n_vals); // ECC-1431: GRIB2: CCSDS encoding failure AEC_STREAM_ERROR buflen = (nbytes * n_vals) * 67 / 64 + 256; - buf = (unsigned char*)grib_context_buffer_malloc_clear(a->context, buflen); + buf = (unsigned char*)grib_context_buffer_malloc_clear(a->context, buflen); if (!buf) { err = GRIB_OUT_OF_MEMORY; @@ -448,7 +334,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) grib_get_double_internal(hand, self->reference_value, &ref); if (ref != reference_value) { grib_context_log(a->context, GRIB_LOG_ERROR, "%s %s: %s (ref=%.10e != reference_value=%.10e)", - cclass_name, __func__, self->reference_value, ref, reference_value); + cclass_name, __func__, self->reference_value, ref, reference_value); return GRIB_INTERNAL_ERROR; } } @@ -469,7 +355,6 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) strm.next_in = encoded; strm.avail_in = nbytes * n_vals; - // This does not support spherical harmonics, and treats 24 differently than: // see http://cdo.sourcearchive.com/documentation/1.5.1.dfsg.1-1/cgribexlib_8c_source.html @@ -477,7 +362,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) if ((err = aec_buffer_encode(&strm)) != AEC_OK) { grib_context_log(a->context, GRIB_LOG_ERROR, "%s %s: aec_buffer_encode error %d (%s)", - cclass_name, __func__, err, aec_get_error_message(err)); + cclass_name, __func__, err, aec_get_error_message(err)); err = GRIB_ENCODING_ERROR; goto cleanup; } @@ -502,21 +387,21 @@ template static int unpack(grib_accessor* a, T* val, size_t* len) { static_assert(std::is_floating_point::value, "Requires floating point numbers"); - grib_accessor_data_ccsds_packing* self = (grib_accessor_data_ccsds_packing*)a; - grib_handle* hand = grib_handle_of_accessor(a); + grib_accessor_data_ccsds_packing_t* self = (grib_accessor_data_ccsds_packing_t*)a; + grib_handle* hand = grib_handle_of_accessor(a); const char* cclass_name = a->cclass->name; int err = GRIB_SUCCESS, i = 0; size_t buflen = 0; struct aec_stream strm; - double bscale = 0; - double dscale = 0; - unsigned char* buf = NULL; - size_t n_vals = 0; - size_t size = 0; + double bscale = 0; + double dscale = 0; + unsigned char* buf = NULL; + size_t n_vals = 0; + size_t size = 0; unsigned char* decoded = NULL; // unsigned char* p = NULL; - long nn = 0; + long nn = 0; long binary_scale_factor = 0; long decimal_scale_factor = 0; @@ -530,7 +415,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) self->dirty = 0; - if ((err = grib_value_count(a, &nn)) != GRIB_SUCCESS) + if ((err = a->value_count(&nn)) != GRIB_SUCCESS) return err; n_vals = nn; @@ -569,10 +454,9 @@ static int unpack(grib_accessor* a, T* val, size_t* len) bscale = codes_power(binary_scale_factor, 2); dscale = codes_power(-decimal_scale_factor, 10); - buflen = grib_byte_count(a); - buf = (unsigned char*)hand->buffer->data; - buf += grib_byte_offset(a); - + buflen = a->byte_count(); + buf = (unsigned char*)hand->buffer->data; + buf += a->byte_offset(); strm.flags = ccsds_flags; strm.bits_per_sample = bits_per_value; strm.block_size = ccsds_block_size; @@ -598,13 +482,13 @@ static int unpack(grib_accessor* a, T* val, size_t* len) if ((err = aec_buffer_decode(&strm)) != AEC_OK) { grib_context_log(a->context, GRIB_LOG_ERROR, "%s %s: aec_buffer_decode error %d (%s)", - cclass_name, __func__, err, aec_get_error_message(err)); + cclass_name, __func__, err, aec_get_error_message(err)); err = GRIB_DECODING_ERROR; goto cleanup; } // ECC-1427: Performance improvement (replaced by ECC-1602) - //grib_decode_array(decoded, &pos, bits8 , reference_value, bscale, dscale, n_vals, val); + // grib_decode_array(decoded, &pos, bits8 , reference_value, bscale, dscale, n_vals, val); // ECC-1602: Performance improvement switch (nbytes) { @@ -625,7 +509,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) break; default: grib_context_log(a->context, GRIB_LOG_ERROR, "%s %s: unpacking %s, bits_per_value=%ld (max 32)", - cclass_name, __func__, a->name, bits_per_value); + cclass_name, __func__, a->name, bits_per_value); err = GRIB_INVALID_BPV; goto cleanup; } @@ -637,26 +521,27 @@ cleanup: return err; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_class_data_ccsds_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len) { return unpack(a, val, len); } -static int unpack_float(grib_accessor* a, float* val, size_t* len) +int grib_accessor_class_data_ccsds_packing_t::unpack_float(grib_accessor* a, float* val, size_t* len) { return unpack(a, val, len); } -static int unpack_double_element(grib_accessor* a, size_t idx, double* val) +int grib_accessor_class_data_ccsds_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) { // The index idx relates to codedValues NOT values! - const grib_accessor_data_ccsds_packing* self = (grib_accessor_data_ccsds_packing*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int err = 0; - size_t size = 0; - long bits_per_value = 0; + const grib_accessor_data_ccsds_packing_t* self = (grib_accessor_data_ccsds_packing_t*)a; + + grib_handle* hand = grib_handle_of_accessor(a); + int err = 0; + size_t size = 0; + long bits_per_value = 0; double reference_value = 0; - double* values = NULL; + double* values = NULL; if ((err = grib_get_long_internal(hand, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) return err; @@ -684,14 +569,14 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) return GRIB_SUCCESS; } -static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) +int grib_accessor_class_data_ccsds_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) { - const grib_accessor_data_ccsds_packing* self = (grib_accessor_data_ccsds_packing*)a; + const grib_accessor_data_ccsds_packing_t* self = (grib_accessor_data_ccsds_packing_t*)a; grib_handle* hand = grib_handle_of_accessor(a); size_t size = 0, i = 0; - double* values = NULL; - int err = 0; - long bits_per_value = 0; + double* values = NULL; + int err = 0; + long bits_per_value = 0; double reference_value = 0; if ((err = grib_get_long_internal(hand, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) @@ -738,27 +623,27 @@ static void print_error_feature_not_enabled(grib_context* c) "CCSDS support not enabled. " "Please rebuild with -DENABLE_AEC=ON (Adaptive Entropy Coding library)"); } -static int pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_class_data_ccsds_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len) { print_error_feature_not_enabled(a->context); return GRIB_FUNCTIONALITY_NOT_ENABLED; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_class_data_ccsds_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len) { print_error_feature_not_enabled(a->context); return GRIB_FUNCTIONALITY_NOT_ENABLED; } -static int unpack_float(grib_accessor* a, float* val, size_t* len) +int grib_accessor_class_data_ccsds_packing_t::unpack_float(grib_accessor* a, float* val, size_t* len) { print_error_feature_not_enabled(a->context); return GRIB_FUNCTIONALITY_NOT_ENABLED; } -static int unpack_double_element(grib_accessor* a, size_t idx, double* val) +int grib_accessor_class_data_ccsds_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) { print_error_feature_not_enabled(a->context); return GRIB_FUNCTIONALITY_NOT_ENABLED; } -static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) +int grib_accessor_class_data_ccsds_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) { print_error_feature_not_enabled(a->context); return GRIB_FUNCTIONALITY_NOT_ENABLED; diff --git a/src/accessor/grib_accessor_class_data_ccsds_packing.h b/src/accessor/grib_accessor_class_data_ccsds_packing.h new file mode 100644 index 000000000..0f9430232 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_ccsds_packing.h @@ -0,0 +1,45 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_values.h" +#include "grib_scaling.h" + +class grib_accessor_data_ccsds_packing_t : public grib_accessor_values_t +{ +public: + /* Members defined in data_ccsds_packing */ + const char* number_of_values; + const char* reference_value; + const char* binary_scale_factor; + const char* decimal_scale_factor; + const char* optimize_scaling_factor; + const char* bits_per_value; + const char* number_of_data_points; + const char* ccsds_flags; + const char* ccsds_block_size; + const char* ccsds_rsi; +}; + + +class grib_accessor_class_data_ccsds_packing_t : public grib_accessor_class_values_t +{ +public: + grib_accessor_class_data_ccsds_packing_t(const char* name) : grib_accessor_class_values_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_ccsds_packing_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_float(grib_accessor*, float* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_double_element(grib_accessor*, size_t i, double* val) override; + int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override; +}; diff --git a/src/grib_accessor_class_data_complex_packing.cc b/src/accessor/grib_accessor_class_data_complex_packing.cc similarity index 77% rename from src/grib_accessor_class_data_complex_packing.cc rename to src/accessor/grib_accessor_class_data_complex_packing.cc index 49d312611..81e402303 100644 --- a/src/grib_accessor_class_data_complex_packing.cc +++ b/src/accessor/grib_accessor_class_data_complex_packing.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,148 +9,16 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_ieeefloat.h" -#include "grib_scaling.h" -#include -#include -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_data_simple_packing - IMPLEMENTS = unpack_double - IMPLEMENTS = unpack_float - IMPLEMENTS = pack_double - IMPLEMENTS = value_count - IMPLEMENTS = init - MEMBERS= const char* GRIBEX_sh_bug_present - MEMBERS= const char* ieee_floats - MEMBERS= const char* laplacianOperatorIsSet - MEMBERS= const char* laplacianOperator - MEMBERS= const char* sub_j - MEMBERS= const char* sub_k - MEMBERS= const char* sub_m - MEMBERS= const char* pen_j - MEMBERS= const char* pen_k - MEMBERS= const char* pen_m - END_CLASS_DEF - - */ - - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_float(grib_accessor*, float* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_data_complex_packing -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in values */ - int carg; - const char* seclen; - const char* offsetdata; - const char* offsetsection; - int dirty; - /* Members defined in data_simple_packing */ - int edition; - const char* units_factor; - const char* units_bias; - const char* changing_precision; - const char* number_of_values; - const char* bits_per_value; - const char* reference_value; - const char* binary_scale_factor; - const char* decimal_scale_factor; - const char* optimize_scaling_factor; - /* Members defined in data_complex_packing */ - const char* GRIBEX_sh_bug_present; - const char* ieee_floats; - const char* laplacianOperatorIsSet; - const char* laplacianOperator; - const char* sub_j; - const char* sub_k; - const char* sub_m; - const char* pen_j; - const char* pen_k; - const char* pen_m; -} grib_accessor_data_complex_packing; - -extern grib_accessor_class* grib_accessor_class_data_simple_packing; - -static grib_accessor_class _grib_accessor_class_data_complex_packing = { - &grib_accessor_class_data_simple_packing, /* super */ - "data_complex_packing", /* name */ - sizeof(grib_accessor_data_complex_packing), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - &unpack_float, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_data_complex_packing.h" +grib_accessor_class_data_complex_packing_t _grib_accessor_class_data_complex_packing{ "data_complex_packing" }; grib_accessor_class* grib_accessor_class_data_complex_packing = &_grib_accessor_class_data_complex_packing; -/* END_CLASS_IMP */ - -typedef unsigned long (*encode_float_proc)(double); -typedef double (*decode_float_proc)(unsigned long); - -static void init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_class_data_complex_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) { - grib_accessor_data_complex_packing* self = (grib_accessor_data_complex_packing*)a; - grib_handle* gh = grib_handle_of_accessor(a); + grib_accessor_class_data_simple_packing_t::init(a, v, args); + grib_accessor_data_complex_packing_t* self = (grib_accessor_data_complex_packing_t*)a; + grib_handle* gh = grib_handle_of_accessor(a); self->GRIBEX_sh_bug_present = grib_arguments_get_name(gh, args, self->carg++); self->ieee_floats = grib_arguments_get_name(gh, args, self->carg++); @@ -165,15 +34,16 @@ static void init(grib_accessor* a, const long v, grib_arguments* args) a->flags |= GRIB_ACCESSOR_FLAG_DATA; } -static int value_count(grib_accessor* a, long* count) +int grib_accessor_class_data_complex_packing_t::value_count(grib_accessor* a, long* count) { - grib_accessor_data_complex_packing* self = (grib_accessor_data_complex_packing*)a; - int ret = 0; + grib_accessor_data_complex_packing_t* self = (grib_accessor_data_complex_packing_t*)a; + + int ret = GRIB_SUCCESS; grib_handle* gh = grib_handle_of_accessor(a); - long pen_j = 0; - long pen_k = 0; - long pen_m = 0; - *count = 0; + long pen_j = 0; + long pen_k = 0; + long pen_m = 0; + *count = 0; if (a->length == 0) return 0; @@ -195,7 +65,7 @@ static int value_count(grib_accessor* a, long* count) return ret; } -static double calculate_pfactor(const grib_context* ctx, const double* spectralField, long fieldTruncation, long subsetTruncation) +double calculate_pfactor(const grib_context* ctx, const double* spectralField, long fieldTruncation, long subsetTruncation) { /*long n_vals = ((fieldTruncation+1)*(fieldTruncation+2));*/ long loop, index, m, n = 0; @@ -229,7 +99,6 @@ static double calculate_pfactor(const grib_context* ctx, const double* spectralF /* * Form norms for the rows which contain part of the unscaled subset. */ - index = -2; for (m = 0; m < subsetTruncation; m++) { for (n = m; n <= fieldTruncation; n++) { @@ -244,7 +113,6 @@ static double calculate_pfactor(const grib_context* ctx, const double* spectralF /* * Form norms for the rows which do not contain part of the unscaled subset. */ - for (m = subsetTruncation; m <= fieldTruncation; m++) { for (n = m; n <= fieldTruncation; n++) { index += 2; @@ -280,7 +148,6 @@ static double calculate_pfactor(const grib_context* ctx, const double* spectralF /* * Perform a least square fit for the equation */ - for (loop = ismin; loop <= ismax; loop++) { x = log((double)(loop * (loop + 1))); y = log(norms[loop]); @@ -302,11 +169,11 @@ static double calculate_pfactor(const grib_context* ctx, const double* spectralF return pFactor; } -static int pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len) { - grib_accessor_data_complex_packing* self = (grib_accessor_data_complex_packing*)a; - grib_handle* gh = grib_handle_of_accessor(a); - const char* cclass_name = a->cclass->name; + grib_accessor_data_complex_packing_t* self = (grib_accessor_data_complex_packing_t*)a; + grib_handle* gh = grib_handle_of_accessor(a); + const char* cclass_name = a->cclass->name; size_t i = 0; int ret = GRIB_SUCCESS; @@ -654,7 +521,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) grib_get_double_internal(gh, self->reference_value, &ref); if (ref != reference_value) { grib_context_log(a->context, GRIB_LOG_ERROR, "%s %s: %s (ref=%.10e != reference_value=%.10e)", - cclass_name, __func__, self->reference_value, ref, reference_value); + cclass_name, __func__, self->reference_value, ref, reference_value); return GRIB_INTERNAL_ERROR; } } @@ -671,32 +538,31 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) return ret; } - template -static int unpack(grib_accessor* a, T* val, size_t* len) +static int unpack_real(grib_accessor* a, T* val, size_t* len) { static_assert(std::is_floating_point::value, "Requires floating point numbers"); - grib_accessor_data_complex_packing* self = (grib_accessor_data_complex_packing*)a; - grib_handle* gh = grib_handle_of_accessor(a); - const char* cclass_name = a->cclass->name; + grib_accessor_data_complex_packing_t* self = (grib_accessor_data_complex_packing_t*)a; + grib_handle* gh = grib_handle_of_accessor(a); + const char* cclass_name = a->cclass->name; - size_t i = 0; - int ret = GRIB_SUCCESS; - long hcount = 0; - long lcount = 0; - long hpos = 0; - long lup = 0; - long mmax = 0; - long n_vals = 0; - T* scals = NULL; - T* pscals = NULL, *pval = NULL; + size_t i = 0; + int ret = GRIB_SUCCESS; + long hcount = 0; + long lcount = 0; + long hpos = 0; + long lup = 0; + long mmax = 0; + long n_vals = 0; + T* scals = NULL; + T *pscals = NULL, *pval = NULL; T s = 0; T d = 0; T laplacianOperator = 0; - unsigned char* buf = NULL; - unsigned char* hres = NULL; - unsigned char* lres = NULL; + unsigned char* buf = NULL; + unsigned char* hres = NULL; + unsigned char* lres = NULL; unsigned long packed_offset; long lpos = 0; @@ -706,7 +572,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) long offsetdata = 0; long bits_per_value = 0; - T reference_value = 0; + T reference_value = 0; long binary_scale_factor = 0; long decimal_scale_factor = 0; @@ -724,7 +590,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) decode_float_proc decode_float = NULL; - err = grib_value_count(a, &n_vals); + err = a->value_count(&n_vals); if (err) return err; @@ -798,7 +664,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) maxv = pen_j + 1; - buf += grib_byte_offset(a); + buf += a->byte_offset(); hres = buf; lres = buf; @@ -814,9 +680,8 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return 0; } - packed_offset = grib_byte_offset(a) + bytes * (sub_k + 1) * (sub_k + 2); - - lpos = 8 * (packed_offset - offsetdata); + packed_offset = a->byte_offset() + bytes * (sub_k + 1) * (sub_k + 2); + lpos = 8 * (packed_offset - offsetdata); s = codes_power(binary_scale_factor, 2); d = codes_power(-decimal_scale_factor, 10); @@ -831,7 +696,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) scals[i] = (1.0 / operat); else { grib_context_log(a->context, GRIB_LOG_WARNING, - "%s: Problem with operator div by zero at index %d of %d", cclass_name, i, maxv); + "%s: Problem with operator div by zero at index %d of %d", cclass_name, i, maxv); scals[i] = 0; } } @@ -895,34 +760,31 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return ret; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_class_data_complex_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len) { - return unpack(a, val, len); + return unpack_real(a, val, len); } -static int unpack_float(grib_accessor* a, float* val, size_t* len) +int grib_accessor_class_data_complex_packing_t::unpack_float(grib_accessor* a, float* val, size_t* len) { // TODO(maee): See ECC-1579 // Investigate why results are not bit-identical // return unpack(a, val, len); - int err = 0; - size_t i = 0; - size_t size = *len; - double* val8 = NULL; - val8 = (double*)grib_context_malloc(a->context, size*(sizeof(double))); + size_t size = *len; + double* val8 = (double*)grib_context_malloc(a->context, size * (sizeof(double))); if (!val8) return GRIB_OUT_OF_MEMORY; - err = unpack(a, val8, len); + int err = unpack_real(a, val8, len); if (err) { - grib_context_free(a->context,val8); + grib_context_free(a->context, val8); return err; } - for(i=0; icontext,val8); + grib_context_free(a->context, val8); return GRIB_SUCCESS; } diff --git a/src/accessor/grib_accessor_class_data_complex_packing.h b/src/accessor/grib_accessor_class_data_complex_packing.h new file mode 100644 index 000000000..ee19b195c --- /dev/null +++ b/src/accessor/grib_accessor_class_data_complex_packing.h @@ -0,0 +1,46 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_data_simple_packing.h" +#include "grib_scaling.h" +#include "grib_ieeefloat.h" + +typedef unsigned long (*encode_float_proc)(double); +typedef double (*decode_float_proc)(unsigned long); + +class grib_accessor_data_complex_packing_t : public grib_accessor_data_simple_packing_t +{ +public: + /* Members defined in data_complex_packing */ + const char* GRIBEX_sh_bug_present; + const char* ieee_floats; + const char* laplacianOperatorIsSet; + const char* laplacianOperator; + const char* sub_j; + const char* sub_k; + const char* sub_m; + const char* pen_j; + const char* pen_k; + const char* pen_m; +}; + +class grib_accessor_class_data_complex_packing_t : public grib_accessor_class_data_simple_packing_t +{ +public: + grib_accessor_class_data_complex_packing_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_complex_packing_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_float(grib_accessor*, float* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_data_dummy_field.cc b/src/accessor/grib_accessor_class_data_dummy_field.cc new file mode 100644 index 000000000..eddadcc08 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_dummy_field.cc @@ -0,0 +1,102 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_data_dummy_field.h" + +grib_accessor_class_data_dummy_field_t _grib_accessor_class_data_dummy_field{"data_dummy_field"}; +grib_accessor_class* grib_accessor_class_data_dummy_field = &_grib_accessor_class_data_dummy_field; + + +void grib_accessor_class_data_dummy_field_t::init(grib_accessor* a, const long v, grib_arguments* args){ + grib_accessor_class_data_g1simple_packing_t::init(a, v, args); + grib_accessor_data_dummy_field_t* self = (grib_accessor_data_dummy_field_t*)a; + self->missing_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); + self->numberOfPoints = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); + self->bitmap = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); +} + +int grib_accessor_class_data_dummy_field_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + grib_accessor_data_dummy_field_t* self = (grib_accessor_data_dummy_field_t*)a; + size_t i = 0, n_vals = 0; + long numberOfPoints; + double missing_value = 0; + int err = 0; + + if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints, &numberOfPoints)) != GRIB_SUCCESS) + return err; + n_vals = numberOfPoints; + + if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value, &missing_value)) != GRIB_SUCCESS) + return err; + + if (*len < n_vals) { + *len = n_vals; + return GRIB_ARRAY_TOO_SMALL; + } + + for (i = 0; i < n_vals; i++) + val[i] = missing_value; + + if (grib_find_accessor(grib_handle_of_accessor(a), self->bitmap)) { + if ((err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->bitmap, val, n_vals)) != GRIB_SUCCESS) + return err; + } + + *len = (long)n_vals; + return err; +} + +int grib_accessor_class_data_dummy_field_t::pack_double(grib_accessor* a, const double* val, size_t* len){ + grib_accessor_data_dummy_field_t* self = (grib_accessor_data_dummy_field_t*)a; + + size_t n_vals = *len; + int err = 0; + long bits_per_value = 0; + long half_byte = 0; + size_t buflen = 0; + unsigned char* buf = NULL; + + if (*len == 0) + return GRIB_NO_VALUES; + + if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + return err; + + buflen = (1 + ((bits_per_value * n_vals) / 8)) * sizeof(unsigned char); + + buf = (unsigned char*)grib_context_malloc_clear(a->context, buflen); + if (!buf) + return GRIB_OUT_OF_MEMORY; + + half_byte = (buflen * 8) - ((*len) * bits_per_value); + + if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->half_byte, half_byte)) != GRIB_SUCCESS) { + grib_context_free(a->context, buf); + return err; + } + grib_buffer_replace(a, buf, buflen, 1, 1); + + grib_context_free(a->context, buf); + + return GRIB_SUCCESS; +} + +int grib_accessor_class_data_dummy_field_t::value_count(grib_accessor* a, long* numberOfPoints){ + grib_accessor_data_dummy_field_t* self = (grib_accessor_data_dummy_field_t*)a; + int err = 0; + *numberOfPoints = 0; + + if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints, numberOfPoints)) != GRIB_SUCCESS) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to get count of %s (%s)", a->name, grib_get_error_message(err)); + } + + return err; +} diff --git a/src/accessor/grib_accessor_class_data_dummy_field.h b/src/accessor/grib_accessor_class_data_dummy_field.h new file mode 100644 index 000000000..c846abb98 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_dummy_field.h @@ -0,0 +1,33 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_data_g1simple_packing.h" + +class grib_accessor_data_dummy_field_t : public grib_accessor_data_g1simple_packing_t +{ +public: + /* Members defined in data_dummy_field */ + const char* missing_value; + const char* numberOfPoints; + const char* bitmap; +}; + +class grib_accessor_class_data_dummy_field_t : public grib_accessor_class_data_g1simple_packing_t +{ +public: + grib_accessor_class_data_dummy_field_t(const char* name) : grib_accessor_class_data_g1simple_packing_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_dummy_field_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_data_g1complex_packing.cc b/src/accessor/grib_accessor_class_data_g1complex_packing.cc new file mode 100644 index 000000000..5ac11346e --- /dev/null +++ b/src/accessor/grib_accessor_class_data_g1complex_packing.cc @@ -0,0 +1,112 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_data_g1complex_packing.h" + +grib_accessor_class_data_g1complex_packing_t _grib_accessor_class_data_g1complex_packing{"data_g1complex_packing"}; +grib_accessor_class* grib_accessor_class_data_g1complex_packing = &_grib_accessor_class_data_g1complex_packing; + + +void grib_accessor_class_data_g1complex_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){ + grib_accessor_class_data_complex_packing_t::init(a, v, args); + grib_accessor_data_g1complex_packing_t* self = (grib_accessor_data_g1complex_packing_t*)a; + self->half_byte = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); + self->N = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); + self->packingType = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); + self->ieee_packing = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); + self->precision = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); + self->edition = 1; + a->flags |= GRIB_ACCESSOR_FLAG_DATA; +} + +int grib_accessor_class_data_g1complex_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){ + grib_accessor_data_g1complex_packing_t* self = (grib_accessor_data_g1complex_packing_t*)a; + int ret = GRIB_SUCCESS; + long seclen = 0; + long sub_j = 0; + long sub_k = 0; + long sub_m = 0; + long n = 0; + long half_byte = 0; + long bits_per_value = 0; + size_t buflen = 0; + + if (*len == 0) + return GRIB_NO_VALUES; + +// /* TODO: spectral_ieee does not work */ +// if (c->ieee_packing && self->ieee_packing) { +// grib_handle* h = grib_handle_of_accessor(a); +// grib_context* c = a->context; +// char* packingType_s = NULL; +// char* ieee_packing_s = NULL; +// long precision = c->ieee_packing == 32 ? 1 : 2; +// size_t lenstr = strlen(self->ieee_packing); + +// packingType_s = grib_context_strdup(c, self->packingType); +// ieee_packing_s = grib_context_strdup(c, self->ieee_packing); +// precision_s = grib_context_strdup(c, self->precision); + +// grib_set_string(h, packingType_s, ieee_packing_s, &lenstr); +// grib_set_long(h, precision_s, precision); + +// grib_context_free(c, packingType_s); +// grib_context_free(c, ieee_packing_s); +// grib_context_free(c, precision_s); +// return grib_set_double_array(h, "values", val, *len); +// } + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->sub_j, &sub_j)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->sub_k, &sub_k)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->sub_m, &sub_m)) != GRIB_SUCCESS) + return ret; + + self->dirty = 1; + + Assert((sub_j == sub_k) && (sub_m == sub_j)); + + ret = grib_accessor_class_data_complex_packing_t::pack_double(a, val, len); + + if (ret == GRIB_SUCCESS) { + n = a->offset + 4 * ((sub_k + 1) * (sub_k + 2)); + + /* Octet number starts from beginning of message but shouldn't */ + if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->N, n)) != GRIB_SUCCESS) + return ret; + + // ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetsection, &offsetsection); + // if (ret != GRIB_SUCCESS) + // return ret; + // if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->N, n - offsetsection)) != GRIB_SUCCESS) + // return ret; + + ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bits_per_value, &bits_per_value); + if (ret != GRIB_SUCCESS) + return ret; + + ret = grib_get_long_internal(grib_handle_of_accessor(a), self->seclen, &seclen); + if (ret != GRIB_SUCCESS) + return ret; + + buflen = 32 * (sub_k + 1) * (sub_k + 2) + (*len - (sub_k + 1) * (sub_k + 2)) * bits_per_value + 18 * 8; + half_byte = seclen * 8 - buflen; + if (a->context->debug == -1) { + fprintf(stderr, "ECCODES DEBUG: half_byte=%ld\n", half_byte); + } + + ret = grib_set_long_internal(grib_handle_of_accessor(a), self->half_byte, half_byte); + if (ret != GRIB_SUCCESS) + return ret; + } + return ret; +} diff --git a/src/accessor/grib_accessor_class_data_g1complex_packing.h b/src/accessor/grib_accessor_class_data_g1complex_packing.h new file mode 100644 index 000000000..51457e40e --- /dev/null +++ b/src/accessor/grib_accessor_class_data_g1complex_packing.h @@ -0,0 +1,33 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_data_complex_packing.h" + +class grib_accessor_data_g1complex_packing_t : public grib_accessor_data_complex_packing_t +{ +public: + /* Members defined in data_g1complex_packing */ + const char* N; + const char* half_byte; + const char* packingType; + const char* ieee_packing; + const char* precision; +}; + +class grib_accessor_class_data_g1complex_packing_t : public grib_accessor_class_data_complex_packing_t +{ +public: + grib_accessor_class_data_g1complex_packing_t(const char* name) : grib_accessor_class_data_complex_packing_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g1complex_packing_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_data_g1second_order_constant_width_packing.cc b/src/accessor/grib_accessor_class_data_g1second_order_constant_width_packing.cc similarity index 57% rename from src/grib_accessor_class_data_g1second_order_constant_width_packing.cc rename to src/accessor/grib_accessor_class_data_g1second_order_constant_width_packing.cc index 079e91829..579fbd8cb 100644 --- a/src/grib_accessor_class_data_g1second_order_constant_width_packing.cc +++ b/src/accessor/grib_accessor_class_data_g1second_order_constant_width_packing.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,157 +9,16 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_accessor_class_data_g1second_order_constant_width_packing.h" #include "grib_scaling.h" -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_data_simple_packing - IMPLEMENTS = init - IMPLEMENTS = pack_double - IMPLEMENTS = unpack_double;unpack_float - IMPLEMENTS = unpack_double_element;unpack_double_element_set - IMPLEMENTS = value_count - MEMBERS=const char* half_byte - MEMBERS=const char* packingType - MEMBERS=const char* ieee_packing - MEMBERS=const char* precision - MEMBERS=const char* widthOfFirstOrderValues - MEMBERS=const char* N1 - MEMBERS=const char* N2 - MEMBERS=const char* numberOfGroups - MEMBERS=const char* numberOfSecondOrderPackedValues - MEMBERS=const char* extraValues - MEMBERS=const char* pl - MEMBERS=const char* Ni - MEMBERS=const char* Nj - MEMBERS=const char* jPointsAreConsecutive - MEMBERS=const char* bitmap - MEMBERS=const char* groupWidth - - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_float(grib_accessor*, float* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); -static int unpack_double_element(grib_accessor*, size_t i, double* val); -static int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array); - -typedef struct grib_accessor_data_g1second_order_constant_width_packing -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in values */ - int carg; - const char* seclen; - const char* offsetdata; - const char* offsetsection; - int dirty; - /* Members defined in data_simple_packing */ - int edition; - const char* units_factor; - const char* units_bias; - const char* changing_precision; - const char* number_of_values; - const char* bits_per_value; - const char* reference_value; - const char* binary_scale_factor; - const char* decimal_scale_factor; - const char* optimize_scaling_factor; - /* Members defined in data_g1second_order_constant_width_packing */ - const char* half_byte; - const char* packingType; - const char* ieee_packing; - const char* precision; - const char* widthOfFirstOrderValues; - const char* N1; - const char* N2; - const char* numberOfGroups; - const char* numberOfSecondOrderPackedValues; - const char* extraValues; - const char* pl; - const char* Ni; - const char* Nj; - const char* jPointsAreConsecutive; - const char* bitmap; - const char* groupWidth; -} grib_accessor_data_g1second_order_constant_width_packing; - -extern grib_accessor_class* grib_accessor_class_data_simple_packing; - -static grib_accessor_class _grib_accessor_class_data_g1second_order_constant_width_packing = { - &grib_accessor_class_data_simple_packing, /* super */ - "data_g1second_order_constant_width_packing", /* name */ - sizeof(grib_accessor_data_g1second_order_constant_width_packing), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - &unpack_float, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - &unpack_double_element, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - &unpack_double_element_set, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +grib_accessor_class_data_g1second_order_constant_width_packing_t _grib_accessor_class_data_g1second_order_constant_width_packing{"data_g1second_order_constant_width_packing"}; grib_accessor_class* grib_accessor_class_data_g1second_order_constant_width_packing = &_grib_accessor_class_data_g1second_order_constant_width_packing; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long v, grib_arguments* args) -{ - grib_accessor_data_g1second_order_constant_width_packing* self = (grib_accessor_data_g1second_order_constant_width_packing*)a; +void grib_accessor_class_data_g1second_order_constant_width_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){ + grib_accessor_class_data_simple_packing_t::init(a, v, args); + grib_accessor_data_g1second_order_constant_width_packing_t* self = (grib_accessor_data_g1second_order_constant_width_packing_t*)a; grib_handle* hand = grib_handle_of_accessor(a); self->half_byte = grib_arguments_get_name(hand, args, self->carg++); @@ -181,10 +41,9 @@ static void init(grib_accessor* a, const long v, grib_arguments* args) a->flags |= GRIB_ACCESSOR_FLAG_DATA; } -static int value_count(grib_accessor* a, long* numberOfSecondOrderPackedValues) -{ +int grib_accessor_class_data_g1second_order_constant_width_packing_t::value_count(grib_accessor* a, long* numberOfSecondOrderPackedValues){ int err = 0; - grib_accessor_data_g1second_order_constant_width_packing* self = (grib_accessor_data_g1second_order_constant_width_packing*)a; + grib_accessor_data_g1second_order_constant_width_packing_t* self = (grib_accessor_data_g1second_order_constant_width_packing_t*)a; *numberOfSecondOrderPackedValues = 0; err = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfSecondOrderPackedValues, numberOfSecondOrderPackedValues); @@ -192,14 +51,12 @@ static int value_count(grib_accessor* a, long* numberOfSecondOrderPackedValues) return err; } -static int unpack_float(grib_accessor*, float* val, size_t* len) -{ +int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_float(grib_accessor*, float* val, size_t* len){ return GRIB_NOT_IMPLEMENTED; } -static int unpack_double(grib_accessor* a, double* values, size_t* len) -{ - grib_accessor_data_g1second_order_constant_width_packing* self = (grib_accessor_data_g1second_order_constant_width_packing*)a; +int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_double(grib_accessor* a, double* values, size_t* len){ + grib_accessor_data_g1second_order_constant_width_packing_t* self = (grib_accessor_data_g1second_order_constant_width_packing_t*)a; int ret = 0; long numberOfGroups, numberOfSecondOrderPackedValues; long groupWidth = 0; @@ -218,8 +75,7 @@ static int unpack_double(grib_accessor* a, double* values, size_t* len) long* secondaryBitmap; grib_handle* hand = grib_handle_of_accessor(a); - buf += grib_byte_offset(a); - + buf += a->byte_offset(); if ((ret = grib_get_long_internal(hand, self->numberOfGroups, &numberOfGroups)) != GRIB_SUCCESS) return ret; @@ -321,15 +177,13 @@ static int unpack_double(grib_accessor* a, double* values, size_t* len) return ret; } -static int pack_double(grib_accessor* a, const double* cval, size_t* len) -{ +int grib_accessor_class_data_g1second_order_constant_width_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len){ const char* cclass_name = a->cclass->name; grib_context_log(a->context, GRIB_LOG_ERROR, "%s: %s: Not implemented", cclass_name, __func__); return GRIB_NOT_IMPLEMENTED; } -static int unpack_double_element(grib_accessor* a, size_t idx, double* val) -{ +int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val){ grib_handle* hand = grib_handle_of_accessor(a); size_t size = 0; double* values = NULL; @@ -354,8 +208,7 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) return GRIB_SUCCESS; } -static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) -{ +int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array){ grib_handle* hand = grib_handle_of_accessor(a); size_t size = 0, i = 0; double* values = NULL; diff --git a/src/accessor/grib_accessor_class_data_g1second_order_constant_width_packing.h b/src/accessor/grib_accessor_class_data_g1second_order_constant_width_packing.h new file mode 100644 index 000000000..8d2d53f0a --- /dev/null +++ b/src/accessor/grib_accessor_class_data_g1second_order_constant_width_packing.h @@ -0,0 +1,49 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_data_simple_packing.h" + +class grib_accessor_data_g1second_order_constant_width_packing_t : public grib_accessor_data_simple_packing_t +{ +public: + /* Members defined in data_g1second_order_constant_width_packing */ + const char* half_byte; + const char* packingType; + const char* ieee_packing; + const char* precision; + const char* widthOfFirstOrderValues; + const char* N1; + const char* N2; + const char* numberOfGroups; + const char* numberOfSecondOrderPackedValues; + const char* extraValues; + const char* pl; + const char* Ni; + const char* Nj; + const char* jPointsAreConsecutive; + const char* bitmap; + const char* groupWidth; +}; + +class grib_accessor_class_data_g1second_order_constant_width_packing_t : public grib_accessor_class_data_simple_packing_t +{ +public: + grib_accessor_class_data_g1second_order_constant_width_packing_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g1second_order_constant_width_packing_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_float(grib_accessor*, float* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_double_element(grib_accessor*, size_t i, double* val) override; + int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override; +}; diff --git a/src/grib_accessor_class_data_g1second_order_general_extended_packing.cc b/src/accessor/grib_accessor_class_data_g1second_order_general_extended_packing.cc similarity index 84% rename from src/grib_accessor_class_data_g1second_order_general_extended_packing.cc rename to src/accessor/grib_accessor_class_data_g1second_order_general_extended_packing.cc index d337dba48..f78bb1806 100644 --- a/src/grib_accessor_class_data_g1second_order_general_extended_packing.cc +++ b/src/accessor/grib_accessor_class_data_g1second_order_general_extended_packing.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,181 +9,15 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_accessor_class_data_g1second_order_general_extended_packing.h" #include "grib_scaling.h" -#include "grib_api_internal.h" -#include "grib_optimize_decimal_factor.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_data_simple_packing - IMPLEMENTS = init - IMPLEMENTS = pack_double - IMPLEMENTS = unpack_double;unpack_float - IMPLEMENTS = unpack_double_element;unpack_double_element_set - IMPLEMENTS = value_count - IMPLEMENTS = destroy - MEMBERS=const char* half_byte - MEMBERS=const char* packingType - MEMBERS=const char* ieee_packing - MEMBERS=const char* precision - MEMBERS=const char* widthOfFirstOrderValues - MEMBERS=const char* firstOrderValues - MEMBERS=const char* N1 - MEMBERS=const char* N2 - MEMBERS=const char* numberOfGroups - MEMBERS=const char* codedNumberOfGroups - MEMBERS=const char* numberOfSecondOrderPackedValues - MEMBERS=const char* extraValues - MEMBERS=const char* groupWidths - MEMBERS=const char* widthOfWidths - MEMBERS=const char* groupLengths - MEMBERS=const char* widthOfLengths - MEMBERS=const char* NL - MEMBERS=const char* SPD - MEMBERS=const char* widthOfSPD - MEMBERS=const char* orderOfSPD - MEMBERS=const char* numberOfPoints - MEMBERS=const char* dataFlag - MEMBERS=double* dvalues - MEMBERS=float* fvalues - MEMBERS=int double_dirty - MEMBERS=int float_dirty - MEMBERS=size_t size - - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_float(grib_accessor*, float* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void destroy(grib_context*, grib_accessor*); -static void init(grib_accessor*, const long, grib_arguments*); -static int unpack_double_element(grib_accessor*, size_t i, double* val); -static int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array); - -typedef struct grib_accessor_data_g1second_order_general_extended_packing -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in values */ - int carg; - const char* seclen; - const char* offsetdata; - const char* offsetsection; - int dirty; - /* Members defined in data_simple_packing */ - int edition; - const char* units_factor; - const char* units_bias; - const char* changing_precision; - const char* number_of_values; - const char* bits_per_value; - const char* reference_value; - const char* binary_scale_factor; - const char* decimal_scale_factor; - const char* optimize_scaling_factor; - /* Members defined in data_g1second_order_general_extended_packing */ - const char* half_byte; - const char* packingType; - const char* ieee_packing; - const char* precision; - const char* widthOfFirstOrderValues; - const char* firstOrderValues; - const char* N1; - const char* N2; - const char* numberOfGroups; - const char* codedNumberOfGroups; - const char* numberOfSecondOrderPackedValues; - const char* extraValues; - const char* groupWidths; - const char* widthOfWidths; - const char* groupLengths; - const char* widthOfLengths; - const char* NL; - const char* SPD; - const char* widthOfSPD; - const char* orderOfSPD; - const char* numberOfPoints; - const char* dataFlag; - double* dvalues; - float* fvalues; - int double_dirty; - int float_dirty; - size_t size; -} grib_accessor_data_g1second_order_general_extended_packing; - -extern grib_accessor_class* grib_accessor_class_data_simple_packing; - -static grib_accessor_class _grib_accessor_class_data_g1second_order_general_extended_packing = { - &grib_accessor_class_data_simple_packing, /* super */ - "data_g1second_order_general_extended_packing", /* name */ - sizeof(grib_accessor_data_g1second_order_general_extended_packing), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - &destroy, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - &unpack_float, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - &unpack_double_element, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - &unpack_double_element_set, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +grib_accessor_class_data_g1second_order_general_extended_packing_t _grib_accessor_class_data_g1second_order_general_extended_packing{ "data_g1second_order_general_extended_packing" }; grib_accessor_class* grib_accessor_class_data_g1second_order_general_extended_packing = &_grib_accessor_class_data_g1second_order_general_extended_packing; -/* END_CLASS_IMP */ #define MAX_NUMBER_OF_GROUPS 65534 -#define EFDEBUG 0 +#define EFDEBUG 0 static const unsigned long nbits[64] = { 0x1, 0x2, 0x4, 0x8, @@ -203,7 +38,7 @@ static const unsigned long nbits[64] = { 0x1000000000000000, 0x2000000000000000, 0x4000000000000000, 0x8000000000000000 }; -static long number_of_bits(grib_handle* h, unsigned long x) +long number_of_bits(grib_handle* h, unsigned long x) { const unsigned long* n = nbits; const int count = sizeof(nbits) / sizeof(nbits[0]); @@ -220,10 +55,11 @@ static long number_of_bits(grib_handle* h, unsigned long x) return i; } -static void init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_class_data_g1second_order_general_extended_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) { - grib_accessor_data_g1second_order_general_extended_packing* self = (grib_accessor_data_g1second_order_general_extended_packing*)a; - grib_handle* handle = grib_handle_of_accessor(a); + grib_accessor_class_data_simple_packing_t::init(a, v, args); + grib_accessor_data_g1second_order_general_extended_packing_t* self = (grib_accessor_data_g1second_order_general_extended_packing_t*)a; + grib_handle* handle = grib_handle_of_accessor(a); self->half_byte = grib_arguments_get_name(handle, args, self->carg++); self->packingType = grib_arguments_get_name(handle, args, self->carg++); @@ -249,18 +85,18 @@ static void init(grib_accessor* a, const long v, grib_arguments* args) self->dataFlag = grib_arguments_get_name(handle, args, self->carg++); self->edition = 1; self->dirty = 1; - self->dvalues = NULL; - self->fvalues = NULL; + self->dvalues = NULL; + self->fvalues = NULL; self->double_dirty = self->float_dirty = 1; - self->size = 0; + self->size = 0; a->flags |= GRIB_ACCESSOR_FLAG_DATA; } -static int value_count(grib_accessor* a, long* count) +int grib_accessor_class_data_g1second_order_general_extended_packing_t::value_count(grib_accessor* a, long* count) { - grib_accessor_data_g1second_order_general_extended_packing* self = (grib_accessor_data_g1second_order_general_extended_packing*)a; - long numberOfCodedValues = 0; - long numberOfGroups = 0; + grib_accessor_data_g1second_order_general_extended_packing_t* self = (grib_accessor_data_g1second_order_general_extended_packing_t*)a; + long numberOfCodedValues = 0; + long numberOfGroups = 0; size_t ngroups; long* groupLengths; long orderOfSPD = 0; @@ -293,7 +129,7 @@ static int value_count(grib_accessor* a, long* count) return err; } -static int unpack_double_element(grib_accessor* a, size_t idx, double* val) +int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) { size_t size; double* values; @@ -317,7 +153,7 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) return GRIB_SUCCESS; } -static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) +int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) { size_t size = 0, i = 0; double* values; @@ -345,10 +181,10 @@ static int unpack_double_element_set(grib_accessor* a, const size_t* index_array return GRIB_SUCCESS; } -static int unpack(grib_accessor* a, double* dvalues, float* fvalues, size_t* len) +int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack(grib_accessor* a, double* dvalues, float* fvalues, size_t* len) { - grib_accessor_data_g1second_order_general_extended_packing* self = (grib_accessor_data_g1second_order_general_extended_packing*)a; - int ret = 0; + grib_accessor_data_g1second_order_general_extended_packing_t* self = (grib_accessor_data_g1second_order_general_extended_packing_t*)a; + int ret = 0; long numberOfGroups, numberOfSecondOrderPackedValues; long* firstOrderValues = 0; long* X = 0; @@ -396,8 +232,9 @@ static int unpack(grib_accessor* a, double* dvalues, float* fvalues, size_t* len self->float_dirty = 0; } - buf += grib_byte_offset(a); - ret = value_count(a, &numberOfValues); + buf += a->byte_offset(); + ret = a->value_count(&numberOfValues); + if (ret) return ret; @@ -461,14 +298,13 @@ static int unpack(grib_accessor* a, double* dvalues, float* fvalues, size_t* len n++; } -// for (j=0;jdvalues) { if (numberOfValues != self->size) { grib_context_free(a->context, self->dvalues); @@ -565,12 +401,12 @@ static int unpack(grib_accessor* a, double* dvalues, float* fvalues, size_t* len return ret; } -static int unpack_float(grib_accessor* a, float* values, size_t* len) +int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_float(grib_accessor* a, float* values, size_t* len) { return unpack(a, NULL, values, len); } -static int unpack_double(grib_accessor* a, double* values, size_t* len) +int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_double(grib_accessor* a, double* values, size_t* len) { return unpack(a, values, NULL, len); } @@ -698,7 +534,8 @@ static int get_bits_per_value(grib_handle* h, const char* bits_per_value_str, lo /* Note: on a 32bit system, the most significant bit is for signedness, so we have to drop one bit */ if (sizeof(long) == 4) { *bits_per_value = 31; - } else { + } + else { *bits_per_value = 32; } } @@ -708,11 +545,11 @@ static int get_bits_per_value(grib_handle* h, const char* bits_per_value_str, lo // For the old implementation of pack_double, see // src/deprecated/grib_accessor_class_data_g1second_order_general_extended_packing.pack_double.cc // See ECC-441 and ECC-261 -static int pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len) { - grib_accessor_data_g1second_order_general_extended_packing* self = (grib_accessor_data_g1second_order_general_extended_packing*)a; - int ret = 0; - int grib2 = 0; + grib_accessor_data_g1second_order_general_extended_packing_t* self = (grib_accessor_data_g1second_order_general_extended_packing_t*)a; + int ret = 0; + int grib2 = 0; long bits_per_value, orderOfSPD, binary_scale_factor; long numberOfValues; double max, min; @@ -1303,7 +1140,9 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) pos = 0; if (orderOfSPD) { - long SPD[4] = {0,}; + long SPD[4] = { + 0, + }; size_t nSPD = orderOfSPD + 1; Assert(orderOfSPD <= 3); for (i = 0; i < orderOfSPD; i++) @@ -1365,9 +1204,9 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) return GRIB_SUCCESS; } -static void destroy(grib_context* context, grib_accessor* a) +void grib_accessor_class_data_g1second_order_general_extended_packing_t::destroy(grib_context* context, grib_accessor* a) { - grib_accessor_data_g1second_order_general_extended_packing* self = (grib_accessor_data_g1second_order_general_extended_packing*)a; + grib_accessor_data_g1second_order_general_extended_packing_t* self = (grib_accessor_data_g1second_order_general_extended_packing_t*)a; if (self->dvalues != NULL) { grib_context_free(context, self->dvalues); self->dvalues = NULL; @@ -1376,4 +1215,5 @@ static void destroy(grib_context* context, grib_accessor* a) grib_context_free(context, self->fvalues); self->fvalues = NULL; } + grib_accessor_class_data_simple_packing_t::destroy(context, a); } diff --git a/src/accessor/grib_accessor_class_data_g1second_order_general_extended_packing.h b/src/accessor/grib_accessor_class_data_g1second_order_general_extended_packing.h new file mode 100644 index 000000000..4bb50ae34 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_g1second_order_general_extended_packing.h @@ -0,0 +1,64 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_data_simple_packing.h" + +class grib_accessor_data_g1second_order_general_extended_packing_t : public grib_accessor_data_simple_packing_t +{ +public: + /* Members defined in data_g1second_order_general_extended_packing */ + const char* half_byte; + const char* packingType; + const char* ieee_packing; + const char* precision; + const char* widthOfFirstOrderValues; + const char* firstOrderValues; + const char* N1; + const char* N2; + const char* numberOfGroups; + const char* codedNumberOfGroups; + const char* numberOfSecondOrderPackedValues; + const char* extraValues; + const char* groupWidths; + const char* widthOfWidths; + const char* groupLengths; + const char* widthOfLengths; + const char* NL; + const char* SPD; + const char* widthOfSPD; + const char* orderOfSPD; + const char* numberOfPoints; + const char* dataFlag; + double* dvalues; + float* fvalues; + int double_dirty; + int float_dirty; + size_t size; +}; + +class grib_accessor_class_data_g1second_order_general_extended_packing_t : public grib_accessor_class_data_simple_packing_t +{ +public: + grib_accessor_class_data_g1second_order_general_extended_packing_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g1second_order_general_extended_packing_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_float(grib_accessor*, float* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void destroy(grib_context*, grib_accessor*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_double_element(grib_accessor*, size_t i, double* val) override; + int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override; + +private: + int unpack(grib_accessor* a, double*, float*, size_t*); +}; diff --git a/src/grib_accessor_class_data_g1second_order_general_packing.cc b/src/accessor/grib_accessor_class_data_g1second_order_general_packing.cc similarity index 50% rename from src/grib_accessor_class_data_g1second_order_general_packing.cc rename to src/accessor/grib_accessor_class_data_g1second_order_general_packing.cc index 3e41fd3e0..8fb0165d0 100644 --- a/src/grib_accessor_class_data_g1second_order_general_packing.cc +++ b/src/accessor/grib_accessor_class_data_g1second_order_general_packing.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,157 +9,17 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_scaling.h" -#include "grib_api_internal.h" -#include - - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_data_simple_packing - IMPLEMENTS = init - IMPLEMENTS = pack_double - IMPLEMENTS = unpack_double;unpack_float - IMPLEMENTS = value_count - MEMBERS=const char* half_byte - MEMBERS=const char* packingType - MEMBERS=const char* ieee_packing - MEMBERS=const char* precision - MEMBERS=const char* widthOfFirstOrderValues - MEMBERS=const char* N1 - MEMBERS=const char* N2 - MEMBERS=const char* numberOfGroups - MEMBERS=const char* numberOfSecondOrderPackedValues - MEMBERS=const char* extraValues - MEMBERS=const char* pl - MEMBERS=const char* Ni - MEMBERS=const char* Nj - MEMBERS=const char* jPointsAreConsecutive - MEMBERS=const char* bitmap - MEMBERS=const char* groupWidths - - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_float(grib_accessor*, float* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_data_g1second_order_general_packing -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in values */ - int carg; - const char* seclen; - const char* offsetdata; - const char* offsetsection; - int dirty; - /* Members defined in data_simple_packing */ - int edition; - const char* units_factor; - const char* units_bias; - const char* changing_precision; - const char* number_of_values; - const char* bits_per_value; - const char* reference_value; - const char* binary_scale_factor; - const char* decimal_scale_factor; - const char* optimize_scaling_factor; - /* Members defined in data_g1second_order_general_packing */ - const char* half_byte; - const char* packingType; - const char* ieee_packing; - const char* precision; - const char* widthOfFirstOrderValues; - const char* N1; - const char* N2; - const char* numberOfGroups; - const char* numberOfSecondOrderPackedValues; - const char* extraValues; - const char* pl; - const char* Ni; - const char* Nj; - const char* jPointsAreConsecutive; - const char* bitmap; - const char* groupWidths; -} grib_accessor_data_g1second_order_general_packing; - -extern grib_accessor_class* grib_accessor_class_data_simple_packing; - -static grib_accessor_class _grib_accessor_class_data_g1second_order_general_packing = { - &grib_accessor_class_data_simple_packing, /* super */ - "data_g1second_order_general_packing", /* name */ - sizeof(grib_accessor_data_g1second_order_general_packing), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - &unpack_float, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_data_g1second_order_general_packing.h" +grib_accessor_class_data_g1second_order_general_packing_t _grib_accessor_class_data_g1second_order_general_packing{ "data_g1second_order_general_packing" }; grib_accessor_class* grib_accessor_class_data_g1second_order_general_packing = &_grib_accessor_class_data_g1second_order_general_packing; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_class_data_g1second_order_general_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) { - grib_accessor_data_g1second_order_general_packing* self = (grib_accessor_data_g1second_order_general_packing*)a; - grib_handle* hand = grib_handle_of_accessor(a); + grib_accessor_class_data_simple_packing_t::init(a, v, args); + grib_accessor_data_g1second_order_general_packing_t* self = (grib_accessor_data_g1second_order_general_packing_t*)a; + grib_handle* hand = grib_handle_of_accessor(a); self->half_byte = grib_arguments_get_name(hand, args, self->carg++); self->packingType = grib_arguments_get_name(hand, args, self->carg++); @@ -180,23 +41,22 @@ static void init(grib_accessor* a, const long v, grib_arguments* args) a->flags |= GRIB_ACCESSOR_FLAG_DATA; } -static int value_count(grib_accessor* a, long* numberOfSecondOrderPackedValues) +int grib_accessor_class_data_g1second_order_general_packing_t::value_count(grib_accessor* a, long* numberOfSecondOrderPackedValues) { - int err = 0; - grib_accessor_data_g1second_order_general_packing* self = (grib_accessor_data_g1second_order_general_packing*)a; - *numberOfSecondOrderPackedValues = 0; + grib_accessor_data_g1second_order_general_packing_t* self = (grib_accessor_data_g1second_order_general_packing_t*)a; + *numberOfSecondOrderPackedValues = 0; - err = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfSecondOrderPackedValues, numberOfSecondOrderPackedValues); + int err = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfSecondOrderPackedValues, numberOfSecondOrderPackedValues); return err; } template -static int unpack(grib_accessor* a, T* values, size_t* len) +static int unpack_real(grib_accessor* a, T* values, size_t* len) { static_assert(std::is_floating_point::value, "Requires floating point numbers"); - grib_accessor_data_g1second_order_general_packing* self = (grib_accessor_data_g1second_order_general_packing*)a; - int ret = 0; + grib_accessor_data_g1second_order_general_packing_t* self = (grib_accessor_data_g1second_order_general_packing_t*)a; + int ret = 0; long numberOfGroups, numberOfSecondOrderPackedValues; long* groupWidths = 0; long* firstOrderValues = 0; @@ -213,8 +73,7 @@ static int unpack(grib_accessor* a, T* values, size_t* len) long groupLength, j; size_t groupWidthsSize; - buf += grib_byte_offset(a); - + buf += a->byte_offset(); if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfGroups, &numberOfGroups)) != GRIB_SUCCESS) return ret; @@ -296,25 +155,24 @@ static int unpack(grib_accessor* a, T* values, size_t* len) return ret; } -static int unpack_float(grib_accessor* a, float* values, size_t* len) +int grib_accessor_class_data_g1second_order_general_packing_t::unpack_float(grib_accessor* a, float* values, size_t* len) { - return unpack(a, values, len); + return unpack_real(a, values, len); } -static int unpack_double(grib_accessor* a, double* values, size_t* len) +int grib_accessor_class_data_g1second_order_general_packing_t::unpack_double(grib_accessor* a, double* values, size_t* len) { - return unpack(a, values, len); + return unpack_real(a, values, len); } -static int pack_double(grib_accessor* a, const double* cval, size_t* len) +int grib_accessor_class_data_g1second_order_general_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len) { /* return GRIB_NOT_IMPLEMENTED; */ - int err = 0; char type[] = "grid_second_order"; size_t size = strlen(type); grib_handle* hand = grib_handle_of_accessor(a); - err = grib_set_string(hand, "packingType", type, &size); + int err = grib_set_string(hand, "packingType", type, &size); if (err) return err; diff --git a/src/accessor/grib_accessor_class_data_g1second_order_general_packing.h b/src/accessor/grib_accessor_class_data_g1second_order_general_packing.h new file mode 100644 index 000000000..95295dae1 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_g1second_order_general_packing.h @@ -0,0 +1,48 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_data_simple_packing.h" +#include "grib_scaling.h" + +class grib_accessor_data_g1second_order_general_packing_t : public grib_accessor_data_simple_packing_t +{ +public: + /* Members defined in data_g1second_order_general_packing */ + const char* half_byte; + const char* packingType; + const char* ieee_packing; + const char* precision; + const char* widthOfFirstOrderValues; + const char* N1; + const char* N2; + const char* numberOfGroups; + const char* numberOfSecondOrderPackedValues; + const char* extraValues; + const char* pl; + const char* Ni; + const char* Nj; + const char* jPointsAreConsecutive; + const char* bitmap; + const char* groupWidths; +}; + +class grib_accessor_class_data_g1second_order_general_packing_t : public grib_accessor_class_data_simple_packing_t +{ +public: + grib_accessor_class_data_g1second_order_general_packing_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g1second_order_general_packing_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_float(grib_accessor*, float* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_data_g1second_order_row_by_row_packing.cc b/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.cc similarity index 61% rename from src/grib_accessor_class_data_g1second_order_row_by_row_packing.cc rename to src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.cc index b801b3b1c..afed13ca2 100644 --- a/src/grib_accessor_class_data_g1second_order_row_by_row_packing.cc +++ b/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,155 +9,17 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_scaling.h" -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_data_simple_packing - IMPLEMENTS = init - IMPLEMENTS = pack_double - IMPLEMENTS = unpack_double;unpack_float - IMPLEMENTS = value_count - MEMBERS=const char* half_byte - MEMBERS=const char* packingType - MEMBERS=const char* ieee_packing - MEMBERS=const char* precision - MEMBERS=const char* widthOfFirstOrderValues - MEMBERS=const char* N1 - MEMBERS=const char* N2 - MEMBERS=const char* numberOfGroups - MEMBERS=const char* numberOfSecondOrderPackedValues - MEMBERS=const char* extraValues - MEMBERS=const char* pl - MEMBERS=const char* Ni - MEMBERS=const char* Nj - MEMBERS=const char* jPointsAreConsecutive - MEMBERS=const char* bitmap - MEMBERS=const char* groupWidths - - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_float(grib_accessor*, float* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_data_g1second_order_row_by_row_packing -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in values */ - int carg; - const char* seclen; - const char* offsetdata; - const char* offsetsection; - int dirty; - /* Members defined in data_simple_packing */ - int edition; - const char* units_factor; - const char* units_bias; - const char* changing_precision; - const char* number_of_values; - const char* bits_per_value; - const char* reference_value; - const char* binary_scale_factor; - const char* decimal_scale_factor; - const char* optimize_scaling_factor; - /* Members defined in data_g1second_order_row_by_row_packing */ - const char* half_byte; - const char* packingType; - const char* ieee_packing; - const char* precision; - const char* widthOfFirstOrderValues; - const char* N1; - const char* N2; - const char* numberOfGroups; - const char* numberOfSecondOrderPackedValues; - const char* extraValues; - const char* pl; - const char* Ni; - const char* Nj; - const char* jPointsAreConsecutive; - const char* bitmap; - const char* groupWidths; -} grib_accessor_data_g1second_order_row_by_row_packing; - -extern grib_accessor_class* grib_accessor_class_data_simple_packing; - -static grib_accessor_class _grib_accessor_class_data_g1second_order_row_by_row_packing = { - &grib_accessor_class_data_simple_packing, /* super */ - "data_g1second_order_row_by_row_packing", /* name */ - sizeof(grib_accessor_data_g1second_order_row_by_row_packing), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - &unpack_float, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_data_g1second_order_row_by_row_packing.h" +grib_accessor_class_data_g1second_order_row_by_row_packing_t _grib_accessor_class_data_g1second_order_row_by_row_packing{ "data_g1second_order_row_by_row_packing" }; grib_accessor_class* grib_accessor_class_data_g1second_order_row_by_row_packing = &_grib_accessor_class_data_g1second_order_row_by_row_packing; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_class_data_g1second_order_row_by_row_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) { - grib_accessor_data_g1second_order_row_by_row_packing* self = (grib_accessor_data_g1second_order_row_by_row_packing*)a; - grib_handle* gh = grib_handle_of_accessor(a); + grib_accessor_class_data_simple_packing_t::init(a, v, args); + grib_accessor_data_g1second_order_row_by_row_packing_t* self = (grib_accessor_data_g1second_order_row_by_row_packing_t*)a; + grib_handle* gh = grib_handle_of_accessor(a); self->half_byte = grib_arguments_get_name(gh, args, self->carg++); self->packingType = grib_arguments_get_name(gh, args, self->carg++); @@ -178,12 +41,13 @@ static void init(grib_accessor* a, const long v, grib_arguments* args) a->flags |= GRIB_ACCESSOR_FLAG_DATA; } -static int value_count(grib_accessor* a, long* count) +int grib_accessor_class_data_g1second_order_row_by_row_packing_t::value_count(grib_accessor* a, long* count) { - grib_accessor_data_g1second_order_row_by_row_packing* self = (grib_accessor_data_g1second_order_row_by_row_packing*)a; - grib_handle* gh = grib_handle_of_accessor(a); + grib_accessor_data_g1second_order_row_by_row_packing_t* self = (grib_accessor_data_g1second_order_row_by_row_packing_t*)a; + + grib_handle* gh = grib_handle_of_accessor(a); long n = 0, i = 0; - long numberOfRows = 0; + long numberOfRows = 0; long jPointsAreConsecutive = 0; long Ni = 0, Nj = 0; int bitmapPresent = 0; @@ -254,11 +118,12 @@ static int value_count(grib_accessor* a, long* count) } template -static int unpack(grib_accessor* a, T* values, size_t* len) +static int unpack_real(grib_accessor* a, T* values, size_t* len) { - grib_accessor_data_g1second_order_row_by_row_packing* self = (grib_accessor_data_g1second_order_row_by_row_packing*)a; - grib_handle* gh = grib_handle_of_accessor(a); - int ret = 0; + grib_accessor_data_g1second_order_row_by_row_packing_t* self = (grib_accessor_data_g1second_order_row_by_row_packing_t*)a; + + grib_handle* gh = grib_handle_of_accessor(a); + int ret = 0; long numberOfGroups, numberOfSecondOrderPackedValues; long* groupWidths = 0; long* firstOrderValues = 0; @@ -279,8 +144,7 @@ static int unpack(grib_accessor* a, T* values, size_t* len) size_t plSize = 0; long* pl = 0; - buf += grib_byte_offset(a); - + buf += a->byte_offset(); if ((ret = grib_get_long_internal(gh, self->numberOfGroups, &numberOfGroups)) != GRIB_SUCCESS) return ret; @@ -421,17 +285,17 @@ static int unpack(grib_accessor* a, T* values, size_t* len) return ret; } -static int unpack_float(grib_accessor* a, float* values, size_t* len) +int grib_accessor_class_data_g1second_order_row_by_row_packing_t::unpack_float(grib_accessor* a, float* values, size_t* len) { - return unpack(a, values, len); + return unpack_real(a, values, len); } -static int unpack_double(grib_accessor* a, double* values, size_t* len) +int grib_accessor_class_data_g1second_order_row_by_row_packing_t::unpack_double(grib_accessor* a, double* values, size_t* len) { - return unpack(a, values, len); + return unpack_real(a, values, len); } -static int pack_double(grib_accessor* a, const double* cval, size_t* len) +int grib_accessor_class_data_g1second_order_row_by_row_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len) { int err = 0; grib_handle* gh = grib_handle_of_accessor(a); diff --git a/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.h b/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.h new file mode 100644 index 000000000..eca551669 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.h @@ -0,0 +1,48 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_data_simple_packing.h" +#include "grib_scaling.h" + +class grib_accessor_data_g1second_order_row_by_row_packing_t : public grib_accessor_data_simple_packing_t +{ +public: + /* Members defined in data_g1second_order_row_by_row_packing */ + const char* half_byte; + const char* packingType; + const char* ieee_packing; + const char* precision; + const char* widthOfFirstOrderValues; + const char* N1; + const char* N2; + const char* numberOfGroups; + const char* numberOfSecondOrderPackedValues; + const char* extraValues; + const char* pl; + const char* Ni; + const char* Nj; + const char* jPointsAreConsecutive; + const char* bitmap; + const char* groupWidths; +}; + +class grib_accessor_class_data_g1second_order_row_by_row_packing_t : public grib_accessor_class_data_simple_packing_t +{ +public: + grib_accessor_class_data_g1second_order_row_by_row_packing_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g1second_order_row_by_row_packing_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_float(grib_accessor*, float* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_data_g1secondary_bitmap.cc b/src/accessor/grib_accessor_class_data_g1secondary_bitmap.cc new file mode 100644 index 000000000..3697f6f75 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_g1secondary_bitmap.cc @@ -0,0 +1,128 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_data_g1secondary_bitmap.h" + +grib_accessor_class_data_g1secondary_bitmap_t _grib_accessor_class_data_g1secondary_bitmap{"data_g1secondary_bitmap"}; +grib_accessor_class* grib_accessor_class_data_g1secondary_bitmap = &_grib_accessor_class_data_g1secondary_bitmap; + + +void grib_accessor_class_data_g1secondary_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args){ + grib_accessor_class_data_secondary_bitmap_t::init(a, v, args); + grib_accessor_data_g1secondary_bitmap_t* self = (grib_accessor_data_g1secondary_bitmap_t*)a; + self->number_of_ones = grib_arguments_get_name(grib_handle_of_accessor(a), args, 4); +} + +int grib_accessor_class_data_g1secondary_bitmap_t::value_count(grib_accessor* a, long* count){ + grib_accessor_data_g1secondary_bitmap_t* self = (grib_accessor_data_g1secondary_bitmap_t*)a; + size_t len = 0; + int err = 0; + long expand_by; + *count = 0; + + err = grib_get_long_internal(grib_handle_of_accessor(a), self->expand_by, &expand_by); + if (err) + return err; + + err = grib_get_size(grib_handle_of_accessor(a), self->primary_bitmap, &len); + if (err) + return err; + + *count = expand_by * len; + return GRIB_SUCCESS; +} + +int grib_accessor_class_data_g1secondary_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len){ + grib_accessor_data_g1secondary_bitmap_t* self = (grib_accessor_data_g1secondary_bitmap_t*)a; + + int err = 0; + + long primary_len = 0; + long secondary_len = 0; + double* primary_bitmap = NULL; + double* secondary_bitmap = NULL; + long i = 0; + long j = 0; + long on = 0; + long k; + long m; + double missing_value = 0; + double present_value = 0; + long expand_by = 0; + + if (*len == 0) + return GRIB_NO_VALUES; + + if ((err = grib_get_long(grib_handle_of_accessor(a), self->expand_by, &expand_by)) != GRIB_SUCCESS) + return err; + if (expand_by <= 0) + return GRIB_ENCODING_ERROR; + + if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value, &missing_value)) != GRIB_SUCCESS) + return err; + + if (*len % expand_by) { + /*TODO: issue warning */ + return GRIB_ENCODING_ERROR; + } + + primary_len = *len / expand_by; + primary_bitmap = (double*)grib_context_malloc_clear(a->context, primary_len * sizeof(double)); + if (!primary_bitmap) + return GRIB_OUT_OF_MEMORY; + + secondary_len = *len; + secondary_bitmap = (double*)grib_context_malloc_clear(a->context, secondary_len * sizeof(double)); + if (!secondary_bitmap) { + grib_context_free(a->context, primary_bitmap); + return GRIB_OUT_OF_MEMORY; + } + + if (missing_value == 0) + present_value = 1; + else + present_value = 0; + + k = 0; + m = 0; + for (i = 0; i < *len; i += expand_by) { + int cnt = 0; + for (j = 0; j < expand_by; j++) + if (val[i + j] == missing_value) + cnt++; + + if (cnt == expand_by) /* all expand_by values are missing */ + primary_bitmap[k++] = missing_value; + else { + primary_bitmap[k++] = present_value; + for (j = 0; j < expand_by; j++) + secondary_bitmap[m++] = val[i + j]; + on++; + } + } + + *len = k; + + /*printf("QQQQQQQ %ld %ld second=%ld\n",primary_len,on,m);*/ + Assert(k == primary_len); + + err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->primary_bitmap, primary_bitmap, k); + if (err == GRIB_SUCCESS) + err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->secondary_bitmap, secondary_bitmap, m); + + grib_context_free(a->context, primary_bitmap); + grib_context_free(a->context, secondary_bitmap); + + if (err == GRIB_SUCCESS) + err = grib_set_long_internal(grib_handle_of_accessor(a), self->number_of_ones, on); + + return err; +} diff --git a/src/accessor/grib_accessor_class_data_g1secondary_bitmap.h b/src/accessor/grib_accessor_class_data_g1secondary_bitmap.h new file mode 100644 index 000000000..63ee792ae --- /dev/null +++ b/src/accessor/grib_accessor_class_data_g1secondary_bitmap.h @@ -0,0 +1,30 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_data_secondary_bitmap.h" + +class grib_accessor_data_g1secondary_bitmap_t : public grib_accessor_data_secondary_bitmap_t +{ +public: + /* Members defined in data_g1secondary_bitmap */ + const char* number_of_ones; +}; + +class grib_accessor_class_data_g1secondary_bitmap_t : public grib_accessor_class_data_secondary_bitmap_t +{ +public: + grib_accessor_class_data_g1secondary_bitmap_t(const char* name) : grib_accessor_class_data_secondary_bitmap_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g1secondary_bitmap_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_data_g1shsimple_packing.cc b/src/accessor/grib_accessor_class_data_g1shsimple_packing.cc new file mode 100644 index 000000000..f1f06d654 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_g1shsimple_packing.cc @@ -0,0 +1,63 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_data_g1shsimple_packing.h" + +grib_accessor_class_data_g1shsimple_packing_t _grib_accessor_class_data_g1shsimple_packing{"data_g1shsimple_packing"}; +grib_accessor_class* grib_accessor_class_data_g1shsimple_packing = &_grib_accessor_class_data_g1shsimple_packing; + + + +int grib_accessor_class_data_g1shsimple_packing_t::value_count(grib_accessor* a, long* count){ + grib_accessor_data_g1shsimple_packing_t* self = (grib_accessor_data_g1shsimple_packing_t*)a; + size_t len = 0; + int err = 0; + + err = grib_get_size(grib_handle_of_accessor(a), self->coded_values, &len); + len += 1; + + *count = len; + return err; +} + +int grib_accessor_class_data_g1shsimple_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + grib_accessor_data_g1shsimple_packing_t* self = (grib_accessor_data_g1shsimple_packing_t*)a; + int err = GRIB_SUCCESS; + + size_t coded_n_vals = 0; + size_t n_vals = 0; + + if ((err = grib_get_size(grib_handle_of_accessor(a), self->coded_values, &coded_n_vals)) != GRIB_SUCCESS) + return err; + + n_vals = coded_n_vals + 1; + + if (*len < n_vals) { + *len = n_vals; + return GRIB_ARRAY_TOO_SMALL; + } + + if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->real_part, val)) != GRIB_SUCCESS) + return err; + + val++; + + if ((err = grib_get_double_array_internal(grib_handle_of_accessor(a), self->coded_values, val, &coded_n_vals)) != GRIB_SUCCESS) + return err; + + grib_context_log(a->context, GRIB_LOG_DEBUG, + "grib_accessor_data_g1shsimple_packing_t_bitmap : unpack_double : creating %s, %d values", + a->name, n_vals); + + *len = n_vals; + + return err; +} diff --git a/src/accessor/grib_accessor_class_data_g1shsimple_packing.h b/src/accessor/grib_accessor_class_data_g1shsimple_packing.h new file mode 100644 index 000000000..c852c7213 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_g1shsimple_packing.h @@ -0,0 +1,28 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_data_shsimple_packing.h" + +class grib_accessor_data_g1shsimple_packing_t : public grib_accessor_data_shsimple_packing_t +{ +public: + /* Members defined in data_g1shsimple_packing */ +}; + +class grib_accessor_class_data_g1shsimple_packing_t : public grib_accessor_class_data_shsimple_packing_t +{ +public: + grib_accessor_class_data_g1shsimple_packing_t(const char* name) : grib_accessor_class_data_shsimple_packing_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g1shsimple_packing_t{}; } + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; +}; diff --git a/src/grib_accessor_class_data_g1simple_packing.cc b/src/accessor/grib_accessor_class_data_g1simple_packing.cc similarity index 64% rename from src/grib_accessor_class_data_g1simple_packing.cc rename to src/accessor/grib_accessor_class_data_g1simple_packing.cc index cc810e4ae..a19132f1a 100644 --- a/src/grib_accessor_class_data_g1simple_packing.cc +++ b/src/accessor/grib_accessor_class_data_g1simple_packing.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,126 +9,16 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_accessor_class_data_g1simple_packing.h" #include "grib_scaling.h" -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_data_simple_packing - IMPLEMENTS = init - IMPLEMENTS = pack_double - IMPLEMENTS = value_count - MEMBERS=const char* half_byte - MEMBERS=const char* packingType - MEMBERS=const char* ieee_packing - MEMBERS=const char* precision - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_data_g1simple_packing -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in values */ - int carg; - const char* seclen; - const char* offsetdata; - const char* offsetsection; - int dirty; - /* Members defined in data_simple_packing */ - int edition; - const char* units_factor; - const char* units_bias; - const char* changing_precision; - const char* number_of_values; - const char* bits_per_value; - const char* reference_value; - const char* binary_scale_factor; - const char* decimal_scale_factor; - const char* optimize_scaling_factor; - /* Members defined in data_g1simple_packing */ - const char* half_byte; - const char* packingType; - const char* ieee_packing; - const char* precision; -} grib_accessor_data_g1simple_packing; - -extern grib_accessor_class* grib_accessor_class_data_simple_packing; - -static grib_accessor_class _grib_accessor_class_data_g1simple_packing = { - &grib_accessor_class_data_simple_packing, /* super */ - "data_g1simple_packing", /* name */ - sizeof(grib_accessor_data_g1simple_packing), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +grib_accessor_class_data_g1simple_packing_t _grib_accessor_class_data_g1simple_packing{"data_g1simple_packing"}; grib_accessor_class* grib_accessor_class_data_g1simple_packing = &_grib_accessor_class_data_g1simple_packing; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long v, grib_arguments* args) -{ - grib_accessor_data_g1simple_packing* self = (grib_accessor_data_g1simple_packing*)a; +void grib_accessor_class_data_g1simple_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){ + grib_accessor_class_data_simple_packing_t::init(a, v, args); + grib_accessor_data_g1simple_packing_t* self = (grib_accessor_data_g1simple_packing_t*)a; self->half_byte = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); self->packingType = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); @@ -137,9 +28,8 @@ static void init(grib_accessor* a, const long v, grib_arguments* args) a->flags |= GRIB_ACCESSOR_FLAG_DATA; } -static int value_count(grib_accessor* a, long* number_of_values) -{ - grib_accessor_data_g1simple_packing* self = (grib_accessor_data_g1simple_packing*)a; +int grib_accessor_class_data_g1simple_packing_t::value_count(grib_accessor* a, long* number_of_values){ + grib_accessor_data_g1simple_packing_t* self = (grib_accessor_data_g1simple_packing_t*)a; *number_of_values = 0; /* Special case for when values are cleared */ @@ -149,10 +39,8 @@ static int value_count(grib_accessor* a, long* number_of_values) return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, number_of_values); } -static int pack_double(grib_accessor* a, const double* cval, size_t* len) -{ - grib_accessor_data_g1simple_packing* self = (grib_accessor_data_g1simple_packing*)a; - grib_accessor_class* super = *(a->cclass->super); +int grib_accessor_class_data_g1simple_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len){ + grib_accessor_data_g1simple_packing_t* self = (grib_accessor_data_g1simple_packing_t*)a; size_t n_vals = *len; long half_byte = 0; @@ -234,7 +122,7 @@ static int pack_double(grib_accessor* a, const double* cval, size_t* len) } } - ret = super->pack_double(a, val, len); + ret = grib_accessor_class_data_simple_packing_t::pack_double(a, val, len); switch (ret) { case GRIB_CONSTANT_FIELD: ret = grib_get_long(grib_handle_of_accessor(a), "constantFieldHalfByte", &constantFieldHalfByte); @@ -319,7 +207,7 @@ static int pack_double(grib_accessor* a, const double* cval, size_t* len) grib_encode_double_array(n_vals, val, bits_per_value, reference_value, decimal, divisor, encoded, &off); grib_context_log(a->context, GRIB_LOG_DEBUG, - "grib_accessor_data_g1simple_packing : pack_double : packing %s, %d values", a->name, n_vals); + "grib_accessor_data_g1simple_packing_t : pack_double : packing %s, %d values", a->name, n_vals); ret = grib_buffer_replace(a, buf, buflen, 1, 1); if (ret != GRIB_SUCCESS) return ret; diff --git a/src/accessor/grib_accessor_class_data_g1simple_packing.h b/src/accessor/grib_accessor_class_data_g1simple_packing.h new file mode 100644 index 000000000..c82532361 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_g1simple_packing.h @@ -0,0 +1,33 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_data_simple_packing.h" + +class grib_accessor_data_g1simple_packing_t : public grib_accessor_data_simple_packing_t +{ +public: + /* Members defined in data_g1simple_packing */ + const char* half_byte; + const char* packingType; + const char* ieee_packing; + const char* precision; +}; + +class grib_accessor_class_data_g1simple_packing_t : public grib_accessor_class_data_simple_packing_t +{ +public: + grib_accessor_class_data_g1simple_packing_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g1simple_packing_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_data_g22order_packing.cc b/src/accessor/grib_accessor_class_data_g22order_packing.cc similarity index 85% rename from src/grib_accessor_class_data_g22order_packing.cc rename to src/accessor/grib_accessor_class_data_g22order_packing.cc index 954456e2e..bbc698100 100644 --- a/src/grib_accessor_class_data_g22order_packing.cc +++ b/src/accessor/grib_accessor_class_data_g22order_packing.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,164 +9,23 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_accessor_class_data_g22order_packing.h" -#include "grib_scaling.h" -#include "grib_api_internal.h" -#include - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_values - IMPLEMENTS = init - IMPLEMENTS = unpack_double - IMPLEMENTS = unpack_float - IMPLEMENTS = pack_double - IMPLEMENTS = unpack_double_element;unpack_double_element_set - IMPLEMENTS = value_count - MEMBERS=const char* numberOfValues - MEMBERS=const char* bits_per_value - MEMBERS=const char* reference_value - MEMBERS=const char* binary_scale_factor - MEMBERS=const char* decimal_scale_factor - MEMBERS=const char* optimize_scale_factor - MEMBERS=const char* typeOfOriginalFieldValues - MEMBERS=const char* groupSplittingMethodUsed - MEMBERS=const char* missingValueManagementUsed - MEMBERS=const char* primaryMissingValueSubstitute - MEMBERS=const char* secondaryMissingValueSubstitute - MEMBERS=const char* numberOfGroupsOfDataValues - MEMBERS=const char* referenceForGroupWidths - MEMBERS=const char* numberOfBitsUsedForTheGroupWidths - MEMBERS=const char* referenceForGroupLengths - MEMBERS=const char* lengthIncrementForTheGroupLengths - MEMBERS=const char* trueLengthOfLastGroup - MEMBERS=const char* numberOfBitsUsedForTheScaledGroupLengths - MEMBERS=const char* orderOfSpatialDifferencing - MEMBERS=const char* numberOfOctetsExtraDescriptors - - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_float(grib_accessor*, float* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); -static int unpack_double_element(grib_accessor*, size_t i, double* val); -static int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array); - -typedef struct grib_accessor_data_g22order_packing -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in values */ - int carg; - const char* seclen; - const char* offsetdata; - const char* offsetsection; - int dirty; - /* Members defined in data_g22order_packing */ - const char* numberOfValues; - const char* bits_per_value; - const char* reference_value; - const char* binary_scale_factor; - const char* decimal_scale_factor; - const char* optimize_scale_factor; - const char* typeOfOriginalFieldValues; - const char* groupSplittingMethodUsed; - const char* missingValueManagementUsed; - const char* primaryMissingValueSubstitute; - const char* secondaryMissingValueSubstitute; - const char* numberOfGroupsOfDataValues; - const char* referenceForGroupWidths; - const char* numberOfBitsUsedForTheGroupWidths; - const char* referenceForGroupLengths; - const char* lengthIncrementForTheGroupLengths; - const char* trueLengthOfLastGroup; - const char* numberOfBitsUsedForTheScaledGroupLengths; - const char* orderOfSpatialDifferencing; - const char* numberOfOctetsExtraDescriptors; -} grib_accessor_data_g22order_packing; - -extern grib_accessor_class* grib_accessor_class_values; - -static grib_accessor_class _grib_accessor_class_data_g22order_packing = { - &grib_accessor_class_values, /* super */ - "data_g22order_packing", /* name */ - sizeof(grib_accessor_data_g22order_packing), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - &unpack_float, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - &unpack_double_element, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - &unpack_double_element_set, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - +grib_accessor_class_data_g22order_packing_t _grib_accessor_class_data_g22order_packing{ "data_g22order_packing" }; grib_accessor_class* grib_accessor_class_data_g22order_packing = &_grib_accessor_class_data_g22order_packing; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_class_data_g22order_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) { - grib_accessor_data_g22order_packing* self = reinterpret_cast(a); - grib_handle* gh = grib_handle_of_accessor(a); + grib_accessor_class_values_t::init(a, v, args); + grib_accessor_data_g22order_packing_t* self = reinterpret_cast(a); + grib_handle* gh = grib_handle_of_accessor(a); - self->numberOfValues = grib_arguments_get_name(gh, args, self->carg++); - self->bits_per_value = grib_arguments_get_name(gh, args, self->carg++); - self->reference_value = grib_arguments_get_name(gh, args, self->carg++); - self->binary_scale_factor = grib_arguments_get_name(gh, args, self->carg++); - self->decimal_scale_factor = grib_arguments_get_name(gh, args, self->carg++); + self->numberOfValues = grib_arguments_get_name(gh, args, self->carg++); + self->bits_per_value = grib_arguments_get_name(gh, args, self->carg++); + self->reference_value = grib_arguments_get_name(gh, args, self->carg++); + self->binary_scale_factor = grib_arguments_get_name(gh, args, self->carg++); + self->decimal_scale_factor = grib_arguments_get_name(gh, args, self->carg++); self->optimize_scale_factor = grib_arguments_get_name(gh, args, self->carg++); self->typeOfOriginalFieldValues = grib_arguments_get_name(gh, args, self->carg++); @@ -186,33 +46,33 @@ static void init(grib_accessor* a, const long v, grib_arguments* args) a->flags |= GRIB_ACCESSOR_FLAG_DATA; } - #define ONES (~(int)0) // #define UNDEFINED 9.999e20 // #define UNDEFINED_LOW 9.9989e20 // #define UNDEFINED_HIGH 9.9991e20 -#define UNDEFINED 9999.0 -#define UNDEFINED_LOW 9998.9 -#define UNDEFINED_HIGH 9999.1 +#define UNDEFINED 9999.0 +#define UNDEFINED_LOW 9998.9 +#define UNDEFINED_HIGH 9999.1 #define UNDEFINED_VAL(x) ((x) >= UNDEFINED_LOW && (x) <= UNDEFINED_HIGH) -#define DEFINED_VAL(x) ((x) < UNDEFINED_LOW || (x) > UNDEFINED_HIGH) -#define UNDEFINED_ANGLE 999.0 +#define DEFINED_VAL(x) ((x) < UNDEFINED_LOW || (x) > UNDEFINED_HIGH) +#define UNDEFINED_ANGLE 999.0 -struct bitstream_context { +struct bitstream_context +{ unsigned char* bitstream; int rbits; int reg; int n_bitstream; }; -static void init_bitstream(bitstream_context *ctx, unsigned char* new_bitstream) +void init_bitstream(bitstream_context* ctx, unsigned char* new_bitstream) { ctx->bitstream = new_bitstream; ctx->n_bitstream = ctx->reg = ctx->rbits = 0; } -static void finish_bitstream(bitstream_context *ctx) +void finish_bitstream(bitstream_context* ctx) { if (ctx->rbits) { ctx->n_bitstream++; @@ -221,7 +81,7 @@ static void finish_bitstream(bitstream_context *ctx) } } -static void add_many_bitstream(bitstream_context *ctx, grib_accessor* a, int* t, int n, int n_bits) +void add_many_bitstream(bitstream_context* ctx, grib_accessor* a, int* t, int n, int n_bits) { unsigned int jmask; int i; @@ -245,7 +105,7 @@ static void add_many_bitstream(bitstream_context *ctx, grib_accessor* a, int* t, } } -static void add_bitstream(bitstream_context *ctx, grib_accessor* a, int t, int n_bits) +void add_bitstream(bitstream_context* ctx, grib_accessor* a, int t, int n_bits) { unsigned int jmask; const int max_numbits = 25; @@ -506,255 +366,6 @@ static int post_process(grib_context* c, long* vals, long len, long order, long return GRIB_SUCCESS; } -template -static int unpack(grib_accessor* a, T* val, const size_t* len) -{ - static_assert(std::is_floating_point::value, "Requires floating point numbers"); - grib_accessor_data_g22order_packing* self = reinterpret_cast(a); - const char* cclass_name = a->cclass->name; - grib_handle* gh = grib_handle_of_accessor(a); - - size_t i = 0; - size_t j = 0; - long n_vals = 0; - long vcount = 0; - int err = GRIB_SUCCESS; - long* sec_val = NULL; - unsigned char* buf = reinterpret_cast(gh->buffer->data); - unsigned char* buf_ref = NULL; - unsigned char* buf_width = NULL; - unsigned char* buf_length = NULL; - unsigned char* buf_vals = NULL; - - long length_p = 0; - long ref_p = 0; - long width_p = 0; - long vals_p = 0; - long nvals_per_group = 0; - long nbits_per_group_val = 0; - long group_ref_val = 0; - - long bits_per_value = 0; - T binary_s = 0; - T decimal_s = 0; - double reference_value = 0; - - long binary_scale_factor; - long decimal_scale_factor; - long typeOfOriginalFieldValues; - long groupSplittingMethodUsed; - long missingValueManagementUsed; - long primaryMissingValueSubstitute; - long secondaryMissingValueSubstitute; - long numberOfGroupsOfDataValues; - long referenceForGroupWidths; - long numberOfBitsUsedForTheGroupWidths; - long referenceForGroupLengths; - long lengthIncrementForTheGroupLengths; - long trueLengthOfLastGroup; - long numberOfBitsUsedForTheScaledGroupLengths; - long orderOfSpatialDifferencing = 0; - long numberOfOctetsExtraDescriptors = 0; - double missingValue = 0; - - err = grib_value_count(a, &n_vals); - if (err) - return err; - - if (*len < static_cast(n_vals)) - return GRIB_ARRAY_TOO_SMALL; - - if ((err = grib_get_long_internal(gh, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) - return err; - if ((err = grib_get_double_internal(gh, self->reference_value, &reference_value)) != GRIB_SUCCESS) - return err; - if ((err = grib_get_long_internal(gh, self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) - return err; - if ((err = grib_get_long_internal(gh, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) - return err; - if ((err = grib_get_long_internal(gh, self->typeOfOriginalFieldValues, &typeOfOriginalFieldValues)) != GRIB_SUCCESS) - return err; - - // Don't call grib_get_long_internal to suppress error message being output - if ((err = grib_get_long(gh, self->groupSplittingMethodUsed, &groupSplittingMethodUsed)) != GRIB_SUCCESS) - return err; - - if ((err = grib_get_long_internal(gh, self->missingValueManagementUsed, &missingValueManagementUsed)) != GRIB_SUCCESS) - return err; - if ((err = grib_get_long_internal(gh, self->primaryMissingValueSubstitute, &primaryMissingValueSubstitute)) != GRIB_SUCCESS) - return err; - if ((err = grib_get_long_internal(gh, self->secondaryMissingValueSubstitute, &secondaryMissingValueSubstitute)) != GRIB_SUCCESS) - return err; - if ((err = grib_get_long_internal(gh, self->numberOfGroupsOfDataValues, &numberOfGroupsOfDataValues)) != GRIB_SUCCESS) - return err; - if ((err = grib_get_long_internal(gh, self->referenceForGroupWidths, &referenceForGroupWidths)) != GRIB_SUCCESS) - return err; - if ((err = grib_get_long_internal(gh, self->numberOfBitsUsedForTheGroupWidths, &numberOfBitsUsedForTheGroupWidths)) != GRIB_SUCCESS) - return err; - if ((err = grib_get_long_internal(gh, self->referenceForGroupLengths, &referenceForGroupLengths)) != GRIB_SUCCESS) - return err; - - if ((err = grib_get_long_internal(gh, self->lengthIncrementForTheGroupLengths, &lengthIncrementForTheGroupLengths)) != GRIB_SUCCESS) - return err; - if ((err = grib_get_long_internal(gh, self->trueLengthOfLastGroup, &trueLengthOfLastGroup)) != GRIB_SUCCESS) - return err; - if ((err = grib_get_long_internal(gh, self->numberOfBitsUsedForTheScaledGroupLengths, &numberOfBitsUsedForTheScaledGroupLengths)) != GRIB_SUCCESS) - return err; - if ((err = grib_get_long_internal(gh, self->orderOfSpatialDifferencing, &orderOfSpatialDifferencing)) != GRIB_SUCCESS) - return err; - if ((err = grib_get_long_internal(gh, self->numberOfOctetsExtraDescriptors, &numberOfOctetsExtraDescriptors)) != GRIB_SUCCESS) - return err; - if ((err = grib_get_double_internal(gh, "missingValue", &missingValue)) != GRIB_SUCCESS) - return err; - - self->dirty = 0; - - sec_val = (long*)grib_context_malloc(a->context, (n_vals) * sizeof(long)); - if (!sec_val) return GRIB_OUT_OF_MEMORY; - memset(sec_val, 0, (n_vals) * sizeof(long)); // See SUP-718 - - buf_ref = buf + a->offset; - - ref_p = (numberOfGroupsOfDataValues * bits_per_value); - - if (orderOfSpatialDifferencing) - ref_p += (1 + orderOfSpatialDifferencing) * (numberOfOctetsExtraDescriptors * 8); - - buf_width = buf_ref + (ref_p / 8) + ((ref_p % 8) ? 1 : 0); - - width_p = (numberOfGroupsOfDataValues * numberOfBitsUsedForTheGroupWidths); - buf_length = buf_width + (width_p / 8) + ((width_p % 8) ? 1 : 0); - - length_p = (numberOfGroupsOfDataValues * numberOfBitsUsedForTheScaledGroupLengths); - buf_vals = buf_length + (length_p / 8) + ((length_p % 8) ? 1 : 0); - - length_p = 0; - ref_p = orderOfSpatialDifferencing ? (orderOfSpatialDifferencing + 1) * (numberOfOctetsExtraDescriptors * 8) : 0; - width_p = 0; - vals_p = 0; - vcount = 0; - - for (i = 0; i < numberOfGroupsOfDataValues; i++) { - group_ref_val = grib_decode_unsigned_long(buf_ref, &ref_p, bits_per_value); - nvals_per_group = grib_decode_unsigned_long(buf_length, &length_p, numberOfBitsUsedForTheScaledGroupLengths); - nbits_per_group_val = grib_decode_unsigned_long(buf_width, &width_p, numberOfBitsUsedForTheGroupWidths); - - nvals_per_group *= lengthIncrementForTheGroupLengths; - nvals_per_group += referenceForGroupLengths; - nbits_per_group_val += referenceForGroupWidths; - - if (i == numberOfGroupsOfDataValues - 1) - nvals_per_group = trueLengthOfLastGroup; - if (n_vals < vcount + nvals_per_group) { - return GRIB_DECODING_ERROR; - } - - // grib_decode_long_array(buf_vals, &vals_p, nbits_per_group_val, nvals_per_group, &sec_val[vcount]); - if (missingValueManagementUsed == 0) { - // No explicit missing values included within data values - for (j = 0; j < nvals_per_group; j++) { - DEBUG_ASSERT_ACCESS(sec_val, (long)(vcount + j), n_vals); - sec_val[vcount + j] = group_ref_val + grib_decode_unsigned_long(buf_vals, &vals_p, nbits_per_group_val); - // printf("sec_val[%ld]=%ld\n", vcount+j, sec_val[vcount+j]); - } - } - else if (missingValueManagementUsed == 1) { - // Primary missing values included within data values - long maxn = 0; // (1 << bits_per_value) - 1; - for (j = 0; j < nvals_per_group; j++) { - if (nbits_per_group_val == 0) { - maxn = (1 << bits_per_value) - 1; - if (group_ref_val == maxn) { - sec_val[vcount + j] = LONG_MAX; // missing value - } - else { - long temp = grib_decode_unsigned_long(buf_vals, &vals_p, nbits_per_group_val); - sec_val[vcount + j] = group_ref_val + temp; - } - } - else { - long temp = grib_decode_unsigned_long(buf_vals, &vals_p, nbits_per_group_val); - maxn = (1 << nbits_per_group_val) - 1; - if (temp == maxn) { - sec_val[vcount + j] = LONG_MAX; // missing value - } - else { - sec_val[vcount + j] = group_ref_val + temp; - } - } - } - } - else if (missingValueManagementUsed == 2) { - // Primary and secondary missing values included within data values - long maxn = (1 << bits_per_value) - 1; - long maxn2 = 0; // maxn - 1 - for (j = 0; j < nvals_per_group; j++) { - if (nbits_per_group_val == 0) { - maxn2 = maxn - 1; - if (group_ref_val == maxn || group_ref_val == maxn2) { - sec_val[vcount + j] = LONG_MAX; // missing value - } - else { - long temp = grib_decode_unsigned_long(buf_vals, &vals_p, nbits_per_group_val); - sec_val[vcount + j] = group_ref_val + temp; - } - } - else { - long temp = grib_decode_unsigned_long(buf_vals, &vals_p, nbits_per_group_val); - maxn = (1 << nbits_per_group_val) - 1; - maxn2 = maxn - 1; - if (temp == maxn || temp == maxn2) { - sec_val[vcount + j] = LONG_MAX; // missing value - } - else { - sec_val[vcount + j] = group_ref_val + temp; - } - } - } - } - - vcount += nvals_per_group; - } - - if (orderOfSpatialDifferencing) { - long bias = 0; - unsigned long extras[2] = {0, }; - ref_p = 0; - - // For Complex packing, order == 0 - // For Complex packing and spatial differencing, order == 1 or 2 (code table 5.6) - if (orderOfSpatialDifferencing != 1 && orderOfSpatialDifferencing != 2) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s unpacking: Unsupported order of spatial differencing %ld", cclass_name, orderOfSpatialDifferencing); - return GRIB_INTERNAL_ERROR; - } - - for (i = 0; i < orderOfSpatialDifferencing; i++) { - extras[i] = grib_decode_unsigned_long(buf_ref, &ref_p, numberOfOctetsExtraDescriptors * 8); - } - - bias = grib_decode_signed_longb(buf_ref, &ref_p, numberOfOctetsExtraDescriptors * 8); - - post_process(a->context, sec_val, n_vals, orderOfSpatialDifferencing, bias, extras); - // de_spatial_difference (a->context, sec_val, n_vals, orderOfSpatialDifferencing, bias); - } - - binary_s = (T)codes_power(binary_scale_factor, 2); - decimal_s = (T)codes_power(-decimal_scale_factor, 10); - - for (i = 0; i < n_vals; i++) { - if (sec_val[i] == LONG_MAX) { - val[i] = (T)missingValue; - } - else { - val[i] = (T)((((T)sec_val[i]) * binary_s) + reference_value) * decimal_s; - } - } - - grib_context_free(a->context, sec_val); - return err; -} - static int find_nbits(unsigned int i) { #if !defined __GNUC__ || __GNUC__ < 4 @@ -1164,9 +775,9 @@ static void merge_j(struct section* h, int ref_bits, int width_bits, int has_und } } -static int pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len) { - grib_accessor_data_g22order_packing* self = reinterpret_cast(a); + grib_accessor_data_g22order_packing_t* self = reinterpret_cast(a); grib_handle* gh = grib_handle_of_accessor(a); const char* cclass_name = a->cclass->name; @@ -1205,7 +816,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) if ((err = grib_get_long_internal(gh, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) return err; - optimize_scale_factor = 1; // TODO(masn): To be reviewed + optimize_scale_factor = 1; // TODO(masn): To be reviewed if ((err = grib_get_long_internal(gh, self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) return err; @@ -1235,7 +846,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) // orderOfSpatialDifferencing = 1 means "grid_complex_spatial_differencing" with orderOfSpatialDifferencing=1 // orderOfSpatialDifferencing = 2 means "grid_complex_spatial_differencing" with orderOfSpatialDifferencing=2 - use_bitmap = bitmap_present; + use_bitmap = bitmap_present; wanted_bits = bits_per_value; for (i = 0; i < *len; i++) { @@ -1247,7 +858,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) if (ndef == 0) { // Special case: All undefined values // Section 5 const char* packing_type = "grid_complex"; - size_t packing_type_len = strlen(packing_type); + size_t packing_type_len = strlen(packing_type); grib_set_string_internal(gh, "packingType", packing_type, &packing_type_len); if ((err = grib_set_double_internal(gh, self->reference_value, grib_ieee_to_long(0.0))) != GRIB_SUCCESS) @@ -1287,8 +898,8 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) if ((err = grib_set_long_internal(gh, "bitmapPresent", 0)) != GRIB_SUCCESS) return err; // Section 7 - constexpr size_t sec7_size = 3; - unsigned char empty_sec7[sec7_size] = {255, 0, 0}; // group reference, group width, group length + constexpr size_t sec7_size = 3; + unsigned char empty_sec7[sec7_size] = { 255, 0, 0 }; // group reference, group width, group length grib_buffer_replace(a, empty_sec7, sec7_size, 1, 1); return GRIB_SUCCESS; } @@ -1304,12 +915,12 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) dec_scale = -decimal_scale_factor; bin_scale = binary_scale_factor; - //compute bitmap section - //if (use_bitmap == 0 || ndef == ndata) { - // if ((err = grib_set_long_internal(gh, "bitmapPresent", 0)) != GRIB_SUCCESS) return err; - //} else { - // if ((err = grib_set_long_internal(gh, "bitmapPresent", 1)) != GRIB_SUCCESS) return err; - //} + // compute bitmap section + // if (use_bitmap == 0 || ndef == ndata) { + // if ((err = grib_set_long_internal(gh, "bitmapPresent", 0)) != GRIB_SUCCESS) return err; + // } else { + // if ((err = grib_set_long_internal(gh, "bitmapPresent", 1)) != GRIB_SUCCESS) return err; + // } nndata = use_bitmap ? ndef : ndata; has_undef = use_bitmap ? 0 : ndata != ndef; @@ -1478,7 +1089,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) #ifdef DEBUG grib_context_log(a->context, GRIB_LOG_DEBUG, "COMPLEX: 2: vmx %d vmn %d nbits %d", vmx, vmn, - find_nbits(vmx - vmn + has_undef)); + find_nbits(vmx - vmn + has_undef)); #endif for (i = 0; i < nndata; i++) { @@ -1499,7 +1110,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) list = reinterpret_cast(grib_context_malloc_clear(a->context, nstruct * sizeof(section))); if (list == NULL) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s packing: memory allocation of list failed",cclass_name); + grib_context_log(a->context, GRIB_LOG_ERROR, "%s packing: memory allocation of list failed", cclass_name); return GRIB_OUT_OF_MEMORY; } @@ -1575,10 +1186,10 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) LEN_SEC_MAX); j = size_all(start.tail, vbits, LEN_BITS + est_group_width, has_undef); #ifdef DEBUG - grib_context_log(a->context, GRIB_LOG_DEBUG, - "COMPLEX: complex inc segments size size0 %d size1 %d segsize %d " - "LEN_BITS=%d", - j0, j, LEN_SEC_MAX, LEN_BITS); + grib_context_log(a->context, GRIB_LOG_DEBUG, + "COMPLEX: complex inc segments size size0 %d size1 %d segsize %d " + "LEN_BITS=%d", + j0, j, LEN_SEC_MAX, LEN_BITS); #endif if (j > j0) { memcpy(list, list_backup, nstruct * sizeof(struct section)); @@ -1586,7 +1197,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) LEN_SEC_MAX = (LEN_SEC_MAX - 1) / 2; } } - grib_context_free(a->context,list_backup); + grib_context_free(a->context, list_backup); exchange(start.tail, v, has_undef, LEN_SEC_MAX); #ifdef DEBUG @@ -1637,7 +1248,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) itmp2 = reinterpret_cast(grib_context_malloc(a->context, ngroups * sizeof(int))); if (lens == NULL || widths == NULL || refs == NULL || itmp == NULL || itmp2 == NULL) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s packing: memory alloc of lens/widths/refs/itmp/itmp2 failed",cclass_name); + grib_context_log(a->context, GRIB_LOG_ERROR, "%s packing: memory alloc of lens/widths/refs/itmp/itmp2 failed", cclass_name); return GRIB_OUT_OF_MEMORY; } @@ -1694,7 +1305,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) } } - bits_per_value = find_nbits(grefmx + has_undef); + bits_per_value = find_nbits(grefmx + has_undef); numberOfBitsUsedForTheGroupWidths = find_nbits(gwidmx - gwidmn + has_undef); if ((err = grib_set_long_internal(gh, self->bits_per_value, bits_per_value)) != GRIB_SUCCESS) @@ -1850,17 +1461,268 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) return GRIB_SUCCESS; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) +template +static int unpack(grib_accessor* a, T* val, const size_t* len) +{ + static_assert(std::is_floating_point::value, "Requires floating points numbers"); + grib_accessor_data_g22order_packing_t* self = reinterpret_cast(a); + const char* cclass_name = a->cclass->name; + grib_handle* gh = grib_handle_of_accessor(a); + + size_t i = 0; + size_t j = 0; + long n_vals = 0; + long vcount = 0; + int err = GRIB_SUCCESS; + long* sec_val = NULL; + unsigned char* buf = reinterpret_cast(gh->buffer->data); + unsigned char* buf_ref = NULL; + unsigned char* buf_width = NULL; + unsigned char* buf_length = NULL; + unsigned char* buf_vals = NULL; + + long length_p = 0; + long ref_p = 0; + long width_p = 0; + long vals_p = 0; + long nvals_per_group = 0; + long nbits_per_group_val = 0; + long group_ref_val = 0; + + long bits_per_value = 0; + T binary_s = 0; + T decimal_s = 0; + double reference_value = 0; + + long binary_scale_factor; + long decimal_scale_factor; + long typeOfOriginalFieldValues; + long groupSplittingMethodUsed; + long missingValueManagementUsed; + long primaryMissingValueSubstitute; + long secondaryMissingValueSubstitute; + long numberOfGroupsOfDataValues; + long referenceForGroupWidths; + long numberOfBitsUsedForTheGroupWidths; + long referenceForGroupLengths; + long lengthIncrementForTheGroupLengths; + long trueLengthOfLastGroup; + long numberOfBitsUsedForTheScaledGroupLengths; + long orderOfSpatialDifferencing = 0; + long numberOfOctetsExtraDescriptors = 0; + double missingValue = 0; + + err = a->value_count(&n_vals); + if (err) + return err; + + if (*len < static_cast(n_vals)) + return GRIB_ARRAY_TOO_SMALL; + + if ((err = grib_get_long_internal(gh, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + return err; + if ((err = grib_get_double_internal(gh, self->reference_value, &reference_value)) != GRIB_SUCCESS) + return err; + if ((err = grib_get_long_internal(gh, self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) + return err; + if ((err = grib_get_long_internal(gh, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) + return err; + if ((err = grib_get_long_internal(gh, self->typeOfOriginalFieldValues, &typeOfOriginalFieldValues)) != GRIB_SUCCESS) + return err; + + // Don't call grib_get_long_internal to suppress error message being output + if ((err = grib_get_long(gh, self->groupSplittingMethodUsed, &groupSplittingMethodUsed)) != GRIB_SUCCESS) + return err; + + if ((err = grib_get_long_internal(gh, self->missingValueManagementUsed, &missingValueManagementUsed)) != GRIB_SUCCESS) + return err; + if ((err = grib_get_long_internal(gh, self->primaryMissingValueSubstitute, &primaryMissingValueSubstitute)) != GRIB_SUCCESS) + return err; + if ((err = grib_get_long_internal(gh, self->secondaryMissingValueSubstitute, &secondaryMissingValueSubstitute)) != GRIB_SUCCESS) + return err; + if ((err = grib_get_long_internal(gh, self->numberOfGroupsOfDataValues, &numberOfGroupsOfDataValues)) != GRIB_SUCCESS) + return err; + if ((err = grib_get_long_internal(gh, self->referenceForGroupWidths, &referenceForGroupWidths)) != GRIB_SUCCESS) + return err; + if ((err = grib_get_long_internal(gh, self->numberOfBitsUsedForTheGroupWidths, &numberOfBitsUsedForTheGroupWidths)) != GRIB_SUCCESS) + return err; + if ((err = grib_get_long_internal(gh, self->referenceForGroupLengths, &referenceForGroupLengths)) != GRIB_SUCCESS) + return err; + + if ((err = grib_get_long_internal(gh, self->lengthIncrementForTheGroupLengths, &lengthIncrementForTheGroupLengths)) != GRIB_SUCCESS) + return err; + if ((err = grib_get_long_internal(gh, self->trueLengthOfLastGroup, &trueLengthOfLastGroup)) != GRIB_SUCCESS) + return err; + if ((err = grib_get_long_internal(gh, self->numberOfBitsUsedForTheScaledGroupLengths, &numberOfBitsUsedForTheScaledGroupLengths)) != GRIB_SUCCESS) + return err; + if ((err = grib_get_long_internal(gh, self->orderOfSpatialDifferencing, &orderOfSpatialDifferencing)) != GRIB_SUCCESS) + return err; + if ((err = grib_get_long_internal(gh, self->numberOfOctetsExtraDescriptors, &numberOfOctetsExtraDescriptors)) != GRIB_SUCCESS) + return err; + if ((err = grib_get_double_internal(gh, "missingValue", &missingValue)) != GRIB_SUCCESS) + return err; + + self->dirty = 0; + + sec_val = (long*)grib_context_malloc(a->context, (n_vals) * sizeof(long)); + if (!sec_val) return GRIB_OUT_OF_MEMORY; + memset(sec_val, 0, (n_vals) * sizeof(long)); // See SUP-718 + + buf_ref = buf + a->offset; + + ref_p = (numberOfGroupsOfDataValues * bits_per_value); + + if (orderOfSpatialDifferencing) + ref_p += (1 + orderOfSpatialDifferencing) * (numberOfOctetsExtraDescriptors * 8); + + buf_width = buf_ref + (ref_p / 8) + ((ref_p % 8) ? 1 : 0); + + width_p = (numberOfGroupsOfDataValues * numberOfBitsUsedForTheGroupWidths); + buf_length = buf_width + (width_p / 8) + ((width_p % 8) ? 1 : 0); + + length_p = (numberOfGroupsOfDataValues * numberOfBitsUsedForTheScaledGroupLengths); + buf_vals = buf_length + (length_p / 8) + ((length_p % 8) ? 1 : 0); + + length_p = 0; + ref_p = orderOfSpatialDifferencing ? (orderOfSpatialDifferencing + 1) * (numberOfOctetsExtraDescriptors * 8) : 0; + width_p = 0; + vals_p = 0; + vcount = 0; + + for (i = 0; i < numberOfGroupsOfDataValues; i++) { + group_ref_val = grib_decode_unsigned_long(buf_ref, &ref_p, bits_per_value); + nvals_per_group = grib_decode_unsigned_long(buf_length, &length_p, numberOfBitsUsedForTheScaledGroupLengths); + nbits_per_group_val = grib_decode_unsigned_long(buf_width, &width_p, numberOfBitsUsedForTheGroupWidths); + + nvals_per_group *= lengthIncrementForTheGroupLengths; + nvals_per_group += referenceForGroupLengths; + nbits_per_group_val += referenceForGroupWidths; + + if (i == numberOfGroupsOfDataValues - 1) + nvals_per_group = trueLengthOfLastGroup; + if (n_vals < vcount + nvals_per_group) { + return GRIB_DECODING_ERROR; + } + + // grib_decode_long_array(buf_vals, &vals_p, nbits_per_group_val, nvals_per_group, &sec_val[vcount]); + if (missingValueManagementUsed == 0) { + // No explicit missing values included within data values + for (j = 0; j < nvals_per_group; j++) { + DEBUG_ASSERT_ACCESS(sec_val, (long)(vcount + j), n_vals); + sec_val[vcount + j] = group_ref_val + grib_decode_unsigned_long(buf_vals, &vals_p, nbits_per_group_val); + // printf("sec_val[%ld]=%ld\n", vcount+j, sec_val[vcount+j]); + } + } + else if (missingValueManagementUsed == 1) { + // Primary missing values included within data values + long maxn = 0; // (1 << bits_per_value) - 1; + for (j = 0; j < nvals_per_group; j++) { + if (nbits_per_group_val == 0) { + maxn = (1 << bits_per_value) - 1; + if (group_ref_val == maxn) { + sec_val[vcount + j] = LONG_MAX; // missing value + } + else { + long temp = grib_decode_unsigned_long(buf_vals, &vals_p, nbits_per_group_val); + sec_val[vcount + j] = group_ref_val + temp; + } + } + else { + long temp = grib_decode_unsigned_long(buf_vals, &vals_p, nbits_per_group_val); + maxn = (1 << nbits_per_group_val) - 1; + if (temp == maxn) { + sec_val[vcount + j] = LONG_MAX; // missing value + } + else { + sec_val[vcount + j] = group_ref_val + temp; + } + } + } + } + else if (missingValueManagementUsed == 2) { + // Primary and secondary missing values included within data values + long maxn = (1 << bits_per_value) - 1; + long maxn2 = 0; // maxn - 1 + for (j = 0; j < nvals_per_group; j++) { + if (nbits_per_group_val == 0) { + maxn2 = maxn - 1; + if (group_ref_val == maxn || group_ref_val == maxn2) { + sec_val[vcount + j] = LONG_MAX; // missing value + } + else { + long temp = grib_decode_unsigned_long(buf_vals, &vals_p, nbits_per_group_val); + sec_val[vcount + j] = group_ref_val + temp; + } + } + else { + long temp = grib_decode_unsigned_long(buf_vals, &vals_p, nbits_per_group_val); + maxn = (1 << nbits_per_group_val) - 1; + maxn2 = maxn - 1; + if (temp == maxn || temp == maxn2) { + sec_val[vcount + j] = LONG_MAX; // missing value + } + else { + sec_val[vcount + j] = group_ref_val + temp; + } + } + } + } + + vcount += nvals_per_group; + } + + if (orderOfSpatialDifferencing) { + long bias = 0; + unsigned long extras[2] = { + 0, + }; + ref_p = 0; + + // For Complex packing, order == 0 + // For Complex packing and spatial differencing, order == 1 or 2 (code table 5.6) + if (orderOfSpatialDifferencing != 1 && orderOfSpatialDifferencing != 2) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s unpacking: Unsupported order of spatial differencing %ld", cclass_name, orderOfSpatialDifferencing); + return GRIB_INTERNAL_ERROR; + } + + for (i = 0; i < orderOfSpatialDifferencing; i++) { + extras[i] = grib_decode_unsigned_long(buf_ref, &ref_p, numberOfOctetsExtraDescriptors * 8); + } + + bias = grib_decode_signed_longb(buf_ref, &ref_p, numberOfOctetsExtraDescriptors * 8); + + post_process(a->context, sec_val, n_vals, orderOfSpatialDifferencing, bias, extras); + // de_spatial_difference (a->context, sec_val, n_vals, orderOfSpatialDifferencing, bias); + } + + binary_s = (T)codes_power(binary_scale_factor, 2); + decimal_s = (T)codes_power(-decimal_scale_factor, 10); + + for (i = 0; i < n_vals; i++) { + if (sec_val[i] == LONG_MAX) { + val[i] = (T)missingValue; + } + else { + val[i] = (T)((((T)sec_val[i]) * binary_s) + reference_value) * decimal_s; + } + } + + grib_context_free(a->context, sec_val); + return err; +} + +int grib_accessor_class_data_g22order_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len) { return unpack(a, val, len); } -static int unpack_float(grib_accessor* a, float* val, size_t* len) +int grib_accessor_class_data_g22order_packing_t::unpack_float(grib_accessor* a, float* val, size_t* len) { return unpack(a, val, len); } -static int unpack_double_element(grib_accessor* a, size_t idx, double* val) +int grib_accessor_class_data_g22order_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) { size_t size = 0; double* values = NULL; @@ -1881,7 +1743,7 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) return GRIB_SUCCESS; } -static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) +int grib_accessor_class_data_g22order_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) { size_t size = 0, i = 0; double* values; @@ -1909,9 +1771,9 @@ static int unpack_double_element_set(grib_accessor* a, const size_t* index_array return GRIB_SUCCESS; } -static int value_count(grib_accessor* a, long* count) +int grib_accessor_class_data_g22order_packing_t::value_count(grib_accessor* a, long* count) { - grib_accessor_data_g22order_packing* self = reinterpret_cast(a); - *count = 0; + grib_accessor_data_g22order_packing_t* self = reinterpret_cast(a); + *count = 0; return grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfValues, count); } diff --git a/src/accessor/grib_accessor_class_data_g22order_packing.h b/src/accessor/grib_accessor_class_data_g22order_packing.h new file mode 100644 index 000000000..329823633 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_g22order_packing.h @@ -0,0 +1,54 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_values.h" +#include "grib_scaling.h" + +class grib_accessor_data_g22order_packing_t : public grib_accessor_values_t +{ +public: + /* Members defined in data_g22order_packing */ + const char* numberOfValues; + const char* bits_per_value; + const char* reference_value; + const char* binary_scale_factor; + const char* decimal_scale_factor; + const char* optimize_scale_factor; + const char* typeOfOriginalFieldValues; + const char* groupSplittingMethodUsed; + const char* missingValueManagementUsed; + const char* primaryMissingValueSubstitute; + const char* secondaryMissingValueSubstitute; + const char* numberOfGroupsOfDataValues; + const char* referenceForGroupWidths; + const char* numberOfBitsUsedForTheGroupWidths; + const char* referenceForGroupLengths; + const char* lengthIncrementForTheGroupLengths; + const char* trueLengthOfLastGroup; + const char* numberOfBitsUsedForTheScaledGroupLengths; + const char* orderOfSpatialDifferencing; + const char* numberOfOctetsExtraDescriptors; +}; + +class grib_accessor_class_data_g22order_packing_t : public grib_accessor_class_values_t +{ +public: + grib_accessor_class_data_g22order_packing_t(const char* name) : grib_accessor_class_values_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g22order_packing_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_float(grib_accessor*, float* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_double_element(grib_accessor*, size_t i, double* val) override; + int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override; +}; diff --git a/src/grib_accessor_class_data_g2bifourier_packing.cc b/src/accessor/grib_accessor_class_data_g2bifourier_packing.cc similarity index 79% rename from src/grib_accessor_class_data_g2bifourier_packing.cc rename to src/accessor/grib_accessor_class_data_g2bifourier_packing.cc index 86275d470..a014ef3c2 100644 --- a/src/grib_accessor_class_data_g2bifourier_packing.cc +++ b/src/accessor/grib_accessor_class_data_g2bifourier_packing.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,156 +9,19 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -/******************************** - * philippe.marguinaud@meteo.fr - *******************************/ - +#include "grib_accessor_class_data_g2bifourier_packing.h" #include "grib_scaling.h" -#include "grib_api_internal.h" -#include "grib_optimize_decimal_factor.h" -#include -#include - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_data_simple_packing - IMPLEMENTS = init - IMPLEMENTS = unpack_double - IMPLEMENTS = pack_double - IMPLEMENTS = value_count - MEMBERS= const char* ieee_floats - MEMBERS= const char* laplacianOperatorIsSet - MEMBERS= const char* laplacianOperator - MEMBERS= const char* biFourierTruncationType - MEMBERS= const char* sub_i - MEMBERS= const char* sub_j - MEMBERS= const char* bif_i - MEMBERS= const char* bif_j - MEMBERS= const char* biFourierSubTruncationType - MEMBERS= const char* biFourierDoNotPackAxes - MEMBERS= const char* biFourierMakeTemplate - MEMBERS= const char* totalNumberOfValuesInUnpackedSubset - MEMBERS=const char* numberOfValues - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_data_g2bifourier_packing -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in values */ - int carg; - const char* seclen; - const char* offsetdata; - const char* offsetsection; - int dirty; - /* Members defined in data_simple_packing */ - int edition; - const char* units_factor; - const char* units_bias; - const char* changing_precision; - const char* number_of_values; - const char* bits_per_value; - const char* reference_value; - const char* binary_scale_factor; - const char* decimal_scale_factor; - const char* optimize_scaling_factor; - /* Members defined in data_g2bifourier_packing */ - const char* ieee_floats; - const char* laplacianOperatorIsSet; - const char* laplacianOperator; - const char* biFourierTruncationType; - const char* sub_i; - const char* sub_j; - const char* bif_i; - const char* bif_j; - const char* biFourierSubTruncationType; - const char* biFourierDoNotPackAxes; - const char* biFourierMakeTemplate; - const char* totalNumberOfValuesInUnpackedSubset; - const char* numberOfValues; -} grib_accessor_data_g2bifourier_packing; - -extern grib_accessor_class* grib_accessor_class_data_simple_packing; - -static grib_accessor_class _grib_accessor_class_data_g2bifourier_packing = { - &grib_accessor_class_data_simple_packing, /* super */ - "data_g2bifourier_packing", /* name */ - sizeof(grib_accessor_data_g2bifourier_packing), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +grib_accessor_class_data_g2bifourier_packing_t _grib_accessor_class_data_g2bifourier_packing{"data_g2bifourier_packing"}; grib_accessor_class* grib_accessor_class_data_g2bifourier_packing = &_grib_accessor_class_data_g2bifourier_packing; -/* END_CLASS_IMP */ typedef unsigned long (*encode_float_proc)(double); typedef double (*decode_float_proc)(unsigned long); -static void init(grib_accessor* a, const long v, grib_arguments* args) -{ - grib_accessor_data_g2bifourier_packing* self = (grib_accessor_data_g2bifourier_packing*)a; +void grib_accessor_class_data_g2bifourier_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){ + grib_accessor_class_data_simple_packing_t::init(a, v, args); + grib_accessor_data_g2bifourier_packing_t* self = (grib_accessor_data_g2bifourier_packing_t*)a; grib_handle* gh = grib_handle_of_accessor(a); self->ieee_floats = grib_arguments_get_name(gh, args, self->carg++); @@ -178,9 +42,8 @@ static void init(grib_accessor* a, const long v, grib_arguments* args) self->dirty = 1; } -static int value_count(grib_accessor* a, long* numberOfValues) -{ - grib_accessor_data_g2bifourier_packing* self = (grib_accessor_data_g2bifourier_packing*)a; +int grib_accessor_class_data_g2bifourier_packing_t::value_count(grib_accessor* a, long* numberOfValues){ + grib_accessor_data_g2bifourier_packing_t* self = (grib_accessor_data_g2bifourier_packing_t*)a; grib_handle* gh = grib_handle_of_accessor(a); *numberOfValues = 0; @@ -496,7 +359,7 @@ static void free_bif_trunc(bif_trunc_t* bt, grib_accessor* a) static bif_trunc_t* new_bif_trunc(grib_accessor* a) { int ret; - grib_accessor_data_g2bifourier_packing* self = (grib_accessor_data_g2bifourier_packing*)a; + grib_accessor_data_g2bifourier_packing_t* self = (grib_accessor_data_g2bifourier_packing_t*)a; grib_handle* gh = grib_handle_of_accessor(a); bif_trunc_t* bt = (bif_trunc_t*)grib_context_malloc(gh->context, sizeof(bif_trunc_t)); @@ -607,9 +470,8 @@ cleanup: return NULL; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_data_g2bifourier_packing* self = (grib_accessor_data_g2bifourier_packing*)a; +int grib_accessor_class_data_g2bifourier_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + grib_accessor_data_g2bifourier_packing_t* self = (grib_accessor_data_g2bifourier_packing_t*)a; grib_handle* gh = grib_handle_of_accessor(a); unsigned char* buf = NULL; @@ -633,7 +495,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) int ret = GRIB_SUCCESS; int i, j, k; - if ((ret = grib_value_count(a, &count)) != GRIB_SUCCESS) + if ((ret = a->value_count(&count)) != GRIB_SUCCESS) goto cleanup; bt = new_bif_trunc(a); @@ -659,8 +521,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) self->dirty = 0; buf = (unsigned char*)gh->buffer->data; - buf += grib_byte_offset(a); - + buf += a->byte_offset(); s = codes_power(bt->binary_scale_factor, 2); d = codes_power(-bt->decimal_scale_factor, 10); @@ -670,7 +531,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) hres = buf; lres = buf; - packed_offset = grib_byte_offset(a) + bt->bytes * bt->n_vals_sub; + packed_offset = a->byte_offset() + bt->bytes * bt->n_vals_sub; lpos = 8 * (packed_offset - offsetdata); hpos = 0; @@ -706,9 +567,8 @@ cleanup: return ret; } -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_data_g2bifourier_packing* self = (grib_accessor_data_g2bifourier_packing*)a; +int grib_accessor_class_data_g2bifourier_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){ + grib_accessor_data_g2bifourier_packing_t* self = (grib_accessor_data_g2bifourier_packing_t*)a; grib_handle* gh = grib_handle_of_accessor(a); const char* cclass_name = a->cclass->name; diff --git a/src/accessor/grib_accessor_class_data_g2bifourier_packing.h b/src/accessor/grib_accessor_class_data_g2bifourier_packing.h new file mode 100644 index 000000000..2fd7378a5 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_g2bifourier_packing.h @@ -0,0 +1,43 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_data_simple_packing.h" + +class grib_accessor_data_g2bifourier_packing_t : public grib_accessor_data_simple_packing_t +{ +public: + /* Members defined in data_g2bifourier_packing */ + const char* ieee_floats; + const char* laplacianOperatorIsSet; + const char* laplacianOperator; + const char* biFourierTruncationType; + const char* sub_i; + const char* sub_j; + const char* bif_i; + const char* bif_j; + const char* biFourierSubTruncationType; + const char* biFourierDoNotPackAxes; + const char* biFourierMakeTemplate; + const char* totalNumberOfValuesInUnpackedSubset; + const char* numberOfValues; +}; + +class grib_accessor_class_data_g2bifourier_packing_t : public grib_accessor_class_data_simple_packing_t +{ +public: + grib_accessor_class_data_g2bifourier_packing_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g2bifourier_packing_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_data_g2complex_packing.cc b/src/accessor/grib_accessor_class_data_g2complex_packing.cc new file mode 100644 index 000000000..c1e5e7aad --- /dev/null +++ b/src/accessor/grib_accessor_class_data_g2complex_packing.cc @@ -0,0 +1,47 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_data_g2complex_packing.h" + +grib_accessor_class_data_g2complex_packing_t _grib_accessor_class_data_g2complex_packing{"data_g2complex_packing"}; +grib_accessor_class* grib_accessor_class_data_g2complex_packing = &_grib_accessor_class_data_g2complex_packing; + + +void grib_accessor_class_data_g2complex_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){ + grib_accessor_class_data_complex_packing_t::init(a, v, args); + grib_accessor_data_g2complex_packing_t* self = (grib_accessor_data_g2complex_packing_t*)a; + self->numberOfValues = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); + self->edition = 2; + + a->flags |= GRIB_ACCESSOR_FLAG_DATA; +} + +int grib_accessor_class_data_g2complex_packing_t::value_count(grib_accessor* a, long* numberOfValues){ + grib_accessor_data_g2complex_packing_t* self = (grib_accessor_data_g2complex_packing_t*)a; + *numberOfValues = 0; + + return grib_get_long(grib_handle_of_accessor(a), self->numberOfValues, numberOfValues); +} + +int grib_accessor_class_data_g2complex_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){ + grib_accessor_data_g2complex_packing_t* self = (grib_accessor_data_g2complex_packing_t*)a; + int ret = GRIB_SUCCESS; + + if (*len == 0) + return GRIB_NO_VALUES; + + ret = grib_accessor_class_data_complex_packing_t::pack_double(a, val, len); + + if (ret == GRIB_SUCCESS) + ret = grib_set_long_internal(grib_handle_of_accessor(a), self->numberOfValues, *len); + + return ret; +} diff --git a/src/accessor/grib_accessor_class_data_g2complex_packing.h b/src/accessor/grib_accessor_class_data_g2complex_packing.h new file mode 100644 index 000000000..49f33a711 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_g2complex_packing.h @@ -0,0 +1,30 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_data_complex_packing.h" + +class grib_accessor_data_g2complex_packing_t : public grib_accessor_data_complex_packing_t +{ +public: + /* Members defined in data_g2complex_packing */ + const char* numberOfValues; +}; + +class grib_accessor_class_data_g2complex_packing_t : public grib_accessor_class_data_complex_packing_t +{ +public: + grib_accessor_class_data_g2complex_packing_t(const char* name) : grib_accessor_class_data_complex_packing_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g2complex_packing_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_data_g2secondary_bitmap.cc b/src/accessor/grib_accessor_class_data_g2secondary_bitmap.cc new file mode 100644 index 000000000..a6fd7bd46 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_g2secondary_bitmap.cc @@ -0,0 +1,107 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_data_g2secondary_bitmap.h" + +grib_accessor_class_data_g2secondary_bitmap_t _grib_accessor_class_data_g2secondary_bitmap{"data_g2secondary_bitmap"}; +grib_accessor_class* grib_accessor_class_data_g2secondary_bitmap = &_grib_accessor_class_data_g2secondary_bitmap; + + +void grib_accessor_class_data_g2secondary_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args){ + grib_accessor_class_data_secondary_bitmap_t::init(a, v, args); + grib_accessor_data_g2secondary_bitmap_t* self = (grib_accessor_data_g2secondary_bitmap_t*)a; + self->number_of_values = grib_arguments_get_name(grib_handle_of_accessor(a), args, 4); +} + +int grib_accessor_class_data_g2secondary_bitmap_t::value_count(grib_accessor* a, long* len){ + grib_accessor_data_g2secondary_bitmap_t* self = (grib_accessor_data_g2secondary_bitmap_t*)a; + *len = 0; + return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, len); +} + +int grib_accessor_class_data_g2secondary_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len){ + grib_accessor_data_g2secondary_bitmap_t* self = (grib_accessor_data_g2secondary_bitmap_t*)a; + int err = 0; + + long primary_len = 0, secondary_len = 0; + double* primary_bitmap = NULL; + double* secondary_bitmap = NULL; + long i = 0, j = 0, k = 0, m = 0; + double missing_value = 0, present_value = 0; + long expand_by = 0; + + if (*len == 0) + return GRIB_NO_VALUES; + + if ((err = grib_get_long(grib_handle_of_accessor(a), self->expand_by, &expand_by)) != GRIB_SUCCESS) + return err; + if (expand_by <= 0) + return GRIB_ENCODING_ERROR; + + if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value, &missing_value)) != GRIB_SUCCESS) + return err; + + if (*len % expand_by) { + /*TODO: issue warning */ + return GRIB_ENCODING_ERROR; + } + + primary_len = *len / expand_by; + primary_bitmap = (double*)grib_context_malloc_clear(a->context, primary_len * sizeof(double)); + if (!primary_bitmap) + return GRIB_OUT_OF_MEMORY; + + secondary_len = *len; + secondary_bitmap = (double*)grib_context_malloc_clear(a->context, secondary_len * sizeof(double)); + if (!secondary_bitmap) { + grib_context_free(a->context, primary_bitmap); + return GRIB_OUT_OF_MEMORY; + } + + if (missing_value == 0) + present_value = 1; + else + present_value = 0; + + k = 0; + m = 0; + for (i = 0; i < *len; i += expand_by) { + int cnt = 0; + for (j = 0; j < expand_by; j++) + if (val[i + j] == missing_value) + cnt++; + + if (cnt == expand_by) /* all expand_by values are missing */ + primary_bitmap[k++] = missing_value; + else { + primary_bitmap[k++] = present_value; + for (j = 0; j < expand_by; j++) + secondary_bitmap[m++] = val[i + j]; + //on++; + } + } + + *len = k; + + Assert(k == primary_len); + + err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->primary_bitmap, primary_bitmap, k); + if (err == GRIB_SUCCESS) + err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->secondary_bitmap, secondary_bitmap, m); + + grib_context_free(a->context, primary_bitmap); + grib_context_free(a->context, secondary_bitmap); + + if (err == GRIB_SUCCESS) + err = grib_set_long_internal(grib_handle_of_accessor(a), self->number_of_values, *len * expand_by); + + return err; +} diff --git a/src/accessor/grib_accessor_class_data_g2secondary_bitmap.h b/src/accessor/grib_accessor_class_data_g2secondary_bitmap.h new file mode 100644 index 000000000..f981e1e6c --- /dev/null +++ b/src/accessor/grib_accessor_class_data_g2secondary_bitmap.h @@ -0,0 +1,30 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_data_secondary_bitmap.h" + +class grib_accessor_data_g2secondary_bitmap_t : public grib_accessor_data_secondary_bitmap_t +{ +public: + /* Members defined in data_g2secondary_bitmap */ + const char* number_of_values; +}; + +class grib_accessor_class_data_g2secondary_bitmap_t : public grib_accessor_class_data_secondary_bitmap_t +{ +public: + grib_accessor_class_data_g2secondary_bitmap_t(const char* name) : grib_accessor_class_data_secondary_bitmap_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g2secondary_bitmap_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_data_g2shsimple_packing.cc b/src/accessor/grib_accessor_class_data_g2shsimple_packing.cc new file mode 100644 index 000000000..7e2b5cd54 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_g2shsimple_packing.cc @@ -0,0 +1,92 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_data_g2shsimple_packing.h" + +grib_accessor_class_data_g2shsimple_packing_t _grib_accessor_class_data_g2shsimple_packing{"data_g2shsimple_packing"}; +grib_accessor_class* grib_accessor_class_data_g2shsimple_packing = &_grib_accessor_class_data_g2shsimple_packing; + + +void grib_accessor_class_data_g2shsimple_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){ + grib_accessor_class_data_shsimple_packing_t::init(a, v, args); + grib_accessor_data_g2shsimple_packing_t* self = (grib_accessor_data_g2shsimple_packing_t*)a; + + self->numberOfValues = grib_arguments_get_name(grib_handle_of_accessor(a), args, 2); + self->numberOfDataPoints = grib_arguments_get_name(grib_handle_of_accessor(a), args, 3); + a->flags |= GRIB_ACCESSOR_FLAG_DATA; +} + +int grib_accessor_class_data_g2shsimple_packing_t::value_count(grib_accessor* a, long* len){ + grib_accessor_data_g2shsimple_packing_t* self = (grib_accessor_data_g2shsimple_packing_t*)a; + *len = 0; + return grib_get_long(grib_handle_of_accessor(a), self->numberOfValues, len); +} + +int grib_accessor_class_data_g2shsimple_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + grib_accessor_data_g2shsimple_packing_t* self = (grib_accessor_data_g2shsimple_packing_t*)a; + int err = GRIB_SUCCESS; + + size_t n_vals = 0; + + if ((err = grib_get_size(grib_handle_of_accessor(a), self->coded_values, &n_vals)) != GRIB_SUCCESS) + return err; + + self->dirty = 0; + + /* n_vals = coded_n_vals+1; */ + + if (*len < n_vals) { + *len = n_vals; + return GRIB_ARRAY_TOO_SMALL; + } + + if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->real_part, val)) != GRIB_SUCCESS) + return err; + + val++; + + if ((err = grib_get_double_array_internal(grib_handle_of_accessor(a), self->coded_values, val, &n_vals)) != GRIB_SUCCESS) + return err; + + *len = n_vals; + + return err; +} + +int grib_accessor_class_data_g2shsimple_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){ + grib_accessor_data_g2shsimple_packing_t* self = (grib_accessor_data_g2shsimple_packing_t*)a; + int err = GRIB_SUCCESS; + + size_t coded_n_vals = *len - 1; + size_t n_vals = *len; + + if (*len == 0) + return GRIB_NO_VALUES; + + self->dirty = 1; + + if ((err = grib_set_double_internal(grib_handle_of_accessor(a), self->real_part, *val)) != GRIB_SUCCESS) + return err; + + val++; + + if ((err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->coded_values, val, coded_n_vals)) != GRIB_SUCCESS) + return err; + + *len = n_vals; + + if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->numberOfValues, (long)n_vals)) != GRIB_SUCCESS) + return err; + if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->numberOfDataPoints, (long)n_vals)) != GRIB_SUCCESS) + return err; + + return err; +} diff --git a/src/accessor/grib_accessor_class_data_g2shsimple_packing.h b/src/accessor/grib_accessor_class_data_g2shsimple_packing.h new file mode 100644 index 000000000..02da8345e --- /dev/null +++ b/src/accessor/grib_accessor_class_data_g2shsimple_packing.h @@ -0,0 +1,32 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_data_shsimple_packing.h" + +class grib_accessor_data_g2shsimple_packing_t : public grib_accessor_data_shsimple_packing_t +{ +public: + /* Members defined in data_g2shsimple_packing */ + const char* numberOfValues; + const char* numberOfDataPoints; +}; + +class grib_accessor_class_data_g2shsimple_packing_t : public grib_accessor_class_data_shsimple_packing_t +{ +public: + grib_accessor_class_data_g2shsimple_packing_t(const char* name) : grib_accessor_class_data_shsimple_packing_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g2shsimple_packing_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_data_g2simple_packing.cc b/src/accessor/grib_accessor_class_data_g2simple_packing.cc similarity index 51% rename from src/grib_accessor_class_data_g2simple_packing.cc rename to src/accessor/grib_accessor_class_data_g2simple_packing.cc index 56441fc96..08aa11699 100644 --- a/src/grib_accessor_class_data_g2simple_packing.cc +++ b/src/accessor/grib_accessor_class_data_g2simple_packing.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,135 +9,29 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_accessor_class_data_g2simple_packing.h" #include "grib_scaling.h" -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_data_simple_packing - IMPLEMENTS = init - IMPLEMENTS = pack_double - IMPLEMENTS = pack_bytes - IMPLEMENTS = value_count - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_bytes(grib_accessor*, const unsigned char*, size_t* len); -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_data_g2simple_packing -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in values */ - int carg; - const char* seclen; - const char* offsetdata; - const char* offsetsection; - int dirty; - /* Members defined in data_simple_packing */ - int edition; - const char* units_factor; - const char* units_bias; - const char* changing_precision; - const char* number_of_values; - const char* bits_per_value; - const char* reference_value; - const char* binary_scale_factor; - const char* decimal_scale_factor; - const char* optimize_scaling_factor; - /* Members defined in data_g2simple_packing */ -} grib_accessor_data_g2simple_packing; - -extern grib_accessor_class* grib_accessor_class_data_simple_packing; - -static grib_accessor_class _grib_accessor_class_data_g2simple_packing = { - &grib_accessor_class_data_simple_packing, /* super */ - "data_g2simple_packing", /* name */ - sizeof(grib_accessor_data_g2simple_packing), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - &pack_bytes, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +grib_accessor_class_data_g2simple_packing_t _grib_accessor_class_data_g2simple_packing{"data_g2simple_packing"}; grib_accessor_class* grib_accessor_class_data_g2simple_packing = &_grib_accessor_class_data_g2simple_packing; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long v, grib_arguments* args) -{ - grib_accessor_data_g2simple_packing* self = (grib_accessor_data_g2simple_packing*)a; +void grib_accessor_class_data_g2simple_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){ + grib_accessor_class_data_simple_packing_t::init(a, v, args); + grib_accessor_data_g2simple_packing_t* self = (grib_accessor_data_g2simple_packing_t*)a; a->flags |= GRIB_ACCESSOR_FLAG_DATA; self->edition = 2; } -static int value_count(grib_accessor* a, long* n_vals) -{ - grib_accessor_data_g2simple_packing* self = (grib_accessor_data_g2simple_packing*)a; +int grib_accessor_class_data_g2simple_packing_t::value_count(grib_accessor* a, long* n_vals){ + grib_accessor_data_g2simple_packing_t* self = (grib_accessor_data_g2simple_packing_t*)a; *n_vals = 0; return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, n_vals); } -static int pack_double(grib_accessor* a, const double* cval, size_t* len) -{ - grib_accessor_data_g2simple_packing* self = (grib_accessor_data_g2simple_packing*)a; - grib_accessor_class* super = *(a->cclass->super); +int grib_accessor_class_data_g2simple_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len){ + grib_accessor_data_g2simple_packing_t* self = (grib_accessor_data_g2simple_packing_t*)a; + //grib_accessor_class* super = *(a->cclass->super); size_t n_vals = *len; double reference_value = 0; long binary_scale_factor = 0; @@ -209,17 +104,7 @@ static int pack_double(grib_accessor* a, const double* cval, size_t* len) return grib_set_double_array(h, "values", val, *len); } - if (super != grib_accessor_class_data_g2simple_packing) { - /* Normal case: parent not same as me! */ - ret = super->pack_double(a, val, len); - } - else { - /* GRIB-364: simple packing with logarithm pre-processing */ - grib_accessor_class* super2 = NULL; - Assert(super->super); - super2 = *(super->super); - ret = super2->pack_double(a, val, len); - } + ret = grib_accessor_class_data_simple_packing_t::pack_double(a, cval, len); switch (ret) { case GRIB_CONSTANT_FIELD: grib_buffer_replace(a, NULL, 0, 1, 1); @@ -253,7 +138,7 @@ static int pack_double(grib_accessor* a, const double* cval, size_t* len) grib_encode_double_array(n_vals, val, bits_per_value, reference_value, decimal, divisor, encoded, &off); grib_context_log(a->context, GRIB_LOG_DEBUG, - "grib_accessor_data_g2simple_packing : pack_double : packing %s, %d values", a->name, n_vals); + "grib_accessor_data_g2simple_packing_t : pack_double : packing %s, %d values", a->name, n_vals); grib_buffer_replace(a, buf, buflen, 1, 1); @@ -262,8 +147,7 @@ static int pack_double(grib_accessor* a, const double* cval, size_t* len) return ret; } -static int pack_bytes(grib_accessor* a, const unsigned char* val, size_t* len) -{ +int grib_accessor_class_data_g2simple_packing_t::pack_bytes(grib_accessor* a, const unsigned char* val, size_t* len){ size_t length = *len; grib_buffer_replace(a, val, length, 1, 1); return GRIB_SUCCESS; diff --git a/src/accessor/grib_accessor_class_data_g2simple_packing.h b/src/accessor/grib_accessor_class_data_g2simple_packing.h new file mode 100644 index 000000000..a88cccac0 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_g2simple_packing.h @@ -0,0 +1,26 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_data_simple_packing.h" + +class grib_accessor_data_g2simple_packing_t : public grib_accessor_data_simple_packing_t {}; + +class grib_accessor_class_data_g2simple_packing_t : public grib_accessor_class_data_simple_packing_t +{ +public: + grib_accessor_class_data_g2simple_packing_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g2simple_packing_t{}; } + int pack_bytes(grib_accessor*, const unsigned char*, size_t* len) override; + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_data_g2simple_packing_with_preprocessing.cc b/src/accessor/grib_accessor_class_data_g2simple_packing_with_preprocessing.cc new file mode 100644 index 000000000..fc87df231 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_g2simple_packing_with_preprocessing.cc @@ -0,0 +1,175 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_data_g2simple_packing_with_preprocessing.h" +#define DIRECT 0 +#define INVERSE 1 + +grib_accessor_class_data_g2simple_packing_with_preprocessing_t _grib_accessor_class_data_g2simple_packing_with_preprocessing{ "data_g2simple_packing_with_preprocessing" }; +grib_accessor_class* grib_accessor_class_data_g2simple_packing_with_preprocessing = &_grib_accessor_class_data_g2simple_packing_with_preprocessing; + + +void grib_accessor_class_data_g2simple_packing_with_preprocessing_t::init(grib_accessor* a, const long v, grib_arguments* args) +{ + grib_accessor_class_data_g2simple_packing_t::init(a, v, args); + grib_accessor_data_g2simple_packing_with_preprocessing_t* self = (grib_accessor_data_g2simple_packing_with_preprocessing_t*)a; + self->pre_processing = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); + self->pre_processing_parameter = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); + a->flags |= GRIB_ACCESSOR_FLAG_DATA; +} + +int grib_accessor_class_data_g2simple_packing_with_preprocessing_t::value_count(grib_accessor* a, long* n_vals) +{ + grib_accessor_data_g2simple_packing_with_preprocessing_t* self = (grib_accessor_data_g2simple_packing_with_preprocessing_t*)a; + *n_vals = 0; + + return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, n_vals); +} + +static int pre_processing_func(double* values, long length, long pre_processing, + double* pre_processing_parameter, int mode) +{ + int i = 0, ret = 0; + double min = values[0]; + double next_min = values[0]; + Assert(length > 0); + + switch (pre_processing) { + /* NONE */ + case 0: + break; + /* LOGARITHM */ + case 1: + if (mode == DIRECT) { + for (i = 0; i < length; i++) { + if (values[i] < min) + min = values[i]; + if (values[i] > next_min) + next_min = values[i]; + } + for (i = 0; i < length; i++) { + if (values[i] > min && values[i] < next_min) + next_min = values[i]; + } + if (min > 0) { + *pre_processing_parameter = 0; + for (i = 0; i < length; i++) { + DEBUG_ASSERT(values[i] > 0); + values[i] = log(values[i]); + } + } + else { + double ppp = 0; + *pre_processing_parameter = next_min - 2 * min; + if (next_min == min) + return ret; + ppp = *pre_processing_parameter; + for (i = 0; i < length; i++) { + DEBUG_ASSERT((values[i] + ppp) > 0); + values[i] = log(values[i] + ppp); + } + } + } + else { + Assert(mode == INVERSE); + if (*pre_processing_parameter == 0) { + for (i = 0; i < length; i++) + values[i] = exp(values[i]); + } + else { + for (i = 0; i < length; i++) + values[i] = exp(values[i]) - *pre_processing_parameter; + } + } + break; + default: + ret = GRIB_NOT_IMPLEMENTED; + break; + } + + return ret; +} + +int grib_accessor_class_data_g2simple_packing_with_preprocessing_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ + grib_accessor_data_g2simple_packing_with_preprocessing_t* self = (grib_accessor_data_g2simple_packing_with_preprocessing_t*)a; + + size_t n_vals = 0; + long nn = 0; + int err = 0; + + long pre_processing; + double pre_processing_parameter; + + err = a->value_count(&nn); + n_vals = nn; + if (err) + return err; + + if (n_vals == 0) { + *len = 0; + return GRIB_SUCCESS; + } + + self->dirty = 0; + + if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->pre_processing, &pre_processing)) != GRIB_SUCCESS) { + return err; + } + + if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->pre_processing_parameter, &pre_processing_parameter)) != GRIB_SUCCESS) { + return err; + } + + err = grib_accessor_class_data_simple_packing_t::unpack_double(a, val, &n_vals); + if (err != GRIB_SUCCESS) + return err; + + err = pre_processing_func(val, n_vals, pre_processing, &pre_processing_parameter, INVERSE); + if (err != GRIB_SUCCESS) + return err; + + *len = (long)n_vals; + + return err; +} + +int grib_accessor_class_data_g2simple_packing_with_preprocessing_t::pack_double(grib_accessor* a, const double* val, size_t* len) +{ + grib_accessor_data_g2simple_packing_with_preprocessing_t* self = (grib_accessor_data_g2simple_packing_with_preprocessing_t*)a; + + size_t n_vals = *len; + int err = 0; + + long pre_processing = 0; + double pre_processing_parameter = 0; + + self->dirty = 1; + + if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->pre_processing, &pre_processing)) != GRIB_SUCCESS) + return err; + + err = pre_processing_func((double*)val, n_vals, pre_processing, &pre_processing_parameter, DIRECT); + if (err != GRIB_SUCCESS) + return err; + + err = grib_accessor_class_data_g2simple_packing_t::pack_double(a, val, len); + if (err != GRIB_SUCCESS) + return err; + + if ((err = grib_set_double_internal(grib_handle_of_accessor(a), self->pre_processing_parameter, pre_processing_parameter)) != GRIB_SUCCESS) + return err; + + if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->number_of_values, n_vals)) != GRIB_SUCCESS) + return err; + + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_data_g2simple_packing_with_preprocessing.h b/src/accessor/grib_accessor_class_data_g2simple_packing_with_preprocessing.h new file mode 100644 index 000000000..4e2437e8b --- /dev/null +++ b/src/accessor/grib_accessor_class_data_g2simple_packing_with_preprocessing.h @@ -0,0 +1,32 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_data_g2simple_packing.h" + +class grib_accessor_data_g2simple_packing_with_preprocessing_t : public grib_accessor_data_g2simple_packing_t +{ +public: + /* Members defined in data_g2simple_packing_with_preprocessing */ + const char* pre_processing; + const char* pre_processing_parameter; +}; + +class grib_accessor_class_data_g2simple_packing_with_preprocessing_t : public grib_accessor_class_data_g2simple_packing_t +{ +public: + grib_accessor_class_data_g2simple_packing_with_preprocessing_t(const char* name) : grib_accessor_class_data_g2simple_packing_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g2simple_packing_with_preprocessing_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_data_jpeg2000_packing.cc b/src/accessor/grib_accessor_class_data_jpeg2000_packing.cc similarity index 73% rename from src/grib_accessor_class_data_jpeg2000_packing.cc rename to src/accessor/grib_accessor_class_data_jpeg2000_packing.cc index a1a43b6f7..5ce5ae154 100644 --- a/src/grib_accessor_class_data_jpeg2000_packing.cc +++ b/src/accessor/grib_accessor_class_data_jpeg2000_packing.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,148 +9,21 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_scaling.h" -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_data_simple_packing - IMPLEMENTS = init - IMPLEMENTS = unpack_double - IMPLEMENTS = pack_double;unpack_float - IMPLEMENTS = unpack_double_element;unpack_double_element_set - IMPLEMENTS = value_count - MEMBERS=const char* type_of_compression_used - MEMBERS=const char* target_compression_ratio - MEMBERS=const char* ni - MEMBERS=const char* nj - MEMBERS=const char* list_defining_points - MEMBERS=const char* number_of_data_points - MEMBERS=const char* scanning_mode - MEMBERS=int jpeg_lib - MEMBERS=const char* dump_jpg - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_float(grib_accessor*, float* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); -static int unpack_double_element(grib_accessor*, size_t i, double* val); -static int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array); - -typedef struct grib_accessor_data_jpeg2000_packing -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in values */ - int carg; - const char* seclen; - const char* offsetdata; - const char* offsetsection; - int dirty; - /* Members defined in data_simple_packing */ - int edition; - const char* units_factor; - const char* units_bias; - const char* changing_precision; - const char* number_of_values; - const char* bits_per_value; - const char* reference_value; - const char* binary_scale_factor; - const char* decimal_scale_factor; - const char* optimize_scaling_factor; - /* Members defined in data_jpeg2000_packing */ - const char* type_of_compression_used; - const char* target_compression_ratio; - const char* ni; - const char* nj; - const char* list_defining_points; - const char* number_of_data_points; - const char* scanning_mode; - int jpeg_lib; - const char* dump_jpg; -} grib_accessor_data_jpeg2000_packing; - -extern grib_accessor_class* grib_accessor_class_data_simple_packing; - -static grib_accessor_class _grib_accessor_class_data_jpeg2000_packing = { - &grib_accessor_class_data_simple_packing, /* super */ - "data_jpeg2000_packing", /* name */ - sizeof(grib_accessor_data_jpeg2000_packing), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - &unpack_float, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - &unpack_double_element, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - &unpack_double_element_set, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_data_jpeg2000_packing.h" +grib_accessor_class_data_jpeg2000_packing_t _grib_accessor_class_data_jpeg2000_packing{"data_jpeg2000_packing"}; grib_accessor_class* grib_accessor_class_data_jpeg2000_packing = &_grib_accessor_class_data_jpeg2000_packing; -/* END_CLASS_IMP */ static int first = 1; #define JASPER_LIB 1 #define OPENJPEG_LIB 2 -static void init(grib_accessor* a, const long v, grib_arguments* args) -{ +void grib_accessor_class_data_jpeg2000_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){ + grib_accessor_class_data_simple_packing_t::init(a, v, args); const char* user_lib = NULL; - grib_accessor_data_jpeg2000_packing* self = (grib_accessor_data_jpeg2000_packing*)a; + grib_accessor_data_jpeg2000_packing_t* self = (grib_accessor_data_jpeg2000_packing_t*)a; grib_handle* hand = grib_handle_of_accessor(a); self->jpeg_lib = 0; @@ -204,9 +78,8 @@ static void init(grib_accessor* a, const long v, grib_arguments* args) } } -static int value_count(grib_accessor* a, long* n_vals) -{ - grib_accessor_data_jpeg2000_packing* self = (grib_accessor_data_jpeg2000_packing*)a; +int grib_accessor_class_data_jpeg2000_packing_t::value_count(grib_accessor* a, long* n_vals){ + grib_accessor_data_jpeg2000_packing_t* self = (grib_accessor_data_jpeg2000_packing_t*)a; *n_vals = 0; return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, n_vals); @@ -215,19 +88,16 @@ static int value_count(grib_accessor* a, long* n_vals) #define EXTRA_BUFFER_SIZE 10240 #if HAVE_JPEG -static int unpack_float(grib_accessor*, float* val, size_t* len) -{ +int grib_accessor_class_data_jpeg2000_packing_t::unpack_float(grib_accessor*, float* val, size_t* len){ return GRIB_NOT_IMPLEMENTED; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_data_jpeg2000_packing* self = (grib_accessor_data_jpeg2000_packing*)a; +int grib_accessor_class_data_jpeg2000_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + grib_accessor_data_jpeg2000_packing_t* self = (grib_accessor_data_jpeg2000_packing_t*)a; int err = GRIB_SUCCESS; size_t i = 0; - size_t buflen = grib_byte_count(a); - + size_t buflen = a->byte_count(); double bscale = 0; double dscale = 0; unsigned char* buf = NULL; @@ -242,8 +112,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) double units_bias = 0.0; n_vals = 0; - err = grib_value_count(a, &nn); - n_vals = nn; + err = a->value_count(&nn); n_vals = nn; if (err) return err; @@ -282,8 +151,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) } buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; - buf += grib_byte_offset(a); - + buf += a->byte_offset(); switch (self->jpeg_lib) { case OPENJPEG_LIB: if ((err = grib_openjpeg_decode(a->context, buf, &buflen, val, &n_vals)) != GRIB_SUCCESS) @@ -323,10 +191,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) return err; } -static int pack_double(grib_accessor* a, const double* cval, size_t* len) -{ - grib_accessor_data_jpeg2000_packing* self = (grib_accessor_data_jpeg2000_packing*)a; - grib_accessor_class* super = *(a->cclass->super); +int grib_accessor_class_data_jpeg2000_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len){ + grib_accessor_data_jpeg2000_packing_t* self = (grib_accessor_data_jpeg2000_packing_t*)a; size_t n_vals = *len; int err = 0; int i; @@ -383,7 +249,8 @@ static int pack_double(grib_accessor* a, const double* cval, size_t* len) for (i = 0; i < n_vals; i++) val[i] += units_bias; - ret = super->pack_double(a, val, len); + ret = grib_accessor_class_data_simple_packing_t::pack_double(a, val, len); + switch (ret) { case GRIB_CONSTANT_FIELD: grib_buffer_replace(a, NULL, 0, 1, 1); @@ -561,33 +428,28 @@ cleanup: } #else -static void print_error_feature_not_enabled(grib_context* c) -{ +static void print_error_feature_not_enabled(grib_context* c){ grib_context_log(c, GRIB_LOG_ERROR, "JPEG support not enabled. Please rebuild with -DENABLE_JPG=ON"); } -static int unpack_float(grib_accessor* a, float* val, size_t* len) -{ +int grib_accessor_class_data_jpeg2000_packing_t::unpack_float(grib_accessor* a, float* val, size_t* len){ print_error_feature_not_enabled(a->context); return GRIB_FUNCTIONALITY_NOT_ENABLED; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ +int grib_accessor_class_data_jpeg2000_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len){ print_error_feature_not_enabled(a->context); return GRIB_FUNCTIONALITY_NOT_ENABLED; } -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ +int grib_accessor_class_data_jpeg2000_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){ print_error_feature_not_enabled(a->context); return GRIB_FUNCTIONALITY_NOT_ENABLED; } #endif -static int unpack_double_element(grib_accessor* a, size_t idx, double* val) -{ - grib_accessor_data_jpeg2000_packing* self = (grib_accessor_data_jpeg2000_packing*)a; +int grib_accessor_class_data_jpeg2000_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val){ + grib_accessor_data_jpeg2000_packing_t* self = (grib_accessor_data_jpeg2000_packing_t*)a; grib_handle* hand = grib_handle_of_accessor(a); size_t size = 0; double* values = NULL; @@ -624,9 +486,8 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) return GRIB_SUCCESS; } -static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) -{ - grib_accessor_data_jpeg2000_packing* self = (grib_accessor_data_jpeg2000_packing*)a; +int grib_accessor_class_data_jpeg2000_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array){ + grib_accessor_data_jpeg2000_packing_t* self = (grib_accessor_data_jpeg2000_packing_t*)a; grib_handle* hand = grib_handle_of_accessor(a); size_t size = 0, i = 0; double* values = NULL; diff --git a/src/accessor/grib_accessor_class_data_jpeg2000_packing.h b/src/accessor/grib_accessor_class_data_jpeg2000_packing.h new file mode 100644 index 000000000..54dcc457c --- /dev/null +++ b/src/accessor/grib_accessor_class_data_jpeg2000_packing.h @@ -0,0 +1,42 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_data_simple_packing.h" + +class grib_accessor_data_jpeg2000_packing_t : public grib_accessor_data_simple_packing_t +{ +public: + /* Members defined in data_jpeg2000_packing */ + const char* type_of_compression_used; + const char* target_compression_ratio; + const char* ni; + const char* nj; + const char* list_defining_points; + const char* number_of_data_points; + const char* scanning_mode; + int jpeg_lib; + const char* dump_jpg; +}; + +class grib_accessor_class_data_jpeg2000_packing_t : public grib_accessor_class_data_simple_packing_t +{ +public: + grib_accessor_class_data_jpeg2000_packing_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_jpeg2000_packing_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_float(grib_accessor*, float* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_double_element(grib_accessor*, size_t i, double* val) override; + int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override; +}; diff --git a/src/grib_accessor_class_data_png_packing.cc b/src/accessor/grib_accessor_class_data_png_packing.cc similarity index 76% rename from src/grib_accessor_class_data_png_packing.cc rename to src/accessor/grib_accessor_class_data_png_packing.cc index e9747b19d..690070214 100644 --- a/src/grib_accessor_class_data_png_packing.cc +++ b/src/accessor/grib_accessor_class_data_png_packing.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,134 +9,18 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_accessor_class_data_png_packing.h" #include "grib_scaling.h" -#include "grib_api_internal.h" + #define PNG_ANYBITS -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_values - IMPLEMENTS = init - IMPLEMENTS = unpack_double - IMPLEMENTS = pack_double - IMPLEMENTS = value_count - IMPLEMENTS = unpack_double_element;unpack_double_element_set - MEMBERS=const char* number_of_values - MEMBERS=const char* reference_value - MEMBERS=const char* binary_scale_factor - MEMBERS=const char* decimal_scale_factor - MEMBERS=const char* bits_per_value - MEMBERS=const char* ni - MEMBERS=const char* nj - MEMBERS=const char* list_defining_points - MEMBERS=const char* number_of_data_points - MEMBERS=const char* scanning_mode - - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); -static int unpack_double_element(grib_accessor*, size_t i, double* val); -static int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array); - -typedef struct grib_accessor_data_png_packing -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in values */ - int carg; - const char* seclen; - const char* offsetdata; - const char* offsetsection; - int dirty; - /* Members defined in data_png_packing */ - const char* number_of_values; - const char* reference_value; - const char* binary_scale_factor; - const char* decimal_scale_factor; - const char* bits_per_value; - const char* ni; - const char* nj; - const char* list_defining_points; - const char* number_of_data_points; - const char* scanning_mode; -} grib_accessor_data_png_packing; - -extern grib_accessor_class* grib_accessor_class_values; - -static grib_accessor_class _grib_accessor_class_data_png_packing = { - &grib_accessor_class_values, /* super */ - "data_png_packing", /* name */ - sizeof(grib_accessor_data_png_packing), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - &unpack_double_element, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - &unpack_double_element_set, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - +grib_accessor_class_data_png_packing_t _grib_accessor_class_data_png_packing{"data_png_packing"}; grib_accessor_class* grib_accessor_class_data_png_packing = &_grib_accessor_class_data_png_packing; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long v, grib_arguments* args) -{ - grib_accessor_data_png_packing* self = (grib_accessor_data_png_packing*)a; +void grib_accessor_class_data_png_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){ + grib_accessor_class_values_t::init(a, v, args); + grib_accessor_data_png_packing_t* self = (grib_accessor_data_png_packing_t*)a; grib_handle* h = grib_handle_of_accessor(a); self->number_of_values = grib_arguments_get_name(h, args, self->carg++); @@ -151,9 +36,8 @@ static void init(grib_accessor* a, const long v, grib_arguments* args) a->flags |= GRIB_ACCESSOR_FLAG_DATA; } -static int value_count(grib_accessor* a, long* n_vals) -{ - grib_accessor_data_png_packing* self = (grib_accessor_data_png_packing*)a; +int grib_accessor_class_data_png_packing_t::value_count(grib_accessor* a, long* n_vals){ + grib_accessor_data_png_packing_t* self = (grib_accessor_data_png_packing_t*)a; *n_vals = 0; return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, n_vals); } @@ -196,14 +80,12 @@ static void png_flush_callback(png_structp png) /* Empty */ } -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_data_png_packing* self = (grib_accessor_data_png_packing*)a; +int grib_accessor_class_data_png_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + grib_accessor_data_png_packing_t* self = (grib_accessor_data_png_packing_t*)a; int err = GRIB_SUCCESS; int i, j; - size_t buflen = grib_byte_count(a); - + size_t buflen = a->byte_count(); double bscale = 0; double dscale = 0; unsigned char* buf = NULL; @@ -227,8 +109,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) self->dirty = 0; - err = grib_value_count(a, &nn); - n_vals = nn; + err = a->value_count(&nn); n_vals = nn; if (err) return err; if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) @@ -257,8 +138,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) } buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; - buf += grib_byte_offset(a); - + buf += a->byte_offset(); if (png_sig_cmp(buf, 0, 8) != 0) return GRIB_INVALID_MESSAGE; @@ -356,9 +236,8 @@ static bool is_constant(const double* values, size_t n_vals) return isConstant; } -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_data_png_packing* self = (grib_accessor_data_png_packing*)a; +int grib_accessor_class_data_png_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){ + grib_accessor_data_png_packing_t* self = (grib_accessor_data_png_packing_t*)a; const char* cclass_name = a->cclass->name; int err = GRIB_SUCCESS; @@ -545,7 +424,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) } /* buflen = n_vals*(bits_per_value/8); */ grib_context_log(a->context, GRIB_LOG_DEBUG, - "grib_accessor_data_png_packing : pack_double : packing %s, %d values", a->name, n_vals); + "grib_accessor_data_png_packing_t : pack_double : packing %s, %d values", a->name, n_vals); buf = (unsigned char*)grib_context_buffer_malloc_clear(a->context, buflen); if (!buf) { @@ -652,10 +531,9 @@ cleanup: return err; } -static int unpack_double_element(grib_accessor* a, size_t idx, double* val) -{ +int grib_accessor_class_data_png_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val){ /* The index idx relates to codedValues NOT values! */ - grib_accessor_data_png_packing* self = (grib_accessor_data_png_packing*)a; + grib_accessor_data_png_packing_t* self = (grib_accessor_data_png_packing_t*)a; grib_handle* hand = grib_handle_of_accessor(a); int err = 0; size_t size = 0; @@ -688,10 +566,9 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) return GRIB_SUCCESS; } -static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) -{ +int grib_accessor_class_data_png_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array){ /* The index idx relates to codedValues NOT values! */ - grib_accessor_data_png_packing* self = (grib_accessor_data_png_packing*)a; + grib_accessor_data_png_packing_t* self = (grib_accessor_data_png_packing_t*)a; grib_handle* hand = grib_handle_of_accessor(a); int err = 0; size_t size = 0, i = 0; @@ -735,29 +612,24 @@ static int unpack_double_element_set(grib_accessor* a, const size_t* index_array #else -static void print_error_feature_not_enabled(grib_context* c) -{ +static void print_error_feature_not_enabled(grib_context* c){ grib_context_log(c, GRIB_LOG_ERROR, "PNG support not enabled. Please rebuild with -DENABLE_PNG=ON"); } -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ +int grib_accessor_class_data_png_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len){ print_error_feature_not_enabled(a->context); return GRIB_FUNCTIONALITY_NOT_ENABLED; } -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ +int grib_accessor_class_data_png_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){ print_error_feature_not_enabled(a->context); return GRIB_FUNCTIONALITY_NOT_ENABLED; } -static int unpack_double_element(grib_accessor* a, size_t idx, double* val) -{ +int grib_accessor_class_data_png_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val){ print_error_feature_not_enabled(a->context); return GRIB_FUNCTIONALITY_NOT_ENABLED; } -static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) -{ +int grib_accessor_class_data_png_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array){ print_error_feature_not_enabled(a->context); return GRIB_FUNCTIONALITY_NOT_ENABLED; } diff --git a/src/accessor/grib_accessor_class_data_png_packing.h b/src/accessor/grib_accessor_class_data_png_packing.h new file mode 100644 index 000000000..841ed9d31 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_png_packing.h @@ -0,0 +1,41 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_values.h" + +class grib_accessor_data_png_packing_t : public grib_accessor_values_t +{ +public: + const char* number_of_values; + const char* reference_value; + const char* binary_scale_factor; + const char* decimal_scale_factor; + const char* bits_per_value; + const char* ni; + const char* nj; + const char* list_defining_points; + const char* number_of_data_points; + const char* scanning_mode; +}; + +class grib_accessor_class_data_png_packing_t : public grib_accessor_class_values_t +{ +public: + grib_accessor_class_data_png_packing_t(const char* name) : grib_accessor_class_values_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_png_packing_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_double_element(grib_accessor*, size_t i, double* val) override; + int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override; +}; diff --git a/src/accessor/grib_accessor_class_data_raw_packing.cc b/src/accessor/grib_accessor_class_data_raw_packing.cc new file mode 100644 index 000000000..499b46bec --- /dev/null +++ b/src/accessor/grib_accessor_class_data_raw_packing.cc @@ -0,0 +1,194 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_data_raw_packing.h" +#include "grib_ieeefloat.h" + +grib_accessor_class_data_raw_packing_t _grib_accessor_class_data_raw_packing{"data_raw_packing"}; +grib_accessor_class* grib_accessor_class_data_raw_packing = &_grib_accessor_class_data_raw_packing; + + +void grib_accessor_class_data_raw_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){ + grib_accessor_class_values_t::init(a, v, args); + grib_accessor_data_raw_packing_t* self = (grib_accessor_data_raw_packing_t*)a; + + self->number_of_values = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); + self->precision = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); + a->flags |= GRIB_ACCESSOR_FLAG_DATA; +} + +int grib_accessor_class_data_raw_packing_t::value_count(grib_accessor* a, long* n_vals){ + grib_accessor_data_raw_packing_t* self = (grib_accessor_data_raw_packing_t*)a; + *n_vals = 0; + return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, n_vals); +} + +int grib_accessor_class_data_raw_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + grib_accessor_data_raw_packing_t* self = (grib_accessor_data_raw_packing_t*)a; + unsigned char* buf = NULL; + int bytes = 0; + size_t nvals = 0; + long inlen = a->byte_count(); + long precision = 0; + + int code = GRIB_SUCCESS; + + if ((code = grib_get_long(grib_handle_of_accessor(a), self->precision, &precision)) != GRIB_SUCCESS) + return code; + + self->dirty = 0; + + buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; + buf += a->byte_offset(); + switch (precision) { + case 1: + bytes = 4; + break; + case 2: + bytes = 8; + break; + default: + return GRIB_NOT_IMPLEMENTED; + } + + nvals = inlen / bytes; + + if (*len < nvals) + return GRIB_ARRAY_TOO_SMALL; + + code = grib_ieee_decode_array(a->context, buf, nvals, bytes, val); + + *len = nvals; + + return code; +} + +int grib_accessor_class_data_raw_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){ + grib_accessor_data_raw_packing_t* self = (grib_accessor_data_raw_packing_t*)a; + + int bytes = 0; + unsigned char* buffer = NULL; + + long precision = 0; + + double* values = (double*)val; + size_t inlen = *len; + + /*int free_buffer = 0; + *int free_values = 0;*/ + + int code = GRIB_SUCCESS; + + size_t bufsize = 0; + + if (*len == 0) + return GRIB_NO_VALUES; + + if ((code = grib_get_long_internal(grib_handle_of_accessor(a), self->precision, &precision)) != GRIB_SUCCESS) + return code; + + self->dirty = 1; + + switch (precision) { + case 1: + bytes = 4; + break; + + case 2: + bytes = 8; + break; + + default: + code = GRIB_NOT_IMPLEMENTED; + goto clean_up; + } + + bufsize = bytes * inlen; + + buffer = (unsigned char*)grib_context_malloc(a->context, bufsize); + + if (!buffer) { + code = GRIB_OUT_OF_MEMORY; + goto clean_up; + } + + code = grib_ieee_encode_array(a->context, values, inlen, bytes, buffer); + +clean_up: + /*if (free_buffer) + * free(buffer); + * if (free_values) + * free(values); + */ + + grib_buffer_replace(a, buffer, bufsize, 1, 1); + + grib_context_buffer_free(a->context, buffer); + + if (code == GRIB_SUCCESS) { + code = grib_set_long(grib_handle_of_accessor(a), self->number_of_values, inlen); + if (code == GRIB_READ_ONLY) + code = 0; + } + + return code; +} + +int grib_accessor_class_data_raw_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val){ + int ret = 0; + grib_accessor_data_raw_packing_t* self = (grib_accessor_data_raw_packing_t*)a; + unsigned char* buf = NULL; + int bytes = 0; + size_t nvals = 0; + long inlen = a->byte_count(); long pos = 0; + long precision = 0; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->precision, &precision)) != GRIB_SUCCESS) + return ret; + + self->dirty = 0; + + buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; + buf += a->byte_offset(); + switch (precision) { + case 1: + bytes = 4; + break; + + case 2: + bytes = 8; + break; + + default: + return GRIB_NOT_IMPLEMENTED; + } + + pos = bytes * idx; + + Assert(pos <= inlen); + + nvals = 1; + buf += pos; + + ret = grib_ieee_decode_array(a->context, buf, nvals, bytes, val); + + return ret; +} + +int grib_accessor_class_data_raw_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array){ + int err = 0; + size_t i = 0; + for (i=0; inumber_of_values = grib_arguments_get_name(gh, args, self->carg++); self->bits_per_value = grib_arguments_get_name(gh, args, self->carg++); @@ -133,16 +29,14 @@ static void init(grib_accessor* a, const long v, grib_arguments* args) a->flags |= GRIB_ACCESSOR_FLAG_DATA; } -static int value_count(grib_accessor* a, long* number_of_values) -{ - grib_accessor_data_run_length_packing* self = (grib_accessor_data_run_length_packing*)a; +int grib_accessor_class_data_run_length_packing_t::value_count(grib_accessor* a, long* number_of_values){ + grib_accessor_data_run_length_packing_t* self = (grib_accessor_data_run_length_packing_t*)a; *number_of_values = 0; return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, number_of_values); } -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_data_run_length_packing* self = (grib_accessor_data_run_length_packing*)a; +int grib_accessor_class_data_run_length_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + grib_accessor_data_run_length_packing_t* self = (grib_accessor_data_run_length_packing_t*)a; grib_handle* gh = grib_handle_of_accessor(a); const char* cclass_name = a->cclass->name; int err = GRIB_SUCCESS; @@ -204,8 +98,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) } compressed_values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * number_of_compressed_values); buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; - offsetBeforeData = grib_byte_offset(a); - buf += offsetBeforeData; + offsetBeforeData = a->byte_offset(); buf += offsetBeforeData; pos = 0; grib_decode_long_array(buf, &pos, bits_per_value, number_of_compressed_values, compressed_values); j = 0; @@ -246,9 +139,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) return err; } -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_data_run_length_packing* self = (grib_accessor_data_run_length_packing*)a; +int grib_accessor_class_data_run_length_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){ + grib_accessor_data_run_length_packing_t* self = (grib_accessor_data_run_length_packing_t*)a; grib_handle* gh = grib_handle_of_accessor(a); const char* cclass_name = a->cclass->name; int err = GRIB_SUCCESS; diff --git a/src/accessor/grib_accessor_class_data_run_length_packing.h b/src/accessor/grib_accessor_class_data_run_length_packing.h new file mode 100644 index 000000000..5a69a7ba0 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_run_length_packing.h @@ -0,0 +1,36 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_values.h" + +class grib_accessor_data_run_length_packing_t : public grib_accessor_values_t +{ +public: + /* Members defined in data_run_length_packing */ + const char* number_of_values; + const char* bits_per_value; + const char* max_level_value; + const char* number_of_level_values; + const char* decimal_scale_factor; + const char* level_values; +}; + +class grib_accessor_class_data_run_length_packing_t : public grib_accessor_class_values_t +{ +public: + grib_accessor_class_data_run_length_packing_t(const char* name) : grib_accessor_class_values_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_run_length_packing_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_data_secondary_bitmap.cc b/src/accessor/grib_accessor_class_data_secondary_bitmap.cc new file mode 100644 index 000000000..f79098f84 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_secondary_bitmap.cc @@ -0,0 +1,118 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_data_secondary_bitmap.h" + +grib_accessor_class_data_secondary_bitmap_t _grib_accessor_class_data_secondary_bitmap{"data_secondary_bitmap"}; +grib_accessor_class* grib_accessor_class_data_secondary_bitmap = &_grib_accessor_class_data_secondary_bitmap; + + +void grib_accessor_class_data_secondary_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args){ + grib_accessor_class_gen_t::init(a, v, args); + grib_accessor_data_secondary_bitmap_t* self = (grib_accessor_data_secondary_bitmap_t*)a; + self->primary_bitmap = grib_arguments_get_name(grib_handle_of_accessor(a), args, 0); + self->secondary_bitmap = grib_arguments_get_name(grib_handle_of_accessor(a), args, 1); + self->missing_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, 2); + self->expand_by = grib_arguments_get_name(grib_handle_of_accessor(a), args, 3); + + a->length = 0; +} + +void grib_accessor_class_data_secondary_bitmap_t::dump(grib_accessor* a, grib_dumper* dumper){ + grib_dump_values(dumper, a); +} + +int grib_accessor_class_data_secondary_bitmap_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + grib_accessor_data_secondary_bitmap_t* self = (grib_accessor_data_secondary_bitmap_t*)a; + + size_t i = 0; + size_t j = 0; + size_t k = 0; + size_t m = 0; + size_t n_vals = 0; + long nn = 0; + long expand_by = 0; + int err = 0; + size_t primary_len; + size_t secondary_len; + double* primary_vals; + double* secondary_vals; + err = a->value_count(&nn); n_vals = nn; + if (err) + return err; + + if (*len < n_vals) { + *len = n_vals; + return GRIB_ARRAY_TOO_SMALL; + } + + if ((err = grib_get_long(grib_handle_of_accessor(a), self->expand_by, &expand_by)) != GRIB_SUCCESS) + return err; + + if ((err = grib_get_size(grib_handle_of_accessor(a), self->primary_bitmap, &primary_len)) != GRIB_SUCCESS) + return err; + + if ((err = grib_get_size(grib_handle_of_accessor(a), self->secondary_bitmap, &secondary_len)) != GRIB_SUCCESS) + return err; + + primary_vals = (double*)grib_context_malloc(a->context, primary_len * sizeof(double)); + if (!primary_vals) + return GRIB_OUT_OF_MEMORY; + + secondary_vals = (double*)grib_context_malloc(a->context, secondary_len * sizeof(double)); + if (!secondary_vals) { + grib_context_free(a->context, primary_vals); + return GRIB_OUT_OF_MEMORY; + } + + if ((err = grib_get_double_array_internal(grib_handle_of_accessor(a), self->primary_bitmap, primary_vals, &primary_len)) != GRIB_SUCCESS) { + grib_context_free(a->context, secondary_vals); + grib_context_free(a->context, primary_vals); + return err; + } + + if ((err = grib_get_double_array_internal(grib_handle_of_accessor(a), self->secondary_bitmap, secondary_vals, &secondary_len)) != GRIB_SUCCESS) { + grib_context_free(a->context, secondary_vals); + grib_context_free(a->context, primary_vals); + return err; + } + + k = 0; + m = 0; + for (i = 0; i < primary_len; i++) { + /* if(primary_vals[i]) f++; */ + if (primary_vals[i]) { + for (j = 0; j < expand_by; j++) + val[k++] = secondary_vals[m++]; + } + else { + for (j = 0; j < expand_by; j++) + val[k++] = 0; + } + } + + Assert(k <= *len); + Assert(m <= secondary_len); + + /*printf("FOOBAR %d %d %ld %d\n",f,primary_len,expand_by,n_vals);*/ + + *len = n_vals; + + grib_context_free(a->context, primary_vals); + grib_context_free(a->context, secondary_vals); + return err; +} + +int grib_accessor_class_data_secondary_bitmap_t::get_native_type(grib_accessor* a){ + // grib_accessor_data_secondary_bitmap_t* self = (grib_accessor_data_secondary_bitmap_t*)a; + //return grib_accessor_get_native_type(grib_find_accessor(grib_handle_of_accessor(a),self->coded_values)); + return GRIB_TYPE_DOUBLE; +} diff --git a/src/accessor/grib_accessor_class_data_secondary_bitmap.h b/src/accessor/grib_accessor_class_data_secondary_bitmap.h new file mode 100644 index 000000000..a24772be4 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_secondary_bitmap.h @@ -0,0 +1,34 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_data_secondary_bitmap_t : public grib_accessor_gen_t +{ +public: + /* Members defined in data_secondary_bitmap */ + const char* primary_bitmap; + const char* secondary_bitmap; + const char* missing_value; + const char* expand_by; +}; + +class grib_accessor_class_data_secondary_bitmap_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_data_secondary_bitmap_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_secondary_bitmap_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_data_sh_packed.cc b/src/accessor/grib_accessor_class_data_sh_packed.cc similarity index 63% rename from src/grib_accessor_class_data_sh_packed.cc rename to src/accessor/grib_accessor_class_data_sh_packed.cc index 25687d262..80bc7648f 100644 --- a/src/grib_accessor_class_data_sh_packed.cc +++ b/src/accessor/grib_accessor_class_data_sh_packed.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,142 +9,19 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_accessor_class_data_sh_packed.h" #include "grib_scaling.h" -#include "grib_api_internal.h" -#include -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_data_simple_packing - IMPLEMENTS = unpack_double - IMPLEMENTS = value_count - IMPLEMENTS = init - MEMBERS= const char* GRIBEX_sh_bug_present - MEMBERS= const char* ieee_floats - MEMBERS= const char* laplacianOperatorIsSet - MEMBERS= const char* laplacianOperator - MEMBERS= const char* sub_j - MEMBERS= const char* sub_k - MEMBERS= const char* sub_m - MEMBERS= const char* pen_j - MEMBERS= const char* pen_k - MEMBERS= const char* pen_m - END_CLASS_DEF - - */ - - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_data_sh_packed -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in values */ - int carg; - const char* seclen; - const char* offsetdata; - const char* offsetsection; - int dirty; - /* Members defined in data_simple_packing */ - int edition; - const char* units_factor; - const char* units_bias; - const char* changing_precision; - const char* number_of_values; - const char* bits_per_value; - const char* reference_value; - const char* binary_scale_factor; - const char* decimal_scale_factor; - const char* optimize_scaling_factor; - /* Members defined in data_sh_packed */ - const char* GRIBEX_sh_bug_present; - const char* ieee_floats; - const char* laplacianOperatorIsSet; - const char* laplacianOperator; - const char* sub_j; - const char* sub_k; - const char* sub_m; - const char* pen_j; - const char* pen_k; - const char* pen_m; -} grib_accessor_data_sh_packed; - -extern grib_accessor_class* grib_accessor_class_data_simple_packing; - -static grib_accessor_class _grib_accessor_class_data_sh_packed = { - &grib_accessor_class_data_simple_packing, /* super */ - "data_sh_packed", /* name */ - sizeof(grib_accessor_data_sh_packed), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +grib_accessor_class_data_sh_packed_t _grib_accessor_class_data_sh_packed{"data_sh_packed"}; grib_accessor_class* grib_accessor_class_data_sh_packed = &_grib_accessor_class_data_sh_packed; -/* END_CLASS_IMP */ typedef unsigned long (*encode_float_proc)(double); typedef double (*decode_float_proc)(unsigned long); -static void init(grib_accessor* a, const long v, grib_arguments* args) -{ - grib_accessor_data_sh_packed* self = (grib_accessor_data_sh_packed*)a; +void grib_accessor_class_data_sh_packed_t::init(grib_accessor* a, const long v, grib_arguments* args){ + grib_accessor_class_data_simple_packing_t::init(a, v, args); + grib_accessor_data_sh_packed_t* self = (grib_accessor_data_sh_packed_t*)a; grib_handle* hand = grib_handle_of_accessor(a); self->GRIBEX_sh_bug_present = grib_arguments_get_name(hand, args, self->carg++); @@ -161,9 +39,8 @@ static void init(grib_accessor* a, const long v, grib_arguments* args) a->length = 0; } -static int value_count(grib_accessor* a, long* count) -{ - grib_accessor_data_sh_packed* self = (grib_accessor_data_sh_packed*)a; +int grib_accessor_class_data_sh_packed_t::value_count(grib_accessor* a, long* count){ + grib_accessor_data_sh_packed_t* self = (grib_accessor_data_sh_packed_t*)a; grib_handle* hand = grib_handle_of_accessor(a); int ret = 0; const char* cclass_name = a->cclass->name; @@ -198,9 +75,8 @@ static int value_count(grib_accessor* a, long* count) return ret; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_data_sh_packed* self = (grib_accessor_data_sh_packed*)a; +int grib_accessor_class_data_sh_packed_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + grib_accessor_data_sh_packed_t* self = (grib_accessor_data_sh_packed_t*)a; size_t i = 0; int ret = GRIB_SUCCESS; @@ -234,8 +110,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) decode_float_proc decode_float = NULL; n_vals = 0; - err = grib_value_count(a, &n_vals); - if (err) + err = a->value_count(&n_vals); if (err) return err; if (*len < n_vals) { diff --git a/src/accessor/grib_accessor_class_data_sh_packed.h b/src/accessor/grib_accessor_class_data_sh_packed.h new file mode 100644 index 000000000..bbe3caafe --- /dev/null +++ b/src/accessor/grib_accessor_class_data_sh_packed.h @@ -0,0 +1,39 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_data_simple_packing.h" + +class grib_accessor_data_sh_packed_t : public grib_accessor_data_simple_packing_t +{ +public: + /* Members defined in data_sh_packed */ + const char* GRIBEX_sh_bug_present; + const char* ieee_floats; + const char* laplacianOperatorIsSet; + const char* laplacianOperator; + const char* sub_j; + const char* sub_k; + const char* sub_m; + const char* pen_j; + const char* pen_k; + const char* pen_m; +}; + +class grib_accessor_class_data_sh_packed_t : public grib_accessor_class_data_simple_packing_t +{ +public: + grib_accessor_class_data_sh_packed_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_sh_packed_t{}; } + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_data_sh_unpacked.cc b/src/accessor/grib_accessor_class_data_sh_unpacked.cc similarity index 61% rename from src/grib_accessor_class_data_sh_unpacked.cc rename to src/accessor/grib_accessor_class_data_sh_unpacked.cc index 394793612..efa738c65 100644 --- a/src/grib_accessor_class_data_sh_unpacked.cc +++ b/src/accessor/grib_accessor_class_data_sh_unpacked.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,142 +9,19 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_accessor_class_data_sh_unpacked.h" #include "grib_scaling.h" -#include "grib_api_internal.h" -#include -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_data_simple_packing - IMPLEMENTS = unpack_double - IMPLEMENTS = value_count - IMPLEMENTS = init - MEMBERS= const char* GRIBEX_sh_bug_present - MEMBERS= const char* ieee_floats - MEMBERS= const char* laplacianOperatorIsSet - MEMBERS= const char* laplacianOperator - MEMBERS= const char* sub_j - MEMBERS= const char* sub_k - MEMBERS= const char* sub_m - MEMBERS= const char* pen_j - MEMBERS= const char* pen_k - MEMBERS= const char* pen_m - END_CLASS_DEF - - */ - - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_data_sh_unpacked -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in values */ - int carg; - const char* seclen; - const char* offsetdata; - const char* offsetsection; - int dirty; - /* Members defined in data_simple_packing */ - int edition; - const char* units_factor; - const char* units_bias; - const char* changing_precision; - const char* number_of_values; - const char* bits_per_value; - const char* reference_value; - const char* binary_scale_factor; - const char* decimal_scale_factor; - const char* optimize_scaling_factor; - /* Members defined in data_sh_unpacked */ - const char* GRIBEX_sh_bug_present; - const char* ieee_floats; - const char* laplacianOperatorIsSet; - const char* laplacianOperator; - const char* sub_j; - const char* sub_k; - const char* sub_m; - const char* pen_j; - const char* pen_k; - const char* pen_m; -} grib_accessor_data_sh_unpacked; - -extern grib_accessor_class* grib_accessor_class_data_simple_packing; - -static grib_accessor_class _grib_accessor_class_data_sh_unpacked = { - &grib_accessor_class_data_simple_packing, /* super */ - "data_sh_unpacked", /* name */ - sizeof(grib_accessor_data_sh_unpacked), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +grib_accessor_class_data_sh_unpacked_t _grib_accessor_class_data_sh_unpacked{"data_sh_unpacked"}; grib_accessor_class* grib_accessor_class_data_sh_unpacked = &_grib_accessor_class_data_sh_unpacked; -/* END_CLASS_IMP */ typedef unsigned long (*encode_float_proc)(double); typedef double (*decode_float_proc)(unsigned long); -static void init(grib_accessor* a, const long v, grib_arguments* args) -{ - grib_accessor_data_sh_unpacked* self = (grib_accessor_data_sh_unpacked*)a; +void grib_accessor_class_data_sh_unpacked_t::init(grib_accessor* a, const long v, grib_arguments* args){ + grib_accessor_class_data_simple_packing_t::init(a, v, args); + grib_accessor_data_sh_unpacked_t* self = (grib_accessor_data_sh_unpacked_t*)a; grib_handle* hand = grib_handle_of_accessor(a); self->GRIBEX_sh_bug_present = grib_arguments_get_name(hand, args, self->carg++); @@ -161,9 +39,8 @@ static void init(grib_accessor* a, const long v, grib_arguments* args) a->length = 0; } -static int value_count(grib_accessor* a, long* count) -{ - grib_accessor_data_sh_unpacked* self = (grib_accessor_data_sh_unpacked*)a; +int grib_accessor_class_data_sh_unpacked_t::value_count(grib_accessor* a, long* count){ + grib_accessor_data_sh_unpacked_t* self = (grib_accessor_data_sh_unpacked_t*)a; int ret = 0; long sub_j = 0; @@ -185,9 +62,8 @@ static int value_count(grib_accessor* a, long* count) return ret; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_data_sh_unpacked* self = (grib_accessor_data_sh_unpacked*)a; +int grib_accessor_class_data_sh_unpacked_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + grib_accessor_data_sh_unpacked_t* self = (grib_accessor_data_sh_unpacked_t*)a; size_t i = 0; int ret = GRIB_SUCCESS; @@ -234,8 +110,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) decode_float_proc decode_float = NULL; n_vals = 0; - err = grib_value_count(a, &n_vals); - if (err) + err = a->value_count(&n_vals); if (err) return err; if (*len < n_vals) { diff --git a/src/accessor/grib_accessor_class_data_sh_unpacked.h b/src/accessor/grib_accessor_class_data_sh_unpacked.h new file mode 100644 index 000000000..7907b8c68 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_sh_unpacked.h @@ -0,0 +1,39 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_data_simple_packing.h" + +class grib_accessor_data_sh_unpacked_t : public grib_accessor_data_simple_packing_t +{ +public: + /* Members defined in data_sh_unpacked */ + const char* GRIBEX_sh_bug_present; + const char* ieee_floats; + const char* laplacianOperatorIsSet; + const char* laplacianOperator; + const char* sub_j; + const char* sub_k; + const char* sub_m; + const char* pen_j; + const char* pen_k; + const char* pen_m; +}; + +class grib_accessor_class_data_sh_unpacked_t : public grib_accessor_class_data_simple_packing_t +{ +public: + grib_accessor_class_data_sh_unpacked_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_sh_unpacked_t{}; } + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_data_shsimple_packing.cc b/src/accessor/grib_accessor_class_data_shsimple_packing.cc new file mode 100644 index 000000000..0de921d06 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_shsimple_packing.cc @@ -0,0 +1,60 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_data_shsimple_packing.h" + +grib_accessor_class_data_shsimple_packing_t _grib_accessor_class_data_shsimple_packing{"data_shsimple_packing"}; +grib_accessor_class* grib_accessor_class_data_shsimple_packing = &_grib_accessor_class_data_shsimple_packing; + + +void grib_accessor_class_data_shsimple_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){ + grib_accessor_class_gen_t::init(a, v, args); + grib_accessor_data_shsimple_packing_t* self = (grib_accessor_data_shsimple_packing_t*)a; + + self->coded_values = grib_arguments_get_name(grib_handle_of_accessor(a), args, 0); + self->real_part = grib_arguments_get_name(grib_handle_of_accessor(a), args, 1); + a->flags |= GRIB_ACCESSOR_FLAG_DATA; + + a->length = 0; +} + +void grib_accessor_class_data_shsimple_packing_t::dump(grib_accessor* a, grib_dumper* dumper){ + grib_dump_values(dumper, a); +} + +int grib_accessor_class_data_shsimple_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){ + grib_accessor_data_shsimple_packing_t* self = (grib_accessor_data_shsimple_packing_t*)a; + int err = GRIB_SUCCESS; + + size_t coded_n_vals = *len - 1; + size_t n_vals = *len; + + self->dirty = 1; + + if (*len == 0) + return GRIB_NO_VALUES; + + if ((err = grib_set_double_internal(grib_handle_of_accessor(a), self->real_part, *val)) != GRIB_SUCCESS) + return err; + + val++; + + if ((err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->coded_values, val, coded_n_vals)) != GRIB_SUCCESS) + return err; + + *len = n_vals; + + return err; +} + +int grib_accessor_class_data_shsimple_packing_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_DOUBLE; +} diff --git a/src/accessor/grib_accessor_class_data_shsimple_packing.h b/src/accessor/grib_accessor_class_data_shsimple_packing.h new file mode 100644 index 000000000..7b1620141 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_shsimple_packing.h @@ -0,0 +1,33 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_data_shsimple_packing_t : public grib_accessor_gen_t +{ +public: + /* Members defined in data_shsimple_packing */ + const char* coded_values; + const char* real_part; + int dirty; +}; + +class grib_accessor_class_data_shsimple_packing_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_data_shsimple_packing_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_shsimple_packing_t{}; } + int get_native_type(grib_accessor*) override; + int pack_double(grib_accessor*, const double* val, size_t* len) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_data_simple_packing.cc b/src/accessor/grib_accessor_class_data_simple_packing.cc similarity index 71% rename from src/grib_accessor_class_data_simple_packing.cc rename to src/accessor/grib_accessor_class_data_simple_packing.cc index e78bda53c..591e89526 100644 --- a/src/grib_accessor_class_data_simple_packing.cc +++ b/src/accessor/grib_accessor_class_data_simple_packing.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,148 +9,30 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_scaling.h" -#include "grib_bits_any_endian_simple.h" +#include "grib_accessor_class_data_simple_packing.h" #include "grib_optimize_decimal_factor.h" +#include "grib_bits_any_endian_simple.h" #include #include -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_values - IMPLEMENTS = init - IMPLEMENTS = unpack_double;unpack_float - IMPLEMENTS = unpack_double_element;unpack_double_element_set - IMPLEMENTS = unpack_double_subarray - IMPLEMENTS = pack_double - IMPLEMENTS = value_count - MEMBERS=int edition - MEMBERS=const char* units_factor - MEMBERS=const char* units_bias - MEMBERS=const char* changing_precision - MEMBERS=const char* number_of_values - MEMBERS=const char* bits_per_value - MEMBERS=const char* reference_value - MEMBERS=const char* binary_scale_factor - MEMBERS=const char* decimal_scale_factor - MEMBERS=const char* optimize_scaling_factor - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_float(grib_accessor*, float* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); -static int unpack_double_element(grib_accessor*, size_t i, double* val); -static int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array); -static int unpack_double_subarray(grib_accessor*, double* val, size_t start, size_t len); - -typedef struct grib_accessor_data_simple_packing -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in values */ - int carg; - const char* seclen; - const char* offsetdata; - const char* offsetsection; - int dirty; - /* Members defined in data_simple_packing */ - int edition; - const char* units_factor; - const char* units_bias; - const char* changing_precision; - const char* number_of_values; - const char* bits_per_value; - const char* reference_value; - const char* binary_scale_factor; - const char* decimal_scale_factor; - const char* optimize_scaling_factor; -} grib_accessor_data_simple_packing; - -extern grib_accessor_class* grib_accessor_class_values; - -static grib_accessor_class _grib_accessor_class_data_simple_packing = { - &grib_accessor_class_values, /* super */ - "data_simple_packing", /* name */ - sizeof(grib_accessor_data_simple_packing), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - &unpack_float, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - &unpack_double_element, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - &unpack_double_element_set, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - &unpack_double_subarray, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - +grib_accessor_class_data_simple_packing_t _grib_accessor_class_data_simple_packing{ "data_simple_packing" }; grib_accessor_class* grib_accessor_class_data_simple_packing = &_grib_accessor_class_data_simple_packing; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_class_data_simple_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) { - grib_accessor_data_simple_packing* self = (grib_accessor_data_simple_packing*)a; - grib_handle* gh = grib_handle_of_accessor(a); - self->units_factor = grib_arguments_get_name(gh, args, self->carg++); - self->units_bias = grib_arguments_get_name(gh, args, self->carg++); - self->changing_precision = grib_arguments_get_name(gh, args, self->carg++); - self->number_of_values = grib_arguments_get_name(gh, args, self->carg++); - self->bits_per_value = grib_arguments_get_name(gh, args, self->carg++); - self->reference_value = grib_arguments_get_name(gh, args, self->carg++); - self->binary_scale_factor = grib_arguments_get_name(gh, args, self->carg++); - self->decimal_scale_factor = grib_arguments_get_name(gh, args, self->carg++); - self->optimize_scaling_factor = grib_arguments_get_name(gh, args, self->carg++); + grib_accessor_class_values_t::init(a, v, args); + grib_accessor_data_simple_packing_t* self = (grib_accessor_data_simple_packing_t*)a; + grib_handle* gh = grib_handle_of_accessor(a); + self->units_factor = grib_arguments_get_name(gh, args, self->carg++); + self->units_bias = grib_arguments_get_name(gh, args, self->carg++); + self->changing_precision = grib_arguments_get_name(gh, args, self->carg++); + self->number_of_values = grib_arguments_get_name(gh, args, self->carg++); + self->bits_per_value = grib_arguments_get_name(gh, args, self->carg++); + self->reference_value = grib_arguments_get_name(gh, args, self->carg++); + self->binary_scale_factor = grib_arguments_get_name(gh, args, self->carg++); + self->decimal_scale_factor = grib_arguments_get_name(gh, args, self->carg++); + self->optimize_scaling_factor = grib_arguments_get_name(gh, args, self->carg++); a->flags |= GRIB_ACCESSOR_FLAG_DATA; self->dirty = 1; } @@ -178,21 +61,21 @@ static int number_of_bits(unsigned long x, long* result) return GRIB_SUCCESS; } -static int value_count(grib_accessor* a, long* number_of_values) +int grib_accessor_class_data_simple_packing_t::value_count(grib_accessor* a, long* number_of_values) { - grib_accessor_data_simple_packing* self = (grib_accessor_data_simple_packing*)a; - *number_of_values = 0; + grib_accessor_data_simple_packing_t* self = (grib_accessor_data_simple_packing_t*)a; + *number_of_values = 0; return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, number_of_values); } -static int unpack_double_element(grib_accessor* a, size_t idx, double* val) +int grib_accessor_class_data_simple_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) { - grib_accessor_data_simple_packing* self = (grib_accessor_data_simple_packing*)a; - const char* cclass_name = a->cclass->name; + grib_accessor_data_simple_packing_t* self = (grib_accessor_data_simple_packing_t*)a; + const char* cclass_name = a->cclass->name; - long n_vals; - int err = 0; + long n_vals = 0; + int err = 0; grib_handle* gh = grib_handle_of_accessor(a); double reference_value; @@ -200,12 +83,11 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) long bits_per_value; long decimal_scale_factor; unsigned char* buf = (unsigned char*)gh->buffer->data; - double s = 0; - double d = 0; - long pos = 0; + double s = 0; + double d = 0; + long pos = 0; - n_vals = 0; - err = grib_value_count(a, &n_vals); + err = a->value_count(&n_vals); if (err) return err; @@ -237,8 +119,7 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) "%s: %s: creating %s, %ld values (idx=%zu)", cclass_name, __func__, a->name, n_vals, idx); - buf += grib_byte_offset(a); - + buf += a->byte_offset(); /*Assert(((bits_per_value*n_vals)/8) < (1<<29));*/ /* See GRIB-787 */ if (bits_per_value % 8) { @@ -270,12 +151,12 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val) return err; } -static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) +int grib_accessor_class_data_simple_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) { - int err = 0; + int err = 0; size_t i = 0; - for (i=0; i::value, "Requires floating point numbers"); - grib_accessor_data_simple_packing* self = (grib_accessor_data_simple_packing*)a; - const char* cclass_name = a->cclass->name; - grib_handle* gh = grib_handle_of_accessor(a); - unsigned char* buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; + grib_accessor_data_simple_packing_t* self = (grib_accessor_data_simple_packing_t*)a; + const char* cclass_name = a->cclass->name; + grib_handle* gh = grib_handle_of_accessor(a); + unsigned char* buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; size_t i = 0; int err = 0; @@ -307,7 +188,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) double units_factor = 1.0; double units_bias = 0.0; - err = grib_value_count(a, &count); + err = a->value_count(&count); if (err) return err; n_vals = count; @@ -369,7 +250,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) grib_context_log(a->context, GRIB_LOG_DEBUG, "%s %s: Creating %s, %zu values", cclass_name, __func__, a->name, n_vals); - offsetBeforeData = grib_byte_offset(a); + offsetBeforeData = a->byte_offset(); buf += offsetBeforeData; /*Assert(((bits_per_value*n_vals)/8) < (1<<29));*/ /* See GRIB-787 */ @@ -383,9 +264,9 @@ static int unpack(grib_accessor* a, T* val, size_t* len) const long valuesSize = (bits_per_value * n_vals) / 8; /*in bytes*/ if (offsetBeforeData + valuesSize > offsetAfterData) { grib_context_log(a->context, GRIB_LOG_ERROR, - "%s: Data section size mismatch: " - "offset before data=%ld, offset after data=%ld (num values=%zu, bits per value=%ld)", - cclass_name, offsetBeforeData, offsetAfterData, n_vals, bits_per_value); + "%s: Data section size mismatch: " + "offset before data=%ld, offset after data=%ld (num values=%zu, bits per value=%ld)", + cclass_name, offsetBeforeData, offsetAfterData, n_vals, bits_per_value); return GRIB_DECODING_ERROR; } } @@ -410,7 +291,8 @@ static int unpack(grib_accessor* a, T* val, size_t* len) for (i = 0; i < n_vals; i++) { val[i] = val[i] * units_factor + units_bias; } - } else { + } + else { for (i = 0; i < n_vals; i++) { val[i] *= units_factor; } @@ -424,21 +306,21 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return err; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_class_data_simple_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len) { return unpack(a, val, len); } -static int unpack_float(grib_accessor* a, float* val, size_t* len) +int grib_accessor_class_data_simple_packing_t::unpack_float(grib_accessor* a, float* val, size_t* len) { return unpack(a, val, len); } static int _unpack_double(grib_accessor* a, double* val, size_t* len, unsigned char* buf, long pos, size_t n_vals) { - grib_accessor_data_simple_packing* self = (grib_accessor_data_simple_packing*)a; - grib_handle* gh = grib_handle_of_accessor(a); - const char* cclass_name = a->cclass->name; + grib_accessor_data_simple_packing_t* self = (grib_accessor_data_simple_packing_t*)a; + grib_handle* gh = grib_handle_of_accessor(a); + const char* cclass_name = a->cclass->name; size_t i = 0; int err = 0; @@ -510,7 +392,7 @@ static int _unpack_double(grib_accessor* a, double* val, size_t* len, unsigned c grib_context_log(a->context, GRIB_LOG_DEBUG, "%s %s: Creating %s, %zu values", cclass_name, __func__, a->name, n_vals); - offsetBeforeData = grib_byte_offset(a); + offsetBeforeData = a->byte_offset(); buf += offsetBeforeData; /*Assert(((bits_per_value*n_vals)/8) < (1<<29));*/ /* See GRIB-787 */ @@ -561,15 +443,16 @@ static int _unpack_double(grib_accessor* a, double* val, size_t* len, unsigned c return err; } -static int unpack_double_subarray(grib_accessor* a, double* val, size_t start, size_t len) +int grib_accessor_class_data_simple_packing_t::unpack_double_subarray(grib_accessor* a, double* val, size_t start, size_t len) { - grib_accessor_data_simple_packing* self = (grib_accessor_data_simple_packing*)a; - unsigned char* buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; - size_t nvals = len; - size_t* plen = &len; - long bits_per_value = 0; - long pos; - int err; + grib_accessor_data_simple_packing_t* self = (grib_accessor_data_simple_packing_t*)a; + + unsigned char* buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; + size_t nvals = len; + size_t* plen = &len; + long bits_per_value = 0; + long pos = 0; + int err = GRIB_SUCCESS; if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) @@ -580,15 +463,15 @@ static int unpack_double_subarray(grib_accessor* a, double* val, size_t start, s return _unpack_double(a, val, plen, buf, pos, nvals); } -static int pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_class_data_simple_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len) { - grib_accessor_data_simple_packing* self = (grib_accessor_data_simple_packing*)a; - grib_handle* gh = grib_handle_of_accessor(a); - const char* cclass_name = a->cclass->name; + grib_accessor_data_simple_packing_t* self = (grib_accessor_data_simple_packing_t*)a; + grib_handle* gh = grib_handle_of_accessor(a); + const char* cclass_name = a->cclass->name; - size_t i = 0; - size_t n_vals = *len; - int err = 0; + size_t i = 0; + size_t n_vals = *len; + int err = 0; double reference_value = 0; long binary_scale_factor = 0; long bits_per_value = 0; @@ -633,8 +516,10 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) max = val[0]; min = max; for (i = 1; i < n_vals; i++) { - if (val[i] > max) max = val[i]; - else if (val[i] < min) min = val[i]; + if (val[i] > max) + max = val[i]; + else if (val[i] < min) + min = val[i]; } if ((err = grib_check_data_values_minmax(gh, min, max)) != GRIB_SUCCESS) { @@ -733,7 +618,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) /* divisor=1; */ } else { - int last = 127; /* 'last' should be a parameter coming from a definitions file */ + int last = 127; /* 'last' should be a parameter coming from a definitions file */ if (c->gribex_mode_on && self->edition == 1) last = 99; /* bits_per_value is given and decimal_scale_factor and binary_scale_factor are calcualated */ diff --git a/src/accessor/grib_accessor_class_data_simple_packing.h b/src/accessor/grib_accessor_class_data_simple_packing.h new file mode 100644 index 000000000..3e50239a0 --- /dev/null +++ b/src/accessor/grib_accessor_class_data_simple_packing.h @@ -0,0 +1,45 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_values.h" +#include "grib_scaling.h" + +class grib_accessor_data_simple_packing_t : public grib_accessor_values_t +{ +public: + /* Members defined in data_simple_packing */ + int edition; + const char* units_factor; + const char* units_bias; + const char* changing_precision; + const char* number_of_values; + const char* bits_per_value; + const char* reference_value; + const char* binary_scale_factor; + const char* decimal_scale_factor; + const char* optimize_scaling_factor; +}; + +class grib_accessor_class_data_simple_packing_t : public grib_accessor_class_values_t +{ +public: + grib_accessor_class_data_simple_packing_t(const char* name) : grib_accessor_class_values_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_data_simple_packing_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_float(grib_accessor*, float* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_double_element(grib_accessor*, size_t i, double* val) override; + int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override; + int unpack_double_subarray(grib_accessor*, double* val, size_t start, size_t len) override; +}; diff --git a/src/accessor/grib_accessor_class_decimal_precision.cc b/src/accessor/grib_accessor_class_decimal_precision.cc new file mode 100644 index 000000000..6149de763 --- /dev/null +++ b/src/accessor/grib_accessor_class_decimal_precision.cc @@ -0,0 +1,103 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_decimal_precision.h" + +grib_accessor_class_decimal_precision_t _grib_accessor_class_decimal_precision{"decimal_precision"}; +grib_accessor_class* grib_accessor_class_decimal_precision = &_grib_accessor_class_decimal_precision; + + +void grib_accessor_class_decimal_precision_t::init(grib_accessor* a, const long l, grib_arguments* args){ + grib_accessor_class_long_t::init(a, l, args); + int n = 0; + grib_accessor_decimal_precision_t* self = (grib_accessor_decimal_precision_t*)a; + + self->bits_per_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + self->decimal_scale_factor = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + self->changing_precision = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + + a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; + a->length = 0; +} + +int grib_accessor_class_decimal_precision_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + int ret = 0; + grib_accessor_decimal_precision_t* self = (grib_accessor_decimal_precision_t*)a; + grib_handle* h = grib_handle_of_accessor(a); + + if ((ret = grib_get_long_internal(h, self->decimal_scale_factor, val)) != GRIB_SUCCESS) + return ret; + + *len = 1; + return ret; +} + +int grib_accessor_class_decimal_precision_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + long bitsPerValue = 0; + double* values = NULL; + size_t size = 0; + int ret = 0; + grib_accessor_decimal_precision_t* self = (grib_accessor_decimal_precision_t*)a; + grib_context* c = a->context; + grib_handle* h = grib_handle_of_accessor(a); + + if (!self->values) { + if ((ret = grib_set_long_internal(h, self->bits_per_value, 0)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_set_long_internal(h, self->decimal_scale_factor, *val)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_set_long_internal(h, self->changing_precision, 1)) != GRIB_SUCCESS) { + grib_context_free(c, values); + return ret; + } + + return GRIB_SUCCESS; + } + + if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) + return ret; + + values = (double*)grib_context_malloc(c, size * sizeof(double)); + if (!values) + return GRIB_OUT_OF_MEMORY; + + if ((ret = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) { + grib_context_buffer_free(c, values); + return ret; + } + + if ((ret = grib_set_long_internal(h, self->decimal_scale_factor, *val)) != GRIB_SUCCESS) { + grib_context_buffer_free(c, values); + return ret; + } + + if ((ret = grib_set_long_internal(h, self->bits_per_value, bitsPerValue)) != GRIB_SUCCESS) { + grib_context_free(c, values); + return ret; + } + + if ((ret = grib_set_long_internal(h, self->changing_precision, 1)) != GRIB_SUCCESS) { + grib_context_free(c, values); + return ret; + } + + if ((ret = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) { + grib_context_buffer_free(c, values); + return ret; + } + + grib_context_free(c, values); + + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_decimal_precision.h b/src/accessor/grib_accessor_class_decimal_precision.h new file mode 100644 index 000000000..a6b6d4839 --- /dev/null +++ b/src/accessor/grib_accessor_class_decimal_precision.h @@ -0,0 +1,33 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_decimal_precision_t : public grib_accessor_long_t +{ +public: + /* Members defined in decimal_precision */ + const char* values; + const char* bits_per_value; + const char* changing_precision; + const char* decimal_scale_factor; +}; + +class grib_accessor_class_decimal_precision_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_decimal_precision_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_decimal_precision_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_dictionary.cc b/src/accessor/grib_accessor_class_dictionary.cc similarity index 61% rename from src/grib_accessor_class_dictionary.cc rename to src/accessor/grib_accessor_class_dictionary.cc index dde22abdc..9a0b3307d 100644 --- a/src/grib_accessor_class_dictionary.cc +++ b/src/accessor/grib_accessor_class_dictionary.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,114 +9,16 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init;dump;unpack_string;unpack_long;unpack_double - IMPLEMENTS = value_count; get_native_type; - MEMBERS = const char* dictionary - MEMBERS = const char* key - MEMBERS = long column - MEMBERS = const char* masterDir - MEMBERS = const char* localDir - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static int value_count(grib_accessor*, long*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_dictionary -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in dictionary */ - const char* dictionary; - const char* key; - long column; - const char* masterDir; - const char* localDir; -} grib_accessor_dictionary; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_dictionary = { - &grib_accessor_class_gen, /* super */ - "dictionary", /* name */ - sizeof(grib_accessor_dictionary), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_dictionary.h" +grib_accessor_class_dictionary_t _grib_accessor_class_dictionary{"dictionary"}; grib_accessor_class* grib_accessor_class_dictionary = &_grib_accessor_class_dictionary; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long len, grib_arguments* params) -{ +void grib_accessor_class_dictionary_t::init(grib_accessor* a, const long len, grib_arguments* params){ + grib_accessor_class_gen_t::init(a, len, params); int n = 0; - grib_accessor_dictionary* self = (grib_accessor_dictionary*)a; + grib_accessor_dictionary_t* self = (grib_accessor_dictionary_t*)a; self->dictionary = grib_arguments_get_string(grib_handle_of_accessor(a), params, n++); self->key = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++); @@ -129,7 +32,7 @@ static void init(grib_accessor* a, const long len, grib_arguments* params) static grib_trie* load_dictionary(grib_accessor* a, int* err) { - grib_accessor_dictionary* self = (grib_accessor_dictionary*)a; + grib_accessor_dictionary_t* self = (grib_accessor_dictionary_t*)a; char* filename = NULL; char line[1024] = {0,}; @@ -243,8 +146,7 @@ static grib_trie* load_dictionary(grib_accessor* a, int* err) return dictionary; } -static void dump(grib_accessor* a, grib_dumper* dumper) -{ +void grib_accessor_class_dictionary_t::dump(grib_accessor* a, grib_dumper* dumper){ switch (get_native_type(a)) { case GRIB_TYPE_STRING: grib_dump_string(dumper, a, NULL); @@ -258,9 +160,8 @@ static void dump(grib_accessor* a, grib_dumper* dumper) } } -static int unpack_string(grib_accessor* a, char* buffer, size_t* len) -{ - grib_accessor_dictionary* self = (grib_accessor_dictionary*)a; +int grib_accessor_class_dictionary_t::unpack_string(grib_accessor* a, char* buffer, size_t* len){ + grib_accessor_dictionary_t* self = (grib_accessor_dictionary_t*)a; int err = GRIB_SUCCESS; char key[1024] = {0,}; size_t size = 1024; @@ -313,14 +214,12 @@ static int unpack_string(grib_accessor* a, char* buffer, size_t* len) return err; } -static int value_count(grib_accessor* a, long* count) -{ +int grib_accessor_class_dictionary_t::value_count(grib_accessor* a, long* count){ *count = 1; return 0; } -static int get_native_type(grib_accessor* a) -{ +int grib_accessor_class_dictionary_t::get_native_type(grib_accessor* a){ int type = GRIB_TYPE_DOUBLE; if (a->flags & GRIB_ACCESSOR_FLAG_LONG_TYPE) type = GRIB_TYPE_LONG; @@ -329,8 +228,7 @@ static int get_native_type(grib_accessor* a) return type; } -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ +int grib_accessor_class_dictionary_t::unpack_long(grib_accessor* a, long* val, size_t* len){ int err = 0; char buffer[1024] = {0,}; size_t size = 1024; @@ -345,8 +243,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) return GRIB_SUCCESS; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ +int grib_accessor_class_dictionary_t::unpack_double(grib_accessor* a, double* val, size_t* len){ int err = 0; char buffer[1024] = {0,}; size_t size = 1024; diff --git a/src/accessor/grib_accessor_class_dictionary.h b/src/accessor/grib_accessor_class_dictionary.h new file mode 100644 index 000000000..8dc976e51 --- /dev/null +++ b/src/accessor/grib_accessor_class_dictionary.h @@ -0,0 +1,38 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_dictionary_t : public grib_accessor_gen_t +{ +public: + /* Members defined in dictionary */ + const char* dictionary; + const char* key; + long column; + const char* masterDir; + const char* localDir; +}; + +class grib_accessor_class_dictionary_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_dictionary_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_dictionary_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_dirty.cc b/src/accessor/grib_accessor_class_dirty.cc new file mode 100644 index 000000000..73f11c9d7 --- /dev/null +++ b/src/accessor/grib_accessor_class_dirty.cc @@ -0,0 +1,50 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_dirty.h" + +grib_accessor_class_dirty_t _grib_accessor_class_dirty{ "dirty" }; +grib_accessor_class* grib_accessor_class_dirty = &_grib_accessor_class_dirty; + + +void grib_accessor_class_dirty_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ + grib_accessor_class_long_t::init(a, l, c); + grib_accessor_dirty_t* self = (grib_accessor_dirty_t*)a; + self->accessor = grib_arguments_get_name(grib_handle_of_accessor(a), c, 0); + a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; + a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; + a->length = 0; +} + +int grib_accessor_class_dirty_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ + grib_accessor_dirty_t* self = (grib_accessor_dirty_t*)a; + grib_accessor* x = grib_find_accessor(grib_handle_of_accessor(a), self->accessor); + + if (x) + x->dirty = *val; + + return GRIB_SUCCESS; +} + +int grib_accessor_class_dirty_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ + grib_accessor_dirty_t* self = (grib_accessor_dirty_t*)a; + grib_accessor* x = grib_find_accessor(grib_handle_of_accessor(a), self->accessor); + + if (x) + x->dirty = 1; + + *val = 1; + + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_dirty.h b/src/accessor/grib_accessor_class_dirty.h new file mode 100644 index 000000000..b024b69f7 --- /dev/null +++ b/src/accessor/grib_accessor_class_dirty.h @@ -0,0 +1,30 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_dirty_t : public grib_accessor_long_t +{ +public: + /* Members defined in dirty */ + const char* accessor; +}; + +class grib_accessor_class_dirty_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_dirty_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_dirty_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_divdouble.cc b/src/accessor/grib_accessor_class_divdouble.cc new file mode 100644 index 000000000..a652752fa --- /dev/null +++ b/src/accessor/grib_accessor_class_divdouble.cc @@ -0,0 +1,43 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_divdouble.h" + +grib_accessor_class_divdouble_t _grib_accessor_class_divdouble{"divdouble"}; +grib_accessor_class* grib_accessor_class_divdouble = &_grib_accessor_class_divdouble; + + +void grib_accessor_class_divdouble_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_double_t::init(a, l, c); + grib_accessor_divdouble_t* self = (grib_accessor_divdouble_t*)a; + int n = 0; + + self->val = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->divisor = grib_arguments_get_double(grib_handle_of_accessor(a), c, n++); +} + +int grib_accessor_class_divdouble_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + const grib_accessor_divdouble_t* self = (grib_accessor_divdouble_t*)a; + int ret = GRIB_SUCCESS; + double value = 0; + + ret = grib_get_double_internal(grib_handle_of_accessor(a), self->val, &value); + if (ret != GRIB_SUCCESS) + return ret; + + if (self->divisor == 0) { + return GRIB_INVALID_ARGUMENT; + } + *val = value / self->divisor; + + *len = 1; + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_divdouble.h b/src/accessor/grib_accessor_class_divdouble.h new file mode 100644 index 000000000..9408b073a --- /dev/null +++ b/src/accessor/grib_accessor_class_divdouble.h @@ -0,0 +1,30 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_double.h" + +class grib_accessor_divdouble_t : public grib_accessor_double_t +{ +public: + /* Members defined in divdouble */ + const char* val; + double divisor; +}; + +class grib_accessor_class_divdouble_t : public grib_accessor_class_double_t +{ +public: + grib_accessor_class_divdouble_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_divdouble_t{}; } + int unpack_double(grib_accessor*, double* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_double.cc b/src/accessor/grib_accessor_class_double.cc new file mode 100644 index 000000000..a0e3a49b5 --- /dev/null +++ b/src/accessor/grib_accessor_class_double.cc @@ -0,0 +1,105 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_double.h" + +grib_accessor_class_double_t _grib_accessor_class_double{"double"}; +grib_accessor_class* grib_accessor_class_double = &_grib_accessor_class_double; + + +int grib_accessor_class_double_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_DOUBLE; +} + +int grib_accessor_class_double_t::unpack_string(grib_accessor* a, char* v, size_t* len){ + double val = 0; + size_t l = 1; + char repres[1024]; + char format[32] = "%g"; + grib_handle* h = grib_handle_of_accessor(a); + const char* cclass_name = a->cclass->name; + + a->unpack_double(&val, &l); + if ((val == GRIB_MISSING_DOUBLE) && ((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0)) { + snprintf(repres, sizeof(repres), "MISSING"); + } else { + size_t size = sizeof(format); + grib_get_string(h, "formatForDoubles", format, &size); + snprintf(repres, sizeof(repres), format, val); + } + + l = strlen(repres) + 1; + + if (l > *len) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", + cclass_name, a->name, l, *len); + *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; +} + +void grib_accessor_class_double_t::dump(grib_accessor* a, grib_dumper* dumper){ + grib_dump_values(dumper, a); +} + +int grib_accessor_class_double_t::compare(grib_accessor* a, grib_accessor* b){ + int retval = 0; + double* aval = 0; + double* bval = 0; + + size_t alen = 0; + size_t blen = 0; + long count = 0; + int err = 0; + + err = a->value_count(&count); if (err) + return err; + alen = count; + + err = b->value_count(&count); if (err) + return err; + blen = count; + + if (alen != blen) + return GRIB_COUNT_MISMATCH; + + aval = (double*)grib_context_malloc(a->context, alen * sizeof(double)); + bval = (double*)grib_context_malloc(b->context, blen * sizeof(double)); + + a->unpack_double(aval, &alen); b->unpack_double(bval, &blen); + retval = GRIB_SUCCESS; + while (alen != 0) { + if (*bval != *aval) + retval = GRIB_DOUBLE_VALUE_MISMATCH; + alen--; + } + + grib_context_free(a->context, aval); + grib_context_free(b->context, bval); + + return retval; +} + +int grib_accessor_class_double_t::pack_missing(grib_accessor* a){ + size_t len = 1; + double value = GRIB_MISSING_DOUBLE; + + if (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) + return a->pack_double(&value, &len); + return GRIB_VALUE_CANNOT_BE_MISSING; +} diff --git a/src/accessor/grib_accessor_class_double.h b/src/accessor/grib_accessor_class_double.h new file mode 100644 index 000000000..7ad9771c2 --- /dev/null +++ b/src/accessor/grib_accessor_class_double.h @@ -0,0 +1,27 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_double_t : public grib_accessor_gen_t {}; + +class grib_accessor_class_double_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_double_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_double_t{}; } + int get_native_type(grib_accessor*) override; + int pack_missing(grib_accessor*) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + void dump(grib_accessor*, grib_dumper*) override; + int compare(grib_accessor*, grib_accessor*) override; +}; diff --git a/src/grib_accessor_class_element.cc b/src/accessor/grib_accessor_class_element.cc similarity index 56% rename from src/grib_accessor_class_element.cc rename to src/accessor/grib_accessor_class_element.cc index 2041cd62d..3d150d79e 100644 --- a/src/grib_accessor_class_element.cc +++ b/src/accessor/grib_accessor_class_element.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,105 +9,16 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long;pack_long; - IMPLEMENTS = unpack_double - IMPLEMENTS = init - MEMBERS=const char* array - MEMBERS=long element - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_element -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in element */ - const char* array; - long element; -} grib_accessor_element; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_element = { - &grib_accessor_class_long, /* super */ - "element", /* name */ - sizeof(grib_accessor_element), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_element.h" +grib_accessor_class_element_t _grib_accessor_class_element{"element"}; grib_accessor_class* grib_accessor_class_element = &_grib_accessor_class_element; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_class_element_t::init(grib_accessor* a, const long l, grib_arguments* c) { - grib_accessor_element* self = (grib_accessor_element*)a; + grib_accessor_class_long_t::init(a, l, c); + grib_accessor_element_t* self = (grib_accessor_element_t*)a; grib_handle* hand = grib_handle_of_accessor(a); int n = 0; @@ -125,9 +37,9 @@ static int check_element_index(const char* func, const char* array_name, long in return GRIB_SUCCESS; } -static int unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_class_element_t::unpack_long(grib_accessor* a, long* val, size_t* len) { - grib_accessor_element* self = (grib_accessor_element*)a; + grib_accessor_element_t* self = (grib_accessor_element_t*)a; int ret = 0; size_t size = 0; long* ar = NULL; @@ -168,9 +80,9 @@ the_end: return ret; } -static int pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_class_element_t::pack_long(grib_accessor* a, const long* val, size_t* len) { - grib_accessor_element* self = (grib_accessor_element*)a; + grib_accessor_element_t* self = (grib_accessor_element_t*)a; int ret = 0; size_t size = 0; long* ar = NULL; @@ -216,9 +128,9 @@ the_end: return ret; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_class_element_t::unpack_double(grib_accessor* a, double* val, size_t* len) { - grib_accessor_element* self = (grib_accessor_element*)a; + grib_accessor_element_t* self = (grib_accessor_element_t*)a; int ret = 0; size_t size = 0; double* ar = NULL; diff --git a/src/accessor/grib_accessor_class_element.h b/src/accessor/grib_accessor_class_element.h new file mode 100644 index 000000000..220b8ff84 --- /dev/null +++ b/src/accessor/grib_accessor_class_element.h @@ -0,0 +1,32 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_element_t : public grib_accessor_long_t +{ +public: + /* Members defined in element */ + const char* array; + long element; +}; + +class grib_accessor_class_element_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_element_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_element_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_evaluate.cc b/src/accessor/grib_accessor_class_evaluate.cc new file mode 100644 index 000000000..0312107a4 --- /dev/null +++ b/src/accessor/grib_accessor_class_evaluate.cc @@ -0,0 +1,35 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_evaluate.h" + +grib_accessor_class_evaluate_t _grib_accessor_class_evaluate{ "evaluate" }; +grib_accessor_class* grib_accessor_class_evaluate = &_grib_accessor_class_evaluate; + + +void grib_accessor_class_evaluate_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ + grib_accessor_class_long_t::init(a, l, c); + grib_accessor_evaluate_t* self = (grib_accessor_evaluate_t*)a; + self->arg = c; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; +} + +int grib_accessor_class_evaluate_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ + grib_accessor_evaluate_t* self = (grib_accessor_evaluate_t*)a; + grib_expression* e = grib_arguments_get_expression(grib_handle_of_accessor(a), self->arg, 0); + + int ret = grib_expression_evaluate_long(grib_handle_of_accessor(a), e, val); + *len = 1; + + return ret; +} diff --git a/src/accessor/grib_accessor_class_evaluate.h b/src/accessor/grib_accessor_class_evaluate.h new file mode 100644 index 000000000..0e40cf206 --- /dev/null +++ b/src/accessor/grib_accessor_class_evaluate.h @@ -0,0 +1,29 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_evaluate_t : public grib_accessor_long_t +{ +public: + /* Members defined in evaluate */ + grib_arguments* arg; +}; + +class grib_accessor_class_evaluate_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_evaluate_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_evaluate_t{}; } + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_expanded_descriptors.cc b/src/accessor/grib_accessor_class_expanded_descriptors.cc similarity index 80% rename from src/grib_accessor_class_expanded_descriptors.cc rename to src/accessor/grib_accessor_class_expanded_descriptors.cc index 11f4ba73b..b30e745a9 100644 --- a/src/grib_accessor_class_expanded_descriptors.cc +++ b/src/accessor/grib_accessor_class_expanded_descriptors.cc @@ -1,137 +1,20 @@ + /* -* (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. -*/ - -/* Sequences and replication (not delayed) are resolved in this class. - Number of elements to which a delayed replication applies are recomputed to - take account of the expansion. - Expanded descriptors cannot contain sequences and only delayed replication - can appear -*/ + * (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. + */ +#include "grib_accessor_class_expanded_descriptors.h" #include "grib_scaling.h" -#include "grib_api_internal.h" -/* -This is used by make_class.pl - -START_CLASS_DEF -CLASS = accessor -SUPER = grib_accessor_class_long -IMPLEMENTS = unpack_long;pack_long -IMPLEMENTS = unpack_double -IMPLEMENTS = unpack_string_array -IMPLEMENTS = init;destroy -IMPLEMENTS = value_count; get_native_type -MEMBERS = const char* unexpandedDescriptors -MEMBERS = const char* sequence -MEMBERS = const char* expandedName -MEMBERS = const char* tablesAccessorName -MEMBERS = bufr_descriptors_array* expanded -MEMBERS = int rank -MEMBERS = grib_accessor* expandedAccessor -MEMBERS = int do_expand -MEMBERS = grib_accessor* tablesAccessor - -END_CLASS_DEF - -*/ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string_array(grib_accessor*, char**, size_t* len); -static int value_count(grib_accessor*, long*); -static void destroy(grib_context*, grib_accessor*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_expanded_descriptors -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in expanded_descriptors */ - const char* unexpandedDescriptors; - const char* sequence; - const char* expandedName; - const char* tablesAccessorName; - bufr_descriptors_array* expanded; - int rank; - grib_accessor* expandedAccessor; - int do_expand; - grib_accessor* tablesAccessor; -} grib_accessor_expanded_descriptors; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_expanded_descriptors = { - &grib_accessor_class_long, /* super */ - "expanded_descriptors", /* name */ - sizeof(grib_accessor_expanded_descriptors), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - &destroy, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - &unpack_string_array, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +grib_accessor_class_expanded_descriptors_t _grib_accessor_class_expanded_descriptors{"expanded_descriptors"}; grib_accessor_class* grib_accessor_class_expanded_descriptors = &_grib_accessor_class_expanded_descriptors; -/* END_CLASS_IMP */ #define MYDEBUG 0 #define DESC_SIZE_INIT 400 /* Initial size for grib_bufr_descriptors_array_new */ @@ -158,9 +41,10 @@ typedef struct change_coding_params result = grib_bufr_descriptors_array_pop_front(array); \ } -static void init(grib_accessor* a, const long len, grib_arguments* args) +void grib_accessor_class_expanded_descriptors_t::init(grib_accessor* a, const long len, grib_arguments* args) { - grib_accessor_expanded_descriptors* self = (grib_accessor_expanded_descriptors*)a; + grib_accessor_class_long_t::init(a, len, args); + grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; int n = 0; grib_handle* hand = grib_handle_of_accessor(a); self->tablesAccessorName = grib_arguments_get_name(hand, args, n++); @@ -208,7 +92,7 @@ static char* descriptor_type_name(int dtype) static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_descriptors_array* expanded, change_coding_params* ccp, int* err) { int k, j, i; - grib_accessor_expanded_descriptors* self = (grib_accessor_expanded_descriptors*)a; + grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; size_t size = 0; long* v_array = NULL; bufr_descriptor* u = NULL; @@ -583,7 +467,7 @@ static bufr_descriptors_array* do_expand(grib_accessor* a, bufr_descriptors_arra static int expand(grib_accessor* a) { - grib_accessor_expanded_descriptors* self = (grib_accessor_expanded_descriptors*)a; + grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; int err = 0; size_t unexpandedSize = 0; /* grib_iarray* unexp=0; */ @@ -605,7 +489,7 @@ static int expand(grib_accessor* a) self->do_expand = 0; if (self->rank != 0) { err = expand(self->expandedAccessor); - self->expanded = ((grib_accessor_expanded_descriptors*)self->expandedAccessor)->expanded; + self->expanded = ((grib_accessor_expanded_descriptors_t*)self->expandedAccessor)->expanded; return err; } @@ -706,21 +590,21 @@ static int expand(grib_accessor* a) int grib_accessor_class_expanded_descriptors_set_do_expand(grib_accessor* a, long do_expand) { - grib_accessor_expanded_descriptors* self = (grib_accessor_expanded_descriptors*)a; + grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; self->do_expand = do_expand; return 0; } bufr_descriptors_array* grib_accessor_class_expanded_descriptors_get_expanded(grib_accessor* a, int* err) { - const grib_accessor_expanded_descriptors* self = (grib_accessor_expanded_descriptors*)a; + const grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; *err = expand(a); return self->expanded; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_class_expanded_descriptors_t::unpack_double(grib_accessor* a, double* val, size_t* len) { - grib_accessor_expanded_descriptors* self = (grib_accessor_expanded_descriptors*)a; + grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; int ret = 0; size_t i = 0; size_t expandedSize; @@ -753,9 +637,9 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) return ret; } -static int unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_class_expanded_descriptors_t::unpack_long(grib_accessor* a, long* val, size_t* len) { - grib_accessor_expanded_descriptors* self = (grib_accessor_expanded_descriptors*)a; + grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; int ret = 0; size_t rlen = 0; size_t i = 0; @@ -799,7 +683,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) return GRIB_SUCCESS; } -static int unpack_string_array(grib_accessor* a, char** buffer, size_t* len) +int grib_accessor_class_expanded_descriptors_t::unpack_string_array(grib_accessor* a, char** buffer, size_t* len) { int err = 0; long* v = NULL; @@ -808,13 +692,11 @@ static int unpack_string_array(grib_accessor* a, char** buffer, size_t* len) size_t i = 0, size = 0; const grib_context* c = a->context; - err = grib_value_count(a, &llen); - if (err) return err; + err = a->value_count(&llen); if (err) return err; size = llen; v = (long*)grib_context_malloc_clear(c, sizeof(long) * size); - err = grib_unpack_long(a, v, &size); - if (err) return err; + err = a->unpack_long(v, &size); if (err) return err; for (i = 0; i < size; i++) { snprintf(buf, sizeof(buf), "%06ld", v[i]); @@ -826,16 +708,16 @@ static int unpack_string_array(grib_accessor* a, char** buffer, size_t* len) return GRIB_NOT_IMPLEMENTED; } -static int pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_class_expanded_descriptors_t::pack_long(grib_accessor* a, const long* val, size_t* len) { - grib_accessor_expanded_descriptors* self = (grib_accessor_expanded_descriptors*)a; + grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; self->do_expand = 1; return GRIB_NOT_IMPLEMENTED; } -static int value_count(grib_accessor* a, long* rlen) +int grib_accessor_class_expanded_descriptors_t::value_count(grib_accessor* a, long* rlen) { - grib_accessor_expanded_descriptors* self = (grib_accessor_expanded_descriptors*)a; + grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; int err = 0; *rlen = 0; @@ -849,16 +731,17 @@ static int value_count(grib_accessor* a, long* rlen) return err; } -static void destroy(grib_context* c, grib_accessor* a) +void grib_accessor_class_expanded_descriptors_t::destroy(grib_context* c, grib_accessor* a) { - // grib_accessor_expanded_descriptors* self = (grib_accessor_expanded_descriptors*)a; + grib_accessor_class_long_t::destroy(c, a); + // grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; // if (self->rank==0 && self->expanded) // grib_bufr_descriptors_array_delete(self->expanded); } -static int get_native_type(grib_accessor* a) +int grib_accessor_class_expanded_descriptors_t::get_native_type(grib_accessor* a) { - grib_accessor_expanded_descriptors* self = (grib_accessor_expanded_descriptors*)a; + grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; if (self->rank == 2) return GRIB_TYPE_DOUBLE; else diff --git a/src/accessor/grib_accessor_class_expanded_descriptors.h b/src/accessor/grib_accessor_class_expanded_descriptors.h new file mode 100644 index 000000000..7e42ad28c --- /dev/null +++ b/src/accessor/grib_accessor_class_expanded_descriptors.h @@ -0,0 +1,43 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_expanded_descriptors_t : public grib_accessor_long_t +{ +public: + /* Members defined in expanded_descriptors */ + const char* unexpandedDescriptors; + const char* sequence; + const char* expandedName; + const char* tablesAccessorName; + bufr_descriptors_array* expanded; + int rank; + grib_accessor* expandedAccessor; + int do_expand; + grib_accessor* tablesAccessor; +}; + +class grib_accessor_class_expanded_descriptors_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_expanded_descriptors_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_expanded_descriptors_t{}; } + int get_native_type(grib_accessor*) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string_array(grib_accessor*, char**, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void destroy(grib_context*, grib_accessor*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_from_scale_factor_scaled_value.cc b/src/accessor/grib_accessor_class_from_scale_factor_scaled_value.cc similarity index 59% rename from src/grib_accessor_class_from_scale_factor_scaled_value.cc rename to src/accessor/grib_accessor_class_from_scale_factor_scaled_value.cc index 53784e172..4168e1476 100644 --- a/src/grib_accessor_class_from_scale_factor_scaled_value.cc +++ b/src/accessor/grib_accessor_class_from_scale_factor_scaled_value.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,111 +9,15 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" -#include -#ifdef ECCODES_ON_WINDOWS - #include -#endif - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_double - IMPLEMENTS = unpack_double;pack_double;is_missing - IMPLEMENTS = value_count - IMPLEMENTS = init - MEMBERS=const char* scaleFactor - MEMBERS=const char* scaledValue - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int is_missing(grib_accessor*); -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_from_scale_factor_scaled_value -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in from_scale_factor_scaled_value */ - const char* scaleFactor; - const char* scaledValue; -} grib_accessor_from_scale_factor_scaled_value; - -extern grib_accessor_class* grib_accessor_class_double; - -static grib_accessor_class _grib_accessor_class_from_scale_factor_scaled_value = { - &grib_accessor_class_double, /* super */ - "from_scale_factor_scaled_value", /* name */ - sizeof(grib_accessor_from_scale_factor_scaled_value), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - &is_missing, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_from_scale_factor_scaled_value.h" +grib_accessor_class_from_scale_factor_scaled_value_t _grib_accessor_class_from_scale_factor_scaled_value{"from_scale_factor_scaled_value"}; grib_accessor_class* grib_accessor_class_from_scale_factor_scaled_value = &_grib_accessor_class_from_scale_factor_scaled_value; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_from_scale_factor_scaled_value* self = (grib_accessor_from_scale_factor_scaled_value*)a; +void grib_accessor_class_from_scale_factor_scaled_value_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_double_t::init(a, l, c); + grib_accessor_from_scale_factor_scaled_value_t* self = (grib_accessor_from_scale_factor_scaled_value_t*)a; int n = 0; grib_handle* hand = grib_handle_of_accessor(a); @@ -123,11 +28,10 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) // a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ +int grib_accessor_class_from_scale_factor_scaled_value_t::pack_double(grib_accessor* a, const double* val, size_t* len){ // See ECC-979 and ECC-1416 // Evaluate self->scaleFactor and self->scaledValue from input double '*val' - grib_accessor_from_scale_factor_scaled_value* self = (grib_accessor_from_scale_factor_scaled_value*)a; + grib_accessor_from_scale_factor_scaled_value_t* self = (grib_accessor_from_scale_factor_scaled_value_t*)a; grib_handle* hand = grib_handle_of_accessor(a); int err = 0; int64_t factor = 0; @@ -181,9 +85,8 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) return GRIB_SUCCESS; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_from_scale_factor_scaled_value* self = (grib_accessor_from_scale_factor_scaled_value*)a; +int grib_accessor_class_from_scale_factor_scaled_value_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + grib_accessor_from_scale_factor_scaled_value_t* self = (grib_accessor_from_scale_factor_scaled_value_t*)a; int err = 0; long scaleFactor = 0, scaledValue = 0; grib_handle* hand = grib_handle_of_accessor(a); @@ -257,9 +160,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) return err; } -static int is_missing(grib_accessor* a) -{ - grib_accessor_from_scale_factor_scaled_value* self = (grib_accessor_from_scale_factor_scaled_value*)a; +int grib_accessor_class_from_scale_factor_scaled_value_t::is_missing(grib_accessor* a){ + grib_accessor_from_scale_factor_scaled_value_t* self = (grib_accessor_from_scale_factor_scaled_value_t*)a; grib_handle* hand = grib_handle_of_accessor(a); int err = 0; long scaleFactor = 0, scaledValue = 0; @@ -273,9 +175,8 @@ static int is_missing(grib_accessor* a) return ((scaleFactor == GRIB_MISSING_LONG) || (scaledValue == GRIB_MISSING_LONG)); } -static int value_count(grib_accessor* a, long* len) -{ - grib_accessor_from_scale_factor_scaled_value* self = (grib_accessor_from_scale_factor_scaled_value*)a; +int grib_accessor_class_from_scale_factor_scaled_value_t::value_count(grib_accessor* a, long* len){ + grib_accessor_from_scale_factor_scaled_value_t* self = (grib_accessor_from_scale_factor_scaled_value_t*)a; int err = 0; grib_handle* hand = grib_handle_of_accessor(a); size_t vsize; diff --git a/src/accessor/grib_accessor_class_from_scale_factor_scaled_value.h b/src/accessor/grib_accessor_class_from_scale_factor_scaled_value.h new file mode 100644 index 000000000..d8dc1bcb8 --- /dev/null +++ b/src/accessor/grib_accessor_class_from_scale_factor_scaled_value.h @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_double.h" + +class grib_accessor_from_scale_factor_scaled_value_t : public grib_accessor_double_t +{ +public: + /* Members defined in from_scale_factor_scaled_value */ + const char* scaleFactor; + const char* scaledValue; +}; + +class grib_accessor_class_from_scale_factor_scaled_value_t : public grib_accessor_class_double_t +{ +public: + grib_accessor_class_from_scale_factor_scaled_value_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_from_scale_factor_scaled_value_t{}; } + int is_missing(grib_accessor*) override; + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_g1_half_byte_codeflag.cc b/src/accessor/grib_accessor_class_g1_half_byte_codeflag.cc new file mode 100644 index 000000000..2f757addc --- /dev/null +++ b/src/accessor/grib_accessor_class_g1_half_byte_codeflag.cc @@ -0,0 +1,60 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_g1_half_byte_codeflag.h" + +grib_accessor_class_g1_half_byte_codeflag_t _grib_accessor_class_g1_half_byte_codeflag{"g1_half_byte_codeflag"}; +grib_accessor_class* grib_accessor_class_g1_half_byte_codeflag = &_grib_accessor_class_g1_half_byte_codeflag; + + +void grib_accessor_class_g1_half_byte_codeflag_t::init(grib_accessor* a, const long len, grib_arguments* arg){ + grib_accessor_class_gen_t::init(a, len, arg); + a->length = 0; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; +} + +void grib_accessor_class_g1_half_byte_codeflag_t::dump(grib_accessor* a, grib_dumper* dumper){ + grib_dump_long(dumper, a, NULL); +} + +int grib_accessor_class_g1_half_byte_codeflag_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + unsigned char dat = 0; + if (*len < 1) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name, 1); + *len = 0; + return GRIB_ARRAY_TOO_SMALL; + } + dat = grib_handle_of_accessor(a)->buffer->data[a->offset] & 0x0f; + + *val = dat; + *len = 1; + return GRIB_SUCCESS; +} + +int grib_accessor_class_g1_half_byte_codeflag_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + int ret = 0; + if (*len < 1) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name, 1); + *len = 0; + return GRIB_ARRAY_TOO_SMALL; + } + /* printf("HALF BYTE pack long %ld %02x\n",*val,grib_handle_of_accessor(a)->buffer->data[a->offset]);*/ + grib_handle_of_accessor(a)->buffer->data[a->offset] = (a->parent->h->buffer->data[a->offset] & 0xf0) | (*val & 0x0f); + /* printf("HALF BYTE pack long %ld %02x\n",*val,grib_handle_of_accessor(a)->buffer->data[a->offset]);*/ + + *len = 1; + return ret; +} + +int grib_accessor_class_g1_half_byte_codeflag_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_LONG; +} diff --git a/src/accessor/grib_accessor_class_g1_half_byte_codeflag.h b/src/accessor/grib_accessor_class_g1_half_byte_codeflag.h new file mode 100644 index 000000000..662a75569 --- /dev/null +++ b/src/accessor/grib_accessor_class_g1_half_byte_codeflag.h @@ -0,0 +1,32 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_g1_half_byte_codeflag_t : public grib_accessor_gen_t +{ +public: + /* Members defined in g1_half_byte_codeflag */ +}; + +class grib_accessor_class_g1_half_byte_codeflag_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_g1_half_byte_codeflag_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g1_half_byte_codeflag_t{}; } + int get_native_type(grib_accessor*) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_g1_message_length.cc b/src/accessor/grib_accessor_class_g1_message_length.cc similarity index 53% rename from src/grib_accessor_class_g1_message_length.cc rename to src/accessor/grib_accessor_class_g1_message_length.cc index 1d38e7ea4..89ce742c5 100644 --- a/src/grib_accessor_class_g1_message_length.cc +++ b/src/accessor/grib_accessor_class_g1_message_length.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,104 +9,15 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_section_length - IMPLEMENTS = init;unpack_long;pack_long - MEMBERS = const char *sec4_length - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g1_message_length -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in unsigned */ - long nbytes; - grib_arguments* arg; - /* Members defined in section_length */ - /* Members defined in g1_message_length */ - const char *sec4_length; -} grib_accessor_g1_message_length; - -extern grib_accessor_class* grib_accessor_class_section_length; - -static grib_accessor_class _grib_accessor_class_g1_message_length = { - &grib_accessor_class_section_length, /* super */ - "g1_message_length", /* name */ - sizeof(grib_accessor_g1_message_length), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_g1_message_length.h" +grib_accessor_class_g1_message_length_t _grib_accessor_class_g1_message_length{"g1_message_length"}; grib_accessor_class* grib_accessor_class_g1_message_length = &_grib_accessor_class_g1_message_length; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long len, grib_arguments* args) -{ - grib_accessor_g1_message_length* self = (grib_accessor_g1_message_length*)a; +void grib_accessor_class_g1_message_length_t::init(grib_accessor* a, const long len, grib_arguments* args){ + grib_accessor_class_section_length_t::init(a, len, args); + grib_accessor_g1_message_length_t* self = (grib_accessor_g1_message_length_t*)a; self->sec4_length = grib_arguments_get_name(grib_handle_of_accessor(a), args, 0); } @@ -148,9 +60,8 @@ int grib_get_g1_message_size(grib_handle* h, grib_accessor* tl, grib_accessor* s return GRIB_SUCCESS; } -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - grib_accessor_g1_message_length* self = (grib_accessor_g1_message_length*)a; +int grib_accessor_class_g1_message_length_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + grib_accessor_g1_message_length_t* self = (grib_accessor_g1_message_length_t*)a; /*grib_accessor_class* super = *(a->cclass->super);*/ /* Here we assume that the totalLength will be coded AFTER the section4 length, and @@ -182,7 +93,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) tlen = 0x800000 | t120; *len = 1; - if ((ret = grib_pack_long(s4, &slen, len)) != GRIB_SUCCESS) + if ((ret = s4->pack_long(&slen, len)) != GRIB_SUCCESS) return ret; *len = 1; @@ -211,9 +122,8 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) return GRIB_SUCCESS; } -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_g1_message_length* self = (grib_accessor_g1_message_length*)a; +int grib_accessor_class_g1_message_length_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_accessor_g1_message_length_t* self = (grib_accessor_g1_message_length_t*)a; int ret; long total_length, sec4_length; diff --git a/src/accessor/grib_accessor_class_g1_message_length.h b/src/accessor/grib_accessor_class_g1_message_length.h new file mode 100644 index 000000000..9a24e3213 --- /dev/null +++ b/src/accessor/grib_accessor_class_g1_message_length.h @@ -0,0 +1,31 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_section_length.h" + +class grib_accessor_g1_message_length_t : public grib_accessor_section_length_t +{ +public: + /* Members defined in g1_message_length */ + const char *sec4_length; +}; + +class grib_accessor_class_g1_message_length_t : public grib_accessor_class_section_length_t +{ +public: + grib_accessor_class_g1_message_length_t(const char* name) : grib_accessor_class_section_length_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g1_message_length_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_g1_section4_length.cc b/src/accessor/grib_accessor_class_g1_section4_length.cc new file mode 100644 index 000000000..8eea656b0 --- /dev/null +++ b/src/accessor/grib_accessor_class_g1_section4_length.cc @@ -0,0 +1,53 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_g1_section4_length.h" + +grib_accessor_class_g1_section4_length_t _grib_accessor_class_g1_section4_length{"g1_section4_length"}; +grib_accessor_class* grib_accessor_class_g1_section4_length = &_grib_accessor_class_g1_section4_length; + + +void grib_accessor_class_g1_section4_length_t::init(grib_accessor* a, const long len, grib_arguments* args){ + grib_accessor_class_section_length_t::init(a, len, args); + grib_accessor_g1_section4_length_t* self = (grib_accessor_g1_section4_length_t*)a; + self->total_length = grib_arguments_get_name(grib_handle_of_accessor(a), args, 0); +} + +int grib_accessor_class_g1_section4_length_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + // Old implementation: + // Here we assume that the totalLength will be coded AFTER the section4 length, and + // the section4 length will be overwritten by the totalLength accessor for large GRIBs + // grib_accessor_class* super = *(a->cclass->super); + // return super->pack_long(a,val,len); + + // Note: Do not directly call pack_long on base class + // because in this special case we want to skip the checks. + // So we call the helper function which has an extra argument + return pack_long_unsigned_helper(a, val, len, /*check=*/0); +} + +int grib_accessor_class_g1_section4_length_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_accessor_g1_section4_length_t* self = (grib_accessor_g1_section4_length_t*)a; + int ret = 0; + long total_length = 0, sec4_length = 0; + + if ((ret = grib_get_g1_message_size(grib_handle_of_accessor(a), + grib_find_accessor(grib_handle_of_accessor(a), self->total_length), + a, + &total_length, + &sec4_length)) != GRIB_SUCCESS) { + return ret; + } + + *val = sec4_length; + + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_g1_section4_length.h b/src/accessor/grib_accessor_class_g1_section4_length.h new file mode 100644 index 000000000..9e805985c --- /dev/null +++ b/src/accessor/grib_accessor_class_g1_section4_length.h @@ -0,0 +1,31 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_section_length.h" + +class grib_accessor_g1_section4_length_t : public grib_accessor_section_length_t +{ +public: + /* Members defined in g1_section4_length */ + const char* total_length; +}; + +class grib_accessor_class_g1_section4_length_t : public grib_accessor_class_section_length_t +{ +public: + grib_accessor_class_g1_section4_length_t(const char* name) : grib_accessor_class_section_length_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g1_section4_length_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_g1bitmap.cc b/src/accessor/grib_accessor_class_g1bitmap.cc new file mode 100644 index 000000000..e8c0645ad --- /dev/null +++ b/src/accessor/grib_accessor_class_g1bitmap.cc @@ -0,0 +1,98 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_g1bitmap.h" +#include "shared_functions.h" + +grib_accessor_class_g1bitmap_t _grib_accessor_class_g1bitmap{"g1bitmap"}; +grib_accessor_class* grib_accessor_class_g1bitmap = &_grib_accessor_class_g1bitmap; + + +void grib_accessor_class_g1bitmap_t::init(grib_accessor* a, const long len, grib_arguments* arg){ + grib_accessor_class_bitmap_t::init(a, len, arg); + grib_accessor_g1bitmap_t* self = (grib_accessor_g1bitmap_t*)a; + self->unusedBits = grib_arguments_get_name(grib_handle_of_accessor(a), arg, 4); +} + +int grib_accessor_class_g1bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len){ + grib_accessor_g1bitmap_t* self = (grib_accessor_g1bitmap_t*)a; + size_t tlen; + + unsigned char* buf = NULL; + size_t i; + int err = 0; + long pos = 0; + //long bmaplen = 0; + const int bit_padding = 16; + double miss_values = 0; + tlen = ((*len + bit_padding - 1) / bit_padding * bit_padding) / 8; + + if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value, &miss_values)) != GRIB_SUCCESS) + return err; + + buf = (unsigned char*)grib_context_malloc_clear(a->context, tlen); + if (!buf) + return GRIB_OUT_OF_MEMORY; + pos = 0; + for (i = 0; i < *len; i++) { + if (val[i] == miss_values) + pos++; + else { + //bmaplen++; + grib_set_bit_on(buf, &pos); + } + } + + if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->unusedBits, tlen * 8 - *len)) != GRIB_SUCCESS) + return err; + + err = grib_buffer_replace(a, buf, tlen, 1, 1); + if (err) return err; + + grib_context_free(a->context, buf); + + return GRIB_SUCCESS; +} + +int grib_accessor_class_g1bitmap_t::value_count(grib_accessor* a, long* count){ + grib_accessor_g1bitmap_t* self = (grib_accessor_g1bitmap_t*)a; + long tlen; + int err; + + 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; +} + +int grib_accessor_class_g1bitmap_t::unpack_bytes(grib_accessor* a, unsigned char* val, size_t* len){ + unsigned char* buf = grib_handle_of_accessor(a)->buffer->data; + grib_accessor_g1bitmap_t* self = (grib_accessor_g1bitmap_t*)a; + long tlen; + int err; + long length = a->byte_count(); long offset = a->byte_offset(); + if (*len < (size_t)length) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it is %ld bytes long\n", a->name, length); + *len = length; + return GRIB_ARRAY_TOO_SMALL; + } + + 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.unpack_bytes : cannot get %s err=%d", self->unusedBits, err); + + length -= tlen / 8; + memcpy(val, buf + offset, length); + *len = length; + + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_g1bitmap.h b/src/accessor/grib_accessor_class_g1bitmap.h new file mode 100644 index 000000000..28914c591 --- /dev/null +++ b/src/accessor/grib_accessor_class_g1bitmap.h @@ -0,0 +1,32 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_bitmap.h" + +class grib_accessor_g1bitmap_t : public grib_accessor_bitmap_t +{ +public: + /* Members defined in g1bitmap */ + const char* unusedBits; +}; + +class grib_accessor_class_g1bitmap_t : public grib_accessor_class_bitmap_t +{ +public: + grib_accessor_class_g1bitmap_t(const char* name) : grib_accessor_class_bitmap_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g1bitmap_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_bytes(grib_accessor*, unsigned char*, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_g1date.cc b/src/accessor/grib_accessor_class_g1date.cc similarity index 50% rename from src/grib_accessor_class_g1date.cc rename to src/accessor/grib_accessor_class_g1date.cc index c53b3768a..64631a1ea 100644 --- a/src/grib_accessor_class_g1date.cc +++ b/src/accessor/grib_accessor_class_g1date.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,110 +9,15 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long;pack_long;unpack_string - IMPLEMENTS = init;value_count - MEMBERS=const char* century - MEMBERS=const char* year - MEMBERS=const char* month - MEMBERS=const char* day - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g1date -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in g1date */ - const char* century; - const char* year; - const char* month; - const char* day; -} grib_accessor_g1date; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_g1date = { - &grib_accessor_class_long, /* super */ - "g1date", /* name */ - sizeof(grib_accessor_g1date), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_g1date.h" +grib_accessor_class_g1date_t _grib_accessor_class_g1date{"g1date"}; grib_accessor_class* grib_accessor_class_g1date = &_grib_accessor_class_g1date; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_g1date* self = (grib_accessor_g1date*)a; +void grib_accessor_class_g1date_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_long_t::init(a, l, c); + grib_accessor_g1date_t* self = (grib_accessor_g1date_t*)a; grib_handle* hand = grib_handle_of_accessor(a); int n = 0; @@ -121,9 +27,8 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) self->day = grib_arguments_get_name(hand, c, n++); } -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_g1date* self = (grib_accessor_g1date*)a; +int grib_accessor_class_g1date_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_accessor_g1date_t* self = (grib_accessor_g1date_t*)a; grib_handle* hand = grib_handle_of_accessor(a); int ret = 0; @@ -154,9 +59,8 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) return GRIB_SUCCESS; } -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - grib_accessor_g1date* self = (grib_accessor_g1date*)a; +int grib_accessor_class_g1date_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + grib_accessor_g1date_t* self = (grib_accessor_g1date_t*)a; grib_handle* hand = grib_handle_of_accessor(a); int ret = 0; @@ -168,7 +72,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) long d = grib_julian_to_date(grib_date_to_julian(v)); if (v != d) { - grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_g1date: pack_long invalid date %ld, changed to %ld", v, d); + grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_g1date_t: pack_long invalid date %ld, changed to %ld", v, d); return GRIB_ENCODING_ERROR; } @@ -212,9 +116,8 @@ static const char* months[] = { "dec", }; -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - grib_accessor_g1date* self = (grib_accessor_g1date*)a; +int grib_accessor_class_g1date_t::unpack_string(grib_accessor* a, char* val, size_t* len){ + grib_accessor_g1date_t* self = (grib_accessor_g1date_t*)a; grib_handle* hand = grib_handle_of_accessor(a); int ret = 0; @@ -256,8 +159,7 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len) return GRIB_SUCCESS; } -static int value_count(grib_accessor* a, long* count) -{ +int grib_accessor_class_g1date_t::value_count(grib_accessor* a, long* count){ *count = 1; return 0; } diff --git a/src/accessor/grib_accessor_class_g1date.h b/src/accessor/grib_accessor_class_g1date.h new file mode 100644 index 000000000..1195ac01c --- /dev/null +++ b/src/accessor/grib_accessor_class_g1date.h @@ -0,0 +1,36 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_g1date_t : public grib_accessor_long_t +{ +public: + /* Members defined in g1date */ + const char* century; + const char* year; + const char* month; + const char* day; +}; + +class grib_accessor_class_g1date_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_g1date_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g1date_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_g1day_of_the_year_date.cc b/src/accessor/grib_accessor_class_g1day_of_the_year_date.cc new file mode 100644 index 000000000..83d23ea92 --- /dev/null +++ b/src/accessor/grib_accessor_class_g1day_of_the_year_date.cc @@ -0,0 +1,60 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_g1day_of_the_year_date.h" + +grib_accessor_class_g1day_of_the_year_date_t _grib_accessor_class_g1day_of_the_year_date{"g1day_of_the_year_date"}; +grib_accessor_class* grib_accessor_class_g1day_of_the_year_date = &_grib_accessor_class_g1day_of_the_year_date; + + + +void grib_accessor_class_g1day_of_the_year_date_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_g1date_t::init(a, l, c); + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; +} + +void grib_accessor_class_g1day_of_the_year_date_t::dump(grib_accessor* a, grib_dumper* dumper){ + grib_dump_string(dumper, a, NULL); +} + +int grib_accessor_class_g1day_of_the_year_date_t::unpack_string(grib_accessor* a, char* val, size_t* len){ + /* special clim case where each mont have 30 days.. to comply with mars*/ + grib_accessor_g1day_of_the_year_date_t* self = (grib_accessor_g1day_of_the_year_date_t*)a; + grib_handle* hand = grib_handle_of_accessor(a); + char tmp[1024]; + + long year = 0; + long century = 0; + long month = 0; + long day = 0; + long fullyear = 0; + long fake_day_of_year = 0; + + grib_get_long_internal(hand, self->century, ¢ury); + grib_get_long_internal(hand, self->day, &day); + grib_get_long_internal(hand, self->month, &month); + grib_get_long_internal(hand, self->year, &year); + + fullyear = ((century - 1) * 100 + year); + fake_day_of_year = ((month - 1) * 30) + day; + snprintf(tmp, sizeof(tmp), "%04ld-%03ld", fullyear, fake_day_of_year); + + size_t l = strlen(tmp) + 1; + if (*len < l) { + *len = l; + return GRIB_BUFFER_TOO_SMALL; + } + + *len = l; + strcpy(val, tmp); + + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_g1day_of_the_year_date.h b/src/accessor/grib_accessor_class_g1day_of_the_year_date.h new file mode 100644 index 000000000..5e484686c --- /dev/null +++ b/src/accessor/grib_accessor_class_g1day_of_the_year_date.h @@ -0,0 +1,30 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_g1date.h" + +class grib_accessor_g1day_of_the_year_date_t : public grib_accessor_g1date_t +{ +public: + /* Members defined in g1day_of_the_year_date */ +}; + +class grib_accessor_class_g1day_of_the_year_date_t : public grib_accessor_class_g1date_t +{ +public: + grib_accessor_class_g1day_of_the_year_date_t(const char* name) : grib_accessor_class_g1date_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g1day_of_the_year_date_t{}; } + int unpack_string(grib_accessor*, char*, size_t* len) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_g1end_of_interval_monthly.cc b/src/accessor/grib_accessor_class_g1end_of_interval_monthly.cc new file mode 100644 index 000000000..ea48fc6cb --- /dev/null +++ b/src/accessor/grib_accessor_class_g1end_of_interval_monthly.cc @@ -0,0 +1,136 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_g1end_of_interval_monthly.h" + +grib_accessor_class_g1end_of_interval_monthly_t _grib_accessor_class_g1end_of_interval_monthly{"g1end_of_interval_monthly"}; +grib_accessor_class* grib_accessor_class_g1end_of_interval_monthly = &_grib_accessor_class_g1end_of_interval_monthly; + + +void grib_accessor_class_g1end_of_interval_monthly_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_abstract_vector_t::init(a, l, c); + grib_accessor_g1end_of_interval_monthly_t* self = (grib_accessor_g1end_of_interval_monthly_t*)a; + int n = 0; + + self->verifyingMonth = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; + a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; + + self->number_of_elements = 6; + self->v = (double*)grib_context_malloc(a->context, sizeof(double) * self->number_of_elements); + + a->length = 0; + a->dirty = 1; +} + +int grib_accessor_class_g1end_of_interval_monthly_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + grib_accessor_g1end_of_interval_monthly_t* self = (grib_accessor_g1end_of_interval_monthly_t*)a; + int ret = 0; + char verifyingMonth[7] = {0,}; + size_t slen = 7; + long year = 0, month = 0, date = 0; + const long mdays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + long days = 0; + + if (!a->dirty) + return GRIB_SUCCESS; + + if (*len != (size_t)self->number_of_elements) + return GRIB_ARRAY_TOO_SMALL; + + if ((ret = grib_get_string(grib_handle_of_accessor(a), self->verifyingMonth, verifyingMonth, &slen)) != GRIB_SUCCESS) + return ret; + + date = atoi(verifyingMonth); + if (date < 0) { + return GRIB_INVALID_ARGUMENT; + } + year = date / 100; + month = date - year * 100; + if (month == 2) { + days = 28; + if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) + days = 29; + } + else { + if (month < 1 || month > 12) return GRIB_INVALID_ARGUMENT; + days = mdays[month - 1]; + } + self->v[0] = year; + self->v[1] = month; + + self->v[2] = days; + self->v[3] = 24; + self->v[4] = 00; + self->v[5] = 00; + + a->dirty = 0; + + val[0] = self->v[0]; + val[1] = self->v[1]; + val[2] = self->v[2]; + val[3] = self->v[3]; + val[4] = self->v[4]; + val[5] = self->v[5]; + + return ret; +} + +int grib_accessor_class_g1end_of_interval_monthly_t::value_count(grib_accessor* a, long* count){ + grib_accessor_g1end_of_interval_monthly_t* self = (grib_accessor_g1end_of_interval_monthly_t*)a; + *count = self->number_of_elements; + return 0; +} + +void grib_accessor_class_g1end_of_interval_monthly_t::destroy(grib_context* c, grib_accessor* a){ + grib_accessor_g1end_of_interval_monthly_t* self = (grib_accessor_g1end_of_interval_monthly_t*)a; + grib_context_free(c, self->v); + grib_accessor_class_abstract_vector_t::destroy(c, a); +} + +int grib_accessor_class_g1end_of_interval_monthly_t::compare(grib_accessor* a, grib_accessor* b){ + int retval = GRIB_SUCCESS; + double* aval = 0; + double* bval = 0; + + long count = 0; + size_t alen = 0; + size_t blen = 0; + int err = 0; + + err = a->value_count(&count); if (err) + return err; + alen = count; + + err = b->value_count(&count); if (err) + return err; + blen = count; + + if (alen != blen) + return GRIB_COUNT_MISMATCH; + + aval = (double*)grib_context_malloc(a->context, alen * sizeof(double)); + bval = (double*)grib_context_malloc(b->context, blen * sizeof(double)); + + b->dirty = 1; + a->dirty = 1; + + err = a->unpack_double(aval, &alen); err = b->unpack_double(bval, &blen); + for(size_t i=0; icontext, aval); + grib_context_free(b->context, bval); + + return retval; +} diff --git a/src/accessor/grib_accessor_class_g1end_of_interval_monthly.h b/src/accessor/grib_accessor_class_g1end_of_interval_monthly.h new file mode 100644 index 000000000..baaea5320 --- /dev/null +++ b/src/accessor/grib_accessor_class_g1end_of_interval_monthly.h @@ -0,0 +1,33 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_abstract_vector.h" + +class grib_accessor_g1end_of_interval_monthly_t : public grib_accessor_abstract_vector_t +{ +public: + /* Members defined in g1end_of_interval_monthly */ + const char* verifyingMonth; +}; + +class grib_accessor_class_g1end_of_interval_monthly_t : public grib_accessor_class_abstract_vector_t +{ +public: + grib_accessor_class_g1end_of_interval_monthly_t(const char* name) : grib_accessor_class_abstract_vector_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g1end_of_interval_monthly_t{}; } + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void destroy(grib_context*, grib_accessor*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + int compare(grib_accessor*, grib_accessor*) override; +}; diff --git a/src/accessor/grib_accessor_class_g1fcperiod.cc b/src/accessor/grib_accessor_class_g1fcperiod.cc new file mode 100644 index 000000000..fcf98d78d --- /dev/null +++ b/src/accessor/grib_accessor_class_g1fcperiod.cc @@ -0,0 +1,41 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_g1fcperiod.h" + +grib_accessor_class_g1fcperiod_t _grib_accessor_class_g1fcperiod{"g1fcperiod"}; +grib_accessor_class* grib_accessor_class_g1fcperiod = &_grib_accessor_class_g1fcperiod; + + +int grib_accessor_class_g1fcperiod_t::unpack_string(grib_accessor* a, char* val, size_t* len){ + long start = 0, theEnd = 0; + char tmp[1024]; + const size_t tmpLen = sizeof(tmp); + int err = grib_g1_step_get_steps(a, &start, &theEnd); + size_t l = 0; + + if (err) + return err; + + snprintf(tmp, tmpLen, "%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; + } + + *len = l; + strcpy(val, tmp); /* NOLINT: CWE-119 clang-analyzer-security.insecureAPI.strcpy */ + + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_g1fcperiod.h b/src/accessor/grib_accessor_class_g1fcperiod.h new file mode 100644 index 000000000..1b5b8dc7e --- /dev/null +++ b/src/accessor/grib_accessor_class_g1fcperiod.h @@ -0,0 +1,28 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_g1step_range.h" + +class grib_accessor_g1fcperiod_t : public grib_accessor_g1step_range_t +{ +public: + /* Members defined in g1fcperiod */ +}; + +class grib_accessor_class_g1fcperiod_t : public grib_accessor_class_g1step_range_t +{ +public: + grib_accessor_class_g1fcperiod_t(const char* name) : grib_accessor_class_g1step_range_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g1fcperiod_t{}; } + int unpack_string(grib_accessor*, char*, size_t* len) override; +}; diff --git a/src/grib_accessor_class_g1forecastmonth.cc b/src/accessor/grib_accessor_class_g1forecastmonth.cc similarity index 54% rename from src/grib_accessor_class_g1forecastmonth.cc rename to src/accessor/grib_accessor_class_g1forecastmonth.cc index e25db6930..7ec448cf6 100644 --- a/src/grib_accessor_class_g1forecastmonth.cc +++ b/src/accessor/grib_accessor_class_g1forecastmonth.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,113 +9,16 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = init;dump - MEMBERS=const char* verification_yearmonth - MEMBERS=const char* base_date - MEMBERS=const char* day - MEMBERS=const char* hour - MEMBERS=const char* fcmonth - MEMBERS=const char* check - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g1forecastmonth -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in g1forecastmonth */ - const char* verification_yearmonth; - const char* base_date; - const char* day; - const char* hour; - const char* fcmonth; - const char* check; -} grib_accessor_g1forecastmonth; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_g1forecastmonth = { - &grib_accessor_class_long, /* super */ - "g1forecastmonth", /* name */ - sizeof(grib_accessor_g1forecastmonth), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_g1forecastmonth.h" +grib_accessor_class_g1forecastmonth_t _grib_accessor_class_g1forecastmonth{ "g1forecastmonth" }; grib_accessor_class* grib_accessor_class_g1forecastmonth = &_grib_accessor_class_g1forecastmonth; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_class_g1forecastmonth_t::init(grib_accessor* a, const long l, grib_arguments* c) { - grib_accessor_g1forecastmonth* self = (grib_accessor_g1forecastmonth*)a; + grib_accessor_class_long_t::init(a, l, c); + grib_accessor_g1forecastmonth_t* self = (grib_accessor_g1forecastmonth_t*)a; grib_handle* h = grib_handle_of_accessor(a); int n = 0; const int count = grib_arguments_get_count(c); @@ -128,7 +32,7 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) } } -static void dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_class_g1forecastmonth_t::dump(grib_accessor* a, grib_dumper* dumper) { grib_dump_long(dumper, a, NULL); } @@ -136,11 +40,11 @@ static void dump(grib_accessor* a, grib_dumper* dumper) static int calculate_fcmonth(grib_accessor* a, long verification_yearmonth, long base_date, long day, long hour, long* result) { long base_yearmonth = 0; - long vyear = 0; - long vmonth = 0; - long byear = 0; - long bmonth = 0; - long fcmonth = 0; + long vyear = 0; + long vmonth = 0; + long byear = 0; + long bmonth = 0; + long fcmonth = 0; base_yearmonth = base_date / 100; @@ -167,10 +71,10 @@ static int unpack_long_edition2(grib_accessor* a, long* val, size_t* len) long forecastTime, indicatorOfUnitOfTimeRange; double jul_base, jul2, dstep; - if ((err = grib_get_long(h, "year", &year)) != GRIB_SUCCESS) return err; + if ((err = grib_get_long(h, "year", &year)) != GRIB_SUCCESS) return err; if ((err = grib_get_long(h, "month", &month)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long(h, "day", &day)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long(h, "hour", &hour)) != GRIB_SUCCESS) return err; + if ((err = grib_get_long(h, "day", &day)) != GRIB_SUCCESS) return err; + if ((err = grib_get_long(h, "hour", &hour)) != GRIB_SUCCESS) return err; if ((err = grib_get_long(h, "minute", &minute)) != GRIB_SUCCESS) return err; if ((err = grib_get_long(h, "second", &second)) != GRIB_SUCCESS) return err; @@ -190,30 +94,30 @@ static int unpack_long_edition2(grib_accessor* a, long* val, size_t* len) return err; dstep = (((double)forecastTime) * 3600) / 86400; /* as a fraction of a day */ - jul2 = jul_base + dstep; + jul2 = jul_base + dstep; if ((err = grib_julian_to_datetime(jul2, &year2, &month2, &day2, &hour2, &minute2, &second2)) != GRIB_SUCCESS) return err; - verification_yearmonth = year2*100 + month2; + verification_yearmonth = year2 * 100 + month2; if ((err = calculate_fcmonth(a, verification_yearmonth, dataDate, day, hour, val)) != GRIB_SUCCESS) return err; return GRIB_SUCCESS; } -static int unpack_long_edition1(grib_accessor* a, long* val, size_t* len) +int unpack_long_edition1(grib_accessor* a, long* val, size_t* len) { int err = 0; - grib_accessor_g1forecastmonth* self = (grib_accessor_g1forecastmonth*)a; + grib_accessor_g1forecastmonth_t* self = (grib_accessor_g1forecastmonth_t*)a; long verification_yearmonth = 0; long base_date = 0; long day = 0; long hour = 0; - long gribForecastMonth = 0; - long check = 0; - long fcmonth = 0; + long gribForecastMonth = 0; + long check = 0; + long fcmonth = 0; if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->verification_yearmonth, &verification_yearmonth)) != GRIB_SUCCESS) @@ -249,11 +153,11 @@ static int unpack_long_edition1(grib_accessor* a, long* val, size_t* len) return GRIB_SUCCESS; } -static int unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_class_g1forecastmonth_t::unpack_long(grib_accessor* a, long* val, size_t* len) { - int err = 0; + int err = 0; grib_handle* hand = grib_handle_of_accessor(a); - long edition = 0; + long edition = 0; if ((err = grib_get_long(hand, "edition", &edition)) != GRIB_SUCCESS) return err; @@ -267,8 +171,8 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) } /* TODO: Check for a valid date */ -static int pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_class_g1forecastmonth_t::pack_long(grib_accessor* a, const long* val, size_t* len) { - grib_accessor_g1forecastmonth* self = (grib_accessor_g1forecastmonth*)a; + grib_accessor_g1forecastmonth_t* self = (grib_accessor_g1forecastmonth_t*)a; return grib_set_long_internal(grib_handle_of_accessor(a), self->fcmonth, *val); } diff --git a/src/accessor/grib_accessor_class_g1forecastmonth.h b/src/accessor/grib_accessor_class_g1forecastmonth.h new file mode 100644 index 000000000..cd3a6d5f6 --- /dev/null +++ b/src/accessor/grib_accessor_class_g1forecastmonth.h @@ -0,0 +1,37 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_g1forecastmonth_t : public grib_accessor_long_t +{ +public: + /* Members defined in g1forecastmonth */ + const char* verification_yearmonth; + const char* base_date; + const char* day; + const char* hour; + const char* fcmonth; + const char* check; +}; + +class grib_accessor_class_g1forecastmonth_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_g1forecastmonth_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g1forecastmonth_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_g1monthlydate.cc b/src/accessor/grib_accessor_class_g1monthlydate.cc new file mode 100644 index 000000000..420f96ef3 --- /dev/null +++ b/src/accessor/grib_accessor_class_g1monthlydate.cc @@ -0,0 +1,41 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_g1monthlydate.h" + +grib_accessor_class_g1monthlydate_t _grib_accessor_class_g1monthlydate{"g1monthlydate"}; +grib_accessor_class* grib_accessor_class_g1monthlydate = &_grib_accessor_class_g1monthlydate; + + +void grib_accessor_class_g1monthlydate_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_long_t::init(a, l, c); + grib_accessor_g1monthlydate_t* self = (grib_accessor_g1monthlydate_t*)a; + int n = 0; + + self->date = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; +} + +int grib_accessor_class_g1monthlydate_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_accessor_g1monthlydate_t* self = (grib_accessor_g1monthlydate_t*)a; + + long date = 0; + + grib_get_long_internal(grib_handle_of_accessor(a), self->date, &date); + + date /= 100; + date *= 100; + date += 1; + + *val = date; + + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_g1monthlydate.h b/src/accessor/grib_accessor_class_g1monthlydate.h new file mode 100644 index 000000000..8503fa0af --- /dev/null +++ b/src/accessor/grib_accessor_class_g1monthlydate.h @@ -0,0 +1,30 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_g1monthlydate_t : public grib_accessor_long_t +{ +public: + /* Members defined in g1monthlydate */ + const char* date; +}; + +class grib_accessor_class_g1monthlydate_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_g1monthlydate_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g1monthlydate_t{}; } + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_complex.cc b/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_complex.cc new file mode 100644 index 000000000..9976ad812 --- /dev/null +++ b/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_complex.cc @@ -0,0 +1,81 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_g1number_of_coded_values_sh_complex.h" + +grib_accessor_class_g1number_of_coded_values_sh_complex_t _grib_accessor_class_g1number_of_coded_values_sh_complex{"g1number_of_coded_values_sh_complex"}; +grib_accessor_class* grib_accessor_class_g1number_of_coded_values_sh_complex = &_grib_accessor_class_g1number_of_coded_values_sh_complex; + + +void grib_accessor_class_g1number_of_coded_values_sh_complex_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_long_t::init(a, l, c); + int n = 0; + grib_accessor_g1number_of_coded_values_sh_complex_t* self = (grib_accessor_g1number_of_coded_values_sh_complex_t*)a; + self->bitsPerValue = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->offsetBeforeData = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->offsetAfterData = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->unusedBits = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->numberOfValues = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->JS = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->KS = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->MS = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; + a->length = 0; +} + +int grib_accessor_class_g1number_of_coded_values_sh_complex_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + int ret = GRIB_SUCCESS; + long bpv = 0; + long offsetBeforeData = 0, offsetAfterData = 0, unusedBits = 0, numberOfValues; + long JS = 0, KS = 0, MS = 0, NS = 0; + + grib_accessor_g1number_of_coded_values_sh_complex_t* self = (grib_accessor_g1number_of_coded_values_sh_complex_t*)a; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bitsPerValue, &bpv)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetBeforeData, &offsetBeforeData)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetAfterData, &offsetAfterData)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->unusedBits, &unusedBits)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->JS, &JS)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->KS, &KS)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->MS, &MS)) != GRIB_SUCCESS) + return ret; + + if (JS != KS || KS != MS) + return GRIB_NOT_IMPLEMENTED; + + NS = (MS + 1) * (MS + 2); + + if (bpv != 0) { + DEBUG_ASSERT(offsetAfterData > offsetBeforeData); + *val = ((offsetAfterData - offsetBeforeData) * 8 - unusedBits + NS * (bpv - 32)) / bpv; + } + else { + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfValues, &numberOfValues)) != GRIB_SUCCESS) + return ret; + + *val = numberOfValues; + } + + return ret; +} diff --git a/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_complex.h b/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_complex.h new file mode 100644 index 000000000..97379631d --- /dev/null +++ b/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_complex.h @@ -0,0 +1,37 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_g1number_of_coded_values_sh_complex_t : public grib_accessor_long_t +{ +public: + /* Members defined in g1number_of_coded_values_sh_complex */ + const char* numberOfValues; + const char* bitsPerValue; + const char* offsetBeforeData; + const char* offsetAfterData; + const char* unusedBits; + const char* JS; + const char* KS; + const char* MS; +}; + +class grib_accessor_class_g1number_of_coded_values_sh_complex_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_g1number_of_coded_values_sh_complex_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g1number_of_coded_values_sh_complex_t{}; } + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_simple.cc b/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_simple.cc new file mode 100644 index 000000000..802e6ceb7 --- /dev/null +++ b/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_simple.cc @@ -0,0 +1,62 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_g1number_of_coded_values_sh_simple.h" + +grib_accessor_class_g1number_of_coded_values_sh_simple_t _grib_accessor_class_g1number_of_coded_values_sh_simple{"g1number_of_coded_values_sh_simple"}; +grib_accessor_class* grib_accessor_class_g1number_of_coded_values_sh_simple = &_grib_accessor_class_g1number_of_coded_values_sh_simple; + + +void grib_accessor_class_g1number_of_coded_values_sh_simple_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_long_t::init(a, l, c); + int n = 0; + grib_accessor_g1number_of_coded_values_sh_simple_t* self = (grib_accessor_g1number_of_coded_values_sh_simple_t*)a; + self->bitsPerValue = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->offsetBeforeData = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->offsetAfterData = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->unusedBits = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->numberOfValues = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; + a->length = 0; +} + +int grib_accessor_class_g1number_of_coded_values_sh_simple_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + int ret = GRIB_SUCCESS; + long bpv = 0; + long offsetBeforeData = 0, offsetAfterData = 0, unusedBits = 0, numberOfValues; + + grib_accessor_g1number_of_coded_values_sh_simple_t* self = (grib_accessor_g1number_of_coded_values_sh_simple_t*)a; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bitsPerValue, &bpv)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetBeforeData, &offsetBeforeData)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetAfterData, &offsetAfterData)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->unusedBits, &unusedBits)) != GRIB_SUCCESS) + return ret; + + if (bpv != 0) { + DEBUG_ASSERT(offsetAfterData > offsetBeforeData); + *val = ((offsetAfterData - offsetBeforeData) * 8 - unusedBits) / bpv; + } + else { + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfValues, &numberOfValues)) != GRIB_SUCCESS) + return ret; + + *val = numberOfValues; + } + return ret; +} diff --git a/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_simple.h b/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_simple.h new file mode 100644 index 000000000..4dafe6b15 --- /dev/null +++ b/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_simple.h @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_g1number_of_coded_values_sh_simple_t : public grib_accessor_long_t +{ +public: + /* Members defined in g1number_of_coded_values_sh_simple */ + const char* numberOfValues; + const char* bitsPerValue; + const char* offsetBeforeData; + const char* offsetAfterData; + const char* unusedBits; +}; + +class grib_accessor_class_g1number_of_coded_values_sh_simple_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_g1number_of_coded_values_sh_simple_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g1number_of_coded_values_sh_simple_t{}; } + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_g1step_range.cc b/src/accessor/grib_accessor_class_g1step_range.cc similarity index 78% rename from src/grib_accessor_class_g1step_range.cc rename to src/accessor/grib_accessor_class_g1step_range.cc index 46c7a3cc8..a2920a1cf 100644 --- a/src/grib_accessor_class_g1step_range.cc +++ b/src/accessor/grib_accessor_class_g1step_range.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,131 +9,15 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -/********************************************* - * Enrico Fucile - *******************************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_abstract_long_vector - IMPLEMENTS = pack_string;unpack_string;value_count - IMPLEMENTS = pack_long;unpack_long;dump - IMPLEMENTS = get_native_type;string_length - IMPLEMENTS = init; destroy - MEMBERS = const char* p1 - MEMBERS = const char* p2 - MEMBERS = const char* timeRangeIndicator - MEMBERS = const char *unit - MEMBERS = const char *step_unit - MEMBERS = const char *stepType - MEMBERS = const char *patch_fp_precip - MEMBERS = int error_on_units - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int pack_string(grib_accessor*, const char*, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static size_t string_length(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void destroy(grib_context*, grib_accessor*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g1step_range -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in abstract_long_vector */ - long* v; - long pack_index; - int number_of_elements; - /* Members defined in g1step_range */ - const char* p1; - const char* p2; - const char* timeRangeIndicator; - const char *unit; - const char *step_unit; - const char *stepType; - const char *patch_fp_precip; - int error_on_units; -} grib_accessor_g1step_range; - -extern grib_accessor_class* grib_accessor_class_abstract_long_vector; - -static grib_accessor_class _grib_accessor_class_g1step_range = { - &grib_accessor_class_abstract_long_vector, /* super */ - "g1step_range", /* name */ - sizeof(grib_accessor_g1step_range), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - &destroy, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - &string_length, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - &pack_string, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_g1step_range.h" +grib_accessor_class_g1step_range_t _grib_accessor_class_g1step_range{"g1step_range"}; grib_accessor_class* grib_accessor_class_g1step_range = &_grib_accessor_class_g1step_range; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_g1step_range* self = (grib_accessor_g1step_range*)a; +void grib_accessor_class_g1step_range_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_abstract_long_vector_t::init(a, l, c); + grib_accessor_g1step_range_t* self = (grib_accessor_g1step_range_t*)a; grib_handle* h = grib_handle_of_accessor(a); int n = 0; self->p1 = grib_arguments_get_name(h, c, n++); @@ -153,8 +38,7 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) a->length = 0; } -static void dump(grib_accessor* a, grib_dumper* dumper) -{ +void grib_accessor_class_g1step_range_t::dump(grib_accessor* a, grib_dumper* dumper){ grib_dump_string(dumper, a, NULL); } @@ -203,7 +87,7 @@ static const int u2s[] = { int grib_g1_step_get_steps(grib_accessor* a, long* start, long* theEnd) { - grib_accessor_g1step_range* self = (grib_accessor_g1step_range*)a; + grib_accessor_g1step_range_t* self = (grib_accessor_g1step_range_t*)a; int err = 0; long p1 = 0, p2 = 0, unit = 0, timeRangeIndicator = 0, timeRangeIndicatorFromStepRange = 0; long step_unit = 1; @@ -298,9 +182,8 @@ int grib_g1_step_get_steps(grib_accessor* a, long* start, long* theEnd) return 0; } -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - grib_accessor_g1step_range* self = (grib_accessor_g1step_range*)a; +int grib_accessor_class_g1step_range_t::unpack_string(grib_accessor* a, char* val, size_t* len){ + grib_accessor_g1step_range_t* self = (grib_accessor_g1step_range_t*)a; char buf[100]; size_t size = 0; long start = 0, theEnd = 0; @@ -450,9 +333,8 @@ static int grib_g1_step_apply_units( return GRIB_WRONG_STEP; } -static int pack_string(grib_accessor* a, const char* val, size_t* len) -{ - grib_accessor_g1step_range* self = (grib_accessor_g1step_range*)a; +int grib_accessor_class_g1step_range_t::pack_string(grib_accessor* a, const char* val, size_t* len){ + grib_accessor_g1step_range_t* self = (grib_accessor_g1step_range_t*)a; grib_handle* h = grib_handle_of_accessor(a); long timeRangeIndicator = 0, P1 = 0, P2 = 0; long start = 0, theEnd = -1, unit = 0, ounit = 0, step_unit = 1; @@ -631,25 +513,22 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len) return 0; } -static int value_count(grib_accessor* a, long* count) -{ +int grib_accessor_class_g1step_range_t::value_count(grib_accessor* a, long* count){ *count = 1; return 0; } -static size_t string_length(grib_accessor* a) -{ +size_t grib_accessor_class_g1step_range_t::string_length(grib_accessor* a){ return 255; } -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ +int grib_accessor_class_g1step_range_t::pack_long(grib_accessor* a, const long* val, size_t* len){ char buff[256]; size_t bufflen = 100; char sval[100] = { 0 }; char* p = sval; size_t svallen = 100; - grib_accessor_g1step_range* self = (grib_accessor_g1step_range*)a; + grib_accessor_g1step_range_t* self = (grib_accessor_g1step_range_t*)a; char stepType[20] = {0,}; size_t stepTypeLen = 20; long step_unit = 0; @@ -718,9 +597,8 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) return GRIB_INTERNAL_ERROR; } -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_g1step_range* self = (grib_accessor_g1step_range*)a; +int grib_accessor_class_g1step_range_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_accessor_g1step_range_t* self = (grib_accessor_g1step_range_t*)a; char buff[100]; size_t bufflen = 100; long start, theEnd; @@ -749,13 +627,12 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) return 0; } -static int get_native_type(grib_accessor* a) -{ +int grib_accessor_class_g1step_range_t::get_native_type(grib_accessor* a){ return GRIB_TYPE_STRING; } -static void destroy(grib_context* c, grib_accessor* a) -{ - grib_accessor_g1step_range* self = (grib_accessor_g1step_range*)a; +void grib_accessor_class_g1step_range_t::destroy(grib_context* c, grib_accessor* a){ + grib_accessor_g1step_range_t* self = (grib_accessor_g1step_range_t*)a; grib_context_free(c, self->v); + grib_accessor_class_abstract_long_vector_t::destroy(c, a); } diff --git a/src/accessor/grib_accessor_class_g1step_range.h b/src/accessor/grib_accessor_class_g1step_range.h new file mode 100644 index 000000000..7ca19cb08 --- /dev/null +++ b/src/accessor/grib_accessor_class_g1step_range.h @@ -0,0 +1,45 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_abstract_long_vector.h" + +class grib_accessor_g1step_range_t : public grib_accessor_abstract_long_vector_t +{ +public: + /* Members defined in g1step_range */ + const char* p1; + const char* p2; + const char* timeRangeIndicator; + const char *unit; + const char *step_unit; + const char *stepType; + const char *patch_fp_precip; + int error_on_units; +}; + +class grib_accessor_class_g1step_range_t : public grib_accessor_class_abstract_long_vector_t +{ +public: + grib_accessor_class_g1step_range_t(const char* name) : grib_accessor_class_abstract_long_vector_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g1step_range_t{}; } + int get_native_type(grib_accessor*) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int pack_string(grib_accessor*, const char*, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + size_t string_length(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void destroy(grib_context*, grib_accessor*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_g1verificationdate.cc b/src/accessor/grib_accessor_class_g1verificationdate.cc new file mode 100644 index 000000000..63a1f1356 --- /dev/null +++ b/src/accessor/grib_accessor_class_g1verificationdate.cc @@ -0,0 +1,64 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_g1verificationdate.h" + +grib_accessor_class_g1verificationdate_t _grib_accessor_class_g1verificationdate{"g1verificationdate"}; +grib_accessor_class* grib_accessor_class_g1verificationdate = &_grib_accessor_class_g1verificationdate; + + +void grib_accessor_class_g1verificationdate_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_long_t::init(a, l, c); + grib_accessor_g1verificationdate_t* self = (grib_accessor_g1verificationdate_t*)a; + int n = 0; + + self->date = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->time = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->step = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; +} + +int grib_accessor_class_g1verificationdate_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_accessor_g1verificationdate_t* self = (grib_accessor_g1verificationdate_t*)a; + int ret = 0; + long date = 0; + long time = 0; + long cdate = 0; + long step = 0; + long vtime = 0; + long vdate = 0; + long vd = 0; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->date, &date)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->time, &time)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->step, &step)) != GRIB_SUCCESS) + return ret; + + time /= 100; + + cdate = (long)grib_date_to_julian(date); + vtime = cdate * 24 + time + step; + vd = vtime / 24; + vdate = grib_julian_to_date(vd); + + /* printf("\n********\n date %d, time %d, step %d, vdate: %d, cdate %d, vd %d\n********\n", date, time, step, vdate, cdate, vd); */ + + if (*len < 1) + return GRIB_ARRAY_TOO_SMALL; + + *val = vdate; + + /* fprintf(stdout,"\n********\n %d cdate %d vd %d\n********\n", vdate, cdate, step); */ + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_g1verificationdate.h b/src/accessor/grib_accessor_class_g1verificationdate.h new file mode 100644 index 000000000..0e0469926 --- /dev/null +++ b/src/accessor/grib_accessor_class_g1verificationdate.h @@ -0,0 +1,32 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_g1verificationdate_t : public grib_accessor_long_t +{ +public: + /* Members defined in g1verificationdate */ + const char* date; + const char* time; + const char* step; +}; + +class grib_accessor_class_g1verificationdate_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_g1verificationdate_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g1verificationdate_t{}; } + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_g2_aerosol.cc b/src/accessor/grib_accessor_class_g2_aerosol.cc new file mode 100644 index 000000000..464563187 --- /dev/null +++ b/src/accessor/grib_accessor_class_g2_aerosol.cc @@ -0,0 +1,114 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_g2_aerosol.h" + +grib_accessor_class_g2_aerosol_t _grib_accessor_class_g2_aerosol{"g2_aerosol"}; +grib_accessor_class* grib_accessor_class_g2_aerosol = &_grib_accessor_class_g2_aerosol; + + +void grib_accessor_class_g2_aerosol_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_unsigned_t::init(a, l, c); + grib_accessor_g2_aerosol_t* self = (grib_accessor_g2_aerosol_t*)a; + grib_handle* hand = grib_handle_of_accessor(a); + int n = 0; + + self->productDefinitionTemplateNumber = grib_arguments_get_name(hand, c, n++); + self->stepType = grib_arguments_get_name(hand, c, n++); + self->optical = grib_arguments_get_long(hand, c, n++); +} + +int grib_accessor_class_g2_aerosol_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_accessor_g2_aerosol_t* self = (grib_accessor_g2_aerosol_t*)a; + long productDefinitionTemplateNumber = 0; + grib_get_long(grib_handle_of_accessor(a), self->productDefinitionTemplateNumber, &productDefinitionTemplateNumber); + + if (self->optical) + *val = grib2_is_PDTN_AerosolOptical(productDefinitionTemplateNumber); + else + *val = grib2_is_PDTN_Aerosol(productDefinitionTemplateNumber); + + return GRIB_SUCCESS; +} + +int grib_accessor_class_g2_aerosol_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + grib_accessor_g2_aerosol_t* self = (grib_accessor_g2_aerosol_t*)a; + grib_handle* hand = grib_handle_of_accessor(a); + long productDefinitionTemplateNumber = -1; + long productDefinitionTemplateNumberNew = -1; + /*long type=-1; + long stream=-1;*/ + long eps = -1; + char stepType[15] = {0,}; + size_t slen = 15; + /*int aerosol = *val;*/ + int isInstant = 0; + /*long derivedForecast=-1;*/ + int ret = 0; + + if (grib_get_long(hand, self->productDefinitionTemplateNumber, &productDefinitionTemplateNumber) != GRIB_SUCCESS) + return GRIB_SUCCESS; + + /* + grib_get_long(hand, self->type,&type); + grib_get_long(hand, self->stream,&stream); + */ + ret = grib_get_string(hand, self->stepType, stepType, &slen); + Assert(ret == GRIB_SUCCESS); + + //eps = grib2_is_PDTN_EPS(productDefinitionTemplateNumber); + eps = grib_is_defined(hand, "perturbationNumber"); + + if (!strcmp(stepType, "instant")) + isInstant = 1; + + if (eps == 1) { + if (isInstant) { + productDefinitionTemplateNumberNew = 45; + } + else { + /*productDefinitionTemplateNumberNew = 47; PDT deprecated*/ + productDefinitionTemplateNumberNew = 85; + } + } + else { + if (isInstant) { + productDefinitionTemplateNumberNew = 48; /*44 is deprecated*/ + } + else { + productDefinitionTemplateNumberNew = 46; + } + } + + if (self->optical) { + /* Note: There is no interval based template for optical properties of aerosol! */ + if (eps) + productDefinitionTemplateNumberNew = 49; + else + productDefinitionTemplateNumberNew = 48; + if (!isInstant) { + grib_context_log(hand->context, GRIB_LOG_ERROR, + "The product definition templates for optical properties of aerosol are for a point-in-time only"); + } + } + + if (productDefinitionTemplateNumber != productDefinitionTemplateNumberNew) { + grib_set_long(hand, self->productDefinitionTemplateNumber, productDefinitionTemplateNumberNew); + /*if (derivedForecast>=0) grib_set_long(hand, self->derivedForecast,derivedForecast);*/ + } + + return 0; +} + +int grib_accessor_class_g2_aerosol_t::value_count(grib_accessor* a, long* count){ + *count = 1; + return 0; +} diff --git a/src/accessor/grib_accessor_class_g2_aerosol.h b/src/accessor/grib_accessor_class_g2_aerosol.h new file mode 100644 index 000000000..9fbd0c79b --- /dev/null +++ b/src/accessor/grib_accessor_class_g2_aerosol.h @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_unsigned.h" + +class grib_accessor_g2_aerosol_t : public grib_accessor_unsigned_t +{ +public: + /* Members defined in g2_aerosol */ + const char* productDefinitionTemplateNumber; + const char* stepType; + int optical; +}; + +class grib_accessor_class_g2_aerosol_t : public grib_accessor_class_unsigned_t +{ +public: + grib_accessor_class_g2_aerosol_t(const char* name) : grib_accessor_class_unsigned_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g2_aerosol_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_g2_chemical.cc b/src/accessor/grib_accessor_class_g2_chemical.cc similarity index 53% rename from src/grib_accessor_class_g2_chemical.cc rename to src/accessor/grib_accessor_class_g2_chemical.cc index 16d8e6f33..3d05886a5 100644 --- a/src/grib_accessor_class_g2_chemical.cc +++ b/src/accessor/grib_accessor_class_g2_chemical.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,109 +9,15 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_unsigned - IMPLEMENTS = unpack_long;pack_long; value_count - IMPLEMENTS = init - MEMBERS=const char* productDefinitionTemplateNumber - MEMBERS=const char* stepType - MEMBERS=int chemical_type - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g2_chemical -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in unsigned */ - long nbytes; - grib_arguments* arg; - /* Members defined in g2_chemical */ - const char* productDefinitionTemplateNumber; - const char* stepType; - int chemical_type; -} grib_accessor_g2_chemical; - -extern grib_accessor_class* grib_accessor_class_unsigned; - -static grib_accessor_class _grib_accessor_class_g2_chemical = { - &grib_accessor_class_unsigned, /* super */ - "g2_chemical", /* name */ - sizeof(grib_accessor_g2_chemical), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_g2_chemical.h" +grib_accessor_class_g2_chemical_t _grib_accessor_class_g2_chemical{"g2_chemical"}; grib_accessor_class* grib_accessor_class_g2_chemical = &_grib_accessor_class_g2_chemical; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_g2_chemical* self = (grib_accessor_g2_chemical*)a; +void grib_accessor_class_g2_chemical_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_unsigned_t::init(a, l, c); + grib_accessor_g2_chemical_t* self = (grib_accessor_g2_chemical_t*)a; grib_handle* hand = grib_handle_of_accessor(a); int n = 0; @@ -119,9 +26,8 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) self->chemical_type = grib_arguments_get_long(hand, c, n++); } -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_g2_chemical* self = (grib_accessor_g2_chemical*)a; +int grib_accessor_class_g2_chemical_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_accessor_g2_chemical_t* self = (grib_accessor_g2_chemical_t*)a; long productDefinitionTemplateNumber = 0; grib_get_long(grib_handle_of_accessor(a), self->productDefinitionTemplateNumber, &productDefinitionTemplateNumber); @@ -141,9 +47,8 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) return GRIB_SUCCESS; } -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - grib_accessor_g2_chemical* self = (grib_accessor_g2_chemical*)a; +int grib_accessor_class_g2_chemical_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + grib_accessor_g2_chemical_t* self = (grib_accessor_g2_chemical_t*)a; grib_handle* hand = grib_handle_of_accessor(a); long productDefinitionTemplateNumber = -1; long productDefinitionTemplateNumberNew = -1; @@ -214,8 +119,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) return 0; } -static int value_count(grib_accessor* a, long* count) -{ +int grib_accessor_class_g2_chemical_t::value_count(grib_accessor* a, long* count){ *count = 1; return 0; } diff --git a/src/accessor/grib_accessor_class_g2_chemical.h b/src/accessor/grib_accessor_class_g2_chemical.h new file mode 100644 index 000000000..66bf945aa --- /dev/null +++ b/src/accessor/grib_accessor_class_g2_chemical.h @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_unsigned.h" + +class grib_accessor_g2_chemical_t : public grib_accessor_unsigned_t +{ +public: + /* Members defined in g2_chemical */ + const char* productDefinitionTemplateNumber; + const char* stepType; + int chemical_type; +}; + +class grib_accessor_class_g2_chemical_t : public grib_accessor_class_unsigned_t +{ +public: + grib_accessor_class_g2_chemical_t(const char* name) : grib_accessor_class_unsigned_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g2_chemical_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_g2_eps.cc b/src/accessor/grib_accessor_class_g2_eps.cc similarity index 57% rename from src/grib_accessor_class_g2_eps.cc rename to src/accessor/grib_accessor_class_g2_eps.cc index fc202a572..6b6c42fd7 100644 --- a/src/grib_accessor_class_g2_eps.cc +++ b/src/accessor/grib_accessor_class_g2_eps.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,114 +9,15 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_unsigned - IMPLEMENTS = unpack_long;pack_long; value_count - IMPLEMENTS = init - MEMBERS=const char* productDefinitionTemplateNumber - MEMBERS=const char* stream - MEMBERS=const char* type - MEMBERS=const char* stepType - MEMBERS=const char* derivedForecast - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g2_eps -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in unsigned */ - long nbytes; - grib_arguments* arg; - /* Members defined in g2_eps */ - const char* productDefinitionTemplateNumber; - const char* stream; - const char* type; - const char* stepType; - const char* derivedForecast; -} grib_accessor_g2_eps; - -extern grib_accessor_class* grib_accessor_class_unsigned; - -static grib_accessor_class _grib_accessor_class_g2_eps = { - &grib_accessor_class_unsigned, /* super */ - "g2_eps", /* name */ - sizeof(grib_accessor_g2_eps), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_g2_eps.h" +grib_accessor_class_g2_eps_t _grib_accessor_class_g2_eps{"g2_eps"}; grib_accessor_class* grib_accessor_class_g2_eps = &_grib_accessor_class_g2_eps; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_g2_eps* self = (grib_accessor_g2_eps*)a; +void grib_accessor_class_g2_eps_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_unsigned_t::init(a, l, c); + grib_accessor_g2_eps_t* self = (grib_accessor_g2_eps_t*)a; int n = 0; self->productDefinitionTemplateNumber = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); @@ -125,9 +27,8 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) self->derivedForecast = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); } -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_g2_eps* self = (grib_accessor_g2_eps*)a; +int grib_accessor_class_g2_eps_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_accessor_g2_eps_t* self = (grib_accessor_g2_eps_t*)a; long productDefinitionTemplateNumber = 0; int err = 0; grib_handle* hand = grib_handle_of_accessor(a); @@ -145,9 +46,8 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) return GRIB_SUCCESS; } -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - grib_accessor_g2_eps* self = (grib_accessor_g2_eps*)a; +int grib_accessor_class_g2_eps_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + grib_accessor_g2_eps_t* self = (grib_accessor_g2_eps_t*)a; grib_handle* hand = grib_handle_of_accessor(a); long productDefinitionTemplateNumber = -1; long productDefinitionTemplateNumberNew = -1; @@ -266,8 +166,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) return 0; } -static int value_count(grib_accessor* a, long* count) -{ +int grib_accessor_class_g2_eps_t::value_count(grib_accessor* a, long* count){ *count = 1; return 0; } diff --git a/src/accessor/grib_accessor_class_g2_eps.h b/src/accessor/grib_accessor_class_g2_eps.h new file mode 100644 index 000000000..8453387fa --- /dev/null +++ b/src/accessor/grib_accessor_class_g2_eps.h @@ -0,0 +1,36 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_unsigned.h" + +class grib_accessor_g2_eps_t : public grib_accessor_unsigned_t +{ +public: + /* Members defined in g2_eps */ + const char* productDefinitionTemplateNumber; + const char* stream; + const char* type; + const char* stepType; + const char* derivedForecast; +}; + +class grib_accessor_class_g2_eps_t : public grib_accessor_class_unsigned_t +{ +public: + grib_accessor_class_g2_eps_t(const char* name) : grib_accessor_class_unsigned_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g2_eps_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_g2_mars_labeling.cc b/src/accessor/grib_accessor_class_g2_mars_labeling.cc similarity index 72% rename from src/grib_accessor_class_g2_mars_labeling.cc rename to src/accessor/grib_accessor_class_g2_mars_labeling.cc index ad0647e30..b9059220f 100644 --- a/src/grib_accessor_class_g2_mars_labeling.cc +++ b/src/accessor/grib_accessor_class_g2_mars_labeling.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,131 +9,18 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -/************************************** - * Enrico Fucile - **************************************/ - - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = unpack_long;pack_long; value_count - IMPLEMENTS = unpack_string;pack_string - IMPLEMENTS = init; get_native_type - MEMBERS=int index - MEMBERS=const char* the_class - MEMBERS=const char* stream - MEMBERS=const char* type - MEMBERS=const char* expver - MEMBERS=const char* typeOfProcessedData - MEMBERS=const char* productDefinitionTemplateNumber - MEMBERS=const char* stepType - MEMBERS=const char* derivedForecast - MEMBERS=const char* typeOfGeneratingProcess - - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int pack_string(grib_accessor*, const char*, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g2_mars_labeling -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in g2_mars_labeling */ - int index; - const char* the_class; - const char* stream; - const char* type; - const char* expver; - const char* typeOfProcessedData; - const char* productDefinitionTemplateNumber; - const char* stepType; - const char* derivedForecast; - const char* typeOfGeneratingProcess; -} grib_accessor_g2_mars_labeling; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_g2_mars_labeling = { - &grib_accessor_class_gen, /* super */ - "g2_mars_labeling", /* name */ - sizeof(grib_accessor_g2_mars_labeling), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - &pack_string, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_g2_mars_labeling.h" +grib_accessor_class_g2_mars_labeling_t _grib_accessor_class_g2_mars_labeling{ "g2_mars_labeling" }; grib_accessor_class* grib_accessor_class_g2_mars_labeling = &_grib_accessor_class_g2_mars_labeling; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_class_g2_mars_labeling_t::init(grib_accessor* a, const long l, grib_arguments* c) { - grib_accessor_g2_mars_labeling* self = (grib_accessor_g2_mars_labeling*)a; - int n = 0; - grib_handle* hand = grib_handle_of_accessor(a); + grib_accessor_class_gen_t::init(a, l, c); + grib_accessor_g2_mars_labeling_t* self = (grib_accessor_g2_mars_labeling_t*)a; + int n = 0; + grib_handle* hand = grib_handle_of_accessor(a); self->index = grib_arguments_get_long(hand, c, n++); self->the_class = grib_arguments_get_name(hand, c, n++); @@ -146,10 +34,10 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) self->typeOfGeneratingProcess = grib_arguments_get_name(hand, c, n++); } -static int unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_class_g2_mars_labeling_t::unpack_long(grib_accessor* a, long* val, size_t* len) { - grib_accessor_g2_mars_labeling* self = (grib_accessor_g2_mars_labeling*)a; - char* key = NULL; + grib_accessor_g2_mars_labeling_t* self = (grib_accessor_g2_mars_labeling_t*)a; + char* key = NULL; switch (self->index) { case 0: @@ -170,10 +58,10 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) return grib_get_long(grib_handle_of_accessor(a), key, val); } -static int unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_class_g2_mars_labeling_t::unpack_string(grib_accessor* a, char* val, size_t* len) { - grib_accessor_g2_mars_labeling* self = (grib_accessor_g2_mars_labeling*)a; - char* key = NULL; + grib_accessor_g2_mars_labeling_t* self = (grib_accessor_g2_mars_labeling_t*)a; + char* key = NULL; switch (self->index) { case 0: @@ -196,10 +84,10 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len) static int extra_set(grib_accessor* a, long val) { - int ret = 0; - grib_accessor_g2_mars_labeling* self = (grib_accessor_g2_mars_labeling*)a; - grib_handle* hand = grib_handle_of_accessor(a); - char stepType[30] = {0,}; + int ret = 0; + grib_accessor_g2_mars_labeling_t* self = (grib_accessor_g2_mars_labeling_t*)a; + grib_handle* hand = grib_handle_of_accessor(a); + char stepType[30] = {0,}; size_t stepTypelen = 30; long derivedForecast = -1; long productDefinitionTemplateNumberNew = -1; @@ -417,12 +305,12 @@ static int extra_set(grib_accessor* a, long val) return ret; } -static int pack_string(grib_accessor* a, const char* val, size_t* len) +int grib_accessor_class_g2_mars_labeling_t::pack_string(grib_accessor* a, const char* val, size_t* len) { - grib_accessor_g2_mars_labeling* self = (grib_accessor_g2_mars_labeling*)a; - char* key = NULL; - int ret = 0; - long lval = 0; + grib_accessor_g2_mars_labeling_t* self = (grib_accessor_g2_mars_labeling_t*)a; + char* key = NULL; + int ret = 0; + long lval = 0; switch (self->index) { case 0: @@ -451,11 +339,11 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len) return extra_set(a, lval); } -static int pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_class_g2_mars_labeling_t::pack_long(grib_accessor* a, const long* val, size_t* len) { - grib_accessor_g2_mars_labeling* self = (grib_accessor_g2_mars_labeling*)a; - char* key = NULL; - int ret = 0; + grib_accessor_g2_mars_labeling_t* self = (grib_accessor_g2_mars_labeling_t*)a; + char* key = NULL; + int ret = 0; switch (self->index) { case 0: @@ -480,18 +368,18 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) return extra_set(a, *val); } -static int value_count(grib_accessor* a, long* count) +int grib_accessor_class_g2_mars_labeling_t::value_count(grib_accessor* a, long* count) { *count = 1; return 0; } -static int get_native_type(grib_accessor* a) +int grib_accessor_class_g2_mars_labeling_t::get_native_type(grib_accessor* a) { - grib_accessor_g2_mars_labeling* self = (grib_accessor_g2_mars_labeling*)a; - char* key = NULL; - int ret = 0; - int type = 0; + grib_accessor_g2_mars_labeling_t* self = (grib_accessor_g2_mars_labeling_t*)a; + char* key = NULL; + int ret = 0; + int type = 0; switch (self->index) { case 0: diff --git a/src/accessor/grib_accessor_class_g2_mars_labeling.h b/src/accessor/grib_accessor_class_g2_mars_labeling.h new file mode 100644 index 000000000..d47848565 --- /dev/null +++ b/src/accessor/grib_accessor_class_g2_mars_labeling.h @@ -0,0 +1,44 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_g2_mars_labeling_t : public grib_accessor_gen_t +{ +public: + /* Members defined in g2_mars_labeling */ + int index; + const char* the_class; + const char* stream; + const char* type; + const char* expver; + const char* typeOfProcessedData; + const char* productDefinitionTemplateNumber; + const char* stepType; + const char* derivedForecast; + const char* typeOfGeneratingProcess; +}; + +class grib_accessor_class_g2_mars_labeling_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_g2_mars_labeling_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g2_mars_labeling_t{}; } + int get_native_type(grib_accessor*) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int pack_string(grib_accessor*, const char*, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_g2bitmap.cc b/src/accessor/grib_accessor_class_g2bitmap.cc new file mode 100644 index 000000000..d5af880b3 --- /dev/null +++ b/src/accessor/grib_accessor_class_g2bitmap.cc @@ -0,0 +1,75 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_g2bitmap.h" +#include "shared_functions.h" + +grib_accessor_class_g2bitmap_t _grib_accessor_class_g2bitmap{"g2bitmap"}; +grib_accessor_class* grib_accessor_class_g2bitmap = &_grib_accessor_class_g2bitmap; + + +void grib_accessor_class_g2bitmap_t::init(grib_accessor* a, const long len, grib_arguments* arg){ + grib_accessor_class_bitmap_t::init(a, len, arg); + grib_accessor_g2bitmap_t* self = (grib_accessor_g2bitmap_t*)a; + + self->numberOfValues = grib_arguments_get_name(grib_handle_of_accessor(a), arg, 4); +} + +int grib_accessor_class_g2bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len){ + grib_accessor_g2bitmap_t* self = (grib_accessor_g2bitmap_t*)a; + + size_t tlen; + + unsigned char* buf = NULL; + size_t i; + int err = 0; + long pos = 0; + // long bmaplen = 0; + double miss_values = 0; + tlen = (*len + 7) / 8; + + if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value, &miss_values)) != GRIB_SUCCESS) + return err; + + buf = (unsigned char*)grib_context_malloc_clear(a->context, tlen); + if (!buf) + return GRIB_OUT_OF_MEMORY; + pos = 0; + for (i = 0; i < *len; i++) { + if (val[i] == miss_values) + pos++; + else { + // bmaplen++; + grib_set_bit_on(buf, &pos); + } + } + + if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->numberOfValues, *len)) != GRIB_SUCCESS) { + grib_context_free(a->context, buf); + return err; + } + + grib_buffer_replace(a, buf, tlen, 1, 1); + + grib_context_free(a->context, buf); + + return GRIB_SUCCESS; +} + + +int grib_accessor_class_g2bitmap_t::value_count(grib_accessor* a, long* tlen){ + grib_accessor_g2bitmap_t* self = (grib_accessor_g2bitmap_t*)a; + int err; + *tlen = 0; + + err = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfValues, tlen); + return err; +} diff --git a/src/accessor/grib_accessor_class_g2bitmap.h b/src/accessor/grib_accessor_class_g2bitmap.h new file mode 100644 index 000000000..2276b702c --- /dev/null +++ b/src/accessor/grib_accessor_class_g2bitmap.h @@ -0,0 +1,31 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_bitmap.h" + +class grib_accessor_g2bitmap_t : public grib_accessor_bitmap_t +{ +public: + /* Members defined in g2bitmap */ + const char* numberOfValues; +}; + +class grib_accessor_class_g2bitmap_t : public grib_accessor_class_bitmap_t +{ +public: + grib_accessor_class_g2bitmap_t(const char* name) : grib_accessor_class_bitmap_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g2bitmap_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_g2bitmap_present.cc b/src/accessor/grib_accessor_class_g2bitmap_present.cc new file mode 100644 index 000000000..1444783fe --- /dev/null +++ b/src/accessor/grib_accessor_class_g2bitmap_present.cc @@ -0,0 +1,59 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_g2bitmap_present.h" + +grib_accessor_class_g2bitmap_present_t _grib_accessor_class_g2bitmap_present{"g2bitmap_present"}; +grib_accessor_class* grib_accessor_class_g2bitmap_present = &_grib_accessor_class_g2bitmap_present; + + +void grib_accessor_class_g2bitmap_present_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_long_t::init(a, l, c); + int n = 0; + grib_accessor_g2bitmap_present_t* self = (grib_accessor_g2bitmap_present_t*)a; + self->bitmapIndicator = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + + a->length = 0; +} + +int grib_accessor_class_g2bitmap_present_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + int ret = GRIB_SUCCESS; + long bitmapIndicator = 0; + + grib_accessor_g2bitmap_present_t* self = (grib_accessor_g2bitmap_present_t*)a; + + ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bitmapIndicator, &bitmapIndicator); + if (ret) { + if (ret == GRIB_NOT_FOUND) { + *val = 0; + return 0; + } + else + return ret; + } + + *val = 1; + if (bitmapIndicator == 255) + *val = 0; + + *len = 1; + return ret; +} + +int grib_accessor_class_g2bitmap_present_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + grib_accessor_g2bitmap_present_t* self = (grib_accessor_g2bitmap_present_t*)a; + long bitmapIndicator = 0; + + if (*val == 0) + bitmapIndicator = 255; + + return grib_set_long(grib_handle_of_accessor(a), self->bitmapIndicator, bitmapIndicator); +} diff --git a/src/accessor/grib_accessor_class_g2bitmap_present.h b/src/accessor/grib_accessor_class_g2bitmap_present.h new file mode 100644 index 000000000..87d603f54 --- /dev/null +++ b/src/accessor/grib_accessor_class_g2bitmap_present.h @@ -0,0 +1,31 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_g2bitmap_present_t : public grib_accessor_long_t +{ +public: + /* Members defined in g2bitmap_present */ + const char* bitmapIndicator; +}; + +class grib_accessor_class_g2bitmap_present_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_g2bitmap_present_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g2bitmap_present_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_g2date.cc b/src/accessor/grib_accessor_class_g2date.cc new file mode 100644 index 000000000..238da76f7 --- /dev/null +++ b/src/accessor/grib_accessor_class_g2date.cc @@ -0,0 +1,82 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_g2date.h" + +grib_accessor_class_g2date_t _grib_accessor_class_g2date{"g2date"}; +grib_accessor_class* grib_accessor_class_g2date = &_grib_accessor_class_g2date; + +void grib_accessor_class_g2date_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_long_t::init(a, l, c); + grib_accessor_g2date_t* self = (grib_accessor_g2date_t*)a; + int n = 0; + + self->year = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->month = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->day = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); +} + +int grib_accessor_class_g2date_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + const grib_accessor_g2date_t* self = (grib_accessor_g2date_t*)a; + + int ret = 0; + long year = 0; + long month = 0; + long day = 0; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->day, &day)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->month, &month)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->year, &year)) != GRIB_SUCCESS) + return ret; + + if (*len < 1) + return GRIB_WRONG_ARRAY_SIZE; + + val[0] = year * 10000 + month * 100 + day; + + return GRIB_SUCCESS; +} + +int grib_accessor_class_g2date_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + const grib_accessor_g2date_t* self = (grib_accessor_g2date_t*)a; + + int ret = GRIB_SUCCESS; + long v = val[0]; + long year = 0; + long month = 0; + long day = 0; + + if (*len != 1) + return GRIB_WRONG_ARRAY_SIZE; + + year = v / 10000; + v %= 10000; + month = v / 100; + v %= 100; + day = v; + + if (!is_date_valid(year, month, day, 0, 0, 0)) { + // ECC-1777: For now just a warning. Will later change to an error + fprintf(stderr, "ECCODES WARNING : %s:%s: Date is not valid! year=%ld month=%ld day=%ld\n", + a->cclass->name, __func__, year, month, day); + } + + if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->day, day)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->month, month)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->year, year)) != GRIB_SUCCESS) + return ret; + + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_g2date.h b/src/accessor/grib_accessor_class_g2date.h new file mode 100644 index 000000000..e6981665c --- /dev/null +++ b/src/accessor/grib_accessor_class_g2date.h @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_g2date_t : public grib_accessor_long_t +{ +public: + /* Members defined in g2date */ + const char* century; + const char* year; + const char* month; + const char* day; +}; + +class grib_accessor_class_g2date_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_g2date_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g2date_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_g2end_step.cc b/src/accessor/grib_accessor_class_g2end_step.cc similarity index 67% rename from src/grib_accessor_class_g2end_step.cc rename to src/accessor/grib_accessor_class_g2end_step.cc index eed6b5d13..6e8cfcda3 100644 --- a/src/grib_accessor_class_g2end_step.cc +++ b/src/accessor/grib_accessor_class_g2end_step.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,153 +9,21 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" +#include "grib_accessor_class_g2end_step.h" #include "step.h" #include "step_utilities.h" #include -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = unpack_double - IMPLEMENTS = unpack_string;pack_string - IMPLEMENTS = init;dump - IMPLEMENTS = get_native_type - MEMBERS = const char* start_step_value - MEMBERS = const char* step_units - - MEMBERS = const char* year - MEMBERS = const char* month - MEMBERS = const char* day - MEMBERS = const char* hour - MEMBERS = const char* minute - MEMBERS = const char* second - - MEMBERS = const char* year_of_end_of_interval - MEMBERS = const char* month_of_end_of_interval - MEMBERS = const char* day_of_end_of_interval - MEMBERS = const char* hour_of_end_of_interval - MEMBERS = const char* minute_of_end_of_interval - MEMBERS = const char* second_of_end_of_interval - - MEMBERS = const char* time_range_unit - MEMBERS = const char* time_range_value - MEMBERS = const char* typeOfTimeIncrement - MEMBERS = const char* numberOfTimeRange - - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int pack_string(grib_accessor*, const char*, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g2end_step -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in g2end_step */ - const char* start_step_value; - const char* step_units; - const char* year; - const char* month; - const char* day; - const char* hour; - const char* minute; - const char* second; - const char* year_of_end_of_interval; - const char* month_of_end_of_interval; - const char* day_of_end_of_interval; - const char* hour_of_end_of_interval; - const char* minute_of_end_of_interval; - const char* second_of_end_of_interval; - const char* time_range_unit; - const char* time_range_value; - const char* typeOfTimeIncrement; - const char* numberOfTimeRange; -} grib_accessor_g2end_step; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_g2end_step = { - &grib_accessor_class_long, /* super */ - "g2end_step", /* name */ - sizeof(grib_accessor_g2end_step), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - &pack_string, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - +grib_accessor_class_g2end_step_t _grib_accessor_class_g2end_step{ "g2end_step" }; grib_accessor_class* grib_accessor_class_g2end_step = &_grib_accessor_class_g2end_step; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_class_g2end_step_t::init(grib_accessor* a, const long l, grib_arguments* c) { - grib_accessor_g2end_step* self = (grib_accessor_g2end_step*)a; - int n = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_accessor_class_long_t::init(a, l, c); + grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; + int n = 0; + grib_handle* h = grib_handle_of_accessor(a); self->start_step_value = grib_arguments_get_name(h, c, n++); self->step_units = grib_arguments_get_name(h, c, n++); @@ -173,31 +42,31 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) self->minute_of_end_of_interval = grib_arguments_get_name(h, c, n++); self->second_of_end_of_interval = grib_arguments_get_name(h, c, n++); - self->time_range_unit = grib_arguments_get_name(h, c, n++); + self->time_range_unit = grib_arguments_get_name(h, c, n++); self->time_range_value = grib_arguments_get_name(h, c, n++); self->typeOfTimeIncrement = grib_arguments_get_name(h, c, n++); self->numberOfTimeRange = grib_arguments_get_name(h, c, n++); } -static void dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_class_g2end_step_t::dump(grib_accessor* a, grib_dumper* dumper) { grib_dump_double(dumper, a, NULL); } // See GRIB-488 -static bool is_special_expver(const grib_handle* h) +bool is_special_expver(const grib_handle* h) { - int ret = 0; + int ret = 0; char strMarsExpVer[50] = {0,}; char strMarsClass[50] = {0,}; size_t slen = 50; - ret = grib_get_string(h, "mars.class", strMarsClass, &slen); + ret = grib_get_string(h, "mars.class", strMarsClass, &slen); if (ret == GRIB_SUCCESS && STR_EQUAL(strMarsClass, "em")) { // em = ERA-CLIM model integration for the 20th-century (ERA-20CM) slen = 50; - ret = grib_get_string(h, "experimentVersionNumber", strMarsExpVer, &slen); + ret = grib_get_string(h, "experimentVersionNumber", strMarsExpVer, &slen); if (ret == GRIB_SUCCESS && STR_EQUAL(strMarsExpVer, "1605")) { - return true; // Special case of expVer 1605 in class "em" + return true; // Special case of expVer 1605 in class "em" } } @@ -214,8 +83,8 @@ static int convert_time_range_long_( Assert(lengthOfTimeRange != NULL); if (indicatorOfUnitForTimeRange != stepUnits) { - eccodes::Step time_range{*lengthOfTimeRange, indicatorOfUnitForTimeRange}; - time_range.set_unit(eccodes::Unit{stepUnits}); + eccodes::Step time_range{ *lengthOfTimeRange, indicatorOfUnitForTimeRange }; + time_range.set_unit(eccodes::Unit{ stepUnits }); if (time_range.value() != time_range.value()) { return GRIB_DECODING_ERROR; } @@ -227,8 +96,8 @@ static int convert_time_range_long_( static int unpack_one_time_range_long_(grib_accessor* a, long* val, size_t* len) { - grib_accessor_g2end_step* self = (grib_accessor_g2end_step*)a; - int err = 0; + grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; + int err = 0; long start_step_value; long step_units; long time_range_unit; @@ -274,10 +143,10 @@ static int unpack_one_time_range_long_(grib_accessor* a, long* val, size_t* len) return GRIB_SUCCESS; } -static int unpack_one_time_range_double_(grib_accessor* a, double *val , size_t* len) +static int unpack_one_time_range_double_(grib_accessor* a, double* val, size_t* len) { - grib_accessor_g2end_step* self = (grib_accessor_g2end_step*)a; - int err = 0; + grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; + int err = 0; double start_step_value; long start_step_unit; long step_units; @@ -301,8 +170,8 @@ static int unpack_one_time_range_double_(grib_accessor* a, double *val , size_t* if ((err = grib_get_long_internal(h, self->typeOfTimeIncrement, &typeOfTimeIncrement))) return err; - eccodes::Step start_step{start_step_value, start_step_unit}; - eccodes::Step time_range{time_range_value, time_range_unit}; + eccodes::Step start_step{ start_step_value, start_step_unit }; + eccodes::Step time_range{ time_range_value, time_range_unit }; if (typeOfTimeIncrement == 1) { /* See GRIB-488 */ @@ -329,15 +198,21 @@ static int unpack_one_time_range_double_(grib_accessor* a, double *val , size_t* #define MAX_NUM_TIME_RANGES 16 /* maximum number of time range specifications */ static int unpack_multiple_time_ranges_long_(grib_accessor* a, long* val, size_t* len) { - grib_accessor_g2end_step* self = (grib_accessor_g2end_step*)a; + grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; int i = 0, err = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(a); long numberOfTimeRange = 0, step_units = 0, start_step_value = 0; - size_t count = 0; - long arr_typeOfTimeIncrement[MAX_NUM_TIME_RANGES] = {0,}; - long arr_coded_unit[MAX_NUM_TIME_RANGES] = {0,}; - long arr_coded_time_range[MAX_NUM_TIME_RANGES] = {0,}; + size_t count = 0; + long arr_typeOfTimeIncrement[MAX_NUM_TIME_RANGES] = { + 0, + }; + long arr_coded_unit[MAX_NUM_TIME_RANGES] = { + 0, + }; + long arr_coded_time_range[MAX_NUM_TIME_RANGES] = { + 0, + }; if ((err = grib_get_long_internal(h, self->start_step_value, &start_step_value))) return err; @@ -382,29 +257,35 @@ static int unpack_multiple_time_ranges_long_(grib_accessor* a, long* val, size_t static int unpack_multiple_time_ranges_double_(grib_accessor* a, double* val, size_t* len) { - grib_accessor_g2end_step* self = (grib_accessor_g2end_step*)a; + grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; int i = 0, err = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(a); long numberOfTimeRange = 0; - long step_units = 0; - long start_step_value = 0; - long start_step_unit = 0; + long step_units = 0; + long start_step_value = 0; + long start_step_unit = 0; - size_t count = 0; - long arr_typeOfTimeIncrement[MAX_NUM_TIME_RANGES] = {0, }; - long arr_coded_unit[MAX_NUM_TIME_RANGES] = {0, }; - long arr_coded_time_range[MAX_NUM_TIME_RANGES] = {0, }; + size_t count = 0; + long arr_typeOfTimeIncrement[MAX_NUM_TIME_RANGES] = { + 0, + }; + long arr_coded_unit[MAX_NUM_TIME_RANGES] = { + 0, + }; + long arr_coded_time_range[MAX_NUM_TIME_RANGES] = { + 0, + }; if ((err = grib_get_long_internal(h, self->start_step_value, &start_step_value))) return err; if ((err = grib_get_long_internal(h, "startStepUnit", &start_step_unit))) return err; - eccodes::Step start_step{start_step_value, start_step_unit}; + eccodes::Step start_step{ start_step_value, start_step_unit }; if ((err = grib_get_long_internal(h, self->step_units, &step_units))) return err; - + if ((err = grib_get_long_internal(h, self->numberOfTimeRange, &numberOfTimeRange))) return err; if (numberOfTimeRange > MAX_NUM_TIME_RANGES) { @@ -428,7 +309,7 @@ static int unpack_multiple_time_ranges_double_(grib_accessor* a, double* val, si long the_coded_unit = arr_coded_unit[i]; long the_coded_time_range = arr_coded_time_range[i]; - eccodes::Step time_range{the_coded_unit, the_coded_time_range}; + eccodes::Step time_range{ the_coded_unit, the_coded_time_range }; *val = (start_step + time_range).value(eccodes::Unit(step_units)); return GRIB_SUCCESS; @@ -443,11 +324,11 @@ static int unpack_multiple_time_ranges_double_(grib_accessor* a, double* val, si // For the old implementation of unpack_long, see // src/deprecated/grib_accessor_class_g2end_step.unpack_long.cc // -static int unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_class_g2end_step_t::unpack_long(grib_accessor* a, long* val, size_t* len) { - grib_accessor_g2end_step* self = (grib_accessor_g2end_step*)a; - grib_handle* h = grib_handle_of_accessor(a); - int ret = 0; + grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; + grib_handle* h = grib_handle_of_accessor(a); + int ret = 0; long start_step_value; long start_step_unit; long numberOfTimeRange; @@ -472,25 +353,25 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) try { if (numberOfTimeRange == 1) { - ret = unpack_one_time_range_long_(a, val, len); + ret = unpack_one_time_range_long_(a, val, len); } else { ret = unpack_multiple_time_ranges_long_(a, val, len); } } catch (std::exception& e) { - grib_context_log(h->context, GRIB_LOG_ERROR, "grib_accessor_g2end_step::unpack_long: %s", e.what()); + grib_context_log(h->context, GRIB_LOG_ERROR, "grib_accessor_g2end_step_t::unpack_long: %s", e.what()); ret = GRIB_DECODING_ERROR; } return ret; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_class_g2end_step_t::unpack_double(grib_accessor* a, double* val, size_t* len) { - grib_accessor_g2end_step* self = (grib_accessor_g2end_step*)a; - grib_handle* h = grib_handle_of_accessor(a); - int ret = 0; + grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; + grib_handle* h = grib_handle_of_accessor(a); + int ret = 0; long start_step_value; long start_step_unit; long numberOfTimeRange; @@ -515,14 +396,14 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) try { if (numberOfTimeRange == 1) { - ret = unpack_one_time_range_double_(a, val, len); + ret = unpack_one_time_range_double_(a, val, len); } else { ret = unpack_multiple_time_ranges_double_(a, val, len); } } catch (std::exception& e) { - grib_context_log(h->context, GRIB_LOG_ERROR, "grib_accessor_g2end_step::unpack_double: %s", e.what()); + grib_context_log(h->context, GRIB_LOG_ERROR, "grib_accessor_g2end_step_t::unpack_double: %s", e.what()); ret = GRIB_DECODING_ERROR; } @@ -531,9 +412,9 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) static int pack_long_(grib_accessor* a, const long end_step_value, const long end_step_unit) { - grib_accessor_g2end_step* self = (grib_accessor_g2end_step*)a; - grib_handle* h = grib_handle_of_accessor(a); - int err = 0; + grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; + grib_handle* h = grib_handle_of_accessor(a); + int err = 0; long year; long month; @@ -556,7 +437,7 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en double dend, dstep; const int show_units_for_hours = a->context->grib_hourly_steps_with_units; - eccodes::Step end_step{end_step_value, end_step_unit}; + eccodes::Step end_step{ end_step_value, end_step_unit }; /*point in time */ if (self->year == NULL) { @@ -587,10 +468,10 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en return err; long force_step_units; - if ((err= grib_get_long_internal(h, "forceStepUnits", &force_step_units)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, "forceStepUnits", &force_step_units)) != GRIB_SUCCESS) return err; - if (eccodes::Unit{start_step_unit} == eccodes::Unit{eccodes::Unit::Value::MISSING}) { + if (eccodes::Unit{ start_step_unit } == eccodes::Unit{ eccodes::Unit::Value::MISSING }) { grib_context_log(h->context, GRIB_LOG_ERROR, "missing start step unit"); return GRIB_WRONG_STEP_UNIT; @@ -599,7 +480,7 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en if ((err = grib_get_long_internal(h, self->typeOfTimeIncrement, &typeOfTimeIncrement))) return err; - eccodes::Step start_step{start_step_value, start_step_unit}; + eccodes::Step start_step{ start_step_value, start_step_unit }; eccodes::Step time_range = end_step - start_step; if (time_range.value() < 0) { @@ -614,7 +495,7 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en if (err != GRIB_SUCCESS) return err; - dstep = end_step.value(eccodes::Unit{eccodes::Unit::Value::DAY}); + dstep = end_step.value(eccodes::Unit{ eccodes::Unit::Value::DAY }); dend += dstep; err = grib_julian_to_datetime(dend, &year_of_end_of_interval, &month_of_end_of_interval, @@ -637,15 +518,15 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en return err; const char* forecast_time_value_key = "forecastTime"; - const char* forecast_time_unit_key = "indicatorOfUnitOfTimeRange"; + const char* forecast_time_unit_key = "indicatorOfUnitOfTimeRange"; eccodes::Step forecast_time_opt; eccodes::Step time_range_opt; - if (eccodes::Unit{force_step_units} == eccodes::Unit{eccodes::Unit::Value::MISSING}) { + if (eccodes::Unit{ force_step_units } == eccodes::Unit{ eccodes::Unit::Value::MISSING }) { std::tie(forecast_time_opt, time_range_opt) = find_common_units(start_step.optimize_unit(), time_range.optimize_unit()); } else { - forecast_time_opt = eccodes::Step{start_step.value(eccodes::Unit{force_step_units}), eccodes::Unit{force_step_units}}; - time_range_opt = eccodes::Step{time_range.value(eccodes::Unit{force_step_units}), eccodes::Unit{force_step_units}}; + forecast_time_opt = eccodes::Step{ start_step.value(eccodes::Unit{ force_step_units }), eccodes::Unit{ force_step_units } }; + time_range_opt = eccodes::Step{ time_range.value(eccodes::Unit{ force_step_units }), eccodes::Unit{ force_step_units } }; } if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->time_range_value, time_range_opt.value())) != GRIB_SUCCESS) @@ -660,14 +541,14 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en return GRIB_SUCCESS; } -static int unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_class_g2end_step_t::unpack_string(grib_accessor* a, char* val, size_t* len) { - grib_accessor_g2end_step* self = (grib_accessor_g2end_step*)a; - grib_handle* h = grib_handle_of_accessor(a); - int ret = 0; - char fp_format[128] = "%g"; - size_t fp_format_len = sizeof(fp_format); - size_t step_len = 0; + grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; + grib_handle* h = grib_handle_of_accessor(a); + int ret = 0; + char fp_format[128] = "%g"; + size_t fp_format_len = sizeof(fp_format); + size_t step_len = 0; long step_value; long step_units; const int show_units_for_hours = a->context->grib_hourly_steps_with_units; @@ -697,14 +578,14 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len) memcpy(val, ss.str().c_str(), size); } catch (std::exception& e) { - grib_context_log(h->context, GRIB_LOG_ERROR, "grib_accessor_g2end_step::unpack_string: %s", e.what()); + grib_context_log(h->context, GRIB_LOG_ERROR, "grib_accessor_g2end_step_t::unpack_string: %s", e.what()); return GRIB_DECODING_ERROR; } return GRIB_SUCCESS; } -static int pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_class_g2end_step_t::pack_long(grib_accessor* a, const long* val, size_t* len) { grib_handle* h = grib_handle_of_accessor(a); int ret; @@ -715,12 +596,12 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) try { long end_step_unit; - if (eccodes::Unit{force_step_units} == eccodes::Unit{eccodes::Unit::Value::MISSING}) { + if (eccodes::Unit{ force_step_units } == eccodes::Unit{ eccodes::Unit::Value::MISSING }) { if ((ret = grib_get_long_internal(h, "endStepUnit", &end_step_unit)) != GRIB_SUCCESS) return ret; - if (eccodes::Unit{end_step_unit} == eccodes::Unit{eccodes::Unit::Value::MISSING}) - end_step_unit = eccodes::Unit{eccodes::Unit::Value::HOUR}.value(); + if (eccodes::Unit{ end_step_unit } == eccodes::Unit{ eccodes::Unit::Value::MISSING }) + end_step_unit = eccodes::Unit{ eccodes::Unit::Value::HOUR }.value(); } else { end_step_unit = force_step_units; @@ -728,22 +609,22 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) ret = pack_long_(a, *val, end_step_unit); } catch (std::exception& e) { - grib_context_log(h->context, GRIB_LOG_ERROR, "grib_accessor_g2end_step::pack_long: %s", e.what()); + grib_context_log(h->context, GRIB_LOG_ERROR, "grib_accessor_g2end_step_t::pack_long: %s", e.what()); return GRIB_DECODING_ERROR; } return ret; } -static int pack_string(grib_accessor* a, const char* val, size_t* len) +int grib_accessor_class_g2end_step_t::pack_string(grib_accessor* a, const char* val, size_t* len) { grib_handle* h = grib_handle_of_accessor(a); - int ret = 0; + int ret = 0; long force_step_units; if ((ret = grib_get_long_internal(h, "forceStepUnits", &force_step_units)) != GRIB_SUCCESS) return ret; try { - eccodes::Step end_step = step_from_string(val, eccodes::Unit{force_step_units}); + eccodes::Step end_step = step_from_string(val, eccodes::Unit{ force_step_units }); end_step.optimize_unit(); if ((ret = grib_set_long_internal(h, "endStepUnit", end_step.unit().value())) != GRIB_SUCCESS) @@ -753,22 +634,22 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len) return ret; } catch (std::exception& e) { - grib_context_log(h->context, GRIB_LOG_ERROR, "grib_accessor_g2end_step::pack_string: %s", e.what()); + grib_context_log(h->context, GRIB_LOG_ERROR, "grib_accessor_g2end_step_t::pack_string: %s", e.what()); return GRIB_DECODING_ERROR; } return GRIB_SUCCESS; } -static int get_native_type(grib_accessor* a) +int grib_accessor_class_g2end_step_t::get_native_type(grib_accessor* a) { - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(a); const int show_units_for_hours = a->context->grib_hourly_steps_with_units; if (!show_units_for_hours) { long step_units = 0; if (grib_get_long_internal(h, "stepUnits", &step_units) == GRIB_SUCCESS) { - if (eccodes::Unit{step_units} == eccodes::Unit::Value::HOUR) { - return GRIB_TYPE_LONG; // For backward compatibility + if (eccodes::Unit{ step_units } == eccodes::Unit::Value::HOUR) { + return GRIB_TYPE_LONG; // For backward compatibility } } } diff --git a/src/accessor/grib_accessor_class_g2end_step.h b/src/accessor/grib_accessor_class_g2end_step.h new file mode 100644 index 000000000..d3a3b1433 --- /dev/null +++ b/src/accessor/grib_accessor_class_g2end_step.h @@ -0,0 +1,53 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_g2end_step_t : public grib_accessor_long_t +{ +public: + /* Members defined in g2end_step */ + const char* start_step_value; + const char* step_units; + const char* year; + const char* month; + const char* day; + const char* hour; + const char* minute; + const char* second; + const char* year_of_end_of_interval; + const char* month_of_end_of_interval; + const char* day_of_end_of_interval; + const char* hour_of_end_of_interval; + const char* minute_of_end_of_interval; + const char* second_of_end_of_interval; + const char* time_range_unit; + const char* time_range_value; + const char* typeOfTimeIncrement; + const char* numberOfTimeRange; +}; + +class grib_accessor_class_g2end_step_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_g2end_step_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g2end_step_t{}; } + int get_native_type(grib_accessor*) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int pack_string(grib_accessor*, const char*, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_g2grid.cc b/src/accessor/grib_accessor_class_g2grid.cc similarity index 58% rename from src/grib_accessor_class_g2grid.cc rename to src/accessor/grib_accessor_class_g2grid.cc index 28d216b90..3bc0a9a22 100644 --- a/src/grib_accessor_class_g2grid.cc +++ b/src/accessor/grib_accessor_class_g2grid.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,119 +9,18 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" -#include -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_double - IMPLEMENTS = unpack_double;pack_double;value_count - IMPLEMENTS = init - MEMBERS=const char* latitude_first - MEMBERS=const char* longitude_first - MEMBERS=const char* latitude_last - MEMBERS=const char* longitude_last - MEMBERS=const char* i_increment - MEMBERS=const char* j_increment - MEMBERS=const char* basic_angle - MEMBERS=const char* sub_division - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g2grid -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in g2grid */ - const char* latitude_first; - const char* longitude_first; - const char* latitude_last; - const char* longitude_last; - const char* i_increment; - const char* j_increment; - const char* basic_angle; - const char* sub_division; -} grib_accessor_g2grid; - -extern grib_accessor_class* grib_accessor_class_double; - -static grib_accessor_class _grib_accessor_class_g2grid = { - &grib_accessor_class_double, /* super */ - "g2grid", /* name */ - sizeof(grib_accessor_g2grid), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_g2grid.h" +grib_accessor_class_g2grid_t _grib_accessor_class_g2grid{ "g2grid" }; grib_accessor_class* grib_accessor_class_g2grid = &_grib_accessor_class_g2grid; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_class_g2grid_t::init(grib_accessor* a, const long l, grib_arguments* c) { - grib_accessor_g2grid* self = (grib_accessor_g2grid*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int n = 0; + grib_accessor_class_double_t::init(a, l, c); + grib_accessor_g2grid_t* self = (grib_accessor_g2grid_t*)a; + grib_handle* hand = grib_handle_of_accessor(a); + int n = 0; self->latitude_first = grib_arguments_get_name(hand, c, n++); self->longitude_first = grib_arguments_get_name(hand, c, n++); @@ -136,7 +36,7 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) GRIB_ACCESSOR_FLAG_READ_ONLY; } -static int value_count(grib_accessor* a, long* count) +int grib_accessor_class_g2grid_t::value_count(grib_accessor* a, long* count) { *count = 6; return 0; @@ -145,11 +45,11 @@ static int value_count(grib_accessor* a, long* count) // GRIB edition 2 uses microdegrees #define ANGLE_SUBDIVISIONS (1000 * 1000) -static int unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_class_g2grid_t::unpack_double(grib_accessor* a, double* val, size_t* len) { - grib_accessor_g2grid* self = (grib_accessor_g2grid*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int ret = GRIB_SUCCESS; + grib_accessor_g2grid_t* self = (grib_accessor_g2grid_t*)a; + grib_handle* hand = grib_handle_of_accessor(a); + int ret = 0; long basic_angle = 0; long sub_division = 0; @@ -194,7 +94,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) if (!self->j_increment) { v[n++] = GRIB_MISSING_LONG; - } else { + } + else { if ((ret = grib_get_long_internal(hand, self->j_increment, &v[n++])) != GRIB_SUCCESS) return ret; } @@ -277,11 +178,11 @@ static int trial(const double* val, long v[6], long* basic_angle, long* sub_divi return is_ok(val, v, *basic_angle, *sub_division); } -static int pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_class_g2grid_t::pack_double(grib_accessor* a, const double* val, size_t* len) { - grib_accessor_g2grid* self = (grib_accessor_g2grid*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int ret = GRIB_SUCCESS; + grib_accessor_g2grid_t* self = (grib_accessor_g2grid_t*)a; + grib_handle* hand = grib_handle_of_accessor(a); + int ret; long v[6]; int n; long basic_angle; diff --git a/src/accessor/grib_accessor_class_g2grid.h b/src/accessor/grib_accessor_class_g2grid.h new file mode 100644 index 000000000..07c9f9862 --- /dev/null +++ b/src/accessor/grib_accessor_class_g2grid.h @@ -0,0 +1,39 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_double.h" + +class grib_accessor_g2grid_t : public grib_accessor_double_t +{ +public: + /* Members defined in g2grid */ + const char* latitude_first; + const char* longitude_first; + const char* latitude_last; + const char* longitude_last; + const char* i_increment; + const char* j_increment; + const char* basic_angle; + const char* sub_division; +}; + +class grib_accessor_class_g2grid_t : public grib_accessor_class_double_t +{ +public: + grib_accessor_class_g2grid_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g2grid_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_g2latlon.cc b/src/accessor/grib_accessor_class_g2latlon.cc new file mode 100644 index 000000000..afb3a2f7a --- /dev/null +++ b/src/accessor/grib_accessor_class_g2latlon.cc @@ -0,0 +1,120 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_g2latlon.h" + +grib_accessor_class_g2latlon_t _grib_accessor_class_g2latlon{ "g2latlon" }; +grib_accessor_class* grib_accessor_class_g2latlon = &_grib_accessor_class_g2latlon; + + +void grib_accessor_class_g2latlon_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ + grib_accessor_class_double_t::init(a, l, c); + grib_accessor_g2latlon_t* self = (grib_accessor_g2latlon_t*)a; + int n = 0; + + self->grid = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->index = grib_arguments_get_long(grib_handle_of_accessor(a), c, n++); + self->given = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); +} + +int grib_accessor_class_g2latlon_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ + grib_accessor_g2latlon_t* self = (grib_accessor_g2latlon_t*)a; + int ret = 0; + + long given = 1; + double grid[6]; + size_t size = 6; + + if (*len < 1) { + ret = GRIB_ARRAY_TOO_SMALL; + return ret; + } + + if (self->given) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->given, &given)) != GRIB_SUCCESS) + return ret; + + if (!given) { + *val = GRIB_MISSING_DOUBLE; + return GRIB_SUCCESS; + } + + if ((ret = grib_get_double_array_internal(grib_handle_of_accessor(a), self->grid, grid, &size)) != GRIB_SUCCESS) + return ret; + + *val = grid[self->index]; + + return GRIB_SUCCESS; +} + +int grib_accessor_class_g2latlon_t::pack_double(grib_accessor* a, const double* val, size_t* len) +{ + grib_accessor_g2latlon_t* self = (grib_accessor_g2latlon_t*)a; + int ret = 0; + double grid[6]; + size_t size = 6; + double new_val = *val; + grib_handle* hand = grib_handle_of_accessor(a); + + if (*len < 1) { + ret = GRIB_ARRAY_TOO_SMALL; + return ret; + } + + if (self->given) { + long given = *val != GRIB_MISSING_DOUBLE; + if ((ret = grib_set_long_internal(hand, self->given, given)) != GRIB_SUCCESS) + return ret; + } + + if ((ret = grib_get_double_array_internal(hand, self->grid, grid, &size)) != GRIB_SUCCESS) + return ret; + + /* index 1 is longitudeOfFirstGridPointInDegrees + * index 3 is longitudeOfLastGridPointInDegrees + */ + if ((self->index == 1 || self->index == 3)) { + /* WMO regulation for GRIB edition 2: + * The longitude values shall be limited to the range 0 to 360 degrees inclusive */ + new_val = normalise_longitude_in_degrees(*val); + if (hand->context->debug && new_val != *val) { + fprintf(stderr, "ECCODES DEBUG pack_double g2latlon: normalise longitude %g -> %g\n", *val, new_val); + } + } + grid[self->index] = new_val; + + return grib_set_double_array_internal(hand, self->grid, grid, size); +} + +int grib_accessor_class_g2latlon_t::pack_missing(grib_accessor* a) +{ + grib_accessor_g2latlon_t* self = (grib_accessor_g2latlon_t*)a; + double missing = GRIB_MISSING_DOUBLE; + size_t size = 1; + + if (!self->given) + return GRIB_NOT_IMPLEMENTED; + + return pack_double(a, &missing, &size); +} + +int grib_accessor_class_g2latlon_t::is_missing(grib_accessor* a) +{ + grib_accessor_g2latlon_t* self = (grib_accessor_g2latlon_t*)a; + long given = 1; + + if (self->given) + grib_get_long_internal(grib_handle_of_accessor(a), self->given, &given); + + return !given; +} diff --git a/src/accessor/grib_accessor_class_g2latlon.h b/src/accessor/grib_accessor_class_g2latlon.h new file mode 100644 index 000000000..f4733757e --- /dev/null +++ b/src/accessor/grib_accessor_class_g2latlon.h @@ -0,0 +1,35 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_double.h" + +class grib_accessor_g2latlon_t : public grib_accessor_double_t +{ +public: + /* Members defined in g2latlon */ + const char* grid; + int index; + const char* given; +}; + +class grib_accessor_class_g2latlon_t : public grib_accessor_class_double_t +{ +public: + grib_accessor_class_g2latlon_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g2latlon_t{}; } + int pack_missing(grib_accessor*) override; + int is_missing(grib_accessor*) override; + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_g2level.cc b/src/accessor/grib_accessor_class_g2level.cc similarity index 52% rename from src/grib_accessor_class_g2level.cc rename to src/accessor/grib_accessor_class_g2level.cc index 39bd79033..8da0be27f 100644 --- a/src/grib_accessor_class_g2level.cc +++ b/src/accessor/grib_accessor_class_g2level.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,113 +9,18 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_double;pack_double - IMPLEMENTS = unpack_long;pack_long;init;is_missing - MEMBERS=const char* type_first - MEMBERS=const char* scale_first - MEMBERS=const char* value_first - MEMBERS=const char* pressure_units - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int is_missing(grib_accessor*); -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g2level -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in g2level */ - const char* type_first; - const char* scale_first; - const char* value_first; - const char* pressure_units; -} grib_accessor_g2level; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_g2level = { - &grib_accessor_class_long, /* super */ - "g2level", /* name */ - sizeof(grib_accessor_g2level), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - &is_missing, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_g2level.h" +grib_accessor_class_g2level_t _grib_accessor_class_g2level{ "g2level" }; grib_accessor_class* grib_accessor_class_g2level = &_grib_accessor_class_g2level; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_class_g2level_t::init(grib_accessor* a, const long l, grib_arguments* c) { - grib_accessor_g2level* self = (grib_accessor_g2level*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int n = 0; + grib_accessor_class_long_t::init(a, l, c); + grib_accessor_g2level_t* self = (grib_accessor_g2level_t*)a; + grib_handle* hand = grib_handle_of_accessor(a); + int n = 0; self->type_first = grib_arguments_get_name(hand, c, n++); self->scale_first = grib_arguments_get_name(hand, c, n++); @@ -125,26 +31,26 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) a->flags |= GRIB_ACCESSOR_FLAG_COPY_IF_CHANGING_EDITION; } -static bool is_tigge(grib_handle* h) +bool is_tigge(grib_handle* h) { long productionStatus = 0; - int err = grib_get_long(h, "productionStatusOfProcessedData", &productionStatus); + int err = grib_get_long(h, "productionStatusOfProcessedData", &productionStatus); if (err) return false; return (productionStatus == 4 || productionStatus == 5); } -static int unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_class_g2level_t::unpack_double(grib_accessor* a, double* val, size_t* len) { - int ret = 0; - grib_accessor_g2level* self = (grib_accessor_g2level*)a; - grib_handle* hand = grib_handle_of_accessor(a); + int ret = 0; + grib_accessor_g2level_t* self = (grib_accessor_g2level_t*)a; + grib_handle* hand = grib_handle_of_accessor(a); long type_first = 0; long scale_first = 0; long value_first = 0; char pressure_units[10] = {0,}; size_t pressure_units_len = 10; - bool tigge = is_tigge(hand); + bool tigge = is_tigge(hand); double v; @@ -172,8 +78,9 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) // GRIB-637, ECC-1081: Potential vorticity surface if (type_first == 109) { if (tigge) { - scale_first -= 6; // TIGGE data follows different rules - } else { + scale_first -= 6; // TIGGE data follows different rules + } + else { scale_first -= 9; } } @@ -189,9 +96,9 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) } switch (type_first) { - case 100: // Isobaric surface (Pa) + case 100: // Isobaric surface (Pa) if (!strcmp(pressure_units, "hPa")) { - long x = v / 100.0; // 1 hPa = 100 Pa + long x = v / 100.0; // 1 hPa = 100 Pa if (scale_first == 0 && x == 0) { // Switch to Pa instead of hPa as the value is less than a hectoPascal char pa[] = "Pa"; @@ -211,29 +118,29 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) return GRIB_SUCCESS; } -static int unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_class_g2level_t::unpack_long(grib_accessor* a, long* val, size_t* len) { double dval = 0; int ret = unpack_double(a, &dval, len); if (ret == GRIB_SUCCESS) { - *val = (long)(dval + 0.5); // round up + *val = (long)(dval + 0.5); // round up } return ret; } -static int pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_class_g2level_t::pack_double(grib_accessor* a, const double* val, size_t* len) { - grib_accessor_g2level* self = (grib_accessor_g2level*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int ret = 0; - double value_first = *val; - //long scale_first = 0; - long type_first = 0; - char pressure_units[10] = {0,}; - size_t pressure_units_len = 10; - const long lval = (long)value_first; + grib_accessor_g2level_t* self = (grib_accessor_g2level_t*)a; + grib_handle* hand = grib_handle_of_accessor(a); + int ret = 0; + double value_first = *val; + // long scale_first = 0; + long type_first = 0; + char pressure_units[10] = {0,}; + size_t pressure_units_len = 10; + const long lval = (long)value_first; - if (value_first == lval) { // input is a whole number; process it as an integer + if (value_first == lval) { // input is a whole number; process it as an integer return pack_long(a, &lval, len); } @@ -247,7 +154,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) return ret; switch (type_first) { - case 100: // Pa + case 100: // Pa if (!strcmp(pressure_units, "hPa")) value_first *= 100; break; @@ -258,14 +165,14 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) // final = scaled_value * 10 ^ -scale_factor - //scale_first = 2; - //value_first *= 100; - //value_first = value_first + 0.5; //round up + // scale_first = 2; + // value_first *= 100; + // value_first = value_first + 0.5; //round up // TODO(masn): These maxima should come from the respective accessors - const int64_t scaled_value_max = (1ULL << 32) - 1; // scaledValueOf*FixedSurface is 4 octets - const int64_t scale_factor_max = (1ULL << 8) - 1; // scaleFactorOf*FixedSurface is 1 octet - int64_t lscaled_value=0, lscale_factor=0; + const int64_t scaled_value_max = (1ULL << 32) - 1; // scaledValueOf*FixedSurface is 4 octets + const int64_t scale_factor_max = (1ULL << 8) - 1; // scaleFactorOf*FixedSurface is 1 octet + int64_t lscaled_value = 0, lscale_factor = 0; ret = compute_scaled_value_and_scale_factor(value_first, scaled_value_max, scale_factor_max, &lscaled_value, &lscale_factor); if (ret) { @@ -284,7 +191,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) return GRIB_SUCCESS; } -static int pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_class_g2level_t::pack_long(grib_accessor* a, const long* val, size_t* len) { int ret = 0; long value_first = *val; @@ -293,10 +200,10 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) char pressure_units[10] = {0,}; size_t pressure_units_len = 10; - grib_accessor_g2level* self = (grib_accessor_g2level*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int change_scale_and_value = 1; - bool tigge = is_tigge(hand); + grib_accessor_g2level_t* self = (grib_accessor_g2level_t*)a; + grib_handle* hand = grib_handle_of_accessor(a); + int change_scale_and_value = 1; + bool tigge = is_tigge(hand); if (*len != 1) return GRIB_WRONG_ARRAY_SIZE; @@ -317,16 +224,17 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) return ret; switch (type_first) { - case 100: // Pa + case 100: // Pa scale_first = 0; if (!strcmp(pressure_units, "hPa")) value_first *= 100; break; - case 109: // Potential vorticity surface (See ECC-1081) + case 109: // Potential vorticity surface (See ECC-1081) if (!tigge) { scale_first = 9; - } else { - scale_first = 6; // TIGGE data follows different rules + } + else { + scale_first = 6; // TIGGE data follows different rules } break; @@ -359,14 +267,13 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) return GRIB_SUCCESS; } -static int is_missing(grib_accessor* a) +int grib_accessor_class_g2level_t::is_missing(grib_accessor* a) { - grib_accessor_g2level* self = (grib_accessor_g2level*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int err = 0; - int ret = 0; + grib_accessor_g2level_t* self = (grib_accessor_g2level_t*)a; + grib_handle* hand = grib_handle_of_accessor(a); + int err = 0; - ret = grib_is_missing(hand, self->scale_first, &err) + + int ret = grib_is_missing(hand, self->scale_first, &err) + grib_is_missing(hand, self->value_first, &err); return ret; } diff --git a/src/accessor/grib_accessor_class_g2level.h b/src/accessor/grib_accessor_class_g2level.h new file mode 100644 index 000000000..55511b8f0 --- /dev/null +++ b/src/accessor/grib_accessor_class_g2level.h @@ -0,0 +1,37 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_g2level_t : public grib_accessor_long_t +{ +public: + /* Members defined in g2level */ + const char* type_first; + const char* scale_first; + const char* value_first; + const char* pressure_units; +}; + +class grib_accessor_class_g2level_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_g2level_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g2level_t{}; } + int is_missing(grib_accessor*) override; + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_g2lon.cc b/src/accessor/grib_accessor_class_g2lon.cc new file mode 100644 index 000000000..b7cb43d03 --- /dev/null +++ b/src/accessor/grib_accessor_class_g2lon.cc @@ -0,0 +1,61 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_g2lon.h" + +grib_accessor_class_g2lon_t _grib_accessor_class_g2lon{ "g2lon" }; +grib_accessor_class* grib_accessor_class_g2lon = &_grib_accessor_class_g2lon; + + +void grib_accessor_class_g2lon_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ + grib_accessor_class_double_t::init(a, l, c); + grib_accessor_g2lon_t* self = (grib_accessor_g2lon_t*)a; + int n = 0; + + self->longitude = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); +} + +int grib_accessor_class_g2lon_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ + grib_accessor_g2lon_t* self = (grib_accessor_g2lon_t*)a; + int ret = 0; + long longitude; + + if ((ret = grib_get_long(grib_handle_of_accessor(a), self->longitude, &longitude)) != GRIB_SUCCESS) + return ret; + + if (longitude == GRIB_MISSING_LONG) { + *val = GRIB_MISSING_DOUBLE; + return GRIB_SUCCESS; + } + + *val = ((double)longitude) / 1000000.0; + + return GRIB_SUCCESS; +} + +int grib_accessor_class_g2lon_t::pack_double(grib_accessor* a, const double* val, size_t* len) +{ + grib_accessor_g2lon_t* self = (grib_accessor_g2lon_t*)a; + long longitude; + double value = *val; + + if (value == GRIB_MISSING_DOUBLE) { + longitude = GRIB_MISSING_LONG; + } + else { + if (value < 0) + value += 360; + longitude = (long)(value * 1000000); + } + return grib_set_long(grib_handle_of_accessor(a), self->longitude, longitude); +} diff --git a/src/accessor/grib_accessor_class_g2lon.h b/src/accessor/grib_accessor_class_g2lon.h new file mode 100644 index 000000000..d3f5bd8ff --- /dev/null +++ b/src/accessor/grib_accessor_class_g2lon.h @@ -0,0 +1,31 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_double.h" + +class grib_accessor_g2lon_t : public grib_accessor_double_t +{ +public: + /* Members defined in g2lon */ + const char* longitude; +}; + +class grib_accessor_class_g2lon_t : public grib_accessor_class_double_t +{ +public: + grib_accessor_class_g2lon_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g2lon_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_g2step_range.cc b/src/accessor/grib_accessor_class_g2step_range.cc similarity index 50% rename from src/grib_accessor_class_g2step_range.cc rename to src/accessor/grib_accessor_class_g2step_range.cc index e1dd9494b..0c1b49e21 100644 --- a/src/grib_accessor_class_g2step_range.cc +++ b/src/accessor/grib_accessor_class_g2step_range.cc @@ -8,117 +8,20 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" +#include "grib_accessor_class_g2step_range.h" #include "step.h" #include "step_utilities.h" -#include -#include #include -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = pack_string;unpack_string;value_count - IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = unpack_double - IMPLEMENTS = unpack_string;pack_string - IMPLEMENTS = get_native_type;string_length - IMPLEMENTS = init - MEMBERS = const char* start_step - MEMBERS = const char* end_step - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int pack_string(grib_accessor*, const char*, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static size_t string_length(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g2step_range -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in g2step_range */ - const char* start_step; - const char* end_step; -} grib_accessor_g2step_range; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_g2step_range = { - &grib_accessor_class_gen, /* super */ - "g2step_range", /* name */ - sizeof(grib_accessor_g2step_range), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - &string_length, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - &pack_string, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; +grib_accessor_class_g2step_range_t _grib_accessor_class_g2step_range{ "g2step_range" }; grib_accessor_class* grib_accessor_class_g2step_range = &_grib_accessor_class_g2step_range; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_class_g2step_range_t::init(grib_accessor* a, const long l, grib_arguments* c) { - grib_accessor_g2step_range* self = (grib_accessor_g2step_range*)a; + grib_accessor_class_gen_t::init(a, l, c); + grib_accessor_g2step_range_t* self = (grib_accessor_g2step_range_t*)a; int n = 0; @@ -128,40 +31,40 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) a->length = 0; } -//static void dump(grib_accessor* a, grib_dumper* dumper) +// static void dump(grib_accessor* a, grib_dumper* dumper) //{ - //grib_dump_string(dumper, a, NULL); +// grib_dump_string(dumper, a, NULL); //} -static int unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_class_g2step_range_t::unpack_string(grib_accessor* a, char* val, size_t* len) { - grib_accessor_g2step_range* self = (grib_accessor_g2step_range*)a; - grib_handle* h = grib_handle_of_accessor(a); - int ret = 0; - size_t size = 0; - double start_step_value = 0; - double end_step_value = 0; + grib_accessor_g2step_range_t* self = (grib_accessor_g2step_range_t*)a; + grib_handle* h = grib_handle_of_accessor(a); + int ret = 0; + size_t size = 0; + double start_step_value = 0; + double end_step_value = 0; long step_units; int show_hours = a->context->grib_hourly_steps_with_units; if ((ret = grib_get_double_internal(h, self->start_step, &start_step_value)) != GRIB_SUCCESS) return ret; - if ((ret= grib_get_long_internal(h, "stepUnits", &step_units)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, "stepUnits", &step_units)) != GRIB_SUCCESS) return ret; try { - if (eccodes::Unit{step_units} == eccodes::Unit{eccodes::Unit::Value::MISSING}) { + if (eccodes::Unit{ step_units } == eccodes::Unit{ eccodes::Unit::Value::MISSING }) { if ((ret = grib_get_long_internal(h, "stepUnits", &step_units)) != GRIB_SUCCESS) return ret; } - char fp_format[128] = "%g"; + char fp_format[128] = "%g"; size_t fp_format_len = sizeof(fp_format); if ((ret = grib_get_string_internal(h, "formatForDoubles", fp_format, &fp_format_len)) != GRIB_SUCCESS) return ret; std::stringstream ss; - eccodes::Step start_step{start_step_value, step_units}; + eccodes::Step start_step{ start_step_value, step_units }; if (self->end_step == NULL) { ss << start_step.value(fp_format, show_hours); } @@ -169,7 +72,7 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len) if ((ret = grib_get_double_internal(h, self->end_step, &end_step_value)) != GRIB_SUCCESS) return ret; - eccodes::Step end_step{end_step_value, step_units}; + eccodes::Step end_step{ end_step_value, step_units }; if (start_step_value == end_step_value) { ss << end_step.value(fp_format, show_hours); @@ -189,23 +92,22 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len) memcpy(val, ss.str().c_str(), size); } catch (std::exception& e) { - grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_g2step_range::unpack_string: %s", e.what()); + grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_g2step_range_t::unpack_string: %s", e.what()); return GRIB_DECODING_ERROR; } return GRIB_SUCCESS; } - // Step range format: [-] // and can be in different units // stepRange="X" in instantaneous field is equivalent to set step=X // stepRange="X" in accumulated field is equivalent to startStep=X, endStep=startStep -static int pack_string(grib_accessor* a, const char* val, size_t* len) +int grib_accessor_class_g2step_range_t::pack_string(grib_accessor* a, const char* val, size_t* len) { - grib_accessor_g2step_range* self = (grib_accessor_g2step_range*)a; - grib_handle* h = grib_handle_of_accessor(a); - int ret = 0; + grib_accessor_g2step_range_t* self = (grib_accessor_g2step_range_t*)a; + grib_handle* h = grib_handle_of_accessor(a); + int ret = 0; long force_step_units; if ((ret = grib_get_long_internal(h, "forceStepUnits", &force_step_units)) != GRIB_SUCCESS) @@ -217,12 +119,12 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len) // If this key is defined (!= 255), it indicates that the stepUnits have been defined by the user. // Once this key is set, it has the highest priority: it automatically overrides certain units and the default value in stepUnits - if (h->loader) { // h->loader is set only when rebuilding or reparsing - force_step_units = 255; // See ECC-1768 and ECC-1800 + if (h->loader) { // h->loader is set only when rebuilding or reparsing + force_step_units = 255; // See ECC-1768 and ECC-1800 } try { - std::vector steps = parse_range(val, eccodes::Unit{force_step_units}); + std::vector steps = parse_range(val, eccodes::Unit{ force_step_units }); if (steps.size() == 0) { grib_context_log(a->context, GRIB_LOG_ERROR, "Could not parse step range: %s", val); return GRIB_INVALID_ARGUMENT; @@ -230,22 +132,22 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len) eccodes::Step step_0; eccodes::Step step_1; - if (eccodes::Unit{force_step_units} == eccodes::Unit{eccodes::Unit::Value::MISSING}) { + if (eccodes::Unit{ force_step_units } == eccodes::Unit{ eccodes::Unit::Value::MISSING }) { if (steps.size() > 1) std::tie(step_0, step_1) = find_common_units(steps[0].optimize_unit(), steps[1].optimize_unit()); else step_0 = steps[0].optimize_unit(); } else { - step_0 = eccodes::Step{steps[0].value(eccodes::Unit{force_step_units}), eccodes::Unit{force_step_units}}; + step_0 = eccodes::Step{ steps[0].value(eccodes::Unit{ force_step_units }), eccodes::Unit{ force_step_units } }; if (steps.size() > 1) { - step_1 = eccodes::Step{steps[1].value(eccodes::Unit{force_step_units}), eccodes::Unit{force_step_units}}; + step_1 = eccodes::Step{ steps[1].value(eccodes::Unit{ force_step_units }), eccodes::Unit{ force_step_units } }; } } if ((ret = grib_set_long_internal(h, "startStepUnit", step_0.unit().value()))) return ret; - if ((ret = set_step(h, "forecastTime" , "indicatorOfUnitOfTimeRange", step_0)) != GRIB_SUCCESS) + if ((ret = set_step(h, "forecastTime", "indicatorOfUnitOfTimeRange", step_0)) != GRIB_SUCCESS) return ret; if (self->end_step != NULL) { @@ -254,7 +156,8 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len) return ret; if ((ret = grib_set_long_internal(h, self->end_step, step_1.value()))) return ret; - } else { + } + else { if ((ret = grib_set_long_internal(h, "endStepUnit", step_0.unit().value()))) return ret; if ((ret = grib_set_long_internal(h, self->end_step, step_0.value()))) @@ -269,18 +172,18 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len) return GRIB_SUCCESS; } -static int value_count(grib_accessor* a, long* count) +int grib_accessor_class_g2step_range_t::value_count(grib_accessor* a, long* count) { *count = 1; return 0; } -static size_t string_length(grib_accessor* a) +size_t grib_accessor_class_g2step_range_t::string_length(grib_accessor* a) { return 255; } -static int pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_class_g2step_range_t::pack_long(grib_accessor* a, const long* val, size_t* len) { char buff[100]; size_t bufflen = 100; @@ -289,34 +192,33 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) return pack_string(a, buff, &bufflen); } - -static int unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_class_g2step_range_t::unpack_long(grib_accessor* a, long* val, size_t* len) { - grib_accessor_g2step_range* self = (grib_accessor_g2step_range*)a; - grib_handle* h = grib_handle_of_accessor(a); - int ret = 0; - long end_start_value = 0; - long end_step_value = 0; - long step_units = 0; + grib_accessor_g2step_range_t* self = (grib_accessor_g2step_range_t*)a; + grib_handle* h = grib_handle_of_accessor(a); + int ret = 0; + long end_start_value = 0; + long end_step_value = 0; + long step_units = 0; if ((ret = grib_get_long_internal(h, self->start_step, &end_start_value)) != GRIB_SUCCESS) return ret; try { if ((ret = grib_get_long_internal(h, "stepUnits", &step_units)) != GRIB_SUCCESS) throw std::runtime_error("Failed to get stepUnits"); - if (eccodes::Unit{step_units} == eccodes::Unit{eccodes::Unit::Value::MISSING}) { + if (eccodes::Unit{ step_units } == eccodes::Unit{ eccodes::Unit::Value::MISSING }) { if ((ret = grib_get_long_internal(h, "stepUnits", &step_units)) != GRIB_SUCCESS) return ret; } - eccodes::Step start_step{end_start_value, step_units}; + eccodes::Step start_step{ end_start_value, step_units }; if (self->end_step == NULL) { *val = start_step.value(); } else { if ((ret = grib_get_long_internal(h, self->end_step, &end_step_value)) != GRIB_SUCCESS) return ret; - eccodes::Step end_step{end_step_value, step_units}; + eccodes::Step end_step{ end_step_value, step_units }; *val = end_step.value(); } } @@ -328,15 +230,14 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) return GRIB_SUCCESS; } - -static int unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_class_g2step_range_t::unpack_double(grib_accessor* a, double* val, size_t* len) { - grib_accessor_g2step_range* self = (grib_accessor_g2step_range*)a; - grib_handle* h = grib_handle_of_accessor(a); - int ret = 0; - double end_start_value = 0; - double end_step_value = 0; - long step_units = 0; + grib_accessor_g2step_range_t* self = (grib_accessor_g2step_range_t*)a; + grib_handle* h = grib_handle_of_accessor(a); + int ret = 0; + double end_start_value = 0; + double end_step_value = 0; + long step_units = 0; if ((ret = grib_get_double_internal(h, self->start_step, &end_start_value)) != GRIB_SUCCESS) return ret; @@ -344,19 +245,19 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) throw std::runtime_error("Failed to get stepUnits"); try { - if (eccodes::Unit{step_units} == eccodes::Unit{eccodes::Unit::Value::MISSING}) { + if (eccodes::Unit{ step_units } == eccodes::Unit{ eccodes::Unit::Value::MISSING }) { if ((ret = grib_get_long_internal(h, "stepUnits", &step_units)) != GRIB_SUCCESS) return ret; } - eccodes::Step start_step{end_start_value, step_units}; + eccodes::Step start_step{ end_start_value, step_units }; if (self->end_step == NULL) { *val = start_step.value(); } else { if ((ret = grib_get_double_internal(h, self->end_step, &end_step_value)) != GRIB_SUCCESS) return ret; - eccodes::Step end_step{end_step_value, step_units}; + eccodes::Step end_step{ end_step_value, step_units }; *val = end_step.value(); } } @@ -368,8 +269,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) return GRIB_SUCCESS; } - -static int get_native_type(grib_accessor* a) +int grib_accessor_class_g2step_range_t::get_native_type(grib_accessor* a) { return GRIB_TYPE_STRING; } diff --git a/src/accessor/grib_accessor_class_g2step_range.h b/src/accessor/grib_accessor_class_g2step_range.h new file mode 100644 index 000000000..ec44546b3 --- /dev/null +++ b/src/accessor/grib_accessor_class_g2step_range.h @@ -0,0 +1,37 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_g2step_range_t : public grib_accessor_gen_t +{ +public: + /* Members defined in g2step_range */ + const char* start_step; + const char* end_step; +}; + +class grib_accessor_class_g2step_range_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_g2step_range_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_g2step_range_t{}; } + int get_native_type(grib_accessor*) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int pack_string(grib_accessor*, const char*, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + size_t string_length(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_gaussian_grid_name.cc b/src/accessor/grib_accessor_class_gaussian_grid_name.cc new file mode 100644 index 000000000..f6b79e794 --- /dev/null +++ b/src/accessor/grib_accessor_class_gaussian_grid_name.cc @@ -0,0 +1,88 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_gaussian_grid_name.h" + +grib_accessor_class_gaussian_grid_name_t _grib_accessor_class_gaussian_grid_name{ "gaussian_grid_name" }; +grib_accessor_class* grib_accessor_class_gaussian_grid_name = &_grib_accessor_class_gaussian_grid_name; + + +void grib_accessor_class_gaussian_grid_name_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ + grib_accessor_class_gen_t::init(a, len, arg); + grib_accessor_gaussian_grid_name_t* self = (grib_accessor_gaussian_grid_name_t*)a; + int n = 0; + + self->N = grib_arguments_get_name(a->parent->h, arg, n++); + self->Ni = grib_arguments_get_name(a->parent->h, arg, n++); + self->isOctahedral = grib_arguments_get_name(a->parent->h, arg, n++); + a->length = 0; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; +} + +int grib_accessor_class_gaussian_grid_name_t::get_native_type(grib_accessor* a) +{ + return GRIB_TYPE_STRING; +} + +#define MAX_GRIDNAME_LEN 16 + +int grib_accessor_class_gaussian_grid_name_t::unpack_string(grib_accessor* a, char* v, size_t* len) +{ + grib_accessor_gaussian_grid_name_t* self = (grib_accessor_gaussian_grid_name_t*)a; + + long N = 0, Ni = 0; + char tmp[MAX_GRIDNAME_LEN] = {0,}; + size_t length = 0; + int ret = GRIB_SUCCESS; + + if ((ret = grib_get_long_internal(a->parent->h, self->N, &N)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_get_long_internal(a->parent->h, self->Ni, &Ni)) != GRIB_SUCCESS) + return ret; + + if (Ni == GRIB_MISSING_LONG) { + /* Reduced gaussian grid */ + long isOctahedral = 0; + if ((ret = grib_get_long_internal(a->parent->h, self->isOctahedral, &isOctahedral)) != GRIB_SUCCESS) + return ret; + if (isOctahedral == 1) { + snprintf(tmp, sizeof(tmp), "O%ld", N); + } + else { + snprintf(tmp, sizeof(tmp), "N%ld", N); /* Classic */ + } + } + else { + /* Regular gaussian grid */ + snprintf(tmp, sizeof(tmp), "F%ld", N); + } + length = strlen(tmp) + 1; + + if (*len < length) { + const char* cclass_name = a->cclass->name; + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", + cclass_name, a->name, length, *len); + *len = length; + return GRIB_BUFFER_TOO_SMALL; + } + + strcpy(v, tmp); + *len = length; + return GRIB_SUCCESS; +} + +size_t grib_accessor_class_gaussian_grid_name_t::string_length(grib_accessor* a) +{ + return MAX_GRIDNAME_LEN; +} diff --git a/src/accessor/grib_accessor_class_gaussian_grid_name.h b/src/accessor/grib_accessor_class_gaussian_grid_name.h new file mode 100644 index 000000000..d67f80aa5 --- /dev/null +++ b/src/accessor/grib_accessor_class_gaussian_grid_name.h @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_gaussian_grid_name_t : public grib_accessor_gen_t +{ +public: + /* Members defined in gaussian_grid_name */ + const char* N; + const char* Ni; + const char* isOctahedral; +}; + +class grib_accessor_class_gaussian_grid_name_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_gaussian_grid_name_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_gaussian_grid_name_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + size_t string_length(grib_accessor*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_gds_is_present.cc b/src/accessor/grib_accessor_class_gds_is_present.cc new file mode 100644 index 000000000..b568b9bdd --- /dev/null +++ b/src/accessor/grib_accessor_class_gds_is_present.cc @@ -0,0 +1,89 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_gds_is_present.h" + +grib_accessor_class_gds_is_present_t _grib_accessor_class_gds_is_present{ "gds_is_present" }; +grib_accessor_class* grib_accessor_class_gds_is_present = &_grib_accessor_class_gds_is_present; + + +void grib_accessor_class_gds_is_present_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ + grib_accessor_class_long_t::init(a, l, c); + int n = 0; + grib_accessor_gds_is_present_t* self = (grib_accessor_gds_is_present_t*)a; + grib_handle* h = grib_handle_of_accessor(a); + self->gds_present = grib_arguments_get_name(h, c, n++); + self->grid_definition = grib_arguments_get_name(h, c, n++); + self->bitmap_present = grib_arguments_get_name(h, c, n++); + self->values = grib_arguments_get_name(h, c, n++); + + a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; + a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; + a->length = 0; +} + +int grib_accessor_class_gds_is_present_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ + grib_accessor_gds_is_present_t* self = (grib_accessor_gds_is_present_t*)a; + long missing = 255; + int ret = 0; + size_t size = 0; + double* values = NULL; + grib_context* c = a->context; + grib_handle* h = grib_handle_of_accessor(a); + + if (*val != 1) + return GRIB_NOT_IMPLEMENTED; + + if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) + return ret; + + values = (double*)grib_context_malloc(c, size * sizeof(double)); + if (!values) + return GRIB_OUT_OF_MEMORY; + + if ((ret = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) { + grib_context_free(c, values); + return ret; + } + + if ((ret = grib_set_long_internal(h, self->gds_present, *val)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_set_long_internal(h, self->bitmap_present, *val)) != GRIB_SUCCESS) + return ret; + + + if ((ret = grib_set_long_internal(h, self->grid_definition, missing)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) + return ret; + + grib_context_free(c, values); + + return GRIB_SUCCESS; +} + +int grib_accessor_class_gds_is_present_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ + int ret = 0; + grib_handle* h = grib_handle_of_accessor(a); + grib_accessor_gds_is_present_t* self = (grib_accessor_gds_is_present_t*)a; + + if ((ret = grib_get_long_internal(h, self->gds_present, val)) != GRIB_SUCCESS) + return ret; + + *len = 1; + + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_gds_is_present.h b/src/accessor/grib_accessor_class_gds_is_present.h new file mode 100644 index 000000000..d69619d44 --- /dev/null +++ b/src/accessor/grib_accessor_class_gds_is_present.h @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_gds_is_present_t : public grib_accessor_long_t +{ +public: + /* Members defined in gds_is_present */ + const char* gds_present; + const char* grid_definition; + const char* bitmap_present; + const char* values; +}; + +class grib_accessor_class_gds_is_present_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_gds_is_present_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_gds_is_present_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_gds_not_present_bitmap.cc b/src/accessor/grib_accessor_class_gds_not_present_bitmap.cc new file mode 100644 index 000000000..6691e2fea --- /dev/null +++ b/src/accessor/grib_accessor_class_gds_not_present_bitmap.cc @@ -0,0 +1,109 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_gds_not_present_bitmap.h" + +grib_accessor_class_gds_not_present_bitmap_t _grib_accessor_class_gds_not_present_bitmap{"gds_not_present_bitmap"}; +grib_accessor_class* grib_accessor_class_gds_not_present_bitmap = &_grib_accessor_class_gds_not_present_bitmap; + + +void grib_accessor_class_gds_not_present_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args){ + grib_accessor_class_gen_t::init(a, v, args); + int n = 0; + grib_accessor_gds_not_present_bitmap_t* self = (grib_accessor_gds_not_present_bitmap_t*)a; + grib_handle* hand = grib_handle_of_accessor(a); + + self->missing_value = grib_arguments_get_name(hand, args, n++); + self->number_of_values = grib_arguments_get_name(hand, args, n++); + self->number_of_points = grib_arguments_get_name(hand, args, n++); + self->latitude_of_first_point = grib_arguments_get_name(hand, args, n++); + self->ni = grib_arguments_get_name(hand, args, n++); + a->length = 0; +} + +int grib_accessor_class_gds_not_present_bitmap_t::value_count(grib_accessor* a, long* number_of_points){ + grib_accessor_gds_not_present_bitmap_t* self = (grib_accessor_gds_not_present_bitmap_t*)a; + *number_of_points = 0; + return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_points, number_of_points); +} + +int grib_accessor_class_gds_not_present_bitmap_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + grib_accessor_gds_not_present_bitmap_t* self = (grib_accessor_gds_not_present_bitmap_t*)a; + grib_handle* hand = grib_handle_of_accessor(a); + + long number_of_points = 0, number_of_values = 0, ni = 0; + long latitude_of_first_point = 0; + size_t i = 0; + size_t n_vals = 0; + long nn = 0; + long missing_value; + + double* coded_vals = NULL; + int err = a->value_count(&nn); + n_vals = nn; + if (err) + return err; + + if ((err = grib_get_long(hand, self->number_of_points, &number_of_points)) != GRIB_SUCCESS) + return err; + + if ((err = grib_get_long(hand, self->number_of_values, &number_of_values)) != GRIB_SUCCESS) + return err; + + if ((err = grib_get_long(hand, self->latitude_of_first_point, &latitude_of_first_point)) != GRIB_SUCCESS) + return err; + + if ((err = grib_get_long(hand, self->missing_value, &missing_value)) != GRIB_SUCCESS) + return err; + + if ((err = grib_get_long(hand, self->ni, &ni)) != GRIB_SUCCESS) + return err; + + if (*len < number_of_points) { + *len = n_vals; + return GRIB_ARRAY_TOO_SMALL; + } + + if (number_of_values > 0) { + coded_vals = (double*)grib_context_malloc(a->context, number_of_values * sizeof(double)); + + if (coded_vals == NULL) + return GRIB_OUT_OF_MEMORY; + } + + if (latitude_of_first_point == 0) { + for (i = 0; i < number_of_values; i++) + val[i] = 1; + for (i = number_of_values; i < number_of_points; i++) + val[i] = 0; + } + else { + for (i = 0; i < ni - 1; i++) + val[i] = 0; + for (i = ni - 1; i < number_of_points; i++) + val[i] = 1; + } + + *len = number_of_points; + + grib_context_free(a->context, coded_vals); + return err; +} + +int grib_accessor_class_gds_not_present_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len){ + // See deprecated/grib_accessor_class_gds_not_present_bitmap.cc for + // a possible implementation + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_class_gds_not_present_bitmap_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_DOUBLE; +} diff --git a/src/accessor/grib_accessor_class_gds_not_present_bitmap.h b/src/accessor/grib_accessor_class_gds_not_present_bitmap.h new file mode 100644 index 000000000..bf9c0c012 --- /dev/null +++ b/src/accessor/grib_accessor_class_gds_not_present_bitmap.h @@ -0,0 +1,37 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_gds_not_present_bitmap_t : public grib_accessor_gen_t +{ +public: + /* Members defined in gds_not_present_bitmap */ + const char* missing_value; + const char* number_of_values; + const char* number_of_points; + const char* latitude_of_first_point; + const char* ni; +}; + +class grib_accessor_class_gds_not_present_bitmap_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_gds_not_present_bitmap_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_gds_not_present_bitmap_t{}; } + int get_native_type(grib_accessor*) override; + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_gen.cc b/src/accessor/grib_accessor_class_gen.cc new file mode 100644 index 000000000..7223f39a9 --- /dev/null +++ b/src/accessor/grib_accessor_class_gen.cc @@ -0,0 +1,751 @@ +/* + * (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. + */ + +#include "grib_accessor.h" +#include "grib_accessor_class_gen.h" +#include + +// ======================== grib_accessor_gen ======================== +void grib_accessor_gen_t::dump(grib_dumper* f) +{ + return cclass->dump(this, f); +} +int grib_accessor_gen_t::pack_missing() +{ + // grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is packing (double) %g",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?(*v):0); + return cclass->pack_missing(this); +} +// int grib_accessor_gen_t::pack_zero(grib_accessor* a) +// { +// return cclass->clear(a); +// } + +int grib_accessor_gen_t::is_missing_internal() +{ + return cclass->is_missing(this); +} + +int grib_accessor_gen_t::pack_double(const double* v, size_t* len) +{ + return cclass->pack_double(this, v, len); +} + +int grib_accessor_gen_t::pack_float(const float* v, size_t* len) +{ + return cclass->pack_float(this, v, len); +} + +int grib_accessor_gen_t::pack_expression(grib_expression* e) +{ + return cclass->pack_expression(this, e); +} + +int grib_accessor_gen_t::pack_string(const char* v, size_t* len) +{ + return cclass->pack_string(this, v, len); +} + +int grib_accessor_gen_t::pack_string_array(const char** v, size_t* len) +{ + return cclass->pack_string_array(this, v, len); +} + +int grib_accessor_gen_t::pack_long(const long* v, size_t* len) +{ + return cclass->pack_long(this, v, len); +} + +int grib_accessor_gen_t::pack_bytes(const unsigned char* v, size_t* len) +{ + return cclass->pack_bytes(this, v, len); +} + +int grib_accessor_gen_t::unpack_bytes(unsigned char* v, size_t* len) +{ + return cclass->unpack_bytes(this, v, len); +} + +int grib_accessor_gen_t::unpack_double_subarray(double* v, size_t start, size_t len) +{ + return cclass->unpack_double_subarray(this, v, start, len); +} + +int grib_accessor_gen_t::unpack_double(double* v, size_t* len) +{ + return cclass->unpack_double(this, v, len); +} + +int grib_accessor_gen_t::unpack_float(float* v, size_t* len) +{ + return cclass->unpack_float(this, v, len); +} + +int grib_accessor_gen_t::unpack_double_element(size_t i, double* v) +{ + return cclass->unpack_double_element(this, i, v); +} + +int grib_accessor_gen_t::unpack_float_element(size_t i, float* v) +{ + // return cclass->unpack_float_element(this, i, v); + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_gen_t::unpack_long(long* v, size_t* len) +{ + return cclass->unpack_long(this, v, len); +} + +long grib_accessor_gen_t::get_native_type() +{ + return cclass->get_native_type(this); +} + +long grib_accessor_gen_t::get_next_position_offset() +{ + return cclass->next_offset(this); +} + +long grib_accessor_gen_t::string_length() +{ + return cclass->string_length(this); +} + +long grib_accessor_gen_t::byte_offset() +{ + return cclass->byte_offset(this); +} + +long grib_accessor_gen_t::byte_count() +{ + return cclass->byte_count(this); +} + +int grib_accessor_gen_t::value_count(long* count) +{ + return cclass->value_count(this, count); +} + +int grib_accessor_gen_t::notify_change(grib_accessor* changed) +{ + return cclass->notify_change(this, changed); +} + +// Get the values for the indices passed in. +// The length of the 'index_array' argument should be 'len' and 'val_array' should also contain at least 'len' elements +int grib_accessor_gen_t::unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) +{ + return cclass->unpack_double_element_set(this, index_array, len, val_array); +} +int grib_accessor_gen_t::unpack_float_element_set(const size_t* index_array, size_t len, float* val_array) +{ + throw std::runtime_error("grib_unpack_float_element_set not implemented"); +} +int grib_accessor_gen_t::unpack_string(char* v, size_t* len) +{ + return cclass->unpack_string(this, v, len); +} +int grib_accessor_gen_t::unpack_string_array(char** v, size_t* len) +{ + return cclass->unpack_string_array(this, v, len); +} + +void grib_accessor_gen_t::init_accessor(const long len, grib_arguments* args) +{ + this->cclass->init(this, len, args); +} + +grib_accessor* grib_accessor_gen_t::clone(grib_section* s, int* err) +{ + grib_context* ct = this->context; + grib_context_log(ct, GRIB_LOG_DEBUG, "clone %s ==> %s", cclass->name, this->name); + return cclass->make_clone(this, s, err); +} + +void grib_accessor_gen_t::update_size(size_t len) +{ + cclass->update_size(this, len); +} + +int grib_accessor_gen_t::nearest_smaller_value(double val, double* nearest) +{ + return cclass->nearest_smaller_value(this, val, nearest); +} + +size_t grib_accessor_gen_t::preferred_size(int from_handle) +{ + return cclass->preferred_size(this, from_handle); +} + +grib_accessor* grib_accessor_gen_t::next_accessor() +{ + return cclass->next(this, 1); +} + +void grib_accessor_gen_t::resize(size_t new_size) +{ + cclass->resize(this, new_size); +} + +// For this one, ALL destroy are called +void grib_accessor_gen_t::destroy(grib_context* ct) +{ + cclass->destroy(ct, this); + delete this; +} + + + + +// ======================== grib_accessor_class_gen ======================== + + +grib_accessor_class_gen_t _grib_accessor_class_gen = grib_accessor_class_gen_t("gen"); +grib_accessor_class* grib_accessor_class_gen = &_grib_accessor_class_gen; + +void grib_accessor_class_gen_t::init(grib_accessor* a, const long len, grib_arguments* param) +{ + grib_action* act = (grib_action*)(a->creator); + if (a->flags & GRIB_ACCESSOR_FLAG_TRANSIENT) { + a->length = 0; + if (!a->vvalue) + a->vvalue = (grib_virtual_value*)grib_context_malloc_clear(a->context, sizeof(grib_virtual_value)); + a->vvalue->type = a->get_native_type(); + a->vvalue->length = len; + if (act->default_value != NULL) { + const char* p = 0; + size_t s_len = 1; + long l; + int ret = 0; + double d; + char tmp[1024]; + grib_expression* expression = grib_arguments_get_expression(grib_handle_of_accessor(a), act->default_value, 0); + int type = grib_expression_native_type(grib_handle_of_accessor(a), expression); + switch (type) { + // TODO(maee): add single-precision case + + case GRIB_TYPE_DOUBLE: + grib_expression_evaluate_double(grib_handle_of_accessor(a), expression, &d); + a->pack_double(&d, &s_len); + break; + + case GRIB_TYPE_LONG: + grib_expression_evaluate_long(grib_handle_of_accessor(a), expression, &l); + a->pack_long(&l, &s_len); + break; + + default: + s_len = sizeof(tmp); + p = grib_expression_evaluate_string(grib_handle_of_accessor(a), expression, tmp, &s_len, &ret); + if (ret != GRIB_SUCCESS) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to evaluate %s as string", a->name); + Assert(0); + } + s_len = strlen(p) + 1; + a->pack_string(p, &s_len); + break; + } + } + } + else { + a->length = len; + } +} + +void grib_accessor_class_gen_t::dump(grib_accessor* a, grib_dumper* dumper) +{ + const int type = a->get_native_type(); + switch (type) { + case GRIB_TYPE_STRING: + grib_dump_string(dumper, a, NULL); + break; + case GRIB_TYPE_DOUBLE: + grib_dump_double(dumper, a, NULL); + break; + case GRIB_TYPE_LONG: + grib_dump_long(dumper, a, NULL); + break; + default: + grib_dump_bytes(dumper, a, NULL); + } +} + +long grib_accessor_class_gen_t::next_offset(grib_accessor* a) +{ + return a->offset + a->length; +} + +int grib_accessor_class_gen_t::value_count(grib_accessor* a, long* count) +{ + *count = 1; + return 0; +} + +size_t grib_accessor_class_gen_t::string_length(grib_accessor* a) +{ + return 1024; +} + +long grib_accessor_class_gen_t::byte_count(grib_accessor* a) +{ + return a->length; +} + +int grib_accessor_class_gen_t::get_native_type(grib_accessor* a) +{ + grib_context_log(a->context, GRIB_LOG_ERROR, + "Accessor %s [%s] must implement 'get_native_type'", a->name, a->cclass->name); + return GRIB_TYPE_UNDEFINED; +} + +long grib_accessor_class_gen_t::byte_offset(grib_accessor* a) +{ + return a->offset; +} + +int grib_accessor_class_gen_t::unpack_bytes(grib_accessor* a, unsigned char* val, size_t* len) +{ + unsigned char* buf = grib_handle_of_accessor(a)->buffer->data; + const long length = a->byte_count(); + const long offset = a->byte_offset(); + + if (*len < length) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it is %ld bytes long", a->name, length); + *len = length; + return GRIB_ARRAY_TOO_SMALL; + } + + memcpy(val, buf + offset, length); + *len = length; + + return GRIB_SUCCESS; +} + +int grib_accessor_class_gen_t::clear(grib_accessor* a) +{ + unsigned char* buf = grib_handle_of_accessor(a)->buffer->data; + const long length = a->byte_count(); + const long offset = a->byte_offset(); + + memset(buf + offset, 0, length); + + return GRIB_SUCCESS; +} + +int grib_accessor_class_gen_t::unpack_long(grib_accessor* a, long* v, size_t* len) +{ + is_overridden_[UNPACK_LONG] = 0; + int type = GRIB_TYPE_UNDEFINED; + if (is_overridden_[UNPACK_DOUBLE] == 1) { + double val = 0.0; + size_t l = 1; + a->unpack_double(&val, &l); + if (is_overridden_[UNPACK_DOUBLE] == 1) { + if (val == GRIB_MISSING_DOUBLE) + *v = GRIB_MISSING_LONG; + else + *v = (long)val; + grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting double %s to long", a->name); + return GRIB_SUCCESS; + } + } + + if (is_overridden_[UNPACK_STRING] == 1) { + char val[1024]; + size_t l = sizeof(val); + char* last = NULL; + a->unpack_string(val, &l); + + if (is_overridden_[UNPACK_STRING] == 1) { + *v = strtol(val, &last, 10); + + if (*last == 0) { + grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting string %s to long", a->name); + return GRIB_SUCCESS; + } + } + } + + grib_context_log(a->context, GRIB_LOG_ERROR, "Cannot unpack key '%s' as long", a->name); + if (grib_get_native_type(grib_handle_of_accessor(a), a->name, &type) == GRIB_SUCCESS) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Hint: Try unpacking as %s", grib_get_type_name(type)); + } + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_class_gen_t::unpack_double(grib_accessor* a, double* v, size_t* len) +{ + return unpack_helper(a, v, len); +} + +int grib_accessor_class_gen_t::unpack_float(grib_accessor* a, float* v, size_t* len) +{ + return unpack_helper(a, v, len); +} + +int grib_accessor_class_gen_t::unpack_string(grib_accessor* a, char* v, size_t* len) +{ + is_overridden_[UNPACK_STRING] = 0; + + int err = 0; + if (is_overridden_[UNPACK_DOUBLE] == 1) { + double val = 0.0; + size_t l = 1; + err = a->unpack_double(&val, &l); + if (is_overridden_[UNPACK_DOUBLE] == 1) { + if (err) return err; + snprintf(v, 64, "%g", val); + *len = strlen(v); + grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting double %s to string", a->name); + return GRIB_SUCCESS; + } + } + + if (is_overridden_[UNPACK_LONG] == 1) { + long val = 0; + size_t l = 1; + err = a->unpack_long(&val, &l); + if (is_overridden_[UNPACK_LONG] == 1) { + if (err) return err; + snprintf(v, 64, "%ld", val); + *len = strlen(v); + grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting long %s to string\n", a->name); + return GRIB_SUCCESS; + } + } + + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_class_gen_t::unpack_string_array(grib_accessor* a, char** v, size_t* len) +{ + size_t length = 0; + + int err = grib_get_string_length_acc(a, &length); + if (err) + return err; + v[0] = (char*)grib_context_malloc_clear(a->context, length); + a->unpack_string(v[0], &length); // TODO(masn): check return value + *len = 1; + + return GRIB_SUCCESS; +} + +int grib_accessor_class_gen_t::pack_expression(grib_accessor* a, grib_expression* e) +{ + size_t len = 1; + long lval = 0; + double dval = 0; + const char* cval = NULL; + int ret = 0; + grib_handle* hand = grib_handle_of_accessor(a); + + // Use the native type of the expression not the accessor + switch (grib_expression_native_type(hand, e)) { + case GRIB_TYPE_LONG: { + len = 1; + ret = grib_expression_evaluate_long(hand, e, &lval); + if (ret != GRIB_SUCCESS) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to set %s as long (from %s)", + a->name, e->cclass->name); + return ret; + } + /*if (hand->context->debug) + printf("ECCODES DEBUG grib_accessor_class_gen_t::pack_expression %s %ld\n", a->name,lval);*/ + return a->pack_long(&lval, &len); + } + + case GRIB_TYPE_DOUBLE: { + len = 1; + ret = grib_expression_evaluate_double(hand, e, &dval); + if (ret != GRIB_SUCCESS) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to set %s as double (from %s)", + a->name, e->cclass->name); + return ret; + } + /*if (hand->context->debug) + printf("ECCODES DEBUG grib_accessor_class_gen_t::pack_expression %s %g\n", a->name, dval);*/ + return a->pack_double(&dval, &len); + } + + case GRIB_TYPE_STRING: { + char tmp[1024]; + len = sizeof(tmp); + cval = grib_expression_evaluate_string(hand, e, tmp, &len, &ret); + if (ret != GRIB_SUCCESS) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to set %s as string (from %s)", + a->name, e->cclass->name); + return ret; + } + len = strlen(cval); + /*if (hand->context->debug) + printf("ECCODES DEBUG grib_accessor_class_gen_t::pack_expression %s %s\n", a->name, cval);*/ + return a->pack_string(cval, &len); + } + } + + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_class_gen_t::pack_long(grib_accessor* a, const long* v, size_t* len) +{ + is_overridden_[PACK_LONG] = 0; + grib_context* c = a->context; + if (is_overridden_[PACK_DOUBLE]) { + double* val = (double*)grib_context_malloc(c, *len * (sizeof(double))); + if (!val) { + grib_context_log(c, GRIB_LOG_ERROR, "Unable to allocate %zu bytes", *len * (sizeof(double))); + return GRIB_OUT_OF_MEMORY; + } + for (size_t i = 0; i < *len; i++) + val[i] = v[i]; + int ret = a->pack_double(val, len); + grib_context_free(c, val); + if (is_overridden_[PACK_DOUBLE]) { + return ret; + } + } + + grib_context_log(c, GRIB_LOG_ERROR, "Should not pack '%s' as an integer", a->name); + if (is_overridden_[PACK_STRING]) { + grib_context_log(c, GRIB_LOG_ERROR, "Try packing as a string"); + } + + return GRIB_NOT_IMPLEMENTED; +} + +int pack_double_array_as_long(grib_accessor* a, const double* v, size_t* len) +{ + grib_context* c = a->context; + int ret = GRIB_SUCCESS; + size_t numBytes = *len * (sizeof(long)); + long* lValues = (long*)grib_context_malloc(c, numBytes); + if (!lValues) { + grib_context_log(c, GRIB_LOG_ERROR, "Unable to allocate %ld bytes", numBytes); + return GRIB_OUT_OF_MEMORY; + } + for (size_t i = 0; i < *len; i++) + lValues[i] = (long)v[i]; /* convert from double to long */ + ret = a->pack_long(lValues, len); + grib_context_free(c, lValues); + return ret; +} + +int grib_accessor_class_gen_t::pack_double(grib_accessor* a, const double* v, size_t* len) +{ + is_overridden_[PACK_DOUBLE] = 0; + grib_context* c = a->context; + + if (is_overridden_[PACK_LONG] || strcmp(a->cclass->name, "codetable") == 0) { + /* ECC-648: Special case of codetable */ + return pack_double_array_as_long(a, v, len); + } + + grib_context_log(c, GRIB_LOG_ERROR, "Should not pack '%s' as a double", a->name); + if (is_overridden_[PACK_STRING]) { + grib_context_log(c, GRIB_LOG_ERROR, "Try packing as a string"); + } + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_class_gen_t::pack_string_array(grib_accessor* a, const char** v, size_t* len) +{ + int err = 0; + size_t length = 0; + grib_accessor* as = 0; + + as = a; + long i = (long)*len - 1; + while (as && i >= 0) { + length = strlen(v[i]); + err = as->pack_string(v[i], &length); + if (err) + return err; + --i; + as = as->same; + } + return GRIB_SUCCESS; +} + +int grib_accessor_class_gen_t::pack_string(grib_accessor* a, const char* v, size_t* len) +{ + is_overridden_[PACK_STRING] = 0; + if (is_overridden_[PACK_DOUBLE]) { + size_t l = 1; + char* endPtr = NULL; /* for error handling */ + double val = strtod(v, &endPtr); + if (*endPtr) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s: Invalid value (%s) for key '%s'. String cannot be converted to a double", + __func__, v, a->name); + return GRIB_WRONG_TYPE; + } + return a->pack_double(&val, &l); + } + + if (is_overridden_[PACK_LONG]) { + size_t l = 1; + long val = atol(v); + int err = a->pack_long(&val, &l); + if (is_overridden_[PACK_LONG]) { + return err; + } + } + + grib_context_log(a->context, GRIB_LOG_ERROR, "Should not pack '%s' as string", a->name); + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_class_gen_t::pack_bytes(grib_accessor* a, const unsigned char* val, size_t* len) +{ + const size_t length = *len; + if (length != a->length) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "pack_bytes: Wrong size (%zu) for %s. It is %ld bytes long", + length, a->name, a->length); + return GRIB_BUFFER_TOO_SMALL; + } + grib_buffer_replace(a, val, length, 1, 1); + return GRIB_SUCCESS; +} + +void grib_accessor_class_gen_t::destroy(grib_context* ct, grib_accessor* a) +{ + grib_dependency_remove_observed(a); + grib_dependency_remove_observer(a); + if (a->vvalue != NULL) { + grib_context_free(ct, a->vvalue); + a->vvalue = NULL; + } + /*grib_context_log(ct,GRIB_LOG_DEBUG,"address=%p",a);*/ +} + +grib_section* grib_accessor_class_gen_t::sub_section(grib_accessor* a) +{ + return NULL; +} + +int grib_accessor_class_gen_t::notify_change(grib_accessor* self, grib_accessor* observed) +{ + /* Default behaviour is to notify creator */ + return grib_action_notify_change(self->creator, self, observed); +} + +void grib_accessor_class_gen_t::update_size(grib_accessor* a, size_t s) +{ + grib_context_log(a->context, GRIB_LOG_FATAL, + "Accessor %s [%s] must implement 'update_size'", a->name, a->cclass->name); +} + +grib_accessor* grib_accessor_class_gen_t::next(grib_accessor* a, int mod) +{ + grib_accessor* next = NULL; + if (a->next_) { + next = a->next_; + } + else { + if (a->parent->owner) + next = a->parent->owner->cclass->next(a->parent->owner, 0); + } + return next; +} + +int grib_accessor_class_gen_t::compare(grib_accessor* a, grib_accessor* b) +{ + return GRIB_NOT_IMPLEMENTED; +} + +/* Redefined in all padding */ + +size_t grib_accessor_class_gen_t::preferred_size(grib_accessor* a, int from_handle) +{ + return a->length; +} + +int grib_accessor_class_gen_t::is_missing(grib_accessor* a) +{ + int i = 0; + int is_missing = 1; + unsigned char ones = 0xff; + unsigned char* v = NULL; + + if (a->flags & GRIB_ACCESSOR_FLAG_TRANSIENT) { + if (a->vvalue == NULL) { + grib_context_log(a->context, GRIB_LOG_ERROR, "%s internal error (flags=0x%lX)", a->name, a->flags); + Assert(!"grib_accessor_class_gen_t::is_missing(): a->vvalue == NULL"); + return 0; + } + return a->vvalue->missing; + } + Assert(a->length >= 0); + + v = grib_handle_of_accessor(a)->buffer->data + a->offset; + + for (i = 0; i < a->length; i++) { + if (*v != ones) { + is_missing = 0; + break; + } + v++; + } + + return is_missing; +} + +int grib_accessor_class_gen_t::unpack_double_element(grib_accessor* a, size_t i, double* val) +{ + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_class_gen_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) +{ + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_class_gen_t::unpack_double_subarray(grib_accessor* a, double* val, size_t start, size_t len) +{ + return GRIB_NOT_IMPLEMENTED; +} + +grib_accessor* grib_accessor_class_gen_t::make_clone(grib_accessor* a, grib_section* s, int* err) +{ + *err = GRIB_NOT_IMPLEMENTED; + return NULL; +} + + + + +grib_accessor_class_gen_t::~grib_accessor_class_gen_t(){}; + +void grib_accessor_class_gen_t::post_init(grib_accessor*){ + return; +}; +int grib_accessor_class_gen_t::pack_missing(grib_accessor*) { + throw std::runtime_error("grib_accessor_class_gen_t::pack_missing not implemented"); +}; +int grib_accessor_class_gen_t::pack_float(grib_accessor*, const float*, size_t* len) { + throw std::runtime_error("grib_accessor_class_gen_t::pack_float not implemented"); +}; +void grib_accessor_class_gen_t::resize(grib_accessor*, size_t) { + throw std::runtime_error("grib_accessor_class_gen_t::resize not implemented"); +}; +int grib_accessor_class_gen_t::nearest_smaller_value(grib_accessor*, double, double*) { + throw std::runtime_error("grib_accessor_class_gen_t::nearest_smaller_value not implemented"); +}; +int grib_accessor_class_gen_t::unpack_float_element(grib_accessor*, size_t, float*) { + throw std::runtime_error("grib_accessor_class_gen_t::unpack_float_element not implemented"); +}; +int unpack_element_set(grib_accessor*, const size_t*, size_t, double*) { + throw std::runtime_error("grib_accessor_class_gen_t::unpack_element_set not implemented"); +}; +int grib_accessor_class_gen_t::unpack_float_element_set(grib_accessor*, const size_t*, size_t, float*) { + throw std::runtime_error("grib_accessor_class_gen_t::unpack_float_element_set not implemented"); +}; diff --git a/src/accessor/grib_accessor_class_gen.h b/src/accessor/grib_accessor_class_gen.h new file mode 100644 index 000000000..deba6cad2 --- /dev/null +++ b/src/accessor/grib_accessor_class_gen.h @@ -0,0 +1,168 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_api_internal.h" +#include "grib_accessor.h" +#include + +class grib_accessor_gen_t : public grib_accessor { + void init_accessor(const long, grib_arguments*) override; + void dump(grib_dumper* f) override; + int pack_missing() override; + //int grib_pack_zero(grib_accessor* a) override; + int is_missing_internal() override; + int pack_double(const double* v, size_t* len) override; + int pack_float(const float* v, size_t* len) override; + int pack_expression(grib_expression* e) override; + int pack_string(const char* v, size_t* len) override; + int pack_string_array(const char** v, size_t* len) override; + int pack_long(const long* v, size_t* len) override; + int pack_bytes(const unsigned char* v, size_t* len) override; + int unpack_bytes(unsigned char* v, size_t* len) override; + int unpack_double_subarray(double* v, size_t start, size_t len) override; + int unpack_double(double* v, size_t* len) override; + int unpack_float(float* v, size_t* len) override; + int unpack_double_element(size_t i, double* v) override; + int unpack_float_element(size_t i, float* v) override; + int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; + int unpack_float_element_set(const size_t* index_array, size_t len, float* val_array) override; + int unpack_string(char* v, size_t* len) override; + int unpack_string_array(char** v, size_t* len) override; + int unpack_long(long* v, size_t* len) override; + long get_native_type() override; + long get_next_position_offset() override; + long string_length() override; + long byte_offset() override; + long byte_count() override; + int value_count(long* count) override; + int notify_change(grib_accessor* changed) override; + grib_accessor* clone(grib_section* s, int* err) override; + void update_size(size_t len) override; + int nearest_smaller_value(double val, double* nearest) override; + size_t preferred_size(int from_handle) override; + grib_accessor* next_accessor() override; + void resize(size_t new_size) override; + void destroy(grib_context* ct) override; +}; + +class grib_accessor_class_gen_t : public grib_accessor_class +{ +public: + grib_accessor_class_gen_t(const char* name) : grib_accessor_class{name} {} + ~grib_accessor_class_gen_t(); + + grib_accessor* create_empty_accessor() override{ return new grib_accessor_gen_t(); } + grib_section* sub_section(grib_accessor* a) override; + int get_native_type(grib_accessor*) override; + int pack_missing(grib_accessor*) override; + int is_missing(grib_accessor*) override; + int pack_bytes(grib_accessor*, const unsigned char*, size_t* len) override; + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int pack_float(grib_accessor*, const float* val, size_t* len) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int pack_string(grib_accessor*, const char*, size_t* len) override; + int pack_string_array(grib_accessor*, const char**, size_t* len) override; + int pack_expression(grib_accessor*, grib_expression*) override; + int unpack_bytes(grib_accessor*, unsigned char*, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_float(grib_accessor*, float* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + int unpack_string_array(grib_accessor*, char**, size_t* len) override; + size_t string_length(grib_accessor*) override; + long byte_count(grib_accessor*) override; + long byte_offset(grib_accessor*) override; + long next_offset(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void destroy(grib_context*, grib_accessor*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + void post_init(grib_accessor*) override; + int notify_change(grib_accessor*, grib_accessor*) override; + void update_size(grib_accessor*, size_t) override; + size_t preferred_size(grib_accessor*, int) override; + void resize(grib_accessor*, size_t) override; + int nearest_smaller_value(grib_accessor*, double, double*) override; + grib_accessor* next(grib_accessor*, int) override; + int compare(grib_accessor*, grib_accessor*) override; + int unpack_double_element(grib_accessor*, size_t i, double* val) override; + int unpack_float_element(grib_accessor*, size_t i, float* val) override; + int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override; + int unpack_float_element_set(grib_accessor*, const size_t* index_array, size_t len, float* val_array) override; + int unpack_double_subarray(grib_accessor*, double* val, size_t start, size_t len) override; + int clear(grib_accessor*) override; + grib_accessor* make_clone(grib_accessor*, grib_section*, int*) override; + + template + int unpack_helper(grib_accessor* a, T* v, size_t* len); + +private: + enum { + PACK_DOUBLE, + PACK_FLOAT, + PACK_LONG, + PACK_STRING, + UNPACK_DOUBLE, + UNPACK_FLOAT, + UNPACK_LONG, + UNPACK_STRING, + }; + std::bitset<8> is_overridden_ = 0b11111111; +}; + + +template +int grib_accessor_class_gen_t::unpack_helper(grib_accessor* a, T* v, size_t* len) +{ + static_assert(std::is_floating_point::value, "Requires floating point numbers"); + int type = GRIB_TYPE_UNDEFINED; + const char* Tname = type_to_string(*v); + + if constexpr (std::is_same_v) { + is_overridden_[UNPACK_FLOAT] = 0; + } + else if constexpr (std::is_same_v) { + is_overridden_[UNPACK_DOUBLE] = 0; + } + + if (is_overridden_[UNPACK_LONG]) { + long val = 0; + size_t l = 1; + a->unpack_long(&val, &l); + if (is_overridden_[UNPACK_LONG]) { + *v = val; + grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting long %s to %s", a->name, Tname); + return GRIB_SUCCESS; + } + } + + if (is_overridden_[UNPACK_STRING]) { + char val[1024]; + size_t l = sizeof(val); + char* last = NULL; + a->unpack_string(val, &l); + if (is_overridden_[UNPACK_STRING]) { + *v = strtod(val, &last); + if (*last == 0) { /* conversion of string to double worked */ + grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting string %s to %s", a->name, Tname); + return GRIB_SUCCESS; + } + } + } + + grib_context_log(a->context, GRIB_LOG_ERROR, "Cannot unpack key '%s' as %s", a->name, Tname); + if (grib_get_native_type(grib_handle_of_accessor(a), a->name, &type) == GRIB_SUCCESS) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Hint: Try unpacking as %s", grib_get_type_name(type)); + } + + return GRIB_NOT_IMPLEMENTED; +} diff --git a/src/accessor/grib_accessor_class_getenv.cc b/src/accessor/grib_accessor_class_getenv.cc new file mode 100644 index 000000000..d812cc276 --- /dev/null +++ b/src/accessor/grib_accessor_class_getenv.cc @@ -0,0 +1,62 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_getenv.h" + +grib_accessor_class_getenv_t _grib_accessor_class_getenv{"getenv"}; +grib_accessor_class* grib_accessor_class_getenv = &_grib_accessor_class_getenv; + + +void grib_accessor_class_getenv_t::init(grib_accessor* a, const long l, grib_arguments* args){ + grib_accessor_class_ascii_t::init(a, l, args); + grib_accessor_getenv_t* self = (grib_accessor_getenv_t*)a; + static char undefined[] = "undefined"; + + self->name = grib_arguments_get_string(grib_handle_of_accessor(a), args, 0); + self->default_value = grib_arguments_get_string(grib_handle_of_accessor(a), args, 1); + if (!self->default_value) + self->default_value = undefined; + self->value = 0; +} + +int grib_accessor_class_getenv_t::pack_string(grib_accessor* a, const char* val, size_t* len){ + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_class_getenv_t::unpack_string(grib_accessor* a, char* val, size_t* len){ + grib_accessor_getenv_t* self = (grib_accessor_getenv_t*)a; + char* v = 0; + size_t l = 0; + + if (!self->value) { + v = getenv(self->name); + if (!v) + v = (char*)self->default_value; + self->value = v; + } + + l = strlen(self->value); + if (*len < l) + return GRIB_BUFFER_TOO_SMALL; + snprintf(val, 1024, "%s", self->value); + *len = strlen(self->value); + + return GRIB_SUCCESS; +} + +int grib_accessor_class_getenv_t::value_count(grib_accessor* a, long* count){ + *count = 1; + return 0; +} + +size_t grib_accessor_class_getenv_t::string_length(grib_accessor* a){ + return 1024; +} diff --git a/src/accessor/grib_accessor_class_getenv.h b/src/accessor/grib_accessor_class_getenv.h new file mode 100644 index 000000000..b04c58a4d --- /dev/null +++ b/src/accessor/grib_accessor_class_getenv.h @@ -0,0 +1,34 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_ascii.h" + +class grib_accessor_getenv_t : public grib_accessor_ascii_t +{ +public: + const char* name; + char* value; + const char* default_value; +}; + +class grib_accessor_class_getenv_t : public grib_accessor_class_ascii_t +{ +public: + grib_accessor_class_getenv_t(const char* name) : grib_accessor_class_ascii_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_getenv_t{}; } + int pack_string(grib_accessor*, const char*, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + size_t string_length(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; + diff --git a/src/grib_accessor_class_global_gaussian.cc b/src/accessor/grib_accessor_class_global_gaussian.cc similarity index 64% rename from src/grib_accessor_class_global_gaussian.cc rename to src/accessor/grib_accessor_class_global_gaussian.cc index b39677da2..34ac67881 100644 --- a/src/grib_accessor_class_global_gaussian.cc +++ b/src/accessor/grib_accessor_class_global_gaussian.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,122 +9,15 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = init - MEMBERS=const char* N - MEMBERS=const char* Ni - MEMBERS=const char* di - MEMBERS=const char* latfirst - MEMBERS=const char* lonfirst - MEMBERS=const char* latlast - MEMBERS=const char* lonlast - MEMBERS=const char* plpresent - MEMBERS=const char* pl - MEMBERS=const char* basic_angle - MEMBERS=const char* subdivision - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_global_gaussian -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in global_gaussian */ - const char* N; - const char* Ni; - const char* di; - const char* latfirst; - const char* lonfirst; - const char* latlast; - const char* lonlast; - const char* plpresent; - const char* pl; - const char* basic_angle; - const char* subdivision; -} grib_accessor_global_gaussian; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_global_gaussian = { - &grib_accessor_class_long, /* super */ - "global_gaussian", /* name */ - sizeof(grib_accessor_global_gaussian), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_global_gaussian.h" +grib_accessor_class_global_gaussian_t _grib_accessor_class_global_gaussian{"global_gaussian"}; grib_accessor_class* grib_accessor_class_global_gaussian = &_grib_accessor_class_global_gaussian; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_global_gaussian* self = (grib_accessor_global_gaussian*)a; +void grib_accessor_class_global_gaussian_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_long_t::init(a, l, c); + grib_accessor_global_gaussian_t* self = (grib_accessor_global_gaussian_t*)a; int n = 0; grib_handle* h = grib_handle_of_accessor(a); @@ -140,9 +34,8 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) self->subdivision = grib_arguments_get_name(h, c, n++); } -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_global_gaussian* self = (grib_accessor_global_gaussian*)a; +int grib_accessor_class_global_gaussian_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_accessor_global_gaussian_t* self = (grib_accessor_global_gaussian_t*)a; int ret = GRIB_SUCCESS; long latfirst, latlast, lonfirst, lonlast, basic_angle, subdivision, N, Ni; double dlatfirst, dlatlast, dlonfirst, dlonlast; @@ -247,9 +140,8 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) return ret; } -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - grib_accessor_global_gaussian* self = (grib_accessor_global_gaussian*)a; +int grib_accessor_class_global_gaussian_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + grib_accessor_global_gaussian_t* self = (grib_accessor_global_gaussian_t*)a; int ret = GRIB_SUCCESS; long latfirst, latlast, lonfirst, lonlast, di, diold, basic_angle = 0, N, Ni; long factor; diff --git a/src/accessor/grib_accessor_class_global_gaussian.h b/src/accessor/grib_accessor_class_global_gaussian.h new file mode 100644 index 000000000..1d49c0c32 --- /dev/null +++ b/src/accessor/grib_accessor_class_global_gaussian.h @@ -0,0 +1,41 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_global_gaussian_t : public grib_accessor_long_t +{ +public: + /* Members defined in global_gaussian */ + const char* N; + const char* Ni; + const char* di; + const char* latfirst; + const char* lonfirst; + const char* latlast; + const char* lonlast; + const char* plpresent; + const char* pl; + const char* basic_angle; + const char* subdivision; +}; + +class grib_accessor_class_global_gaussian_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_global_gaussian_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_global_gaussian_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_group.cc b/src/accessor/grib_accessor_class_group.cc new file mode 100644 index 000000000..aef185022 --- /dev/null +++ b/src/accessor/grib_accessor_class_group.cc @@ -0,0 +1,160 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_group.h" + +grib_accessor_class_group_t _grib_accessor_class_group{"group"}; +grib_accessor_class* grib_accessor_class_group = &_grib_accessor_class_group; + + +void grib_accessor_class_group_t::init(grib_accessor* a, const long len, grib_arguments* arg){ + grib_accessor_class_gen_t::init(a, len, arg); + grib_buffer* buffer = grib_handle_of_accessor(a)->buffer; + grib_accessor_group_t* self = (grib_accessor_group_t*)a; + + size_t i = 0; + unsigned char* v; + const char* s = grib_arguments_get_string(grib_handle_of_accessor(a), arg, 0); + + if (s && strlen(s) > 1) { + grib_context_log(a->context, GRIB_LOG_WARNING, + "Using only first character as group end of %s not the string %s", a->name, s); + } + + self->endCharacter = s ? s[0] : 0; + + v = buffer->data + a->offset; + i = 0; + if (s) { + while (*v != self->endCharacter && i <= buffer->ulength) { + if (*v > 126) + *v = 32; + v++; + i++; + } + } + else { + while (*v > 32 && *v != 61 && *v < 127 && i <= buffer->ulength) { + v++; + i++; + } + } + a->length = i; + + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; +} + +int grib_accessor_class_group_t::value_count(grib_accessor* a, long* count){ + *count = 1; + return 0; +} + +size_t grib_accessor_class_group_t::string_length(grib_accessor* a){ + return a->length; +} + +void grib_accessor_class_group_t::dump(grib_accessor* a, grib_dumper* dumper){ + grib_dump_string(dumper, a, NULL); +} + +int grib_accessor_class_group_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_STRING; +} + +int grib_accessor_class_group_t::unpack_string(grib_accessor* a, char* val, size_t* len){ + long i = 0; + size_t l = a->length + 1; + grib_handle* h = grib_handle_of_accessor(a); + + if (*len < l) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", + a->cclass->name, a->name, l, *len); + *len = l; + return GRIB_ARRAY_TOO_SMALL; + } + + for (i = 0; i < a->length; i++) + val[i] = h->buffer->data[a->offset + i]; + val[i] = 0; + *len = i; + return GRIB_SUCCESS; +} + +int grib_accessor_class_group_t::unpack_long(grib_accessor* a, long* v, size_t* len){ + char val[1024] = {0,}; + size_t l = sizeof(val); + size_t i = 0; + char* last = NULL; + int err = a->unpack_string(val, &l); + if (err) + return err; + + i = 0; + while (i < l - 1 && val[i] == ' ') + i++; + + if (val[i] == 0) { + *v = 0; + return 0; + } + if (val[i + 1] == ' ' && i < l - 2) + val[i + 1] = 0; + + *v = strtol(val, &last, 10); + + grib_context_log(a->context, GRIB_LOG_DEBUG, " Casting string %s to long", a->name); + return GRIB_SUCCESS; +} + +int grib_accessor_class_group_t::unpack_double(grib_accessor* a, double* v, size_t* len){ + char val[1024]; + size_t l = sizeof(val); + char* last = NULL; + a->unpack_string(val, &l); + *v = strtod(val, &last); + + if (*last == 0) { + grib_context_log(a->context, GRIB_LOG_DEBUG, " Casting string %s to long", a->name); + return GRIB_SUCCESS; + } + + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_class_group_t::compare(grib_accessor* a, grib_accessor* b){ + grib_context_log(a->context, GRIB_LOG_ERROR, "%s:%s not implemented", __func__, a->name); + return GRIB_NOT_IMPLEMENTED; + + // int retval = 0; + // char* aval = 0; + // char* bval = 0; + // int err = 0; + // size_t alen = 0; + // size_t blen = 0; + // long count = 0; + // err = a->value_count(&count); // if (err) return err; + // alen = count; + // err = b->value_count(&count); // if (err) return err; + // blen = count; + // if (alen != blen) return GRIB_COUNT_MISMATCH; + // aval = (char*)grib_context_malloc(a->context, alen * sizeof(char)); + // bval = (char*)grib_context_malloc(b->context, blen * sizeof(char)); + // a->unpack_string(aval, &alen); // b->unpack_string(bval, &blen); // retval = GRIB_SUCCESS; + // if (strcmp(aval, bval)) retval = GRIB_STRING_VALUE_MISMATCH; + // grib_context_free(a->context, aval); + // grib_context_free(b->context, bval); + // return retval; +} + +long grib_accessor_class_group_t::next_offset(grib_accessor* a){ + return a->offset + a->length; +} diff --git a/src/accessor/grib_accessor_class_group.h b/src/accessor/grib_accessor_class_group.h new file mode 100644 index 000000000..9f1c31a81 --- /dev/null +++ b/src/accessor/grib_accessor_class_group.h @@ -0,0 +1,38 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_group_t : public grib_accessor_gen_t +{ +public: + /* Members defined in group */ + char endCharacter; +}; + +class grib_accessor_class_group_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_group_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_group_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + size_t string_length(grib_accessor*) override; + long next_offset(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + int compare(grib_accessor*, grib_accessor*) override; +}; diff --git a/src/accessor/grib_accessor_class_gts_header.cc b/src/accessor/grib_accessor_class_gts_header.cc new file mode 100644 index 000000000..62a63bb8f --- /dev/null +++ b/src/accessor/grib_accessor_class_gts_header.cc @@ -0,0 +1,61 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_gts_header.h" + +grib_accessor_class_gts_header_t _grib_accessor_class_gts_header{"gts_header"}; +grib_accessor_class* grib_accessor_class_gts_header = &_grib_accessor_class_gts_header; + + +void grib_accessor_class_gts_header_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_ascii_t::init(a, l, c); + grib_accessor_gts_header_t* self = (grib_accessor_gts_header_t*)a; + self->gts_offset = -1; + self->gts_length = -1; + self->gts_offset = grib_arguments_get_long(grib_handle_of_accessor(a), c, 0); + self->gts_length = grib_arguments_get_long(grib_handle_of_accessor(a), c, 1); + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; +} + +int grib_accessor_class_gts_header_t::unpack_string(grib_accessor* a, char* val, size_t* len){ + grib_accessor_gts_header_t* self = (grib_accessor_gts_header_t*)a; + grib_handle* h = grib_handle_of_accessor(a); + int offset = 0; + size_t length = 0; + + if (h->gts_header == NULL || h->gts_header_len < 8) { + if (*len < 8) + return GRIB_BUFFER_TOO_SMALL; + snprintf(val, 1024, "missing"); + return GRIB_SUCCESS; + } + if (*len < h->gts_header_len) + return GRIB_BUFFER_TOO_SMALL; + + offset = self->gts_offset > 0 ? self->gts_offset : 0; + length = self->gts_length > 0 ? self->gts_length : h->gts_header_len; + + memcpy(val, h->gts_header + offset, length); + + *len = length; + + return GRIB_SUCCESS; +} + +int grib_accessor_class_gts_header_t::value_count(grib_accessor* a, long* count){ + *count = 1; + return 0; +} + +size_t grib_accessor_class_gts_header_t::string_length(grib_accessor* a){ + grib_handle* h = grib_handle_of_accessor(a); + return h->gts_header_len; +} diff --git a/src/accessor/grib_accessor_class_gts_header.h b/src/accessor/grib_accessor_class_gts_header.h new file mode 100644 index 000000000..8072986a7 --- /dev/null +++ b/src/accessor/grib_accessor_class_gts_header.h @@ -0,0 +1,33 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_ascii.h" + +class grib_accessor_gts_header_t : public grib_accessor_ascii_t +{ +public: + /* Members defined in gts_header */ + int gts_offset; + int gts_length; +}; + +class grib_accessor_class_gts_header_t : public grib_accessor_class_ascii_t +{ +public: + grib_accessor_class_gts_header_t(const char* name) : grib_accessor_class_ascii_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_gts_header_t{}; } + int unpack_string(grib_accessor*, char*, size_t* len) override; + size_t string_length(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_hash_array.cc b/src/accessor/grib_accessor_class_hash_array.cc new file mode 100644 index 000000000..1955dc07f --- /dev/null +++ b/src/accessor/grib_accessor_class_hash_array.cc @@ -0,0 +1,177 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_hash_array.h" + +grib_accessor_class_hash_array_t _grib_accessor_class_hash_array{"hash_array"}; +grib_accessor_class* grib_accessor_class_hash_array = &_grib_accessor_class_hash_array; + + +#define MAX_HASH_ARRAY_STRING_LENGTH 255 + +void grib_accessor_class_hash_array_t::init(grib_accessor* a, const long len, grib_arguments* args){ + grib_accessor_class_gen_t::init(a, len, args); + grib_accessor_hash_array_t* self = (grib_accessor_hash_array_t*)a; + a->length = 0; + self->key = 0; + self->ha = NULL; +} + +void grib_accessor_class_hash_array_t::dump(grib_accessor* a, grib_dumper* dumper){ + grib_dump_string(dumper, a, NULL); +} + +int grib_accessor_class_hash_array_t::pack_double(grib_accessor* a, const double* val, size_t* len){ + grib_accessor_hash_array_t* self = (grib_accessor_hash_array_t*)a; + char s[200] = {0,}; + snprintf(s, sizeof(s), "%g", *val); + self->key = grib_context_strdup(a->context, s); + self->ha = 0; + return GRIB_SUCCESS; +} + +int grib_accessor_class_hash_array_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + grib_accessor_hash_array_t* self = (grib_accessor_hash_array_t*)a; + char s[200] = {0,}; + snprintf(s, sizeof(s), "%ld", *val); + if (self->key) + grib_context_free(a->context, self->key); + self->key = grib_context_strdup(a->context, s); + self->ha = 0; + return GRIB_SUCCESS; +} + +int grib_accessor_class_hash_array_t::pack_string(grib_accessor* a, const char* v, size_t* len){ + grib_accessor_hash_array_t* self = (grib_accessor_hash_array_t*)a; + self->key = grib_context_strdup(a->context, v); + self->ha = 0; + return GRIB_SUCCESS; +} + +int grib_accessor_class_hash_array_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + return GRIB_NOT_IMPLEMENTED; +} + +static grib_hash_array_value* find_hash_value(grib_accessor* a, int* err) +{ + grib_accessor_hash_array_t* self = (grib_accessor_hash_array_t*)a; + grib_hash_array_value* ha_ret = 0; + grib_hash_array_value* ha = NULL; + + ha = get_hash_array(grib_handle_of_accessor(a), a->creator); + if (!ha) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "unable to get hash value for %s", a->creator->name); + *err = GRIB_HASH_ARRAY_NO_MATCH; + return NULL; + } + + *err = GRIB_SUCCESS; + + Assert(ha != NULL); + if (!self->key) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "unable to get hash value for %s, set before getting", a->creator->name); + *err = GRIB_HASH_ARRAY_NO_MATCH; + return NULL; + } + + ha_ret = (grib_hash_array_value*)grib_trie_get(ha->index, self->key); + if (!ha_ret) + ha_ret = (grib_hash_array_value*)grib_trie_get(ha->index, "default"); + + if (!ha_ret) { + *err = GRIB_HASH_ARRAY_NO_MATCH; + grib_context_log(a->context, GRIB_LOG_ERROR, + "hash_array: no match for %s=%s", + a->creator->name, self->key); + const char* full_path = get_hash_array_full_path(a->creator); + if (full_path) { + grib_context_log(a->context, GRIB_LOG_ERROR, "hash_array: file path = %s", full_path); + } + grib_context_log(a->context, GRIB_LOG_ERROR, "Hint: Check the key 'masterTablesVersionNumber'"); + return NULL; + } + return ha_ret; +} + +int grib_accessor_class_hash_array_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_hash_array_value* ha = 0; + grib_accessor_hash_array_t* self = (grib_accessor_hash_array_t*)a; + int err = 0; + size_t i = 0; + + if (!self->ha) { + ha = find_hash_value(a, &err); + if (err) + return err; + self->ha = ha; + } + + switch (self->ha->type) { + case GRIB_HASH_ARRAY_TYPE_INTEGER: + if (*len < self->ha->iarray->n) { + return GRIB_ARRAY_TOO_SMALL; + } + *len = self->ha->iarray->n; + for (i = 0; i < *len; i++) + val[i] = self->ha->iarray->v[i]; + break; + + default: + return GRIB_NOT_IMPLEMENTED; + } + + return GRIB_SUCCESS; +} + +int grib_accessor_class_hash_array_t::get_native_type(grib_accessor* a){ + int type = GRIB_TYPE_STRING; + if (a->flags & GRIB_ACCESSOR_FLAG_LONG_TYPE) + type = GRIB_TYPE_LONG; + + return type; +} + +void grib_accessor_class_hash_array_t::destroy(grib_context* c, grib_accessor* a){ + grib_accessor_hash_array_t* self = (grib_accessor_hash_array_t*)a; + if (self->key) + grib_context_free(c, self->key); + grib_accessor_class_gen_t::destroy(c, a); +} + +int grib_accessor_class_hash_array_t::unpack_string(grib_accessor* a, char* val, size_t* len){ + return GRIB_NOT_IMPLEMENTED; +} + +size_t grib_accessor_class_hash_array_t::string_length(grib_accessor* a){ + return MAX_HASH_ARRAY_STRING_LENGTH; +} + +int grib_accessor_class_hash_array_t::value_count(grib_accessor* a, long* count){ + int err = 0; + grib_accessor_hash_array_t* self = (grib_accessor_hash_array_t*)a; + grib_hash_array_value* ha = 0; + + if (!self->ha) { + ha = find_hash_value(a, &err); + if (err) + return err; + self->ha = ha; + } + + *count = self->ha->iarray->n; + return err; +} + +int grib_accessor_class_hash_array_t::compare(grib_accessor* a, grib_accessor* b){ + return GRIB_NOT_IMPLEMENTED; +} diff --git a/src/accessor/grib_accessor_class_hash_array.h b/src/accessor/grib_accessor_class_hash_array.h new file mode 100644 index 000000000..fa2732cac --- /dev/null +++ b/src/accessor/grib_accessor_class_hash_array.h @@ -0,0 +1,42 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_hash_array_t : public grib_accessor_gen_t +{ +public: + /* Members defined in hash_array */ + char* key; + grib_hash_array_value* ha; +}; + +class grib_accessor_class_hash_array_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_hash_array_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_hash_array_t{}; } + int get_native_type(grib_accessor*) override; + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int pack_string(grib_accessor*, const char*, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + size_t string_length(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void destroy(grib_context*, grib_accessor*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + int compare(grib_accessor*, grib_accessor*) override; +}; diff --git a/src/accessor/grib_accessor_class_headers_only.cc b/src/accessor/grib_accessor_class_headers_only.cc new file mode 100644 index 000000000..9b053112d --- /dev/null +++ b/src/accessor/grib_accessor_class_headers_only.cc @@ -0,0 +1,33 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_headers_only.h" + +grib_accessor_class_headers_only_t _grib_accessor_class_headers_only{"headers_only"}; +grib_accessor_class* grib_accessor_class_headers_only = &_grib_accessor_class_headers_only; + + +void grib_accessor_class_headers_only_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_gen_t::init(a, l, c); + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; + a->length = 0; +} + +int grib_accessor_class_headers_only_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + *val = grib_handle_of_accessor(a)->partial; + *len = 1; + return 0; +} + +int grib_accessor_class_headers_only_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_LONG; +} diff --git a/src/accessor/grib_accessor_class_headers_only.h b/src/accessor/grib_accessor_class_headers_only.h new file mode 100644 index 000000000..a7dc81891 --- /dev/null +++ b/src/accessor/grib_accessor_class_headers_only.h @@ -0,0 +1,30 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_headers_only_t : public grib_accessor_gen_t +{ +public: + /* Members defined in headers_only */ +}; + +class grib_accessor_class_headers_only_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_headers_only_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_headers_only_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_ibmfloat.cc b/src/accessor/grib_accessor_class_ibmfloat.cc new file mode 100644 index 000000000..c5766db01 --- /dev/null +++ b/src/accessor/grib_accessor_class_ibmfloat.cc @@ -0,0 +1,165 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_ibmfloat.h" + +grib_accessor_class_ibmfloat_t _grib_accessor_class_ibmfloat{ "ibmfloat" }; +grib_accessor_class* grib_accessor_class_ibmfloat = &_grib_accessor_class_ibmfloat; + + +void grib_accessor_class_ibmfloat_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ + grib_accessor_class_double_t::init(a, len, arg); + grib_accessor_ibmfloat_t* self = (grib_accessor_ibmfloat_t*)a; + long count = 0; + + self->arg = arg; + a->value_count(&count); + a->length = 4 * count; + Assert(a->length >= 0); +} + + +template +static int unpack(grib_accessor* a, T* val, size_t* len) +{ + static_assert(std::is_floating_point::value, "Requires floating point numbers"); + unsigned long rlen = 0; + long count = 0; + int err = 0; + unsigned long i = 0; + long bitp = a->offset * 8; + grib_handle* hand = grib_handle_of_accessor(a); + + err = a->value_count(&count); + if (err) + return err; + rlen = count; + + if (*len < rlen) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size (%zu) for %s, it contains %lu values", *len, a->name, rlen); + *len = 0; + return GRIB_ARRAY_TOO_SMALL; + } + + for (i = 0; i < rlen; i++) + val[i] = (T)grib_long_to_ibm(grib_decode_unsigned_long(hand->buffer->data, &bitp, 32)); + + *len = rlen; + return GRIB_SUCCESS; +} + +int grib_accessor_class_ibmfloat_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ + return unpack(a, val, len); +} + +int grib_accessor_class_ibmfloat_t::unpack_float(grib_accessor* a, float* val, size_t* len) +{ + return unpack(a, val, len); +} + +int grib_accessor_class_ibmfloat_t::pack_double(grib_accessor* a, const double* val, size_t* len) +{ + grib_accessor_ibmfloat_t* self = (grib_accessor_ibmfloat_t*)a; + + int ret = 0; + unsigned long i = 0; + unsigned long rlen = *len; + size_t buflen = 0; + unsigned char* buf = NULL; + long off = 0; + + if (*len < 1) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it packs at least 1 value", a->name); + *len = 0; + return GRIB_ARRAY_TOO_SMALL; + } + + if (rlen == 1) { + // double x = 0; + // grib_nearest_smaller_ibm_float(val[0],&x); + // double y = grib_long_to_ibm(grib_ibm_to_long(val[0])); + // printf("IBMFLOAT val=%.20f nearest_smaller_ibm_float=%.20f long_to_ibm=%.20f\n",val[0],x ,y); + + off = a->byte_offset() * 8; + ret = grib_encode_unsigned_long(grib_handle_of_accessor(a)->buffer->data, grib_ibm_to_long(val[0]), &off, 32); + if (*len > 1) + grib_context_log(a->context, GRIB_LOG_WARNING, "ibmfloat: Trying to pack %zu values in a scalar %s, packing first value", + *len, a->name); + if (ret == GRIB_SUCCESS) + len[0] = 1; + return ret; + } + + buflen = rlen * 4; + + buf = (unsigned char*)grib_context_malloc(a->context, buflen); + + for (i = 0; i < rlen; i++) { + grib_encode_unsigned_longb(buf, grib_ibm_to_long(val[i]), &off, 32); + } + ret = grib_set_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, self->arg, 0), rlen); + + if (ret == GRIB_SUCCESS) + grib_buffer_replace(a, buf, buflen, 1, 1); + else + *len = 0; + + grib_context_free(a->context, buf); + + a->length = a->byte_count(); + + return ret; +} + +long grib_accessor_class_ibmfloat_t::byte_count(grib_accessor* a) +{ + return a->length; +} + +int grib_accessor_class_ibmfloat_t::value_count(grib_accessor* a, long* len) +{ + grib_accessor_ibmfloat_t* self = (grib_accessor_ibmfloat_t*)a; + *len = 0; + if (!self->arg) { + *len = 1; + return 0; + } + return grib_get_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, self->arg, 0), len); +} + +long grib_accessor_class_ibmfloat_t::byte_offset(grib_accessor* a) +{ + return a->offset; +} + +void grib_accessor_class_ibmfloat_t::update_size(grib_accessor* a, size_t s) +{ + a->length = (long)s; + Assert(a->length >= 0); +} + +long grib_accessor_class_ibmfloat_t::next_offset(grib_accessor* a) +{ + return a->byte_offset() + a->byte_count(); +} + +int grib_accessor_class_ibmfloat_t::nearest_smaller_value(grib_accessor* a, double val, double* nearest) +{ + int ret = 0; + if (grib_nearest_smaller_ibm_float(val, nearest) == GRIB_INTERNAL_ERROR) { + grib_context_log(a->context, GRIB_LOG_ERROR, "ibm_float:nearest_smaller_value overflow value=%g", val); + grib_dump_content(grib_handle_of_accessor(a), stderr, "wmo", GRIB_DUMP_FLAG_HEXADECIMAL, 0); + ret = GRIB_INTERNAL_ERROR; + } + return ret; +} diff --git a/src/accessor/grib_accessor_class_ibmfloat.h b/src/accessor/grib_accessor_class_ibmfloat.h new file mode 100644 index 000000000..66bd01132 --- /dev/null +++ b/src/accessor/grib_accessor_class_ibmfloat.h @@ -0,0 +1,37 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_double.h" + +class grib_accessor_ibmfloat_t : public grib_accessor_double_t +{ +public: + /* Members defined in ibmfloat */ + grib_arguments* arg; +}; + +class grib_accessor_class_ibmfloat_t : public grib_accessor_class_double_t +{ +public: + grib_accessor_class_ibmfloat_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_ibmfloat_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_float(grib_accessor*, float* val, size_t* len) override; + long byte_count(grib_accessor*) override; + long byte_offset(grib_accessor*) override; + long next_offset(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + void update_size(grib_accessor*, size_t) override; + int nearest_smaller_value(grib_accessor*, double, double*) override; +}; diff --git a/src/accessor/grib_accessor_class_ieeefloat.cc b/src/accessor/grib_accessor_class_ieeefloat.cc new file mode 100644 index 000000000..64b08fe50 --- /dev/null +++ b/src/accessor/grib_accessor_class_ieeefloat.cc @@ -0,0 +1,136 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_ieeefloat.h" + +grib_accessor_class_ieeefloat_t _grib_accessor_class_ieeefloat{ "ieeefloat" }; +grib_accessor_class* grib_accessor_class_ieeefloat = &_grib_accessor_class_ieeefloat; + + +void grib_accessor_class_ieeefloat_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ + grib_accessor_class_double_t::init(a, len, arg); + grib_accessor_ieeefloat_t* self = (grib_accessor_ieeefloat_t*)a; + long count = 0; + self->arg = arg; + a->value_count(&count); + a->length = 4 * count; + Assert(a->length >= 0); +} + +int grib_accessor_class_ieeefloat_t::value_count(grib_accessor* a, long* len) +{ + grib_accessor_ieeefloat_t* self = (grib_accessor_ieeefloat_t*)a; + *len = 0; + + if (!self->arg) { + *len = 1; + return 0; + } + return grib_get_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, self->arg, 0), len); +} + +int grib_accessor_class_ieeefloat_t::pack_double(grib_accessor* a, const double* val, size_t* len) +{ + grib_accessor_ieeefloat_t* self = (grib_accessor_ieeefloat_t*)a; + + int ret = 0; + unsigned long i = 0; + unsigned long rlen = (unsigned long)*len; + size_t buflen = 0; + unsigned char* buf = NULL; + long off = 0; + + if (*len < 1) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it packs at least 1 value", a->name); + *len = 0; + return GRIB_ARRAY_TOO_SMALL; + } + + if (rlen == 1) { + off = a->offset * 8; + ret = grib_encode_unsigned_long(grib_handle_of_accessor(a)->buffer->data, grib_ieee_to_long(val[0]), &off, 32); + if (*len > 1) + grib_context_log(a->context, GRIB_LOG_WARNING, "ieeefloat: Trying to pack %zu values in a scalar %s, packing first value", + *len, a->name); + if (ret == GRIB_SUCCESS) + len[0] = 1; + return ret; + } + + buflen = rlen * 4; + + buf = (unsigned char*)grib_context_malloc(a->context, buflen); + + for (i = 0; i < rlen; i++) { + grib_encode_unsigned_longb(buf, grib_ieee_to_long(val[i]), &off, 32); + } + ret = grib_set_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, self->arg, 0), rlen); + + if (ret == GRIB_SUCCESS) + grib_buffer_replace(a, buf, buflen, 1, 1); + else + *len = 0; + + grib_context_free(a->context, buf); + + return ret; +} + + +template +static int unpack(grib_accessor* a, T* val, size_t* len) +{ + static_assert(std::is_floating_point::value, "Requires floating point numbers"); + + long rlen = 0; + int err = 0; + long i = 0; + long bitp = a->offset * 8; + grib_handle* hand = grib_handle_of_accessor(a); + + err = a->value_count(&rlen); + if (err) + return err; + + if (*len < (size_t)rlen) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size (%zu) for %s, it contains %ld values", *len, a->name, rlen); + *len = 0; + return GRIB_ARRAY_TOO_SMALL; + } + + for (i = 0; i < rlen; i++) + val[i] = (T)grib_long_to_ieee(grib_decode_unsigned_long(hand->buffer->data, &bitp, 32)); + + *len = rlen; + return GRIB_SUCCESS; +} + +int grib_accessor_class_ieeefloat_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ + return unpack(a, val, len); +} + +int grib_accessor_class_ieeefloat_t::unpack_float(grib_accessor* a, float* val, size_t* len) +{ + return unpack(a, val, len); +} + +void grib_accessor_class_ieeefloat_t::update_size(grib_accessor* a, size_t s) +{ + a->length = (long)s; + Assert(a->length >= 0); +} + +int grib_accessor_class_ieeefloat_t::nearest_smaller_value(grib_accessor* a, double val, double* nearest) +{ + return grib_nearest_smaller_ieee_float(val, nearest); +} diff --git a/src/accessor/grib_accessor_class_ieeefloat.h b/src/accessor/grib_accessor_class_ieeefloat.h new file mode 100644 index 000000000..27536169f --- /dev/null +++ b/src/accessor/grib_accessor_class_ieeefloat.h @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_double.h" + +class grib_accessor_ieeefloat_t : public grib_accessor_double_t +{ +public: + grib_arguments* arg; +}; + +class grib_accessor_class_ieeefloat_t : public grib_accessor_class_double_t +{ +public: + grib_accessor_class_ieeefloat_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_ieeefloat_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_float(grib_accessor*, float* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + void update_size(grib_accessor*, size_t) override; + int nearest_smaller_value(grib_accessor* a, double val, double* nearest) override; +}; diff --git a/src/accessor/grib_accessor_class_ifs_param.cc b/src/accessor/grib_accessor_class_ifs_param.cc new file mode 100644 index 000000000..32a972c7c --- /dev/null +++ b/src/accessor/grib_accessor_class_ifs_param.cc @@ -0,0 +1,93 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_ifs_param.h" + +grib_accessor_class_ifs_param_t _grib_accessor_class_ifs_param{"ifs_param"}; +grib_accessor_class* grib_accessor_class_ifs_param = &_grib_accessor_class_ifs_param; + + +void grib_accessor_class_ifs_param_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_gen_t::init(a, l, c); + grib_accessor_ifs_param_t* self = (grib_accessor_ifs_param_t*)a; + int n = 0; + + self->paramId = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->type = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); +} + +int grib_accessor_class_ifs_param_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_accessor_ifs_param_t* self = (grib_accessor_ifs_param_t*)a; + int ret = 0; + long paramId = 0; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->paramId, ¶mId)) != GRIB_SUCCESS) + return ret; + + if (paramId > 129000 && paramId < 129999) + *val = paramId - 129000; + else if (paramId > 200000 && paramId < 200999) + *val = paramId - 200000; + else if (paramId > 211000 && paramId < 211999) + *val = paramId - 1000; + else + *val = paramId; + + return ret; +} + +int grib_accessor_class_ifs_param_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + grib_accessor_ifs_param_t* self = (grib_accessor_ifs_param_t*)a; + long type = 0; + long table = 128; + long paramId = *val; + long param; + + grib_get_long(grib_handle_of_accessor(a), self->type, &type); + + if (type == 33 || type == 35) { + if (paramId > 1000) { + table = paramId / 1000; + param = paramId - table * 1000; + paramId = param; + } + switch (table) { + case 210: + paramId += 211000; + break; + case 128: + paramId += 200000; + break; + default: + break; + } + } + if (type == 50 || type == 52) { + if (paramId > 1000) { + table = paramId / 1000; + param = paramId - table * 1000; + paramId = param; + } + switch (table) { + case 128: + paramId += 129000; + break; + default: + break; + } + } + + return grib_set_long_internal(grib_handle_of_accessor(a), self->paramId, paramId); +} + +int grib_accessor_class_ifs_param_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_LONG; +} diff --git a/src/accessor/grib_accessor_class_ifs_param.h b/src/accessor/grib_accessor_class_ifs_param.h new file mode 100644 index 000000000..2beb90925 --- /dev/null +++ b/src/accessor/grib_accessor_class_ifs_param.h @@ -0,0 +1,33 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_ifs_param_t : public grib_accessor_gen_t +{ +public: + /* Members defined in ifs_param */ + const char* paramId; + const char* type; +}; + +class grib_accessor_class_ifs_param_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_ifs_param_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_ifs_param_t{}; } + int get_native_type(grib_accessor*) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_iterator.cc b/src/accessor/grib_accessor_class_iterator.cc new file mode 100644 index 000000000..4cdfd6670 --- /dev/null +++ b/src/accessor/grib_accessor_class_iterator.cc @@ -0,0 +1,48 @@ +/* + * (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. + */ + +#include "grib_accessor_class_iterator.h" + +grib_accessor_class_iterator_t _grib_accessor_class_iterator{"iterator"}; +grib_accessor_class* grib_accessor_class_iterator = &_grib_accessor_class_iterator; + +void grib_accessor_class_iterator_t::init(grib_accessor* a, const long l, grib_arguments* args) +{ + grib_accessor_class_gen_t::init(a, l, args); + grib_accessor_iterator_t* self = (grib_accessor_iterator_t*)a; + self->args = args; +} + +void grib_accessor_class_iterator_t::dump(grib_accessor* a, grib_dumper* dumper) +{ + /* TODO: pass args */ + grib_dump_label(dumper, a, NULL); +} + +grib_iterator* grib_iterator_new(const grib_handle* ch, unsigned long flags, int* error) +{ + grib_handle* h = (grib_handle*)ch; + grib_accessor* a = NULL; + grib_accessor_iterator_t* ita = NULL; + grib_iterator* iter = NULL; + *error = GRIB_NOT_IMPLEMENTED; + a = grib_find_accessor(h, "ITERATOR"); + ita = (grib_accessor_iterator_t*)a; + + if (!a) + return NULL; + + iter = grib_iterator_factory(h, ita->args, flags, error); + + if (iter) + *error = GRIB_SUCCESS; + + return iter; +} diff --git a/src/accessor/grib_accessor_class_iterator.h b/src/accessor/grib_accessor_class_iterator.h new file mode 100644 index 000000000..03fbdf5b6 --- /dev/null +++ b/src/accessor/grib_accessor_class_iterator.h @@ -0,0 +1,30 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_iterator_t : public grib_accessor_gen_t +{ +public: + grib_arguments* args; +}; + +class grib_accessor_class_iterator_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_iterator_t(const char* name) : grib_accessor_class_gen_t(name) {}; + grib_accessor* create_empty_accessor() override { return new grib_accessor_iterator_t{}; } + void init(grib_accessor* a, const long l, grib_arguments* args) override; + void dump(grib_accessor* a, grib_dumper* dumper) override; +}; + +//grib_iterator* grib_iterator_new(const grib_handle* ch, unsigned long flags, int* error) diff --git a/src/grib_accessor_class_julian_date.cc b/src/accessor/grib_accessor_class_julian_date.cc similarity index 66% rename from src/grib_accessor_class_julian_date.cc rename to src/accessor/grib_accessor_class_julian_date.cc index 61fd6959c..e633b42e4 100644 --- a/src/grib_accessor_class_julian_date.cc +++ b/src/accessor/grib_accessor_class_julian_date.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,129 +9,16 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_double - IMPLEMENTS = unpack_double; pack_double - IMPLEMENTS = unpack_long; pack_long - IMPLEMENTS = unpack_string; pack_string - IMPLEMENTS = dump - IMPLEMENTS = init - IMPLEMENTS = pack_expression - MEMBERS = const char *year - MEMBERS = const char *month - MEMBERS = const char *day - MEMBERS = const char *hour - MEMBERS = const char *minute - MEMBERS = const char *second - MEMBERS = const char *ymd - MEMBERS = const char *hms - MEMBERS = char sep[5] - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int pack_string(grib_accessor*, const char*, size_t* len); -static int pack_expression(grib_accessor*, grib_expression*); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_julian_date -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in julian_date */ - const char *year; - const char *month; - const char *day; - const char *hour; - const char *minute; - const char *second; - const char *ymd; - const char *hms; - char sep[5]; -} grib_accessor_julian_date; - -extern grib_accessor_class* grib_accessor_class_double; - -static grib_accessor_class _grib_accessor_class_julian_date = { - &grib_accessor_class_double, /* super */ - "julian_date", /* name */ - sizeof(grib_accessor_julian_date), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - &pack_string, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - &pack_expression, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_julian_date.h" +grib_accessor_class_julian_date_t _grib_accessor_class_julian_date{"julian_date"}; grib_accessor_class* grib_accessor_class_julian_date = &_grib_accessor_class_julian_date; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_julian_date* self = (grib_accessor_julian_date*)a; +void grib_accessor_class_julian_date_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_double_t::init(a, l, c); + grib_accessor_julian_date_t* self = (grib_accessor_julian_date_t*)a; int n = 0; grib_handle* h = grib_handle_of_accessor(a); @@ -163,18 +51,16 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) a->length = 0; } -static void dump(grib_accessor* a, grib_dumper* dumper) -{ +void grib_accessor_class_julian_date_t::dump(grib_accessor* a, grib_dumper* dumper){ grib_dump_string(dumper, a, NULL); } -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ +int grib_accessor_class_julian_date_t::unpack_double(grib_accessor* a, double* val, size_t* len){ int ret = 0; long hour, minute, second; long year, month, day, ymd, hms; grib_handle* h = grib_handle_of_accessor(a); - grib_accessor_julian_date* self = (grib_accessor_julian_date*)a; + grib_accessor_julian_date_t* self = (grib_accessor_julian_date_t*)a; if (self->ymd == NULL) { ret = grib_get_long(h, self->year, &year); @@ -222,9 +108,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) return ret; } -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_julian_date* self = (grib_accessor_julian_date*)a; +int grib_accessor_class_julian_date_t::pack_double(grib_accessor* a, const double* val, size_t* len){ + grib_accessor_julian_date_t* self = (grib_accessor_julian_date_t*)a; int ret = 0; long hour = 0; long minute = 0; @@ -272,12 +157,11 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) return ret; } -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ +int grib_accessor_class_julian_date_t::unpack_string(grib_accessor* a, char* val, size_t* len){ int ret = 0; long hour, minute, second; long year, month, day, ymd, hms; - grib_accessor_julian_date* self = (grib_accessor_julian_date*)a; + grib_accessor_julian_date_t* self = (grib_accessor_julian_date_t*)a; char* sep = self->sep; grib_handle* h = grib_handle_of_accessor(a); @@ -338,12 +222,11 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len) return ret; } -static int pack_string(grib_accessor* a, const char* val, size_t* len) -{ +int grib_accessor_class_julian_date_t::pack_string(grib_accessor* a, const char* val, size_t* len){ int ret = 0; long hour, minute, second; long year, month, day, ymd, hms; - grib_accessor_julian_date* self = (grib_accessor_julian_date*)a; + grib_accessor_julian_date_t* self = (grib_accessor_julian_date_t*)a; char* sep = self->sep; grib_handle* h = grib_handle_of_accessor(a); @@ -409,19 +292,16 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len) return ret; } -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ +int grib_accessor_class_julian_date_t::unpack_long(grib_accessor* a, long* val, size_t* len){ grib_context_log(a->context, GRIB_LOG_ERROR, " Cannot unpack %s as long", a->name); return GRIB_NOT_IMPLEMENTED; } -static int pack_long(grib_accessor* a, const long* v, size_t* len) -{ +int grib_accessor_class_julian_date_t::pack_long(grib_accessor* a, const long* v, size_t* len){ grib_context_log(a->context, GRIB_LOG_ERROR, " Cannot pack %s as long", a->name); return GRIB_NOT_IMPLEMENTED; } -static int pack_expression(grib_accessor* a, grib_expression* e) -{ +int grib_accessor_class_julian_date_t::pack_expression(grib_accessor* a, grib_expression* e){ size_t len = 1; long lval = 0; double dval = 0; @@ -439,16 +319,14 @@ static int pack_expression(grib_accessor* a, grib_expression* e) } /*if (hand->context->debug) printf("ECCODES DEBUG grib_accessor_class_gen::pack_expression %s %ld\n", a->name,lval);*/ - return grib_pack_long(a, &lval, &len); - } + return a->pack_long(&lval, &len); } case GRIB_TYPE_DOUBLE: { len = 1; ret = grib_expression_evaluate_double(hand, e, &dval); /*if (hand->context->debug) printf("ECCODES DEBUG grib_accessor_class_gen::pack_expression %s %g\n", a->name, dval);*/ - return grib_pack_double(a, &dval, &len); - } + return a->pack_double(&dval, &len); } case GRIB_TYPE_STRING: { char tmp[1024]; @@ -461,8 +339,7 @@ static int pack_expression(grib_accessor* a, grib_expression* e) len = strlen(cval); /*if (hand->context->debug) printf("ECCODES DEBUG grib_accessor_class_gen::pack_expression %s %s\n", a->name, cval);*/ - return grib_pack_string(a, cval, &len); - } + return a->pack_string(cval, &len); } } return GRIB_NOT_IMPLEMENTED; diff --git a/src/accessor/grib_accessor_class_julian_date.h b/src/accessor/grib_accessor_class_julian_date.h new file mode 100644 index 000000000..c52380e10 --- /dev/null +++ b/src/accessor/grib_accessor_class_julian_date.h @@ -0,0 +1,45 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_double.h" + +class grib_accessor_julian_date_t : public grib_accessor_double_t +{ +public: + /* Members defined in julian_date */ + const char *year; + const char *month; + const char *day; + const char *hour; + const char *minute; + const char *second; + const char *ymd; + const char *hms; + char sep[5]; +}; + +class grib_accessor_class_julian_date_t : public grib_accessor_class_double_t +{ +public: + grib_accessor_class_julian_date_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_julian_date_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int pack_string(grib_accessor*, const char*, size_t* len) override; + int pack_expression(grib_accessor*, grib_expression*) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_julian_day.cc b/src/accessor/grib_accessor_class_julian_day.cc new file mode 100644 index 000000000..e46751181 --- /dev/null +++ b/src/accessor/grib_accessor_class_julian_day.cc @@ -0,0 +1,107 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_julian_day.h" + +grib_accessor_class_julian_day_t _grib_accessor_class_julian_day{"julian_day"}; +grib_accessor_class* grib_accessor_class_julian_day = &_grib_accessor_class_julian_day; + + +void grib_accessor_class_julian_day_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_double_t::init(a, l, c); + grib_accessor_julian_day_t* self = (grib_accessor_julian_day_t*)a; + int n = 0; + + self->date = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->hour = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->minute = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->second = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + + a->length = 0; +} + +void grib_accessor_class_julian_day_t::dump(grib_accessor* a, grib_dumper* dumper){ + grib_dump_string(dumper, a, NULL); +} + +int grib_accessor_class_julian_day_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + const double v = *val; + return pack_double(a, &v, len); +} + +int grib_accessor_class_julian_day_t::pack_double(grib_accessor* a, const double* val, size_t* len){ + grib_accessor_julian_day_t* self = (grib_accessor_julian_day_t*)a; + int ret = 0; + long hour = 0; + long minute = 0; + long second = 0; + long date = 0; + long year, month, day; + + ret = grib_julian_to_datetime(*val, &year, &month, &day, &hour, &minute, &second); + if (ret != 0) + return ret; + + date = year * 10000 + month * 100 + day; + + ret = grib_set_long_internal(grib_handle_of_accessor(a), self->date, date); + if (ret != 0) + return ret; + ret = grib_set_long_internal(grib_handle_of_accessor(a), self->hour, hour); + if (ret != 0) + return ret; + ret = grib_set_long_internal(grib_handle_of_accessor(a), self->minute, minute); + if (ret != 0) + return ret; + ret = grib_set_long_internal(grib_handle_of_accessor(a), self->second, second); + + return ret; +} + +int grib_accessor_class_julian_day_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + int ret = 0; + double v = 0; + + ret = unpack_double(a, &v, len); + *val = (long)v; + + return ret; +} + +int grib_accessor_class_julian_day_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + int ret = 0; + long date, hour, minute, second; + long year, month, day; + grib_accessor_julian_day_t* self = (grib_accessor_julian_day_t*)a; + + ret = grib_get_long_internal(grib_handle_of_accessor(a), self->date, &date); + if (ret != GRIB_SUCCESS) + return ret; + ret = grib_get_long_internal(grib_handle_of_accessor(a), self->hour, &hour); + if (ret != GRIB_SUCCESS) + return ret; + ret = grib_get_long_internal(grib_handle_of_accessor(a), self->minute, &minute); + if (ret != GRIB_SUCCESS) + return ret; + ret = grib_get_long_internal(grib_handle_of_accessor(a), self->second, &second); + if (ret != GRIB_SUCCESS) + return ret; + + year = date / 10000; + date %= 10000; + month = date / 100; + date %= 100; + day = date; + + ret = grib_datetime_to_julian(year, month, day, hour, minute, second, val); + + return ret; +} diff --git a/src/accessor/grib_accessor_class_julian_day.h b/src/accessor/grib_accessor_class_julian_day.h new file mode 100644 index 000000000..5d06753b0 --- /dev/null +++ b/src/accessor/grib_accessor_class_julian_day.h @@ -0,0 +1,37 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_double.h" + +class grib_accessor_julian_day_t : public grib_accessor_double_t +{ +public: + /* Members defined in julian_day */ + const char *date; + const char *hour; + const char *minute; + const char *second; +}; + +class grib_accessor_class_julian_day_t : public grib_accessor_class_double_t +{ +public: + grib_accessor_class_julian_day_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_julian_day_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_ksec1expver.cc b/src/accessor/grib_accessor_class_ksec1expver.cc new file mode 100644 index 000000000..0eb0af2c1 --- /dev/null +++ b/src/accessor/grib_accessor_class_ksec1expver.cc @@ -0,0 +1,95 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_ksec1expver.h" + +grib_accessor_class_ksec1expver_t _grib_accessor_class_ksec1expver{"ksec1expver"}; +grib_accessor_class* grib_accessor_class_ksec1expver = &_grib_accessor_class_ksec1expver; + + +void grib_accessor_class_ksec1expver_t::init(grib_accessor* a, const long len, grib_arguments* arg){ + grib_accessor_class_ascii_t::init(a, len, arg); + a->length = len; + Assert(a->length >= 0); +} + +int grib_accessor_class_ksec1expver_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + long value = 0; + long pos = a->offset * 8; + char* intc = NULL; + char* pTemp = NULL; + char expver[5]; + char refexpver[5]; + size_t llen = a->length + 1; + Assert(a->length == 4); + + if (*len < 1) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name, 1); + *len = 0; + return GRIB_ARRAY_TOO_SMALL; + } + value = grib_decode_unsigned_long(grib_handle_of_accessor(a)->buffer->data, &pos, a->length * 8); + + a->unpack_string(refexpver, &llen); + /* test for endian */ + intc = (char*)&value; + pTemp = intc; + + expver[0] = *pTemp++; + expver[1] = *pTemp++; + expver[2] = *pTemp++; + expver[3] = *pTemp++; + expver[4] = 0; + +// expver[0] = intc[0]; +// expver[1] = intc[1]; +// expver[2] = intc[2]; +// expver[3] = intc[3]; +// expver[4] = 0; + + /* if there is a difference, have to reverse*/ + if (strcmp(refexpver, expver)) { + intc[0] = expver[3]; + intc[1] = expver[2]; + intc[2] = expver[1]; + intc[3] = expver[0]; + } + + *val = value; + *len = 1; + return GRIB_SUCCESS; +} + +int grib_accessor_class_ksec1expver_t::pack_string(grib_accessor* a, const char* val, size_t* len){ + int i = 0; + if (len[0] != 4) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong length for %s. It has to be 4", a->name); + return GRIB_INVALID_KEY_VALUE; + } + if (len[0] > (a->length) + 1) { + grib_context_log(a->context, GRIB_LOG_ERROR, "pack_string: Wrong size (%lu) for %s, it contains %ld values", + len[0], a->name, a->length + 1); + len[0] = 0; + return GRIB_BUFFER_TOO_SMALL; + } + + for (i = 0; i < a->length; i++) + grib_handle_of_accessor(a)->buffer->data[a->offset + i] = val[i]; + + return GRIB_SUCCESS; +} + +int grib_accessor_class_ksec1expver_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + char sval[5] = {0,}; + size_t slen = 4; + snprintf(sval, sizeof(sval), "%04d", (int)(*val)); + return pack_string(a, sval, &slen); +} diff --git a/src/accessor/grib_accessor_class_ksec1expver.h b/src/accessor/grib_accessor_class_ksec1expver.h new file mode 100644 index 000000000..098a40a14 --- /dev/null +++ b/src/accessor/grib_accessor_class_ksec1expver.h @@ -0,0 +1,31 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_ascii.h" + +class grib_accessor_ksec1expver_t : public grib_accessor_ascii_t +{ +public: + /* Members defined in ksec1expver */ +}; + +class grib_accessor_class_ksec1expver_t : public grib_accessor_class_ascii_t +{ +public: + grib_accessor_class_ksec1expver_t(const char* name) : grib_accessor_class_ascii_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_ksec1expver_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int pack_string(grib_accessor*, const char*, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_label.cc b/src/accessor/grib_accessor_class_label.cc new file mode 100644 index 000000000..5b9448399 --- /dev/null +++ b/src/accessor/grib_accessor_class_label.cc @@ -0,0 +1,40 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_label.h" + +grib_accessor_class_label_t _grib_accessor_class_label{"label"}; +grib_accessor_class* grib_accessor_class_label = &_grib_accessor_class_label; + + +void grib_accessor_class_label_t::init(grib_accessor* a, const long len, grib_arguments* arg){ + grib_accessor_class_gen_t::init(a, len, arg); + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; + a->length = 0; +} + +void grib_accessor_class_label_t::dump(grib_accessor* a, grib_dumper* dumper){ + grib_dump_label(dumper, a, NULL); +} + +int grib_accessor_class_label_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_LABEL; +} + +int grib_accessor_class_label_t::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; +} diff --git a/src/accessor/grib_accessor_class_label.h b/src/accessor/grib_accessor_class_label.h new file mode 100644 index 000000000..59590e77c --- /dev/null +++ b/src/accessor/grib_accessor_class_label.h @@ -0,0 +1,31 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_label_t : public grib_accessor_gen_t +{ +public: + /* Members defined in label */ +}; + +class grib_accessor_class_label_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_label_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_label_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_latitudes.cc b/src/accessor/grib_accessor_class_latitudes.cc similarity index 54% rename from src/grib_accessor_class_latitudes.cc rename to src/accessor/grib_accessor_class_latitudes.cc index 35c1a9049..1c69d39e9 100644 --- a/src/grib_accessor_class_latitudes.cc +++ b/src/accessor/grib_accessor_class_latitudes.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,111 +9,13 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_double - IMPLEMENTS = unpack_double; - IMPLEMENTS = value_count - IMPLEMENTS = init - MEMBERS =const char* values - MEMBERS =long distinct - MEMBERS =double* lats - MEMBERS =long size - MEMBERS =int save - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_latitudes -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in latitudes */ - const char* values; - long distinct; - double* lats; - long size; - int save; -} grib_accessor_latitudes; - -extern grib_accessor_class* grib_accessor_class_double; - -static grib_accessor_class _grib_accessor_class_latitudes = { - &grib_accessor_class_double, /* super */ - "latitudes", /* name */ - sizeof(grib_accessor_latitudes), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_latitudes.h" +grib_accessor_class_latitudes_t _grib_accessor_class_latitudes{ "latitudes" }; grib_accessor_class* grib_accessor_class_latitudes = &_grib_accessor_class_latitudes; -/* END_CLASS_IMP */ - - static int get_distinct(grib_accessor* a, double** val, long* len); - -static int compare_doubles(const void* a, const void* b, int ascending) +int compare_doubles(const void* a, const void* b, int ascending) { // ascending is a boolean: 0 or 1 double* arg1 = (double*)a; @@ -130,19 +33,20 @@ static int compare_doubles(const void* a, const void* b, int ascending) else return 1; } -static int compare_doubles_ascending(const void* a, const void* b) +int compare_doubles_ascending(const void* a, const void* b) { return compare_doubles(a, b, 1); } -static int compare_doubles_descending(const void* a, const void* b) +int compare_doubles_descending(const void* a, const void* b) { return compare_doubles(a, b, 0); } -static void init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_class_latitudes_t::init(grib_accessor* a, const long l, grib_arguments* c) { - grib_accessor_latitudes* self = (grib_accessor_latitudes*)a; - int n = 0; + grib_accessor_class_double_t::init(a, l, c); + grib_accessor_latitudes_t* self = (grib_accessor_latitudes_t*)a; + int n = 0; self->values = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); self->distinct = grib_arguments_get_long(grib_handle_of_accessor(a), c, n++); @@ -151,19 +55,19 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_class_latitudes_t::unpack_double(grib_accessor* a, double* val, size_t* len) { - grib_context* c = a->context; - grib_accessor_latitudes* self = (grib_accessor_latitudes*)a; - int ret = GRIB_SUCCESS; - double* v = val; - double dummyLon = 0; - size_t size = 0; - long count = 0; - grib_iterator* iter = NULL; + grib_context* c = a->context; + grib_accessor_latitudes_t* self = (grib_accessor_latitudes_t*)a; + int ret = 0; + double* v = val; + double dummyLon = 0; + size_t size = 0; + long count = 0; + grib_iterator* iter = NULL; self->save = 1; - ret = value_count(a, &count); + ret = value_count(a, &count); if (ret) return ret; size = count; if (*len < size) { @@ -205,13 +109,13 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) return ret; } -static int value_count(grib_accessor* a, long* len) +int grib_accessor_class_latitudes_t::value_count(grib_accessor* a, long* len) { - grib_accessor_latitudes* self = (grib_accessor_latitudes*)a; - grib_handle* h = grib_handle_of_accessor(a); - grib_context* c = a->context; - double* val = NULL; - int ret = GRIB_SUCCESS; + grib_accessor_latitudes_t* self = (grib_accessor_latitudes_t*)a; + grib_handle* h = grib_handle_of_accessor(a); + grib_context* c = a->context; + double* val = NULL; + int ret; size_t size; *len = 0; @@ -258,7 +162,7 @@ static int get_distinct(grib_accessor* a, double** val, long* len) grib_context* c = a->context; // Performance: We do not need the values to be decoded - grib_iterator* iter = grib_iterator_new(grib_handle_of_accessor(a), GRIB_GEOITERATOR_NO_VALUES, &ret); + grib_iterator* iter = grib_iterator_new(grib_handle_of_accessor(a), GRIB_GEOITERATOR_NO_VALUES, &ret); if (ret != GRIB_SUCCESS) { if (iter) grib_iterator_delete(iter); diff --git a/src/accessor/grib_accessor_class_latitudes.h b/src/accessor/grib_accessor_class_latitudes.h new file mode 100644 index 000000000..cb1f6ada8 --- /dev/null +++ b/src/accessor/grib_accessor_class_latitudes.h @@ -0,0 +1,35 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_double.h" + +class grib_accessor_latitudes_t : public grib_accessor_double_t +{ +public: + /* Members defined in latitudes */ + const char* values; + long distinct; + double* lats; + long size; + int save; +}; + +class grib_accessor_class_latitudes_t : public grib_accessor_class_double_t +{ +public: + grib_accessor_class_latitudes_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_latitudes_t{}; } + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_latlon_increment.cc b/src/accessor/grib_accessor_class_latlon_increment.cc similarity index 61% rename from src/grib_accessor_class_latlon_increment.cc rename to src/accessor/grib_accessor_class_latlon_increment.cc index de43e60c9..885a4cd61 100644 --- a/src/grib_accessor_class_latlon_increment.cc +++ b/src/accessor/grib_accessor_class_latlon_increment.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,118 +9,15 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_double - IMPLEMENTS = unpack_double;pack_double;is_missing - IMPLEMENTS = init - MEMBERS=const char* directionIncrementGiven - MEMBERS=const char* directionIncrement - MEMBERS=const char* scansPositively - MEMBERS=const char* first - MEMBERS=const char* last - MEMBERS=const char* numberOfPoints - MEMBERS=const char* angleMultiplier - MEMBERS=const char* angleDivisor - MEMBERS=long isLongitude - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int is_missing(grib_accessor*); -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_latlon_increment -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in latlon_increment */ - const char* directionIncrementGiven; - const char* directionIncrement; - const char* scansPositively; - const char* first; - const char* last; - const char* numberOfPoints; - const char* angleMultiplier; - const char* angleDivisor; - long isLongitude; -} grib_accessor_latlon_increment; - -extern grib_accessor_class* grib_accessor_class_double; - -static grib_accessor_class _grib_accessor_class_latlon_increment = { - &grib_accessor_class_double, /* super */ - "latlon_increment", /* name */ - sizeof(grib_accessor_latlon_increment), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - &is_missing, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_latlon_increment.h" +grib_accessor_class_latlon_increment_t _grib_accessor_class_latlon_increment{"latlon_increment"}; grib_accessor_class* grib_accessor_class_latlon_increment = &_grib_accessor_class_latlon_increment; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_latlon_increment* self = (grib_accessor_latlon_increment*)a; +void grib_accessor_class_latlon_increment_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_double_t::init(a, l, c); + grib_accessor_latlon_increment_t* self = (grib_accessor_latlon_increment_t*)a; int n = 0; grib_handle* hand = grib_handle_of_accessor(a); @@ -134,9 +32,8 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) self->isLongitude = grib_arguments_get_long(hand, c, n++); } -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_latlon_increment* self = (grib_accessor_latlon_increment*)a; +int grib_accessor_class_latlon_increment_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + grib_accessor_latlon_increment_t* self = (grib_accessor_latlon_increment_t*)a; int ret = 0; grib_handle* hand = grib_handle_of_accessor(a); @@ -221,9 +118,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) return ret; } -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_latlon_increment* self = (grib_accessor_latlon_increment*)a; +int grib_accessor_class_latlon_increment_t::pack_double(grib_accessor* a, const double* val, size_t* len){ + grib_accessor_latlon_increment_t* self = (grib_accessor_latlon_increment_t*)a; int ret = 0; long codedNumberOfPoints = 0; grib_handle* hand = grib_handle_of_accessor(a); @@ -305,8 +201,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) return GRIB_SUCCESS; } -static int is_missing(grib_accessor* a) -{ +int grib_accessor_class_latlon_increment_t::is_missing(grib_accessor* a){ size_t len = 1; double val = 0; diff --git a/src/accessor/grib_accessor_class_latlon_increment.h b/src/accessor/grib_accessor_class_latlon_increment.h new file mode 100644 index 000000000..8dfa7cb93 --- /dev/null +++ b/src/accessor/grib_accessor_class_latlon_increment.h @@ -0,0 +1,40 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_double.h" + +class grib_accessor_latlon_increment_t : public grib_accessor_double_t +{ +public: + /* Members defined in latlon_increment */ + const char* directionIncrementGiven; + const char* directionIncrement; + const char* scansPositively; + const char* first; + const char* last; + const char* numberOfPoints; + const char* angleMultiplier; + const char* angleDivisor; + long isLongitude; +}; + +class grib_accessor_class_latlon_increment_t : public grib_accessor_class_double_t +{ +public: + grib_accessor_class_latlon_increment_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_latlon_increment_t{}; } + int is_missing(grib_accessor*) override; + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_latlonvalues.cc b/src/accessor/grib_accessor_class_latlonvalues.cc new file mode 100644 index 000000000..5d43d6be9 --- /dev/null +++ b/src/accessor/grib_accessor_class_latlonvalues.cc @@ -0,0 +1,76 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_latlonvalues.h" + +grib_accessor_class_latlonvalues_t _grib_accessor_class_latlonvalues{"latlonvalues"}; +grib_accessor_class* grib_accessor_class_latlonvalues = &_grib_accessor_class_latlonvalues; + + +void grib_accessor_class_latlonvalues_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_double_t::init(a, l, c); + grib_accessor_latlonvalues_t* self = (grib_accessor_latlonvalues_t*)a; + int n = 0; + + self->values = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; +} + +int grib_accessor_class_latlonvalues_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + grib_context* c = a->context; + int err = 0; + double* v = val; + double lat, lon, value; + size_t size = 0; + long count = 0; + grib_iterator* iter = grib_iterator_new(grib_handle_of_accessor(a), 0, &err); + if (err) { + if (iter) grib_iterator_delete(iter); + grib_context_log(c, GRIB_LOG_ERROR, "latlonvalues: Unable to create iterator"); + return err; + } + + err = value_count(a, &count); + if (err) return err; + size = count; + + if (*len < size) { + if (iter) grib_iterator_delete(iter); + return GRIB_ARRAY_TOO_SMALL; + } + + while (grib_iterator_next(iter, &lat, &lon, &value)) { + *(v++) = lat; + *(v++) = lon; + *(v++) = value; + } + + grib_iterator_delete(iter); + + *len = size; + + return GRIB_SUCCESS; +} + +int grib_accessor_class_latlonvalues_t::value_count(grib_accessor* a, long* count){ + grib_accessor_latlonvalues_t* self = (grib_accessor_latlonvalues_t*)a; + grib_handle* h = grib_handle_of_accessor(a); + int ret = GRIB_SUCCESS; + size_t size; + if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) { + grib_context_log(h->context, GRIB_LOG_ERROR, "latlonvalues: Unable to get size of %s", self->values); + return ret; + } + + *count = 3 * size; + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_latlonvalues.h b/src/accessor/grib_accessor_class_latlonvalues.h new file mode 100644 index 000000000..7328688c6 --- /dev/null +++ b/src/accessor/grib_accessor_class_latlonvalues.h @@ -0,0 +1,31 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_double.h" + +class grib_accessor_latlonvalues_t : public grib_accessor_double_t +{ +public: + /* Members defined in latlonvalues */ + const char* values; +}; + +class grib_accessor_class_latlonvalues_t : public grib_accessor_class_double_t +{ +public: + grib_accessor_class_latlonvalues_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_latlonvalues_t{}; } + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_library_version.cc b/src/accessor/grib_accessor_class_library_version.cc new file mode 100644 index 000000000..527b4809a --- /dev/null +++ b/src/accessor/grib_accessor_class_library_version.cc @@ -0,0 +1,45 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_library_version.h" + +grib_accessor_class_library_version_t _grib_accessor_class_library_version{"library_version"}; +grib_accessor_class* grib_accessor_class_library_version = &_grib_accessor_class_library_version; + + +int grib_accessor_class_library_version_t::unpack_string(grib_accessor* a, char* val, size_t* len){ + char result[30] = {0,}; + size_t size; + + int major = ECCODES_MAJOR_VERSION; + int minor = ECCODES_MINOR_VERSION; + int revision = ECCODES_REVISION_VERSION; + + snprintf(result, sizeof(result), "%d.%d.%d", major, minor, revision); + size = sizeof(result); + + if (*len < size) + return GRIB_ARRAY_TOO_SMALL; + strcpy(val, result); + + *len = size; + + return GRIB_SUCCESS; +} + +int grib_accessor_class_library_version_t::value_count(grib_accessor* a, long* count){ + *count = 1; + return 0; +} + +size_t grib_accessor_class_library_version_t::string_length(grib_accessor* a){ + return 255; +} diff --git a/src/accessor/grib_accessor_class_library_version.h b/src/accessor/grib_accessor_class_library_version.h new file mode 100644 index 000000000..cb2a45f04 --- /dev/null +++ b/src/accessor/grib_accessor_class_library_version.h @@ -0,0 +1,30 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_ascii.h" + +class grib_accessor_library_version_t : public grib_accessor_ascii_t +{ +public: + /* Members defined in library_version */ +}; + +class grib_accessor_class_library_version_t : public grib_accessor_class_ascii_t +{ +public: + grib_accessor_class_library_version_t(const char* name) : grib_accessor_class_ascii_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_library_version_t{}; } + int unpack_string(grib_accessor*, char*, size_t* len) override; + size_t string_length(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; +}; diff --git a/src/grib_accessor_class_local_definition.cc b/src/accessor/grib_accessor_class_local_definition.cc similarity index 72% rename from src/grib_accessor_class_local_definition.cc rename to src/accessor/grib_accessor_class_local_definition.cc index 782ce5fde..0964a3005 100644 --- a/src/grib_accessor_class_local_definition.cc +++ b/src/accessor/grib_accessor_class_local_definition.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,125 +9,15 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -/************************************** - * This pertains to GRIB edition 2 - **************************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_unsigned - IMPLEMENTS = unpack_long;pack_long; value_count - IMPLEMENTS = init - MEMBERS=const char* productDefinitionTemplateNumber - MEMBERS=const char* productDefinitionTemplateNumberInternal - MEMBERS=const char* grib2LocalSectionNumber - MEMBERS=const char* type - MEMBERS=const char* stream - MEMBERS=const char* the_class - MEMBERS=const char* eps - MEMBERS=const char* stepType - MEMBERS=const char* derivedForecast - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_local_definition -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in unsigned */ - long nbytes; - grib_arguments* arg; - /* Members defined in local_definition */ - const char* productDefinitionTemplateNumber; - const char* productDefinitionTemplateNumberInternal; - const char* grib2LocalSectionNumber; - const char* type; - const char* stream; - const char* the_class; - const char* eps; - const char* stepType; - const char* derivedForecast; -} grib_accessor_local_definition; - -extern grib_accessor_class* grib_accessor_class_unsigned; - -static grib_accessor_class _grib_accessor_class_local_definition = { - &grib_accessor_class_unsigned, /* super */ - "local_definition", /* name */ - sizeof(grib_accessor_local_definition), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_local_definition.h" +grib_accessor_class_local_definition_t _grib_accessor_class_local_definition{"local_definition"}; grib_accessor_class* grib_accessor_class_local_definition = &_grib_accessor_class_local_definition; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_local_definition* self = (grib_accessor_local_definition*)a; +void grib_accessor_class_local_definition_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_unsigned_t::init(a, l, c); + grib_accessor_local_definition_t* self = (grib_accessor_local_definition_t*)a; grib_handle* hand = grib_handle_of_accessor(a); int n = 0; @@ -141,16 +32,14 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) self->derivedForecast = grib_arguments_get_name(hand, c, n++); } -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_local_definition* self = (grib_accessor_local_definition*)a; +int grib_accessor_class_local_definition_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_accessor_local_definition_t* self = (grib_accessor_local_definition_t*)a; return grib_get_long(grib_handle_of_accessor(a), self->grib2LocalSectionNumber, val); } -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - grib_accessor_local_definition* self = (grib_accessor_local_definition*)a; +int grib_accessor_class_local_definition_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + grib_accessor_local_definition_t* self = (grib_accessor_local_definition_t*)a; grib_handle* hand = grib_handle_of_accessor(a); long productDefinitionTemplateNumber = -1; long productDefinitionTemplateNumberInternal = -1; @@ -316,7 +205,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) #ifdef DEBUG // In test & development mode, fail so we remember to adjust PDTN grib_context_log(a->context, GRIB_LOG_ERROR, - "grib_accessor_local_definition: Invalid localDefinitionNumber %d", localDefinitionNumber); + "grib_accessor_local_definition_t: Invalid localDefinitionNumber %d", localDefinitionNumber); return GRIB_ENCODING_ERROR; #endif // ECC-1253: Do not fail in operations. Leave PDTN as is @@ -419,7 +308,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) if (productDefinitionTemplateNumber != productDefinitionTemplateNumberNew) { if (a->context->debug) { - fprintf(stderr, "ECCODES DEBUG grib_accessor_local_definition: ldNumber=%d, newPDTN=%ld\n", + fprintf(stderr, "ECCODES DEBUG grib_accessor_local_definition_t: ldNumber=%d, newPDTN=%ld\n", localDefinitionNumber, productDefinitionTemplateNumberNew); } if (tooEarly) @@ -435,8 +324,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) return 0; } -static int value_count(grib_accessor* a, long* count) -{ +int grib_accessor_class_local_definition_t::value_count(grib_accessor* a, long* count){ *count = 1; return 0; } diff --git a/src/accessor/grib_accessor_class_local_definition.h b/src/accessor/grib_accessor_class_local_definition.h new file mode 100644 index 000000000..f91ebbef4 --- /dev/null +++ b/src/accessor/grib_accessor_class_local_definition.h @@ -0,0 +1,40 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_unsigned.h" + +class grib_accessor_local_definition_t : public grib_accessor_unsigned_t +{ +public: + /* Members defined in local_definition */ + const char* productDefinitionTemplateNumber; + const char* productDefinitionTemplateNumberInternal; + const char* grib2LocalSectionNumber; + const char* type; + const char* stream; + const char* the_class; + const char* eps; + const char* stepType; + const char* derivedForecast; +}; + +class grib_accessor_class_local_definition_t : public grib_accessor_class_unsigned_t +{ +public: + grib_accessor_class_local_definition_t(const char* name) : grib_accessor_class_unsigned_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_local_definition_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_long.cc b/src/accessor/grib_accessor_class_long.cc new file mode 100644 index 000000000..588083c49 --- /dev/null +++ b/src/accessor/grib_accessor_class_long.cc @@ -0,0 +1,182 @@ +/* + * (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. + */ + +#include "grib_accessor_class_long.h" + +grib_accessor_class_long_t _grib_accessor_class_long{"long"}; +grib_accessor_class* grib_accessor_class_long = &_grib_accessor_class_long; + +void grib_accessor_class_long_t::init(grib_accessor* a, const long len, grib_arguments* arg) { + grib_accessor_class_gen_t::init(a, len, arg); +} + +int grib_accessor_class_long_t::get_native_type(grib_accessor* a) +{ + return GRIB_TYPE_LONG; +} + +void grib_accessor_class_long_t::dump(grib_accessor* a, grib_dumper* dumper) +{ + grib_dump_long(dumper, a, NULL); +} + +int grib_accessor_class_long_t::unpack_string(grib_accessor* a, char* v, size_t* len) +{ + long val = 0; + size_t l = 1; + char repres[1024]; + char format[32] = "%ld"; + grib_handle* h = grib_handle_of_accessor(a); + + a->unpack_long(&val, &l); + /* TODO: We should catch all errors but in this case the test ERA_Gen.sh will fail + * as the output from grib_ls will be different */ + + if ((val == GRIB_MISSING_LONG) && ((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0)) { + snprintf(repres, sizeof(repres), "MISSING"); + } else { + size_t size = sizeof(format); + grib_get_string(h, "formatForLongs", format, &size); + snprintf(repres, sizeof(repres), format, val); + } + + l = strlen(repres) + 1; + + if (*len < l) { + const char* cclass_name = a->cclass->name; + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", + cclass_name, a->name, l, *len); + *len = l; + return GRIB_BUFFER_TOO_SMALL; + } + /*grib_context_log(a->context,GRIB_LOG_DEBUG, "grib_accessor_long: Casting long %s to string ", a->name);*/ + + *len = l; + + strcpy(v, repres); + return GRIB_SUCCESS; +} + +int grib_accessor_class_long_t::pack_missing(grib_accessor* a) +{ + size_t len = 1; + long value = GRIB_MISSING_LONG; + + if (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) + return a->pack_long(&value, &len); + + return GRIB_VALUE_CANNOT_BE_MISSING; +} + +int grib_accessor_class_long_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ + size_t rlen = 0; + long count = 0; + unsigned long i = 0; + long* values = NULL; + long oneval = 0; + int ret = GRIB_SUCCESS; + + ret = a->value_count(&count); + if (ret) + return ret; + rlen = count; + + if (*len < rlen) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %lu values", a->name, rlen); + *len = 0; + return GRIB_ARRAY_TOO_SMALL; + } + + if (rlen == 1) { + ret = a->unpack_long(&oneval, &rlen); + if (ret != GRIB_SUCCESS) + return ret; + *val = oneval; + *len = 1; + return GRIB_SUCCESS; + } + + values = (long*)grib_context_malloc(a->context, rlen * sizeof(long)); + if (!values) + return GRIB_OUT_OF_MEMORY; + + ret = a->unpack_long(values, &rlen); + if (ret != GRIB_SUCCESS) { + grib_context_free(a->context, values); + return ret; + } + for (i = 0; i < rlen; i++) + val[i] = values[i]; + + grib_context_free(a->context, values); + + *len = rlen; + return GRIB_SUCCESS; +} + +int grib_accessor_class_long_t::compare(grib_accessor* a, grib_accessor* b) +{ + int retval = 0; + long* aval = 0; + long* bval = 0; + long count = 0; + + size_t alen = 0; + size_t blen = 0; + int err = 0; + + err = a->value_count(&count); + if (err) + return err; + alen = count; + + err = b->value_count(&count); + if (err) + return err; + blen = count; + + if (alen != blen) + return GRIB_COUNT_MISMATCH; + + aval = (long*)grib_context_malloc(a->context, alen * sizeof(long)); + bval = (long*)grib_context_malloc(b->context, blen * sizeof(long)); + + a->unpack_long(aval, &alen); + b->unpack_long(bval, &blen); + + retval = GRIB_SUCCESS; + for (size_t i=0; icontext, aval); + grib_context_free(b->context, bval); + + return retval; +} + +int grib_accessor_class_long_t::pack_string(grib_accessor* a, const char* val, size_t* len) +{ + long v = 0; /* The converted value */ + + // ECC-1722 + if (STR_EQUAL_NOCASE(val, "missing")) { + return pack_missing(a); + } + + if (string_to_long(val, &v, 1) != GRIB_SUCCESS) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "Trying to pack \"%s\" as long. String cannot be converted to an integer", val); + return GRIB_WRONG_TYPE; + } + return a->pack_long(&v, len); +} diff --git a/src/accessor/grib_accessor_class_long.h b/src/accessor/grib_accessor_class_long.h new file mode 100644 index 000000000..72a67a8e5 --- /dev/null +++ b/src/accessor/grib_accessor_class_long.h @@ -0,0 +1,31 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_long_t : public grib_accessor_gen_t +{}; + +class grib_accessor_class_long_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_long_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_long_t{}; } + void init(grib_accessor* a, const long len, grib_arguments* arg) override; + int get_native_type(grib_accessor* a) override; + int pack_missing(grib_accessor* a) override; + int pack_string(grib_accessor* a, const char*, size_t* len) override; + int unpack_double(grib_accessor* a, double* val, size_t* len) override; + int unpack_string(grib_accessor* a, char*, size_t* len) override; + void dump(grib_accessor* a, grib_dumper*) override; + int compare(grib_accessor* a, grib_accessor*) override; +}; diff --git a/src/accessor/grib_accessor_class_long_vector.cc b/src/accessor/grib_accessor_class_long_vector.cc new file mode 100644 index 000000000..0aee8c8c9 --- /dev/null +++ b/src/accessor/grib_accessor_class_long_vector.cc @@ -0,0 +1,95 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_long_vector.h" +#include "grib_accessor_class_abstract_long_vector.h" + +grib_accessor_class_long_vector_t _grib_accessor_class_long_vector{"long_vector"}; +grib_accessor_class* grib_accessor_class_long_vector = &_grib_accessor_class_long_vector; + + +void grib_accessor_class_long_vector_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_abstract_long_vector_t::init(a, l, c); + grib_accessor_long_vector_t* self = (grib_accessor_long_vector_t*)a; + grib_accessor* va = NULL; + grib_accessor_abstract_long_vector_t* v = NULL; + int n = 0; + + 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_t*)va; + + 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); + + a->length = 0; +} + +int grib_accessor_class_long_vector_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + size_t size = 0; + int err = 0; + long* vector; + grib_accessor_long_vector_t* self = (grib_accessor_long_vector_t*)a; + grib_accessor* va = NULL; + grib_accessor_abstract_long_vector_t* v = NULL; + + va = (grib_accessor*)grib_find_accessor(grib_handle_of_accessor(a), self->vector); + v = (grib_accessor_abstract_long_vector_t*)va; + + /*TODO implement the dirty mechanism to avoid to unpack every time */ + err = grib_get_size(grib_handle_of_accessor(a), self->vector, &size); + if (err) return err; + DEBUG_ASSERT(size > 0); + vector = (long*)grib_context_malloc(a->context, sizeof(long) * size); + err = va->unpack_long(vector, &size); grib_context_free(a->context, vector); + if (err) return err; + + *val = v->v[self->index]; + + return GRIB_SUCCESS; +} + +int grib_accessor_class_long_vector_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + long lval = 0; + int err = 0; + grib_accessor_long_vector_t* self = (grib_accessor_long_vector_t*)a; + grib_accessor* va = NULL; + grib_accessor_abstract_long_vector_t* v = NULL; + va = (grib_accessor*)grib_find_accessor(grib_handle_of_accessor(a), self->vector); + v = (grib_accessor_abstract_long_vector_t*)va; + + err = unpack_long(a, &lval, len); + + *val = (double)v->v[self->index]; + + return err; +} + +int grib_accessor_class_long_vector_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + int err = 0; + grib_accessor_long_vector_t* self = (grib_accessor_long_vector_t*)a; + grib_accessor* va = NULL; + grib_accessor_abstract_long_vector_t* v = NULL; + + va = (grib_accessor*)grib_find_accessor(grib_handle_of_accessor(a), self->vector); + v = (grib_accessor_abstract_long_vector_t*)va; + + v->pack_index = self->index; + + err = va->pack_long(val, len); + return err; +} + +int grib_accessor_class_long_vector_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_LONG; +} diff --git a/src/accessor/grib_accessor_class_long_vector.h b/src/accessor/grib_accessor_class_long_vector.h new file mode 100644 index 000000000..010a4ed7e --- /dev/null +++ b/src/accessor/grib_accessor_class_long_vector.h @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_abstract_long_vector.h" + +class grib_accessor_long_vector_t : public grib_accessor_abstract_long_vector_t +{ +public: + /* Members defined in long_vector */ + const char* vector; + int index; +}; + +class grib_accessor_class_long_vector_t : public grib_accessor_class_abstract_long_vector_t +{ +public: + grib_accessor_class_long_vector_t(const char* name) : grib_accessor_class_abstract_long_vector_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_long_vector_t{}; } + int get_native_type(grib_accessor*) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_longitudes.cc b/src/accessor/grib_accessor_class_longitudes.cc similarity index 56% rename from src/grib_accessor_class_longitudes.cc rename to src/accessor/grib_accessor_class_longitudes.cc index 78fc7a733..a9ae31309 100644 --- a/src/grib_accessor_class_longitudes.cc +++ b/src/accessor/grib_accessor_class_longitudes.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,114 +9,17 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_double - IMPLEMENTS = unpack_double; - IMPLEMENTS = value_count - IMPLEMENTS = init - MEMBERS =const char* values - MEMBERS =long distinct - MEMBERS =double* lons - MEMBERS =long size - MEMBERS =int save - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_longitudes -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in longitudes */ - const char* values; - long distinct; - double* lons; - long size; - int save; -} grib_accessor_longitudes; - -extern grib_accessor_class* grib_accessor_class_double; - -static grib_accessor_class _grib_accessor_class_longitudes = { - &grib_accessor_class_double, /* super */ - "longitudes", /* name */ - sizeof(grib_accessor_longitudes), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_longitudes.h" +grib_accessor_class_longitudes_t _grib_accessor_class_longitudes{"longitudes"}; grib_accessor_class* grib_accessor_class_longitudes = &_grib_accessor_class_longitudes; -/* END_CLASS_IMP */ - static int get_distinct(grib_accessor* a, double** val, long* len); -static int compare_doubles(const void* a, const void* b); - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_longitudes* self = (grib_accessor_longitudes*)a; +int compare_doubles(const void* a, const void* b); +void grib_accessor_class_longitudes_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_double_t::init(a, l, c); + grib_accessor_longitudes_t* self = (grib_accessor_longitudes_t*)a; int n = 0; self->values = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); @@ -126,10 +30,9 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ +int grib_accessor_class_longitudes_t::unpack_double(grib_accessor* a, double* val, size_t* len){ grib_context* c = a->context; - grib_accessor_longitudes* self = (grib_accessor_longitudes*)a; + grib_accessor_longitudes_t* self = (grib_accessor_longitudes_t*)a; int ret = 0; double* v = val; double dummyLat = 0; @@ -181,9 +84,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) return ret; } -static int value_count(grib_accessor* a, long* len) -{ - grib_accessor_longitudes* self = (grib_accessor_longitudes*)a; +int grib_accessor_class_longitudes_t::value_count(grib_accessor* a, long* len){ + grib_accessor_longitudes_t* self = (grib_accessor_longitudes_t*)a; grib_handle* h = grib_handle_of_accessor(a); grib_context* c = a->context; double* val = NULL; @@ -219,15 +121,13 @@ static int value_count(grib_accessor* a, long* len) return ret; } -static int get_distinct(grib_accessor* a, double** val, long* len) -{ +static int get_distinct(grib_accessor* a, double** val, long* len){ long count = 0; double prev; double* v = NULL; double* v1 = NULL; double dummyLat = 0; int ret = 0; - int i; size_t size = *len; grib_context* c = a->context; @@ -261,7 +161,7 @@ static int get_distinct(grib_accessor* a, double** val, long* len) prev = v[0]; v1[0] = prev; count = 1; - for (i = 1; i < *len; i++) { + for (long i = 1; i < *len; i++) { if (v[i] != prev) { prev = v[i]; v1[count] = prev; @@ -277,8 +177,7 @@ static int get_distinct(grib_accessor* a, double** val, long* len) return GRIB_SUCCESS; } -static int compare_doubles(const void* a, const void* b) -{ +int compare_doubles(const void* a, const void* b){ double* arg1 = (double*)a; double* arg2 = (double*)b; if (*arg1 < *arg2) diff --git a/src/accessor/grib_accessor_class_longitudes.h b/src/accessor/grib_accessor_class_longitudes.h new file mode 100644 index 000000000..def174a74 --- /dev/null +++ b/src/accessor/grib_accessor_class_longitudes.h @@ -0,0 +1,35 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_double.h" + +class grib_accessor_longitudes_t : public grib_accessor_double_t +{ +public: + /* Members defined in longitudes */ + const char* values; + long distinct; + double* lons; + long size; + int save; +}; + +class grib_accessor_class_longitudes_t : public grib_accessor_class_double_t +{ +public: + grib_accessor_class_longitudes_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_longitudes_t{}; } + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_lookup.cc b/src/accessor/grib_accessor_class_lookup.cc new file mode 100644 index 000000000..17ccd4d61 --- /dev/null +++ b/src/accessor/grib_accessor_class_lookup.cc @@ -0,0 +1,133 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_lookup.h" + +grib_accessor_class_lookup_t _grib_accessor_class_lookup{"lookup"}; +grib_accessor_class* grib_accessor_class_lookup = &_grib_accessor_class_lookup; + + +void grib_accessor_class_lookup_t::init(grib_accessor* a, const long len, grib_arguments* arg){ + grib_accessor_class_long_t::init(a, len, arg); + grib_accessor_lookup_t* self = (grib_accessor_lookup_t*)a; + a->length = 0; + self->llength = len; + self->loffset = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 0); + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + self->real_name = grib_arguments_get_expression(grib_handle_of_accessor(a), arg, 1); +} + +void grib_accessor_class_lookup_t::post_init(grib_accessor* a){ + grib_accessor_lookup_t* self = (grib_accessor_lookup_t*)a; + if (self->real_name) { + grib_dependency_observe_expression(a, self->real_name); + } +} + +void grib_accessor_class_lookup_t::dump(grib_accessor* a, grib_dumper* dumper){ + grib_accessor_lookup_t* self = (grib_accessor_lookup_t*)a; + unsigned char bytes[1024] = {0,}; + char msg[1024] = {0,}; + char buf[2048]; + int i; + unsigned long v = 0; + + size_t llen = self->llength; + a->unpack_bytes(bytes, &llen); + bytes[llen] = 0; + for (i = 0; i < llen; i++) { + msg[i] = isprint(bytes[i]) ? bytes[i] : '?'; + v <<= 8; + v |= bytes[i]; + } + + msg[llen] = 0; + + snprintf(buf, sizeof(buf), "%s %lu %ld-%ld", msg, v, (long)a->offset + self->loffset, (long)self->llength); + + grib_dump_long(dumper, a, buf); +} + +int grib_accessor_class_lookup_t::unpack_string(grib_accessor* a, char* v, size_t* len){ + grib_accessor_lookup_t* self = (grib_accessor_lookup_t*)a; + unsigned char bytes[1024] = {0,}; + int i; + + size_t llen = self->llength; + a->unpack_bytes(bytes, &llen); + bytes[llen] = 0; + + for (i = 0; i < llen; i++) { + v[i] = isprint(bytes[i]) ? bytes[i] : '?'; + } + + v[llen] = 0; + if (llen == 1 && v[0] == '?') { + /* Try unpack as long */ + size_t length = 10; + long lval = 0; + int err = unpack_long(a, &lval, &length); + if (!err) { + char str[5]; + int conv = snprintf(str, sizeof(str), "%ld", lval); + if (conv == 1) { + v[0] = str[0]; + } + } + } + + return GRIB_SUCCESS; +} + +int grib_accessor_class_lookup_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_accessor_lookup_t* self = (grib_accessor_lookup_t*)a; + grib_handle* h = grib_handle_of_accessor(a); + + long pos = (a->offset + self->loffset) * 8; + + if (len[0] < 1) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name, 1); + len[0] = 0; + return GRIB_ARRAY_TOO_SMALL; + } + + /* This is used when reparsing or rebuilding */ + if (h->loader) { + Assert(*len == 1); + return h->loader->lookup_long(h->context, h->loader, a->name, val); + } + + val[0] = grib_decode_unsigned_long(h->buffer->data, &pos, self->llength * 8); + len[0] = 1; + + /*printf("###########lookup unpack_long: %s %ld %ld\n",a->name, pos/8, val[0]);*/ + + return GRIB_SUCCESS; +} + +int grib_accessor_class_lookup_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + return GRIB_NOT_IMPLEMENTED; +} + +long grib_accessor_class_lookup_t::byte_count(grib_accessor* a){ + grib_accessor_lookup_t* self = (grib_accessor_lookup_t*)a; + return self->llength; +} + +long grib_accessor_class_lookup_t::byte_offset(grib_accessor* a){ + grib_accessor_lookup_t* self = (grib_accessor_lookup_t*)a; + return self->loffset; +} + +int grib_accessor_class_lookup_t::notify_change(grib_accessor* self, grib_accessor* changed){ + /* Forward changes */ + return grib_dependency_notify_change(self); +} diff --git a/src/accessor/grib_accessor_class_lookup.h b/src/accessor/grib_accessor_class_lookup.h new file mode 100644 index 000000000..be1663ae7 --- /dev/null +++ b/src/accessor/grib_accessor_class_lookup.h @@ -0,0 +1,38 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_lookup_t : public grib_accessor_long_t +{ +public: + long llength; + long loffset; + grib_expression* real_name; +}; + +class grib_accessor_class_lookup_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_lookup_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_lookup_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + long byte_count(grib_accessor*) override; + long byte_offset(grib_accessor*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + void post_init(grib_accessor*) override; + int notify_change(grib_accessor*, grib_accessor*) override; +}; diff --git a/src/accessor/grib_accessor_class_mars_param.cc b/src/accessor/grib_accessor_class_mars_param.cc new file mode 100644 index 000000000..feb5fc905 --- /dev/null +++ b/src/accessor/grib_accessor_class_mars_param.cc @@ -0,0 +1,53 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_mars_param.h" + +grib_accessor_class_mars_param_t _grib_accessor_class_mars_param{"mars_param"}; +grib_accessor_class* grib_accessor_class_mars_param = &_grib_accessor_class_mars_param; + + +void grib_accessor_class_mars_param_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_ascii_t::init(a, l, c); + int n = 0; + grib_accessor_mars_param_t* self = (grib_accessor_mars_param_t*)a; + self->paramId = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->table = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->param = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); +} + +// For an implementation of pack_string, see +// src/deprecated/grib_accessor_class_mars_param.cc + +// For an alternative implementation of unpack_string, see +// src/deprecated/grib_accessor_class_mars_param.cc +// +int grib_accessor_class_mars_param_t::unpack_string(grib_accessor* a, char* val, size_t* len){ + grib_accessor_mars_param_t* self = (grib_accessor_mars_param_t*)a; + long param = 0; + long table = 0; + int ret = 0; + + if (self->table != NULL && (ret = grib_get_long_internal(grib_handle_of_accessor(a), self->table, &table)) != GRIB_SUCCESS) + return ret; + if (self->param != NULL && (ret = grib_get_long_internal(grib_handle_of_accessor(a), self->param, ¶m)) != GRIB_SUCCESS) + return ret; + + /*if (table==200) table=128;*/ + snprintf(val, 32, "%ld.%ld", param, table); + *len = strlen(val) + 1; + + return GRIB_SUCCESS; +} + +size_t grib_accessor_class_mars_param_t::string_length(grib_accessor* a){ + return 7; +} diff --git a/src/accessor/grib_accessor_class_mars_param.h b/src/accessor/grib_accessor_class_mars_param.h new file mode 100644 index 000000000..1eab50fb6 --- /dev/null +++ b/src/accessor/grib_accessor_class_mars_param.h @@ -0,0 +1,33 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_ascii.h" + +class grib_accessor_mars_param_t : public grib_accessor_ascii_t +{ +public: + /* Members defined in mars_param */ + const char* paramId; + const char* table; + const char* param; +}; + +class grib_accessor_class_mars_param_t : public grib_accessor_class_ascii_t +{ +public: + grib_accessor_class_mars_param_t(const char* name) : grib_accessor_class_ascii_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_mars_param_t{}; } + int unpack_string(grib_accessor*, char*, size_t* len) override; + size_t string_length(grib_accessor*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_mars_step.cc b/src/accessor/grib_accessor_class_mars_step.cc new file mode 100644 index 000000000..8fd9f9dfa --- /dev/null +++ b/src/accessor/grib_accessor_class_mars_step.cc @@ -0,0 +1,126 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_mars_step.h" + +grib_accessor_class_mars_step_t _grib_accessor_class_mars_step{ "mars_step" }; +grib_accessor_class* grib_accessor_class_mars_step = &_grib_accessor_class_mars_step; + + +void grib_accessor_class_mars_step_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ + grib_accessor_class_ascii_t::init(a, l, c); + int n = 0; + grib_accessor_mars_step_t* self = (grib_accessor_mars_step_t*)a; + self->stepRange = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->stepType = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); +} + +int grib_accessor_class_mars_step_t::pack_string(grib_accessor* a, const char* val, size_t* len) +{ + char stepType[100]; + size_t stepTypeLen = 100; + char buf[100] = {0,}; + int ret; + grib_accessor_mars_step_t* self = (grib_accessor_mars_step_t*)a; + grib_accessor* stepRangeAcc = grib_find_accessor(grib_handle_of_accessor(a), self->stepRange); + + if (!stepRangeAcc) { + grib_context_log(a->context, GRIB_LOG_ERROR, "%s not found", self->stepRange); + return GRIB_NOT_FOUND; + } + + if ((ret = grib_get_string(grib_handle_of_accessor(a), self->stepType, stepType, &stepTypeLen)) != GRIB_SUCCESS) + return ret; + + if (!strcmp(stepType, "instant")) + snprintf(buf, sizeof(buf), "%s", val); + else + snprintf(buf, sizeof(buf), "0-%s", val); + + return stepRangeAcc->pack_string(buf, len); +} + +int grib_accessor_class_mars_step_t::unpack_string(grib_accessor* a, char* val, size_t* len) +{ + grib_accessor_mars_step_t* self = (grib_accessor_mars_step_t*)a; + + int ret = 0; + char buf[100] = {0,}; + char* p = NULL; + size_t buflen = 100; + long step; + grib_accessor* stepRangeAcc = grib_find_accessor(grib_handle_of_accessor(a), self->stepRange); + const char* cclass_name = a->cclass->name; + + if (!stepRangeAcc) { + grib_context_log(a->context, GRIB_LOG_ERROR, "%s: %s not found", cclass_name, self->stepRange); + return GRIB_NOT_FOUND; + } + + if ((ret = stepRangeAcc->unpack_string(buf, &buflen)) != GRIB_SUCCESS) + return ret; + + if (*len < buflen) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", + cclass_name, a->name, buflen, *len); + *len = buflen; + return GRIB_BUFFER_TOO_SMALL; + } + + strcpy(val, buf); + step = strtol(buf, &p, 10); + + if (p != NULL && *p == '-' && step == 0) + strcpy(val, ++p); + + *len = strlen(val); + + return ret; +} + +int grib_accessor_class_mars_step_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ + char buff[100] = {0,}; + size_t bufflen = 100; + + snprintf(buff, sizeof(buff), "%ld", *val); + + return pack_string(a, buff, &bufflen); +} + +int grib_accessor_class_mars_step_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ + grib_accessor_mars_step_t* self = (grib_accessor_mars_step_t*)a; + grib_accessor* stepRangeAcc = grib_find_accessor(grib_handle_of_accessor(a), self->stepRange); + + if (!stepRangeAcc) + return GRIB_NOT_FOUND; + + return stepRangeAcc->unpack_long(val, len); +} + +int grib_accessor_class_mars_step_t::value_count(grib_accessor* a, long* count) +{ + *count = 1; + return 0; +} + +size_t grib_accessor_class_mars_step_t::string_length(grib_accessor* a) +{ + return 16; +} + +int grib_accessor_class_mars_step_t::get_native_type(grib_accessor* a) +{ + return GRIB_TYPE_LONG; +} diff --git a/src/accessor/grib_accessor_class_mars_step.h b/src/accessor/grib_accessor_class_mars_step.h new file mode 100644 index 000000000..8a49f56a6 --- /dev/null +++ b/src/accessor/grib_accessor_class_mars_step.h @@ -0,0 +1,37 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_ascii.h" + +class grib_accessor_mars_step_t : public grib_accessor_ascii_t +{ +public: + /* Members defined in mars_step */ + const char* stepRange; + const char* stepType; +}; + +class grib_accessor_class_mars_step_t : public grib_accessor_class_ascii_t +{ +public: + grib_accessor_class_mars_step_t(const char* name) : grib_accessor_class_ascii_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_mars_step_t{}; } + int get_native_type(grib_accessor*) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int pack_string(grib_accessor*, const char*, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + size_t string_length(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_md5.cc b/src/accessor/grib_accessor_class_md5.cc similarity index 51% rename from src/grib_accessor_class_md5.cc rename to src/accessor/grib_accessor_class_md5.cc index 6a57c1329..40cbae672 100644 --- a/src/grib_accessor_class_md5.cc +++ b/src/accessor/grib_accessor_class_md5.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,108 +9,17 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" +#include "grib_accessor_class_md5.h" #include "md5.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = get_native_type;init - IMPLEMENTS = compare;unpack_string;value_count;destroy - MEMBERS = const char* offset - MEMBERS = grib_expression* length - MEMBERS = grib_string_list* blocklist - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_string(grib_accessor*, char*, size_t* len); -static int value_count(grib_accessor*, long*); -static void destroy(grib_context*, grib_accessor*); -static void init(grib_accessor*, const long, grib_arguments*); -static int compare(grib_accessor*, grib_accessor*); - -typedef struct grib_accessor_md5 -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in md5 */ - const char* offset; - grib_expression* length; - grib_string_list* blocklist; -} grib_accessor_md5; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_md5 = { - &grib_accessor_class_gen, /* super */ - "md5", /* name */ - sizeof(grib_accessor_md5), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - &destroy, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - &compare, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +grib_accessor_class_md5_t _grib_accessor_class_md5{ "md5" }; grib_accessor_class* grib_accessor_class_md5 = &_grib_accessor_class_md5; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_class_md5_t::init(grib_accessor* a, const long len, grib_arguments* arg) { - grib_accessor_md5* self = (grib_accessor_md5*)a; + grib_accessor_class_gen_t::init(a, len, arg); + grib_accessor_md5_t* self = (grib_accessor_md5_t*)a; char* b = 0; int n = 0; grib_string_list* current = 0; @@ -138,12 +48,12 @@ static void init(grib_accessor* a, const long len, grib_arguments* arg) a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; } -static int get_native_type(grib_accessor* a) +int grib_accessor_class_md5_t::get_native_type(grib_accessor* a) { return GRIB_TYPE_STRING; } -static int compare(grib_accessor* a, grib_accessor* b) +int grib_accessor_class_md5_t::compare(grib_accessor* a, grib_accessor* b) { int retval = GRIB_SUCCESS; @@ -152,12 +62,12 @@ static int compare(grib_accessor* a, grib_accessor* b) int err = 0; long count = 0; - err = grib_value_count(a, &count); + err = a->value_count(&count); if (err) return err; alen = count; - err = grib_value_count(b, &count); + err = b->value_count(&count); if (err) return err; blen = count; @@ -168,16 +78,16 @@ static int compare(grib_accessor* a, grib_accessor* b) return retval; } -static int unpack_string(grib_accessor* a, char* v, size_t* len) +int grib_accessor_class_md5_t::unpack_string(grib_accessor* a, char* v, size_t* len) { - grib_accessor_md5* self = (grib_accessor_md5*)a; + grib_accessor_md5_t* self = (grib_accessor_md5_t*)a; unsigned mess_len; unsigned char* mess; unsigned char* p; long offset = 0, length = 0; grib_string_list* blocklist = NULL; int ret = GRIB_SUCCESS; - long i = 0; + long i = 0; struct grib_md5_state md5c; if (*len < 32) { @@ -226,9 +136,9 @@ static int unpack_string(grib_accessor* a, char* v, size_t* len) return ret; } -static void destroy(grib_context* c, grib_accessor* a) +void grib_accessor_class_md5_t::destroy(grib_context* c, grib_accessor* a) { - grib_accessor_md5* self = (grib_accessor_md5*)a; + grib_accessor_md5_t* self = (grib_accessor_md5_t*)a; if (self->blocklist) { grib_string_list* next = self->blocklist; grib_string_list* cur = NULL; @@ -239,9 +149,10 @@ static void destroy(grib_context* c, grib_accessor* a) grib_context_free(c, cur); } } + grib_accessor_class_gen_t::destroy(c, a); } -static int value_count(grib_accessor* a, long* count) +int grib_accessor_class_md5_t::value_count(grib_accessor* a, long* count) { *count = 1; /* ECC-1475 */ return 0; diff --git a/src/accessor/grib_accessor_class_md5.h b/src/accessor/grib_accessor_class_md5.h new file mode 100644 index 000000000..ae66f397f --- /dev/null +++ b/src/accessor/grib_accessor_class_md5.h @@ -0,0 +1,36 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_md5_t : public grib_accessor_gen_t +{ +public: + /* Members defined in md5 */ + const char* offset; + grib_expression* length; + grib_string_list* blocklist; +}; + +class grib_accessor_class_md5_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_md5_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_md5_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void destroy(grib_context*, grib_accessor*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + int compare(grib_accessor*, grib_accessor*) override; +}; diff --git a/src/accessor/grib_accessor_class_message.cc b/src/accessor/grib_accessor_class_message.cc new file mode 100644 index 000000000..be704b1a1 --- /dev/null +++ b/src/accessor/grib_accessor_class_message.cc @@ -0,0 +1,75 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_message.h" + +grib_accessor_class_message_t _grib_accessor_class_message{"message"}; +grib_accessor_class* grib_accessor_class_message = &_grib_accessor_class_message; + + + +void grib_accessor_class_message_t::init(grib_accessor* a, const long len, grib_arguments* arg){ + grib_accessor_class_bytes_t::init(a, len, 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; +} + +// static int compare(grib_accessor* a, grib_accessor* b) +// { +// if (a->length != b->length) +// return GRIB_COUNT_MISMATCH; +// return GRIB_SUCCESS; +// } + +void grib_accessor_class_message_t::update_size(grib_accessor* a, size_t new_size){ + a->length = new_size; +} + +void grib_accessor_class_message_t::resize(grib_accessor* a, size_t new_size){ + grib_context_log(a->context, GRIB_LOG_FATAL, "%s %s: Not supported", a->cclass->name, __func__); + + // 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 %ld %ld %s %s", + // (long)new_size, (long)a->length, a->cclass->name, a->name); + // Assert(new_size == a->length); +} + +int grib_accessor_class_message_t::value_count(grib_accessor* a, long* count){ + *count = 1; + return 0; +} + +int grib_accessor_class_message_t::unpack_string(grib_accessor* a, char* val, size_t* len){ + long i = 0; + size_t l = string_length(a) + 1; + grib_handle* h = grib_handle_of_accessor(a); + + if (*len < l) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", + a->cclass->name, a->name, l, *len); + *len = l; + return GRIB_BUFFER_TOO_SMALL; + } + + for (i = 0; i < a->length; i++) + val[i] = h->buffer->data[a->offset + i]; + val[i] = 0; + *len = i; + return GRIB_SUCCESS; +} + +size_t grib_accessor_class_message_t::string_length(grib_accessor* a){ + return a->length; +} diff --git a/src/accessor/grib_accessor_class_message.h b/src/accessor/grib_accessor_class_message.h new file mode 100644 index 000000000..2e29d6ebd --- /dev/null +++ b/src/accessor/grib_accessor_class_message.h @@ -0,0 +1,33 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_bytes.h" + +class grib_accessor_message_t : public grib_accessor_bytes_t +{ +public: + /* Members defined in message */ +}; + +class grib_accessor_class_message_t : public grib_accessor_class_bytes_t +{ +public: + grib_accessor_class_message_t(const char* name) : grib_accessor_class_bytes_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_message_t{}; } + int unpack_string(grib_accessor*, char*, size_t* len) override; + size_t string_length(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + void update_size(grib_accessor*, size_t) override; + void resize(grib_accessor*,size_t) override; +}; diff --git a/src/accessor/grib_accessor_class_message_copy.cc b/src/accessor/grib_accessor_class_message_copy.cc new file mode 100644 index 000000000..7927b6c60 --- /dev/null +++ b/src/accessor/grib_accessor_class_message_copy.cc @@ -0,0 +1,59 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_message_copy.h" + +grib_accessor_class_message_copy_t _grib_accessor_class_message_copy{"message_copy"}; +grib_accessor_class* grib_accessor_class_message_copy = &_grib_accessor_class_message_copy; + + +void grib_accessor_class_message_copy_t::init(grib_accessor* a, const long length, grib_arguments* args){ + grib_accessor_class_gen_t::init(a, length, args); + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->length = 0; +} + +void grib_accessor_class_message_copy_t::dump(grib_accessor* a, grib_dumper* dumper){ + grib_dump_string(dumper, a, NULL); +} + +int grib_accessor_class_message_copy_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_STRING; +} + +int grib_accessor_class_message_copy_t::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; i < slen; i++) + if (v[i] > 126) + v[i] = 32; + memcpy(val, grib_handle_of_accessor(a)->buffer->data, slen); + val[i] = 0; + + *len = slen; + + return GRIB_SUCCESS; +} + +size_t grib_accessor_class_message_copy_t::string_length(grib_accessor* a){ + return grib_handle_of_accessor(a)->buffer->ulength; +} + +long grib_accessor_class_message_copy_t::byte_count(grib_accessor* a){ + return a->length; +} diff --git a/src/accessor/grib_accessor_class_message_copy.h b/src/accessor/grib_accessor_class_message_copy.h new file mode 100644 index 000000000..608817a93 --- /dev/null +++ b/src/accessor/grib_accessor_class_message_copy.h @@ -0,0 +1,33 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_message_copy_t : public grib_accessor_gen_t +{ +public: + /* Members defined in message_copy */ +}; + +class grib_accessor_class_message_copy_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_message_copy_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_message_copy_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + size_t string_length(grib_accessor*) override; + long byte_count(grib_accessor*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_multdouble.cc b/src/accessor/grib_accessor_class_multdouble.cc new file mode 100644 index 000000000..cbe5b42da --- /dev/null +++ b/src/accessor/grib_accessor_class_multdouble.cc @@ -0,0 +1,40 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_multdouble.h" + +grib_accessor_class_multdouble_t _grib_accessor_class_multdouble{"multdouble"}; +grib_accessor_class* grib_accessor_class_multdouble = &_grib_accessor_class_multdouble; + + +void grib_accessor_class_multdouble_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_double_t::init(a, l, c); + grib_accessor_multdouble_t* self = (grib_accessor_multdouble_t*)a; + int n = 0; + + self->val = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->multiplier = grib_arguments_get_double(grib_handle_of_accessor(a), c, n++); +} + +int grib_accessor_class_multdouble_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + const grib_accessor_multdouble_t* self = (grib_accessor_multdouble_t*)a; + int ret = GRIB_SUCCESS; + double value = 0; + + ret = grib_get_double_internal(grib_handle_of_accessor(a), self->val, &value); + if (ret != GRIB_SUCCESS) + return ret; + + *val = value * self->multiplier; + + *len = 1; + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_multdouble.h b/src/accessor/grib_accessor_class_multdouble.h new file mode 100644 index 000000000..025daf903 --- /dev/null +++ b/src/accessor/grib_accessor_class_multdouble.h @@ -0,0 +1,31 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_double.h" + +class grib_accessor_multdouble_t : public grib_accessor_double_t +{ +public: + /* Members defined in multdouble */ + const char* val; + double multiplier; +}; + +class grib_accessor_class_multdouble_t : public grib_accessor_class_double_t +{ +public: + grib_accessor_class_multdouble_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_multdouble_t{}; } + int unpack_double(grib_accessor*, double* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_nearest.cc b/src/accessor/grib_accessor_class_nearest.cc new file mode 100644 index 000000000..6dbac1722 --- /dev/null +++ b/src/accessor/grib_accessor_class_nearest.cc @@ -0,0 +1,49 @@ +/* + * (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. + */ + +#include "grib_accessor_class_nearest.h" + +grib_accessor_class_nearest_t _grib_accessor_class_nearest{"nearest"}; +grib_accessor_class* grib_accessor_class_nearest = &_grib_accessor_class_nearest; + + +void grib_accessor_class_nearest_t::init(grib_accessor* a, const long l, grib_arguments* args) +{ + grib_accessor_class_gen_t::init(a, l, args); + grib_accessor_nearest_t* self = (grib_accessor_nearest_t*)a; + self->args = args; +} + +void grib_accessor_class_nearest_t::dump(grib_accessor* a, grib_dumper* dumper) +{ + /* 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_t* na = NULL; + grib_nearest* n = NULL; + *error = GRIB_NOT_IMPLEMENTED; + a = grib_find_accessor(h, "NEAREST"); + na = (grib_accessor_nearest_t*)a; + + if (!a) + return NULL; + + n = grib_nearest_factory(h, na->args, error); + + if (n) + *error = GRIB_SUCCESS; + + return n; +} diff --git a/src/accessor/grib_accessor_class_nearest.h b/src/accessor/grib_accessor_class_nearest.h new file mode 100644 index 000000000..3ac4fdae2 --- /dev/null +++ b/src/accessor/grib_accessor_class_nearest.h @@ -0,0 +1,31 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_nearest_t : public grib_accessor_gen_t +{ +public: + grib_arguments* args; +}; + + +class grib_accessor_class_nearest_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_nearest_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_nearest_t{}; } + void init(grib_accessor* a, const long l, grib_arguments* args) override; + void dump(grib_accessor* a, grib_dumper* dumper) override; +}; + +//grib_nearest* grib_nearest_new(const grib_handle* ch, int* error); diff --git a/src/accessor/grib_accessor_class_non_alpha.cc b/src/accessor/grib_accessor_class_non_alpha.cc new file mode 100644 index 000000000..68aaffdd7 --- /dev/null +++ b/src/accessor/grib_accessor_class_non_alpha.cc @@ -0,0 +1,112 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_non_alpha.h" + +grib_accessor_class_non_alpha_t _grib_accessor_class_non_alpha{"non_alpha"}; +grib_accessor_class* grib_accessor_class_non_alpha = &_grib_accessor_class_non_alpha; + + +void grib_accessor_class_non_alpha_t::init(grib_accessor* a, const long len, grib_arguments* arg){ + grib_accessor_class_gen_t::init(a, len, arg); + grib_buffer* buffer = grib_handle_of_accessor(a)->buffer; + size_t i = 0; + unsigned char* v; + + v = buffer->data + a->offset; + i = 0; + while ((*v < 33 || *v > 126) && i <= buffer->ulength) { + v++; + i++; + } + a->length = i; + + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; +} + +int grib_accessor_class_non_alpha_t::value_count(grib_accessor* a, long* count){ + *count = 1; + return 0; +} + +size_t grib_accessor_class_non_alpha_t::string_length(grib_accessor* a){ + return a->length; +} + +void grib_accessor_class_non_alpha_t::dump(grib_accessor* a, grib_dumper* dumper){ + grib_dump_string(dumper, a, NULL); +} + +int grib_accessor_class_non_alpha_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_STRING; +} + +int grib_accessor_class_non_alpha_t::unpack_string(grib_accessor* a, char* val, size_t* len){ + grib_handle* hand = grib_handle_of_accessor(a); + long i = 0; + + if (*len < (a->length + 1)) { + grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%lu) for %s, it contains %ld values", + *len, a->name, a->length + 1); + *len = a->length + 1; + return GRIB_BUFFER_TOO_SMALL; + } + + for (i = 0; i < a->length; i++) { + val[i] = hand->buffer->data[a->offset + i]; + } + val[i] = 0; + *len = i; + return GRIB_SUCCESS; +} + +int grib_accessor_class_non_alpha_t::unpack_long(grib_accessor* a, long* v, size_t* len){ + char val[1024] = {0,}; + size_t l = sizeof(val); + size_t i = 0; + char* last = NULL; + int err = a->unpack_string(val, &l); + if (err) + return err; + + i = 0; + while (i < l - 1 && val[i] == ' ') + i++; + + if (val[i] == 0) { + *v = 0; + return 0; + } + if (val[i + 1] == ' ' && i < l - 2) + val[i + 1] = 0; + + *v = strtol(val, &last, 10); + + return GRIB_SUCCESS; +} + +int grib_accessor_class_non_alpha_t::unpack_double(grib_accessor* a, double* v, size_t* len){ + char val[1024]; + size_t l = sizeof(val); + char* last = NULL; + a->unpack_string(val, &l); + *v = strtod(val, &last); + + if (*last == 0) { + return GRIB_SUCCESS; + } + + return GRIB_NOT_IMPLEMENTED; +} + +long grib_accessor_class_non_alpha_t::next_offset(grib_accessor* a){ + return a->offset + a->length; +} diff --git a/src/accessor/grib_accessor_class_non_alpha.h b/src/accessor/grib_accessor_class_non_alpha.h new file mode 100644 index 000000000..83b1ca9ba --- /dev/null +++ b/src/accessor/grib_accessor_class_non_alpha.h @@ -0,0 +1,36 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_non_alpha_t : public grib_accessor_gen_t +{ +public: + /* Members defined in non_alpha */ +}; + +class grib_accessor_class_non_alpha_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_non_alpha_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_non_alpha_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + size_t string_length(grib_accessor*) override; + long next_offset(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_number_of_coded_values.cc b/src/accessor/grib_accessor_class_number_of_coded_values.cc new file mode 100644 index 000000000..f1023dd2e --- /dev/null +++ b/src/accessor/grib_accessor_class_number_of_coded_values.cc @@ -0,0 +1,66 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_number_of_coded_values.h" + +grib_accessor_class_number_of_coded_values_t _grib_accessor_class_number_of_coded_values{"number_of_coded_values"}; +grib_accessor_class* grib_accessor_class_number_of_coded_values = &_grib_accessor_class_number_of_coded_values; + + +void grib_accessor_class_number_of_coded_values_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_long_t::init(a, l, c); + int n = 0; + grib_accessor_number_of_coded_values_t* self = (grib_accessor_number_of_coded_values_t*)a; + self->bitsPerValue = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->offsetBeforeData = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->offsetAfterData = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->unusedBits = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->numberOfValues = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; + a->length = 0; +} + +int grib_accessor_class_number_of_coded_values_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + int ret = GRIB_SUCCESS; + long bpv = 0; + long offsetBeforeData = 0, offsetAfterData = 0, unusedBits = 0, numberOfValues; + + grib_accessor_number_of_coded_values_t* self = (grib_accessor_number_of_coded_values_t*)a; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bitsPerValue, &bpv)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetBeforeData, &offsetBeforeData)) != GRIB_SUCCESS) + return ret; + + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetAfterData, &offsetAfterData)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->unusedBits, &unusedBits)) != GRIB_SUCCESS) + return ret; + + if (bpv != 0) { + grib_context_log(a->context, GRIB_LOG_DEBUG, "grib_accessor_number_of_coded_values_t: offsetAfterData=%ld offsetBeforeData=%ld unusedBits=%ld bpv=%ld\n", + offsetAfterData, offsetBeforeData, unusedBits, bpv); + DEBUG_ASSERT(offsetAfterData > offsetBeforeData); + *val = ((offsetAfterData - offsetBeforeData) * 8 - unusedBits) / bpv; + } + else { + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfValues, &numberOfValues)) != GRIB_SUCCESS) + return ret; + + *val = numberOfValues; + } + + return ret; +} diff --git a/src/accessor/grib_accessor_class_number_of_coded_values.h b/src/accessor/grib_accessor_class_number_of_coded_values.h new file mode 100644 index 000000000..6578e1dcf --- /dev/null +++ b/src/accessor/grib_accessor_class_number_of_coded_values.h @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_number_of_coded_values_t : public grib_accessor_long_t +{ +public: + /* Members defined in number_of_coded_values */ + const char* numberOfValues; + const char* bitsPerValue; + const char* offsetBeforeData; + const char* offsetAfterData; + const char* unusedBits; +}; + +class grib_accessor_class_number_of_coded_values_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_number_of_coded_values_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_number_of_coded_values_t{}; } + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_number_of_points.cc b/src/accessor/grib_accessor_class_number_of_points.cc new file mode 100644 index 000000000..c1b63f2a2 --- /dev/null +++ b/src/accessor/grib_accessor_class_number_of_points.cc @@ -0,0 +1,80 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_number_of_points.h" + +grib_accessor_class_number_of_points_t _grib_accessor_class_number_of_points{"number_of_points"}; +grib_accessor_class* grib_accessor_class_number_of_points = &_grib_accessor_class_number_of_points; + + +void grib_accessor_class_number_of_points_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_long_t::init(a, l, c); + int n = 0; + grib_handle* hand = grib_handle_of_accessor(a); + + grib_accessor_number_of_points_t* self = (grib_accessor_number_of_points_t*)a; + self->ni = grib_arguments_get_name(hand, c, n++); + self->nj = grib_arguments_get_name(hand, c, n++); + self->plpresent = grib_arguments_get_name(hand, c, n++); + self->pl = grib_arguments_get_name(hand, c, n++); + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; + a->length = 0; +} + +int grib_accessor_class_number_of_points_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_accessor_number_of_points_t* self = (grib_accessor_number_of_points_t*)a; + + int ret = GRIB_SUCCESS; + long ni = 0, nj = 0, plpresent = 0; + size_t plsize = 0; + long* pl = NULL; + int i = 0; + grib_context* c = a->context; + grib_handle* hand = grib_handle_of_accessor(a); + + if ((ret = grib_get_long_internal(hand, self->ni, &ni)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_get_long_internal(hand, self->nj, &nj)) != GRIB_SUCCESS) + return ret; + + if (self->plpresent && + ((ret = grib_get_long_internal(hand, self->plpresent, &plpresent)) != GRIB_SUCCESS)) + return ret; + + if (grib_is_missing(hand, self->nj, &ret) && ret == GRIB_SUCCESS) { + grib_context_log(c, GRIB_LOG_ERROR, "grib_accessor_class_number_of_points: Key %s cannot be 'missing'!", self->nj); + return GRIB_GEOCALCULUS_PROBLEM; + } + + if (nj == 0) { + grib_context_log(c, GRIB_LOG_ERROR, "grib_accessor_class_number_of_points: Key %s cannot be 0!", self->nj); + return GRIB_GEOCALCULUS_PROBLEM; + } + + if (plpresent) { + /*reduced*/ + plsize = nj; + pl = (long*)grib_context_malloc(c, sizeof(long) * plsize); + grib_get_long_array_internal(hand, self->pl, pl, &plsize); + *val = 0; + for (i = 0; i < plsize; i++) + *val += pl[i]; + grib_context_free(c, pl); + } + else { + /*regular*/ + *val = ni * nj; + } + + return ret; +} diff --git a/src/accessor/grib_accessor_class_number_of_points.h b/src/accessor/grib_accessor_class_number_of_points.h new file mode 100644 index 000000000..f55d9bbeb --- /dev/null +++ b/src/accessor/grib_accessor_class_number_of_points.h @@ -0,0 +1,33 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_number_of_points_t : public grib_accessor_long_t +{ +public: + /* Members defined in number_of_points */ + const char* ni; + const char* nj; + const char* plpresent; + const char* pl; +}; + +class grib_accessor_class_number_of_points_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_number_of_points_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_number_of_points_t{}; } + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_number_of_points_gaussian.cc b/src/accessor/grib_accessor_class_number_of_points_gaussian.cc similarity index 64% rename from src/grib_accessor_class_number_of_points_gaussian.cc rename to src/accessor/grib_accessor_class_number_of_points_gaussian.cc index 2114a9c87..39324fbd3 100644 --- a/src/grib_accessor_class_number_of_points_gaussian.cc +++ b/src/accessor/grib_accessor_class_number_of_points_gaussian.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,137 +9,31 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -/************************************** - * Enrico Fucile - ************************************/ - -#include "grib_api_internal.h" - - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long - IMPLEMENTS = init - MEMBERS = const char* ni - MEMBERS = const char* nj - MEMBERS = const char* plpresent - MEMBERS = const char* pl - MEMBERS = const char* order - MEMBERS = const char* lat_first - MEMBERS = const char* lon_first - MEMBERS = const char* lat_last - MEMBERS = const char* lon_last - MEMBERS = const char* support_legacy - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_number_of_points_gaussian -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in number_of_points_gaussian */ - const char* ni; - const char* nj; - const char* plpresent; - const char* pl; - const char* order; - const char* lat_first; - const char* lon_first; - const char* lat_last; - const char* lon_last; - const char* support_legacy; -} grib_accessor_number_of_points_gaussian; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_number_of_points_gaussian = { - &grib_accessor_class_long, /* super */ - "number_of_points_gaussian", /* name */ - sizeof(grib_accessor_number_of_points_gaussian), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_number_of_points_gaussian.h" +grib_accessor_class_number_of_points_gaussian_t _grib_accessor_class_number_of_points_gaussian{ "number_of_points_gaussian" }; grib_accessor_class* grib_accessor_class_number_of_points_gaussian = &_grib_accessor_class_number_of_points_gaussian; -/* END_CLASS_IMP */ #define EFDEBUG 0 -static void init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_class_number_of_points_gaussian_t::init(grib_accessor* a, const long l, grib_arguments* c) { - int n = 0; - grib_handle* h = grib_handle_of_accessor(a); - grib_accessor_number_of_points_gaussian* self = (grib_accessor_number_of_points_gaussian*)a; - self->ni = grib_arguments_get_name(h, c, n++); - self->nj = grib_arguments_get_name(h, c, n++); - self->plpresent = grib_arguments_get_name(h, c, n++); - self->pl = grib_arguments_get_name(h, c, n++); - self->order = grib_arguments_get_name(h, c, n++); - self->lat_first = grib_arguments_get_name(h, c, n++); - self->lon_first = grib_arguments_get_name(h, c, n++); - self->lat_last = grib_arguments_get_name(h, c, n++); - self->lon_last = grib_arguments_get_name(h, c, n++); - self->support_legacy = grib_arguments_get_name(h, c, n++); + grib_accessor_class_long_t::init(a, l, c); + int n = 0; + grib_handle* h = grib_handle_of_accessor(a); + grib_accessor_number_of_points_gaussian_t* self = (grib_accessor_number_of_points_gaussian_t*)a; + + self->ni = grib_arguments_get_name(h, c, n++); + self->nj = grib_arguments_get_name(h, c, n++); + self->plpresent = grib_arguments_get_name(h, c, n++); + self->pl = grib_arguments_get_name(h, c, n++); + self->order = grib_arguments_get_name(h, c, n++); + self->lat_first = grib_arguments_get_name(h, c, n++); + self->lon_first = grib_arguments_get_name(h, c, n++); + self->lat_last = grib_arguments_get_name(h, c, n++); + self->lon_last = grib_arguments_get_name(h, c, n++); + self->support_legacy = grib_arguments_get_name(h, c, n++); a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; a->length = 0; @@ -147,7 +42,6 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) // Old implementation of num_points_reduced_gauss_old // See src/deprecated/grib_accessor_class_number_of_points_gaussian.cc // - static int angleApproximatelyEqual(double A, double B, double angular_precision) { return angular_precision > 0 ? (fabs(A - B) <= angular_precision) : (A == B); @@ -218,15 +112,15 @@ static int get_number_of_data_values(grib_handle* h, size_t* numDataValues) return err; } -static int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t* len); -static int unpack_long_new(grib_accessor* a, long* val, size_t* len); +int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t* len); +int unpack_long_new(grib_accessor* a, long* val, size_t* len); -static int unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_class_number_of_points_gaussian_t::unpack_long(grib_accessor* a, long* val, size_t* len) { - int err = GRIB_SUCCESS; - long support_legacy = 1; - grib_accessor_number_of_points_gaussian* self = (grib_accessor_number_of_points_gaussian*)a; - grib_handle* h = grib_handle_of_accessor(a); + int err = GRIB_SUCCESS; + long support_legacy = 1; + grib_accessor_number_of_points_gaussian_t* self = (grib_accessor_number_of_points_gaussian_t*)a; + grib_handle* h = grib_handle_of_accessor(a); if ((err = grib_get_long_internal(h, self->support_legacy, &support_legacy)) != GRIB_SUCCESS) return err; @@ -238,7 +132,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) } /* New algorithm */ -static int unpack_long_new(grib_accessor* a, long* val, size_t* len) +int unpack_long_new(grib_accessor* a, long* val, size_t* len) { int err = GRIB_SUCCESS; int is_global = 0; @@ -253,8 +147,8 @@ static int unpack_long_new(grib_accessor* a, long* val, size_t* len) long angleSubdivisions = 0; grib_handle* h = grib_handle_of_accessor(a); - grib_accessor_number_of_points_gaussian* self = (grib_accessor_number_of_points_gaussian*)a; - grib_context* c = a->context; + grib_accessor_number_of_points_gaussian_t* self = (grib_accessor_number_of_points_gaussian_t*)a; + grib_context* c = a->context; if ((err = grib_get_long_internal(h, self->ni, &ni)) != GRIB_SUCCESS) return err; @@ -274,8 +168,8 @@ static int unpack_long_new(grib_accessor* a, long* val, size_t* len) } if (plpresent) { - long max_pl = 0; - int j = 0; + long max_pl = 0; + int j = 0; // double lon_first_row = 0, lon_last_row = 0; /*reduced*/ @@ -324,8 +218,8 @@ static int unpack_long_new(grib_accessor* a, long* val, size_t* len) return GRIB_GEOCALCULUS_PROBLEM; } grib_get_reduced_row_wrapper(h, pl[j], lon_first, lon_last, &row_count, &ilon_first, &ilon_last); - //lon_first_row = ((ilon_first)*360.0) / pl[j]; - //lon_last_row = ((ilon_last)*360.0) / pl[j]; + // lon_first_row = ((ilon_first)*360.0) / pl[j]; + // lon_last_row = ((ilon_last)*360.0) / pl[j]; *val += row_count; } } @@ -347,7 +241,7 @@ static int unpack_long_new(grib_accessor* a, long* val, size_t* len) } /* With Legacy support */ -static int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t* len) +int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t* len) { int err = GRIB_SUCCESS; int is_global = 0; @@ -363,8 +257,8 @@ static int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t* grib_handle* h = grib_handle_of_accessor(a); size_t numDataValues = 0; - grib_accessor_number_of_points_gaussian* self = (grib_accessor_number_of_points_gaussian*)a; - grib_context* c = a->context; + grib_accessor_number_of_points_gaussian_t* self = (grib_accessor_number_of_points_gaussian_t*)a; + grib_context* c = a->context; if ((err = grib_get_long_internal(h, self->ni, &ni)) != GRIB_SUCCESS) return err; @@ -385,7 +279,7 @@ static int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t* if (plpresent) { long max_pl = 0; - int j = 0; + int j = 0; // double lon_first_row = 0, lon_last_row = 0; /*reduced*/ @@ -447,9 +341,9 @@ static int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t* } grib_get_reduced_row_wrapper(h, pl[j], lon_first, lon_last, &row_count, &ilon_first, &ilon_last); -// if ( row_count != pl[j] ) { -// printf("oops...... rc=%ld but pl[%d]=%ld\n", row_count, j,pl[j]); -// } + // if ( row_count != pl[j] ) { + // printf("oops...... rc=%ld but pl[%d]=%ld\n", row_count, j,pl[j]); + // } // lon_first_row = ((ilon_first)*360.0) / pl[j]; // lon_last_row = ((ilon_last)*360.0) / pl[j]; *val += row_count; diff --git a/src/accessor/grib_accessor_class_number_of_points_gaussian.h b/src/accessor/grib_accessor_class_number_of_points_gaussian.h new file mode 100644 index 000000000..d00fb5b6e --- /dev/null +++ b/src/accessor/grib_accessor_class_number_of_points_gaussian.h @@ -0,0 +1,39 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_number_of_points_gaussian_t : public grib_accessor_long_t +{ +public: + /* Members defined in number_of_points_gaussian */ + const char* ni; + const char* nj; + const char* plpresent; + const char* pl; + const char* order; + const char* lat_first; + const char* lon_first; + const char* lat_last; + const char* lon_last; + const char* support_legacy; +}; + +class grib_accessor_class_number_of_points_gaussian_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_number_of_points_gaussian_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_number_of_points_gaussian_t{}; } + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_number_of_values.cc b/src/accessor/grib_accessor_class_number_of_values.cc new file mode 100644 index 000000000..414cf5e05 --- /dev/null +++ b/src/accessor/grib_accessor_class_number_of_values.cc @@ -0,0 +1,67 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_number_of_values.h" + +grib_accessor_class_number_of_values_t _grib_accessor_class_number_of_values{"number_of_values"}; +grib_accessor_class* grib_accessor_class_number_of_values = &_grib_accessor_class_number_of_values; + + +void grib_accessor_class_number_of_values_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_long_t::init(a, l, c); + int n = 0; + grib_accessor_number_of_values_t* self = (grib_accessor_number_of_values_t*)a; + grib_handle* hand = grib_handle_of_accessor(a); + + self->values = grib_arguments_get_name(hand, c, n++); + self->bitsPerValue = grib_arguments_get_name(hand, c, n++); + self->numberOfPoints = grib_arguments_get_name(hand, c, n++); + self->bitmapPresent = grib_arguments_get_name(hand, c, n++); + self->bitmap = grib_arguments_get_name(hand, c, n++); + self->numberOfCodedValues = grib_arguments_get_name(hand, c, n++); + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + + a->length = 0; +} + +int grib_accessor_class_number_of_values_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_accessor_number_of_values_t* self = (grib_accessor_number_of_values_t*)a; + int ret = GRIB_SUCCESS, i; + long npoints = 0, bitmap_present = 0; + size_t size = 0; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints, &npoints)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bitmapPresent, &bitmap_present)) != GRIB_SUCCESS) + return ret; + + if (bitmap_present) { + double* bitmap; + size = npoints; + bitmap = (double*)grib_context_malloc(a->context, sizeof(double) * size); + if ((ret = grib_get_double_array_internal(grib_handle_of_accessor(a), self->bitmap, bitmap, &size)) != GRIB_SUCCESS) { + grib_context_free(a->context, bitmap); + return ret; + } + *val = 0; + for (i = 0; i < size; i++) + if (bitmap[i] != 0) + (*val)++; + + grib_context_free(a->context, bitmap); + } + else { + *val = npoints; + } + + return ret; +} diff --git a/src/accessor/grib_accessor_class_number_of_values.h b/src/accessor/grib_accessor_class_number_of_values.h new file mode 100644 index 000000000..895669f34 --- /dev/null +++ b/src/accessor/grib_accessor_class_number_of_values.h @@ -0,0 +1,35 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_number_of_values_t : public grib_accessor_long_t +{ +public: + /* Members defined in number_of_values */ + const char* values; + const char* bitsPerValue; + const char* numberOfPoints; + const char* bitmapPresent; + const char* bitmap; + const char* numberOfCodedValues; +}; + +class grib_accessor_class_number_of_values_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_number_of_values_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_number_of_values_t{}; } + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_number_of_values_data_raw_packing.cc b/src/accessor/grib_accessor_class_number_of_values_data_raw_packing.cc new file mode 100644 index 000000000..b8f1d667b --- /dev/null +++ b/src/accessor/grib_accessor_class_number_of_values_data_raw_packing.cc @@ -0,0 +1,63 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_number_of_values_data_raw_packing.h" + +grib_accessor_class_number_of_values_data_raw_packing_t _grib_accessor_class_number_of_values_data_raw_packing{"number_of_values_data_raw_packing"}; +grib_accessor_class* grib_accessor_class_number_of_values_data_raw_packing = &_grib_accessor_class_number_of_values_data_raw_packing; + + +void grib_accessor_class_number_of_values_data_raw_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){ + grib_accessor_class_gen_t::init(a, v, args); + int n = 0; + grib_accessor_number_of_values_data_raw_packing_t* self = (grib_accessor_number_of_values_data_raw_packing_t*)a; + + self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + self->precision = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->length = 0; +} + +int grib_accessor_class_number_of_values_data_raw_packing_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + int err = 0; + grib_accessor_number_of_values_data_raw_packing_t* self = (grib_accessor_number_of_values_data_raw_packing_t*)a; + grib_accessor* adata = NULL; + long precision = 0; + int bytes = 0; + long byte_count = 0; + + adata = grib_find_accessor(grib_handle_of_accessor(a), self->values); + Assert(adata != NULL); + byte_count = adata->byte_count(); + if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->precision, &precision)) != GRIB_SUCCESS) + return err; + + switch (precision) { + case 1: + bytes = 4; + break; + + case 2: + bytes = 8; + break; + + default: + return GRIB_NOT_IMPLEMENTED; + } + + *val = byte_count / bytes; + + return err; +} + +int grib_accessor_class_number_of_values_data_raw_packing_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_LONG; +} diff --git a/src/accessor/grib_accessor_class_number_of_values_data_raw_packing.h b/src/accessor/grib_accessor_class_number_of_values_data_raw_packing.h new file mode 100644 index 000000000..798f428f5 --- /dev/null +++ b/src/accessor/grib_accessor_class_number_of_values_data_raw_packing.h @@ -0,0 +1,32 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_number_of_values_data_raw_packing_t : public grib_accessor_gen_t +{ +public: + /* Members defined in number_of_values_data_raw_packing */ + const char* values; + const char* precision; +}; + +class grib_accessor_class_number_of_values_data_raw_packing_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_number_of_values_data_raw_packing_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_number_of_values_data_raw_packing_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_octahedral_gaussian.cc b/src/accessor/grib_accessor_class_octahedral_gaussian.cc new file mode 100644 index 000000000..8c556e84a --- /dev/null +++ b/src/accessor/grib_accessor_class_octahedral_gaussian.cc @@ -0,0 +1,120 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_octahedral_gaussian.h" + +grib_accessor_class_octahedral_gaussian_t _grib_accessor_class_octahedral_gaussian{"octahedral_gaussian"}; +grib_accessor_class* grib_accessor_class_octahedral_gaussian = &_grib_accessor_class_octahedral_gaussian; + + +void grib_accessor_class_octahedral_gaussian_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_long_t::init(a, l, c); + grib_accessor_octahedral_gaussian_t* self = (grib_accessor_octahedral_gaussian_t*)a; + int n = 0; + grib_handle* hand = grib_handle_of_accessor(a); + + self->N = grib_arguments_get_name(hand, c, n++); + self->Ni = grib_arguments_get_name(hand, c, n++); + self->plpresent = grib_arguments_get_name(hand, c, n++); + self->pl = grib_arguments_get_name(hand, c, n++); +} + +/* Returns 1 (=true) if input pl array is Octahedral, 0 otherwise. + * Possible cases for the deltas in an octahedral pl array: + * +4 .. +4 Top part, above equator + * +4 .. 0 Top part, above and including equator + * +4.. 0 -4.. Middle part, above, equator and below + * 0 -4.. Equator and below + * -4 ..-4 All below equator + * Anything else is considered not octahedral + */ +static int is_pl_octahedral(const long pl[], size_t size){ + long i; + long prev_diff = -1; + for (i = 1; i < size; ++i) { + const long diff = pl[i] - pl[i - 1]; + if (diff == 0) { + /* prev must be +4 or undef */ + if (!(prev_diff == +4 || i == 1)) { + return 0; + } + } + else { + if (labs(diff) != 4) { + return 0; + } + if (diff == +4) { + /* prev must be +4 or undef */ + if (!(prev_diff == +4 || i == 1)) { + return 0; + } + } + if (diff == -4) { + /* prev must be 0, -4 or undef */ + if (!(prev_diff == -4 || prev_diff == 0 || i == 1)) { + return 0; + } + } + } + prev_diff = diff; + } + return 1; /* it's octahedral */ +} + +int grib_accessor_class_octahedral_gaussian_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_accessor_octahedral_gaussian_t* self = (grib_accessor_octahedral_gaussian_t*)a; + int ret = GRIB_SUCCESS; + long Ni; + long plpresent = 0; + long* pl = NULL; /* pl array */ + size_t plsize = 0; + grib_handle* hand = grib_handle_of_accessor(a); + + grib_context* c = a->context; + + if ((ret = grib_get_long_internal(hand, self->Ni, &Ni)) != GRIB_SUCCESS) + return ret; + + /* If Ni is not missing, then this is a plain gaussian grid and not reduced. */ + /* So it cannot be an octahedral grid */ + if (Ni != GRIB_MISSING_LONG) { + *val = 0; + return GRIB_SUCCESS; + } + + if ((ret = grib_get_long_internal(hand, self->plpresent, &plpresent)) != GRIB_SUCCESS) + return ret; + if (!plpresent) { + *val = 0; /* Not octahedral */ + return GRIB_SUCCESS; + } + + if ((ret = grib_get_size(hand, self->pl, &plsize)) != GRIB_SUCCESS) + return ret; + Assert(plsize); /* pl array must have at least one element */ + + pl = (long*)grib_context_malloc_clear(c, sizeof(long) * plsize); + if (!pl) { + return GRIB_OUT_OF_MEMORY; + } + if ((ret = grib_get_long_array_internal(hand, self->pl, pl, &plsize)) != GRIB_SUCCESS) + return ret; + + /* pl[0] is guaranteed to exist. Have already asserted previously */ + *val = is_pl_octahedral(pl, plsize); + grib_context_free(c, pl); + + return ret; +} + +int grib_accessor_class_octahedral_gaussian_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + return GRIB_NOT_IMPLEMENTED; +} diff --git a/src/accessor/grib_accessor_class_octahedral_gaussian.h b/src/accessor/grib_accessor_class_octahedral_gaussian.h new file mode 100644 index 000000000..cc7f52a25 --- /dev/null +++ b/src/accessor/grib_accessor_class_octahedral_gaussian.h @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_octahedral_gaussian_t : public grib_accessor_long_t +{ +public: + /* Members defined in octahedral_gaussian */ + const char* N; + const char* Ni; + const char* plpresent; + const char* pl; +}; + +class grib_accessor_class_octahedral_gaussian_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_octahedral_gaussian_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_octahedral_gaussian_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_octet_number.cc b/src/accessor/grib_accessor_class_octet_number.cc new file mode 100644 index 000000000..4b270f257 --- /dev/null +++ b/src/accessor/grib_accessor_class_octet_number.cc @@ -0,0 +1,47 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_octet_number.h" + +grib_accessor_class_octet_number_t _grib_accessor_class_octet_number{"octet_number"}; +grib_accessor_class* grib_accessor_class_octet_number = &_grib_accessor_class_octet_number; + + +void grib_accessor_class_octet_number_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_long_t::init(a, l, c); + grib_accessor_octet_number_t* self = (grib_accessor_octet_number_t*)a; + + int n = 0; + self->left = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->right = grib_arguments_get_long(grib_handle_of_accessor(a), c, n++); + + a->length = 0; +} + +int grib_accessor_class_octet_number_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_accessor_octet_number_t* self = (grib_accessor_octet_number_t*)a; + int ret = GRIB_SUCCESS; + long offset; + + offset = a->offset + self->right; + + if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->left, offset)) != GRIB_SUCCESS) + return ret; + + *val = offset; + *len = 1; + + return ret; +} + +int grib_accessor_class_octet_number_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_octet_number.h b/src/accessor/grib_accessor_class_octet_number.h new file mode 100644 index 000000000..691dcb564 --- /dev/null +++ b/src/accessor/grib_accessor_class_octet_number.h @@ -0,0 +1,32 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_octet_number_t : public grib_accessor_long_t +{ +public: + /* Members defined in octet_number */ + const char* left; + long right; +}; + +class grib_accessor_class_octet_number_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_octet_number_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_octet_number_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_offset_file.cc b/src/accessor/grib_accessor_class_offset_file.cc new file mode 100644 index 000000000..b52e8eb41 --- /dev/null +++ b/src/accessor/grib_accessor_class_offset_file.cc @@ -0,0 +1,55 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_offset_file.h" + +grib_accessor_class_offset_file_t _grib_accessor_class_offset_file{"offset_file"}; +grib_accessor_class* grib_accessor_class_offset_file = &_grib_accessor_class_offset_file; + + +void grib_accessor_class_offset_file_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_double_t::init(a, l, c); + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->length = 0; +} + +int grib_accessor_class_offset_file_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + *val = (double)grib_handle_of_accessor(a)->offset; + *len = 1; + return GRIB_SUCCESS; +} + +int grib_accessor_class_offset_file_t::unpack_string(grib_accessor* a, char* v, size_t* len){ + double val = 0; + size_t l = 1; + char repres[1024] = {0,}; + int err = 0; + const char* cclass_name = a->cclass->name; + + err = a->unpack_double(&val, &l); if (err) return err; + + snprintf(repres, sizeof(repres), "%.0f", val); + + l = strlen(repres) + 1; + if (l > *len) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", + cclass_name, a->name, l, *len); + *len = l; + return GRIB_BUFFER_TOO_SMALL; + } + grib_context_log(a->context, GRIB_LOG_DEBUG, "%s: Casting double %s to string", __func__, a->name); + + *len = l; + + strcpy(v, repres); + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_offset_file.h b/src/accessor/grib_accessor_class_offset_file.h new file mode 100644 index 000000000..6cb25b864 --- /dev/null +++ b/src/accessor/grib_accessor_class_offset_file.h @@ -0,0 +1,30 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_double.h" + +class grib_accessor_offset_file_t : public grib_accessor_double_t +{ +public: + /* Members defined in offset_file */ +}; + +class grib_accessor_class_offset_file_t : public grib_accessor_class_double_t +{ +public: + grib_accessor_class_offset_file_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_offset_file_t{}; } + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_offset_values.cc b/src/accessor/grib_accessor_class_offset_values.cc new file mode 100644 index 000000000..26f78b5c3 --- /dev/null +++ b/src/accessor/grib_accessor_class_offset_values.cc @@ -0,0 +1,83 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_offset_values.h" + +grib_accessor_class_offset_values_t _grib_accessor_class_offset_values{"offset_values"}; +grib_accessor_class* grib_accessor_class_offset_values = &_grib_accessor_class_offset_values; + + +void grib_accessor_class_offset_values_t::init(grib_accessor* a, const long l, grib_arguments* args){ + grib_accessor_class_double_t::init(a, l, args); + int n = 0; + grib_accessor_offset_values_t* self = (grib_accessor_offset_values_t*)a; + self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + self->missingValue = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; + a->length = 0; +} + +int grib_accessor_class_offset_values_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + int ret = 0; + *val = 0; + *len = 1; + return ret; +} + +int grib_accessor_class_offset_values_t::pack_double(grib_accessor* a, const double* val, size_t* len){ + double* values = NULL; + size_t size = 0; + double missingValue = 0; + long missingValuesPresent = 0; + int ret = 0, i = 0; + grib_accessor_offset_values_t* self = (grib_accessor_offset_values_t*)a; + grib_context* c = a->context; + grib_handle* h = grib_handle_of_accessor(a); + + if (*val == 0) + return GRIB_SUCCESS; + + if ((ret = grib_get_double_internal(h, self->missingValue, &missingValue)) != GRIB_SUCCESS) { + return ret; + } + if ((ret = grib_get_long_internal(h, "missingValuesPresent", &missingValuesPresent)) != GRIB_SUCCESS) { + return ret; + } + + if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) + return ret; + + values = (double*)grib_context_malloc(c, size * sizeof(double)); + if (!values) + return GRIB_OUT_OF_MEMORY; + + if ((ret = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) { + grib_context_free(c, values); + return ret; + } + + for (i = 0; i < size; i++) { + if (missingValuesPresent) { + if (values[i] != missingValue) + values[i] += *val; + } + else { + values[i] += *val; + } + } + + if ((ret = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) + return ret; + + grib_context_free(c, values); + + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_offset_values.h b/src/accessor/grib_accessor_class_offset_values.h new file mode 100644 index 000000000..702e48da7 --- /dev/null +++ b/src/accessor/grib_accessor_class_offset_values.h @@ -0,0 +1,32 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_double.h" + +class grib_accessor_offset_values_t : public grib_accessor_double_t +{ +public: + /* Members defined in offset_values */ + const char* values; + const char* missingValue; +}; + +class grib_accessor_class_offset_values_t : public grib_accessor_class_double_t +{ +public: + grib_accessor_class_offset_values_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_offset_values_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_optimal_step_units.cc b/src/accessor/grib_accessor_class_optimal_step_units.cc similarity index 59% rename from src/grib_accessor_class_optimal_step_units.cc rename to src/accessor/grib_accessor_class_optimal_step_units.cc index d06592e31..adc89e743 100644 --- a/src/grib_accessor_class_optimal_step_units.cc +++ b/src/accessor/grib_accessor_class_optimal_step_units.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,119 +9,17 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" +#include "grib_accessor_class_optimal_step_units.h" #include "step.h" #include "step_utilities.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = pack_long;unpack_long;dump - IMPLEMENTS = pack_string;unpack_string;dump - IMPLEMENTS = string_length;pack_expression;get_native_type;is_missing - IMPLEMENTS = init - MEMBERS = const char* forecast_time_value - MEMBERS = const char* forecast_time_unit - MEMBERS = const char* time_range_value - MEMBERS = const char* time_range_unit - MEMBERS = long overwriteStepUnits - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int is_missing(grib_accessor*); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int pack_string(grib_accessor*, const char*, size_t* len); -static int pack_expression(grib_accessor*, grib_expression*); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static size_t string_length(grib_accessor*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_optimal_step_units -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in optimal_step_units */ - const char* forecast_time_value; - const char* forecast_time_unit; - const char* time_range_value; - const char* time_range_unit; - long overwriteStepUnits; -} grib_accessor_optimal_step_units; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_optimal_step_units = { - &grib_accessor_class_gen, /* super */ - "optimal_step_units", /* name */ - sizeof(grib_accessor_optimal_step_units), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - &string_length, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - &is_missing, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - &pack_string, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - &pack_expression, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +grib_accessor_class_optimal_step_units_t _grib_accessor_class_optimal_step_units{"optimal_step_units"}; grib_accessor_class* grib_accessor_class_optimal_step_units = &_grib_accessor_class_optimal_step_units; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_optimal_step_units* self = (grib_accessor_optimal_step_units*)a; +void grib_accessor_class_optimal_step_units_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_gen_t::init(a, l, c); + grib_accessor_optimal_step_units_t* self = (grib_accessor_optimal_step_units_t*)a; grib_handle* hand = grib_handle_of_accessor(a); int n = 0; @@ -132,18 +31,15 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) self->overwriteStepUnits = eccodes::Unit{eccodes::Unit::Value::MISSING}.value(); } -static void dump(grib_accessor* a, grib_dumper* dumper) -{ +void grib_accessor_class_optimal_step_units_t::dump(grib_accessor* a, grib_dumper* dumper){ grib_dump_string(dumper, a, NULL); } -static size_t string_length(grib_accessor* a) -{ +size_t grib_accessor_class_optimal_step_units_t::string_length(grib_accessor* a){ return 255; } -static int pack_expression(grib_accessor* a, grib_expression* e) -{ +int grib_accessor_class_optimal_step_units_t::pack_expression(grib_accessor* a, grib_expression* e){ const char* cval = NULL; int ret = 0; long lval = 0; @@ -153,8 +49,7 @@ static int pack_expression(grib_accessor* a, grib_expression* e) if (strcmp(e->cclass->name, "long") == 0) { grib_expression_evaluate_long(hand, e, &lval); /* TODO: check return value */ - ret = grib_pack_long(a, &lval, &len); - } + ret = a->pack_long(&lval, &len); } else { char tmp[1024]; len = sizeof(tmp); @@ -168,15 +63,13 @@ static int pack_expression(grib_accessor* a, grib_expression* e) len = strlen(cval) + 1; //if (hand->context->debug) // printf("ECCODES DEBUG grib_accessor_class_codetable::pack_expression %s %s\n", a->name, cval); - ret = grib_pack_string(a, cval, &len); - } + ret = a->pack_string(cval, &len); } return ret; } -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ +int grib_accessor_class_optimal_step_units_t::pack_long(grib_accessor* a, const long* val, size_t* len){ grib_handle* h = grib_handle_of_accessor(a); - grib_accessor_optimal_step_units* self = (grib_accessor_optimal_step_units*)a; + grib_accessor_optimal_step_units_t* self = (grib_accessor_optimal_step_units_t*)a; long start_step = 0; long start_step_unit = 0; @@ -245,18 +138,17 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) return GRIB_SUCCESS; } -static int unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_class_optimal_step_units_t::unpack_long(grib_accessor* a, long* val, size_t* len) { - grib_accessor_optimal_step_units* self = (grib_accessor_optimal_step_units*)a; + const grib_accessor_optimal_step_units_t* self = (grib_accessor_optimal_step_units_t*)a; + grib_handle* h = grib_handle_of_accessor(a); + try { if (eccodes::Unit{self->overwriteStepUnits} != eccodes::Unit{eccodes::Unit::Value::MISSING}) { *val = self->overwriteStepUnits; return GRIB_SUCCESS; } - const grib_accessor_optimal_step_units* self = (grib_accessor_optimal_step_units*)a; - grib_handle* h = grib_handle_of_accessor(a); - auto forecast_time_opt = get_step(h, self->forecast_time_value, self->forecast_time_unit); auto time_range_opt = get_step(h, self->time_range_value, self->time_range_unit); @@ -283,8 +175,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) return GRIB_SUCCESS; } -static int pack_string(grib_accessor* a, const char* val, size_t* len) -{ +int grib_accessor_class_optimal_step_units_t::pack_string(grib_accessor* a, const char* val, size_t* len){ try { long unit = eccodes::Unit{val}.value(); pack_long(a, &unit, len); @@ -304,8 +195,7 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len) return GRIB_SUCCESS; } -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ +int grib_accessor_class_optimal_step_units_t::unpack_string(grib_accessor* a, char* val, size_t* len){ int ret = 0; long unit = 0; size_t unit_len = 0; @@ -317,12 +207,10 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len) // Step units are never missing // If the user does not specify a step unit, we default to hours -static int is_missing(grib_accessor* a) -{ +int grib_accessor_class_optimal_step_units_t::is_missing(grib_accessor* a){ return 0; } -static int get_native_type(grib_accessor* a) -{ +int grib_accessor_class_optimal_step_units_t::get_native_type(grib_accessor* a){ return GRIB_TYPE_LONG; } diff --git a/src/accessor/grib_accessor_class_optimal_step_units.h b/src/accessor/grib_accessor_class_optimal_step_units.h new file mode 100644 index 000000000..e7aa35247 --- /dev/null +++ b/src/accessor/grib_accessor_class_optimal_step_units.h @@ -0,0 +1,42 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_optimal_step_units_t : public grib_accessor_gen_t +{ +public: + /* Members defined in optimal_step_units */ + const char* forecast_time_value; + const char* forecast_time_unit; + const char* time_range_value; + const char* time_range_unit; + long overwriteStepUnits; +}; + +class grib_accessor_class_optimal_step_units_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_optimal_step_units_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_optimal_step_units_t{}; } + int get_native_type(grib_accessor*) override; + int is_missing(grib_accessor*) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int pack_string(grib_accessor*, const char*, size_t* len) override; + int pack_expression(grib_accessor*, grib_expression*) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + size_t string_length(grib_accessor*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_pack_bufr_values.cc b/src/accessor/grib_accessor_class_pack_bufr_values.cc new file mode 100644 index 000000000..08b80d607 --- /dev/null +++ b/src/accessor/grib_accessor_class_pack_bufr_values.cc @@ -0,0 +1,70 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_pack_bufr_values.h" + +grib_accessor_class_pack_bufr_values_t _grib_accessor_class_pack_bufr_values{"pack_bufr_values"}; +grib_accessor_class* grib_accessor_class_pack_bufr_values = &_grib_accessor_class_pack_bufr_values; + + +void grib_accessor_class_pack_bufr_values_t::init(grib_accessor* a, const long len, grib_arguments* params){ + grib_accessor_class_gen_t::init(a, len, params); + char* key; + grib_accessor_pack_bufr_values_t* self = (grib_accessor_pack_bufr_values_t*)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; +} + +void grib_accessor_class_pack_bufr_values_t::dump(grib_accessor* a, grib_dumper* dumper){ +} + +int grib_accessor_class_pack_bufr_values_t::unpack_string_array(grib_accessor* a, char** buffer, size_t* len){ + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_class_pack_bufr_values_t::unpack_string(grib_accessor* a, char* buffer, size_t* len){ + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_class_pack_bufr_values_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_class_pack_bufr_values_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_class_pack_bufr_values_t::value_count(grib_accessor* a, long* count){ + *count = 1; + return 0; +} + +void grib_accessor_class_pack_bufr_values_t::destroy(grib_context* context, grib_accessor* a){ + grib_accessor_class_gen_t::destroy(context, a); +} + +int grib_accessor_class_pack_bufr_values_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_LONG; +} + +int grib_accessor_class_pack_bufr_values_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + grib_accessor_pack_bufr_values_t* self = (grib_accessor_pack_bufr_values_t*)a; + grib_accessor* data = (grib_accessor*)self->data_accessor; + + return data->pack_double(0, 0);} + +int grib_accessor_class_pack_bufr_values_t::pack_double(grib_accessor* a, const double* val, size_t* len){ + grib_accessor_pack_bufr_values_t* self = (grib_accessor_pack_bufr_values_t*)a; + grib_accessor* data = (grib_accessor*)self->data_accessor; + + return data->pack_double(0, 0);} diff --git a/src/accessor/grib_accessor_class_pack_bufr_values.h b/src/accessor/grib_accessor_class_pack_bufr_values.h new file mode 100644 index 000000000..0a59a5141 --- /dev/null +++ b/src/accessor/grib_accessor_class_pack_bufr_values.h @@ -0,0 +1,39 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_pack_bufr_values_t : public grib_accessor_gen_t +{ +public: + /* Members defined in pack_bufr_values */ + grib_accessor* data_accessor; +}; + +class grib_accessor_class_pack_bufr_values_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_pack_bufr_values_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_pack_bufr_values_t{}; } + int get_native_type(grib_accessor*) override; + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + int unpack_string_array(grib_accessor*, char**, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void destroy(grib_context*, grib_accessor*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_packing_type.cc b/src/accessor/grib_accessor_class_packing_type.cc new file mode 100644 index 000000000..5dd862a07 --- /dev/null +++ b/src/accessor/grib_accessor_class_packing_type.cc @@ -0,0 +1,74 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_packing_type.h" + +grib_accessor_class_packing_type_t _grib_accessor_class_packing_type{"packing_type"}; +grib_accessor_class* grib_accessor_class_packing_type = &_grib_accessor_class_packing_type; + + +void grib_accessor_class_packing_type_t::init(grib_accessor* a, const long l, grib_arguments* args){ + grib_accessor_class_gen_t::init(a, l, args); + int n = 0; + grib_accessor_packing_type_t* self = (grib_accessor_packing_type_t*)a; + self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + self->packing_type = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; + a->length = 0; +} + +size_t grib_accessor_class_packing_type_t::string_length(grib_accessor* a){ + return 1024; +} + +int grib_accessor_class_packing_type_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_STRING; +} + +int grib_accessor_class_packing_type_t::pack_string(grib_accessor*a, const char* sval, size_t* len){ + grib_accessor_packing_type_t* self = (grib_accessor_packing_type_t*)a; + grib_handle* h = grib_handle_of_accessor(a); + double* values = NULL; + grib_context* c = a->context; + size_t size = 0; + int err = 0; + + if ((err = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) + return err; + + values = (double*)grib_context_malloc(c, size * sizeof(double)); + if (!values) return GRIB_OUT_OF_MEMORY; + + if ((err = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) { + grib_context_free(c, values); + return err; + } + + if ((err = grib_set_string_internal(h, self->packing_type, sval, len)) != GRIB_SUCCESS) { + grib_context_free(c, values); + return err; + } + + if ((err = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) { + grib_context_free(c, values); + return err; + } + + grib_context_free(c, values); + return GRIB_SUCCESS; +} + +int grib_accessor_class_packing_type_t::unpack_string(grib_accessor* a, char* val, size_t* len){ + grib_accessor_packing_type_t* self = (grib_accessor_packing_type_t*)a; + grib_handle* h = grib_handle_of_accessor(a); + + return grib_get_string(h, self->packing_type, val, len); +} diff --git a/src/accessor/grib_accessor_class_packing_type.h b/src/accessor/grib_accessor_class_packing_type.h new file mode 100644 index 000000000..7deb8f4cf --- /dev/null +++ b/src/accessor/grib_accessor_class_packing_type.h @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_packing_type_t : public grib_accessor_gen_t +{ +public: + /* Members defined in packing_type */ + const char* values; + const char* packing_type; +}; + +class grib_accessor_class_packing_type_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_packing_type_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_packing_type_t{}; } + int get_native_type(grib_accessor*) override; + int pack_string(grib_accessor*, const char*, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + size_t string_length(grib_accessor*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_pad.cc b/src/accessor/grib_accessor_class_pad.cc new file mode 100644 index 000000000..345b510fb --- /dev/null +++ b/src/accessor/grib_accessor_class_pad.cc @@ -0,0 +1,36 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_pad.h" + +grib_accessor_class_pad_t _grib_accessor_class_pad{"pad"}; +grib_accessor_class* grib_accessor_class_pad = &_grib_accessor_class_pad; + + + +size_t grib_accessor_class_pad_t::preferred_size(grib_accessor* a, int from_handle){ + grib_accessor_pad_t* self = (grib_accessor_pad_t*)a; + + long length = 0; + + grib_expression_evaluate_long(grib_handle_of_accessor(a), self->expression, &length); + + return length > 0 ? length : 0; +} + + +void grib_accessor_class_pad_t::init(grib_accessor* a, const long len, grib_arguments* arg){ + grib_accessor_class_padding_t::init(a, len, arg); + grib_accessor_pad_t* self = (grib_accessor_pad_t*)a; + + self->expression = grib_arguments_get_expression(grib_handle_of_accessor(a), arg, 0); + a->length = preferred_size(a, 1); +} diff --git a/src/accessor/grib_accessor_class_pad.h b/src/accessor/grib_accessor_class_pad.h new file mode 100644 index 000000000..5234e73a5 --- /dev/null +++ b/src/accessor/grib_accessor_class_pad.h @@ -0,0 +1,31 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_padding.h" + +class grib_accessor_pad_t : public grib_accessor_padding_t +{ +public: + /* Members defined in padding */ + /* Members defined in pad */ + grib_expression* expression; +}; + +class grib_accessor_class_pad_t : public grib_accessor_class_padding_t +{ +public: + grib_accessor_class_pad_t(const char* name) : grib_accessor_class_padding_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_pad_t{}; } + void init(grib_accessor*, const long, grib_arguments*) override; + size_t preferred_size(grib_accessor*, int) override; +}; diff --git a/src/accessor/grib_accessor_class_padding.cc b/src/accessor/grib_accessor_class_padding.cc new file mode 100644 index 000000000..499c77f2b --- /dev/null +++ b/src/accessor/grib_accessor_class_padding.cc @@ -0,0 +1,58 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_padding.h" + +grib_accessor_class_padding_t _grib_accessor_class_padding{"padding"}; +grib_accessor_class* grib_accessor_class_padding = &_grib_accessor_class_padding; + + +void grib_accessor_class_padding_t::init(grib_accessor* a, const long len, grib_arguments* arg){ + grib_accessor_class_bytes_t::init(a, len, arg); + a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; +} + +int grib_accessor_class_padding_t::compare(grib_accessor* a, grib_accessor* b){ + if (a->length != b->length) + return GRIB_COUNT_MISMATCH; + return GRIB_SUCCESS; +} + +void grib_accessor_class_padding_t::update_size(grib_accessor* a, size_t new_size){ + a->length = new_size; +} + +void grib_accessor_class_padding_t::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, + /*update_lengths=*/1, /*update_paddings=*/0); + grib_context_free(a->context, zero); + + grib_context_log(a->context, GRIB_LOG_DEBUG, + "grib_accessor_class_padding::resize new_size=%zu a->length=%ld %s %s", + new_size, a->length, a->cclass->name, a->name); + Assert(new_size == a->length); +} + +int grib_accessor_class_padding_t::value_count(grib_accessor* a, long* c){ + *c = a->length; + return 0; +} + +long grib_accessor_class_padding_t::byte_count(grib_accessor* a){ + return a->length; +} + +size_t grib_accessor_class_padding_t::string_length(grib_accessor* a){ + return (size_t)a->length; +} diff --git a/src/accessor/grib_accessor_class_padding.h b/src/accessor/grib_accessor_class_padding.h new file mode 100644 index 000000000..6d4175de3 --- /dev/null +++ b/src/accessor/grib_accessor_class_padding.h @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_bytes.h" + +class grib_accessor_padding_t : public grib_accessor_bytes_t +{ +public: + /* Members defined in padding */ +}; + +class grib_accessor_class_padding_t : public grib_accessor_class_bytes_t +{ +public: + grib_accessor_class_padding_t(const char* name) : grib_accessor_class_bytes_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_padding_t{}; } + size_t string_length(grib_accessor*) override; + long byte_count(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + void update_size(grib_accessor*, size_t) override; + void resize(grib_accessor*,size_t) override; + int compare(grib_accessor*, grib_accessor*) override; +}; diff --git a/src/accessor/grib_accessor_class_padto.cc b/src/accessor/grib_accessor_class_padto.cc new file mode 100644 index 000000000..110d8d858 --- /dev/null +++ b/src/accessor/grib_accessor_class_padto.cc @@ -0,0 +1,45 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_padto.h" + +grib_accessor_class_padto_t _grib_accessor_class_padto{"padto"}; +grib_accessor_class* grib_accessor_class_padto = &_grib_accessor_class_padto; + + + +size_t grib_accessor_class_padto_t::preferred_size(grib_accessor* a, int from_handle){ + grib_accessor_padto_t* self = (grib_accessor_padto_t*)a; + + long length = 0; + long theEnd; + + grib_expression_evaluate_long(grib_handle_of_accessor(a), self->expression, &theEnd); + + length = theEnd - a->offset; + + /* printf("preferred_size: prefered: %ld current:%ld %s %s %ld\n", (long)length,(long)a->length,a->cclass->name,a->name,(long)a->offset); */ + + return length > 0 ? length : 0; +} + + +void grib_accessor_class_padto_t::init(grib_accessor* a, const long len, grib_arguments* arg){ + grib_accessor_class_padding_t::init(a, len, arg); + grib_accessor_padto_t* self = (grib_accessor_padto_t*)a; + + self->expression = grib_arguments_get_expression(grib_handle_of_accessor(a), arg, 0); + a->length = preferred_size(a, 1); +} + +void grib_accessor_class_padto_t::dump(grib_accessor* a, grib_dumper* dumper){ + /*grib_dump_string(dumper,a,NULL);*/ +} diff --git a/src/accessor/grib_accessor_class_padto.h b/src/accessor/grib_accessor_class_padto.h new file mode 100644 index 000000000..a1b7b398a --- /dev/null +++ b/src/accessor/grib_accessor_class_padto.h @@ -0,0 +1,31 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_padding.h" + +class grib_accessor_padto_t : public grib_accessor_padding_t +{ +public: + /* Members defined in padto */ + grib_expression* expression; +}; + +class grib_accessor_class_padto_t : public grib_accessor_class_padding_t +{ +public: + grib_accessor_class_padto_t(const char* name) : grib_accessor_class_padding_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_padto_t{}; } + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + size_t preferred_size(grib_accessor*, int) override; +}; diff --git a/src/accessor/grib_accessor_class_padtoeven.cc b/src/accessor/grib_accessor_class_padtoeven.cc new file mode 100644 index 000000000..adf8b0d84 --- /dev/null +++ b/src/accessor/grib_accessor_class_padtoeven.cc @@ -0,0 +1,48 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_padtoeven.h" + +grib_accessor_class_padtoeven_t _grib_accessor_class_padtoeven{"padtoeven"}; +grib_accessor_class* grib_accessor_class_padtoeven = &_grib_accessor_class_padtoeven; + + +size_t grib_accessor_class_padtoeven_t::preferred_size(grib_accessor* a, int from_handle){ + grib_accessor_padtoeven_t* self = (grib_accessor_padtoeven_t*)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); + + if ((length % 2) && from_handle) { + // grib_context_log(a->context, + // GRIB_LOG_ERROR,"GRIB message has an odd length section (%ld, %s)", + // (long)length,a->name); + return 0; + } + + /* printf("EVEN %ld %ld\n",(long) a->offset,(long) offset);*/ + seclen = a->offset - offset; + + return (seclen % 2) ? 1 : 0; +} + +void grib_accessor_class_padtoeven_t::init(grib_accessor* a, const long len, grib_arguments* args){ + grib_accessor_class_padding_t::init(a, len, args); + grib_accessor_padtoeven_t* self = (grib_accessor_padtoeven_t*)a; + + self->section_offset = grib_arguments_get_name(grib_handle_of_accessor(a), args, 0); + self->section_length = grib_arguments_get_name(grib_handle_of_accessor(a), args, 1); + + a->length = preferred_size(a, 1); +} diff --git a/src/accessor/grib_accessor_class_padtoeven.h b/src/accessor/grib_accessor_class_padtoeven.h new file mode 100644 index 000000000..9f42f5880 --- /dev/null +++ b/src/accessor/grib_accessor_class_padtoeven.h @@ -0,0 +1,31 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_padding.h" + +class grib_accessor_padtoeven_t : public grib_accessor_padding_t +{ +public: + /* Members defined in padtoeven */ + const char* section_offset; + const char* section_length; +}; + +class grib_accessor_class_padtoeven_t : public grib_accessor_class_padding_t +{ +public: + grib_accessor_class_padtoeven_t(const char* name) : grib_accessor_class_padding_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_padtoeven_t{}; } + void init(grib_accessor*, const long, grib_arguments*) override; + size_t preferred_size(grib_accessor*, int) override; +}; diff --git a/src/accessor/grib_accessor_class_padtomultiple.cc b/src/accessor/grib_accessor_class_padtomultiple.cc new file mode 100644 index 000000000..d4e463578 --- /dev/null +++ b/src/accessor/grib_accessor_class_padtomultiple.cc @@ -0,0 +1,40 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_padtomultiple.h" + +grib_accessor_class_padtomultiple_t _grib_accessor_class_padtomultiple{"padtomultiple"}; +grib_accessor_class* grib_accessor_class_padtomultiple = &_grib_accessor_class_padtomultiple; + + +size_t grib_accessor_class_padtomultiple_t::preferred_size(grib_accessor* a, int from_handle){ + grib_accessor_padtomultiple_t* self = (grib_accessor_padtomultiple_t*)a; + long padding = 0; + long begin = 0; + long multiple = 0; + + grib_expression_evaluate_long(grib_handle_of_accessor(a), self->begin, &begin); + grib_expression_evaluate_long(grib_handle_of_accessor(a), self->multiple, &multiple); + + padding = a->offset - begin; + padding = ((padding + multiple - 1) / multiple) * multiple - padding; + + return padding == 0 ? multiple : padding; +} + +void grib_accessor_class_padtomultiple_t::init(grib_accessor* a, const long len, grib_arguments* arg){ + grib_accessor_class_padding_t::init(a, len, arg); + grib_accessor_padtomultiple_t* self = (grib_accessor_padtomultiple_t*)a; + + self->begin = grib_arguments_get_expression(grib_handle_of_accessor(a), arg, 0); + self->multiple = grib_arguments_get_expression(grib_handle_of_accessor(a), arg, 1); + a->length = preferred_size(a, 1); +} diff --git a/src/accessor/grib_accessor_class_padtomultiple.h b/src/accessor/grib_accessor_class_padtomultiple.h new file mode 100644 index 000000000..1de8e4059 --- /dev/null +++ b/src/accessor/grib_accessor_class_padtomultiple.h @@ -0,0 +1,31 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_padding.h" + +class grib_accessor_padtomultiple_t : public grib_accessor_padding_t +{ +public: + /* Members defined in padtomultiple */ + grib_expression* begin; + grib_expression* multiple; +}; + +class grib_accessor_class_padtomultiple_t : public grib_accessor_class_padding_t +{ +public: + grib_accessor_class_padtomultiple_t(const char* name) : grib_accessor_class_padding_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_padtomultiple_t{}; } + void init(grib_accessor*, const long, grib_arguments*) override; + size_t preferred_size(grib_accessor*, int) override; +}; diff --git a/src/accessor/grib_accessor_class_position.cc b/src/accessor/grib_accessor_class_position.cc new file mode 100644 index 000000000..a2c3daacd --- /dev/null +++ b/src/accessor/grib_accessor_class_position.cc @@ -0,0 +1,54 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_position.h" + +grib_accessor_class_position_t _grib_accessor_class_position{ "position" }; +grib_accessor_class* grib_accessor_class_position = &_grib_accessor_class_position; + + +void grib_accessor_class_position_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ + grib_accessor_class_gen_t::init(a, len, arg); + a->length = 0; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; + a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; +} + +int grib_accessor_class_position_t::get_native_type(grib_accessor* a) +{ + return GRIB_TYPE_LONG; +} + +void grib_accessor_class_position_t::dump(grib_accessor* a, grib_dumper* dumper) +{ + grib_dump_long(dumper, a, NULL); +} + +int grib_accessor_class_position_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ + if (*len < 1) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %d values ", a->name, 1); + *len = 0; + return GRIB_ARRAY_TOO_SMALL; + } + *val = a->offset; + *len = 1; + return GRIB_SUCCESS; +} + +// static int compare(grib_accessor* a, grib_accessor* b) +// { +// if (a->offset != b->offset) +// return GRIB_OFFSET_MISMATCH; +// return GRIB_SUCCESS; +// } diff --git a/src/accessor/grib_accessor_class_position.h b/src/accessor/grib_accessor_class_position.h new file mode 100644 index 000000000..58e5beb24 --- /dev/null +++ b/src/accessor/grib_accessor_class_position.h @@ -0,0 +1,31 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_position_t : public grib_accessor_gen_t +{ +public: + /* Members defined in position */ +}; + +class grib_accessor_class_position_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_position_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_position_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_proj_string.cc b/src/accessor/grib_accessor_class_proj_string.cc similarity index 65% rename from src/grib_accessor_class_proj_string.cc rename to src/accessor/grib_accessor_class_proj_string.cc index 7edfbf5be..03866753d 100644 --- a/src/grib_accessor_class_proj_string.cc +++ b/src/accessor/grib_accessor_class_proj_string.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,103 +9,17 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = get_native_type;init - IMPLEMENTS = unpack_string - MEMBERS = const char* grid_type - MEMBERS = int endpoint - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_string(grib_accessor*, char*, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_proj_string -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in proj_string */ - const char* grid_type; - int endpoint; -} grib_accessor_proj_string; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_proj_string = { - &grib_accessor_class_gen, /* super */ - "proj_string", /* name */ - sizeof(grib_accessor_proj_string), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_proj_string.h" +grib_accessor_class_proj_string_t _grib_accessor_class_proj_string{ "proj_string" }; grib_accessor_class* grib_accessor_class_proj_string = &_grib_accessor_class_proj_string; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_class_proj_string_t::init(grib_accessor* a, const long len, grib_arguments* arg) { - grib_accessor_proj_string* self = (grib_accessor_proj_string*)a; - grib_handle* h = grib_handle_of_accessor(a); + grib_accessor_class_gen_t::init(a, len, arg); + grib_accessor_proj_string_t* self = (grib_accessor_proj_string_t*)a; + grib_handle* h = grib_handle_of_accessor(a); self->grid_type = grib_arguments_get_name(h, arg, 0); self->endpoint = grib_arguments_get_long(h, arg, 1); @@ -113,7 +28,7 @@ static void init(grib_accessor* a, const long len, grib_arguments* arg) a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; } -static int get_native_type(grib_accessor* a) +int grib_accessor_class_proj_string_t::get_native_type(grib_accessor* a) { return GRIB_TYPE_STRING; } @@ -122,8 +37,8 @@ static int get_native_type(grib_accessor* a) typedef int (*proj_func)(grib_handle*, char*); struct proj_mapping { - const char* gridType; // key gridType - proj_func func; // function to compute proj string + const char* gridType; // key gridType + proj_func func; // function to compute proj string }; typedef struct proj_mapping proj_mapping; @@ -151,9 +66,9 @@ static int get_earth_shape(grib_handle* h, char* result) if ((err = get_major_minor_axes(h, &major, &minor)) != GRIB_SUCCESS) return err; if (major == minor) - snprintf(result, 128, "+R=%lf", major); // spherical + snprintf(result, 128, "+R=%lf", major); // spherical else - snprintf(result, 128, "+a=%lf +b=%lf", major, minor); // oblate + snprintf(result, 128, "+a=%lf +b=%lf", major, minor); // oblate return err; } @@ -189,7 +104,7 @@ static int proj_equatorial_azimuthal_equidistant(grib_handle* h, char* result) static int proj_lambert_conformal(grib_handle* h, char* result) { - int err = 0; + int err = 0; char shape[128] = {0,}; double LoVInDegrees = 0, LaDInDegrees = 0, Latin1InDegrees = 0, Latin2InDegrees = 0; @@ -204,13 +119,13 @@ static int proj_lambert_conformal(grib_handle* h, char* result) if ((err = grib_get_double_internal(h, "LaDInDegrees", &LaDInDegrees)) != GRIB_SUCCESS) return err; snprintf(result, 1024, "+proj=lcc +lon_0=%lf +lat_0=%lf +lat_1=%lf +lat_2=%lf %s", - LoVInDegrees, LaDInDegrees, Latin1InDegrees, Latin2InDegrees, shape); + LoVInDegrees, LaDInDegrees, Latin1InDegrees, Latin2InDegrees, shape); return err; } static int proj_lambert_azimuthal_equal_area(grib_handle* h, char* result) { - int err = 0; + int err = 0; char shape[128] = {0,}; double standardParallel = 0, centralLongitude = 0; @@ -221,7 +136,7 @@ static int proj_lambert_azimuthal_equal_area(grib_handle* h, char* result) if ((err = grib_get_double_internal(h, "centralLongitudeInDegrees", ¢ralLongitude)) != GRIB_SUCCESS) return err; snprintf(result, 1024, "+proj=laea +lon_0=%lf +lat_0=%lf %s", - centralLongitude, standardParallel, shape); + centralLongitude, standardParallel, shape); return err; } @@ -243,7 +158,7 @@ static int proj_polar_stereographic(grib_handle* h, char* result) return err; has_northPole = ((projectionCentreFlag & 128) == 0); snprintf(result, 1024, "+proj=stere +lat_ts=%lf +lat_0=%s +lon_0=%lf +k_0=1 +x_0=0 +y_0=0 %s", - centralLatitude, has_northPole ? "90" : "-90", centralLongitude, shape); + centralLatitude, has_northPole ? "90" : "-90", centralLongitude, shape); return err; } @@ -252,9 +167,9 @@ static int proj_polar_stereographic(grib_handle* h, char* result) static int proj_unprojected(grib_handle* h, char* result) { int err = 0; - //char shape[128] = {0,}; - //if ((err = get_earth_shape(h, shape)) != GRIB_SUCCESS) return err; - //snprintf(result, 1024, "+proj=longlat %s", shape); + // char shape[128] = {0,}; + // if ((err = get_earth_shape(h, shape)) != GRIB_SUCCESS) return err; + // snprintf(result, 1024, "+proj=longlat %s", shape); snprintf(result, 1024, "+proj=longlat +datum=WGS84 +no_defs +type=crs"); return err; @@ -264,14 +179,14 @@ static int proj_mercator(grib_handle* h, char* result) { int err = 0; double LaDInDegrees = 0; - char shape[128] = {0,}; + char shape[128] = {0,}; if ((err = grib_get_double_internal(h, "LaDInDegrees", &LaDInDegrees)) != GRIB_SUCCESS) return err; if ((err = get_earth_shape(h, shape)) != GRIB_SUCCESS) return err; snprintf(result, 1024, "+proj=merc +lat_ts=%lf +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 %s", - LaDInDegrees, shape); + LaDInDegrees, shape); return err; } @@ -293,18 +208,18 @@ static proj_mapping proj_mappings[] = { #define ENDPOINT_SOURCE 0 #define ENDPOINT_TARGET 1 -static int unpack_string(grib_accessor* a, char* v, size_t* len) +int grib_accessor_class_proj_string_t::unpack_string(grib_accessor* a, char* v, size_t* len) { - grib_accessor_proj_string* self = (grib_accessor_proj_string*)a; + grib_accessor_proj_string_t* self = (grib_accessor_proj_string_t*)a; int err = 0, found = 0; - size_t i = 0; + size_t i = 0; char grid_type[64] = {0,}; grib_handle* h = grib_handle_of_accessor(a); - size_t size = sizeof(grid_type) / sizeof(*grid_type); + size_t size = sizeof(grid_type) / sizeof(*grid_type); Assert(self->endpoint == ENDPOINT_SOURCE || self->endpoint == ENDPOINT_TARGET); - size_t l = 100; // Safe bet + size_t l = 100; // Safe bet if (*len < l) { const char* cclass_name = a->cclass->name; grib_context_log(a->context, GRIB_LOG_ERROR, diff --git a/src/accessor/grib_accessor_class_proj_string.h b/src/accessor/grib_accessor_class_proj_string.h new file mode 100644 index 000000000..e214c32a9 --- /dev/null +++ b/src/accessor/grib_accessor_class_proj_string.h @@ -0,0 +1,32 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_proj_string_t : public grib_accessor_gen_t +{ +public: + /* Members defined in proj_string */ + const char* grid_type; + int endpoint; +}; + +class grib_accessor_class_proj_string_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_proj_string_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_proj_string_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_raw.cc b/src/accessor/grib_accessor_class_raw.cc new file mode 100644 index 000000000..cf1f502c7 --- /dev/null +++ b/src/accessor/grib_accessor_class_raw.cc @@ -0,0 +1,126 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_raw.h" + +grib_accessor_class_raw_t _grib_accessor_class_raw{ "raw" }; +grib_accessor_class* grib_accessor_class_raw = &_grib_accessor_class_raw; + + +void grib_accessor_class_raw_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ + grib_accessor_class_gen_t::init(a, len, arg); + int n = 0; + int err = 0; + long sectionLength; + grib_accessor_raw_t* self = (grib_accessor_raw_t*)a; + grib_expression* e; + grib_handle* hand = grib_handle_of_accessor(a); + + a->length = 0; + self->totalLength = grib_arguments_get_name(hand, arg, n++); + self->sectionLength = grib_arguments_get_name(hand, arg, n++); + + e = grib_arguments_get_expression(hand, arg, n++); + err = grib_expression_evaluate_long(hand, e, &(self->relativeOffset)); + if (err) + grib_context_log(hand->context, GRIB_LOG_ERROR, "Unable to evaluate relativeOffset"); + + grib_get_long(hand, self->sectionLength, §ionLength); + + a->length = sectionLength - self->relativeOffset; + if (a->length < 0) + a->length = 0; + + /* Assert(a->length>=0); */ +} + +int grib_accessor_class_raw_t::get_native_type(grib_accessor* a) +{ + return GRIB_TYPE_BYTES; +} + + +int grib_accessor_class_raw_t::compare(grib_accessor* a, grib_accessor* b) +{ + int retval = GRIB_SUCCESS; + + size_t alen = (size_t)a->byte_count(); + size_t blen = (size_t)b->byte_count(); + if (alen != blen) + return GRIB_COUNT_MISMATCH; + + return retval; +} + +long grib_accessor_class_raw_t::byte_count(grib_accessor* a) +{ + return a->length; +} + +int grib_accessor_class_raw_t::value_count(grib_accessor* a, long* len) +{ + *len = a->length; + return 0; +} + +int grib_accessor_class_raw_t::unpack_bytes(grib_accessor* a, unsigned char* buffer, size_t* len) +{ + if (*len < a->length) { + *len = a->length; + return GRIB_ARRAY_TOO_SMALL; + } + *len = a->length; + + memcpy(buffer, grib_handle_of_accessor(a)->buffer->data + a->offset, *len); + + return GRIB_SUCCESS; +} + +void grib_accessor_class_raw_t::update_size(grib_accessor* a, size_t s) +{ + grib_context_log(a->context, GRIB_LOG_DEBUG, "updating size of %s old %ld new %ld", a->name, a->length, s); + a->length = s; + Assert(a->length >= 0); +} + +void accessor_raw_set_length(grib_accessor* a, size_t len) +{ + a->length = len; +} + +long accessor_raw_get_offset(grib_accessor* a) +{ + return a->offset; +} + +int grib_accessor_class_raw_t::pack_bytes(grib_accessor* a, const unsigned char* val, size_t* len) +{ + size_t length = *len; + long totalLength; + long sectionLength; + grib_handle* h = grib_handle_of_accessor(a); + grib_accessor_raw_t* self = (grib_accessor_raw_t*)a; + long dlen = length - a->length; + + grib_get_long(h, self->totalLength, &totalLength); + totalLength += dlen; + grib_get_long(h, self->sectionLength, §ionLength); + sectionLength += dlen; + + grib_buffer_replace(a, val, length, 1, 1); + + grib_set_long(h, self->totalLength, totalLength); + grib_set_long(h, self->sectionLength, sectionLength); + a->length = length; + + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_raw.h b/src/accessor/grib_accessor_class_raw.h new file mode 100644 index 000000000..8a588ac61 --- /dev/null +++ b/src/accessor/grib_accessor_class_raw.h @@ -0,0 +1,38 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_raw_t : public grib_accessor_gen_t +{ +public: + /* Members defined in raw */ + const char* totalLength; + const char* sectionLength; + long relativeOffset; +}; + +class grib_accessor_class_raw_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_raw_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_raw_t{}; } + int get_native_type(grib_accessor*) override; + int pack_bytes(grib_accessor*, const unsigned char*, size_t* len) override; + int unpack_bytes(grib_accessor*, unsigned char*, size_t* len) override; + long byte_count(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + void update_size(grib_accessor*, size_t) override; + int compare(grib_accessor*, grib_accessor*) override; +}; diff --git a/src/accessor/grib_accessor_class_rdbtime_guess_date.cc b/src/accessor/grib_accessor_class_rdbtime_guess_date.cc new file mode 100644 index 000000000..f4b317daa --- /dev/null +++ b/src/accessor/grib_accessor_class_rdbtime_guess_date.cc @@ -0,0 +1,78 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_rdbtime_guess_date.h" + +grib_accessor_class_rdbtime_guess_date_t _grib_accessor_class_rdbtime_guess_date{"rdbtime_guess_date"}; +grib_accessor_class* grib_accessor_class_rdbtime_guess_date = &_grib_accessor_class_rdbtime_guess_date; + + +void grib_accessor_class_rdbtime_guess_date_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ + grib_accessor_class_long_t::init(a, l, c); + grib_accessor_rdbtime_guess_date_t* self = (grib_accessor_rdbtime_guess_date_t*)a; + int n = 0; + + self->typicalYear = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->typicalMonth = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->typicalDay = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->rdbDay = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->yearOrMonth = grib_arguments_get_long(grib_handle_of_accessor(a), c, n++); + + /* a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; */ +} + +int grib_accessor_class_rdbtime_guess_date_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ + grib_accessor_rdbtime_guess_date_t* self = (grib_accessor_rdbtime_guess_date_t*)a; + grib_handle* h = grib_handle_of_accessor(a); + long typicalYear, typicalMonth, typicalDay, rdbDay; + long rdbYear, rdbMonth; + + int ret = grib_get_long(h, self->typicalYear, &typicalYear); + if (ret) + return ret; + ret = grib_get_long(h, self->typicalMonth, &typicalMonth); + if (ret) + return ret; + ret = grib_get_long(h, self->typicalDay, &typicalDay); + if (ret) + return ret; + ret = grib_get_long(h, self->rdbDay, &rdbDay); + if (ret) + return ret; + + if (rdbDay < typicalDay) { + if (typicalDay == 31 && typicalMonth == 12) { + rdbYear = typicalYear + 1; + rdbMonth = 1; + } + else { + rdbYear = typicalYear; + rdbMonth = typicalMonth + 1; + } + } + else { + rdbYear = typicalYear; + rdbMonth = typicalMonth; + } + + *val = self->yearOrMonth == 1 ? rdbYear : rdbMonth; + *len = 1; + + return GRIB_SUCCESS; +} + +int grib_accessor_class_rdbtime_guess_date_t::pack_long(grib_accessor* a, const long* v, size_t* len) +{ + /* do nothing*/ + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_rdbtime_guess_date.h b/src/accessor/grib_accessor_class_rdbtime_guess_date.h new file mode 100644 index 000000000..739c95e8d --- /dev/null +++ b/src/accessor/grib_accessor_class_rdbtime_guess_date.h @@ -0,0 +1,35 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_rdbtime_guess_date_t : public grib_accessor_long_t +{ +public: + /* Members defined in rdbtime_guess_date */ + const char* typicalYear; + const char* typicalMonth; + const char* typicalDay; + const char* rdbDay; + long yearOrMonth; +}; + +class grib_accessor_class_rdbtime_guess_date_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_rdbtime_guess_date_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_rdbtime_guess_date_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_reference_value_error.cc b/src/accessor/grib_accessor_class_reference_value_error.cc new file mode 100644 index 000000000..fbf1a1c1b --- /dev/null +++ b/src/accessor/grib_accessor_class_reference_value_error.cc @@ -0,0 +1,52 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_reference_value_error.h" + +grib_accessor_class_reference_value_error_t _grib_accessor_class_reference_value_error{ "reference_value_error" }; +grib_accessor_class* grib_accessor_class_reference_value_error = &_grib_accessor_class_reference_value_error; + + +void grib_accessor_class_reference_value_error_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ + grib_accessor_class_double_t::init(a, l, c); + grib_accessor_reference_value_error_t* self = (grib_accessor_reference_value_error_t*)a; + int n = 0; + + self->referenceValue = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->floatType = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->length = 0; +} + +int grib_accessor_class_reference_value_error_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ + grib_accessor_reference_value_error_t* self = (grib_accessor_reference_value_error_t*)a; + int ret = GRIB_SUCCESS; + double referenceValue = 0; + + if ((ret = grib_get_double_internal(grib_handle_of_accessor(a), + self->referenceValue, &referenceValue)) != GRIB_SUCCESS) + return ret; + + if (!strcmp(self->floatType, "ibm")) + *val = grib_ibmfloat_error(referenceValue); + else if (!strcmp(self->floatType, "ieee")) + *val = grib_ieeefloat_error(referenceValue); + else + Assert(1 == 0); + + if (ret == GRIB_SUCCESS) + *len = 1; + + return ret; +} diff --git a/src/accessor/grib_accessor_class_reference_value_error.h b/src/accessor/grib_accessor_class_reference_value_error.h new file mode 100644 index 000000000..2a470562e --- /dev/null +++ b/src/accessor/grib_accessor_class_reference_value_error.h @@ -0,0 +1,31 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_double.h" + +class grib_accessor_reference_value_error_t : public grib_accessor_double_t +{ +public: + /* Members defined in reference_value_error */ + const char* referenceValue; + const char* floatType; +}; + +class grib_accessor_class_reference_value_error_t : public grib_accessor_class_double_t +{ +public: + grib_accessor_class_reference_value_error_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_reference_value_error_t{}; } + int unpack_double(grib_accessor*, double* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_round.cc b/src/accessor/grib_accessor_class_round.cc new file mode 100644 index 000000000..e1d6aaeda --- /dev/null +++ b/src/accessor/grib_accessor_class_round.cc @@ -0,0 +1,70 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_round.h" + +grib_accessor_class_round_t _grib_accessor_class_round{ "round" }; +grib_accessor_class* grib_accessor_class_round = &_grib_accessor_class_round; + + +int grib_accessor_class_round_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ + grib_accessor_round_t* self = (grib_accessor_round_t*)a; + + int ret = GRIB_SUCCESS; + + size_t replen = 0; + double rounding_precision = 0; + double rounded = 0; + double toround = 0; + + const char* oval = NULL; + oval = grib_arguments_get_name(grib_handle_of_accessor(a), self->arg, 0); + + if ((ret = grib_get_double_internal(grib_handle_of_accessor(a), oval, &toround)) != 0) + return ret; + + rounding_precision = grib_arguments_get_long(grib_handle_of_accessor(a), self->arg, 1); + + rounded = floor(rounding_precision * toround + 0.5) / rounding_precision; + + *len = replen; + + *val = rounded; + + return ret; +} + +int grib_accessor_class_round_t::unpack_string(grib_accessor* a, char* val, size_t* len) +{ + char result[1024]; + int ret = GRIB_SUCCESS; + size_t replen = 1; + + double value = 0; + + ret = unpack_double(a, &value, &replen); + + snprintf(result, sizeof(result), "%.3f", value); + + replen = strlen(result) + 1; + + if (*len < replen) { + *len = replen; + return GRIB_ARRAY_TOO_SMALL; + } + + *len = replen; + + snprintf(val, 1024, "%s", result); + + return ret; +} diff --git a/src/accessor/grib_accessor_class_round.h b/src/accessor/grib_accessor_class_round.h new file mode 100644 index 000000000..364e24b34 --- /dev/null +++ b/src/accessor/grib_accessor_class_round.h @@ -0,0 +1,29 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_evaluate.h" + +class grib_accessor_round_t : public grib_accessor_evaluate_t +{ +public: + /* Members defined in round */ +}; + +class grib_accessor_class_round_t : public grib_accessor_class_evaluate_t +{ +public: + grib_accessor_class_round_t(const char* name) : grib_accessor_class_evaluate_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_round_t{}; } + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; +}; diff --git a/src/accessor/grib_accessor_class_scale.cc b/src/accessor/grib_accessor_class_scale.cc new file mode 100644 index 000000000..59ab7bfb4 --- /dev/null +++ b/src/accessor/grib_accessor_class_scale.cc @@ -0,0 +1,139 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_scale.h" + +grib_accessor_class_scale_t _grib_accessor_class_scale{ "scale" }; +grib_accessor_class* grib_accessor_class_scale = &_grib_accessor_class_scale; + + +void grib_accessor_class_scale_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ + grib_accessor_class_double_t::init(a, l, c); + grib_accessor_scale_t* self = (grib_accessor_scale_t*)a; + int n = 0; + + self->value = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->multiplier = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->divisor = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->truncating = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); +} + +int grib_accessor_class_scale_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ + grib_accessor_scale_t* self = (grib_accessor_scale_t*)a; + int ret = 0; + long value = 0; + long multiplier = 0; + long divisor = 0; + + if (*len < 1) { + ret = GRIB_ARRAY_TOO_SMALL; + grib_context_log(a->context, GRIB_LOG_ERROR, + "Accessor %s cannot gather value for %s and/or %s", + a->name, self->multiplier, self->divisor); + return ret; + } + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->divisor, &divisor)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->multiplier, &multiplier)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->value, &value)) != GRIB_SUCCESS) + return ret; + + if (value == GRIB_MISSING_LONG) + *val = GRIB_MISSING_DOUBLE; + else + *val = ((double)(value * multiplier)) / divisor; + + if (ret == GRIB_SUCCESS) + *len = 1; + + return ret; +} + +int grib_accessor_class_scale_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ + const double dval = (double)*val; + return pack_double(a, &dval, len); +} + +int grib_accessor_class_scale_t::pack_double(grib_accessor* a, const double* val, size_t* len) +{ + grib_accessor_scale_t* self = (grib_accessor_scale_t*)a; + int ret = 0; + + long value = 0; + long divisor = 0; + long multiplier = 0; + long truncating = 0; + double x; + + ret = grib_get_long_internal(grib_handle_of_accessor(a), self->divisor, &divisor); + if (ret != GRIB_SUCCESS) return ret; + + ret = grib_get_long_internal(grib_handle_of_accessor(a), self->multiplier, &multiplier); + if (ret != GRIB_SUCCESS) return ret; + + if (self->truncating) { + ret = grib_get_long_internal(grib_handle_of_accessor(a), self->truncating, &truncating); + if (ret != GRIB_SUCCESS) return ret; + } + + if (multiplier == 0) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Accessor %s: cannot divide by a zero multiplier %s", + a->name, self->multiplier); + return GRIB_ENCODING_ERROR; + } + + x = *val * (double)divisor / (double)multiplier; + if (*val == GRIB_MISSING_DOUBLE) + value = GRIB_MISSING_LONG; + else if (truncating) { + value = (long)x; + } + else { + value = x > 0 ? (long)(x + 0.5) : (long)(x - 0.5); + } + + ret = grib_set_long_internal(grib_handle_of_accessor(a), self->value, value); + if (ret) + grib_context_log(a->context, GRIB_LOG_ERROR, + "Accessor %s: cannot pack value for %s (%s)\n", + a->name, self->value, grib_get_error_message(ret)); + + if (ret == GRIB_SUCCESS) + *len = 1; + + return ret; +} + +int grib_accessor_class_scale_t::is_missing(grib_accessor* a) +{ + grib_accessor_scale_t* self = (grib_accessor_scale_t*)a; + grib_accessor* av = grib_find_accessor(grib_handle_of_accessor(a), self->value); + + if (!av) + return GRIB_NOT_FOUND; + return av->is_missing_internal(); + // int ret=0; + // long value=0; + // if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->value, &value))!= GRIB_SUCCESS){ + // grib_context_log(a->context, GRIB_LOG_ERROR, + // "Accessor %s cannot gather value for %s error %d \n", a->name, + // self->value, ret); + // return 0; + // } + // return (value == GRIB_MISSING_LONG); +} diff --git a/src/accessor/grib_accessor_class_scale.h b/src/accessor/grib_accessor_class_scale.h new file mode 100644 index 000000000..29b65f34b --- /dev/null +++ b/src/accessor/grib_accessor_class_scale.h @@ -0,0 +1,36 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_double.h" + +class grib_accessor_scale_t : public grib_accessor_double_t +{ +public: + /* Members defined in scale */ + const char* value; + const char* multiplier; + const char* divisor; + const char* truncating; +}; + +class grib_accessor_class_scale_t : public grib_accessor_class_double_t +{ +public: + grib_accessor_class_scale_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_scale_t{}; } + int is_missing(grib_accessor*) override; + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_scale_values.cc b/src/accessor/grib_accessor_class_scale_values.cc new file mode 100644 index 000000000..03072311d --- /dev/null +++ b/src/accessor/grib_accessor_class_scale_values.cc @@ -0,0 +1,88 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_scale_values.h" + +grib_accessor_class_scale_values_t _grib_accessor_class_scale_values{ "scale_values" }; +grib_accessor_class* grib_accessor_class_scale_values = &_grib_accessor_class_scale_values; + + +void grib_accessor_class_scale_values_t::init(grib_accessor* a, const long l, grib_arguments* args) +{ + grib_accessor_class_double_t::init(a, l, args); + int n = 0; + grib_accessor_scale_values_t* self = (grib_accessor_scale_values_t*)a; + self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + self->missingValue = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; + a->length = 0; +} + +int grib_accessor_class_scale_values_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ + int ret = GRIB_SUCCESS; + *val = 1; + *len = 1; + return ret; +} + +int grib_accessor_class_scale_values_t::pack_double(grib_accessor* a, const double* val, size_t* len) +{ + double* values = NULL; + double missingValue = 0; + long missingValuesPresent = 0; + size_t size = 0; + int ret = 0, i = 0; + grib_accessor_scale_values_t* self = (grib_accessor_scale_values_t*)a; + const grib_context* c = a->context; + grib_handle* h = grib_handle_of_accessor(a); + + if (*val == 1) + return GRIB_SUCCESS; + + if ((ret = grib_get_double_internal(h, self->missingValue, &missingValue)) != GRIB_SUCCESS) { + return ret; + } + if ((ret = grib_get_long_internal(h, "missingValuesPresent", &missingValuesPresent)) != GRIB_SUCCESS) { + return ret; + } + + if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) + return ret; + + values = (double*)grib_context_malloc(c, size * sizeof(double)); + if (!values) + return GRIB_OUT_OF_MEMORY; + + if ((ret = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) { + grib_context_free(c, values); + return ret; + } + + for (i = 0; i < size; i++) { + if (missingValuesPresent) { + if (values[i] != missingValue) + values[i] *= *val; + } + else { + values[i] *= *val; + } + } + + if ((ret = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) { + grib_context_free(c, values); + return ret; + } + + grib_context_free(c, values); + + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_scale_values.h b/src/accessor/grib_accessor_class_scale_values.h new file mode 100644 index 000000000..f004db30e --- /dev/null +++ b/src/accessor/grib_accessor_class_scale_values.h @@ -0,0 +1,32 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_double.h" + +class grib_accessor_scale_values_t : public grib_accessor_double_t +{ +public: + /* Members defined in scale_values */ + const char* values; + const char* missingValue; +}; + +class grib_accessor_class_scale_values_t : public grib_accessor_class_double_t +{ +public: + grib_accessor_class_scale_values_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_scale_values_t{}; } + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_second_order_bits_per_value.cc b/src/accessor/grib_accessor_class_second_order_bits_per_value.cc similarity index 50% rename from src/grib_accessor_class_second_order_bits_per_value.cc rename to src/accessor/grib_accessor_class_second_order_bits_per_value.cc index 74c4b4c05..ea7c4c931 100644 --- a/src/grib_accessor_class_second_order_bits_per_value.cc +++ b/src/accessor/grib_accessor_class_second_order_bits_per_value.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,108 +9,12 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -/********************************** - * Enrico Fucile - **********************************/ - +#include "grib_accessor_class_second_order_bits_per_value.h" #include "grib_scaling.h" -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long - IMPLEMENTS = pack_long - IMPLEMENTS = init - MEMBERS = const char* values - MEMBERS = const char* binaryScaleFactor - MEMBERS = const char* decimalScaleFactor - MEMBERS = long bitsPerValue - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_second_order_bits_per_value -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in second_order_bits_per_value */ - const char* values; - const char* binaryScaleFactor; - const char* decimalScaleFactor; - long bitsPerValue; -} grib_accessor_second_order_bits_per_value; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_second_order_bits_per_value = { - &grib_accessor_class_long, /* super */ - "second_order_bits_per_value", /* name */ - sizeof(grib_accessor_second_order_bits_per_value), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +grib_accessor_class_second_order_bits_per_value_t _grib_accessor_class_second_order_bits_per_value{"second_order_bits_per_value"}; grib_accessor_class* grib_accessor_class_second_order_bits_per_value = &_grib_accessor_class_second_order_bits_per_value; -/* END_CLASS_IMP */ static const size_t nbits[64] = { 0x1, 0x2, 0x4, 0x8, @@ -130,8 +35,7 @@ static const size_t nbits[64] = { 0x1000000000000000, 0x2000000000000000, 0x4000000000000000, 0x8000000000000000 }; -static int number_of_bits(size_t x, long* result) -{ +static int number_of_bits(size_t x, long* result){ const size_t* n = nbits; const int count = sizeof(nbits) / sizeof(nbits[0]); *result = 0; @@ -145,10 +49,10 @@ static int number_of_bits(size_t x, long* result) return GRIB_SUCCESS; } -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ +void grib_accessor_class_second_order_bits_per_value_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_long_t::init(a, l, c); int n = 0; - grib_accessor_second_order_bits_per_value* self = (grib_accessor_second_order_bits_per_value*)a; + grib_accessor_second_order_bits_per_value_t* self = (grib_accessor_second_order_bits_per_value_t*)a; self->values = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); self->binaryScaleFactor = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); self->decimalScaleFactor = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); @@ -157,17 +61,15 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) a->length = 0; } -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - grib_accessor_second_order_bits_per_value* self = (grib_accessor_second_order_bits_per_value*)a; +int grib_accessor_class_second_order_bits_per_value_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + grib_accessor_second_order_bits_per_value_t* self = (grib_accessor_second_order_bits_per_value_t*)a; self->bitsPerValue = (long)*val; *len = 1; return 0; } -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ +int grib_accessor_class_second_order_bits_per_value_t::unpack_long(grib_accessor* a, long* val, size_t* len){ int ret = GRIB_SUCCESS; size_t size = 0; size_t i; @@ -175,7 +77,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) double* values = 0; long binaryScaleFactor, decimalScaleFactor; - grib_accessor_second_order_bits_per_value* self = (grib_accessor_second_order_bits_per_value*)a; + grib_accessor_second_order_bits_per_value_t* self = (grib_accessor_second_order_bits_per_value_t*)a; if (self->bitsPerValue) { *val = self->bitsPerValue; return GRIB_SUCCESS; diff --git a/src/accessor/grib_accessor_class_second_order_bits_per_value.h b/src/accessor/grib_accessor_class_second_order_bits_per_value.h new file mode 100644 index 000000000..c3459db41 --- /dev/null +++ b/src/accessor/grib_accessor_class_second_order_bits_per_value.h @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_second_order_bits_per_value_t : public grib_accessor_long_t +{ +public: + /* Members defined in second_order_bits_per_value */ + const char* values; + const char* binaryScaleFactor; + const char* decimalScaleFactor; + long bitsPerValue; +}; + +class grib_accessor_class_second_order_bits_per_value_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_second_order_bits_per_value_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_second_order_bits_per_value_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_section.cc b/src/accessor/grib_accessor_class_section.cc new file mode 100644 index 000000000..ec6e14c2b --- /dev/null +++ b/src/accessor/grib_accessor_class_section.cc @@ -0,0 +1,96 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_section.h" + +grib_accessor_class_section_t _grib_accessor_class_section{"section"}; +grib_accessor_class* grib_accessor_class_section = &_grib_accessor_class_section; + + +void grib_accessor_class_section_t::init(grib_accessor* a, const long len, grib_arguments* arg){ + grib_accessor_class_gen_t::init(a, len, arg); + a->sub_section = grib_section_create(grib_handle_of_accessor(a), a); + a->length = 0; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; +} + +void grib_accessor_class_section_t::dump(grib_accessor* a, grib_dumper* dumper){ + grib_dump_section(dumper, a, a->sub_section->block); +} + +long grib_accessor_class_section_t::byte_count(grib_accessor* a){ + if (!a->length || grib_handle_of_accessor(a)->loader) { + if (a->name[1] == '_') + return 0; + + /* printf("adjusting sizes SECTION %s is %ld %ld\n",a->name,(long)a->offset,(long)a->length); */ + grib_section_adjust_sizes(a->sub_section, grib_handle_of_accessor(a)->loader != NULL, 0); + /* printf(" SECTION %s is %ld %ld\n",a->name,(long)a->offset,(long)a->length); */ + } + + /* printf("SECTION %s is %ld %d\n",a->name,a->length,a->sub_section->aclength != NULL); */ + return a->length; +} + +long grib_accessor_class_section_t::next_offset(grib_accessor* a){ + return a->offset + a->byte_count(); +} + +void grib_accessor_class_section_t::destroy(grib_context* ct, grib_accessor* a){ + grib_section_delete(ct, a->sub_section); + grib_accessor_class_gen_t::destroy(ct, a); +} + +int grib_accessor_class_section_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_SECTION; +} + +grib_section* grib_accessor_class_section_t::sub_section(grib_accessor* a) +{ + return a->sub_section; +} + +void grib_accessor_class_section_t::update_size(grib_accessor* a, size_t length){ + size_t size = 1; + long len = length; + Assert(length <= 0x7fffffff); + if (a->sub_section->aclength) { + int e = a->sub_section->aclength->pack_long(&len, &size); Assert(e == GRIB_SUCCESS); + // printf("update_length %s %ld %ld\n", a->sub_section->aclength->name, + // (long)a->sub_section->aclength->offset, + // (long)a->sub_section->aclength->length); + } + + a->sub_section->length = a->length = length; + a->sub_section->padding = 0; + + // printf("update_size %s %ld\n", a->name, a->length); + + Assert(a->length >= 0); +} + +grib_accessor* grib_accessor_class_section_t::next(grib_accessor* a, int explore) +{ + grib_accessor* next = NULL; + if (explore) { + next = a->sub_section->block->first; + if (!next) + next = a->next_; + } + else { + next = a->next_; + } + if (!next) { + if (a->parent->owner) + next = a->parent->owner->cclass->next(a->parent->owner, 0); + } + return next; +} diff --git a/src/accessor/grib_accessor_class_section.h b/src/accessor/grib_accessor_class_section.h new file mode 100644 index 000000000..8dbd831cc --- /dev/null +++ b/src/accessor/grib_accessor_class_section.h @@ -0,0 +1,32 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_section_t : public grib_accessor_gen_t {}; + +class grib_accessor_class_section_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_section_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_section_t{}; } + int get_native_type(grib_accessor*) override; + long byte_count(grib_accessor*) override; + long next_offset(grib_accessor*) override; + void destroy(grib_context*, grib_accessor*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + void update_size(grib_accessor*, size_t) override; + grib_section* sub_section(grib_accessor*) override; + grib_accessor* next(grib_accessor*, int) override; +}; diff --git a/src/accessor/grib_accessor_class_section_length.cc b/src/accessor/grib_accessor_class_section_length.cc new file mode 100644 index 000000000..bcc75cc2b --- /dev/null +++ b/src/accessor/grib_accessor_class_section_length.cc @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_section_length.h" + +grib_accessor_class_section_length_t _grib_accessor_class_section_length{"section_length"}; +grib_accessor_class* grib_accessor_class_section_length = &_grib_accessor_class_section_length; + + +void grib_accessor_class_section_length_t::init(grib_accessor* a, const long len, grib_arguments* arg){ + grib_accessor_class_unsigned_t::init(a, len, 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); +} + +void grib_accessor_class_section_length_t::dump(grib_accessor* a, grib_dumper* dumper){ + grib_dump_long(dumper, a, NULL); +} + +int grib_accessor_class_section_length_t::value_count(grib_accessor* a, long* c){ + *c = 1; + return 0; +} diff --git a/src/accessor/grib_accessor_class_section_length.h b/src/accessor/grib_accessor_class_section_length.h new file mode 100644 index 000000000..e7965b9b1 --- /dev/null +++ b/src/accessor/grib_accessor_class_section_length.h @@ -0,0 +1,30 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_unsigned.h" + +class grib_accessor_section_length_t : public grib_accessor_unsigned_t +{ +public: + /* Members defined in section_length */ +}; + +class grib_accessor_class_section_length_t : public grib_accessor_class_unsigned_t +{ +public: + grib_accessor_class_section_length_t(const char* name) : grib_accessor_class_unsigned_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_section_length_t{}; } + int value_count(grib_accessor*, long*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_section_padding.cc b/src/accessor/grib_accessor_class_section_padding.cc new file mode 100644 index 000000000..c3457898f --- /dev/null +++ b/src/accessor/grib_accessor_class_section_padding.cc @@ -0,0 +1,70 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_section_padding.h" + +grib_accessor_class_section_padding_t _grib_accessor_class_section_padding{"section_padding"}; +grib_accessor_class* grib_accessor_class_section_padding = &_grib_accessor_class_section_padding; + + +size_t grib_accessor_class_section_padding_t::preferred_size(grib_accessor* a, int from_handle){ + grib_accessor_section_padding_t* self = (grib_accessor_section_padding_t*)a; + grib_accessor* b = a; + grib_accessor* section_length = 0; + long length = 0; + size_t size = 1; + + long alength = 0; + + if (!from_handle) { + if (self->preserve) + return a->length; + else + return 0; + } + + /* The section length should be a parameter */ + while (section_length == NULL && b != NULL) { + section_length = b->parent->aclength; + b = b->parent->owner; + } + + if (!section_length) { + /* printf("PADDING is no !section_length\n"); */ + return 0; + } + + if (section_length->unpack_long(&length, &size) == GRIB_SUCCESS) { + if (length) + alength = length - a->offset + section_length->parent->owner->offset; + else + alength = 0; + + /*Assert(a->length>=0);*/ + + if (alength < 0) + alength = 0; + + /* printf("PADDING is %ld\n",a->length); */ + } + else { + /* printf("PADDING unpack fails\n"); */ + } + + return alength; +} + +void grib_accessor_class_section_padding_t::init(grib_accessor* a, const long len, grib_arguments* arg){ + grib_accessor_class_padding_t::init(a, len, arg); + grib_accessor_section_padding_t* self = (grib_accessor_section_padding_t*)a; + self->preserve = 1; /* This should be a parameter */ + a->length = preferred_size(a, 1); +} diff --git a/src/accessor/grib_accessor_class_section_padding.h b/src/accessor/grib_accessor_class_section_padding.h new file mode 100644 index 000000000..f35da4977 --- /dev/null +++ b/src/accessor/grib_accessor_class_section_padding.h @@ -0,0 +1,30 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_padding.h" + +class grib_accessor_section_padding_t : public grib_accessor_padding_t +{ +public: + /* Members defined in section_padding */ + int preserve; +}; + +class grib_accessor_class_section_padding_t : public grib_accessor_class_padding_t +{ +public: + grib_accessor_class_section_padding_t(const char* name) : grib_accessor_class_padding_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_section_padding_t{}; } + void init(grib_accessor*, const long, grib_arguments*) override; + size_t preferred_size(grib_accessor*, int) override; +}; diff --git a/src/accessor/grib_accessor_class_section_pointer.cc b/src/accessor/grib_accessor_class_section_pointer.cc new file mode 100644 index 000000000..72eb78d6d --- /dev/null +++ b/src/accessor/grib_accessor_class_section_pointer.cc @@ -0,0 +1,97 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_section_pointer.h" + +grib_accessor_class_section_pointer_t _grib_accessor_class_section_pointer{"section_pointer"}; +grib_accessor_class* grib_accessor_class_section_pointer = &_grib_accessor_class_section_pointer; + + +void grib_accessor_class_section_pointer_t::init(grib_accessor* a, const long len, grib_arguments* arg){ + grib_accessor_class_gen_t::init(a, len, arg); + int n = 0; + grib_accessor_section_pointer_t* self = (grib_accessor_section_pointer_t*)a; + + self->sectionOffset = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); + self->sectionLength = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); + self->sectionNumber = grib_arguments_get_long(grib_handle_of_accessor(a), arg, n++); + + Assert(self->sectionNumber < MAX_NUM_SECTIONS); + + grib_handle_of_accessor(a)->section_offset[self->sectionNumber] = (char*)self->sectionOffset; + grib_handle_of_accessor(a)->section_length[self->sectionNumber] = (char*)self->sectionLength; + + /* printf("++++++++++++++ GRIB_API: creating section_pointer%d %s %s\n", */ + /* self->sectionNumber,self->sectionLength,self->sectionLength); */ + + if (grib_handle_of_accessor(a)->sections_count < self->sectionNumber) + grib_handle_of_accessor(a)->sections_count = self->sectionNumber; + + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; + a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; + a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; + a->length = 0; +} + +int grib_accessor_class_section_pointer_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_BYTES; +} + +int grib_accessor_class_section_pointer_t::unpack_string(grib_accessor* a, char* v, size_t* len){ + /* + unsigned char* p=NULL; + char* s=v; + int i; + long length=a->byte_count(); + if (*len < length) return GRIB_ARRAY_TOO_SMALL; + + p = grib_handle_of_accessor(a)->buffer->data + a->byte_offset(); + for (i = 0; i < length; i++) { + snprintf (s,64,"%02x", *(p++)); + s+=2; + } + *len=length; + */ + snprintf(v, 64, "%ld_%ld", a->byte_offset(), a->byte_count()); return GRIB_SUCCESS; +} + +long grib_accessor_class_section_pointer_t::byte_count(grib_accessor* a){ + grib_accessor_section_pointer_t* self = (grib_accessor_section_pointer_t*)a; + long sectionLength = 0; + int ret = 0; + + ret = grib_get_long(grib_handle_of_accessor(a), self->sectionLength, §ionLength); + if (ret) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "Unable to get %s %s", + self->sectionLength, grib_get_error_message(ret)); + return -1; + } + + return sectionLength; +} + +long grib_accessor_class_section_pointer_t::byte_offset(grib_accessor* a){ + grib_accessor_section_pointer_t* self = (grib_accessor_section_pointer_t*)a; + long sectionOffset = 0; + int ret = 0; + + ret = grib_get_long(grib_handle_of_accessor(a), self->sectionOffset, §ionOffset); + if (ret) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "Unable to get %s %s", + self->sectionOffset, grib_get_error_message(ret)); + return -1; + } + + return sectionOffset; +} diff --git a/src/accessor/grib_accessor_class_section_pointer.h b/src/accessor/grib_accessor_class_section_pointer.h new file mode 100644 index 000000000..569e20201 --- /dev/null +++ b/src/accessor/grib_accessor_class_section_pointer.h @@ -0,0 +1,35 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_section_pointer_t : public grib_accessor_gen_t +{ +public: + /* Members defined in section_pointer */ + const char* sectionOffset; + const char* sectionLength; + long sectionNumber; +}; + +class grib_accessor_class_section_pointer_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_section_pointer_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_section_pointer_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + long byte_count(grib_accessor*) override; + long byte_offset(grib_accessor*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_select_step_template.cc b/src/accessor/grib_accessor_class_select_step_template.cc similarity index 60% rename from src/grib_accessor_class_select_step_template.cc rename to src/accessor/grib_accessor_class_select_step_template.cc index 7a0e76c23..bc72a5220 100644 --- a/src/grib_accessor_class_select_step_template.cc +++ b/src/accessor/grib_accessor_class_select_step_template.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,108 +9,15 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_unsigned - IMPLEMENTS = unpack_long;pack_long; value_count - IMPLEMENTS = init - MEMBERS=const char* productDefinitionTemplateNumber - MEMBERS=int instant - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_select_step_template -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in unsigned */ - long nbytes; - grib_arguments* arg; - /* Members defined in select_step_template */ - const char* productDefinitionTemplateNumber; - int instant; -} grib_accessor_select_step_template; - -extern grib_accessor_class* grib_accessor_class_unsigned; - -static grib_accessor_class _grib_accessor_class_select_step_template = { - &grib_accessor_class_unsigned, /* super */ - "select_step_template", /* name */ - sizeof(grib_accessor_select_step_template), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_select_step_template.h" +grib_accessor_class_select_step_template_t _grib_accessor_class_select_step_template{"select_step_template"}; grib_accessor_class* grib_accessor_class_select_step_template = &_grib_accessor_class_select_step_template; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_select_step_template* self = (grib_accessor_select_step_template*)a; +void grib_accessor_class_select_step_template_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_unsigned_t::init(a, l, c); + grib_accessor_select_step_template_t* self = (grib_accessor_select_step_template_t*)a; grib_handle* hand = grib_handle_of_accessor(a); int n = 0; @@ -117,15 +25,13 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) self->instant = grib_arguments_get_long(hand, c, n++); } -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ +int grib_accessor_class_select_step_template_t::unpack_long(grib_accessor* a, long* val, size_t* len){ *val = 1; return GRIB_SUCCESS; } -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - grib_accessor_select_step_template* self = (grib_accessor_select_step_template*)a; +int grib_accessor_class_select_step_template_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + grib_accessor_select_step_template_t* self = (grib_accessor_select_step_template_t*)a; grib_handle* hand = grib_handle_of_accessor(a); long productDefinitionTemplateNumber = 0; long productDefinitionTemplateNumberNew = 0; @@ -266,8 +172,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) return GRIB_SUCCESS; } -static int value_count(grib_accessor* a, long* c) -{ +int grib_accessor_class_select_step_template_t::value_count(grib_accessor* a, long* c){ *c = 1; return 0; } diff --git a/src/accessor/grib_accessor_class_select_step_template.h b/src/accessor/grib_accessor_class_select_step_template.h new file mode 100644 index 000000000..e327a99da --- /dev/null +++ b/src/accessor/grib_accessor_class_select_step_template.h @@ -0,0 +1,33 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_unsigned.h" + +class grib_accessor_select_step_template_t : public grib_accessor_unsigned_t +{ +public: + /* Members defined in select_step_template */ + const char* productDefinitionTemplateNumber; + int instant; +}; + +class grib_accessor_class_select_step_template_t : public grib_accessor_class_unsigned_t +{ +public: + grib_accessor_class_select_step_template_t(const char* name) : grib_accessor_class_unsigned_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_select_step_template_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_sexagesimal2decimal.cc b/src/accessor/grib_accessor_class_sexagesimal2decimal.cc new file mode 100644 index 000000000..e1920c1b9 --- /dev/null +++ b/src/accessor/grib_accessor_class_sexagesimal2decimal.cc @@ -0,0 +1,146 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_sexagesimal2decimal.h" + +grib_accessor_class_sexagesimal2decimal_t _grib_accessor_class_sexagesimal2decimal{"sexagesimal2decimal"}; +grib_accessor_class* grib_accessor_class_sexagesimal2decimal = &_grib_accessor_class_sexagesimal2decimal; + + +void grib_accessor_class_sexagesimal2decimal_t::init(grib_accessor* a, const long len, grib_arguments* arg){ + grib_accessor_class_to_double_t::init(a, len, arg); + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; +} + +void grib_accessor_class_sexagesimal2decimal_t::dump(grib_accessor* a, grib_dumper* dumper){ + grib_dump_double(dumper, a, NULL); +} + +int grib_accessor_class_sexagesimal2decimal_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_DOUBLE; +} + +int grib_accessor_class_sexagesimal2decimal_t::unpack_string(grib_accessor* a, char* val, size_t* len){ + int err = 0; + grib_accessor_sexagesimal2decimal_t* self = (grib_accessor_sexagesimal2decimal_t*)a; + char buff[512] = {0,}; + size_t length = 0; + size_t size = 512; + char* p; + char* q; + double dd, mm = 0, ss = 0; + int dd_sign = 1; + + err = grib_get_string(grib_handle_of_accessor(a), self->key, buff, &size); + if (err) + return err; + q = buff + self->start; + if (self->length) + q[length] = 0; + p = q; + + while (*p != '-' && *p != ':' && *p != ' ' && *p != 0) { + p++; + } + + if (*p == 0) { + return GRIB_WRONG_CONVERSION; + } + *p = 0; + + dd = atoi(q); + p++; + q = p; + while (*p != '-' && *p != ':' && *p != ' ' && *p != 'N' && *p != 'S' && *p != 'E' && *p != 'W' && *p != 0) { + p++; + } + switch (*p) { + case ' ': + case '-': + case ':': + *p = 0; + mm = atoi(q) / 60.0; + dd += mm; + p++; + q = p; + break; + case 'N': + case 'E': + *p = 0; + dd_sign = 1; + mm = atoi(q) / 60.0; + dd += mm; + p++; + q = p; + break; + case 'S': + case 'W': + *p = 0; + mm = atoi(q) / 60.0; + dd += mm; + dd_sign = -1; + p++; + q = p; + break; + case 0: + break; + default: + return GRIB_WRONG_CONVERSION; + } + if (*p) { + while (*p != '-' && *p != ':' && *p != ' ' && *p != 'N' && *p != 'S' && *p != 'E' && *p != 'W' && *p != 0) { + p++; + } + switch (*p) { + case ' ': + case '-': + case ':': + *p = 0; + ss = atof(q) / 60.0; + dd += ss; + break; + case 'N': + case 'E': + *p = 0; + ss = atof(q) / 60.0; + dd += ss; + dd_sign = 1; + break; + case 'S': + case 'W': + *p = 0; + ss = atof(q) / 60.0; + dd += ss; + dd_sign = -1; + break; + case 0: + break; + default: + return GRIB_WRONG_CONVERSION; + } + } + dd *= dd_sign; + + snprintf(buff, sizeof(buff), "%.2f", dd); + length = strlen(buff); + + if (len[0] < length + 1) { + grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%lu) for %s, it contains %ld values", + len[0], a->name, a->length + 1); + len[0] = 0; + return GRIB_ARRAY_TOO_SMALL; + } + + strcpy(val, buff); + + len[0] = length; + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_sexagesimal2decimal.h b/src/accessor/grib_accessor_class_sexagesimal2decimal.h new file mode 100644 index 000000000..d9051bca9 --- /dev/null +++ b/src/accessor/grib_accessor_class_sexagesimal2decimal.h @@ -0,0 +1,31 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_to_double.h" + +class grib_accessor_sexagesimal2decimal_t : public grib_accessor_to_double_t +{ +public: + /* Members defined in sexagesimal2decimal */ +}; + +class grib_accessor_class_sexagesimal2decimal_t : public grib_accessor_class_to_double_t +{ +public: + grib_accessor_class_sexagesimal2decimal_t(const char* name) : grib_accessor_class_to_double_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_sexagesimal2decimal_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_signed.cc b/src/accessor/grib_accessor_class_signed.cc new file mode 100644 index 000000000..36c20bd59 --- /dev/null +++ b/src/accessor/grib_accessor_class_signed.cc @@ -0,0 +1,219 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_signed.h" + +grib_accessor_class_signed_t _grib_accessor_class_signed{ "signed" }; +grib_accessor_class* grib_accessor_class_signed = &_grib_accessor_class_signed; + + +void grib_accessor_class_signed_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ + grib_accessor_class_long_t::init(a, len, arg); + grib_accessor_signed_t* self = (grib_accessor_signed_t*)a; + long count = 0; + + self->arg = arg; + a->value_count(&count); + a->length = len * count; + self->nbytes = len; + Assert(a->length >= 0); +} + +void grib_accessor_class_signed_t::dump(grib_accessor* a, grib_dumper* dumper) +{ + long rlen = 0; + a->value_count(&rlen); + if (rlen == 1) + grib_dump_long(dumper, a, NULL); + else + grib_dump_values(dumper, a); +} + +static const long ones[] = { + 0, + -0x7f, + -0x7fff, + -0x7fffff, + -0x7fffffff, +}; + +int grib_accessor_class_signed_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ + grib_accessor_signed_t* self = (grib_accessor_signed_t*)a; + unsigned long rlen = 0; + int err = 0; + long count = 0; + unsigned long i = 0; + grib_handle* hand = grib_handle_of_accessor(a); + long pos = a->offset; + long missing = 0; + + err = a->value_count(&count); + if (err) + return err; + rlen = count; + + if (*len < rlen) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %lu values", a->name, rlen); + *len = 0; + return GRIB_ARRAY_TOO_SMALL; + } + + if (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) { + Assert(self->nbytes <= 4); + missing = ones[self->nbytes]; + } + + for (i = 0; i < rlen; i++) { + val[i] = (long)grib_decode_signed_long(hand->buffer->data, pos, self->nbytes); + if (missing) + if (val[i] == missing) + val[i] = GRIB_MISSING_LONG; + pos += self->nbytes; + } + + *len = rlen; + return GRIB_SUCCESS; +} + +int grib_accessor_class_signed_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ + grib_accessor_signed_t* self = (grib_accessor_signed_t*)a; + + int ret = 0; + long off = 0; + unsigned long rlen = 0; + long count = 0; + size_t buflen = 0; + unsigned char* buf = NULL; + unsigned long i = 0; + long missing = 0; + + int err = a->value_count(&count); + if (err) + return err; + rlen = count; + + if (*len < 1) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %d values", a->name, 1); + len[0] = 0; + return GRIB_ARRAY_TOO_SMALL; + } + + if (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) { + Assert(self->nbytes <= 4); + missing = ones[self->nbytes]; + } + + if (rlen == 1) { + long v = val[0]; + if (missing) { + if (v == GRIB_MISSING_LONG) + v = missing; + } + else { + // ECC-1605: Check overflow/underflow + const int nbits = self->nbytes * 8; + const long minval = -(1L << (nbits - 1)) + 1; + const long maxval = (1L << (nbits - 1)) - 1; + // printf(" key=%s: v=%ld (minval=%ld maxval=%ld)\n", a->name, v, minval, maxval); + if (v > maxval || v < minval) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "Key \"%s\": Trying to encode value of %ld but the allowable range is %ld to %ld (number of bits=%d)", + a->name, v, minval, maxval, nbits); + return GRIB_ENCODING_ERROR; + } + } + + off = a->offset; + ret = grib_encode_signed_long(grib_handle_of_accessor(a)->buffer->data, v, off, a->length); + if (ret == GRIB_SUCCESS) + len[0] = 1; + if (*len > 1) + grib_context_log(a->context, GRIB_LOG_WARNING, "grib_accessor_signed_t : Trying to pack %d values in a scalar %s, packing first value", *len, a->name); + len[0] = 1; + return ret; + } + + /* TODO: We assume that there are no missing values if there are more that 1 value */ + + buflen = *len * a->length; + + buf = (unsigned char*)grib_context_malloc(a->context, buflen); + + for (i = 0; i < *len; i++) { + grib_encode_signed_long(buf, val[i], off, a->length); + off += a->length; + } + ret = grib_set_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, self->arg, 0), *len); + + if (ret == GRIB_SUCCESS) + grib_buffer_replace(a, buf, buflen, 1, 1); + else + *len = 0; + + grib_context_free(a->context, buf); + return ret; +} + +long grib_accessor_class_signed_t::byte_count(grib_accessor* a) +{ + return a->length; +} + +int grib_accessor_class_signed_t::value_count(grib_accessor* a, long* len) +{ + grib_accessor_signed_t* self = (grib_accessor_signed_t*)a; + *len = 0; + if (!self->arg) { + *len = 1; + return 0; + } + return grib_get_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, self->arg, 0), len); +} + +long grib_accessor_class_signed_t::byte_offset(grib_accessor* a) +{ + return a->offset; +} + +void grib_accessor_class_signed_t::update_size(grib_accessor* a, size_t s) +{ + a->length = s; + Assert(a->length >= 0); +} + +long grib_accessor_class_signed_t::next_offset(grib_accessor* a) +{ + return a->byte_offset() + a->byte_count(); +} + +int grib_accessor_class_signed_t::is_missing(grib_accessor* a) +{ + int i = 0; + unsigned char ff = 0xff; + unsigned long offset = a->offset; + grib_handle* hand = grib_handle_of_accessor(a); + + if (a->length == 0) { + Assert(a->vvalue != NULL); + return a->vvalue->missing; + } + + for (i = 0; i < a->length; i++) { + if (hand->buffer->data[offset] != ff) + return 0; + offset++; + } + + return 1; +} diff --git a/src/accessor/grib_accessor_class_signed.h b/src/accessor/grib_accessor_class_signed.h new file mode 100644 index 000000000..9fbb6f8d2 --- /dev/null +++ b/src/accessor/grib_accessor_class_signed.h @@ -0,0 +1,39 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_signed_t : public grib_accessor_long_t +{ +public: + /* Members defined in signed */ + grib_arguments* arg; + int nbytes; +}; + +class grib_accessor_class_signed_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_signed_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_signed_t{}; } + int is_missing(grib_accessor*) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + long byte_count(grib_accessor*) override; + long byte_offset(grib_accessor*) override; + long next_offset(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + void update_size(grib_accessor*, size_t) override; +}; diff --git a/src/accessor/grib_accessor_class_signed_bits.cc b/src/accessor/grib_accessor_class_signed_bits.cc new file mode 100644 index 000000000..3da4d03c2 --- /dev/null +++ b/src/accessor/grib_accessor_class_signed_bits.cc @@ -0,0 +1,152 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_signed_bits.h" + +grib_accessor_class_signed_bits_t _grib_accessor_class_signed_bits{"signed_bits"}; +grib_accessor_class* grib_accessor_class_signed_bits = &_grib_accessor_class_signed_bits; + + +long grib_accessor_class_signed_bits_t::byte_count(grib_accessor* a){ + return a->length; +} + +static long compute_byte_count(grib_accessor* a){ + grib_accessor_signed_bits_t* self = (grib_accessor_signed_bits_t*)a; + long numberOfBits; + long numberOfElements; + int ret = 0; + + ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); + if (ret) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", a->name, self->numberOfBits); + return 0; + } + + ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements, &numberOfElements); + if (ret) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", a->name, self->numberOfElements); + return 0; + } + + return (numberOfBits * numberOfElements + 7) / 8; +} + +void grib_accessor_class_signed_bits_t::init(grib_accessor* a, const long len, grib_arguments* args){ + grib_accessor_class_long_t::init(a, len, args); + grib_accessor_signed_bits_t* self = (grib_accessor_signed_bits_t*)a; + int n = 0; + self->numberOfBits = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + self->numberOfElements = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + a->length = compute_byte_count(a); +} + +int grib_accessor_class_signed_bits_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + return GRIB_NOT_IMPLEMENTED; +#if 0 + grib_accessor_signed_bits_t* self = (grib_accessor_signed_bits_t*)a; + int i; + int ret = 0; + long pos = a->offset * 8; + long rlen = 0; + long numberOfBits = 0; + + ret = value_count(a, &rlen); + if (ret) + return ret; + + if (*len < rlen) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "Wrong size (%ld) for %s it contains %ld values", *len, a->name, rlen); + *len = 0; + return GRIB_ARRAY_TOO_SMALL; + } + + ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); + if (ret) + return ret; + + if (numberOfBits == 0) { + for (i = 0; i < rlen; i++) + val[i] = 0; + return GRIB_SUCCESS; + } + + for (i = 0; i < rlen; i++) + val[i] = grib_decode_signed_longb(grib_handle_of_accessor(a)->buffer->data, &pos, numberOfBits); + + *len = rlen; + + return GRIB_SUCCESS; +#endif +} + +int grib_accessor_class_signed_bits_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + return GRIB_NOT_IMPLEMENTED; +#if 0 + grib_accessor_signed_bits_t* self = (grib_accessor_signed_bits_t*)a; + int ret = 0; + long off = 0; + long numberOfBits = 0; + size_t buflen = 0; + unsigned char* buf = NULL; + unsigned long i = 0; + unsigned long rlen = 0; + long count = 0; + + ret = value_count(a, &count); + if (ret) + return ret; + rlen = count; + if (*len != rlen) { + ret = grib_set_long(grib_handle_of_accessor(a), self->numberOfElements, rlen); + if (ret) + return ret; + } + + ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); + if (ret) + return ret; + + buflen = compute_byte_count(a); + buf = (unsigned char*)grib_context_malloc_clear(a->context, buflen + sizeof(long)); + + for (i = 0; i < rlen; i++) + grib_encode_signed_longb(buf, val[i], &off, numberOfBits); + + grib_buffer_replace(a, buf, buflen, 1, 1); + + grib_context_free(a->context, buf); + + return ret; +#endif +} + +int grib_accessor_class_signed_bits_t::value_count(grib_accessor* a, long* numberOfElements){ + grib_accessor_signed_bits_t* self = (grib_accessor_signed_bits_t*)a; + *numberOfElements = 0; + + return grib_get_long(grib_handle_of_accessor(a), self->numberOfElements, numberOfElements); +} + +long grib_accessor_class_signed_bits_t::byte_offset(grib_accessor* a){ + return a->offset; +} + +void grib_accessor_class_signed_bits_t::update_size(grib_accessor* a, size_t s){ + a->length = s; +} + +long grib_accessor_class_signed_bits_t::next_offset(grib_accessor* a){ + return a->byte_offset() + a->byte_count(); +} diff --git a/src/accessor/grib_accessor_class_signed_bits.h b/src/accessor/grib_accessor_class_signed_bits.h new file mode 100644 index 000000000..dd49c5c75 --- /dev/null +++ b/src/accessor/grib_accessor_class_signed_bits.h @@ -0,0 +1,37 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_signed_bits_t : public grib_accessor_long_t +{ +public: + /* Members defined in signed_bits */ + const char* numberOfBits; + const char* numberOfElements; +}; + +class grib_accessor_class_signed_bits_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_signed_bits_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_signed_bits_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + long byte_count(grib_accessor*) override; + long byte_offset(grib_accessor*) override; + long next_offset(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + void update_size(grib_accessor*, size_t) override; +}; diff --git a/src/accessor/grib_accessor_class_simple_packing_error.cc b/src/accessor/grib_accessor_class_simple_packing_error.cc new file mode 100644 index 000000000..5f713a950 --- /dev/null +++ b/src/accessor/grib_accessor_class_simple_packing_error.cc @@ -0,0 +1,70 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_simple_packing_error.h" +#include "grib_scaling.h" + +grib_accessor_class_simple_packing_error_t _grib_accessor_class_simple_packing_error{"simple_packing_error"}; +grib_accessor_class* grib_accessor_class_simple_packing_error = &_grib_accessor_class_simple_packing_error; + + +void grib_accessor_class_simple_packing_error_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_double_t::init(a, l, c); + grib_accessor_simple_packing_error_t* self = (grib_accessor_simple_packing_error_t*)a; + int n = 0; + grib_handle* h = grib_handle_of_accessor(a); + + self->bitsPerValue = grib_arguments_get_name(h, c, n++); + self->binaryScaleFactor = grib_arguments_get_name(h, c, n++); + self->decimalScaleFactor = grib_arguments_get_name(h, c, n++); + self->referenceValue = grib_arguments_get_name(h, c, n++); + self->floatType = grib_arguments_get_name(h, c, n++); + + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->length = 0; +} + +int grib_accessor_class_simple_packing_error_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + grib_accessor_simple_packing_error_t* self = (grib_accessor_simple_packing_error_t*)a; + + int ret = 0; + long binaryScaleFactor = 0; + long bitsPerValue = 0; + long decimalScaleFactor = 0; + double referenceValue = 0; + grib_handle* h = grib_handle_of_accessor(a); + + if ((ret = grib_get_long_internal(h, self->binaryScaleFactor, &binaryScaleFactor)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_get_long_internal(h, self->bitsPerValue, &bitsPerValue)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_get_long_internal(h, self->decimalScaleFactor, &decimalScaleFactor)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_get_double_internal(h, self->referenceValue, &referenceValue)) != GRIB_SUCCESS) + return ret; + + if (!strcmp(self->floatType, "ibm")) + *val = grib_ibmfloat_error(referenceValue); + else if (!strcmp(self->floatType, "ieee")) + *val = grib_ieeefloat_error(referenceValue); + else + Assert(1 == 0); + + if (bitsPerValue != 0) + *val = (*val + codes_power(binaryScaleFactor, 2)) * codes_power(-decimalScaleFactor, 10) * 0.5; + + if (ret == GRIB_SUCCESS) + *len = 1; + + return ret; +} diff --git a/src/accessor/grib_accessor_class_simple_packing_error.h b/src/accessor/grib_accessor_class_simple_packing_error.h new file mode 100644 index 000000000..f0c005e03 --- /dev/null +++ b/src/accessor/grib_accessor_class_simple_packing_error.h @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_double.h" + +class grib_accessor_simple_packing_error_t : public grib_accessor_double_t +{ +public: + /* Members defined in simple_packing_error */ + const char* binaryScaleFactor; + const char* bitsPerValue; + const char* decimalScaleFactor; + const char* referenceValue; + const char* floatType; +}; + +class grib_accessor_class_simple_packing_error_t : public grib_accessor_class_double_t +{ +public: + grib_accessor_class_simple_packing_error_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_simple_packing_error_t{}; } + int unpack_double(grib_accessor*, double* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_size.cc b/src/accessor/grib_accessor_class_size.cc new file mode 100644 index 000000000..71c0dd947 --- /dev/null +++ b/src/accessor/grib_accessor_class_size.cc @@ -0,0 +1,37 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_size.h" + +grib_accessor_class_size_t _grib_accessor_class_size{ "size" }; +grib_accessor_class* grib_accessor_class_size = &_grib_accessor_class_size; + + +void grib_accessor_class_size_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ + grib_accessor_class_long_t::init(a, l, c); + grib_accessor_size_t* self = (grib_accessor_size_t*)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; +} + +int grib_accessor_class_size_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ + grib_accessor_size_t* self = (grib_accessor_size_t*)a; + + size_t size = 0; + int ret = grib_get_size(grib_handle_of_accessor(a), self->accessor, &size); + *val = (long)size; + *len = 1; + return ret; +} diff --git a/src/accessor/grib_accessor_class_size.h b/src/accessor/grib_accessor_class_size.h new file mode 100644 index 000000000..9901c479e --- /dev/null +++ b/src/accessor/grib_accessor_class_size.h @@ -0,0 +1,30 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_size_t : public grib_accessor_long_t +{ +public: + /* Members defined in size */ + const char* accessor; +}; + +class grib_accessor_class_size_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_size_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_size_t{}; } + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_smart_table.cc b/src/accessor/grib_accessor_class_smart_table.cc similarity index 70% rename from src/grib_accessor_class_smart_table.cc rename to src/accessor/grib_accessor_class_smart_table.cc index a3f257312..1c49f2ab0 100644 --- a/src/grib_accessor_class_smart_table.cc +++ b/src/accessor/grib_accessor_class_smart_table.cc @@ -8,127 +8,12 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" +#include "grib_accessor_class_smart_table.h" #include -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_unsigned - IMPLEMENTS = init;dump;unpack_string;unpack_long - IMPLEMENTS = value_count; destroy; get_native_type; - MEMBERS = const char* values - MEMBERS = const char* tablename - MEMBERS = const char* masterDir - MEMBERS = const char* localDir - MEMBERS = const char* extraDir - MEMBERS = const char* extraTable - MEMBERS = int widthOfCode - MEMBERS = long* tableCodes - MEMBERS = size_t tableCodesSize - MEMBERS = grib_smart_table* table - MEMBERS = int dirty - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static int value_count(grib_accessor*, long*); -static void destroy(grib_context*, grib_accessor*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_smart_table -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in unsigned */ - long nbytes; - grib_arguments* arg; - /* Members defined in smart_table */ - const char* values; - const char* tablename; - const char* masterDir; - const char* localDir; - const char* extraDir; - const char* extraTable; - int widthOfCode; - long* tableCodes; - size_t tableCodesSize; - grib_smart_table* table; - int dirty; -} grib_accessor_smart_table; - -extern grib_accessor_class* grib_accessor_class_unsigned; - -static grib_accessor_class _grib_accessor_class_smart_table = { - &grib_accessor_class_unsigned, /* super */ - "smart_table", /* name */ - sizeof(grib_accessor_smart_table), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - &destroy, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - +grib_accessor_class_smart_table_t _grib_accessor_class_smart_table{"smart_table"}; grib_accessor_class* grib_accessor_class_smart_table = &_grib_accessor_class_smart_table; -/* END_CLASS_IMP */ - #if GRIB_PTHREADS static pthread_once_t once = PTHREAD_ONCE_INIT; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; @@ -145,7 +30,7 @@ static void thread_init() static int once = 0; static omp_nest_lock_t mutex; -static void thread_init() +void thread_init() { GRIB_OMP_CRITICAL(lock_grib_accessor_class_smart_table_c) { @@ -159,10 +44,12 @@ static void thread_init() static int grib_load_smart_table(grib_context* c, const char* filename, const char* recomposed_name, size_t size, grib_smart_table* t); -static void init(grib_accessor* a, const long len, grib_arguments* params) +void grib_accessor_class_smart_table_t::init(grib_accessor* a, const long len, grib_arguments* params) { + grib_accessor_class_unsigned_t::init(a, len, params); + int n = 0; - grib_accessor_smart_table* self = (grib_accessor_smart_table*)a; + grib_accessor_smart_table_t* self = (grib_accessor_smart_table_t*)a; grib_handle* hand = grib_handle_of_accessor(a); self->values = grib_arguments_get_name(hand, params, n++); @@ -180,9 +67,9 @@ static void init(grib_accessor* a, const long len, grib_arguments* params) self->tableCodes = 0; } -static grib_smart_table* load_table(grib_accessor* a) +grib_smart_table* load_table(grib_accessor* a) { - grib_accessor_smart_table* self = (grib_accessor_smart_table*)a; + grib_accessor_smart_table_t* self = (grib_accessor_smart_table_t*)a; size_t size = 0; grib_handle* h = ((grib_accessor*)self)->parent->h; grib_context* c = h->context; @@ -393,14 +280,14 @@ void grib_smart_table_delete(grib_context* c) } } -static void dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_class_smart_table_t::dump(grib_accessor* a, grib_dumper* dumper) { grib_dump_long(dumper, a, NULL); } -static int unpack_string(grib_accessor* a, char* buffer, size_t* len) +int grib_accessor_class_smart_table_t::unpack_string(grib_accessor* a, char* buffer, size_t* len) { - grib_accessor_smart_table* self = (grib_accessor_smart_table*)a; + grib_accessor_smart_table_t* self = (grib_accessor_smart_table_t*)a; grib_smart_table* table = NULL; size_t size = 1; @@ -409,7 +296,7 @@ static int unpack_string(grib_accessor* a, char* buffer, size_t* len) char tmp[1024]; size_t l = 0; - if ((err = grib_unpack_long(a, &value, &size)) != GRIB_SUCCESS) + if ((err = a->unpack_long(&value, &size)) != GRIB_SUCCESS) return err; if (!self->table) @@ -439,7 +326,7 @@ static int unpack_string(grib_accessor* a, char* buffer, size_t* len) static int get_table_codes(grib_accessor* a) { - grib_accessor_smart_table* self = (grib_accessor_smart_table*)a; + grib_accessor_smart_table_t* self = (grib_accessor_smart_table_t*)a; size_t size = 0; long* v = 0; int err = 0; @@ -489,10 +376,10 @@ static int get_table_codes(grib_accessor* a) return 0; } -static int value_count(grib_accessor* a, long* count) +int grib_accessor_class_smart_table_t::value_count(grib_accessor* a, long* count) { int err = 0; - grib_accessor_smart_table* self = (grib_accessor_smart_table*)a; + grib_accessor_smart_table_t* self = (grib_accessor_smart_table_t*)a; *count = 0; if (!self->values) @@ -505,18 +392,20 @@ static int value_count(grib_accessor* a, long* count) return GRIB_SUCCESS; } -static void destroy(grib_context* context, grib_accessor* a) +void grib_accessor_class_smart_table_t::destroy(grib_context* context, grib_accessor* a) { - grib_accessor_smart_table* self = (grib_accessor_smart_table*)a; + grib_accessor_smart_table_t* self = (grib_accessor_smart_table_t*)a; if (a->vvalue != NULL) { grib_context_free(context, a->vvalue); a->vvalue = NULL; } if (self->tableCodes) grib_context_free(a->context, self->tableCodes); + + grib_accessor_class_unsigned_t::destroy(context, a); } -static int get_native_type(grib_accessor* a) +int grib_accessor_class_smart_table_t::get_native_type(grib_accessor* a) { int type = GRIB_TYPE_LONG; //printf("---------- %s flags=%ld GRIB_ACCESSOR_FLAG_STRING_TYPE=%d\n", @@ -526,10 +415,10 @@ static int get_native_type(grib_accessor* a) return type; } -static int unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_class_smart_table_t::unpack_long(grib_accessor* a, long* val, size_t* len) { int err = 0; - grib_accessor_smart_table* self = (grib_accessor_smart_table*)a; + grib_accessor_smart_table_t* self = (grib_accessor_smart_table_t*)a; size_t i; if (!self->values) diff --git a/src/accessor/grib_accessor_class_smart_table.h b/src/accessor/grib_accessor_class_smart_table.h new file mode 100644 index 000000000..c7aaf0827 --- /dev/null +++ b/src/accessor/grib_accessor_class_smart_table.h @@ -0,0 +1,44 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_unsigned.h" +#include + +class grib_accessor_smart_table_t : public grib_accessor_unsigned_t +{ +public: + const char* values; + const char* tablename; + const char* masterDir; + const char* localDir; + const char* extraDir; + const char* extraTable; + int widthOfCode; + long* tableCodes; + size_t tableCodesSize; + grib_smart_table* table; + int dirty; +}; + +class grib_accessor_class_smart_table_t : public grib_accessor_class_unsigned_t +{ +public: + grib_accessor_class_smart_table_t(const char* name) : grib_accessor_class_unsigned_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_smart_table_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void destroy(grib_context*, grib_accessor*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_smart_table_column.cc b/src/accessor/grib_accessor_class_smart_table_column.cc new file mode 100644 index 000000000..7d352471d --- /dev/null +++ b/src/accessor/grib_accessor_class_smart_table_column.cc @@ -0,0 +1,179 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_smart_table_column.h" +#include "grib_accessor_class_smart_table.h" + +grib_accessor_class_smart_table_column_t _grib_accessor_class_smart_table_column{"smart_table_column"}; +grib_accessor_class* grib_accessor_class_smart_table_column = &_grib_accessor_class_smart_table_column; + + + +void grib_accessor_class_smart_table_column_t::init(grib_accessor* a, const long len, grib_arguments* params){ + grib_accessor_class_gen_t::init(a, len, params); + int n = 0; + grib_accessor_smart_table_column_t* self = (grib_accessor_smart_table_column_t*)a; + + self->smartTable = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++); + self->index = grib_arguments_get_long(grib_handle_of_accessor(a), params, n++); + + a->length = 0; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; +} + +void grib_accessor_class_smart_table_column_t::dump(grib_accessor* a, grib_dumper* dumper){ + int type = get_native_type(a); + + switch (type) { + case GRIB_TYPE_LONG: + grib_dump_long(dumper, a, NULL); + break; + case GRIB_TYPE_STRING: + grib_dump_string_array(dumper, a, NULL); + break; + } +} + +int grib_accessor_class_smart_table_column_t::unpack_string_array(grib_accessor* a, char** buffer, size_t* len){ + grib_accessor_smart_table_column_t* self = (grib_accessor_smart_table_column_t*)a; + grib_accessor_smart_table_t* tableAccessor = NULL; + grib_smart_table* table = NULL; + + size_t size = 1; + long* code; + int err = GRIB_SUCCESS; + char tmp[1024] = {0,}; + int i = 0; + + tableAccessor = (grib_accessor_smart_table_t*)grib_find_accessor(grib_handle_of_accessor(a), self->smartTable); + if (!tableAccessor) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "Unable to find accessor %s", self->smartTable); + return GRIB_NOT_FOUND; + } + + err = grib_get_size_acc(grib_handle_of_accessor(a), (grib_accessor*)tableAccessor, &size); + if (err) + return err; + if (*len < size) { + return GRIB_BUFFER_TOO_SMALL; + } + + code = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); + if (!code) { + grib_context_log(a->context, GRIB_LOG_FATAL, "%s: Memory allocation error: %zu bytes", a->name, size); + return GRIB_OUT_OF_MEMORY; + } + + if ((err = ((grib_accessor*)tableAccessor)->unpack_long(code, &size)) != GRIB_SUCCESS) + return err; + + table = tableAccessor->table; + + for (i = 0; i < size; i++) { + if (table && (code[i] >= 0) && + (code[i] < table->numberOfEntries) && + table->entries[code[i]].column[self->index]) { + strcpy(tmp, table->entries[code[i]].column[self->index]); + } + else { + snprintf(tmp, sizeof(tmp), "%d", (int)code[i]); + } + + buffer[i] = grib_context_strdup(a->context, tmp); + } + *len = size; + grib_context_free(a->context, code); + + return GRIB_SUCCESS; +} + +int grib_accessor_class_smart_table_column_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_accessor_smart_table_column_t* self = (grib_accessor_smart_table_column_t*)a; + grib_accessor_smart_table_t* tableAccessor = NULL; + grib_smart_table* table = NULL; + + size_t size = 1; + long* code; + int err = GRIB_SUCCESS; + int i = 0; + + for (i = 0; i < *len; i++) + val[i] = GRIB_MISSING_LONG; + + tableAccessor = (grib_accessor_smart_table_t*)grib_find_accessor(grib_handle_of_accessor(a), self->smartTable); + if (!tableAccessor) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "Unable to find accessor %s", self->smartTable); + return GRIB_NOT_FOUND; + } + + err = grib_get_size_acc(grib_handle_of_accessor(a), (grib_accessor*)tableAccessor, &size); + if (err) + return err; + if (*len < size) { + return GRIB_BUFFER_TOO_SMALL; + } + + code = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); + if (!code) return GRIB_OUT_OF_MEMORY; + + if ((err = ((grib_accessor*)tableAccessor)->unpack_long(code, &size)) != GRIB_SUCCESS) { + grib_context_free(a->context, code); + return err; + } + + table = tableAccessor->table; + + for (i = 0; i < size; i++) { + if (table && (code[i] >= 0) && + (code[i] < table->numberOfEntries) && + table->entries[code[i]].column[self->index]) { + val[i] = atol(table->entries[code[i]].column[self->index]); + } + } + *len = size; + grib_context_free(a->context, code); + + return GRIB_SUCCESS; +} + +int grib_accessor_class_smart_table_column_t::value_count(grib_accessor* a, long* count){ + grib_accessor_smart_table_column_t* self = (grib_accessor_smart_table_column_t*)a; + size_t size = 0; + int err = 0; + *count = 0; + + if (!self->smartTable) + return 0; + + err = grib_get_size(grib_handle_of_accessor(a), self->smartTable, &size); + *count = size; + return err; +} + +void grib_accessor_class_smart_table_column_t::destroy(grib_context* context, grib_accessor* a){ + if (a->vvalue != NULL) { + grib_context_free(context, a->vvalue); + a->vvalue = NULL; + } + + grib_accessor_class_gen_t::destroy(context, a); +} + +int grib_accessor_class_smart_table_column_t::get_native_type(grib_accessor* a){ + int type = GRIB_TYPE_LONG; + /*printf("---------- %s flags=%ld GRIB_ACCESSOR_FLAG_STRING_TYPE=%d\n", + a->name,a->flags,GRIB_ACCESSOR_FLAG_STRING_TYPE);*/ + if (a->flags & GRIB_ACCESSOR_FLAG_STRING_TYPE) + type = GRIB_TYPE_STRING; + return type; +} diff --git a/src/accessor/grib_accessor_class_smart_table_column.h b/src/accessor/grib_accessor_class_smart_table_column.h new file mode 100644 index 000000000..9e1edcd2a --- /dev/null +++ b/src/accessor/grib_accessor_class_smart_table_column.h @@ -0,0 +1,35 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_smart_table_column_t : public grib_accessor_gen_t +{ +public: + const char* smartTable; + int index; +}; + +class grib_accessor_class_smart_table_column_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_smart_table_column_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_smart_table_column_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string_array(grib_accessor*, char**, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void destroy(grib_context*, grib_accessor*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_spd.cc b/src/accessor/grib_accessor_class_spd.cc new file mode 100644 index 000000000..dd717ba3c --- /dev/null +++ b/src/accessor/grib_accessor_class_spd.cc @@ -0,0 +1,155 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_spd.h" + +grib_accessor_class_spd_t _grib_accessor_class_spd{"spd"}; +grib_accessor_class* grib_accessor_class_spd = &_grib_accessor_class_spd; + + +long grib_accessor_class_spd_t::byte_count(grib_accessor* a){ + return a->length; +} + +static long compute_byte_count(grib_accessor* a){ + grib_accessor_spd_t* self = (grib_accessor_spd_t*)a; + long numberOfBits = 0; + long numberOfElements = 0; + + int ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); + if (ret) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", a->name, self->numberOfBits); + return 0; + } + + ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements, &numberOfElements); + if (ret) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", a->name, self->numberOfElements); + return 0; + } + numberOfElements++; + + return (numberOfBits * numberOfElements + 7) / 8; +} + +void grib_accessor_class_spd_t::init(grib_accessor* a, const long len, grib_arguments* args){ + grib_accessor_class_long_t::init(a, len, args); + grib_accessor_spd_t* self = (grib_accessor_spd_t*)a; + int n = 0; + self->numberOfBits = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + self->numberOfElements = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + a->length = compute_byte_count(a); +} + +int grib_accessor_class_spd_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_accessor_spd_t* self = (grib_accessor_spd_t*)a; + long pos = a->offset * 8; + long rlen = 0; + long numberOfBits = 0; + + int ret = value_count(a, &rlen); + if (ret) + return ret; + + if (*len < rlen) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "Wrong size (%zu) for %s, it contains %ld values", *len, a->name, rlen); + *len = rlen; + return GRIB_ARRAY_TOO_SMALL; + } + + ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); + if (ret) + return ret; + if (numberOfBits > 64) { + grib_context_log(a->context, GRIB_LOG_ERROR,"Invalid number of bits: %ld",numberOfBits); + return GRIB_DECODING_ERROR; + } + + for (long i = 0; i < rlen - 1; i++) + val[i] = grib_decode_unsigned_long(grib_handle_of_accessor(a)->buffer->data, &pos, numberOfBits); + + val[rlen - 1] = grib_decode_signed_longb(grib_handle_of_accessor(a)->buffer->data, &pos, numberOfBits); + + *len = rlen; + + return GRIB_SUCCESS; +} + +int grib_accessor_class_spd_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + grib_accessor_spd_t* self = (grib_accessor_spd_t*)a; + int ret = 0; + long off = 0; + long numberOfBits = 0; + size_t buflen = 0; + unsigned char* buf = NULL; + unsigned long i = 0; + long rlen = 0; + + ret = value_count(a, &rlen); + if (ret) + return ret; + + if (*len != rlen) { + ret = grib_set_long(grib_handle_of_accessor(a), self->numberOfElements, (*len) - 1); + if (ret) return ret; + } + + ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); + if (ret) + return ret; + + buflen = compute_byte_count(a); + buf = (unsigned char*)grib_context_malloc_clear(a->context, buflen); + + for (i = 0; i < rlen - 1; i++) { + grib_encode_unsigned_longb(buf, val[i], &off, numberOfBits); + } + + grib_encode_signed_longb(buf, val[rlen - 1], &off, numberOfBits); + + grib_buffer_replace(a, buf, buflen, 1, 1); + + grib_context_free(a->context, buf); + + *len = rlen; + return ret; +} + +int grib_accessor_class_spd_t::value_count(grib_accessor* a, long* numberOfElements){ + grib_accessor_spd_t* self = (grib_accessor_spd_t*)a; + int ret; + *numberOfElements = 0; + + ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements, numberOfElements); + if (ret) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", a->name, self->numberOfElements); + return ret; + } + (*numberOfElements)++; + + return ret; +} + +long grib_accessor_class_spd_t::byte_offset(grib_accessor* a){ + return a->offset; +} + +void grib_accessor_class_spd_t::update_size(grib_accessor* a, size_t s){ + a->length = s; +} + +long grib_accessor_class_spd_t::next_offset(grib_accessor* a){ + return a->byte_offset() + a->length; +} diff --git a/src/accessor/grib_accessor_class_spd.h b/src/accessor/grib_accessor_class_spd.h new file mode 100644 index 000000000..ee4fa5d12 --- /dev/null +++ b/src/accessor/grib_accessor_class_spd.h @@ -0,0 +1,37 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_spd_t : public grib_accessor_long_t +{ +public: + /* Members defined in spd */ + const char* numberOfBits; + const char* numberOfElements; +}; + +class grib_accessor_class_spd_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_spd_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_spd_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + long byte_count(grib_accessor*) override; + long byte_offset(grib_accessor*) override; + long next_offset(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + void update_size(grib_accessor*, size_t) override; +}; diff --git a/src/accessor/grib_accessor_class_spectral_truncation.cc b/src/accessor/grib_accessor_class_spectral_truncation.cc new file mode 100644 index 000000000..2fc45511f --- /dev/null +++ b/src/accessor/grib_accessor_class_spectral_truncation.cc @@ -0,0 +1,81 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_spectral_truncation.h" + +grib_accessor_class_spectral_truncation_t _grib_accessor_class_spectral_truncation{"spectral_truncation"}; +grib_accessor_class* grib_accessor_class_spectral_truncation = &_grib_accessor_class_spectral_truncation; + + +void grib_accessor_class_spectral_truncation_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_long_t::init(a, l, c); + grib_accessor_spectral_truncation_t* self = (grib_accessor_spectral_truncation_t*)a; + int n = 0; + + self->J = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->K = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->M = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->T = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; +} + +int grib_accessor_class_spectral_truncation_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_accessor_spectral_truncation_t* self = (grib_accessor_spectral_truncation_t*)a; + int ret = 0; + + long J, K, M, T, Tc; + + if (*len < 1) + return GRIB_ARRAY_TOO_SMALL; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->J, &J)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->K, &K)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->M, &M)) != GRIB_SUCCESS) + return ret; + + Tc = -1; + if (J == K && K == M) { + /* Triangular truncation */ + Tc = (M + 1) * (M + 2); + } + if (K == J + M) { + /* Rhomboidal truncation */ + Tc = 2 * J * M; + } + if (J == K && K > M) { + /* Trapezoidal truncation */ + Tc = M * (2 * J - M); + } + *val = Tc; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->T, &T)) != GRIB_SUCCESS) { + if (Tc == -1) + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s. Spectral Truncation Type Unknown: %s=%ld %s=%ld %s=%ld", + a->name, self->J, J, self->K, K, self->M, M); + Tc = 0; + grib_set_long(grib_handle_of_accessor(a), self->T, Tc); + } + else { + if (Tc != -1 && Tc != T) + grib_set_long(grib_handle_of_accessor(a), self->T, Tc); + } + + if (ret == GRIB_SUCCESS) + *len = 1; + + return ret; +} diff --git a/src/accessor/grib_accessor_class_spectral_truncation.h b/src/accessor/grib_accessor_class_spectral_truncation.h new file mode 100644 index 000000000..c9f85b9f8 --- /dev/null +++ b/src/accessor/grib_accessor_class_spectral_truncation.h @@ -0,0 +1,33 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_spectral_truncation_t : public grib_accessor_long_t +{ +public: + /* Members defined in spectral_truncation */ + const char* J; + const char* K; + const char* M; + const char* T; +}; + +class grib_accessor_class_spectral_truncation_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_spectral_truncation_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_spectral_truncation_t{}; } + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_sprintf.cc b/src/accessor/grib_accessor_class_sprintf.cc similarity index 54% rename from src/grib_accessor_class_sprintf.cc rename to src/accessor/grib_accessor_class_sprintf.cc index 106ce1e4d..cc9e37e6a 100644 --- a/src/grib_accessor_class_sprintf.cc +++ b/src/accessor/grib_accessor_class_sprintf.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,109 +9,21 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_ascii - IMPLEMENTS = unpack_string;value_count - IMPLEMENTS = init;string_length - MEMBERS= grib_arguments* args - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_string(grib_accessor*, char*, size_t* len); -static size_t string_length(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_sprintf -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in ascii */ - /* Members defined in sprintf */ - grib_arguments* args; -} grib_accessor_sprintf; - -extern grib_accessor_class* grib_accessor_class_ascii; - -static grib_accessor_class _grib_accessor_class_sprintf = { - &grib_accessor_class_ascii, /* super */ - "sprintf", /* name */ - sizeof(grib_accessor_sprintf), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - &string_length, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_sprintf.h" +grib_accessor_class_sprintf_t _grib_accessor_class_sprintf{"sprintf"}; grib_accessor_class* grib_accessor_class_sprintf = &_grib_accessor_class_sprintf; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_sprintf* self = (grib_accessor_sprintf*)a; +void grib_accessor_class_sprintf_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_ascii_t::init(a, l, c); + grib_accessor_sprintf_t* self = (grib_accessor_sprintf_t*)a; self->args = c; a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - grib_accessor_sprintf* self = (grib_accessor_sprintf*)a; +int grib_accessor_class_sprintf_t::unpack_string(grib_accessor* a, char* val, size_t* len){ + grib_accessor_sprintf_t* self = (grib_accessor_sprintf_t*)a; char result[1024]; char tempBuffer[2048]; char sres[1024]; @@ -148,8 +61,7 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len) if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), tempname, &ires)) != GRIB_SUCCESS) return ret; /* Bug GRIB-56: Check to see if the key is missing */ - is_missing = grib_is_missing(grib_handle_of_accessor(a), tempname, &ret); - if (ret != GRIB_SUCCESS) + is_missing = grib_is_missing(grib_handle_of_accessor(a), tempname, &ret); if (ret != GRIB_SUCCESS) return ret; if (is_missing) { snprintf(tempBuffer, sizeof(tempBuffer), "%sMISSING", result); @@ -205,13 +117,11 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len) return GRIB_SUCCESS; } -static int value_count(grib_accessor* a, long* count) -{ +int grib_accessor_class_sprintf_t::value_count(grib_accessor* a, long* count){ *count = 1; return 0; } -static size_t string_length(grib_accessor* a) -{ +size_t grib_accessor_class_sprintf_t::string_length(grib_accessor* a){ return 1024; } diff --git a/src/accessor/grib_accessor_class_sprintf.h b/src/accessor/grib_accessor_class_sprintf.h new file mode 100644 index 000000000..36d5f3e10 --- /dev/null +++ b/src/accessor/grib_accessor_class_sprintf.h @@ -0,0 +1,32 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_ascii.h" + +class grib_accessor_sprintf_t : public grib_accessor_ascii_t +{ +public: + /* Members defined in sprintf */ + grib_arguments* args; +}; + +class grib_accessor_class_sprintf_t : public grib_accessor_class_ascii_t +{ +public: + grib_accessor_class_sprintf_t(const char* name) : grib_accessor_class_ascii_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_sprintf_t{}; } + int unpack_string(grib_accessor*, char*, size_t* len) override; + size_t string_length(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_statistics.cc b/src/accessor/grib_accessor_class_statistics.cc similarity index 55% rename from src/grib_accessor_class_statistics.cc rename to src/accessor/grib_accessor_class_statistics.cc index 915701a3a..2d5cfd756 100644 --- a/src/grib_accessor_class_statistics.cc +++ b/src/accessor/grib_accessor_class_statistics.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,116 +9,15 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -/************************************** - * Enrico Fucile - **************************************/ - - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_abstract_vector - IMPLEMENTS = unpack_double; destroy - IMPLEMENTS = unpack_string - IMPLEMENTS = value_count;compare - IMPLEMENTS = init - MEMBERS = const char* values - MEMBERS = const char* missing_value - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static int value_count(grib_accessor*, long*); -static void destroy(grib_context*, grib_accessor*); -static void init(grib_accessor*, const long, grib_arguments*); -static int compare(grib_accessor*, grib_accessor*); - -typedef struct grib_accessor_statistics -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in abstract_vector */ - double* v; - int number_of_elements; - /* Members defined in statistics */ - const char* values; - const char* missing_value; -} grib_accessor_statistics; - -extern grib_accessor_class* grib_accessor_class_abstract_vector; - -static grib_accessor_class _grib_accessor_class_statistics = { - &grib_accessor_class_abstract_vector, /* super */ - "statistics", /* name */ - sizeof(grib_accessor_statistics), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - &destroy, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - &compare, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +#include "grib_accessor_class_statistics.h" +grib_accessor_class_statistics_t _grib_accessor_class_statistics{"statistics"}; grib_accessor_class* grib_accessor_class_statistics = &_grib_accessor_class_statistics; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_statistics* self = (grib_accessor_statistics*)a; +void grib_accessor_class_statistics_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_abstract_vector_t::init(a, l, c); + grib_accessor_statistics_t* self = (grib_accessor_statistics_t*)a; int n = 0; self->missing_value = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); @@ -134,9 +34,8 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) a->dirty = 1; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_statistics* self = (grib_accessor_statistics*)a; +int grib_accessor_class_statistics_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + grib_accessor_statistics_t* self = (grib_accessor_statistics_t*)a; int ret = 0; double* values = NULL; size_t i = 0, size = 0, real_size = 0; @@ -157,7 +56,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) return ret; grib_context_log(a->context, GRIB_LOG_DEBUG, - "grib_accessor_statistics: computing statistics for %d values", size); + "grib_accessor_statistics_t: computing statistics for %d values", size); if ((ret = grib_get_double(h, self->missing_value, &missing)) != GRIB_SUCCESS) return ret; @@ -267,21 +166,19 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) return ret; } -static int value_count(grib_accessor* a, long* count) -{ - grib_accessor_statistics* self = (grib_accessor_statistics*)a; +int grib_accessor_class_statistics_t::value_count(grib_accessor* a, long* count){ + grib_accessor_statistics_t* self = (grib_accessor_statistics_t*)a; *count = self->number_of_elements; return 0; } -static void destroy(grib_context* c, grib_accessor* a) -{ - grib_accessor_statistics* self = (grib_accessor_statistics*)a; +void grib_accessor_class_statistics_t::destroy(grib_context* c, grib_accessor* a){ + grib_accessor_statistics_t* self = (grib_accessor_statistics_t*)a; grib_context_free(c, self->v); + grib_accessor_class_abstract_vector_t::destroy(c, a); } -static int compare(grib_accessor* a, grib_accessor* b) -{ +int grib_accessor_class_statistics_t::compare(grib_accessor* a, grib_accessor* b){ int retval = GRIB_SUCCESS; double* aval = 0; double* bval = 0; @@ -291,13 +188,11 @@ static int compare(grib_accessor* a, grib_accessor* b) int err = 0; long count = 0; - err = grib_value_count(a, &count); - if (err) + err = a->value_count(&count); if (err) return err; alen = count; - err = grib_value_count(b, &count); - if (err) + err = b->value_count(&count); if (err) return err; blen = count; @@ -310,9 +205,7 @@ static int compare(grib_accessor* a, grib_accessor* b) b->dirty = 1; a->dirty = 1; - grib_unpack_double(a, aval, &alen); - grib_unpack_double(b, bval, &blen); - + a->unpack_double(aval, &alen); b->unpack_double(bval, &blen); retval = GRIB_SUCCESS; for (size_t i=0; ivalues = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->J = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->K = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->M = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->JS = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; + + self->number_of_elements = 4; + self->v = (double*)grib_context_malloc(a->context, + sizeof(double) * self->number_of_elements); + + a->length = 0; + a->dirty = 1; +} + +int grib_accessor_class_statistics_spectral_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + grib_accessor_statistics_spectral_t* self = (grib_accessor_statistics_spectral_t*)a; + int ret = 0, i = 0; + double* values; + size_t size = 0; + long J, K, M, N; + double avg, enorm, sd; + grib_context* c = a->context; + grib_handle* h = grib_handle_of_accessor(a); + + if (!a->dirty) + return GRIB_SUCCESS; + + if (*len != self->number_of_elements) + return GRIB_ARRAY_TOO_SMALL; + + if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_get_long(grib_handle_of_accessor(a), self->J, &J)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_get_long(grib_handle_of_accessor(a), self->K, &K)) != GRIB_SUCCESS) + return ret; + + if ((ret = grib_get_long(grib_handle_of_accessor(a), self->M, &M)) != GRIB_SUCCESS) + return ret; + + if (J != M || M != K) + return GRIB_NOT_IMPLEMENTED; + + N = (M + 1) * (M + 2) / 2; + + if (2 * N != size) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "wrong number of components for spherical harmonics %ld != %ld", 2 * N, size); + return GRIB_WRONG_ARRAY_SIZE; + } + + values = (double*)grib_context_malloc(c, size * sizeof(double)); + if (!values) + return GRIB_OUT_OF_MEMORY; + + if ((ret = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) { + grib_context_free(c, values); + return ret; + } + + avg = values[0]; + sd = 0; + + for (i = 2; i < 2 * J; i += 2) + sd += values[i] * values[i]; + + for (i = 2 * J; i < size; i += 2) + sd += 2 * values[i] * values[i] + 2 * values[i + 1] * values[i + 1]; + + enorm = sd + avg * avg; + + sd = sqrt(sd); + enorm = sqrt(enorm); + + a->dirty = 0; + + grib_context_free(c, values); + + self->v[0] = avg; + self->v[1] = enorm; + self->v[2] = sd; + self->v[3] = sd == 0 ? 1 : 0; + + for (i = 0; i < self->number_of_elements; i++) + val[i] = self->v[i]; + + return ret; +} + +int grib_accessor_class_statistics_spectral_t::value_count(grib_accessor* a, long* count){ + grib_accessor_statistics_spectral_t* self = (grib_accessor_statistics_spectral_t*)a; + *count = self->number_of_elements; + return 0; +} + +void grib_accessor_class_statistics_spectral_t::destroy(grib_context* c, grib_accessor* a){ + grib_accessor_statistics_spectral_t* self = (grib_accessor_statistics_spectral_t*)a; + grib_context_free(c, self->v); + grib_accessor_class_abstract_vector_t::destroy(c, a); +} + +int grib_accessor_class_statistics_spectral_t::compare(grib_accessor* a, grib_accessor* b){ + int retval = GRIB_SUCCESS; + double* aval = 0; + double* bval = 0; + + size_t alen = 0; + size_t blen = 0; + int err = 0; + long count = 0; + + err = a->value_count(&count); if (err) + return err; + alen = count; + + err = b->value_count(&count); if (err) + return err; + blen = count; + + if (alen != blen) + return GRIB_COUNT_MISMATCH; + + aval = (double*)grib_context_malloc(a->context, alen * sizeof(double)); + bval = (double*)grib_context_malloc(b->context, blen * sizeof(double)); + + b->dirty = 1; + a->dirty = 1; + + a->unpack_double(aval, &alen); b->unpack_double(bval, &blen); + retval = GRIB_SUCCESS; + for (size_t i=0; icontext, aval); + grib_context_free(b->context, bval); + + return retval; +} diff --git a/src/accessor/grib_accessor_class_statistics_spectral.h b/src/accessor/grib_accessor_class_statistics_spectral.h new file mode 100644 index 000000000..41846c5c7 --- /dev/null +++ b/src/accessor/grib_accessor_class_statistics_spectral.h @@ -0,0 +1,37 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_abstract_vector.h" + +class grib_accessor_statistics_spectral_t : public grib_accessor_abstract_vector_t +{ +public: + /* Members defined in statistics_spectral */ + const char* values; + const char* J; + const char* K; + const char* M; + const char* JS; +}; + +class grib_accessor_class_statistics_spectral_t : public grib_accessor_class_abstract_vector_t +{ +public: + grib_accessor_class_statistics_spectral_t(const char* name) : grib_accessor_class_abstract_vector_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_statistics_spectral_t{}; } + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void destroy(grib_context*, grib_accessor*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + int compare(grib_accessor*, grib_accessor*) override; +}; diff --git a/src/accessor/grib_accessor_class_step_human_readable.cc b/src/accessor/grib_accessor_class_step_human_readable.cc new file mode 100644 index 000000000..18dec9c14 --- /dev/null +++ b/src/accessor/grib_accessor_class_step_human_readable.cc @@ -0,0 +1,87 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_step_human_readable.h" + +grib_accessor_class_step_human_readable_t _grib_accessor_class_step_human_readable{ "step_human_readable" }; +grib_accessor_class* grib_accessor_class_step_human_readable = &_grib_accessor_class_step_human_readable; + + +void grib_accessor_class_step_human_readable_t::init(grib_accessor* a, const long len, grib_arguments* params) +{ + grib_accessor_class_gen_t::init(a, len, params); + grib_accessor_step_human_readable_t* self = (grib_accessor_step_human_readable_t*)a; + int n = 0; + grib_handle* h = grib_handle_of_accessor(a); + + self->stepUnits = grib_arguments_get_name(h, params, n++); + self->step = grib_arguments_get_name(h, params, n++); + a->length = 0; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; +} + +int grib_accessor_class_step_human_readable_t::get_native_type(grib_accessor* a) +{ + return GRIB_TYPE_STRING; +} + +static int get_step_human_readable(grib_handle* h, char* result, size_t* length) +{ + int err = 0; + size_t slen = 2; + long step, hour, minute, second; + + /* Change units to seconds (highest resolution) + * before computing the step value + */ + if ((err = grib_set_string(h, "stepUnits", "s", &slen)) != GRIB_SUCCESS) + return err; + if ((err = grib_get_long(h, "step", &step)) != GRIB_SUCCESS) + return err; + + hour = step / 3600; + minute = step / 60 % 60; + second = step % 60; + /* sprintf(result, "%ld:%ld:%ld", hour, minute, second); */ + + if (second) { + snprintf(result, 1024, "%ldh %ldm %lds", hour, minute, second); + } + else { + if (minute) + snprintf(result, 1024, "%ldh %ldm", hour, minute); + else + snprintf(result, 1024, "%ldh", hour); + } + + *length = strlen(result); + return GRIB_SUCCESS; +} + +int grib_accessor_class_step_human_readable_t::unpack_string(grib_accessor* a, char* buffer, size_t* len) +{ + grib_accessor_step_human_readable_t* self = (grib_accessor_step_human_readable_t*)a; + + grib_handle* h = grib_handle_of_accessor(a); + long stepUnits = 0; + int err = 0; + + /* Save the current value of stepUnits */ + err = grib_get_long_internal(h, self->stepUnits, &stepUnits); + if (err) return err; + + /* This will change stepUnits to seconds for its calculation */ + err = get_step_human_readable(h, buffer, len); + + /* Restore stepUnits */ + grib_set_long(h, self->stepUnits, stepUnits); + return err; +} diff --git a/src/accessor/grib_accessor_class_step_human_readable.h b/src/accessor/grib_accessor_class_step_human_readable.h new file mode 100644 index 000000000..cbd61ed31 --- /dev/null +++ b/src/accessor/grib_accessor_class_step_human_readable.h @@ -0,0 +1,32 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_step_human_readable_t : public grib_accessor_gen_t +{ +public: + /* Members defined in step_human_readable */ + const char* stepUnits; + const char* step; +}; + +class grib_accessor_class_step_human_readable_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_step_human_readable_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_step_human_readable_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_step_in_units.cc b/src/accessor/grib_accessor_class_step_in_units.cc similarity index 63% rename from src/grib_accessor_class_step_in_units.cc rename to src/accessor/grib_accessor_class_step_in_units.cc index a25c85aec..52086d700 100644 --- a/src/grib_accessor_class_step_in_units.cc +++ b/src/accessor/grib_accessor_class_step_in_units.cc @@ -1,3 +1,4 @@ + /* * (C) Copyright 2005- ECMWF. * @@ -8,121 +9,18 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" +#include "grib_accessor_class_step_in_units.h" #include "step.h" #include "step_utilities.h" #include -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = unpack_double - IMPLEMENTS = unpack_string;pack_string - IMPLEMENTS = init;dump - IMPLEMENTS = get_native_type - MEMBERS = const char* forecast_time_value - MEMBERS = const char* forecast_time_unit - MEMBERS = const char* step_units - MEMBERS = const char* time_range_unit - MEMBERS = const char* time_range_value - - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int pack_string(grib_accessor*, const char*, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_step_in_units -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in step_in_units */ - const char* forecast_time_value; - const char* forecast_time_unit; - const char* step_units; - const char* time_range_unit; - const char* time_range_value; -} grib_accessor_step_in_units; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_step_in_units = { - &grib_accessor_class_long, /* super */ - "step_in_units", /* name */ - sizeof(grib_accessor_step_in_units), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - &pack_string, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - +grib_accessor_class_step_in_units_t _grib_accessor_class_step_in_units{"step_in_units"}; grib_accessor_class* grib_accessor_class_step_in_units = &_grib_accessor_class_step_in_units; -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_class_step_in_units_t::init(grib_accessor* a, const long l, grib_arguments* c) { - grib_accessor_step_in_units* self = (grib_accessor_step_in_units*)a; + grib_accessor_class_long_t::init(a, l, c); + grib_accessor_step_in_units_t* self = (grib_accessor_step_in_units_t*)a; grib_handle* hand = grib_handle_of_accessor(a); int n = 0; @@ -133,14 +31,14 @@ static void init(grib_accessor* a, const long l, grib_arguments* c) self->time_range_value = grib_arguments_get_name(hand, c, n++); } -static void dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_class_step_in_units_t::dump(grib_accessor* a, grib_dumper* dumper) { grib_dump_double(dumper, a, NULL); } -static int unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_class_step_in_units_t::unpack_long(grib_accessor* a, long* val, size_t* len) { - const grib_accessor_step_in_units* self = (grib_accessor_step_in_units*)a; + const grib_accessor_step_in_units_t* self = (grib_accessor_step_in_units_t*)a; int err = 0; long forecast_time_value, forecast_time_unit, step_units; grib_handle* h = grib_handle_of_accessor(a); @@ -169,9 +67,9 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) return GRIB_SUCCESS; } -static int unpack_double(grib_accessor* a, double * val, size_t* len) +int grib_accessor_class_step_in_units_t::unpack_double(grib_accessor* a, double * val, size_t* len) { - const grib_accessor_step_in_units* self = (grib_accessor_step_in_units*)a; + const grib_accessor_step_in_units_t* self = (grib_accessor_step_in_units_t*)a; int err = 0; long forecast_time_value, forecast_time_unit, step_units; grib_handle* h = grib_handle_of_accessor(a); @@ -199,9 +97,9 @@ static int unpack_double(grib_accessor* a, double * val, size_t* len) return GRIB_SUCCESS; } -static int pack_long_new_(grib_accessor* a, const long start_step_value, const long start_step_unit, const long force_step_units) +int pack_long_new_(grib_accessor* a, const long start_step_value, const long start_step_unit, const long force_step_units) { - const grib_accessor_step_in_units* self = (grib_accessor_step_in_units*)a; + const grib_accessor_step_in_units_t* self = (grib_accessor_step_in_units_t*)a; grib_handle* h = grib_handle_of_accessor(a); int err = 0; long forecast_time_unit; @@ -211,7 +109,7 @@ static int pack_long_new_(grib_accessor* a, const long start_step_value, const l if ((err = grib_get_long_internal(h, self->forecast_time_unit, &forecast_time_unit)) != GRIB_SUCCESS) return err; - if ((err = unpack_long(a, &start_step_value_old, &len)) != GRIB_SUCCESS) + if ((err = a->unpack_long(&start_step_value_old, &len)) != GRIB_SUCCESS) return err; if ((err = grib_get_long_internal(h, "startStepUnit", &start_step_unit_old)) != GRIB_SUCCESS) return err; @@ -249,7 +147,7 @@ static int pack_long_new_(grib_accessor* a, const long start_step_value, const l return GRIB_SUCCESS; } -static int pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_class_step_in_units_t::pack_long(grib_accessor* a, const long* val, size_t* len) { grib_handle* h = grib_handle_of_accessor(a); int ret = GRIB_SUCCESS; @@ -281,7 +179,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) return ret; } -static int pack_string(grib_accessor* a, const char* val, size_t* len) +int grib_accessor_class_step_in_units_t::pack_string(grib_accessor* a, const char* val, size_t* len) { grib_handle* h = grib_handle_of_accessor(a); //long force_step_units = eccodes::Unit(eccodes::Unit::Value::MISSING).value(); @@ -303,9 +201,9 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len) return GRIB_SUCCESS; } -static int unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_class_step_in_units_t::unpack_string(grib_accessor* a, char* val, size_t* len) { - const grib_accessor_step_in_units* self = (grib_accessor_step_in_units*)a; + const grib_accessor_step_in_units_t* self = (grib_accessor_step_in_units_t*)a; grib_handle* h = grib_handle_of_accessor(a); int ret = GRIB_SUCCESS; long start_step_value = 0; @@ -347,7 +245,7 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len) return GRIB_SUCCESS; } -static int get_native_type(grib_accessor* a) +int grib_accessor_class_step_in_units_t::get_native_type(grib_accessor* a) { grib_handle* h = grib_handle_of_accessor(a); const int show_units_for_hours = a->context->grib_hourly_steps_with_units; diff --git a/src/accessor/grib_accessor_class_step_in_units.h b/src/accessor/grib_accessor_class_step_in_units.h new file mode 100644 index 000000000..66f4b2b44 --- /dev/null +++ b/src/accessor/grib_accessor_class_step_in_units.h @@ -0,0 +1,40 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_step_in_units_t : public grib_accessor_long_t +{ +public: + /* Members defined in step_in_units */ + const char* forecast_time_value; + const char* forecast_time_unit; + const char* step_units; + const char* time_range_unit; + const char* time_range_value; +}; + +class grib_accessor_class_step_in_units_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_step_in_units_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_step_in_units_t{}; } + int get_native_type(grib_accessor*) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int pack_string(grib_accessor*, const char*, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_sum.cc b/src/accessor/grib_accessor_class_sum.cc new file mode 100644 index 000000000..39b96854f --- /dev/null +++ b/src/accessor/grib_accessor_class_sum.cc @@ -0,0 +1,107 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_sum.h" + +grib_accessor_class_sum_t _grib_accessor_class_sum{"sum"}; +grib_accessor_class* grib_accessor_class_sum = &_grib_accessor_class_sum; + + +void grib_accessor_class_sum_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_double_t::init(a, l, c); + grib_accessor_sum_t* self = (grib_accessor_sum_t*)a; + int n = 0; + self->values = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + a->length = 0; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; +} + +int grib_accessor_class_sum_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_accessor_sum_t* self = (grib_accessor_sum_t*)a; + int ret = 0; + size_t size = 0; + long* values = 0; + long i; + long count = 0; + + ret = value_count(a, &count); + if (ret) + return ret; + size = count; + + if (size == 0) { + *val = 0; + return GRIB_SUCCESS; + } + values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); + if (!values) + return GRIB_OUT_OF_MEMORY; + + grib_get_long_array(grib_handle_of_accessor(a), self->values, values, &size); + + *val = 0; + for (i = 0; i < size; i++) + *val += values[i]; + + grib_context_free(a->context, values); + + return GRIB_SUCCESS; +} + +int grib_accessor_class_sum_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + grib_accessor_sum_t* self = (grib_accessor_sum_t*)a; + int ret = 0; + size_t size = 0; + double* values = 0; + long i; + long count = 0; + + ret = value_count(a, &count); + if (ret) + return ret; + size = count; + + if (size == 0) { + *val = 0; + return GRIB_SUCCESS; + } + values = (double*)grib_context_malloc_clear(a->context, sizeof(double) * size); + if (!values) + return GRIB_OUT_OF_MEMORY; + + ret = grib_get_double_array(grib_handle_of_accessor(a), self->values, values, &size); + if (ret) { + grib_context_free(a->context, values); + return ret; + } + *val = 0; + for (i = 0; i < size; i++) + *val += values[i]; + + grib_context_free(a->context, values); + + return GRIB_SUCCESS; +} + +int grib_accessor_class_sum_t::value_count(grib_accessor* a, long* count){ + grib_accessor_sum_t* self = (grib_accessor_sum_t*)a; + size_t n = 0; + int ret = 0; + + ret = grib_get_size(grib_handle_of_accessor(a), self->values, &n); + *count = n; + + if (ret) + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s is unable to get size of %s", a->name, self->values); + + return ret; +} diff --git a/src/accessor/grib_accessor_class_sum.h b/src/accessor/grib_accessor_class_sum.h new file mode 100644 index 000000000..5667d8da9 --- /dev/null +++ b/src/accessor/grib_accessor_class_sum.h @@ -0,0 +1,32 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_double.h" + +class grib_accessor_sum_t : public grib_accessor_double_t +{ +public: + /* Members defined in sum */ + const char* values; +}; + +class grib_accessor_class_sum_t : public grib_accessor_class_double_t +{ +public: + grib_accessor_class_sum_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_sum_t{}; } + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_suppressed.cc b/src/accessor/grib_accessor_class_suppressed.cc new file mode 100644 index 000000000..10a99ee64 --- /dev/null +++ b/src/accessor/grib_accessor_class_suppressed.cc @@ -0,0 +1,72 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_suppressed.h" + +grib_accessor_class_suppressed_t _grib_accessor_class_suppressed{ "suppressed" }; +grib_accessor_class* grib_accessor_class_suppressed = &_grib_accessor_class_suppressed; + + +void grib_accessor_class_suppressed_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ + grib_accessor_class_long_t::init(a, l, c); + grib_accessor_suppressed_t* self = (grib_accessor_suppressed_t*)a; + self->args = c; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; + a->length = 0; +} + +static void log_message(grib_accessor* a) +{ + grib_accessor_suppressed_t* self = (grib_accessor_suppressed_t*)a; + int i = 0; + grib_handle* hand = grib_handle_of_accessor(a); + + grib_context_log(a->context, GRIB_LOG_ERROR, + "key '%s' is unavailable in this version.", a->name); + grib_context_log(a->context, GRIB_LOG_ERROR, + "Please use the following key(s):"); + while (grib_arguments_get_name(hand, self->args, i)) { + grib_context_log(a->context, GRIB_LOG_ERROR, "\t- %s", + grib_arguments_get_name(hand, self->args, i)); + i++; + } +} + +int grib_accessor_class_suppressed_t::unpack_string(grib_accessor* a, char* val, size_t* len) +{ + log_message(a); + return GRIB_NOT_FOUND; +} + +int grib_accessor_class_suppressed_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ + log_message(a); + return GRIB_NOT_FOUND; +} + +int grib_accessor_class_suppressed_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ + log_message(a); + return GRIB_NOT_FOUND; +} + +int grib_accessor_class_suppressed_t::value_count(grib_accessor* a, long* count) +{ + *count = 1; + return 0; +} + +int grib_accessor_class_suppressed_t::get_native_type(grib_accessor* a) +{ + return GRIB_TYPE_STRING; +} diff --git a/src/accessor/grib_accessor_class_suppressed.h b/src/accessor/grib_accessor_class_suppressed.h new file mode 100644 index 000000000..5d764be35 --- /dev/null +++ b/src/accessor/grib_accessor_class_suppressed.h @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_suppressed_t : public grib_accessor_long_t +{ +public: + /* Members defined in suppressed */ + grib_arguments* args; +}; + +class grib_accessor_class_suppressed_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_suppressed_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_suppressed_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_time.cc b/src/accessor/grib_accessor_class_time.cc new file mode 100644 index 000000000..debb1a2f4 --- /dev/null +++ b/src/accessor/grib_accessor_class_time.cc @@ -0,0 +1,113 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_time.h" + +grib_accessor_class_time_t _grib_accessor_class_time{"time"}; +grib_accessor_class* grib_accessor_class_time = &_grib_accessor_class_time; + + +void grib_accessor_class_time_t::init(grib_accessor* a, const long l, grib_arguments* c){ + grib_accessor_class_long_t::init(a, l, c); + grib_accessor_time_t* self = (grib_accessor_time_t*)a; + grib_handle* hand = grib_handle_of_accessor(a); + int n = 0; + + self->hour = grib_arguments_get_name(hand, c, n++); + self->minute = grib_arguments_get_name(hand, c, n++); + self->second = grib_arguments_get_name(hand, c, n++); +} + +int grib_accessor_class_time_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + const grib_accessor_time_t* self = (grib_accessor_time_t*)a; + + int ret = 0; + long hour = 0, minute = 0, second = 0; + grib_handle* hand = grib_handle_of_accessor(a); + + if ((ret = grib_get_long_internal(hand, self->hour, &hour)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_get_long_internal(hand, self->minute, &minute)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_get_long_internal(hand, self->second, &second)) != GRIB_SUCCESS) + return ret; + + /* We ignore the 'seconds' in our time calculation! */ + if (second != 0) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "Key %s (%s): Truncating time: non-zero seconds(%ld) ignored", a->name, __func__, second); + } + + if (*len < 1) + return GRIB_WRONG_ARRAY_SIZE; + + *val = hour * 100 + minute; + + if (hour == 255) { + *val = 12 * 100; + } + if (hour != 255 && minute == 255) { + *val = hour * 100; + } + return GRIB_SUCCESS; +} + +int grib_accessor_class_time_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + const grib_accessor_time_t* self = (grib_accessor_time_t*)a; + + int ret = 0; + long v = val[0]; + grib_handle* hand = grib_handle_of_accessor(a); + long hour = 0, minute = 0, second = 0; + + if (*len != 1) + return GRIB_WRONG_ARRAY_SIZE; + + if (!is_time_valid(v)) { + // ECC-1777: For now just a warning. Will later change to an error + fprintf(stderr, "ECCODES WARNING : %s:%s: Time is not valid! hour=%ld min=%ld sec=%ld\n", + a->cclass->name, __func__, hour, minute, second); + // return GRIB_ENCODING_ERROR; + } + + hour = v / 100; + minute = v % 100; + second = 0; /* We ignore the 'seconds' in our time calculation! */ + + if ((ret = grib_set_long_internal(hand, self->hour, hour)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_set_long_internal(hand, self->minute, minute)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_set_long_internal(hand, self->second, second)) != GRIB_SUCCESS) + return ret; + + return GRIB_SUCCESS; +} + +int grib_accessor_class_time_t::unpack_string(grib_accessor* a, char* val, size_t* len){ + long v = 0; + size_t lsize = 1, lmin = 5; + + unpack_long(a, &v, &lsize); + + if (*len < lmin) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", + a->cclass->name, a->name, lmin, *len); + *len = lmin; + return GRIB_BUFFER_TOO_SMALL; + } + + snprintf(val, 64, "%04ld", v); + + len[0] = lmin; + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_time.h b/src/accessor/grib_accessor_class_time.h new file mode 100644 index 000000000..dee0325a9 --- /dev/null +++ b/src/accessor/grib_accessor_class_time.h @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_time_t : public grib_accessor_long_t +{ +public: + /* Members defined in time */ + const char* hour; + const char* minute; + const char* second; +}; + +class grib_accessor_class_time_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_time_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_time_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_to_double.cc b/src/accessor/grib_accessor_class_to_double.cc new file mode 100644 index 000000000..854a32ffc --- /dev/null +++ b/src/accessor/grib_accessor_class_to_double.cc @@ -0,0 +1,130 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_to_double.h" + +grib_accessor_class_to_double_t _grib_accessor_class_to_double{"to_double"}; +grib_accessor_class* grib_accessor_class_to_double = &_grib_accessor_class_to_double; + + +void grib_accessor_class_to_double_t::init(grib_accessor* a, const long len, grib_arguments* arg){ + grib_accessor_class_gen_t::init(a, len, arg); + grib_accessor_to_double_t* self = (grib_accessor_to_double_t*)a; + + self->key = grib_arguments_get_name(grib_handle_of_accessor(a), arg, 0); + self->start = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 1); + self->length = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 2); + self->scale = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 3); + if (!self->scale) + self->scale = 1; + + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->length = 0; +} + +int grib_accessor_class_to_double_t::value_count(grib_accessor* a, long* count){ + grib_accessor_to_double_t* self = (grib_accessor_to_double_t*)a; + size_t size = 0; + + int err = grib_get_size(grib_handle_of_accessor(a), self->key, &size); + *count = size; + + return err; +} + +size_t grib_accessor_class_to_double_t::string_length(grib_accessor* a){ + grib_accessor_to_double_t* self = (grib_accessor_to_double_t*)a; + size_t size = 0; + + if (self->length) + return self->length; + + grib_get_string_length_acc(a, &size); + return size; +} + +void grib_accessor_class_to_double_t::dump(grib_accessor* a, grib_dumper* dumper){ + grib_dump_string(dumper, a, NULL); +} + +int grib_accessor_class_to_double_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_LONG; +} + +int grib_accessor_class_to_double_t::unpack_string(grib_accessor* a, char* val, size_t* len){ + grib_accessor_to_double_t* self = (grib_accessor_to_double_t*)a; + + int err = 0; + char buff[512] = {0,}; + size_t size = 512; + size_t length = string_length(a); + + if (*len < length + 1) { + grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%lu) for %s, it contains %ld values", + *len, a->name, a->length + 1); + *len = length + 1; + return GRIB_ARRAY_TOO_SMALL; + } + + err = grib_get_string(grib_handle_of_accessor(a), self->key, buff, &size); + if (err) + return err; + if (length > size) { + err = GRIB_STRING_TOO_SMALL; + length = size; + } + + memcpy(val, buff + self->start, length); + + val[length] = 0; + *len = length; + return err; +} + +int grib_accessor_class_to_double_t::unpack_long(grib_accessor* a, long* v, size_t* len){ + grib_accessor_to_double_t* self = (grib_accessor_to_double_t*)a; + char val[1024] = {0,}; + size_t l = sizeof(val); + char* last = NULL; + int err = a->unpack_string(val, &l); + if (err) + return err; + + *v = strtol(val, &last, 10); + if (*last) { + err = GRIB_WRONG_CONVERSION; + } + *v /= self->scale; + + return err; +} + +int grib_accessor_class_to_double_t::unpack_double(grib_accessor* a, double* v, size_t* len){ + grib_accessor_to_double_t* self = (grib_accessor_to_double_t*)a; + char val[1024] = {0,}; + size_t l = sizeof(val); + char* last = NULL; + int err = a->unpack_string(val, &l); + if (err) + return err; + + *v = strtod(val, &last); + if (*last) { + err = GRIB_WRONG_CONVERSION; + } + *v /= self->scale; + + return err; +} + +long grib_accessor_class_to_double_t::next_offset(grib_accessor* a){ + return a->offset + a->length; +} diff --git a/src/accessor/grib_accessor_class_to_double.h b/src/accessor/grib_accessor_class_to_double.h new file mode 100644 index 000000000..c8755c90f --- /dev/null +++ b/src/accessor/grib_accessor_class_to_double.h @@ -0,0 +1,40 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_to_double_t : public grib_accessor_gen_t +{ +public: + /* Members defined in to_double */ + const char* key; + long start; + size_t length; + long scale; +}; + +class grib_accessor_class_to_double_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_to_double_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_to_double_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + size_t string_length(grib_accessor*) override; + long next_offset(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_to_integer.cc b/src/accessor/grib_accessor_class_to_integer.cc new file mode 100644 index 000000000..bc58f31c6 --- /dev/null +++ b/src/accessor/grib_accessor_class_to_integer.cc @@ -0,0 +1,132 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_to_integer.h" + +grib_accessor_class_to_integer_t _grib_accessor_class_to_integer{"to_integer"}; +grib_accessor_class* grib_accessor_class_to_integer = &_grib_accessor_class_to_integer; + + +void grib_accessor_class_to_integer_t::init(grib_accessor* a, const long len, grib_arguments* arg){ + grib_accessor_class_gen_t::init(a, len, arg); + grib_accessor_to_integer_t* self = (grib_accessor_to_integer_t*)a; + + self->key = grib_arguments_get_name(grib_handle_of_accessor(a), arg, 0); + self->start = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 1); + self->length = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 2); + + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->length = 0; +} + +int grib_accessor_class_to_integer_t::value_count(grib_accessor* a, long* count){ + grib_accessor_to_integer_t* self = (grib_accessor_to_integer_t*)a; + size_t size = 0; + + int err = grib_get_size(grib_handle_of_accessor(a), self->key, &size); + *count = size; + + return err; +} + +size_t grib_accessor_class_to_integer_t::string_length(grib_accessor* a){ + grib_accessor_to_integer_t* self = (grib_accessor_to_integer_t*)a; + size_t size = 0; + + if (self->length) + return self->length; + + grib_get_string_length(grib_handle_of_accessor(a), self->key, &size); + return size; +} + +void grib_accessor_class_to_integer_t::dump(grib_accessor* a, grib_dumper* dumper){ + grib_dump_long(dumper, a, NULL); +} + +int grib_accessor_class_to_integer_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_LONG; +} + +int grib_accessor_class_to_integer_t::unpack_string(grib_accessor* a, char* val, size_t* len){ + grib_accessor_to_integer_t* self = (grib_accessor_to_integer_t*)a; + + int err = 0; + char buff[512] = {0,}; + size_t size = 512; + + size_t length = string_length(a); + + if (*len < length + 1) { + const char* cclass_name = a->cclass->name; + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", + cclass_name, a->name, length+1, *len); + *len = length + 1; + return GRIB_BUFFER_TOO_SMALL; + } + + err = grib_get_string(grib_handle_of_accessor(a), self->key, buff, &size); + if (err) + return err; + if (length > size) { + /*err=GRIB_STRING_TOO_SMALL;*/ + length = size; + } + + memcpy(val, buff + self->start, length); + + val[length] = 0; + *len = length; + return GRIB_SUCCESS; +} + +int grib_accessor_class_to_integer_t::pack_string(grib_accessor* a, const char* val, size_t* len){ + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_class_to_integer_t::pack_long(grib_accessor* a, const long* v, size_t* len){ + grib_context_log(a->context, GRIB_LOG_ERROR, "Should not pack %s as an integer", a->name); + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_class_to_integer_t::pack_double(grib_accessor* a, const double* v, size_t* len){ + grib_context_log(a->context, GRIB_LOG_ERROR, "Should not pack %s as a double", a->name); + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_class_to_integer_t::unpack_long(grib_accessor* a, long* v, size_t* len){ + char val[1024] = {0,}; + size_t l = sizeof(val); + char* last = NULL; + int err = unpack_string(a, val, &l); + + if (err) + return err; + + *v = strtol(val, &last, 10); + /* if (*last) {err=GRIB_WRONG_CONVERSION;} */ + + return GRIB_SUCCESS; +} + +int grib_accessor_class_to_integer_t::unpack_double(grib_accessor* a, double* v, size_t* len){ + size_t l = 1; + long val = 0; + int err = unpack_long(a, &val, &l); + + *v = (double)val; + return err; +} + +long grib_accessor_class_to_integer_t::next_offset(grib_accessor* a){ + return a->offset + a->length; +} diff --git a/src/accessor/grib_accessor_class_to_integer.h b/src/accessor/grib_accessor_class_to_integer.h new file mode 100644 index 000000000..da8334e4f --- /dev/null +++ b/src/accessor/grib_accessor_class_to_integer.h @@ -0,0 +1,42 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_to_integer_t : public grib_accessor_gen_t +{ +public: + /* Members defined in to_integer */ + const char* key; + long start; + size_t length; +}; + +class grib_accessor_class_to_integer_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_to_integer_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_to_integer_t{}; } + int get_native_type(grib_accessor*) override; + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int pack_string(grib_accessor*, const char*, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + size_t string_length(grib_accessor*) override; + long next_offset(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_to_string.cc b/src/accessor/grib_accessor_class_to_string.cc new file mode 100644 index 000000000..4f1150ffb --- /dev/null +++ b/src/accessor/grib_accessor_class_to_string.cc @@ -0,0 +1,120 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_to_string.h" + +grib_accessor_class_to_string_t _grib_accessor_class_to_string{"to_string"}; +grib_accessor_class* grib_accessor_class_to_string = &_grib_accessor_class_to_string; + + +void grib_accessor_class_to_string_t::init(grib_accessor* a, const long len, grib_arguments* arg){ + grib_accessor_class_gen_t::init(a, len, arg); + grib_accessor_to_string_t* self = (grib_accessor_to_string_t*)a; + + self->key = grib_arguments_get_name(grib_handle_of_accessor(a), arg, 0); + self->start = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 1); + self->length = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 2); + + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->length = 0; +} + +int grib_accessor_class_to_string_t::value_count(grib_accessor* a, long* count){ + grib_accessor_to_string_t* self = (grib_accessor_to_string_t*)a; + size_t size = 0; + + int err = grib_get_size(grib_handle_of_accessor(a), self->key, &size); + *count = size; + + return err; +} + +size_t grib_accessor_class_to_string_t::string_length(grib_accessor* a){ + grib_accessor_to_string_t* self = (grib_accessor_to_string_t*)a; + + if (self->length) + return self->length; + + size_t size = 0; + grib_get_string_length(grib_handle_of_accessor(a), self->key, &size); + return size; +} + +void grib_accessor_class_to_string_t::dump(grib_accessor* a, grib_dumper* dumper){ + grib_dump_string(dumper, a, NULL); +} + +int grib_accessor_class_to_string_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_STRING; +} + +int grib_accessor_class_to_string_t::unpack_string(grib_accessor* a, char* val, size_t* len){ + grib_accessor_to_string_t* self = (grib_accessor_to_string_t*)a; + + int err = 0; + char buff[512] = {0,}; + + size_t length = string_length(a); + + if (*len < length + 1) { + const char* cclass_name = a->cclass->name; + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", + cclass_name, a->name, length+1, *len); + *len = length + 1; + return GRIB_BUFFER_TOO_SMALL; + } + + size_t size = sizeof(buff); + err = grib_get_string(grib_handle_of_accessor(a), self->key, buff, &size); + if (err) + return err; + if (length > size) { + /*err=GRIB_STRING_TOO_SMALL;*/ + length = size; + } + + memcpy(val, buff + self->start, length); + + val[length] = 0; + *len = length; + return GRIB_SUCCESS; +} + +int grib_accessor_class_to_string_t::unpack_long(grib_accessor* a, long* v, size_t* len){ + char val[1024] = {0,}; + size_t l = sizeof(val); + char* last = NULL; + int err = unpack_string(a, val, &l); + + if (err) + return err; + + *v = strtol(val, &last, 10); + if (*last) { + err = GRIB_WRONG_CONVERSION; + } + + return err; +} + +int grib_accessor_class_to_string_t::unpack_double(grib_accessor* a, double* v, size_t* len){ + size_t l = 1; + long val = 0; + int err = unpack_long(a, &val, &l); + + *v = (double)val; + return err; +} + +long grib_accessor_class_to_string_t::next_offset(grib_accessor* a){ + return a->offset + a->length; +} diff --git a/src/accessor/grib_accessor_class_to_string.h b/src/accessor/grib_accessor_class_to_string.h new file mode 100644 index 000000000..ea6981276 --- /dev/null +++ b/src/accessor/grib_accessor_class_to_string.h @@ -0,0 +1,39 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_to_string_t : public grib_accessor_gen_t +{ +public: + /* Members defined in to_string */ + const char* key; + long start; + size_t length; +}; + +class grib_accessor_class_to_string_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_to_string_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_to_string_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + size_t string_length(grib_accessor*) override; + long next_offset(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_transient.cc b/src/accessor/grib_accessor_class_transient.cc new file mode 100644 index 000000000..0cda763d0 --- /dev/null +++ b/src/accessor/grib_accessor_class_transient.cc @@ -0,0 +1,20 @@ +/* + * (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. + */ + +#include "grib_accessor_class_transient.h" + +grib_accessor_class_transient_t _grib_accessor_class_transient{"transient"}; +grib_accessor_class* grib_accessor_class_transient = &_grib_accessor_class_transient; + + +void grib_accessor_class_transient_t::init(grib_accessor* a, const long l, grib_arguments* args) { + grib_accessor_class_variable_t::init(a, l, args); +} + diff --git a/src/accessor/grib_accessor_class_transient.h b/src/accessor/grib_accessor_class_transient.h new file mode 100644 index 000000000..e330ad686 --- /dev/null +++ b/src/accessor/grib_accessor_class_transient.h @@ -0,0 +1,25 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_variable.h" + +class grib_accessor_transient_t : public grib_accessor_variable_t { +public: +}; + +class grib_accessor_class_transient_t : public grib_accessor_class_variable_t { +public: + void init(grib_accessor* a, const long l, grib_arguments* args) override; + grib_accessor_class_transient_t(const char* name) : grib_accessor_class_variable_t(name) {}; + grib_accessor* create_empty_accessor() override { return new grib_accessor_transient_t{}; } +}; + diff --git a/src/accessor/grib_accessor_class_transient_darray.cc b/src/accessor/grib_accessor_class_transient_darray.cc new file mode 100644 index 000000000..d45ec3478 --- /dev/null +++ b/src/accessor/grib_accessor_class_transient_darray.cc @@ -0,0 +1,112 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_transient_darray.h" + +grib_accessor_class_transient_darray_t _grib_accessor_class_transient_darray{"transient_darray"}; +grib_accessor_class* grib_accessor_class_transient_darray = &_grib_accessor_class_transient_darray; + + +void grib_accessor_class_transient_darray_t::init(grib_accessor* a, const long length, grib_arguments* args){ + grib_accessor_class_gen_t::init(a, length, args); + grib_accessor_transient_darray_t* self = (grib_accessor_transient_darray_t*)a; + self->arr = NULL; + self->type = GRIB_TYPE_DOUBLE; + a->length = 0; +} + +void grib_accessor_class_transient_darray_t::dump(grib_accessor* a, grib_dumper* dumper){ + grib_dump_double(dumper, a, NULL); +} + +int grib_accessor_class_transient_darray_t::pack_double(grib_accessor* a, const double* val, size_t* len){ + grib_accessor_transient_darray_t* self = (grib_accessor_transient_darray_t*)a; + + if (self->arr) + grib_darray_delete(a->context, self->arr); + self->arr = grib_darray_new(a->context, *len, 10); + + for (size_t i = 0; i < *len; i++) + grib_darray_push(a->context, self->arr, val[i]); + + return GRIB_SUCCESS; +} + +int grib_accessor_class_transient_darray_t::pack_long(grib_accessor* a, const long* val, size_t* len){ + grib_accessor_transient_darray_t* self = (grib_accessor_transient_darray_t*)a; + + if (self->arr) + grib_darray_delete(a->context, self->arr); + self->arr = grib_darray_new(a->context, *len, 10); + + for (size_t i = 0; i < *len; i++) + grib_darray_push(a->context, self->arr, (double)val[i]); + + return GRIB_SUCCESS; +} + +int grib_accessor_class_transient_darray_t::unpack_double(grib_accessor* a, double* val, size_t* len){ + grib_accessor_transient_darray_t* self = (grib_accessor_transient_darray_t*)a; + long count = 0; + + value_count(a, &count); + + if (*len < count) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s (setting %ld, required %ld) ", a->name, *len, count); + return GRIB_ARRAY_TOO_SMALL; + } + + *len = count; + for (size_t i = 0; i < *len; i++) + val[i] = self->arr->v[i]; + + return GRIB_SUCCESS; +} + +int grib_accessor_class_transient_darray_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + grib_accessor_transient_darray_t* self = (grib_accessor_transient_darray_t*)a; + long count = 0; + + value_count(a, &count); + + if (*len < count) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s (setting %ld, required %ld) ", a->name, *len, count); + return GRIB_ARRAY_TOO_SMALL; + } + + *len = count; + for (size_t i = 0; i < *len; i++) + val[i] = (long)self->arr->v[i]; + + return GRIB_SUCCESS; +} + +void grib_accessor_class_transient_darray_t::destroy(grib_context* c, grib_accessor* a){ + grib_accessor_transient_darray_t* self = (grib_accessor_transient_darray_t*)a; + if (self->arr) + grib_darray_delete(a->context, self->arr); + grib_accessor_class_gen_t::destroy(c, a); +} + +int grib_accessor_class_transient_darray_t::value_count(grib_accessor* a, long* count){ + grib_accessor_transient_darray_t* self = (grib_accessor_transient_darray_t*)a; + if (self->arr) + *count = grib_darray_used_size(self->arr); + else + *count = 0; + + return 0; +} + +int grib_accessor_class_transient_darray_t::get_native_type(grib_accessor* a){ + const grib_accessor_transient_darray_t* self = (grib_accessor_transient_darray_t*)a; + return self->type; +} diff --git a/src/accessor/grib_accessor_class_transient_darray.h b/src/accessor/grib_accessor_class_transient_darray.h new file mode 100644 index 000000000..230dfa1a1 --- /dev/null +++ b/src/accessor/grib_accessor_class_transient_darray.h @@ -0,0 +1,38 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_transient_darray_t : public grib_accessor_gen_t +{ +public: + /* Members defined in transient_darray */ + grib_darray* arr; + int type; +}; + +class grib_accessor_class_transient_darray_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_transient_darray_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_transient_darray_t{}; } + int get_native_type(grib_accessor*) override; + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void destroy(grib_context*, grib_accessor*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_trim.cc b/src/accessor/grib_accessor_class_trim.cc new file mode 100644 index 000000000..a7db4f3ff --- /dev/null +++ b/src/accessor/grib_accessor_class_trim.cc @@ -0,0 +1,76 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_trim.h" + +grib_accessor_class_trim_t _grib_accessor_class_trim{"trim"}; +grib_accessor_class* grib_accessor_class_trim = &_grib_accessor_class_trim; + + +void grib_accessor_class_trim_t::init(grib_accessor* a, const long l, grib_arguments* arg){ + grib_accessor_class_ascii_t::init(a, l, arg); + int n = 0; + grib_accessor_trim_t* self = (grib_accessor_trim_t*)a; + grib_handle* h = grib_handle_of_accessor(a); + + self->input = grib_arguments_get_name(h, arg, n++); + self->trim_left = grib_arguments_get_long(h, arg, n++); + self->trim_right= grib_arguments_get_long(h, arg, n++); + DEBUG_ASSERT(self->trim_left == 0 || self->trim_left == 1); + DEBUG_ASSERT(self->trim_right == 0 || self->trim_right == 1); +} + +int grib_accessor_class_trim_t::unpack_string(grib_accessor* a, char* val, size_t* len){ + grib_accessor_trim_t* self = (grib_accessor_trim_t*)a; + + int err = 0; + grib_handle* h = grib_handle_of_accessor(a); + char input[256] = {0,}; + size_t size = sizeof(input) / sizeof(*input); + char* pInput = input; + + err = grib_get_string(h, self->input, input, &size); + if (err) return err; + + string_lrtrim(&pInput, self->trim_left, self->trim_right); + snprintf(val, 1024, "%s", pInput); + size = strlen(val); + *len = size + 1; + return GRIB_SUCCESS; +} + +int grib_accessor_class_trim_t::pack_string(grib_accessor* a, const char* val, size_t* len){ + char input[256] = {0,}; + + size_t inputLen = 256; + char buf[256] = {0,}; + char* pBuf = NULL; + int err; + grib_handle* h = grib_handle_of_accessor(a); + grib_accessor_trim_t* self = (grib_accessor_trim_t*)a; + grib_accessor* inputAccesstor = grib_find_accessor(h, self->input); + if (!inputAccesstor) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Accessor for %s not found", self->input); + return GRIB_NOT_FOUND; + } + + if ((err = grib_get_string(h, self->input, input, &inputLen)) != GRIB_SUCCESS) + return err; + + snprintf(buf, sizeof(buf), "%s", val); + pBuf = buf; + string_lrtrim(&pBuf, self->trim_left, self->trim_right); + + return inputAccesstor->pack_string(pBuf, len);} + +size_t grib_accessor_class_trim_t::string_length(grib_accessor* a){ + return 1024; +} diff --git a/src/accessor/grib_accessor_class_trim.h b/src/accessor/grib_accessor_class_trim.h new file mode 100644 index 000000000..d5c029a78 --- /dev/null +++ b/src/accessor/grib_accessor_class_trim.h @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_ascii.h" + +class grib_accessor_trim_t : public grib_accessor_ascii_t +{ +public: + /* Members defined in trim */ + const char* input; + int trim_left; + int trim_right; +}; + +class grib_accessor_class_trim_t : public grib_accessor_class_ascii_t +{ +public: + grib_accessor_class_trim_t(const char* name) : grib_accessor_class_ascii_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_trim_t{}; } + int pack_string(grib_accessor*, const char*, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + size_t string_length(grib_accessor*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_uint16.cc b/src/accessor/grib_accessor_class_uint16.cc new file mode 100644 index 000000000..1d9158ac0 --- /dev/null +++ b/src/accessor/grib_accessor_class_uint16.cc @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_uint16.h" + +grib_accessor_class_uint16_t _grib_accessor_class_uint16{"uint16"}; +grib_accessor_class* grib_accessor_class_uint16 = &_grib_accessor_class_uint16; + + +int grib_accessor_class_uint16_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + long value = 0; + /*long pos = a->offset;*/ + /*unsigned char* data = grib_handle_of_accessor(a)->buffer->data;*/ + + if (*len < 1) { + return GRIB_ARRAY_TOO_SMALL; + } + + *val = value; + *len = 1; + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_class_uint16_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_LONG; +} diff --git a/src/accessor/grib_accessor_class_uint16.h b/src/accessor/grib_accessor_class_uint16.h new file mode 100644 index 000000000..05818ebbd --- /dev/null +++ b/src/accessor/grib_accessor_class_uint16.h @@ -0,0 +1,29 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_uint16_t : public grib_accessor_gen_t +{ +public: + /* Members defined in uint16 */ +}; + +class grib_accessor_class_uint16_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_uint16_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_uint16_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; +}; diff --git a/src/accessor/grib_accessor_class_uint32.cc b/src/accessor/grib_accessor_class_uint32.cc new file mode 100644 index 000000000..7518cb68c --- /dev/null +++ b/src/accessor/grib_accessor_class_uint32.cc @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_uint32.h" + +grib_accessor_class_uint32_t _grib_accessor_class_uint32{"uint32"}; +grib_accessor_class* grib_accessor_class_uint32 = &_grib_accessor_class_uint32; + + +int grib_accessor_class_uint32_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + long value = 0; + /* long pos = a->offset; */ + /* unsigned char* data = grib_handle_of_accessor(a)->buffer->data; */ + + if (*len < 1) { + return GRIB_ARRAY_TOO_SMALL; + } + + *val = value; + *len = 1; + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_class_uint32_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_LONG; +} diff --git a/src/accessor/grib_accessor_class_uint32.h b/src/accessor/grib_accessor_class_uint32.h new file mode 100644 index 000000000..143dfc809 --- /dev/null +++ b/src/accessor/grib_accessor_class_uint32.h @@ -0,0 +1,29 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_uint32_t : public grib_accessor_gen_t +{ +public: + /* Members defined in uint32 */ +}; + +class grib_accessor_class_uint32_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_uint32_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_uint32_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; +}; diff --git a/src/accessor/grib_accessor_class_uint32_little_endian.cc b/src/accessor/grib_accessor_class_uint32_little_endian.cc new file mode 100644 index 000000000..b8733bd0a --- /dev/null +++ b/src/accessor/grib_accessor_class_uint32_little_endian.cc @@ -0,0 +1,34 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_uint32_little_endian.h" + +grib_accessor_class_uint32_little_endian_t _grib_accessor_class_uint32_little_endian{"uint32_little_endian"}; +grib_accessor_class* grib_accessor_class_uint32_little_endian = &_grib_accessor_class_uint32_little_endian; + + +int grib_accessor_class_uint32_little_endian_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + long value = 0; + /* long pos = a->offset; */ + /* unsigned char* data = grib_handle_of_accessor(a)->buffer->data; */ + + if (*len < 1) { + return GRIB_ARRAY_TOO_SMALL; + } + + *val = value; + *len = 1; + return GRIB_NOT_IMPLEMENTED; +} + +int grib_accessor_class_uint32_little_endian_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_LONG; +} diff --git a/src/accessor/grib_accessor_class_uint32_little_endian.h b/src/accessor/grib_accessor_class_uint32_little_endian.h new file mode 100644 index 000000000..83e808bc5 --- /dev/null +++ b/src/accessor/grib_accessor_class_uint32_little_endian.h @@ -0,0 +1,29 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_uint32_little_endian_t : public grib_accessor_gen_t +{ +public: + /* Members defined in uint32_little_endian */ +}; + +class grib_accessor_class_uint32_little_endian_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_uint32_little_endian_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_uint32_little_endian_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; +}; diff --git a/src/accessor/grib_accessor_class_uint64.cc b/src/accessor/grib_accessor_class_uint64.cc new file mode 100644 index 000000000..4c79f7bb4 --- /dev/null +++ b/src/accessor/grib_accessor_class_uint64.cc @@ -0,0 +1,50 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_uint64.h" + +grib_accessor_class_uint64_t _grib_accessor_class_uint64{"uint64"}; +grib_accessor_class* grib_accessor_class_uint64 = &_grib_accessor_class_uint64; + + +int grib_accessor_class_uint64_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + long value = 0; + long pos = a->offset; + unsigned char* data = grib_handle_of_accessor(a)->buffer->data; + unsigned long long result = 0, tmp; + int i; + + if (*len < 1) { + return GRIB_ARRAY_TOO_SMALL; + } + + for (i = 0; i < 8; i++) { + result <<= 8; + result |= data[pos + i]; + } + + value = result; + tmp = value; + + /* Result does not fit in long */ + if (tmp != result) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Value for %s cannot be decoded as a 'long' (%llu)", a->name, result); + return GRIB_DECODING_ERROR; + } + + *val = value; + *len = 1; + return GRIB_SUCCESS; +} + +int grib_accessor_class_uint64_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_LONG; +} diff --git a/src/accessor/grib_accessor_class_uint64.h b/src/accessor/grib_accessor_class_uint64.h new file mode 100644 index 000000000..d442b736d --- /dev/null +++ b/src/accessor/grib_accessor_class_uint64.h @@ -0,0 +1,29 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_uint64_t : public grib_accessor_gen_t +{ +public: + /* Members defined in uint64 */ +}; + +class grib_accessor_class_uint64_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_uint64_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_uint64_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; +}; diff --git a/src/accessor/grib_accessor_class_uint64_little_endian.cc b/src/accessor/grib_accessor_class_uint64_little_endian.cc new file mode 100644 index 000000000..81d0fed37 --- /dev/null +++ b/src/accessor/grib_accessor_class_uint64_little_endian.cc @@ -0,0 +1,50 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_uint64_little_endian.h" + +grib_accessor_class_uint64_little_endian_t _grib_accessor_class_uint64_little_endian{"uint64_little_endian"}; +grib_accessor_class* grib_accessor_class_uint64_little_endian = &_grib_accessor_class_uint64_little_endian; + + +int grib_accessor_class_uint64_little_endian_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + long value = 0; + long pos = a->offset; + unsigned char* data = grib_handle_of_accessor(a)->buffer->data; + unsigned long long result = 0, tmp; + int i; + + if (*len < 1) { + return GRIB_ARRAY_TOO_SMALL; + } + + for (i = 7; i >= 0; i--) { + result <<= 8; + result |= data[pos + i]; + } + + value = result; + tmp = value; + + /* Result does not fit in long */ + if (tmp != result) { + grib_context_log(a->context, GRIB_LOG_ERROR, "Value for %s cannot be decoded as a 'long' (%llu)", a->name, result); + return GRIB_DECODING_ERROR; + } + + *val = value; + *len = 1; + return GRIB_SUCCESS; +} + +int grib_accessor_class_uint64_little_endian_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_LONG; +} diff --git a/src/accessor/grib_accessor_class_uint64_little_endian.h b/src/accessor/grib_accessor_class_uint64_little_endian.h new file mode 100644 index 000000000..9e8f4327e --- /dev/null +++ b/src/accessor/grib_accessor_class_uint64_little_endian.h @@ -0,0 +1,29 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_uint64_little_endian_t : public grib_accessor_gen_t +{ +public: + /* Members defined in uint64_little_endian */ +}; + +class grib_accessor_class_uint64_little_endian_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_uint64_little_endian_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_uint64_little_endian_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; +}; diff --git a/src/accessor/grib_accessor_class_uint8.cc b/src/accessor/grib_accessor_class_uint8.cc new file mode 100644 index 000000000..ce5d88f98 --- /dev/null +++ b/src/accessor/grib_accessor_class_uint8.cc @@ -0,0 +1,36 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_uint8.h" + +grib_accessor_class_uint8_t _grib_accessor_class_uint8{"uint8"}; +grib_accessor_class* grib_accessor_class_uint8 = &_grib_accessor_class_uint8; + + +int grib_accessor_class_uint8_t::unpack_long(grib_accessor* a, long* val, size_t* len){ + long value = 0; + long pos = a->offset; + unsigned char* data = grib_handle_of_accessor(a)->buffer->data; + + if (*len < 1) { + return GRIB_ARRAY_TOO_SMALL; + } + + value = data[pos]; + + *val = value; + *len = 1; + return GRIB_SUCCESS; +} + +int grib_accessor_class_uint8_t::get_native_type(grib_accessor* a){ + return GRIB_TYPE_LONG; +} diff --git a/src/accessor/grib_accessor_class_uint8.h b/src/accessor/grib_accessor_class_uint8.h new file mode 100644 index 000000000..8a58b27f3 --- /dev/null +++ b/src/accessor/grib_accessor_class_uint8.h @@ -0,0 +1,29 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_uint8_t : public grib_accessor_gen_t +{ +public: + /* Members defined in uint8 */ +}; + +class grib_accessor_class_uint8_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_uint8_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_uint8_t{}; } + int get_native_type(grib_accessor*) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; +}; diff --git a/src/accessor/grib_accessor_class_unexpanded_descriptors.cc b/src/accessor/grib_accessor_class_unexpanded_descriptors.cc new file mode 100644 index 000000000..5c9402360 --- /dev/null +++ b/src/accessor/grib_accessor_class_unexpanded_descriptors.cc @@ -0,0 +1,142 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_unexpanded_descriptors.h" + +grib_accessor_class_unexpanded_descriptors_t _grib_accessor_class_unexpanded_descriptors{ "unexpanded_descriptors" }; +grib_accessor_class* grib_accessor_class_unexpanded_descriptors = &_grib_accessor_class_unexpanded_descriptors; + + +void grib_accessor_class_unexpanded_descriptors_t::init(grib_accessor* a, const long len, grib_arguments* args) +{ + grib_accessor_class_long_t::init(a, len, args); + grib_accessor_unexpanded_descriptors_t* self = (grib_accessor_unexpanded_descriptors_t*)a; + + int n = 0; + grib_handle* hand = grib_handle_of_accessor(a); + self->unexpandedDescriptorsEncoded = grib_find_accessor(hand, grib_arguments_get_name(hand, args, n++)); + self->createNewData = grib_arguments_get_name(hand, args, n++); + a->length = 0; +} + +int grib_accessor_class_unexpanded_descriptors_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ + grib_accessor_unexpanded_descriptors_t* self = (grib_accessor_unexpanded_descriptors_t*)a; + int ret = 0; + long pos = 0; + long rlen = 0; + long f, x, y; + long* v = val; + long i; + grib_handle* hand = grib_handle_of_accessor(a); + + pos = accessor_raw_get_offset(self->unexpandedDescriptorsEncoded) * 8; + + ret = value_count(a, &rlen); + if (ret) + return ret; + + if (rlen == 0) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "No descriptors in section 3. Malformed message."); + return GRIB_MESSAGE_MALFORMED; + } + + if (*len < rlen) { + /* grib_context_log(a->context, GRIB_LOG_ERROR, */ + /* " wrong size (%ld) for %s it contains %d values ",*len, a->name , rlen); */ + *len = 0; + return GRIB_ARRAY_TOO_SMALL; + } + + for (i = 0; i < rlen; i++) { + f = grib_decode_unsigned_long(hand->buffer->data, &pos, 2); + x = grib_decode_unsigned_long(hand->buffer->data, &pos, 6); + y = grib_decode_unsigned_long(hand->buffer->data, &pos, 8); + *v++ = f * 100000 + x * 1000 + y; + } + *len = rlen; + return GRIB_SUCCESS; +} + +int grib_accessor_class_unexpanded_descriptors_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ + grib_accessor_unexpanded_descriptors_t* self = (grib_accessor_unexpanded_descriptors_t*)a; + int ret = 0; + long pos = 0; + unsigned long f, x, y; + unsigned char* buf = NULL; + grib_accessor* expanded = NULL; + size_t buflen = *len * 2; + size_t i = 0, length = *len; + long createNewData = 1; + grib_handle* hand = grib_handle_of_accessor(a); + + grib_get_long(hand, self->createNewData, &createNewData); + + buf = (unsigned char*)grib_context_malloc_clear(a->context, buflen); + + for (i = 0; i < length; i++) { + const long tmp = val[i] % 100000; + f = val[i] / 100000; + x = tmp / 1000; + y = tmp % 1000; + grib_encode_unsigned_longb(buf, f, &pos, 2); + grib_encode_unsigned_longb(buf, x, &pos, 6); + grib_encode_unsigned_longb(buf, y, &pos, 8); + } + + self->unexpandedDescriptorsEncoded->pack_bytes(buf, &buflen); + grib_context_free(hand->context, buf); + + if (createNewData == 0) + return ret; + + expanded = grib_find_accessor(hand, "expandedCodes"); + Assert(expanded != NULL); + ret = grib_accessor_class_expanded_descriptors_set_do_expand(expanded, 1); + if (ret != GRIB_SUCCESS) + return ret; + + ret = grib_set_long(hand, "unpack", 3); /* BUFR new data */ + if (ret != GRIB_SUCCESS) + return ret; + + ret = grib_set_long(hand, "unpack", 1); /* Unpack structure */ + + return ret; +} + +int grib_accessor_class_unexpanded_descriptors_t::value_count(grib_accessor* a, long* numberOfUnexpandedDescriptors) +{ + grib_accessor_unexpanded_descriptors_t* self = (grib_accessor_unexpanded_descriptors_t*)a; + long n = 0; + + self->unexpandedDescriptorsEncoded->value_count(&n); + *numberOfUnexpandedDescriptors = n / 2; + + return 0; +} + +long grib_accessor_class_unexpanded_descriptors_t::byte_offset(grib_accessor* a) +{ + return a->offset; +} + +void grib_accessor_class_unexpanded_descriptors_t::update_size(grib_accessor* a, size_t s) +{ + a->length = s; +} + +long grib_accessor_class_unexpanded_descriptors_t::next_offset(grib_accessor* a) +{ + return a->byte_offset() + a->length; +} diff --git a/src/accessor/grib_accessor_class_unexpanded_descriptors.h b/src/accessor/grib_accessor_class_unexpanded_descriptors.h new file mode 100644 index 000000000..f9a016c1e --- /dev/null +++ b/src/accessor/grib_accessor_class_unexpanded_descriptors.h @@ -0,0 +1,36 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_unexpanded_descriptors_t : public grib_accessor_long_t +{ +public: + /* Members defined in unexpanded_descriptors */ + grib_accessor* unexpandedDescriptorsEncoded; + const char* createNewData; +}; + +class grib_accessor_class_unexpanded_descriptors_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_unexpanded_descriptors_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_unexpanded_descriptors_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + long byte_offset(grib_accessor*) override; + long next_offset(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + void update_size(grib_accessor*, size_t) override; +}; diff --git a/src/accessor/grib_accessor_class_unpack_bufr_values.cc b/src/accessor/grib_accessor_class_unpack_bufr_values.cc new file mode 100644 index 000000000..3497bbbe2 --- /dev/null +++ b/src/accessor/grib_accessor_class_unpack_bufr_values.cc @@ -0,0 +1,113 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_unpack_bufr_values.h" +#include "grib_accessor_class_bufr_data_array.h" + +grib_accessor_class_unpack_bufr_values_t _grib_accessor_class_unpack_bufr_values{ "unpack_bufr_values" }; +grib_accessor_class* grib_accessor_class_unpack_bufr_values = &_grib_accessor_class_unpack_bufr_values; + +void grib_accessor_class_unpack_bufr_values_t::init(grib_accessor* a, const long len, grib_arguments* params) +{ + grib_accessor_class_gen_t::init(a, len, params); + char* key; + grib_accessor_unpack_bufr_values_t* self = (grib_accessor_unpack_bufr_values_t*)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; +} + +void grib_accessor_class_unpack_bufr_values_t::dump(grib_accessor* a, grib_dumper* dumper) +{ +} + +int grib_accessor_class_unpack_bufr_values_t::unpack_string_array(grib_accessor* a, char** buffer, size_t* len) +{ + grib_accessor_unpack_bufr_values_t* self = (grib_accessor_unpack_bufr_values_t*)a; + grib_accessor* data = (grib_accessor*)self->data_accessor; + + return data->unpack_double(0, 0); +} + +int grib_accessor_class_unpack_bufr_values_t::unpack_string(grib_accessor* a, char* buffer, size_t* len) +{ + grib_accessor_unpack_bufr_values_t* self = (grib_accessor_unpack_bufr_values_t*)a; + grib_accessor* data = (grib_accessor*)self->data_accessor; + strcpy(buffer, "0"); + *len = 1; + + return data->unpack_double(0, 0); +} + +int grib_accessor_class_unpack_bufr_values_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ + grib_accessor_unpack_bufr_values_t* self = (grib_accessor_unpack_bufr_values_t*)a; + grib_accessor* data = (grib_accessor*)self->data_accessor; + + return data->unpack_double(0, 0); +} + +int grib_accessor_class_unpack_bufr_values_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ + grib_accessor_unpack_bufr_values_t* self = (grib_accessor_unpack_bufr_values_t*)a; + grib_accessor* data = (grib_accessor*)self->data_accessor; + + return data->unpack_double(0, 0); +} + +int grib_accessor_class_unpack_bufr_values_t::value_count(grib_accessor* a, long* count) +{ + *count = 1; + return 0; +} + +void grib_accessor_class_unpack_bufr_values_t::destroy(grib_context* context, grib_accessor* a) +{ + grib_accessor_class_gen_t::destroy(context, a); +} + +int grib_accessor_class_unpack_bufr_values_t::get_native_type(grib_accessor* a) +{ + return GRIB_TYPE_LONG; +} + +// static const char* mode_to_str(int p) +// { +// if (p==CODES_BUFR_UNPACK_STRUCTURE) return "CODES_BUFR_UNPACK_STRUCTURE"; +// if (p==CODES_BUFR_UNPACK_FLAT) return "CODES_BUFR_UNPACK_FLAT"; +// if (p==CODES_BUFR_NEW_DATA) return "CODES_BUFR_NEW_DATA"; +// return "unknown proc flag"; +// } + +int grib_accessor_class_unpack_bufr_values_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ + int unpackMode = CODES_BUFR_UNPACK_STRUCTURE; + grib_accessor_unpack_bufr_values_t* self = (grib_accessor_unpack_bufr_values_t*)a; + grib_accessor* data = (grib_accessor*)self->data_accessor; + + if (*val == 2) + unpackMode = CODES_BUFR_UNPACK_FLAT; + if (*val == 3) + unpackMode = CODES_BUFR_NEW_DATA; + + accessor_bufr_data_array_set_unpackMode(data, unpackMode); + + return data->unpack_double(0, 0); +} + +int grib_accessor_class_unpack_bufr_values_t::pack_double(grib_accessor* a, const double* val, size_t* len) +{ + grib_accessor_unpack_bufr_values_t* self = (grib_accessor_unpack_bufr_values_t*)a; + grib_accessor* data = (grib_accessor*)self->data_accessor; + + return data->unpack_double(0, 0); +} diff --git a/src/accessor/grib_accessor_class_unpack_bufr_values.h b/src/accessor/grib_accessor_class_unpack_bufr_values.h new file mode 100644 index 000000000..46dd91ec5 --- /dev/null +++ b/src/accessor/grib_accessor_class_unpack_bufr_values.h @@ -0,0 +1,39 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_unpack_bufr_values_t : public grib_accessor_gen_t +{ +public: + /* Members defined in unpack_bufr_values */ + grib_accessor* data_accessor; +}; + +class grib_accessor_class_unpack_bufr_values_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_unpack_bufr_values_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_unpack_bufr_values_t{}; } + int get_native_type(grib_accessor*) override; + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + int unpack_string_array(grib_accessor*, char**, size_t* len) override; + int value_count(grib_accessor*, long*) override; + void destroy(grib_context*, grib_accessor*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/grib_accessor_class_unsigned.cc b/src/accessor/grib_accessor_class_unsigned.cc similarity index 50% rename from src/grib_accessor_class_unsigned.cc rename to src/accessor/grib_accessor_class_unsigned.cc index f1202b0d0..8093e3a6a 100644 --- a/src/grib_accessor_class_unsigned.cc +++ b/src/accessor/grib_accessor_class_unsigned.cc @@ -8,119 +8,19 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = init;dump;is_missing - IMPLEMENTS = next_offset - IMPLEMENTS = byte_count - IMPLEMENTS = value_count - IMPLEMENTS = byte_offset - IMPLEMENTS = update_size; destroy - MEMBERS = long nbytes - MEMBERS = grib_arguments* arg - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int is_missing(grib_accessor*); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static long byte_count(grib_accessor*); -static long byte_offset(grib_accessor*); -static long next_offset(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void destroy(grib_context*, grib_accessor*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); -static void update_size(grib_accessor*, size_t); - -typedef struct grib_accessor_unsigned -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in unsigned */ - long nbytes; - grib_arguments* arg; -} grib_accessor_unsigned; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_unsigned = { - &grib_accessor_class_long, /* super */ - "unsigned", /* name */ - sizeof(grib_accessor_unsigned), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - &destroy, /* destroy */ - &dump, /* dump */ - &next_offset, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - &byte_count, /* get number of bytes */ - &byte_offset, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - &is_missing, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - &update_size, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; +#include "grib_accessor_class_unsigned.h" +grib_accessor_class_unsigned_t _grib_accessor_class_unsigned("unsigned"); grib_accessor_class* grib_accessor_class_unsigned = &_grib_accessor_class_unsigned; -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_class_unsigned_t::init(grib_accessor* a, const long len, grib_arguments* arg) { - grib_accessor_unsigned* self = (grib_accessor_unsigned*)a; - self->arg = NULL; - self->arg = arg; - self->nbytes = len; + grib_accessor_class_long_t::init(a, len, arg); + grib_accessor_unsigned_t* self = (grib_accessor_unsigned_t*)a; + self->arg = arg; + self->nbytes = len; if (a->flags & GRIB_ACCESSOR_FLAG_TRANSIENT) { a->length = 0; @@ -131,17 +31,17 @@ static void init(grib_accessor* a, const long len, grib_arguments* arg) } else { long count = 0; - grib_value_count(a, &count); + a->value_count(&count); a->length = len * count; a->vvalue = NULL; } } -static void dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_class_unsigned_t::dump(grib_accessor* a, grib_dumper* dumper) { long rlen = 0; - grib_value_count(a, &rlen); + a->value_count(&rlen); if (rlen == 1) grib_dump_long(dumper, a, NULL); else @@ -158,25 +58,26 @@ static const unsigned long ones[] = { /* See GRIB-490 */ static const unsigned long all_ones = -1; -static int value_is_missing(long val) + +int value_is_missing(long val) { return (val == GRIB_MISSING_LONG || val == all_ones); } int pack_long_unsigned_helper(grib_accessor* a, const long* val, size_t* len, int check) { - grib_accessor_unsigned* self = (grib_accessor_unsigned*)a; - int ret = 0; - long off = 0; - long rlen = 0; - int err = 0; + grib_accessor_unsigned_t* self = (grib_accessor_unsigned_t*)a; + int ret = 0; + long off = 0; + long rlen = 0; + int err = 0; size_t buflen = 0; unsigned char* buf = NULL; unsigned long i = 0; unsigned long missing = 0; - err = grib_value_count(a, &rlen); + err = a->value_count(&rlen); if (err) return err; @@ -213,7 +114,7 @@ int pack_long_unsigned_helper(grib_accessor* a, const long* val, size_t* len, in if (check) { if (val[0] < 0) { grib_context_log(a->context, GRIB_LOG_ERROR, - "Key \"%s\": Trying to encode a negative value of %ld for key of type unsigned", a->name, val[0]); + "Key \"%s\": Trying to encode a negative value of %ld for key of type unsigned", a->name, val[0]); return GRIB_ENCODING_ERROR; } /* See GRIB-23 and GRIB-262 */ @@ -223,8 +124,8 @@ int pack_long_unsigned_helper(grib_accessor* a, const long* val, size_t* len, in unsigned long maxval = (1UL << nbits) - 1; if (maxval > 0 && v > maxval) { /* See ECC-1002 */ grib_context_log(a->context, GRIB_LOG_ERROR, - "Key \"%s\": Trying to encode value of %ld but the maximum allowable value is %lu (number of bits=%ld)", - a->name, v, maxval, nbits); + "Key \"%s\": Trying to encode value of %ld but the maximum allowable value is %lu (number of bits=%ld)", + a->name, v, maxval, nbits); return GRIB_ENCODING_ERROR; } } @@ -260,18 +161,18 @@ int pack_long_unsigned_helper(grib_accessor* a, const long* val, size_t* len, in return ret; } -static int unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_class_unsigned_t::unpack_long(grib_accessor* a, long* val, size_t* len) { - grib_accessor_unsigned* self = (grib_accessor_unsigned*)a; - long rlen = 0; - unsigned long i = 0; - unsigned long missing = 0; - long count = 0; - int err = 0; - long pos = a->offset * 8; - grib_handle* hand = grib_handle_of_accessor(a); + grib_accessor_unsigned_t* self = (grib_accessor_unsigned_t*)a; + long rlen = 0; + unsigned long i = 0; + unsigned long missing = 0; + long count = 0; + int err = 0; + long pos = a->offset * 8; + grib_handle* hand = grib_handle_of_accessor(a); - err = grib_value_count(a, &count); + err = a->value_count(&count); if (err) return err; rlen = count; @@ -304,20 +205,20 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) return GRIB_SUCCESS; } -static int pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_class_unsigned_t::pack_long(grib_accessor* a, const long* val, size_t* len) { /* See GRIB-262 as example of why we do the checks */ return pack_long_unsigned_helper(a, val, len, /*check=*/1); } -static long byte_count(grib_accessor* a) +long grib_accessor_class_unsigned_t::byte_count(grib_accessor* a) { return a->length; } -static int value_count(grib_accessor* a, long* len) +int grib_accessor_class_unsigned_t::value_count(grib_accessor* a, long* len) { - grib_accessor_unsigned* self = (grib_accessor_unsigned*)a; + grib_accessor_unsigned_t* self = (grib_accessor_unsigned_t*)a; if (!self->arg) { *len = 1; return 0; @@ -325,22 +226,22 @@ static int value_count(grib_accessor* a, long* len) return grib_get_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, self->arg, 0), len); } -static long byte_offset(grib_accessor* a) +long grib_accessor_class_unsigned_t::byte_offset(grib_accessor* a) { return a->offset; } -static void update_size(grib_accessor* a, size_t s) +void grib_accessor_class_unsigned_t::update_size(grib_accessor* a, size_t s) { a->length = s; } -static long next_offset(grib_accessor* a) +long grib_accessor_class_unsigned_t::next_offset(grib_accessor* a) { - return grib_byte_offset(a) + grib_byte_count(a); + return a->byte_offset() + a->byte_count(); } -static int is_missing(grib_accessor* a) +int grib_accessor_class_unsigned_t::is_missing(grib_accessor* a) { int i = 0; unsigned char ff = 0xff; @@ -361,10 +262,12 @@ static int is_missing(grib_accessor* a) return 1; } -static void destroy(grib_context* context, grib_accessor* a) +void grib_accessor_class_unsigned_t::destroy(grib_context* context, grib_accessor* a) { if (a->vvalue != NULL) grib_context_free(context, a->vvalue); a->vvalue = NULL; + + grib_accessor_class_long_t::destroy(context, a); } diff --git a/src/accessor/grib_accessor_class_unsigned.h b/src/accessor/grib_accessor_class_unsigned.h new file mode 100644 index 000000000..50f3cfb16 --- /dev/null +++ b/src/accessor/grib_accessor_class_unsigned.h @@ -0,0 +1,39 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_unsigned_t : public grib_accessor_long_t +{ +public: + long nbytes; + grib_arguments* arg; +}; + + +class grib_accessor_class_unsigned_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_unsigned_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_unsigned_t{}; } + void init(grib_accessor* a, const long len, grib_arguments* arg) override; + void dump(grib_accessor* a, grib_dumper* dumper) override; + int unpack_long(grib_accessor* a, long* val, size_t* len) override; + int pack_long(grib_accessor* a, const long* val, size_t* len) override; + long byte_count(grib_accessor* a) override; + int value_count(grib_accessor* a, long* len) override; + long byte_offset(grib_accessor* a) override; + void update_size(grib_accessor* a, size_t s) override; + long next_offset(grib_accessor* a) override; + int is_missing(grib_accessor* a) override; + void destroy(grib_context* context, grib_accessor* a) override; +}; diff --git a/src/accessor/grib_accessor_class_unsigned_bits.cc b/src/accessor/grib_accessor_class_unsigned_bits.cc new file mode 100644 index 000000000..44873938a --- /dev/null +++ b/src/accessor/grib_accessor_class_unsigned_bits.cc @@ -0,0 +1,167 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_unsigned_bits.h" + +grib_accessor_class_unsigned_bits_t _grib_accessor_class_unsigned_bits{ "unsigned_bits" }; +grib_accessor_class* grib_accessor_class_unsigned_bits = &_grib_accessor_class_unsigned_bits; + + +static long compute_byte_count(grib_accessor* a) +{ + grib_accessor_unsigned_bits_t* self = (grib_accessor_unsigned_bits_t*)a; + long numberOfBits; + long numberOfElements; + int ret = 0; + + ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); + if (ret) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", a->name, self->numberOfBits); + return 0; + } + + ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements, &numberOfElements); + if (ret) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", a->name, self->numberOfElements); + return 0; + } + + return (numberOfBits * numberOfElements + 7) / 8; +} + + +void grib_accessor_class_unsigned_bits_t::init(grib_accessor* a, const long len, grib_arguments* args) +{ + grib_accessor_class_long_t::init(a, len, args); + grib_accessor_unsigned_bits_t* self = (grib_accessor_unsigned_bits_t*)a; + int n = 0; + self->numberOfBits = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + self->numberOfElements = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + a->length = compute_byte_count(a); +} + +int grib_accessor_class_unsigned_bits_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ + grib_accessor_unsigned_bits_t* self = (grib_accessor_unsigned_bits_t*)a; + int ret = 0; + long pos = a->offset * 8; + long rlen = 0; + long numberOfBits = 0; + + ret = value_count(a, &rlen); + if (ret) + return ret; + + if (*len < rlen) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "Wrong size (%ld) for %s, it contains %ld values", *len, a->name, rlen); + *len = rlen; + return GRIB_ARRAY_TOO_SMALL; + } + + ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); + if (ret) + return ret; + if (numberOfBits == 0) { + int i; + for (i = 0; i < rlen; i++) + val[i] = 0; + return GRIB_SUCCESS; + } + + grib_decode_long_array(grib_handle_of_accessor(a)->buffer->data, &pos, numberOfBits, rlen, val); + + *len = rlen; + + return GRIB_SUCCESS; +} + +int grib_accessor_class_unsigned_bits_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ + grib_accessor_unsigned_bits_t* self = (grib_accessor_unsigned_bits_t*)a; + int ret = 0; + long off = 0; + long numberOfBits = 0; + size_t buflen = 0; + unsigned char* buf = NULL; + unsigned long i = 0; + long rlen = 0; + ret = value_count(a, &rlen); + if (ret) return ret; + + /* + if(*len < rlen) + { + grib_context_log(a->context, GRIB_LOG_ERROR, + "Wrong size for %s it contains %d values ", a->name , rlen ); + return GRIB_ARRAY_TOO_SMALL; + } + */ + if (*len != rlen) + ret = grib_set_long(grib_handle_of_accessor(a), self->numberOfElements, *len); + if (ret) return ret; + + ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); + if (ret) return ret; + if (numberOfBits == 0) { + grib_buffer_replace(a, NULL, 0, 1, 1); + return GRIB_SUCCESS; + } + + buflen = compute_byte_count(a); + buf = (unsigned char*)grib_context_malloc_clear(a->context, buflen + sizeof(long)); + + for (i = 0; i < *len; i++) + grib_encode_unsigned_longb(buf, val[i], &off, numberOfBits); + + grib_buffer_replace(a, buf, buflen, 1, 1); + + grib_context_free(a->context, buf); + + return ret; +} + +long grib_accessor_class_unsigned_bits_t::byte_count(grib_accessor* a) +{ + return a->length; +} + +int grib_accessor_class_unsigned_bits_t::value_count(grib_accessor* a, long* numberOfElements) +{ + grib_accessor_unsigned_bits_t* self = (grib_accessor_unsigned_bits_t*)a; + int ret; + *numberOfElements = 0; + + ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements, numberOfElements); + if (ret) { + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", a->name, self->numberOfElements); + } + + return ret; +} + +long grib_accessor_class_unsigned_bits_t::byte_offset(grib_accessor* a) +{ + return a->offset; +} + +void grib_accessor_class_unsigned_bits_t::update_size(grib_accessor* a, size_t s) +{ + a->length = s; +} + +long grib_accessor_class_unsigned_bits_t::next_offset(grib_accessor* a) +{ + return a->byte_offset() + a->length; +} diff --git a/src/accessor/grib_accessor_class_unsigned_bits.h b/src/accessor/grib_accessor_class_unsigned_bits.h new file mode 100644 index 000000000..52528ab83 --- /dev/null +++ b/src/accessor/grib_accessor_class_unsigned_bits.h @@ -0,0 +1,37 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_unsigned_bits_t : public grib_accessor_long_t +{ +public: + /* Members defined in unsigned_bits */ + const char* numberOfBits; + const char* numberOfElements; +}; + +class grib_accessor_class_unsigned_bits_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_unsigned_bits_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_unsigned_bits_t{}; } + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + long byte_count(grib_accessor*) override; + long byte_offset(grib_accessor*) override; + long next_offset(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + void update_size(grib_accessor*, size_t) override; +}; diff --git a/src/accessor/grib_accessor_class_validity_date.cc b/src/accessor/grib_accessor_class_validity_date.cc new file mode 100644 index 000000000..331c4ec82 --- /dev/null +++ b/src/accessor/grib_accessor_class_validity_date.cc @@ -0,0 +1,98 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_validity_date.h" +#include "shared_functions.h" + +grib_accessor_class_validity_date_t _grib_accessor_class_validity_date{ "validity_date" }; +grib_accessor_class* grib_accessor_class_validity_date = &_grib_accessor_class_validity_date; + +void grib_accessor_class_validity_date_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ + grib_accessor_class_long_t::init(a, l, c); + grib_accessor_validity_date_t* self = (grib_accessor_validity_date_t*)a; + grib_handle* hand = grib_handle_of_accessor(a); + int n = 0; + + self->date = grib_arguments_get_name(hand, c, n++); + self->time = grib_arguments_get_name(hand, c, n++); + self->step = grib_arguments_get_name(hand, c, n++); + self->stepUnits = grib_arguments_get_name(hand, c, n++); + self->year = grib_arguments_get_name(hand, c, n++); + self->month = grib_arguments_get_name(hand, c, n++); + self->day = grib_arguments_get_name(hand, c, n++); + + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; +} + +int grib_accessor_class_validity_date_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ + grib_accessor_validity_date_t* self = (grib_accessor_validity_date_t*)a; + grib_handle* hand = grib_handle_of_accessor(a); + int ret = 0; + long date = 0; + long time = 0; + long step = 0; + long stepUnits = 0; + long hours = 0, minutes = 0, step_mins = 0, tmp, tmp_hrs; + + if (self->year) { + long year, month, day; + if ((ret = grib_get_long_internal(hand, self->year, &year)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_get_long_internal(hand, self->month, &month)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_get_long_internal(hand, self->day, &day)) != GRIB_SUCCESS) + return ret; + *val = year * 10000 + month * 100 + day; + return GRIB_SUCCESS; + } + if ((ret = grib_get_long_internal(hand, self->date, &date)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_get_long_internal(hand, self->time, &time)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_get_long(hand, self->step, &step)) != GRIB_SUCCESS) { + if ((ret = grib_get_long_internal(hand, "endStep", &step)) != GRIB_SUCCESS) { + return ret; /* See ECC-817 */ + } + } + + if (self->stepUnits) { + if ((ret = grib_get_long_internal(hand, self->stepUnits, &stepUnits)) != GRIB_SUCCESS) + return ret; + step_mins = convert_to_minutes(step, stepUnits); + } + + minutes = time % 100; + hours = time / 100; + tmp = minutes + step_mins; /* add the step to our minutes */ + tmp_hrs = tmp / 60; /* how many hours and mins is that? */ + hours += tmp_hrs; /* increment hours */ + + date = grib_date_to_julian(date); + /* does the new 'hours' exceed 24? if so increment julian */ + while (hours >= 24) { + date++; + hours -= 24; + } + /* GRIB-29: Negative forecast time */ + while (hours < 0) { + date--; + hours += 24; + } + + if (*len < 1) + return GRIB_ARRAY_TOO_SMALL; + + *val = grib_julian_to_date(date); + + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_validity_date.h b/src/accessor/grib_accessor_class_validity_date.h new file mode 100644 index 000000000..ca87b3282 --- /dev/null +++ b/src/accessor/grib_accessor_class_validity_date.h @@ -0,0 +1,36 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_validity_date_t : public grib_accessor_long_t +{ +public: + /* Members defined in validity_date */ + const char* date; + const char* time; + const char* step; + const char* stepUnits; + const char* year; + const char* month; + const char* day; +}; + +class grib_accessor_class_validity_date_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_validity_date_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_validity_date_t{}; } + int unpack_long(grib_accessor*, long* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_validity_time.cc b/src/accessor/grib_accessor_class_validity_time.cc new file mode 100644 index 000000000..350a19e92 --- /dev/null +++ b/src/accessor/grib_accessor_class_validity_time.cc @@ -0,0 +1,119 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_validity_time.h" +#include "shared_functions.h" + +grib_accessor_class_validity_time_t _grib_accessor_class_validity_time{ "validity_time" }; +grib_accessor_class* grib_accessor_class_validity_time = &_grib_accessor_class_validity_time; + + +void grib_accessor_class_validity_time_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ + grib_accessor_class_long_t::init(a, l, c); + grib_accessor_validity_time_t* self = (grib_accessor_validity_time_t*)a; + grib_handle* hand = grib_handle_of_accessor(a); + int n = 0; + + self->date = grib_arguments_get_name(hand, c, n++); + self->time = grib_arguments_get_name(hand, c, n++); + self->step = grib_arguments_get_name(hand, c, n++); + self->stepUnits = grib_arguments_get_name(hand, c, n++); + self->hours = grib_arguments_get_name(hand, c, n++); + self->minutes = grib_arguments_get_name(hand, c, n++); + + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; +} + +int grib_accessor_class_validity_time_t::unpack_long(grib_accessor* a, long* val, size_t* len) +{ + grib_accessor_validity_time_t* self = (grib_accessor_validity_time_t*)a; + grib_handle* hand = grib_handle_of_accessor(a); + int ret = 0; + long date = 0; + long time = 0; + long step = 0; + long stepUnits = 0; + long hours = 0, minutes = 0, step_mins = 0, tmp, tmp_hrs, tmp_mins; + + if (self->hours) { + if ((ret = grib_get_long_internal(hand, self->hours, &hours)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_get_long_internal(hand, self->minutes, &minutes)) != GRIB_SUCCESS) + return ret; + *val = hours * 100 + minutes; + return GRIB_SUCCESS; + } + if ((ret = grib_get_long_internal(hand, self->date, &date)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_get_long_internal(hand, self->time, &time)) != GRIB_SUCCESS) + return ret; + if ((ret = grib_get_long(hand, self->step, &step)) != GRIB_SUCCESS) { + if ((ret = grib_get_long_internal(hand, "endStep", &step)) != GRIB_SUCCESS) { + return ret; /* See ECC-817 */ + } + } + + /* Seconds will always be zero. So convert to minutes */ + if (self->stepUnits) { + if ((ret = grib_get_long_internal(hand, self->stepUnits, &stepUnits)) != GRIB_SUCCESS) + return ret; + step_mins = convert_to_minutes(step, stepUnits); + } + + minutes = time % 100; + hours = time / 100; + tmp = minutes + step_mins; /* add the step to our minutes */ + tmp_hrs = tmp / 60; /* how many hours and mins is that? */ + tmp_mins = tmp % 60; + hours += tmp_hrs; /* increment hours */ + if (hours > 0) { + hours = hours % 24; /* wrap round if >= 24 */ + } + else { + /* GRIB-29: Negative forecast time */ + while (hours < 0) { + hours += 24; + } + } + time = hours * 100 + tmp_mins; + + if (*len < 1) + return GRIB_ARRAY_TOO_SMALL; + + *val = time; + + return GRIB_SUCCESS; +} + +int grib_accessor_class_validity_time_t::unpack_string(grib_accessor* a, char* val, size_t* len) +{ + int err = 0; + long v = 0; + size_t lsize = 1, lmin = 5; + + err = unpack_long(a, &v, &lsize); + if (err) return err; + + if (*len < lmin) { + const char* cclass_name = a->cclass->name; + grib_context_log(a->context, GRIB_LOG_ERROR, + "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", + cclass_name, a->name, lmin, *len); + *len = lmin; + return GRIB_BUFFER_TOO_SMALL; + } + + snprintf(val, 64, "%04ld", v); + + len[0] = lmin; + return GRIB_SUCCESS; +} diff --git a/src/accessor/grib_accessor_class_validity_time.h b/src/accessor/grib_accessor_class_validity_time.h new file mode 100644 index 000000000..023c3e30a --- /dev/null +++ b/src/accessor/grib_accessor_class_validity_time.h @@ -0,0 +1,36 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_long.h" + +class grib_accessor_validity_time_t : public grib_accessor_long_t +{ +public: + /* Members defined in validity_time */ + const char* date; + const char* time; + const char* step; + const char* stepUnits; + const char* hours; + const char* minutes; +}; + +class grib_accessor_class_validity_time_t : public grib_accessor_class_long_t +{ +public: + grib_accessor_class_validity_time_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_validity_time_t{}; } + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_values.cc b/src/accessor/grib_accessor_class_values.cc new file mode 100644 index 000000000..cd2107559 --- /dev/null +++ b/src/accessor/grib_accessor_class_values.cc @@ -0,0 +1,149 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_values.h" + +grib_accessor_class_values_t _grib_accessor_class_values{"values"}; +grib_accessor_class* grib_accessor_class_values = &_grib_accessor_class_values; + +long init_length(grib_accessor* a) +{ + grib_accessor_values_t* self = (grib_accessor_values_t*)a; + int ret = 0; + + long seclen = 0; + long offsetsection = 0; + long offsetdata = 0; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->seclen, &seclen))) + return ret; + + if (seclen == 0) { + /* printf("init_length seclen=0\n"); */ + return 0; + } + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetsection, &offsetsection))) + return ret; + + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetdata, &offsetdata))) + return ret; + + /* When reparsing */ + if (offsetdata < offsetsection) { + /* printf("init_length offsetdata < offsetsection=0\n"); */ + Assert(grib_handle_of_accessor(a)->loader); + return 0; + } + + return seclen - (offsetdata - offsetsection); +} + +void grib_accessor_class_values_t::init(grib_accessor* a, const long v, grib_arguments* params) +{ + grib_accessor_class_gen_t::init(a, v, params); + grib_accessor_values_t* self = (grib_accessor_values_t*)a; + self->carg = 0; + + self->seclen = grib_arguments_get_name(grib_handle_of_accessor(a), params, self->carg++); + self->offsetdata = grib_arguments_get_name(grib_handle_of_accessor(a), params, self->carg++); + self->offsetsection = grib_arguments_get_name(grib_handle_of_accessor(a), params, self->carg++); + self->dirty = 1; + + a->length = init_length(a); + /* Assert(a->length>=0); */ +} + +int grib_accessor_class_values_t::get_native_type(grib_accessor* a) +{ + return GRIB_TYPE_DOUBLE; +} + +void grib_accessor_class_values_t::dump(grib_accessor* a, grib_dumper* dumper) +{ + grib_dump_values(dumper, a); +} + +long grib_accessor_class_values_t::byte_count(grib_accessor* a) +{ + grib_context_log(a->context, GRIB_LOG_DEBUG, "byte_count of %s = %ld", a->name, a->length); + return a->length; +} + +long grib_accessor_class_values_t::byte_offset(grib_accessor* a) +{ + return a->offset; +} + +long grib_accessor_class_values_t::next_offset(grib_accessor* a) +{ + return a->offset + a->length; +} + +void grib_accessor_class_values_t::update_size(grib_accessor* a, size_t s) +{ + grib_context_log(a->context, GRIB_LOG_DEBUG, "updating size of %s old %ld new %ld", a->name, a->length, s); + a->length = s; + Assert(a->length >= 0); +} + +int grib_accessor_class_values_t::compare(grib_accessor* a, grib_accessor* b) +{ + int retval = 0; + double* aval = 0; + double* bval = 0; + + size_t alen = 0; + size_t blen = 0; + int err = 0; + long count = 0; + + err = a->value_count(&count); if (err) + return err; + alen = count; + + err = b->value_count(&count); if (err) + return err; + blen = count; + + if (alen != blen) + return GRIB_COUNT_MISMATCH; + + aval = (double*)grib_context_malloc(a->context, alen * sizeof(double)); + bval = (double*)grib_context_malloc(b->context, blen * sizeof(double)); + + a->unpack_double(aval, &alen); b->unpack_double(bval, &blen); + retval = GRIB_SUCCESS; + for (size_t i=0; icontext, aval); + grib_context_free(b->context, bval); + + return retval; +} + +int grib_accessor_class_values_t::pack_long(grib_accessor* a, const long* val, size_t* len) +{ + grib_accessor_values_t* self = (grib_accessor_values_t*)a; + double* dval = (double*)grib_context_malloc(a->context, *len * sizeof(double)); + + for (size_t i = 0; i < *len; i++) + dval[i] = (double)val[i]; + + int ret = a->pack_double(dval, len); + grib_context_free(a->context, dval); + + self->dirty = 1; + + return ret; +} diff --git a/src/accessor/grib_accessor_class_values.h b/src/accessor/grib_accessor_class_values.h new file mode 100644 index 000000000..5de50f2bd --- /dev/null +++ b/src/accessor/grib_accessor_class_values.h @@ -0,0 +1,39 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_values_t : public grib_accessor_gen_t +{ +public: + int carg; + const char* seclen; + const char* offsetdata; + const char* offsetsection; + int dirty; +}; + +class grib_accessor_class_values_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_values_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_values_t{}; } + int get_native_type(grib_accessor*) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + long byte_count(grib_accessor*) override; + long byte_offset(grib_accessor*) override; + long next_offset(grib_accessor*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + void update_size(grib_accessor*, size_t) override; + int compare(grib_accessor*, grib_accessor*) override; +}; diff --git a/src/grib_accessor_class_variable.cc b/src/accessor/grib_accessor_class_variable.cc similarity index 52% rename from src/grib_accessor_class_variable.cc rename to src/accessor/grib_accessor_class_variable.cc index f47da7383..b87798663 100644 --- a/src/grib_accessor_class_variable.cc +++ b/src/accessor/grib_accessor_class_variable.cc @@ -8,124 +8,13 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_api_internal.h" +#include "grib_accessor_class_variable.h" #include -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = unpack_double;pack_double - IMPLEMENTS = unpack_float; pack_float - IMPLEMENTS = unpack_string;pack_string;string_length - IMPLEMENTS = unpack_long;pack_long;destroy;byte_count - IMPLEMENTS = init;dump;value_count;get_native_type - IMPLEMENTS = compare; make_clone - MEMBERS=double dval - MEMBERS=float fval - MEMBERS=char* cval - MEMBERS=char* cname - MEMBERS=int type - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int pack_float(grib_accessor*, const float* val, size_t* len); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int pack_string(grib_accessor*, const char*, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_float(grib_accessor*, float* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static size_t string_length(grib_accessor*); -static long byte_count(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void destroy(grib_context*, grib_accessor*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); -static int compare(grib_accessor*, grib_accessor*); -static grib_accessor* make_clone(grib_accessor*, grib_section*, int*); - -typedef struct grib_accessor_variable -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in variable */ - double dval; - float fval; - char* cval; - char* cname; - int type; -} grib_accessor_variable; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_variable = { - &grib_accessor_class_gen, /* super */ - "variable", /* name */ - sizeof(grib_accessor_variable), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - &destroy, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - &string_length, /* get length of string */ - &value_count, /* get number of values */ - &byte_count, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - &pack_double, /* pack_double */ - &pack_float, /* pack_float */ - &unpack_double, /* unpack_double */ - &unpack_float, /* unpack_float */ - &pack_string, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - &compare, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - &make_clone, /* clone accessor */ -}; +grib_accessor_class_variable_t _grib_accessor_class_variable{"variable"}; grib_accessor_class* grib_accessor_class_variable = &_grib_accessor_class_variable; -/* END_CLASS_IMP */ - // // This accessor is used for: // constant @@ -134,9 +23,11 @@ grib_accessor_class* grib_accessor_class_variable = &_grib_accessor_class_variab #define MAX_VARIABLE_STRING_LENGTH 255 -static void init(grib_accessor* a, const long length, grib_arguments* args) +void grib_accessor_class_variable_t::init(grib_accessor* a, const long length, grib_arguments* args) { - grib_accessor_variable* self = (grib_accessor_variable*)a; + grib_accessor_class_gen_t::init(a, length, args); + + grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; grib_handle* hand = grib_handle_of_accessor(a); grib_expression* expression = grib_arguments_get_expression(hand, args, 0); const char* p = 0; @@ -153,12 +44,12 @@ static void init(grib_accessor* a, const long length, grib_arguments* args) switch (self->type) { case GRIB_TYPE_DOUBLE: grib_expression_evaluate_double(hand, expression, &d); - pack_double(a, &d, &len); + a->pack_double(&d, &len); break; case GRIB_TYPE_LONG: grib_expression_evaluate_long(hand, expression, &l); - pack_long(a, &l, &len); + a->pack_long(&l, &len); break; default: { @@ -171,7 +62,7 @@ static void init(grib_accessor* a, const long length, grib_arguments* args) return; } len = strlen(p) + 1; - pack_string(a, p, &len); + a->pack_string(p, &len); break; } } @@ -180,13 +71,13 @@ static void init(grib_accessor* a, const long length, grib_arguments* args) void accessor_variable_set_type(grib_accessor* a, int type) { - grib_accessor_variable* self = (grib_accessor_variable*)a; + grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; self->type = type; } -static void dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_class_variable_t::dump(grib_accessor* a, grib_dumper* dumper) { - const grib_accessor_variable* self = (grib_accessor_variable*)a; + const grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; switch (self->type) { case GRIB_TYPE_DOUBLE: grib_dump_double(dumper, a, NULL); @@ -202,9 +93,9 @@ static void dump(grib_accessor* a, grib_dumper* dumper) } } -static int pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_class_variable_t::pack_double(grib_accessor* a, const double* val, size_t* len) { - grib_accessor_variable* self = (grib_accessor_variable*)a; + grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; const double dval = *val; if (*len != 1) { @@ -227,9 +118,9 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) return GRIB_SUCCESS; } -static int pack_float(grib_accessor* a, const float* val, size_t* len) +int grib_accessor_class_variable_t::pack_float(grib_accessor* a, const float* val, size_t* len) { - grib_accessor_variable* self = (grib_accessor_variable*)a; + grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; const double fval = *val; if (*len != 1) { @@ -247,9 +138,9 @@ static int pack_float(grib_accessor* a, const float* val, size_t* len) return GRIB_SUCCESS; } -static int pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_class_variable_t::pack_long(grib_accessor* a, const long* val, size_t* len) { - grib_accessor_variable* self = (grib_accessor_variable*)a; + grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; if (*len != 1) { grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains 1 value", a->name); @@ -264,9 +155,9 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) return GRIB_SUCCESS; } -static int unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_class_variable_t::unpack_double(grib_accessor* a, double* val, size_t* len) { - const grib_accessor_variable* self = (grib_accessor_variable*)a; + const grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; if (*len < 1) { grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %d values", a->name, 1); @@ -278,9 +169,9 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len) return GRIB_SUCCESS; } -static int unpack_float(grib_accessor* a, float* val, size_t* len) +int grib_accessor_class_variable_t::unpack_float(grib_accessor* a, float* val, size_t* len) { - const grib_accessor_variable* self = (grib_accessor_variable*)a; + const grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; if (*len < 1) { grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %d values", a->name, 1); @@ -292,9 +183,9 @@ static int unpack_float(grib_accessor* a, float* val, size_t* len) return GRIB_SUCCESS; } -static int unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_class_variable_t::unpack_long(grib_accessor* a, long* val, size_t* len) { - const grib_accessor_variable* self = (grib_accessor_variable*)a; + const grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; if (*len < 1) { grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name, 1); @@ -306,15 +197,15 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) return GRIB_SUCCESS; } -static int get_native_type(grib_accessor* a) +int grib_accessor_class_variable_t::get_native_type(grib_accessor* a) { - const grib_accessor_variable* self = (grib_accessor_variable*)a; + const grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; return self->type; } -static void destroy(grib_context* c, grib_accessor* a) +void grib_accessor_class_variable_t::destroy(grib_context* c, grib_accessor* a) { - grib_accessor_variable* self = (grib_accessor_variable*)a; + grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; int i = 0; grib_context_free(c, self->cval); @@ -323,15 +214,17 @@ static void destroy(grib_context* c, grib_accessor* a) /* Note: BUFR operator descriptors are variables and have attributes so need to free them */ while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes[i]) { - grib_accessor_delete(c, a->attributes[i]); + a->attributes[i]->destroy(c); a->attributes[i] = NULL; ++i; } + + grib_accessor_class_gen_t::destroy(c, a); } -static int unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_class_variable_t::unpack_string(grib_accessor* a, char* val, size_t* len) { - grib_accessor_variable* self = (grib_accessor_variable*)a; + grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; char buf[80]; char* p = buf; @@ -358,9 +251,9 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len) return GRIB_SUCCESS; } -static int pack_string(grib_accessor* a, const char* val, size_t* len) +int grib_accessor_class_variable_t::pack_string(grib_accessor* a, const char* val, size_t* len) { - grib_accessor_variable* self = (grib_accessor_variable*)a; + grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; const grib_context* c = a->context; grib_context_free(c, self->cval); @@ -372,27 +265,27 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len) return GRIB_SUCCESS; } -static int value_count(grib_accessor* a, long* count) +int grib_accessor_class_variable_t::value_count(grib_accessor* a, long* count) { *count = 1; return 0; } -static size_t string_length(grib_accessor* a) +size_t grib_accessor_class_variable_t::string_length(grib_accessor* a) { - const grib_accessor_variable* self = (grib_accessor_variable*)a; + const grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; if (self->type == GRIB_TYPE_STRING) return strlen(self->cval); else return MAX_VARIABLE_STRING_LENGTH; } -static long byte_count(grib_accessor* a) +long grib_accessor_class_variable_t::byte_count(grib_accessor* a) { return a->length; } -static int compare(grib_accessor* a, grib_accessor* b) +int grib_accessor_class_variable_t::compare(grib_accessor* a, grib_accessor* b) { int retval = GRIB_SUCCESS; double* aval = 0; @@ -403,12 +296,12 @@ static int compare(grib_accessor* a, grib_accessor* b) int err = 0; long count = 0; - err = grib_value_count(a, &count); + err = a->value_count(&count); if (err) return err; alen = count; - err = grib_value_count(b, &count); + err = b->value_count(&count); if (err) return err; blen = count; @@ -419,8 +312,8 @@ static int compare(grib_accessor* a, grib_accessor* b) aval = (double*)grib_context_malloc(a->context, alen * sizeof(double)); bval = (double*)grib_context_malloc(b->context, blen * sizeof(double)); - grib_unpack_double(a, aval, &alen); - grib_unpack_double(b, bval, &blen); + a->unpack_double(aval, &alen); + b->unpack_double(bval, &blen); retval = GRIB_SUCCESS; retval = GRIB_SUCCESS; @@ -434,11 +327,11 @@ static int compare(grib_accessor* a, grib_accessor* b) return retval; } -static grib_accessor* make_clone(grib_accessor* a, grib_section* s, int* err) +grib_accessor* grib_accessor_class_variable_t::make_clone(grib_accessor* a, grib_section* s, int* err) { grib_accessor* the_clone = NULL; - const grib_accessor_variable* self = (grib_accessor_variable*)a; - grib_accessor_variable* variableAccessor = NULL; + const grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; + grib_accessor_variable_t* variableAccessor = NULL; grib_action creator = {0,}; creator.op = (char*)"variable"; creator.name_space = (char*)""; @@ -449,7 +342,7 @@ static grib_accessor* make_clone(grib_accessor* a, grib_section* s, int* err) the_clone->parent = NULL; the_clone->h = s->h; the_clone->flags = a->flags; - variableAccessor = (grib_accessor_variable*)the_clone; + variableAccessor = (grib_accessor_variable_t*)the_clone; variableAccessor->cname = creator.name; /* ECC-765: Store for later freeing memory */ *err = 0; diff --git a/src/accessor/grib_accessor_class_variable.h b/src/accessor/grib_accessor_class_variable.h new file mode 100644 index 000000000..90ff71238 --- /dev/null +++ b/src/accessor/grib_accessor_class_variable.h @@ -0,0 +1,49 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor.h" +#include "grib_accessor_class_gen.h" + + +class grib_accessor_variable_t : public grib_accessor_gen_t +{ +public: + double dval; + float fval; + char* cval; + char* cname; + int type; +}; + +class grib_accessor_class_variable_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_variable_t(const char* name) : grib_accessor_class_gen_t(name) {}; + grib_accessor* create_empty_accessor() override { return new grib_accessor_variable_t{}; } + int get_native_type(grib_accessor*) override; + int pack_double(grib_accessor*, const double* val, size_t* len) override; + int pack_float(grib_accessor*, const float* val, size_t* len) override; + int pack_long(grib_accessor*, const long* val, size_t* len) override; + int pack_string(grib_accessor*, const char*, size_t* len) override; + int unpack_double(grib_accessor*, double* val, size_t* len) override; + int unpack_float(grib_accessor*, float* val, size_t* len) override; + int unpack_long(grib_accessor*, long* val, size_t* len) override; + int unpack_string(grib_accessor*, char*, size_t* len) override; + size_t string_length(grib_accessor*) override; + long byte_count(grib_accessor*) override; + int value_count(grib_accessor*, long*) override; + void destroy(grib_context*, grib_accessor*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + int compare(grib_accessor*, grib_accessor*) override; + grib_accessor* make_clone(grib_accessor*, grib_section*, int*) override; +}; diff --git a/src/accessor/grib_accessor_class_vector.cc b/src/accessor/grib_accessor_class_vector.cc new file mode 100644 index 000000000..f08809f6f --- /dev/null +++ b/src/accessor/grib_accessor_class_vector.cc @@ -0,0 +1,60 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_vector.h" +#include "grib_accessor_class_abstract_vector.h" + +grib_accessor_class_vector_t _grib_accessor_class_vector{ "vector" }; +grib_accessor_class* grib_accessor_class_vector = &_grib_accessor_class_vector; + + +void grib_accessor_class_vector_t::init(grib_accessor* a, const long l, grib_arguments* c) +{ + grib_accessor_class_abstract_vector_t::init(a, l, c); + grib_accessor_vector_t* self = (grib_accessor_vector_t*)a; + int n = 0; + + self->vector = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + self->index = grib_arguments_get_long(grib_handle_of_accessor(a), c, n++); + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; + a->length = 0; +} + +int grib_accessor_class_vector_t::unpack_double(grib_accessor* a, double* val, size_t* len) +{ + int err = 0; + size_t size = 0; + double* stat; + grib_accessor_vector_t* self = (grib_accessor_vector_t*)a; + grib_accessor* va = (grib_accessor*)grib_find_accessor(grib_handle_of_accessor(a), self->vector); + grib_accessor_abstract_vector_t* v = (grib_accessor_abstract_vector_t*)va; + + Assert(self->index >= 0); + + if (self->index >= v->number_of_elements) { + grib_context_log(a->context, GRIB_LOG_FATAL, "index=%d number_of_elements=%d for %s", self->index, v->number_of_elements, a->name); + Assert(self->index < v->number_of_elements); + } + + if (va->dirty) { + grib_get_size(grib_handle_of_accessor(a), self->vector, &size); + stat = (double*)grib_context_malloc_clear(a->context, sizeof(double) * size); + err = va->unpack_double(stat, &size); + grib_context_free(a->context, stat); + if (err) + return err; + } + + *val = v->v[self->index]; + + return err; +} diff --git a/src/accessor/grib_accessor_class_vector.h b/src/accessor/grib_accessor_class_vector.h new file mode 100644 index 000000000..92dc6a13e --- /dev/null +++ b/src/accessor/grib_accessor_class_vector.h @@ -0,0 +1,31 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_abstract_vector.h" + +class grib_accessor_vector_t : public grib_accessor_abstract_vector_t +{ +public: + /* Members defined in vector */ + const char* vector; + int index; +}; + +class grib_accessor_class_vector_t : public grib_accessor_class_abstract_vector_t +{ +public: + grib_accessor_class_vector_t(const char* name) : grib_accessor_class_abstract_vector_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_vector_t{}; } + int unpack_double(grib_accessor*, double* val, size_t* len) override; + void init(grib_accessor*, const long, grib_arguments*) override; +}; diff --git a/src/accessor/grib_accessor_class_when.cc b/src/accessor/grib_accessor_class_when.cc new file mode 100644 index 000000000..48db76803 --- /dev/null +++ b/src/accessor/grib_accessor_class_when.cc @@ -0,0 +1,39 @@ + +/* + * (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. + */ + +#include "grib_accessor_class_when.h" + +grib_accessor_class_when_t _grib_accessor_class_when{ "when" }; +grib_accessor_class* grib_accessor_class_when = &_grib_accessor_class_when; + + +void grib_accessor_class_when_t::init(grib_accessor* a, const long len, grib_arguments* arg) +{ + grib_accessor_class_gen_t::init(a, len, arg); + a->length = 0; + a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; + a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; +} + +void grib_accessor_class_when_t::dump(grib_accessor* a, grib_dumper* dumper) +{ + /* grib_dump_when(dumper,a,NULL); */ +} + +int grib_accessor_class_when_t::notify_change(grib_accessor* a, grib_accessor* changed) +{ + return grib_action_notify_change(a->creator, a, changed); +} + +int grib_accessor_class_when_t::get_native_type(grib_accessor* a) +{ + return GRIB_TYPE_UNDEFINED; +} diff --git a/src/accessor/grib_accessor_class_when.h b/src/accessor/grib_accessor_class_when.h new file mode 100644 index 000000000..515afb4b1 --- /dev/null +++ b/src/accessor/grib_accessor_class_when.h @@ -0,0 +1,31 @@ + +/* + * (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. + */ + +#pragma once + +#include "grib_accessor_class_gen.h" + +class grib_accessor_when_t : public grib_accessor_gen_t +{ +public: + /* Members defined in when */ +}; + +class grib_accessor_class_when_t : public grib_accessor_class_gen_t +{ +public: + grib_accessor_class_when_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor* create_empty_accessor() override { return new grib_accessor_when_t{}; } + int get_native_type(grib_accessor*) override; + void dump(grib_accessor*, grib_dumper*) override; + void init(grib_accessor*, const long, grib_arguments*) override; + int notify_change(grib_accessor*, grib_accessor*) override; +}; diff --git a/src/accessor/grib_accessors_list.cc b/src/accessor/grib_accessors_list.cc new file mode 100644 index 000000000..173077e69 --- /dev/null +++ b/src/accessor/grib_accessors_list.cc @@ -0,0 +1,150 @@ +/* + * (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. + */ + +#include "grib_accessors_list.h" + +grib_accessors_list* grib_accessors_list_create(grib_context* c) +{ + return (grib_accessors_list*)grib_context_malloc_clear(c, sizeof(grib_accessors_list)); +} + +void grib_accessors_list_delete(grib_context* c, grib_accessors_list* al) +{ + grib_accessors_list* tmp; + while (al) { + tmp = al->next_; + grib_context_free(c, al); + al = tmp; + } +} + +int grib_accessors_list::value_count(size_t* count) +{ + long lcount = 0; + *count = 0; + grib_accessors_list* al = this; + while (al) { + al->accessor->value_count(&lcount); + *count += lcount; + al = al->next_; + } + return 0; +} + +void grib_accessors_list::push(grib_accessor* a, int rank) +{ + grib_accessors_list* last; + const grib_context* c = a->context; + + last = this->last(); + if (last && last->accessor) { + last->next_ = (grib_accessors_list*)grib_context_malloc_clear(c, sizeof(grib_accessors_list)); + last->next_->accessor = a; + last->next_->prev_ = last; + last->next_->rank_ = rank; + this->last_ = last->next_; + } + else { + this->accessor = a; + this->rank_ = rank; + this->last_ = this; + } +} + +grib_accessors_list* grib_accessors_list::last() +{ + return last_; +} + +grib_accessors_list::~grib_accessors_list() +{ + grib_accessors_list* tmp; + grib_context* c = grib_context_get_default(); + + grib_accessors_list* al = this; + while (al) { + tmp = al->next_; + // grib_accessor_delete(c, al->accessor); + grib_context_free(c, al); + al = tmp; + } +} + +int grib_accessors_list::unpack_long(long* val, size_t* buffer_len) +{ + int err = GRIB_SUCCESS; + size_t unpacked_len = 0; + size_t len = 0; + + grib_accessors_list* al = this; + while (al && err == GRIB_SUCCESS) { + len = *buffer_len - unpacked_len; + err = al->accessor->unpack_long(val + unpacked_len, &len); + unpacked_len += len; + al = al->next_; + } + + *buffer_len = unpacked_len; + return err; +} + +int grib_accessors_list::unpack_double(double* val, size_t* buffer_len) +{ + int err = GRIB_SUCCESS; + size_t unpacked_len = 0; + size_t len = 0; + + grib_accessors_list* al = this; + while (al && err == GRIB_SUCCESS) { + len = *buffer_len - unpacked_len; + err = al->accessor->unpack_double(val + unpacked_len, &len); + unpacked_len += len; + al = al->next_; + } + + *buffer_len = unpacked_len; + return err; +} + +int grib_accessors_list::unpack_float(float* val, size_t* buffer_len) +{ + int err = GRIB_SUCCESS; + size_t unpacked_len = 0; + size_t len = 0; + + grib_accessors_list* al = this; + while (al && err == GRIB_SUCCESS) { + len = *buffer_len - unpacked_len; + err = al->accessor->unpack_float(val + unpacked_len, &len); + unpacked_len += len; + al = al->next_; + } + + *buffer_len = unpacked_len; + return err; +} + +int grib_accessors_list::unpack_string(char** val, size_t* buffer_len) +{ + int err = GRIB_SUCCESS; + size_t unpacked_len = 0; + size_t len = 0; + + grib_accessors_list* al = this; + while (al && err == GRIB_SUCCESS) { + len = *buffer_len - unpacked_len; + err = al->accessor->unpack_string_array(val + unpacked_len, &len); + unpacked_len += len; + al = al->next_; + } + + *buffer_len = unpacked_len; + return err; +} diff --git a/src/accessor/grib_accessors_list.h b/src/accessor/grib_accessors_list.h new file mode 100644 index 000000000..e136d955a --- /dev/null +++ b/src/accessor/grib_accessors_list.h @@ -0,0 +1,40 @@ +/* + * (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. + */ + +#pragma once + +#include "grib_accessor.h" + +class grib_accessors_list +{ +public: + grib_accessors_list(); + ~grib_accessors_list(); + + int value_count(size_t* count); + void push(grib_accessor* a, int rank); + grib_accessors_list* last(); + int unpack_long(long* val, size_t* buffer_len); + int unpack_double(double* val, size_t* buffer_len); + int unpack_float(float* val, size_t* buffer_len); + int unpack_string(char** val, size_t* buffer_len); + + int rank() const { return rank_; } + + grib_accessor* accessor = nullptr; + grib_accessors_list* next_ = nullptr; + grib_accessors_list* prev_ = nullptr; + grib_accessors_list* last_ = nullptr; +private: + int rank_ = 0; +}; + +grib_accessors_list* grib_accessors_list_create(grib_context* c); +void grib_accessors_list_delete(grib_context* c, grib_accessors_list* al); diff --git a/src/action_class_gen.cc b/src/action_class_gen.cc index 641aa3c92..722391c7f 100644 --- a/src/action_class_gen.cc +++ b/src/action_class_gen.cc @@ -152,7 +152,7 @@ static int create_accessor(grib_section* p, grib_action* act, grib_loader* loade static int notify_change(grib_action* act, grib_accessor* notified, grib_accessor* changed) { if (act->default_value) - return grib_pack_expression(notified, grib_arguments_get_expression(grib_handle_of_accessor(notified), act->default_value, 0)); + return notified->pack_expression(grib_arguments_get_expression(grib_handle_of_accessor(notified), act->default_value, 0)); return GRIB_SUCCESS; } diff --git a/src/action_class_remove.cc b/src/action_class_remove.cc index 40f5079a7..eff91cdce 100644 --- a/src/action_class_remove.cc +++ b/src/action_class_remove.cc @@ -94,7 +94,7 @@ static void remove_accessor(grib_accessor* a) grib_section* s = NULL; int id; - if (!a || !a->previous) + if (!a || !a->previous_) return; s = a->parent; @@ -103,14 +103,14 @@ static void remove_accessor(grib_accessor* a) grib_handle_of_accessor(a)->accessors[id] = NULL; } - if (a->next) - a->previous->next = a->next; + if (a->next_) + a->previous_->next_ = a->next_; else return; - a->next->previous = a->previous; + a->next_->previous_ = a->previous_; - grib_accessor_delete(s->h->context, a); + a->destroy(s->h->context); } static int create_accessor(grib_section* p, grib_action* act, grib_loader* h) diff --git a/src/action_class_transient_darray.cc b/src/action_class_transient_darray.cc index 673f83502..276dcf3fa 100644 --- a/src/action_class_transient_darray.cc +++ b/src/action_class_transient_darray.cc @@ -117,7 +117,7 @@ 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 a->pack_double(self->darray->v, &len); } static void dump(grib_action* act, FILE* f, int lvl) diff --git a/src/bufr_keys_iterator.cc b/src/bufr_keys_iterator.cc index e1ab89697..d22b0349b 100644 --- a/src/bufr_keys_iterator.cc +++ b/src/bufr_keys_iterator.cc @@ -176,7 +176,7 @@ int codes_bufr_keys_iterator_next(bufr_keys_iterator* kiter) return 1; } else { - kiter->current = grib_next_accessor(kiter->current); + kiter->current = kiter->current->next_accessor(); kiter->attributes = 0; if (kiter->prefix) { grib_context_free(kiter->current->context, kiter->prefix); @@ -187,7 +187,7 @@ int codes_bufr_keys_iterator_next(bufr_keys_iterator* kiter) } while (kiter->current && skip(kiter)) - kiter->current = grib_next_accessor(kiter->current); + kiter->current = kiter->current->next_accessor(); return kiter->current != NULL; } diff --git a/src/eccodes_prototypes.h b/src/eccodes_prototypes.h index e98ae83c2..ab2d4531e 100644 --- a/src/eccodes_prototypes.h +++ b/src/eccodes_prototypes.h @@ -1,13 +1,3 @@ -/* - * (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. - */ - #pragma once #ifdef ECCODES_ON_WINDOWS @@ -107,57 +97,7 @@ grib_action* grib_action_create_modify(grib_context* context, const char* name, /* action_class_transient_darray.cc */ grib_action* grib_action_create_transient_darray(grib_context* context, const char* name, grib_darray* darray, int flags); -/* grib_accessor.cc */ -void grib_accessor_dump(grib_accessor* a, grib_dumper* f); -int grib_pack_missing(grib_accessor* a); -int grib_is_missing_internal(grib_accessor* a); -int grib_pack_double(grib_accessor* a, const double* v, size_t* len); -int grib_pack_float(grib_accessor* a, const float* v, size_t* len); -int grib_pack_expression(grib_accessor* a, grib_expression* e); -int grib_pack_string(grib_accessor* a, const char* v, size_t* len); -int grib_pack_string_array(grib_accessor* a, const char** v, size_t* len); -int grib_pack_long(grib_accessor* a, const long* v, size_t* len); -int grib_pack_bytes(grib_accessor* a, const unsigned char* v, size_t* len); -int grib_unpack_bytes(grib_accessor* a, unsigned char* v, size_t* len); -int grib_unpack_double_subarray(grib_accessor* a, double* v, size_t start, size_t len); -int grib_unpack_double(grib_accessor* a, double* v, size_t* len); -int grib_unpack_float(grib_accessor* a, float* v, size_t* len); -int grib_unpack_double_element(grib_accessor* a, size_t i, double* v); -int grib_unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array); -int grib_unpack_float_element(grib_accessor* a, size_t i, float* v); -int grib_unpack_float_element_set(grib_accessor* a, const size_t* index_array, size_t len, float* val_array); -int grib_unpack_string(grib_accessor* a, char* v, size_t* len); -int grib_unpack_string_array(grib_accessor* a, char** v, size_t* len); -int grib_accessors_list_unpack_long(grib_accessors_list* al, long* val, size_t* buffer_len); -int grib_accessors_list_unpack_double(grib_accessors_list* al, double* val, size_t* buffer_len); -int grib_accessors_list_unpack_float(grib_accessors_list* al, float* val, size_t* buffer_len); -int grib_accessors_list_unpack_string(grib_accessors_list* al, char** val, size_t* buffer_len); -int grib_unpack_long(grib_accessor* a, long* v, size_t* len); -long grib_accessor_get_native_type(grib_accessor* a); -long grib_get_next_position_offset(grib_accessor* a); -long grib_string_length(grib_accessor* a); -long grib_byte_offset(grib_accessor* a); -long grib_byte_count(grib_accessor* a); -int grib_value_count(grib_accessor* a, long* count); -int grib_accessors_list_value_count(grib_accessors_list* al, size_t* count); -int grib_accessor_notify_change(grib_accessor* a, grib_accessor* changed); -void grib_init_accessor(grib_accessor* a, const long len, grib_arguments* args); -void grib_accessor_delete(grib_context* ct, grib_accessor* a); -grib_accessor* grib_accessor_clone(grib_accessor* a, grib_section* s, int* err); -void grib_update_size(grib_accessor* a, size_t len); -int grib_nearest_smaller_value(grib_accessor* a, double val, double* nearest); -size_t grib_preferred_size(grib_accessor* a, int from_handle); -grib_accessor* grib_next_accessor(grib_accessor* a); -void grib_resize(grib_accessor* a, size_t new_size); -int grib_compare_accessors(grib_accessor* a1, grib_accessor* a2, int compare_flags); -int grib_accessor_add_attribute(grib_accessor* a, grib_accessor* attr, int nest_if_clash); -grib_accessor* grib_accessor_get_attribute_index(grib_accessor* a, const char* name, int* index); -int grib_accessor_has_attributes(grib_accessor* a); -grib_accessor* grib_accessor_get_attribute(grib_accessor* a, const char* name); -grib_accessors_list* grib_accessors_list_create(grib_context* c); -void grib_accessors_list_push(grib_accessors_list* al, grib_accessor* a, int rank); -grib_accessors_list* grib_accessors_list_last(grib_accessors_list* al); -void grib_accessors_list_delete(grib_context* c, grib_accessors_list* al); +/* grib_accessor.cc*/ /* grib_concept.cc */ grib_concept_value* grib_concept_value_new(grib_context* c, const char* name, grib_concept_condition* conditions); @@ -243,11 +183,17 @@ grib_viarray* grib_viarray_push(grib_context* c, grib_viarray* v, grib_iarray* v void grib_viarray_delete(grib_context* c, grib_viarray* v); void grib_viarray_delete_content(grib_context* c, grib_viarray* v); -/* grib_accessor_class_bufr_data_array.cc */ -grib_vsarray* accessor_bufr_data_array_get_stringValues(grib_accessor* a); -grib_accessors_list* accessor_bufr_data_array_get_dataAccessors(grib_accessor* a); -grib_trie_with_rank* accessor_bufr_data_array_get_dataAccessorsTrie(grib_accessor* a); -void accessor_bufr_data_array_set_unpackMode(grib_accessor* a, int unpackMode); +/* grib_accessor_class_ascii.cc*/ + +/* grib_accessor_class_bit.cc*/ + +/* grib_accessor_class_bitmap.cc*/ + +/* grib_accessor_class_bits.cc*/ + +/* grib_accessor_class_bits_per_value.cc*/ + +/* grib_accessor_class_bufr_data_array.cc*/ /* grib_accessor_class_bufr_data_element.cc */ void accessor_bufr_data_element_set_index(grib_accessor* a, long index); @@ -532,6 +478,7 @@ grib_handle* grib_fieldset_retrieve(grib_fieldset* set, int i, int* err); /* grib_filepool.cc */ void grib_file_pool_clean(void); +grib_file* grib_file_pool_get_files(void); grib_file* grib_file_open(const char* filename, const char* mode, int* err); void grib_file_pool_delete_file(grib_file* file); void grib_file_close(const char* filename, int force, int* err); diff --git a/src/grib_accessor_class.cc b/src/grib_accessor_class.cc index 9cdd04b97..4120fb5bd 100644 --- a/src/grib_accessor_class.cc +++ b/src/grib_accessor_class.cc @@ -11,11 +11,12 @@ #include "grib_api_internal.h" #include "grib_accessor_classes_hash.cc" +#include /* grib level */ /* This file is generated by ./make_class.pl */ -#include "grib_accessor_class.h" +#include "accessor/grib_accessor.h" #if GRIB_PTHREADS static pthread_once_t once = PTHREAD_ONCE_INIT; @@ -139,7 +140,7 @@ grib_accessor* grib_accessor_factory(grib_section* p, grib_action* creator, c = *((grib_accessor_classes_hash(creator->op, strlen(creator->op)))->cclass); #endif - a = (grib_accessor*)grib_context_malloc_clear(p->h->context, c->size); + a = c->create_empty_accessor(); a->name = creator->name; a->name_space = creator->name_space; @@ -150,8 +151,8 @@ grib_accessor* grib_accessor_factory(grib_section* p, grib_action* creator, a->creator = creator; a->context = p->h->context; a->h = NULL; - a->next = NULL; - a->previous = NULL; + a->next_ = NULL; + a->previous_ = NULL; a->parent = p; a->length = 0; a->offset = 0; @@ -159,7 +160,7 @@ grib_accessor* grib_accessor_factory(grib_section* p, grib_action* creator, a->set = creator->set; if (p->block->last) { - a->offset = grib_get_next_position_offset(p->block->last); + a->offset = p->block->last->get_next_position_offset(); //printf("offset: p->block->last %s %s %ld %ld\n", // p->block->last->cclass->name, @@ -176,8 +177,8 @@ grib_accessor* grib_accessor_factory(grib_section* p, grib_action* creator, a->cclass = c; - grib_init_accessor(a, len, params); - size = grib_get_next_position_offset(a); + a->init_accessor(len, params); + size = a->get_next_position_offset(); if (size > p->h->buffer->ulength) { if (!p->h->buffer->growable) { @@ -189,7 +190,7 @@ grib_accessor* grib_accessor_factory(grib_section* p, grib_action* creator, a->offset + a->length, p->h->buffer->ulength); - grib_accessor_delete(p->h->context, a); + a->destroy(p->h->context); return NULL; } else { @@ -223,10 +224,10 @@ static void link_same_attributes(grib_accessor* a, grib_accessor* b) grib_accessor* bAttribute = NULL; if (a == NULL || b == NULL) return; - if (!grib_accessor_has_attributes(b)) + if (!b->has_attributes()) return; while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes[i]) { - bAttribute = grib_accessor_get_attribute_index(b, a->attributes[i]->name, &idx); + bAttribute = b->get_attribute_index(a->attributes[i]->name, &idx); if (bAttribute) a->attributes[i]->same = bAttribute; i++; @@ -240,8 +241,8 @@ void grib_push_accessor(grib_accessor* a, grib_block_of_accessors* l) if (!l->first) l->first = l->last = a; else { - l->last->next = a; - a->previous = l->last; + l->last->next_ = a; + a->previous_ = l->last; } l->last = a; @@ -270,11 +271,11 @@ void grib_section_post_init(grib_section* s) while (a) { grib_accessor_class* c = a->cclass; - if (c->post_init) - c->post_init(a); + c->post_init(a); + if (a->sub_section) grib_section_post_init(a->sub_section); - a = a->next; + a = a->next_; } } @@ -306,20 +307,20 @@ int grib_section_adjust_sizes(grib_section* s, int update, int depth) } length += l; offset += l; - a = a->next; + a = a->next_; } if (s) { if (s->aclength) { size_t len = 1; long plen = 0; - int lret = grib_unpack_long(s->aclength, &plen, &len); + int lret = s->aclength->unpack_long(&plen, &len); Assert(lret == GRIB_SUCCESS); /* This happens when there is some padding */ if ((plen != length) || force_update) { if (update) { plen = length; - lret = grib_pack_long(s->aclength, &plen, &len); + lret = s->aclength->pack_long(&plen, &len); if (lret != GRIB_SUCCESS) return lret; s->padding = 0; @@ -358,7 +359,7 @@ int grib_get_block_length(grib_section* s, size_t* l) // if(s->aclength) { // size_t len = 1; // long plen = 0; -// int ret = grib_unpack_long(s->aclength, &plen, &len); +// int ret = s->aclength->unpack_long(&plen, &len); // if(ret == GRIB_SUCCESS && plen != 0) // { // *l = plen; @@ -371,13 +372,13 @@ int grib_get_block_length(grib_section* s, size_t* l) // return GRIB_SUCCESS; // } // // no accessor for block length -// if(s->owner) *l = grib_get_next_position_offset(s->block->last) - s->owner->offset; -// else *l = grib_get_next_position_offset(s->block->last); +// if(s->owner) *l = s->block->last->get_next_position_offset() - s->owner->offset; +// else *l = s->block->last->get_next_position_offset(); // if(s->aclength) { // size_t len = 1; // long plen = *l; -// int ret = grib_pack_long(s->aclength, &plen, &len); +// int ret = s->aclength->pack_long(&plen, &len); // if(ret != GRIB_SUCCESS) // ; // if(s->h->context->debug) @@ -397,10 +398,10 @@ grib_accessor* find_paddings(grib_section* s) if (p) return p; - if (grib_preferred_size(a, 0) != a->length) + if (a->preferred_size(0) != a->length) return a; - a = a->next; + a = a->next_; } return NULL; @@ -414,7 +415,7 @@ void grib_update_paddings(grib_section* s) /* while((changed = find_paddings(s)) != NULL) */ while ((changed = find_paddings(s->h->root)) != NULL) { Assert(changed != last); - grib_resize(changed, grib_preferred_size(changed, 0)); + changed->resize(changed->preferred_size(0)); last = changed; } } diff --git a/src/grib_accessor_class.h b/src/grib_accessor_class.h index 0c569decd..cfec4d21d 100644 --- a/src/grib_accessor_class.h +++ b/src/grib_accessor_class.h @@ -1,4 +1,5 @@ -/* This file is automatically generated by ./make_class.pl, do not edit */ +#include "grib_api_internal.h" + extern grib_accessor_class* grib_accessor_class_abstract_long_vector; extern grib_accessor_class* grib_accessor_class_abstract_vector; extern grib_accessor_class* grib_accessor_class_ascii; diff --git a/src/grib_accessor_class_abstract_long_vector.cc b/src/grib_accessor_class_abstract_long_vector.cc deleted file mode 100644 index 523e0a740..000000000 --- a/src/grib_accessor_class_abstract_long_vector.cc +++ /dev/null @@ -1,103 +0,0 @@ -/* - * (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. - */ - -/****************************************************************** - * Enrico Fucile - ******************************************************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - MEMBERS = long* v - MEMBERS = long pack_index - MEMBERS = int number_of_elements - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - - -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_abstract_long_vector; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_abstract_long_vector = { - &grib_accessor_class_gen, /* super */ - "abstract_long_vector", /* name */ - sizeof(grib_accessor_abstract_long_vector), /* size */ - 0, /* inited */ - 0, /* init_class */ - 0, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_abstract_long_vector = &_grib_accessor_class_abstract_long_vector; - -/* END_CLASS_IMP */ diff --git a/src/grib_accessor_class_abstract_vector.cc b/src/grib_accessor_class_abstract_vector.cc deleted file mode 100644 index 1353aeffc..000000000 --- a/src/grib_accessor_class_abstract_vector.cc +++ /dev/null @@ -1,98 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_double - MEMBERS = double* v - MEMBERS = int number_of_elements - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - - -typedef struct grib_accessor_abstract_vector -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in abstract_vector */ - double* v; - int number_of_elements; -} grib_accessor_abstract_vector; - -extern grib_accessor_class* grib_accessor_class_double; - -static grib_accessor_class _grib_accessor_class_abstract_vector = { - &grib_accessor_class_double, /* super */ - "abstract_vector", /* name */ - sizeof(grib_accessor_abstract_vector), /* size */ - 0, /* inited */ - 0, /* init_class */ - 0, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_abstract_vector = &_grib_accessor_class_abstract_vector; - -/* END_CLASS_IMP */ diff --git a/src/grib_accessor_class_ascii.cc b/src/grib_accessor_class_ascii.cc deleted file mode 100644 index b0c90182e..000000000 --- a/src/grib_accessor_class_ascii.cc +++ /dev/null @@ -1,278 +0,0 @@ -/* - * (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. - */ -/*********************************************************** - * Enrico Fucile - ***********************************************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = unpack_string;pack_string - IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = unpack_double;pack_double - IMPLEMENTS = init;dump;string_length - IMPLEMENTS = value_count - IMPLEMENTS = get_native_type - IMPLEMENTS = compare - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int pack_string(grib_accessor*, const char*, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static size_t string_length(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); -static int compare(grib_accessor*, grib_accessor*); - -typedef struct grib_accessor_ascii -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in ascii */ -} grib_accessor_ascii; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_ascii = { - &grib_accessor_class_gen, /* super */ - "ascii", /* name */ - sizeof(grib_accessor_ascii), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - &string_length, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - &pack_string, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - &compare, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_ascii = &_grib_accessor_class_ascii; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - a->length = len; - Assert(a->length >= 0); -} - -static int value_count(grib_accessor* a, long* count) -{ - *count = 1; - return 0; -} - -static size_t string_length(grib_accessor* a) -{ - return a->length; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_string(dumper, a, NULL); -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_STRING; -} - -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - size_t i = 0; - grib_handle* hand = grib_handle_of_accessor(a); - const size_t alen = a->length; - - if (*len < (alen + 1)) { - const char* cclass_name = a->cclass->name; - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, alen+1, *len); - *len = alen + 1; - return GRIB_BUFFER_TOO_SMALL; - } - - for (i = 0; i < alen; i++) - val[i] = hand->buffer->data[a->offset + i]; - val[i] = 0; - *len = i; - return GRIB_SUCCESS; -} - -static int pack_string(grib_accessor* a, const char* val, size_t* len) -{ - size_t i = 0; - grib_handle* hand = grib_handle_of_accessor(a); - const size_t alen = a->length; - if (len[0] > (alen + 1)) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "pack_string: Wrong size (%zu) for %s, it contains %ld values", len[0], a->name, a->length + 1); - len[0] = 0; - return GRIB_BUFFER_TOO_SMALL; - } - - for (i = 0; i < alen; i++) { - if (i < len[0]) - hand->buffer->data[a->offset + i] = val[i]; - else - hand->buffer->data[a->offset + i] = 0; - } - - return GRIB_SUCCESS; -} - -static int pack_long(grib_accessor* a, const long* v, size_t* len) -{ - grib_context_log(a->context, GRIB_LOG_ERROR, "Should not pack %s as long (It's a string)", a->name); - return GRIB_NOT_IMPLEMENTED; -} - -static int pack_double(grib_accessor* a, const double* v, size_t* len) -{ - grib_context_log(a->context, GRIB_LOG_ERROR, "Should not pack %s as double (It's a string)", a->name); - return GRIB_NOT_IMPLEMENTED; -} - -static int unpack_long(grib_accessor* a, long* v, size_t* len) -{ - char val[1024] = {0,}; - size_t l = sizeof(val); - size_t i = 0; - char* last = NULL; - int err = grib_unpack_string(a, val, &l); - - if (err) - return err; - - i = 0; - while (i < l - 1 && val[i] == ' ') - i++; - - if (val[i] == 0) { - *v = 0; - return 0; - } - if (val[i + 1] == ' ' && i < l - 2) - val[i + 1] = 0; - - *v = strtol(val, &last, 10); - - grib_context_log(a->context, GRIB_LOG_DEBUG, " Casting string %s to long", a->name); - return GRIB_SUCCESS; -} - -static int unpack_double(grib_accessor* a, double* v, size_t* len) -{ - char val[1024]; - size_t l = sizeof(val); - char* last = NULL; - - int err = grib_unpack_string(a, val, &l); - if (err) return err; - - *v = strtod(val, &last); - - if (*last == 0) { - grib_context_log(a->context, GRIB_LOG_DEBUG, " Casting string %s to long", a->name); - return GRIB_SUCCESS; - } - - grib_context_log(a->context, GRIB_LOG_WARNING, "Cannot unpack %s as double. Hint: Try unpacking as string", a->name); - - return GRIB_NOT_IMPLEMENTED; -} - -static int compare(grib_accessor* a, grib_accessor* b) -{ - int retval = 0; - char* aval = 0; - char* bval = 0; - int err = 0; - - size_t alen = a->length+1; - size_t blen = b->length+1; - - if (alen != blen) - return GRIB_COUNT_MISMATCH; - - aval = (char*)grib_context_malloc(a->context, alen * sizeof(char)); - bval = (char*)grib_context_malloc(b->context, blen * sizeof(char)); - - err = grib_unpack_string(a, aval, &alen); - if (err) return err; - err = grib_unpack_string(b, bval, &blen); - if (err) return err; - - retval = GRIB_SUCCESS; - if (!STR_EQUAL(aval, bval)) - retval = GRIB_STRING_VALUE_MISMATCH; - - grib_context_free(a->context, aval); - grib_context_free(b->context, bval); - - return retval; -} diff --git a/src/grib_accessor_class_bit.cc b/src/grib_accessor_class_bit.cc deleted file mode 100644 index ab81eecda..000000000 --- a/src/grib_accessor_class_bit.cc +++ /dev/null @@ -1,170 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = init - MEMBERS = const char* owner - MEMBERS = int bit_index - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_bit -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in bit */ - const char* owner; - int bit_index; -} grib_accessor_bit; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_bit = { - &grib_accessor_class_long, /* super */ - "bit", /* name */ - sizeof(grib_accessor_bit), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_bit = &_grib_accessor_class_bit; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - grib_accessor_bit* self = (grib_accessor_bit*)a; - a->length = 0; - self->owner = grib_arguments_get_name(grib_handle_of_accessor(a), arg, 0); - self->bit_index = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 1); -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_bit* self = (grib_accessor_bit*)a; - int ret = 0; - long data = 0; - - if (*len < 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_bit: unpack_long: Wrong size for %s, it contains %d values ", a->name, 1); - *len = 1; - return GRIB_ARRAY_TOO_SMALL; - } - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->owner, &data)) != GRIB_SUCCESS) { - *len = 0; - return ret; - } - - if (data & (1 << self->bit_index)) - *val = 1; - else - *val = 0; - - *len = 1; - return GRIB_SUCCESS; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - grib_accessor_bit* self = (grib_accessor_bit*)a; - - if (*len < 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_bit: pack_long: At least one value to pack for %s", a->name); - *len = 1; - return GRIB_ARRAY_TOO_SMALL; - } - - grib_accessor* owner = grib_find_accessor(grib_handle_of_accessor(a), self->owner); - if (!owner) { - grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_bit: Cannot get the owner %s for computing the bit value of %s", - self->owner, a->name); - *len = 0; - return GRIB_NOT_FOUND; - } - - unsigned char* mdata = grib_handle_of_accessor(a)->buffer->data; - mdata += grib_byte_offset(owner); - - /* Note: In the definitions, flagbit numbers go from 7 to 0 (the bit_index), while WMO convention is from 1 to 8 */ - if (a->context->debug) { - /* Print bit positions from 1 (MSB) */ - fprintf(stderr, "ECCODES DEBUG Setting bit %d in %s to %d\n", 8 - self->bit_index, owner->name, (*val > 0) ); - } - grib_set_bit(mdata, 7 - self->bit_index, *val > 0); - - *len = 1; - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_bitmap.cc b/src/grib_accessor_class_bitmap.cc deleted file mode 100644 index c5be0ebbb..000000000 --- a/src/grib_accessor_class_bitmap.cc +++ /dev/null @@ -1,297 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -#include - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_bytes - IMPLEMENTS = next_offset - IMPLEMENTS = unpack_double;unpack_double_element;unpack_double_element_set - IMPLEMENTS = unpack_float - IMPLEMENTS = unpack_long - IMPLEMENTS = unpack_string - IMPLEMENTS = string_length - IMPLEMENTS = init;dump;update_size - MEMBERS=const char* tableReference - MEMBERS=const char* missing_value - MEMBERS=const char* offsetbsec - MEMBERS=const char* sLength - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_float(grib_accessor*, float* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static size_t string_length(grib_accessor*); -static long next_offset(grib_accessor*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); -static void update_size(grib_accessor*, size_t); -static int unpack_double_element(grib_accessor*, size_t i, double* val); -static int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array); - -typedef struct grib_accessor_bitmap -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in bytes */ - /* Members defined in bitmap */ - const char* tableReference; - const char* missing_value; - const char* offsetbsec; - const char* sLength; -} grib_accessor_bitmap; - -extern grib_accessor_class* grib_accessor_class_bytes; - -static grib_accessor_class _grib_accessor_class_bitmap = { - &grib_accessor_class_bytes, /* super */ - "bitmap", /* name */ - sizeof(grib_accessor_bitmap), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - &next_offset, /* next_offset */ - &string_length, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - &unpack_float, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - &update_size, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - &unpack_double_element, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - &unpack_double_element_set, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_bitmap = &_grib_accessor_class_bitmap; - -/* END_CLASS_IMP */ - - -static void compute_size(grib_accessor* a) -{ - long slen = 0; - long off = 0; - grib_handle* hand = grib_handle_of_accessor(a); - - grib_accessor_bitmap* self = (grib_accessor_bitmap*)a; - grib_get_long_internal(hand, self->offsetbsec, &off); - grib_get_long_internal(hand, self->sLength, &slen); - - if (slen == 0) { - grib_accessor* seclen; - size_t size; - /* Assume reparsing */ - Assert(hand->loader != 0); - if (hand->loader != 0) { - seclen = grib_find_accessor(hand, self->sLength); - Assert(seclen); - grib_get_block_length(seclen->parent, &size); - slen = size; - } - } - - // printf("compute_size off=%ld slen=%ld a->offset=%ld\n", (long)off,(long)slen,(long)a->offset); - - a->length = off + (slen - a->offset); - - if (a->length < 0) { - /* Assume reparsing */ - /*Assert(hand->loader != 0);*/ - a->length = 0; - } - - Assert(a->length >= 0); -} - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - grib_accessor_bitmap* self = (grib_accessor_bitmap*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int n = 0; - - self->tableReference = grib_arguments_get_name(hand, arg, n++); - self->missing_value = grib_arguments_get_name(hand, arg, n++); - self->offsetbsec = grib_arguments_get_name(hand, arg, n++); - self->sLength = grib_arguments_get_name(hand, arg, n++); - - compute_size(a); -} - -static long next_offset(grib_accessor* a) -{ - return grib_byte_offset(a) + grib_byte_count(a); -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - long len = 0; - char label[1024]; - - grib_value_count(a, &len); - - snprintf(label, 1024, "Bitmap of %ld values", len); - grib_dump_bytes(dumper, a, label); -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - long pos = a->offset * 8; - long tlen = 0; - const grib_handle* hand = grib_handle_of_accessor(a); - - int err = grib_value_count(a, &tlen); - if (err) - return err; - - if (*len < tlen) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %ld values", a->name, tlen); - *len = tlen; - return GRIB_ARRAY_TOO_SMALL; - } - - for (long i = 0; i < tlen; i++) { - val[i] = (long)grib_decode_unsigned_long(hand->buffer->data, &pos, 1); - } - *len = tlen; - return GRIB_SUCCESS; -} - -template -static int unpack(grib_accessor* a, T* val, size_t* len) -{ - static_assert(std::is_floating_point::value, "Requires floating point numbers"); - long pos = a->offset * 8; - long tlen; - grib_handle* hand = grib_handle_of_accessor(a); - - int err = grib_value_count(a, &tlen); - if (err) - return err; - - if (*len < tlen) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %ld values", a->name, tlen); - *len = tlen; - return GRIB_ARRAY_TOO_SMALL; - } - - for (long i = 0; i < tlen; i++) { - val[i] = (T)grib_decode_unsigned_long(hand->buffer->data, &pos, 1); - } - *len = tlen; - return GRIB_SUCCESS; -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - return unpack(a, val, len); -} - -static int unpack_float(grib_accessor* a, float* val, size_t* len) -{ - return unpack(a, val, len); -} - -static int unpack_double_element(grib_accessor* a, size_t idx, double* val) -{ - long pos = a->offset * 8; - - pos += idx; - *val = (double)grib_decode_unsigned_long(grib_handle_of_accessor(a)->buffer->data, &pos, 1); - - return GRIB_SUCCESS; -} -static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) -{ - for (size_t i=0; ilength = s; -} - -static size_t string_length(grib_accessor* a) -{ - return a->length; -} - -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - grib_handle* hand = grib_handle_of_accessor(a); - const size_t l = a->length; - - if (*len < l) { - const char* cclass_name = a->cclass->name; - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, l, *len); - *len = l; - return GRIB_BUFFER_TOO_SMALL; - } - - for (long i = 0; i < a->length; i++) { - val[i] = hand->buffer->data[a->offset + i]; - } - - *len = a->length; - - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_bits_per_value.cc b/src/grib_accessor_class_bits_per_value.cc deleted file mode 100644 index 5648a9a69..000000000 --- a/src/grib_accessor_class_bits_per_value.cc +++ /dev/null @@ -1,165 +0,0 @@ -/* - * (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. - */ - -/********************************** - * Enrico Fucile - *********************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long; pack_long - IMPLEMENTS = init - MEMBERS = const char* values - MEMBERS = const char* bits_per_value - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_bits_per_value -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in bits_per_value */ - const char* values; - const char* bits_per_value; -} grib_accessor_bits_per_value; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_bits_per_value = { - &grib_accessor_class_long, /* super */ - "bits_per_value", /* name */ - sizeof(grib_accessor_bits_per_value), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_bits_per_value = &_grib_accessor_class_bits_per_value; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* args) -{ - int n = 0; - grib_accessor_bits_per_value* self = (grib_accessor_bits_per_value*)a; - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->bits_per_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->length = 0; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - int ret = 0; - grib_accessor_bits_per_value* self = (grib_accessor_bits_per_value*)a; - grib_handle* h = grib_handle_of_accessor(a); - - if ((ret = grib_get_long_internal(h, self->bits_per_value, val)) != GRIB_SUCCESS) - return ret; - - *len = 1; - return ret; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - double* values = NULL; - size_t size = 0; - int ret = 0; - grib_accessor_bits_per_value* self = (grib_accessor_bits_per_value*)a; - grib_context* c = a->context; - grib_handle* h = grib_handle_of_accessor(a); - - if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) - return ret; - - values = (double*)grib_context_malloc(c, size * sizeof(double)); - if (!values) - return GRIB_OUT_OF_MEMORY; - - if ((ret = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) { - grib_context_free(c, values); - return ret; - } - - if ((ret = grib_set_long_internal(h, self->bits_per_value, *val)) != GRIB_SUCCESS) { - grib_context_free(c, values); - return ret; - } - - if ((ret = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) { - grib_context_free(c, values); - return ret; - } - - grib_context_free(c, values); - - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_blob.cc b/src/grib_accessor_class_blob.cc deleted file mode 100644 index 7e1c1de62..000000000 --- a/src/grib_accessor_class_blob.cc +++ /dev/null @@ -1,128 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = get_native_type;init - IMPLEMENTS = unpack_bytes;dump - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_bytes(grib_accessor*, unsigned char*, size_t* len); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_blob -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in blob */ -} grib_accessor_blob; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_blob = { - &grib_accessor_class_gen, /* super */ - "blob", /* name */ - sizeof(grib_accessor_blob), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - &unpack_bytes, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_blob = &_grib_accessor_class_blob; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - grib_get_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, arg, 0), &a->length); - Assert(a->length >= 0); -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_BYTES; -} - -static int unpack_bytes(grib_accessor* a, unsigned char* buffer, size_t* len) -{ - if (*len < (size_t)a->length) { - *len = a->length; - return GRIB_ARRAY_TOO_SMALL; - } - *len = a->length; - - memcpy(buffer, grib_handle_of_accessor(a)->buffer->data + a->offset, *len); - - return GRIB_SUCCESS; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_bytes(dumper, a, NULL); -} diff --git a/src/grib_accessor_class_budgdate.cc b/src/grib_accessor_class_budgdate.cc deleted file mode 100644 index 15fc9b4bd..000000000 --- a/src/grib_accessor_class_budgdate.cc +++ /dev/null @@ -1,174 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = init - MEMBERS=const char* year - MEMBERS=const char* month - MEMBERS=const char* day - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_budgdate -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in budgdate */ - const char* year; - const char* month; - const char* day; -} grib_accessor_budgdate; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_budgdate = { - &grib_accessor_class_long, /* super */ - "budgdate", /* name */ - sizeof(grib_accessor_budgdate), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_budgdate = &_grib_accessor_class_budgdate; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_budgdate* self = (grib_accessor_budgdate*)a; - int n = 0; - - self->year = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->month = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->day = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - int ret = 0; - grib_accessor_budgdate* self = (grib_accessor_budgdate*)a; - - long year = 0; - long month = 0; - long day = 0; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->day, &day)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->month, &month)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->year, &year)) != GRIB_SUCCESS) - return ret; - - if (*len < 1) - return GRIB_WRONG_ARRAY_SIZE; - - val[0] = (1900 + year) * 10000 + month * 100 + day; - - return ret; -} - -/* TODO: Check for a valid date */ -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - int ret = 0; - long v = val[0]; - grib_accessor_budgdate* self = (grib_accessor_budgdate*)a; - - long year = 0; - long month = 0; - long day = 0; - - if (*len != 1) - return GRIB_WRONG_ARRAY_SIZE; - - year = v / 10000; - v %= 10000; - month = v / 100; - v %= 100; - day = v; - - year -= 1900; - - Assert(year < 255); - - if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->day, day)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->month, month)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->year, year)) != GRIB_SUCCESS) - return ret; - - return ret; -} diff --git a/src/grib_accessor_class_bufr_extract_subsets.cc b/src/grib_accessor_class_bufr_extract_subsets.cc deleted file mode 100644 index 567ceb61a..000000000 --- a/src/grib_accessor_class_bufr_extract_subsets.cc +++ /dev/null @@ -1,152 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init; get_native_type - IMPLEMENTS = pack_long; - MEMBERS = const char* numericValues - MEMBERS = const char* pack - MEMBERS = grib_accessor* numericValuesAccessor - MEMBERS = grib_accessor* packAccessor - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_bufr_extract_subsets -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in bufr_extract_subsets */ - const char* numericValues; - const char* pack; - grib_accessor* numericValuesAccessor; - grib_accessor* packAccessor; -} grib_accessor_bufr_extract_subsets; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_bufr_extract_subsets = { - &grib_accessor_class_gen, /* super */ - "bufr_extract_subsets", /* name */ - sizeof(grib_accessor_bufr_extract_subsets), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_bufr_extract_subsets = &_grib_accessor_class_bufr_extract_subsets; - -/* END_CLASS_IMP */ - -static void get_accessors(grib_accessor* a) -{ - grib_accessor_bufr_extract_subsets* self = (grib_accessor_bufr_extract_subsets*)a; - const grib_handle* h = grib_handle_of_accessor(a); - - if (self->packAccessor) - return; - self->numericValuesAccessor = grib_find_accessor(h, self->numericValues); - self->packAccessor = grib_find_accessor(h, self->pack); -} - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - int n = 0; - grib_accessor_bufr_extract_subsets* self = (grib_accessor_bufr_extract_subsets*)a; - - a->length = 0; - self->numericValues = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); - self->pack = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; -} - -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) -{ - grib_accessor_bufr_extract_subsets* self = (grib_accessor_bufr_extract_subsets*)a; - size_t l = 1; - long v[1]; - - get_accessors(a); - - v[0] = 1; - int err = grib_pack_long(self->packAccessor, v, &l); - if (err) { - if (err == GRIB_ENCODING_ERROR) - grib_context_log(a->context, GRIB_LOG_ERROR, "Could not extract subset(s).\n\tHint: Did you forget to set unpack=1?"); - return err; - } - - return err; -} diff --git a/src/grib_accessor_class_bufr_group.cc b/src/grib_accessor_class_bufr_group.cc deleted file mode 100644 index 9af0a5633..000000000 --- a/src/grib_accessor_class_bufr_group.cc +++ /dev/null @@ -1,126 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_variable - IMPLEMENTS = dump;next - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static void dump(grib_accessor*, grib_dumper*); -static grib_accessor* next(grib_accessor*, int); - -typedef struct grib_accessor_bufr_group -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in variable */ - double dval; - float fval; - char* cval; - char* cname; - int type; - /* Members defined in bufr_group */ -} grib_accessor_bufr_group; - -extern grib_accessor_class* grib_accessor_class_variable; - -static grib_accessor_class _grib_accessor_class_bufr_group = { - &grib_accessor_class_variable, /* super */ - "bufr_group", /* name */ - sizeof(grib_accessor_bufr_group), /* size */ - 0, /* inited */ - 0, /* init_class */ - 0, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - &next, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_bufr_group = &_grib_accessor_class_bufr_group; - -/* END_CLASS_IMP */ - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_section(dumper, a, a->sub_section->block); -} - -static grib_accessor* next(grib_accessor* a, int explore) -{ - grib_accessor* next = NULL; - if (explore) { - next = a->sub_section->block->first; - if (!next) - next = a->next; - } - else { - next = a->next; - } - if (!next) { - if (a->parent->owner) - next = a->parent->owner->cclass->next(a->parent->owner, 0); - } - return next; -} diff --git a/src/grib_accessor_class_bufr_simple_thinning.cc b/src/grib_accessor_class_bufr_simple_thinning.cc deleted file mode 100644 index cd0181fe4..000000000 --- a/src/grib_accessor_class_bufr_simple_thinning.cc +++ /dev/null @@ -1,211 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init; get_native_type - IMPLEMENTS = pack_long; - MEMBERS = const char* doExtractSubsets - MEMBERS = const char* numberOfSubsets - MEMBERS = const char* extractSubsetList - MEMBERS = const char* simpleThinningStart - MEMBERS = const char* simpleThinningMissingRadius - MEMBERS = const char* simpleThinningSkip - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_bufr_simple_thinning -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in bufr_simple_thinning */ - const char* doExtractSubsets; - const char* numberOfSubsets; - const char* extractSubsetList; - const char* simpleThinningStart; - const char* simpleThinningMissingRadius; - const char* simpleThinningSkip; -} grib_accessor_bufr_simple_thinning; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_bufr_simple_thinning = { - &grib_accessor_class_gen, /* super */ - "bufr_simple_thinning", /* name */ - sizeof(grib_accessor_bufr_simple_thinning), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_bufr_simple_thinning = &_grib_accessor_class_bufr_simple_thinning; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - grib_accessor_bufr_simple_thinning* self = (grib_accessor_bufr_simple_thinning*)a; - grib_handle* h = grib_handle_of_accessor(a); - int n = 0; - - a->length = 0; - self->doExtractSubsets = grib_arguments_get_name(h, arg, n++); - self->numberOfSubsets = grib_arguments_get_name(h, arg, n++); - self->extractSubsetList = grib_arguments_get_name(h, arg, n++); - self->simpleThinningStart = grib_arguments_get_name(h, arg, n++); - self->simpleThinningMissingRadius = grib_arguments_get_name(h, arg, n++); - self->simpleThinningSkip = grib_arguments_get_name(h, arg, n++); - - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_LONG; -} - -static int apply_thinning(grib_accessor* a) -{ - const grib_accessor_bufr_simple_thinning* self = (grib_accessor_bufr_simple_thinning*)a; - - long skip; - grib_handle* h = grib_handle_of_accessor(a); - grib_context* c = h->context; - long compressed = 0, nsubsets; - grib_iarray* subsets; - long* subsets_ar = 0; - long start = 0, radius = 0; - - int ret = grib_get_long(h, "compressedData", &compressed); - if (ret) - return ret; - if (compressed) { - long numberOfSubsets = 0; - ret = grib_get_long(h, self->numberOfSubsets, &numberOfSubsets); - if (ret) - return ret; - - ret = grib_get_long(h, self->simpleThinningStart, &start); - if (ret) - return ret; - - ret = grib_get_long(h, self->simpleThinningSkip, &skip); - if (ret) - return ret; - if (skip <= 0) - return GRIB_INVALID_KEY_VALUE; - - ret = grib_get_long(h, self->simpleThinningMissingRadius, &radius); - if (ret) - return ret; - - subsets = grib_iarray_new(c, numberOfSubsets / skip + 1, 10); - for (long i = 0; i < numberOfSubsets; i += skip + 1) { - grib_iarray_push(subsets, i + 1); - } - - nsubsets = grib_iarray_used_size(subsets); - - if (nsubsets != 0) { - subsets_ar = grib_iarray_get_array(subsets); - ret = grib_set_long_array(h, self->extractSubsetList, subsets_ar, nsubsets); - grib_context_free(c, subsets_ar); - if (ret) - return ret; - - ret = grib_set_long(h, "unpack", 1); - if (ret) - return ret; - - ret = grib_set_long(h, self->doExtractSubsets, 1); - if (ret) - return ret; - } - grib_iarray_delete(subsets); - } - else { - return GRIB_NOT_IMPLEMENTED; - } - - return ret; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - const grib_accessor_bufr_simple_thinning* self = (grib_accessor_bufr_simple_thinning*)a; - - if (*len == 0) - return GRIB_SUCCESS; - int err = apply_thinning(a); - if (err) - return err; - - return grib_set_long(a->parent->h, self->doExtractSubsets, 1); -} diff --git a/src/grib_accessor_class_bufr_string_values.cc b/src/grib_accessor_class_bufr_string_values.cc deleted file mode 100644 index 02627e763..000000000 --- a/src/grib_accessor_class_bufr_string_values.cc +++ /dev/null @@ -1,189 +0,0 @@ -/* -* (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. -*/ - -/* Sequences and replication (not delayed) are resolved in this class. - Number of elements to which a delayed replication applies are recomputed to - take account of the expansion. - Expanded descriptors cannot contain sequences and only delayed replication - can appear -*/ - -#include "grib_api_internal.h" -/* -This is used by make_class.pl - -START_CLASS_DEF -CLASS = accessor -SUPER = grib_accessor_class_ascii -IMPLEMENTS = unpack_string_array -IMPLEMENTS = unpack_string -IMPLEMENTS = init;dump;destroy -IMPLEMENTS = value_count -MEMBERS = const char* dataAccessorName -MEMBERS = grib_accessor* dataAccessor - -END_CLASS_DEF - -*/ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_string(grib_accessor*, char*, size_t* len); -static int unpack_string_array(grib_accessor*, char**, size_t* len); -static int value_count(grib_accessor*, long*); -static void destroy(grib_context*, grib_accessor*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_bufr_string_values -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in ascii */ - /* Members defined in bufr_string_values */ - const char* dataAccessorName; - grib_accessor* dataAccessor; -} grib_accessor_bufr_string_values; - -extern grib_accessor_class* grib_accessor_class_ascii; - -static grib_accessor_class _grib_accessor_class_bufr_string_values = { - &grib_accessor_class_ascii, /* super */ - "bufr_string_values", /* name */ - sizeof(grib_accessor_bufr_string_values), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - &destroy, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - &unpack_string_array, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_bufr_string_values = &_grib_accessor_class_bufr_string_values; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* args) -{ - grib_accessor_bufr_string_values* self = (grib_accessor_bufr_string_values*)a; - int n = 0; - self->dataAccessorName = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->dataAccessor = NULL; - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_string_array(dumper, a, NULL); -} - -static grib_accessor* get_accessor(grib_accessor* a) -{ - grib_accessor_bufr_string_values* self = (grib_accessor_bufr_string_values*)a; - if (!self->dataAccessor) { - self->dataAccessor = grib_find_accessor(grib_handle_of_accessor(a), self->dataAccessorName); - } - return self->dataAccessor; -} - -static int unpack_string_array(grib_accessor* a, char** buffer, size_t* len) -{ - grib_accessor* data = 0; - grib_context* c = a->context; - grib_vsarray* stringValues = NULL; - size_t l = 0, tl; - size_t i, j, n = 0; - char** b = buffer; - - data = get_accessor(a); - if (!data) - return GRIB_NOT_FOUND; - - stringValues = accessor_bufr_data_array_get_stringValues(data); - - n = grib_vsarray_used_size(stringValues); - - tl = 0; - for (j = 0; j < n; j++) { - l = grib_sarray_used_size(stringValues->v[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]); - } - } - *len = tl; - - return GRIB_SUCCESS; -} - -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - return GRIB_NOT_IMPLEMENTED; -} - -static int value_count(grib_accessor* a, long* rlen) -{ - grib_accessor* descriptors = get_accessor(a); - return grib_value_count(descriptors, rlen); -} - -static void destroy(grib_context* c, grib_accessor* a) -{ -} diff --git a/src/grib_accessor_class_bufrdc_expanded_descriptors.cc b/src/grib_accessor_class_bufrdc_expanded_descriptors.cc deleted file mode 100644 index 929e21724..000000000 --- a/src/grib_accessor_class_bufrdc_expanded_descriptors.cc +++ /dev/null @@ -1,206 +0,0 @@ -/* -* (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. -*/ - -/* Sequences and replication (not delayed) are resolved in this class. - Number of elements to which a delayed replication applies are recomputed to - take account of the expansion. - Expanded descriptors cannot contain sequences and only delayed replication - can appear -*/ - -#include "grib_api_internal.h" -/* -This is used by make_class.pl - -START_CLASS_DEF -CLASS = accessor -SUPER = grib_accessor_class_long -IMPLEMENTS = unpack_long -IMPLEMENTS = unpack_string_array -IMPLEMENTS = init;destroy -IMPLEMENTS = value_count -MEMBERS = const char* expandedDescriptors -MEMBERS = grib_accessor* expandedDescriptorsAccessor - -END_CLASS_DEF - -*/ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string_array(grib_accessor*, char**, size_t* len); -static int value_count(grib_accessor*, long*); -static void destroy(grib_context*, grib_accessor*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_bufrdc_expanded_descriptors -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in bufrdc_expanded_descriptors */ - const char* expandedDescriptors; - grib_accessor* expandedDescriptorsAccessor; -} grib_accessor_bufrdc_expanded_descriptors; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_bufrdc_expanded_descriptors = { - &grib_accessor_class_long, /* super */ - "bufrdc_expanded_descriptors", /* name */ - sizeof(grib_accessor_bufrdc_expanded_descriptors), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - &destroy, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - &unpack_string_array, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_bufrdc_expanded_descriptors = &_grib_accessor_class_bufrdc_expanded_descriptors; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* args) -{ - grib_accessor_bufrdc_expanded_descriptors* self = (grib_accessor_bufrdc_expanded_descriptors*)a; - int n = 0; - self->expandedDescriptors = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->expandedDescriptorsAccessor = 0; - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; -} - -static grib_accessor* get_accessor(grib_accessor* a) -{ - grib_accessor_bufrdc_expanded_descriptors* self = (grib_accessor_bufrdc_expanded_descriptors*)a; - if (!self->expandedDescriptorsAccessor) { - self->expandedDescriptorsAccessor = grib_find_accessor(grib_handle_of_accessor(a), self->expandedDescriptors); - } - return self->expandedDescriptorsAccessor; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor* descriptors = 0; - size_t rlen = 0, l; - long lenall = 0; - size_t i = 0; - long* v = 0; - grib_context* c = a->context; - - descriptors = get_accessor(a); - if (!descriptors) return GRIB_NOT_FOUND; - - grib_value_count(a, &lenall); - v = (long*)grib_context_malloc_clear(c, sizeof(long) * lenall); - l = lenall; - grib_unpack_long(descriptors, v, &l); - - rlen = 0; - for (i = 0; i < l; i++) { - if ((v[i] < 100000 || v[i] > 221999)) - val[rlen++] = v[i]; - } - *len = rlen; - grib_context_free(c,v); - - return GRIB_SUCCESS; -} - -static int unpack_string_array(grib_accessor* a, char** buffer, size_t* len) -{ - int err = 0; - grib_accessor* descriptors = 0; - size_t l = 0; - long lenall = 0; - size_t i = 0; - long* v = 0; - char buf[25] = {0,}; - grib_context* c = a->context; - - descriptors = get_accessor(a); - if (!descriptors) return GRIB_NOT_FOUND; - - err = grib_value_count(a, &lenall); - if (err) return err; - l = lenall; - if (l > *len) return GRIB_ARRAY_TOO_SMALL; - - v = (long*)grib_context_malloc_clear(c, sizeof(long) * l); - err = grib_unpack_long(descriptors, v, &l); - if (err) return err; - - for (i = 0; i < l; i++) { - snprintf(buf, sizeof(buf), "%06ld", v[i]); - buffer[i] = grib_context_strdup(c, buf); - } - *len = l; - grib_context_free(c,v); - - return GRIB_SUCCESS; -} - -static int value_count(grib_accessor* a, long* rlen) -{ - grib_accessor* descriptors = get_accessor(a); - - return grib_value_count(descriptors, rlen); -} - -static void destroy(grib_context* c, grib_accessor* a) -{ -} diff --git a/src/grib_accessor_class_bytes.cc b/src/grib_accessor_class_bytes.cc deleted file mode 100644 index 71533095e..000000000 --- a/src/grib_accessor_class_bytes.cc +++ /dev/null @@ -1,192 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = get_native_type;init - IMPLEMENTS = compare;unpack_string;pack_string - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_string(grib_accessor*, const char*, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); -static int compare(grib_accessor*, grib_accessor*); - -typedef struct grib_accessor_bytes -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in bytes */ -} grib_accessor_bytes; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_bytes = { - &grib_accessor_class_gen, /* super */ - "bytes", /* name */ - sizeof(grib_accessor_bytes), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - &pack_string, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - &compare, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_bytes = &_grib_accessor_class_bytes; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - /*grib_accessor_signed* self = (grib_accessor_signed*)a; */ - a->length = len; - Assert(a->length >= 0); -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_BYTES; -} - -static int compare(grib_accessor* a, grib_accessor* b) -{ - int retval = GRIB_SUCCESS; - - size_t alen = (size_t)grib_byte_count(a); - size_t blen = (size_t)grib_byte_count(b); - - if (alen != blen) - return GRIB_COUNT_MISMATCH; - - return retval; -} - -static int unpack_string(grib_accessor* a, char* v, size_t* len) -{ - unsigned char* p = NULL; - char* s = v; - long i = 0; - const long length = grib_byte_count(a); - const long slength = 2 * length; - - if (*len < (size_t)slength) { - *len = slength; - return GRIB_BUFFER_TOO_SMALL; - } - - p = grib_handle_of_accessor(a)->buffer->data + grib_byte_offset(a); - - for (i = 0; i < length; i++) { - snprintf(s, INT_MAX, "%02x", *(p++)); - s += 2; - } - - *len = slength; - - return GRIB_SUCCESS; -} - -static int pack_string(grib_accessor* a, const char* val, size_t* len) -{ - /* The string representation (val) of the byte array will have two chars - * per byte e.g. 4C5B means the 2 bytes 0114 and 0133 in octal - * so has to be twice the length of the byte array - */ - int err = 0; - grib_accessor_class* super = *(a->cclass->super); - grib_context* c = a->context; - size_t nbytes = a->length; - const size_t expected_blen = nbytes; - const size_t expected_slen = 2 * expected_blen; - unsigned char* bytearray = NULL; - size_t i = 0, slen = strlen(val); - - if (slen != expected_slen || *len != expected_slen) { - grib_context_log(c, GRIB_LOG_ERROR, - "%s: Key %s is %lu bytes. Expected a string with %lu characters (actual length=%zu)", - __func__, a->name, expected_blen, expected_slen, *len); - return GRIB_WRONG_ARRAY_SIZE; - } - - bytearray = (unsigned char*)grib_context_malloc(c, nbytes * (sizeof(unsigned char))); - if (!bytearray) return GRIB_OUT_OF_MEMORY; - - for (i = 0; i < (slen/2); i++) { - unsigned int byteVal = 0; - if (sscanf(val + 2*i, "%02x", &byteVal) != 1) { - grib_context_log(c, GRIB_LOG_ERROR,"%s: Invalid hex byte specfication '%.2s'", __func__, val + 2*i); - grib_context_free(c, bytearray); - return GRIB_INVALID_KEY_VALUE; - } - Assert(byteVal < 256); - bytearray[i] = (int)byteVal; - } - - /* Forward to base class to pack the byte array */ - err = super->pack_bytes(a, bytearray, &nbytes); - grib_context_free(c, bytearray); - return err; -} diff --git a/src/grib_accessor_class_change_alternative_row_scanning.cc b/src/grib_accessor_class_change_alternative_row_scanning.cc deleted file mode 100644 index d8eef0eb4..000000000 --- a/src/grib_accessor_class_change_alternative_row_scanning.cc +++ /dev/null @@ -1,212 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = pack_long; - IMPLEMENTS = unpack_long - IMPLEMENTS = init;get_native_type - MEMBERS = const char* values - MEMBERS = const char* Ni - MEMBERS = const char* Nj - MEMBERS = const char* alternativeRowScanning - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_change_alternative_row_scanning -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in change_alternative_row_scanning */ - const char* values; - const char* Ni; - const char* Nj; - const char* alternativeRowScanning; -} grib_accessor_change_alternative_row_scanning; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_change_alternative_row_scanning = { - &grib_accessor_class_gen, /* super */ - "change_alternative_row_scanning", /* name */ - sizeof(grib_accessor_change_alternative_row_scanning), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_change_alternative_row_scanning = &_grib_accessor_class_change_alternative_row_scanning; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* args) -{ - int n = 0; - grib_accessor_change_alternative_row_scanning* self = (grib_accessor_change_alternative_row_scanning*)a; - - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->Ni = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->Nj = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->alternativeRowScanning = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->length = 0; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - int err = 0; - grib_accessor_change_alternative_row_scanning* self = (grib_accessor_change_alternative_row_scanning*)a; - const grib_context* c = a->context; - grib_handle* h = grib_handle_of_accessor(a); - long i, j, jr, theEnd, Ni, Nj, k, kp, alternativeRowScanning; - size_t size = 0; - double* values = NULL; - double tmp = 0.0; - - if (*val == 0) - return 0; - - /* Make sure Ni / Nj are not missing */ - if (grib_is_missing(h, self->Ni, &err) && !err) { - grib_context_log(c, GRIB_LOG_ERROR, "change_alternative_row_scanning: Key %s cannot be 'missing'!", self->Ni); - return GRIB_WRONG_GRID; - } - if (grib_is_missing(h, self->Nj, &err) && !err) { - grib_context_log(c, GRIB_LOG_ERROR, "change_alternative_row_scanning: Key %s cannot be 'missing'!", self->Nj); - return GRIB_WRONG_GRID; - } - - if ((err = grib_get_long_internal(h, self->Ni, &Ni)) != GRIB_SUCCESS) - return err; - if ((err = grib_get_long_internal(h, self->Nj, &Nj)) != GRIB_SUCCESS) - return err; - if ((err = grib_get_long_internal(h, self->alternativeRowScanning, &alternativeRowScanning)) != GRIB_SUCCESS) - return err; - - if ((err = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) - return err; - - if ( size > (size_t)(Ni * Nj) ) { - grib_context_log(c, GRIB_LOG_ERROR, "change_alternative_row_scanning: wrong values size!=Ni*Nj (%zu!=%ld*%ld)", size, Ni, Nj); - return GRIB_WRONG_ARRAY_SIZE; - } - - values = (double*)grib_context_malloc(c, size * sizeof(double)); - if (!values) - return GRIB_OUT_OF_MEMORY; - - if ((err = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) { - grib_context_free(c, values); - return err; - } - - theEnd = Ni / 2; - for (j = 0; j < Nj; j++) { - jr = Ni * j; - for (i = 0; i < theEnd; i++) { - if (j % 2 == 1) { - /* Swap first and last value on every odd row */ - k = jr + i; - kp = jr + Ni - i - 1; - tmp = values[k]; - values[k] = values[kp]; - values[kp] = tmp; - } - } - } - alternativeRowScanning = !alternativeRowScanning; - if ((err = grib_set_long_internal(h, self->alternativeRowScanning, alternativeRowScanning)) != GRIB_SUCCESS) { - grib_context_free(c, values); - return err; - } - - if ((err = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) { - grib_context_free(c, values); - return err; - } - - grib_context_free(c, values); - - return GRIB_SUCCESS; -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_LONG; -} - -static int unpack_long(grib_accessor* a, long* v, size_t* len) -{ - /* Decoding this accessor doesn't make sense so we return a dummy value */ - *v = -1; - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_check_internal_version.cc b/src/grib_accessor_class_check_internal_version.cc deleted file mode 100644 index d59f353de..000000000 --- a/src/grib_accessor_class_check_internal_version.cc +++ /dev/null @@ -1,136 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_ascii - IMPLEMENTS = value_count;string_length - IMPLEMENTS = init - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static size_t string_length(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_check_internal_version -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in ascii */ - /* Members defined in check_internal_version */ -} grib_accessor_check_internal_version; - -extern grib_accessor_class* grib_accessor_class_ascii; - -static grib_accessor_class _grib_accessor_class_check_internal_version = { - &grib_accessor_class_ascii, /* super */ - "check_internal_version", /* name */ - sizeof(grib_accessor_check_internal_version), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - &string_length, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_check_internal_version = &_grib_accessor_class_check_internal_version; - -/* END_CLASS_IMP */ - -/* This is the internal engine version number */ -/* We check this against the version number found in the definitions boot.def file */ -/* See the key "internalVersion" */ -#define LATEST_ENGINE_VERSION 30 - -static void init(grib_accessor* a, const long l, grib_arguments* args) -{ - /* Check version of definition files is compatible with the engine */ - int err = 0; - long defs_file_version = 0; - grib_handle* h = grib_handle_of_accessor(a); - const char* s_defn_version = grib_arguments_get_name(h, args, 0); - Assert(s_defn_version); - - err = grib_get_long_internal(h, s_defn_version, &defs_file_version); - if (!err) { - if (defs_file_version > LATEST_ENGINE_VERSION) { - grib_context_log(h->context, GRIB_LOG_FATAL, - "Definition files version (%d) is greater than engine version (%d)!\n" - " " /* indent for 2nd line */ - "These definition files are for a later version of the ecCodes engine.", - defs_file_version, LATEST_ENGINE_VERSION); - } - } -} - -static int value_count(grib_accessor* a, long* count) -{ - *count = 1; - return 0; -} - -static size_t string_length(grib_accessor* a) -{ - return 255; -} diff --git a/src/grib_accessor_class_codeflag.cc b/src/grib_accessor_class_codeflag.cc deleted file mode 100644 index ab86a64b1..000000000 --- a/src/grib_accessor_class_codeflag.cc +++ /dev/null @@ -1,216 +0,0 @@ -/* - * (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. - */ - -/**************************************** - * Enrico Fucile - **************************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_unsigned - IMPLEMENTS = init;dump - IMPLEMENTS = value_count - MEMBERS = const char* tablename - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int value_count(grib_accessor*, long*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_codeflag -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in unsigned */ - long nbytes; - grib_arguments* arg; - /* Members defined in codeflag */ - const char* tablename; -} grib_accessor_codeflag; - -extern grib_accessor_class* grib_accessor_class_unsigned; - -static grib_accessor_class _grib_accessor_class_codeflag = { - &grib_accessor_class_unsigned, /* super */ - "codeflag", /* name */ - sizeof(grib_accessor_codeflag), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_codeflag = &_grib_accessor_class_codeflag; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* param) -{ - grib_accessor_codeflag* self = (grib_accessor_codeflag*)a; - a->length = len; - self->tablename = grib_arguments_get_string(grib_handle_of_accessor(a), param, 0); - Assert(a->length >= 0); -} - -static int test_bit(long a, long b) -{ - DEBUG_ASSERT(b>=0); - return a & (1 << b); -} - -static int grib_get_codeflag(grib_accessor* a, long code, char* codename) -{ - const grib_accessor_codeflag* self = (grib_accessor_codeflag*)a; - FILE* f = NULL; - char fname[1024]; - char bval[50]; - char num[50]; - char* filename = 0; - char line[1024]; - size_t i = 0; - int j = 0; - int err = 0; - - err = grib_recompose_name(grib_handle_of_accessor(a), NULL, self->tablename, fname, 1); - if (err) { - strncpy(fname, self->tablename, sizeof(fname)-1); - fname[sizeof(fname)-1] = '\0'; - } - - if ((filename = grib_context_full_defs_path(a->context, fname)) == NULL) { - grib_context_log(a->context, GRIB_LOG_WARNING, "Cannot open flag table %s", filename); - strcpy(codename, "Cannot open flag table"); - return GRIB_FILE_NOT_FOUND; - } - - f = codes_fopen(filename, "r"); - if (!f) { - grib_context_log(a->context, (GRIB_LOG_WARNING) | (GRIB_LOG_PERROR), "Cannot open flag table %s", filename); - strcpy(codename, "Cannot open flag table"); - return GRIB_FILE_NOT_FOUND; - } - - // strcpy(codename, self->tablename); - // strcat(codename,": "); - // j = strlen(codename); - - while (fgets(line, sizeof(line) - 1, f)) { - sscanf(line, "%49s %49s", num, bval); - - if (num[0] != '#') { - if ((test_bit(code, a->length * 8 - atol(num)) > 0) == atol(bval)) { - size_t linelen = strlen(line); - codename[j++] = '('; - codename[j++] = num[0]; - codename[j++] = '='; - codename[j++] = bval[0]; - codename[j++] = ')'; - codename[j++] = ' '; - if (j) - codename[j++] = ' '; - - for (i = (strlen(num) + strlen(bval) + 2); i < linelen - 1; i++) - codename[j++] = line[i]; - if (line[i] != '\n') - codename[j++] = line[i]; - codename[j++] = ';'; - } - } - } - - if (j > 1 && codename[j - 1] == ';') - j--; - codename[j] = 0; - - strcat(codename, ":"); - strcat(codename, fname); - - fclose(f); - return GRIB_SUCCESS; -} - -static int value_count(grib_accessor* a, long* count) -{ - *count = 1; - return 0; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - const grib_accessor_codeflag* self = (grib_accessor_codeflag*)a; - long v = 0; - char flagname[1024] = {0,}; - char fname[1024] = {0,}; - - size_t llen = 1; - - grib_recompose_name(grib_handle_of_accessor(a), NULL, self->tablename, fname, 1); - grib_unpack_long(a, &v, &llen); - - grib_get_codeflag(a, v, flagname); - - grib_dump_bits(dumper, a, flagname); -} diff --git a/src/grib_accessor_class_codetable_title.cc b/src/grib_accessor_class_codetable_title.cc deleted file mode 100644 index 2ddd0f3cb..000000000 --- a/src/grib_accessor_class_codetable_title.cc +++ /dev/null @@ -1,171 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init;unpack_string; get_native_type - MEMBERS = const char* codetable - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_string(grib_accessor*, char*, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_codetable_title -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in codetable_title */ - const char* codetable; -} grib_accessor_codetable_title; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_codetable_title = { - &grib_accessor_class_gen, /* super */ - "codetable_title", /* name */ - sizeof(grib_accessor_codetable_title), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_codetable_title = &_grib_accessor_class_codetable_title; - -/* END_CLASS_IMP */ - -typedef struct grib_accessor_codetable -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in unsigned */ - long nbytes; - grib_arguments* arg; - /* Members defined in codetable */ - const char* tablename; - const char* masterDir; - const char* localDir; - grib_codetable* table; -} grib_accessor_codetable; - - -static void init(grib_accessor* a, const long len, grib_arguments* params) -{ - grib_accessor_codetable_title* self = (grib_accessor_codetable_title*)a; - int n = 0; - self->codetable = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++); - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_STRING; -} - -static int unpack_string(grib_accessor* a, char* buffer, size_t* len) -{ - grib_accessor_codetable_title* self = (grib_accessor_codetable_title*)a; - grib_codetable* table = NULL; - - size_t size = 1; - long value; - int err = GRIB_SUCCESS; - char tmp[1024]; - size_t l = 1024; - grib_accessor_codetable* ca = (grib_accessor_codetable*)grib_find_accessor(grib_handle_of_accessor(a), self->codetable); - - if ((err = grib_unpack_long((grib_accessor*)ca, &value, &size)) != GRIB_SUCCESS) - return err; - - table = ca->table; - - if (table && (value >= 0) && (value < table->size) && table->entries[value].title) { - strcpy(tmp, table->entries[value].title); - } - else { - snprintf(tmp, sizeof(tmp), "%d", (int)value); - } - - l = strlen(tmp) + 1; - - if (*len < l) { - const char* cclass_name = a->cclass->name; - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, l, *len); - *len = l; - return GRIB_BUFFER_TOO_SMALL; - } - - strcpy(buffer, tmp); - *len = l; - - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_codetable_units.cc b/src/grib_accessor_class_codetable_units.cc deleted file mode 100644 index de9a9655f..000000000 --- a/src/grib_accessor_class_codetable_units.cc +++ /dev/null @@ -1,171 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init;unpack_string; get_native_type - MEMBERS = const char* codetable - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_string(grib_accessor*, char*, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_codetable_units -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in codetable_units */ - const char* codetable; -} grib_accessor_codetable_units; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_codetable_units = { - &grib_accessor_class_gen, /* super */ - "codetable_units", /* name */ - sizeof(grib_accessor_codetable_units), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_codetable_units = &_grib_accessor_class_codetable_units; - -/* END_CLASS_IMP */ - -typedef struct grib_accessor_codetable -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in unsigned */ - long nbytes; - grib_arguments* arg; - /* Members defined in codetable */ - const char* tablename; - const char* masterDir; - const char* localDir; - grib_codetable* table; -} grib_accessor_codetable; - -static void init(grib_accessor* a, const long len, grib_arguments* params) -{ - grib_accessor_codetable_units* self = (grib_accessor_codetable_units*)a; - - int n = 0; - self->codetable = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++); - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_STRING; -} - -static int unpack_string(grib_accessor* a, char* buffer, size_t* len) -{ - grib_accessor_codetable_units* self = (grib_accessor_codetable_units*)a; - grib_codetable* table = NULL; - - size_t size = 1; - long value; - int err = GRIB_SUCCESS; - char tmp[1024]; - size_t l = sizeof(tmp); - grib_accessor_codetable* ca = (grib_accessor_codetable*)grib_find_accessor(grib_handle_of_accessor(a), self->codetable); - - if ((err = grib_unpack_long((grib_accessor*)ca, &value, &size)) != GRIB_SUCCESS) - return err; - - table = ca->table; - - if (table && (value >= 0) && (value < table->size) && table->entries[value].units) { - strcpy(tmp, table->entries[value].units); - } - else { - snprintf(tmp, sizeof(tmp), "%d", (int)value); - } - - l = strlen(tmp) + 1; - - if (*len < l) { - const char* cclass_name = a->cclass->name; - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, l, *len); - *len = l; - return GRIB_BUFFER_TOO_SMALL; - } - - strcpy(buffer, tmp); - *len = l; - - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_constant.cc b/src/grib_accessor_class_constant.cc deleted file mode 100644 index b54de5b88..000000000 --- a/src/grib_accessor_class_constant.cc +++ /dev/null @@ -1,111 +0,0 @@ -/* - * (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. - */ - - -/************************************* - * Enrico Fucile - **************************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_variable - IMPLEMENTS = init - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_constant -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in variable */ - double dval; - float fval; - char* cval; - char* cname; - int type; - /* Members defined in constant */ -} grib_accessor_constant; - -extern grib_accessor_class* grib_accessor_class_variable; - -static grib_accessor_class _grib_accessor_class_constant = { - &grib_accessor_class_variable, /* super */ - "constant", /* name */ - sizeof(grib_accessor_constant), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_constant = &_grib_accessor_class_constant; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; -} diff --git a/src/grib_accessor_class_count_file.cc b/src/grib_accessor_class_count_file.cc deleted file mode 100644 index 196a48038..000000000 --- a/src/grib_accessor_class_count_file.cc +++ /dev/null @@ -1,114 +0,0 @@ -/* - * (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. - */ - -/*********************************************** - * Enrico Fucile - **********************************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long - IMPLEMENTS = init - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_count_file -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in count_file */ -} grib_accessor_count_file; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_count_file = { - &grib_accessor_class_long, /* super */ - "count_file", /* name */ - sizeof(grib_accessor_count_file), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_count_file = &_grib_accessor_class_count_file; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length = 0; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - *val = grib_context_get_handle_file_count(a->context); - *len = 1; - return 0; -} diff --git a/src/grib_accessor_class_count_total.cc b/src/grib_accessor_class_count_total.cc deleted file mode 100644 index 022cc4998..000000000 --- a/src/grib_accessor_class_count_total.cc +++ /dev/null @@ -1,116 +0,0 @@ -/* - * (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. - */ - - -/*************************************************** - * Enrico Fucile - **************************************************/ - - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long - IMPLEMENTS = init - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_count_total -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in count_total */ -} grib_accessor_count_total; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_count_total = { - &grib_accessor_class_long, /* super */ - "count_total", /* name */ - sizeof(grib_accessor_count_total), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_count_total = &_grib_accessor_class_count_total; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length = 0; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - *val = grib_context_get_handle_total_count(a->context); - *len = 1; - return 0; -} diff --git a/src/grib_accessor_class_data_dummy_field.cc b/src/grib_accessor_class_data_dummy_field.cc deleted file mode 100644 index 65b6d5a8f..000000000 --- a/src/grib_accessor_class_data_dummy_field.cc +++ /dev/null @@ -1,219 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_data_g1simple_packing - IMPLEMENTS = init - IMPLEMENTS = unpack_double - IMPLEMENTS = value_count - IMPLEMENTS = pack_double - MEMBERS=const char* missing_value - MEMBERS=const char* numberOfPoints - MEMBERS=const char* bitmap - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_data_dummy_field -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in values */ - int carg; - const char* seclen; - const char* offsetdata; - const char* offsetsection; - int dirty; - /* Members defined in data_simple_packing */ - int edition; - const char* units_factor; - const char* units_bias; - const char* changing_precision; - const char* number_of_values; - const char* bits_per_value; - const char* reference_value; - const char* binary_scale_factor; - const char* decimal_scale_factor; - const char* optimize_scaling_factor; - /* Members defined in data_g1simple_packing */ - const char* half_byte; - const char* packingType; - const char* ieee_packing; - const char* precision; - /* Members defined in data_dummy_field */ - const char* missing_value; - const char* numberOfPoints; - const char* bitmap; -} grib_accessor_data_dummy_field; - -extern grib_accessor_class* grib_accessor_class_data_g1simple_packing; - -static grib_accessor_class _grib_accessor_class_data_dummy_field = { - &grib_accessor_class_data_g1simple_packing, /* super */ - "data_dummy_field", /* name */ - sizeof(grib_accessor_data_dummy_field), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_data_dummy_field = &_grib_accessor_class_data_dummy_field; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long v, grib_arguments* args) -{ - grib_accessor_data_dummy_field* self = (grib_accessor_data_dummy_field*)a; - self->missing_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); - self->numberOfPoints = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); - self->bitmap = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_data_dummy_field* self = (grib_accessor_data_dummy_field*)a; - size_t i = 0, n_vals = 0; - long numberOfPoints; - double missing_value = 0; - int err = 0; - - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints, &numberOfPoints)) != GRIB_SUCCESS) - return err; - n_vals = numberOfPoints; - - if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value, &missing_value)) != GRIB_SUCCESS) - return err; - - if (*len < n_vals) { - *len = n_vals; - return GRIB_ARRAY_TOO_SMALL; - } - - for (i = 0; i < n_vals; i++) - val[i] = missing_value; - - if (grib_find_accessor(grib_handle_of_accessor(a), self->bitmap)) { - if ((err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->bitmap, val, n_vals)) != GRIB_SUCCESS) - return err; - } - - *len = (long)n_vals; - return err; -} - -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_data_dummy_field* self = (grib_accessor_data_dummy_field*)a; - - size_t n_vals = *len; - int err = 0; - long bits_per_value = 0; - long half_byte = 0; - size_t buflen = 0; - unsigned char* buf = NULL; - - if (*len == 0) - return GRIB_NO_VALUES; - - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) - return err; - - buflen = (1 + ((bits_per_value * n_vals) / 8)) * sizeof(unsigned char); - - buf = (unsigned char*)grib_context_malloc_clear(a->context, buflen); - if (!buf) - return GRIB_OUT_OF_MEMORY; - - half_byte = (buflen * 8) - ((*len) * bits_per_value); - - if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->half_byte, half_byte)) != GRIB_SUCCESS) { - grib_context_free(a->context, buf); - return err; - } - grib_buffer_replace(a, buf, buflen, 1, 1); - - grib_context_free(a->context, buf); - - return GRIB_SUCCESS; -} - -static int value_count(grib_accessor* a, long* numberOfPoints) -{ - grib_accessor_data_dummy_field* self = (grib_accessor_data_dummy_field*)a; - int err = 0; - *numberOfPoints = 0; - - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints, numberOfPoints)) != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to get count of %s (%s)", a->name, grib_get_error_message(err)); - } - - return err; -} diff --git a/src/grib_accessor_class_data_g1complex_packing.cc b/src/grib_accessor_class_data_g1complex_packing.cc deleted file mode 100644 index 6c8fa5cd6..000000000 --- a/src/grib_accessor_class_data_g1complex_packing.cc +++ /dev/null @@ -1,235 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_data_complex_packing - IMPLEMENTS = pack_double - IMPLEMENTS = init - MEMBERS= const char* N - MEMBERS=const char* half_byte - MEMBERS=const char* packingType - MEMBERS=const char* ieee_packing - MEMBERS=const char* precision - END_CLASS_DEF - - */ - - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_data_g1complex_packing -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in values */ - int carg; - const char* seclen; - const char* offsetdata; - const char* offsetsection; - int dirty; - /* Members defined in data_simple_packing */ - int edition; - const char* units_factor; - const char* units_bias; - const char* changing_precision; - const char* number_of_values; - const char* bits_per_value; - const char* reference_value; - const char* binary_scale_factor; - const char* decimal_scale_factor; - const char* optimize_scaling_factor; - /* Members defined in data_complex_packing */ - const char* GRIBEX_sh_bug_present; - const char* ieee_floats; - const char* laplacianOperatorIsSet; - const char* laplacianOperator; - const char* sub_j; - const char* sub_k; - const char* sub_m; - const char* pen_j; - const char* pen_k; - const char* pen_m; - /* Members defined in data_g1complex_packing */ - const char* N; - const char* half_byte; - const char* packingType; - const char* ieee_packing; - const char* precision; -} grib_accessor_data_g1complex_packing; - -extern grib_accessor_class* grib_accessor_class_data_complex_packing; - -static grib_accessor_class _grib_accessor_class_data_g1complex_packing = { - &grib_accessor_class_data_complex_packing, /* super */ - "data_g1complex_packing", /* name */ - sizeof(grib_accessor_data_g1complex_packing), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_data_g1complex_packing = &_grib_accessor_class_data_g1complex_packing; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long v, grib_arguments* args) -{ - grib_accessor_data_g1complex_packing* self = (grib_accessor_data_g1complex_packing*)a; - self->half_byte = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); - self->N = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); - self->packingType = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); - self->ieee_packing = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); - self->precision = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); - self->edition = 1; - a->flags |= GRIB_ACCESSOR_FLAG_DATA; -} - -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_data_g1complex_packing* self = (grib_accessor_data_g1complex_packing*)a; - int ret = GRIB_SUCCESS; - long seclen = 0; - long sub_j = 0; - long sub_k = 0; - long sub_m = 0; - long n = 0; - long half_byte = 0; - long bits_per_value = 0; - size_t buflen = 0; - grib_accessor_class* super = *(a->cclass->super); - - if (*len == 0) - return GRIB_NO_VALUES; - -// /* TODO: spectral_ieee does not work */ -// if (c->ieee_packing && self->ieee_packing) { -// grib_handle* h = grib_handle_of_accessor(a); -// grib_context* c = a->context; -// char* packingType_s = NULL; -// char* ieee_packing_s = NULL; -// long precision = c->ieee_packing == 32 ? 1 : 2; -// size_t lenstr = strlen(self->ieee_packing); - -// packingType_s = grib_context_strdup(c, self->packingType); -// ieee_packing_s = grib_context_strdup(c, self->ieee_packing); -// precision_s = grib_context_strdup(c, self->precision); - -// grib_set_string(h, packingType_s, ieee_packing_s, &lenstr); -// grib_set_long(h, precision_s, precision); - -// grib_context_free(c, packingType_s); -// grib_context_free(c, ieee_packing_s); -// grib_context_free(c, precision_s); -// return grib_set_double_array(h, "values", val, *len); -// } - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->sub_j, &sub_j)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->sub_k, &sub_k)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->sub_m, &sub_m)) != GRIB_SUCCESS) - return ret; - - self->dirty = 1; - - Assert((sub_j == sub_k) && (sub_m == sub_j)); - - ret = super->pack_double(a, val, len); - - if (ret == GRIB_SUCCESS) { - n = a->offset + 4 * ((sub_k + 1) * (sub_k + 2)); - - /* Octet number starts from beginning of message but shouldn't */ - if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->N, n)) != GRIB_SUCCESS) - return ret; - - // ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetsection, &offsetsection); - // if (ret != GRIB_SUCCESS) - // return ret; - // if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->N, n - offsetsection)) != GRIB_SUCCESS) - // return ret; - - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bits_per_value, &bits_per_value); - if (ret != GRIB_SUCCESS) - return ret; - - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->seclen, &seclen); - if (ret != GRIB_SUCCESS) - return ret; - - buflen = 32 * (sub_k + 1) * (sub_k + 2) + (*len - (sub_k + 1) * (sub_k + 2)) * bits_per_value + 18 * 8; - half_byte = seclen * 8 - buflen; - if (a->context->debug == -1) { - fprintf(stderr, "ECCODES DEBUG: half_byte=%ld\n", half_byte); - } - - ret = grib_set_long_internal(grib_handle_of_accessor(a), self->half_byte, half_byte); - if (ret != GRIB_SUCCESS) - return ret; - } - return ret; -} diff --git a/src/grib_accessor_class_data_g1secondary_bitmap.cc b/src/grib_accessor_class_data_g1secondary_bitmap.cc deleted file mode 100644 index 4ae89c576..000000000 --- a/src/grib_accessor_class_data_g1secondary_bitmap.cc +++ /dev/null @@ -1,220 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_data_secondary_bitmap - IMPLEMENTS = init - IMPLEMENTS = pack_double - IMPLEMENTS = value_count - MEMBERS=const char* number_of_ones - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_data_g1secondary_bitmap -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in data_secondary_bitmap */ - const char* primary_bitmap; - const char* secondary_bitmap; - const char* missing_value; - const char* expand_by; - /* Members defined in data_g1secondary_bitmap */ - const char* number_of_ones; -} grib_accessor_data_g1secondary_bitmap; - -extern grib_accessor_class* grib_accessor_class_data_secondary_bitmap; - -static grib_accessor_class _grib_accessor_class_data_g1secondary_bitmap = { - &grib_accessor_class_data_secondary_bitmap, /* super */ - "data_g1secondary_bitmap", /* name */ - sizeof(grib_accessor_data_g1secondary_bitmap), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_data_g1secondary_bitmap = &_grib_accessor_class_data_g1secondary_bitmap; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long v, grib_arguments* args) -{ - grib_accessor_data_g1secondary_bitmap* self = (grib_accessor_data_g1secondary_bitmap*)a; - self->number_of_ones = grib_arguments_get_name(grib_handle_of_accessor(a), args, 4); -} - -static int value_count(grib_accessor* a, long* count) -{ - grib_accessor_data_g1secondary_bitmap* self = (grib_accessor_data_g1secondary_bitmap*)a; - size_t len = 0; - int err = 0; - long expand_by; - *count = 0; - - err = grib_get_long_internal(grib_handle_of_accessor(a), self->expand_by, &expand_by); - if (err) - return err; - - err = grib_get_size(grib_handle_of_accessor(a), self->primary_bitmap, &len); - if (err) - return err; - - *count = expand_by * len; - return GRIB_SUCCESS; -} - -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_data_g1secondary_bitmap* self = (grib_accessor_data_g1secondary_bitmap*)a; - - int err = 0; - - long primary_len = 0; - long secondary_len = 0; - double* primary_bitmap = NULL; - double* secondary_bitmap = NULL; - long i = 0; - long j = 0; - long on = 0; - long k; - long m; - double missing_value = 0; - double present_value = 0; - long expand_by = 0; - - if (*len == 0) - return GRIB_NO_VALUES; - - if ((err = grib_get_long(grib_handle_of_accessor(a), self->expand_by, &expand_by)) != GRIB_SUCCESS) - return err; - if (expand_by <= 0) - return GRIB_ENCODING_ERROR; - - if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value, &missing_value)) != GRIB_SUCCESS) - return err; - - if (*len % expand_by) { - /*TODO: issue warning */ - return GRIB_ENCODING_ERROR; - } - - primary_len = *len / expand_by; - primary_bitmap = (double*)grib_context_malloc_clear(a->context, primary_len * sizeof(double)); - if (!primary_bitmap) - return GRIB_OUT_OF_MEMORY; - - secondary_len = *len; - secondary_bitmap = (double*)grib_context_malloc_clear(a->context, secondary_len * sizeof(double)); - if (!secondary_bitmap) { - grib_context_free(a->context, primary_bitmap); - return GRIB_OUT_OF_MEMORY; - } - - if (missing_value == 0) - present_value = 1; - else - present_value = 0; - - k = 0; - m = 0; - for (i = 0; i < *len; i += expand_by) { - int cnt = 0; - for (j = 0; j < expand_by; j++) - if (val[i + j] == missing_value) - cnt++; - - if (cnt == expand_by) /* all expand_by values are missing */ - primary_bitmap[k++] = missing_value; - else { - primary_bitmap[k++] = present_value; - for (j = 0; j < expand_by; j++) - secondary_bitmap[m++] = val[i + j]; - on++; - } - } - - *len = k; - - /*printf("QQQQQQQ %ld %ld second=%ld\n",primary_len,on,m);*/ - Assert(k == primary_len); - - err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->primary_bitmap, primary_bitmap, k); - if (err == GRIB_SUCCESS) - err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->secondary_bitmap, secondary_bitmap, m); - - grib_context_free(a->context, primary_bitmap); - grib_context_free(a->context, secondary_bitmap); - - if (err == GRIB_SUCCESS) - err = grib_set_long_internal(grib_handle_of_accessor(a), self->number_of_ones, on); - - return err; -} diff --git a/src/grib_accessor_class_data_g1shsimple_packing.cc b/src/grib_accessor_class_data_g1shsimple_packing.cc deleted file mode 100644 index 332b0af0c..000000000 --- a/src/grib_accessor_class_data_g1shsimple_packing.cc +++ /dev/null @@ -1,150 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_data_shsimple_packing - IMPLEMENTS = unpack_double - IMPLEMENTS = value_count - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int value_count(grib_accessor*, long*); - -typedef struct grib_accessor_data_g1shsimple_packing -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in data_shsimple_packing */ - const char* coded_values; - const char* real_part; - int dirty; - /* Members defined in data_g1shsimple_packing */ -} grib_accessor_data_g1shsimple_packing; - -extern grib_accessor_class* grib_accessor_class_data_shsimple_packing; - -static grib_accessor_class _grib_accessor_class_data_g1shsimple_packing = { - &grib_accessor_class_data_shsimple_packing, /* super */ - "data_g1shsimple_packing", /* name */ - sizeof(grib_accessor_data_g1shsimple_packing), /* size */ - 0, /* inited */ - 0, /* init_class */ - 0, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_data_g1shsimple_packing = &_grib_accessor_class_data_g1shsimple_packing; - -/* END_CLASS_IMP */ - - -static int value_count(grib_accessor* a, long* count) -{ - grib_accessor_data_g1shsimple_packing* self = (grib_accessor_data_g1shsimple_packing*)a; - size_t len = 0; - int err = 0; - - err = grib_get_size(grib_handle_of_accessor(a), self->coded_values, &len); - len += 1; - - *count = len; - return err; -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_data_g1shsimple_packing* self = (grib_accessor_data_g1shsimple_packing*)a; - int err = GRIB_SUCCESS; - - size_t coded_n_vals = 0; - size_t n_vals = 0; - - if ((err = grib_get_size(grib_handle_of_accessor(a), self->coded_values, &coded_n_vals)) != GRIB_SUCCESS) - return err; - - n_vals = coded_n_vals + 1; - - if (*len < n_vals) { - *len = n_vals; - return GRIB_ARRAY_TOO_SMALL; - } - - if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->real_part, val)) != GRIB_SUCCESS) - return err; - - val++; - - if ((err = grib_get_double_array_internal(grib_handle_of_accessor(a), self->coded_values, val, &coded_n_vals)) != GRIB_SUCCESS) - return err; - - grib_context_log(a->context, GRIB_LOG_DEBUG, - "grib_accessor_data_g1shsimple_packing_bitmap : unpack_double : creating %s, %d values", - a->name, n_vals); - - *len = n_vals; - - return err; -} diff --git a/src/grib_accessor_class_data_g2complex_packing.cc b/src/grib_accessor_class_data_g2complex_packing.cc deleted file mode 100644 index 98bcaf5cc..000000000 --- a/src/grib_accessor_class_data_g2complex_packing.cc +++ /dev/null @@ -1,164 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_data_complex_packing - IMPLEMENTS = pack_double - IMPLEMENTS = value_count - IMPLEMENTS = init - MEMBERS=const char* numberOfValues - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_data_g2complex_packing -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in values */ - int carg; - const char* seclen; - const char* offsetdata; - const char* offsetsection; - int dirty; - /* Members defined in data_simple_packing */ - int edition; - const char* units_factor; - const char* units_bias; - const char* changing_precision; - const char* number_of_values; - const char* bits_per_value; - const char* reference_value; - const char* binary_scale_factor; - const char* decimal_scale_factor; - const char* optimize_scaling_factor; - /* Members defined in data_complex_packing */ - const char* GRIBEX_sh_bug_present; - const char* ieee_floats; - const char* laplacianOperatorIsSet; - const char* laplacianOperator; - const char* sub_j; - const char* sub_k; - const char* sub_m; - const char* pen_j; - const char* pen_k; - const char* pen_m; - /* Members defined in data_g2complex_packing */ - const char* numberOfValues; -} grib_accessor_data_g2complex_packing; - -extern grib_accessor_class* grib_accessor_class_data_complex_packing; - -static grib_accessor_class _grib_accessor_class_data_g2complex_packing = { - &grib_accessor_class_data_complex_packing, /* super */ - "data_g2complex_packing", /* name */ - sizeof(grib_accessor_data_g2complex_packing), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_data_g2complex_packing = &_grib_accessor_class_data_g2complex_packing; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long v, grib_arguments* args) -{ - grib_accessor_data_g2complex_packing* self = (grib_accessor_data_g2complex_packing*)a; - self->numberOfValues = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); - self->edition = 2; - - a->flags |= GRIB_ACCESSOR_FLAG_DATA; -} - -static int value_count(grib_accessor* a, long* numberOfValues) -{ - grib_accessor_data_g2complex_packing* self = (grib_accessor_data_g2complex_packing*)a; - *numberOfValues = 0; - - return grib_get_long(grib_handle_of_accessor(a), self->numberOfValues, numberOfValues); -} - -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_data_g2complex_packing* self = (grib_accessor_data_g2complex_packing*)a; - int ret = GRIB_SUCCESS; - grib_accessor_class* super = *(a->cclass->super); - - if (*len == 0) - return GRIB_NO_VALUES; - - ret = super->pack_double(a, val, len); - - if (ret == GRIB_SUCCESS) - ret = grib_set_long_internal(grib_handle_of_accessor(a), self->numberOfValues, *len); - - return ret; -} diff --git a/src/grib_accessor_class_data_g2secondary_bitmap.cc b/src/grib_accessor_class_data_g2secondary_bitmap.cc deleted file mode 100644 index cceb3d765..000000000 --- a/src/grib_accessor_class_data_g2secondary_bitmap.cc +++ /dev/null @@ -1,199 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_data_secondary_bitmap - IMPLEMENTS = init - IMPLEMENTS = pack_double - IMPLEMENTS = value_count - MEMBERS=const char* number_of_values - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_data_g2secondary_bitmap -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in data_secondary_bitmap */ - const char* primary_bitmap; - const char* secondary_bitmap; - const char* missing_value; - const char* expand_by; - /* Members defined in data_g2secondary_bitmap */ - const char* number_of_values; -} grib_accessor_data_g2secondary_bitmap; - -extern grib_accessor_class* grib_accessor_class_data_secondary_bitmap; - -static grib_accessor_class _grib_accessor_class_data_g2secondary_bitmap = { - &grib_accessor_class_data_secondary_bitmap, /* super */ - "data_g2secondary_bitmap", /* name */ - sizeof(grib_accessor_data_g2secondary_bitmap), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_data_g2secondary_bitmap = &_grib_accessor_class_data_g2secondary_bitmap; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long v, grib_arguments* args) -{ - grib_accessor_data_g2secondary_bitmap* self = (grib_accessor_data_g2secondary_bitmap*)a; - self->number_of_values = grib_arguments_get_name(grib_handle_of_accessor(a), args, 4); -} - -static int value_count(grib_accessor* a, long* len) -{ - grib_accessor_data_g2secondary_bitmap* self = (grib_accessor_data_g2secondary_bitmap*)a; - *len = 0; - return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, len); -} - -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_data_g2secondary_bitmap* self = (grib_accessor_data_g2secondary_bitmap*)a; - int err = 0; - - long primary_len = 0, secondary_len = 0; - double* primary_bitmap = NULL; - double* secondary_bitmap = NULL; - long i = 0, j = 0, k = 0, m = 0; - double missing_value = 0, present_value = 0; - long expand_by = 0; - - if (*len == 0) - return GRIB_NO_VALUES; - - if ((err = grib_get_long(grib_handle_of_accessor(a), self->expand_by, &expand_by)) != GRIB_SUCCESS) - return err; - if (expand_by <= 0) - return GRIB_ENCODING_ERROR; - - if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value, &missing_value)) != GRIB_SUCCESS) - return err; - - if (*len % expand_by) { - /*TODO: issue warning */ - return GRIB_ENCODING_ERROR; - } - - primary_len = *len / expand_by; - primary_bitmap = (double*)grib_context_malloc_clear(a->context, primary_len * sizeof(double)); - if (!primary_bitmap) - return GRIB_OUT_OF_MEMORY; - - secondary_len = *len; - secondary_bitmap = (double*)grib_context_malloc_clear(a->context, secondary_len * sizeof(double)); - if (!secondary_bitmap) { - grib_context_free(a->context, primary_bitmap); - return GRIB_OUT_OF_MEMORY; - } - - if (missing_value == 0) - present_value = 1; - else - present_value = 0; - - k = 0; - m = 0; - for (i = 0; i < *len; i += expand_by) { - int cnt = 0; - for (j = 0; j < expand_by; j++) - if (val[i + j] == missing_value) - cnt++; - - if (cnt == expand_by) /* all expand_by values are missing */ - primary_bitmap[k++] = missing_value; - else { - primary_bitmap[k++] = present_value; - for (j = 0; j < expand_by; j++) - secondary_bitmap[m++] = val[i + j]; - //on++; - } - } - - *len = k; - - Assert(k == primary_len); - - err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->primary_bitmap, primary_bitmap, k); - if (err == GRIB_SUCCESS) - err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->secondary_bitmap, secondary_bitmap, m); - - grib_context_free(a->context, primary_bitmap); - grib_context_free(a->context, secondary_bitmap); - - if (err == GRIB_SUCCESS) - err = grib_set_long_internal(grib_handle_of_accessor(a), self->number_of_values, *len * expand_by); - - return err; -} diff --git a/src/grib_accessor_class_data_g2shsimple_packing.cc b/src/grib_accessor_class_data_g2shsimple_packing.cc deleted file mode 100644 index bdb1157cf..000000000 --- a/src/grib_accessor_class_data_g2shsimple_packing.cc +++ /dev/null @@ -1,188 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_data_shsimple_packing - IMPLEMENTS = init - IMPLEMENTS = unpack_double - IMPLEMENTS = pack_double - IMPLEMENTS = value_count - MEMBERS=const char* numberOfValues - MEMBERS=const char* numberOfDataPoints - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_data_g2shsimple_packing -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in data_shsimple_packing */ - const char* coded_values; - const char* real_part; - int dirty; - /* Members defined in data_g2shsimple_packing */ - const char* numberOfValues; - const char* numberOfDataPoints; -} grib_accessor_data_g2shsimple_packing; - -extern grib_accessor_class* grib_accessor_class_data_shsimple_packing; - -static grib_accessor_class _grib_accessor_class_data_g2shsimple_packing = { - &grib_accessor_class_data_shsimple_packing, /* super */ - "data_g2shsimple_packing", /* name */ - sizeof(grib_accessor_data_g2shsimple_packing), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_data_g2shsimple_packing = &_grib_accessor_class_data_g2shsimple_packing; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long v, grib_arguments* args) -{ - grib_accessor_data_g2shsimple_packing* self = (grib_accessor_data_g2shsimple_packing*)a; - - self->numberOfValues = grib_arguments_get_name(grib_handle_of_accessor(a), args, 2); - self->numberOfDataPoints = grib_arguments_get_name(grib_handle_of_accessor(a), args, 3); - a->flags |= GRIB_ACCESSOR_FLAG_DATA; -} - -static int value_count(grib_accessor* a, long* len) -{ - grib_accessor_data_g2shsimple_packing* self = (grib_accessor_data_g2shsimple_packing*)a; - *len = 0; - return grib_get_long(grib_handle_of_accessor(a), self->numberOfValues, len); -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_data_g2shsimple_packing* self = (grib_accessor_data_g2shsimple_packing*)a; - int err = GRIB_SUCCESS; - - size_t n_vals = 0; - - if ((err = grib_get_size(grib_handle_of_accessor(a), self->coded_values, &n_vals)) != GRIB_SUCCESS) - return err; - - self->dirty = 0; - - /* n_vals = coded_n_vals+1; */ - - if (*len < n_vals) { - *len = n_vals; - return GRIB_ARRAY_TOO_SMALL; - } - - if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->real_part, val)) != GRIB_SUCCESS) - return err; - - val++; - - if ((err = grib_get_double_array_internal(grib_handle_of_accessor(a), self->coded_values, val, &n_vals)) != GRIB_SUCCESS) - return err; - - *len = n_vals; - - return err; -} - -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_data_g2shsimple_packing* self = (grib_accessor_data_g2shsimple_packing*)a; - int err = GRIB_SUCCESS; - - size_t coded_n_vals = *len - 1; - size_t n_vals = *len; - - if (*len == 0) - return GRIB_NO_VALUES; - - self->dirty = 1; - - if ((err = grib_set_double_internal(grib_handle_of_accessor(a), self->real_part, *val)) != GRIB_SUCCESS) - return err; - - val++; - - if ((err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->coded_values, val, coded_n_vals)) != GRIB_SUCCESS) - return err; - - *len = n_vals; - - if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->numberOfValues, (long)n_vals)) != GRIB_SUCCESS) - return err; - if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->numberOfDataPoints, (long)n_vals)) != GRIB_SUCCESS) - return err; - - return err; -} diff --git a/src/grib_accessor_class_data_g2simple_packing_with_preprocessing.cc b/src/grib_accessor_class_data_g2simple_packing_with_preprocessing.cc deleted file mode 100644 index 88a4de2cb..000000000 --- a/src/grib_accessor_class_data_g2simple_packing_with_preprocessing.cc +++ /dev/null @@ -1,287 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -#define DIRECT 0 -#define INVERSE 1 - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_data_g2simple_packing - IMPLEMENTS = init - IMPLEMENTS = pack_double - IMPLEMENTS = unpack_double - IMPLEMENTS = value_count - MEMBERS=const char* pre_processing - MEMBERS=const char* pre_processing_parameter - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_data_g2simple_packing_with_preprocessing -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in values */ - int carg; - const char* seclen; - const char* offsetdata; - const char* offsetsection; - int dirty; - /* Members defined in data_simple_packing */ - int edition; - const char* units_factor; - const char* units_bias; - const char* changing_precision; - const char* number_of_values; - const char* bits_per_value; - const char* reference_value; - const char* binary_scale_factor; - const char* decimal_scale_factor; - const char* optimize_scaling_factor; - /* Members defined in data_g2simple_packing */ - /* Members defined in data_g2simple_packing_with_preprocessing */ - const char* pre_processing; - const char* pre_processing_parameter; -} grib_accessor_data_g2simple_packing_with_preprocessing; - -extern grib_accessor_class* grib_accessor_class_data_g2simple_packing; - -static grib_accessor_class _grib_accessor_class_data_g2simple_packing_with_preprocessing = { - &grib_accessor_class_data_g2simple_packing, /* super */ - "data_g2simple_packing_with_preprocessing", /* name */ - sizeof(grib_accessor_data_g2simple_packing_with_preprocessing), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_data_g2simple_packing_with_preprocessing = &_grib_accessor_class_data_g2simple_packing_with_preprocessing; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long v, grib_arguments* args) -{ - grib_accessor_data_g2simple_packing_with_preprocessing* self = (grib_accessor_data_g2simple_packing_with_preprocessing*)a; - self->pre_processing = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); - self->pre_processing_parameter = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); - a->flags |= GRIB_ACCESSOR_FLAG_DATA; -} - -static int value_count(grib_accessor* a, long* n_vals) -{ - grib_accessor_data_g2simple_packing_with_preprocessing* self = (grib_accessor_data_g2simple_packing_with_preprocessing*)a; - *n_vals = 0; - - return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, n_vals); -} - -static int pre_processing_func(double* values, long length, long pre_processing, - double* pre_processing_parameter, int mode) -{ - int i = 0, ret = 0; - double min = values[0]; - double next_min = values[0]; - Assert(length > 0); - - switch (pre_processing) { - /* NONE */ - case 0: - break; - /* LOGARITHM */ - case 1: - if (mode == DIRECT) { - for (i = 0; i < length; i++) { - if (values[i] < min) - min = values[i]; - if (values[i] > next_min) - next_min = values[i]; - } - for (i = 0; i < length; i++) { - if (values[i] > min && values[i] < next_min) - next_min = values[i]; - } - if (min > 0) { - *pre_processing_parameter = 0; - for (i = 0; i < length; i++) { - DEBUG_ASSERT(values[i] > 0); - values[i] = log(values[i]); - } - } - else { - double ppp = 0; - *pre_processing_parameter = next_min - 2 * min; - if (next_min == min) - return ret; - ppp = *pre_processing_parameter; - for (i = 0; i < length; i++) { - DEBUG_ASSERT((values[i] + ppp) > 0); - values[i] = log(values[i] + ppp); - } - } - } - else { - Assert(mode == INVERSE); - if (*pre_processing_parameter == 0) { - for (i = 0; i < length; i++) - values[i] = exp(values[i]); - } - else { - for (i = 0; i < length; i++) - values[i] = exp(values[i]) - *pre_processing_parameter; - } - } - break; - default: - ret = GRIB_NOT_IMPLEMENTED; - break; - } - - return ret; -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_data_g2simple_packing_with_preprocessing* self = (grib_accessor_data_g2simple_packing_with_preprocessing*)a; - grib_accessor_class* super = *(a->cclass->super); - grib_accessor_class* super2 = NULL; - - size_t n_vals = 0; - long nn = 0; - int err = 0; - - long pre_processing; - double pre_processing_parameter; - - err = grib_value_count(a, &nn); - n_vals = nn; - if (err) - return err; - - if (n_vals == 0) { - *len = 0; - return GRIB_SUCCESS; - } - - self->dirty = 0; - - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->pre_processing, &pre_processing)) != GRIB_SUCCESS) { - return err; - } - - if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->pre_processing_parameter, &pre_processing_parameter)) != GRIB_SUCCESS) { - return err; - } - - Assert(super->super); - super2 = *(super->super); - err = super2->unpack_double(a, val, &n_vals); /* GRIB-364 */ - if (err != GRIB_SUCCESS) - return err; - - err = pre_processing_func(val, n_vals, pre_processing, &pre_processing_parameter, INVERSE); - if (err != GRIB_SUCCESS) - return err; - - *len = (long)n_vals; - - return err; -} - -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_data_g2simple_packing_with_preprocessing* self = (grib_accessor_data_g2simple_packing_with_preprocessing*)a; - grib_accessor_class* super = *(a->cclass->super); - - size_t n_vals = *len; - int err = 0; - - long pre_processing = 0; - double pre_processing_parameter = 0; - - self->dirty = 1; - - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->pre_processing, &pre_processing)) != GRIB_SUCCESS) - return err; - - err = pre_processing_func((double*)val, n_vals, pre_processing, &pre_processing_parameter, DIRECT); - if (err != GRIB_SUCCESS) - return err; - - err = super->pack_double(a, val, len); - if (err != GRIB_SUCCESS) - return err; - - if ((err = grib_set_double_internal(grib_handle_of_accessor(a), self->pre_processing_parameter, pre_processing_parameter)) != GRIB_SUCCESS) - return err; - - if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->number_of_values, n_vals)) != GRIB_SUCCESS) - return err; - - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_data_raw_packing.cc b/src/grib_accessor_class_data_raw_packing.cc deleted file mode 100644 index 27c3d62e3..000000000 --- a/src/grib_accessor_class_data_raw_packing.cc +++ /dev/null @@ -1,306 +0,0 @@ -/* - * (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. - */ -/***************************** - * Enrico Fucile - ****************************/ - -#include "grib_ieeefloat.h" - -#define PRE_PROCESSING_NONE 0 -#define PRE_PROCESSING_DIFFERENCE 1 -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_values - IMPLEMENTS = init - IMPLEMENTS = unpack_double - IMPLEMENTS = unpack_double_element;unpack_double_element_set - IMPLEMENTS = pack_double - IMPLEMENTS = value_count - MEMBERS=const char* number_of_values - MEMBERS=const char* precision - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); -static int unpack_double_element(grib_accessor*, size_t i, double* val); -static int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array); - -typedef struct grib_accessor_data_raw_packing -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in values */ - int carg; - const char* seclen; - const char* offsetdata; - const char* offsetsection; - int dirty; - /* Members defined in data_raw_packing */ - const char* number_of_values; - const char* precision; -} grib_accessor_data_raw_packing; - -extern grib_accessor_class* grib_accessor_class_values; - -static grib_accessor_class _grib_accessor_class_data_raw_packing = { - &grib_accessor_class_values, /* super */ - "data_raw_packing", /* name */ - sizeof(grib_accessor_data_raw_packing), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - &unpack_double_element, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - &unpack_double_element_set, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_data_raw_packing = &_grib_accessor_class_data_raw_packing; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long v, grib_arguments* args) -{ - grib_accessor_data_raw_packing* self = (grib_accessor_data_raw_packing*)a; - - self->number_of_values = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); - self->precision = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); - a->flags |= GRIB_ACCESSOR_FLAG_DATA; -} - -static int value_count(grib_accessor* a, long* n_vals) -{ - grib_accessor_data_raw_packing* self = (grib_accessor_data_raw_packing*)a; - *n_vals = 0; - return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, n_vals); -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_data_raw_packing* self = (grib_accessor_data_raw_packing*)a; - unsigned char* buf = NULL; - int bytes = 0; - size_t nvals = 0; - long inlen = grib_byte_count(a); - - long precision = 0; - - int code = GRIB_SUCCESS; - - if ((code = grib_get_long(grib_handle_of_accessor(a), self->precision, &precision)) != GRIB_SUCCESS) - return code; - - self->dirty = 0; - - buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; - buf += grib_byte_offset(a); - - switch (precision) { - case 1: - bytes = 4; - break; - case 2: - bytes = 8; - break; - default: - return GRIB_NOT_IMPLEMENTED; - } - - nvals = inlen / bytes; - - if (*len < nvals) - return GRIB_ARRAY_TOO_SMALL; - - code = grib_ieee_decode_array(a->context, buf, nvals, bytes, val); - - *len = nvals; - - return code; -} - -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_data_raw_packing* self = (grib_accessor_data_raw_packing*)a; - - int bytes = 0; - unsigned char* buffer = NULL; - - long precision = 0; - - double* values = (double*)val; - size_t inlen = *len; - - /*int free_buffer = 0; - *int free_values = 0;*/ - - int code = GRIB_SUCCESS; - - size_t bufsize = 0; - - if (*len == 0) - return GRIB_NO_VALUES; - - if ((code = grib_get_long_internal(grib_handle_of_accessor(a), self->precision, &precision)) != GRIB_SUCCESS) - return code; - - self->dirty = 1; - - switch (precision) { - case 1: - bytes = 4; - break; - - case 2: - bytes = 8; - break; - - default: - code = GRIB_NOT_IMPLEMENTED; - goto clean_up; - } - - bufsize = bytes * inlen; - - buffer = (unsigned char*)grib_context_malloc(a->context, bufsize); - - if (!buffer) { - code = GRIB_OUT_OF_MEMORY; - goto clean_up; - } - - code = grib_ieee_encode_array(a->context, values, inlen, bytes, buffer); - -clean_up: - /*if (free_buffer) - * free(buffer); - * if (free_values) - * free(values); - */ - - grib_buffer_replace(a, buffer, bufsize, 1, 1); - - grib_context_buffer_free(a->context, buffer); - - if (code == GRIB_SUCCESS) { - code = grib_set_long(grib_handle_of_accessor(a), self->number_of_values, inlen); - if (code == GRIB_READ_ONLY) - code = 0; - } - - return code; -} - -static int unpack_double_element(grib_accessor* a, size_t idx, double* val) -{ - int ret = 0; - grib_accessor_data_raw_packing* self = (grib_accessor_data_raw_packing*)a; - unsigned char* buf = NULL; - int bytes = 0; - size_t nvals = 0; - long inlen = grib_byte_count(a); - long pos = 0; - long precision = 0; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->precision, &precision)) != GRIB_SUCCESS) - return ret; - - self->dirty = 0; - - buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; - buf += grib_byte_offset(a); - - switch (precision) { - case 1: - bytes = 4; - break; - - case 2: - bytes = 8; - break; - - default: - return GRIB_NOT_IMPLEMENTED; - } - - pos = bytes * idx; - - Assert(pos <= inlen); - - nvals = 1; - buf += pos; - - ret = grib_ieee_decode_array(a->context, buf, nvals, bytes, val); - - return ret; -} - -static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) -{ - int err = 0; - size_t i = 0; - for (i=0; iprimary_bitmap = grib_arguments_get_name(grib_handle_of_accessor(a), args, 0); - self->secondary_bitmap = grib_arguments_get_name(grib_handle_of_accessor(a), args, 1); - self->missing_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, 2); - self->expand_by = grib_arguments_get_name(grib_handle_of_accessor(a), args, 3); - - a->length = 0; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_values(dumper, a); -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_data_secondary_bitmap* self = (grib_accessor_data_secondary_bitmap*)a; - - size_t i = 0; - size_t j = 0; - size_t k = 0; - size_t m = 0; - size_t n_vals = 0; - long nn = 0; - long expand_by = 0; - int err = 0; - size_t primary_len; - size_t secondary_len; - double* primary_vals; - double* secondary_vals; - err = grib_value_count(a, &nn); - n_vals = nn; - if (err) - return err; - - if (*len < n_vals) { - *len = n_vals; - return GRIB_ARRAY_TOO_SMALL; - } - - if ((err = grib_get_long(grib_handle_of_accessor(a), self->expand_by, &expand_by)) != GRIB_SUCCESS) - return err; - - if ((err = grib_get_size(grib_handle_of_accessor(a), self->primary_bitmap, &primary_len)) != GRIB_SUCCESS) - return err; - - if ((err = grib_get_size(grib_handle_of_accessor(a), self->secondary_bitmap, &secondary_len)) != GRIB_SUCCESS) - return err; - - primary_vals = (double*)grib_context_malloc(a->context, primary_len * sizeof(double)); - if (!primary_vals) - return GRIB_OUT_OF_MEMORY; - - secondary_vals = (double*)grib_context_malloc(a->context, secondary_len * sizeof(double)); - if (!secondary_vals) { - grib_context_free(a->context, primary_vals); - return GRIB_OUT_OF_MEMORY; - } - - if ((err = grib_get_double_array_internal(grib_handle_of_accessor(a), self->primary_bitmap, primary_vals, &primary_len)) != GRIB_SUCCESS) { - grib_context_free(a->context, secondary_vals); - grib_context_free(a->context, primary_vals); - return err; - } - - if ((err = grib_get_double_array_internal(grib_handle_of_accessor(a), self->secondary_bitmap, secondary_vals, &secondary_len)) != GRIB_SUCCESS) { - grib_context_free(a->context, secondary_vals); - grib_context_free(a->context, primary_vals); - return err; - } - - k = 0; - m = 0; - for (i = 0; i < primary_len; i++) { - /* if(primary_vals[i]) f++; */ - if (primary_vals[i]) { - for (j = 0; j < expand_by; j++) - val[k++] = secondary_vals[m++]; - } - else { - for (j = 0; j < expand_by; j++) - val[k++] = 0; - } - } - - Assert(k <= *len); - Assert(m <= secondary_len); - - /*printf("FOOBAR %d %d %ld %d\n",f,primary_len,expand_by,n_vals);*/ - - *len = n_vals; - - grib_context_free(a->context, primary_vals); - grib_context_free(a->context, secondary_vals); - return err; -} - -static int get_native_type(grib_accessor* a) -{ - // grib_accessor_data_secondary_bitmap* self = (grib_accessor_data_secondary_bitmap*)a; - //return grib_accessor_get_native_type(grib_find_accessor(grib_handle_of_accessor(a),self->coded_values)); - return GRIB_TYPE_DOUBLE; -} diff --git a/src/grib_accessor_class_data_shsimple_packing.cc b/src/grib_accessor_class_data_shsimple_packing.cc deleted file mode 100644 index d06743f8d..000000000 --- a/src/grib_accessor_class_data_shsimple_packing.cc +++ /dev/null @@ -1,153 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init - IMPLEMENTS = pack_double - IMPLEMENTS = dump;get_native_type - MEMBERS=const char* coded_values - MEMBERS=const char* real_part - MEMBERS=int dirty - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_double(grib_accessor*, const double* val, size_t* len); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_data_shsimple_packing -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in data_shsimple_packing */ - const char* coded_values; - const char* real_part; - int dirty; -} grib_accessor_data_shsimple_packing; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_data_shsimple_packing = { - &grib_accessor_class_gen, /* super */ - "data_shsimple_packing", /* name */ - sizeof(grib_accessor_data_shsimple_packing), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_data_shsimple_packing = &_grib_accessor_class_data_shsimple_packing; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long v, grib_arguments* args) -{ - grib_accessor_data_shsimple_packing* self = (grib_accessor_data_shsimple_packing*)a; - - self->coded_values = grib_arguments_get_name(grib_handle_of_accessor(a), args, 0); - self->real_part = grib_arguments_get_name(grib_handle_of_accessor(a), args, 1); - a->flags |= GRIB_ACCESSOR_FLAG_DATA; - - a->length = 0; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_values(dumper, a); -} - -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_data_shsimple_packing* self = (grib_accessor_data_shsimple_packing*)a; - int err = GRIB_SUCCESS; - - size_t coded_n_vals = *len - 1; - size_t n_vals = *len; - - self->dirty = 1; - - if (*len == 0) - return GRIB_NO_VALUES; - - if ((err = grib_set_double_internal(grib_handle_of_accessor(a), self->real_part, *val)) != GRIB_SUCCESS) - return err; - - val++; - - if ((err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->coded_values, val, coded_n_vals)) != GRIB_SUCCESS) - return err; - - *len = n_vals; - - return err; -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_DOUBLE; -} diff --git a/src/grib_accessor_class_decimal_precision.cc b/src/grib_accessor_class_decimal_precision.cc deleted file mode 100644 index e498931b7..000000000 --- a/src/grib_accessor_class_decimal_precision.cc +++ /dev/null @@ -1,199 +0,0 @@ -/* - * (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. - */ - -/********************************** - * Enrico Fucile - *********************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long; pack_long - IMPLEMENTS = init - MEMBERS = const char* values - MEMBERS = const char* bits_per_value - MEMBERS = const char* changing_precision - MEMBERS = const char* decimal_scale_factor - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_decimal_precision -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in decimal_precision */ - const char* values; - const char* bits_per_value; - const char* changing_precision; - const char* decimal_scale_factor; -} grib_accessor_decimal_precision; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_decimal_precision = { - &grib_accessor_class_long, /* super */ - "decimal_precision", /* name */ - sizeof(grib_accessor_decimal_precision), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_decimal_precision = &_grib_accessor_class_decimal_precision; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* args) -{ - int n = 0; - grib_accessor_decimal_precision* self = (grib_accessor_decimal_precision*)a; - - self->bits_per_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->decimal_scale_factor = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->changing_precision = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->length = 0; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - int ret = 0; - grib_accessor_decimal_precision* self = (grib_accessor_decimal_precision*)a; - grib_handle* h = grib_handle_of_accessor(a); - - if ((ret = grib_get_long_internal(h, self->decimal_scale_factor, val)) != GRIB_SUCCESS) - return ret; - - *len = 1; - return ret; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - long bitsPerValue = 0; - double* values = NULL; - size_t size = 0; - int ret = 0; - grib_accessor_decimal_precision* self = (grib_accessor_decimal_precision*)a; - grib_context* c = a->context; - grib_handle* h = grib_handle_of_accessor(a); - - if (!self->values) { - if ((ret = grib_set_long_internal(h, self->bits_per_value, 0)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_set_long_internal(h, self->decimal_scale_factor, *val)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_set_long_internal(h, self->changing_precision, 1)) != GRIB_SUCCESS) { - grib_context_free(c, values); - return ret; - } - - return GRIB_SUCCESS; - } - - if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) - return ret; - - values = (double*)grib_context_malloc(c, size * sizeof(double)); - if (!values) - return GRIB_OUT_OF_MEMORY; - - if ((ret = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) { - grib_context_buffer_free(c, values); - return ret; - } - - if ((ret = grib_set_long_internal(h, self->decimal_scale_factor, *val)) != GRIB_SUCCESS) { - grib_context_buffer_free(c, values); - return ret; - } - - if ((ret = grib_set_long_internal(h, self->bits_per_value, bitsPerValue)) != GRIB_SUCCESS) { - grib_context_free(c, values); - return ret; - } - - if ((ret = grib_set_long_internal(h, self->changing_precision, 1)) != GRIB_SUCCESS) { - grib_context_free(c, values); - return ret; - } - - if ((ret = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) { - grib_context_buffer_free(c, values); - return ret; - } - - grib_context_free(c, values); - - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_dirty.cc b/src/grib_accessor_class_dirty.cc deleted file mode 100644 index ec29923e3..000000000 --- a/src/grib_accessor_class_dirty.cc +++ /dev/null @@ -1,138 +0,0 @@ -/* - * (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. - */ - -/************************************ - * Enrico Fucile - **********************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long - IMPLEMENTS = pack_long - IMPLEMENTS = init - MEMBERS = const char* accessor - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_dirty -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in dirty */ - const char* accessor; -} grib_accessor_dirty; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_dirty = { - &grib_accessor_class_long, /* super */ - "dirty", /* name */ - sizeof(grib_accessor_dirty), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_dirty = &_grib_accessor_class_dirty; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_dirty* self = (grib_accessor_dirty*)a; - self->accessor = grib_arguments_get_name(grib_handle_of_accessor(a), c, 0); - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; - a->length = 0; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - grib_accessor_dirty* self = (grib_accessor_dirty*)a; - grib_accessor* x = grib_find_accessor(grib_handle_of_accessor(a), self->accessor); - - if (x) - x->dirty = *val; - - return GRIB_SUCCESS; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_dirty* self = (grib_accessor_dirty*)a; - grib_accessor* x = grib_find_accessor(grib_handle_of_accessor(a), self->accessor); - - if (x) - x->dirty = 1; - - *val = 1; - - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_divdouble.cc b/src/grib_accessor_class_divdouble.cc deleted file mode 100644 index 8ab86e22e..000000000 --- a/src/grib_accessor_class_divdouble.cc +++ /dev/null @@ -1,129 +0,0 @@ -/* - * (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. - */ -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_double - IMPLEMENTS = unpack_double - IMPLEMENTS = init - MEMBERS = const char* val - MEMBERS = double divisor - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_double(grib_accessor*, double* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_divdouble -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in divdouble */ - const char* val; - double divisor; -} grib_accessor_divdouble; - -extern grib_accessor_class* grib_accessor_class_double; - -static grib_accessor_class _grib_accessor_class_divdouble = { - &grib_accessor_class_double, /* super */ - "divdouble", /* name */ - sizeof(grib_accessor_divdouble), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_divdouble = &_grib_accessor_class_divdouble; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_divdouble* self = (grib_accessor_divdouble*)a; - int n = 0; - - self->val = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->divisor = grib_arguments_get_double(grib_handle_of_accessor(a), c, n++); -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - const grib_accessor_divdouble* self = (grib_accessor_divdouble*)a; - int ret = GRIB_SUCCESS; - double value = 0; - - ret = grib_get_double_internal(grib_handle_of_accessor(a), self->val, &value); - if (ret != GRIB_SUCCESS) - return ret; - - if (self->divisor == 0) { - return GRIB_INVALID_ARGUMENT; - } - *val = value / self->divisor; - - *len = 1; - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_double.cc b/src/grib_accessor_class_double.cc deleted file mode 100644 index 3a2933aff..000000000 --- a/src/grib_accessor_class_double.cc +++ /dev/null @@ -1,201 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = get_native_type;unpack_string - IMPLEMENTS = pack_missing; - IMPLEMENTS = dump - IMPLEMENTS = compare - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_missing(grib_accessor*); -static int unpack_string(grib_accessor*, char*, size_t* len); -static void dump(grib_accessor*, grib_dumper*); -static int compare(grib_accessor*, grib_accessor*); - -typedef struct grib_accessor_double -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ -} grib_accessor_double; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_double = { - &grib_accessor_class_gen, /* super */ - "double", /* name */ - sizeof(grib_accessor_double), /* size */ - 0, /* inited */ - 0, /* init_class */ - 0, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - &pack_missing, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - &compare, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_double = &_grib_accessor_class_double; - -/* END_CLASS_IMP */ - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_DOUBLE; -} - -static int unpack_string(grib_accessor* a, char* v, size_t* len) -{ - double val = 0; - size_t l = 1; - char repres[1024]; - char format[32] = "%g"; - grib_handle* h = grib_handle_of_accessor(a); - const char* cclass_name = a->cclass->name; - - grib_unpack_double(a, &val, &l); - - if ((val == GRIB_MISSING_DOUBLE) && ((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0)) { - snprintf(repres, sizeof(repres), "MISSING"); - } else { - size_t size = sizeof(format); - grib_get_string(h, "formatForDoubles", format, &size); - snprintf(repres, sizeof(repres), format, val); - } - - l = strlen(repres) + 1; - - if (l > *len) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, l, *len); - *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; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_values(dumper, a); -} - -static int compare(grib_accessor* a, grib_accessor* b) -{ - int retval = 0; - double* aval = 0; - double* bval = 0; - - size_t alen = 0; - size_t blen = 0; - long count = 0; - int err = 0; - - err = grib_value_count(a, &count); - if (err) - return err; - alen = count; - - err = grib_value_count(b, &count); - if (err) - return err; - blen = count; - - if (alen != blen) - return GRIB_COUNT_MISMATCH; - - aval = (double*)grib_context_malloc(a->context, alen * sizeof(double)); - bval = (double*)grib_context_malloc(b->context, blen * sizeof(double)); - - grib_unpack_double(a, aval, &alen); - grib_unpack_double(b, bval, &blen); - - retval = GRIB_SUCCESS; - while (alen != 0) { - if (*bval != *aval) - retval = GRIB_DOUBLE_VALUE_MISMATCH; - alen--; - } - - grib_context_free(a->context, aval); - grib_context_free(b->context, bval); - - return retval; -} - -static int pack_missing(grib_accessor* a) -{ - size_t len = 1; - double value = GRIB_MISSING_DOUBLE; - - if (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) - return grib_pack_double(a, &value, &len); - return GRIB_VALUE_CANNOT_BE_MISSING; -} diff --git a/src/grib_accessor_class_evaluate.cc b/src/grib_accessor_class_evaluate.cc deleted file mode 100644 index 596b95884..000000000 --- a/src/grib_accessor_class_evaluate.cc +++ /dev/null @@ -1,118 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long - IMPLEMENTS = init - MEMBERS= grib_arguments* arg - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_evaluate -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in evaluate */ - grib_arguments* arg; -} grib_accessor_evaluate; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_evaluate = { - &grib_accessor_class_long, /* super */ - "evaluate", /* name */ - sizeof(grib_accessor_evaluate), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_evaluate = &_grib_accessor_class_evaluate; - -/* END_CLASS_IMP */ - -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; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - 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 = grib_expression_evaluate_long(grib_handle_of_accessor(a), e, val); - *len = 1; - - return ret; -} diff --git a/src/grib_accessor_class_g1_half_byte_codeflag.cc b/src/grib_accessor_class_g1_half_byte_codeflag.cc deleted file mode 100644 index c7d9828e0..000000000 --- a/src/grib_accessor_class_g1_half_byte_codeflag.cc +++ /dev/null @@ -1,147 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = init;dump - IMPLEMENTS = get_native_type - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g1_half_byte_codeflag -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in g1_half_byte_codeflag */ -} grib_accessor_g1_half_byte_codeflag; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_g1_half_byte_codeflag = { - &grib_accessor_class_gen, /* super */ - "g1_half_byte_codeflag", /* name */ - sizeof(grib_accessor_g1_half_byte_codeflag), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_g1_half_byte_codeflag = &_grib_accessor_class_g1_half_byte_codeflag; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_long(dumper, a, NULL); -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - if (*len < 1) { - *len = 1; - return GRIB_ARRAY_TOO_SMALL; - } - unsigned char dat = grib_handle_of_accessor(a)->buffer->data[a->offset] & 0x0f; - - *val = dat; - *len = 1; - return GRIB_SUCCESS; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - if (*len < 1) { - *len = 1; - return GRIB_ARRAY_TOO_SMALL; - } - - // printf("HALF BYTE pack long %ld %02x\n",*val,grib_handle_of_accessor(a)->buffer->data[a->offset]); - grib_handle_of_accessor(a)->buffer->data[a->offset] = (a->parent->h->buffer->data[a->offset] & 0xf0) | (*val & 0x0f); - // printf("HALF BYTE pack long %ld %02x\n",*val,grib_handle_of_accessor(a)->buffer->data[a->offset]); - - *len = 1; - return GRIB_SUCCESS; -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_LONG; -} diff --git a/src/grib_accessor_class_g1_section4_length.cc b/src/grib_accessor_class_g1_section4_length.cc deleted file mode 100644 index 8e6c2b3f1..000000000 --- a/src/grib_accessor_class_g1_section4_length.cc +++ /dev/null @@ -1,143 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_section_length - IMPLEMENTS = init;unpack_long;pack_long - MEMBERS = const char* total_length - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g1_section4_length -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in unsigned */ - long nbytes; - grib_arguments* arg; - /* Members defined in section_length */ - /* Members defined in g1_section4_length */ - const char* total_length; -} grib_accessor_g1_section4_length; - -extern grib_accessor_class* grib_accessor_class_section_length; - -static grib_accessor_class _grib_accessor_class_g1_section4_length = { - &grib_accessor_class_section_length, /* super */ - "g1_section4_length", /* name */ - sizeof(grib_accessor_g1_section4_length), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_g1_section4_length = &_grib_accessor_class_g1_section4_length; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* args) -{ - grib_accessor_g1_section4_length* self = (grib_accessor_g1_section4_length*)a; - self->total_length = grib_arguments_get_name(grib_handle_of_accessor(a), args, 0); -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - // Old implementation: - // Here we assume that the totalLength will be coded AFTER the section4 length, and - // the section4 length will be overwritten by the totalLength accessor for large GRIBs - // grib_accessor_class* super = *(a->cclass->super); - // return super->pack_long(a,val,len); - - // Note: Do not directly call pack_long on base class - // because in this special case we want to skip the checks. - // So we call the helper function which has an extra argument - return pack_long_unsigned_helper(a, val, len, /*check=*/0); -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_g1_section4_length* self = (grib_accessor_g1_section4_length*)a; - int ret = 0; - long total_length = 0, sec4_length = 0; - - if ((ret = grib_get_g1_message_size(grib_handle_of_accessor(a), - grib_find_accessor(grib_handle_of_accessor(a), self->total_length), - a, - &total_length, - &sec4_length)) != GRIB_SUCCESS) { - return ret; - } - - *val = sec4_length; - - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_g1bitmap.cc b/src/grib_accessor_class_g1bitmap.cc deleted file mode 100644 index 519638f6a..000000000 --- a/src/grib_accessor_class_g1bitmap.cc +++ /dev/null @@ -1,206 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_bitmap - IMPLEMENTS = pack_double; unpack_bytes - IMPLEMENTS = value_count - IMPLEMENTS = init; - MEMBERS=const char* unusedBits - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_bytes(grib_accessor*, unsigned char*, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g1bitmap -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in bytes */ - /* Members defined in bitmap */ - const char* tableReference; - const char* missing_value; - const char* offsetbsec; - const char* sLength; - /* Members defined in g1bitmap */ - const char* unusedBits; -} grib_accessor_g1bitmap; - -extern grib_accessor_class* grib_accessor_class_bitmap; - -static grib_accessor_class _grib_accessor_class_g1bitmap = { - &grib_accessor_class_bitmap, /* super */ - "g1bitmap", /* name */ - sizeof(grib_accessor_g1bitmap), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - &unpack_bytes, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_g1bitmap = &_grib_accessor_class_g1bitmap; - -/* END_CLASS_IMP */ - - -static void grib_set_bit_on(unsigned char* p, long* bitp); - -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) -{ - grib_accessor_g1bitmap* self = (grib_accessor_g1bitmap*)a; - size_t tlen; - - unsigned char* buf = NULL; - size_t i; - int err = 0; - long pos = 0; - //long bmaplen = 0; - const int bit_padding = 16; - double miss_values = 0; - tlen = ((*len + bit_padding - 1) / bit_padding * bit_padding) / 8; - - if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value, &miss_values)) != GRIB_SUCCESS) - return err; - - buf = (unsigned char*)grib_context_malloc_clear(a->context, tlen); - if (!buf) - return GRIB_OUT_OF_MEMORY; - pos = 0; - for (i = 0; i < *len; i++) { - if (val[i] == miss_values) - pos++; - else { - //bmaplen++; - grib_set_bit_on(buf, &pos); - } - } - - if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->unusedBits, tlen * 8 - *len)) != GRIB_SUCCESS) - return err; - - err = grib_buffer_replace(a, buf, tlen, 1, 1); - if (err) return err; - - grib_context_free(a->context, buf); - - return GRIB_SUCCESS; -} - -static int value_count(grib_accessor* a, long* count) -{ - grib_accessor_g1bitmap* self = (grib_accessor_g1bitmap*)a; - long tlen; - int err; - - 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; -} - -static int unpack_bytes(grib_accessor* a, unsigned char* val, size_t* len) -{ - unsigned char* buf = grib_handle_of_accessor(a)->buffer->data; - grib_accessor_g1bitmap* self = (grib_accessor_g1bitmap*)a; - long tlen; - int err; - long length = grib_byte_count(a); - long offset = grib_byte_offset(a); - - if (*len < (size_t)length) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it is %ld bytes long\n", a->name, length); - *len = length; - return GRIB_ARRAY_TOO_SMALL; - } - - 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.unpack_bytes : cannot get %s err=%d", self->unusedBits, err); - - length -= tlen / 8; - memcpy(val, buf + offset, length); - *len = length; - - return GRIB_SUCCESS; -} - -static void grib_set_bit_on(unsigned char* p, long* bitp) -{ - unsigned char o = 1; - p += (*bitp >> 3); - o <<= 7 - ((*bitp) % 8); - *p |= o; - (*bitp) += 1; -} diff --git a/src/grib_accessor_class_g1day_of_the_year_date.cc b/src/grib_accessor_class_g1day_of_the_year_date.cc deleted file mode 100644 index 9028d5076..000000000 --- a/src/grib_accessor_class_g1day_of_the_year_date.cc +++ /dev/null @@ -1,152 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_g1date - IMPLEMENTS = unpack_string - IMPLEMENTS = dump - IMPLEMENTS = init - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_string(grib_accessor*, char*, size_t* len); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g1day_of_the_year_date -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in g1date */ - const char* century; - const char* year; - const char* month; - const char* day; - /* Members defined in g1day_of_the_year_date */ -} grib_accessor_g1day_of_the_year_date; - -extern grib_accessor_class* grib_accessor_class_g1date; - -static grib_accessor_class _grib_accessor_class_g1day_of_the_year_date = { - &grib_accessor_class_g1date, /* super */ - "g1day_of_the_year_date", /* name */ - sizeof(grib_accessor_g1day_of_the_year_date), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_g1day_of_the_year_date = &_grib_accessor_class_g1day_of_the_year_date; - -/* END_CLASS_IMP */ - - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_string(dumper, a, NULL); -} - -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - /* special clim case where each mont have 30 days.. to comply with mars*/ - grib_accessor_g1day_of_the_year_date* self = (grib_accessor_g1day_of_the_year_date*)a; - grib_handle* hand = grib_handle_of_accessor(a); - char tmp[1024]; - - long year = 0; - long century = 0; - long month = 0; - long day = 0; - long fullyear = 0; - long fake_day_of_year = 0; - - grib_get_long_internal(hand, self->century, ¢ury); - grib_get_long_internal(hand, self->day, &day); - grib_get_long_internal(hand, self->month, &month); - grib_get_long_internal(hand, self->year, &year); - - fullyear = ((century - 1) * 100 + year); - fake_day_of_year = ((month - 1) * 30) + day; - snprintf(tmp, sizeof(tmp), "%04ld-%03ld", fullyear, fake_day_of_year); - - size_t l = strlen(tmp) + 1; - if (*len < l) { - *len = l; - return GRIB_BUFFER_TOO_SMALL; - } - - *len = l; - strcpy(val, tmp); - - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_g1end_of_interval_monthly.cc b/src/grib_accessor_class_g1end_of_interval_monthly.cc deleted file mode 100644 index cbf74322c..000000000 --- a/src/grib_accessor_class_g1end_of_interval_monthly.cc +++ /dev/null @@ -1,234 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_abstract_vector - IMPLEMENTS = unpack_double; destroy - IMPLEMENTS = value_count;compare - IMPLEMENTS = init - MEMBERS = const char* verifyingMonth - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void destroy(grib_context*, grib_accessor*); -static void init(grib_accessor*, const long, grib_arguments*); -static int compare(grib_accessor*, grib_accessor*); - -typedef struct grib_accessor_g1end_of_interval_monthly -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in abstract_vector */ - double* v; - int number_of_elements; - /* Members defined in g1end_of_interval_monthly */ - const char* verifyingMonth; -} grib_accessor_g1end_of_interval_monthly; - -extern grib_accessor_class* grib_accessor_class_abstract_vector; - -static grib_accessor_class _grib_accessor_class_g1end_of_interval_monthly = { - &grib_accessor_class_abstract_vector, /* super */ - "g1end_of_interval_monthly", /* name */ - sizeof(grib_accessor_g1end_of_interval_monthly), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - &destroy, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - &compare, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_g1end_of_interval_monthly = &_grib_accessor_class_g1end_of_interval_monthly; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_g1end_of_interval_monthly* self = (grib_accessor_g1end_of_interval_monthly*)a; - int n = 0; - - self->verifyingMonth = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; - - self->number_of_elements = 6; - self->v = (double*)grib_context_malloc(a->context, sizeof(double) * self->number_of_elements); - - a->length = 0; - a->dirty = 1; -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_g1end_of_interval_monthly* self = (grib_accessor_g1end_of_interval_monthly*)a; - int ret = 0; - char verifyingMonth[7] = {0,}; - size_t slen = 7; - long year = 0, month = 0, date = 0; - const long mdays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; - long days = 0; - - if (!a->dirty) - return GRIB_SUCCESS; - - if (*len != (size_t)self->number_of_elements) - return GRIB_ARRAY_TOO_SMALL; - - if ((ret = grib_get_string(grib_handle_of_accessor(a), self->verifyingMonth, verifyingMonth, &slen)) != GRIB_SUCCESS) - return ret; - - date = atoi(verifyingMonth); - if (date < 0) { - return GRIB_INVALID_ARGUMENT; - } - year = date / 100; - month = date - year * 100; - if (month == 2) { - days = 28; - if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) - days = 29; - } - else { - if (month < 1 || month > 12) return GRIB_INVALID_ARGUMENT; - days = mdays[month - 1]; - } - self->v[0] = year; - self->v[1] = month; - - self->v[2] = days; - self->v[3] = 24; - self->v[4] = 00; - self->v[5] = 00; - - a->dirty = 0; - - val[0] = self->v[0]; - val[1] = self->v[1]; - val[2] = self->v[2]; - val[3] = self->v[3]; - val[4] = self->v[4]; - val[5] = self->v[5]; - - return ret; -} - -static int value_count(grib_accessor* a, long* count) -{ - grib_accessor_g1end_of_interval_monthly* self = (grib_accessor_g1end_of_interval_monthly*)a; - *count = self->number_of_elements; - return 0; -} - -static void destroy(grib_context* c, grib_accessor* a) -{ - grib_accessor_g1end_of_interval_monthly* self = (grib_accessor_g1end_of_interval_monthly*)a; - grib_context_free(c, self->v); -} - -static int compare(grib_accessor* a, grib_accessor* b) -{ - int retval = GRIB_SUCCESS; - double* aval = 0; - double* bval = 0; - - long count = 0; - size_t alen = 0; - size_t blen = 0; - int err = 0; - - err = grib_value_count(a, &count); - if (err) - return err; - alen = count; - - err = grib_value_count(b, &count); - if (err) - return err; - blen = count; - - if (alen != blen) - return GRIB_COUNT_MISMATCH; - - aval = (double*)grib_context_malloc(a->context, alen * sizeof(double)); - bval = (double*)grib_context_malloc(b->context, blen * sizeof(double)); - - b->dirty = 1; - a->dirty = 1; - - err = grib_unpack_double(a, aval, &alen); if(err) return err; - err = grib_unpack_double(b, bval, &blen); if(err) return err; - - for(size_t i=0; icontext, aval); - grib_context_free(b->context, bval); - - return retval; -} diff --git a/src/grib_accessor_class_g1fcperiod.cc b/src/grib_accessor_class_g1fcperiod.cc deleted file mode 100644 index 03aa6e3f4..000000000 --- a/src/grib_accessor_class_g1fcperiod.cc +++ /dev/null @@ -1,134 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_g1step_range - IMPLEMENTS = unpack_string - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_string(grib_accessor*, char*, size_t* len); - -typedef struct grib_accessor_g1fcperiod -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in abstract_long_vector */ - long* v; - long pack_index; - int number_of_elements; - /* Members defined in g1step_range */ - const char* p1; - const char* p2; - const char* timeRangeIndicator; - const char *unit; - const char *step_unit; - const char *stepType; - const char *patch_fp_precip; - int error_on_units; - /* Members defined in g1fcperiod */ -} grib_accessor_g1fcperiod; - -extern grib_accessor_class* grib_accessor_class_g1step_range; - -static grib_accessor_class _grib_accessor_class_g1fcperiod = { - &grib_accessor_class_g1step_range, /* super */ - "g1fcperiod", /* name */ - sizeof(grib_accessor_g1fcperiod), /* size */ - 0, /* inited */ - 0, /* init_class */ - 0, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_g1fcperiod = &_grib_accessor_class_g1fcperiod; - -/* END_CLASS_IMP */ - -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - long start = 0, theEnd = 0; - char tmp[1024]; - const size_t tmpLen = sizeof(tmp); - int err = grib_g1_step_get_steps(a, &start, &theEnd); - size_t l = 0; - - if (err) - return err; - - snprintf(tmp, tmpLen, "%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; - } - - *len = l; - strcpy(val, tmp); /* NOLINT: CWE-119 clang-analyzer-security.insecureAPI.strcpy */ - - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_g1monthlydate.cc b/src/grib_accessor_class_g1monthlydate.cc deleted file mode 100644 index 57c3ea729..000000000 --- a/src/grib_accessor_class_g1monthlydate.cc +++ /dev/null @@ -1,132 +0,0 @@ -/* - * (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. - */ - - -/*********************************************** - * Enrico Fucile - **********************************************/ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long - IMPLEMENTS = init - MEMBERS=const char* date - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g1monthlydate -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in g1monthlydate */ - const char* date; -} grib_accessor_g1monthlydate; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_g1monthlydate = { - &grib_accessor_class_long, /* super */ - "g1monthlydate", /* name */ - sizeof(grib_accessor_g1monthlydate), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_g1monthlydate = &_grib_accessor_class_g1monthlydate; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_g1monthlydate* self = (grib_accessor_g1monthlydate*)a; - int n = 0; - - self->date = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_g1monthlydate* self = (grib_accessor_g1monthlydate*)a; - - long date = 0; - - grib_get_long_internal(grib_handle_of_accessor(a), self->date, &date); - - date /= 100; - date *= 100; - date += 1; - - *val = date; - - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_g1number_of_coded_values_sh_complex.cc b/src/grib_accessor_class_g1number_of_coded_values_sh_complex.cc deleted file mode 100644 index 45b983502..000000000 --- a/src/grib_accessor_class_g1number_of_coded_values_sh_complex.cc +++ /dev/null @@ -1,183 +0,0 @@ -/* - * (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. - */ - -/****************************************************** - * Enrico Fucile - *******************************************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long - IMPLEMENTS = init - MEMBERS = const char* numberOfValues - MEMBERS = const char* bitsPerValue - MEMBERS = const char* offsetBeforeData - MEMBERS = const char* offsetAfterData - MEMBERS = const char* unusedBits - MEMBERS = const char* JS - MEMBERS = const char* KS - MEMBERS = const char* MS - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g1number_of_coded_values_sh_complex -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in g1number_of_coded_values_sh_complex */ - const char* numberOfValues; - const char* bitsPerValue; - const char* offsetBeforeData; - const char* offsetAfterData; - const char* unusedBits; - const char* JS; - const char* KS; - const char* MS; -} grib_accessor_g1number_of_coded_values_sh_complex; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_g1number_of_coded_values_sh_complex = { - &grib_accessor_class_long, /* super */ - "g1number_of_coded_values_sh_complex", /* name */ - sizeof(grib_accessor_g1number_of_coded_values_sh_complex), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_g1number_of_coded_values_sh_complex = &_grib_accessor_class_g1number_of_coded_values_sh_complex; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - int n = 0; - grib_accessor_g1number_of_coded_values_sh_complex* self = (grib_accessor_g1number_of_coded_values_sh_complex*)a; - self->bitsPerValue = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->offsetBeforeData = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->offsetAfterData = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->unusedBits = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->numberOfValues = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->JS = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->KS = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->MS = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - 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) -{ - int ret = GRIB_SUCCESS; - long bpv = 0; - long offsetBeforeData = 0, offsetAfterData = 0, unusedBits = 0, numberOfValues; - long JS = 0, KS = 0, MS = 0, NS = 0; - - grib_accessor_g1number_of_coded_values_sh_complex* self = (grib_accessor_g1number_of_coded_values_sh_complex*)a; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bitsPerValue, &bpv)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetBeforeData, &offsetBeforeData)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetAfterData, &offsetAfterData)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->unusedBits, &unusedBits)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->JS, &JS)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->KS, &KS)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->MS, &MS)) != GRIB_SUCCESS) - return ret; - - if (JS != KS || KS != MS) - return GRIB_NOT_IMPLEMENTED; - - NS = (MS + 1) * (MS + 2); - - if (bpv != 0) { - DEBUG_ASSERT(offsetAfterData > offsetBeforeData); - *val = ((offsetAfterData - offsetBeforeData) * 8 - unusedBits + NS * (bpv - 32)) / bpv; - } - else { - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfValues, &numberOfValues)) != GRIB_SUCCESS) - return ret; - - *val = numberOfValues; - } - - return ret; -} diff --git a/src/grib_accessor_class_g1number_of_coded_values_sh_simple.cc b/src/grib_accessor_class_g1number_of_coded_values_sh_simple.cc deleted file mode 100644 index 532a4c5dd..000000000 --- a/src/grib_accessor_class_g1number_of_coded_values_sh_simple.cc +++ /dev/null @@ -1,158 +0,0 @@ -/* - * (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. - */ - -/********************************************** - * Enrico Fucile - **********************************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long - IMPLEMENTS = init - MEMBERS = const char* numberOfValues - MEMBERS = const char* bitsPerValue - MEMBERS = const char* offsetBeforeData - MEMBERS = const char* offsetAfterData - MEMBERS = const char* unusedBits - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g1number_of_coded_values_sh_simple -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in g1number_of_coded_values_sh_simple */ - const char* numberOfValues; - const char* bitsPerValue; - const char* offsetBeforeData; - const char* offsetAfterData; - const char* unusedBits; -} grib_accessor_g1number_of_coded_values_sh_simple; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_g1number_of_coded_values_sh_simple = { - &grib_accessor_class_long, /* super */ - "g1number_of_coded_values_sh_simple", /* name */ - sizeof(grib_accessor_g1number_of_coded_values_sh_simple), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_g1number_of_coded_values_sh_simple = &_grib_accessor_class_g1number_of_coded_values_sh_simple; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - int n = 0; - grib_accessor_g1number_of_coded_values_sh_simple* self = (grib_accessor_g1number_of_coded_values_sh_simple*)a; - self->bitsPerValue = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->offsetBeforeData = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->offsetAfterData = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->unusedBits = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->numberOfValues = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - 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) -{ - int ret = GRIB_SUCCESS; - long bpv = 0; - long offsetBeforeData = 0, offsetAfterData = 0, unusedBits = 0, numberOfValues; - - grib_accessor_g1number_of_coded_values_sh_simple* self = (grib_accessor_g1number_of_coded_values_sh_simple*)a; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bitsPerValue, &bpv)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetBeforeData, &offsetBeforeData)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetAfterData, &offsetAfterData)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->unusedBits, &unusedBits)) != GRIB_SUCCESS) - return ret; - - if (bpv != 0) { - DEBUG_ASSERT(offsetAfterData > offsetBeforeData); - *val = ((offsetAfterData - offsetBeforeData) * 8 - unusedBits) / bpv; - } - else { - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfValues, &numberOfValues)) != GRIB_SUCCESS) - return ret; - - *val = numberOfValues; - } - return ret; -} diff --git a/src/grib_accessor_class_g1verificationdate.cc b/src/grib_accessor_class_g1verificationdate.cc deleted file mode 100644 index 03c871617..000000000 --- a/src/grib_accessor_class_g1verificationdate.cc +++ /dev/null @@ -1,154 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long - IMPLEMENTS = init - MEMBERS=const char* date - MEMBERS=const char* time - MEMBERS=const char* step - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g1verificationdate -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in g1verificationdate */ - const char* date; - const char* time; - const char* step; -} grib_accessor_g1verificationdate; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_g1verificationdate = { - &grib_accessor_class_long, /* super */ - "g1verificationdate", /* name */ - sizeof(grib_accessor_g1verificationdate), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_g1verificationdate = &_grib_accessor_class_g1verificationdate; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_g1verificationdate* self = (grib_accessor_g1verificationdate*)a; - int n = 0; - - self->date = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->time = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->step = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_g1verificationdate* self = (grib_accessor_g1verificationdate*)a; - int ret = 0; - long date = 0; - long time = 0; - long cdate = 0; - long step = 0; - long vtime = 0; - long vdate = 0; - long vd = 0; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->date, &date)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->time, &time)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->step, &step)) != GRIB_SUCCESS) - return ret; - - time /= 100; - - cdate = (long)grib_date_to_julian(date); - vtime = cdate * 24 + time + step; - vd = vtime / 24; - vdate = grib_julian_to_date(vd); - - /* printf("\n********\n date %d, time %d, step %d, vdate: %d, cdate %d, vd %d\n********\n", date, time, step, vdate, cdate, vd); */ - - if (*len < 1) - return GRIB_ARRAY_TOO_SMALL; - - *val = vdate; - - /* fprintf(stdout,"\n********\n %d cdate %d vd %d\n********\n", vdate, cdate, step); */ - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_g2_aerosol.cc b/src/grib_accessor_class_g2_aerosol.cc deleted file mode 100644 index 7cd8659df..000000000 --- a/src/grib_accessor_class_g2_aerosol.cc +++ /dev/null @@ -1,210 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_unsigned - IMPLEMENTS = unpack_long;pack_long; value_count - IMPLEMENTS = init - MEMBERS=const char* productDefinitionTemplateNumber - MEMBERS=const char* stepType - MEMBERS=int optical - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g2_aerosol -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in unsigned */ - long nbytes; - grib_arguments* arg; - /* Members defined in g2_aerosol */ - const char* productDefinitionTemplateNumber; - const char* stepType; - int optical; -} grib_accessor_g2_aerosol; - -extern grib_accessor_class* grib_accessor_class_unsigned; - -static grib_accessor_class _grib_accessor_class_g2_aerosol = { - &grib_accessor_class_unsigned, /* super */ - "g2_aerosol", /* name */ - sizeof(grib_accessor_g2_aerosol), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_g2_aerosol = &_grib_accessor_class_g2_aerosol; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_g2_aerosol* self = (grib_accessor_g2_aerosol*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int n = 0; - - self->productDefinitionTemplateNumber = grib_arguments_get_name(hand, c, n++); - self->stepType = grib_arguments_get_name(hand, c, n++); - self->optical = grib_arguments_get_long(hand, c, n++); -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_g2_aerosol* self = (grib_accessor_g2_aerosol*)a; - long productDefinitionTemplateNumber = 0; - grib_get_long(grib_handle_of_accessor(a), self->productDefinitionTemplateNumber, &productDefinitionTemplateNumber); - - if (self->optical) - *val = grib2_is_PDTN_AerosolOptical(productDefinitionTemplateNumber); - else - *val = grib2_is_PDTN_Aerosol(productDefinitionTemplateNumber); - - return GRIB_SUCCESS; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - grib_accessor_g2_aerosol* self = (grib_accessor_g2_aerosol*)a; - grib_handle* hand = grib_handle_of_accessor(a); - long productDefinitionTemplateNumber = -1; - long productDefinitionTemplateNumberNew = -1; - /*long type=-1; - long stream=-1;*/ - long eps = -1; - char stepType[15] = {0,}; - size_t slen = 15; - /*int aerosol = *val;*/ - int isInstant = 0; - /*long derivedForecast=-1;*/ - int ret = 0; - - if (grib_get_long(hand, self->productDefinitionTemplateNumber, &productDefinitionTemplateNumber) != GRIB_SUCCESS) - return GRIB_SUCCESS; - - /* - grib_get_long(hand, self->type,&type); - grib_get_long(hand, self->stream,&stream); - */ - ret = grib_get_string(hand, self->stepType, stepType, &slen); - Assert(ret == GRIB_SUCCESS); - - //eps = grib2_is_PDTN_EPS(productDefinitionTemplateNumber); - eps = grib_is_defined(hand, "perturbationNumber"); - - if (!strcmp(stepType, "instant")) - isInstant = 1; - - if (eps == 1) { - if (isInstant) { - productDefinitionTemplateNumberNew = 45; - } - else { - /*productDefinitionTemplateNumberNew = 47; PDT deprecated*/ - productDefinitionTemplateNumberNew = 85; - } - } - else { - if (isInstant) { - productDefinitionTemplateNumberNew = 48; /*44 is deprecated*/ - } - else { - productDefinitionTemplateNumberNew = 46; - } - } - - if (self->optical) { - /* Note: There is no interval based template for optical properties of aerosol! */ - if (eps) - productDefinitionTemplateNumberNew = 49; - else - productDefinitionTemplateNumberNew = 48; - if (!isInstant) { - grib_context_log(hand->context, GRIB_LOG_ERROR, - "The product definition templates for optical properties of aerosol are for a point-in-time only"); - } - } - - if (productDefinitionTemplateNumber != productDefinitionTemplateNumberNew) { - grib_set_long(hand, self->productDefinitionTemplateNumber, productDefinitionTemplateNumberNew); - /*if (derivedForecast>=0) grib_set_long(hand, self->derivedForecast,derivedForecast);*/ - } - - return 0; -} - -static int value_count(grib_accessor* a, long* count) -{ - *count = 1; - return 0; -} diff --git a/src/grib_accessor_class_g2bitmap.cc b/src/grib_accessor_class_g2bitmap.cc deleted file mode 100644 index 441ad70a6..000000000 --- a/src/grib_accessor_class_g2bitmap.cc +++ /dev/null @@ -1,178 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_bitmap - IMPLEMENTS = pack_double - IMPLEMENTS = value_count - IMPLEMENTS = init; - MEMBERS=const char* numberOfValues - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g2bitmap -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in bytes */ - /* Members defined in bitmap */ - const char* tableReference; - const char* missing_value; - const char* offsetbsec; - const char* sLength; - /* Members defined in g2bitmap */ - const char* numberOfValues; -} grib_accessor_g2bitmap; - -extern grib_accessor_class* grib_accessor_class_bitmap; - -static grib_accessor_class _grib_accessor_class_g2bitmap = { - &grib_accessor_class_bitmap, /* super */ - "g2bitmap", /* name */ - sizeof(grib_accessor_g2bitmap), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_g2bitmap = &_grib_accessor_class_g2bitmap; - -/* END_CLASS_IMP */ - - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - grib_accessor_g2bitmap* self = (grib_accessor_g2bitmap*)a; - - self->numberOfValues = grib_arguments_get_name(grib_handle_of_accessor(a), arg, 4); -} - - -static void grib_set_bit_on(unsigned char* p, long* bitp) -{ - unsigned char o = 1; - p += (*bitp >> 3); - o <<= 7 - ((*bitp) % 8); - *p |= o; - (*bitp) += 1; -} - -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_g2bitmap* self = (grib_accessor_g2bitmap*)a; - - size_t tlen; - - unsigned char* buf = NULL; - size_t i; - int err = 0; - long pos = 0; - // long bmaplen = 0; - double miss_values = 0; - tlen = (*len + 7) / 8; - - if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value, &miss_values)) != GRIB_SUCCESS) - return err; - - buf = (unsigned char*)grib_context_malloc_clear(a->context, tlen); - if (!buf) - return GRIB_OUT_OF_MEMORY; - pos = 0; - for (i = 0; i < *len; i++) { - if (val[i] == miss_values) - pos++; - else { - // bmaplen++; - grib_set_bit_on(buf, &pos); - } - } - - if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->numberOfValues, *len)) != GRIB_SUCCESS) { - grib_context_free(a->context, buf); - return err; - } - - grib_buffer_replace(a, buf, tlen, 1, 1); - - grib_context_free(a->context, buf); - - return GRIB_SUCCESS; -} - - -static int value_count(grib_accessor* a, long* tlen) -{ - grib_accessor_g2bitmap* self = (grib_accessor_g2bitmap*)a; - int err; - *tlen = 0; - - err = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfValues, tlen); - return err; -} diff --git a/src/grib_accessor_class_g2bitmap_present.cc b/src/grib_accessor_class_g2bitmap_present.cc deleted file mode 100644 index 52378d4eb..000000000 --- a/src/grib_accessor_class_g2bitmap_present.cc +++ /dev/null @@ -1,150 +0,0 @@ -/* - * (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. - */ - -/**************************************** - * Enrico Fucile - *************************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long - IMPLEMENTS = pack_long - IMPLEMENTS = init - MEMBERS = const char* bitmapIndicator - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g2bitmap_present -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in g2bitmap_present */ - const char* bitmapIndicator; -} grib_accessor_g2bitmap_present; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_g2bitmap_present = { - &grib_accessor_class_long, /* super */ - "g2bitmap_present", /* name */ - sizeof(grib_accessor_g2bitmap_present), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_g2bitmap_present = &_grib_accessor_class_g2bitmap_present; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - int n = 0; - grib_accessor_g2bitmap_present* self = (grib_accessor_g2bitmap_present*)a; - self->bitmapIndicator = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - - a->length = 0; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - int ret = GRIB_SUCCESS; - long bitmapIndicator = 0; - - grib_accessor_g2bitmap_present* self = (grib_accessor_g2bitmap_present*)a; - - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bitmapIndicator, &bitmapIndicator); - if (ret) { - if (ret == GRIB_NOT_FOUND) { - *val = 0; - return 0; - } - else - return ret; - } - - *val = 1; - if (bitmapIndicator == 255) - *val = 0; - - *len = 1; - return ret; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - grib_accessor_g2bitmap_present* self = (grib_accessor_g2bitmap_present*)a; - long bitmapIndicator = 0; - - if (*val == 0) - bitmapIndicator = 255; - - return grib_set_long(grib_handle_of_accessor(a), self->bitmapIndicator, bitmapIndicator); -} diff --git a/src/grib_accessor_class_g2date.cc b/src/grib_accessor_class_g2date.cc deleted file mode 100644 index 698cd4a26..000000000 --- a/src/grib_accessor_class_g2date.cc +++ /dev/null @@ -1,175 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long;pack_long;init - MEMBERS=const char* century - MEMBERS=const char* year - MEMBERS=const char* month - MEMBERS=const char* day - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g2date -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in g2date */ - const char* century; - const char* year; - const char* month; - const char* day; -} grib_accessor_g2date; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_g2date = { - &grib_accessor_class_long, /* super */ - "g2date", /* name */ - sizeof(grib_accessor_g2date), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_g2date = &_grib_accessor_class_g2date; - -/* END_CLASS_IMP */ -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_g2date* self = (grib_accessor_g2date*)a; - int n = 0; - - self->year = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->month = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->day = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - const grib_accessor_g2date* self = (grib_accessor_g2date*)a; - - int ret = 0; - long year = 0; - long month = 0; - long day = 0; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->day, &day)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->month, &month)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->year, &year)) != GRIB_SUCCESS) - return ret; - - if (*len < 1) - return GRIB_WRONG_ARRAY_SIZE; - - val[0] = year * 10000 + month * 100 + day; - - return GRIB_SUCCESS; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - const grib_accessor_g2date* self = (grib_accessor_g2date*)a; - - int ret = GRIB_SUCCESS; - long v = val[0]; - long year = 0; - long month = 0; - long day = 0; - - if (*len != 1) - return GRIB_WRONG_ARRAY_SIZE; - - year = v / 10000; - v %= 10000; - month = v / 100; - v %= 100; - day = v; - - if (!is_date_valid(year, month, day, 0, 0, 0)) { - // ECC-1777: For now just a warning. Will later change to an error - fprintf(stderr, "ECCODES WARNING : %s:%s: Date is not valid! year=%ld month=%ld day=%ld\n", - a->cclass->name, __func__, year, month, day); - } - - if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->day, day)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->month, month)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->year, year)) != GRIB_SUCCESS) - return ret; - - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_g2latlon.cc b/src/grib_accessor_class_g2latlon.cc deleted file mode 100644 index 5549b79a3..000000000 --- a/src/grib_accessor_class_g2latlon.cc +++ /dev/null @@ -1,215 +0,0 @@ -/* - * (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. - */ - -/******************************************** - * Enrico Fucile - *********************************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_double - IMPLEMENTS = unpack_double;pack_double - IMPLEMENTS = is_missing;pack_missing - IMPLEMENTS = init - MEMBERS=const char* grid - MEMBERS=int index - MEMBERS=const char* given - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_missing(grib_accessor*); -static int is_missing(grib_accessor*); -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g2latlon -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in g2latlon */ - const char* grid; - int index; - const char* given; -} grib_accessor_g2latlon; - -extern grib_accessor_class* grib_accessor_class_double; - -static grib_accessor_class _grib_accessor_class_g2latlon = { - &grib_accessor_class_double, /* super */ - "g2latlon", /* name */ - sizeof(grib_accessor_g2latlon), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - &pack_missing, /* pack_missing */ - &is_missing, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_g2latlon = &_grib_accessor_class_g2latlon; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_g2latlon* self = (grib_accessor_g2latlon*)a; - int n = 0; - - self->grid = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->index = grib_arguments_get_long(grib_handle_of_accessor(a), c, n++); - self->given = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_g2latlon* self = (grib_accessor_g2latlon*)a; - int ret = 0; - - long given = 1; - double grid[6]; - size_t size = 6; - - if (*len < 1) { - ret = GRIB_ARRAY_TOO_SMALL; - return ret; - } - - if (self->given) - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->given, &given)) != GRIB_SUCCESS) - return ret; - - if (!given) { - *val = GRIB_MISSING_DOUBLE; - return GRIB_SUCCESS; - } - - if ((ret = grib_get_double_array_internal(grib_handle_of_accessor(a), self->grid, grid, &size)) != GRIB_SUCCESS) - return ret; - - *val = grid[self->index]; - - return GRIB_SUCCESS; -} - -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_g2latlon* self = (grib_accessor_g2latlon*)a; - int ret = 0; - double grid[6]; - size_t size = 6; - double new_val = *val; - grib_handle* hand = grib_handle_of_accessor(a); - - if (*len < 1) { - ret = GRIB_ARRAY_TOO_SMALL; - return ret; - } - - if (self->given) { - long given = *val != GRIB_MISSING_DOUBLE; - if ((ret = grib_set_long_internal(hand, self->given, given)) != GRIB_SUCCESS) - return ret; - } - - if ((ret = grib_get_double_array_internal(hand, self->grid, grid, &size)) != GRIB_SUCCESS) - return ret; - - /* index 1 is longitudeOfFirstGridPointInDegrees - * index 3 is longitudeOfLastGridPointInDegrees - */ - if ((self->index == 1 || self->index == 3)) { - /* WMO regulation for GRIB edition 2: - * The longitude values shall be limited to the range 0 to 360 degrees inclusive */ - new_val = normalise_longitude_in_degrees(*val); - if (hand->context->debug && new_val != *val) { - fprintf(stderr, "ECCODES DEBUG pack_double g2latlon: normalise longitude %g -> %g\n", *val, new_val); - } - } - grid[self->index] = new_val; - - return grib_set_double_array_internal(hand, self->grid, grid, size); -} - -static int pack_missing(grib_accessor* a) -{ - grib_accessor_g2latlon* self = (grib_accessor_g2latlon*)a; - double missing = GRIB_MISSING_DOUBLE; - size_t size = 1; - - if (!self->given) - return GRIB_NOT_IMPLEMENTED; - - return pack_double(a, &missing, &size); -} - -static int is_missing(grib_accessor* a) -{ - grib_accessor_g2latlon* self = (grib_accessor_g2latlon*)a; - long given = 1; - - if (self->given) - grib_get_long_internal(grib_handle_of_accessor(a), self->given, &given); - - return !given; -} diff --git a/src/grib_accessor_class_g2lon.cc b/src/grib_accessor_class_g2lon.cc deleted file mode 100644 index c84776915..000000000 --- a/src/grib_accessor_class_g2lon.cc +++ /dev/null @@ -1,149 +0,0 @@ -/* - * (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. - */ - -/******************************************** - * Enrico Fucile - *********************************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_double - IMPLEMENTS = unpack_double;pack_double - IMPLEMENTS = init - MEMBERS=const char* longitude - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_g2lon -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in g2lon */ - const char* longitude; -} grib_accessor_g2lon; - -extern grib_accessor_class* grib_accessor_class_double; - -static grib_accessor_class _grib_accessor_class_g2lon = { - &grib_accessor_class_double, /* super */ - "g2lon", /* name */ - sizeof(grib_accessor_g2lon), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_g2lon = &_grib_accessor_class_g2lon; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_g2lon* self = (grib_accessor_g2lon*)a; - int n = 0; - - self->longitude = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_g2lon* self = (grib_accessor_g2lon*)a; - int ret = 0; - long longitude; - - if ((ret = grib_get_long(grib_handle_of_accessor(a), self->longitude, &longitude)) != GRIB_SUCCESS) - return ret; - - if (longitude == GRIB_MISSING_LONG) { - *val = GRIB_MISSING_DOUBLE; - return GRIB_SUCCESS; - } - - *val = ((double)longitude) / 1000000.0; - - return GRIB_SUCCESS; -} - -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_g2lon* self = (grib_accessor_g2lon*)a; - long longitude; - double value = *val; - - if (value == GRIB_MISSING_DOUBLE) { - longitude = GRIB_MISSING_LONG; - } - else { - if (value < 0) - value += 360; - longitude = (long)(value * 1000000); - } - return grib_set_long(grib_handle_of_accessor(a), self->longitude, longitude); -} diff --git a/src/grib_accessor_class_gaussian_grid_name.cc b/src/grib_accessor_class_gaussian_grid_name.cc deleted file mode 100644 index 21117d4f1..000000000 --- a/src/grib_accessor_class_gaussian_grid_name.cc +++ /dev/null @@ -1,176 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init;unpack_string; get_native_type;string_length - MEMBERS = const char* N - MEMBERS = const char* Ni - MEMBERS = const char* isOctahedral - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_string(grib_accessor*, char*, size_t* len); -static size_t string_length(grib_accessor*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_gaussian_grid_name -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in gaussian_grid_name */ - const char* N; - const char* Ni; - const char* isOctahedral; -} grib_accessor_gaussian_grid_name; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_gaussian_grid_name = { - &grib_accessor_class_gen, /* super */ - "gaussian_grid_name", /* name */ - sizeof(grib_accessor_gaussian_grid_name), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - &string_length, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_gaussian_grid_name = &_grib_accessor_class_gaussian_grid_name; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - grib_accessor_gaussian_grid_name* self = (grib_accessor_gaussian_grid_name*)a; - int n = 0; - - self->N = grib_arguments_get_name(a->parent->h, arg, n++); - self->Ni = grib_arguments_get_name(a->parent->h, arg, n++); - self->isOctahedral = grib_arguments_get_name(a->parent->h, arg, n++); - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_STRING; -} - -#define MAX_GRIDNAME_LEN 16 - -static int unpack_string(grib_accessor* a, char* v, size_t* len) -{ - grib_accessor_gaussian_grid_name* self = (grib_accessor_gaussian_grid_name*)a; - - long N = 0, Ni = 0; - char tmp[MAX_GRIDNAME_LEN] = {0,}; - size_t length = 0; - int ret = GRIB_SUCCESS; - - if ((ret = grib_get_long_internal(a->parent->h, self->N, &N)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_get_long_internal(a->parent->h, self->Ni, &Ni)) != GRIB_SUCCESS) - return ret; - - if (Ni == GRIB_MISSING_LONG) { - /* Reduced gaussian grid */ - long isOctahedral = 0; - if ((ret = grib_get_long_internal(a->parent->h, self->isOctahedral, &isOctahedral)) != GRIB_SUCCESS) - return ret; - if (isOctahedral == 1) { - snprintf(tmp, sizeof(tmp), "O%ld", N); - } - else { - snprintf(tmp, sizeof(tmp), "N%ld", N); /* Classic */ - } - } - else { - /* Regular gaussian grid */ - snprintf(tmp, sizeof(tmp), "F%ld", N); - } - length = strlen(tmp) + 1; - - if (*len < length) { - const char* cclass_name = a->cclass->name; - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, length, *len); - *len = length; - return GRIB_BUFFER_TOO_SMALL; - } - - strcpy(v, tmp); - *len = length; - return GRIB_SUCCESS; -} - -static size_t string_length(grib_accessor* a) -{ - return MAX_GRIDNAME_LEN; -} diff --git a/src/grib_accessor_class_gds_is_present.cc b/src/grib_accessor_class_gds_is_present.cc deleted file mode 100644 index 6066231ac..000000000 --- a/src/grib_accessor_class_gds_is_present.cc +++ /dev/null @@ -1,183 +0,0 @@ -/* - * (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. - */ - -/****************************** - * Enrico Fucile - *****************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long - IMPLEMENTS = pack_long - IMPLEMENTS = init - MEMBERS = const char* gds_present - MEMBERS = const char* grid_definition - MEMBERS = const char* bitmap_present - MEMBERS = const char* values - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_gds_is_present -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in gds_is_present */ - const char* gds_present; - const char* grid_definition; - const char* bitmap_present; - const char* values; -} grib_accessor_gds_is_present; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_gds_is_present = { - &grib_accessor_class_long, /* super */ - "gds_is_present", /* name */ - sizeof(grib_accessor_gds_is_present), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_gds_is_present = &_grib_accessor_class_gds_is_present; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - int n = 0; - grib_accessor_gds_is_present* self = (grib_accessor_gds_is_present*)a; - grib_handle* h = grib_handle_of_accessor(a); - self->gds_present = grib_arguments_get_name(h, c, n++); - self->grid_definition = grib_arguments_get_name(h, c, n++); - self->bitmap_present = grib_arguments_get_name(h, c, n++); - self->values = grib_arguments_get_name(h, c, n++); - - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; - a->length = 0; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - grib_accessor_gds_is_present* self = (grib_accessor_gds_is_present*)a; - long missing = 255; - int ret = 0; - size_t size = 0; - double* values = NULL; - grib_context* c = a->context; - grib_handle* h = grib_handle_of_accessor(a); - - if (*val != 1) - return GRIB_NOT_IMPLEMENTED; - - if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) - return ret; - - values = (double*)grib_context_malloc(c, size * sizeof(double)); - if (!values) - return GRIB_OUT_OF_MEMORY; - - if ((ret = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) { - grib_context_free(c, values); - return ret; - } - - if ((ret = grib_set_long_internal(h, self->gds_present, *val)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_set_long_internal(h, self->bitmap_present, *val)) != GRIB_SUCCESS) - return ret; - - - if ((ret = grib_set_long_internal(h, self->grid_definition, missing)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) - return ret; - - grib_context_free(c, values); - - return GRIB_SUCCESS; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - int ret = 0; - grib_handle* h = grib_handle_of_accessor(a); - grib_accessor_gds_is_present* self = (grib_accessor_gds_is_present*)a; - - if ((ret = grib_get_long_internal(h, self->gds_present, val)) != GRIB_SUCCESS) - return ret; - - *len = 1; - - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_gds_not_present_bitmap.cc b/src/grib_accessor_class_gds_not_present_bitmap.cc deleted file mode 100644 index d8ec8ecd1..000000000 --- a/src/grib_accessor_class_gds_not_present_bitmap.cc +++ /dev/null @@ -1,216 +0,0 @@ -/* - * (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. - */ - -/****************************** - * Enrico Fucile - *****************************/ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init - IMPLEMENTS = unpack_double - IMPLEMENTS = pack_double - IMPLEMENTS = value_count - IMPLEMENTS = get_native_type - MEMBERS=const char* missing_value - MEMBERS=const char* number_of_values - MEMBERS=const char* number_of_points - MEMBERS=const char* latitude_of_first_point - MEMBERS=const char* ni - - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_gds_not_present_bitmap -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in gds_not_present_bitmap */ - const char* missing_value; - const char* number_of_values; - const char* number_of_points; - const char* latitude_of_first_point; - const char* ni; -} grib_accessor_gds_not_present_bitmap; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_gds_not_present_bitmap = { - &grib_accessor_class_gen, /* super */ - "gds_not_present_bitmap", /* name */ - sizeof(grib_accessor_gds_not_present_bitmap), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_gds_not_present_bitmap = &_grib_accessor_class_gds_not_present_bitmap; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long v, grib_arguments* args) -{ - int n = 0; - grib_accessor_gds_not_present_bitmap* self = (grib_accessor_gds_not_present_bitmap*)a; - grib_handle* hand = grib_handle_of_accessor(a); - - self->missing_value = grib_arguments_get_name(hand, args, n++); - self->number_of_values = grib_arguments_get_name(hand, args, n++); - self->number_of_points = grib_arguments_get_name(hand, args, n++); - self->latitude_of_first_point = grib_arguments_get_name(hand, args, n++); - self->ni = grib_arguments_get_name(hand, args, n++); - a->length = 0; -} - -static int value_count(grib_accessor* a, long* number_of_points) -{ - grib_accessor_gds_not_present_bitmap* self = (grib_accessor_gds_not_present_bitmap*)a; - *number_of_points = 0; - return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_points, number_of_points); -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_gds_not_present_bitmap* self = (grib_accessor_gds_not_present_bitmap*)a; - grib_handle* hand = grib_handle_of_accessor(a); - - long number_of_points = 0, number_of_values = 0, ni = 0; - long latitude_of_first_point = 0; - size_t i = 0; - size_t n_vals = 0; - long nn = 0; - long missing_value; - - int err = 0; - double* coded_vals = NULL; - err = grib_value_count(a, &nn); - n_vals = nn; - if (err) - return err; - - if ((err = grib_get_long(hand, self->number_of_points, &number_of_points)) != GRIB_SUCCESS) - return err; - - if ((err = grib_get_long(hand, self->number_of_values, &number_of_values)) != GRIB_SUCCESS) - return err; - - if ((err = grib_get_long(hand, self->latitude_of_first_point, &latitude_of_first_point)) != GRIB_SUCCESS) - return err; - - if ((err = grib_get_long(hand, self->missing_value, &missing_value)) != GRIB_SUCCESS) - return err; - - if ((err = grib_get_long(hand, self->ni, &ni)) != GRIB_SUCCESS) - return err; - - if (*len < number_of_points) { - *len = n_vals; - return GRIB_ARRAY_TOO_SMALL; - } - - if (number_of_values > 0) { - coded_vals = (double*)grib_context_malloc(a->context, number_of_values * sizeof(double)); - - if (coded_vals == NULL) - return GRIB_OUT_OF_MEMORY; - } - - if (latitude_of_first_point == 0) { - for (i = 0; i < number_of_values; i++) - val[i] = 1; - for (i = number_of_values; i < number_of_points; i++) - val[i] = 0; - } - else { - for (i = 0; i < ni - 1; i++) - val[i] = 0; - for (i = ni - 1; i < number_of_points; i++) - val[i] = 1; - } - - *len = number_of_points; - - grib_context_free(a->context, coded_vals); - return err; -} - -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - // See deprecated/grib_accessor_class_gds_not_present_bitmap.cc for - // a possible implementation - return GRIB_NOT_IMPLEMENTED; -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_DOUBLE; -} diff --git a/src/grib_accessor_class_gen.cc b/src/grib_accessor_class_gen.cc deleted file mode 100644 index b611f5043..000000000 --- a/src/grib_accessor_class_gen.cc +++ /dev/null @@ -1,675 +0,0 @@ -/* - * (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. - */ - -/*************************************************************************** - * Jean Baptiste Filippi - 01.11.2005 * - * Enrico Fucile * - * Shahram Najm * - ***************************************************************************/ -#include "grib_api_internal.h" -#include "grib_value.h" -#include -#include - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - IMPLEMENTS = unpack_long;pack_long; clear - IMPLEMENTS = unpack_double;pack_double;unpack_double_element;unpack_double_element_set - IMPLEMENTS = unpack_float - IMPLEMENTS = unpack_string;pack_string - IMPLEMENTS = unpack_string_array;pack_string_array - IMPLEMENTS = unpack_bytes;pack_bytes - IMPLEMENTS = unpack_double_subarray - IMPLEMENTS = init;dump;destroy;string_length - IMPLEMENTS = get_native_type;sub_section - IMPLEMENTS = next_offset;value_count;byte_offset;byte_count - IMPLEMENTS = notify_change;pack_expression - IMPLEMENTS = update_size; next; preferred_size - IMPLEMENTS = compare;is_missing;make_clone - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static grib_section* sub_section(grib_accessor* a); -static int get_native_type(grib_accessor*); -static int is_missing(grib_accessor*); -static int pack_bytes(grib_accessor*, const unsigned char*, size_t* len); -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int pack_string(grib_accessor*, const char*, size_t* len); -static int pack_string_array(grib_accessor*, const char**, size_t* len); -static int pack_expression(grib_accessor*, grib_expression*); -static int unpack_bytes(grib_accessor*, unsigned char*, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_float(grib_accessor*, float* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static int unpack_string_array(grib_accessor*, char**, size_t* len); -static size_t string_length(grib_accessor*); -static long byte_count(grib_accessor*); -static long byte_offset(grib_accessor*); -static long next_offset(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void destroy(grib_context*, grib_accessor*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); -static int notify_change(grib_accessor*, grib_accessor*); -static void update_size(grib_accessor*, size_t); -static size_t preferred_size(grib_accessor*, int); -static grib_accessor* next(grib_accessor*, int); -static int compare(grib_accessor*, grib_accessor*); -static int unpack_double_element(grib_accessor*, size_t i, double* val); -static int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array); -static int unpack_double_subarray(grib_accessor*, double* val, size_t start, size_t len); -static int clear(grib_accessor*); -static grib_accessor* make_clone(grib_accessor*, grib_section*, int*); - -typedef struct grib_accessor_gen -{ - grib_accessor att; - /* Members defined in gen */ -} grib_accessor_gen; - - -static grib_accessor_class _grib_accessor_class_gen = { - 0, /* super */ - "gen", /* name */ - sizeof(grib_accessor_gen), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - &destroy, /* destroy */ - &dump, /* dump */ - &next_offset, /* next_offset */ - &string_length, /* get length of string */ - &value_count, /* get number of values */ - &byte_count, /* get number of bytes */ - &byte_offset, /* get offset to bytes */ - &get_native_type, /* get native type */ - &sub_section, /* get sub_section */ - 0, /* pack_missing */ - &is_missing, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - &unpack_float, /* unpack_float */ - &pack_string, /* pack_string */ - &unpack_string, /* unpack_string */ - &pack_string_array, /* pack_string_array */ - &unpack_string_array, /* unpack_string_array */ - &pack_bytes, /* pack_bytes */ - &unpack_bytes, /* unpack_bytes */ - &pack_expression, /* pack_expression */ - ¬ify_change, /* notify_change */ - &update_size, /* update_size */ - &preferred_size, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - &next, /* next accessor */ - &compare, /* compare vs. another accessor */ - &unpack_double_element, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - &unpack_double_element_set, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - &unpack_double_subarray, /* unpack a subarray */ - &clear, /* clear */ - &make_clone, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_gen = &_grib_accessor_class_gen; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* param) -{ - grib_action* act = (grib_action*)(a->creator); - if (a->flags & GRIB_ACCESSOR_FLAG_TRANSIENT) { - a->length = 0; - if (!a->vvalue) - a->vvalue = (grib_virtual_value*)grib_context_malloc_clear(a->context, sizeof(grib_virtual_value)); - a->vvalue->type = grib_accessor_get_native_type(a); - a->vvalue->length = len; - if (act->default_value != NULL) { - const char* p = 0; - size_t s_len = 1; - long l; - int ret = 0; - double d; - char tmp[1024]; - grib_expression* expression = grib_arguments_get_expression(grib_handle_of_accessor(a), act->default_value, 0); - int type = grib_expression_native_type(grib_handle_of_accessor(a), expression); - switch (type) { - case GRIB_TYPE_DOUBLE: - grib_expression_evaluate_double(grib_handle_of_accessor(a), expression, &d); - grib_pack_double(a, &d, &s_len); - break; - - case GRIB_TYPE_LONG: - grib_expression_evaluate_long(grib_handle_of_accessor(a), expression, &l); - grib_pack_long(a, &l, &s_len); - break; - - default: - s_len = sizeof(tmp); - p = grib_expression_evaluate_string(grib_handle_of_accessor(a), expression, tmp, &s_len, &ret); - if (ret != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to evaluate %s as string", a->name); - Assert(0); - } - s_len = strlen(p) + 1; - grib_pack_string(a, p, &s_len); - break; - } - } - } - else { - a->length = len; - } -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - const int type = grib_accessor_get_native_type(a); - switch (type) { - case GRIB_TYPE_STRING: - grib_dump_string(dumper, a, NULL); - break; - case GRIB_TYPE_DOUBLE: - grib_dump_double(dumper, a, NULL); - break; - case GRIB_TYPE_LONG: - grib_dump_long(dumper, a, NULL); - break; - default: - grib_dump_bytes(dumper, a, NULL); - } -} - -static long next_offset(grib_accessor* a) -{ - return a->offset + a->length; -} - -static int value_count(grib_accessor* a, long* count) -{ - *count = 1; - return 0; -} - -static size_t string_length(grib_accessor* a) -{ - return 1024; -} - -static long byte_count(grib_accessor* a) -{ - return a->length; -} - -static int get_native_type(grib_accessor* a) -{ - grib_context_log(a->context, GRIB_LOG_ERROR, - "Accessor %s [%s] must implement 'get_native_type'", a->name, a->cclass->name); - return GRIB_TYPE_UNDEFINED; -} - -static long byte_offset(grib_accessor* a) -{ - return a->offset; -} - -static int unpack_bytes(grib_accessor* a, unsigned char* val, size_t* len) -{ - unsigned char* buf = grib_handle_of_accessor(a)->buffer->data; - const long length = grib_byte_count(a); - const long offset = grib_byte_offset(a); - - if (*len < length) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it is %ld bytes long", a->name, length); - *len = length; - return GRIB_ARRAY_TOO_SMALL; - } - - memcpy(val, buf + offset, length); - *len = length; - - return GRIB_SUCCESS; -} - -static int clear(grib_accessor* a) -{ - unsigned char* buf = grib_handle_of_accessor(a)->buffer->data; - const long length = grib_byte_count(a); - const long offset = grib_byte_offset(a); - - memset(buf + offset, 0, length); - - return GRIB_SUCCESS; -} - -static int unpack_long(grib_accessor* a, long* v, size_t* len) -{ - int type = GRIB_TYPE_UNDEFINED; - if (a->cclass->unpack_double && a->cclass->unpack_double != &unpack_double) { - double val = 0.0; - size_t l = 1; - grib_unpack_double(a, &val, &l); - if (val == GRIB_MISSING_DOUBLE) - *v = GRIB_MISSING_LONG; - else - *v = (long)val; - grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting double %s to long", a->name); - return GRIB_SUCCESS; - } - - if (a->cclass->unpack_string && a->cclass->unpack_string != &unpack_string) { - char val[1024]; - size_t l = sizeof(val); - char* last = NULL; - grib_unpack_string(a, val, &l); - - *v = strtol(val, &last, 10); - - if (*last == 0) { - grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting string %s to long", a->name); - return GRIB_SUCCESS; - } - } - - grib_context_log(a->context, GRIB_LOG_ERROR, "Cannot unpack key '%s' as long", a->name); - if (grib_get_native_type(grib_handle_of_accessor(a), a->name, &type) == GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Hint: Try unpacking as %s", grib_get_type_name(type)); - } - return GRIB_NOT_IMPLEMENTED; -} - -template -static int unpack(grib_accessor* a, T* v, size_t* len) -{ - static_assert(std::is_floating_point::value, "Requires floating point numbers"); - int type = GRIB_TYPE_UNDEFINED; - const char* Tname = type_to_string(*v); - if (a->cclass->unpack_long && a->cclass->unpack_long != &unpack_long) { - long val = 0; - size_t l = 1; - grib_unpack_long(a, &val, &l); - *v = val; - grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting long %s to %s", a->name, Tname); - return GRIB_SUCCESS; - } - - if (a->cclass->unpack_string && a->cclass->unpack_string != &unpack_string) { - char val[1024]; - size_t l = sizeof(val); - char* last = NULL; - grib_unpack_string(a, val, &l); - - *v = strtod(val, &last); - if (*last == 0) { /* conversion of string to double worked */ - grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting string %s to %s", a->name, Tname); - return GRIB_SUCCESS; - } - } - - grib_context_log(a->context, GRIB_LOG_ERROR, "Cannot unpack key '%s' as %s", a->name, Tname); - if (grib_get_native_type(grib_handle_of_accessor(a), a->name, &type) == GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Hint: Try unpacking as %s", grib_get_type_name(type)); - } - - return GRIB_NOT_IMPLEMENTED; -} - -static int unpack_double(grib_accessor* a, double* v, size_t* len) -{ - return unpack(a, v, len); -} - -static int unpack_float(grib_accessor* a, float* v, size_t* len) -{ - return unpack(a, v, len); -} - -static int unpack_string(grib_accessor* a, char* v, size_t* len) -{ - int err = 0; - if (a->cclass->unpack_double && a->cclass->unpack_double != &unpack_double) { - double val = 0.0; - size_t l = 1; - err = grib_unpack_double(a, &val, &l); - if (err) return err; - snprintf(v, 64, "%g", val); - *len = strlen(v); - grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting double %s to string", a->name); - return GRIB_SUCCESS; - } - - if (a->cclass->unpack_long && a->cclass->unpack_long != &unpack_long) { - long val = 0; - size_t l = 1; - err = grib_unpack_long(a, &val, &l); - if (err) return err; - snprintf(v, 64, "%ld", val); - *len = strlen(v); - grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting long %s to string\n", a->name); - return GRIB_SUCCESS; - } - - return GRIB_NOT_IMPLEMENTED; -} - -static int unpack_string_array(grib_accessor* a, char** v, size_t* len) -{ - size_t length = 0; - - int err = grib_get_string_length_acc(a, &length); - if (err) - return err; - v[0] = (char*)grib_context_malloc_clear(a->context, length); - grib_unpack_string(a, v[0], &length); // TODO(masn): check return value - *len = 1; - - return GRIB_SUCCESS; -} - -static int pack_expression(grib_accessor* a, grib_expression* e) -{ - size_t len = 1; - long lval = 0; - double dval = 0; - const char* cval = NULL; - int ret = 0; - grib_handle* hand = grib_handle_of_accessor(a); - - // Use the native type of the expression not the accessor - switch (grib_expression_native_type(hand, e)) { - case GRIB_TYPE_LONG: { - len = 1; - ret = grib_expression_evaluate_long(hand, e, &lval); - if (ret != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to set %s as long (from %s)", - a->name, e->cclass->name); - return ret; - } - /*if (hand->context->debug) - printf("ECCODES DEBUG grib_accessor_class_gen::pack_expression %s %ld\n", a->name,lval);*/ - return grib_pack_long(a, &lval, &len); - } - - case GRIB_TYPE_DOUBLE: { - len = 1; - ret = grib_expression_evaluate_double(hand, e, &dval); - if (ret != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to set %s as double (from %s)", - a->name, e->cclass->name); - return ret; - } - /*if (hand->context->debug) - printf("ECCODES DEBUG grib_accessor_class_gen::pack_expression %s %g\n", a->name, dval);*/ - return grib_pack_double(a, &dval, &len); - } - - case GRIB_TYPE_STRING: { - char tmp[1024]; - len = sizeof(tmp); - cval = grib_expression_evaluate_string(hand, e, tmp, &len, &ret); - if (ret != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to set %s as string (from %s)", - a->name, e->cclass->name); - return ret; - } - len = strlen(cval); - /*if (hand->context->debug) - printf("ECCODES DEBUG grib_accessor_class_gen::pack_expression %s %s\n", a->name, cval);*/ - return grib_pack_string(a, cval, &len); - } - } - - return GRIB_NOT_IMPLEMENTED; -} - -static int pack_long(grib_accessor* a, const long* v, size_t* len) -{ - grib_context* c = a->context; - if (a->cclass->pack_double && a->cclass->pack_double != &pack_double) { - double* val = (double*)grib_context_malloc(c, *len * (sizeof(double))); - if (!val) { - grib_context_log(c, GRIB_LOG_ERROR, "Unable to allocate %zu bytes", *len * (sizeof(double))); - return GRIB_OUT_OF_MEMORY; - } - for (size_t i = 0; i < *len; i++) - val[i] = v[i]; - int ret = grib_pack_double(a, val, len); - grib_context_free(c, val); - return ret; - } - grib_context_log(c, GRIB_LOG_ERROR, "Should not pack '%s' as an integer", a->name); - if (a->cclass->pack_string && a->cclass->pack_string != &pack_string) { - grib_context_log(c, GRIB_LOG_ERROR, "Try packing as a string"); - } - return GRIB_NOT_IMPLEMENTED; -} - -static int pack_double_array_as_long(grib_accessor* a, const double* v, size_t* len) -{ - grib_context* c = a->context; - int ret = GRIB_SUCCESS; - size_t numBytes = *len * (sizeof(long)); - long* lValues = (long*)grib_context_malloc(c, numBytes); - if (!lValues) { - grib_context_log(c, GRIB_LOG_ERROR, "Unable to allocate %ld bytes", numBytes); - return GRIB_OUT_OF_MEMORY; - } - for (size_t i = 0; i < *len; i++) - lValues[i] = (long)v[i]; /* convert from double to long */ - ret = grib_pack_long(a, lValues, len); - grib_context_free(c, lValues); - return ret; -} - -static int pack_double(grib_accessor* a, const double* v, size_t* len) -{ - int do_pack_as_long = 0; - grib_context* c = a->context; - if (a->cclass->pack_long && a->cclass->pack_long != &pack_long) { - do_pack_as_long = 1; - } - else { - /* ECC-648: Special case of codetable */ - if (strcmp(a->cclass->name, "codetable") == 0) { - do_pack_as_long = 1; - } - } - if (do_pack_as_long) { - return pack_double_array_as_long(a, v, len); - } - grib_context_log(c, GRIB_LOG_ERROR, "Should not pack '%s' as a double", a->name); - if (a->cclass->pack_string && a->cclass->pack_string != &pack_string) { - grib_context_log(c, GRIB_LOG_ERROR, "Try packing as a string"); - } - return GRIB_NOT_IMPLEMENTED; -} - -static int pack_string_array(grib_accessor* a, const char** v, size_t* len) -{ - int err = 0; - size_t length = 0; - grib_accessor* as = 0; - - as = a; - long i = (long)*len - 1; - while (as && i >= 0) { - length = strlen(v[i]); - err = grib_pack_string(as, v[i], &length); - if (err) - return err; - --i; - as = as->same; - } - return GRIB_SUCCESS; -} - -static int pack_string(grib_accessor* a, const char* v, size_t* len) -{ - if (a->cclass->pack_double && a->cclass->pack_double != &pack_double) { - size_t l = 1; - char* endPtr = NULL; /* for error handling */ - double val = strtod(v, &endPtr); - if (*endPtr) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s: Invalid value (%s) for key '%s'. String cannot be converted to a double", - __func__, v, a->name); - return GRIB_WRONG_TYPE; - } - return grib_pack_double(a, &val, &l); - } - - if (a->cclass->pack_long && a->cclass->pack_long != &pack_long) { - size_t l = 1; - long val = atol(v); - return grib_pack_long(a, &val, &l); - } - - grib_context_log(a->context, GRIB_LOG_ERROR, "Should not pack '%s' as string", a->name); - return GRIB_NOT_IMPLEMENTED; -} - -static int pack_bytes(grib_accessor* a, const unsigned char* val, size_t* len) -{ - const size_t length = *len; - if (length != a->length) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "pack_bytes: Wrong size (%zu) for %s. It is %ld bytes long", - length, a->name, a->length); - return GRIB_BUFFER_TOO_SMALL; - } - grib_buffer_replace(a, val, length, 1, 1); - return GRIB_SUCCESS; -} - -static void destroy(grib_context* ct, grib_accessor* a) -{ - grib_dependency_remove_observed(a); - grib_dependency_remove_observer(a); - if (a->vvalue != NULL) { - grib_context_free(ct, a->vvalue); - a->vvalue = NULL; - } - /*grib_context_log(ct,GRIB_LOG_DEBUG,"address=%p",a);*/ -} - -static grib_section* sub_section(grib_accessor* a) -{ - return NULL; -} - -static int notify_change(grib_accessor* self, grib_accessor* observed) -{ - /* Default behaviour is to notify creator */ - return grib_action_notify_change(self->creator, self, observed); -} - -static void update_size(grib_accessor* a, size_t s) -{ - grib_context_log(a->context, GRIB_LOG_FATAL, - "Accessor %s [%s] must implement 'update_size'", a->name, a->cclass->name); -} - -static grib_accessor* next(grib_accessor* a, int mod) -{ - grib_accessor* next = NULL; - if (a->next) { - next = a->next; - } - else { - if (a->parent->owner) - next = a->parent->owner->cclass->next(a->parent->owner, 0); - } - return next; -} - -static int compare(grib_accessor* a, grib_accessor* b) -{ - return GRIB_NOT_IMPLEMENTED; -} - -/* Redefined in all padding */ - -static size_t preferred_size(grib_accessor* a, int from_handle) -{ - return a->length; -} - -static int is_missing(grib_accessor* a) -{ - int i = 0; - int is_missing = 1; - unsigned char ones = 0xff; - unsigned char* v = NULL; - - if (a->flags & GRIB_ACCESSOR_FLAG_TRANSIENT) { - if (a->vvalue == NULL) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s internal error (flags=0x%lX)", a->name, a->flags); - Assert(!"grib_accessor_class_gen::is_missing(): a->vvalue == NULL"); - return 0; - } - return a->vvalue->missing; - } - Assert(a->length >= 0); - - v = grib_handle_of_accessor(a)->buffer->data + a->offset; - - for (i = 0; i < a->length; i++) { - if (*v != ones) { - is_missing = 0; - break; - } - v++; - } - - return is_missing; -} - -static int unpack_double_element(grib_accessor* a, size_t i, double* val) -{ - return GRIB_NOT_IMPLEMENTED; -} - -static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) -{ - return GRIB_NOT_IMPLEMENTED; -} - -static int unpack_double_subarray(grib_accessor* a, double* val, size_t start, size_t len) -{ - return GRIB_NOT_IMPLEMENTED; -} - -static grib_accessor* make_clone(grib_accessor* a, grib_section* s, int* err) -{ - *err = GRIB_NOT_IMPLEMENTED; - return NULL; -} diff --git a/src/grib_accessor_class_getenv.cc b/src/grib_accessor_class_getenv.cc deleted file mode 100644 index 6bc0ced3e..000000000 --- a/src/grib_accessor_class_getenv.cc +++ /dev/null @@ -1,157 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_ascii - IMPLEMENTS = pack_string;unpack_string;value_count - IMPLEMENTS = init;string_length - MEMBERS= const char* name - MEMBERS= char* value - MEMBERS= const char* default_value - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_string(grib_accessor*, const char*, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static size_t string_length(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_getenv -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in ascii */ - /* Members defined in getenv */ - const char* name; - char* value; - const char* default_value; -} grib_accessor_getenv; - -extern grib_accessor_class* grib_accessor_class_ascii; - -static grib_accessor_class _grib_accessor_class_getenv = { - &grib_accessor_class_ascii, /* super */ - "getenv", /* name */ - sizeof(grib_accessor_getenv), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - &string_length, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - &pack_string, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_getenv = &_grib_accessor_class_getenv; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* args) -{ - grib_accessor_getenv* self = (grib_accessor_getenv*)a; - static char undefined[] = "undefined"; - - self->name = grib_arguments_get_string(grib_handle_of_accessor(a), args, 0); - self->default_value = grib_arguments_get_string(grib_handle_of_accessor(a), args, 1); - if (!self->default_value) - self->default_value = undefined; - self->value = 0; -} - -static int pack_string(grib_accessor* a, const char* val, size_t* len) -{ - return GRIB_NOT_IMPLEMENTED; -} - -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - grib_accessor_getenv* self = (grib_accessor_getenv*)a; - char* v = 0; - size_t l = 0; - - if (!self->value) { - v = getenv(self->name); - if (!v) - v = (char*)self->default_value; - self->value = v; - } - - l = strlen(self->value); - if (*len < l) - return GRIB_BUFFER_TOO_SMALL; - snprintf(val, 1024, "%s", self->value); - *len = strlen(self->value); - - return GRIB_SUCCESS; -} - -static int value_count(grib_accessor* a, long* count) -{ - *count = 1; - return 0; -} - -static size_t string_length(grib_accessor* a) -{ - return 1024; -} diff --git a/src/grib_accessor_class_group.cc b/src/grib_accessor_class_group.cc deleted file mode 100644 index df2118bff..000000000 --- a/src/grib_accessor_class_group.cc +++ /dev/null @@ -1,272 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = unpack_string - IMPLEMENTS = unpack_long - IMPLEMENTS = unpack_double - IMPLEMENTS = init;dump;string_length - IMPLEMENTS = value_count - IMPLEMENTS = next_offset - IMPLEMENTS = get_native_type - IMPLEMENTS = compare - MEMBERS = char endCharacter - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static size_t string_length(grib_accessor*); -static long next_offset(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); -static int compare(grib_accessor*, grib_accessor*); - -typedef struct grib_accessor_group -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in group */ - char endCharacter; -} grib_accessor_group; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_group = { - &grib_accessor_class_gen, /* super */ - "group", /* name */ - sizeof(grib_accessor_group), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - &next_offset, /* next_offset */ - &string_length, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - &compare, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_group = &_grib_accessor_class_group; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - grib_buffer* buffer = grib_handle_of_accessor(a)->buffer; - grib_accessor_group* self = (grib_accessor_group*)a; - - size_t i = 0; - unsigned char* v; - const char* s = grib_arguments_get_string(grib_handle_of_accessor(a), arg, 0); - - if (s && strlen(s) > 1) { - grib_context_log(a->context, GRIB_LOG_WARNING, - "Using only first character as group end of %s not the string %s", a->name, s); - } - - self->endCharacter = s ? s[0] : 0; - - v = buffer->data + a->offset; - i = 0; - if (s) { - while (*v != self->endCharacter && i <= buffer->ulength) { - if (*v > 126) - *v = 32; - v++; - i++; - } - } - else { - while (*v > 32 && *v != 61 && *v < 127 && i <= buffer->ulength) { - v++; - i++; - } - } - a->length = i; - - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; -} - -static int value_count(grib_accessor* a, long* count) -{ - *count = 1; - return 0; -} - -static size_t string_length(grib_accessor* a) -{ - return a->length; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_string(dumper, a, NULL); -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_STRING; -} - -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - long i = 0; - size_t l = a->length + 1; - grib_handle* h = grib_handle_of_accessor(a); - - if (*len < l) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - a->cclass->name, a->name, l, *len); - *len = l; - return GRIB_ARRAY_TOO_SMALL; - } - - for (i = 0; i < a->length; i++) - val[i] = h->buffer->data[a->offset + i]; - val[i] = 0; - *len = i; - return GRIB_SUCCESS; -} - -static int unpack_long(grib_accessor* a, long* v, size_t* len) -{ - char val[1024] = {0,}; - size_t l = sizeof(val); - size_t i = 0; - char* last = NULL; - int err = grib_unpack_string(a, val, &l); - - if (err) - return err; - - i = 0; - while (i < l - 1 && val[i] == ' ') - i++; - - if (val[i] == 0) { - *v = 0; - return 0; - } - if (val[i + 1] == ' ' && i < l - 2) - val[i + 1] = 0; - - *v = strtol(val, &last, 10); - - grib_context_log(a->context, GRIB_LOG_DEBUG, " Casting string %s to long", a->name); - return GRIB_SUCCESS; -} - -static int unpack_double(grib_accessor* a, double* v, size_t* len) -{ - char val[1024]; - size_t l = sizeof(val); - char* last = NULL; - grib_unpack_string(a, val, &l); - - *v = strtod(val, &last); - - if (*last == 0) { - grib_context_log(a->context, GRIB_LOG_DEBUG, " Casting string %s to long", a->name); - return GRIB_SUCCESS; - } - - return GRIB_NOT_IMPLEMENTED; -} - -static int compare(grib_accessor* a, grib_accessor* b) -{ - grib_context_log(a->context, GRIB_LOG_ERROR, "%s:%s not implemented", __func__, a->name); - return GRIB_NOT_IMPLEMENTED; - - // int retval = 0; - // char* aval = 0; - // char* bval = 0; - // int err = 0; - // size_t alen = 0; - // size_t blen = 0; - // long count = 0; - // err = grib_value_count(a, &count); - // if (err) return err; - // alen = count; - // err = grib_value_count(b, &count); - // if (err) return err; - // blen = count; - // if (alen != blen) return GRIB_COUNT_MISMATCH; - // aval = (char*)grib_context_malloc(a->context, alen * sizeof(char)); - // bval = (char*)grib_context_malloc(b->context, blen * sizeof(char)); - // grib_unpack_string(a, aval, &alen); - // grib_unpack_string(b, bval, &blen); - // retval = GRIB_SUCCESS; - // if (strcmp(aval, bval)) retval = GRIB_STRING_VALUE_MISMATCH; - // grib_context_free(a->context, aval); - // grib_context_free(b->context, bval); - // return retval; -} - -static long next_offset(grib_accessor* a) -{ - return a->offset + a->length; -} diff --git a/src/grib_accessor_class_gts_header.cc b/src/grib_accessor_class_gts_header.cc deleted file mode 100644 index 65b295634..000000000 --- a/src/grib_accessor_class_gts_header.cc +++ /dev/null @@ -1,152 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_ascii - IMPLEMENTS = unpack_string;value_count - IMPLEMENTS = init;string_length - MEMBERS = int gts_offset - MEMBERS = int gts_length - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_string(grib_accessor*, char*, size_t* len); -static size_t string_length(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_gts_header -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in ascii */ - /* Members defined in gts_header */ - int gts_offset; - int gts_length; -} grib_accessor_gts_header; - -extern grib_accessor_class* grib_accessor_class_ascii; - -static grib_accessor_class _grib_accessor_class_gts_header = { - &grib_accessor_class_ascii, /* super */ - "gts_header", /* name */ - sizeof(grib_accessor_gts_header), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - &string_length, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_gts_header = &_grib_accessor_class_gts_header; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_gts_header* self = (grib_accessor_gts_header*)a; - self->gts_offset = -1; - self->gts_length = -1; - self->gts_offset = grib_arguments_get_long(grib_handle_of_accessor(a), c, 0); - self->gts_length = grib_arguments_get_long(grib_handle_of_accessor(a), c, 1); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; -} - -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - grib_accessor_gts_header* self = (grib_accessor_gts_header*)a; - grib_handle* h = grib_handle_of_accessor(a); - int offset = 0; - size_t length = 0; - - if (h->gts_header == NULL || h->gts_header_len < 8) { - if (*len < 8) - return GRIB_BUFFER_TOO_SMALL; - snprintf(val, 1024, "missing"); - return GRIB_SUCCESS; - } - if (*len < h->gts_header_len) - return GRIB_BUFFER_TOO_SMALL; - - offset = self->gts_offset > 0 ? self->gts_offset : 0; - length = self->gts_length > 0 ? self->gts_length : h->gts_header_len; - - memcpy(val, h->gts_header + offset, length); - - *len = length; - - return GRIB_SUCCESS; -} - -static int value_count(grib_accessor* a, long* count) -{ - *count = 1; - return 0; -} - -static size_t string_length(grib_accessor* a) -{ - grib_handle* h = grib_handle_of_accessor(a); - return h->gts_header_len; -} diff --git a/src/grib_accessor_class_hash_array.cc b/src/grib_accessor_class_hash_array.cc deleted file mode 100644 index d191a5232..000000000 --- a/src/grib_accessor_class_hash_array.cc +++ /dev/null @@ -1,293 +0,0 @@ -/* - * (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. - */ - - -/******************************************************* - * Enrico Fucile - ******************************************************/ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = unpack_double;pack_double - IMPLEMENTS = unpack_string;pack_string;string_length - IMPLEMENTS = unpack_long;pack_long;destroy - IMPLEMENTS = init;dump;value_count;get_native_type - IMPLEMENTS = compare - MEMBERS = char* key - MEMBERS = grib_hash_array_value* ha - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int pack_string(grib_accessor*, const char*, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static size_t string_length(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void destroy(grib_context*, grib_accessor*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); -static int compare(grib_accessor*, grib_accessor*); - -typedef struct grib_accessor_hash_array -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in hash_array */ - char* key; - grib_hash_array_value* ha; -} grib_accessor_hash_array; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_hash_array = { - &grib_accessor_class_gen, /* super */ - "hash_array", /* name */ - sizeof(grib_accessor_hash_array), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - &destroy, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - &string_length, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - &pack_string, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - &compare, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_hash_array = &_grib_accessor_class_hash_array; - -/* END_CLASS_IMP */ - -#define MAX_HASH_ARRAY_STRING_LENGTH 255 - -static void init(grib_accessor* a, const long len, grib_arguments* args) -{ - grib_accessor_hash_array* self = (grib_accessor_hash_array*)a; - a->length = 0; - self->key = 0; - self->ha = NULL; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_string(dumper, a, NULL); -} - -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_hash_array* self = (grib_accessor_hash_array*)a; - char s[200] = {0,}; - snprintf(s, sizeof(s), "%g", *val); - self->key = grib_context_strdup(a->context, s); - self->ha = 0; - return GRIB_SUCCESS; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - grib_accessor_hash_array* self = (grib_accessor_hash_array*)a; - char s[200] = {0,}; - snprintf(s, sizeof(s), "%ld", *val); - if (self->key) - grib_context_free(a->context, self->key); - self->key = grib_context_strdup(a->context, s); - self->ha = 0; - return GRIB_SUCCESS; -} - -static int pack_string(grib_accessor* a, const char* v, size_t* len) -{ - grib_accessor_hash_array* self = (grib_accessor_hash_array*)a; - self->key = grib_context_strdup(a->context, v); - self->ha = 0; - return GRIB_SUCCESS; -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - return GRIB_NOT_IMPLEMENTED; -} - -static grib_hash_array_value* find_hash_value(grib_accessor* a, int* err) -{ - grib_accessor_hash_array* self = (grib_accessor_hash_array*)a; - grib_hash_array_value* ha_ret = 0; - grib_hash_array_value* ha = NULL; - - ha = get_hash_array(grib_handle_of_accessor(a), a->creator); - if (!ha) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "unable to get hash value for %s", a->creator->name); - *err = GRIB_HASH_ARRAY_NO_MATCH; - return NULL; - } - - *err = GRIB_SUCCESS; - - Assert(ha != NULL); - if (!self->key) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "unable to get hash value for %s, set before getting", a->creator->name); - *err = GRIB_HASH_ARRAY_NO_MATCH; - return NULL; - } - - ha_ret = (grib_hash_array_value*)grib_trie_get(ha->index, self->key); - if (!ha_ret) - ha_ret = (grib_hash_array_value*)grib_trie_get(ha->index, "default"); - - if (!ha_ret) { - *err = GRIB_HASH_ARRAY_NO_MATCH; - grib_context_log(a->context, GRIB_LOG_ERROR, - "hash_array: no match for %s=%s", - a->creator->name, self->key); - const char* full_path = get_hash_array_full_path(a->creator); - if (full_path) { - grib_context_log(a->context, GRIB_LOG_ERROR, "hash_array: file path = %s", full_path); - } - grib_context_log(a->context, GRIB_LOG_ERROR, "Hint: Check the key 'masterTablesVersionNumber'"); - return NULL; - } - return ha_ret; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_hash_array_value* ha = 0; - grib_accessor_hash_array* self = (grib_accessor_hash_array*)a; - int err = 0; - size_t i = 0; - - if (!self->ha) { - ha = find_hash_value(a, &err); - if (err) - return err; - self->ha = ha; - } - - switch (self->ha->type) { - case GRIB_HASH_ARRAY_TYPE_INTEGER: - if (*len < self->ha->iarray->n) { - return GRIB_ARRAY_TOO_SMALL; - } - *len = self->ha->iarray->n; - for (i = 0; i < *len; i++) - val[i] = self->ha->iarray->v[i]; - break; - - default: - return GRIB_NOT_IMPLEMENTED; - } - - return GRIB_SUCCESS; -} - -static int get_native_type(grib_accessor* a) -{ - int type = GRIB_TYPE_STRING; - if (a->flags & GRIB_ACCESSOR_FLAG_LONG_TYPE) - type = GRIB_TYPE_LONG; - - return type; -} - -static void destroy(grib_context* c, grib_accessor* a) -{ - grib_accessor_hash_array* self = (grib_accessor_hash_array*)a; - if (self->key) - grib_context_free(c, self->key); -} - -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - return GRIB_NOT_IMPLEMENTED; -} - -static size_t string_length(grib_accessor* a) -{ - return MAX_HASH_ARRAY_STRING_LENGTH; -} - -static int value_count(grib_accessor* a, long* count) -{ - int err = 0; - grib_accessor_hash_array* self = (grib_accessor_hash_array*)a; - grib_hash_array_value* ha = 0; - - if (!self->ha) { - ha = find_hash_value(a, &err); - if (err) - return err; - self->ha = ha; - } - - *count = self->ha->iarray->n; - return err; -} - -static int compare(grib_accessor* a, grib_accessor* b) -{ - return GRIB_NOT_IMPLEMENTED; -} diff --git a/src/grib_accessor_class_headers_only.cc b/src/grib_accessor_class_headers_only.cc deleted file mode 100644 index d3a98efb0..000000000 --- a/src/grib_accessor_class_headers_only.cc +++ /dev/null @@ -1,116 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = unpack_long; get_native_type - IMPLEMENTS = init - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_headers_only -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in headers_only */ -} grib_accessor_headers_only; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_headers_only = { - &grib_accessor_class_gen, /* super */ - "headers_only", /* name */ - sizeof(grib_accessor_headers_only), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_headers_only = &_grib_accessor_class_headers_only; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; - a->length = 0; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - *val = grib_handle_of_accessor(a)->partial; - *len = 1; - return 0; -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_LONG; -} diff --git a/src/grib_accessor_class_ibmfloat.cc b/src/grib_accessor_class_ibmfloat.cc deleted file mode 100644 index 27e6da1c5..000000000 --- a/src/grib_accessor_class_ibmfloat.cc +++ /dev/null @@ -1,264 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -#include - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_double - IMPLEMENTS = unpack_double;pack_double - IMPLEMENTS = unpack_float - IMPLEMENTS = init - IMPLEMENTS = next_offset - IMPLEMENTS = byte_count - IMPLEMENTS = value_count - IMPLEMENTS = byte_offset - MEMBERS = grib_arguments* arg - IMPLEMENTS = update_size - IMPLEMENTS = nearest_smaller_value - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_float(grib_accessor*, float* val, size_t* len); -static long byte_count(grib_accessor*); -static long byte_offset(grib_accessor*); -static long next_offset(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); -static void update_size(grib_accessor*, size_t); -static int nearest_smaller_value (grib_accessor*, double, double*); - -typedef struct grib_accessor_ibmfloat -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in ibmfloat */ - grib_arguments* arg; -} grib_accessor_ibmfloat; - -extern grib_accessor_class* grib_accessor_class_double; - -static grib_accessor_class _grib_accessor_class_ibmfloat = { - &grib_accessor_class_double, /* super */ - "ibmfloat", /* name */ - sizeof(grib_accessor_ibmfloat), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - &next_offset, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - &byte_count, /* get number of bytes */ - &byte_offset, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - &unpack_float, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - &update_size, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - &nearest_smaller_value, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_ibmfloat = &_grib_accessor_class_ibmfloat; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - grib_accessor_ibmfloat* self = (grib_accessor_ibmfloat*)a; - long count = 0; - - self->arg = arg; - grib_value_count(a, &count); - a->length = 4 * count; - Assert(a->length >= 0); -} - -template -static int unpack(grib_accessor* a, T* val, size_t* len) -{ - static_assert(std::is_floating_point::value, "Requires floating point numbers"); - unsigned long rlen = 0; - long count = 0; - int err = 0; - unsigned long i = 0; - long bitp = a->offset * 8; - grib_handle* hand = grib_handle_of_accessor(a); - - err = grib_value_count(a, &count); - if (err) - return err; - rlen = count; - - if (*len < rlen) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size (%zu) for %s, it contains %lu values", *len, a->name, rlen); - *len = 0; - return GRIB_ARRAY_TOO_SMALL; - } - - for (i = 0; i < rlen; i++) - val[i] = (T)grib_long_to_ibm(grib_decode_unsigned_long(hand->buffer->data, &bitp, 32)); - - *len = rlen; - return GRIB_SUCCESS; -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - return unpack(a, val, len); -} - -static int unpack_float(grib_accessor* a, float* val, size_t* len) -{ - return unpack(a, val, len); -} - -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_ibmfloat* self = (grib_accessor_ibmfloat*)a; - int ret = 0; - unsigned long i = 0; - unsigned long rlen = *len; - size_t buflen = 0; - unsigned char* buf = NULL; - long off = 0; - - if (*len < 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it packs at least 1 value", a->name); - *len = 0; - return GRIB_ARRAY_TOO_SMALL; - } - - if (rlen == 1) { - - //double x = 0; - //grib_nearest_smaller_ibm_float(val[0],&x); - //double y = grib_long_to_ibm(grib_ibm_to_long(val[0])); - //printf("IBMFLOAT val=%.20f nearest_smaller_ibm_float=%.20f long_to_ibm=%.20f\n",val[0],x ,y); - - off = byte_offset(a) * 8; - ret = grib_encode_unsigned_long(grib_handle_of_accessor(a)->buffer->data, grib_ibm_to_long(val[0]), &off, 32); - if (*len > 1) - grib_context_log(a->context, GRIB_LOG_WARNING, "ibmfloat: Trying to pack %zu values in a scalar %s, packing first value", - *len, a->name); - if (ret == GRIB_SUCCESS) - len[0] = 1; - return ret; - } - - buflen = rlen * 4; - - buf = (unsigned char*)grib_context_malloc(a->context, buflen); - - for (i = 0; i < rlen; i++) { - grib_encode_unsigned_longb(buf, grib_ibm_to_long(val[i]), &off, 32); - } - ret = grib_set_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, self->arg, 0), rlen); - - if (ret == GRIB_SUCCESS) - grib_buffer_replace(a, buf, buflen, 1, 1); - else - *len = 0; - - grib_context_free(a->context, buf); - - a->length = byte_count(a); - - return ret; -} - -static long byte_count(grib_accessor* a) -{ - return a->length; -} - -static int value_count(grib_accessor* a, long* len) -{ - grib_accessor_ibmfloat* self = (grib_accessor_ibmfloat*)a; - *len = 0; - if (!self->arg) { - *len = 1; - return 0; - } - return grib_get_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, self->arg, 0), len); -} - -static long byte_offset(grib_accessor* a) -{ - return a->offset; -} - -static void update_size(grib_accessor* a, size_t s) -{ - a->length = (long)s; - Assert(a->length >= 0); -} - -static long next_offset(grib_accessor* a) -{ - return grib_byte_offset(a) + grib_byte_count(a); -} - -static int nearest_smaller_value(grib_accessor* a, double val, double* nearest) -{ - int ret = 0; - if (grib_nearest_smaller_ibm_float(val, nearest) == GRIB_INTERNAL_ERROR) { - grib_context_log(a->context, GRIB_LOG_ERROR, "ibm_float:nearest_smaller_value overflow value=%g", val); - grib_dump_content(grib_handle_of_accessor(a), stderr, "wmo", GRIB_DUMP_FLAG_HEXADECIMAL, 0); - ret = GRIB_INTERNAL_ERROR; - } - return ret; -} diff --git a/src/grib_accessor_class_ieeefloat.cc b/src/grib_accessor_class_ieeefloat.cc deleted file mode 100644 index d6fa411bb..000000000 --- a/src/grib_accessor_class_ieeefloat.cc +++ /dev/null @@ -1,226 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -#include -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_double - IMPLEMENTS = unpack_double;pack_double - IMPLEMENTS = unpack_float - IMPLEMENTS = init - IMPLEMENTS = value_count - MEMBERS = grib_arguments* arg - IMPLEMENTS = update_size - IMPLEMENTS = nearest_smaller_value - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_float(grib_accessor*, float* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); -static void update_size(grib_accessor*, size_t); -static int nearest_smaller_value (grib_accessor*, double, double*); - -typedef struct grib_accessor_ieeefloat -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in ieeefloat */ - grib_arguments* arg; -} grib_accessor_ieeefloat; - -extern grib_accessor_class* grib_accessor_class_double; - -static grib_accessor_class _grib_accessor_class_ieeefloat = { - &grib_accessor_class_double, /* super */ - "ieeefloat", /* name */ - sizeof(grib_accessor_ieeefloat), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - &unpack_float, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - &update_size, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - &nearest_smaller_value, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_ieeefloat = &_grib_accessor_class_ieeefloat; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - grib_accessor_ieeefloat* self = (grib_accessor_ieeefloat*)a; - long count = 0; - self->arg = arg; - grib_value_count(a, &count); - a->length = 4 * count; - Assert(a->length >= 0); -} - -static int value_count(grib_accessor* a, long* len) -{ - grib_accessor_ieeefloat* self = (grib_accessor_ieeefloat*)a; - *len = 0; - - if (!self->arg) { - *len = 1; - return 0; - } - return grib_get_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, self->arg, 0), len); -} - -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_ieeefloat* self = (grib_accessor_ieeefloat*)a; - int ret = 0; - unsigned long i = 0; - unsigned long rlen = (unsigned long)*len; - size_t buflen = 0; - unsigned char* buf = NULL; - long off = 0; - - if (*len < 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it packs at least 1 value", a->name); - *len = 0; - return GRIB_ARRAY_TOO_SMALL; - } - - if (rlen == 1) { - off = a->offset * 8; - ret = grib_encode_unsigned_long(grib_handle_of_accessor(a)->buffer->data, grib_ieee_to_long(val[0]), &off, 32); - if (*len > 1) - grib_context_log(a->context, GRIB_LOG_WARNING, "ieeefloat: Trying to pack %zu values in a scalar %s, packing first value", - *len, a->name); - if (ret == GRIB_SUCCESS) - len[0] = 1; - return ret; - } - - buflen = rlen * 4; - - buf = (unsigned char*)grib_context_malloc(a->context, buflen); - - for (i = 0; i < rlen; i++) { - grib_encode_unsigned_longb(buf, grib_ieee_to_long(val[i]), &off, 32); - } - ret = grib_set_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, self->arg, 0), rlen); - - if (ret == GRIB_SUCCESS) - grib_buffer_replace(a, buf, buflen, 1, 1); - else - *len = 0; - - grib_context_free(a->context, buf); - - return ret; -} - -template -static int unpack(grib_accessor* a, T* val, size_t* len) -{ - static_assert(std::is_floating_point::value, "Requires floating point numbers"); - long rlen = 0; - int err = 0; - long i = 0; - long bitp = a->offset * 8; - grib_handle* hand = grib_handle_of_accessor(a); - - err = grib_value_count(a, &rlen); - if (err) - return err; - - if (*len < (size_t)rlen) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size (%zu) for %s, it contains %ld values", *len, a->name, rlen); - *len = 0; - return GRIB_ARRAY_TOO_SMALL; - } - - for (i = 0; i < rlen; i++) - val[i] = (T)grib_long_to_ieee(grib_decode_unsigned_long(hand->buffer->data, &bitp, 32)); - - *len = rlen; - return GRIB_SUCCESS; -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - return unpack(a, val, len); -} - -static int unpack_float(grib_accessor* a, float* val, size_t* len) -{ - return unpack(a, val, len); -} - -static void update_size(grib_accessor* a, size_t s) -{ - a->length = (long)s; - Assert(a->length >= 0); -} - -static int nearest_smaller_value(grib_accessor* a, double val, double* nearest) -{ - return grib_nearest_smaller_ieee_float(val, nearest); -} diff --git a/src/grib_accessor_class_ifs_param.cc b/src/grib_accessor_class_ifs_param.cc deleted file mode 100644 index ba7e522c1..000000000 --- a/src/grib_accessor_class_ifs_param.cc +++ /dev/null @@ -1,188 +0,0 @@ -/* - * (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. - */ - -/************************************** - * Enrico Fucile - **************************************/ - - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = unpack_long; pack_long - IMPLEMENTS = init; get_native_type - MEMBERS=const char* paramId - MEMBERS=const char* type - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_ifs_param -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in ifs_param */ - const char* paramId; - const char* type; -} grib_accessor_ifs_param; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_ifs_param = { - &grib_accessor_class_gen, /* super */ - "ifs_param", /* name */ - sizeof(grib_accessor_ifs_param), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_ifs_param = &_grib_accessor_class_ifs_param; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_ifs_param* self = (grib_accessor_ifs_param*)a; - int n = 0; - - self->paramId = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->type = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_ifs_param* self = (grib_accessor_ifs_param*)a; - int ret = 0; - long paramId = 0; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->paramId, ¶mId)) != GRIB_SUCCESS) - return ret; - - if (paramId > 129000 && paramId < 129999) - *val = paramId - 129000; - else if (paramId > 200000 && paramId < 200999) - *val = paramId - 200000; - else if (paramId > 211000 && paramId < 211999) - *val = paramId - 1000; - else - *val = paramId; - - return ret; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - grib_accessor_ifs_param* self = (grib_accessor_ifs_param*)a; - long type = 0; - long table = 128; - long paramId = *val; - long param; - - grib_get_long(grib_handle_of_accessor(a), self->type, &type); - - if (type == 33 || type == 35) { - if (paramId > 1000) { - table = paramId / 1000; - param = paramId - table * 1000; - paramId = param; - } - switch (table) { - case 210: - paramId += 211000; - break; - case 128: - paramId += 200000; - break; - default: - break; - } - } - if (type == 50 || type == 52) { - if (paramId > 1000) { - table = paramId / 1000; - param = paramId - table * 1000; - paramId = param; - } - switch (table) { - case 128: - paramId += 129000; - break; - default: - break; - } - } - - return grib_set_long_internal(grib_handle_of_accessor(a), self->paramId, paramId); -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_LONG; -} diff --git a/src/grib_accessor_class_iterator.cc b/src/grib_accessor_class_iterator.cc deleted file mode 100644 index 2a5fc815b..000000000 --- a/src/grib_accessor_class_iterator.cc +++ /dev/null @@ -1,135 +0,0 @@ -/* - * (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. - */ - -/*************************** - * Enrico Fucile - *************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init;dump - MEMBERS=grib_arguments* args - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_iterator -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in iterator */ - grib_arguments* args; -} grib_accessor_iterator; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_iterator = { - &grib_accessor_class_gen, /* super */ - "iterator", /* name */ - sizeof(grib_accessor_iterator), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_iterator = &_grib_accessor_class_iterator; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* args) -{ - grib_accessor_iterator* self = (grib_accessor_iterator*)a; - self->args = args; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - /* TODO: pass args */ - grib_dump_label(dumper, a, NULL); -} - -grib_iterator* grib_iterator_new(const grib_handle* ch, unsigned long flags, int* error) -{ - grib_handle* h = (grib_handle*)ch; - grib_accessor* a = NULL; - grib_accessor_iterator* ita = NULL; - grib_iterator* iter = NULL; - *error = GRIB_NOT_IMPLEMENTED; - a = grib_find_accessor(h, "ITERATOR"); - ita = (grib_accessor_iterator*)a; - - if (!a) - return NULL; - - iter = grib_iterator_factory(h, ita->args, flags, error); - - if (iter) - *error = GRIB_SUCCESS; - - return iter; -} diff --git a/src/grib_accessor_class_julian_day.cc b/src/grib_accessor_class_julian_day.cc deleted file mode 100644 index 7a8e28cfc..000000000 --- a/src/grib_accessor_class_julian_day.cc +++ /dev/null @@ -1,209 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_double - IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = unpack_double;pack_double - IMPLEMENTS = dump - IMPLEMENTS = init - MEMBERS = const char *date - MEMBERS = const char *hour - MEMBERS = const char *minute - MEMBERS = const char *second - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_julian_day -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in julian_day */ - const char *date; - const char *hour; - const char *minute; - const char *second; -} grib_accessor_julian_day; - -extern grib_accessor_class* grib_accessor_class_double; - -static grib_accessor_class _grib_accessor_class_julian_day = { - &grib_accessor_class_double, /* super */ - "julian_day", /* name */ - sizeof(grib_accessor_julian_day), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_julian_day = &_grib_accessor_class_julian_day; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_julian_day* self = (grib_accessor_julian_day*)a; - int n = 0; - - self->date = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->hour = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->minute = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->second = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - - a->length = 0; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_string(dumper, a, NULL); -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - const double v = *val; - return pack_double(a, &v, len); -} - -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_julian_day* self = (grib_accessor_julian_day*)a; - int ret = 0; - long hour = 0; - long minute = 0; - long second = 0; - long date = 0; - long year, month, day; - - ret = grib_julian_to_datetime(*val, &year, &month, &day, &hour, &minute, &second); - if (ret != 0) - return ret; - - date = year * 10000 + month * 100 + day; - - ret = grib_set_long_internal(grib_handle_of_accessor(a), self->date, date); - if (ret != 0) - return ret; - ret = grib_set_long_internal(grib_handle_of_accessor(a), self->hour, hour); - if (ret != 0) - return ret; - ret = grib_set_long_internal(grib_handle_of_accessor(a), self->minute, minute); - if (ret != 0) - return ret; - ret = grib_set_long_internal(grib_handle_of_accessor(a), self->second, second); - - return ret; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - int ret = 0; - double v = 0; - - ret = unpack_double(a, &v, len); - *val = (long)v; - - return ret; -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - int ret = 0; - long date, hour, minute, second; - long year, month, day; - grib_accessor_julian_day* self = (grib_accessor_julian_day*)a; - - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->date, &date); - if (ret != GRIB_SUCCESS) - return ret; - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->hour, &hour); - if (ret != GRIB_SUCCESS) - return ret; - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->minute, &minute); - if (ret != GRIB_SUCCESS) - return ret; - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->second, &second); - if (ret != GRIB_SUCCESS) - return ret; - - year = date / 10000; - date %= 10000; - month = date / 100; - date %= 100; - day = date; - - ret = grib_datetime_to_julian(year, month, day, hour, minute, second, val); - - return ret; -} diff --git a/src/grib_accessor_class_ksec1expver.cc b/src/grib_accessor_class_ksec1expver.cc deleted file mode 100644 index 762bf66e2..000000000 --- a/src/grib_accessor_class_ksec1expver.cc +++ /dev/null @@ -1,185 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_ascii - IMPLEMENTS = unpack_long;pack_string; - IMPLEMENTS = pack_long - IMPLEMENTS = init - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int pack_string(grib_accessor*, const char*, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_ksec1expver -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in ascii */ - /* Members defined in ksec1expver */ -} grib_accessor_ksec1expver; - -extern grib_accessor_class* grib_accessor_class_ascii; - -static grib_accessor_class _grib_accessor_class_ksec1expver = { - &grib_accessor_class_ascii, /* super */ - "ksec1expver", /* name */ - sizeof(grib_accessor_ksec1expver), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - &pack_string, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_ksec1expver = &_grib_accessor_class_ksec1expver; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - a->length = len; - Assert(a->length >= 0); -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - long value = 0; - long pos = a->offset * 8; - char* intc = NULL; - char* pTemp = NULL; - char expver[5]; - char refexpver[5]; - size_t llen = a->length + 1; - Assert(a->length == 4); - - if (*len < 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name, 1); - *len = 0; - return GRIB_ARRAY_TOO_SMALL; - } - value = grib_decode_unsigned_long(grib_handle_of_accessor(a)->buffer->data, &pos, a->length * 8); - - grib_unpack_string(a, refexpver, &llen); - - /* test for endian */ - intc = (char*)&value; - pTemp = intc; - - expver[0] = *pTemp++; - expver[1] = *pTemp++; - expver[2] = *pTemp++; - expver[3] = *pTemp++; - expver[4] = 0; - -// expver[0] = intc[0]; -// expver[1] = intc[1]; -// expver[2] = intc[2]; -// expver[3] = intc[3]; -// expver[4] = 0; - - /* if there is a difference, have to reverse*/ - if (strcmp(refexpver, expver)) { - intc[0] = expver[3]; - intc[1] = expver[2]; - intc[2] = expver[1]; - intc[3] = expver[0]; - } - - *val = value; - *len = 1; - return GRIB_SUCCESS; -} - -static int pack_string(grib_accessor* a, const char* val, size_t* len) -{ - int i = 0; - if (len[0] != 4) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong length for %s. It has to be 4", a->name); - return GRIB_INVALID_KEY_VALUE; - } - if (len[0] > (a->length) + 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "pack_string: Wrong size (%lu) for %s, it contains %ld values", - len[0], a->name, a->length + 1); - len[0] = 0; - return GRIB_BUFFER_TOO_SMALL; - } - - for (i = 0; i < a->length; i++) - grib_handle_of_accessor(a)->buffer->data[a->offset + i] = val[i]; - - return GRIB_SUCCESS; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - char sval[5] = {0,}; - size_t slen = 4; - snprintf(sval, sizeof(sval), "%04d", (int)(*val)); - return pack_string(a, sval, &slen); -} diff --git a/src/grib_accessor_class_label.cc b/src/grib_accessor_class_label.cc deleted file mode 100644 index 8d7831faf..000000000 --- a/src/grib_accessor_class_label.cc +++ /dev/null @@ -1,125 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init;dump;get_native_type;unpack_string - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_string(grib_accessor*, char*, size_t* len); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_label -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in label */ -} grib_accessor_label; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_label = { - &grib_accessor_class_gen, /* super */ - "label", /* name */ - sizeof(grib_accessor_label), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_label = &_grib_accessor_class_label; - -/* END_CLASS_IMP */ - -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; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_label(dumper, a, NULL); -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_LABEL; -} - -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; -} diff --git a/src/grib_accessor_class_latlonvalues.cc b/src/grib_accessor_class_latlonvalues.cc deleted file mode 100644 index e559eaa3d..000000000 --- a/src/grib_accessor_class_latlonvalues.cc +++ /dev/null @@ -1,164 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_double - IMPLEMENTS = unpack_double; - IMPLEMENTS = value_count - IMPLEMENTS = init - MEMBERS =const char* values - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_latlonvalues -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in latlonvalues */ - const char* values; -} grib_accessor_latlonvalues; - -extern grib_accessor_class* grib_accessor_class_double; - -static grib_accessor_class _grib_accessor_class_latlonvalues = { - &grib_accessor_class_double, /* super */ - "latlonvalues", /* name */ - sizeof(grib_accessor_latlonvalues), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_latlonvalues = &_grib_accessor_class_latlonvalues; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_latlonvalues* self = (grib_accessor_latlonvalues*)a; - int n = 0; - - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_context* c = a->context; - int err = 0; - double* v = val; - double lat, lon, value; - size_t size = 0; - long count = 0; - grib_iterator* iter = grib_iterator_new(grib_handle_of_accessor(a), 0, &err); - if (err) { - if (iter) grib_iterator_delete(iter); - grib_context_log(c, GRIB_LOG_ERROR, "latlonvalues: Unable to create iterator"); - return err; - } - - err = value_count(a, &count); - if (err) return err; - size = count; - - if (*len < size) { - if (iter) grib_iterator_delete(iter); - return GRIB_ARRAY_TOO_SMALL; - } - - while (grib_iterator_next(iter, &lat, &lon, &value)) { - *(v++) = lat; - *(v++) = lon; - *(v++) = value; - } - - grib_iterator_delete(iter); - - *len = size; - - return GRIB_SUCCESS; -} - -static int value_count(grib_accessor* a, long* count) -{ - grib_accessor_latlonvalues* self = (grib_accessor_latlonvalues*)a; - grib_handle* h = grib_handle_of_accessor(a); - int ret = GRIB_SUCCESS; - size_t size; - if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) { - grib_context_log(h->context, GRIB_LOG_ERROR, "latlonvalues: Unable to get size of %s", self->values); - return ret; - } - - *count = 3 * size; - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_library_version.cc b/src/grib_accessor_class_library_version.cc deleted file mode 100644 index 2088b68c4..000000000 --- a/src/grib_accessor_class_library_version.cc +++ /dev/null @@ -1,130 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_ascii - IMPLEMENTS = unpack_string;value_count;string_length - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_string(grib_accessor*, char*, size_t* len); -static size_t string_length(grib_accessor*); -static int value_count(grib_accessor*, long*); - -typedef struct grib_accessor_library_version -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in ascii */ - /* Members defined in library_version */ -} grib_accessor_library_version; - -extern grib_accessor_class* grib_accessor_class_ascii; - -static grib_accessor_class _grib_accessor_class_library_version = { - &grib_accessor_class_ascii, /* super */ - "library_version", /* name */ - sizeof(grib_accessor_library_version), /* size */ - 0, /* inited */ - 0, /* init_class */ - 0, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - &string_length, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_library_version = &_grib_accessor_class_library_version; - -/* END_CLASS_IMP */ - -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - char result[30] = {0,}; - size_t size; - - int major = ECCODES_MAJOR_VERSION; - int minor = ECCODES_MINOR_VERSION; - int revision = ECCODES_REVISION_VERSION; - - snprintf(result, sizeof(result), "%d.%d.%d", major, minor, revision); - size = sizeof(result); - - if (*len < size) - return GRIB_ARRAY_TOO_SMALL; - strcpy(val, result); - - *len = size; - - return GRIB_SUCCESS; -} - -static int value_count(grib_accessor* a, long* count) -{ - *count = 1; - return 0; -} - -static size_t string_length(grib_accessor* a) -{ - return 255; -} diff --git a/src/grib_accessor_class_long.cc b/src/grib_accessor_class_long.cc deleted file mode 100644 index 5eb10fec5..000000000 --- a/src/grib_accessor_class_long.cc +++ /dev/null @@ -1,269 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = get_native_type;pack_missing; - IMPLEMENTS = unpack_string; pack_string - IMPLEMENTS = unpack_double - IMPLEMENTS = dump - IMPLEMENTS = compare - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_missing(grib_accessor*); -static int pack_string(grib_accessor*, const char*, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static void dump(grib_accessor*, grib_dumper*); -static int compare(grib_accessor*, grib_accessor*); - -typedef struct grib_accessor_long -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ -} grib_accessor_long; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_long = { - &grib_accessor_class_gen, /* super */ - "long", /* name */ - sizeof(grib_accessor_long), /* size */ - 0, /* inited */ - 0, /* init_class */ - 0, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - &pack_missing, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - &pack_string, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - &compare, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_long = &_grib_accessor_class_long; - -/* END_CLASS_IMP */ - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_LONG; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_long(dumper, a, NULL); -} - -static int unpack_string(grib_accessor* a, char* v, size_t* len) -{ - long val = 0; - size_t l = 1; - char repres[1024]; - char format[32] = "%ld"; - grib_handle* h = grib_handle_of_accessor(a); - - grib_unpack_long(a, &val, &l); - /* TODO: We should catch all errors but in this case the test ERA_Gen.sh will fail - * as the output from grib_ls will be different */ - - if ((val == GRIB_MISSING_LONG) && ((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0)) { - snprintf(repres, sizeof(repres), "MISSING"); - } else { - size_t size = sizeof(format); - grib_get_string(h, "formatForLongs", format, &size); - snprintf(repres, sizeof(repres), format, val); - } - - l = strlen(repres) + 1; - - if (*len < l) { - const char* cclass_name = a->cclass->name; - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, l, *len); - *len = l; - return GRIB_BUFFER_TOO_SMALL; - } - /*grib_context_log(a->context,GRIB_LOG_DEBUG, "grib_accessor_long: Casting long %s to string ", a->name);*/ - - *len = l; - - strcpy(v, repres); - return GRIB_SUCCESS; -} - -static int pack_missing(grib_accessor* a) -{ - size_t len = 1; - long value = GRIB_MISSING_LONG; - - if (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) - return grib_pack_long(a, &value, &len); - - return GRIB_VALUE_CANNOT_BE_MISSING; -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - size_t rlen = 0; - long count = 0; - unsigned long i = 0; - long* values = NULL; - long oneval = 0; - int ret = GRIB_SUCCESS; - - ret = grib_value_count(a, &count); - if (ret) - return ret; - rlen = count; - - if (*len < rlen) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %lu values", a->name, rlen); - *len = 0; - return GRIB_ARRAY_TOO_SMALL; - } - - if (rlen == 1) { - ret = grib_unpack_long(a, &oneval, &rlen); - if (ret != GRIB_SUCCESS) - return ret; - *val = oneval; - *len = 1; - return GRIB_SUCCESS; - } - - values = (long*)grib_context_malloc(a->context, rlen * sizeof(long)); - if (!values) - return GRIB_OUT_OF_MEMORY; - - ret = grib_unpack_long(a, values, &rlen); - if (ret != GRIB_SUCCESS) { - grib_context_free(a->context, values); - return ret; - } - for (i = 0; i < rlen; i++) - val[i] = values[i]; - - grib_context_free(a->context, values); - - *len = rlen; - return GRIB_SUCCESS; -} - -static int compare(grib_accessor* a, grib_accessor* b) -{ - int retval = 0; - long* aval = 0; - long* bval = 0; - long count = 0; - - size_t alen = 0; - size_t blen = 0; - int err = 0; - - err = grib_value_count(a, &count); - if (err) - return err; - alen = count; - - err = grib_value_count(b, &count); - if (err) - return err; - blen = count; - - if (alen != blen) - return GRIB_COUNT_MISMATCH; - - aval = (long*)grib_context_malloc(a->context, alen * sizeof(long)); - bval = (long*)grib_context_malloc(b->context, blen * sizeof(long)); - - grib_unpack_long(a, aval, &alen); - grib_unpack_long(b, bval, &blen); - - retval = GRIB_SUCCESS; - for (size_t i=0; icontext, aval); - grib_context_free(b->context, bval); - - return retval; -} - -static int pack_string(grib_accessor* a, const char* val, size_t* len) -{ - long v = 0; /* The converted value */ - - // ECC-1722 - if (STR_EQUAL_NOCASE(val, "missing")) { - return pack_missing(a); - } - - if (string_to_long(val, &v, 1) != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Trying to pack \"%s\" as long. String cannot be converted to an integer", val); - return GRIB_WRONG_TYPE; - } - return grib_pack_long(a, &v, len); -} diff --git a/src/grib_accessor_class_long_vector.cc b/src/grib_accessor_class_long_vector.cc deleted file mode 100644 index 612163a3e..000000000 --- a/src/grib_accessor_class_long_vector.cc +++ /dev/null @@ -1,208 +0,0 @@ -/* - * (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. - */ - -/************************************** - * Enrico Fucile - **************************************/ - - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_abstract_long_vector - IMPLEMENTS = init - IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = unpack_double;get_native_type - MEMBERS = const char* vector - MEMBERS = int index - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_long_vector -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in abstract_long_vector */ - long* v; - long pack_index; - int number_of_elements; - /* Members defined in long_vector */ - const char* vector; - int index; -} grib_accessor_long_vector; - -extern grib_accessor_class* grib_accessor_class_abstract_long_vector; - -static grib_accessor_class _grib_accessor_class_long_vector = { - &grib_accessor_class_abstract_long_vector, /* super */ - "long_vector", /* name */ - sizeof(grib_accessor_long_vector), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_long_vector = &_grib_accessor_class_long_vector; - -/* 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_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; - - 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; - - 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); - - a->length = 0; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - size_t size = 0; - int err = 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 */ - err = grib_get_size(grib_handle_of_accessor(a), self->vector, &size); - if (err) return err; - DEBUG_ASSERT(size > 0); - vector = (long*)grib_context_malloc(a->context, sizeof(long) * size); - err = grib_unpack_long(va, vector, &size); - grib_context_free(a->context, vector); - if (err) return err; - - *val = v->v[self->index]; - - return GRIB_SUCCESS; -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - long lval = 0; - int err = 0; - grib_accessor_long_vector* self = (grib_accessor_long_vector*)a; - grib_accessor* va = NULL; - grib_accessor_abstract_long_vector* v = NULL; - va = (grib_accessor*)grib_find_accessor(grib_handle_of_accessor(a), self->vector); - v = (grib_accessor_abstract_long_vector*)va; - - err = unpack_long(a, &lval, len); - - *val = (double)v->v[self->index]; - - return err; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - int err = 0; - grib_accessor_long_vector* self = (grib_accessor_long_vector*)a; - grib_accessor* va = NULL; - grib_accessor_abstract_long_vector* v = NULL; - - va = (grib_accessor*)grib_find_accessor(grib_handle_of_accessor(a), self->vector); - v = (grib_accessor_abstract_long_vector*)va; - - 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_lookup.cc b/src/grib_accessor_class_lookup.cc deleted file mode 100644 index 5fc2880a8..000000000 --- a/src/grib_accessor_class_lookup.cc +++ /dev/null @@ -1,242 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -#include -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long; unpack_string - IMPLEMENTS = init;post_init;dump - IMPLEMENTS = byte_offset;byte_count - IMPLEMENTS = pack_long - IMPLEMENTS = notify_change - MEMBERS = long llength - MEMBERS = long loffset - MEMBERS = grib_expression* real_name - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static long byte_count(grib_accessor*); -static long byte_offset(grib_accessor*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); -static void post_init(grib_accessor*); -static int notify_change(grib_accessor*, grib_accessor*); - -typedef struct grib_accessor_lookup -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in lookup */ - long llength; - long loffset; - grib_expression* real_name; -} grib_accessor_lookup; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_lookup = { - &grib_accessor_class_long, /* super */ - "lookup", /* name */ - sizeof(grib_accessor_lookup), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - &post_init, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - &byte_count, /* get number of bytes */ - &byte_offset, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - ¬ify_change, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_lookup = &_grib_accessor_class_lookup; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - grib_accessor_lookup* self = (grib_accessor_lookup*)a; - a->length = 0; - self->llength = len; - self->loffset = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 0); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - self->real_name = grib_arguments_get_expression(grib_handle_of_accessor(a), arg, 1); -} - -static void post_init(grib_accessor* a) -{ - grib_accessor_lookup* self = (grib_accessor_lookup*)a; - if (self->real_name) { - grib_dependency_observe_expression(a, self->real_name); - } -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_accessor_lookup* self = (grib_accessor_lookup*)a; - unsigned char bytes[1024] = {0,}; - char msg[1024] = {0,}; - char buf[2048]; - int i; - unsigned long v = 0; - - size_t llen = self->llength; - grib_unpack_bytes(a, bytes, &llen); /* TODO: Unpack byte unpack the wrong offset */ - - bytes[llen] = 0; - for (i = 0; i < llen; i++) { - msg[i] = isprint(bytes[i]) ? bytes[i] : '?'; - v <<= 8; - v |= bytes[i]; - } - - msg[llen] = 0; - - snprintf(buf, sizeof(buf), "%s %lu %ld-%ld", msg, v, (long)a->offset + self->loffset, (long)self->llength); - - grib_dump_long(dumper, a, buf); -} - -static int unpack_string(grib_accessor* a, char* v, size_t* len) -{ - grib_accessor_lookup* self = (grib_accessor_lookup*)a; - unsigned char bytes[1024] = {0,}; - int i; - - size_t llen = self->llength; - grib_unpack_bytes(a, bytes, &llen); /* TODO: Unpack byte unpack the wrong offset */ - - bytes[llen] = 0; - - for (i = 0; i < llen; i++) { - v[i] = isprint(bytes[i]) ? bytes[i] : '?'; - } - - v[llen] = 0; - if (llen == 1 && v[0] == '?') { - /* Try unpack as long */ - size_t length = 10; - long lval = 0; - int err = unpack_long(a, &lval, &length); - if (!err) { - char str[5]; - int conv = snprintf(str, sizeof(str), "%ld", lval); - if (conv == 1) { - v[0] = str[0]; - } - } - } - - return GRIB_SUCCESS; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_lookup* self = (grib_accessor_lookup*)a; - grib_handle* h = grib_handle_of_accessor(a); - - long pos = (a->offset + self->loffset) * 8; - - if (len[0] < 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name, 1); - len[0] = 0; - return GRIB_ARRAY_TOO_SMALL; - } - - /* This is used when reparsing or rebuilding */ - if (h->loader) { - Assert(*len == 1); - return h->loader->lookup_long(h->context, h->loader, a->name, val); - } - - val[0] = grib_decode_unsigned_long(h->buffer->data, &pos, self->llength * 8); - len[0] = 1; - - /*printf("###########lookup unpack_long: %s %ld %ld\n",a->name, pos/8, val[0]);*/ - - return GRIB_SUCCESS; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - return GRIB_NOT_IMPLEMENTED; -} - -static long byte_count(grib_accessor* a) -{ - grib_accessor_lookup* self = (grib_accessor_lookup*)a; - return self->llength; -} - -static long byte_offset(grib_accessor* a) -{ - grib_accessor_lookup* self = (grib_accessor_lookup*)a; - return self->loffset; -} - -static int notify_change(grib_accessor* self, grib_accessor* changed) -{ - /* Forward changes */ - return grib_dependency_notify_change(self); -} diff --git a/src/grib_accessor_class_mars_param.cc b/src/grib_accessor_class_mars_param.cc deleted file mode 100644 index beb7a68c5..000000000 --- a/src/grib_accessor_class_mars_param.cc +++ /dev/null @@ -1,144 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_ascii - IMPLEMENTS = unpack_string - IMPLEMENTS = init; string_length - MEMBERS= const char* paramId - MEMBERS= const char* table - MEMBERS= const char* param - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_string(grib_accessor*, char*, size_t* len); -static size_t string_length(grib_accessor*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_mars_param -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in ascii */ - /* Members defined in mars_param */ - const char* paramId; - const char* table; - const char* param; -} grib_accessor_mars_param; - -extern grib_accessor_class* grib_accessor_class_ascii; - -static grib_accessor_class _grib_accessor_class_mars_param = { - &grib_accessor_class_ascii, /* super */ - "mars_param", /* name */ - sizeof(grib_accessor_mars_param), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - &string_length, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_mars_param = &_grib_accessor_class_mars_param; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - int n = 0; - grib_accessor_mars_param* self = (grib_accessor_mars_param*)a; - self->paramId = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->table = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->param = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); -} - -// For an implementation of pack_string, see -// src/deprecated/grib_accessor_class_mars_param.cc - -// For an alternative implementation of unpack_string, see -// src/deprecated/grib_accessor_class_mars_param.cc -// -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - grib_accessor_mars_param* self = (grib_accessor_mars_param*)a; - long param = 0; - long table = 0; - int ret = 0; - - if (self->table != NULL && (ret = grib_get_long_internal(grib_handle_of_accessor(a), self->table, &table)) != GRIB_SUCCESS) - return ret; - if (self->param != NULL && (ret = grib_get_long_internal(grib_handle_of_accessor(a), self->param, ¶m)) != GRIB_SUCCESS) - return ret; - - /*if (table==200) table=128;*/ - snprintf(val, 32, "%ld.%ld", param, table); - *len = strlen(val) + 1; - - return GRIB_SUCCESS; -} - -static size_t string_length(grib_accessor* a) -{ - return 7; -} diff --git a/src/grib_accessor_class_mars_step.cc b/src/grib_accessor_class_mars_step.cc deleted file mode 100644 index 7792995a7..000000000 --- a/src/grib_accessor_class_mars_step.cc +++ /dev/null @@ -1,218 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_ascii - IMPLEMENTS = pack_string;unpack_string;value_count;string_length - IMPLEMENTS = pack_long; unpack_long - IMPLEMENTS = get_native_type - IMPLEMENTS = init - MEMBERS = const char* stepRange - MEMBERS = const char* stepType - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int pack_string(grib_accessor*, const char*, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static size_t string_length(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_mars_step -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in ascii */ - /* Members defined in mars_step */ - const char* stepRange; - const char* stepType; -} grib_accessor_mars_step; - -extern grib_accessor_class* grib_accessor_class_ascii; - -static grib_accessor_class _grib_accessor_class_mars_step = { - &grib_accessor_class_ascii, /* super */ - "mars_step", /* name */ - sizeof(grib_accessor_mars_step), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - &string_length, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - &pack_string, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_mars_step = &_grib_accessor_class_mars_step; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - int n = 0; - grib_accessor_mars_step* self = (grib_accessor_mars_step*)a; - self->stepRange = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->stepType = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); -} - -static int pack_string(grib_accessor* a, const char* val, size_t* len) -{ - char stepType[100]; - size_t stepTypeLen = 100; - char buf[100] = {0,}; - int ret; - grib_accessor_mars_step* self = (grib_accessor_mars_step*)a; - grib_accessor* stepRangeAcc = grib_find_accessor(grib_handle_of_accessor(a), self->stepRange); - - if (!stepRangeAcc) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s not found", self->stepRange); - return GRIB_NOT_FOUND; - } - - if ((ret = grib_get_string(grib_handle_of_accessor(a), self->stepType, stepType, &stepTypeLen)) != GRIB_SUCCESS) - return ret; - - if (!strcmp(stepType, "instant")) - snprintf(buf, sizeof(buf), "%s", val); - else - snprintf(buf, sizeof(buf), "0-%s", val); - - return grib_pack_string(stepRangeAcc, buf, len); -} - -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - int ret = 0; - grib_accessor_mars_step* self = (grib_accessor_mars_step*)a; - char buf[100] = {0,}; - char* p = NULL; - size_t buflen = 100; - long step; - grib_accessor* stepRangeAcc = grib_find_accessor(grib_handle_of_accessor(a), self->stepRange); - const char* cclass_name = a->cclass->name; - - if (!stepRangeAcc) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s: %s not found", cclass_name, self->stepRange); - return GRIB_NOT_FOUND; - } - - if ((ret = grib_unpack_string(stepRangeAcc, buf, &buflen)) != GRIB_SUCCESS) - return ret; - - if (*len < buflen) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, buflen, *len); - *len = buflen; - return GRIB_BUFFER_TOO_SMALL; - } - - strcpy(val, buf); - step = strtol(buf, &p, 10); - - if (p != NULL && *p == '-' && step == 0) - strcpy(val, ++p); - - *len = strlen(val); - - return ret; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - char buff[100] = {0,}; - size_t bufflen = 100; - - snprintf(buff, sizeof(buff), "%ld", *val); - - return pack_string(a, buff, &bufflen); -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_mars_step* self = (grib_accessor_mars_step*)a; - grib_accessor* stepRangeAcc = grib_find_accessor(grib_handle_of_accessor(a), self->stepRange); - - if (!stepRangeAcc) - return GRIB_NOT_FOUND; - - return grib_unpack_long(stepRangeAcc, val, len); -} - -static int value_count(grib_accessor* a, long* count) -{ - *count = 1; - return 0; -} - -static size_t string_length(grib_accessor* a) -{ - return 16; -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_LONG; -} diff --git a/src/grib_accessor_class_message.cc b/src/grib_accessor_class_message.cc deleted file mode 100644 index 6c5587b22..000000000 --- a/src/grib_accessor_class_message.cc +++ /dev/null @@ -1,166 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_bytes - IMPLEMENTS = init;update_size;resize; value_count - IMPLEMENTS = unpack_string; string_length - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_string(grib_accessor*, char*, size_t* len); -static size_t string_length(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); -static void update_size(grib_accessor*, size_t); -static void resize(grib_accessor*,size_t); - -typedef struct grib_accessor_message -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in bytes */ - /* Members defined in message */ -} grib_accessor_message; - -extern grib_accessor_class* grib_accessor_class_bytes; - -static grib_accessor_class _grib_accessor_class_message = { - &grib_accessor_class_bytes, /* super */ - "message", /* name */ - sizeof(grib_accessor_message), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - &string_length, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - &update_size, /* update_size */ - 0, /* preferred_size */ - &resize, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_message = &_grib_accessor_class_message; - -/* 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->length = grib_handle_of_accessor(a)->buffer->ulength - len - a->offset; -} - -// 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) -{ - a->length = new_size; -} - -static void resize(grib_accessor* a, size_t new_size) -{ - grib_context_log(a->context, GRIB_LOG_FATAL, "%s %s: Not supported", a->cclass->name, __func__); - - // 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 %ld %ld %s %s", - // (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) -{ - long i = 0; - size_t l = string_length(a) + 1; - grib_handle* h = grib_handle_of_accessor(a); - - if (*len < l) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - a->cclass->name, a->name, l, *len); - *len = l; - return GRIB_BUFFER_TOO_SMALL; - } - - for (i = 0; i < a->length; i++) - val[i] = h->buffer->data[a->offset + i]; - val[i] = 0; - *len = i; - return GRIB_SUCCESS; -} - -static size_t string_length(grib_accessor* a) -{ - return a->length; -} diff --git a/src/grib_accessor_class_message_copy.cc b/src/grib_accessor_class_message_copy.cc deleted file mode 100644 index 30806b163..000000000 --- a/src/grib_accessor_class_message_copy.cc +++ /dev/null @@ -1,151 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = unpack_string;string_length - IMPLEMENTS = byte_count - IMPLEMENTS = init;dump;get_native_type - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_string(grib_accessor*, char*, size_t* len); -static size_t string_length(grib_accessor*); -static long byte_count(grib_accessor*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_message_copy -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in message_copy */ -} grib_accessor_message_copy; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_message_copy = { - &grib_accessor_class_gen, /* super */ - "message_copy", /* name */ - sizeof(grib_accessor_message_copy), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - &string_length, /* get length of string */ - 0, /* get number of values */ - &byte_count, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_message_copy = &_grib_accessor_class_message_copy; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long length, grib_arguments* args) -{ - 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); -} - -static int get_native_type(grib_accessor* a) -{ - 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; - - if (*len < slen) { - return GRIB_ARRAY_TOO_SMALL; - } - v = grib_handle_of_accessor(a)->buffer->data; - /* replace unprintable characters with space */ - for (i = 0; i < slen; i++) - if (v[i] > 126) - v[i] = 32; - memcpy(val, grib_handle_of_accessor(a)->buffer->data, slen); - val[i] = 0; - - *len = slen; - - return GRIB_SUCCESS; -} - -static size_t string_length(grib_accessor* a) -{ - return grib_handle_of_accessor(a)->buffer->ulength; -} - -static long byte_count(grib_accessor* a) -{ - return a->length; -} diff --git a/src/grib_accessor_class_multdouble.cc b/src/grib_accessor_class_multdouble.cc deleted file mode 100644 index ac5771627..000000000 --- a/src/grib_accessor_class_multdouble.cc +++ /dev/null @@ -1,127 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_double - IMPLEMENTS = unpack_double - IMPLEMENTS = init - MEMBERS = const char* val - MEMBERS = double multiplier - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_double(grib_accessor*, double* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_multdouble -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in multdouble */ - const char* val; - double multiplier; -} grib_accessor_multdouble; - -extern grib_accessor_class* grib_accessor_class_double; - -static grib_accessor_class _grib_accessor_class_multdouble = { - &grib_accessor_class_double, /* super */ - "multdouble", /* name */ - sizeof(grib_accessor_multdouble), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_multdouble = &_grib_accessor_class_multdouble; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_multdouble* self = (grib_accessor_multdouble*)a; - int n = 0; - - self->val = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->multiplier = grib_arguments_get_double(grib_handle_of_accessor(a), c, n++); -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - const grib_accessor_multdouble* self = (grib_accessor_multdouble*)a; - int ret = GRIB_SUCCESS; - double value = 0; - - ret = grib_get_double_internal(grib_handle_of_accessor(a), self->val, &value); - if (ret != GRIB_SUCCESS) - return ret; - - *val = value * self->multiplier; - - *len = 1; - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_nearest.cc b/src/grib_accessor_class_nearest.cc deleted file mode 100644 index b1a3138d3..000000000 --- a/src/grib_accessor_class_nearest.cc +++ /dev/null @@ -1,131 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init;dump - MEMBERS=grib_arguments* args - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_nearest -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in nearest */ - grib_arguments* args; -} grib_accessor_nearest; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_nearest = { - &grib_accessor_class_gen, /* super */ - "nearest", /* name */ - sizeof(grib_accessor_nearest), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_nearest = &_grib_accessor_class_nearest; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* 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); -} - -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; - - if (!a) - return NULL; - - n = grib_nearest_factory(h, na->args, error); - - if (n) - *error = GRIB_SUCCESS; - - return n; -} diff --git a/src/grib_accessor_class_non_alpha.cc b/src/grib_accessor_class_non_alpha.cc deleted file mode 100644 index 821f2311f..000000000 --- a/src/grib_accessor_class_non_alpha.cc +++ /dev/null @@ -1,215 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = unpack_string - IMPLEMENTS = unpack_long - IMPLEMENTS = unpack_double - IMPLEMENTS = init;dump;string_length - IMPLEMENTS = value_count - IMPLEMENTS = next_offset - IMPLEMENTS = get_native_type - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static size_t string_length(grib_accessor*); -static long next_offset(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_non_alpha -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in non_alpha */ -} grib_accessor_non_alpha; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_non_alpha = { - &grib_accessor_class_gen, /* super */ - "non_alpha", /* name */ - sizeof(grib_accessor_non_alpha), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - &next_offset, /* next_offset */ - &string_length, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_non_alpha = &_grib_accessor_class_non_alpha; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - grib_buffer* buffer = grib_handle_of_accessor(a)->buffer; - size_t i = 0; - unsigned char* v; - - v = buffer->data + a->offset; - i = 0; - while ((*v < 33 || *v > 126) && i <= buffer->ulength) { - v++; - i++; - } - a->length = i; - - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; -} - -static int value_count(grib_accessor* a, long* count) -{ - *count = 1; - return 0; -} - -static size_t string_length(grib_accessor* a) -{ - return a->length; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_string(dumper, a, NULL); -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_STRING; -} - -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - grib_handle* hand = grib_handle_of_accessor(a); - long i = 0; - - if (*len < (a->length + 1)) { - grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%lu) for %s, it contains %ld values", - *len, a->name, a->length + 1); - *len = a->length + 1; - return GRIB_BUFFER_TOO_SMALL; - } - - for (i = 0; i < a->length; i++) { - val[i] = hand->buffer->data[a->offset + i]; - } - val[i] = 0; - *len = i; - return GRIB_SUCCESS; -} - -static int unpack_long(grib_accessor* a, long* v, size_t* len) -{ - char val[1024] = {0,}; - size_t l = sizeof(val); - size_t i = 0; - char* last = NULL; - int err = grib_unpack_string(a, val, &l); - - if (err) - return err; - - i = 0; - while (i < l - 1 && val[i] == ' ') - i++; - - if (val[i] == 0) { - *v = 0; - return 0; - } - if (val[i + 1] == ' ' && i < l - 2) - val[i + 1] = 0; - - *v = strtol(val, &last, 10); - - return GRIB_SUCCESS; -} - -static int unpack_double(grib_accessor* a, double* v, size_t* len) -{ - char val[1024]; - size_t l = sizeof(val); - char* last = NULL; - grib_unpack_string(a, val, &l); - - *v = strtod(val, &last); - - if (*last == 0) { - return GRIB_SUCCESS; - } - - return GRIB_NOT_IMPLEMENTED; -} - -static long next_offset(grib_accessor* a) -{ - return a->offset + a->length; -} diff --git a/src/grib_accessor_class_number_of_coded_values.cc b/src/grib_accessor_class_number_of_coded_values.cc deleted file mode 100644 index 14ef832d7..000000000 --- a/src/grib_accessor_class_number_of_coded_values.cc +++ /dev/null @@ -1,162 +0,0 @@ -/* - * (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. - */ - -/***************************** - * Enrico Fucile - ****************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long - IMPLEMENTS = init - MEMBERS = const char* numberOfValues - MEMBERS = const char* bitsPerValue - MEMBERS = const char* offsetBeforeData - MEMBERS = const char* offsetAfterData - MEMBERS = const char* unusedBits - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_number_of_coded_values -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in number_of_coded_values */ - const char* numberOfValues; - const char* bitsPerValue; - const char* offsetBeforeData; - const char* offsetAfterData; - const char* unusedBits; -} grib_accessor_number_of_coded_values; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_number_of_coded_values = { - &grib_accessor_class_long, /* super */ - "number_of_coded_values", /* name */ - sizeof(grib_accessor_number_of_coded_values), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_number_of_coded_values = &_grib_accessor_class_number_of_coded_values; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - int n = 0; - grib_accessor_number_of_coded_values* self = (grib_accessor_number_of_coded_values*)a; - self->bitsPerValue = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->offsetBeforeData = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->offsetAfterData = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->unusedBits = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->numberOfValues = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - 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) -{ - int ret = GRIB_SUCCESS; - long bpv = 0; - long offsetBeforeData = 0, offsetAfterData = 0, unusedBits = 0, numberOfValues; - - grib_accessor_number_of_coded_values* self = (grib_accessor_number_of_coded_values*)a; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bitsPerValue, &bpv)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetBeforeData, &offsetBeforeData)) != GRIB_SUCCESS) - return ret; - - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetAfterData, &offsetAfterData)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->unusedBits, &unusedBits)) != GRIB_SUCCESS) - return ret; - - if (bpv != 0) { - grib_context_log(a->context, GRIB_LOG_DEBUG, "grib_accessor_number_of_coded_values: offsetAfterData=%ld offsetBeforeData=%ld unusedBits=%ld bpv=%ld\n", - offsetAfterData, offsetBeforeData, unusedBits, bpv); - DEBUG_ASSERT(offsetAfterData > offsetBeforeData); - *val = ((offsetAfterData - offsetBeforeData) * 8 - unusedBits) / bpv; - } - else { - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfValues, &numberOfValues)) != GRIB_SUCCESS) - return ret; - - *val = numberOfValues; - } - - return ret; -} diff --git a/src/grib_accessor_class_number_of_points.cc b/src/grib_accessor_class_number_of_points.cc deleted file mode 100644 index b3d1eade2..000000000 --- a/src/grib_accessor_class_number_of_points.cc +++ /dev/null @@ -1,174 +0,0 @@ -/* - * (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. - */ - -/**************************************** - * Enrico Fucile - *************************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long - IMPLEMENTS = init - MEMBERS = const char* ni - MEMBERS = const char* nj - MEMBERS = const char* plpresent - MEMBERS = const char* pl - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_number_of_points -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in number_of_points */ - const char* ni; - const char* nj; - const char* plpresent; - const char* pl; -} grib_accessor_number_of_points; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_number_of_points = { - &grib_accessor_class_long, /* super */ - "number_of_points", /* name */ - sizeof(grib_accessor_number_of_points), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_number_of_points = &_grib_accessor_class_number_of_points; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - int n = 0; - grib_handle* hand = grib_handle_of_accessor(a); - - grib_accessor_number_of_points* self = (grib_accessor_number_of_points*)a; - self->ni = grib_arguments_get_name(hand, c, n++); - self->nj = grib_arguments_get_name(hand, c, n++); - self->plpresent = grib_arguments_get_name(hand, c, n++); - self->pl = grib_arguments_get_name(hand, c, n++); - 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) -{ - grib_accessor_number_of_points* self = (grib_accessor_number_of_points*)a; - - int ret = GRIB_SUCCESS; - long ni = 0, nj = 0, plpresent = 0; - size_t plsize = 0; - long* pl = NULL; - int i = 0; - grib_context* c = a->context; - grib_handle* hand = grib_handle_of_accessor(a); - - if ((ret = grib_get_long_internal(hand, self->ni, &ni)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_get_long_internal(hand, self->nj, &nj)) != GRIB_SUCCESS) - return ret; - - if (self->plpresent && - ((ret = grib_get_long_internal(hand, self->plpresent, &plpresent)) != GRIB_SUCCESS)) - return ret; - - if (grib_is_missing(hand, self->nj, &ret) && ret == GRIB_SUCCESS) { - grib_context_log(c, GRIB_LOG_ERROR, "grib_accessor_class_number_of_points: Key %s cannot be 'missing'!", self->nj); - return GRIB_GEOCALCULUS_PROBLEM; - } - - if (nj == 0) { - grib_context_log(c, GRIB_LOG_ERROR, "grib_accessor_class_number_of_points: Key %s cannot be 0!", self->nj); - return GRIB_GEOCALCULUS_PROBLEM; - } - - if (plpresent) { - /*reduced*/ - plsize = nj; - pl = (long*)grib_context_malloc(c, sizeof(long) * plsize); - grib_get_long_array_internal(hand, self->pl, pl, &plsize); - *val = 0; - for (i = 0; i < plsize; i++) - *val += pl[i]; - grib_context_free(c, pl); - } - else { - /*regular*/ - *val = ni * nj; - } - - return ret; -} diff --git a/src/grib_accessor_class_number_of_values.cc b/src/grib_accessor_class_number_of_values.cc deleted file mode 100644 index fb1aff779..000000000 --- a/src/grib_accessor_class_number_of_values.cc +++ /dev/null @@ -1,165 +0,0 @@ -/* - * (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. - */ - -/********************************** - * Enrico Fucile - **********************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long - IMPLEMENTS = init - MEMBERS = const char* values - MEMBERS = const char* bitsPerValue - MEMBERS = const char* numberOfPoints - MEMBERS = const char* bitmapPresent - MEMBERS = const char* bitmap - MEMBERS = const char* numberOfCodedValues - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_number_of_values -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in number_of_values */ - const char* values; - const char* bitsPerValue; - const char* numberOfPoints; - const char* bitmapPresent; - const char* bitmap; - const char* numberOfCodedValues; -} grib_accessor_number_of_values; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_number_of_values = { - &grib_accessor_class_long, /* super */ - "number_of_values", /* name */ - sizeof(grib_accessor_number_of_values), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_number_of_values = &_grib_accessor_class_number_of_values; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - int n = 0; - grib_accessor_number_of_values* self = (grib_accessor_number_of_values*)a; - grib_handle* hand = grib_handle_of_accessor(a); - - self->values = grib_arguments_get_name(hand, c, n++); - self->bitsPerValue = grib_arguments_get_name(hand, c, n++); - self->numberOfPoints = grib_arguments_get_name(hand, c, n++); - self->bitmapPresent = grib_arguments_get_name(hand, c, n++); - self->bitmap = grib_arguments_get_name(hand, c, n++); - self->numberOfCodedValues = grib_arguments_get_name(hand, c, n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - - a->length = 0; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_number_of_values* self = (grib_accessor_number_of_values*)a; - int ret = GRIB_SUCCESS, i; - long npoints = 0, bitmap_present = 0; - size_t size = 0; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints, &npoints)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bitmapPresent, &bitmap_present)) != GRIB_SUCCESS) - return ret; - - if (bitmap_present) { - double* bitmap; - size = npoints; - bitmap = (double*)grib_context_malloc(a->context, sizeof(double) * size); - if ((ret = grib_get_double_array_internal(grib_handle_of_accessor(a), self->bitmap, bitmap, &size)) != GRIB_SUCCESS) { - grib_context_free(a->context, bitmap); - return ret; - } - *val = 0; - for (i = 0; i < size; i++) - if (bitmap[i] != 0) - (*val)++; - - grib_context_free(a->context, bitmap); - } - else { - *val = npoints; - } - - return ret; -} diff --git a/src/grib_accessor_class_number_of_values_data_raw_packing.cc b/src/grib_accessor_class_number_of_values_data_raw_packing.cc deleted file mode 100644 index 5652797ac..000000000 --- a/src/grib_accessor_class_number_of_values_data_raw_packing.cc +++ /dev/null @@ -1,165 +0,0 @@ -/* - * (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. - */ -/***************************** - * Enrico Fucile - ****************************/ - -#include "grib_api_internal.h" -#define PRECISION_32_IEEE 1 -#define PRECISION_64_IEEE 2 -#define PRECISION_128_IEEE 3 - -#define COMPRESSION_NONE 0 -#define COMPRESSION_LZW 1 - -#define PRE_PROCESSING_NONE 0 -#define PRE_PROCESSING_DIFFERENCE 1 -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init - IMPLEMENTS = unpack_long - IMPLEMENTS = get_native_type - MEMBERS=const char* values - MEMBERS=const char* precision - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_number_of_values_data_raw_packing -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in number_of_values_data_raw_packing */ - const char* values; - const char* precision; -} grib_accessor_number_of_values_data_raw_packing; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_number_of_values_data_raw_packing = { - &grib_accessor_class_gen, /* super */ - "number_of_values_data_raw_packing", /* name */ - sizeof(grib_accessor_number_of_values_data_raw_packing), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_number_of_values_data_raw_packing = &_grib_accessor_class_number_of_values_data_raw_packing; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long v, grib_arguments* args) -{ - int n = 0; - grib_accessor_number_of_values_data_raw_packing* self = (grib_accessor_number_of_values_data_raw_packing*)a; - - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->precision = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length = 0; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - int err = 0; - grib_accessor_number_of_values_data_raw_packing* self = (grib_accessor_number_of_values_data_raw_packing*)a; - grib_accessor* adata = NULL; - long precision = 0; - int bytes = 0; - long byte_count = 0; - - adata = grib_find_accessor(grib_handle_of_accessor(a), self->values); - Assert(adata != NULL); - byte_count = grib_byte_count(adata); - - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->precision, &precision)) != GRIB_SUCCESS) - return err; - - switch (precision) { - case 1: - bytes = 4; - break; - - case 2: - bytes = 8; - break; - - default: - return GRIB_NOT_IMPLEMENTED; - } - - *val = byte_count / bytes; - - return err; -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_LONG; -} diff --git a/src/grib_accessor_class_octahedral_gaussian.cc b/src/grib_accessor_class_octahedral_gaussian.cc deleted file mode 100644 index 8035c9ab0..000000000 --- a/src/grib_accessor_class_octahedral_gaussian.cc +++ /dev/null @@ -1,216 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long - IMPLEMENTS = init - IMPLEMENTS = pack_long - MEMBERS=const char* N - MEMBERS=const char* Ni - MEMBERS=const char* plpresent - MEMBERS=const char* pl - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_octahedral_gaussian -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in octahedral_gaussian */ - const char* N; - const char* Ni; - const char* plpresent; - const char* pl; -} grib_accessor_octahedral_gaussian; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_octahedral_gaussian = { - &grib_accessor_class_long, /* super */ - "octahedral_gaussian", /* name */ - sizeof(grib_accessor_octahedral_gaussian), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_octahedral_gaussian = &_grib_accessor_class_octahedral_gaussian; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_octahedral_gaussian* self = (grib_accessor_octahedral_gaussian*)a; - int n = 0; - grib_handle* hand = grib_handle_of_accessor(a); - - self->N = grib_arguments_get_name(hand, c, n++); - self->Ni = grib_arguments_get_name(hand, c, n++); - self->plpresent = grib_arguments_get_name(hand, c, n++); - self->pl = grib_arguments_get_name(hand, c, n++); -} - -/* Returns 1 (=true) if input pl array is Octahedral, 0 otherwise. - * Possible cases for the deltas in an octahedral pl array: - * +4 .. +4 Top part, above equator - * +4 .. 0 Top part, above and including equator - * +4.. 0 -4.. Middle part, above, equator and below - * 0 -4.. Equator and below - * -4 ..-4 All below equator - * Anything else is considered not octahedral - */ -static int is_pl_octahedral(const long pl[], size_t size) -{ - long i; - long prev_diff = -1; - for (i = 1; i < size; ++i) { - const long diff = pl[i] - pl[i - 1]; - if (diff == 0) { - /* prev must be +4 or undef */ - if (!(prev_diff == +4 || i == 1)) { - return 0; - } - } - else { - if (labs(diff) != 4) { - return 0; - } - if (diff == +4) { - /* prev must be +4 or undef */ - if (!(prev_diff == +4 || i == 1)) { - return 0; - } - } - if (diff == -4) { - /* prev must be 0, -4 or undef */ - if (!(prev_diff == -4 || prev_diff == 0 || i == 1)) { - return 0; - } - } - } - prev_diff = diff; - } - return 1; /* it's octahedral */ -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_octahedral_gaussian* self = (grib_accessor_octahedral_gaussian*)a; - int ret = GRIB_SUCCESS; - long Ni; - long plpresent = 0; - long* pl = NULL; /* pl array */ - size_t plsize = 0; - grib_handle* hand = grib_handle_of_accessor(a); - - grib_context* c = a->context; - - if ((ret = grib_get_long_internal(hand, self->Ni, &Ni)) != GRIB_SUCCESS) - return ret; - - /* If Ni is not missing, then this is a plain gaussian grid and not reduced. */ - /* So it cannot be an octahedral grid */ - if (Ni != GRIB_MISSING_LONG) { - *val = 0; - return GRIB_SUCCESS; - } - - if ((ret = grib_get_long_internal(hand, self->plpresent, &plpresent)) != GRIB_SUCCESS) - return ret; - if (!plpresent) { - *val = 0; /* Not octahedral */ - return GRIB_SUCCESS; - } - - if ((ret = grib_get_size(hand, self->pl, &plsize)) != GRIB_SUCCESS) - return ret; - Assert(plsize); /* pl array must have at least one element */ - - pl = (long*)grib_context_malloc_clear(c, sizeof(long) * plsize); - if (!pl) { - return GRIB_OUT_OF_MEMORY; - } - if ((ret = grib_get_long_array_internal(hand, self->pl, pl, &plsize)) != GRIB_SUCCESS) - return ret; - - /* pl[0] is guaranteed to exist. Have already asserted previously */ - *val = is_pl_octahedral(pl, plsize); - grib_context_free(c, pl); - - return ret; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - return GRIB_NOT_IMPLEMENTED; -} diff --git a/src/grib_accessor_class_octet_number.cc b/src/grib_accessor_class_octet_number.cc deleted file mode 100644 index cce0e742b..000000000 --- a/src/grib_accessor_class_octet_number.cc +++ /dev/null @@ -1,136 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = init - MEMBERS=const char* left - MEMBERS=long right - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_octet_number -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in octet_number */ - const char* left; - long right; -} grib_accessor_octet_number; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_octet_number = { - &grib_accessor_class_long, /* super */ - "octet_number", /* name */ - sizeof(grib_accessor_octet_number), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_octet_number = &_grib_accessor_class_octet_number; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_octet_number* self = (grib_accessor_octet_number*)a; - - int n = 0; - self->left = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->right = grib_arguments_get_long(grib_handle_of_accessor(a), c, n++); - - a->length = 0; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_octet_number* self = (grib_accessor_octet_number*)a; - int ret = GRIB_SUCCESS; - long offset; - - offset = a->offset + self->right; - - if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->left, offset)) != GRIB_SUCCESS) - return ret; - - *val = offset; - *len = 1; - - return ret; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_offset_file.cc b/src/grib_accessor_class_offset_file.cc deleted file mode 100644 index 8fd0a0018..000000000 --- a/src/grib_accessor_class_offset_file.cc +++ /dev/null @@ -1,141 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_double - IMPLEMENTS = unpack_double - IMPLEMENTS = unpack_string - IMPLEMENTS = init - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_offset_file -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in offset_file */ -} grib_accessor_offset_file; - -extern grib_accessor_class* grib_accessor_class_double; - -static grib_accessor_class _grib_accessor_class_offset_file = { - &grib_accessor_class_double, /* super */ - "offset_file", /* name */ - sizeof(grib_accessor_offset_file), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_offset_file = &_grib_accessor_class_offset_file; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length = 0; -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - *val = (double)grib_handle_of_accessor(a)->offset; - *len = 1; - return GRIB_SUCCESS; -} - -static int unpack_string(grib_accessor* a, char* v, size_t* len) -{ - double val = 0; - size_t l = 1; - char repres[1024] = {0,}; - int err = 0; - const char* cclass_name = a->cclass->name; - - err = grib_unpack_double(a, &val, &l); - if (err) return err; - - snprintf(repres, sizeof(repres), "%.0f", val); - - l = strlen(repres) + 1; - if (l > *len) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, l, *len); - *len = l; - return GRIB_BUFFER_TOO_SMALL; - } - grib_context_log(a->context, GRIB_LOG_DEBUG, "%s: Casting double %s to string", __func__, a->name); - - *len = l; - - strcpy(v, repres); - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_offset_values.cc b/src/grib_accessor_class_offset_values.cc deleted file mode 100644 index 012698f79..000000000 --- a/src/grib_accessor_class_offset_values.cc +++ /dev/null @@ -1,175 +0,0 @@ -/* - * (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. - */ - -/********************************** - * Enrico Fucile - *********************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_double - IMPLEMENTS = unpack_double; pack_double - IMPLEMENTS = init - MEMBERS = const char* values - MEMBERS = const char* missingValue - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_offset_values -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in offset_values */ - const char* values; - const char* missingValue; -} grib_accessor_offset_values; - -extern grib_accessor_class* grib_accessor_class_double; - -static grib_accessor_class _grib_accessor_class_offset_values = { - &grib_accessor_class_double, /* super */ - "offset_values", /* name */ - sizeof(grib_accessor_offset_values), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_offset_values = &_grib_accessor_class_offset_values; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* args) -{ - int n = 0; - grib_accessor_offset_values* self = (grib_accessor_offset_values*)a; - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->missingValue = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->length = 0; -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - int ret = 0; - *val = 0; - *len = 1; - return ret; -} - -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - double* values = NULL; - size_t size = 0; - double missingValue = 0; - long missingValuesPresent = 0; - int ret = 0, i = 0; - grib_accessor_offset_values* self = (grib_accessor_offset_values*)a; - grib_context* c = a->context; - grib_handle* h = grib_handle_of_accessor(a); - - if (*val == 0) - return GRIB_SUCCESS; - - if ((ret = grib_get_double_internal(h, self->missingValue, &missingValue)) != GRIB_SUCCESS) { - return ret; - } - if ((ret = grib_get_long_internal(h, "missingValuesPresent", &missingValuesPresent)) != GRIB_SUCCESS) { - return ret; - } - - if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) - return ret; - - values = (double*)grib_context_malloc(c, size * sizeof(double)); - if (!values) - return GRIB_OUT_OF_MEMORY; - - if ((ret = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) { - grib_context_free(c, values); - return ret; - } - - for (i = 0; i < size; i++) { - if (missingValuesPresent) { - if (values[i] != missingValue) - values[i] += *val; - } - else { - values[i] += *val; - } - } - - if ((ret = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) - return ret; - - grib_context_free(c, values); - - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_pack_bufr_values.cc b/src/grib_accessor_class_pack_bufr_values.cc deleted file mode 100644 index a076e12ac..000000000 --- a/src/grib_accessor_class_pack_bufr_values.cc +++ /dev/null @@ -1,177 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init;dump - IMPLEMENTS = unpack_string;unpack_string_array;unpack_long; unpack_double - IMPLEMENTS = pack_long; pack_double - IMPLEMENTS = value_count; destroy; get_native_type; - MEMBERS = grib_accessor* data_accessor - - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static int unpack_string_array(grib_accessor*, char**, size_t* len); -static int value_count(grib_accessor*, long*); -static void destroy(grib_context*, grib_accessor*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_pack_bufr_values -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in pack_bufr_values */ - grib_accessor* data_accessor; -} grib_accessor_pack_bufr_values; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_pack_bufr_values = { - &grib_accessor_class_gen, /* super */ - "pack_bufr_values", /* name */ - sizeof(grib_accessor_pack_bufr_values), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - &destroy, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - &unpack_string_array, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_pack_bufr_values = &_grib_accessor_class_pack_bufr_values; - -/* 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); - - a->length = 0; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ -} - -static int unpack_string_array(grib_accessor* a, char** buffer, size_t* len) -{ - return GRIB_NOT_IMPLEMENTED; -} - -static int unpack_string(grib_accessor* a, char* buffer, size_t* len) -{ - return GRIB_NOT_IMPLEMENTED; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - return GRIB_NOT_IMPLEMENTED; -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - return GRIB_NOT_IMPLEMENTED; -} - -static int value_count(grib_accessor* a, long* count) -{ - *count = 1; - return 0; -} - -static void destroy(grib_context* context, grib_accessor* a) -{ -} - -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) -{ - 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); -} - -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_pack_bufr_values* self = (grib_accessor_pack_bufr_values*)a; - grib_accessor* data = (grib_accessor*)self->data_accessor; - - return grib_pack_double(data, 0, 0); -} diff --git a/src/grib_accessor_class_packing_type.cc b/src/grib_accessor_class_packing_type.cc deleted file mode 100644 index a9a4a2deb..000000000 --- a/src/grib_accessor_class_packing_type.cc +++ /dev/null @@ -1,167 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = unpack_string;pack_string - IMPLEMENTS = string_length - IMPLEMENTS = get_native_type - IMPLEMENTS = init - MEMBERS = const char* values - MEMBERS = const char* packing_type - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_string(grib_accessor*, const char*, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static size_t string_length(grib_accessor*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_packing_type -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in packing_type */ - const char* values; - const char* packing_type; -} grib_accessor_packing_type; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_packing_type = { - &grib_accessor_class_gen, /* super */ - "packing_type", /* name */ - sizeof(grib_accessor_packing_type), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - &string_length, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - &pack_string, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_packing_type = &_grib_accessor_class_packing_type; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* args) -{ - int n = 0; - grib_accessor_packing_type* self = (grib_accessor_packing_type*)a; - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->packing_type = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->length = 0; -} - -static size_t string_length(grib_accessor* a) -{ - return 1024; -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_STRING; -} - -static int pack_string(grib_accessor*a, const char* sval, size_t* len) -{ - grib_accessor_packing_type* self = (grib_accessor_packing_type*)a; - grib_handle* h = grib_handle_of_accessor(a); - double* values = NULL; - grib_context* c = a->context; - size_t size = 0; - int err = 0; - - if ((err = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) - return err; - - values = (double*)grib_context_malloc(c, size * sizeof(double)); - if (!values) return GRIB_OUT_OF_MEMORY; - - if ((err = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) { - grib_context_free(c, values); - return err; - } - - if ((err = grib_set_string_internal(h, self->packing_type, sval, len)) != GRIB_SUCCESS) { - grib_context_free(c, values); - return err; - } - - if ((err = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) { - grib_context_free(c, values); - return err; - } - - grib_context_free(c, values); - return GRIB_SUCCESS; -} - -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - grib_accessor_packing_type* self = (grib_accessor_packing_type*)a; - grib_handle* h = grib_handle_of_accessor(a); - - return grib_get_string(h, self->packing_type, val, len); -} diff --git a/src/grib_accessor_class_pad.cc b/src/grib_accessor_class_pad.cc deleted file mode 100644 index 473a507e1..000000000 --- a/src/grib_accessor_class_pad.cc +++ /dev/null @@ -1,126 +0,0 @@ -/* - * (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. - */ - -/************************************** - * Enrico Fucile - **************************************/ - - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_padding - IMPLEMENTS = init;preferred_size - MEMBERS =grib_expression* expression - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static void init(grib_accessor*, const long, grib_arguments*); -static size_t preferred_size(grib_accessor*, int); - -typedef struct grib_accessor_pad -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in bytes */ - /* Members defined in padding */ - /* Members defined in pad */ - grib_expression* expression; -} grib_accessor_pad; - -extern grib_accessor_class* grib_accessor_class_padding; - -static grib_accessor_class _grib_accessor_class_pad = { - &grib_accessor_class_padding, /* super */ - "pad", /* name */ - sizeof(grib_accessor_pad), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - &preferred_size, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_pad = &_grib_accessor_class_pad; - -/* END_CLASS_IMP */ - - -static size_t preferred_size(grib_accessor* a, int from_handle) -{ - grib_accessor_pad* self = (grib_accessor_pad*)a; - - long length = 0; - - grib_expression_evaluate_long(grib_handle_of_accessor(a), self->expression, &length); - - return length > 0 ? length : 0; -} - - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - grib_accessor_pad* self = (grib_accessor_pad*)a; - - self->expression = grib_arguments_get_expression(grib_handle_of_accessor(a), arg, 0); - a->length = preferred_size(a, 1); -} diff --git a/src/grib_accessor_class_padding.cc b/src/grib_accessor_class_padding.cc deleted file mode 100644 index 790ea9db2..000000000 --- a/src/grib_accessor_class_padding.cc +++ /dev/null @@ -1,151 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_bytes - IMPLEMENTS = init;update_size;resize; value_count - IMPLEMENTS = compare;string_length;byte_count - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static size_t string_length(grib_accessor*); -static long byte_count(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); -static void update_size(grib_accessor*, size_t); -static void resize(grib_accessor*,size_t); -static int compare(grib_accessor*, grib_accessor*); - -typedef struct grib_accessor_padding -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in bytes */ - /* Members defined in padding */ -} grib_accessor_padding; - -extern grib_accessor_class* grib_accessor_class_bytes; - -static grib_accessor_class _grib_accessor_class_padding = { - &grib_accessor_class_bytes, /* super */ - "padding", /* name */ - sizeof(grib_accessor_padding), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - &string_length, /* get length of string */ - &value_count, /* get number of values */ - &byte_count, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - &update_size, /* update_size */ - 0, /* preferred_size */ - &resize, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - &compare, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_padding = &_grib_accessor_class_padding; - -/* 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; -} - -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) -{ - 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, - /*update_lengths=*/1, /*update_paddings=*/0); - grib_context_free(a->context, zero); - - grib_context_log(a->context, GRIB_LOG_DEBUG, - "grib_accessor_class_padding::resize new_size=%zu a->length=%ld %s %s", - new_size, 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; -} - -static long byte_count(grib_accessor* a) -{ - return a->length; -} - -static size_t string_length(grib_accessor* a) -{ - return (size_t)a->length; -} diff --git a/src/grib_accessor_class_padto.cc b/src/grib_accessor_class_padto.cc deleted file mode 100644 index f6f9417b4..000000000 --- a/src/grib_accessor_class_padto.cc +++ /dev/null @@ -1,136 +0,0 @@ -/* - * (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. - */ - -/************************************** - * Enrico Fucile - **************************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_padding - IMPLEMENTS = init;preferred_size;dump - MEMBERS=grib_expression* expression - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); -static size_t preferred_size(grib_accessor*, int); - -typedef struct grib_accessor_padto -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in bytes */ - /* Members defined in padding */ - /* Members defined in padto */ - grib_expression* expression; -} grib_accessor_padto; - -extern grib_accessor_class* grib_accessor_class_padding; - -static grib_accessor_class _grib_accessor_class_padto = { - &grib_accessor_class_padding, /* super */ - "padto", /* name */ - sizeof(grib_accessor_padto), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - &preferred_size, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_padto = &_grib_accessor_class_padto; - -/* END_CLASS_IMP */ - - -static size_t preferred_size(grib_accessor* a, int from_handle) -{ - grib_accessor_padto* self = (grib_accessor_padto*)a; - - long length = 0; - long theEnd; - - grib_expression_evaluate_long(grib_handle_of_accessor(a), self->expression, &theEnd); - - length = theEnd - a->offset; - - /* printf("preferred_size: prefered: %ld current:%ld %s %s %ld\n", (long)length,(long)a->length,a->cclass->name,a->name,(long)a->offset); */ - - return length > 0 ? length : 0; -} - - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - grib_accessor_padto* self = (grib_accessor_padto*)a; - - self->expression = grib_arguments_get_expression(grib_handle_of_accessor(a), arg, 0); - a->length = preferred_size(a, 1); -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - /*grib_dump_string(dumper,a,NULL);*/ -} diff --git a/src/grib_accessor_class_padtoeven.cc b/src/grib_accessor_class_padtoeven.cc deleted file mode 100644 index c75e0e254..000000000 --- a/src/grib_accessor_class_padtoeven.cc +++ /dev/null @@ -1,139 +0,0 @@ -/* - * (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. - */ - -/************************************** - * Enrico Fucile - **************************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_padding - IMPLEMENTS = init;preferred_size - MEMBERS=const char* section_offset - MEMBERS=const char* section_length - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static void init(grib_accessor*, const long, grib_arguments*); -static size_t preferred_size(grib_accessor*, int); - -typedef struct grib_accessor_padtoeven -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in bytes */ - /* Members defined in padding */ - /* Members defined in padtoeven */ - const char* section_offset; - const char* section_length; -} grib_accessor_padtoeven; - -extern grib_accessor_class* grib_accessor_class_padding; - -static grib_accessor_class _grib_accessor_class_padtoeven = { - &grib_accessor_class_padding, /* super */ - "padtoeven", /* name */ - sizeof(grib_accessor_padtoeven), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - &preferred_size, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_padtoeven = &_grib_accessor_class_padtoeven; - -/* END_CLASS_IMP */ - -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_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) { - // grib_context_log(a->context, - // GRIB_LOG_ERROR,"GRIB message has an odd length section (%ld, %s)", - // (long)length,a->name); - return 0; - } - - /* printf("EVEN %ld %ld\n",(long) a->offset,(long) offset);*/ - seclen = a->offset - offset; - - 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); - - a->length = preferred_size(a, 1); -} diff --git a/src/grib_accessor_class_padtomultiple.cc b/src/grib_accessor_class_padtomultiple.cc deleted file mode 100644 index 3104cdf2f..000000000 --- a/src/grib_accessor_class_padtomultiple.cc +++ /dev/null @@ -1,132 +0,0 @@ -/* - * (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. - */ - -/************************************** - * Enrico Fucile - **************************************/ - - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_padding - IMPLEMENTS = init;preferred_size - MEMBERS=grib_expression* begin - MEMBERS=grib_expression* multiple - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static void init(grib_accessor*, const long, grib_arguments*); -static size_t preferred_size(grib_accessor*, int); - -typedef struct grib_accessor_padtomultiple -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in bytes */ - /* Members defined in padding */ - /* Members defined in padtomultiple */ - grib_expression* begin; - grib_expression* multiple; -} grib_accessor_padtomultiple; - -extern grib_accessor_class* grib_accessor_class_padding; - -static grib_accessor_class _grib_accessor_class_padtomultiple = { - &grib_accessor_class_padding, /* super */ - "padtomultiple", /* name */ - sizeof(grib_accessor_padtomultiple), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - &preferred_size, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_padtomultiple = &_grib_accessor_class_padtomultiple; - -/* END_CLASS_IMP */ - -static size_t preferred_size(grib_accessor* a, int from_handle) -{ - grib_accessor_padtomultiple* self = (grib_accessor_padtomultiple*)a; - long padding = 0; - long begin = 0; - long multiple = 0; - - grib_expression_evaluate_long(grib_handle_of_accessor(a), self->begin, &begin); - grib_expression_evaluate_long(grib_handle_of_accessor(a), self->multiple, &multiple); - - padding = a->offset - begin; - padding = ((padding + multiple - 1) / multiple) * multiple - padding; - - return padding == 0 ? multiple : padding; -} - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - grib_accessor_padtomultiple* self = (grib_accessor_padtomultiple*)a; - - self->begin = grib_arguments_get_expression(grib_handle_of_accessor(a), arg, 0); - self->multiple = grib_arguments_get_expression(grib_handle_of_accessor(a), arg, 1); - a->length = preferred_size(a, 1); -} diff --git a/src/grib_accessor_class_position.cc b/src/grib_accessor_class_position.cc deleted file mode 100644 index 0f9565c37..000000000 --- a/src/grib_accessor_class_position.cc +++ /dev/null @@ -1,137 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = unpack_long - IMPLEMENTS = get_native_type - IMPLEMENTS = init;dump - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_position -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in position */ -} grib_accessor_position; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_position = { - &grib_accessor_class_gen, /* super */ - "position", /* name */ - sizeof(grib_accessor_position), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_position = &_grib_accessor_class_position; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; - a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_LONG; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_long(dumper, a, NULL); -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - if (*len < 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name, 1); - *len = 0; - return GRIB_ARRAY_TOO_SMALL; - } - *val = a->offset; - *len = 1; - return GRIB_SUCCESS; -} - -// static int compare(grib_accessor* a, grib_accessor* b) -// { -// if (a->offset != b->offset) -// return GRIB_OFFSET_MISMATCH; -// return GRIB_SUCCESS; -// } diff --git a/src/grib_accessor_class_raw.cc b/src/grib_accessor_class_raw.cc deleted file mode 100644 index cdac6a100..000000000 --- a/src/grib_accessor_class_raw.cc +++ /dev/null @@ -1,219 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = get_native_type;init;update_size; pack_bytes - IMPLEMENTS = compare;unpack_bytes;byte_count;value_count - MEMBERS = const char* totalLength - MEMBERS = const char* sectionLength - MEMBERS = long relativeOffset - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_bytes(grib_accessor*, const unsigned char*, size_t* len); -static int unpack_bytes(grib_accessor*, unsigned char*, size_t* len); -static long byte_count(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); -static void update_size(grib_accessor*, size_t); -static int compare(grib_accessor*, grib_accessor*); - -typedef struct grib_accessor_raw -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in raw */ - const char* totalLength; - const char* sectionLength; - long relativeOffset; -} grib_accessor_raw; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_raw = { - &grib_accessor_class_gen, /* super */ - "raw", /* name */ - sizeof(grib_accessor_raw), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - &byte_count, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - &pack_bytes, /* pack_bytes */ - &unpack_bytes, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - &update_size, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - &compare, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_raw = &_grib_accessor_class_raw; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - int n = 0; - int err = 0; - long sectionLength; - grib_accessor_raw* self = (grib_accessor_raw*)a; - grib_expression* e; - grib_handle* hand = grib_handle_of_accessor(a); - - a->length = 0; - self->totalLength = grib_arguments_get_name(hand, arg, n++); - self->sectionLength = grib_arguments_get_name(hand, arg, n++); - - e = grib_arguments_get_expression(hand, arg, n++); - err = grib_expression_evaluate_long(hand, e, &(self->relativeOffset)); - if (err) - grib_context_log(hand->context, GRIB_LOG_ERROR, "Unable to evaluate relativeOffset"); - - grib_get_long(hand, self->sectionLength, §ionLength); - - a->length = sectionLength - self->relativeOffset; - if (a->length < 0) - a->length = 0; - - /* Assert(a->length>=0); */ -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_BYTES; -} - - -static int compare(grib_accessor* a, grib_accessor* b) -{ - int retval = GRIB_SUCCESS; - - size_t alen = (size_t)grib_byte_count(a); - size_t blen = (size_t)grib_byte_count(b); - - if (alen != blen) - return GRIB_COUNT_MISMATCH; - - return retval; -} - -static long byte_count(grib_accessor* a) -{ - return a->length; -} - -static int value_count(grib_accessor* a, long* len) -{ - *len = a->length; - return 0; -} - -static int unpack_bytes(grib_accessor* a, unsigned char* buffer, size_t* len) -{ - if (*len < a->length) { - *len = a->length; - return GRIB_ARRAY_TOO_SMALL; - } - *len = a->length; - - memcpy(buffer, grib_handle_of_accessor(a)->buffer->data + a->offset, *len); - - return GRIB_SUCCESS; -} - -static void update_size(grib_accessor* a, size_t s) -{ - grib_context_log(a->context, GRIB_LOG_DEBUG, "updating size of %s old %ld new %ld", a->name, a->length, s); - a->length = s; - Assert(a->length >= 0); -} - -void accessor_raw_set_length(grib_accessor* a, size_t len) -{ - a->length = len; -} - -long accessor_raw_get_offset(grib_accessor* a) -{ - return a->offset; -} - -static int pack_bytes(grib_accessor* a, const unsigned char* val, size_t* len) -{ - size_t length = *len; - long totalLength; - long sectionLength; - grib_handle* h = grib_handle_of_accessor(a); - grib_accessor_raw* self = (grib_accessor_raw*)a; - long dlen = length - a->length; - - grib_get_long(h, self->totalLength, &totalLength); - totalLength += dlen; - grib_get_long(h, self->sectionLength, §ionLength); - sectionLength += dlen; - - grib_buffer_replace(a, val, length, 1, 1); - - grib_set_long(h, self->totalLength, totalLength); - grib_set_long(h, self->sectionLength, sectionLength); - a->length = length; - - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_rdbtime_guess_date.cc b/src/grib_accessor_class_rdbtime_guess_date.cc deleted file mode 100644 index 8a3bfa2a1..000000000 --- a/src/grib_accessor_class_rdbtime_guess_date.cc +++ /dev/null @@ -1,172 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = init - MEMBERS=const char* typicalYear - MEMBERS=const char* typicalMonth - MEMBERS=const char* typicalDay - MEMBERS=const char* rdbDay - MEMBERS=long yearOrMonth - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_rdbtime_guess_date -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in rdbtime_guess_date */ - const char* typicalYear; - const char* typicalMonth; - const char* typicalDay; - const char* rdbDay; - long yearOrMonth; -} grib_accessor_rdbtime_guess_date; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_rdbtime_guess_date = { - &grib_accessor_class_long, /* super */ - "rdbtime_guess_date", /* name */ - sizeof(grib_accessor_rdbtime_guess_date), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_rdbtime_guess_date = &_grib_accessor_class_rdbtime_guess_date; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_rdbtime_guess_date* self = (grib_accessor_rdbtime_guess_date*)a; - int n = 0; - - self->typicalYear = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->typicalMonth = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->typicalDay = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->rdbDay = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->yearOrMonth = grib_arguments_get_long(grib_handle_of_accessor(a), c, n++); - - /* a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; */ -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_rdbtime_guess_date* self = (grib_accessor_rdbtime_guess_date*)a; - grib_handle* h = grib_handle_of_accessor(a); - int ret = 0; - long typicalYear, typicalMonth, typicalDay, rdbDay; - long rdbYear, rdbMonth; - - ret = grib_get_long(h, self->typicalYear, &typicalYear); - if (ret) - return ret; - ret = grib_get_long(h, self->typicalMonth, &typicalMonth); - if (ret) - return ret; - ret = grib_get_long(h, self->typicalDay, &typicalDay); - if (ret) - return ret; - ret = grib_get_long(h, self->rdbDay, &rdbDay); - if (ret) - return ret; - - if (rdbDay < typicalDay) { - if (typicalDay == 31 && typicalMonth == 12) { - rdbYear = typicalYear + 1; - rdbMonth = 1; - } - else { - rdbYear = typicalYear; - rdbMonth = typicalMonth + 1; - } - } - else { - rdbYear = typicalYear; - rdbMonth = typicalMonth; - } - - *val = self->yearOrMonth == 1 ? rdbYear : rdbMonth; - *len = 1; - - return GRIB_SUCCESS; -} - -static int pack_long(grib_accessor* a, const long* v, size_t* len) -{ - /* do nothing*/ - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_reference_value_error.cc b/src/grib_accessor_class_reference_value_error.cc deleted file mode 100644 index 3cc4af20d..000000000 --- a/src/grib_accessor_class_reference_value_error.cc +++ /dev/null @@ -1,142 +0,0 @@ -/* - * (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. - */ - -/************************************** - * Enrico Fucile - **************************************/ - - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_double - IMPLEMENTS = unpack_double - IMPLEMENTS = init - MEMBERS=const char* referenceValue - MEMBERS=const char* floatType - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_double(grib_accessor*, double* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_reference_value_error -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in reference_value_error */ - const char* referenceValue; - const char* floatType; -} grib_accessor_reference_value_error; - -extern grib_accessor_class* grib_accessor_class_double; - -static grib_accessor_class _grib_accessor_class_reference_value_error = { - &grib_accessor_class_double, /* super */ - "reference_value_error", /* name */ - sizeof(grib_accessor_reference_value_error), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_reference_value_error = &_grib_accessor_class_reference_value_error; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_reference_value_error* self = (grib_accessor_reference_value_error*)a; - int n = 0; - - self->referenceValue = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->floatType = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length = 0; -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_reference_value_error* self = (grib_accessor_reference_value_error*)a; - int ret = 0; - double referenceValue = 0; - - if ((ret = grib_get_double_internal(grib_handle_of_accessor(a), - self->referenceValue, &referenceValue)) != GRIB_SUCCESS) - return ret; - - if (!strcmp(self->floatType, "ibm")) - *val = grib_ibmfloat_error(referenceValue); - else if (!strcmp(self->floatType, "ieee")) - *val = grib_ieeefloat_error(referenceValue); - else - Assert(1 == 0); - - if (ret == GRIB_SUCCESS) - *len = 1; - - return ret; -} diff --git a/src/grib_accessor_class_round.cc b/src/grib_accessor_class_round.cc deleted file mode 100644 index 98fe2fda5..000000000 --- a/src/grib_accessor_class_round.cc +++ /dev/null @@ -1,154 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_evaluate - IMPLEMENTS = unpack_double - IMPLEMENTS = unpack_string - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); - -typedef struct grib_accessor_round -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in evaluate */ - grib_arguments* arg; - /* Members defined in round */ -} grib_accessor_round; - -extern grib_accessor_class* grib_accessor_class_evaluate; - -static grib_accessor_class _grib_accessor_class_round = { - &grib_accessor_class_evaluate, /* super */ - "round", /* name */ - sizeof(grib_accessor_round), /* size */ - 0, /* inited */ - 0, /* init_class */ - 0, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_round = &_grib_accessor_class_round; - -/* END_CLASS_IMP */ - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_round* self = (grib_accessor_round*)a; - - int ret = GRIB_SUCCESS; - - size_t replen = 0; - double rounding_precision = 0; - double rounded = 0; - double toround = 0; - - const char* oval = NULL; - oval = grib_arguments_get_name(grib_handle_of_accessor(a), self->arg, 0); - - if ((ret = grib_get_double_internal(grib_handle_of_accessor(a), oval, &toround)) != 0) - return ret; - - rounding_precision = grib_arguments_get_long(grib_handle_of_accessor(a), self->arg, 1); - - rounded = floor(rounding_precision * toround + 0.5) / rounding_precision; - - *len = replen; - - *val = rounded; - - return ret; -} - -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - char result[1024]; - int ret = GRIB_SUCCESS; - size_t replen = 1; - - double value = 0; - - ret = unpack_double(a, &value, &replen); - - snprintf(result, sizeof(result), "%.3f", value); - - replen = strlen(result) + 1; - - if (*len < replen) { - *len = replen; - return GRIB_ARRAY_TOO_SMALL; - } - - *len = replen; - - snprintf(val, 1024, "%s", result); - - return ret; -} diff --git a/src/grib_accessor_class_scale.cc b/src/grib_accessor_class_scale.cc deleted file mode 100644 index 6fec75e94..000000000 --- a/src/grib_accessor_class_scale.cc +++ /dev/null @@ -1,237 +0,0 @@ -/* - * (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. - */ - -/************************************** - * Enrico Fucile - **************************************/ - - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_double - IMPLEMENTS = unpack_double;pack_double;is_missing - IMPLEMENTS = pack_long - IMPLEMENTS = init - MEMBERS=const char* value - MEMBERS=const char* multiplier - MEMBERS=const char* divisor - MEMBERS=const char* truncating - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int is_missing(grib_accessor*); -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_scale -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in scale */ - const char* value; - const char* multiplier; - const char* divisor; - const char* truncating; -} grib_accessor_scale; - -extern grib_accessor_class* grib_accessor_class_double; - -static grib_accessor_class _grib_accessor_class_scale = { - &grib_accessor_class_double, /* super */ - "scale", /* name */ - sizeof(grib_accessor_scale), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - &is_missing, /* is_missing */ - &pack_long, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_scale = &_grib_accessor_class_scale; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_scale* self = (grib_accessor_scale*)a; - int n = 0; - - self->value = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->multiplier = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->divisor = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->truncating = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_scale* self = (grib_accessor_scale*)a; - int ret = 0; - long value = 0; - long multiplier = 0; - long divisor = 0; - - if (*len < 1) { - ret = GRIB_ARRAY_TOO_SMALL; - grib_context_log(a->context, GRIB_LOG_ERROR, - "Accessor %s cannot gather value for %s and/or %s", - a->name, self->multiplier, self->divisor); - return ret; - } - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->divisor, &divisor)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->multiplier, &multiplier)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->value, &value)) != GRIB_SUCCESS) - return ret; - - if (value == GRIB_MISSING_LONG) - *val = GRIB_MISSING_DOUBLE; - else - *val = ((double)(value * multiplier)) / divisor; - - if (ret == GRIB_SUCCESS) - *len = 1; - - return ret; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - const double dval = (double)*val; - return pack_double(a, &dval, len); -} - -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_scale* self = (grib_accessor_scale*)a; - int ret = 0; - - long value = 0; - long divisor = 0; - long multiplier = 0; - long truncating = 0; - double x; - - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->divisor, &divisor); - if (ret != GRIB_SUCCESS) return ret; - - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->multiplier, &multiplier); - if (ret != GRIB_SUCCESS) return ret; - - if (self->truncating) { - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->truncating, &truncating); - if (ret != GRIB_SUCCESS) return ret; - } - - if (multiplier == 0) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Accessor %s: cannot divide by a zero multiplier %s", - a->name, self->multiplier); - return GRIB_ENCODING_ERROR; - } - - x = *val * (double)divisor / (double)multiplier; - if (*val == GRIB_MISSING_DOUBLE) - value = GRIB_MISSING_LONG; - else if (truncating) { - value = (long)x; - } - else { - value = x > 0 ? (long)(x + 0.5) : (long)(x - 0.5); - } - - ret = grib_set_long_internal(grib_handle_of_accessor(a), self->value, value); - if (ret) - grib_context_log(a->context, GRIB_LOG_ERROR, - "Accessor %s: cannot pack value for %s (%s)\n", - a->name, self->value, grib_get_error_message(ret)); - - if (ret == GRIB_SUCCESS) - *len = 1; - - return ret; -} - -static int is_missing(grib_accessor* a) -{ - grib_accessor_scale* self = (grib_accessor_scale*)a; - grib_accessor* av = grib_find_accessor(grib_handle_of_accessor(a), self->value); - - if (!av) - return GRIB_NOT_FOUND; - return grib_is_missing_internal(av); - // int ret=0; - // long value=0; - // if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->value, &value))!= GRIB_SUCCESS){ - // grib_context_log(a->context, GRIB_LOG_ERROR, - // "Accessor %s cannot gather value for %s error %d \n", a->name, - // self->value, ret); - // return 0; - // } - // return (value == GRIB_MISSING_LONG); -} diff --git a/src/grib_accessor_class_scale_values.cc b/src/grib_accessor_class_scale_values.cc deleted file mode 100644 index 8c4b33fcb..000000000 --- a/src/grib_accessor_class_scale_values.cc +++ /dev/null @@ -1,177 +0,0 @@ -/* - * (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. - */ - -/********************************** - * Enrico Fucile - *********************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_double - IMPLEMENTS = unpack_double; pack_double - IMPLEMENTS = init - MEMBERS = const char* values - MEMBERS = const char* missingValue - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_scale_values -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in scale_values */ - const char* values; - const char* missingValue; -} grib_accessor_scale_values; - -extern grib_accessor_class* grib_accessor_class_double; - -static grib_accessor_class _grib_accessor_class_scale_values = { - &grib_accessor_class_double, /* super */ - "scale_values", /* name */ - sizeof(grib_accessor_scale_values), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_scale_values = &_grib_accessor_class_scale_values; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* args) -{ - int n = 0; - grib_accessor_scale_values* self = (grib_accessor_scale_values*)a; - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->missingValue = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->length = 0; -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - int ret = 0; - *val = 1; - *len = 1; - return ret; -} - -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - double* values = NULL; - double missingValue = 0; - long missingValuesPresent = 0; - size_t size = 0; - int ret = 0, i = 0; - grib_accessor_scale_values* self = (grib_accessor_scale_values*)a; - const grib_context* c = a->context; - grib_handle* h = grib_handle_of_accessor(a); - - if (*val == 1) - return GRIB_SUCCESS; - - if ((ret = grib_get_double_internal(h, self->missingValue, &missingValue)) != GRIB_SUCCESS) { - return ret; - } - if ((ret = grib_get_long_internal(h, "missingValuesPresent", &missingValuesPresent)) != GRIB_SUCCESS) { - return ret; - } - - if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) - return ret; - - values = (double*)grib_context_malloc(c, size * sizeof(double)); - if (!values) - return GRIB_OUT_OF_MEMORY; - - if ((ret = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) { - grib_context_free(c, values); - return ret; - } - - for (i = 0; i < size; i++) { - if (missingValuesPresent) { - if (values[i] != missingValue) - values[i] *= *val; - } - else { - values[i] *= *val; - } - } - - if ((ret = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) { - grib_context_free(c, values); - return ret; - } - - grib_context_free(c, values); - - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_section.cc b/src/grib_accessor_class_section.cc deleted file mode 100644 index f9c8857a7..000000000 --- a/src/grib_accessor_class_section.cc +++ /dev/null @@ -1,194 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = next_offset;byte_count - IMPLEMENTS = destroy;sub_section - IMPLEMENTS = get_native_type - IMPLEMENTS = init;dump;update_size - IMPLEMENTS = next - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static grib_section* sub_section(grib_accessor* a); -static int get_native_type(grib_accessor*); -static long byte_count(grib_accessor*); -static long next_offset(grib_accessor*); -static void destroy(grib_context*, grib_accessor*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); -static void update_size(grib_accessor*, size_t); -static grib_accessor* next(grib_accessor*, int); - -typedef struct grib_accessor_section -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in section */ -} grib_accessor_section; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_section = { - &grib_accessor_class_gen, /* super */ - "section", /* name */ - sizeof(grib_accessor_section), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - &destroy, /* destroy */ - &dump, /* dump */ - &next_offset, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - &byte_count, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - &sub_section, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - &update_size, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - &next, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_section = &_grib_accessor_class_section; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - a->sub_section = grib_section_create(grib_handle_of_accessor(a), a); - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_section(dumper, a, a->sub_section->block); -} - -static long byte_count(grib_accessor* a) -{ - if (!a->length || grib_handle_of_accessor(a)->loader) { - if (a->name[1] == '_') - return 0; - - /* printf("adjusting sizes SECTION %s is %ld %ld\n",a->name,(long)a->offset,(long)a->length); */ - grib_section_adjust_sizes(a->sub_section, grib_handle_of_accessor(a)->loader != NULL, 0); - /* printf(" SECTION %s is %ld %ld\n",a->name,(long)a->offset,(long)a->length); */ - } - - /* printf("SECTION %s is %ld %d\n",a->name,a->length,a->sub_section->aclength != NULL); */ - return a->length; -} - -static long next_offset(grib_accessor* a) -{ - return a->offset + byte_count(a); -} - -static void destroy(grib_context* ct, grib_accessor* a) -{ - grib_section_delete(ct, a->sub_section); -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_SECTION; -} - -static grib_section* sub_section(grib_accessor* a) -{ - return a->sub_section; -} - -static void update_size(grib_accessor* a, size_t length) -{ - size_t size = 1; - long len = length; - Assert(length <= 0x7fffffff); - if (a->sub_section->aclength) { - int e = grib_pack_long(a->sub_section->aclength, &len, &size); - Assert(e == GRIB_SUCCESS); - // printf("update_length %s %ld %ld\n", a->sub_section->aclength->name, - // (long)a->sub_section->aclength->offset, - // (long)a->sub_section->aclength->length); - } - - a->sub_section->length = a->length = length; - a->sub_section->padding = 0; - - // printf("update_size %s %ld\n", a->name, a->length); - - Assert(a->length >= 0); -} - -static grib_accessor* next(grib_accessor* a, int explore) -{ - grib_accessor* next = NULL; - if (explore) { - next = a->sub_section->block->first; - if (!next) - next = a->next; - } - else { - next = a->next; - } - if (!next) { - if (a->parent->owner) - next = a->parent->owner->cclass->next(a->parent->owner, 0); - } - return next; -} diff --git a/src/grib_accessor_class_section_length.cc b/src/grib_accessor_class_section_length.cc deleted file mode 100644 index 4e5957e71..000000000 --- a/src/grib_accessor_class_section_length.cc +++ /dev/null @@ -1,122 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_unsigned - IMPLEMENTS = init;dump - IMPLEMENTS = value_count - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int value_count(grib_accessor*, long*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_section_length -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in unsigned */ - long nbytes; - grib_arguments* arg; - /* Members defined in section_length */ -} grib_accessor_section_length; - -extern grib_accessor_class* grib_accessor_class_unsigned; - -static grib_accessor_class _grib_accessor_class_section_length = { - &grib_accessor_class_unsigned, /* super */ - "section_length", /* name */ - sizeof(grib_accessor_section_length), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_section_length = &_grib_accessor_class_section_length; - -/* END_CLASS_IMP */ - -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); -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_long(dumper, a, NULL); -} - -static int value_count(grib_accessor* a, long* c) -{ - *c = 1; - return 0; -} diff --git a/src/grib_accessor_class_section_padding.cc b/src/grib_accessor_class_section_padding.cc deleted file mode 100644 index 682946df5..000000000 --- a/src/grib_accessor_class_section_padding.cc +++ /dev/null @@ -1,155 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_padding - IMPLEMENTS = init;preferred_size - MEMBERS = int preserve - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static void init(grib_accessor*, const long, grib_arguments*); -static size_t preferred_size(grib_accessor*, int); - -typedef struct grib_accessor_section_padding -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in bytes */ - /* Members defined in padding */ - /* Members defined in section_padding */ - int preserve; -} grib_accessor_section_padding; - -extern grib_accessor_class* grib_accessor_class_padding; - -static grib_accessor_class _grib_accessor_class_section_padding = { - &grib_accessor_class_padding, /* super */ - "section_padding", /* name */ - sizeof(grib_accessor_section_padding), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - &preferred_size, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_section_padding = &_grib_accessor_class_section_padding; - -/* END_CLASS_IMP */ - -static size_t preferred_size(grib_accessor* a, int from_handle) -{ - grib_accessor_section_padding* self = (grib_accessor_section_padding*)a; - grib_accessor* b = a; - grib_accessor* section_length = 0; - long length = 0; - size_t size = 1; - - long alength = 0; - - if (!from_handle) { - if (self->preserve) - return a->length; - else - return 0; - } - - /* The section length should be a parameter */ - while (section_length == NULL && b != NULL) { - section_length = b->parent->aclength; - b = b->parent->owner; - } - - if (!section_length) { - /* printf("PADDING is no !section_length\n"); */ - return 0; - } - - if (grib_unpack_long(section_length, &length, &size) == GRIB_SUCCESS) { - if (length) - alength = length - a->offset + section_length->parent->owner->offset; - else - alength = 0; - - /*Assert(a->length>=0);*/ - - if (alength < 0) - alength = 0; - - /* printf("PADDING is %ld\n",a->length); */ - } - else { - /* printf("PADDING unpack fails\n"); */ - } - - return alength; -} - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - grib_accessor_section_padding* self = (grib_accessor_section_padding*)a; - self->preserve = 1; /* This should be a parameter */ - a->length = preferred_size(a, 1); -} diff --git a/src/grib_accessor_class_section_pointer.cc b/src/grib_accessor_class_section_pointer.cc deleted file mode 100644 index 861ab12e7..000000000 --- a/src/grib_accessor_class_section_pointer.cc +++ /dev/null @@ -1,194 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init;get_native_type;unpack_string - IMPLEMENTS = byte_count; byte_offset - MEMBERS = const char* sectionOffset - MEMBERS = const char* sectionLength - MEMBERS = long sectionNumber - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_string(grib_accessor*, char*, size_t* len); -static long byte_count(grib_accessor*); -static long byte_offset(grib_accessor*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_section_pointer -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in section_pointer */ - const char* sectionOffset; - const char* sectionLength; - long sectionNumber; -} grib_accessor_section_pointer; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_section_pointer = { - &grib_accessor_class_gen, /* super */ - "section_pointer", /* name */ - sizeof(grib_accessor_section_pointer), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - &byte_count, /* get number of bytes */ - &byte_offset, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_section_pointer = &_grib_accessor_class_section_pointer; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - int n = 0; - grib_accessor_section_pointer* self = (grib_accessor_section_pointer*)a; - - self->sectionOffset = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); - self->sectionLength = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); - self->sectionNumber = grib_arguments_get_long(grib_handle_of_accessor(a), arg, n++); - - Assert(self->sectionNumber < MAX_NUM_SECTIONS); - - grib_handle_of_accessor(a)->section_offset[self->sectionNumber] = (char*)self->sectionOffset; - grib_handle_of_accessor(a)->section_length[self->sectionNumber] = (char*)self->sectionLength; - - /* printf("++++++++++++++ GRIB_API: creating section_pointer%d %s %s\n", */ - /* self->sectionNumber,self->sectionLength,self->sectionLength); */ - - if (grib_handle_of_accessor(a)->sections_count < self->sectionNumber) - grib_handle_of_accessor(a)->sections_count = self->sectionNumber; - - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; - a->length = 0; -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_BYTES; -} - -static int unpack_string(grib_accessor* a, char* v, size_t* len) -{ - /* - unsigned char* p=NULL; - char* s=v; - int i; - long length=grib_byte_count(a); - - if (*len < length) return GRIB_ARRAY_TOO_SMALL; - - p = grib_handle_of_accessor(a)->buffer->data + grib_byte_offset(a); - - for (i = 0; i < length; i++) { - snprintf (s,64,"%02x", *(p++)); - s+=2; - } - *len=length; - */ - snprintf(v, 64, "%ld_%ld", grib_byte_offset(a), grib_byte_count(a)); - return GRIB_SUCCESS; -} - -static long byte_count(grib_accessor* a) -{ - grib_accessor_section_pointer* self = (grib_accessor_section_pointer*)a; - long sectionLength = 0; - int ret = 0; - - ret = grib_get_long(grib_handle_of_accessor(a), self->sectionLength, §ionLength); - if (ret) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Unable to get %s %s", - self->sectionLength, grib_get_error_message(ret)); - return -1; - } - - return sectionLength; -} - -static long byte_offset(grib_accessor* a) -{ - grib_accessor_section_pointer* self = (grib_accessor_section_pointer*)a; - long sectionOffset = 0; - int ret = 0; - - ret = grib_get_long(grib_handle_of_accessor(a), self->sectionOffset, §ionOffset); - if (ret) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Unable to get %s %s", - self->sectionOffset, grib_get_error_message(ret)); - return -1; - } - - return sectionOffset; -} diff --git a/src/grib_accessor_class_sexagesimal2decimal.cc b/src/grib_accessor_class_sexagesimal2decimal.cc deleted file mode 100644 index 9e132d9c2..000000000 --- a/src/grib_accessor_class_sexagesimal2decimal.cc +++ /dev/null @@ -1,241 +0,0 @@ -/* - * (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. - */ -/*********************************************************** - * Enrico Fucile - ***********************************************************/ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_to_double - IMPLEMENTS = init; unpack_string - IMPLEMENTS = dump - IMPLEMENTS = get_native_type - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_string(grib_accessor*, char*, size_t* len); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_sexagesimal2decimal -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in to_double */ - const char* key; - long start; - size_t length; - long scale; - /* Members defined in sexagesimal2decimal */ -} grib_accessor_sexagesimal2decimal; - -extern grib_accessor_class* grib_accessor_class_to_double; - -static grib_accessor_class _grib_accessor_class_sexagesimal2decimal = { - &grib_accessor_class_to_double, /* super */ - "sexagesimal2decimal", /* name */ - sizeof(grib_accessor_sexagesimal2decimal), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_sexagesimal2decimal = &_grib_accessor_class_sexagesimal2decimal; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_double(dumper, a, NULL); -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_DOUBLE; -} - -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - int err = 0; - grib_accessor_sexagesimal2decimal* self = (grib_accessor_sexagesimal2decimal*)a; - char buff[512] = {0,}; - size_t length = 0; - size_t size = 512; - char* p; - char* q; - double dd, mm = 0, ss = 0; - int dd_sign = 1; - - err = grib_get_string(grib_handle_of_accessor(a), self->key, buff, &size); - if (err) - return err; - q = buff + self->start; - if (self->length) - q[length] = 0; - p = q; - - while (*p != '-' && *p != ':' && *p != ' ' && *p != 0) { - p++; - } - - if (*p == 0) { - return GRIB_WRONG_CONVERSION; - } - *p = 0; - - dd = atoi(q); - p++; - q = p; - while (*p != '-' && *p != ':' && *p != ' ' && *p != 'N' && *p != 'S' && *p != 'E' && *p != 'W' && *p != 0) { - p++; - } - switch (*p) { - case ' ': - case '-': - case ':': - *p = 0; - mm = atoi(q) / 60.0; - dd += mm; - p++; - q = p; - break; - case 'N': - case 'E': - *p = 0; - dd_sign = 1; - mm = atoi(q) / 60.0; - dd += mm; - p++; - q = p; - break; - case 'S': - case 'W': - *p = 0; - mm = atoi(q) / 60.0; - dd += mm; - dd_sign = -1; - p++; - q = p; - break; - case 0: - break; - default: - return GRIB_WRONG_CONVERSION; - } - if (*p) { - while (*p != '-' && *p != ':' && *p != ' ' && *p != 'N' && *p != 'S' && *p != 'E' && *p != 'W' && *p != 0) { - p++; - } - switch (*p) { - case ' ': - case '-': - case ':': - *p = 0; - ss = atof(q) / 60.0; - dd += ss; - break; - case 'N': - case 'E': - *p = 0; - ss = atof(q) / 60.0; - dd += ss; - dd_sign = 1; - break; - case 'S': - case 'W': - *p = 0; - ss = atof(q) / 60.0; - dd += ss; - dd_sign = -1; - break; - case 0: - break; - default: - return GRIB_WRONG_CONVERSION; - } - } - dd *= dd_sign; - - snprintf(buff, sizeof(buff), "%.2f", dd); - length = strlen(buff); - - if (len[0] < length + 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%lu) for %s, it contains %ld values", - len[0], a->name, a->length + 1); - len[0] = 0; - return GRIB_ARRAY_TOO_SMALL; - } - - strcpy(val, buff); - - len[0] = length; - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_signed.cc b/src/grib_accessor_class_signed.cc deleted file mode 100644 index 3439934e1..000000000 --- a/src/grib_accessor_class_signed.cc +++ /dev/null @@ -1,317 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = init;dump - IMPLEMENTS = next_offset - IMPLEMENTS = byte_count - IMPLEMENTS = value_count - IMPLEMENTS = byte_offset - IMPLEMENTS = update_size; is_missing - MEMBERS = grib_arguments* arg - MEMBERS = int nbytes; - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int is_missing(grib_accessor*); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static long byte_count(grib_accessor*); -static long byte_offset(grib_accessor*); -static long next_offset(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); -static void update_size(grib_accessor*, size_t); - -typedef struct grib_accessor_signed -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in signed */ - grib_arguments* arg; - int nbytes; -} grib_accessor_signed; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_signed = { - &grib_accessor_class_long, /* super */ - "signed", /* name */ - sizeof(grib_accessor_signed), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - &next_offset, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - &byte_count, /* get number of bytes */ - &byte_offset, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - &is_missing, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - &update_size, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_signed = &_grib_accessor_class_signed; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - grib_accessor_signed* self = (grib_accessor_signed*)a; - long count = 0; - - self->arg = arg; - grib_value_count(a, &count); - a->length = len * count; - self->nbytes = len; - Assert(a->length >= 0); -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - long rlen = 0; - grib_value_count(a, &rlen); - if (rlen == 1) - grib_dump_long(dumper, a, NULL); - else - grib_dump_values(dumper, a); -} - -static const long ones[] = { - 0, - -0x7f, - -0x7fff, - -0x7fffff, - -0x7fffffff, -}; - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_signed* self = (grib_accessor_signed*)a; - unsigned long rlen = 0; - int err = 0; - long count = 0; - unsigned long i = 0; - grib_handle* hand = grib_handle_of_accessor(a); - long pos = a->offset; - long missing = 0; - - err = grib_value_count(a, &count); - if (err) - return err; - rlen = count; - - if (*len < rlen) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %lu values", a->name, rlen); - *len = 0; - return GRIB_ARRAY_TOO_SMALL; - } - - if (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) { - Assert(self->nbytes <= 4); - missing = ones[self->nbytes]; - } - - for (i = 0; i < rlen; i++) { - val[i] = (long)grib_decode_signed_long(hand->buffer->data, pos, self->nbytes); - if (missing) - if (val[i] == missing) - val[i] = GRIB_MISSING_LONG; - pos += self->nbytes; - } - - *len = rlen; - return GRIB_SUCCESS; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - grib_accessor_signed* self = (grib_accessor_signed*)a; - int ret = 0; - long off = 0; - unsigned long rlen = 0; - int err = 0; - long count = 0; - size_t buflen = 0; - unsigned char* buf = NULL; - unsigned long i = 0; - long missing = 0; - - err = grib_value_count(a, &count); - if (err) - return err; - rlen = count; - - if (*len < 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %d values", a->name, 1); - len[0] = 0; - return GRIB_ARRAY_TOO_SMALL; - } - - if (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) { - Assert(self->nbytes <= 4); - missing = ones[self->nbytes]; - } - - if (rlen == 1) { - long v = val[0]; - if (missing) { - if (v == GRIB_MISSING_LONG) - v = missing; - } else { - // ECC-1605: Check overflow/underflow - const int nbits = self->nbytes * 8; - const long minval = -(1L << (nbits-1)) + 1; - const long maxval = (1L << (nbits-1)) - 1; - //printf(" key=%s: v=%ld (minval=%ld maxval=%ld)\n", a->name, v, minval, maxval); - if (v > maxval || v < minval) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Key \"%s\": Trying to encode value of %ld but the allowable range is %ld to %ld (number of bits=%d)", - a->name, v, minval, maxval, nbits); - return GRIB_ENCODING_ERROR; - } - } - - off = a->offset; - ret = grib_encode_signed_long(grib_handle_of_accessor(a)->buffer->data, v, off, a->length); - if (ret == GRIB_SUCCESS) - len[0] = 1; - if (*len > 1) - grib_context_log(a->context, GRIB_LOG_WARNING, "grib_accessor_signed : Trying to pack %d values in a scalar %s, packing first value", *len, a->name); - len[0] = 1; - return ret; - } - - /* TODO: We assume that there are no missing values if there are more that 1 value */ - - buflen = *len * a->length; - - buf = (unsigned char*)grib_context_malloc(a->context, buflen); - - for (i = 0; i < *len; i++) { - grib_encode_signed_long(buf, val[i], off, a->length); - off += a->length; - } - ret = grib_set_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, self->arg, 0), *len); - - if (ret == GRIB_SUCCESS) - grib_buffer_replace(a, buf, buflen, 1, 1); - else - *len = 0; - - grib_context_free(a->context, buf); - return ret; -} - -static long byte_count(grib_accessor* a) -{ - return a->length; -} - -static int value_count(grib_accessor* a, long* len) -{ - grib_accessor_signed* self = (grib_accessor_signed*)a; - *len = 0; - if (!self->arg) { - *len = 1; - return 0; - } - return grib_get_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, self->arg, 0), len); -} - -static long byte_offset(grib_accessor* a) -{ - return a->offset; -} - -static void update_size(grib_accessor* a, size_t s) -{ - a->length = s; - Assert(a->length >= 0); -} - -static long next_offset(grib_accessor* a) -{ - return grib_byte_offset(a) + grib_byte_count(a); -} - -static int is_missing(grib_accessor* a) -{ - int i = 0; - unsigned char ff = 0xff; - unsigned long offset = a->offset; - grib_handle* hand = grib_handle_of_accessor(a); - - if (a->length == 0) { - Assert(a->vvalue != NULL); - return a->vvalue->missing; - } - - for (i = 0; i < a->length; i++) { - if (hand->buffer->data[offset] != ff) - return 0; - offset++; - } - - return 1; -} diff --git a/src/grib_accessor_class_signed_bits.cc b/src/grib_accessor_class_signed_bits.cc deleted file mode 100644 index dc8ccf488..000000000 --- a/src/grib_accessor_class_signed_bits.cc +++ /dev/null @@ -1,258 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = init - IMPLEMENTS = next_offset - IMPLEMENTS = byte_count - IMPLEMENTS = value_count - IMPLEMENTS = byte_offset - IMPLEMENTS = update_size - MEMBERS = const char* numberOfBits - MEMBERS = const char* numberOfElements - - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static long byte_count(grib_accessor*); -static long byte_offset(grib_accessor*); -static long next_offset(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); -static void update_size(grib_accessor*, size_t); - -typedef struct grib_accessor_signed_bits -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in signed_bits */ - const char* numberOfBits; - const char* numberOfElements; -} grib_accessor_signed_bits; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_signed_bits = { - &grib_accessor_class_long, /* super */ - "signed_bits", /* name */ - sizeof(grib_accessor_signed_bits), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - &next_offset, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - &byte_count, /* get number of bytes */ - &byte_offset, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - &update_size, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_signed_bits = &_grib_accessor_class_signed_bits; - -/* END_CLASS_IMP */ - -static long byte_count(grib_accessor* a) -{ - return a->length; -} - -static long compute_byte_count(grib_accessor* a) -{ - grib_accessor_signed_bits* self = (grib_accessor_signed_bits*)a; - long numberOfBits; - long numberOfElements; - int ret = 0; - - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); - if (ret) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name, self->numberOfBits); - return 0; - } - - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements, &numberOfElements); - if (ret) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name, self->numberOfElements); - return 0; - } - - return (numberOfBits * numberOfElements + 7) / 8; -} - -static void init(grib_accessor* a, const long len, grib_arguments* args) -{ - grib_accessor_signed_bits* self = (grib_accessor_signed_bits*)a; - int n = 0; - self->numberOfBits = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->numberOfElements = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - a->length = compute_byte_count(a); -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - return GRIB_NOT_IMPLEMENTED; -#if 0 - grib_accessor_signed_bits* self = (grib_accessor_signed_bits*)a; - int i; - int ret = 0; - long pos = a->offset * 8; - long rlen = 0; - long numberOfBits = 0; - - ret = value_count(a, &rlen); - if (ret) - return ret; - - if (*len < rlen) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Wrong size (%ld) for %s it contains %ld values", *len, a->name, rlen); - *len = 0; - return GRIB_ARRAY_TOO_SMALL; - } - - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); - if (ret) - return ret; - - if (numberOfBits == 0) { - for (i = 0; i < rlen; i++) - val[i] = 0; - return GRIB_SUCCESS; - } - - for (i = 0; i < rlen; i++) - val[i] = grib_decode_signed_longb(grib_handle_of_accessor(a)->buffer->data, &pos, numberOfBits); - - *len = rlen; - - return GRIB_SUCCESS; -#endif -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - return GRIB_NOT_IMPLEMENTED; -#if 0 - grib_accessor_signed_bits* self = (grib_accessor_signed_bits*)a; - int ret = 0; - long off = 0; - long numberOfBits = 0; - size_t buflen = 0; - unsigned char* buf = NULL; - unsigned long i = 0; - unsigned long rlen = 0; - long count = 0; - - ret = value_count(a, &count); - if (ret) - return ret; - rlen = count; - if (*len != rlen) { - ret = grib_set_long(grib_handle_of_accessor(a), self->numberOfElements, rlen); - if (ret) - return ret; - } - - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); - if (ret) - return ret; - - buflen = compute_byte_count(a); - buf = (unsigned char*)grib_context_malloc_clear(a->context, buflen + sizeof(long)); - - for (i = 0; i < rlen; i++) - grib_encode_signed_longb(buf, val[i], &off, numberOfBits); - - grib_buffer_replace(a, buf, buflen, 1, 1); - - grib_context_free(a->context, buf); - - return ret; -#endif -} - -static int value_count(grib_accessor* a, long* numberOfElements) -{ - grib_accessor_signed_bits* self = (grib_accessor_signed_bits*)a; - *numberOfElements = 0; - - return grib_get_long(grib_handle_of_accessor(a), self->numberOfElements, numberOfElements); -} - -static long byte_offset(grib_accessor* a) -{ - return a->offset; -} - -static void update_size(grib_accessor* a, size_t s) -{ - a->length = s; -} - -static long next_offset(grib_accessor* a) -{ - return byte_offset(a) + byte_count(a); -} diff --git a/src/grib_accessor_class_simple_packing_error.cc b/src/grib_accessor_class_simple_packing_error.cc deleted file mode 100644 index 64f96eeea..000000000 --- a/src/grib_accessor_class_simple_packing_error.cc +++ /dev/null @@ -1,163 +0,0 @@ -/* - * (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. - */ - -#include "grib_scaling.h" -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_double - IMPLEMENTS = unpack_double - IMPLEMENTS = init - MEMBERS=const char* binaryScaleFactor - MEMBERS=const char* bitsPerValue - MEMBERS=const char* decimalScaleFactor - MEMBERS=const char* referenceValue - MEMBERS=const char* floatType - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_double(grib_accessor*, double* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_simple_packing_error -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in simple_packing_error */ - const char* binaryScaleFactor; - const char* bitsPerValue; - const char* decimalScaleFactor; - const char* referenceValue; - const char* floatType; -} grib_accessor_simple_packing_error; - -extern grib_accessor_class* grib_accessor_class_double; - -static grib_accessor_class _grib_accessor_class_simple_packing_error = { - &grib_accessor_class_double, /* super */ - "simple_packing_error", /* name */ - sizeof(grib_accessor_simple_packing_error), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_simple_packing_error = &_grib_accessor_class_simple_packing_error; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_simple_packing_error* self = (grib_accessor_simple_packing_error*)a; - int n = 0; - grib_handle* h = grib_handle_of_accessor(a); - - self->bitsPerValue = grib_arguments_get_name(h, c, n++); - self->binaryScaleFactor = grib_arguments_get_name(h, c, n++); - self->decimalScaleFactor = grib_arguments_get_name(h, c, n++); - self->referenceValue = grib_arguments_get_name(h, c, n++); - self->floatType = grib_arguments_get_name(h, c, n++); - - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length = 0; -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_simple_packing_error* self = (grib_accessor_simple_packing_error*)a; - - int ret = 0; - long binaryScaleFactor = 0; - long bitsPerValue = 0; - long decimalScaleFactor = 0; - double referenceValue = 0; - grib_handle* h = grib_handle_of_accessor(a); - - if ((ret = grib_get_long_internal(h, self->binaryScaleFactor, &binaryScaleFactor)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_get_long_internal(h, self->bitsPerValue, &bitsPerValue)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_get_long_internal(h, self->decimalScaleFactor, &decimalScaleFactor)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_get_double_internal(h, self->referenceValue, &referenceValue)) != GRIB_SUCCESS) - return ret; - - if (!strcmp(self->floatType, "ibm")) - *val = grib_ibmfloat_error(referenceValue); - else if (!strcmp(self->floatType, "ieee")) - *val = grib_ieeefloat_error(referenceValue); - else - Assert(1 == 0); - - if (bitsPerValue != 0) - *val = (*val + codes_power(binaryScaleFactor, 2)) * codes_power(-decimalScaleFactor, 10) * 0.5; - - if (ret == GRIB_SUCCESS) - *len = 1; - - return ret; -} diff --git a/src/grib_accessor_class_size.cc b/src/grib_accessor_class_size.cc deleted file mode 100644 index 410cec3c3..000000000 --- a/src/grib_accessor_class_size.cc +++ /dev/null @@ -1,119 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long - IMPLEMENTS = init - MEMBERS = const char* accessor - END_CLASS_DEF - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_size -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in size */ - const char* accessor; -} grib_accessor_size; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_size = { - &grib_accessor_class_long, /* super */ - "size", /* name */ - sizeof(grib_accessor_size), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_size = &_grib_accessor_class_size; - -/* END_CLASS_IMP */ - -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; -} - -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; -} diff --git a/src/grib_accessor_class_smart_table_column.cc b/src/grib_accessor_class_smart_table_column.cc deleted file mode 100644 index 295f29281..000000000 --- a/src/grib_accessor_class_smart_table_column.cc +++ /dev/null @@ -1,294 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init;dump;unpack_string_array;unpack_long - IMPLEMENTS = value_count; destroy; get_native_type; - MEMBERS = const char* smartTable - MEMBERS = int index - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string_array(grib_accessor*, char**, size_t* len); -static int value_count(grib_accessor*, long*); -static void destroy(grib_context*, grib_accessor*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_smart_table_column -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in smart_table_column */ - const char* smartTable; - int index; -} grib_accessor_smart_table_column; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_smart_table_column = { - &grib_accessor_class_gen, /* super */ - "smart_table_column", /* name */ - sizeof(grib_accessor_smart_table_column), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - &destroy, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - &unpack_string_array, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_smart_table_column = &_grib_accessor_class_smart_table_column; - -/* END_CLASS_IMP */ - -typedef struct grib_accessor_smart_table -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in unsigned */ - long nbytes; - grib_arguments* arg; - /* Members defined in smart_table */ - const char* values; - const char* tablename; - const char* masterDir; - const char* localDir; - const char* extraDir; - const char* extraTable; - int widthOfCode; - long* tableCodes; - size_t tableCodesSize; - grib_smart_table* table; - int dirty; -} grib_accessor_smart_table; - -static void init(grib_accessor* a, const long len, grib_arguments* params) -{ - int n = 0; - grib_accessor_smart_table_column* self = (grib_accessor_smart_table_column*)a; - - self->smartTable = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++); - self->index = grib_arguments_get_long(grib_handle_of_accessor(a), params, n++); - - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - int type = get_native_type(a); - - switch (type) { - case GRIB_TYPE_LONG: - grib_dump_long(dumper, a, NULL); - break; - case GRIB_TYPE_STRING: - grib_dump_string_array(dumper, a, NULL); - break; - } -} - -static int unpack_string_array(grib_accessor* a, char** buffer, size_t* len) -{ - grib_accessor_smart_table_column* self = (grib_accessor_smart_table_column*)a; - grib_accessor_smart_table* tableAccessor = NULL; - grib_smart_table* table = NULL; - - size_t size = 1; - long* code; - int err = GRIB_SUCCESS; - char tmp[1024] = {0,}; - int i = 0; - - tableAccessor = (grib_accessor_smart_table*)grib_find_accessor(grib_handle_of_accessor(a), self->smartTable); - if (!tableAccessor) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Unable to find accessor %s", self->smartTable); - return GRIB_NOT_FOUND; - } - - err = grib_get_size_acc(grib_handle_of_accessor(a), (grib_accessor*)tableAccessor, &size); - if (err) - return err; - if (*len < size) { - return GRIB_BUFFER_TOO_SMALL; - } - - code = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); - if (!code) { - grib_context_log(a->context, GRIB_LOG_FATAL, "%s: Memory allocation error: %zu bytes", a->name, size); - return GRIB_OUT_OF_MEMORY; - } - - if ((err = grib_unpack_long((grib_accessor*)tableAccessor, code, &size)) != GRIB_SUCCESS) - return err; - - table = tableAccessor->table; - - for (i = 0; i < size; i++) { - if (table && (code[i] >= 0) && - (code[i] < table->numberOfEntries) && - table->entries[code[i]].column[self->index]) { - strcpy(tmp, table->entries[code[i]].column[self->index]); - } - else { - snprintf(tmp, sizeof(tmp), "%d", (int)code[i]); - } - - buffer[i] = grib_context_strdup(a->context, tmp); - } - *len = size; - grib_context_free(a->context, code); - - return GRIB_SUCCESS; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_smart_table_column* self = (grib_accessor_smart_table_column*)a; - grib_accessor_smart_table* tableAccessor = NULL; - grib_smart_table* table = NULL; - - size_t size = 1; - long* code; - int err = GRIB_SUCCESS; - int i = 0; - - for (i = 0; i < *len; i++) - val[i] = GRIB_MISSING_LONG; - - tableAccessor = (grib_accessor_smart_table*)grib_find_accessor(grib_handle_of_accessor(a), self->smartTable); - if (!tableAccessor) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Unable to find accessor %s", self->smartTable); - return GRIB_NOT_FOUND; - } - - err = grib_get_size_acc(grib_handle_of_accessor(a), (grib_accessor*)tableAccessor, &size); - if (err) - return err; - if (*len < size) { - return GRIB_BUFFER_TOO_SMALL; - } - - code = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); - if (!code) return GRIB_OUT_OF_MEMORY; - - if ((err = grib_unpack_long((grib_accessor*)tableAccessor, code, &size)) != GRIB_SUCCESS) { - grib_context_free(a->context, code); - return err; - } - - table = tableAccessor->table; - - for (i = 0; i < size; i++) { - if (table && (code[i] >= 0) && - (code[i] < table->numberOfEntries) && - table->entries[code[i]].column[self->index]) { - val[i] = atol(table->entries[code[i]].column[self->index]); - } - } - *len = size; - grib_context_free(a->context, code); - - return GRIB_SUCCESS; -} - -static int value_count(grib_accessor* a, long* count) -{ - grib_accessor_smart_table_column* self = (grib_accessor_smart_table_column*)a; - size_t size = 0; - int err = 0; - *count = 0; - - if (!self->smartTable) - return 0; - - err = grib_get_size(grib_handle_of_accessor(a), self->smartTable, &size); - *count = size; - return err; -} - -static void destroy(grib_context* context, grib_accessor* a) -{ - if (a->vvalue != NULL) { - grib_context_free(context, a->vvalue); - a->vvalue = NULL; - } -} - -static int get_native_type(grib_accessor* a) -{ - int type = GRIB_TYPE_LONG; - /*printf("---------- %s flags=%ld GRIB_ACCESSOR_FLAG_STRING_TYPE=%d\n", - a->name,a->flags,GRIB_ACCESSOR_FLAG_STRING_TYPE);*/ - if (a->flags & GRIB_ACCESSOR_FLAG_STRING_TYPE) - type = GRIB_TYPE_STRING; - return type; -} diff --git a/src/grib_accessor_class_spd.cc b/src/grib_accessor_class_spd.cc deleted file mode 100644 index e0f4a20a7..000000000 --- a/src/grib_accessor_class_spd.cc +++ /dev/null @@ -1,264 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = init - IMPLEMENTS = next_offset - IMPLEMENTS = byte_count - IMPLEMENTS = value_count - IMPLEMENTS = byte_offset - IMPLEMENTS = update_size - MEMBERS = const char* numberOfBits - MEMBERS = const char* numberOfElements - - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static long byte_count(grib_accessor*); -static long byte_offset(grib_accessor*); -static long next_offset(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); -static void update_size(grib_accessor*, size_t); - -typedef struct grib_accessor_spd -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in spd */ - const char* numberOfBits; - const char* numberOfElements; -} grib_accessor_spd; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_spd = { - &grib_accessor_class_long, /* super */ - "spd", /* name */ - sizeof(grib_accessor_spd), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - &next_offset, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - &byte_count, /* get number of bytes */ - &byte_offset, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - &update_size, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_spd = &_grib_accessor_class_spd; - -/* END_CLASS_IMP */ - -static long byte_count(grib_accessor* a) -{ - return a->length; -} - -static long compute_byte_count(grib_accessor* a) -{ - grib_accessor_spd* self = (grib_accessor_spd*)a; - long numberOfBits; - long numberOfElements; - int ret = 0; - - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); - if (ret) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name, self->numberOfBits); - return 0; - } - - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements, &numberOfElements); - if (ret) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name, self->numberOfElements); - return 0; - } - numberOfElements++; - - return (numberOfBits * numberOfElements + 7) / 8; -} - -static void init(grib_accessor* a, const long len, grib_arguments* args) -{ - grib_accessor_spd* self = (grib_accessor_spd*)a; - int n = 0; - self->numberOfBits = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->numberOfElements = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - a->length = compute_byte_count(a); -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_spd* self = (grib_accessor_spd*)a; - int i; - int ret = 0; - long pos = a->offset * 8; - long rlen = 0; - long numberOfBits = 0; - - ret = value_count(a, &rlen); - if (ret) - return ret; - - if (*len < rlen) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Wrong size (%zu) for %s, it contains %ld values", *len, a->name, rlen); - *len = rlen; - return GRIB_ARRAY_TOO_SMALL; - } - - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); - if (ret) - return ret; - if (numberOfBits > 64) { - grib_context_log(a->context, GRIB_LOG_ERROR,"Invalid number of bits: %ld",numberOfBits); - return GRIB_DECODING_ERROR; - } - - for (i = 0; i < rlen - 1; i++) - val[i] = grib_decode_unsigned_long(grib_handle_of_accessor(a)->buffer->data, &pos, numberOfBits); - - val[rlen - 1] = grib_decode_signed_longb(grib_handle_of_accessor(a)->buffer->data, &pos, numberOfBits); - - *len = rlen; - - return GRIB_SUCCESS; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - grib_accessor_spd* self = (grib_accessor_spd*)a; - int ret = 0; - long off = 0; - long numberOfBits = 0; - size_t buflen = 0; - unsigned char* buf = NULL; - unsigned long i = 0; - long rlen = 0; - - ret = value_count(a, &rlen); - if (ret) - return ret; - - if (*len != rlen) { - ret = grib_set_long(grib_handle_of_accessor(a), self->numberOfElements, (*len) - 1); - if (ret) return ret; - } - - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); - if (ret) - return ret; - - buflen = compute_byte_count(a); - buf = (unsigned char*)grib_context_malloc_clear(a->context, buflen); - - for (i = 0; i < rlen - 1; i++) { - grib_encode_unsigned_longb(buf, val[i], &off, numberOfBits); - } - - grib_encode_signed_longb(buf, val[rlen - 1], &off, numberOfBits); - - grib_buffer_replace(a, buf, buflen, 1, 1); - - grib_context_free(a->context, buf); - - *len = rlen; - return ret; -} - -static int value_count(grib_accessor* a, long* numberOfElements) -{ - grib_accessor_spd* self = (grib_accessor_spd*)a; - int ret; - *numberOfElements = 0; - - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements, numberOfElements); - if (ret) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name, self->numberOfElements); - return ret; - } - (*numberOfElements)++; - - return ret; -} - -static long byte_offset(grib_accessor* a) -{ - return a->offset; -} - -static void update_size(grib_accessor* a, size_t s) -{ - a->length = s; -} - -static long next_offset(grib_accessor* a) -{ - return byte_offset(a) + a->length; -} diff --git a/src/grib_accessor_class_spectral_truncation.cc b/src/grib_accessor_class_spectral_truncation.cc deleted file mode 100644 index 6cc902fa7..000000000 --- a/src/grib_accessor_class_spectral_truncation.cc +++ /dev/null @@ -1,177 +0,0 @@ -/* - * (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. - */ - -/************************************** - * Enrico Fucile - **************************************/ - - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long - IMPLEMENTS = init - MEMBERS=const char* J - MEMBERS=const char* K - MEMBERS=const char* M - MEMBERS=const char* T - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_spectral_truncation -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in spectral_truncation */ - const char* J; - const char* K; - const char* M; - const char* T; -} grib_accessor_spectral_truncation; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_spectral_truncation = { - &grib_accessor_class_long, /* super */ - "spectral_truncation", /* name */ - sizeof(grib_accessor_spectral_truncation), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_spectral_truncation = &_grib_accessor_class_spectral_truncation; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_spectral_truncation* self = (grib_accessor_spectral_truncation*)a; - int n = 0; - - self->J = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->K = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->M = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->T = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_spectral_truncation* self = (grib_accessor_spectral_truncation*)a; - int ret = 0; - - long J, K, M, T, Tc; - - if (*len < 1) - return GRIB_ARRAY_TOO_SMALL; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->J, &J)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->K, &K)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->M, &M)) != GRIB_SUCCESS) - return ret; - - Tc = -1; - if (J == K && K == M) { - /* Triangular truncation */ - Tc = (M + 1) * (M + 2); - } - if (K == J + M) { - /* Rhomboidal truncation */ - Tc = 2 * J * M; - } - if (J == K && K > M) { - /* Trapezoidal truncation */ - Tc = M * (2 * J - M); - } - *val = Tc; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->T, &T)) != GRIB_SUCCESS) { - if (Tc == -1) - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s. Spectral Truncation Type Unknown: %s=%ld %s=%ld %s=%ld", - a->name, self->J, J, self->K, K, self->M, M); - Tc = 0; - grib_set_long(grib_handle_of_accessor(a), self->T, Tc); - } - else { - if (Tc != -1 && Tc != T) - grib_set_long(grib_handle_of_accessor(a), self->T, Tc); - } - - if (ret == GRIB_SUCCESS) - *len = 1; - - return ret; -} diff --git a/src/grib_accessor_class_statistics_spectral.cc b/src/grib_accessor_class_statistics_spectral.cc deleted file mode 100644 index 435582bef..000000000 --- a/src/grib_accessor_class_statistics_spectral.cc +++ /dev/null @@ -1,277 +0,0 @@ -/* - * (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. - */ - -/************************************** - * Enrico Fucile - **************************************/ - - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_abstract_vector - IMPLEMENTS = unpack_double; destroy - IMPLEMENTS = value_count;compare - IMPLEMENTS = init - MEMBERS = const char* values - MEMBERS = const char* J - MEMBERS = const char* K - MEMBERS = const char* M - MEMBERS = const char* JS - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void destroy(grib_context*, grib_accessor*); -static void init(grib_accessor*, const long, grib_arguments*); -static int compare(grib_accessor*, grib_accessor*); - -typedef struct grib_accessor_statistics_spectral -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in abstract_vector */ - double* v; - int number_of_elements; - /* Members defined in statistics_spectral */ - const char* values; - const char* J; - const char* K; - const char* M; - const char* JS; -} grib_accessor_statistics_spectral; - -extern grib_accessor_class* grib_accessor_class_abstract_vector; - -static grib_accessor_class _grib_accessor_class_statistics_spectral = { - &grib_accessor_class_abstract_vector, /* super */ - "statistics_spectral", /* name */ - sizeof(grib_accessor_statistics_spectral), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - &destroy, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - &compare, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_statistics_spectral = &_grib_accessor_class_statistics_spectral; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_statistics_spectral* self = (grib_accessor_statistics_spectral*)a; - int n = 0; - - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->J = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->K = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->M = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->JS = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - - self->number_of_elements = 4; - self->v = (double*)grib_context_malloc(a->context, - sizeof(double) * self->number_of_elements); - - a->length = 0; - a->dirty = 1; -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_statistics_spectral* self = (grib_accessor_statistics_spectral*)a; - int ret = 0, i = 0; - double* values; - size_t size = 0; - long J, K, M, N; - double avg, enorm, sd; - grib_context* c = a->context; - grib_handle* h = grib_handle_of_accessor(a); - - if (!a->dirty) - return GRIB_SUCCESS; - - if (*len != self->number_of_elements) - return GRIB_ARRAY_TOO_SMALL; - - if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_get_long(grib_handle_of_accessor(a), self->J, &J)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_get_long(grib_handle_of_accessor(a), self->K, &K)) != GRIB_SUCCESS) - return ret; - - if ((ret = grib_get_long(grib_handle_of_accessor(a), self->M, &M)) != GRIB_SUCCESS) - return ret; - - if (J != M || M != K) - return GRIB_NOT_IMPLEMENTED; - - N = (M + 1) * (M + 2) / 2; - - if (2 * N != size) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "wrong number of components for spherical harmonics %ld != %ld", 2 * N, size); - return GRIB_WRONG_ARRAY_SIZE; - } - - values = (double*)grib_context_malloc(c, size * sizeof(double)); - if (!values) - return GRIB_OUT_OF_MEMORY; - - if ((ret = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) { - grib_context_free(c, values); - return ret; - } - - avg = values[0]; - sd = 0; - - for (i = 2; i < 2 * J; i += 2) - sd += values[i] * values[i]; - - for (i = 2 * J; i < size; i += 2) - sd += 2 * values[i] * values[i] + 2 * values[i + 1] * values[i + 1]; - - enorm = sd + avg * avg; - - sd = sqrt(sd); - enorm = sqrt(enorm); - - a->dirty = 0; - - grib_context_free(c, values); - - self->v[0] = avg; - self->v[1] = enorm; - self->v[2] = sd; - self->v[3] = sd == 0 ? 1 : 0; - - for (i = 0; i < self->number_of_elements; i++) - val[i] = self->v[i]; - - return ret; -} - -static int value_count(grib_accessor* a, long* count) -{ - grib_accessor_statistics_spectral* self = (grib_accessor_statistics_spectral*)a; - *count = self->number_of_elements; - return 0; -} - -static void destroy(grib_context* c, grib_accessor* a) -{ - grib_accessor_statistics_spectral* self = (grib_accessor_statistics_spectral*)a; - grib_context_free(c, self->v); -} - -static int compare(grib_accessor* a, grib_accessor* b) -{ - int retval = GRIB_SUCCESS; - double* aval = 0; - double* bval = 0; - - size_t alen = 0; - size_t blen = 0; - int err = 0; - long count = 0; - - err = grib_value_count(a, &count); - if (err) - return err; - alen = count; - - err = grib_value_count(b, &count); - if (err) - return err; - blen = count; - - if (alen != blen) - return GRIB_COUNT_MISMATCH; - - aval = (double*)grib_context_malloc(a->context, alen * sizeof(double)); - bval = (double*)grib_context_malloc(b->context, blen * sizeof(double)); - - b->dirty = 1; - a->dirty = 1; - - grib_unpack_double(a, aval, &alen); - grib_unpack_double(b, bval, &blen); - - retval = GRIB_SUCCESS; - for (size_t i=0; icontext, aval); - grib_context_free(b->context, bval); - - return retval; -} diff --git a/src/grib_accessor_class_step_human_readable.cc b/src/grib_accessor_class_step_human_readable.cc deleted file mode 100644 index 557a58185..000000000 --- a/src/grib_accessor_class_step_human_readable.cc +++ /dev/null @@ -1,169 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -#include "step.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init;unpack_string; get_native_type - MEMBERS = const char* stepUnits - MEMBERS = const char* step - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_string(grib_accessor*, char*, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_step_human_readable -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in step_human_readable */ - const char* stepUnits; - const char* step; -} grib_accessor_step_human_readable; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_step_human_readable = { - &grib_accessor_class_gen, /* super */ - "step_human_readable", /* name */ - sizeof(grib_accessor_step_human_readable), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_step_human_readable = &_grib_accessor_class_step_human_readable; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* params) -{ - grib_accessor_step_human_readable* self = (grib_accessor_step_human_readable*)a; - int n = 0; - grib_handle* h = grib_handle_of_accessor(a); - - self->stepUnits = grib_arguments_get_name(h, params, n++); - self->step = grib_arguments_get_name(h, params, n++); - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_STRING; -} - -static int get_step_human_readable(grib_handle* h, char* result, size_t* length) -{ - int err = 0; - size_t slen = 2; - long step, hour, minute, second; - - /* Change units to seconds (highest resolution) - * before computing the step value - */ - if ((err = grib_set_string(h, "stepUnits", "s", &slen)) != GRIB_SUCCESS) - return err; - if ((err = grib_get_long(h, "step", &step)) != GRIB_SUCCESS) - return err; - - hour = step/3600; - minute = step/60 % 60; - second = step % 60; - /* sprintf(result, "%ld:%ld:%ld", hour, minute, second); */ - - if (second) { - snprintf(result, 1024, "%ldh %ldm %lds", hour, minute, second); - } else { - if (minute) snprintf(result, 1024, "%ldh %ldm", hour, minute); - else snprintf(result, 1024, "%ldh", hour); - } - - *length = strlen(result); - return GRIB_SUCCESS; -} - -static int unpack_string(grib_accessor* a, char* buffer, size_t* len) -{ - grib_accessor_step_human_readable* self = (grib_accessor_step_human_readable*)a; - grib_handle* h = grib_handle_of_accessor(a); - long stepUnits; - int err = 0; - - /* Save the current value of stepUnits */ - err = grib_get_long_internal(h, self->stepUnits, &stepUnits); - if (err) return err; - - /* This will change stepUnits to seconds for its calculation */ - err = get_step_human_readable(h, buffer, len); - - /* Restore stepUnits */ - grib_set_long(h, self->stepUnits, stepUnits); - return err; -} diff --git a/src/grib_accessor_class_sum.cc b/src/grib_accessor_class_sum.cc deleted file mode 100644 index 4d964fc0c..000000000 --- a/src/grib_accessor_class_sum.cc +++ /dev/null @@ -1,203 +0,0 @@ -/* - * (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. - */ - -/************************************** - * Enrico Fucile - **************************************/ - - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_double - IMPLEMENTS = unpack_long - IMPLEMENTS = unpack_double - IMPLEMENTS = value_count - IMPLEMENTS = init - MEMBERS=const char* values - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_sum -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in sum */ - const char* values; -} grib_accessor_sum; - -extern grib_accessor_class* grib_accessor_class_double; - -static grib_accessor_class _grib_accessor_class_sum = { - &grib_accessor_class_double, /* super */ - "sum", /* name */ - sizeof(grib_accessor_sum), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_sum = &_grib_accessor_class_sum; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_sum* self = (grib_accessor_sum*)a; - int n = 0; - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_sum* self = (grib_accessor_sum*)a; - int ret = 0; - size_t size = 0; - long* values = 0; - long i; - long count = 0; - - ret = value_count(a, &count); - if (ret) - return ret; - size = count; - - if (size == 0) { - *val = 0; - return GRIB_SUCCESS; - } - values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); - if (!values) - return GRIB_OUT_OF_MEMORY; - - grib_get_long_array(grib_handle_of_accessor(a), self->values, values, &size); - - *val = 0; - for (i = 0; i < size; i++) - *val += values[i]; - - grib_context_free(a->context, values); - - return GRIB_SUCCESS; -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_sum* self = (grib_accessor_sum*)a; - int ret = 0; - size_t size = 0; - double* values = 0; - long i; - long count = 0; - - ret = value_count(a, &count); - if (ret) - return ret; - size = count; - - if (size == 0) { - *val = 0; - return GRIB_SUCCESS; - } - values = (double*)grib_context_malloc_clear(a->context, sizeof(double) * size); - if (!values) - return GRIB_OUT_OF_MEMORY; - - ret = grib_get_double_array(grib_handle_of_accessor(a), self->values, values, &size); - if (ret) { - grib_context_free(a->context, values); - return ret; - } - *val = 0; - for (i = 0; i < size; i++) - *val += values[i]; - - grib_context_free(a->context, values); - - return GRIB_SUCCESS; -} - -static int value_count(grib_accessor* a, long* count) -{ - grib_accessor_sum* self = (grib_accessor_sum*)a; - size_t n = 0; - int ret = 0; - - ret = grib_get_size(grib_handle_of_accessor(a), self->values, &n); - *count = n; - - if (ret) - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s is unable to get size of %s", a->name, self->values); - - return ret; -} diff --git a/src/grib_accessor_class_suppressed.cc b/src/grib_accessor_class_suppressed.cc deleted file mode 100644 index a95269c5d..000000000 --- a/src/grib_accessor_class_suppressed.cc +++ /dev/null @@ -1,162 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = value_count;get_native_type - IMPLEMENTS = unpack_string - IMPLEMENTS = unpack_long - IMPLEMENTS = unpack_double - IMPLEMENTS = init - MEMBERS= grib_arguments* args - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_suppressed -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in suppressed */ - grib_arguments* args; -} grib_accessor_suppressed; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_suppressed = { - &grib_accessor_class_long, /* super */ - "suppressed", /* name */ - sizeof(grib_accessor_suppressed), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_suppressed = &_grib_accessor_class_suppressed; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_suppressed* self = (grib_accessor_suppressed*)a; - self->args = c; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->length = 0; -} - -static void log_message(grib_accessor* a) -{ - grib_accessor_suppressed* self = (grib_accessor_suppressed*)a; - int i = 0; - grib_handle* hand = grib_handle_of_accessor(a); - - grib_context_log(a->context, GRIB_LOG_ERROR, - "key '%s' is unavailable in this version.", a->name); - grib_context_log(a->context, GRIB_LOG_ERROR, - "Please use the following key(s):"); - while (grib_arguments_get_name(hand, self->args, i)) { - grib_context_log(a->context, GRIB_LOG_ERROR, "\t- %s", - grib_arguments_get_name(hand, self->args, i)); - i++; - } -} - -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - log_message(a); - return GRIB_NOT_FOUND; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - log_message(a); - return GRIB_NOT_FOUND; -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - log_message(a); - return GRIB_NOT_FOUND; -} - -static int value_count(grib_accessor* a, long* count) -{ - *count = 1; - return 0; -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_STRING; -} diff --git a/src/grib_accessor_class_time.cc b/src/grib_accessor_class_time.cc deleted file mode 100644 index 3251fdd33..000000000 --- a/src/grib_accessor_class_time.cc +++ /dev/null @@ -1,208 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = unpack_string - IMPLEMENTS = init - MEMBERS=const char* hour - MEMBERS=const char* minute - MEMBERS=const char* second - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_time -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in time */ - const char* hour; - const char* minute; - const char* second; -} grib_accessor_time; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_time = { - &grib_accessor_class_long, /* super */ - "time", /* name */ - sizeof(grib_accessor_time), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_time = &_grib_accessor_class_time; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_time* self = (grib_accessor_time*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int n = 0; - - self->hour = grib_arguments_get_name(hand, c, n++); - self->minute = grib_arguments_get_name(hand, c, n++); - self->second = grib_arguments_get_name(hand, c, n++); -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - const grib_accessor_time* self = (grib_accessor_time*)a; - - int ret = 0; - long hour = 0, minute = 0, second = 0; - grib_handle* hand = grib_handle_of_accessor(a); - - if ((ret = grib_get_long_internal(hand, self->hour, &hour)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_get_long_internal(hand, self->minute, &minute)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_get_long_internal(hand, self->second, &second)) != GRIB_SUCCESS) - return ret; - - /* We ignore the 'seconds' in our time calculation! */ - if (second != 0) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Key %s (%s): Truncating time: non-zero seconds(%ld) ignored", a->name, __func__, second); - } - - if (*len < 1) - return GRIB_WRONG_ARRAY_SIZE; - - *val = hour * 100 + minute; - - if (hour == 255) { - *val = 12 * 100; - } - if (hour != 255 && minute == 255) { - *val = hour * 100; - } - return GRIB_SUCCESS; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - const grib_accessor_time* self = (grib_accessor_time*)a; - - int ret = 0; - long v = val[0]; - grib_handle* hand = grib_handle_of_accessor(a); - long hour = 0, minute = 0, second = 0; - - if (*len != 1) - return GRIB_WRONG_ARRAY_SIZE; - - if (!is_time_valid(v)) { - // ECC-1777: For now just a warning. Will later change to an error - fprintf(stderr, "ECCODES WARNING : %s:%s: Time is not valid! hour=%ld min=%ld sec=%ld\n", - a->cclass->name, __func__, hour, minute, second); - // return GRIB_ENCODING_ERROR; - } - - hour = v / 100; - minute = v % 100; - second = 0; /* We ignore the 'seconds' in our time calculation! */ - - if ((ret = grib_set_long_internal(hand, self->hour, hour)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_set_long_internal(hand, self->minute, minute)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_set_long_internal(hand, self->second, second)) != GRIB_SUCCESS) - return ret; - - return GRIB_SUCCESS; -} - -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - long v = 0; - size_t lsize = 1, lmin = 5; - - unpack_long(a, &v, &lsize); - - if (*len < lmin) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - a->cclass->name, a->name, lmin, *len); - *len = lmin; - return GRIB_BUFFER_TOO_SMALL; - } - - snprintf(val, 64, "%04ld", v); - - len[0] = lmin; - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_to_double.cc b/src/grib_accessor_class_to_double.cc deleted file mode 100644 index 69b06add9..000000000 --- a/src/grib_accessor_class_to_double.cc +++ /dev/null @@ -1,241 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = unpack_string - IMPLEMENTS = unpack_long - IMPLEMENTS = unpack_double - IMPLEMENTS = init;dump;string_length - IMPLEMENTS = value_count - IMPLEMENTS = next_offset - IMPLEMENTS = get_native_type - MEMBERS = const char* key - MEMBERS = long start - MEMBERS = size_t length - MEMBERS = long scale - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static size_t string_length(grib_accessor*); -static long next_offset(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_to_double -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in to_double */ - const char* key; - long start; - size_t length; - long scale; -} grib_accessor_to_double; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_to_double = { - &grib_accessor_class_gen, /* super */ - "to_double", /* name */ - sizeof(grib_accessor_to_double), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - &next_offset, /* next_offset */ - &string_length, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_to_double = &_grib_accessor_class_to_double; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - grib_accessor_to_double* self = (grib_accessor_to_double*)a; - - self->key = grib_arguments_get_name(grib_handle_of_accessor(a), arg, 0); - self->start = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 1); - self->length = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 2); - self->scale = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 3); - if (!self->scale) - self->scale = 1; - - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length = 0; -} - -static int value_count(grib_accessor* a, long* count) -{ - grib_accessor_to_double* self = (grib_accessor_to_double*)a; - size_t size = 0; - - int err = grib_get_size(grib_handle_of_accessor(a), self->key, &size); - *count = size; - - return err; -} - -static size_t string_length(grib_accessor* a) -{ - grib_accessor_to_double* self = (grib_accessor_to_double*)a; - size_t size = 0; - - if (self->length) - return self->length; - - grib_get_string_length_acc(a, &size); - return size; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_string(dumper, a, NULL); -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_LONG; -} - -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - grib_accessor_to_double* self = (grib_accessor_to_double*)a; - - int err = 0; - char buff[512] = {0,}; - size_t size = 512; - size_t length = string_length(a); - - if (*len < length + 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%lu) for %s, it contains %ld values", - *len, a->name, a->length + 1); - *len = length + 1; - return GRIB_ARRAY_TOO_SMALL; - } - - err = grib_get_string(grib_handle_of_accessor(a), self->key, buff, &size); - if (err) - return err; - if (length > size) { - err = GRIB_STRING_TOO_SMALL; - length = size; - } - - memcpy(val, buff + self->start, length); - - val[length] = 0; - *len = length; - return err; -} - -static int unpack_long(grib_accessor* a, long* v, size_t* len) -{ - grib_accessor_to_double* self = (grib_accessor_to_double*)a; - char val[1024] = {0,}; - size_t l = sizeof(val); - char* last = NULL; - int err = grib_unpack_string(a, val, &l); - - if (err) - return err; - - *v = strtol(val, &last, 10); - if (*last) { - err = GRIB_WRONG_CONVERSION; - } - *v /= self->scale; - - return err; -} - -static int unpack_double(grib_accessor* a, double* v, size_t* len) -{ - grib_accessor_to_double* self = (grib_accessor_to_double*)a; - char val[1024] = {0,}; - size_t l = sizeof(val); - char* last = NULL; - int err = grib_unpack_string(a, val, &l); - - if (err) - return err; - - *v = strtod(val, &last); - if (*last) { - err = GRIB_WRONG_CONVERSION; - } - *v /= self->scale; - - return err; -} - -static long next_offset(grib_accessor* a) -{ - return a->offset + a->length; -} diff --git a/src/grib_accessor_class_to_integer.cc b/src/grib_accessor_class_to_integer.cc deleted file mode 100644 index 76ce1205d..000000000 --- a/src/grib_accessor_class_to_integer.cc +++ /dev/null @@ -1,245 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = unpack_string;pack_string - IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = unpack_double;pack_double - IMPLEMENTS = init;dump;string_length - IMPLEMENTS = value_count - IMPLEMENTS = next_offset - IMPLEMENTS = get_native_type - MEMBERS = const char* key - MEMBERS = long start - MEMBERS = size_t length - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int pack_string(grib_accessor*, const char*, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static size_t string_length(grib_accessor*); -static long next_offset(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_to_integer -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in to_integer */ - const char* key; - long start; - size_t length; -} grib_accessor_to_integer; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_to_integer = { - &grib_accessor_class_gen, /* super */ - "to_integer", /* name */ - sizeof(grib_accessor_to_integer), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - &next_offset, /* next_offset */ - &string_length, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - &pack_string, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_to_integer = &_grib_accessor_class_to_integer; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - grib_accessor_to_integer* self = (grib_accessor_to_integer*)a; - - self->key = grib_arguments_get_name(grib_handle_of_accessor(a), arg, 0); - self->start = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 1); - self->length = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 2); - - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length = 0; -} - -static int value_count(grib_accessor* a, long* count) -{ - grib_accessor_to_integer* self = (grib_accessor_to_integer*)a; - size_t size = 0; - - int err = grib_get_size(grib_handle_of_accessor(a), self->key, &size); - *count = size; - - return err; -} - -static size_t string_length(grib_accessor* a) -{ - grib_accessor_to_integer* self = (grib_accessor_to_integer*)a; - size_t size = 0; - - if (self->length) - return self->length; - - grib_get_string_length(grib_handle_of_accessor(a), self->key, &size); - return size; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_long(dumper, a, NULL); -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_LONG; -} - -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - grib_accessor_to_integer* self = (grib_accessor_to_integer*)a; - - int err = 0; - char buff[512] = {0,}; - size_t size = 512; - - size_t length = string_length(a); - - if (*len < length + 1) { - const char* cclass_name = a->cclass->name; - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, length+1, *len); - *len = length + 1; - return GRIB_BUFFER_TOO_SMALL; - } - - err = grib_get_string(grib_handle_of_accessor(a), self->key, buff, &size); - if (err) - return err; - if (length > size) { - /*err=GRIB_STRING_TOO_SMALL;*/ - length = size; - } - - memcpy(val, buff + self->start, length); - - val[length] = 0; - *len = length; - return GRIB_SUCCESS; -} - -static int pack_string(grib_accessor* a, const char* val, size_t* len) -{ - return GRIB_NOT_IMPLEMENTED; -} - -static int pack_long(grib_accessor* a, const long* v, size_t* len) -{ - grib_context_log(a->context, GRIB_LOG_ERROR, "Should not pack %s as an integer", a->name); - return GRIB_NOT_IMPLEMENTED; -} - -static int pack_double(grib_accessor* a, const double* v, size_t* len) -{ - grib_context_log(a->context, GRIB_LOG_ERROR, "Should not pack %s as a double", a->name); - return GRIB_NOT_IMPLEMENTED; -} - -static int unpack_long(grib_accessor* a, long* v, size_t* len) -{ - char val[1024] = {0,}; - size_t l = sizeof(val); - char* last = NULL; - int err = unpack_string(a, val, &l); - - if (err) - return err; - - *v = strtol(val, &last, 10); - /* if (*last) {err=GRIB_WRONG_CONVERSION;} */ - - return GRIB_SUCCESS; -} - -static int unpack_double(grib_accessor* a, double* v, size_t* len) -{ - size_t l = 1; - long val = 0; - int err = unpack_long(a, &val, &l); - - *v = (double)val; - return err; -} - -static long next_offset(grib_accessor* a) -{ - return a->offset + a->length; -} diff --git a/src/grib_accessor_class_to_string.cc b/src/grib_accessor_class_to_string.cc deleted file mode 100644 index 648edd1aa..000000000 --- a/src/grib_accessor_class_to_string.cc +++ /dev/null @@ -1,227 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = unpack_string - IMPLEMENTS = unpack_long - IMPLEMENTS = unpack_double - IMPLEMENTS = init;dump;string_length - IMPLEMENTS = value_count - IMPLEMENTS = next_offset - IMPLEMENTS = get_native_type - MEMBERS = const char* key - MEMBERS = long start - MEMBERS = size_t length - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static size_t string_length(grib_accessor*); -static long next_offset(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_to_string -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in to_string */ - const char* key; - long start; - size_t length; -} grib_accessor_to_string; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_to_string = { - &grib_accessor_class_gen, /* super */ - "to_string", /* name */ - sizeof(grib_accessor_to_string), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - &next_offset, /* next_offset */ - &string_length, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_to_string = &_grib_accessor_class_to_string; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - grib_accessor_to_string* self = (grib_accessor_to_string*)a; - - self->key = grib_arguments_get_name(grib_handle_of_accessor(a), arg, 0); - self->start = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 1); - self->length = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 2); - - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length = 0; -} - -static int value_count(grib_accessor* a, long* count) -{ - grib_accessor_to_string* self = (grib_accessor_to_string*)a; - size_t size = 0; - - int err = grib_get_size(grib_handle_of_accessor(a), self->key, &size); - *count = size; - - return err; -} - -static size_t string_length(grib_accessor* a) -{ - grib_accessor_to_string* self = (grib_accessor_to_string*)a; - - if (self->length) - return self->length; - - size_t size = 0; - grib_get_string_length(grib_handle_of_accessor(a), self->key, &size); - return size; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_string(dumper, a, NULL); -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_STRING; -} - -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - grib_accessor_to_string* self = (grib_accessor_to_string*)a; - - int err = 0; - char buff[512] = {0,}; - - size_t length = string_length(a); - - if (*len < length + 1) { - const char* cclass_name = a->cclass->name; - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, length+1, *len); - *len = length + 1; - return GRIB_BUFFER_TOO_SMALL; - } - - size_t size = sizeof(buff); - err = grib_get_string(grib_handle_of_accessor(a), self->key, buff, &size); - if (err) - return err; - if (length > size) { - /*err=GRIB_STRING_TOO_SMALL;*/ - length = size; - } - - memcpy(val, buff + self->start, length); - - val[length] = 0; - *len = length; - return GRIB_SUCCESS; -} - -static int unpack_long(grib_accessor* a, long* v, size_t* len) -{ - char val[1024] = {0,}; - size_t l = sizeof(val); - char* last = NULL; - int err = unpack_string(a, val, &l); - - if (err) - return err; - - *v = strtol(val, &last, 10); - if (*last) { - err = GRIB_WRONG_CONVERSION; - } - - return err; -} - -static int unpack_double(grib_accessor* a, double* v, size_t* len) -{ - size_t l = 1; - long val = 0; - int err = unpack_long(a, &val, &l); - - *v = (double)val; - return err; -} - -static long next_offset(grib_accessor* a) -{ - return a->offset + a->length; -} diff --git a/src/grib_accessor_class_transient.cc b/src/grib_accessor_class_transient.cc deleted file mode 100644 index c51886c20..000000000 --- a/src/grib_accessor_class_transient.cc +++ /dev/null @@ -1,100 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_variable - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - - -typedef struct grib_accessor_transient -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in variable */ - double dval; - float fval; - char* cval; - char* cname; - int type; - /* Members defined in transient */ -} grib_accessor_transient; - -extern grib_accessor_class* grib_accessor_class_variable; - -static grib_accessor_class _grib_accessor_class_transient = { - &grib_accessor_class_variable, /* super */ - "transient", /* name */ - sizeof(grib_accessor_transient), /* size */ - 0, /* inited */ - 0, /* init_class */ - 0, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_transient = &_grib_accessor_class_transient; - -/* END_CLASS_IMP */ diff --git a/src/grib_accessor_class_transient_darray.cc b/src/grib_accessor_class_transient_darray.cc deleted file mode 100644 index 51dbc2433..000000000 --- a/src/grib_accessor_class_transient_darray.cc +++ /dev/null @@ -1,216 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = unpack_double;pack_double - IMPLEMENTS = unpack_long;pack_long;destroy - IMPLEMENTS = init;dump;value_count - IMPLEMENTS = get_native_type - MEMBERS=grib_darray* arr - MEMBERS=int type; - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int value_count(grib_accessor*, long*); -static void destroy(grib_context*, grib_accessor*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_transient_darray -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in transient_darray */ - grib_darray* arr; - int type; -} grib_accessor_transient_darray; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_transient_darray = { - &grib_accessor_class_gen, /* super */ - "transient_darray", /* name */ - sizeof(grib_accessor_transient_darray), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - &destroy, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_transient_darray = &_grib_accessor_class_transient_darray; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long length, grib_arguments* args) -{ - grib_accessor_transient_darray* self = (grib_accessor_transient_darray*)a; - self->arr = NULL; - self->type = GRIB_TYPE_DOUBLE; - a->length = 0; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_double(dumper, a, NULL); -} - -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_transient_darray* self = (grib_accessor_transient_darray*)a; - - if (self->arr) - grib_darray_delete(a->context, self->arr); - self->arr = grib_darray_new(a->context, *len, 10); - - for (size_t i = 0; i < *len; i++) - grib_darray_push(a->context, self->arr, val[i]); - - return GRIB_SUCCESS; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - grib_accessor_transient_darray* self = (grib_accessor_transient_darray*)a; - - if (self->arr) - grib_darray_delete(a->context, self->arr); - self->arr = grib_darray_new(a->context, *len, 10); - - for (size_t i = 0; i < *len; i++) - grib_darray_push(a->context, self->arr, (double)val[i]); - - return GRIB_SUCCESS; -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_transient_darray* self = (grib_accessor_transient_darray*)a; - long count = 0; - - value_count(a, &count); - - if (*len < count) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s (setting %zu, required %ld)", a->name, *len, count); - *len = count; - return GRIB_ARRAY_TOO_SMALL; - } - - *len = count; - for (size_t i = 0; i < *len; i++) - val[i] = self->arr->v[i]; - - return GRIB_SUCCESS; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_transient_darray* self = (grib_accessor_transient_darray*)a; - long count = 0; - - value_count(a, &count); - - if (*len < count) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s (setting %zu, required %ld)", a->name, *len, count); - *len = count; - return GRIB_ARRAY_TOO_SMALL; - } - - *len = count; - for (size_t i = 0; i < *len; i++) - val[i] = (long)self->arr->v[i]; - - return GRIB_SUCCESS; -} - -static void destroy(grib_context* c, grib_accessor* a) -{ - grib_accessor_transient_darray* self = (grib_accessor_transient_darray*)a; - if (self->arr) - grib_darray_delete(a->context, self->arr); -} - -static int value_count(grib_accessor* a, long* count) -{ - grib_accessor_transient_darray* self = (grib_accessor_transient_darray*)a; - if (self->arr) - *count = grib_darray_used_size(self->arr); - else - *count = 0; - - return 0; -} - -static int get_native_type(grib_accessor* a) -{ - const grib_accessor_transient_darray* self = (grib_accessor_transient_darray*)a; - return self->type; -} diff --git a/src/grib_accessor_class_trim.cc b/src/grib_accessor_class_trim.cc deleted file mode 100644 index 21948ab82..000000000 --- a/src/grib_accessor_class_trim.cc +++ /dev/null @@ -1,170 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_ascii - IMPLEMENTS = unpack_string;pack_string - IMPLEMENTS = init; string_length - MEMBERS= const char* input - MEMBERS= int trim_left - MEMBERS= int trim_right - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_string(grib_accessor*, const char*, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static size_t string_length(grib_accessor*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_trim -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in ascii */ - /* Members defined in trim */ - const char* input; - int trim_left; - int trim_right; -} grib_accessor_trim; - -extern grib_accessor_class* grib_accessor_class_ascii; - -static grib_accessor_class _grib_accessor_class_trim = { - &grib_accessor_class_ascii, /* super */ - "trim", /* name */ - sizeof(grib_accessor_trim), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - &string_length, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - &pack_string, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_trim = &_grib_accessor_class_trim; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long l, grib_arguments* arg) -{ - int n = 0; - grib_accessor_trim* self = (grib_accessor_trim*)a; - grib_handle* h = grib_handle_of_accessor(a); - - self->input = grib_arguments_get_name(h, arg, n++); - self->trim_left = grib_arguments_get_long(h, arg, n++); - self->trim_right= grib_arguments_get_long(h, arg, n++); - DEBUG_ASSERT(self->trim_left == 0 || self->trim_left == 1); - DEBUG_ASSERT(self->trim_right == 0 || self->trim_right == 1); -} - -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - grib_accessor_trim* self = (grib_accessor_trim*)a; - - int err = 0; - grib_handle* h = grib_handle_of_accessor(a); - char input[256] = {0,}; - size_t size = sizeof(input) / sizeof(*input); - char* pInput = input; - - err = grib_get_string(h, self->input, input, &size); - if (err) return err; - - string_lrtrim(&pInput, self->trim_left, self->trim_right); - snprintf(val, 1024, "%s", pInput); - size = strlen(val); - *len = size + 1; - return GRIB_SUCCESS; -} - -static int pack_string(grib_accessor* a, const char* val, size_t* len) -{ - char input[256] = {0,}; - - size_t inputLen = 256; - char buf[256] = {0,}; - char* pBuf = NULL; - int err; - grib_handle* h = grib_handle_of_accessor(a); - grib_accessor_trim* self = (grib_accessor_trim*)a; - grib_accessor* inputAccesstor = grib_find_accessor(h, self->input); - if (!inputAccesstor) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Accessor for %s not found", self->input); - return GRIB_NOT_FOUND; - } - - if ((err = grib_get_string(h, self->input, input, &inputLen)) != GRIB_SUCCESS) - return err; - - snprintf(buf, sizeof(buf), "%s", val); - pBuf = buf; - string_lrtrim(&pBuf, self->trim_left, self->trim_right); - - return grib_pack_string(inputAccesstor, pBuf, len); -} - -static size_t string_length(grib_accessor* a) -{ - return 1024; -} diff --git a/src/grib_accessor_class_uint16.cc b/src/grib_accessor_class_uint16.cc deleted file mode 100644 index 4bac26b59..000000000 --- a/src/grib_accessor_class_uint16.cc +++ /dev/null @@ -1,118 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = unpack_long - IMPLEMENTS = get_native_type - END_CLASS_DEF - -*/ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_long(grib_accessor*, long* val, size_t* len); - -typedef struct grib_accessor_uint16 -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in uint16 */ -} grib_accessor_uint16; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_uint16 = { - &grib_accessor_class_gen, /* super */ - "uint16", /* name */ - sizeof(grib_accessor_uint16), /* size */ - 0, /* inited */ - 0, /* init_class */ - 0, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_uint16 = &_grib_accessor_class_uint16; - -/* END_CLASS_IMP */ - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - long value = 0; - /*long pos = a->offset;*/ - /*unsigned char* data = grib_handle_of_accessor(a)->buffer->data;*/ - - if (*len < 1) { - return GRIB_ARRAY_TOO_SMALL; - } - - *val = value; - *len = 1; - return GRIB_NOT_IMPLEMENTED; -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_LONG; -} diff --git a/src/grib_accessor_class_uint32.cc b/src/grib_accessor_class_uint32.cc deleted file mode 100644 index b45b7451f..000000000 --- a/src/grib_accessor_class_uint32.cc +++ /dev/null @@ -1,118 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = unpack_long - IMPLEMENTS = get_native_type - END_CLASS_DEF - -*/ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_long(grib_accessor*, long* val, size_t* len); - -typedef struct grib_accessor_uint32 -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in uint32 */ -} grib_accessor_uint32; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_uint32 = { - &grib_accessor_class_gen, /* super */ - "uint32", /* name */ - sizeof(grib_accessor_uint32), /* size */ - 0, /* inited */ - 0, /* init_class */ - 0, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_uint32 = &_grib_accessor_class_uint32; - -/* END_CLASS_IMP */ - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - long value = 0; - /* long pos = a->offset; */ - /* unsigned char* data = grib_handle_of_accessor(a)->buffer->data; */ - - if (*len < 1) { - return GRIB_ARRAY_TOO_SMALL; - } - - *val = value; - *len = 1; - return GRIB_NOT_IMPLEMENTED; -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_LONG; -} diff --git a/src/grib_accessor_class_uint32_little_endian.cc b/src/grib_accessor_class_uint32_little_endian.cc deleted file mode 100644 index 3e39e0586..000000000 --- a/src/grib_accessor_class_uint32_little_endian.cc +++ /dev/null @@ -1,118 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = unpack_long - IMPLEMENTS = get_native_type - END_CLASS_DEF - -*/ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_long(grib_accessor*, long* val, size_t* len); - -typedef struct grib_accessor_uint32_little_endian -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in uint32_little_endian */ -} grib_accessor_uint32_little_endian; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_uint32_little_endian = { - &grib_accessor_class_gen, /* super */ - "uint32_little_endian", /* name */ - sizeof(grib_accessor_uint32_little_endian), /* size */ - 0, /* inited */ - 0, /* init_class */ - 0, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_uint32_little_endian = &_grib_accessor_class_uint32_little_endian; - -/* END_CLASS_IMP */ - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - long value = 0; - /* long pos = a->offset; */ - /* unsigned char* data = grib_handle_of_accessor(a)->buffer->data; */ - - if (*len < 1) { - return GRIB_ARRAY_TOO_SMALL; - } - - *val = value; - *len = 1; - return GRIB_NOT_IMPLEMENTED; -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_LONG; -} diff --git a/src/grib_accessor_class_uint64.cc b/src/grib_accessor_class_uint64.cc deleted file mode 100644 index 20bd7e194..000000000 --- a/src/grib_accessor_class_uint64.cc +++ /dev/null @@ -1,134 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = unpack_long - IMPLEMENTS = get_native_type - END_CLASS_DEF - -*/ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_long(grib_accessor*, long* val, size_t* len); - -typedef struct grib_accessor_uint64 -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in uint64 */ -} grib_accessor_uint64; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_uint64 = { - &grib_accessor_class_gen, /* super */ - "uint64", /* name */ - sizeof(grib_accessor_uint64), /* size */ - 0, /* inited */ - 0, /* init_class */ - 0, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_uint64 = &_grib_accessor_class_uint64; - -/* END_CLASS_IMP */ - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - long value = 0; - long pos = a->offset; - unsigned char* data = grib_handle_of_accessor(a)->buffer->data; - unsigned long long result = 0, tmp; - int i; - - if (*len < 1) { - return GRIB_ARRAY_TOO_SMALL; - } - - for (i = 0; i < 8; i++) { - result <<= 8; - result |= data[pos + i]; - } - - value = result; - tmp = value; - - /* Result does not fit in long */ - if (tmp != result) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Value for %s cannot be decoded as a 'long' (%llu)", a->name, result); - return GRIB_DECODING_ERROR; - } - - *val = value; - *len = 1; - return GRIB_SUCCESS; -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_LONG; -} diff --git a/src/grib_accessor_class_uint64_little_endian.cc b/src/grib_accessor_class_uint64_little_endian.cc deleted file mode 100644 index 0553aefbf..000000000 --- a/src/grib_accessor_class_uint64_little_endian.cc +++ /dev/null @@ -1,134 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = unpack_long - IMPLEMENTS = get_native_type - END_CLASS_DEF - -*/ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_long(grib_accessor*, long* val, size_t* len); - -typedef struct grib_accessor_uint64_little_endian -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in uint64_little_endian */ -} grib_accessor_uint64_little_endian; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_uint64_little_endian = { - &grib_accessor_class_gen, /* super */ - "uint64_little_endian", /* name */ - sizeof(grib_accessor_uint64_little_endian), /* size */ - 0, /* inited */ - 0, /* init_class */ - 0, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_uint64_little_endian = &_grib_accessor_class_uint64_little_endian; - -/* END_CLASS_IMP */ - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - long value = 0; - long pos = a->offset; - unsigned char* data = grib_handle_of_accessor(a)->buffer->data; - unsigned long long result = 0, tmp; - int i; - - if (*len < 1) { - return GRIB_ARRAY_TOO_SMALL; - } - - for (i = 7; i >= 0; i--) { - result <<= 8; - result |= data[pos + i]; - } - - value = result; - tmp = value; - - /* Result does not fit in long */ - if (tmp != result) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Value for %s cannot be decoded as a 'long' (%llu)", a->name, result); - return GRIB_DECODING_ERROR; - } - - *val = value; - *len = 1; - return GRIB_SUCCESS; -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_LONG; -} diff --git a/src/grib_accessor_class_uint8.cc b/src/grib_accessor_class_uint8.cc deleted file mode 100644 index 3f4195eff..000000000 --- a/src/grib_accessor_class_uint8.cc +++ /dev/null @@ -1,120 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = unpack_long - IMPLEMENTS = get_native_type - END_CLASS_DEF - -*/ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int unpack_long(grib_accessor*, long* val, size_t* len); - -typedef struct grib_accessor_uint8 -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in uint8 */ -} grib_accessor_uint8; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_uint8 = { - &grib_accessor_class_gen, /* super */ - "uint8", /* name */ - sizeof(grib_accessor_uint8), /* size */ - 0, /* inited */ - 0, /* init_class */ - 0, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_uint8 = &_grib_accessor_class_uint8; - -/* END_CLASS_IMP */ - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - long value = 0; - long pos = a->offset; - unsigned char* data = grib_handle_of_accessor(a)->buffer->data; - - if (*len < 1) { - return GRIB_ARRAY_TOO_SMALL; - } - - value = data[pos]; - - *val = value; - *len = 1; - return GRIB_SUCCESS; -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_LONG; -} diff --git a/src/grib_accessor_class_unexpanded_descriptors.cc b/src/grib_accessor_class_unexpanded_descriptors.cc deleted file mode 100644 index a026388f2..000000000 --- a/src/grib_accessor_class_unexpanded_descriptors.cc +++ /dev/null @@ -1,236 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = init - IMPLEMENTS = next_offset - IMPLEMENTS = value_count - IMPLEMENTS = byte_offset - IMPLEMENTS = update_size - MEMBERS = grib_accessor* unexpandedDescriptorsEncoded - MEMBERS = const char* createNewData - - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static long byte_offset(grib_accessor*); -static long next_offset(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); -static void update_size(grib_accessor*, size_t); - -typedef struct grib_accessor_unexpanded_descriptors -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in unexpanded_descriptors */ - grib_accessor* unexpandedDescriptorsEncoded; - const char* createNewData; -} grib_accessor_unexpanded_descriptors; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_unexpanded_descriptors = { - &grib_accessor_class_long, /* super */ - "unexpanded_descriptors", /* name */ - sizeof(grib_accessor_unexpanded_descriptors), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - &next_offset, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - &byte_offset, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - &update_size, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_unexpanded_descriptors = &_grib_accessor_class_unexpanded_descriptors; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* args) -{ - grib_accessor_unexpanded_descriptors* self = (grib_accessor_unexpanded_descriptors*)a; - int n = 0; - grib_handle* hand = grib_handle_of_accessor(a); - self->unexpandedDescriptorsEncoded = grib_find_accessor(hand, grib_arguments_get_name(hand, args, n++)); - self->createNewData = grib_arguments_get_name(hand, args, n++); - a->length = 0; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_unexpanded_descriptors* self = (grib_accessor_unexpanded_descriptors*)a; - int ret = 0; - long pos = 0; - long rlen = 0; - long f, x, y; - long* v = val; - long i; - grib_handle* hand = grib_handle_of_accessor(a); - - pos = accessor_raw_get_offset(self->unexpandedDescriptorsEncoded) * 8; - - ret = value_count(a, &rlen); - if (ret) - return ret; - - if (rlen == 0) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "No descriptors in section 3. Malformed message."); - return GRIB_MESSAGE_MALFORMED; - } - - if (*len < rlen) { - /* grib_context_log(a->context, GRIB_LOG_ERROR, */ - /* " wrong size (%ld) for %s it contains %d values ",*len, a->name , rlen); */ - *len = 0; - return GRIB_ARRAY_TOO_SMALL; - } - - for (i = 0; i < rlen; i++) { - f = grib_decode_unsigned_long(hand->buffer->data, &pos, 2); - x = grib_decode_unsigned_long(hand->buffer->data, &pos, 6); - y = grib_decode_unsigned_long(hand->buffer->data, &pos, 8); - *v++ = f * 100000 + x * 1000 + y; - } - *len = rlen; - return GRIB_SUCCESS; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - grib_accessor_unexpanded_descriptors* self = (grib_accessor_unexpanded_descriptors*)a; - int ret = 0; - long pos = 0; - unsigned long f, x, y; - unsigned char* buf = NULL; - grib_accessor* expanded = NULL; - size_t buflen = *len * 2; - size_t i = 0, length = *len; - long createNewData = 1; - grib_handle* hand = grib_handle_of_accessor(a); - - grib_get_long(hand, self->createNewData, &createNewData); - - buf = (unsigned char*)grib_context_malloc_clear(a->context, buflen); - - for (i = 0; i < length; i++) { - const long tmp = val[i] % 100000; - f = val[i] / 100000; - x = tmp / 1000; - y = tmp % 1000; - grib_encode_unsigned_longb(buf, f, &pos, 2); - grib_encode_unsigned_longb(buf, x, &pos, 6); - grib_encode_unsigned_longb(buf, y, &pos, 8); - } - - grib_pack_bytes(self->unexpandedDescriptorsEncoded, buf, &buflen); - grib_context_free(hand->context, buf); - - if (createNewData == 0) - return ret; - - expanded = grib_find_accessor(hand, "expandedCodes"); - Assert(expanded != NULL); - ret = grib_accessor_class_expanded_descriptors_set_do_expand(expanded, 1); - if (ret != GRIB_SUCCESS) - return ret; - - ret = grib_set_long(hand, "unpack", 3); /* BUFR new data */ - if (ret != GRIB_SUCCESS) - return ret; - - ret = grib_set_long(hand, "unpack", 1); /* Unpack structure */ - - return ret; -} - -static int value_count(grib_accessor* a, long* numberOfUnexpandedDescriptors) -{ - grib_accessor_unexpanded_descriptors* self = (grib_accessor_unexpanded_descriptors*)a; - long n = 0; - - grib_value_count(self->unexpandedDescriptorsEncoded, &n); - *numberOfUnexpandedDescriptors = n / 2; - - return 0; -} - -static long byte_offset(grib_accessor* a) -{ - return a->offset; -} - -static void update_size(grib_accessor* a, size_t s) -{ - a->length = s; -} - -static long next_offset(grib_accessor* a) -{ - return byte_offset(a) + a->length; -} diff --git a/src/grib_accessor_class_unpack_bufr_values.cc b/src/grib_accessor_class_unpack_bufr_values.cc deleted file mode 100644 index cac0cdfd7..000000000 --- a/src/grib_accessor_class_unpack_bufr_values.cc +++ /dev/null @@ -1,207 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init;dump - IMPLEMENTS = unpack_string;unpack_string_array;unpack_long; unpack_double - IMPLEMENTS = pack_long; pack_double - IMPLEMENTS = value_count; destroy; get_native_type; - MEMBERS = grib_accessor* data_accessor - - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_double(grib_accessor*, const double* val, size_t* len); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_double(grib_accessor*, double* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static int unpack_string_array(grib_accessor*, char**, size_t* len); -static int value_count(grib_accessor*, long*); -static void destroy(grib_context*, grib_accessor*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_unpack_bufr_values -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in unpack_bufr_values */ - grib_accessor* data_accessor; -} grib_accessor_unpack_bufr_values; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_unpack_bufr_values = { - &grib_accessor_class_gen, /* super */ - "unpack_bufr_values", /* name */ - sizeof(grib_accessor_unpack_bufr_values), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - &destroy, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - &pack_double, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - &unpack_string_array, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_unpack_bufr_values = &_grib_accessor_class_unpack_bufr_values; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* params) -{ - char* key; - grib_accessor_unpack_bufr_values* self = (grib_accessor_unpack_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; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ -} - -static int unpack_string_array(grib_accessor* a, char** buffer, size_t* len) -{ - grib_accessor_unpack_bufr_values* self = (grib_accessor_unpack_bufr_values*)a; - grib_accessor* data = (grib_accessor*)self->data_accessor; - - return grib_unpack_double(data, 0, 0); -} - -static int unpack_string(grib_accessor* a, char* buffer, size_t* len) -{ - grib_accessor_unpack_bufr_values* self = (grib_accessor_unpack_bufr_values*)a; - grib_accessor* data = (grib_accessor*)self->data_accessor; - strcpy(buffer, "0"); - *len=1; - - return grib_unpack_double(data, 0, 0); -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_unpack_bufr_values* self = (grib_accessor_unpack_bufr_values*)a; - grib_accessor* data = (grib_accessor*)self->data_accessor; - - return grib_unpack_double(data, 0, 0); -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_unpack_bufr_values* self = (grib_accessor_unpack_bufr_values*)a; - grib_accessor* data = (grib_accessor*)self->data_accessor; - - return grib_unpack_double(data, 0, 0); -} - -static int value_count(grib_accessor* a, long* count) -{ - *count = 1; - return 0; -} - -static void destroy(grib_context* context, grib_accessor* a) -{ -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_LONG; -} - -// static const char* mode_to_str(int p) -// { -// if (p==CODES_BUFR_UNPACK_STRUCTURE) return "CODES_BUFR_UNPACK_STRUCTURE"; -// if (p==CODES_BUFR_UNPACK_FLAT) return "CODES_BUFR_UNPACK_FLAT"; -// if (p==CODES_BUFR_NEW_DATA) return "CODES_BUFR_NEW_DATA"; -// return "unknown proc flag"; -// } - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - int unpackMode = CODES_BUFR_UNPACK_STRUCTURE; - grib_accessor_unpack_bufr_values* self = (grib_accessor_unpack_bufr_values*)a; - grib_accessor* data = (grib_accessor*)self->data_accessor; - - if (*val == 2) - unpackMode = CODES_BUFR_UNPACK_FLAT; - if (*val == 3) - unpackMode = CODES_BUFR_NEW_DATA; - - accessor_bufr_data_array_set_unpackMode(data, unpackMode); - - return grib_unpack_double(data, 0, 0); -} - -static int pack_double(grib_accessor* a, const double* val, size_t* len) -{ - grib_accessor_unpack_bufr_values* self = (grib_accessor_unpack_bufr_values*)a; - grib_accessor* data = (grib_accessor*)self->data_accessor; - - return grib_unpack_double(data, 0, 0); -} diff --git a/src/grib_accessor_class_unsigned_bits.cc b/src/grib_accessor_class_unsigned_bits.cc deleted file mode 100644 index 38c3425cf..000000000 --- a/src/grib_accessor_class_unsigned_bits.cc +++ /dev/null @@ -1,265 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long;pack_long - IMPLEMENTS = init - IMPLEMENTS = next_offset - IMPLEMENTS = byte_count - IMPLEMENTS = value_count - IMPLEMENTS = byte_offset - IMPLEMENTS = update_size - MEMBERS = const char* numberOfBits - MEMBERS = const char* numberOfElements - - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int pack_long(grib_accessor*, const long* val, size_t* len); -static int unpack_long(grib_accessor*, long* val, size_t* len); -static long byte_count(grib_accessor*); -static long byte_offset(grib_accessor*); -static long next_offset(grib_accessor*); -static int value_count(grib_accessor*, long*); -static void init(grib_accessor*, const long, grib_arguments*); -static void update_size(grib_accessor*, size_t); - -typedef struct grib_accessor_unsigned_bits -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in unsigned_bits */ - const char* numberOfBits; - const char* numberOfElements; -} grib_accessor_unsigned_bits; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_unsigned_bits = { - &grib_accessor_class_long, /* super */ - "unsigned_bits", /* name */ - sizeof(grib_accessor_unsigned_bits), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - &next_offset, /* next_offset */ - 0, /* get length of string */ - &value_count, /* get number of values */ - &byte_count, /* get number of bytes */ - &byte_offset, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - &update_size, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_unsigned_bits = &_grib_accessor_class_unsigned_bits; - -/* END_CLASS_IMP */ - - -static long compute_byte_count(grib_accessor* a) -{ - grib_accessor_unsigned_bits* self = (grib_accessor_unsigned_bits*)a; - long numberOfBits; - long numberOfElements; - int ret = 0; - - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); - if (ret) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name, self->numberOfBits); - return 0; - } - - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements, &numberOfElements); - if (ret) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name, self->numberOfElements); - return 0; - } - - return (numberOfBits * numberOfElements + 7) / 8; -} - - -static void init(grib_accessor* a, const long len, grib_arguments* args) -{ - grib_accessor_unsigned_bits* self = (grib_accessor_unsigned_bits*)a; - int n = 0; - self->numberOfBits = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->numberOfElements = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - a->length = compute_byte_count(a); -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_unsigned_bits* self = (grib_accessor_unsigned_bits*)a; - int ret = 0; - long pos = a->offset * 8; - long rlen = 0; - long numberOfBits = 0; - - ret = value_count(a, &rlen); - if (ret) - return ret; - - if (*len < rlen) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Wrong size (%ld) for %s, it contains %ld values", *len, a->name, rlen); - *len = rlen; - return GRIB_ARRAY_TOO_SMALL; - } - - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); - if (ret) - return ret; - if (numberOfBits == 0) { - int i; - for (i = 0; i < rlen; i++) - val[i] = 0; - return GRIB_SUCCESS; - } - - grib_decode_long_array(grib_handle_of_accessor(a)->buffer->data, &pos, numberOfBits, rlen, val); - - *len = rlen; - - return GRIB_SUCCESS; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - grib_accessor_unsigned_bits* self = (grib_accessor_unsigned_bits*)a; - int ret = 0; - long off = 0; - long numberOfBits = 0; - size_t buflen = 0; - unsigned char* buf = NULL; - unsigned long i = 0; - long rlen = 0; - ret = value_count(a, &rlen); - if (ret) return ret; - - /* - if(*len < rlen) - { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Wrong size for %s it contains %d values ", a->name , rlen ); - return GRIB_ARRAY_TOO_SMALL; - } - */ - if (*len != rlen) - ret = grib_set_long(grib_handle_of_accessor(a), self->numberOfElements, *len); - if (ret) return ret; - - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); - if (ret) return ret; - if (numberOfBits == 0) { - grib_buffer_replace(a, NULL, 0, 1, 1); - return GRIB_SUCCESS; - } - - buflen = compute_byte_count(a); - buf = (unsigned char*)grib_context_malloc_clear(a->context, buflen + sizeof(long)); - - for (i = 0; i < *len; i++) - grib_encode_unsigned_longb(buf, val[i], &off, numberOfBits); - - grib_buffer_replace(a, buf, buflen, 1, 1); - - grib_context_free(a->context, buf); - - return ret; -} - -static long byte_count(grib_accessor* a) -{ - return a->length; -} - -static int value_count(grib_accessor* a, long* numberOfElements) -{ - grib_accessor_unsigned_bits* self = (grib_accessor_unsigned_bits*)a; - int ret; - *numberOfElements = 0; - - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements, numberOfElements); - if (ret) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name, self->numberOfElements); - } - - return ret; -} - -static long byte_offset(grib_accessor* a) -{ - return a->offset; -} - -static void update_size(grib_accessor* a, size_t s) -{ - a->length = s; -} - -static long next_offset(grib_accessor* a) -{ - return byte_offset(a) + a->length; -} diff --git a/src/grib_accessor_class_validity_date.cc b/src/grib_accessor_class_validity_date.cc deleted file mode 100644 index 760b7bccd..000000000 --- a/src/grib_accessor_class_validity_date.cc +++ /dev/null @@ -1,229 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long - IMPLEMENTS = init - MEMBERS=const char* date - MEMBERS=const char* time - MEMBERS=const char* step - MEMBERS=const char* stepUnits - MEMBERS=const char* year - MEMBERS=const char* month - MEMBERS=const char* day - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_long(grib_accessor*, long* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_validity_date -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in validity_date */ - const char* date; - const char* time; - const char* step; - const char* stepUnits; - const char* year; - const char* month; - const char* day; -} grib_accessor_validity_date; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_validity_date = { - &grib_accessor_class_long, /* super */ - "validity_date", /* name */ - sizeof(grib_accessor_validity_date), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_validity_date = &_grib_accessor_class_validity_date; - -/* END_CLASS_IMP */ - -/* Table of multipliers to convert step units to minutes */ -static const double u2m[] = { - 1, /* index 0: minutes */ - 60, /* index 1: hour */ - 24 * 60, /* index 2: day */ - 24 * 60 * 30, /* index 3: month */ - -1, /* index 4: year */ - -1, /* index 5: decade */ - -1, /* index 6: 30 years */ - -1, /* index 7: century */ - -1, /* index 8: RESERVED */ - -1, /* index 9: RESERVED */ - 3 * 60, /* index 10: 3 hours */ - 6 * 60, /* index 11: 6 hours */ - 12 * 60, /* index 12: 12 hours */ - 1 / 60.0, /* index 13: seconds */ - 15, /* index 14: 15 mins */ - 30 /* index 15: 30 mins */ -}; - -static long convert_to_minutes(long step, long stepUnits) -{ - double result = 0; - if (stepUnits == 0) - return step; /* unit=minutes so no change */ - if (stepUnits == 1) - return step * 60; /* unit=hours */ - if (stepUnits == 13) - return step / 60; /* unit=seconds */ - /* Assert( stepUnits < sizeof(u2m)/sizeof(u2m[0]) ); */ - - result = step * u2m[stepUnits]; - return (long)result; -} - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_validity_date* self = (grib_accessor_validity_date*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int n = 0; - - self->date = grib_arguments_get_name(hand, c, n++); - self->time = grib_arguments_get_name(hand, c, n++); - self->step = grib_arguments_get_name(hand, c, n++); - self->stepUnits = grib_arguments_get_name(hand, c, n++); - self->year = grib_arguments_get_name(hand, c, n++); - self->month = grib_arguments_get_name(hand, c, n++); - self->day = grib_arguments_get_name(hand, c, n++); - - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_validity_date* self = (grib_accessor_validity_date*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int ret = 0; - long date = 0; - long time = 0; - long step = 0; - long stepUnits = 0; - long hours = 0, minutes = 0, step_mins = 0, tmp, tmp_hrs; - - if (self->year) { - long year, month, day; - if ((ret = grib_get_long_internal(hand, self->year, &year)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_get_long_internal(hand, self->month, &month)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_get_long_internal(hand, self->day, &day)) != GRIB_SUCCESS) - return ret; - *val = year * 10000 + month * 100 + day; - return GRIB_SUCCESS; - } - if ((ret = grib_get_long_internal(hand, self->date, &date)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_get_long_internal(hand, self->time, &time)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_get_long(hand, self->step, &step)) != GRIB_SUCCESS) { - if ((ret = grib_get_long_internal(hand, "endStep", &step)) != GRIB_SUCCESS) { - return ret; /* See ECC-817 */ - } - } - - if (self->stepUnits) { - if ((ret = grib_get_long_internal(hand, self->stepUnits, &stepUnits)) != GRIB_SUCCESS) - return ret; - step_mins = convert_to_minutes(step, stepUnits); - } - - minutes = time % 100; - hours = time / 100; - tmp = minutes + step_mins; /* add the step to our minutes */ - tmp_hrs = tmp / 60; /* how many hours and mins is that? */ - hours += tmp_hrs; /* increment hours */ - - date = grib_date_to_julian(date); - /* does the new 'hours' exceed 24? if so increment julian */ - while (hours >= 24) { - date++; - hours -= 24; - } - /* GRIB-29: Negative forecast time */ - while (hours < 0) { - date--; - hours += 24; - } - - if (*len < 1) - return GRIB_ARRAY_TOO_SMALL; - - *val = grib_julian_to_date(date); - - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_validity_time.cc b/src/grib_accessor_class_validity_time.cc deleted file mode 100644 index 34eb78128..000000000 --- a/src/grib_accessor_class_validity_time.cc +++ /dev/null @@ -1,249 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_long - IMPLEMENTS = unpack_long - IMPLEMENTS = unpack_string - IMPLEMENTS = init - MEMBERS=const char* date - MEMBERS=const char* time - MEMBERS=const char* step - MEMBERS=const char* stepUnits - MEMBERS=const char* hours - MEMBERS=const char* minutes - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_long(grib_accessor*, long* val, size_t* len); -static int unpack_string(grib_accessor*, char*, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_validity_time -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in long */ - /* Members defined in validity_time */ - const char* date; - const char* time; - const char* step; - const char* stepUnits; - const char* hours; - const char* minutes; -} grib_accessor_validity_time; - -extern grib_accessor_class* grib_accessor_class_long; - -static grib_accessor_class _grib_accessor_class_validity_time = { - &grib_accessor_class_long, /* super */ - "validity_time", /* name */ - sizeof(grib_accessor_validity_time), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - &unpack_long, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - &unpack_string, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_validity_time = &_grib_accessor_class_validity_time; - -/* END_CLASS_IMP */ - -/* Table of multipliers to convert step units to minutes */ -static const double u2m[] = { - 1, /* index 0: minutes */ - 60, /* index 1: hour */ - 24 * 60, /* index 2: day */ - 24 * 60 * 30, /* index 3: month */ - -1, /* index 4: year */ - -1, /* index 5: decade */ - -1, /* index 6: 30 years */ - -1, /* index 7: century */ - -1, /* index 8: RESERVED */ - -1, /* index 9: RESERVED */ - 3 * 60, /* index 10: 3 hours */ - 6 * 60, /* index 11: 6 hours */ - 12 * 60, /* index 12: 12 hours */ - 1 / 60.0, /* index 13: seconds */ - 15, /* index 14: 15 mins */ - 30 /* index 15: 30 mins */ -}; - -static long convert_to_minutes(long step, long stepUnits) -{ - double result = 0; - if (stepUnits == 0) - return step; /* unit=minutes so no change */ - if (stepUnits == 1) - return step * 60; /* unit=hours */ - if (stepUnits == 13) - return step / 60; /* unit=seconds*/ - /* Assert( stepUnits < sizeof(u2m)/sizeof(u2m[0]) ); */ - - result = step * u2m[stepUnits]; - return (long)result; -} - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_validity_time* self = (grib_accessor_validity_time*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int n = 0; - - self->date = grib_arguments_get_name(hand, c, n++); - self->time = grib_arguments_get_name(hand, c, n++); - self->step = grib_arguments_get_name(hand, c, n++); - self->stepUnits = grib_arguments_get_name(hand, c, n++); - self->hours = grib_arguments_get_name(hand, c, n++); - self->minutes = grib_arguments_get_name(hand, c, n++); - - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; -} - -static int unpack_long(grib_accessor* a, long* val, size_t* len) -{ - grib_accessor_validity_time* self = (grib_accessor_validity_time*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int ret = 0; - long date = 0; - long time = 0; - long step = 0; - long stepUnits = 0; - long hours = 0, minutes = 0, step_mins = 0, tmp, tmp_hrs, tmp_mins; - - if (self->hours) { - if ((ret = grib_get_long_internal(hand, self->hours, &hours)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_get_long_internal(hand, self->minutes, &minutes)) != GRIB_SUCCESS) - return ret; - *val = hours * 100 + minutes; - return GRIB_SUCCESS; - } - if ((ret = grib_get_long_internal(hand, self->date, &date)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_get_long_internal(hand, self->time, &time)) != GRIB_SUCCESS) - return ret; - if ((ret = grib_get_long(hand, self->step, &step)) != GRIB_SUCCESS) { - if ((ret = grib_get_long_internal(hand, "endStep", &step)) != GRIB_SUCCESS) { - return ret; /* See ECC-817 */ - } - } - - /* Seconds will always be zero. So convert to minutes */ - if (self->stepUnits) { - if ((ret = grib_get_long_internal(hand, self->stepUnits, &stepUnits)) != GRIB_SUCCESS) - return ret; - step_mins = convert_to_minutes(step, stepUnits); - } - - minutes = time % 100; - hours = time / 100; - tmp = minutes + step_mins; /* add the step to our minutes */ - tmp_hrs = tmp / 60; /* how many hours and mins is that? */ - tmp_mins = tmp % 60; - hours += tmp_hrs; /* increment hours */ - if (hours > 0) { - hours = hours % 24; /* wrap round if >= 24 */ - } - else { - /* GRIB-29: Negative forecast time */ - while (hours < 0) { - hours += 24; - } - } - time = hours * 100 + tmp_mins; - - if (*len < 1) - return GRIB_ARRAY_TOO_SMALL; - - *val = time; - - return GRIB_SUCCESS; -} - -static int unpack_string(grib_accessor* a, char* val, size_t* len) -{ - int err = 0; - long v = 0; - size_t lsize = 1, lmin = 5; - - err = unpack_long(a, &v, &lsize); - if (err) return err; - - if (*len < lmin) { - const char* cclass_name = a->cclass->name; - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, lmin, *len); - *len = lmin; - return GRIB_BUFFER_TOO_SMALL; - } - - snprintf(val, 64, "%04ld", v); - - len[0] = lmin; - return GRIB_SUCCESS; -} diff --git a/src/grib_accessor_class_values.cc b/src/grib_accessor_class_values.cc deleted file mode 100644 index 384282317..000000000 --- a/src/grib_accessor_class_values.cc +++ /dev/null @@ -1,259 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" - -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init - IMPLEMENTS = dump - IMPLEMENTS = next_offset - IMPLEMENTS = byte_count - IMPLEMENTS = byte_offset - IMPLEMENTS = get_native_type - IMPLEMENTS = update_size - IMPLEMENTS = compare - IMPLEMENTS = pack_long - MEMBERS= int carg - MEMBERS= const char* seclen - MEMBERS= const char* offsetdata - MEMBERS= const char* offsetsection - MEMBERS= int dirty - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static int pack_long(grib_accessor*, const long* val, size_t* len); -static long byte_count(grib_accessor*); -static long byte_offset(grib_accessor*); -static long next_offset(grib_accessor*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); -static void update_size(grib_accessor*, size_t); -static int compare(grib_accessor*, grib_accessor*); - -typedef struct grib_accessor_values -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in values */ - int carg; - const char* seclen; - const char* offsetdata; - const char* offsetsection; - int dirty; -} grib_accessor_values; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_values = { - &grib_accessor_class_gen, /* super */ - "values", /* name */ - sizeof(grib_accessor_values), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - &next_offset, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - &byte_count, /* get number of bytes */ - &byte_offset, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - &pack_long, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - &update_size, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - &compare, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_values = &_grib_accessor_class_values; - -/* END_CLASS_IMP */ -static long init_length(grib_accessor* a) -{ - grib_accessor_values* self = (grib_accessor_values*)a; - int ret = 0; - - long seclen = 0; - long offsetsection = 0; - long offsetdata = 0; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->seclen, &seclen))) - return ret; - - if (seclen == 0) { - /* printf("init_length seclen=0\n"); */ - return 0; - } - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetsection, &offsetsection))) - return ret; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetdata, &offsetdata))) - return ret; - - /* When reparsing */ - if (offsetdata < offsetsection) { - /* printf("init_length offsetdata < offsetsection=0\n"); */ - Assert(grib_handle_of_accessor(a)->loader); - return 0; - } - - return seclen - (offsetdata - offsetsection); -} - -static void init(grib_accessor* a, const long v, grib_arguments* params) -{ - grib_accessor_values* self = (grib_accessor_values*)a; - self->carg = 0; - - self->seclen = grib_arguments_get_name(grib_handle_of_accessor(a), params, self->carg++); - self->offsetdata = grib_arguments_get_name(grib_handle_of_accessor(a), params, self->carg++); - self->offsetsection = grib_arguments_get_name(grib_handle_of_accessor(a), params, self->carg++); - self->dirty = 1; - - a->length = init_length(a); - /* Assert(a->length>=0); */ -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_DOUBLE; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - grib_dump_values(dumper, a); -} - -static long byte_count(grib_accessor* a) -{ - grib_context_log(a->context, GRIB_LOG_DEBUG, "byte_count of %s = %ld", a->name, a->length); - return a->length; -} - -static long byte_offset(grib_accessor* a) -{ - return a->offset; -} - -static long next_offset(grib_accessor* a) -{ - return a->offset + a->length; -} - -static void update_size(grib_accessor* a, size_t s) -{ - grib_context_log(a->context, GRIB_LOG_DEBUG, "updating size of %s old %ld new %ld", a->name, a->length, s); - a->length = s; - Assert(a->length >= 0); -} - -static int compare(grib_accessor* a, grib_accessor* b) -{ - int retval = 0; - double* aval = 0; - double* bval = 0; - - size_t alen = 0; - size_t blen = 0; - int err = 0; - long count = 0; - - err = grib_value_count(a, &count); - if (err) - return err; - alen = count; - - err = grib_value_count(b, &count); - if (err) - return err; - blen = count; - - if (alen != blen) - return GRIB_COUNT_MISMATCH; - - aval = (double*)grib_context_malloc(a->context, alen * sizeof(double)); - bval = (double*)grib_context_malloc(b->context, blen * sizeof(double)); - - grib_unpack_double(a, aval, &alen); - grib_unpack_double(b, bval, &blen); - - retval = GRIB_SUCCESS; - for (size_t i=0; icontext, aval); - grib_context_free(b->context, bval); - - return retval; -} - -static int pack_long(grib_accessor* a, const long* val, size_t* len) -{ - grib_accessor_values* self = (grib_accessor_values*)a; - double* dval = (double*)grib_context_malloc(a->context, *len * sizeof(double)); - - for (size_t i = 0; i < *len; i++) - dval[i] = (double)val[i]; - - int ret = grib_pack_double(a, dval, len); - - grib_context_free(a->context, dval); - - self->dirty = 1; - - return ret; -} diff --git a/src/grib_accessor_class_vector.cc b/src/grib_accessor_class_vector.cc deleted file mode 100644 index 1cc69a4c7..000000000 --- a/src/grib_accessor_class_vector.cc +++ /dev/null @@ -1,162 +0,0 @@ -/* - * (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. - */ - -/************************************** - * Enrico Fucile - **************************************/ - - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_abstract_vector - IMPLEMENTS = init - IMPLEMENTS = unpack_double - MEMBERS = const char* vector - MEMBERS = int index - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int unpack_double(grib_accessor*, double* val, size_t* len); -static void init(grib_accessor*, const long, grib_arguments*); - -typedef struct grib_accessor_vector -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in abstract_vector */ - double* v; - int number_of_elements; - /* Members defined in vector */ - const char* vector; - int index; -} grib_accessor_vector; - -extern grib_accessor_class* grib_accessor_class_abstract_vector; - -static grib_accessor_class _grib_accessor_class_vector = { - &grib_accessor_class_abstract_vector, /* super */ - "vector", /* name */ - sizeof(grib_accessor_vector), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - 0, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - 0, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - &unpack_double, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - 0, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_vector = &_grib_accessor_class_vector; - -/* END_CLASS_IMP */ - -typedef struct grib_accessor_abstract_vector -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in double */ - /* Members defined in abstract_vector */ - double* v; - int number_of_elements; -} grib_accessor_abstract_vector; - -static void init(grib_accessor* a, const long l, grib_arguments* c) -{ - grib_accessor_vector* self = (grib_accessor_vector*)a; - int n = 0; - - self->vector = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->index = grib_arguments_get_long(grib_handle_of_accessor(a), c, n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->length = 0; -} - -static int unpack_double(grib_accessor* a, double* val, size_t* len) -{ - int err = 0; - size_t size = 0; - double* stat; - grib_accessor_vector* self = (grib_accessor_vector*)a; - grib_accessor* va = (grib_accessor*)grib_find_accessor(grib_handle_of_accessor(a), self->vector); - grib_accessor_abstract_vector* v = (grib_accessor_abstract_vector*)va; - - Assert(self->index >= 0); - - if (self->index >= v->number_of_elements) { - grib_context_log(a->context, GRIB_LOG_FATAL, "index=%d number_of_elements=%d for %s", self->index, v->number_of_elements, a->name); - Assert(self->index < v->number_of_elements); - } - - if (va->dirty) { - grib_get_size(grib_handle_of_accessor(a), self->vector, &size); - stat = (double*)grib_context_malloc_clear(a->context, sizeof(double) * size); - err = grib_unpack_double(va, stat, &size); - grib_context_free(a->context, stat); - if (err) - return err; - } - - *val = v->v[self->index]; - - return err; -} diff --git a/src/grib_accessor_class_when.cc b/src/grib_accessor_class_when.cc deleted file mode 100644 index 1bf0d999e..000000000 --- a/src/grib_accessor_class_when.cc +++ /dev/null @@ -1,122 +0,0 @@ -/* - * (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. - */ - -#include "grib_api_internal.h" -/* - This is used by make_class.pl - - START_CLASS_DEF - CLASS = accessor - SUPER = grib_accessor_class_gen - IMPLEMENTS = init;dump; - IMPLEMENTS = get_native_type - IMPLEMENTS = notify_change - END_CLASS_DEF - - */ - -/* START_CLASS_IMP */ - -/* - -Don't edit anything between START_CLASS_IMP and END_CLASS_IMP -Instead edit values between START_CLASS_DEF and END_CLASS_DEF -or edit "accessor.class" and rerun ./make_class.pl - -*/ - -static int get_native_type(grib_accessor*); -static void dump(grib_accessor*, grib_dumper*); -static void init(grib_accessor*, const long, grib_arguments*); -static int notify_change(grib_accessor*, grib_accessor*); - -typedef struct grib_accessor_when -{ - grib_accessor att; - /* Members defined in gen */ - /* Members defined in when */ -} grib_accessor_when; - -extern grib_accessor_class* grib_accessor_class_gen; - -static grib_accessor_class _grib_accessor_class_when = { - &grib_accessor_class_gen, /* super */ - "when", /* name */ - sizeof(grib_accessor_when), /* size */ - 0, /* inited */ - 0, /* init_class */ - &init, /* init */ - 0, /* post_init */ - 0, /* destroy */ - &dump, /* dump */ - 0, /* next_offset */ - 0, /* get length of string */ - 0, /* get number of values */ - 0, /* get number of bytes */ - 0, /* get offset to bytes */ - &get_native_type, /* get native type */ - 0, /* get sub_section */ - 0, /* pack_missing */ - 0, /* is_missing */ - 0, /* pack_long */ - 0, /* unpack_long */ - 0, /* pack_double */ - 0, /* pack_float */ - 0, /* unpack_double */ - 0, /* unpack_float */ - 0, /* pack_string */ - 0, /* unpack_string */ - 0, /* pack_string_array */ - 0, /* unpack_string_array */ - 0, /* pack_bytes */ - 0, /* unpack_bytes */ - 0, /* pack_expression */ - ¬ify_change, /* notify_change */ - 0, /* update_size */ - 0, /* preferred_size */ - 0, /* resize */ - 0, /* nearest_smaller_value */ - 0, /* next accessor */ - 0, /* compare vs. another accessor */ - 0, /* unpack only ith value (double) */ - 0, /* unpack only ith value (float) */ - 0, /* unpack a given set of elements (double) */ - 0, /* unpack a given set of elements (float) */ - 0, /* unpack a subarray */ - 0, /* clear */ - 0, /* clone accessor */ -}; - - -grib_accessor_class* grib_accessor_class_when = &_grib_accessor_class_when; - -/* END_CLASS_IMP */ - -static void init(grib_accessor* a, const long len, grib_arguments* arg) -{ - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; -} - -static void dump(grib_accessor* a, grib_dumper* dumper) -{ - /* grib_dump_when(dumper,a,NULL); */ -} - -static int notify_change(grib_accessor* a, grib_accessor* changed) -{ - return grib_action_notify_change(a->creator, a, changed); -} - -static int get_native_type(grib_accessor* a) -{ - return GRIB_TYPE_UNDEFINED; -} diff --git a/src/grib_api_internal.h b/src/grib_api_internal.h index d13edbc46..335da5954 100644 --- a/src/grib_api_internal.h +++ b/src/grib_api_internal.h @@ -240,14 +240,14 @@ typedef struct grib_action_file grib_action_file; typedef struct grib_action_file_list grib_action_file_list; typedef struct grib_block_of_accessors grib_block_of_accessors; typedef struct grib_buffer grib_buffer; -typedef struct grib_accessor_class grib_accessor_class; +class grib_accessor_class; typedef struct grib_action grib_action; typedef struct grib_action_class grib_action_class; typedef struct grib_section grib_section; typedef struct grib_codetable grib_codetable; typedef struct grib_smart_table grib_smart_table; -typedef struct grib_accessor grib_accessor; +class grib_accessor; typedef struct grib_iterator_class grib_iterator_class; typedef struct grib_nearest_class grib_nearest_class; typedef struct grib_dumper grib_dumper; @@ -279,53 +279,6 @@ typedef long (*iterator_has_next_proc)(grib_iterator* i); typedef int (*grib_pack_proc)(grib_handle* h, const double* in, size_t inlen, void* out, size_t* outlen); typedef int (*grib_unpack_proc)(grib_handle* h, const void* in, size_t inlen, double* out, size_t* outlen); -typedef void (*accessor_destroy_proc)(grib_context*, grib_accessor*); - -typedef int (*accessor_unpack_long_proc)(grib_accessor*, long*, size_t* len); -typedef int (*accessor_unpack_double_proc)(grib_accessor*, double*, size_t* len); -typedef int (*accessor_unpack_float_proc)(grib_accessor*, float*, size_t* len); - -typedef int (*accessor_unpack_double_element_proc)(grib_accessor*, size_t, double*); -typedef int (*accessor_unpack_float_element_proc)(grib_accessor*, size_t, float*); -typedef int (*accessor_unpack_double_element_set_proc)(grib_accessor*, const size_t*, size_t, double*); -typedef int (*accessor_unpack_float_element_set_proc)(grib_accessor*, const size_t*, size_t, float*); - -typedef int (*accessor_unpack_double_subarray_proc)(grib_accessor*, double*, size_t, size_t); -typedef int (*accessor_unpack_string_proc)(grib_accessor*, char*, size_t* len); -typedef int (*accessor_unpack_string_array_proc)(grib_accessor*, char**, size_t* len); -typedef int (*accessor_unpack_bytes_proc)(grib_accessor*, unsigned char*, size_t* len); -typedef int (*accessor_get_native_type_proc)(grib_accessor*); -typedef int (*accessor_notify_change_proc)(grib_accessor*, grib_accessor*); -typedef void (*accessor_update_size_proc)(grib_accessor*, size_t); -typedef size_t (*accessor_preferred_size_proc)(grib_accessor*, int); -typedef void (*accessor_resize_proc)(grib_accessor*, size_t); - -typedef grib_accessor* (*accessor_next_proc)(grib_accessor*, int); -typedef grib_section* (*accessor_sub_section_proc)(grib_accessor*); - -typedef int (*accessor_pack_missing_proc)(grib_accessor*); -typedef int (*accessor_pack_is_missing_proc)(grib_accessor*); -typedef int (*accessor_pack_long_proc)(grib_accessor*, const long*, size_t* len); -typedef int (*accessor_pack_double_proc)(grib_accessor*, const double*, size_t* len); -typedef int (*accessor_pack_float_proc)(grib_accessor*, const float*, size_t* len); -typedef int (*accessor_pack_string_proc)(grib_accessor*, const char*, size_t* len); -typedef int (*accessor_pack_string_array_proc)(grib_accessor*, const char**, size_t* len); -typedef int (*accessor_pack_bytes_proc)(grib_accessor*, const unsigned char*, size_t* len); -typedef int (*accessor_pack_expression_proc)(grib_accessor*, grib_expression*); -typedef int (*accessor_clear_proc)(grib_accessor*); -typedef grib_accessor* (*accessor_clone_proc)(grib_accessor*, grib_section*, int*); - -typedef void (*accessor_init_class_proc)(grib_accessor_class*); - -typedef int (*accessor_compare_proc)(grib_accessor*, grib_accessor*); -typedef size_t (*accessor_string_proc)(grib_accessor*); -typedef int (*accessor_value_with_ret_proc)(grib_accessor*, long*); -typedef long (*accessor_value_proc)(grib_accessor*); -typedef void (*accessor_dump_proc)(grib_accessor*, grib_dumper*); -typedef void (*accessor_init_proc)(grib_accessor*, const long len, grib_arguments*); -typedef void (*accessor_post_init_proc)(grib_accessor*); - -typedef int (*accessor_nearest_proc)(grib_accessor*, double, double*); typedef long (*grib_binop_long_proc)(long, long); typedef long (*grib_unop_long_proc)(long); @@ -395,16 +348,7 @@ struct grib_action char* debug_info; /** purely for debugging and tracing */ }; -typedef struct grib_accessors_list grib_accessors_list; - -struct grib_accessors_list -{ - grib_accessor* accessor; - int rank; - grib_accessors_list* next; - grib_accessors_list* prev; - grib_accessors_list* last; -}; +class grib_accessors_list; typedef int (*action_create_accessors_handle_proc)(grib_section* p, grib_action* a, grib_loader* h); typedef int (*action_notify_change_proc)(grib_action* a, grib_accessor* observer, grib_accessor* observed); @@ -479,34 +423,6 @@ struct grib_virtual_value int type; }; -struct grib_accessor -{ - const char* name; /** < name of the accessor */ - const char* name_space; /** < namespace to which the accessor belongs */ - grib_context* context; - grib_handle* h; - grib_action* creator; /** < action that created the accessor */ - long length; /** < byte length of the accessor */ - long offset; /** < offset of the data in the buffer */ - grib_section* parent; /** < section to which the accessor is attached */ - grib_accessor* next; /** < next accessor in list */ - grib_accessor* previous; /** < next accessor in list */ - grib_accessor_class* cclass; /** < behaviour of the accessor */ - unsigned long flags; /** < Various flags */ - grib_section* sub_section; - - const char* all_names[MAX_ACCESSOR_NAMES]; /** < name of the accessor */ - const char* all_name_spaces[MAX_ACCESSOR_NAMES]; /** < namespace to which the accessor belongs */ - int dirty; - - grib_accessor* same; /** < accessors with the same name */ - long loop; /** < used in lists */ - grib_virtual_value* vvalue; /** < virtual value used when transient flag on **/ - const char* set; - grib_accessor* attributes[MAX_ACCESSOR_ATTRIBUTES]; /** < attributes are accessors */ - grib_accessor* parent_as_attribute; -}; - #define GRIB_ACCESSOR_FLAG_READ_ONLY (1 << 1) #define GRIB_ACCESSOR_FLAG_DUMP (1 << 2) #define GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC (1 << 3) @@ -833,71 +749,6 @@ struct grib_multi_handle size_t length; }; -struct grib_accessor_class -{ - grib_accessor_class** super; - const char* name; - size_t size; - - int inited; - accessor_init_class_proc init_class; - - accessor_init_proc init; - accessor_post_init_proc post_init; - accessor_destroy_proc destroy; - - accessor_dump_proc dump; - accessor_value_proc next_offset; - - accessor_string_proc string_length; - accessor_value_with_ret_proc value_count; - - accessor_value_proc byte_count; - accessor_value_proc byte_offset; - - accessor_get_native_type_proc get_native_type; - - accessor_sub_section_proc sub_section; - - accessor_pack_missing_proc pack_missing; - accessor_pack_is_missing_proc is_missing; - - accessor_pack_long_proc pack_long; - accessor_unpack_long_proc unpack_long; - - accessor_pack_double_proc pack_double; - accessor_pack_float_proc pack_float; - accessor_unpack_double_proc unpack_double; - accessor_unpack_float_proc unpack_float; - - accessor_pack_string_proc pack_string; - accessor_unpack_string_proc unpack_string; - - accessor_pack_string_array_proc pack_string_array; - accessor_unpack_string_array_proc unpack_string_array; - - accessor_pack_bytes_proc pack_bytes; - accessor_unpack_bytes_proc unpack_bytes; - - accessor_pack_expression_proc pack_expression; - - accessor_notify_change_proc notify_change; - accessor_update_size_proc update_size; - - accessor_preferred_size_proc preferred_size; - accessor_resize_proc resize; - - accessor_nearest_proc nearest_smaller_value; - accessor_next_proc next; - accessor_compare_proc compare; - accessor_unpack_double_element_proc unpack_double_element; - accessor_unpack_float_element_proc unpack_float_element; - accessor_unpack_double_element_set_proc unpack_double_element_set; - accessor_unpack_float_element_set_proc unpack_float_element_set; - accessor_unpack_double_subarray_proc unpack_double_subarray; - accessor_clear_proc clear; - accessor_clone_proc make_clone; -}; typedef struct grib_multi_support grib_multi_support; struct grib_multi_support @@ -1434,6 +1285,8 @@ typedef struct j2k_encode_helper #ifdef __cplusplus } +#include "accessor/grib_accessor.h" +#include "accessor/grib_accessors_list.h" #endif #endif diff --git a/src/grib_buffer.cc b/src/grib_buffer.cc index 525e59f31..cb313141c 100644 --- a/src/grib_buffer.cc +++ b/src/grib_buffer.cc @@ -123,14 +123,14 @@ static void update_offsets(grib_accessor* a, long len) grib_context_log(a->context, GRIB_LOG_DEBUG, "::::: grib_buffer : accessor %s is moving by %d bytes to %ld", a->name, len, a->offset); if (s) update_offsets(s->block->first, len); - a = a->next; + a = a->next_; } } static void update_offsets_after(grib_accessor* a, long len) { while (a) { - update_offsets(a->next, len); + update_offsets(a->next_, len); a = a->parent->owner; } } @@ -152,10 +152,10 @@ static void update_offsets_after(grib_accessor* a, long len) // { // int ret; // if(s->owner) -// plen = grib_get_next_position_offset(s->block->last) - s->owner->offset; +// plen = s->block->last->get_next_position_offset() - s->owner->offset; // else -// plen = grib_get_next_position_offset(s->block->last); -// if((ret = grib_pack_long(s->aclength, &plen, &len)) != GRIB_SUCCESS) +// plen = s->block->last->get_next_position_offset(); +// if((ret = s->aclength->pack_long(&plen, &len)) != GRIB_SUCCESS) // ; // // if(s->h->context->debug) @@ -174,19 +174,19 @@ static void update_offsets_after(grib_accessor* a, long len) // { // int ret; // if(s->owner) -// plen = grib_get_next_position_offset(s->block->last) - s->owner->offset; +// plen = s->block->last->get_next_position_offset() - s->owner->offset; // else -// plen = grib_get_next_position_offset(s->block->last); +// plen = s->block->last->get_next_position_offset(); // /* if(s->owner) */ // /* s->owner->length = plen; */ // /* if(s->aclength) */ -// if((ret = grib_pack_long(s->aclength, &plen, &len)) != GRIB_SUCCESS) +// if((ret = s->aclength->pack_long(&plen, &len)) != GRIB_SUCCESS) // ; // if(s->h->context->debug) // { // printf("SECTION updating length %ld .. %s\n",plen,s->owner->name); // printf("NEXT_POS = %ld, owner offset= %ld %s %s\n", -// grib_get_next_position_offset(s->block->last), +// s->block->last->get_next_position_offset(), // s->owner ? s->owner->offset : 0L, s->owner->name, // s->block->last->name); // } @@ -199,7 +199,7 @@ int grib_buffer_replace(grib_accessor* a, const unsigned char* data, size_t newsize, int update_lengths, int update_paddings) { size_t offset = a->offset; - long oldsize = grib_get_next_position_offset(a) - offset; + long oldsize = a->get_next_position_offset() - offset; long increase = (long)newsize - (long)oldsize; grib_buffer* buffer = grib_handle_of_accessor(a)->buffer; @@ -231,7 +231,7 @@ int grib_buffer_replace(grib_accessor* a, const unsigned char* data, if (increase) { update_offsets_after(a, increase); if (update_lengths) { - grib_update_size(a, newsize); + a->update_size(newsize); int err = grib_section_adjust_sizes(grib_handle_of_accessor(a)->root, 1, 0); if (err) return err; if (update_paddings) diff --git a/src/grib_bufr_descriptor.cc b/src/grib_bufr_descriptor.cc index fcaeeac46..6b7f2b3ce 100644 --- a/src/grib_bufr_descriptor.cc +++ b/src/grib_bufr_descriptor.cc @@ -9,8 +9,9 @@ */ -#include "grib_scaling.h" #include "grib_api_internal.h" +#include "accessor/grib_accessor_class_bufr_data_array.h" +#include "grib_scaling.h" bufr_descriptor* grib_bufr_descriptor_new(grib_accessor* tables_accessor, int code, int silent, int* err) { diff --git a/src/grib_dependency.cc b/src/grib_dependency.cc index 4c417173e..37c89dbbf 100644 --- a/src/grib_dependency.cc +++ b/src/grib_dependency.cc @@ -124,7 +124,7 @@ int grib_dependency_notify_change(grib_accessor* observed) while (d) { if (d->run) { /*printf("grib_dependency_notify_change %s %s %p\n", observed->name, d->observer ? d->observer->name : "?", (void*)d->observer);*/ - if (d->observer && (ret = grib_accessor_notify_change(d->observer, observed)) != GRIB_SUCCESS) + if (d->observer && (ret = d->observer->notify_change(observed)) != GRIB_SUCCESS) return ret; } d = d->next; @@ -149,7 +149,7 @@ int grib_dependency_notify_change_h(grib_handle* h, grib_accessor* observed) while (d) { if (d->run) { /*printf("grib_dependency_notify_change %s %s %p\n",observed->name,d->observer ? d->observer->name : "?", (void*)d->observer);*/ - if (d->observer && (ret = grib_accessor_notify_change(d->observer, observed)) != GRIB_SUCCESS) + if (d->observer && (ret = d->observer->notify_change(observed)) != GRIB_SUCCESS) return ret; } d = d->next; diff --git a/src/grib_dumper_class.cc b/src/grib_dumper_class.cc index abd1cbf02..4af527151 100644 --- a/src/grib_dumper_class.cc +++ b/src/grib_dumper_class.cc @@ -52,8 +52,8 @@ void grib_dump_accessors_block(grib_dumper* dumper, grib_block_of_accessors* blo { grib_accessor* a = block->first; while (a) { - grib_accessor_dump(a, dumper); - a = a->next; + a->dump(dumper); + a = a->next_; } } @@ -61,8 +61,8 @@ void grib_dump_accessors_list(grib_dumper* dumper, grib_accessors_list* al) { grib_accessors_list* cur = al; while (cur) { - grib_accessor_dump(cur->accessor, dumper); - cur = cur->next; + cur->accessor->dump(dumper); + cur = cur->next_; } } @@ -70,7 +70,7 @@ int grib_print(grib_handle* h, const char* name, grib_dumper* d) { grib_accessor* act = grib_find_accessor(h, name); if (act) { - grib_accessor_dump(act, d); + act->dump(d); return GRIB_SUCCESS; } return GRIB_NOT_FOUND; @@ -106,7 +106,7 @@ void grib_dump_keys(grib_handle* h, FILE* f, const char* mode, unsigned long fla for (i = 0; i < num_keys; ++i) { acc = grib_find_accessor(h, keys[i]); if (acc) - grib_accessor_dump(acc, dumper); + acc->dump(dumper); } grib_dumper_delete(dumper); } diff --git a/src/grib_dumper_class_bufr_decode_C.cc b/src/grib_dumper_class_bufr_decode_C.cc index 49805279b..6811cdf94 100644 --- a/src/grib_dumper_class_bufr_decode_C.cc +++ b/src/grib_dumper_class_bufr_decode_C.cc @@ -150,11 +150,11 @@ static void dump_values(grib_dumper* d, grib_accessor* a) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size <= 1) { - err = grib_unpack_double(a, &value, &size); + err = a->unpack_double(&value, &size); } self->empty = 0; @@ -220,11 +220,11 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size <= 1) { - err = grib_unpack_double(a, &value, &size); + err = a->unpack_double(&value, &size); } self->empty = 0; @@ -279,7 +279,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { @@ -305,7 +305,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) } if (size <= 1) { - err = grib_unpack_long(a, &value, &size); + err = a->unpack_long(&value, &size); } self->empty = 0; @@ -368,11 +368,11 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size <= 1) { - err = grib_unpack_long(a, &value, &size); + err = a->unpack_long(&value, &size); } self->empty = 0; @@ -428,7 +428,7 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_unpack_double(a, &value, &size); + a->unpack_double(&value, &size); self->empty = 0; r = compute_bufr_key_rank(h, self->keys, a->name); @@ -477,7 +477,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size == 1) { dump_string(d, a, comment); @@ -497,7 +497,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm return; } - err = grib_unpack_string_array(a, values, &size); + err = a->unpack_string_array(values, &size); if (self->isLeaf == 0) { if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) @@ -545,7 +545,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) self->empty = 0; - err = grib_unpack_string(a, value, &size); + err = a->unpack_string(value, &size); p = value; r = compute_bufr_key_rank(h, self->keys, a->name); if (grib_is_missing_string(a, (unsigned char*)value, size)) { @@ -656,7 +656,7 @@ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix self->isLeaf = a->attributes[i]->attributes[0] == NULL ? 1 : 0; flags = a->attributes[i]->flags; a->attributes[i]->flags |= GRIB_ACCESSOR_FLAG_DUMP; - switch (grib_accessor_get_native_type(a->attributes[i])) { + switch (a->attributes[i]->get_native_type()) { case GRIB_TYPE_LONG: dump_long_attribute(d, a->attributes[i], prefix); break; diff --git a/src/grib_dumper_class_bufr_decode_filter.cc b/src/grib_dumper_class_bufr_decode_filter.cc index 0fff0fc14..87cb0e2fe 100644 --- a/src/grib_dumper_class_bufr_decode_filter.cc +++ b/src/grib_dumper_class_bufr_decode_filter.cc @@ -140,11 +140,11 @@ static void dump_values(grib_dumper* d, grib_accessor* a) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size <= 1) { - err = grib_unpack_double(a, &value, &size); + err = a->unpack_double(&value, &size); } self->begin = 0; @@ -199,11 +199,11 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size <= 1) { - err = grib_unpack_double(a, &value, &size); + err = a->unpack_double(&value, &size); } self->empty = 0; @@ -244,7 +244,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { @@ -270,7 +270,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) } if (size <= 1) { - err = grib_unpack_long(a, &value, &size); + err = a->unpack_long(&value, &size); } self->begin = 0; @@ -353,7 +353,7 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_unpack_double(a, &value, &size); + a->unpack_double(&value, &size); self->begin = 0; self->empty = 0; @@ -399,7 +399,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size == 1) { dump_string(d, a, comment); @@ -457,7 +457,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) self->empty = 0; - err = grib_unpack_string(a, value, &size); + err = a->unpack_string(value, &size); p = value; r = compute_bufr_key_rank(h, self->keys, a->name); if (grib_is_missing_string(a, (unsigned char*)value, size)) { @@ -569,7 +569,7 @@ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix /* fprintf(out,"\"%s\" : ",a->attributes[i]->name); */ flags = a->attributes[i]->flags; a->attributes[i]->flags |= GRIB_ACCESSOR_FLAG_DUMP; - switch (grib_accessor_get_native_type(a->attributes[i])) { + switch (a->attributes[i]->get_native_type()) { case GRIB_TYPE_LONG: dump_long_attribute(d, a->attributes[i], prefix); break; diff --git a/src/grib_dumper_class_bufr_decode_fortran.cc b/src/grib_dumper_class_bufr_decode_fortran.cc index b07f59b49..dbc4ed271 100644 --- a/src/grib_dumper_class_bufr_decode_fortran.cc +++ b/src/grib_dumper_class_bufr_decode_fortran.cc @@ -142,11 +142,11 @@ static void dump_values(grib_dumper* d, grib_accessor* a) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size <= 1) { - err = grib_unpack_double(a, &value, &size); + err = a->unpack_double(&value, &size); } self->empty = 0; @@ -202,11 +202,11 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size <= 1) { - err = grib_unpack_double(a, &value, &size); + err = a->unpack_double(&value, &size); } self->empty = 0; @@ -249,7 +249,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { @@ -275,7 +275,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) } if (size <= 1) { - err = grib_unpack_long(a, &value, &size); + err = a->unpack_long(&value, &size); } self->empty = 0; @@ -331,11 +331,11 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size <= 1) { - err = grib_unpack_long(a, &value, &size); + err = a->unpack_long(&value, &size); } self->empty = 0; @@ -384,7 +384,7 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_unpack_double(a, &value, &size); + a->unpack_double(&value, &size); self->empty = 0; r = compute_bufr_key_rank(h, self->keys, a->name); @@ -429,7 +429,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size == 1) { dump_string(d, a, comment); @@ -485,7 +485,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) self->empty = 0; - err = grib_unpack_string(a, value, &size); + err = a->unpack_string(value, &size); p = value; r = compute_bufr_key_rank(h, self->keys, a->name); if (grib_is_missing_string(a, (unsigned char*)value, size)) { @@ -595,7 +595,7 @@ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix self->isLeaf = a->attributes[i]->attributes[0] == NULL ? 1 : 0; flags = a->attributes[i]->flags; a->attributes[i]->flags |= GRIB_ACCESSOR_FLAG_DUMP; - switch (grib_accessor_get_native_type(a->attributes[i])) { + switch (a->attributes[i]->get_native_type()) { case GRIB_TYPE_LONG: dump_long_attribute(d, a->attributes[i], prefix); break; diff --git a/src/grib_dumper_class_bufr_decode_python.cc b/src/grib_dumper_class_bufr_decode_python.cc index 632cbe98b..3e2edc70a 100644 --- a/src/grib_dumper_class_bufr_decode_python.cc +++ b/src/grib_dumper_class_bufr_decode_python.cc @@ -150,11 +150,11 @@ static void dump_values(grib_dumper* d, grib_accessor* a) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size <= 1) { - err = grib_unpack_double(a, &value, &size); + err = a->unpack_double(&value, &size); } self->empty = 0; @@ -213,11 +213,11 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size <= 1) { - err = grib_unpack_double(a, &value, &size); + err = a->unpack_double(&value, &size); } self->empty = 0; @@ -265,7 +265,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { @@ -291,7 +291,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) } if (size <= 1) { - err = grib_unpack_long(a, &value, &size); + err = a->unpack_long(&value, &size); } self->empty = 0; @@ -345,11 +345,11 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size <= 1) { - err = grib_unpack_long(a, &value, &size); + err = a->unpack_long(&value, &size); } self->empty = 0; @@ -397,7 +397,7 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_unpack_double(a, &value, &size); + a->unpack_double(&value, &size); self->empty = 0; r = compute_bufr_key_rank(h, self->keys, a->name); @@ -445,7 +445,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size == 1) { dump_string(d, a, comment); @@ -498,7 +498,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) self->empty = 0; - err = grib_unpack_string(a, value, &size); + err = a->unpack_string(value, &size); p = value; r = compute_bufr_key_rank(h, self->keys, a->name); if (grib_is_missing_string(a, (unsigned char*)value, size)) { @@ -605,7 +605,7 @@ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix self->isLeaf = a->attributes[i]->attributes[0] == NULL ? 1 : 0; flags = a->attributes[i]->flags; a->attributes[i]->flags |= GRIB_ACCESSOR_FLAG_DUMP; - switch (grib_accessor_get_native_type(a->attributes[i])) { + switch (a->attributes[i]->get_native_type()) { case GRIB_TYPE_LONG: dump_long_attribute(d, a->attributes[i], prefix); break; diff --git a/src/grib_dumper_class_bufr_encode_C.cc b/src/grib_dumper_class_bufr_encode_C.cc index 568a035bb..915649814 100644 --- a/src/grib_dumper_class_bufr_encode_C.cc +++ b/src/grib_dumper_class_bufr_encode_C.cc @@ -168,15 +168,15 @@ static void dump_values(grib_dumper* d, grib_accessor* a) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = size2 = count; if (size > 1) { values = (double*)grib_context_malloc_clear(c, sizeof(double) * size); - err = grib_unpack_double(a, values, &size2); + err = a->unpack_double(values, &size2); } else { - err = grib_unpack_double(a, &value, &size2); + err = a->unpack_double(&value, &size2); } Assert(size2 == size); @@ -264,15 +264,15 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = size2 = count; if (size > 1) { values = (double*)grib_context_malloc_clear(c, sizeof(double) * size); - err = grib_unpack_double(a, values, &size2); + err = a->unpack_double(values, &size2); } else { - err = grib_unpack_double(a, &value, &size2); + err = a->unpack_double(&value, &size2); } Assert(size2 == size); @@ -357,7 +357,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) } doing_unexpandedDescriptors = (strcmp(a->name, "unexpandedDescriptors") == 0); - grib_value_count(a, &count); + a->value_count(&count); size = size2 = count; if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { @@ -385,10 +385,10 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) if (size > 1) { values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); - err = grib_unpack_long(a, values, &size2); + err = a->unpack_long(values, &size2); } else { - err = grib_unpack_long(a, &value, &size2); + err = a->unpack_long(&value, &size2); } Assert(size2 == size); @@ -488,15 +488,15 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = size2 = count; if (size > 1) { values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); - err = grib_unpack_long(a, values, &size2); + err = a->unpack_long(values, &size2); } else { - err = grib_unpack_long(a, &value, &size2); + err = a->unpack_long(&value, &size2); } Assert(size2 == size); @@ -568,7 +568,7 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_unpack_double(a, &value, &size); + a->unpack_double(&value, &size); self->empty = 0; r = compute_bufr_key_rank(h, self->keys, a->name); @@ -614,7 +614,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size == 1) { dump_string(d, a, comment); @@ -633,7 +633,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm return; } - err = grib_unpack_string_array(a, values, &size); + err = a->unpack_string_array(values, &size); for (i = 0; i < size - 1; i++) { fprintf(self->dumper.out, " svalues[%lu]=\"%s\"; \n", (unsigned long)i, values[i]); } @@ -697,7 +697,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) self->empty = 0; - err = grib_unpack_string(a, value, &size); + err = a->unpack_string(value, &size); p = value; r = compute_bufr_key_rank(h, self->keys, acc_name); if (grib_is_missing_string(a, (unsigned char*)value, size)) { @@ -833,7 +833,7 @@ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix self->isLeaf = a->attributes[i]->attributes[0] == NULL ? 1 : 0; flags = a->attributes[i]->flags; a->attributes[i]->flags |= GRIB_ACCESSOR_FLAG_DUMP; - switch (grib_accessor_get_native_type(a->attributes[i])) { + switch (a->attributes[i]->get_native_type()) { case GRIB_TYPE_LONG: dump_long_attribute(d, a->attributes[i], prefix); break; diff --git a/src/grib_dumper_class_bufr_encode_filter.cc b/src/grib_dumper_class_bufr_encode_filter.cc index 49c4d19ef..a90ab0f56 100644 --- a/src/grib_dumper_class_bufr_encode_filter.cc +++ b/src/grib_dumper_class_bufr_encode_filter.cc @@ -144,15 +144,15 @@ static void dump_values(grib_dumper* d, grib_accessor* a) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = size2 = count; if (size > 1) { values = (double*)grib_context_malloc_clear(c, sizeof(double) * size); - err = grib_unpack_double(a, values, &size2); + err = a->unpack_double(values, &size2); } else { - err = grib_unpack_double(a, &value, &size2); + err = a->unpack_double(&value, &size2); } Assert(size2 == size); @@ -234,15 +234,15 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = size2 = count; if (size > 1) { values = (double*)grib_context_malloc_clear(c, sizeof(double) * size); - err = grib_unpack_double(a, values, &size2); + err = a->unpack_double(values, &size2); } else { - err = grib_unpack_double(a, &value, &size2); + err = a->unpack_double(&value, &size2); } Assert(size2 == size); @@ -306,7 +306,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = size2 = count; if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { @@ -333,10 +333,10 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) if (size > 1) { values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); - err = grib_unpack_long(a, values, &size2); + err = a->unpack_long(values, &size2); } else { - err = grib_unpack_long(a, &value, &size2); + err = a->unpack_long(&value, &size2); } Assert(size2 == size); @@ -416,15 +416,15 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = size2 = count; if (size > 1) { values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); - err = grib_unpack_long(a, values, &size2); + err = a->unpack_long(values, &size2); } else { - err = grib_unpack_long(a, &value, &size2); + err = a->unpack_long(&value, &size2); } Assert(size2 == size); @@ -489,7 +489,7 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_unpack_double(a, &value, &size); + a->unpack_double(&value, &size); self->begin = 0; self->empty = 0; @@ -538,7 +538,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size == 1) { dump_string(d, a, comment); @@ -563,7 +563,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm return; } - err = grib_unpack_string_array(a, values, &size); + err = a->unpack_string_array(values, &size); fprintf(self->dumper.out, "{"); depth += 2; @@ -624,7 +624,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) self->begin = 0; self->empty = 0; - err = grib_unpack_string(a, value, &size); + err = a->unpack_string(value, &size); p = value; r = compute_bufr_key_rank(h, self->keys, a->name); if (grib_is_missing_string(a, (unsigned char*)value, size)) { @@ -759,7 +759,7 @@ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix /* fprintf(out,"\"%s\" : ",a->attributes[i]->name); */ flags = a->attributes[i]->flags; a->attributes[i]->flags |= GRIB_ACCESSOR_FLAG_DUMP; - switch (grib_accessor_get_native_type(a->attributes[i])) { + switch (a->attributes[i]->get_native_type()) { case GRIB_TYPE_LONG: dump_long_attribute(d, a->attributes[i], prefix); break; diff --git a/src/grib_dumper_class_bufr_encode_fortran.cc b/src/grib_dumper_class_bufr_encode_fortran.cc index e76bd0872..1e6cd3bd7 100644 --- a/src/grib_dumper_class_bufr_encode_fortran.cc +++ b/src/grib_dumper_class_bufr_encode_fortran.cc @@ -217,15 +217,15 @@ static void dump_values(grib_dumper* d, grib_accessor* a) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = size2 = count; if (size > 1) { values = (double*)grib_context_malloc_clear(c, sizeof(double) * size); - err = grib_unpack_double(a, values, &size2); + err = a->unpack_double(values, &size2); } else { - err = grib_unpack_double(a, &value, &size2); + err = a->unpack_double(&value, &size2); } Assert(size2 == size); @@ -312,15 +312,15 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = size2 = count; if (size > 1) { values = (double*)grib_context_malloc_clear(c, sizeof(double) * size); - err = grib_unpack_double(a, values, &size2); + err = a->unpack_double(values, &size2); } else { - err = grib_unpack_double(a, &value, &size2); + err = a->unpack_double(&value, &size2); } Assert(size2 == size); @@ -406,7 +406,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) } doing_unexpandedDescriptors = (strcmp(a->name, "unexpandedDescriptors") == 0); - grib_value_count(a, &count); + a->value_count(&count); size = size2 = count; if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { @@ -433,10 +433,10 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) if (size > 1) { values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); - err = grib_unpack_long(a, values, &size2); + err = a->unpack_long(values, &size2); } else { - err = grib_unpack_long(a, &value, &size2); + err = a->unpack_long(&value, &size2); } Assert(size2 == size); @@ -535,15 +535,15 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = size2 = count; if (size > 1) { values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); - err = grib_unpack_long(a, values, &size2); + err = a->unpack_long(values, &size2); } else { - err = grib_unpack_long(a, &value, &size2); + err = a->unpack_long(&value, &size2); } Assert(size2 == size); @@ -620,7 +620,7 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_unpack_double(a, &value, &size); + a->unpack_double(&value, &size); self->empty = 0; r = compute_bufr_key_rank(h, self->keys, a->name); @@ -665,7 +665,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size == 1) { dump_string(d, a, comment); @@ -685,7 +685,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm return; } - err = grib_unpack_string_array(a, values, &size); + err = a->unpack_string_array(values, &size); for (i = 0; i < size - 1; i++) { fprintf(self->dumper.out, " \"%s\", &\n", values[i]); @@ -747,7 +747,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) self->empty = 0; - err = grib_unpack_string(a, value, &size); + err = a->unpack_string(value, &size); p = value; r = compute_bufr_key_rank(h, self->keys, acc_name); if (grib_is_missing_string(a, (unsigned char*)value, size)) { @@ -880,7 +880,7 @@ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix self->isLeaf = a->attributes[i]->attributes[0] == NULL ? 1 : 0; flags = a->attributes[i]->flags; a->attributes[i]->flags |= GRIB_ACCESSOR_FLAG_DUMP; - switch (grib_accessor_get_native_type(a->attributes[i])) { + switch (a->attributes[i]->get_native_type()) { case GRIB_TYPE_LONG: dump_long_attribute(d, a->attributes[i], prefix); break; diff --git a/src/grib_dumper_class_bufr_encode_python.cc b/src/grib_dumper_class_bufr_encode_python.cc index 34367c913..565bc34ac 100644 --- a/src/grib_dumper_class_bufr_encode_python.cc +++ b/src/grib_dumper_class_bufr_encode_python.cc @@ -164,15 +164,15 @@ static void dump_values(grib_dumper* d, grib_accessor* a) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = size2 = count; if (size > 1) { values = (double*)grib_context_malloc_clear(c, sizeof(double) * size); - err = grib_unpack_double(a, values, &size2); + err = a->unpack_double(values, &size2); } else { - err = grib_unpack_double(a, &value, &size2); + err = a->unpack_double(&value, &size2); } Assert(size2 == size); @@ -258,15 +258,15 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = size2 = count; if (size > 1) { values = (double*)grib_context_malloc_clear(c, sizeof(double) * size); - err = grib_unpack_double(a, values, &size2); + err = a->unpack_double(values, &size2); } else { - err = grib_unpack_double(a, &value, &size2); + err = a->unpack_double(&value, &size2); } Assert(size2 == size); @@ -351,7 +351,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) } doing_unexpandedDescriptors = (strcmp(a->name, "unexpandedDescriptors") == 0); - grib_value_count(a, &count); + a->value_count(&count); size = size2 = count; if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { @@ -378,10 +378,10 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) if (size > 1) { values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); - err = grib_unpack_long(a, values, &size2); + err = a->unpack_long(values, &size2); } else { - err = grib_unpack_long(a, &value, &size2); + err = a->unpack_long(&value, &size2); } Assert(size2 == size); @@ -478,15 +478,15 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = size2 = count; if (size > 1) { values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); - err = grib_unpack_long(a, values, &size2); + err = a->unpack_long(values, &size2); } else { - err = grib_unpack_long(a, &value, &size2); + err = a->unpack_long(&value, &size2); } Assert(size2 == size); @@ -558,7 +558,7 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_unpack_double(a, &value, &size); + a->unpack_double(&value, &size); self->empty = 0; r = compute_bufr_key_rank(h, self->keys, a->name); @@ -603,7 +603,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size == 1) { dump_string(d, a, comment); @@ -620,7 +620,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm return; } - err = grib_unpack_string_array(a, values, &size); + err = a->unpack_string_array(values, &size); for (i = 0; i < size - 1; i++) { fprintf(self->dumper.out, " \"%s\", \n", values[i]); @@ -680,7 +680,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) self->empty = 0; - err = grib_unpack_string(a, value, &size); + err = a->unpack_string(value, &size); p = value; r = compute_bufr_key_rank(h, self->keys, acc_name); if (grib_is_missing_string(a, (unsigned char*)value, size)) { @@ -814,7 +814,7 @@ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix self->isLeaf = a->attributes[i]->attributes[0] == NULL ? 1 : 0; flags = a->attributes[i]->flags; a->attributes[i]->flags |= GRIB_ACCESSOR_FLAG_DUMP; - switch (grib_accessor_get_native_type(a->attributes[i])) { + switch (a->attributes[i]->get_native_type()) { case GRIB_TYPE_LONG: dump_long_attribute(d, a->attributes[i], prefix); break; diff --git a/src/grib_dumper_class_bufr_simple.cc b/src/grib_dumper_class_bufr_simple.cc index ca4701f38..868b81ba5 100644 --- a/src/grib_dumper_class_bufr_simple.cc +++ b/src/grib_dumper_class_bufr_simple.cc @@ -141,15 +141,15 @@ static void dump_values(grib_dumper* d, grib_accessor* a) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = size2 = count; if (size > 1) { values = (double*)grib_context_malloc_clear(c, sizeof(double) * size); - err = grib_unpack_double(a, values, &size2); + err = a->unpack_double(values, &size2); } else { - err = grib_unpack_double(a, &value, &size2); + err = a->unpack_double(&value, &size2); } Assert(size2 == size); @@ -231,15 +231,15 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = size2 = count; if (size > 1) { values = (double*)grib_context_malloc_clear(c, sizeof(double) * size); - err = grib_unpack_double(a, values, &size2); + err = a->unpack_double(values, &size2); } else { - err = grib_unpack_double(a, &value, &size2); + err = a->unpack_double(&value, &size2); } Assert(size2 == size); @@ -304,7 +304,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = size2 = count; if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { @@ -314,7 +314,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) /* Note: the "subsetNumber" key is only there for UNCOMPRESSED BUFR messages */ if (self->numberOfSubsets > 1 && strcmp(a->name, "subsetNumber") == 0) { - err = grib_unpack_long(a, &value, &size); + err = a->unpack_long(&value, &size); DEBUG_ASSERT(!err); fprintf(self->dumper.out, "%s=%ld\n", a->name, value); DEBUG_ASSERT(!grib_is_missing_long(a, value)); @@ -340,10 +340,10 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) if (size > 1) { values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); - err = grib_unpack_long(a, values, &size2); + err = a->unpack_long(values, &size2); } else { - err = grib_unpack_long(a, &value, &size2); + err = a->unpack_long(&value, &size2); } Assert(size2 == size); @@ -432,15 +432,15 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = size2 = count; if (size > 1) { values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); - err = grib_unpack_long(a, values, &size2); + err = a->unpack_long(values, &size2); } else { - err = grib_unpack_long(a, &value, &size2); + err = a->unpack_long(&value, &size2); } Assert(size2 == size); @@ -504,7 +504,7 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_unpack_double(a, &value, &size); + a->unpack_double(&value, &size); self->empty = 0; @@ -554,7 +554,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size == 1) { dump_string(d, a, comment); @@ -576,7 +576,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm return; } - err = grib_unpack_string_array(a, values, &size); + err = a->unpack_string_array(values, &size); fprintf(self->dumper.out, "{"); for (i = 0; i < size - 1; i++) { @@ -631,7 +631,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) self->empty = 0; - err = grib_unpack_string(a, value, &size); + err = a->unpack_string(value, &size); if (err) { fprintf(self->dumper.out, " *** ERR=%d (%s) [dump_string on '%s']", err, grib_get_error_message(err), acc_name); return; @@ -768,7 +768,7 @@ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix /* fprintf(out,"\"%s\" : ",a->attributes[i]->name); */ flags = a->attributes[i]->flags; a->attributes[i]->flags |= GRIB_ACCESSOR_FLAG_DUMP; - switch (grib_accessor_get_native_type(a->attributes[i])) { + switch (a->attributes[i]->get_native_type()) { case GRIB_TYPE_LONG: dump_long_attribute(d, a->attributes[i], prefix); break; diff --git a/src/grib_dumper_class_debug.cc b/src/grib_dumper_class_debug.cc index 77206c829..ead1c7cf4 100644 --- a/src/grib_dumper_class_debug.cc +++ b/src/grib_dumper_class_debug.cc @@ -188,14 +188,14 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) (d->option_flags & GRIB_DUMP_FLAG_READ_ONLY) == 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size > 1) { values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); - err = grib_unpack_long(a, values, &size); + err = a->unpack_long(values, &size); } else { - err = grib_unpack_long(a, &value, &size); + err = a->unpack_long(&value, &size); } set_begin_end(d, a); @@ -234,14 +234,14 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) } } else { - if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && grib_is_missing_internal(a)) + if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && a->is_missing_internal()) fprintf(self->dumper.out, "%ld-%ld %s %s = MISSING", self->begin, self->theEnd, a->creator->op, a->name); else fprintf(self->dumper.out, "%ld-%ld %s %s = %ld", self->begin, self->theEnd, a->creator->op, a->name, value); if (comment) fprintf(self->dumper.out, " [%s]", comment); if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) - fprintf(self->dumper.out, " (%s)", grib_get_type_name(grib_accessor_get_native_type(a))); + fprintf(self->dumper.out, " (%s)", grib_get_type_name(a->get_native_type())); if ((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) fprintf(self->dumper.out, " %s", "(can be missing)"); if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) @@ -266,7 +266,7 @@ static void dump_bits(grib_dumper* d, grib_accessor* a, const char* comment) grib_dumper_debug* self = (grib_dumper_debug*)d; long value = 0; size_t size = 1; - int err = grib_unpack_long(a, &value, &size); + int err = a->unpack_long(&value, &size); int i; if (a->length == 0 && @@ -303,7 +303,7 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) grib_dumper_debug* self = (grib_dumper_debug*)d; double value = 0; size_t size = 1; - int err = grib_unpack_double(a, &value, &size); + int err = a->unpack_double(&value, &size); int i; if (a->length == 0 && @@ -315,14 +315,14 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) for (i = 0; i < d->depth; i++) fprintf(self->dumper.out, " "); - if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && grib_is_missing_internal(a)) + if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && a->is_missing_internal()) fprintf(self->dumper.out, "%ld-%ld %s %s = MISSING", self->begin, self->theEnd, a->creator->op, a->name); else fprintf(self->dumper.out, "%ld-%ld %s %s = %g", self->begin, self->theEnd, a->creator->op, a->name, value); if (comment) fprintf(self->dumper.out, " [%s]", comment); if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) - fprintf(self->dumper.out, " (%s)", grib_get_type_name(grib_accessor_get_native_type(a))); + fprintf(self->dumper.out, " (%s)", grib_get_type_name(a->get_native_type())); if (err) fprintf(self->dumper.out, " *** ERR=%d (%s) [grib_dumper_debug::dump_double]", err, grib_get_error_message(err)); aliases(d, a); @@ -342,7 +342,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) return; grib_get_string_length_acc(a, &size); - if ((size < 2) && grib_is_missing_internal(a)) { + if ((size < 2) && a->is_missing_internal()) { /* GRIB-302: transients and missing keys. Need to re-adjust the size */ size = 10; /* big enough to hold the string "missing" */ } @@ -350,7 +350,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) value = (char*)grib_context_malloc_clear(a->context, size); if (!value) return; - err = grib_unpack_string(a, value, &size); + err = a->unpack_string(value, &size); if (err) strcpy(value, ""); @@ -372,7 +372,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) if (comment) fprintf(self->dumper.out, " [%s]", comment); if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) - fprintf(self->dumper.out, " (%s)", grib_get_type_name(grib_accessor_get_native_type(a))); + fprintf(self->dumper.out, " (%s)", grib_get_type_name(a->get_native_type())); if (err) fprintf(self->dumper.out, " *** ERR=%d (%s) [grib_dumper_debug::dump_string]", err, grib_get_error_message(err)); @@ -412,7 +412,7 @@ static void dump_bytes(grib_dumper* d, grib_accessor* a, const char* comment) fprintf(self->dumper.out, "\n"); - err = grib_unpack_bytes(a, buf, &size); + err = a->unpack_bytes(buf, &size); if (err) { grib_context_free(d->context, buf); fprintf(self->dumper.out, " *** ERR=%d (%s) [grib_dumper_debug::dump_bytes]\n}", err, grib_get_error_message(err)); @@ -463,7 +463,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) (d->option_flags & GRIB_DUMP_FLAG_CODED) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size == 1) { dump_double(d, a, NULL); @@ -489,7 +489,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) fprintf(self->dumper.out, "\n"); - err = grib_unpack_double(a, buf, &size); + err = a->unpack_double(buf, &size); if (err) { grib_context_free(d->context, buf); fprintf(self->dumper.out, " *** ERR=%d (%s) [grib_dumper_debug::dump_values]\n}", err, grib_get_error_message(err)); @@ -567,10 +567,10 @@ static void set_begin_end(grib_dumper* d, grib_accessor* a) grib_dumper_debug* self = (grib_dumper_debug*)d; if ((d->option_flags & GRIB_DUMP_FLAG_OCTET) != 0) { self->begin = a->offset - self->section_offset + 1; - self->theEnd = grib_get_next_position_offset(a) - self->section_offset; + self->theEnd = a->get_next_position_offset() - self->section_offset; } else { self->begin = a->offset; - self->theEnd = grib_get_next_position_offset(a); + self->theEnd = a->get_next_position_offset(); } } diff --git a/src/grib_dumper_class_default.cc b/src/grib_dumper_class_default.cc index e9bfdc702..819344cbe 100644 --- a/src/grib_dumper_class_default.cc +++ b/src/grib_dumper_class_default.cc @@ -147,7 +147,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = size2 = count; print_offset(self->dumper.out, d, a); @@ -159,10 +159,10 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) if (size > 1) { values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); - err = grib_unpack_long(a, values, &size2); + err = a->unpack_long(values, &size2); } else { - err = grib_unpack_long(a, &value, &size2); + err = a->unpack_long(&value, &size2); } Assert(size2 == size); @@ -195,7 +195,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) grib_context_free(a->context, values); } else { - if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && grib_is_missing_internal(a)) + if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && a->is_missing_internal()) fprintf(self->dumper.out, "%s = MISSING;", a->name); else fprintf(self->dumper.out, "%s = %ld;", a->name, value); @@ -224,12 +224,12 @@ static void dump_bits(grib_dumper* d, grib_accessor* a, const char* comment) int err = 0; int isDouble = 0; - switch (grib_accessor_get_native_type(a)) { + switch (a->get_native_type()) { case GRIB_TYPE_LONG: - grib_unpack_long(a, &lvalue, &size); + a->unpack_long(&lvalue, &size); break; case GRIB_TYPE_DOUBLE: - grib_unpack_double(a, &dvalue, &size); + a->unpack_double(&dvalue, &size); isDouble = 1; break; default: @@ -269,7 +269,7 @@ static void dump_bits(grib_dumper* d, grib_accessor* a, const char* comment) else fprintf(self->dumper.out, " "); - if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && grib_is_missing_internal(a)) + if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && a->is_missing_internal()) fprintf(self->dumper.out, "%s = MISSING;", a->name); else { if (isDouble) @@ -292,7 +292,7 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) grib_dumper_default* self = (grib_dumper_default*)d; double value = 0; size_t size = 1; - int err = grib_unpack_double(a, &value, &size); + int err = a->unpack_double(&value, &size); if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; @@ -318,7 +318,7 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) else fprintf(self->dumper.out, " "); - if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && grib_is_missing_internal(a)) + if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && a->is_missing_internal()) fprintf(self->dumper.out, "%s = MISSING;", a->name); else fprintf(self->dumper.out, "%s = %g;", a->name, value); @@ -341,7 +341,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm int tab = 0; long count = 0; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size == 1) { dump_string(d, a, comment); @@ -354,7 +354,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm return; } - err = grib_unpack_string_array(a, values, &size); + err = a->unpack_string_array(values, &size); if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; @@ -420,7 +420,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) return; } - err = grib_unpack_string(a, value, &size); + err = a->unpack_string(value, &size); p = value; while (*p) { @@ -449,7 +449,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) else fprintf(self->dumper.out, " "); - if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && grib_is_missing_internal(a)) + if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && a->is_missing_internal()) fprintf(self->dumper.out, "%s = MISSING;", a->name); else fprintf(self->dumper.out, "%s = %s;", a->name, value); @@ -499,7 +499,7 @@ static void dump_bytes(grib_dumper* d, grib_accessor* a, const char* comment) // fprintf(self->dumper.out,"\n"); -// err = grib_unpack_bytes(a,buf,&size); +// err = a->unpack_bytes(buf,&size); // if(err){ // grib_context_free(d->context,buf); // fprintf(self->dumper.out," *** ERR=%d (%s) [grib_dumper_default::dump_bytes]\n}",err,grib_get_error_message(err)); @@ -549,7 +549,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size == 1) { dump_double(d, a, NULL); @@ -562,7 +562,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) { char type_name[32] = ""; - const long native_type = grib_accessor_get_native_type(a); + const long native_type = a->get_native_type(); if (native_type == GRIB_TYPE_LONG) strcpy(type_name, "(int)"); else if (native_type == GRIB_TYPE_DOUBLE) @@ -596,7 +596,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) fprintf(self->dumper.out, "\n"); - err = grib_unpack_double(a, buf, &size); + err = a->unpack_double(buf, &size); if (err) { grib_context_free(d->context, buf); @@ -690,7 +690,7 @@ static void print_offset(FILE* out, grib_dumper* d, grib_accessor* a) grib_handle* h = grib_handle_of_accessor(a); theBegin = a->offset - self->section_offset + 1; - theEnd = grib_get_next_position_offset(a) - self->section_offset; + theEnd = a->get_next_position_offset() - self->section_offset; if ((d->option_flags & GRIB_DUMP_FLAG_HEXADECIMAL) != 0 && a->length != 0) { if (theBegin == theEnd) { diff --git a/src/grib_dumper_class_grib_encode_C.cc b/src/grib_dumper_class_grib_encode_C.cc index 5ecb6953d..5c41e11a0 100644 --- a/src/grib_dumper_class_grib_encode_C.cc +++ b/src/grib_dumper_class_grib_encode_C.cc @@ -130,7 +130,7 @@ 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); + int err = a->unpack_long(&value, &size); if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY)) return; @@ -161,7 +161,7 @@ static void dump_bits(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); + int err = a->unpack_long(&value, &size); int i; char buf[1024]; @@ -201,7 +201,7 @@ 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); + int err = a->unpack_double(&value, &size); if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) return; @@ -221,7 +221,7 @@ 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); + int err = a->unpack_string(value, &size); if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) return; @@ -260,7 +260,7 @@ static void dump_bytes(grib_dumper* d, grib_accessor* a, const char* comment) return; } - err = grib_unpack_bytes(a, buf, &size); + err = a->unpack_bytes(buf, &size); if (err) { grib_context_free(d->context, buf); fprintf(self->dumper.out, " *** ERR=%d (%s) [grib_dumper_grib_encode_C::dump_bytes]\n}", err, grib_get_error_message(err)); @@ -305,7 +305,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) 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); + a->value_count(&count); size = count; if (size == 1) { @@ -313,7 +313,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) return; } - type = grib_accessor_get_native_type(a); + type = a->get_native_type(); switch (type) { case GRIB_TYPE_LONG: snprintf(stype, sizeof(stype), "%s", "long"); @@ -331,7 +331,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) return; } - err = grib_unpack_double(a, buf, &size); + err = a->unpack_double(buf, &size); if (err) { grib_context_free(d->context, buf); diff --git a/src/grib_dumper_class_json.cc b/src/grib_dumper_class_json.cc index a3b052844..dd0210521 100644 --- a/src/grib_dumper_class_json.cc +++ b/src/grib_dumper_class_json.cc @@ -129,15 +129,15 @@ static void dump_values(grib_dumper* d, grib_accessor* a) return; h = grib_handle_of_accessor(a); - grib_value_count(a, &count); + a->value_count(&count); size = size2 = count; if (size > 1) { values = (double*)grib_context_malloc_clear(a->context, sizeof(double) * size); - err = grib_unpack_double(a, values, &size2); + err = a->unpack_double(values, &size2); } else { - err = grib_unpack_double(a, &value, &size2); + err = a->unpack_double(&value, &size2); } Assert(size2 == size); (void)err; /* TODO */ @@ -222,15 +222,15 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = size2 = count; if (size > 1) { values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); - err = grib_unpack_long(a, values, &size2); + err = a->unpack_long(values, &size2); } else { - err = grib_unpack_long(a, &value, &size2); + err = a->unpack_long(&value, &size2); } Assert(size2 == size); @@ -327,7 +327,7 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; - grib_unpack_double(a, &value, &size); + a->unpack_double(&value, &size); if (self->begin == 0 && self->empty == 0 && self->isAttribute == 0) fprintf(self->dumper.out, ",\n"); @@ -374,7 +374,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size == 1) { dump_string(d, a, comment); @@ -401,7 +401,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm return; } - err = grib_unpack_string_array(a, values, &size); + err = a->unpack_string_array(values, &size); if (self->isLeaf == 0) { fprintf(self->dumper.out, "%-*s", depth, " "); @@ -470,7 +470,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) self->empty = 0; - err = grib_unpack_string(a, value, &size); + err = a->unpack_string(value, &size); if (err) { snprintf(value, sizeof(value), " *** ERR=%d (%s) [dump_string on '%s']", err, grib_get_error_message(err), a->name); @@ -582,7 +582,7 @@ static void dump_attributes(grib_dumper* d, grib_accessor* a) fprintf(out, "\"%s\" : ", a->attributes[i]->name); flags = a->attributes[i]->flags; a->attributes[i]->flags |= GRIB_ACCESSOR_FLAG_DUMP; - switch (grib_accessor_get_native_type(a->attributes[i])) { + switch (a->attributes[i]->get_native_type()) { case GRIB_TYPE_LONG: dump_long(d, a->attributes[i], 0); break; diff --git a/src/grib_dumper_class_serialize.cc b/src/grib_dumper_class_serialize.cc index 6dc4d5c87..57f10cee0 100644 --- a/src/grib_dumper_class_serialize.cc +++ b/src/grib_dumper_class_serialize.cc @@ -102,7 +102,7 @@ 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); + int err = a->unpack_long(&value, &size); if ((a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0) return; @@ -136,7 +136,7 @@ static void dump_bits(grib_dumper* d, grib_accessor* a, const char* comment) grib_dumper_serialize* self = (grib_dumper_serialize*)d; long value; size_t size = 1; - int err = grib_unpack_long(a, &value, &size); + int err = a->unpack_long(&value, &size); if ((a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0) return; @@ -171,7 +171,7 @@ 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); + int err = a->unpack_double(&value, &size); if ((a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0) return; @@ -200,7 +200,7 @@ 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 err = a->unpack_string(value, &size); int i; char* p = value; @@ -261,7 +261,7 @@ static void dump_bytes(grib_dumper* d, grib_accessor* a, const char* comment) fprintf(self->dumper.out, "\n"); - err = grib_unpack_bytes(a, buf, &size); + err = a->unpack_bytes(buf, &size); if (err) { grib_context_free(d->context, buf); fprintf(self->dumper.out, " *** ERR=%d (%s) [grib_dumper_serialize::dump_bytes]\n}", err, grib_get_error_message(err)); @@ -319,7 +319,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY)) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (self->format) { @@ -376,7 +376,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) fprintf(self->dumper.out, "\n"); - err = grib_unpack_double(a, buf, &size); + err = a->unpack_double(buf, &size); if (err) { grib_context_free(d->context, buf); diff --git a/src/grib_dumper_class_wmo.cc b/src/grib_dumper_class_wmo.cc index 814ed016f..3949e97a2 100644 --- a/src/grib_dumper_class_wmo.cc +++ b/src/grib_dumper_class_wmo.cc @@ -152,15 +152,15 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) (d->option_flags & GRIB_DUMP_FLAG_CODED) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size > 1) { values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); - err = grib_unpack_long(a, values, &size); + err = a->unpack_long(values, &size); } else { - err = grib_unpack_long(a, &value, &size); + err = a->unpack_long(&value, &size); } if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && @@ -192,7 +192,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) } } else { - if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && grib_is_missing_internal(a)) + if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && a->is_missing_internal()) fprintf(self->dumper.out, "%s = MISSING", a->name); else fprintf(self->dumper.out, "%s = %ld", a->name, value); @@ -228,7 +228,7 @@ static void dump_bits(grib_dumper* d, grib_accessor* a, const char* comment) (d->option_flags & GRIB_DUMP_FLAG_CODED) != 0) return; - err = grib_unpack_long(a, &value, &size); + err = a->unpack_long(&value, &size); set_begin_end(d, a); //for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," "); @@ -274,7 +274,7 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) (d->option_flags & GRIB_DUMP_FLAG_CODED) != 0) return; - err = grib_unpack_double(a, &value, &size); + err = a->unpack_double(&value, &size); set_begin_end(d, a); //for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," "); @@ -283,7 +283,7 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) fprintf(self->dumper.out, "%s (double) ", a->creator->op); - if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && grib_is_missing_internal(a)) + if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && a->is_missing_internal()) fprintf(self->dumper.out, "%s = MISSING", a->name); else fprintf(self->dumper.out, "%s = %g", a->name, value); @@ -317,7 +317,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) grib_context_log(a->context, GRIB_LOG_ERROR, "unable to allocate %zu bytes", size); return; } - err = grib_unpack_string(a, value, &size); + err = a->unpack_string(value, &size); p = value; set_begin_end(d, a); @@ -381,7 +381,7 @@ static void dump_bytes(grib_dumper* d, grib_accessor* a, const char* comment) fprintf(self->dumper.out, "\n"); - err = grib_unpack_bytes(a, buf, &size); + err = a->unpack_bytes(buf, &size); if (err) { grib_context_free(d->context, buf); fprintf(self->dumper.out, " *** ERR=%d (%s) [grib_dumper_wmo::dump_bytes]\n}", err, grib_get_error_message(err)); @@ -433,7 +433,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) (d->option_flags & GRIB_DUMP_FLAG_CODED) != 0) return; - grib_value_count(a, &count); + a->value_count(&count); size = count; if (size == 1) { @@ -452,7 +452,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) print_offset(self->dumper.out, self->begin, self->theEnd, 12); // ECC-1749 if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) { char type_name[32] = ""; - const long native_type = grib_accessor_get_native_type(a); + const long native_type = a->get_native_type(); if (native_type == GRIB_TYPE_LONG) strcpy(type_name, "(int)"); else if (native_type == GRIB_TYPE_DOUBLE) @@ -476,7 +476,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) fprintf(self->dumper.out, "\n"); - err = grib_unpack_double(a, buf, &size); + err = a->unpack_double(buf, &size); if (err) { grib_context_free(d->context, buf); @@ -566,11 +566,11 @@ static void set_begin_end(grib_dumper* d, grib_accessor* a) grib_dumper_wmo* self = (grib_dumper_wmo*)d; if ((d->option_flags & GRIB_DUMP_FLAG_OCTET) != 0) { self->begin = a->offset - self->section_offset + 1; - self->theEnd = grib_get_next_position_offset(a) - self->section_offset; + self->theEnd = a->get_next_position_offset() - self->section_offset; } else { self->begin = a->offset; - self->theEnd = grib_get_next_position_offset(a); + self->theEnd = a->get_next_position_offset(); } } @@ -604,7 +604,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm return; c = a->context; - grib_value_count(a, &count); + a->value_count(&count); if (count == 0) return; size = count; @@ -619,7 +619,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm return; } - err = grib_unpack_string_array(a, values, &size); + err = a->unpack_string_array(values, &size); // print_offset(self->dumper.out,d,a); print_offset(self->dumper.out, self->begin, self->theEnd); diff --git a/src/grib_handle.cc b/src/grib_handle.cc index 1afad3476..a1801650a 100644 --- a/src/grib_handle.cc +++ b/src/grib_handle.cc @@ -54,7 +54,7 @@ static void update_sections(grib_section* s, grib_handle* h, long offset) a->offset += offset; /* update_sections ( grib_get_sub_section ( a ),h,offset ); */ update_sections(a->sub_section, h, offset); - a = a->next; + a = a->next_; } } @@ -74,7 +74,7 @@ void grib_swap_sections(grib_section* the_old, grib_section* the_new) a = the_old->block->first; while (a) { a->parent = the_old; - a = a->next; + a = a->next_; } update_sections(the_old, the_old->h, the_old->owner->offset); @@ -94,12 +94,12 @@ void grib_empty_section(grib_context* c, grib_section* b) current = b->block->first; while (current) { - grib_accessor* next = current->next; + grib_accessor* next = current->next_; if (current->sub_section) { grib_section_delete(c, current->sub_section); current->sub_section = 0; } - grib_accessor_delete(c, current); + current->destroy(c); current = next; } b->block->first = b->block->last = 0; @@ -637,7 +637,6 @@ static grib_handle* grib_handle_new_multi(grib_context* c, unsigned char** data, while (grib2_get_next_section((unsigned char*)message, olen, &secbegin, &seclen, &secnum, &err)) { // seccount++; /*printf(" - %d - section %d length=%d\n",(int)seccount,(int)secnum,(int)seclen);*/ - gm->sections[secnum] = secbegin; gm->sections_length[secnum] = seclen; @@ -686,6 +685,11 @@ static grib_handle* grib_handle_new_multi(grib_context* c, unsigned char** data, break; } } + // ECC-782 + if (err == GRIB_INVALID_SECTION_NUMBER) { + grib_context_log(c, GRIB_LOG_ERROR, "%s: Failed to get section info (%s)", __func__, grib_get_error_message(err)); + return NULL; + } } else if (edition == 3) { *error = GRIB_UNSUPPORTED_EDITION; @@ -840,6 +844,11 @@ static grib_handle* grib_handle_new_from_file_multi(grib_context* c, FILE* f, in break; } } + // ECC-782 + if (err == GRIB_INVALID_SECTION_NUMBER) { + grib_context_log(c, GRIB_LOG_ERROR, "%s: Failed to get section info (%s)", __func__, grib_get_error_message(err)); + return NULL; + } } else if (edition == 3) { /* GRIB3: Multi-field mode not yet supported */ diff --git a/src/grib_keys_iterator.cc b/src/grib_keys_iterator.cc index 854b4a2c5..06c112c04 100644 --- a/src/grib_keys_iterator.cc +++ b/src/grib_keys_iterator.cc @@ -165,11 +165,11 @@ int grib_keys_iterator_next(grib_keys_iterator* kiter) kiter->at_start = 0; } else { - kiter->current = grib_next_accessor(kiter->current); + kiter->current = kiter->current->next_accessor(); } while (kiter->current && skip(kiter)) - kiter->current = grib_next_accessor(kiter->current); + kiter->current = kiter->current->next_accessor(); return kiter->current != NULL; } @@ -200,29 +200,29 @@ int grib_keys_iterator_delete(grib_keys_iterator* kiter) int grib_keys_iterator_get_long(const grib_keys_iterator* kiter, long* v, size_t* len) { - return grib_unpack_long(kiter->current, v, len); + return kiter->current->unpack_long(v, len); } int grib_keys_iterator_get_double(const grib_keys_iterator* kiter, double* v, size_t* len) { - return grib_unpack_double(kiter->current, v, len); + return kiter->current->unpack_double(v, len); } int grib_keys_iterator_get_float(const grib_keys_iterator* kiter, float* v, size_t* len) { - return grib_unpack_float(kiter->current, v, len); + return kiter->current->unpack_float(v, len); } int grib_keys_iterator_get_string(const grib_keys_iterator* kiter, char* v, size_t* len) { - return grib_unpack_string(kiter->current, v, len); + return kiter->current->unpack_string(v, len); } int grib_keys_iterator_get_bytes(const grib_keys_iterator* kiter, unsigned char* v, size_t* len) { - return grib_unpack_bytes(kiter->current, v, len); + return kiter->current->unpack_bytes(v, len); } int grib_keys_iterator_get_native_type(const grib_keys_iterator* kiter) { - return grib_accessor_get_native_type(kiter->current); + return kiter->current->get_native_type(); } diff --git a/src/grib_loader_from_handle.cc b/src/grib_loader_from_handle.cc index 765915bbd..f26c68c21 100644 --- a/src/grib_loader_from_handle.cc +++ b/src/grib_loader_from_handle.cc @@ -27,14 +27,14 @@ static int copy_values(grib_handle* h, grib_accessor* ga) /*printf("SET VALUES %s\n",h->values[j][i].name);*/ switch (h->values[j][i].type) { case GRIB_TYPE_LONG: - return grib_pack_long(ga, &h->values[j][i].long_value, &len); + return ga->pack_long(&h->values[j][i].long_value, &len); case GRIB_TYPE_DOUBLE: - return grib_pack_double(ga, &h->values[j][i].double_value, &len); + return ga->pack_double(&h->values[j][i].double_value, &len); case GRIB_TYPE_STRING: len = strlen(h->values[j][i].string_value); - return grib_pack_string(ga, h->values[j][i].string_value, &len); + return ga->pack_string(h->values[j][i].string_value, &len); } } } @@ -50,7 +50,7 @@ int grib_lookup_long_from_handle(grib_context* gc, grib_loader* loader, const ch grib_accessor* b = grib_find_accessor(h, name); size_t len = 1; if (b) - return grib_unpack_long(b, value, &len); + return b->unpack_long(value, &len); /* TODO: fix me. For now, we don't fail on a lookup. */ *value = -1; @@ -80,7 +80,7 @@ int grib_init_accessor_from_handle(grib_loader* loader, grib_accessor* ga, grib_ if (default_value) { grib_context_log(h->context, GRIB_LOG_DEBUG, "Copying: setting %s to default value", ga->name); - grib_pack_expression(ga, grib_arguments_get_expression(h, default_value, 0)); + ga->pack_expression(grib_arguments_get_expression(h, default_value, 0)); } if ((ga->flags & GRIB_ACCESSOR_FLAG_NO_COPY) || @@ -153,11 +153,11 @@ int grib_init_accessor_from_handle(grib_loader* loader, grib_accessor* ga, grib_ } if ((ga->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) && grib_is_missing(h, name, &e) && e == GRIB_SUCCESS && len == 1) { - grib_pack_missing(ga); + ga->pack_missing(); pack_missing = 1; } - const long ga_type = grib_accessor_get_native_type(ga); + const long ga_type = ga->get_native_type(); if ((ga->flags & GRIB_ACCESSOR_FLAG_COPY_IF_CHANGING_EDITION) && !loader->changing_edition) { // See ECC-1560 and ECC-1644 @@ -173,7 +173,7 @@ int grib_init_accessor_from_handle(grib_loader* loader, grib_accessor* ga, grib_ ret = grib_get_string_internal(h, name, sval, &len); if (ret == GRIB_SUCCESS) { grib_context_log(h->context, GRIB_LOG_DEBUG, "Copying string %s to %s", sval, name); - ret = grib_pack_string(ga, sval, &len); + ret = ga->pack_string(sval, &len); } grib_context_free(h->context, sval); @@ -203,7 +203,7 @@ int grib_init_accessor_from_handle(grib_loader* loader, grib_accessor* ga, grib_ *lval = 0; /* Reset to a reasonable value */ } } - ret = grib_pack_long(ga, lval, &len); + ret = ga->pack_long(lval, &len); } } @@ -224,7 +224,7 @@ int grib_init_accessor_from_handle(grib_loader* loader, grib_accessor* ga, grib_ ret = GRIB_SUCCESS; } else - ret = grib_pack_double(ga, dval, &len); + ret = ga->pack_double(dval, &len); } grib_context_free(h->context, dval); @@ -233,13 +233,13 @@ int grib_init_accessor_from_handle(grib_loader* loader, grib_accessor* ga, grib_ case GRIB_TYPE_BYTES: ao = grib_find_accessor(h, name); - len = grib_byte_count(ao); + len = ao->byte_count(); uval = (unsigned char*)grib_context_malloc(h->context, len * sizeof(char)); - ret = grib_unpack_bytes(ao, uval, &len); + ret = ao->unpack_bytes(uval, &len); /* ret = grib_get_bytes_internal(h,name,uval,&len); */ if (ret == GRIB_SUCCESS) { grib_context_log(h->context, GRIB_LOG_DEBUG, "Copying %d byte(s) to %s", len, name); - ret = grib_pack_bytes(ga, uval, &len); + ret = ga->pack_bytes(uval, &len); } grib_context_free(h->context, uval); @@ -251,7 +251,7 @@ int grib_init_accessor_from_handle(grib_loader* loader, grib_accessor* ga, grib_ default: grib_context_log(h->context, GRIB_LOG_ERROR, - "Copying %s, cannot establish type %ld [%s]", name, grib_accessor_get_native_type(ga), ga->creator->cclass->name); + "Copying %s, cannot establish type %ld [%s]", name, ga->get_native_type(), ga->creator->cclass->name); break; } diff --git a/src/grib_parse_utils.cc b/src/grib_parse_utils.cc index 1d014995c..51de29332 100644 --- a/src/grib_parse_utils.cc +++ b/src/grib_parse_utils.cc @@ -117,16 +117,16 @@ int grib_recompose_name(grib_handle* h, grib_accessor* observer, const char* una switch (type) { case GRIB_TYPE_STRING: replen = 1024; - ret = grib_unpack_string(a, val, &replen); + ret = a->unpack_string(val, &replen); break; case GRIB_TYPE_DOUBLE: replen = 1; - ret = grib_unpack_double(a, &dval, &replen); + ret = a->unpack_double(&dval, &replen); snprintf(val, sizeof(val), "%.12g", dval); break; case GRIB_TYPE_LONG: replen = 1; - ret = grib_unpack_long(a, &lval, &replen); + ret = a->unpack_long(&lval, &replen); snprintf(val, sizeof(val), "%d", (int)lval); break; default: @@ -194,11 +194,11 @@ int grib_recompose_name(grib_handle* h, grib_accessor* observer, const char* una // grib_handle* h = grib_handle_of_accessor(a); // if (type == -1) -// type = grib_accessor_get_native_type(a); +// type = a->get_native_type(); // switch (type) { // case GRIB_TYPE_STRING: // replen = sizeof(sbuf) / sizeof(*sbuf); -// ret = grib_unpack_string(a, sbuf, &replen); +// ret = a->unpack_string(sbuf, &replen); // fprintf(out, "%s", sbuf); // break; // case GRIB_TYPE_DOUBLE: @@ -206,7 +206,7 @@ int grib_recompose_name(grib_handle* h, grib_accessor* observer, const char* una // myseparator = separator ? (char*)separator : default_separator; // if (name[0] == '/' || name[0] == '#') { // long count; -// ret = grib_value_count(a, &count); +// ret = a->value_count(&count); // size = count; // } // else { @@ -216,7 +216,7 @@ int grib_recompose_name(grib_handle* h, grib_accessor* observer, const char* una // dval = (double*)grib_context_malloc_clear(h->context, sizeof(double) * size); // if (name[0] == '/' || name[0] == '#') { // replen = size; -// ret = grib_unpack_double(a, dval, &replen); +// ret = a->unpack_double(dval, &replen); // } // else { // replen = 0; @@ -247,7 +247,7 @@ int grib_recompose_name(grib_handle* h, grib_accessor* observer, const char* una // myseparator = separator ? (char*)separator : default_separator; // if (name[0] == '/' || name[0] == '#') { // long count; -// ret = grib_value_count(a, &count); +// ret = a->value_count(&count); // size = count; // } // else { @@ -257,7 +257,7 @@ int grib_recompose_name(grib_handle* h, grib_accessor* observer, const char* una // lval = (long*)grib_context_malloc_clear(h->context, sizeof(long) * size); // if (name[0] == '/' || name[0] == '#') { // replen = size; -// ret = grib_unpack_long(a, lval, &replen); +// ret = a->unpack_long(lval, &replen); // } // else { // replen = 0; @@ -286,7 +286,7 @@ int grib_recompose_name(grib_handle* h, grib_accessor* observer, const char* una // case GRIB_TYPE_BYTES: // replen = a->length; // sval = (char*)grib_context_malloc(h->context, replen * sizeof(char)); -// ret = grib_unpack_string(a, sval, &replen); +// ret = a->unpack_string(sval, &replen); // p = sval; // while ((replen--) > 0) // fprintf(out, "%c", *(p++)); @@ -321,15 +321,15 @@ int grib_accessors_list_print(grib_handle* h, grib_accessors_list* al, const cha maxcols = INT_MAX; if (type == -1) - type = grib_accessor_get_native_type(al->accessor); - grib_accessors_list_value_count(al, &size); + type = al->accessor->get_native_type(); + al->value_count(&size); switch (type) { case GRIB_TYPE_STRING: myseparator = separator ? (char*)separator : default_separator; if (size == 1) { char sbuf[1024] = {0,}; len = sizeof(sbuf); - ret = grib_unpack_string(al->accessor, sbuf, &len); + ret = al->accessor->unpack_string(sbuf, &len); if (grib_is_missing_string(al->accessor, (unsigned char*)sbuf, len)) { fprintf(out, "%s", "MISSING"); } @@ -341,7 +341,7 @@ int grib_accessors_list_print(grib_handle* h, grib_accessors_list* al, const cha int cols = 0; j = 0; cvals = (char**)grib_context_malloc_clear(h->context, sizeof(char*) * size); - grib_accessors_list_unpack_string(al, cvals, &size); + al->unpack_string(cvals, &size); for (j = 0; j < size; j++) { *newline = 1; fprintf(out, "%s", cvals[j]); @@ -362,7 +362,7 @@ int grib_accessors_list_print(grib_handle* h, grib_accessors_list* al, const cha myformat = format ? (char*)format : double_format; myseparator = separator ? (char*)separator : default_separator; dval = (double*)grib_context_malloc_clear(h->context, sizeof(double) * size); - ret = grib_accessors_list_unpack_double(al, dval, &size); + ret = al->unpack_double(dval, &size); if (size == 1) fprintf(out, myformat, dval[0]); else { @@ -387,7 +387,7 @@ int grib_accessors_list_print(grib_handle* h, grib_accessors_list* al, const cha myformat = format ? (char*)format : long_format; myseparator = separator ? (char*)separator : default_separator; lval = (long*)grib_context_malloc_clear(h->context, sizeof(long) * size); - ret = grib_accessors_list_unpack_long(al, lval, &size); + ret = al->unpack_long(lval, &size); if (size == 1) fprintf(out, myformat, lval[0]); else { @@ -411,7 +411,7 @@ int grib_accessors_list_print(grib_handle* h, grib_accessors_list* al, const cha case GRIB_TYPE_BYTES: replen = a->length; bval = (unsigned char*)grib_context_malloc(h->context, replen * sizeof(unsigned char)); - ret = grib_unpack_bytes(al->accessor, bval, &replen); + ret = al->accessor->unpack_bytes(bval, &replen); for (j = 0; j < replen; j++) { fprintf(out, "%02x", bval[j]); } diff --git a/src/grib_query.cc b/src/grib_query.cc index 253217c0b..a1209efaf 100644 --- a/src/grib_query.cc +++ b/src/grib_query.cc @@ -14,6 +14,7 @@ * * ***************************************************************************/ #include "grib_api_internal.h" +#include "accessor/grib_accessor_class_bufr_data_array.h" /* Note: A fast cut-down version of strcmp which does NOT return -1 */ /* 0 means input strings are equal and 1 means not equal */ @@ -63,7 +64,7 @@ static grib_accessor* search(grib_section* s, const char* name, const char* name if ((b = search(sub, name, name_space)) != NULL) match = b; - a = a->next; + a = a->next_; } return match; @@ -94,7 +95,7 @@ static void rebuild_hash_keys(grib_handle* h, grib_section* s) i++; } rebuild_hash_keys(h, sub); - a = a->next; + a = a->next_; } } @@ -228,7 +229,7 @@ static grib_accessor* _search_by_rank(grib_accessor* a,const char* name,long ran if (r==rank) return al->accessor; r++; } - al=al->next; + al=al->next_; } return NULL; @@ -257,14 +258,14 @@ static int get_single_long_val(grib_accessor* a, long* result) size_t size = 1; if (c->bufr_multi_element_constant_arrays) { long count = 0; - grib_value_count(a, &count); + a->value_count(&count); if (count > 1) { size_t i = 0; long val0 = 0; int is_constant = 1; long* values = (long*)grib_context_malloc_clear(c, sizeof(long) * count); size = count; - err = grib_unpack_long(a, values, &size); + err = a->unpack_long(values, &size); val0 = values[0]; for (i = 0; i < size; i++) { if (val0 != values[i]) { @@ -281,11 +282,11 @@ static int get_single_long_val(grib_accessor* a, long* result) } } else { - err = grib_unpack_long(a, result, &size); + err = a->unpack_long(result, &size); } } else { - err = grib_unpack_long(a, result, &size); + err = a->unpack_long(result, &size); } return err; } @@ -296,14 +297,14 @@ static int get_single_double_val(grib_accessor* a, double* result) size_t size = 1; if (c->bufr_multi_element_constant_arrays) { long count = 0; - grib_value_count(a, &count); + a->value_count(&count); if (count > 1) { size_t i = 0; double val0 = 0; int is_constant = 1; double* values = (double*)grib_context_malloc_clear(c, sizeof(double) * count); size = count; - err = grib_unpack_double(a, values, &size); + err = a->unpack_double(values, &size); val0 = values[0]; for (i = 0; i < size; i++) { if (val0 != values[i]) { @@ -320,11 +321,11 @@ static int get_single_double_val(grib_accessor* a, double* result) } } else { - err = grib_unpack_double(a, result, &size); + err = a->unpack_double(result, &size); } } else { - err = grib_unpack_double(a, result, &size); + err = a->unpack_double(result, &size); } return err; } @@ -377,27 +378,27 @@ static void search_from_accessors_list(grib_accessors_list* al, const grib_acces while (al && al != end && al->accessor) { if (grib_inline_strcmp(al->accessor->name, accessor_name) == 0) { if (attribute_name[0]) { - accessor_result = grib_accessor_get_attribute(al->accessor, attribute_name); + accessor_result = al->accessor->get_attribute(attribute_name); } else { accessor_result = al->accessor; } if (accessor_result) { - grib_accessors_list_push(result, accessor_result, al->rank); + result->push(accessor_result, al->rank()); } } - al = al->next; + al = al->next_; } if (al == end && al->accessor) { if (grib_inline_strcmp(al->accessor->name, accessor_name) == 0) { if (attribute_name[0]) { - accessor_result = grib_accessor_get_attribute(al->accessor, attribute_name); + accessor_result = al->accessor->get_attribute(attribute_name); } else { accessor_result = al->accessor; } if (accessor_result) { - grib_accessors_list_push(result, accessor_result, al->rank); + result->push(accessor_result, al->rank()); } } } @@ -416,7 +417,7 @@ static void search_accessors_list_by_condition(grib_accessors_list* al, const ch if (start && !condition_true(al->accessor, condition)) end = al; } - if (start != NULL && (end != NULL || al->next == NULL)) { + if (start != NULL && (end != NULL || al->next_ == NULL)) { if (end == NULL) end = al; search_from_accessors_list(start, end, name, result); @@ -424,7 +425,7 @@ static void search_accessors_list_by_condition(grib_accessors_list* al, const ch start = NULL; end = NULL; } - al = al->next; + al = al->next_; } } @@ -452,7 +453,7 @@ static void grib_find_same_and_push(grib_accessors_list* al, grib_accessor* a) { if (a) { grib_find_same_and_push(al, a->same); - grib_accessors_list_push(al, a, al->rank); + al->push(a, al->rank()); } } @@ -484,7 +485,7 @@ grib_accessors_list* grib_find_accessors_list(const grib_handle* ch, const char* int r; al = (grib_accessors_list*)grib_context_malloc_clear(h->context, sizeof(grib_accessors_list)); str2 = get_rank(h->context, name, &r); - grib_accessors_list_push(al, a, r); + al->push(a, r); grib_context_free(h->context, str2); } } @@ -585,7 +586,7 @@ grib_accessor* grib_find_accessor(const grib_handle* h, const char* name) aret = a; } else if (a) { - aret = grib_accessor_get_attribute(a, attribute_name); + aret = a->get_attribute(attribute_name); grib_context_free(h->context, accessor_name); } } @@ -600,7 +601,7 @@ grib_accessor* grib_find_accessor(const grib_handle* h, const char* name) // *err = GRIB_NOT_FOUND; // return NULL; // } -// if ((act = grib_accessor_get_attribute(a, attr_name)) == NULL) { +// if ((act = a->get_attribute(attr_name)) == NULL) { // *err = GRIB_ATTRIBUTE_NOT_FOUND; // return NULL; // } diff --git a/src/grib_value.cc b/src/grib_value.cc index f1675ccd2..1142fa6a6 100644 --- a/src/grib_value.cc +++ b/src/grib_value.cc @@ -13,9 +13,10 @@ #include "grib_api_internal.h" #include "grib_value.h" -#include "grib_accessor.h" +//#include "grib_accessor.h" #include #include +#include /* Note: A fast cut-down version of strcmp which does NOT return -1 */ /* 0 means input strings are equal and 1 means not equal */ @@ -70,7 +71,7 @@ int grib_set_expression(grib_handle* h, const char* name, grib_expression* e) if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) return GRIB_READ_ONLY; - ret = grib_pack_expression(a, e); + ret = a->pack_expression(e); if (ret == GRIB_SUCCESS) { return grib_dependency_notify_change(a); } @@ -92,7 +93,7 @@ int grib_set_long_internal(grib_handle* h, const char* name, long val) fprintf(stderr, "ECCODES DEBUG grib_set_long_internal h=%p %s=%ld\n", (void*)h, name, val); if (a) { - ret = grib_pack_long(a, &val, &l); + ret = a->pack_long(&val, &l); if (ret == GRIB_SUCCESS) { return grib_dependency_notify_change(a); } @@ -125,7 +126,7 @@ int grib_set_long(grib_handle* h, const char* name, long val) if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) return GRIB_READ_ONLY; - ret = grib_pack_long(a, &val, &l); + ret = a->pack_long(&val, &l); if (ret == GRIB_SUCCESS) return grib_dependency_notify_change(a); @@ -151,7 +152,7 @@ int grib_set_double_internal(grib_handle* h, const char* name, double val) fprintf(stderr, "ECCODES DEBUG grib_set_double_internal h=%p %s=%.10g\n", (void*)h, name, val); if (a) { - ret = grib_pack_double(a, &val, &l); + ret = a->pack_double(&val, &l); if (ret == GRIB_SUCCESS) { return grib_dependency_notify_change(a); } @@ -357,7 +358,7 @@ int grib_set_double(grib_handle* h, const char* name, double val) if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) return GRIB_READ_ONLY; - ret = grib_pack_double(a, &val, &l); + ret = a->pack_double(&val, &l); if (ret == GRIB_SUCCESS) return grib_dependency_notify_change(a); @@ -378,7 +379,7 @@ int grib_set_string_internal(grib_handle* h, const char* name, fprintf(stderr, "ECCODES DEBUG grib_set_string_internal h=%p %s=%s\n", (void*)h, name, val); if (a) { - ret = grib_pack_string(a, val, length); + ret = a->pack_string(val, length); if (ret == GRIB_SUCCESS) { return grib_dependency_notify_change(a); } @@ -475,7 +476,7 @@ int grib_set_string(grib_handle* h, const char* name, const char* val, size_t* l if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) return GRIB_READ_ONLY; - ret = grib_pack_string(a, val, length); + ret = a->pack_string(val, length); if (ret == GRIB_SUCCESS) { return grib_dependency_notify_change(a); } @@ -504,7 +505,7 @@ int grib_set_string_array(grib_handle* h, const char* name, const char** val, si if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) return GRIB_READ_ONLY; - ret = grib_pack_string_array(a, val, &length); + ret = a->pack_string_array(val, &length); if (ret == GRIB_SUCCESS) { return grib_dependency_notify_change(a); } @@ -519,7 +520,7 @@ int grib_set_string_array(grib_handle* h, const char* name, const char** val, si // grib_accessor* a = NULL; // a = grib_find_accessor(h, name); // if (a) { -// ret = grib_pack_bytes(a, val, length); +// ret = a->pack_bytes(val, length); // if (ret == GRIB_SUCCESS) { // return grib_dependency_notify_change(a); // } @@ -540,7 +541,7 @@ int grib_set_bytes(grib_handle* h, const char* name, const unsigned char* val, s /* if(a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) */ /* return GRIB_READ_ONLY; */ - ret = grib_pack_bytes(a, val, length); + ret = a->pack_bytes(val, length); if (ret == GRIB_SUCCESS) { return grib_dependency_notify_change(a); } @@ -557,7 +558,7 @@ int grib_set_bytes(grib_handle* h, const char* name, const unsigned char* val, s // if (a) { // if (a->length == 0) // return 0; -// if ((ret = grib_pack_zero(a)) != GRIB_SUCCESS) +// if ((ret = a->grib_pack_zero()) != GRIB_SUCCESS) // grib_context_log(h->context, GRIB_LOG_ERROR, "Unable to clear %s (%s)", // name, grib_get_error_message(ret)); // return ret; @@ -581,7 +582,7 @@ int grib_set_missing(grib_handle* h, const char* name) if (h->context->debug) fprintf(stderr, "ECCODES DEBUG grib_set_missing h=%p %s\n", (void*)h, name); - ret = grib_pack_missing(a); + ret = a->pack_missing(); if (ret == GRIB_SUCCESS) return grib_dependency_notify_change(a); } @@ -637,7 +638,7 @@ int grib_accessor_is_missing(grib_accessor* a, int* err) *err = GRIB_SUCCESS; if (a) { if (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) - return grib_is_missing_internal(a); + return a->is_missing_internal(); else return 0; } @@ -697,7 +698,7 @@ static int _grib_set_double_array_internal(grib_handle* h, grib_accessor* a, if (err == GRIB_SUCCESS) { size_t len = buffer_len - *encoded_length; if (len) { - err = grib_pack_double(a, val + *encoded_length, &len); + err = a->pack_double(val + *encoded_length, &len); *encoded_length += len; if (err == GRIB_SUCCESS) { /* See ECC-778 */ @@ -729,7 +730,7 @@ static int _grib_set_double_array(grib_handle* h, const char* name, if (name[0] == '/' || name[0] == '#') { if (check && (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY)) return GRIB_READ_ONLY; - err = grib_pack_double(a, val, &length); + err = a->pack_double(val, &length); encoded = length; } else @@ -754,7 +755,7 @@ int grib_set_double_array_internal(grib_handle* h, const char* name, const doubl if (length == 0) { grib_accessor* a = grib_find_accessor(h, name); - ret = grib_pack_double(a, val, &length); + ret = a->pack_double(val, &length); } else { ret = _grib_set_double_array(h, name, val, length, 0); @@ -783,7 +784,7 @@ static int __grib_set_double_array(grib_handle* h, const char* name, const doubl if (length == 0) { grib_accessor* a = grib_find_accessor(h, name); - return grib_pack_double(a, val, &length); + return a->pack_double(val, &length); } /*second order doesn't have a proper representation for constant fields @@ -873,7 +874,7 @@ static int _grib_set_long_array_internal(grib_handle* h, grib_accessor* a, const if (err == GRIB_SUCCESS) { size_t len = buffer_len - *encoded_length; if (len) { - err = grib_pack_long(a, val + *encoded_length, &len); + err = a->pack_long(val + *encoded_length, &len); *encoded_length += len; } else { @@ -915,7 +916,7 @@ 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); + err = a->pack_long(val, &length); encoded = length; } else @@ -989,14 +990,14 @@ int grib_get_long(const grib_handle* h, const char* name, long* val) al = grib_find_accessors_list(h, name); if (!al) return GRIB_NOT_FOUND; - ret = grib_unpack_long(al->accessor, val, &length); + ret = al->accessor->unpack_long(val, &length); grib_context_free(h->context, al); } else { a = grib_find_accessor(h, name); if (!a) return GRIB_NOT_FOUND; - ret = grib_unpack_long(a, val, &length); + ret = a->unpack_long(val, &length); } return ret; } @@ -1024,14 +1025,14 @@ int grib_get_double(const grib_handle* h, const char* name, double* val) al = grib_find_accessors_list(h, name); if (!al) return GRIB_NOT_FOUND; - ret = grib_unpack_double(al->accessor, val, &length); + ret = al->accessor->unpack_double(val, &length); grib_context_free(h->context, al); } else { a = grib_find_accessor(h, name); if (!a) return GRIB_NOT_FOUND; - ret = grib_unpack_double(a, val, &length); + ret = a->unpack_double(val, &length); } return ret; } @@ -1047,14 +1048,14 @@ int grib_get_float(const grib_handle* h, const char* name, float* val) al = grib_find_accessors_list(h, name); if (!al) return GRIB_NOT_FOUND; - ret = grib_unpack_float(al->accessor, val, &length); + ret = al->accessor->unpack_float(val, &length); grib_context_free(h->context, al); } else { a = grib_find_accessor(h, name); if (!a) return GRIB_NOT_FOUND; - ret = grib_unpack_float(a, val, &length); + ret = a->unpack_float(val, &length); } return ret; } @@ -1076,7 +1077,7 @@ int grib_get_double_element(const grib_handle* h, const char* name, int i, doubl grib_accessor* act = grib_find_accessor(h, name); if (act) { - return grib_unpack_double_element(act, i, val); + return act->unpack_double_element(i, val); } return GRIB_NOT_FOUND; } @@ -1085,7 +1086,7 @@ int grib_get_float_element(const grib_handle* h, const char* name, int i, float* grib_accessor* act = grib_find_accessor(h, name); if (act) { - return grib_unpack_float_element(act, i, val); + return act->unpack_float_element(i, val); } return GRIB_NOT_FOUND; } @@ -1118,7 +1119,7 @@ int grib_get_double_element_set(const grib_handle* h, const char* name, const si grib_accessor* acc = grib_find_accessor(h, name); if (acc) { - return grib_unpack_double_element_set(acc, index_array, len, val_array); + return acc->unpack_double_element_set(index_array, len, val_array); } return GRIB_NOT_FOUND; } @@ -1127,7 +1128,7 @@ int grib_get_float_element_set(const grib_handle* h, const char* name, const siz grib_accessor* acc = grib_find_accessor(h, name); if (acc) { - return grib_unpack_float_element_set(acc, index_array, len, val_array); + return acc->unpack_float_element_set(index_array, len, val_array); } return GRIB_NOT_FOUND; } @@ -1168,7 +1169,7 @@ int grib_get_double_elements(const grib_handle* h, const char* name, const int* return GRIB_OUT_OF_MEMORY; } - err = grib_unpack_double(act, values, &size); + err = act->unpack_double(values, &size); if (!err) { for (j = 0; j < len; j++) { val_array[j] = values[index_array[j]]; @@ -1206,7 +1207,7 @@ int grib_get_string(const grib_handle* h, const char* name, char* val, size_t* l al = grib_find_accessors_list(h, name); if (!al) return GRIB_NOT_FOUND; - ret = grib_unpack_string(al->accessor, val, length); + ret = al->accessor->unpack_string(val, length); grib_context_free(h->context, al); return ret; } @@ -1214,7 +1215,7 @@ int grib_get_string(const grib_handle* h, const char* name, char* val, size_t* l a = grib_find_accessor(h, name); if (!a) return GRIB_NOT_FOUND; - return grib_unpack_string(a, val, length); + return a->unpack_string(val, length); } } @@ -1232,7 +1233,7 @@ int grib_get_bytes(const grib_handle* h, const char* name, unsigned char* val, s { int err = 0; grib_accessor* act = grib_find_accessor(h, name); - err = act ? grib_unpack_bytes(act, val, length) : GRIB_NOT_FOUND; + err = act ? act->unpack_bytes(val, length) : GRIB_NOT_FOUND; if (err) grib_context_log(h->context, GRIB_LOG_ERROR, "grib_get_bytes %s failed %s", name, grib_get_error_message(err)); @@ -1251,14 +1252,14 @@ int grib_get_native_type(const grib_handle* h, const char* name, int* type) al = grib_find_accessors_list(h, name); if (!al) return GRIB_NOT_FOUND; - *type = grib_accessor_get_native_type(al->accessor); + *type = al->accessor->get_native_type(); grib_context_free(h->context, al); } else { a = grib_find_accessor(h, name); if (!a) return GRIB_NOT_FOUND; - *type = grib_accessor_get_native_type(a); + *type = a->get_native_type(); } return GRIB_SUCCESS; @@ -1279,7 +1280,12 @@ static int _grib_get_array_internal(const grib_handle* h, grib_accessor* a, T* v if (err == GRIB_SUCCESS) { size_t len = buffer_len - *decoded_length; - err = grib_unpack(a, val + *decoded_length, &len); + if constexpr (std::is_same::value) { + err = a->unpack_double(val + *decoded_length, &len); + } + else if constexpr (std::is_same::value) { + err = a->unpack_float(val + *decoded_length, &len); + } *decoded_length += len; } @@ -1311,7 +1317,7 @@ int grib_get_double_array(const grib_handle* h, const char* name, double* val, s al = grib_find_accessors_list(h, name); if (!al) return GRIB_NOT_FOUND; - ret = grib_accessors_list_unpack_double(al, val, length); + ret = al->unpack_double(val, length); grib_accessors_list_delete(h->context, al); return ret; } @@ -1320,7 +1326,7 @@ int grib_get_double_array(const grib_handle* h, const char* name, double* val, s if (!a) return GRIB_NOT_FOUND; if (name[0] == '#') { - return grib_unpack(a, val, length); + return a->unpack_double(val, length); } else { *length = 0; @@ -1364,7 +1370,7 @@ int grib_get_string_length_acc(grib_accessor* a, size_t* size) *size = 0; while (a) { - s = grib_string_length(a); + s = a->string_length(); if (s > *size) *size = s; a = a->same; @@ -1407,7 +1413,7 @@ int grib_get_size_acc(const grib_handle* h, grib_accessor* a, size_t* size) *size = 0; while (a) { if (err == 0) { - err = grib_value_count(a, &count); + err = a->value_count(&count); if (err) return err; *size += count; @@ -1429,7 +1435,7 @@ int grib_get_size(const grib_handle* ch, const char* name, size_t* size) al = grib_find_accessors_list(h, name); if (!al) return GRIB_NOT_FOUND; - ret = grib_accessors_list_value_count(al, size); + ret = al->value_count(size); grib_accessors_list_delete(h->context, al); return ret; } @@ -1439,7 +1445,7 @@ int grib_get_size(const grib_handle* ch, const char* name, size_t* size) return GRIB_NOT_FOUND; if (name[0] == '#') { long count = *size; - ret = grib_value_count(a, &count); + ret = a->value_count(&count); *size = count; return ret; } @@ -1471,7 +1477,7 @@ int grib_get_offset(const grib_handle* ch, const char* key, size_t* val) const grib_handle* h = (grib_handle*)ch; grib_accessor* act = grib_find_accessor(h, key); if (act) { - *val = (size_t)grib_byte_offset(act); + *val = (size_t) act->byte_offset(); return GRIB_SUCCESS; } return GRIB_NOT_FOUND; @@ -1484,7 +1490,7 @@ static int grib_get_string_array_internal_(const grib_handle* h, grib_accessor* if (err == GRIB_SUCCESS) { size_t len = buffer_len - *decoded_length; - err = grib_unpack_string_array(a, val + *decoded_length, &len); + err = a->unpack_string_array(val + *decoded_length, &len); *decoded_length += len; } @@ -1506,7 +1512,7 @@ int grib_get_string_array(const grib_handle* h, const char* name, char** val, si al = grib_find_accessors_list(h, name); if (!al) return GRIB_NOT_FOUND; - ret = grib_accessors_list_unpack_string(al, val, length); + ret = al->unpack_string(val, length); grib_context_free(h->context, al); return ret; } @@ -1515,7 +1521,7 @@ int grib_get_string_array(const grib_handle* h, const char* name, char** val, si if (!a) return GRIB_NOT_FOUND; if (name[0] == '#') { - return grib_unpack_string_array(a, val, length); + return a->unpack_string_array(val, length); } else { *length = 0; @@ -1531,7 +1537,7 @@ static int _grib_get_long_array_internal(const grib_handle* h, grib_accessor* a, if (err == GRIB_SUCCESS) { size_t len = buffer_len - *decoded_length; - err = grib_unpack_long(a, val + *decoded_length, &len); + err = a->unpack_long(val + *decoded_length, &len); *decoded_length += len; } @@ -1565,7 +1571,7 @@ int grib_get_long_array(const grib_handle* h, const char* name, long* val, size_ al = grib_find_accessors_list(h, name); if (!al) return GRIB_NOT_FOUND; - ret = grib_accessors_list_unpack_long(al, val, length); + ret = al->unpack_long(val, length); grib_context_free(h->context, al); } else { @@ -1573,7 +1579,7 @@ int grib_get_long_array(const grib_handle* h, const char* name, long* val, size_ if (!a) return GRIB_NOT_FOUND; if (name[0] == '#') { - return grib_unpack_long(a, val, length); + return a->unpack_long(val, length); } else { *length = 0; @@ -1838,7 +1844,7 @@ int grib_get_nearest_smaller_value(grib_handle* h, const char* name, { grib_accessor* act = grib_find_accessor(h, name); Assert(act); - return grib_nearest_smaller_value(act, val, nearest); + return act->nearest_smaller_value(val, nearest); } void grib_print_values(const char* title, grib_values* values, FILE* out) @@ -2028,5 +2034,5 @@ int codes_compare_key(grib_handle* h1, grib_handle* h2, const char* key, int com return GRIB_NOT_FOUND; } - return grib_compare_accessors(a1, a2, GRIB_COMPARE_TYPES); + return a1->compare_accessors(a2, GRIB_COMPARE_TYPES); } diff --git a/src/shared_functions.cc b/src/shared_functions.cc new file mode 100644 index 000000000..fc6f090fb --- /dev/null +++ b/src/shared_functions.cc @@ -0,0 +1,47 @@ +#include "shared_functions.h" + + +/* Table of multipliers to convert step units to minutes */ +static const double u2m[] = { + 1, /* index 0: minutes */ + 60, /* index 1: hour */ + 24 * 60, /* index 2: day */ + 24 * 60 * 30, /* index 3: month */ + -1, /* index 4: year */ + -1, /* index 5: decade */ + -1, /* index 6: 30 years */ + -1, /* index 7: century */ + -1, /* index 8: RESERVED */ + -1, /* index 9: RESERVED */ + 3 * 60, /* index 10: 3 hours */ + 6 * 60, /* index 11: 6 hours */ + 12 * 60, /* index 12: 12 hours */ + 1 / 60.0, /* index 13: seconds */ + 15, /* index 14: 15 mins */ + 30 /* index 15: 30 mins */ +}; + + +void grib_set_bit_on(unsigned char* p, long* bitp){ + unsigned char o = 1; + p += (*bitp >> 3); + o <<= 7 - ((*bitp) % 8); + *p |= o; + (*bitp) += 1; +} + +long convert_to_minutes(long step, long stepUnits) +{ + double result = 0; + if (stepUnits == 0) + return step; /* unit=minutes so no change */ + if (stepUnits == 1) + return step * 60; /* unit=hours */ + if (stepUnits == 13) + return step / 60; /* unit=seconds */ + /* Assert( stepUnits < sizeof(u2m)/sizeof(u2m[0]) ); */ + + result = step * u2m[stepUnits]; + return (long)result; +} + diff --git a/src/shared_functions.h b/src/shared_functions.h new file mode 100644 index 000000000..04ae2f90f --- /dev/null +++ b/src/shared_functions.h @@ -0,0 +1,9 @@ +#ifndef eccodes_shared_functions_h +#define eccodes_shared_functions_h + +#include "grib_api_internal.h" + +void grib_set_bit_on(unsigned char*, long*); +long convert_to_minutes(long step, long stepUnits); + +#endif // eccodes_shared_functions_h diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ac0f133de..0169e4986 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -148,6 +148,7 @@ if( HAVE_BUILD_TOOLS ) grib_ecc-1691 grib_ecc-1766 grib_ecc-1806 + grib_ecc-1829 bufr_ecc-1028 bufr_ecc-1195 bufr_ecc-1259 @@ -155,6 +156,7 @@ if( HAVE_BUILD_TOOLS ) bufr_ecc-1304 bufr_ecc-1347 bufr_ecc-1395 + bufr_ecc-1840 bufr_json_samples bufr_ecc-359 bufr_ecc-517 diff --git a/tests/bufr_ecc-1840.sh b/tests/bufr_ecc-1840.sh new file mode 100755 index 000000000..34acb5bf6 --- /dev/null +++ b/tests/bufr_ecc-1840.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# (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. +# + +. ./include.ctest.sh + +REDIRECT=/dev/null + +label="bufr_ecc-1840_test" +tempBufr=temp.$label.bufr +tempFilt=temp.$label.filt +tempLog=temp.$label.log +tempOut=temp.$label.txt +tempRef=temp.$label.ref + +sample_bufr3=$ECCODES_SAMPLES_PATH/BUFR3.tmpl + +# This sample has: +# typicalYearOfCentury = 12 +# typicalMonth = 10 +# typicalDay = 31 +result=$(${tools_dir}/bufr_get -p typicalYear,typicalDate $sample_bufr3) +[ "$result" = "2012 20121031" ] +result=$(${tools_dir}/bufr_get -p typicalYear,typicalDate -s typicalCentury=20 $sample_bufr3) +[ "$result" = "1912 19121031" ] + + +# Clean up +rm -f $tempBufr $tempFilt $tempLog $tempOut $tempRef diff --git a/tests/bufr_extract_headers.sh b/tests/bufr_extract_headers.sh index 481a5cd2f..4b2b92b08 100755 --- a/tests/bufr_extract_headers.sh +++ b/tests/bufr_extract_headers.sh @@ -64,7 +64,7 @@ r=`${test_dir}/bufr_extract_headers centre ${data_dir}/bufr/israel_observations_ # Check all centres with an abbreviation centre_table=${ECCODES_DEFINITION_PATH}/common/c-11.table -centres=`awk 'NR > 1 {print $2}' < $centre_table` +centres=`awk 'NR > 1 && $1 !~ /#/ {print $2}' < $centre_table` for c in $centres; do ${tools_dir}/bufr_set -s centre=$c $ECCODES_SAMPLES_PATH/BUFR4.tmpl $temp1 r=`${test_dir}/bufr_extract_headers centre $temp1` diff --git a/tests/grib_ecc-1806.sh b/tests/grib_ecc-1806.sh index fcd4684f2..e08f667a6 100755 --- a/tests/grib_ecc-1806.sh +++ b/tests/grib_ecc-1806.sh @@ -42,11 +42,11 @@ test_conversion() test_conversion 174098 262000 sithick test_conversion 151163 262104 t20d test_conversion 151145 262124 zos -test_conversion 130232 235135 mw +test_conversion 130232 235135 avg_w test_conversion 172146 235033 msshf test_conversion 172147 235034 mslhf test_conversion 55 228004 mean2t -test_conversion 56 235168 m2d +test_conversion 56 235168 avg_2d test_conversion 172169 235035 msdwswrf test_conversion 172175 235036 msdwlwrf test_conversion 172176 235037 msnswrf diff --git a/tests/grib_ecc-1829.sh b/tests/grib_ecc-1829.sh new file mode 100755 index 000000000..9e075e6b8 --- /dev/null +++ b/tests/grib_ecc-1829.sh @@ -0,0 +1,50 @@ +#!/bin/sh +# (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. +# + +. ./include.ctest.sh + +REDIRECT=/dev/null + +# ECC-1829: Add MARS support for stream & type combinations required for AIFS ensemble + +label="grib_ecc-1829_test" +temp_grib=temp.$label.grib +mars_sample=temp.$label.mars.grib +sample_grib2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl + +# Setup GRIB2 message with MARS keys +${tools_dir}/grib_set -s setLocalDefinition=1,grib2LocalSectionNumber=1 $sample_grib2 $mars_sample + +# Now set ensemble related keys and check number key is present +${tools_dir}/grib_set -s stream=oper,type=pf,productDefinitionTemplateNumber=1 $mars_sample $temp_grib +grib_check_key_exists $temp_grib mars.number + +# Now set keys and check stepRange is used for mars.step for o2d and o3d fields, and that number is still present +${tools_dir}/grib_set -s stream=oper,type=pf,productDefinitionTemplateNumber=11,param=263101,typeOfLevel=oceanSurface,startStep=0,endStep=6 $mars_sample $temp_grib +grib_check_key_exists $temp_grib mars.number +grib_check_key_equals $temp_grib "step" "0-6" +${tools_dir}/grib_set -s stream=oper,type=pf,productDefinitionTemplateNumber=11,param=263501,typeOfLevel=oceanModel,level=1,startStep=0,endStep=6 $mars_sample $temp_grib +grib_check_key_exists $temp_grib mars.number +grib_check_key_equals $temp_grib "step" "0-6" + +# Now set keys and check stepRange is used for type efi data (just need any template with stat proc keys) +${tools_dir}/grib_set -s stream=oper,type=efi,productDefinitionTemplateNumber=12,startStep=0,endStep=6 $mars_sample $temp_grib +grib_check_key_equals $temp_grib "step" "0-6" + +# Now set keys and check stepRange is used for type em data +${tools_dir}/grib_set -s stream=oper,type=em,productDefinitionTemplateNumber=12,startStep=0,endStep=6 $mars_sample $temp_grib +grib_check_key_equals $temp_grib "step" "0-6" + +# Now set keys and check stepRange is used for type es data +${tools_dir}/grib_set -s stream=oper,type=es,productDefinitionTemplateNumber=12,startStep=0,endStep=6 $mars_sample $temp_grib +grib_check_key_equals $temp_grib "step" "0-6" + +# Clean up +rm -f $temp_grib $mars_sample diff --git a/tests/grib_to_netcdf.sh b/tests/grib_to_netcdf.sh index f13d8475b..ba3589329 100755 --- a/tests/grib_to_netcdf.sh +++ b/tests/grib_to_netcdf.sh @@ -110,6 +110,14 @@ ${tools_dir}/grib_to_netcdf -o $tempNetcdf $tempGrib ${tools_dir}/grib_set -s productDefinitionTemplateNumber=31 $sample2 $tempGrib ${tools_dir}/grib_to_netcdf -o $tempNetcdf $tempGrib +ECCODES_DEBUG=-1 ${tools_dir}/grib_to_netcdf -o $tempNetcdf $tempGrib + + +# The -u option +input=${data_dir}/sample.grib2 +${tools_dir}/grib_to_netcdf -u time -o $tempNetcdf $input + + echo "Test different resolutions ..." # ------------------------------------ # This should fail as messages have different resolutions @@ -170,6 +178,26 @@ set -e grep -q "Wrong message length" $tempText +# Non-GRIB input +input=$data_dir/bufr/aaen_55.bufr +set +e +${tools_dir}/grib_to_netcdf -o $tempNetcdf $input > $tempText 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "Input does not contain any field" $tempText + + +# Bad reference date +input=$data_dir/sample.grib2 +set +e +${tools_dir}/grib_to_netcdf -Rxxx -o $tempNetcdf $input > $tempText 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "Invalid reference date" $tempText + + # Validity time check export GRIB_TO_NETCDF_CHECKVALIDTIME=0 ${tools_dir}/grib_to_netcdf -o $tempNetcdf $tempGrib diff --git a/tests/grib_unpack_subarray.cc b/tests/grib_unpack_subarray.cc index 3321b4040..1a7bfadab 100644 --- a/tests/grib_unpack_subarray.cc +++ b/tests/grib_unpack_subarray.cc @@ -34,12 +34,12 @@ int main(int argc, char** argv) Assert(sub_values); size_t len = nvalues; - GRIB_CHECK(grib_unpack_double(a, all_values, &len), 0); + GRIB_CHECK(a->unpack_double(all_values, &len), 0); size_t start = nvalues / 10; len = nvalues / 5; printf("nvalues=%zu, start=%zu, len=%zu\n", nvalues, start, len); - GRIB_CHECK(grib_unpack_double_subarray(a, sub_values, start, len), 0); + GRIB_CHECK(a->unpack_double_subarray(sub_values, start, len), 0); for (size_t i = 0; i < len; ++i) { //printf("sub[%zu]=%.10e\n", start + i, sub_values[i]); Assert(all_values[start+i] == sub_values[i]); diff --git a/tools/bufr_dump.cc b/tools/bufr_dump.cc index ae4c485cc..6c31ce76e 100644 --- a/tools/bufr_dump.cc +++ b/tools/bufr_dump.cc @@ -9,6 +9,7 @@ */ #include "grib_tools.h" +#include "accessor/grib_accessor_class_bufr_data_array.h" grib_option grib_options[] = { /* {id, args, help}, on, command_line, value*/