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