diff --git a/src/attributes/TileDecoderAttributes.cc b/src/attributes/TileDecoderAttributes.cc index 6bde01ae..32b32c29 100644 --- a/src/attributes/TileDecoderAttributes.cc +++ b/src/attributes/TileDecoderAttributes.cc @@ -27,6 +27,7 @@ using namespace magics; TileDecoderAttributes::TileDecoderAttributes(): file_name_(ParameterManager::getString("grib_input_file_name")), projection_(ParameterManager::getString("grib_tile_projection")), + mode_(ParameterManager::getString("grib_tile_mode")), loop_(ParameterManager::getBool("grib_loop")), z_(ParameterManager::getInt("grib_tile_z")), x_(ParameterManager::getInt("grib_tile_x")), @@ -54,6 +55,7 @@ void TileDecoderAttributes::set(const std::map& params) setAttribute(prefix, "grib_input_file_name", file_name_, params); setAttribute(prefix, "grib_tile_projection", projection_, params); + setAttribute(prefix, "grib_tile_mode", mode_, params); setAttribute(prefix, "grib_loop", loop_, params); setAttribute(prefix, "grib_tile_z", z_, params); setAttribute(prefix, "grib_tile_x", x_, params); @@ -69,6 +71,7 @@ void TileDecoderAttributes::copy(const TileDecoderAttributes& other) { file_name_ = other.file_name_; projection_ = other.projection_; + mode_ = other.mode_; loop_ = other.loop_; z_ = other.z_; x_ = other.x_; @@ -116,6 +119,7 @@ void TileDecoderAttributes::print(ostream& out) const out << "Attributes["; out << " file_name = " << file_name_; out << " projection = " << projection_; + out << " mode = " << mode_; out << " loop = " << loop_; out << " z = " << z_; out << " x = " << x_; @@ -134,6 +138,8 @@ void TileDecoderAttributes::toxml(ostream& out) const niceprint(out,file_name_); out << ", \"grib_tile_projection\":"; niceprint(out,projection_); + out << ", \"grib_tile_mode\":"; + niceprint(out,mode_); out << ", \"grib_loop\":"; niceprint(out,loop_); out << ", \"grib_tile_z\":"; @@ -153,6 +159,7 @@ void TileDecoderAttributes::toxml(ostream& out) const static MagicsParameter grib_input_file_name("grib_input_file_name", ""); static MagicsParameter grib_tile_projection("grib_tile_projection", "cylindrical"); +static MagicsParameter grib_tile_mode("grib_tile_mode", "eccharts"); static MagicsParameter grib_loop("grib_loop", "off"); static MagicsParameter grib_tile_z("grib_tile_z", 1); static MagicsParameter grib_tile_x("grib_tile_x", 0); diff --git a/src/attributes/TileDecoderAttributes.h b/src/attributes/TileDecoderAttributes.h index 659a05d7..470ea181 100644 --- a/src/attributes/TileDecoderAttributes.h +++ b/src/attributes/TileDecoderAttributes.h @@ -52,6 +52,7 @@ class TileDecoderAttributes string tag_; string file_name_; string projection_; + string mode_; bool loop_; int z_; int x_; diff --git a/src/attributes/TileDecoderWrapper.cc b/src/attributes/TileDecoderWrapper.cc index dbc9c0f4..ddbcb42a 100644 --- a/src/attributes/TileDecoderWrapper.cc +++ b/src/attributes/TileDecoderWrapper.cc @@ -63,6 +63,10 @@ void TileDecoderWrapper::set(const MagRequest& request) string projection_value = request("GRIB_TILE_PROJECTION"); tiledecoder_->projection_ = projection_value; } + if (request.countValues("GRIB_TILE_MODE") ) { + string mode_value = request("GRIB_TILE_MODE"); + tiledecoder_->mode_ = mode_value; + } if (request.countValues("GRIB_LOOP") ) { string loop_value = request("GRIB_LOOP"); diff --git a/src/decoders/TileDecoder.cc b/src/decoders/TileDecoder.cc index 3cc62f1b..2d8d1e78 100644 --- a/src/decoders/TileDecoder.cc +++ b/src/decoders/TileDecoder.cc @@ -49,10 +49,15 @@ string TileDecoder::projection() { string TileDecoder::weights() { ostringstream out; string parent = getEnvVariable("MAGPLUS_TILE"); + if (parent.empty()) { parent = buildSharePath("tiles"); } - out << parent << "/weight-" << grid_ << "-" << projection() << "-z" + tostring(z_) << ".nc"; + if (mode_ == "opencharts" ) + out << parent << "/opencharts-cache-" << grid_ << ".nc"; + + else + out << parent << "/weight-" << grid_ << "-" << projection() << "-z" + tostring(z_) << ".nc"; return out.str(); } @@ -435,14 +440,10 @@ void TileDecoder::decode() { Timer timer("Tile", path); #ifdef HAVE_NETCDF + Netcdf netcdf(path, "index"); map first, last; - first["x"] = tostring(x_); - first["y"] = tostring(y_); - last["x"] = tostring(x_); - last["y"] = tostring(y_); - static vector bbox; static vector latitudes; static vector longitudes; @@ -450,41 +451,57 @@ void TileDecoder::decode() { static vector dindex; static vector distances; - int nblat = netcdf.getDimension("lat") - 1; - int nblon = netcdf.getDimension("lon") - 1; - - if (bbox.empty()) { - netcdf.get("bounding-box", bbox, first, last); + if ( mode_ == "opencharts") { - int error; - FILE* in = fopen(file_name_.c_str(), "rb"); - if (!in) { - if (MagicsGlobal::strict()) { - throw CannotOpenFile(file_name_); + netcdf.get(projection_ + "_lat", latitudes, first, last); + netcdf.get(projection_ + "_lon", longitudes, first, last); + netcdf.get(projection_ + "_index", dindex, first, last); + netcdf.get(projection_ + "_distances", distances, first, last); + } + else { + first["x"] = tostring(x_); + first["y"] = tostring(y_); + last["x"] = tostring(x_); + last["y"] = tostring(y_); + + + + int nblat = netcdf.getDimension("lat") - 1; + int nblon = netcdf.getDimension("lon") - 1; + + if (bbox.empty()) { + netcdf.get("bounding-box", bbox, first, last); + + int error; + FILE* in = fopen(file_name_.c_str(), "rb"); + if (!in) { + if (MagicsGlobal::strict()) { + throw CannotOpenFile(file_name_); + } + MagLog::error() << "ERROR: unable to create handle from file" << file_name_ << endl; + return; } - MagLog::error() << "ERROR: unable to create handle from file" << file_name_ << endl; - return; - } - // Adding a gutter of 5 points to avoid borders in tiles - int miny = std::min(bbox[1], bbox[3]); - miny = std::max(0, miny - 5); - int maxy = std::max(bbox[1], bbox[3]); - maxy = std::min(nblat, maxy + 5); - int minx = std::min(bbox[0], bbox[2]); - minx = std::max(0, minx - 5); - int maxx = std::max(bbox[0], bbox[2]); - maxx = std::min(nblon, maxx + 5); - - first["lat"] = tostring(miny); - first["lon"] = tostring(minx); - last["lat"] = tostring(maxy); - last["lon"] = tostring(maxx); - - netcdf.get("lat", latitudes, first, last); - netcdf.get("lon", longitudes, first, last); - netcdf.get("index", dindex, first, last); - netcdf.get("distances", distances, first, last); + // Adding a gutter of 5 points to avoid borders in tiles + int miny = std::min(bbox[1], bbox[3]); + miny = std::max(0, miny - 5); + int maxy = std::max(bbox[1], bbox[3]); + maxy = std::min(nblat, maxy + 5); + int minx = std::min(bbox[0], bbox[2]); + minx = std::max(0, minx - 5); + int maxx = std::max(bbox[0], bbox[2]); + maxx = std::min(nblon, maxx + 5); + + first["lat"] = tostring(miny); + first["lon"] = tostring(minx); + last["lat"] = tostring(maxy); + last["lon"] = tostring(maxx); + + netcdf.get("lat", latitudes, first, last); + netcdf.get("lon", longitudes, first, last); + netcdf.get("index", dindex, first, last); + netcdf.get("distances", distances, first, last); + } } int index[4]; diff --git a/src/params/TileDecoder.xml b/src/params/TileDecoder.xml index e62d7643..d7ee1815 100644 --- a/src/params/TileDecoder.xml +++ b/src/params/TileDecoder.xml @@ -28,6 +28,11 @@ does it submit to any jurisdiction. default="cylindrical" from="string" name="grib_tile_projection"> +