1414// #include "eckit/log/Timer.h"
1515
1616#include " metkit/pointdb/PointIndex.h"
17+ #include " eckit/io/FileHandle.h"
1718#include " eckit/thread/AutoLock.h"
18- #include " metkit/codes/GribHandle.h"
19- #include " metkit/codes/GribIterator.h"
2019// #include "eckit/io/StdFile.h"
2120#include " eckit/config/Resource.h"
21+ #include " metkit/codes/api/CodesAPI.h"
2222
2323// #include "eccodes.h"
2424
@@ -36,11 +36,9 @@ eckit::PathName PointIndex::cachePath(const std::string& dir, const std::string&
3636 return pointdbCachePath / dir / name;
3737}
3838
39- std::string PointIndex::cache (const metkit::grib::GribHandle & h) {
39+ std::string PointIndex::cache (const metkit::codes::CodesHandle & h) {
4040
41- double lat, lon, value;
42-
43- std::string md5 = h.geographyHash ();
41+ std::string md5 = h.getString (" md5GridSection" );
4442
4543
4644 AutoLock<Mutex> lock (mutex);
@@ -55,26 +53,20 @@ std::string PointIndex::cache(const metkit::grib::GribHandle& h) {
5553 }
5654 path.dirName ().mkdir ();
5755
58- size_t v = h.getDataValuesSize ( );
56+ size_t v = h.size ( " values " );
5957
6058
6159 std::vector<Point> p;
6260 p.reserve (v);
6361
64-
65- metkit::grib::GribIterator iter (h);
6662 size_t j = 0 ;
63+ for (auto data : h.values ()) {
64+ while (data.longitude < 0 )
65+ data.longitude += 360 ;
66+ while (data.longitude >= 360 )
67+ data.longitude -= 360 ;
6768
68- while (iter.next (lat, lon, value)) {
69-
70- while (lon < 0 )
71- lon += 360 ;
72- while (lon >= 360 )
73- lon -= 360 ;
74-
75- // ASSERT(lat >= -90 && lat <= 90);
76-
77- p.push_back (Point (lat, lon, j));
69+ p.push_back (Point (data.latitude , data.longitude , j));
7870 j++;
7971 }
8072
@@ -90,8 +82,13 @@ std::string PointIndex::cache(const metkit::grib::GribHandle& h) {
9082 // codes_dump_content(h, f, "debug", 0, 0);
9183 // f.close();
9284
85+ // Write handle to file
9386 PathName grib = cachePath (" grids" , md5 + " .grib" );
94- h.write (grib);
87+ eckit::FileHandle fh (grib.localPath ());
88+ auto data = h.messageData ();
89+ fh.openForWrite (data.size ());
90+ fh.write (data.data (), data.size ());
91+ fh.close ();
9592
9693 PathName::rename (tmp, path);
9794
@@ -111,9 +108,9 @@ PointIndex& PointIndex::lookUp(const std::string& md5) {
111108 PathName grib = cachePath (" grids" , md5 + " .grib" );
112109 if (grib.exists ()) {
113110 Log::warning () << " Rebuilding index from " << grib << std::endl;
114- metkit:: grib::GribHandle h (grib );
111+ auto codesHandle = codes::codesHandleFromFile ( grib. localPath (), codes::Product::GRIB );
115112
116- ASSERT (cache (h ) == md5);
113+ ASSERT (cache (*codesHandle. get () ) == md5);
117114 }
118115 }
119116
0 commit comments