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

Reading attributes of curvilinear grid from file

+) Correct some minor bugs detecting type of grid
+) Use constant string for attributes conforming to CF convention
+) Add part of code to read attributes of curvilinear grid

Test
+) On Curie
+) test_remap passes

File:
1 edited

Legend:

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

    r777 r782  
    202202    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file 
    203203    \param [in] emelentPosition position of domain in grid 
     204    \param [in] fieldId id (or name) associated with the grid 
    204205  */ 
    205206  void CNc4DataInput::readDomainAttributeValueFromFile(CDomain* domain, std::map<StdString, StdSize>& dimSizeMap, 
     
    227228    else if (this->isCurvilinear(fieldId)) 
    228229    { 
    229  
     230      int ni = domain->ni; 
     231      int nj = domain->nj; 
     232      std::vector<StdSize> nBeginLatLon(2), nSizeLatLon(2); 
     233      nBeginLatLon[0] = domain->jbegin.getValue(); nBeginLatLon[1] = domain->ibegin.getValue(); 
     234      nSizeLatLon[0]  = nj; nSizeLatLon[1] = ni; 
     235 
     236      StdString latName = this->getLatCoordName(fieldId); 
     237      domain->latvalue_2d.resize(ni,nj); 
     238      readFieldVariableValue(domain->latvalue_2d, latName, nBeginLatLon, nSizeLatLon); 
     239      StdString lonName = this->getLonCoordName(fieldId); 
     240      domain->lonvalue_2d.resize(ni,nj); 
     241      readFieldVariableValue(domain->lonvalue_2d, lonName, nBeginLatLon, nSizeLatLon); 
     242 
     243      StdString boundsLatName = this->getBoundsId(latName); 
     244      if (0 == boundsLatName.compare("")) 
     245         ERROR("CNc4DataInput::readDomainAttributeValueFromFile(...)", 
     246              << "Field '" << fieldId << std::endl 
     247              << "Trying to read attributes from curvilinear grid." 
     248              << "Latitude variable " << latName << " does not have bounds."); 
     249      StdString boundsLonName = this->getBoundsId(lonName); 
     250      if (0 == boundsLonName.compare("")) 
     251         ERROR("CNc4DataInput::readDomainAttributeValueFromFile(...)", 
     252              << "Field '" << fieldId << std::endl 
     253              << "Trying to read attributes from curvilinear grid." 
     254              << "Longitude variable " << lonName << " does not have bounds."); 
     255 
     256      domain->nvertex.setValue(4); 
     257      std::vector<StdSize> nBeginBndsLatLon(3), nSizeBndsLatLon(3); 
     258      nBeginBndsLatLon[0] = domain->jbegin.getValue(); nSizeBndsLatLon[0] = nj; 
     259      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); 
     263      readFieldVariableValue(domain->bounds_lat_2d, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon); 
     264      domain->bounds_lon_2d.resize(4,ni,nj); 
     265      readFieldVariableValue(domain->bounds_lon_2d, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon); 
    230266    } 
    231267    else if (this->isUnstructured(fieldId)) 
     
    236272 
    237273  /*! 
    238     Read attributes of a domain from a file 
     274    Read attribute value of a domain from a file 
    239275    \param [in] domain domain whose attributes are read from the file 
    240276    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file 
    241277    \param [in] emelentPosition position of domain in grid 
     278    \param [in] fieldId id (or name) associated with the grid 
    242279  */ 
    243280  void CNc4DataInput::readDomainAttributesFromFile(CDomain* domain, std::map<StdString, StdSize>& dimSizeMap, 
     
    251288    itMapNi = itMapNj; ++itMapNi; 
    252289 
    253     if (this->isRectilinear(fieldId)) 
     290    if (this->isRectilinear(fieldId) || this->isCurvilinear(fieldId)) 
    254291    { 
    255292      domain->nj_glo.setValue(itMapNj->second); 
    256293      domain->ni_glo.setValue((itMapNi)->second); 
    257     } 
    258     else if (this->isCurvilinear(fieldId)) 
    259     { 
    260  
    261294    } 
    262295    else if (this->isUnstructured(fieldId)) 
     
    271304    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file 
    272305    \param [in] emelentPosition position of axis in grid 
     306    \param [in] fieldId id (or name) associated with the grid 
    273307  */ 
    274308  void CNc4DataInput::readAxisAttributesFromFile(CAxis* axis, std::map<StdString, StdSize>& dimSizeMap, 
     
    282316 
    283317  /*! 
    284     Read attributes of an axis from a file 
     318    Read attribute value of an axis from a file 
    285319    \param [in] axis axis whose attributes are read from the file 
    286320    \param [in] dimSizeMap Dimensions and and their corresponding names and size read from file 
    287321    \param [in] emelentPosition position of axis in grid 
     322    \param [in] fieldId id (or name) associated with the grid 
    288323  */ 
    289324  void CNc4DataInput::readAxisAttributeValueFromFile(CAxis* axis, std::map<StdString, StdSize>& dimSizeMap, 
     
    306341  } 
    307342 
    308   void CNc4DataInput::readFieldVariableValue(CArray<double,1>& var, const StdString& varId, 
    309                                              const std::vector<StdSize>& nBegin, 
    310                                              const std::vector<StdSize>& nSize, 
    311                                              bool forceIndependent) 
    312   { 
    313     if (SuperClass::type==MULTI_FILE || !isCollective) return; 
    314  
    315     bool openCollective = isCollective; 
    316     if (forceIndependent) openCollective = !isCollective; 
    317     switch (SuperClass::type) 
    318     { 
    319       case MULTI_FILE: 
    320         SuperClassWriter::getData(var, varId, openCollective, 0); 
    321         break; 
    322       case ONE_FILE: 
    323       { 
    324         SuperClassWriter::getData(var, varId, openCollective, 0, &nBegin, &nSize); 
    325         break; 
    326       } 
    327     } 
    328   } 
    329  
    330343  void CNc4DataInput::closeFile_(void) 
    331344  { 
Note: See TracChangeset for help on using the changeset viewer.