[219] | 1 | #include "nc4_data_input.hpp" |
---|
| 2 | |
---|
[599] | 3 | #include "context.hpp" |
---|
| 4 | #include "context_server.hpp" |
---|
[775] | 5 | #include "context_client.hpp" |
---|
| 6 | #include "domain.hpp" |
---|
| 7 | #include "axis.hpp" |
---|
[967] | 8 | #include "scalar.hpp" |
---|
[599] | 9 | |
---|
[335] | 10 | namespace xios |
---|
[219] | 11 | { |
---|
[1639] | 12 | CNc4DataInput::CNc4DataInput(const StdString& filename, MPI_Comm comm_file, bool multifile, bool isCollective /*= true*/, |
---|
[1486] | 13 | bool readMetaDataPar /*= false*/, bool ugridConvention /*= false*/, const StdString& timeCounterName /*= "time_counter"*/) |
---|
[599] | 14 | : SuperClass() |
---|
[1485] | 15 | , SuperClassWriter(filename, &comm_file, multifile, readMetaDataPar, timeCounterName) |
---|
[599] | 16 | , comm_file(comm_file) |
---|
| 17 | , filename(filename) |
---|
| 18 | , isCollective(isCollective) |
---|
[1486] | 19 | , ugridConvention(ugridConvention) |
---|
[775] | 20 | , readMetaDataDomains_(), readValueDomains_() |
---|
| 21 | , readMetaDataAxis_(), readValueAxis_() |
---|
[967] | 22 | , readMetaDataScalar_(), readValueScalar_() |
---|
[599] | 23 | { |
---|
| 24 | SuperClass::type = multifile ? MULTI_FILE : ONE_FILE; |
---|
| 25 | } |
---|
[219] | 26 | |
---|
[599] | 27 | CNc4DataInput::~CNc4DataInput(void) |
---|
| 28 | { /* Nothing more to do */ } |
---|
[219] | 29 | |
---|
[599] | 30 | StdSize CNc4DataInput::getFieldNbRecords_(CField* field) |
---|
[1622] | 31 | TRY |
---|
[599] | 32 | { |
---|
[770] | 33 | StdString fieldId = field->getFieldOutputName(); |
---|
[599] | 34 | |
---|
| 35 | if (SuperClassWriter::isTemporal(fieldId)) |
---|
| 36 | { |
---|
[811] | 37 | // return SuperClassWriter::getDimensions(&fieldId)[SuperClassWriter::getUnlimitedDimensionName()]; |
---|
| 38 | return SuperClassWriter::getDimensions(&fieldId)[SuperClassWriter::getTimeCounterName()]; |
---|
[599] | 39 | } |
---|
| 40 | |
---|
| 41 | return 1; |
---|
| 42 | } |
---|
[1622] | 43 | CATCH |
---|
[599] | 44 | |
---|
[1930] | 45 | void CNc4DataInput::readFieldData_(CField* field, int record, CArray<double,1>& dataOut) |
---|
[1622] | 46 | TRY |
---|
[599] | 47 | { |
---|
| 48 | CContext* context = CContext::getCurrent(); |
---|
| 49 | |
---|
[1869] | 50 | CGrid* grid = field->getGrid(); |
---|
[599] | 51 | |
---|
[1930] | 52 | if (!grid->doGridHaveDataToWrite()) if (SuperClass::type==MULTI_FILE || !isCollective) return; |
---|
[599] | 53 | |
---|
[770] | 54 | StdString fieldId = field->getFieldOutputName(); |
---|
[599] | 55 | |
---|
| 56 | switch (SuperClass::type) |
---|
| 57 | { |
---|
| 58 | case MULTI_FILE: |
---|
[1930] | 59 | SuperClassWriter::getData(dataOut, fieldId, isCollective, record ); |
---|
[599] | 60 | break; |
---|
| 61 | case ONE_FILE: |
---|
| 62 | { |
---|
[765] | 63 | std::vector<StdSize> start, count; |
---|
| 64 | |
---|
[887] | 65 | CArray<int,1> axisDomainOrder = grid->axis_domain_order; |
---|
[765] | 66 | std::vector<StdString> domainList = grid->getDomainList(); |
---|
| 67 | std::vector<StdString> axisList = grid->getAxisList(); |
---|
[2308] | 68 | std::vector<StdString> scalarList = grid->getScalarList(); |
---|
[765] | 69 | int numElement = axisDomainOrder.numElements(); |
---|
[2308] | 70 | int idxDomain = domainList.size() - 1, idxAxis = axisList.size() - 1 ; |
---|
[1553] | 71 | int idx = domainList.size() * 2 + axisList.size() - 1; |
---|
[765] | 72 | |
---|
[1553] | 73 | start.reserve(idx+1); |
---|
| 74 | count.reserve(idx+1); |
---|
[765] | 75 | |
---|
| 76 | for (int i = numElement - 1; i >= 0; --i) |
---|
| 77 | { |
---|
[887] | 78 | if (2 == axisDomainOrder(i)) |
---|
[765] | 79 | { |
---|
| 80 | CDomain* domain = CDomain::get(domainList[idxDomain]); |
---|
| 81 | if ((domain->type) != CDomain::type_attr::unstructured) |
---|
| 82 | { |
---|
[2482] | 83 | start.push_back(domain->jbeginValue_); |
---|
| 84 | count.push_back(domain->njValue_); |
---|
[765] | 85 | } |
---|
[2482] | 86 | start.push_back(domain->ibeginValue_); |
---|
| 87 | count.push_back(domain->niValue_); |
---|
[765] | 88 | --idxDomain; |
---|
| 89 | } |
---|
[887] | 90 | else if (1 == axisDomainOrder(i)) |
---|
[765] | 91 | { |
---|
[1553] | 92 | CAxis* axis = CAxis::get(axisList[idxAxis]); |
---|
| 93 | start.push_back(axis->begin); |
---|
| 94 | count.push_back(axis->n); |
---|
[1573] | 95 | --idxAxis ; |
---|
[967] | 96 | } |
---|
| 97 | else |
---|
| 98 | { |
---|
| 99 | if (1 == axisDomainOrder.numElements()) |
---|
| 100 | { |
---|
[2308] | 101 | CScalar* scalar = CScalar::get(scalarList[0]); |
---|
[967] | 102 | start.push_back(0); |
---|
[2308] | 103 | count.push_back(scalar->n); |
---|
[967] | 104 | } |
---|
| 105 | } |
---|
[765] | 106 | } |
---|
[777] | 107 | |
---|
[1930] | 108 | SuperClassWriter::getData(dataOut, fieldId, isCollective, record, &start, &count); |
---|
[599] | 109 | break; |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | } |
---|
[1622] | 113 | CATCH |
---|
[599] | 114 | |
---|
[775] | 115 | void CNc4DataInput::readFieldAttributes_(CField* field, bool readAttributeValues) |
---|
[1622] | 116 | TRY |
---|
[775] | 117 | { |
---|
[777] | 118 | StdString fieldId = field->getFieldOutputName(); |
---|
[775] | 119 | |
---|
[1869] | 120 | CGrid* grid = field->getGrid(); |
---|
[775] | 121 | |
---|
| 122 | std::vector<CDomain*> domainP = grid->getDomains(); |
---|
| 123 | std::vector<CAxis*> axisP = grid->getAxis(); |
---|
[967] | 124 | std::vector<CScalar*> scalarP = grid->getScalars(); |
---|
[775] | 125 | int gridDim = domainP.size() * 2 + axisP.size(); |
---|
| 126 | |
---|
[967] | 127 | // Nothing to do with scalar without timestep |
---|
| 128 | if ((0 == gridDim) && (!SuperClassWriter::isTemporal(fieldId))) |
---|
| 129 | return; |
---|
| 130 | |
---|
[775] | 131 | // Verify the compatibility of dimension of declared grid and real grid in file |
---|
| 132 | int realGridDim = 1; |
---|
[2482] | 133 | bool isUnstructuredGrid = ((gridDim < 2 || domainP.size()==0) ? false : SuperClassWriter::isUnstructured(fieldId)); |
---|
[775] | 134 | std::map<StdString, StdSize> dimSizeMap = SuperClassWriter::getDimensions(&fieldId); |
---|
[807] | 135 | std::list<StdString> dimList = SuperClassWriter::getDimensionsList(&fieldId); |
---|
[825] | 136 | |
---|
[775] | 137 | realGridDim = SuperClassWriter::isTemporal(fieldId) ? dimSizeMap.size() - 1 : dimSizeMap.size(); |
---|
[783] | 138 | if (isUnstructuredGrid) ++realGridDim; |
---|
[775] | 139 | |
---|
| 140 | if (gridDim != realGridDim) |
---|
| 141 | ERROR("CNc4DataInput::readFieldAttributes_(CField* field, bool readAttributeValues)", |
---|
| 142 | << "Field '" << fieldId << "' has incorrect dimension " << std::endl |
---|
| 143 | << "Verify dimension of grid defined by 'grid_ref' or 'domain_ref'/'axis_ref' and dimension of grid in read file."); |
---|
| 144 | |
---|
| 145 | // Remove unlimited dimension from the map, we dont need it anymore |
---|
[825] | 146 | if (SuperClassWriter::isTemporal(fieldId)) |
---|
[807] | 147 | { |
---|
| 148 | dimSizeMap.erase(SuperClassWriter::getUnlimitedDimensionName()); |
---|
| 149 | dimList.pop_front() ; // assume time dimension is first |
---|
| 150 | } |
---|
[825] | 151 | |
---|
[783] | 152 | std::list<std::pair<StdString, StdSize> > listDimSize; |
---|
[807] | 153 | /* |
---|
[783] | 154 | for (std::map<StdString, StdSize>::const_iterator itMap = dimSizeMap.begin(); itMap != dimSizeMap.end(); ++itMap) |
---|
| 155 | listDimSize.push_front(*itMap); |
---|
[807] | 156 | */ |
---|
[1434] | 157 | |
---|
[1479] | 158 | // if (!SuperClassWriter::isRectilinear(fieldId)) |
---|
| 159 | if (true) |
---|
[1430] | 160 | { |
---|
[1434] | 161 | for (std::list<StdString>::const_iterator it = dimList.begin(); it != dimList.end(); ++it) |
---|
[1430] | 162 | listDimSize.push_front(*dimSizeMap.find(*it)); |
---|
| 163 | } |
---|
[1434] | 164 | else |
---|
| 165 | { |
---|
| 166 | std::list<StdString> coords = SuperClassWriter::getCoordinatesIdList(fieldId); |
---|
| 167 | std::list<StdString>::const_iterator itCoord = coords.begin(); |
---|
| 168 | for (; itCoord != coords.end(); itCoord++) |
---|
| 169 | { |
---|
| 170 | const StdString& coord = *itCoord; |
---|
| 171 | if (SuperClassWriter::hasVariable(coord) && !SuperClassWriter::isTemporal(coord)) |
---|
| 172 | { |
---|
| 173 | std::map<StdString, StdSize> dimsTmp = SuperClassWriter::getDimensions(&coord); |
---|
| 174 | StdString dimNameTmp = dimsTmp.begin()->first; |
---|
| 175 | StdSize dimSizeTmp = dimsTmp.begin()->second; |
---|
| 176 | listDimSize.push_front(make_pair(coord, dimSizeTmp)); |
---|
| 177 | dimSizeMap.erase(dimNameTmp); |
---|
| 178 | dimList.remove(dimNameTmp); |
---|
| 179 | } |
---|
| 180 | } |
---|
| 181 | for (std::list<StdString>::const_iterator it = dimList.begin(); it != dimList.end(); ++it) |
---|
| 182 | listDimSize.push_front(*dimSizeMap.find(*it)); |
---|
| 183 | } |
---|
[1430] | 184 | |
---|
[775] | 185 | // Now process domain and axis |
---|
[887] | 186 | CArray<int,1> axisDomainOrder = grid->axis_domain_order; |
---|
[967] | 187 | int numElement = domainP.size() + axisP.size() + scalarP.size(); |
---|
[775] | 188 | int elementPosition = 0; |
---|
[967] | 189 | int idxDomain = 0, idxAxis = 0, idxScalar = 0; |
---|
[775] | 190 | |
---|
| 191 | std::pair<std::set<StdString>::iterator,bool> it; |
---|
| 192 | for (int i = 0; i < numElement; ++i) |
---|
| 193 | { |
---|
[887] | 194 | if(2 == axisDomainOrder(i)) |
---|
[775] | 195 | { |
---|
| 196 | if (readAttributeValues) |
---|
| 197 | { |
---|
| 198 | it = readValueDomains_.insert(domainP[idxDomain]->getId()); |
---|
[783] | 199 | if (it.second) readDomainAttributeValueFromFile(domainP[idxDomain], listDimSize, elementPosition, fieldId); |
---|
[775] | 200 | } |
---|
| 201 | else |
---|
| 202 | { |
---|
| 203 | it = readMetaDataDomains_.insert(domainP[idxDomain]->getId()); |
---|
[783] | 204 | if (it.second) readDomainAttributesFromFile(domainP[idxDomain], listDimSize, elementPosition, fieldId); |
---|
[775] | 205 | } |
---|
| 206 | ++idxDomain; |
---|
[783] | 207 | if (isUnstructuredGrid) ++elementPosition; |
---|
| 208 | else elementPosition += 2; |
---|
[775] | 209 | } |
---|
[887] | 210 | else if (1 == axisDomainOrder(i)) |
---|
[775] | 211 | { |
---|
| 212 | if (readAttributeValues) |
---|
| 213 | { |
---|
| 214 | it = readValueAxis_.insert(axisP[idxAxis]->getId()); |
---|
[783] | 215 | if (it.second) readAxisAttributeValueFromFile(axisP[idxAxis], listDimSize, elementPosition, fieldId); |
---|
[775] | 216 | } |
---|
| 217 | else |
---|
| 218 | { |
---|
| 219 | it = readMetaDataAxis_.insert(axisP[idxAxis]->getId()); |
---|
[783] | 220 | if (it.second) readAxisAttributesFromFile(axisP[idxAxis], listDimSize, elementPosition, fieldId); |
---|
[775] | 221 | } |
---|
| 222 | ++idxAxis; |
---|
| 223 | ++elementPosition; |
---|
| 224 | } |
---|
[967] | 225 | else |
---|
| 226 | { |
---|
| 227 | if (readAttributeValues) |
---|
| 228 | { |
---|
| 229 | it = readValueScalar_.insert(scalarP[idxScalar]->getId()); |
---|
| 230 | if (it.second) readScalarAttributeValueFromFile(scalarP[idxScalar], listDimSize, elementPosition, fieldId); |
---|
| 231 | } |
---|
| 232 | else |
---|
| 233 | { |
---|
| 234 | it = readMetaDataScalar_.insert(scalarP[idxScalar]->getId()); |
---|
| 235 | if (it.second) readScalarAttributesFromFile(scalarP[idxScalar], listDimSize, elementPosition, fieldId); |
---|
| 236 | } |
---|
| 237 | ++idxScalar; |
---|
| 238 | ++elementPosition; |
---|
| 239 | } |
---|
[775] | 240 | } |
---|
| 241 | } |
---|
[1622] | 242 | CATCH |
---|
[775] | 243 | |
---|
| 244 | /*! |
---|
| 245 | Read attributes of a domain from a file |
---|
| 246 | \param [in] domain domain whose attributes are read from the file |
---|
| 247 | \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file |
---|
| 248 | \param [in] emelentPosition position of domain in grid |
---|
[782] | 249 | \param [in] fieldId id (or name) associated with the grid |
---|
[775] | 250 | */ |
---|
[783] | 251 | void CNc4DataInput::readDomainAttributeValueFromFile(CDomain* domain, std::list<std::pair<StdString, StdSize> >& dimSizeMap, |
---|
[775] | 252 | int elementPosition, const StdString& fieldId) |
---|
[1622] | 253 | TRY |
---|
[775] | 254 | { |
---|
| 255 | // There are some optional attributes of a domain to retrieve from file // + lon lat? |
---|
[783] | 256 | std::list<std::pair<StdString, StdSize> >::const_iterator itMapNi = dimSizeMap.begin(), itMapNj, |
---|
| 257 | iteMap = dimSizeMap.end(); |
---|
[775] | 258 | |
---|
[783] | 259 | for (int i = 0; i < elementPosition; ++i, ++itMapNi) {} |
---|
| 260 | itMapNj = itMapNi; ++itMapNj; |
---|
[775] | 261 | |
---|
[1158] | 262 | if ((CDomain::type_attr::rectilinear == domain->type)) |
---|
[775] | 263 | { |
---|
[1419] | 264 | // Ok, try to read some attributes such as longitude and latitude |
---|
[825] | 265 | bool hasLat = SuperClassWriter::hasVariable(itMapNj->first); |
---|
| 266 | if (hasLat) |
---|
| 267 | { |
---|
| 268 | domain->latvalue_rectilinear_read_from_file.resize(itMapNj->second); |
---|
| 269 | std::vector<StdSize> nBeginLat(1, 0), nSizeLat(1, itMapNj->second); |
---|
| 270 | readFieldVariableValue(domain->latvalue_rectilinear_read_from_file, itMapNj->first, nBeginLat, nSizeLat, true); |
---|
| 271 | } |
---|
[775] | 272 | |
---|
[825] | 273 | bool hasLon = SuperClassWriter::hasVariable(itMapNi->first); |
---|
| 274 | if (hasLon) |
---|
| 275 | { |
---|
| 276 | domain->lonvalue_rectilinear_read_from_file.resize(itMapNi->second); |
---|
| 277 | std::vector<StdSize> nBeginLon(1, 0), nSizeLon(1, itMapNi->second); |
---|
| 278 | readFieldVariableValue(domain->lonvalue_rectilinear_read_from_file, itMapNi->first, nBeginLon, nSizeLon, true); |
---|
[1158] | 279 | } |
---|
[775] | 280 | } |
---|
[1158] | 281 | else if ((CDomain::type_attr::curvilinear == domain->type)) |
---|
[783] | 282 | { |
---|
[1428] | 283 | // Make sure that if there is no local domain defined on a process, the process still reads just one value. |
---|
| 284 | int ni, nj, ibegin, jbegin; |
---|
| 285 | if (domain->ni == 0) |
---|
| 286 | { |
---|
| 287 | ni = 1; |
---|
| 288 | ibegin = 0; |
---|
| 289 | } |
---|
| 290 | else |
---|
| 291 | { |
---|
| 292 | ni = domain->ni; |
---|
| 293 | ibegin = domain->ibegin; |
---|
| 294 | } |
---|
| 295 | if (domain->nj == 0) |
---|
| 296 | { |
---|
| 297 | nj = 1; |
---|
| 298 | jbegin = 0; |
---|
| 299 | } |
---|
| 300 | else |
---|
| 301 | { |
---|
| 302 | nj = domain->nj; |
---|
| 303 | jbegin = domain->jbegin; |
---|
| 304 | } |
---|
| 305 | |
---|
[785] | 306 | std::vector<StdSize> nBeginLatLon(2), nSizeLatLon(2); |
---|
[1428] | 307 | nBeginLatLon[0] = jbegin; nBeginLatLon[1] = ibegin; |
---|
| 308 | nSizeLatLon[0] = nj; nSizeLatLon[1] = ni; |
---|
[783] | 309 | |
---|
| 310 | StdString latName = this->getLatCoordName(fieldId); |
---|
[1158] | 311 | if (SuperClassWriter::hasVariable(latName)) |
---|
[825] | 312 | { |
---|
[1428] | 313 | domain->latvalue_curvilinear_read_from_file.resize(ni, nj); |
---|
[1158] | 314 | readFieldVariableValue(domain->latvalue_curvilinear_read_from_file, latName, nBeginLatLon, nSizeLatLon); |
---|
[825] | 315 | } |
---|
[783] | 316 | StdString lonName = this->getLonCoordName(fieldId); |
---|
[1158] | 317 | if (SuperClassWriter::hasVariable(lonName)) |
---|
[825] | 318 | { |
---|
[1428] | 319 | domain->lonvalue_curvilinear_read_from_file.resize(ni, nj); |
---|
[1158] | 320 | readFieldVariableValue(domain->lonvalue_curvilinear_read_from_file, lonName, nBeginLatLon, nSizeLatLon); |
---|
[825] | 321 | } |
---|
[783] | 322 | |
---|
| 323 | StdString boundsLatName = this->getBoundsId(latName); |
---|
| 324 | StdString boundsLonName = this->getBoundsId(lonName); |
---|
| 325 | |
---|
[1447] | 326 | int nbVertex = 4; //this->getNbVertex(fieldId); |
---|
[1158] | 327 | if (!domain->nvertex.isEmpty() && (domain->nvertex != nbVertex)) |
---|
| 328 | { |
---|
| 329 | ERROR("void CNc4DataInput::readDomainAttributeValueFromFile(...)", |
---|
| 330 | << "The domain " << domain->getDomainOutputName() |
---|
| 331 | << " has nvertex read from file " << this->filename << " and nvertex provided from model" |
---|
| 332 | << " are not coherent. They should be the same." << std::endl |
---|
| 333 | << " nvertex read from file: "<< nbVertex |
---|
| 334 | << " nvertex from model: "<< domain->nvertex << std::endl); |
---|
| 335 | } |
---|
| 336 | |
---|
| 337 | if (SuperClassWriter::hasVariable(boundsLatName) || SuperClassWriter::hasVariable(boundsLonName)) |
---|
[825] | 338 | domain->nvertex.setValue(nbVertex); |
---|
[1201] | 339 | |
---|
[785] | 340 | std::vector<StdSize> nBeginBndsLatLon(3), nSizeBndsLatLon(3); |
---|
[1428] | 341 | nBeginBndsLatLon[0] = jbegin; nSizeBndsLatLon[0] = nj; |
---|
| 342 | nBeginBndsLatLon[1] = ibegin; nSizeBndsLatLon[1] = ni; |
---|
[785] | 343 | nBeginBndsLatLon[2] = 0; nSizeBndsLatLon[2] = nbVertex; |
---|
[783] | 344 | |
---|
[1158] | 345 | if (SuperClassWriter::hasVariable(boundsLatName)) |
---|
[825] | 346 | { |
---|
[1428] | 347 | domain->bounds_latvalue_curvilinear_read_from_file.resize(nbVertex, ni, nj); |
---|
[1158] | 348 | readFieldVariableValue(domain->bounds_latvalue_curvilinear_read_from_file, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon); |
---|
[825] | 349 | |
---|
| 350 | } |
---|
[1158] | 351 | if (SuperClassWriter::hasVariable(boundsLonName)) |
---|
[825] | 352 | { |
---|
[1428] | 353 | domain->bounds_lonvalue_curvilinear_read_from_file.resize(nbVertex, ni, nj); |
---|
[1158] | 354 | readFieldVariableValue(domain->bounds_lonvalue_curvilinear_read_from_file, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon); |
---|
| 355 | } |
---|
[783] | 356 | } |
---|
[825] | 357 | else if ((CDomain::type_attr::unstructured == domain->type))// || (this->isUnstructured(fieldId))) |
---|
[775] | 358 | { |
---|
[1428] | 359 | // Make sure that if there is no local domain defined on a process, the process still reads just one value. |
---|
| 360 | int ni, ibegin; |
---|
| 361 | if (domain->ni == 0) |
---|
| 362 | { |
---|
| 363 | ni = 1; |
---|
| 364 | ibegin = 0; |
---|
| 365 | } |
---|
| 366 | else |
---|
| 367 | { |
---|
| 368 | ni = domain->ni; |
---|
| 369 | ibegin = domain->ibegin; |
---|
| 370 | } |
---|
| 371 | |
---|
[785] | 372 | std::vector<StdSize> nBeginLatLon(1,0), nSizeLatLon(1,0); |
---|
[1428] | 373 | nBeginLatLon[0] = ibegin; |
---|
| 374 | nSizeLatLon[0] = ni; |
---|
[785] | 375 | |
---|
[782] | 376 | StdString latName = this->getLatCoordName(fieldId); |
---|
[1158] | 377 | if (SuperClassWriter::hasVariable(latName)) |
---|
[825] | 378 | { |
---|
[1428] | 379 | domain->latvalue_unstructured_read_from_file.resize(ni); |
---|
[1158] | 380 | readFieldVariableValue(domain->latvalue_unstructured_read_from_file, latName, nBeginLatLon, nSizeLatLon); |
---|
[825] | 381 | } |
---|
[785] | 382 | |
---|
[782] | 383 | StdString lonName = this->getLonCoordName(fieldId); |
---|
[825] | 384 | if (SuperClassWriter::hasVariable(lonName)) //(0 != lonName.compare("")) |
---|
| 385 | { |
---|
[1428] | 386 | domain->lonvalue_unstructured_read_from_file.resize(ni); |
---|
[1158] | 387 | readFieldVariableValue(domain->lonvalue_unstructured_read_from_file, lonName, nBeginLatLon, nSizeLatLon); |
---|
[825] | 388 | } |
---|
[782] | 389 | |
---|
| 390 | StdString boundsLatName = this->getBoundsId(latName); |
---|
| 391 | StdString boundsLonName = this->getBoundsId(lonName); |
---|
| 392 | |
---|
[1486] | 393 | if (ugridConvention && domain->nvertex.isEmpty()) |
---|
| 394 | { |
---|
| 395 | ERROR("void CNc4DataInput::readDomainAttributeValueFromFile(...)", |
---|
| 396 | << " Attribute nvertex must be specified for domain " << domain->getDomainOutputName() |
---|
| 397 | << " read from UGRID file " << this->filename << " ."<< std::endl); |
---|
| 398 | } |
---|
| 399 | // int nbVertex = this->getNbVertex(fieldId); |
---|
| 400 | int nbVertex = (ugridConvention) ? domain->nvertex : this->getNbVertex(fieldId); |
---|
[1158] | 401 | if (!domain->nvertex.isEmpty() && (domain->nvertex != nbVertex)) |
---|
| 402 | { |
---|
| 403 | ERROR("void CNc4DataInput::readDomainAttributeValueFromFile(...)", |
---|
| 404 | << "The domain " << domain->getDomainOutputName() |
---|
| 405 | << " has nvertex read from file " << this->filename << " and nvertex provided from model" |
---|
| 406 | << " are not coherent. They should be the same." << std::endl |
---|
| 407 | << " nvertex read from file: "<< nbVertex |
---|
| 408 | << " nvertex from model: "<< domain->nvertex << std::endl); |
---|
| 409 | } |
---|
| 410 | |
---|
| 411 | if (SuperClassWriter::hasVariable(boundsLatName) || SuperClassWriter::hasVariable(boundsLonName)) |
---|
[825] | 412 | domain->nvertex.setValue(nbVertex); |
---|
| 413 | |
---|
[785] | 414 | std::vector<StdSize> nBeginBndsLatLon(2), nSizeBndsLatLon(2); |
---|
[1428] | 415 | nBeginBndsLatLon[0] = ibegin; nSizeBndsLatLon[0] = ni; |
---|
[1413] | 416 | nBeginBndsLatLon[1] = 0; nSizeBndsLatLon[1] = nbVertex; |
---|
[782] | 417 | |
---|
[1413] | 418 | if (SuperClassWriter::hasVariable(boundsLatName)) |
---|
[825] | 419 | { |
---|
[1158] | 420 | domain->bounds_latvalue_unstructured_read_from_file.resize(nSizeBndsLatLon[1], nSizeBndsLatLon[0]); |
---|
| 421 | readFieldVariableValue(domain->bounds_latvalue_unstructured_read_from_file, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon); |
---|
[825] | 422 | } |
---|
[785] | 423 | |
---|
[1158] | 424 | if (SuperClassWriter::hasVariable(boundsLonName)) |
---|
[825] | 425 | { |
---|
[1158] | 426 | domain->bounds_lonvalue_unstructured_read_from_file.resize(nSizeBndsLatLon[1], nSizeBndsLatLon[0]); |
---|
| 427 | readFieldVariableValue(domain->bounds_lonvalue_unstructured_read_from_file, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon); |
---|
| 428 | } |
---|
[775] | 429 | } |
---|
[1158] | 430 | domain->fillInLonLat(); |
---|
[775] | 431 | } |
---|
[1622] | 432 | CATCH |
---|
[775] | 433 | |
---|
| 434 | /*! |
---|
[782] | 435 | Read attribute value of a domain from a file |
---|
[775] | 436 | \param [in] domain domain whose attributes are read from the file |
---|
| 437 | \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file |
---|
| 438 | \param [in] emelentPosition position of domain in grid |
---|
[782] | 439 | \param [in] fieldId id (or name) associated with the grid |
---|
[775] | 440 | */ |
---|
[783] | 441 | void CNc4DataInput::readDomainAttributesFromFile(CDomain* domain, std::list<std::pair<StdString, StdSize> >& dimSizeMap, |
---|
[775] | 442 | int elementPosition, const StdString& fieldId) |
---|
[1622] | 443 | TRY |
---|
[775] | 444 | { |
---|
| 445 | // There are some mandatory attributes of a domain to retrieve from file |
---|
| 446 | // + ni_glo, nj_glo |
---|
[783] | 447 | std::list<std::pair<StdString, StdSize> >::const_iterator itMapNi = dimSizeMap.begin(), itMapNj, |
---|
| 448 | iteMap = dimSizeMap.end(); |
---|
| 449 | for (int i = 0; i < elementPosition; ++i, ++itMapNi) {} |
---|
| 450 | itMapNj = itMapNi; ++itMapNj; |
---|
[775] | 451 | |
---|
[1479] | 452 | if (CDomain::type_attr::rectilinear == domain->type || CDomain::type_attr::curvilinear == domain->type || |
---|
| 453 | this->isRectilinear(fieldId) || this->isCurvilinear(fieldId)) |
---|
[775] | 454 | { |
---|
[1158] | 455 | if (!domain->nj_glo.isEmpty() && (domain->nj_glo != itMapNj->second)) |
---|
| 456 | { |
---|
| 457 | ERROR("void CNc4DataInput::readDomainAttributesFromFile(...)", |
---|
| 458 | << "The domain " << domain->getDomainOutputName() |
---|
| 459 | << " has nj_glo read from file " << this->filename << " and nj_glo provided from model" |
---|
| 460 | << " are not coherent. They should be the same." << std::endl |
---|
| 461 | << " nj_glo read from file: "<< itMapNj->second |
---|
| 462 | << " nj_glo from model: "<< domain->nj_glo << std::endl); |
---|
| 463 | } |
---|
[775] | 464 | domain->nj_glo.setValue(itMapNj->second); |
---|
[1158] | 465 | |
---|
| 466 | if (!domain->ni_glo.isEmpty() && (domain->ni_glo != itMapNi->second)) |
---|
| 467 | { |
---|
| 468 | ERROR("void CNc4DataInput::readDomainAttributesFromFile(...)", |
---|
| 469 | << "The domain " << domain->getDomainOutputName() |
---|
| 470 | << " has ni_glo read from file " << this->filename << " and ni_glo provided from model" |
---|
| 471 | << " are not coherent. They should be the same." << std::endl |
---|
| 472 | << " ni_glo read from file: "<< itMapNi->second |
---|
| 473 | << " ni_glo from model: "<< domain->ni_glo << std::endl); |
---|
| 474 | } |
---|
[783] | 475 | domain->ni_glo.setValue(itMapNi->second); |
---|
[775] | 476 | } |
---|
[1479] | 477 | else if (CDomain::type_attr::unstructured == domain->type|| this->isUnstructured(fieldId)) |
---|
[775] | 478 | { |
---|
[783] | 479 | domain->nj_glo.setValue(1); |
---|
[1158] | 480 | |
---|
| 481 | if (!domain->ni_glo.isEmpty() && (domain->ni_glo != itMapNi->second)) |
---|
| 482 | { |
---|
| 483 | ERROR("void CNc4DataInput::readDomainAttributesFromFile(...)", |
---|
| 484 | << "The domain " << domain->getDomainOutputName() |
---|
| 485 | << " has ni_glo read from file " << this->filename << " and ni_glo provided from model" |
---|
| 486 | << " are not coherent. They should be the same." << std::endl |
---|
| 487 | << " ni_glo read from file: "<< itMapNi->second |
---|
| 488 | << " ni_glo from model: "<< domain->ni_glo << std::endl); |
---|
| 489 | } |
---|
[783] | 490 | domain->ni_glo.setValue(itMapNi->second); |
---|
[775] | 491 | } |
---|
[1582] | 492 | |
---|
| 493 | // determine if coordinates values are present in file |
---|
| 494 | if ((CDomain::type_attr::rectilinear == domain->type)) |
---|
| 495 | { |
---|
| 496 | // Ok, try to read some attributes such as longitude and latitude |
---|
[2338] | 497 | domain->has_lat_in_read_file = SuperClassWriter::hasVariable(itMapNj->first); |
---|
| 498 | domain->has_lon_in_read_file = SuperClassWriter::hasVariable(itMapNi->first); |
---|
[1582] | 499 | } |
---|
| 500 | else if ((CDomain::type_attr::curvilinear == domain->type) || (CDomain::type_attr::unstructured == domain->type) ) |
---|
| 501 | { |
---|
| 502 | StdString latName = this->getLatCoordName(fieldId); |
---|
[2338] | 503 | domain->has_lat_in_read_file = SuperClassWriter::hasVariable(latName) ; |
---|
[1582] | 504 | StdString lonName = this->getLonCoordName(fieldId); |
---|
[2338] | 505 | domain->has_lon_in_read_file = SuperClassWriter::hasVariable(lonName) ; |
---|
[1582] | 506 | StdString boundsLatName = this->getBoundsId(latName); |
---|
[2338] | 507 | domain->has_bounds_lat_in_read_file = SuperClassWriter::hasVariable(boundsLatName) ; |
---|
[1582] | 508 | StdString boundsLonName = this->getBoundsId(lonName); |
---|
[2338] | 509 | domain->has_bounds_lon_in_read_file = SuperClassWriter::hasVariable(boundsLonName) ; |
---|
[1582] | 510 | } |
---|
[775] | 511 | } |
---|
[1622] | 512 | CATCH |
---|
[775] | 513 | |
---|
| 514 | /*! |
---|
| 515 | Read attributes of an axis from a file |
---|
| 516 | \param [in] axis axis whose attributes are read from the file |
---|
| 517 | \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file |
---|
| 518 | \param [in] emelentPosition position of axis in grid |
---|
[782] | 519 | \param [in] fieldId id (or name) associated with the grid |
---|
[775] | 520 | */ |
---|
[783] | 521 | void CNc4DataInput::readAxisAttributesFromFile(CAxis* axis, std::list<std::pair<StdString, StdSize> >& dimSizeMap, |
---|
[775] | 522 | int elementPosition, const StdString& fieldId) |
---|
[1622] | 523 | TRY |
---|
[775] | 524 | { |
---|
[783] | 525 | std::list<std::pair<StdString, StdSize> >::const_iterator itMapN = dimSizeMap.begin(), |
---|
| 526 | iteMap = dimSizeMap.end(); |
---|
[775] | 527 | for (int i = 0; i < elementPosition; ++i, ++itMapN) {} |
---|
[1158] | 528 | |
---|
| 529 | if (!axis->n_glo.isEmpty() && (axis->n_glo != itMapN->second)) |
---|
| 530 | { |
---|
| 531 | ERROR("void CNc4DataInput::readAxisAttributesFromFile(...)", |
---|
| 532 | << "The axis " << axis->getAxisOutputName() |
---|
| 533 | << " has n_glo read from file " << this->filename << " and n_glo provided from model" |
---|
| 534 | << " are not coherent. They should be the same." << std::endl |
---|
| 535 | << " n_glo read from file: "<< itMapN->second |
---|
| 536 | << " n_glo from model: "<< axis->n_glo << std::endl); |
---|
| 537 | } |
---|
[775] | 538 | axis->n_glo.setValue(itMapN->second); |
---|
| 539 | } |
---|
[1622] | 540 | CATCH |
---|
[775] | 541 | |
---|
| 542 | /*! |
---|
[782] | 543 | Read attribute value of an axis from a file |
---|
[775] | 544 | \param [in] axis axis whose attributes are read from the file |
---|
| 545 | \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file |
---|
| 546 | \param [in] emelentPosition position of axis in grid |
---|
[782] | 547 | \param [in] fieldId id (or name) associated with the grid |
---|
[775] | 548 | */ |
---|
[783] | 549 | void CNc4DataInput::readAxisAttributeValueFromFile(CAxis* axis, std::list<std::pair<StdString, StdSize> >& dimSizeMap, |
---|
[775] | 550 | int elementPosition, const StdString& fieldId) |
---|
[1622] | 551 | TRY |
---|
[775] | 552 | { |
---|
[783] | 553 | std::list<std::pair<StdString, StdSize> >::const_iterator itMapN = dimSizeMap.begin(), |
---|
| 554 | iteMap = dimSizeMap.end(); |
---|
[775] | 555 | for (int i = 0; i < elementPosition; ++i, ++itMapN) {} |
---|
| 556 | |
---|
| 557 | { // Read axis value |
---|
[1310] | 558 | bool hasValue = SuperClassWriter::hasVariable(itMapN->first); |
---|
| 559 | if (hasValue) |
---|
| 560 | { |
---|
| 561 | std::vector<StdSize> nBegin(1, 0), nSize(1, itMapN->second); |
---|
| 562 | CArray<double,1> readAxisValue(itMapN->second); |
---|
| 563 | readFieldVariableValue(readAxisValue, itMapN->first, nBegin, nSize, true); |
---|
| 564 | int begin = 0, n = itMapN->second; |
---|
| 565 | if (!axis->begin.isEmpty()) begin = axis->begin.getValue(); |
---|
| 566 | if (!axis->n.isEmpty()) n = axis->n.getValue(); |
---|
| 567 | axis->value.resize(n); |
---|
| 568 | for (int i = 0; i < n; ++i) axis->value(i) = readAxisValue(begin + i); |
---|
| 569 | } |
---|
[775] | 570 | } |
---|
| 571 | } |
---|
[1622] | 572 | CATCH |
---|
[775] | 573 | |
---|
[967] | 574 | /*! |
---|
| 575 | Read attributes of a scalar from a file |
---|
| 576 | \param [in] scalar scalar whose attributes are read from the file |
---|
| 577 | \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file |
---|
| 578 | \param [in] emelentPosition position of scalar in grid |
---|
| 579 | \param [in] fieldId id (or name) associated with the grid |
---|
| 580 | */ |
---|
| 581 | void CNc4DataInput::readScalarAttributesFromFile(CScalar* scalar, std::list<std::pair<StdString, StdSize> >& dimSizeMap, |
---|
| 582 | int elementPosition, const StdString& fieldId) |
---|
| 583 | { |
---|
[1158] | 584 | /*Nothing to do */ |
---|
[967] | 585 | } |
---|
| 586 | |
---|
| 587 | /*! |
---|
| 588 | Read attribute value of an axis from a file |
---|
| 589 | \param [in] axis axis whose attributes are read from the file |
---|
| 590 | \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file |
---|
| 591 | \param [in] emelentPosition position of axis in grid |
---|
| 592 | \param [in] fieldId id (or name) associated with the grid |
---|
| 593 | */ |
---|
| 594 | void CNc4DataInput::readScalarAttributeValueFromFile(CScalar* scalar, std::list<std::pair<StdString, StdSize> >& dimSizeMap, |
---|
| 595 | int elementPosition, const StdString& fieldId) |
---|
| 596 | { |
---|
[1158] | 597 | /*Nothing to do */ |
---|
[967] | 598 | } |
---|
| 599 | |
---|
[599] | 600 | void CNc4DataInput::closeFile_(void) |
---|
[1622] | 601 | TRY |
---|
[599] | 602 | { |
---|
| 603 | SuperClassWriter::close(); |
---|
| 604 | } |
---|
[1622] | 605 | CATCH |
---|
[335] | 606 | } // namespace xios |
---|