Skip to content

Commit e8e01cc

Browse files
committed
Remove usage of GribHandle in metkit/pointdb
1 parent 9cadd2f commit e8e01cc

File tree

10 files changed

+32
-61
lines changed

10 files changed

+32
-61
lines changed

src/metkit/codes/CodesDataContent.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#include "eckit/io/DataHandle.h"
1717
#include "eckit/io/MemoryHandle.h"
1818

19-
#include "metkit/codes/GribHandle.h"
20-
2119
namespace metkit {
2220
namespace codes {
2321

src/metkit/codes/CodesSplitter.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
#include "eccodes.h"
1414

1515
#include "eckit/io/PeekHandle.h"
16-
#include "eckit/log/Log.h"
1716
#include "eckit/message/Message.h"
1817

1918
#include "metkit/codes/CodesDataContent.h"
20-
#include "metkit/codes/GribHandle.h"
2119
#include "metkit/codes/api/CodesAPI.h"
2220
#include "metkit/codes/api/CodesTypes.h"
2321

src/metkit/codes/GribHandle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class GribHandle : private eckit::NonCopyable {
113113
bool owned_;
114114
};
115115

116-
//------------------------------------------------------------------------------------------------------
116+
//----------------------------------------------------------------------------------------------------------------------
117117

118118
} // namespace grib
119119
} // namespace metkit

src/metkit/codes/GribIterator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class GribIterator : private eckit::NonCopyable {
4242
grib_iterator* iterator_;
4343
};
4444

45-
//------------------------------------------------------------------------------------------------------
45+
//----------------------------------------------------------------------------------------------------------------------
4646

4747
} // namespace grib
4848
} // namespace metkit

src/metkit/pointdb/GribFieldInfo.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
*/
1010

1111
#include "metkit/pointdb/GribFieldInfo.h"
12-
#include "metkit/pointdb/GribDataSource.h"
1312
#include "metkit/codes/api/CodesAPI.h"
13+
#include "metkit/pointdb/GribDataSource.h"
1414

1515
#include <bitset>
1616

src/metkit/pointdb/GribFieldInfo.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,10 @@
1919
#include "eckit/types/FixedString.h"
2020

2121

22-
2322
namespace eckit {
2423
class PathName;
2524
}
26-
namespace metkit {
27-
namespace grib {
28-
class GribHandle;
29-
}
30-
31-
32-
namespace pointdb {
25+
namespace metkit::pointdb {
3326

3427

3528
class GribDataSource;
@@ -73,8 +66,7 @@ class GribFieldInfo {
7366
}
7467
};
7568

76-
} // namespace pointdb
77-
} // namespace metkit
69+
} // namespace metkit::pointdb
7870

7971

8072
#endif

src/metkit/pointdb/GribHandleDataSource.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,12 @@ const GribFieldInfo& GribHandleDataSource::info() const {
8181
open();
8282

8383
handle_->seek(offset_);
84+
auto codesHandle = codes::codesHandleFromStream(
85+
[&](uint8_t* buffer, int64_t len) -> int64_t { return handle_->read(buffer, len); });
8486

85-
grib::GribHandle h(*handle_);
86-
info_.update(h);
87+
ASSERT(codesHandle);
88+
89+
info_.update(*codesHandle.get());
8790

8891
cache.dirName().mkdir();
8992

@@ -92,7 +95,7 @@ const GribFieldInfo& GribHandleDataSource::info() const {
9295
f.close();
9396

9497

95-
PointIndex::cache(h);
98+
PointIndex::cache(*codesHandle.get());
9699
}
97100
}
98101
return info_;

src/metkit/pointdb/PointIndex.cc

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
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

src/metkit/pointdb/PointIndex.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,13 @@
1111
#ifndef PointIndex_H
1212
#define PointIndex_H
1313

14-
// #include <cmath>
1514
#include <memory>
1615

17-
// #include "eckit/eckit.h"
18-
// #include "eckit/filesystem/PathName.h"
19-
20-
2116
#include "eckit/container/KDTree.h"
2217
#include "eckit/geometry/Point3.h"
18+
#include "metkit/codes/api/CodesAPI.h"
2319

2420
namespace metkit {
25-
namespace grib {
26-
class GribHandle;
27-
}
28-
2921
namespace pointdb {
3022

3123

@@ -99,7 +91,7 @@ class PointIndex {
9991
NodeInfo nearestNeighbour(double lat, double lon);
10092

10193
static PointIndex& lookUp(const std::string& md5);
102-
static std::string cache(const metkit::grib::GribHandle& h);
94+
static std::string cache(const metkit::codes::CodesHandle& h);
10395

10496
static eckit::PathName cachePath(const std::string& dir, const std::string& name);
10597

tests/CMakeLists.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,6 @@ ecbuild_add_test( TARGET metkit_test_odbsplitter
5555
NO_AS_NEEDED
5656
LIBS metkit )
5757

58-
ecbuild_add_test( TARGET metkit_test_gribhandle
59-
CONDITION HAVE_GRIB
60-
SOURCES test_gribhandle.cc
61-
INCLUDES "${ECKIT_INCLUDE_DIRS}" "${ECCODES_INCLUDE_DIR}"
62-
LIBS metkit
63-
TEST_DEPENDS grib_get_data
64-
NO_AS_NEEDED
65-
ENVIRONMENT "${metkit_env}")
66-
6758
foreach( test
6859
c_api
6960
codes_api

0 commit comments

Comments
 (0)