-
Notifications
You must be signed in to change notification settings - Fork 16
fdb-adopt to re-index an existing grib file #305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
danovaro
wants to merge
1
commit into
develop
Choose a base branch
from
feature/adopt
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -455,6 +455,7 @@ if(HAVE_FDB_BUILD_TOOLS) | |
| endif() | ||
|
|
||
| list( APPEND fdb5_tools | ||
| fdb-adopt | ||
| fdb-axes | ||
| fdb-write | ||
| fdb-copy | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /* | ||
| * (C) Copyright 1996- ECMWF. | ||
| * | ||
| * This software is licensed under the terms of the Apache Licence Version 2.0 | ||
| * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
| * In applying this licence, ECMWF does not 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 "eckit/log/Bytes.h" | ||
| #include "eckit/log/Plural.h" | ||
| #include "eckit/log/Progress.h" | ||
| #include "eckit/log/Seconds.h" | ||
| #include "eckit/log/Timer.h" | ||
| #include "eckit/message/Message.h" | ||
| #include "eckit/message/Reader.h" | ||
| #include "eckit/option/CmdArgs.h" | ||
|
|
||
| #include "fdb5/api/FDB.h" | ||
| #include "fdb5/database/Key.h" | ||
| #include "fdb5/message/MessageDecoder.h" | ||
| #include "fdb5/toc/TocFieldLocation.h" | ||
| #include "fdb5/tools/FDBTool.h" | ||
|
|
||
| //---------------------------------------------------------------------------------------------------------------------- | ||
| namespace fdb5::tools { | ||
|
|
||
| class FDBAdopt : public fdb5::FDBTool { | ||
|
|
||
| virtual void execute(const eckit::option::CmdArgs& args); | ||
| virtual void usage(const std::string& tool) const; | ||
| virtual int minimumPositionalArguments() const { return 1; } | ||
|
|
||
| public: | ||
|
|
||
| FDBAdopt(int argc, char** argv) : fdb5::FDBTool(argc, argv) {} | ||
| }; | ||
|
|
||
| void FDBAdopt::usage(const std::string& tool) const { | ||
| eckit::Log::info() << std::endl << "Usage: " << tool << " gribfile1 [gribfile2] ..." << std::endl; | ||
| fdb5::FDBTool::usage(tool); | ||
| } | ||
|
|
||
| void FDBAdopt::execute(const eckit::option::CmdArgs& args) { | ||
|
|
||
| FDB fdb(config(args)); | ||
| fdb5::MessageDecoder decoder; | ||
|
|
||
| for (size_t i = 0; i < args.count(); i++) { | ||
| eckit::PathName path(args(i)); | ||
|
|
||
| if (!path.exists()) { | ||
| throw eckit::UserError("File does not exist: " + args(i), Here()); | ||
| } | ||
| if (path.isDir()) { | ||
| throw eckit::UserError("Expected a file but got a directory: " + args(i), Here()); | ||
| } | ||
| // Index GRIB file | ||
| eckit::Log::info() << "Processing file " << path << std::endl; | ||
|
|
||
| eckit::message::Reader reader(path); | ||
| eckit::message::Message msg; | ||
|
|
||
| size_t count = 0; | ||
| eckit::Length total_size = 0; | ||
| eckit::Length totalFileSize = path.size(); | ||
| eckit::Timer timer; | ||
| timer.start(); | ||
|
|
||
| eckit::Progress progress("Scanning", 0, totalFileSize); | ||
|
|
||
| eckit::PathName full(path.realName()); | ||
| eckit::URI uri("file", full); | ||
|
|
||
| while ((msg = reader.next())) { | ||
| fdb5::Key key; | ||
| decoder.messageToKey(msg, key); | ||
|
|
||
| eckit::Length length = msg.length(); | ||
| eckit::Offset offset = reader.position() - length; | ||
|
|
||
| fdb.reindex(key, fdb5::TocFieldLocation{uri, offset, length, fdb5::Key()}); | ||
|
|
||
| total_size += length; | ||
| progress(total_size); | ||
| count++; | ||
| } | ||
|
|
||
| eckit::Log::info() << "FDB indexed " << eckit::Plural(count, "field") << "," | ||
| << " size " << eckit::Bytes(total_size) << "," | ||
| << " in " << eckit::Seconds(timer.elapsed()) << " (" << eckit::Bytes(total_size, timer) | ||
| << ")" << std::endl; | ||
| } | ||
| } | ||
|
|
||
| } // namespace fdb5::tools | ||
|
|
||
| //---------------------------------------------------------------------------------------------------------------------- | ||
|
|
||
| int main(int argc, char** argv) { | ||
| fdb5::tools::FDBAdopt app(argc, argv); | ||
| return app.start(); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.