diff --git a/src/bufr_tools/bufresohmsg_py.cpp b/src/bufr_tools/bufresohmsg_py.cpp index e25f7ef..04f0399 100644 --- a/src/bufr_tools/bufresohmsg_py.cpp +++ b/src/bufr_tools/bufresohmsg_py.cpp @@ -170,6 +170,17 @@ bool norbufr_init_oscar(std::string oscardb_dir) { return ret; } +std::string oscar_wigos_find(std::string wigosId) { + std::string ret; + std::string found_wid; + + found_wid = oscar.findWigosId(wigosId); + if (found_wid.size()) { + ret = oscar.to_string(found_wid); + } + return ret; +} + bool norbufr_init_schema_template(std::string schema_path) { if (schema_path.size()) { @@ -422,6 +433,7 @@ PYBIND11_MODULE(bufresohmsg_py, m) { m.def("bufrlog_clear_py", &norbufr_log_clear, "Clear log messages list"); m.def("init_oscar_py", &norbufr_init_oscar, "Init OSCAR db"); + m.def("oscar_wigos_find_py", &oscar_wigos_find, "Search WigosId in OSCAR db"); m.def("init_bufr_schema_py", &norbufr_init_schema_template, "Init BUFR schema"); m.def("bufr_sdwigos_py", &norbufr_set_default_wigos, diff --git a/src/bufr_tools/bufresohmsg_py.h b/src/bufr_tools/bufresohmsg_py.h index 4ae5037..c1eed83 100644 --- a/src/bufr_tools/bufresohmsg_py.h +++ b/src/bufr_tools/bufresohmsg_py.h @@ -48,6 +48,7 @@ std::list norbufr_log(); void norbufr_log_clear(); bool norbufr_init_oscar(std::string oscardb_dir); +std::string oscar_wigos_find(std::string wigosId); bool norbufr_init_schema_template(std::string schema_path); void norbufr_set_default_wigos(std::string s); diff --git a/src/bufr_tools/oscar_find_wigos.py b/src/bufr_tools/oscar_find_wigos.py new file mode 100644 index 0000000..c7b79aa --- /dev/null +++ b/src/bufr_tools/oscar_find_wigos.py @@ -0,0 +1,24 @@ +import sys + + +from bufr_tools.getenvvalue import getOscarDumpPath + +from bufr_tools.bufresohmsg_py import init_oscar_py # noqa: E402 +from bufr_tools.bufresohmsg_py import oscar_wigos_find_py # noqa: E402 + +OSCAR_DUMP = getOscarDumpPath() + +init_oscar_py(OSCAR_DUMP) + + +if __name__ == "__main__": + if len(sys.argv) > 1: + for i, wigosId in enumerate(sys.argv): + if i < 1: + continue + msg = oscar_wigos_find_py(wigosId) + print(msg) + else: + print("Usage: python3 oscar_find_wigos.py WigosId(s)") + + exit(0) diff --git a/src/bufr_tools/utils/oscar_test.cpp b/src/bufr_tools/utils/oscar_test.cpp new file mode 100644 index 0000000..5c7b865 --- /dev/null +++ b/src/bufr_tools/utils/oscar_test.cpp @@ -0,0 +1,34 @@ + + +#include +#include + +#include "Oscar.h" +#include "WSI.h" + +int main(int argc, char *argv[]) { + + if (argc <= 2) { + std::cerr << "Usage: " << std::string(argv[0]) + << " OSCAR_Db_file WigosID\n"; + std::cerr << "Example: " << std::string(argv[0]) + << " oscar_stations_all.json 0-22000-0-ZZEHWWT\n"; + return 1; + } + + std::cerr << "Oscar: " << std::string(argv[1]) << "\n"; + Oscar oscar(argv[1]); + + for (int i = 2; i < argc; i++) { + + std::string wid = oscar.findWigosId(argv[i]); + if (wid.size()) { + std::cout << "WigosID : " << wid << "\n"; + std::cout << "Details: " << oscar.to_string(wid) << "\n"; + } else { + std::cout << "Station not found: " << std::string(argv[i]) << "\n"; + } + } + + return 0; +}