Ignore:
Timestamp:
11/12/15 16:33:08 (8 years ago)
Author:
mhnguyen
Message:

Adding attribute reading of unstructured grid

+) Fix a minor bug relating to unstructured grid detection
+) Add attribute reading for unstructured domain

Test
+) On Curie
+) test_remap passes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/io/nc4_data_input.cpp

    r782 r783  
    143143    // Verify the compatibility of dimension of declared grid and real grid in file 
    144144    int realGridDim = 1; 
     145    bool isUnstructuredGrid = SuperClassWriter::isUnstructured(fieldId); 
    145146    std::map<StdString, StdSize> dimSizeMap = SuperClassWriter::getDimensions(&fieldId); 
    146147    realGridDim = SuperClassWriter::isTemporal(fieldId) ? dimSizeMap.size() - 1 : dimSizeMap.size(); 
     148    if (isUnstructuredGrid) ++realGridDim; 
    147149 
    148150    if (gridDim != realGridDim) 
     
    154156    if (SuperClassWriter::isTemporal(fieldId)) dimSizeMap.erase(SuperClassWriter::getUnlimitedDimensionName()); 
    155157    int mapSize = dimSizeMap.size() - 1; 
     158    std::list<std::pair<StdString, StdSize> > listDimSize; 
     159    for (std::map<StdString, StdSize>::const_iterator itMap = dimSizeMap.begin(); itMap != dimSizeMap.end(); ++itMap) 
     160      listDimSize.push_front(*itMap); 
    156161 
    157162    // Now process domain and axis 
     
    169174        { 
    170175           it = readValueDomains_.insert(domainP[idxDomain]->getId()); 
    171            if (it.second) readDomainAttributeValueFromFile(domainP[idxDomain], dimSizeMap, mapSize - 1 - elementPosition, fieldId); 
     176           if (it.second) readDomainAttributeValueFromFile(domainP[idxDomain], listDimSize, elementPosition, fieldId); 
    172177        } 
    173178        else 
    174179        { 
    175180          it = readMetaDataDomains_.insert(domainP[idxDomain]->getId()); 
    176           if (it.second) readDomainAttributesFromFile(domainP[idxDomain], dimSizeMap, mapSize - 1 - elementPosition, fieldId); 
     181          if (it.second) readDomainAttributesFromFile(domainP[idxDomain], listDimSize, elementPosition, fieldId); 
    177182        } 
    178183        ++idxDomain; 
    179         elementPosition += 2; 
     184        if (isUnstructuredGrid) ++elementPosition; 
     185        else elementPosition += 2; 
    180186      } 
    181187      else 
     
    184190        { 
    185191          it = readValueAxis_.insert(axisP[idxAxis]->getId()); 
    186           if (it.second) readAxisAttributeValueFromFile(axisP[idxAxis], dimSizeMap, mapSize - elementPosition, fieldId); 
     192          if (it.second) readAxisAttributeValueFromFile(axisP[idxAxis], listDimSize, elementPosition, fieldId); 
    187193        } 
    188194        else 
    189195        { 
    190196          it = readMetaDataAxis_.insert(axisP[idxAxis]->getId()); 
    191           if (it.second) readAxisAttributesFromFile(axisP[idxAxis], dimSizeMap, mapSize - elementPosition, fieldId); 
     197          if (it.second) readAxisAttributesFromFile(axisP[idxAxis], listDimSize, elementPosition, fieldId); 
    192198        } 
    193199        ++idxAxis; 
     
    204210    \param [in] fieldId id (or name) associated with the grid 
    205211  */ 
    206   void CNc4DataInput::readDomainAttributeValueFromFile(CDomain* domain, std::map<StdString, StdSize>& dimSizeMap, 
     212  void CNc4DataInput::readDomainAttributeValueFromFile(CDomain* domain, std::list<std::pair<StdString, StdSize> >& dimSizeMap, 
    207213                                                       int elementPosition, const StdString& fieldId) 
    208214  { 
    209215    // There are some optional attributes of a domain to retrieve from file    // + lon lat? 
    210     std::map<StdString, StdSize>::const_iterator itMapNj = dimSizeMap.begin(), itMapNi, 
    211                                                  iteMap  = dimSizeMap.end(); 
    212  
    213     for (int i = 0; i < elementPosition; ++i, ++itMapNj) {} 
    214     itMapNi = itMapNj; ++itMapNi; 
     216    std::list<std::pair<StdString, StdSize> >::const_iterator itMapNi = dimSizeMap.begin(), itMapNj, 
     217                                                              iteMap  = dimSizeMap.end(); 
     218 
     219    for (int i = 0; i < elementPosition; ++i, ++itMapNi) {} 
     220    itMapNj = itMapNi; ++itMapNj; 
    215221 
    216222    if (this->isRectilinear(fieldId)) 
     
    225231      readFieldVariableValue(domain->lonvalue_rectilinear_read_from_file, itMapNi->first, nBeginLon, nSizeLon, true); 
    226232      domain->fillInRectilinearLonLat(); 
     233    } 
     234    else if (this->isUnstructured(fieldId)) 
     235    { 
     236      int ni = domain->ni; 
     237      std::vector<StdSize> nBeginLatLon(1,0), nSizeLatLon(1,0); 
     238      nBeginLatLon[0] = domain->ibegin.getValue(); 
     239      nSizeLatLon[0]  = ni; 
     240 
     241      StdString latName = this->getLatCoordName(fieldId); 
     242      domain->latvalue_1d.resize(ni); 
     243      readFieldVariableValue(domain->latvalue_1d, latName, nBeginLatLon, nSizeLatLon); 
     244      StdString lonName = this->getLonCoordName(fieldId); 
     245      domain->lonvalue_1d.resize(ni); 
     246      readFieldVariableValue(domain->lonvalue_1d, lonName, nBeginLatLon, nSizeLatLon); 
     247 
     248      StdString boundsLatName = this->getBoundsId(latName); 
     249      if (0 == boundsLatName.compare("")) 
     250         ERROR("CNc4DataInput::readDomainAttributeValueFromFile(...)", 
     251              << "Field '" << fieldId << std::endl 
     252              << "Trying to read attributes from unstructured grid." 
     253              << "Latitude variable " << latName << " does not have bounds."); 
     254      StdString boundsLonName = this->getBoundsId(lonName); 
     255      if (0 == boundsLonName.compare("")) 
     256         ERROR("CNc4DataInput::readDomainAttributeValueFromFile(...)", 
     257              << "Field '" << fieldId << std::endl 
     258              << "Trying to read attributes from unstructured grid." 
     259              << "Longitude variable " << lonName << " does not have bounds."); 
     260 
     261      int nbVertex = this->getNbVertex(fieldId); 
     262      domain->nvertex.setValue(nbVertex); 
     263      std::vector<StdSize> nBeginBndsLatLon(2), nSizeBndsLatLon(2); 
     264      nBeginBndsLatLon[0] = domain->ibegin.getValue(); nSizeBndsLatLon[0] = ni; 
     265      nBeginBndsLatLon[1] = 0; nSizeBndsLatLon[1] = nbVertex; 
     266 
     267      domain->bounds_lat_1d.resize(nbVertex,ni); 
     268      readFieldVariableValue(domain->bounds_lat_1d, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon); 
     269      domain->bounds_lon_1d.resize(nbVertex,ni); 
     270      readFieldVariableValue(domain->bounds_lon_1d, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon); 
    227271    } 
    228272    else if (this->isCurvilinear(fieldId)) 
     
    254298              << "Longitude variable " << lonName << " does not have bounds."); 
    255299 
    256       domain->nvertex.setValue(4); 
     300      int nbVertex = this->getNbVertex(fieldId); 
     301      domain->nvertex.setValue(nbVertex); 
    257302      std::vector<StdSize> nBeginBndsLatLon(3), nSizeBndsLatLon(3); 
    258303      nBeginBndsLatLon[0] = domain->jbegin.getValue(); nSizeBndsLatLon[0] = nj; 
    259304      nBeginBndsLatLon[1] = domain->ibegin.getValue(); nSizeBndsLatLon[1] = ni; 
    260       nBeginBndsLatLon[2] = 0; nSizeBndsLatLon[2] = 4; 
    261  
    262       domain->bounds_lat_2d.resize(4,ni,nj); 
     305      nBeginBndsLatLon[2] = 0; nSizeBndsLatLon[2] = nbVertex; 
     306 
     307      domain->bounds_lat_2d.resize(nbVertex,ni,nj); 
    263308      readFieldVariableValue(domain->bounds_lat_2d, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon); 
    264       domain->bounds_lon_2d.resize(4,ni,nj); 
     309      domain->bounds_lon_2d.resize(nbVertex,ni,nj); 
    265310      readFieldVariableValue(domain->bounds_lon_2d, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon); 
    266     } 
    267     else if (this->isUnstructured(fieldId)) 
    268     { 
    269  
    270311    } 
    271312  } 
     
    278319    \param [in] fieldId id (or name) associated with the grid 
    279320  */ 
    280   void CNc4DataInput::readDomainAttributesFromFile(CDomain* domain, std::map<StdString, StdSize>& dimSizeMap, 
     321  void CNc4DataInput::readDomainAttributesFromFile(CDomain* domain, std::list<std::pair<StdString, StdSize> >& dimSizeMap, 
    281322                                                   int elementPosition, const StdString& fieldId) 
    282323  { 
    283324    // There are some mandatory attributes of a domain to retrieve from file 
    284325    // + ni_glo, nj_glo 
    285     std::map<StdString, StdSize>::const_iterator itMapNj = dimSizeMap.begin(), itMapNi, 
    286                                                  iteMap  = dimSizeMap.end(); 
    287     for (int i = 0; i < elementPosition; ++i, ++itMapNj) {} 
    288     itMapNi = itMapNj; ++itMapNi; 
     326    std::list<std::pair<StdString, StdSize> >::const_iterator itMapNi = dimSizeMap.begin(), itMapNj, 
     327                                                              iteMap  = dimSizeMap.end(); 
     328    for (int i = 0; i < elementPosition; ++i, ++itMapNi) {} 
     329    itMapNj = itMapNi; ++itMapNj; 
    289330 
    290331    if (this->isRectilinear(fieldId) || this->isCurvilinear(fieldId)) 
    291332    { 
    292333      domain->nj_glo.setValue(itMapNj->second); 
    293       domain->ni_glo.setValue((itMapNi)->second); 
     334      domain->ni_glo.setValue(itMapNi->second); 
    294335    } 
    295336    else if (this->isUnstructured(fieldId)) 
    296337    { 
    297  
     338      domain->nj_glo.setValue(1); 
     339      domain->ni_glo.setValue(itMapNi->second); 
    298340    } 
    299341  } 
     
    306348    \param [in] fieldId id (or name) associated with the grid 
    307349  */ 
    308   void CNc4DataInput::readAxisAttributesFromFile(CAxis* axis, std::map<StdString, StdSize>& dimSizeMap, 
     350  void CNc4DataInput::readAxisAttributesFromFile(CAxis* axis, std::list<std::pair<StdString, StdSize> >& dimSizeMap, 
    309351                                                 int elementPosition, const StdString& fieldId) 
    310352  { 
    311     std::map<StdString, StdSize>::const_iterator itMapN = dimSizeMap.begin(), 
    312                                                  iteMap = dimSizeMap.end(); 
     353    std::list<std::pair<StdString, StdSize> >::const_iterator itMapN = dimSizeMap.begin(), 
     354                                                              iteMap = dimSizeMap.end(); 
    313355    for (int i = 0; i < elementPosition; ++i, ++itMapN) {} 
    314356    axis->n_glo.setValue(itMapN->second); 
     
    322364    \param [in] fieldId id (or name) associated with the grid 
    323365  */ 
    324   void CNc4DataInput::readAxisAttributeValueFromFile(CAxis* axis, std::map<StdString, StdSize>& dimSizeMap, 
     366  void CNc4DataInput::readAxisAttributeValueFromFile(CAxis* axis, std::list<std::pair<StdString, StdSize> >& dimSizeMap, 
    325367                                                    int elementPosition, const StdString& fieldId) 
    326368  { 
    327     std::map<StdString, StdSize>::const_iterator itMapN = dimSizeMap.begin(), 
    328                                                  iteMap = dimSizeMap.end(); 
     369    std::list<std::pair<StdString, StdSize> >::const_iterator itMapN = dimSizeMap.begin(), 
     370                                                              iteMap = dimSizeMap.end(); 
    329371    for (int i = 0; i < elementPosition; ++i, ++itMapN) {} 
    330372 
Note: See TracChangeset for help on using the changeset viewer.