#include "SSNCReader.hpp" #include #include #include namespace StrideSearch { NCReader::NCReader(const std::string& filename) { src_file = filename; ncfile = std::unique_ptr(new netCDF::NcFile(filename, netCDF::NcFile::read)); } void NCReader::updateFile(const std::string& filename) { src_file = filename; ncfile = std::unique_ptr(new netCDF::NcFile(filename, netCDF::NcFile::read)); } std::string NCReader::infoString(const Int tab_lev) const { std::ostringstream ss; std::string tabstr(""); for (int i=0; i time_vars = {"time", "time_whole"}; netCDF::NcVar time_var; bool time_found = false; int name_index = -1; for (int i=0; igetVar(time_vars[i]); if (!time_var.isNull()) { name_index = i; time_found = true; break; } } if (!time_found) { throw std::runtime_error("NCReader::getTime error: time variable not found."); } const Int nsteps = time_var.getDim(0).getSize(); Real time_vals[nsteps]; if (nsteps>0) { time_var.getVar(time_vals); } if (dtu != DTUnits::DAYS) { const Real conv_fac = (dtu == DTUnits::HOURS ? HOURS2DAYS : MINUTES2DAYS); for (Int i=0; igetVar("lat"); netCDF::NcVar lon_var = ncfile->getVar("lon"); if (!lat_var.isNull() && !lon_var.isNull()) { n_lat = lat_var.getDim(0).getSize(); n_lon = lon_var.getDim(0).getSize(); Real lats_arr[n_lat]; Real lons_arr[n_lon]; lat_var.getVar(lats_arr); lon_var.getVar(lons_arr); lats = RealArray(&lats_arr[0], &lats_arr[0] + n_lat); lons = RealArray(&lons_arr[0], &lons_arr[0] + n_lon); } else { throw std::runtime_error("LatLonNCReader::initData error: coordinate variables not found."); } } void LatLonNCReader::fillWorkspaceData(Workspace& wspc, const std::vector& inds, const Int t_ind, const Int l_ind) const { /// @throws if Workspace size != inds.size() if (inds.size() != wspc.n) { throw std::runtime_error("LatLonNCReader::fillWorkspaceData error: workspace/indices size mismatch."); } for (auto& var : wspc.data) { if (var.first == "lat" || var.first == "latitude") { for (Int i=0; iresolutionEstimate()/EARTH_RADIUS_KM; for (Int i=0; igetVar(var.first)); const Int ndim = ncv.getDimCount(); if (ndim == 3) { // (time, lat, lon) auto getind = LatLonLayout::get_index_2d(); getind[0] = t_ind; for (Int i=0; iresolutionEstimate()/EARTH_RADIUS_KM; for (Int i=0; igetVar(var.first)); const Int ndim = ncv.getDimCount(); if (ndim == 2) { // (time, node) auto getind = UnstructuredLayout::get_index_2d(); getind[0] = t_ind; for (Int i=0; igetVar("coordx"); netCDF::NcVar y_var = ncfile->getVar("coordy"); netCDF::NcVar z_var = ncfile->getVar("coordz"); netCDF::NcVar coord_var = ncfile->getVar("coord"); if (!x_var.isNull() && !y_var.isNull() && !z_var.isNull()) { n_nodes = x_var.getDim(0).getSize(); Real xarr[n_nodes]; Real yarr[n_nodes]; Real zarr[n_nodes]; x_var.getVar(xarr); y_var.getVar(yarr); z_var.getVar(zarr); lats = RealArray(n_nodes); lons = RealArray(n_nodes); for (Index i=0; i< n_nodes; ++i) { Real lat, lon; XyzToLL(lat, lon, xarr[i], yarr[i], zarr[i]); lats[i] = lat; lons[i] = lon; } } else if (!coord_var.isNull()) { n_nodes = coord_var.getDim(1).getSize(); Real xyz_arr[3][n_nodes]; coord_var.getVar(xyz_arr); lats = RealArray(n_nodes); lons = RealArray(n_nodes); for (Index i=0; i< n_nodes; ++i) { Real lat, lon; XyzToLL(lat, lon, xyz_arr[0][i], xyz_arr[1][i], xyz_arr[2][i]); lats[i] = lat; lons[i] = lon; } } else { throw std::runtime_error("UnstructuredNCReader::initDimensions error: coordinate variables not found."); } } Points UnstructuredNCReader::makePoints() const { Points result(n_nodes); for (Index i=0; i