Ignore:
Timestamp:
11/12/15 16:33:03 (9 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/inetcdf4.cpp

    r736 r782  
    11#include "inetcdf4.hpp" 
    22#include "netCdfInterface.hpp" 
     3#include "netCdf_cf_constant.hpp" 
    34 
    45#include <boost/algorithm/string.hpp> 
     
    302303    { 
    303304      const StdString& attname = *it; 
    304       if (attname.compare(name) == 0) 
     305      if (attname.compare(0, name.size(), name) == 0) 
    305306        return retvalue; 
    306307      retvalue++; 
     
    326327    { 
    327328      const StdString& attname = *it; 
    328       if (attname.compare(name) == 0) return true; 
     329      if (attname.compare(0, name.size(), name) == 0) return true; 
    329330    } 
    330331    return false; 
     
    339340    { 
    340341      const StdString& varname = *it; 
    341       if (varname.compare(name) == 0) return true; 
     342      if (varname.compare(0, name.size(), name) == 0) return true; 
    342343    } 
    343344    return false; 
     
    347348                                 const CVarPath* const path) 
    348349  { 
    349     return this->hasAttribute("coordinates", &name, path); 
     350    return this->hasAttribute(CCFKeywords::XIOS_CF_coordinates, &name, path); 
    350351  } 
    351352 
     
    353354                            const CVarPath* const path) 
    354355  { 
    355     return this->hasAttribute("bounds", &name, path); 
     356    return this->hasAttribute(CCFKeywords::XIOS_CF_bounds, &name, path); 
    356357  } 
    357358 
     
    441442  { 
    442443    StdString retvalue; 
    443     if (this->hasAttribute("coordinates", &name, path)) 
    444     { 
    445       return this->getAttributeValue("coordinates", &name, path); 
     444    if (this->hasAttribute(CCFKeywords::XIOS_CF_coordinates, &name, path)) 
     445    { 
     446      return this->getAttributeValue(CCFKeywords::XIOS_CF_coordinates, &name, path); 
    446447    } 
    447448    else 
     
    464465  { 
    465466    StdString retvalue; 
    466     if (this->hasAttribute("bounds", &name, path)) 
    467       retvalue = this->getAttributeValue("bounds", &name, path); 
     467    if (this->hasAttribute(CCFKeywords::XIOS_CF_bounds, &name, path)) 
     468      retvalue = this->getAttributeValue(CCFKeywords::XIOS_CF_bounds, &name, path); 
    468469    return retvalue; 
    469470  } 
     
    509510      return false; 
    510511 
     512    bool isCurVi = true; 
     513    unsigned int nbLonLat = 0; 
    511514    std::list<StdString> coords = this->getCoordinatesIdList(name, path); 
    512515    std::list<StdString>::const_iterator it = coords.begin(), end = coords.end(); 
     
    514517    { 
    515518      const StdString& coord = *it; 
    516       if (this->hasVariable(coord, path)) 
     519      if (this->hasVariable(coord, path) && !this->isTemporal(coord, path)) 
    517520      { 
    518521        std::map<StdString, StdSize> dimvar = this->getDimensions(&coord, path); 
    519         if (dimvar.size() != 2) return false; 
    520       } 
    521       else return false; 
    522     } 
    523     return true; 
     522        if (2 == dimvar.size()) ++nbLonLat; 
     523      } 
     524    } 
     525    if (2 != nbLonLat) isCurVi = false; 
     526 
     527    return isCurVi; 
    524528  } 
    525529 
     
    538542    { 
    539543      const StdString& coord = *it; 
    540       if (this->hasVariable(coord, path)) 
     544      if (this->hasVariable(coord, path) && !this->isTemporal(coord, path)) 
    541545      { 
    542546        std::map<StdString, StdSize> dimvar = this->getDimensions(&coord, path); 
     
    581585      else 
    582586      { 
    583         if (coord.compare(this->getUnlimitedDimensionName()) == 0) 
     587        StdString unlimitedDimName = this->getUnlimitedDimensionName(); 
     588        if (coord.compare(0, unlimitedDimName.size(), unlimitedDimName) == 0) 
    584589          continue; 
    585590        i++; 
     
    612617        else 
    613618        { 
    614           if (coord.compare(this->getUnlimitedDimensionName()) == 0) 
     619          StdString unlimitedDimName = this->getUnlimitedDimensionName(); 
     620          if (coord.compare(0, unlimitedDimName.size(), unlimitedDimName) == 0) 
    615621            continue; 
    616622          return false; 
     
    712718                          const CVarPath* const path, StdSize record); 
    713719 
    714   template <> 
    715   void CINetCDF4::getData(CArray<double, 1>& data, const StdString& var, 
    716                           bool collective, StdSize record, 
    717                           const std::vector<StdSize>* start /*= NULL*/, 
    718                           const std::vector<StdSize>* count /*= NULL*/) 
    719   { 
    720     int varid = this->getVariable(var); 
    721  
    722     if (this->mpi && collective) 
    723       CNetCdfInterface::varParAccess(ncidp, varid, NC_COLLECTIVE); 
    724     else if (this->mpi && !collective) 
    725       CNetCdfInterface::varParAccess(ncidp, varid, NC_INDEPENDENT); 
    726  
    727     std::vector<StdSize> sstart, scount; 
    728     StdSize array_size = 1; 
    729     this->getDataInfo(var, NULL, record, sstart, scount, array_size, start, count); 
    730  
    731     if (data.numElements() != array_size) 
    732     { 
    733       ERROR("CONetCDF4::getData(...)", 
    734             << "[ Array size = " << data.numElements() 
    735             << ", Data size = "  << array_size 
    736             << " ] Invalid array size"); 
    737     } 
    738  
    739     CNetCdfInterface::getVaraType(ncidp, varid, &sstart[0], &scount[0], data.dataFirst()); 
    740   } 
    741  
    742720  //--------------------------------------------------------------- 
    743721 
     
    745723                                       const CVarPath* const path) 
    746724  { 
     725    std::list<StdString>::const_iterator itbList, itList, iteList; 
    747726    std::list<StdString> clist = this->getCoordinatesIdList(varname, path); 
    748     if (this->hasCoordinates(varname, path)) 
    749       return *clist.begin(); 
    750     else 
    751       return *clist.rbegin(); 
     727    itbList = clist.begin(); iteList = clist.end(); 
     728    for (itList = itbList; itList != iteList; ++itList) 
     729    { 
     730      if (this->hasAttribute(CCFKeywords::XIOS_CF_units, &(*itList), path)) 
     731      { 
     732        StdString unit = this->getAttributeValue(CCFKeywords::XIOS_CF_units, &(*itList), path); 
     733        if (CCFConvention::XIOS_CF_Longitude_units.end() != CCFConvention::XIOS_CF_Longitude_units.find(unit)) 
     734          return *itList; 
     735      } 
     736    } 
    752737  } 
    753738 
     
    755740                                       const CVarPath* const path) 
    756741  { 
     742    std::list<StdString>::const_iterator itbList, itList, iteList; 
    757743    std::list<StdString> clist = this->getCoordinatesIdList(varname, path); 
    758     if (this->hasCoordinates(varname, path)) 
    759       return *(++clist.begin()); 
    760     else 
    761       return *(++clist.rbegin()); 
     744    itbList = clist.begin(); iteList = clist.end(); 
     745    for (itList = itbList; itList != iteList; ++itList) 
     746    { 
     747      if (this->hasAttribute(CCFKeywords::XIOS_CF_units, &(*itList), path)) 
     748      { 
     749        StdString unit = this->getAttributeValue(CCFKeywords::XIOS_CF_units, &(*itList), path); 
     750        if (CCFConvention::XIOS_CF_Latitude_units.end() != CCFConvention::XIOS_CF_Latitude_units.find(unit)) 
     751          return *itList; 
     752      } 
     753    } 
    762754  } 
    763755 
Note: See TracChangeset for help on using the changeset viewer.