13#include "include/ModelArray.hpp"
32 const netCDF::NcGroup& dataGroup,
const std::string& fieldName, ModelArray::Type type)
34 size_t nDims = dataGroup.getVar(fieldName).getDimCount();
35 ModelArray::MultiDim dims;
37 for (
size_t d = 0; d < nDims; ++d) {
38 dims[d] = dataGroup.getVar(fieldName).getDim(d).getSize();
41 if (type == ModelArray::Type::Z)
42 dims[2] = NZLevels::get();
46ModelState RectGridIO::getModelState(
const std::string& filePath)
49 netCDF::NcFile ncFile(filePath, netCDF::NcFile::read);
54 dimensionSetter(dataGroup, hiceName, ModelArray::Type::H);
56 dimensionSetter(dataGroup, hiceName, ModelArray::Type::U);
58 dimensionSetter(dataGroup, hiceName, ModelArray::Type::V);
60 dimensionSetter(dataGroup, ticeName, ModelArray::Type::Z);
62 state.data[maskName] = ModelArray::HField();
63 dataGroup.getVar(maskName).getVar(&state.data[maskName][0]);
64 state.data[hiceName] = ModelArray::HField();
65 dataGroup.getVar(hiceName).getVar(&state.data[hiceName][0]);
66 state.data[ciceName] = ModelArray::HField();
67 dataGroup.getVar(ciceName).getVar(&state.data[ciceName][0]);
68 state.data[hsnowName] = ModelArray::HField();
69 dataGroup.getVar(hsnowName).getVar(&state.data[hsnowName][0]);
72 state.data[ticeName] = ModelArray::ZField();
73 std::vector<size_t> startVector = { 0, 0, 0 };
75 dataGroup.getVar(ticeName).getVar(startVector, zArrayDims, &state.data[ticeName][0]);
82 const std::string& filePath,
bool isRestart)
const
84 netCDF::NcFile ncFile(filePath, netCDF::NcFile::replace);
91 typedef ModelArray::Type Type;
97 std::vector<std::string> dimensionNames = {
"x",
"y",
"z",
"t",
"component",
"u",
"v",
"w" };
101 netCDF::NcDim xDim = dataGroup.addDim(dimensionNames[0], nx);
102 netCDF::NcDim yDim = dataGroup.addDim(dimensionNames[1], ny);
103 std::vector<netCDF::NcDim> dims2 = { xDim, yDim };
104 netCDF::NcDim zDim = dataGroup.addDim(dimensionNames[2], nz);
105 std::vector<netCDF::NcDim> dims3 = { xDim, yDim, zDim };
107 for (
const auto entry : state.data) {
108 const std::string& name = entry.first;
109 if (entry.second.getType() == ModelArray::Type::H && entry.second.trueSize() > 0) {
110 netCDF::NcVar var(dataGroup.addVar(name, netCDF::ncDouble, dims2));
111 var.putAtt(mdiName, netCDF::ncDouble, MissingData::value);
112 var.putVar(entry.second.getData());
113 }
else if (entry.second.getType() == ModelArray::Type::Z && entry.second.trueSize() > 0) {
114 netCDF::NcVar var(dataGroup.addVar(name, netCDF::ncDouble, dims3));
115 var.putAtt(mdiName, netCDF::ncDouble, MissingData::value);
116 var.putVar(entry.second.getData());
static const std::string dataNodeName()
Returns the name of the data node.
static const std::string metadataNodeName()
Returns the name of the metadata node.
const MultiDim & dimensions() const
Returns a vector<size_t> of the size of each dimension of this type of ModelArray.
static void setDimensions(Type, const MultiDim &)
Sets the number and size of the dimensions of a specified type of ModelArray.
void dumpModelState(const ModelState &state, const ModelMetadata &metadata, const std::string &filePath, bool isRestart) const override
Dumps the given ModelState to the given file path.