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