Changeset 825


Ignore:
Timestamp:
02/19/16 14:34:03 (8 years ago)
Author:
mhnguyen
Message:

Relaxing constraints on reading attributes from a file.

+) If there is no coordinate (lon, lat) in file, there wont be error anymore.
It's user who will provide these info.

Test
+) On Curie
+) Correct on test_remap

Location:
XIOS/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/inputs/REMAP/iodef.xml

    r824 r825  
    8181       <generate_rectilinear_domain /> 
    8282     </domain> 
    83      <domain id="src_domain_curvilinear" type="rectilinear"> 
     83     <domain id="src_domain_curvilinear" type="curvilinear"> 
    8484       <generate_rectilinear_domain /> 
    8585     </domain> 
  • XIOS/trunk/src/io/inetcdf4.cpp

    r811 r825  
    2828    this->timeCounterName = timeCounterName; 
    2929    if (!CNetCdfInterface::isDimExisted(this->ncidp, this->timeCounterName)) this->timeCounterName=this->getUnlimitedDimensionName() ; 
    30      
     30 
    3131  } 
    3232 
     
    6363    int varid = 0; 
    6464    int grpid = this->getGroup(path); 
    65     CNetCdfInterface::inqVarId(grpid, varname, varid); 
     65    if (this->hasVariable(varname, path)) 
     66      CNetCdfInterface::inqVarId(grpid, varname, varid); 
    6667    return varid; 
    6768  } 
     
    344345    { 
    345346      const StdString& varname = *it; 
    346       if (varname.compare(0, name.size(), name) == 0) return true; 
     347      if ((varname.compare(0, name.size(), name) == 0) && (0 != name.size())) return true; 
    347348    } 
    348349    return false; 
     
    726727                                       const CVarPath* const path) 
    727728  { 
     729    StdString lonName; 
    728730    std::list<StdString>::const_iterator itbList, itList, iteList; 
    729731    std::list<StdString> clist = this->getCoordinatesIdList(varname, path); 
     
    735737        StdString unit = this->getAttributeValue(CCFKeywords::XIOS_CF_units, &(*itList), path); 
    736738        if (CCFConvention::XIOS_CF_Longitude_units.end() != CCFConvention::XIOS_CF_Longitude_units.find(unit)) 
    737           return *itList; 
    738       } 
    739     } 
     739        { 
     740          lonName = *itList; 
     741          return lonName; 
     742        } 
     743      } 
     744    } 
     745    return lonName; 
    740746  } 
    741747 
     
    743749                                       const CVarPath* const path) 
    744750  { 
     751    StdString latName; 
    745752    std::list<StdString>::const_iterator itbList, itList, iteList; 
    746753    std::list<StdString> clist = this->getCoordinatesIdList(varname, path); 
     
    752759        StdString unit = this->getAttributeValue(CCFKeywords::XIOS_CF_units, &(*itList), path); 
    753760        if (CCFConvention::XIOS_CF_Latitude_units.end() != CCFConvention::XIOS_CF_Latitude_units.find(unit)) 
    754           return *itList; 
    755       } 
    756     } 
     761        { 
     762          latName = *itList; 
     763          return latName; 
     764        } 
     765      } 
     766    } 
     767    return latName; 
    757768  } 
    758769 
  • XIOS/trunk/src/io/nc4_data_input.cpp

    r811 r825  
    147147    std::map<StdString, StdSize> dimSizeMap = SuperClassWriter::getDimensions(&fieldId); 
    148148    std::list<StdString> dimList = SuperClassWriter::getDimensionsList(&fieldId); 
    149      
     149 
    150150    realGridDim = SuperClassWriter::isTemporal(fieldId) ? dimSizeMap.size() - 1 : dimSizeMap.size(); 
    151151    if (isUnstructuredGrid) ++realGridDim; 
     
    157157 
    158158    // Remove unlimited dimension from the map, we dont need it anymore 
    159     if (SuperClassWriter::isTemporal(fieldId))  
     159    if (SuperClassWriter::isTemporal(fieldId)) 
    160160    { 
    161161      dimSizeMap.erase(SuperClassWriter::getUnlimitedDimensionName()); 
    162162      dimList.pop_front() ;  // assume time dimension is first 
    163163    } 
    164      
     164 
    165165    int mapSize = dimSizeMap.size() - 1; 
    166166    std::list<std::pair<StdString, StdSize> > listDimSize; 
     
    232232    itMapNj = itMapNi; ++itMapNj; 
    233233 
    234     if (this->isRectilinear(fieldId)) 
     234    if ((CDomain::type_attr::rectilinear == domain->type))// || this->isRectilinear(fieldId)) 
    235235    { 
    236236      // Ok, try to read some f.. attributes such as longitude and latitude 
    237       domain->latvalue_rectilinear_read_from_file.resize(itMapNj->second); 
    238       std::vector<StdSize> nBeginLat(1, 0), nSizeLat(1, itMapNj->second); 
    239       readFieldVariableValue(domain->latvalue_rectilinear_read_from_file, itMapNj->first, nBeginLat, nSizeLat, true); 
    240  
    241       domain->lonvalue_rectilinear_read_from_file.resize(itMapNi->second); 
    242       std::vector<StdSize> nBeginLon(1, 0), nSizeLon(1, itMapNi->second); 
    243       readFieldVariableValue(domain->lonvalue_rectilinear_read_from_file, itMapNi->first, nBeginLon, nSizeLon, true); 
     237      bool hasLat = SuperClassWriter::hasVariable(itMapNj->first); 
     238      if (hasLat) 
     239      { 
     240        domain->latvalue_rectilinear_read_from_file.resize(itMapNj->second); 
     241        std::vector<StdSize> nBeginLat(1, 0), nSizeLat(1, itMapNj->second); 
     242        readFieldVariableValue(domain->latvalue_rectilinear_read_from_file, itMapNj->first, nBeginLat, nSizeLat, true); 
     243      } 
     244 
     245      bool hasLon = SuperClassWriter::hasVariable(itMapNi->first); 
     246      if (hasLon) 
     247      { 
     248        domain->lonvalue_rectilinear_read_from_file.resize(itMapNi->second); 
     249        std::vector<StdSize> nBeginLon(1, 0), nSizeLon(1, itMapNi->second); 
     250        readFieldVariableValue(domain->lonvalue_rectilinear_read_from_file, itMapNi->first, nBeginLon, nSizeLon, true); 
     251      } 
    244252      domain->fillInRectilinearLonLat(); 
    245253    } 
    246     else if (this->isCurvilinear(fieldId)) 
     254    else if ((CDomain::type_attr::curvilinear == domain->type))// || (this->isCurvilinear(fieldId))) 
    247255    { 
    248256      int ni = domain->ni; 
     
    253261 
    254262      StdString latName = this->getLatCoordName(fieldId); 
    255       domain->latvalue_2d.resize(ni,nj); 
    256       readFieldVariableValue(domain->latvalue_2d, latName, nBeginLatLon, nSizeLatLon); 
     263      if (SuperClassWriter::hasVariable(latName)) //(0 != latName.compare("")) 
     264      { 
     265        domain->latvalue_2d.resize(ni,nj); 
     266        readFieldVariableValue(domain->latvalue_2d, latName, nBeginLatLon, nSizeLatLon); 
     267      } 
    257268      StdString lonName = this->getLonCoordName(fieldId); 
    258       domain->lonvalue_2d.resize(ni,nj); 
    259       readFieldVariableValue(domain->lonvalue_2d, lonName, nBeginLatLon, nSizeLatLon); 
     269      if (SuperClassWriter::hasVariable(lonName)) //(0 != lonName.compare("")) 
     270      { 
     271        domain->lonvalue_2d.resize(ni,nj); 
     272        readFieldVariableValue(domain->lonvalue_2d, lonName, nBeginLatLon, nSizeLatLon); 
     273      } 
    260274 
    261275      StdString boundsLatName = this->getBoundsId(latName); 
    262       if (0 == boundsLatName.compare("")) 
    263          ERROR("CNc4DataInput::readDomainAttributeValueFromFile(...)", 
    264               << "Field '" << fieldId << std::endl 
    265               << "Trying to read attributes from curvilinear grid." 
    266               << "Latitude variable " << latName << " does not have bounds."); 
    267276      StdString boundsLonName = this->getBoundsId(lonName); 
    268       if (0 == boundsLonName.compare("")) 
    269          ERROR("CNc4DataInput::readDomainAttributeValueFromFile(...)", 
    270               << "Field '" << fieldId << std::endl 
    271               << "Trying to read attributes from curvilinear grid." 
    272               << "Longitude variable " << lonName << " does not have bounds."); 
    273277 
    274278      int nbVertex = this->getNbVertex(fieldId); 
    275       domain->nvertex.setValue(nbVertex); 
     279      if (SuperClassWriter::hasVariable(boundsLatName) || SuperClassWriter::hasVariable(boundsLonName)) //if ((0 != boundsLatName.compare("")) || (0 != boundsLonName.compare(""))) 
     280        domain->nvertex.setValue(nbVertex); 
    276281      std::vector<StdSize> nBeginBndsLatLon(3), nSizeBndsLatLon(3); 
    277282      nBeginBndsLatLon[0] = domain->jbegin.getValue(); nSizeBndsLatLon[0] = nj; 
     
    279284      nBeginBndsLatLon[2] = 0; nSizeBndsLatLon[2] = nbVertex; 
    280285 
    281       domain->bounds_lat_2d.resize(nbVertex,ni,nj); 
    282       readFieldVariableValue(domain->bounds_lat_2d, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon); 
    283       domain->bounds_lon_2d.resize(nbVertex,ni,nj); 
    284       readFieldVariableValue(domain->bounds_lon_2d, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon); 
    285     } 
    286     else if (this->isUnstructured(fieldId)) 
     286      if (SuperClassWriter::hasVariable(boundsLatName)) //(0 != boundsLatName.compare("")) 
     287      { 
     288        domain->bounds_lat_2d.resize(nbVertex,ni,nj); 
     289        readFieldVariableValue(domain->bounds_lat_2d, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon); 
     290 
     291      } 
     292      if (SuperClassWriter::hasVariable(boundsLonName)) //(0 != boundsLonName.compare("")) 
     293      { 
     294        domain->bounds_lon_2d.resize(nbVertex,ni,nj); 
     295        readFieldVariableValue(domain->bounds_lon_2d, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon); 
     296      } 
     297    } 
     298    else if ((CDomain::type_attr::unstructured == domain->type))// || (this->isUnstructured(fieldId))) 
    287299    { 
    288300      /* 
     
    292304              << "Trying to read attributes from unstructured grid." 
    293305              << "i_index of domain" << domain->getId() << " is mandatory"); 
    294        
     306 
    295307      int ni = domain->i_index.numElements(); 
    296308*/ 
     
    302314        for(int idx = 0; idx < ni; ++idx) domain->i_index(idx)=ibegin+idx ; 
    303315      } 
    304        
     316 
    305317      std::vector<StdSize> nBeginLatLon(1,0), nSizeLatLon(1,0); 
    306318      nSizeLatLon[0]  = domain->ni_glo.getValue(); 
     
    308320 
    309321      StdString latName = this->getLatCoordName(fieldId); 
    310       readFieldVariableValue(globalLonLat, latName, nBeginLatLon, nSizeLatLon); 
    311       domain->latvalue_1d.resize(ni); 
    312       for (int idx = 0; idx < ni; ++idx) 
    313         domain->latvalue_1d(idx) =  globalLonLat(domain->i_index(idx)); 
     322      if (SuperClassWriter::hasVariable(latName)) //(0 != latName.compare("")) 
     323      { 
     324        readFieldVariableValue(globalLonLat, latName, nBeginLatLon, nSizeLatLon); 
     325        domain->latvalue_1d.resize(ni); 
     326        for (int idx = 0; idx < ni; ++idx) 
     327          domain->latvalue_1d(idx) =  globalLonLat(domain->i_index(idx)); 
     328      } 
    314329 
    315330      StdString lonName = this->getLonCoordName(fieldId); 
    316       readFieldVariableValue(globalLonLat, lonName, nBeginLatLon, nSizeLatLon); 
    317       domain->lonvalue_1d.resize(ni); 
    318       for (int idx = 0; idx < ni; ++idx) 
    319         domain->lonvalue_1d(idx) = globalLonLat(domain->i_index(idx)); 
     331      if (SuperClassWriter::hasVariable(lonName)) //(0 != lonName.compare("")) 
     332      { 
     333        readFieldVariableValue(globalLonLat, lonName, nBeginLatLon, nSizeLatLon); 
     334        domain->lonvalue_1d.resize(ni); 
     335        for (int idx = 0; idx < ni; ++idx) 
     336          domain->lonvalue_1d(idx) = globalLonLat(domain->i_index(idx)); 
     337      } 
    320338 
    321339      StdString boundsLatName = this->getBoundsId(latName); 
    322       if (0 == boundsLatName.compare("")) 
    323          ERROR("CNc4DataInput::readDomainAttributeValueFromFile(...)", 
    324               << "Field '" << fieldId << std::endl 
    325               << "Trying to read attributes from unstructured grid." 
    326               << "Latitude variable " << latName << " does not have bounds."); 
    327340      StdString boundsLonName = this->getBoundsId(lonName); 
    328       if (0 == boundsLonName.compare("")) 
    329          ERROR("CNc4DataInput::readDomainAttributeValueFromFile(...)", 
    330               << "Field '" << fieldId << std::endl 
    331               << "Trying to read attributes from unstructured grid." 
    332               << "Longitude variable " << lonName << " does not have bounds."); 
    333341 
    334342      int nbVertex = this->getNbVertex(fieldId); 
    335       domain->nvertex.setValue(nbVertex); 
     343      if (SuperClassWriter::hasVariable(boundsLatName) || SuperClassWriter::hasVariable(boundsLonName)) // (0 != boundsLatName.compare("")) || (0 != boundsLonName.compare(""))) 
     344        domain->nvertex.setValue(nbVertex); 
     345 
    336346      std::vector<StdSize> nBeginBndsLatLon(2), nSizeBndsLatLon(2); 
    337347      nBeginBndsLatLon[0] = 0; nSizeBndsLatLon[0] = domain->ni_glo.getValue(); 
    338348      nBeginBndsLatLon[1] = 0; nSizeBndsLatLon[1] = nbVertex; 
    339349 
    340       CArray<double,2> globalBndsLonLat(nSizeBndsLatLon[1], nSizeBndsLatLon[0]); 
    341       readFieldVariableValue(globalBndsLonLat, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon); 
    342       domain->bounds_lat_1d.resize(nbVertex,ni); 
    343       for (int idx = 0; idx < ni; ++idx) 
    344         for (int jdx = 0; jdx < nbVertex; ++jdx) 
    345           domain->bounds_lat_1d(jdx,idx) = globalBndsLonLat(jdx, domain->i_index(idx)); 
    346  
    347       readFieldVariableValue(globalBndsLonLat, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon); 
    348       domain->bounds_lon_1d.resize(nbVertex,ni); 
    349       for (int idx = 0; idx < ni; ++idx) 
    350         for (int jdx = 0; jdx < nbVertex; ++jdx) 
    351           domain->bounds_lon_1d(jdx,idx) = globalBndsLonLat(jdx, domain->i_index(idx)); 
     350      if (SuperClassWriter::hasVariable(boundsLatName)) //(0 != boundsLatName.compare("")) 
     351      { 
     352        CArray<double,2> globalBndsLonLat(nSizeBndsLatLon[1], nSizeBndsLatLon[0]); 
     353        readFieldVariableValue(globalBndsLonLat, boundsLatName, nBeginBndsLatLon, nSizeBndsLatLon); 
     354        domain->bounds_lat_1d.resize(nbVertex,ni); 
     355        for (int idx = 0; idx < ni; ++idx) 
     356          for (int jdx = 0; jdx < nbVertex; ++jdx) 
     357            domain->bounds_lat_1d(jdx,idx) = globalBndsLonLat(jdx, domain->i_index(idx)); 
     358      } 
     359 
     360      if (SuperClassWriter::hasVariable(boundsLonName)) //(0 != boundsLonName.compare("")) 
     361      { 
     362        CArray<double,2> globalBndsLonLat(nSizeBndsLatLon[1], nSizeBndsLatLon[0]); 
     363        readFieldVariableValue(globalBndsLonLat, boundsLonName, nBeginBndsLatLon, nSizeBndsLatLon); 
     364        domain->bounds_lon_1d.resize(nbVertex,ni); 
     365        for (int idx = 0; idx < ni; ++idx) 
     366          for (int jdx = 0; jdx < nbVertex; ++jdx) 
     367            domain->bounds_lon_1d(jdx,idx) = globalBndsLonLat(jdx, domain->i_index(idx)); 
     368      } 
    352369    } 
    353370  } 
Note: See TracChangeset for help on using the changeset viewer.