@@ -53,7 +53,7 @@ class ParamID {
5353
5454 template <typename REQUEST_T, typename AXIS_T>
5555 static void normalise (const REQUEST_T& r, std::vector<Param>& req, const AXIS_T& axis, bool & windConversion,
56- bool fullTableDropping = ParamID::fullTableDropping(), bool useParamId = false);
56+ bool fullTableDropping = ParamID::fullTableDropping(), bool forceGRIBParamID = false);
5757
5858 static const std::vector<WindFamily>& getWindFamilies ();
5959 static const std::vector<size_t >& getDropTables ();
@@ -69,16 +69,14 @@ inline long replaceTable(size_t table, long paramid) {
6969
7070template <typename REQUEST_T, typename AXIS_T>
7171void ParamID::normalise (const REQUEST_T& request, std::vector<Param>& req, const AXIS_T& axis, bool & windConversion,
72- bool fullTableDropping, bool forceUseGRIBParamId ) {
72+ bool fullTableDropping, bool forceGRIBParamID ) {
7373
7474 static const bool useGRIBParamID = eckit::Resource<bool >(" useGRIBParamID" , false );
75-
76- bool useParamId = useGRIBParamID || forceUseGRIBParamId;
75+ bool strict = useGRIBParamID || forceGRIBParamID;
7776
7877 const std::vector<WindFamily>& windFamilies (getWindFamilies ());
7978
80- std::vector<std::pair<Param, Param> > tableDropped;
81-
79+ std::vector<std::pair<Param, Param>> tableDropped;
8280 std::set<Param> inAxis;
8381 std::map<long , Param> inAxisParamID;
8482 std::set<Param> wind;
@@ -91,89 +89,87 @@ void ParamID::normalise(const REQUEST_T& request, std::vector<Param>& req, const
9189 std::vector<Param> newreq;
9290 newreq.reserve (req.size ());
9391
94- for (auto r : req) {
92+ for (const auto & r : req) {
9593 if (inAxis.find (r) != inAxis.end ()) { // Perfect match - look no further
9694 newreq.push_back (r);
9795 }
9896 else { // r is normalised to ParamID
99- long paramid = r.paramId ();
100- auto ap = inAxisParamID.find (paramid);
101- if (ap != inAxisParamID.end ()) { // ParamID representation matching - look no further
97+ long paramid = r.paramId ();
98+ const auto & ap = inAxisParamID.find (paramid);
99+
100+ // ParamID representation matching - look no further
101+ if (ap != inAxisParamID.end ()) {
102102 newreq.push_back (ap->second );
103103 }
104104 else { // Special case for U/V - exact match
105105 bool ok = false ;
106- for (eckit::Ordinal w = 0 ; w < windFamilies.size (); w++) {
107- if ((paramid == windFamilies[w].u_ .paramId () || (!useParamId && paramid == windFamilies[w].u_ .grib1value ()) ||
108- paramid == windFamilies[w].v_ .paramId () || (!useParamId && paramid == windFamilies[w].v_ .grib1value ())) &&
109- inAxis.find (windFamilies[w].vo_ ) != inAxis.end () &&
110- inAxis.find (windFamilies[w].d_ ) != inAxis.end ()) {
111-
112- if (paramid == windFamilies[w].u_ .paramId () || paramid == windFamilies[w].u_ .grib1value ())
113- newreq.push_back (windFamilies[w].u_ );
106+ for (const auto & wf : windFamilies) {
107+ if ((paramid == wf.u_ .paramId () || paramid == wf.v_ .paramId () ||
108+ (!strict && (paramid == wf.u_ .grib1value () || paramid == wf.v_ .grib1value ()))) &&
109+ inAxis.find (wf.vo_ ) != inAxis.end () && inAxis.find (wf.d_ ) != inAxis.end ()) {
110+
111+ if (paramid == wf.u_ .paramId () || (!strict && paramid == wf.u_ .grib1value ()))
112+ newreq.push_back (wf.u_ );
114113 else
115- newreq.push_back (windFamilies[w] .v_ );
114+ newreq.push_back (wf .v_ );
116115
117- wind.emplace (windFamilies[w] .vo_ );
118- wind.emplace (windFamilies[w] .d_ );
116+ wind.emplace (wf .vo_ );
117+ wind.emplace (wf .d_ );
119118 windConversion = true ;
120119
121120 ok = true ;
122121 break ;
123122 }
124123 }
125- if (!useParamId) {
126- if (!ok && r.table () == 0 &&
127- paramid < 1000 ) { // Partial match (only it table has not been specified by user)
128- const std::vector<size_t >& dropTables = ParamID::getDropTables ();
129- for (auto t : dropTables) {
130- auto ap = inAxisParamID.find (replaceTable (t, paramid));
131- if (ap != inAxisParamID.end ()) { // ParamID representation matching - look no further
132- newreq.push_back (ap->second );
133- ok = true ;
134- break ;
135- }
124+ // Partial match (only it table has not been specified by user)
125+ if (!ok && !strict && r.table () == 0 && paramid < 1000 ) {
126+ const std::vector<size_t >& dropTables = ParamID::getDropTables ();
127+ for (auto t : dropTables) {
128+ auto ap = inAxisParamID.find (replaceTable (t, paramid));
129+ if (ap != inAxisParamID.end ()) { // ParamID representation matching - look no further
130+ newreq.push_back (ap->second );
131+ ok = true ;
132+ break ;
136133 }
134+ }
137135
138- if (!ok) { // Special case for U/V - partial match
139- for (eckit::Ordinal w = 0 ; !ok && w < windFamilies.size (); w++) {
140- if (paramid == windFamilies[w].u_ .paramId () ||
141- paramid == windFamilies[w].v_ .paramId ()) {
142- for (auto t : dropTables) {
143- auto vo = inAxisParamID.find (replaceTable (t, windFamilies[w].vo_ .paramId ()));
144- auto d = inAxisParamID.find (replaceTable (t, windFamilies[w].d_ .paramId ()));
145-
146- if (vo != inAxisParamID.end () && d != inAxisParamID.end ()) {
147- bool grib1 = vo->second .table () > 0 ;
148- if (paramid == windFamilies[w].u_ .paramId ())
149- newreq.push_back (grib1 ? Param (t, paramid)
150- : Param (0 , replaceTable (t, paramid)));
151- else
152- newreq.push_back (grib1 ? Param (t, paramid)
153- : Param (0 , replaceTable (t, paramid)));
154-
155- wind.emplace (vo->second );
156- wind.emplace (d->second );
157- windConversion = true ;
158-
159- ok = true ;
160- break ;
161- }
162- }
163- if (ok)
136+ if (!ok) { // Special case for U/V - partial match
137+ for (const auto & wf : windFamilies) {
138+ if (paramid == wf.u_ .paramId () || paramid == wf.v_ .paramId ()) {
139+ for (auto t : dropTables) {
140+ auto vo = inAxisParamID.find (replaceTable (t, wf.vo_ .paramId ()));
141+ auto d = inAxisParamID.find (replaceTable (t, wf.d_ .paramId ()));
142+
143+ if (vo != inAxisParamID.end () && d != inAxisParamID.end ()) {
144+ bool grib1 = vo->second .table () > 0 ;
145+ if (paramid == wf.u_ .paramId ())
146+ newreq.push_back (grib1 ? Param (t, paramid)
147+ : Param (0 , replaceTable (t, paramid)));
148+ else
149+ newreq.push_back (grib1 ? Param (t, paramid)
150+ : Param (0 , replaceTable (t, paramid)));
151+
152+ wind.emplace (vo->second );
153+ wind.emplace (d->second );
154+ windConversion = true ;
155+
156+ ok = true ;
164157 break ;
158+ }
165159 }
160+ if (ok)
161+ break ;
166162 }
167163 }
168- if (fullTableDropping &&
169- !ok) { // Backward compatibility - Partial match (drop completely table information)
170- for ( auto ap : inAxisParamID) {
171- if (ap. first % 1000 == paramid % 1000 ) {
172- newreq. push_back (ap. second );
173- ok = true ;
174- tableDropped. push_back ( std::make_pair (r, ap. second )) ;
175- break ;
176- }
164+ }
165+ if (fullTableDropping &&
166+ !ok) { // Backward compatibility - Partial match (drop completely table information)
167+ for ( const auto & ap : inAxisParamID ) {
168+ if (ap. first % 1000 == paramid % 1000 ) {
169+ newreq. push_back (ap. second ) ;
170+ ok = true ;
171+ tableDropped. push_back ( std::make_pair (r, ap. second )) ;
172+ break ;
177173 }
178174 }
179175 }
@@ -183,7 +179,7 @@ void ParamID::normalise(const REQUEST_T& request, std::vector<Param>& req, const
183179 }
184180 req = newreq;
185181
186- for (auto w : wind) {
182+ for (const auto & w : wind) {
187183 bool exist = false ;
188184 for (eckit::Ordinal i = 0 ; i < req.size (); i++)
189185 if (req[i] == w) {
0 commit comments