Changeset 686 for XIOS/trunk/src/io


Ignore:
Timestamp:
09/15/15 15:15:57 (9 years ago)
Author:
rlacroix
Message:

Use the NetCDF wrapper for inputs for better error checking.

Location:
XIOS/trunk/src/io
Files:
9 edited

Legend:

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

    r685 r686  
    2020  { /* Nothing to do */ } 
    2121 
    22   ///-------------------------------------------------------------- 
    23  
    24   void CINetCDF4::CheckError(int status) 
    25   { 
    26     if (status != NC_NOERR) 
    27     { 
    28       StdString errormsg(nc_strerror(status)); // fuite mémoire ici ? 
    29       ERROR("CINetCDF4::CheckError(int status)", 
    30             << "[ status = " << status << " ] " << errormsg); 
    31     } 
    32   } 
    33  
    3422  //--------------------------------------------------------------- 
    3523 
    3624  void CINetCDF4::close(void) 
    3725  { 
    38     CheckError(nc_close(this->ncidp)); 
     26    CNetCdfInterface::close(this->ncidp); 
    3927  } 
    4028 
     
    5038    { 
    5139      const StdString& groupid = *it; 
    52       CheckError(nc_inq_ncid(retvalue, const_cast<char*>(groupid.c_str()), &retvalue)); 
     40      CNetCdfInterface::inqNcId(retvalue, groupid, retvalue); 
    5341    } 
    5442 
     
    6149    int varid = 0; 
    6250    int grpid = this->getGroup(path); 
    63     CheckError(nc_inq_varid(grpid, varname.c_str(), &varid)); 
     51    CNetCdfInterface::inqVarId(grpid, varname, varid); 
    6452    return varid; 
    6553  } 
     
    7058    int dimid = 0; 
    7159    int grpid = this->getGroup(path); 
    72     CheckError(nc_inq_dimid(grpid, dimname.c_str(), &dimid)); 
     60    CNetCdfInterface::inqDimId(grpid, dimname, dimid); 
    7361    return dimid; 
    7462  } 
     
    8169    int grpid = this->getGroup(path); 
    8270    int varid = (var != NULL) ? this->getVariable(*var, path) : NC_GLOBAL; 
    83     CheckError(nc_inq_att(grpid, varid, attname.c_str(), 
    84                           &retvalue.first, &retvalue.second)); 
     71    CNetCdfInterface::inqAtt(grpid, varid, attname, retvalue.first, retvalue.second); 
    8572    return retvalue; 
    8673  } 
     
    9077    int dimid = 0; 
    9178    int grpid = this->getGroup(path); 
    92     CheckError(nc_inq_unlimdim(grpid, &dimid)); 
     79    CNetCdfInterface::inqUnLimDim(grpid, dimid); 
    9380    return dimid; 
    9481  } 
     
    9683  StdString CINetCDF4::getUnlimitedDimensionName(const CVarPath* const path) 
    9784  { 
    98     char full_name_in[NC_MAX_NAME +1]; 
    9985    int grpid = this->getGroup(path); 
    10086    int dimid = this->getUnlimitedDimension(path); 
    101     CheckError(nc_inq_dimname(grpid, dimid, full_name_in)); 
    102  
    103     StdString dimname(full_name_in); 
     87 
     88    StdString dimname; 
     89    if (dimid != -1) 
     90      CNetCdfInterface::inqDimName(grpid, dimid, dimname); 
    10491    return dimname; 
    10592  } 
    10693 
    10794  //--------------------------------------------------------------- 
     95 
    10896  StdSize CINetCDF4::getNbVertex(const StdString& name, 
    10997                                 const CVarPath* const path) 
     
    121109            (this->getCoordinatesIdList(name, path).back(), path); 
    122110      StdString dim = this->getDimensionsList(&bound, path).back(); 
    123       return (this->getDimensions(&bound, path)[dim]); 
     111      return this->getDimensions(&bound, path)[dim]; 
    124112    } 
    125113    return size_t(-1); 
     
    130118  std::list<StdString> CINetCDF4::getGroups(const CVarPath* const path) 
    131119  { 
    132     StdSize strlen = 0; 
    133     char full_name_in[NC_MAX_NAME +1]; 
    134120    int nbgroup = 0, *groupid = NULL; 
    135121    int grpid = this->getGroup(path); 
    136122    std::list<StdString> retvalue; 
    137123 
    138     CheckError(nc_inq_grps(grpid, &nbgroup, NULL)); 
     124    CNetCdfInterface::inqGrpIds(grpid, nbgroup, NULL); 
    139125    groupid = new int[nbgroup](); 
    140     CheckError(nc_inq_grps(grpid, NULL, groupid)); 
     126    CNetCdfInterface::inqGrpIds(grpid, nbgroup, groupid); 
    141127 
    142128    for (int i = 0; i < nbgroup; i++) 
    143129    { 
    144       CheckError(nc_inq_grpname_full(groupid[i], &strlen, full_name_in)); 
    145       StdString groupname(full_name_in, strlen); 
    146       retvalue.push_back(groupname); 
     130      StdString fullGrpName; 
     131      CNetCdfInterface::inqGrpFullName(groupid[i], fullGrpName); 
     132      retvalue.push_back(fullGrpName); 
    147133    } 
    148134 
     
    153139  std::list<StdString> CINetCDF4::getVariables(const CVarPath* const path) 
    154140  { 
    155     char full_name_in[NC_MAX_NAME +1]; 
    156141    int nbvar = 0, *varid = NULL; 
    157142    int grpid = this->getGroup(path); 
    158143    std::list<StdString> retvalue; 
    159144 
    160     CheckError(nc_inq_varids(grpid, &nbvar, NULL)); 
     145    CNetCdfInterface::inqVarIds(grpid, nbvar, NULL); 
    161146    varid = new int[nbvar](); 
    162     CheckError(nc_inq_varids(grpid, NULL, varid)); 
     147    CNetCdfInterface::inqVarIds(grpid, nbvar, varid); 
    163148 
    164149    for (int i = 0; i < nbvar; i++) 
    165150    { 
    166       CheckError(nc_inq_varname(grpid, varid[i], full_name_in)); 
    167       StdString varname(full_name_in); 
    168       retvalue.push_back(varname); 
     151      StdString varName; 
     152      CNetCdfInterface::inqVarName(grpid, varid[i], varName); 
     153      retvalue.push_back(varName); 
    169154    } 
    170155 
     
    175160  StdSize CINetCDF4::getNbOfTimestep(const CVarPath* const path) 
    176161  { 
    177     return (this->getDimensions(NULL, path)[this->getUnlimitedDimensionName(path)]); 
     162    return this->getDimensions(NULL, path)[this->getUnlimitedDimensionName(path)]; 
    178163  } 
    179164 
     
    214199  std::list<StdString> CINetCDF4::getDimensionsList(const StdString* const var, const CVarPath* const path) 
    215200  { 
    216     char full_name_in[NC_MAX_NAME +1]; 
    217201    int nbdim = 0, *dimid = NULL; 
    218202    int grpid = this->getGroup(path); 
     
    222206    if (var != NULL) 
    223207    { 
    224       CheckError(nc_inq_varndims(grpid, varid, &nbdim)); 
     208      CNetCdfInterface::inqVarNDims(grpid, varid, nbdim); 
    225209      dimid = new int[nbdim](); 
    226       CheckError(nc_inq_vardimid(grpid, varid, dimid)); 
     210      CNetCdfInterface::inqVarDimId(grpid, varid, dimid); 
    227211    } 
    228212    else 
    229213    { 
    230       CheckError(nc_inq_dimids(grpid, &nbdim, NULL, 1)); 
     214      CNetCdfInterface::inqDimIds(grpid, nbdim, NULL, 1); 
    231215      dimid = new int[nbdim](); 
    232       CheckError(nc_inq_dimids(grpid, NULL, dimid, 1)); 
     216      CNetCdfInterface::inqDimIds(grpid, nbdim, dimid, 1); 
    233217    } 
    234218 
    235219    for (int i = 0; i < nbdim; i++) 
    236220    { 
    237       CheckError(nc_inq_dimname(grpid, dimid[i], full_name_in)); 
    238       StdString dimname(full_name_in); 
     221      std::string dimname; 
     222      CNetCdfInterface::inqDimName(grpid, dimid[i], dimname); 
    239223      retvalue.push_back(dimname); 
    240224    } 
     
    246230  std::map<StdString, StdSize> CINetCDF4::getDimensions(const StdString* const var, const CVarPath* const path) 
    247231  { 
    248     StdSize size = 0; 
    249     char full_name_in[NC_MAX_NAME + 1]; 
    250232    int nbdim = 0, *dimid = NULL; 
    251233    int grpid = this->getGroup(path); 
     
    255237    if (var != NULL) 
    256238    { 
    257       CheckError(nc_inq_varndims(grpid, varid, &nbdim)); 
     239      CNetCdfInterface::inqVarNDims(grpid, varid, nbdim); 
    258240      dimid = new int[nbdim](); 
    259       CheckError(nc_inq_vardimid(grpid, varid, dimid)); 
     241      CNetCdfInterface::inqVarDimId(grpid, varid, dimid); 
    260242    } 
    261243    else 
    262244    { 
    263       CheckError(nc_inq_dimids(grpid, &nbdim, NULL, 1)); 
     245      CNetCdfInterface::inqDimIds(grpid, nbdim, NULL, 1); 
    264246      dimid = new int[nbdim](); 
    265       CheckError(nc_inq_dimids(grpid, NULL, dimid, 1)); 
     247      CNetCdfInterface::inqDimIds(grpid, nbdim, dimid, 1); 
    266248    } 
    267249 
    268250    for (int i = 0; i < nbdim; i++) 
    269251    { 
    270       CheckError(nc_inq_dimname(grpid, dimid[i], full_name_in)); 
    271       CheckError(nc_inq_dimlen (grpid, dimid[i], &size)); 
    272  
    273       StdString dimname(full_name_in); 
     252      std::string dimname; 
     253      CNetCdfInterface::inqDimName(grpid, dimid[i], dimname); 
     254      StdSize size = 0; 
     255      CNetCdfInterface::inqDimLen(grpid, dimid[i], size); 
     256 
    274257      retvalue.insert(retvalue.end(), std::make_pair(dimname, size)); 
    275258    } 
     
    279262  } 
    280263 
    281   std::list<StdString> CINetCDF4::getAttributes(const StdString* const var, const CVarPath* const path ) 
     264  std::list<StdString> CINetCDF4::getAttributes(const StdString* const var, const CVarPath* const path) 
    282265  { 
    283266    int nbatt = 0; 
    284     char full_name_in[NC_MAX_NAME +1]; 
    285267    std::list<StdString> retvalue; 
    286268    int grpid = this->getGroup(path); 
     
    288270 
    289271    if (var != NULL) 
    290       CheckError(nc_inq_varnatts(grpid, varid, &nbatt)); 
     272      CNetCdfInterface::inqVarNAtts(grpid, varid, nbatt); 
    291273    else 
    292       CheckError(nc_inq_natts(grpid, &nbatt)); 
     274      CNetCdfInterface::inqNAtts(grpid, nbatt); 
    293275 
    294276    for (int i = 0; i < nbatt; i++) 
    295277    { 
    296       CheckError(nc_inq_attname(grpid, varid, i, full_name_in)); 
    297       StdString attname(full_name_in); 
     278      StdString attname; 
     279      CNetCdfInterface::inqAttName(grpid, varid, i, attname); 
    298280      retvalue.push_back(attname); 
    299281    } 
     
    323305                                  const CVarPath* const path) 
    324306  { 
    325     return (this->hasAttribute("missing_value", &name, path) || 
    326           this->hasAttribute("_FillValue", &name, path)); 
     307    return (this->hasAttribute("missing_value", &name, path) || this->hasAttribute("_FillValue", &name, path)); 
    327308  } 
    328309 
     
    357338                                 const CVarPath* const path) 
    358339  { 
    359     return (this->hasAttribute("coordinates", &name, path)); 
     340    return this->hasAttribute("coordinates", &name, path); 
    360341  } 
    361342 
     
    363344                            const CVarPath* const path) 
    364345  { 
    365     return (this->hasAttribute("bounds", &name, path)); 
     346    return this->hasAttribute("bounds", &name, path); 
    366347  } 
    367348 
     
    373354  //--------------------------------------------------------------- 
    374355 
    375 #define GET_ATTRIBUTE_VALUE(type, func_ext, type_enum)                              \ 
    376   template <>                                                                       \ 
    377   std::vector<type> CINetCDF4::getAttributeValue(const StdString& name,             \ 
    378                                                  const StdString* const var,        \ 
    379                                                  const CVarPath* const path)        \ 
    380   {                                                                                 \ 
    381     int grpid = this->getGroup(path);                                               \ 
    382     int varid = (var != NULL) ? this->getVariable(*var, path) : NC_GLOBAL;          \ 
    383     std::pair<nc_type , StdSize> attinfos = this->getAttribute(name, var, path);    \ 
    384     std::vector<type> retvalue(attinfos.second);                                    \ 
    385     if (attinfos.first != type_enum)                                                \ 
    386       ERROR("CINetCDF4::getAttributeValue<double>(name, var, path",                 \ 
    387             << "[ name : " << name                                                  \ 
    388             << ", type requested :" << attinfos.first                               \ 
    389             << ", type stored : " << type_enum << "]"                               \ 
    390             << " Invalid type !");                                                  \ 
    391     CheckError(nc_get_att_##func_ext(grpid, varid, name.c_str(), &(retvalue[0])));  \ 
    392     return retvalue;                                                                \ 
    393   } 
    394  
    395   GET_ATTRIBUTE_VALUE(double, double, NC_DOUBLE) 
    396   GET_ATTRIBUTE_VALUE(float,  float,  NC_FLOAT) 
    397   GET_ATTRIBUTE_VALUE(int,    int ,   NC_INT) 
    398   GET_ATTRIBUTE_VALUE(char,   text,   NC_CHAR) 
    399  
    400   template <> 
     356  template <class T> 
     357  std::vector<T> CINetCDF4::getAttributeValue(const StdString& name, 
     358                                              const StdString* const var, 
     359                                              const CVarPath* const path) 
     360  { 
     361    int grpid = this->getGroup(path); 
     362    int varid = (var != NULL) ? this->getVariable(*var, path) : NC_GLOBAL; 
     363    std::pair<nc_type , StdSize> attinfos = this->getAttribute(name, var, path); 
     364    std::vector<T> retvalue(attinfos.second); 
     365    nc_type type = CNetCdfInterface::getNcType<T>(); 
     366    if (attinfos.first != type) 
     367      ERROR("CINetCDF4::getAttributeValue<T>(name, var, path)", 
     368            << "[ name : " << name 
     369            << ", type requested :" << attinfos.first 
     370            << ", type stored : " << type << "]" 
     371            << " Invalid type !"); 
     372    CNetCdfInterface::getAttType(grpid, varid, name.c_str(), &retvalue[0]); 
     373    return retvalue; 
     374  } 
     375 
     376  template std::vector<double> CINetCDF4::getAttributeValue(const StdString& name, 
     377                                                            const StdString* const var, 
     378                                                            const CVarPath* const path); 
     379  template std::vector<float> CINetCDF4::getAttributeValue(const StdString& name, 
     380                                                           const StdString* const var, 
     381                                                           const CVarPath* const path); 
     382  template std::vector<int> CINetCDF4::getAttributeValue(const StdString& name, 
     383                                                         const StdString* const var, 
     384                                                         const CVarPath* const path); 
     385  template std::vector<char> CINetCDF4::getAttributeValue(const StdString& name, 
     386                                                          const StdString* const var, 
     387                                                          const CVarPath* const path); 
     388 
    401389  StdString CINetCDF4::getAttributeValue(const StdString& name, 
    402390                                         const StdString* const var, 
    403391                                         const CVarPath* const path) 
    404392  { 
    405     std::vector<char> chart = this->getAttributeValue<std::vector<char> >(name, var, path); 
    406     StdString retvalue(&(chart[0]), chart.size()); 
    407     return retvalue; 
    408   } 
    409  
    410   template <> 
    411   int CINetCDF4::getMissingValue(const StdString& name, 
    412                                  const CVarPath* const path) 
     393    std::vector<char> data = this->getAttributeValue<char>(name, var, path); 
     394 
     395    return StdString(data.begin(), data.end()); 
     396  } 
     397 
     398  template <class T> 
     399  T CINetCDF4::getMissingValue(const StdString& name, const CVarPath* const path) 
    413400  { 
    414401    if (this->hasAttribute("missing_value", &name, path)) 
    415       return (this->getAttributeValue<std::vector<int> >("missing_value", &name, path)[0]); 
     402      return this->getAttributeValue<T>("missing_value", &name, path)[0]; 
    416403    if (this->hasAttribute("_FillValue", &name, path)) 
    417       return (this->getAttributeValue<std::vector<int> >("_FillValue", &name, path)[0]); 
     404      return this->getAttributeValue<T>("_FillValue", &name, path)[0]; 
    418405    return 0; 
    419406  } 
    420407 
    421   template <> 
    422   double CINetCDF4::getMissingValue(const StdString& name, 
    423                                     const CVarPath* const path) 
    424   { 
    425     if (this->hasAttribute("missing_value", &name, path)) 
    426       return (this->getAttributeValue<std::vector<double> >("missing_value", &name, path)[0]); 
    427     if (this->hasAttribute("_FillValue", &name, path)) 
    428       return (this->getAttributeValue<std::vector<double> >("_FillValue", &name, path)[0]); 
    429     return 0; 
    430   } 
    431  
    432   template <> 
    433   float CINetCDF4::getMissingValue(const StdString& name, 
    434                                    const CVarPath* const path) 
    435   { 
    436     if (this->hasAttribute("missing_value", &name, path)) 
    437       return (this->getAttributeValue<std::vector<float> >("missing_value", &name, path)[0]); 
    438     if (this->hasAttribute("_FillValue", &name, path)) 
    439       return (this->getAttributeValue<std::vector<float> >("_FillValue", &name, path)[0]); 
    440     return 0; 
    441   } 
     408  template double CINetCDF4::getMissingValue(const StdString& name, const CVarPath* const path); 
     409  template float CINetCDF4::getMissingValue(const StdString& name, const CVarPath* const path); 
     410  template int CINetCDF4::getMissingValue(const StdString& name, const CVarPath* const path); 
     411  template char CINetCDF4::getMissingValue(const StdString& name, const CVarPath* const path); 
    442412 
    443413  //--------------------------------------------------------------- 
     
    464434    if (this->hasAttribute("coordinates", &name, path)) 
    465435    { 
    466       return (this->getAttributeValue<StdString>("coordinates", &name, path)); 
     436      return this->getAttributeValue("coordinates", &name, path); 
    467437    } 
    468438    else 
     
    486456    StdString retvalue; 
    487457    if (this->hasAttribute("bounds", &name, path)) 
    488       return (this->getAttributeValue<StdString>("bounds", &name, path)); 
     458      retvalue = this->getAttributeValue("bounds", &name, path); 
    489459    return retvalue; 
    490460  } 
     
    583553    if (!this->hasTemporalDim(path)) return false; 
    584554    std::map<StdString, StdSize> dims = this->getDimensions(&name, path); 
    585     if (dims.find(this->getUnlimitedDimensionName(path)) != dims.end()) 
    586       return true; 
    587     return false; 
     555    return (dims.find(this->getUnlimitedDimensionName(path)) != dims.end()); 
    588556  } 
    589557 
     
    616584    if (this->isCoordinate(name, path)) 
    617585    { 
    618       return (this->hasBounds(name, path)); 
     586      return this->hasBounds(name, path); 
    619587    } 
    620588    else 
     
    712680  } 
    713681 
    714   template <> 
    715   void CINetCDF4::getData(CArray<int, 1>& data, const StdString& var, 
     682  template <class T> 
     683  void CINetCDF4::getData(CArray<T, 1>& data, const StdString& var, 
    716684                          const CVarPath* const path, StdSize record) 
    717685  { 
    718  
    719686    std::vector<StdSize> start, count; 
    720687    int grpid = this->getGroup(path); 
     
    723690    this->getDataInfo(var, path, record, start, count, array_size); 
    724691    data.resize(array_size); 
    725     CheckError(nc_get_vara_int(grpid, varid, &(start[0]), &(count[0]), data.dataFirst())); 
    726   } 
    727  
     692    CNetCdfInterface::getVaraType(grpid, varid, &start[0], &count[0], data.dataFirst()); 
     693  } 
     694 
     695  template <> 
     696  void CINetCDF4::getData(CArray<int, 1>& data, const StdString& var, 
     697                          const CVarPath* const path, StdSize record); 
    728698  template <> 
    729699  void CINetCDF4::getData(CArray<double, 1>& data, const StdString& var, 
    730                           const CVarPath* const path, StdSize record) 
    731   { 
    732     std::vector<StdSize> start, count; 
    733     int grpid = this->getGroup(path); 
    734     int varid = this->getVariable(var, path); 
    735     StdSize array_size = 1; 
    736     this->getDataInfo(var, path, record, start, count, array_size); 
    737     data.resize(array_size); 
    738     CheckError(nc_get_vara_double(grpid, varid, &(start[0]), &(count[0]), data.dataFirst())); 
    739   } 
    740  
     700                          const CVarPath* const path, StdSize record); 
    741701  template <> 
    742702  void CINetCDF4::getData(CArray<float, 1>& data, const StdString& var, 
    743                           const CVarPath* const path, StdSize record) 
    744   { 
    745     std::vector<StdSize> start, count; 
    746     int grpid = this->getGroup(path); 
    747     int varid = this->getVariable(var, path); 
    748     StdSize array_size = 1; 
    749     this->getDataInfo(var, path, record, start, count, array_size); 
    750     data.resize(array_size); 
    751     CheckError(nc_get_vara_float(grpid, varid, &(start[0]), &(count[0]), data.dataFirst())); 
    752   } 
     703                          const CVarPath* const path, StdSize record); 
    753704 
    754705  template <> 
     
    762713    if (this->mpi && collective) 
    763714      CNetCdfInterface::varParAccess(ncidp, varid, NC_COLLECTIVE); 
    764     if (this->mpi && !collective) 
     715    else if (this->mpi && !collective) 
    765716      CNetCdfInterface::varParAccess(ncidp, varid, NC_INDEPENDENT); 
    766717 
     
    777728    } 
    778729 
    779     CheckError(nc_get_vara_double(ncidp, varid, &(sstart[0]), &(scount[0]), data.dataFirst())); 
     730    CNetCdfInterface::getVaraType(ncidp, varid, &sstart[0], &scount[0], data.dataFirst()); 
    780731  } 
    781732 
     
    787738    std::list<StdString> clist = this->getCoordinatesIdList(varname, path); 
    788739    if (this->hasCoordinates(varname, path)) 
    789       return (*clist.begin()); 
     740      return *clist.begin(); 
    790741    else 
    791       return (*clist.rbegin()); 
     742      return *clist.rbegin(); 
    792743  } 
    793744 
     
    797748    std::list<StdString> clist = this->getCoordinatesIdList(varname, path); 
    798749    if (this->hasCoordinates(varname, path)) 
    799       return (*(++clist.begin())); 
     750      return *(++clist.begin()); 
    800751    else 
    801       return (*(++clist.rbegin())); 
     752      return *(++clist.rbegin()); 
    802753  } 
    803754 
     
    808759    std::list<StdString> clist = this->getCoordinatesIdList(varname, path); 
    809760    if (this->hasCoordinates(varname, path)) 
    810       return (*(++(++clist.begin()))); 
     761      return *(++(++clist.begin())); 
    811762    else 
    812       return (*(++(++clist.rbegin()))); 
     763      return *(++(++clist.rbegin())); 
    813764  } 
    814765} // namespace xios 
  • XIOS/trunk/src/io/inetcdf4.hpp

    r685 r686  
    8484 
    8585      template <class T> 
    86       T getAttributeValue(const StdString& name, 
    87                           const StdString* const var  = NULL, 
    88                           const CVarPath* const path = NULL); 
     86      std::vector<T> getAttributeValue(const StdString& name, 
     87                                       const StdString* const var  = NULL, 
     88                                       const CVarPath* const path = NULL); 
     89 
     90      StdString getAttributeValue(const StdString& name, 
     91                                  const StdString* const var, 
     92                                  const CVarPath* const path); 
    8993 
    9094      template <class T> 
     
    149153 
    150154    private: 
    151       /// Vérification des erreurs NetCDF /// 
    152       static void CheckError(int status); 
    153  
    154       int ncidp; // Identifiant de fichier netcdf. 
    155       bool mpi; //< Whether parallel file access is used 
     155      int ncidp; //< Id of the NetCDF file 
     156      bool mpi;  //< Whether parallel file access is used 
    156157  }; // class CINetCDF4 
    157  
    158   ///-------------------------------------------------------------- 
    159  
    160   template <> 
    161   StdString CINetCDF4::getAttributeValue(const StdString& name, const StdString* const var, 
    162                                          const CVarPath* const path); 
    163  
    164   template <> 
    165   std::vector<double> CINetCDF4::getAttributeValue(const StdString& name, const StdString* const var, 
    166                                                    const CVarPath* const path); 
    167  
    168   template <> 
    169   std::vector<float> CINetCDF4::getAttributeValue(const StdString& name, const StdString* const var, 
    170                                                   const CVarPath* const path); 
    171  
    172   template <> 
    173   std::vector<int> CINetCDF4::getAttributeValue(const StdString& name, const StdString* const var, 
    174                                                 const CVarPath* const path); 
    175  
    176   template <> 
    177   std::vector<char> CINetCDF4::getAttributeValue(const StdString& name, const StdString* const var, 
    178                                                  const CVarPath* const path); 
    179  
    180   //--------------------------------------------------------------- 
    181  
    182   template <> 
    183   int CINetCDF4::getMissingValue(const StdString& name, const CVarPath* const path); 
    184  
    185   template <> 
    186   double CINetCDF4::getMissingValue(const StdString& name, const CVarPath* const path); 
    187  
    188   template <> 
    189   float CINetCDF4::getMissingValue(const StdString& name, const CVarPath* const path); 
    190  
    191   //--------------------------------------------------------------- 
    192  
    193   template <> 
    194   void CINetCDF4::getData(CArray<int, 1>& data, const StdString& var, 
    195                           const CVarPath* const path, StdSize record); 
    196  
    197   template <> 
    198   void CINetCDF4::getData(CArray<double, 1>& data, const StdString& var, 
    199                           const CVarPath* const path, StdSize record); 
    200  
    201   template <> 
    202   void CINetCDF4::getData(CArray<float, 1>& data, const StdString& var, 
    203                           const CVarPath* const path, StdSize record); 
    204  
    205   template <> 
    206   void CINetCDF4::getData(CArray<double, 1>& data, const StdString& var, 
    207                           bool collective, StdSize record, 
    208                           const std::vector<StdSize>* start /*= NULL*/, 
    209                           const std::vector<StdSize>* count /*= NULL*/); 
    210158} // namespace xios 
    211159 
  • XIOS/trunk/src/io/nc4_data_output.cpp

    r685 r686  
    2424         StdString timeid = StdString("time_counter"); 
    2525         SuperClass::type = MULTI_FILE; 
    26 //         if (!exist) 
    27 //            SuperClassWriter::addDimension(timeid); 
    2826      } 
    2927 
     
    4038 
    4139         SuperClass::type = (multifile) ? MULTI_FILE : ONE_FILE; 
    42  
    43  //        if (!exist) 
    44 //            SuperClassWriter::addDimension(timeid); 
    4540      } 
    4641 
  • XIOS/trunk/src/io/netCdfInterface.cpp

    r685 r686  
    2222int CNetCdfInterface::create(const StdString& fileName, int cMode, int& ncId) 
    2323{ 
    24   int status = nc_create((fileName.c_str()), cMode, &ncId); 
    25   if (NC_NOERR != status) 
    26   { 
    27     StdString errormsg(nc_strerror(status)); 
    28     StdStringStream sstr; 
    29     sstr << "Error in calling function : nc_create((fileName.c_str()), cMode, &ncId) " << std::endl 
    30          << errormsg << std::endl 
    31          << "Unable to create file, given its name : " << fileName 
     24  int status = nc_create(fileName.c_str(), cMode, &ncId); 
     25  if (NC_NOERR != status) 
     26  { 
     27    StdString errormsg(nc_strerror(status)); 
     28    StdStringStream sstr; 
     29    sstr << "Error when calling function: nc_create(fileName.c_str(), cMode, &ncId) " << std::endl 
     30         << errormsg << std::endl 
     31         << "Unable to create file, given its name: " << fileName 
    3232         << "and its creation mode " << creationMode2String(cMode) << std::endl; 
    3333    StdString e = sstr.str(); 
     
    4949int CNetCdfInterface::createPar(const StdString& fileName, int cMode, MPI_Comm comm, MPI_Info info, int& ncId) 
    5050{ 
    51   int status = xios::nc_create_par((fileName.c_str()), cMode, comm, info, &ncId); 
    52   if (NC_NOERR != status) 
    53   { 
    54     StdString errormsg(nc_strerror(status)); 
    55     StdStringStream sstr; 
    56     sstr << "Error in calling function : nc_create_par((fileName.c_str()), cMode, comm, info, &ncId) " << std::endl 
    57          << errormsg << std::endl 
    58          << "Unable to create file on parallel filesys, given its name : " << std::endl 
     51  int status = xios::nc_create_par(fileName.c_str(), cMode, comm, info, &ncId); 
     52  if (NC_NOERR != status) 
     53  { 
     54    StdString errormsg(nc_strerror(status)); 
     55    StdStringStream sstr; 
     56    sstr << "Error when calling function: nc_create_par(fileName.c_str(), cMode, comm, info, &ncId) " << std::endl 
     57         << errormsg << std::endl 
     58         << "Unable to create file on parallel file system, given its name: " << std::endl 
    5959         << "and its creation mode " << creationMode2String(cMode) << std::endl; 
    6060    StdString e = sstr.str(); 
     
    7474int CNetCdfInterface::open(const StdString& fileName, int oMode, int& ncId) 
    7575{ 
    76   int status = nc_open((fileName.c_str()), oMode, &ncId); 
    77   if (NC_NOERR != status) 
    78   { 
    79     StdString errormsg(nc_strerror(status)); 
    80     StdStringStream sstr; 
    81     sstr << "Error in calling function : nc_open((fileName.c_str()), oMode, &ncId) "<< std::endl 
    82          << errormsg << std::endl 
    83          << "Unable to open file, given its name : " << fileName 
     76  int status = nc_open(fileName.c_str(), oMode, &ncId); 
     77  if (NC_NOERR != status) 
     78  { 
     79    StdString errormsg(nc_strerror(status)); 
     80    StdStringStream sstr; 
     81    sstr << "Error when calling function: nc_open(fileName.c_str(), oMode, &ncId) "<< std::endl 
     82         << errormsg << std::endl 
     83         << "Unable to open file, given its name: " << fileName 
    8484         << "and its open mode " << openMode2String(oMode) << std::endl; 
    8585    StdString e = sstr.str(); 
     
    102102int CNetCdfInterface::openPar(const StdString& fileName, int oMode, MPI_Comm comm, MPI_Info info, int& ncId) 
    103103{ 
    104   int status = xios::nc_open_par((fileName.c_str()), oMode, comm, info, &ncId); 
    105   if (NC_NOERR != status) 
    106   { 
    107     StdString errormsg(nc_strerror(status)); 
    108     StdStringStream sstr; 
    109     sstr << "Error in calling function " << "nc_open_par((fileName.c_str()), oMode, comm, info, &ncId) " << std::endl 
    110          << errormsg << std::endl 
    111          << "Unable to open file on parallel filesys, given its name : " << fileName 
     104  int status = xios::nc_open_par(fileName.c_str(), oMode, comm, info, &ncId); 
     105  if (NC_NOERR != status) 
     106  { 
     107    StdString errormsg(nc_strerror(status)); 
     108    StdStringStream sstr; 
     109    sstr << "Error when calling function nc_open_par(fileName.c_str(), oMode, comm, info, &ncId) " << std::endl 
     110         << errormsg << std::endl 
     111         << "Unable to open file on parallel file system, given its name: " << fileName 
    112112         << "and its open mode " << openMode2String(oMode) << std::endl; 
    113113    StdString e = sstr.str(); 
     
    130130    StdString errormsg(nc_strerror(status)); 
    131131    StdStringStream sstr; 
    132     sstr << "Error in calling function " << "nc_close(ncId)" << std::endl 
    133          << errormsg << std::endl 
    134          << "Unable to close file, given its id : " << ncId << std::endl; 
     132    sstr << "Error when calling function nc_close(ncId)" << std::endl 
     133         << errormsg << std::endl 
     134         << "Unable to close file, given its id: " << ncId << std::endl; 
    135135    StdString e = sstr.str(); 
    136136    throw CNetCdfException(e); 
     
    152152    StdString errormsg(nc_strerror(status)); 
    153153    StdStringStream sstr; 
    154     sstr << "Error in calling function " << "nc_redef(ncId)" << std::endl 
     154    sstr << "Error when calling function nc_redef(ncId)" << std::endl 
    155155      << errormsg << std::endl 
    156       << "Unable to put this file into define mode given its id : " << ncId << std::endl; 
     156      << "Unable to put this file into define mode given its id: " << ncId << std::endl; 
    157157    StdString e = sstr.str(); 
    158158    throw CNetCdfException(e); 
     
    175175    StdStringStream sstr; 
    176176 
    177     sstr << "Error in calling function " << "nc_enddef(ncId)" << std::endl 
    178          << errormsg << std::endl 
    179          << "Unable to end define mode of this file, given its id : " << ncId << std::endl; 
     177    sstr << "Error when calling function nc_enddef(ncId)" << std::endl 
     178         << errormsg << std::endl 
     179         << "Unable to end define mode of this file, given its id: " << ncId << std::endl; 
    180180    StdString e = sstr.str(); 
    181181    throw CNetCdfException(e); 
     
    194194int CNetCdfInterface::inqNcId(int ncid, const StdString& grpName, int& grpId) 
    195195{ 
    196   int status = nc_inq_ncid(ncid, (grpName.c_str()), &grpId); 
    197   if (NC_NOERR != status) 
    198   { 
    199     StdString errormsg(nc_strerror(status)); 
    200     StdStringStream sstr; 
    201  
    202     sstr << "Error in calling function " << "nc_inq_ncid(ncid, (grpName.c_str()), &grpId)" << std::endl 
    203          << errormsg << std::endl 
    204          << "Unable to get id of a group (File), given its name : " << grpName << std::endl; 
     196  int status = nc_inq_ncid(ncid, grpName.c_str(), &grpId); 
     197  if (NC_NOERR != status) 
     198  { 
     199    StdString errormsg(nc_strerror(status)); 
     200    StdStringStream sstr; 
     201 
     202    sstr << "Error when calling function nc_inq_ncid(ncid, grpName.c_str(), &grpId)" << std::endl 
     203         << errormsg << std::endl 
     204         << "Unable to get id of a group (File), given its name: " << grpName << std::endl; 
    205205    StdString e = sstr.str(); 
    206206    throw CNetCdfException(e); 
     
    218218\return Status code 
    219219*/ 
    220 int CNetCdfInterface::inqVarId(int ncid,const StdString& varName, int& varId) 
    221 { 
    222   int status = nc_inq_varid(ncid, (varName.c_str()), &varId); 
    223   if (NC_NOERR != status) 
    224   { 
    225     StdString errormsg(nc_strerror(status)); 
    226     StdStringStream sstr; 
    227  
    228     sstr << "Error in calling function : nc_inq_varid(ncid, (varName.c_str()), &varId)" << std::endl 
     220int CNetCdfInterface::inqVarId(int ncid, const StdString& varName, int& varId) 
     221{ 
     222  int status = nc_inq_varid(ncid, varName.c_str(), &varId); 
     223  if (NC_NOERR != status) 
     224  { 
     225    StdString errormsg(nc_strerror(status)); 
     226    StdStringStream sstr; 
     227 
     228    sstr << "Error when calling function: nc_inq_varid(ncid, varName.c_str(), &varId)" << std::endl 
    229229         << (errormsg) << std::endl 
    230          << "Unable to get id of variable with name : " << varName << std::endl; 
     230         << "Unable to get id of variable with name: " << varName << std::endl; 
    231231    StdString e = sstr.str(); 
    232232    throw CNetCdfException(e); 
     
    243243\return Status code 
    244244*/ 
    245 int CNetCdfInterface::inqDimId(int ncid,const StdString& dimName, int& dimId) 
    246 { 
    247   int status = nc_inq_dimid(ncid, (dimName.c_str()), &dimId); 
    248   if (NC_NOERR != status) 
    249   { 
    250     StdString errormsg(nc_strerror(status)); 
    251     StdStringStream sstr; 
    252  
    253     sstr << "Error in calling function " << "nc_inq_dimid(ncid, (dimName.c_str()), &dimId)" << std::endl 
    254          << errormsg << std::endl 
    255          << "Unable to get id of dimension, given its name : " << dimName << std::endl; 
    256     StdString e = sstr.str(); 
    257     throw CNetCdfException(e); 
    258   } 
    259  
     245int CNetCdfInterface::inqDimId(int ncid, const StdString& dimName, int& dimId) 
     246{ 
     247  int status = nc_inq_dimid(ncid, dimName.c_str(), &dimId); 
     248  if (NC_NOERR != status) 
     249  { 
     250    StdString errormsg(nc_strerror(status)); 
     251    StdStringStream sstr; 
     252 
     253    sstr << "Error when calling function nc_inq_dimid(ncid, dimName.c_str(), &dimId)" << std::endl 
     254         << errormsg << std::endl 
     255         << "Unable to get id of dimension, given its name: " << dimName << std::endl; 
     256    StdString e = sstr.str(); 
     257    throw CNetCdfException(e); 
     258  } 
     259 
     260  return status; 
     261} 
     262 
     263/*! 
     264This function queries the name of a variable given its id. 
     265\param [in] ncid Groupd id (or File Id) 
     266\param [in] varId Id of desired variable 
     267\param [out] varName name of desired variable 
     268\return Status code 
     269*/ 
     270int CNetCdfInterface::inqVarName(int ncid, int varId, StdString& varName) 
     271{ 
     272  char varNameBuff[NC_MAX_NAME + 1]; 
     273  int status = nc_inq_varname(ncid, varId, varNameBuff); 
     274  if (NC_NOERR != status) 
     275  { 
     276    StdString errormsg(nc_strerror(status)); 
     277    StdStringStream sstr; 
     278 
     279    sstr << "Error when calling function nc_inq_varname(ncid, varId, varNameBuff)" << std::endl 
     280         << errormsg << std::endl 
     281         << "Unable to get variable name given its id: " << varId << std::endl; 
     282    StdString e = sstr.str(); 
     283    throw CNetCdfException(e); 
     284  } 
     285  varName = varNameBuff; 
    260286  return status; 
    261287} 
     
    275301    StdStringStream sstr; 
    276302 
    277     sstr << "Error in calling function " << "nc_inq_dimid" << std::endl 
     303    sstr << "Error when calling function nc_inq_dimid" << std::endl 
    278304      << errormsg << std::endl 
    279305      << "Unable to get id of unlimited dimension " << std::endl; 
     
    289315\param [in] ncid Groupd id (or File Id) 
    290316\param [in] dimId Id of desired dimension 
    291 \param [in/out] dimName Name of desired dimension 
     317\param [out] dimName Name of desired dimension 
    292318\return Status code 
    293319*/ 
    294320int CNetCdfInterface::inqDimName(int ncid, int dimId, StdString& dimName) 
    295321{ 
    296   char fullNameIn[NC_MAX_NAME +1]; 
     322  char fullNameIn[NC_MAX_NAME + 1]; 
    297323  int status = nc_inq_dimname(ncid, dimId, fullNameIn); 
    298324  if (NC_NOERR != status) 
     
    301327    StdStringStream sstr; 
    302328 
    303     sstr << "Error in calling function " << "nc_inq_dimname(ncid, dimId, fullNameIn)" << std::endl 
    304          << errormsg << std::endl 
    305          << "Unable to get dimension name from its id : " << dimId << std::endl; 
     329    sstr << "Error when calling function nc_inq_dimname(ncid, dimId, fullNameIn)" << std::endl 
     330         << errormsg << std::endl 
     331         << "Unable to get dimension name given its id: " << dimId << std::endl; 
    306332    StdString e = sstr.str(); 
    307333    throw CNetCdfException(e); 
     
    326352    StdStringStream sstr; 
    327353 
    328     sstr << "Error in calling function " << "nc_inq_dimlen(ncid, dimId, &dimLen)" << std::endl 
    329          << errormsg << std::endl 
    330          << "Unable to get dimension length from its id: " << dimId << std::endl; 
     354    sstr << "Error when calling function nc_inq_dimlen(ncid, dimId, &dimLen)" << std::endl 
     355         << errormsg << std::endl 
     356         << "Unable to get dimension length given its id: " << dimId << std::endl; 
    331357    StdString e = sstr.str(); 
    332358    throw CNetCdfException(e); 
     
    351377    StdStringStream sstr; 
    352378 
    353     sstr << "Error in calling function " << "nc_inq_varndims(ncid, varId, &nDims)" << std::endl 
    354          << errormsg << std::endl 
    355          << "Unable to get the number of dimension of variable with Id : " << varId << std::endl; 
     379    sstr << "Error when calling function nc_inq_varndims(ncid, varId, &nDims)" << std::endl 
     380         << errormsg << std::endl 
     381         << "Unable to get the number of dimension of variable with Id: " << varId << std::endl; 
    356382    StdString e = sstr.str(); 
    357383    throw CNetCdfException(e); 
     
    376402    StdStringStream sstr; 
    377403 
    378     sstr << "Error in calling function " << "nc_inq_vardimid(ncid, varId, dimIds)" << std::endl 
     404    sstr << "Error when calling function nc_inq_vardimid(ncid, varId, dimIds)" << std::endl 
    379405         << errormsg << std::endl 
    380406         << "Unable to get list of dimension id of the variable with id " << varId << std::endl; 
     
    402428    StdStringStream sstr; 
    403429 
    404     sstr << "Error in calling function " << "nc_inq_dimids(ncid, &nDims, dimIds, includeParents)" << std::endl; 
    405     sstr << errormsg << std::endl; 
    406     sstr << "Unable to retrieve number of dimension in the group with id : " << ncid << std::endl; 
     430    sstr << "Error when calling function nc_inq_dimids(ncid, &nDims, dimIds, includeParents)" << std::endl; 
     431    sstr << errormsg << std::endl; 
     432    sstr << "Unable to retrieve number of dimension in the group with id: " << ncid << std::endl; 
    407433    sstr << "With number of Parents " << includeParents << std::endl; 
     434    StdString e = sstr.str(); 
     435    throw CNetCdfException(e); 
     436  } 
     437 
     438  return status; 
     439} 
     440 
     441/*! 
     442This function queries the full name of a group given its id. 
     443\param [in] ncid Groupd id (or File Id) 
     444\param [in/out] grpFullName the full name of the group 
     445\return Status code 
     446*/ 
     447int CNetCdfInterface::inqGrpFullName(int ncid, StdString& grpFullName) 
     448{ 
     449  StdSize strlen = 0; 
     450  std::vector<char> buff; 
     451  int status = nc_inq_grpname_full(ncid, &strlen, NULL); 
     452  if (NC_NOERR == status) 
     453  { 
     454    buff.resize(strlen + 1); 
     455    status = nc_inq_grpname_full(ncid, NULL, &buff[0]); 
     456  } 
     457 
     458  if (NC_NOERR != status) 
     459  { 
     460    StdString errormsg(nc_strerror(status)); 
     461    StdStringStream sstr; 
     462 
     463    sstr << "Error when calling function nc_inq_grpname_full(ncid, &strlen, &buff[0])" << std::endl 
     464         << errormsg << std::endl 
     465         << "Unable to get the full group name given its id: " << ncid << std::endl; 
     466    StdString e = sstr.str(); 
     467    throw CNetCdfException(e); 
     468  } 
     469 
     470  grpFullName.assign(buff.begin(), buff.end()); 
     471 
     472  return status; 
     473} 
     474 
     475/*! 
     476This function queries the list of group ids given a location id. 
     477\param [in] ncid Groupd id (or File Id) 
     478\param [in/out] numgrps number of groups 
     479\param [in/out] ncids list of group ids 
     480\return Status code 
     481*/ 
     482int CNetCdfInterface::inqGrpIds(int ncid, int& numgrps, int* ncids) 
     483{ 
     484  int status = nc_inq_grps(ncid, &numgrps, ncids); 
     485  if (NC_NOERR != status) 
     486  { 
     487    StdString errormsg(nc_strerror(status)); 
     488    StdStringStream sstr; 
     489 
     490    sstr << "Error when calling function nc_inq_grps(ncid, &numgrps, ncids)" << std::endl; 
     491    sstr << errormsg << std::endl; 
     492    sstr << "Unable to retrieve the list of groups for location id: " << ncid << std::endl; 
     493    StdString e = sstr.str(); 
     494    throw CNetCdfException(e); 
     495  } 
     496 
     497  return status; 
     498} 
     499 
     500/*! 
     501This function queries the list of variable ids given a location id. 
     502\param [in] ncid Groupd id (or File Id) 
     503\param [in/out] nvars number of variables 
     504\param [in/out] varids list of variable ids 
     505\return Status code 
     506*/ 
     507int CNetCdfInterface::inqVarIds(int ncid, int& nvars, int* varids) 
     508{ 
     509  int status = nc_inq_varids(ncid, &nvars, varids); 
     510  if (NC_NOERR != status) 
     511  { 
     512    StdString errormsg(nc_strerror(status)); 
     513    StdStringStream sstr; 
     514 
     515    sstr << "Error when calling function nc_inq_varids(ncid, &nvars, varids)" << std::endl; 
     516    sstr << errormsg << std::endl; 
     517    sstr << "Unable to retrieve the list of variables for location id: " << ncid << std::endl; 
     518    StdString e = sstr.str(); 
     519    throw CNetCdfException(e); 
     520  } 
     521 
     522  return status; 
     523} 
     524 
     525/*! 
     526This function queries the type and the size of an attribute given its name and the id of the variable to which it is attached. 
     527\param [in] ncid Groupd id (or File Id) 
     528\param [in] varid the id of the variable to which the attribute is attached 
     529\param [in] name the name of the attribute 
     530\param [out] type the type of the attribute 
     531\param [out] len the size of the attribute 
     532\return Status code 
     533*/ 
     534int CNetCdfInterface::inqAtt(int ncid, int varid, const StdString& name, nc_type& type, size_t& len) 
     535{ 
     536  int status = nc_inq_att(ncid, varid, name.c_str(), &type, &len); 
     537  if (NC_NOERR != status) 
     538  { 
     539    StdString errormsg(nc_strerror(status)); 
     540    StdStringStream sstr; 
     541 
     542    sstr << "Error when calling function nc_inq_att(ncid, varid, name.c_str(), &type, &len)" << std::endl; 
     543    sstr << errormsg << std::endl; 
     544    sstr << "Unable to query the attribute information given its name: " << name << " and its variable id:" << varid << std::endl; 
     545    StdString e = sstr.str(); 
     546    throw CNetCdfException(e); 
     547  } 
     548 
     549  return status; 
     550} 
     551 
     552/*! 
     553This function queries the number of global attributes given a location id. 
     554\param [in] ncid Groupd id (or File Id) 
     555\param [out] ngatts the number of global attributes 
     556\return Status code 
     557*/ 
     558int CNetCdfInterface::inqNAtts(int ncid, int& ngatts) 
     559{ 
     560  int status = nc_inq_natts(ncid, &ngatts); 
     561  if (NC_NOERR != status) 
     562  { 
     563    StdString errormsg(nc_strerror(status)); 
     564    StdStringStream sstr; 
     565 
     566    sstr << "Error when calling function nc_inq_natts(ncid, &ngatts)" << std::endl; 
     567    sstr << errormsg << std::endl; 
     568    sstr << "Unable to query the number of global attributes given the location id:" << ncid << std::endl; 
     569    StdString e = sstr.str(); 
     570    throw CNetCdfException(e); 
     571  } 
     572 
     573  return status; 
     574} 
     575 
     576/*! 
     577This function queries the number of global attributes given a location id and a variable id. 
     578\param [in] ncid Groupd id (or File Id) 
     579\param [in] varid the id of the variable 
     580\param [out] natts the number of global attributes 
     581\return Status code 
     582*/ 
     583int CNetCdfInterface::inqVarNAtts(int ncid, int varid, int& natts) 
     584{ 
     585  int status = nc_inq_varnatts(ncid, varid, &natts); 
     586  if (NC_NOERR != status) 
     587  { 
     588    StdString errormsg(nc_strerror(status)); 
     589    StdStringStream sstr; 
     590 
     591    sstr << "Error when calling function nc_inq_varnatts(ncid, varid, &natts)" << std::endl; 
     592    sstr << errormsg << std::endl; 
     593    sstr << "Unable to query the number of attributes given the location id:" << ncid << " and the variable id:" << varid << std::endl; 
     594    StdString e = sstr.str(); 
     595    throw CNetCdfException(e); 
     596  } 
     597 
     598  return status; 
     599} 
     600 
     601 
     602//! Query the name of an attribute given a location id, a variable id and the attribute number 
     603int CNetCdfInterface::inqAttName(int ncid, int varid, int attnum, StdString& name) 
     604{ 
     605  char attName[NC_MAX_NAME + 1]; 
     606  int status = nc_inq_attname(ncid, varid, attnum, attName); 
     607  if (NC_NOERR != status) 
     608  { 
     609    StdString errormsg(nc_strerror(status)); 
     610    StdStringStream sstr; 
     611 
     612    sstr << "Error when calling function nc_inq_attname(ncid, varid, attnum, attName)" << std::endl; 
     613    sstr << errormsg << std::endl; 
     614    sstr << "Unable to query the name of attribute " << attnum << " given the location id:" << ncid << " and the variable id:" << varid << std::endl; 
    408615    StdString e = sstr.str(); 
    409616    throw CNetCdfException(e); 
     
    422629int CNetCdfInterface::defGrp(int parentNcid, const StdString& grpName, int& grpId) 
    423630{ 
    424   int status = nc_def_grp(parentNcid, (grpName.c_str()), &grpId); 
    425   if (NC_NOERR != status) 
    426   { 
    427     StdString errormsg(nc_strerror(status)); 
    428     StdStringStream sstr; 
    429  
    430     sstr << "Error in calling function " << "nc_def_grp(parentNcid, (grpName.c_str()), &grpId)" << std::endl; 
    431     sstr << errormsg << std::endl; 
    432     sstr << "Unable to create group Id, given its name : " << grpName << std::endl; 
     631  int status = nc_def_grp(parentNcid, grpName.c_str(), &grpId); 
     632  if (NC_NOERR != status) 
     633  { 
     634    StdString errormsg(nc_strerror(status)); 
     635    StdStringStream sstr; 
     636 
     637    sstr << "Error when calling function nc_def_grp(parentNcid, grpName.c_str(), &grpId)" << std::endl; 
     638    sstr << errormsg << std::endl; 
     639    sstr << "Unable to create group Id, given its name: " << grpName << std::endl; 
    433640    StdString e = sstr.str(); 
    434641    throw CNetCdfException(e); 
     
    447654int CNetCdfInterface::defDim(int ncid, const StdString& dimName, StdSize dimLen, int& dimId) 
    448655{ 
    449   int status = nc_def_dim(ncid, (dimName.c_str()), dimLen, &dimId); 
    450   if (NC_NOERR != status) 
    451   { 
    452     StdString errormsg(nc_strerror(status)); 
    453     StdStringStream sstr; 
    454  
    455     sstr << "Error in calling function " << "nc_def_dim(ncid, (dimName.c_str()), dimLen, &dimId)" << std::endl; 
    456     sstr << errormsg << std::endl; 
    457     sstr << "Unable to create dimension with name : " << dimName 
     656  int status = nc_def_dim(ncid, dimName.c_str(), dimLen, &dimId); 
     657  if (NC_NOERR != status) 
     658  { 
     659    StdString errormsg(nc_strerror(status)); 
     660    StdStringStream sstr; 
     661 
     662    sstr << "Error when calling function nc_def_dim(ncid, dimName.c_str(), dimLen, &dimId)" << std::endl; 
     663    sstr << errormsg << std::endl; 
     664    sstr << "Unable to create dimension with name: " << dimName 
    458665         << " and with length " << dimLen << std::endl; 
    459666    StdString e = sstr.str(); 
     
    475682\return Status code 
    476683*/ 
    477 int CNetCdfInterface::defVar(int ncid,const StdString& varName, nc_type xtype, 
    478                             int nDims, const int dimIds[], int& varId) 
    479 { 
    480   int status = nc_def_var(ncid, (varName.c_str()), xtype, nDims, dimIds, &varId); 
    481   if (NC_NOERR != status) 
    482   { 
    483     StdString errormsg(nc_strerror(status)); 
    484     StdStringStream sstr; 
    485  
    486     sstr << "Error in calling function " << " nc_def_var(ncid, (varName.c_str()), xtype, nDims, dimIds, &varId)" << std::endl; 
    487     sstr << errormsg << std::endl; 
    488     sstr << "Unable to add a new variable with name : " << varName 
     684int CNetCdfInterface::defVar(int ncid, const StdString& varName, nc_type xtype, 
     685                             int nDims, const int dimIds[], int& varId) 
     686{ 
     687  int status = nc_def_var(ncid, varName.c_str(), xtype, nDims, dimIds, &varId); 
     688  if (NC_NOERR != status) 
     689  { 
     690    StdString errormsg(nc_strerror(status)); 
     691    StdStringStream sstr; 
     692 
     693    sstr << "Error when calling function  nc_def_var(ncid, varName.c_str(), xtype, nDims, dimIds, &varId)" << std::endl; 
     694    sstr << errormsg << std::endl; 
     695    sstr << "Unable to add a new variable with name: " << varName 
    489696         << " with type " << xtype 
    490697         << " and number of dimension " << nDims << std::endl; 
     
    501708\param [in] ncid Id groupd(or File Id) 
    502709\param [in] varId Id of the variable 
    503 \param [in] storage Type of storage (It can be : NC_CONTIGUOUS, NC_CHUNKED) 
     710\param [in] storage Type of storage (It can be: NC_CONTIGUOUS, NC_CHUNKED) 
    504711\param [in/out] chunkSize array list of chunk sizes 
    505712\return Status code 
     
    513720    StdStringStream sstr; 
    514721 
    515     sstr << "Error in calling function " << "nc_def_var_chunking(ncid, varId, storage, chunkSize)" << std::endl; 
    516     sstr << errormsg << std::endl; 
    517     sstr << "Unable to set chunk size of the variable with id : " << varId 
     722    sstr << "Error when calling function nc_def_var_chunking(ncid, varId, storage, chunkSize)" << std::endl; 
     723    sstr << errormsg << std::endl; 
     724    sstr << "Unable to set chunk size of the variable with id: " << varId 
    518725      << " and storage type " << storage << std::endl; 
    519726    StdString e = sstr.str(); 
     
    539746    StdStringStream sstr; 
    540747 
    541     sstr << "Error in calling function " << "nc_def_var_deflate(ncid, varId, false, (compressionLevel > 0), compressionLevel)" << std::endl; 
     748    sstr << "Error when calling function nc_def_var_deflate(ncid, varId, false, (compressionLevel > 0), compressionLevel)" << std::endl; 
    542749    sstr << errormsg << std::endl; 
    543750    sstr << "Unable to set the compression level of the variable with id: " << varId 
     
    559766{ 
    560767  int old_fill_mode; 
    561   int status = nc_set_fill(ncid, fill ? NC_FILL : NC_NOFILL, &old_fill_mode); 
    562   if (NC_NOERR != status) 
    563   { 
    564     StdString errormsg(nc_strerror(status)); 
    565     StdStringStream sstr; 
    566  
    567     sstr << "Error when calling function nc_set_fill(ncid, fill ? NC_FILL : NC_NOFILL, &old_fill_mode)" << std::endl; 
    568     sstr << errormsg << std::endl; 
    569     sstr << "Unable to set the fill mode to : " << (fill ? "NC_FILL" : "NC_NOFILL") << std::endl; 
     768  int status = nc_set_fill(ncid, fill ? NC_FILL: NC_NOFILL, &old_fill_mode); 
     769  if (NC_NOERR != status) 
     770  { 
     771    StdString errormsg(nc_strerror(status)); 
     772    StdStringStream sstr; 
     773 
     774    sstr << "Error when calling function nc_set_fill(ncid, fill ? NC_FILL: NC_NOFILL, &old_fill_mode)" << std::endl; 
     775    sstr << errormsg << std::endl; 
     776    sstr << "Unable to set the fill mode to: " << (fill ? "NC_FILL": "NC_NOFILL") << std::endl; 
    570777    StdString e = sstr.str(); 
    571778    throw CNetCdfException(e); 
     
    592799    StdStringStream sstr; 
    593800 
    594     sstr << "Error in calling function " << "nc_def_var_fill(ncid, varId, noFill, fillValue)" << std::endl; 
    595     sstr << errormsg << std::endl; 
    596     sstr << "Unable to set fill parameters of the variable with id : " << varId 
     801    sstr << "Error when calling function nc_def_var_fill(ncid, varId, noFill, fillValue)" << std::endl; 
     802    sstr << errormsg << std::endl; 
     803    sstr << "Unable to set fill parameters of the variable with id: " << varId 
    597804      << " and fill option " << noFill << std::endl; 
    598805    StdString e = sstr.str(); 
     
    620827    StdStringStream sstr; 
    621828 
    622     sstr << "Error in calling function " << "nc_var_par_access(ncid, varId, access)" << std::endl; 
    623     sstr << errormsg << std::endl; 
    624     sstr << "Unable to change read/write option of the variable with id : " << varId << std::endl; 
     829    sstr << "Error when calling function nc_var_par_access(ncid, varId, access)" << std::endl; 
     830    sstr << errormsg << std::endl; 
     831    sstr << "Unable to change read/write option of the variable with id: " << varId << std::endl; 
    625832    StdString e = sstr.str(); 
    626833    throw CNetCdfException(e); 
     
    643850    StdStringStream sstr; 
    644851 
    645     sstr << "Error in calling function " << "nc_sync(ncid)" << std::endl; 
    646     sstr << errormsg << std::endl; 
    647     sstr << "Unable to make a synchronization of a netCDF file with id : " << ncid << std::endl; 
    648     StdString e = sstr.str(); 
    649     throw CNetCdfException(e); 
    650   } 
    651  
    652   return status; 
    653 } 
    654  
    655 /*! 
    656 This function makes a request to netcdf with its id, to add or change a variable attribute or gloabl attribute, 
    657 given its name, type, number of values provided for attribute 
    658 \param [in] ncid Id of groupd(or File Id) 
    659 \param [in] varId Id of the variable 
    660 \param [in] attrName Name of the attribute 
    661 \param [in] xtypes One of the set of predefined netCDF data types 
    662 \param [in] numVal Number of values 
    663 \param [in] op Array of values provided for attribute 
    664 \return Status code 
    665 */ 
    666 int CNetCdfInterface::putAtt(int ncid, int varId, const StdString& attrName, nc_type xtype, 
    667                             StdSize numVal, const void* op) 
    668 { 
    669   int status = nc_put_att(ncid, varId, (attrName.c_str()), xtype, numVal, op); 
    670   if (NC_NOERR != status) 
    671   { 
    672     StdString errormsg(nc_strerror(status)); 
    673     StdStringStream sstr; 
    674  
    675     sstr << "Error in calling function " << "nc_put_att(ncid, varId, (attrName.c_str()), xtype, numVal, op)" << std::endl; 
    676     sstr << errormsg << std::endl; 
    677     sstr << "Unable to set attribute " << attrName << " for a variable with id : " << varId 
    678          << " with number of attribute  " << numVal 
    679          << " with type " << xtype << std::endl; 
    680     StdString e = sstr.str(); 
    681     throw CNetCdfException(e); 
    682   } 
    683  
    684   return status; 
    685 } 
    686  
    687  // Some specilization of putAttributeType 
     852    sstr << "Error when calling function nc_sync(ncid)" << std::endl; 
     853    sstr << errormsg << std::endl; 
     854    sstr << "Unable to make a synchronization of a netCDF file with id: " << ncid << std::endl; 
     855    StdString e = sstr.str(); 
     856    throw CNetCdfException(e); 
     857  } 
     858 
     859  return status; 
     860} 
     861 
     862// Some specializations of getAttributeType 
     863template<> 
     864int CNetCdfInterface::ncGetAttType(int ncid, int varid, const char* attrName, double* data) 
     865{ 
     866  return nc_get_att_double(ncid, varid, attrName, data); 
     867} 
     868 
     869template<> 
     870int CNetCdfInterface::ncGetAttType(int ncid, int varid, const char* attrName, float* data) 
     871{ 
     872  return nc_get_att_float(ncid, varid, attrName, data); 
     873} 
     874 
     875template<> 
     876int CNetCdfInterface::ncGetAttType(int ncid, int varid, const char* attrName, int* data) 
     877{ 
     878  return nc_get_att_int(ncid, varid, attrName, data); 
     879} 
     880 
     881template<> 
     882int CNetCdfInterface::ncGetAttType(int ncid, int varid, const char* attrName, long* data) 
     883{ 
     884  return nc_get_att_long(ncid, varid, attrName, data); 
     885} 
     886 
     887template<> 
     888int CNetCdfInterface::ncGetAttType(int ncid, int varid, const char* attrName, short* data) 
     889{ 
     890  return nc_get_att_short(ncid, varid, attrName, data); 
     891} 
     892 
     893template<> 
     894int CNetCdfInterface::ncGetAttType(int ncid, int varid, const char* attrName, char* data) 
     895{ 
     896  return nc_get_att_text(ncid, varid, attrName, data); 
     897} 
     898 
     899// Some specializations of putAttributeType 
    688900template<> 
    689901int CNetCdfInterface::ncPutAttType(int ncid, int varid, const char* attrName, 
    690                                  StdSize numVal, const double* op) 
    691 { 
    692   return (nc_put_att_double(ncid, varid, attrName, NC_DOUBLE, numVal, op)); 
     902                                   StdSize numVal, const double* data) 
     903{ 
     904  return nc_put_att_double(ncid, varid, attrName, NC_DOUBLE, numVal, data); 
    693905} 
    694906 
    695907template<> 
    696908int CNetCdfInterface::ncPutAttType(int ncid, int varid, const char* attrName, 
    697                                    StdSize numVal, const float* op) 
    698 { 
    699   return (nc_put_att_float(ncid, varid, attrName, NC_FLOAT, numVal, op)); 
     909                                   StdSize numVal, const float* data) 
     910{ 
     911  return nc_put_att_float(ncid, varid, attrName, NC_FLOAT, numVal, data); 
    700912} 
    701913 
    702914template<> 
    703915int CNetCdfInterface::ncPutAttType(int ncid, int varid, const char* attrName, 
    704                                    StdSize numVal, const int* op) 
    705 { 
    706   return (nc_put_att_int(ncid, varid, attrName, NC_INT, numVal, op)); 
     916                                   StdSize numVal, const int* data) 
     917{ 
     918  return nc_put_att_int(ncid, varid, attrName, NC_INT, numVal, data); 
    707919} 
    708920 
    709921template<> 
    710922int CNetCdfInterface::ncPutAttType(int ncid, int varid, const char* attrName, 
    711                                    StdSize numVal, const long* op) 
    712 { 
    713   return (nc_put_att_long(ncid, varid, attrName, NC_LONG, numVal, op)); 
     923                                   StdSize numVal, const long* data) 
     924{ 
     925  return nc_put_att_long(ncid, varid, attrName, NC_LONG, numVal, data); 
    714926} 
    715927 
    716928template<> 
    717929int CNetCdfInterface::ncPutAttType(int ncid, int varid, const char* attrName, 
    718                                    StdSize numVal, const short* op) 
    719 { 
    720   return (nc_put_att_short(ncid, varid, attrName, NC_SHORT, numVal, op)); 
    721 } 
    722  
    723  
    724 // Some specilization of putVariableType 
    725 template<> 
    726 int CNetCdfInterface::ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const double* op) 
    727 { 
    728   return (nc_put_vara_double(ncid, varid, start, count, op)); 
    729 } 
    730  
    731 template<> 
    732 int CNetCdfInterface::ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const float* op) 
    733 { 
    734   return (nc_put_vara_float(ncid, varid, start, count, op)); 
    735 } 
    736  
    737 template<> 
    738 int CNetCdfInterface::ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const int* op) 
    739 { 
    740   return (nc_put_vara_int(ncid, varid, start, count, op)); 
     930                                   StdSize numVal, const short* data) 
     931{ 
     932  return nc_put_att_short(ncid, varid, attrName, NC_SHORT, numVal, data); 
     933} 
     934 
     935template<> 
     936int CNetCdfInterface::ncPutAttType(int ncid, int varid, const char* attrName, 
     937                                   StdSize numVal, const char* data) 
     938{ 
     939  return nc_put_att_text(ncid, varid, attrName, numVal, data); 
     940} 
     941 
     942// Some specializations of getVariableType 
     943template<> 
     944int CNetCdfInterface::ncGetVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, double* data) 
     945{ 
     946  return nc_get_vara_double(ncid, varid, start, count, data); 
     947} 
     948 
     949template<> 
     950int CNetCdfInterface::ncGetVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, float* data) 
     951{ 
     952  return nc_get_vara_float(ncid, varid, start, count, data); 
     953} 
     954 
     955template<> 
     956int CNetCdfInterface::ncGetVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, int* data) 
     957{ 
     958  return nc_get_vara_int(ncid, varid, start, count, data); 
     959} 
     960 
     961// Some specializations of putVariableType 
     962template<> 
     963int CNetCdfInterface::ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const double* data) 
     964{ 
     965  return nc_put_vara_double(ncid, varid, start, count, data); 
     966} 
     967 
     968template<> 
     969int CNetCdfInterface::ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const float* data) 
     970{ 
     971  return nc_put_vara_float(ncid, varid, start, count, data); 
     972} 
     973 
     974template<> 
     975int CNetCdfInterface::ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const int* data) 
     976{ 
     977  return nc_put_vara_int(ncid, varid, start, count, data); 
    741978} 
    742979 
     
    760997  { 
    761998  case NC_NOWRITE: 
    762     modeMes = StdString("NC_NOWRITE : Opening netCDF file with read-only access with buffering and caching access"); 
     999    modeMes = StdString("NC_NOWRITE: Opening netCDF file with read-only access with buffering and caching access"); 
    7631000    break; 
    7641001  case NC_SHARE: 
    765     modeMes = StdString("NC_SHARE : Several processes can read the file concurrently"); 
     1002    modeMes = StdString("NC_SHARE: Several processes can read the file concurrently"); 
    7661003    break; 
    7671004  case NC_WRITE: 
    768     modeMes = StdString("NC_WRITE : NetCDF file is readable and writable"); 
     1005    modeMes = StdString("NC_WRITE: NetCDF file is readable and writable"); 
    7691006    break; 
    7701007  default: 
     
    7811018  { 
    7821019  case NC_NOCLOBBER: 
    783     modeMes = StdString("NC_NOCLOBBER : Not overwrite an exisiting netCDF file "); 
     1020    modeMes = StdString("NC_NOCLOBBER: Not overwrite an exisiting netCDF file "); 
    7841021    break; 
    7851022  case NC_SHARE: 
    786     modeMes = StdString("NC_SHARE : Several processes can read from and write into the file concurrently"); 
     1023    modeMes = StdString("NC_SHARE: Several processes can read from and write into the file concurrently"); 
    7871024    break; 
    7881025  case NC_64BIT_OFFSET: 
    789     modeMes = StdString("NC_64BIT_OFFSET : NetCDF file is 64-bit offset"); 
     1026    modeMes = StdString("NC_64BIT_OFFSET: NetCDF file is 64-bit offset"); 
    7901027    break; 
    7911028  case NC_NETCDF4: 
    792     modeMes = StdString("NC_NETCDF4 : NetCDF file is HDF5/NetCDF-4"); 
     1029    modeMes = StdString("NC_NETCDF4: NetCDF file is HDF5/NetCDF-4"); 
    7931030    break; 
    7941031  case NC_CLASSIC_MODEL: 
    795     modeMes = StdString("NC_CLASSIC_MODEL : NetCDF file is classical model"); 
     1032    modeMes = StdString("NC_CLASSIC_MODEL: NetCDF file is classical model"); 
    7961033    break; 
    7971034  default: 
  • XIOS/trunk/src/io/netCdfInterface.hpp

    r685 r686  
    5555    static int inqVarId(int ncid, const StdString& varName, int& varId); 
    5656 
     57    //! Query the name of a variable given its id 
     58    static int inqVarName(int ncid, int varId, StdString& varName); 
     59 
    5760    //! Query identity of a named dimension 
    58     static int inqDimId(int ncid,const StdString& dimName, int& dimId); 
     61    static int inqDimId(int ncid, const StdString& dimName, int& dimId); 
    5962 
    6063    //! Query identity of unlimited dimension 
     
    7679    static int inqDimIds(int ncid, int& nDims, int* dimIds, int includeParents); 
    7780 
     81    //! Query the full name of a group given its id 
     82    static int inqGrpFullName(int ncid, StdString& grpFullName); 
     83 
     84    //! Query the list of group ids given a location id 
     85    static int inqGrpIds(int ncid, int& numgrps, int* ncids); 
     86 
     87    //! Query the list of variable ids given a location id 
     88    static int inqVarIds(int ncid, int& nvars, int* varids); 
     89 
     90    //! Query the type and the size of an attribute given its name and the id of the variable to which it is attached. 
     91    static int inqAtt(int ncid, int varid, const StdString& name, nc_type& type, size_t& len); 
     92 
     93    //! Query the number of global attributes given a location id 
     94    static int inqNAtts(int ncid, int& ngatts); 
     95 
     96    //! Query the number of attributes given a location id and a variable id 
     97    static int inqVarNAtts(int ncid, int varid, int& natts); 
     98 
     99    //! Query the name of an attribute given a location id, a variable id and the attribute number 
     100    static int inqAttName(int ncid, int varid, int attnum, StdString& name); 
    78101 
    79102    //! Define a group 
    80     static int defGrp(int parentNcid,const StdString& grpName, int& grpId); 
     103    static int defGrp(int parentNcid, const StdString& grpName, int& grpId); 
    81104 
    82105    //! Define a dimension 
    83     static int defDim(int ncid,const StdString& dimName, StdSize dimLen, int& dimId); 
     106    static int defDim(int ncid, const StdString& dimName, StdSize dimLen, int& dimId); 
    84107 
    85108    //! Define a variable 
    86     static int defVar(int ncid,const StdString& varName, nc_type xtype, 
     109    static int defVar(int ncid, const StdString& varName, nc_type xtype, 
    87110                      int nDims, const int dimIds[], int& varId); 
    88111 
     
    103126    static int varParAccess(int ncid, int varid, int access); 
    104127 
    105     //! Syn 
     128    //! Sync the file 
    106129    static int sync(int ncId); 
    107130 
    108     //! Put attribute into variable 
    109     static int putAtt(int ncid, int varid, const StdString& attrName, nc_type xtype, 
    110                       StdSize numVal, const void* op); 
     131    //! Read an attribute 
     132    template<typename T> 
     133    static int getAttType(int ncid, int varid, const StdString& attrName, T* data); 
    111134 
     135    //! Set an attribute 
     136    template<typename T> 
     137    static int putAttType(int ncid, int varid, const StdString& attrName, StdSize numVal, const T* data); 
    112138 
    113     //! Put attribute into variable with specific type 
     139    //! Get data for a variable 
    114140    template<typename T> 
    115     static int putAttType(int ncid, int varid, const StdString& attrName, StdSize numVal, const T* op); 
     141    static int getVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, T* data); 
    116142 
    117     //! Put value into a variable with a specific type 
     143    //! Set data for a variable 
    118144    template<typename T> 
    119     static int putVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const T* op); 
     145    static int putVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const T* data); 
     146 
     147    //! Get the NetCDF type corresponding to a specific C type 
     148    template<typename T> 
     149    static nc_type getNcType(); 
    120150 
    121151  private: 
    122152    template<typename T> 
    123     static int ncPutAttType(int ncid, int varid, const char* attrName, StdSize numVal, const T* op); 
     153    static int ncGetAttType(int ncid, int varid, const char* attrName, T* data); 
    124154 
    125155    template<typename T> 
    126     static int ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const T* op); 
     156    static int ncPutAttType(int ncid, int varid, const char* attrName, StdSize numVal, const T* data); 
     157 
     158    template<typename T> 
     159    static int ncGetVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, T* data); 
     160 
     161    template<typename T> 
     162    static int ncPutVaraType(int ncid, int varid, const StdSize* start, const StdSize* count, const T* data); 
    127163 
    128164  private: 
  • XIOS/trunk/src/io/netCdfInterface_decl.cpp

    r685 r686  
    1212namespace xios 
    1313{ 
    14 #define  macroPutAtt(type) \ 
    15   template int CNetCdfInterface::putAttType(int ncid, int varid, const StdString& attrName, \ 
    16                                             StdSize numVal, const type* op); 
     14#define macroAtt(type) \ 
     15  template int CNetCdfInterface::getAttType(int ncid, int varid, const StdString& attrName, type* data); \ 
     16  template int CNetCdfInterface::putAttType(int ncid, int varid, const StdString& attrName,              \ 
     17                                            StdSize numVal, const type* data); 
    1718 
    18   macroPutAtt(double); 
    19   macroPutAtt(float); 
    20   macroPutAtt(int); 
    21   macroPutAtt(long); 
    22   macroPutAtt(short); 
     19  macroAtt(double) 
     20  macroAtt(float) 
     21  macroAtt(int) 
     22  macroAtt(long) 
     23  macroAtt(short) 
     24  macroAtt(char) 
    2325 
    24 #define  macroPutVar(type) \ 
     26#define macroPutVar(type) \ 
     27 template int CNetCdfInterface::getVaraType(int ncid, int varId, const StdSize* start, \ 
     28                                            const StdSize* count, type* data);         \ 
    2529 template int CNetCdfInterface::putVaraType(int ncid, int varId, const StdSize* start, \ 
    26                                             const StdSize* count, const type* op); 
    27   macroPutVar(double); 
    28   macroPutVar(float); 
    29   macroPutVar(int); 
     30                                            const StdSize* count, const type* data); 
     31 
     32  macroPutVar(double) 
     33  macroPutVar(float) 
     34  macroPutVar(int) 
     35 
     36#define macroType(type, ncType) \ 
     37  template<> nc_type CNetCdfInterface::getNcType<type>() { return ncType; } 
     38 
     39  macroType(double, NC_DOUBLE) 
     40  macroType(float, NC_FLOAT) 
     41  macroType(int, NC_INT) 
     42  macroType(long, NC_LONG) 
     43  macroType(short, NC_SHORT) 
     44  macroType(char, NC_CHAR) 
    3045} 
  • XIOS/trunk/src/io/netCdfInterface_impl.hpp

    r685 r686  
    55   \since 06 Oct 2014 
    66 
    7    \brief Implemention of some templated functions in netCdfInterface 
     7   \brief Implementation of some templated functions in netCdfInterface 
    88 */ 
    99 
     
    1616namespace xios 
    1717{ 
    18    /*! 
    19    This function makes a request to netcdf with its id, to add or change a variable attribute or gloabl attribute, 
    20    given its name, type, number of values provided for attribute 
    21    \param [in] ncid Id of groupd(or File Id) 
    22    \param [in] varId Id of the variable 
    23    \param [in] attrName Name of the attribute 
    24    \param [in] numVal Number of values 
    25    \param [in] op Array of values provided for attribute 
    26    \return Error code 
    27    */ 
     18  /*! 
     19  This function reads a variable attribute or a global attribute 
     20  given a location id, a variable id and the attribute name 
     21  \param [in] ncid Id of group (or file id) 
     22  \param [in] varId Id of the variable 
     23  \param [in] attrName Name of the attribute 
     24  \param [out] data Array of values 
     25  \return Status code 
     26  */ 
     27  template<typename T> 
     28  int CNetCdfInterface::getAttType(int ncid, int varId, const StdString& attrName, T* data) 
     29  { 
     30    int status = ncGetAttType(ncid, varId, attrName.c_str(), data); 
     31    if (NC_NOERR != status) 
     32    { 
     33      StdStringStream sstr; 
     34      sstr << "Error when calling function ncGetAttType(ncid, varId, attrName.c_str(), data)" << std::endl; 
     35      sstr << nc_strerror(status) << std::endl; 
     36      sstr << "Unable to read attribute " << attrName << " given the location id: " << ncid << " and the variable id: " << varId << std::endl; 
     37      throw CNetCdfException(sstr.str()); 
     38    } 
     39 
     40    return status; 
     41  } 
     42 
     43  /*! 
     44  This function adds or modifies a variable attribute or a global attribute 
     45  given a location id, a variable id and the attribute name 
     46  \param [in] ncid Id of group (or file id) 
     47  \param [in] varId Id of the variable 
     48  \param [in] attrName Name of the attribute 
     49  \param [in] numVal Number of values to set 
     50  \param [in] data Array of values 
     51  \return Status code 
     52  */ 
    2853  template<typename T> 
    2954  int CNetCdfInterface::putAttType(int ncid, int varId, const StdString& attrName, 
    30                                    StdSize numVal, const T* op) 
     55                                   StdSize numVal, const T* data) 
    3156  { 
    32     int status = ncPutAttType(ncid, varId, attrName.c_str(), numVal, op); 
     57    int status = ncPutAttType(ncid, varId, attrName.c_str(), numVal, data); 
    3358    if (NC_NOERR != status) 
    34      { 
    35        StdString errormsg(nc_strerror(status)); 
    36        StdStringStream sstr; 
    37        sstr << "Error in calling function " << "ncPutAttType(ncid, varId, attrName.c_str(), numVal, op)" << std::endl; 
    38        sstr << errormsg << std::endl; 
    39        sstr << "Unable to set attribute " << attrName << " for a variable with id : " << varId 
    40          << " with number of attribute  " << numVal << std::endl; 
    41        StdString e = sstr.str(); 
    42        throw CNetCdfException(e); 
    43      } 
     59    { 
     60      StdStringStream sstr; 
     61      sstr << "Error when calling function ncPutAttType(ncid, varId, attrName.c_str(), numVal, data)" << std::endl; 
     62      sstr << nc_strerror(status) << std::endl; 
     63      sstr << "Unable to set attribute " << attrName << " given the location id: " << ncid << " and the variable id: " << varId 
     64           << " with " << numVal << " elements." << std::endl; 
     65      throw CNetCdfException(sstr.str()); 
     66    } 
    4467 
    45      return status; 
     68    return status; 
    4669  } 
    4770 
    48    /*! 
    49    This function makes a request to netcdf with its id, to write variable values into netcdf file, 
    50    \param [in] ncid Id of groupd(or File Id) 
    51    \param [in] varId Id of the variable 
    52    \param [in] start Array specifying the index in the variable where the first data value will be written 
    53    \param [in] count Array specifying the edge lengths along each dimension of block data 
    54    \param [in] op Array of values provided for attribute 
    55    \return Error code 
    56    */ 
     71  /*! 
     72  This function reads data for the specified variable. 
     73  \param [in] ncid Id of group (or file id) 
     74  \param [in] varId Id of the variable 
     75  \param [in] start Array specifying the index in the variable where the first data value will be written 
     76  \param [in] count Array specifying the edge lengths along each dimension of the data block 
     77  \param [out] data Array of values 
     78  \return Status code 
     79  */ 
    5780  template<typename T> 
    58   int CNetCdfInterface::putVaraType(int ncid, int varId, const StdSize* start, const StdSize* count, const T* op) 
     81  int CNetCdfInterface::getVaraType(int ncid, int varId, const StdSize* start, const StdSize* count, T* data) 
    5982  { 
    60     int status = ncPutVaraType(ncid, varId, start, count, op); 
     83    int status = ncGetVaraType(ncid, varId, start, count, data); 
    6184    if (NC_NOERR != status) 
    62      { 
    63        StdString errormsg(nc_strerror(status)); 
    64        StdStringStream sstr; 
    65        sstr << "Error in calling function " << "ncPutVaraType(ncid, varId, start, count, op)" << std::endl; 
    66        sstr << errormsg << std::endl; 
    67        sstr << "Unable to write value of a variable with id : " << varId << std::endl; 
    68        StdString e = sstr.str(); 
    69        throw CNetCdfException(e); 
    70      } 
     85    { 
     86      StdStringStream sstr; 
     87      sstr << "Error when calling function ncGetVaraType(ncid, varId, start, count, data)" << std::endl; 
     88      sstr << nc_strerror(status) << std::endl; 
     89      sstr << "Unable to read data given the location id: " << ncid << " and the variable id: " << varId << std::endl; 
     90      throw CNetCdfException(sstr.str()); 
     91    } 
    7192 
    72      return status; 
     93    return status; 
    7394  } 
    7495 
     96  /*! 
     97  This function writes the given data for the specified variable. 
     98  \param [in] ncid Id of group (or file id) 
     99  \param [in] varId Id of the variable 
     100  \param [in] start Array specifying the index in the variable where the first data value will be written 
     101  \param [in] count Array specifying the edge lengths along each dimension of the data block 
     102  \param [in] data Array of values 
     103  \return Status code 
     104  */ 
     105  template<typename T> 
     106  int CNetCdfInterface::putVaraType(int ncid, int varId, const StdSize* start, const StdSize* count, const T* data) 
     107  { 
     108    int status = ncPutVaraType(ncid, varId, start, count, data); 
     109    if (NC_NOERR != status) 
     110    { 
     111      StdStringStream sstr; 
     112      sstr << "Error when calling function ncPutVaraType(ncid, varId, start, count, data)" << std::endl; 
     113      sstr << nc_strerror(status) << std::endl; 
     114      sstr << "Unable to write data given the location id: " << ncid << " and the variable id: " << varId << std::endl; 
     115      throw CNetCdfException(sstr.str()); 
     116    } 
     117 
     118    return status; 
     119  } 
    75120} 
    76121 
  • XIOS/trunk/src/io/onetcdf4.cpp

    r685 r686  
    1212      /// ////////////////////// Définitions ////////////////////// /// 
    1313 
    14       CONetCDF4::CONetCDF4 
    15          (const StdString & filename, bool append, bool useClassicFormat, const MPI_Comm* comm, bool multifile) 
    16             : path() 
    17             , wmpi(false) 
    18             , useClassicFormat(useClassicFormat) 
    19             , recordOffset(0) 
     14      CONetCDF4::CONetCDF4(const StdString& filename, bool append, bool useClassicFormat, 
     15                           const MPI_Comm* comm, bool multifile) 
     16        : path() 
     17        , wmpi(false) 
     18        , useClassicFormat(useClassicFormat) 
     19        , recordOffset(0) 
    2020      { 
    2121         this->initialize(filename, append, useClassicFormat, comm,multifile); 
     
    2727      CONetCDF4::~CONetCDF4(void) 
    2828      { 
    29 //         CheckError(nc_close(this->ncidp)); 
    3029      } 
    3130 
    3231      ///-------------------------------------------------------------- 
    3332 
    34       void CONetCDF4::initialize 
    35          (const StdString & filename, bool append, bool useClassicFormat, const MPI_Comm* comm, bool multifile) 
     33      void CONetCDF4::initialize(const StdString& filename, bool append, bool useClassicFormat, 
     34                                 const MPI_Comm* comm, bool multifile) 
    3635      { 
    3736         this->useClassicFormat = useClassicFormat; 
     
    8988      void CONetCDF4::close() 
    9089      { 
    91         (CNetCdfInterface::close(this->ncidp)); 
     90        CNetCdfInterface::close(this->ncidp); 
    9291      } 
    9392 
     
    9695      void CONetCDF4::definition_start(void) 
    9796      { 
    98          (CNetCdfInterface::reDef(this->ncidp)); 
     97         CNetCdfInterface::reDef(this->ncidp); 
    9998      } 
    10099 
     
    103102      void CONetCDF4::definition_end(void) 
    104103      { 
    105          (CNetCdfInterface::endDef(this->ncidp)); 
    106       } 
    107  
    108       //--------------------------------------------------------------- 
    109  
    110 // Don't need it anymore? 
    111 //      void CONetCDF4::CheckError(int status) 
    112 //      { 
    113 //         if (status != NC_NOERR) 
    114 //         { 
    115 //            StdString errormsg (nc_strerror(status)); // fuite mémoire ici ? 
    116 //            ERROR("CONetCDF4::CheckError(int status)", 
    117 //                  << "[ status = " << status << " ] " << errormsg); 
    118 //         } 
    119 //      } 
     104         CNetCdfInterface::endDef(this->ncidp); 
     105      } 
    120106 
    121107      //--------------------------------------------------------------- 
     
    123109      int CONetCDF4::getCurrentGroup(void) 
    124110      { 
    125          return (this->getGroup(this->getCurrentPath())); 
    126       } 
    127  
    128       //--------------------------------------------------------------- 
    129  
    130       int CONetCDF4::getGroup(const CONetCDF4Path & path) 
     111         return this->getGroup(this->getCurrentPath()); 
     112      } 
     113 
     114      //--------------------------------------------------------------- 
     115 
     116      int CONetCDF4::getGroup(const CONetCDF4Path& path) 
    131117      { 
    132118         int retvalue = this->ncidp; 
    133119 
    134          CONetCDF4Path::const_iterator 
    135             it  = path.begin(), end = path.end(); 
    136  
    137          for (;it != end; it++) 
    138          { 
    139             const StdString & groupid = *it; 
    140             (CNetCdfInterface::inqNcId(retvalue, groupid, retvalue)); 
    141          } 
    142          return (retvalue); 
    143       } 
    144  
    145       //--------------------------------------------------------------- 
    146  
    147       int CONetCDF4::getVariable(const StdString & varname) 
     120         CONetCDF4Path::const_iterator it = path.begin(), end = path.end(); 
     121 
     122         for (; it != end; it++) 
     123         { 
     124            const StdString& groupid = *it; 
     125            CNetCdfInterface::inqNcId(retvalue, groupid, retvalue); 
     126         } 
     127         return retvalue; 
     128      } 
     129 
     130      //--------------------------------------------------------------- 
     131 
     132      int CONetCDF4::getVariable(const StdString& varname) 
    148133      { 
    149134         int varid = 0; 
    150135         int grpid = this->getCurrentGroup(); 
    151          (CNetCdfInterface::inqVarId(grpid, varname, varid)); 
    152          return (varid); 
    153       } 
    154  
    155       //--------------------------------------------------------------- 
    156  
    157       int CONetCDF4::getDimension(const StdString & dimname) 
     136         CNetCdfInterface::inqVarId(grpid, varname, varid); 
     137         return varid; 
     138      } 
     139 
     140      //--------------------------------------------------------------- 
     141 
     142      int CONetCDF4::getDimension(const StdString& dimname) 
    158143      { 
    159144         int dimid = 0; 
    160145         int grpid = this->getCurrentGroup(); 
    161          (CNetCdfInterface::inqDimId(grpid, dimname, dimid)); 
    162          return (dimid); 
     146         CNetCdfInterface::inqDimId(grpid, dimname, dimid); 
     147         return dimid; 
    163148      } 
    164149 
     
    169154         int dimid = 0; 
    170155         int grpid = this->getCurrentGroup(); 
    171          (CNetCdfInterface::inqUnLimDim(grpid, dimid)); 
    172          return (dimid); 
     156         CNetCdfInterface::inqUnLimDim(grpid, dimid); 
     157         return dimid; 
    173158      } 
    174159 
     
    178163         int dimid = this->getUnlimitedDimension(); 
    179164 
    180          if (dimid == -1) return (std::string()); 
    181165         StdString dimname; 
    182          (CNetCdfInterface::inqDimName(grpid, dimid, dimname)); 
    183  
    184          return (dimname); 
    185       } 
    186  
    187       //--------------------------------------------------------------- 
    188  
    189       std::vector<StdSize> CONetCDF4::getDimensions(const StdString & varname) 
     166         if (dimid != -1) 
     167           CNetCdfInterface::inqDimName(grpid, dimid, dimname); 
     168         return dimname; 
     169      } 
     170 
     171      //--------------------------------------------------------------- 
     172 
     173      std::vector<StdSize> CONetCDF4::getDimensions(const StdString& varname) 
    190174      { 
    191175         StdSize size = 0; 
     
    195179         int nbdim = 0, *dimid = NULL; 
    196180 
    197          (CNetCdfInterface::inqVarNDims(grpid, varid, nbdim)); 
     181         CNetCdfInterface::inqVarNDims(grpid, varid, nbdim); 
    198182         dimid = new int[nbdim](); 
    199          (CNetCdfInterface::inqVarDimId(grpid, varid, dimid)); 
     183         CNetCdfInterface::inqVarDimId(grpid, varid, dimid); 
    200184 
    201185         for (int i = 0; i < nbdim; i++) 
    202186         { 
    203             (CNetCdfInterface::inqDimLen(grpid, dimid[i], size)); 
     187            CNetCdfInterface::inqDimLen(grpid, dimid[i], size); 
    204188            if (size == NC_UNLIMITED) 
    205189                size = UNLIMITED_DIM; 
     
    207191         } 
    208192         delete [] dimid; 
    209          return (retvalue); 
    210       } 
    211  
    212       std::vector<std::string> CONetCDF4::getDimensionsIdList (const std::string * _varname) 
     193         return retvalue; 
     194      } 
     195 
     196      std::vector<std::string> CONetCDF4::getDimensionsIdList(const std::string* _varname) 
    213197      { 
    214198         int nDimNull = 0; 
     
    220204         if (_varname != NULL) 
    221205         { 
    222             (CNetCdfInterface::inqVarNDims(grpid, varid, nbdim)); 
     206            CNetCdfInterface::inqVarNDims(grpid, varid, nbdim); 
    223207            dimid = new int[nbdim](); 
    224             (CNetCdfInterface::inqVarDimId(grpid, varid, dimid)); 
     208            CNetCdfInterface::inqVarDimId(grpid, varid, dimid); 
    225209         } 
    226210         else 
    227211         { 
    228             (CNetCdfInterface::inqDimIds(grpid, nbdim, NULL, 1)); 
     212            CNetCdfInterface::inqDimIds(grpid, nbdim, NULL, 1); 
    229213            dimid = new int[nbdim](); 
    230             (CNetCdfInterface::inqDimIds(grpid, nDimNull, dimid, 1)); 
     214            CNetCdfInterface::inqDimIds(grpid, nDimNull, dimid, 1); 
    231215         } 
    232216 
     
    234218         { 
    235219            std::string dimname; 
    236             (CNetCdfInterface::inqDimName(grpid, dimid[i], dimname)); 
     220            CNetCdfInterface::inqDimName(grpid, dimid[i], dimname); 
    237221            retvalue.push_back(dimname); 
    238222         } 
    239223         delete [] dimid; 
    240224 
    241          return (retvalue); 
    242       } 
    243  
    244  
    245       //--------------------------------------------------------------- 
    246  
    247       const CONetCDF4::CONetCDF4Path & CONetCDF4::getCurrentPath(void) const 
    248       { return (this->path); } 
    249  
    250       void CONetCDF4::setCurrentPath(const CONetCDF4Path & path) 
     225         return retvalue; 
     226      } 
     227 
     228      //--------------------------------------------------------------- 
     229 
     230      const CONetCDF4::CONetCDF4Path& CONetCDF4::getCurrentPath(void) const 
     231      { return this->path; } 
     232 
     233      void CONetCDF4::setCurrentPath(const CONetCDF4Path& path) 
    251234      { this->path = path; } 
    252235 
    253236      //--------------------------------------------------------------- 
    254237 
    255       int CONetCDF4::addGroup(const StdString & name) 
     238      int CONetCDF4::addGroup(const StdString& name) 
    256239      { 
    257240         int retvalue = 0; 
    258241         int grpid = this->getCurrentGroup(); 
    259          (CNetCdfInterface::defGrp(grpid, name, retvalue)); 
    260          return (retvalue); 
     242         CNetCdfInterface::defGrp(grpid, name, retvalue); 
     243         return retvalue; 
    261244      } 
    262245 
     
    268251         int grpid = this->getCurrentGroup(); 
    269252         if (size != UNLIMITED_DIM) 
    270             (CNetCdfInterface::defDim(grpid, name, size, retvalue)); 
     253            CNetCdfInterface::defDim(grpid, name, size, retvalue); 
    271254         else 
    272             (CNetCdfInterface::defDim(grpid, name, NC_UNLIMITED, retvalue)); 
    273          return (retvalue); 
    274       } 
    275  
    276       //--------------------------------------------------------------- 
    277  
    278       int CONetCDF4::addVariable(const StdString & name, nc_type type, 
    279                                  const std::vector<StdString> & dim) 
     255            CNetCdfInterface::defDim(grpid, name, NC_UNLIMITED, retvalue); 
     256         return retvalue; 
     257      } 
     258 
     259      //--------------------------------------------------------------- 
     260 
     261      int CONetCDF4::addVariable(const StdString& name, nc_type type, 
     262                                 const std::vector<StdString>& dim) 
    280263      { 
    281264         int varid = 0; 
     
    292275         for (; it != end; it++) 
    293276         { 
    294             const StdString & dimid = *it; 
     277            const StdString& dimid = *it; 
    295278            dimids.push_back(this->getDimension(dimid)); 
    296279            CNetCdfInterface::inqDimLen(grpid, this->getDimension(dimid), size); 
     
    339322 
    340323      template <> 
    341          void CONetCDF4::addAttribute 
    342             (const StdString & name, const StdString & value, const StdString * varname ) 
    343       { 
    344          int grpid = this->getCurrentGroup(); 
    345          int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 
    346          (CNetCdfInterface::putAtt(grpid, varid, name, NC_CHAR, value.size(), value.c_str())); 
    347          //CheckError(nc_put_att_string(grpid, varid, name.c_str(), 1, &str)); 
    348       } 
    349  
    350       //--------------------------------------------------------------- 
    351  
    352       template <> 
    353          void CONetCDF4::addAttribute 
    354             (const StdString & name, const double & value, const StdString * varname ) 
    355       { 
    356          int grpid = this->getCurrentGroup(); 
    357          int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 
    358          (CNetCdfInterface::putAttType(grpid, varid, name, 1, &value)); 
    359       } 
    360  
    361        template <> 
    362          void CONetCDF4::addAttribute 
    363             (const StdString & name, const CArray<double,1>& value, const StdString * varname ) 
    364       { 
    365          int grpid = this->getCurrentGroup(); 
    366          int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 
    367          (CNetCdfInterface::putAttType(grpid, varid, name, value.numElements(), value.dataFirst())); 
    368       } 
    369       //--------------------------------------------------------------- 
    370  
    371       template <> 
    372          void CONetCDF4::addAttribute 
    373             (const StdString & name, const float & value, const StdString * varname ) 
    374       { 
    375          int grpid = this->getCurrentGroup(); 
    376          int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 
    377          (CNetCdfInterface::putAttType(grpid, varid, name, 1, &value)); 
    378       } 
    379  
    380        template <> 
    381          void CONetCDF4::addAttribute 
    382             (const StdString & name, const CArray<float,1>& value, const StdString * varname ) 
    383       { 
    384          int grpid = this->getCurrentGroup(); 
    385          int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 
    386          (CNetCdfInterface::putAttType(grpid, varid, name, value.numElements(), value.dataFirst())); 
    387       } 
    388  
    389       //--------------------------------------------------------------- 
    390  
    391       template <> 
    392          void CONetCDF4::addAttribute 
    393             (const StdString & name, const int & value, const StdString * varname ) 
    394       { 
    395          int grpid = this->getCurrentGroup(); 
    396          int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 
    397          (CNetCdfInterface::putAttType(grpid, varid, name, 1, &value)); 
    398       } 
    399  
    400        template <> 
    401          void CONetCDF4::addAttribute 
    402             (const StdString & name, const CArray<int,1>& value, const StdString * varname ) 
    403       { 
    404          int grpid = this->getCurrentGroup(); 
    405          int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 
    406          (CNetCdfInterface::putAttType(grpid, varid, name, value.numElements(), value.dataFirst())); 
    407       } 
    408  
    409       template <> 
    410          void CONetCDF4::addAttribute 
    411             (const StdString & name, const short int & value, const StdString * varname ) 
    412       { 
    413          int grpid = this->getCurrentGroup(); 
    414          int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 
    415          (CNetCdfInterface::putAttType(grpid, varid, name, 1, &value)); 
    416       } 
    417  
    418        template <> 
    419          void CONetCDF4::addAttribute 
    420             (const StdString & name, const CArray<short int,1>& value, const StdString * varname ) 
    421       { 
    422          int grpid = this->getCurrentGroup(); 
    423          int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 
    424          (CNetCdfInterface::putAttType(grpid, varid, name, value.numElements(), value.dataFirst())); 
    425       } 
    426  
    427  
    428  
    429       template <> 
    430          void CONetCDF4::addAttribute 
    431             (const StdString & name, const long int & value, const StdString * varname ) 
    432       { 
    433          int grpid = this->getCurrentGroup(); 
    434          int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 
    435          (CNetCdfInterface::putAttType(grpid, varid, name, 1, &value)); 
    436       } 
    437  
    438        template <> 
    439          void CONetCDF4::addAttribute 
    440             (const StdString & name, const CArray<long int,1>& value, const StdString * varname ) 
    441       { 
    442          int grpid = this->getCurrentGroup(); 
    443          int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 
    444          (CNetCdfInterface::putAttType(grpid, varid, name, value.numElements(), value.dataFirst())); 
    445       } 
    446  
    447  
    448  
    449                 //--------------------------------------------------------------- 
    450  
    451       void CONetCDF4::getWriteDataInfos(const StdString & name, StdSize record, StdSize & array_size, 
    452                                         std::vector<StdSize> & sstart, 
    453                                         std::vector<StdSize> & scount, 
    454                                         const std::vector<StdSize> * start, 
    455                                         const std::vector<StdSize> * count) 
     324      void CONetCDF4::addAttribute(const StdString& name, const StdString& value, const StdString* varname) 
     325      { 
     326         int grpid = this->getCurrentGroup(); 
     327         int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 
     328         CNetCdfInterface::putAttType(grpid, varid, name, value.size(), value.c_str()); 
     329      } 
     330 
     331      //--------------------------------------------------------------- 
     332 
     333      template <> 
     334      void CONetCDF4::addAttribute(const StdString& name, const double& value, const StdString* varname) 
     335      { 
     336         int grpid = this->getCurrentGroup(); 
     337         int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 
     338         CNetCdfInterface::putAttType(grpid, varid, name, 1, &value); 
     339      } 
     340 
     341      template <> 
     342      void CONetCDF4::addAttribute(const StdString& name, const CArray<double,1>& value, const StdString* varname) 
     343      { 
     344         int grpid = this->getCurrentGroup(); 
     345         int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 
     346         CNetCdfInterface::putAttType(grpid, varid, name, value.numElements(), value.dataFirst()); 
     347      } 
     348      //--------------------------------------------------------------- 
     349 
     350      template <> 
     351      void CONetCDF4::addAttribute(const StdString& name, const float& value, const StdString* varname) 
     352      { 
     353         int grpid = this->getCurrentGroup(); 
     354         int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 
     355         CNetCdfInterface::putAttType(grpid, varid, name, 1, &value); 
     356      } 
     357 
     358      template <> 
     359      void CONetCDF4::addAttribute(const StdString& name, const CArray<float,1>& value, const StdString* varname) 
     360      { 
     361         int grpid = this->getCurrentGroup(); 
     362         int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 
     363         CNetCdfInterface::putAttType(grpid, varid, name, value.numElements(), value.dataFirst()); 
     364      } 
     365 
     366      //--------------------------------------------------------------- 
     367 
     368      template <> 
     369      void CONetCDF4::addAttribute(const StdString& name, const int& value, const StdString* varname) 
     370      { 
     371         int grpid = this->getCurrentGroup(); 
     372         int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 
     373         CNetCdfInterface::putAttType(grpid, varid, name, 1, &value); 
     374      } 
     375 
     376      template <> 
     377      void CONetCDF4::addAttribute(const StdString& name, const CArray<int,1>& value, const StdString* varname) 
     378      { 
     379         int grpid = this->getCurrentGroup(); 
     380         int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 
     381         CNetCdfInterface::putAttType(grpid, varid, name, value.numElements(), value.dataFirst()); 
     382      } 
     383 
     384      template <> 
     385      void CONetCDF4::addAttribute(const StdString& name, const short int& value, const StdString* varname) 
     386      { 
     387         int grpid = this->getCurrentGroup(); 
     388         int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 
     389         CNetCdfInterface::putAttType(grpid, varid, name, 1, &value); 
     390      } 
     391 
     392      template <> 
     393      void CONetCDF4::addAttribute(const StdString& name, const CArray<short int,1>& value, const StdString* varname) 
     394      { 
     395         int grpid = this->getCurrentGroup(); 
     396         int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 
     397         CNetCdfInterface::putAttType(grpid, varid, name, value.numElements(), value.dataFirst()); 
     398      } 
     399 
     400      template <> 
     401      void CONetCDF4::addAttribute(const StdString& name, const long int& value, const StdString* varname) 
     402      { 
     403         int grpid = this->getCurrentGroup(); 
     404         int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 
     405         CNetCdfInterface::putAttType(grpid, varid, name, 1, &value); 
     406      } 
     407 
     408      template <> 
     409      void CONetCDF4::addAttribute(const StdString& name, const CArray<long int,1>& value, const StdString* varname) 
     410      { 
     411         int grpid = this->getCurrentGroup(); 
     412         int varid = (varname == NULL) ? NC_GLOBAL : this->getVariable(*varname); 
     413         CNetCdfInterface::putAttType(grpid, varid, name, value.numElements(), value.dataFirst()); 
     414      } 
     415 
     416      //--------------------------------------------------------------- 
     417 
     418      void CONetCDF4::getWriteDataInfos(const StdString& name, StdSize record, StdSize& array_size, 
     419                                        std::vector<StdSize>& sstart, 
     420                                        std::vector<StdSize>& scount, 
     421                                        const std::vector<StdSize>* start, 
     422                                        const std::vector<StdSize>* count) 
    456423      { 
    457424         std::vector<std::size_t> sizes  = this->getDimensions(name); 
     
    490457      } 
    491458 
    492  
    493  
    494       template <> 
    495          void CONetCDF4::writeData_(int grpid, int varid, 
    496                                     const std::vector<StdSize> & sstart, 
    497                                     const std::vector<StdSize> & scount, const double * data) 
    498       { 
    499          (CNetCdfInterface::putVaraType(grpid, varid, &(sstart[0]), &(scount[0]), data)); 
    500 //         sync() ; 
    501       } 
    502  
    503       //--------------------------------------------------------------- 
    504  
    505       template <> 
    506          void CONetCDF4::writeData_(int grpid, int varid, 
    507                                     const std::vector<StdSize> & sstart, 
    508                                     const std::vector<StdSize> & scount, const int * data) 
    509       { 
    510           (CNetCdfInterface::putVaraType(grpid, varid, &(sstart[0]), &(scount[0]), data)); 
    511 //          sync() ; 
    512       } 
    513  
    514       //--------------------------------------------------------------- 
    515  
    516       template <> 
    517          void CONetCDF4::writeData_(int grpid, int varid, 
    518                                     const std::vector<StdSize> & sstart, 
    519                                     const std::vector<StdSize> & scount, const float * data) 
    520       { 
    521           (CNetCdfInterface::putVaraType(grpid, varid, &(sstart[0]), &(scount[0]), data)); 
    522 //          sync() ; 
    523       } 
    524  
    525       //--------------------------------------------------------------- 
    526  
    527       void CONetCDF4::writeData(const CArray<int, 2>& data, const StdString & name) 
     459      template <> 
     460      void CONetCDF4::writeData_(int grpid, int varid, 
     461                                 const std::vector<StdSize>& sstart, 
     462                                 const std::vector<StdSize>& scount, const double* data) 
     463      { 
     464         CNetCdfInterface::putVaraType(grpid, varid, &sstart[0], &scount[0], data); 
     465      } 
     466 
     467      //--------------------------------------------------------------- 
     468 
     469      template <> 
     470      void CONetCDF4::writeData_(int grpid, int varid, 
     471                                 const std::vector<StdSize>& sstart, 
     472                                 const std::vector<StdSize>& scount, const int* data) 
     473      { 
     474          CNetCdfInterface::putVaraType(grpid, varid, &sstart[0], &scount[0], data); 
     475      } 
     476 
     477      //--------------------------------------------------------------- 
     478 
     479      template <> 
     480      void CONetCDF4::writeData_(int grpid, int varid, 
     481                                 const std::vector<StdSize>& sstart, 
     482                                 const std::vector<StdSize>& scount, const float* data) 
     483      { 
     484          CNetCdfInterface::putVaraType(grpid, varid, &sstart[0], &scount[0], data); 
     485      } 
     486 
     487      //--------------------------------------------------------------- 
     488 
     489      void CONetCDF4::writeData(const CArray<int, 2>& data, const StdString& name) 
    528490      { 
    529491         int grpid = this->getCurrentGroup(); 
     
    536498      } 
    537499 
    538       void CONetCDF4::writeTimeAxisData(const CArray<double, 1>& data, const StdString & name, 
     500      void CONetCDF4::writeTimeAxisData(const CArray<double, 1>& data, const StdString& name, 
    539501                                        bool collective, StdSize record, bool isRoot) 
    540502      { 
     
    542504         int varid = this->getVariable(name); 
    543505 
    544          map<int,size_t>::iterator it=timeAxis.find(varid) ; 
    545          if (it==timeAxis.end()) timeAxis[varid]=record ; 
     506         map<int,size_t>::iterator it=timeAxis.find(varid); 
     507         if (it == timeAxis.end()) timeAxis[varid] = record; 
    546508         else 
    547509         { 
    548            if (it->second >= record) return ; 
    549            else it->second =record ; 
     510           if (it->second >= record) return; 
     511           else it->second =record; 
    550512         } 
    551513 
     
    554516 
    555517         if (this->wmpi && collective) 
    556          (CNetCdfInterface::varParAccess(grpid, varid, NC_COLLECTIVE)); 
     518            CNetCdfInterface::varParAccess(grpid, varid, NC_COLLECTIVE); 
    557519         if (this->wmpi && !collective) 
    558          (CNetCdfInterface::varParAccess(grpid, varid, NC_INDEPENDENT)); 
     520            CNetCdfInterface::varParAccess(grpid, varid, NC_INDEPENDENT); 
    559521 
    560522         this->getWriteDataInfos(name, record, array_size,  sstart, scount, NULL, NULL); 
    561          if (using_netcdf_internal)  if (!isRoot) { sstart[0]=sstart[0]+1 ; scount[0]=0 ;} 
     523         if (using_netcdf_internal) 
     524         { 
     525           if (!isRoot) 
     526           { 
     527             sstart[0] = sstart[0] + 1; 
     528             scount[0] = 0; 
     529           } 
     530         } 
    562531         this->writeData_(grpid, varid, sstart, scount, data.dataFirst()); 
    563532       } 
     
    565534      //--------------------------------------------------------------- 
    566535 
    567       bool CONetCDF4::varExist(const StdString & varname) 
    568       { 
    569          int grpid = this->getCurrentGroup(); 
    570          return (CNetCdfInterface::isVarExisted(grpid, varname)); 
     536      bool CONetCDF4::varExist(const StdString& varname) 
     537      { 
     538         int grpid = this->getCurrentGroup(); 
     539         return CNetCdfInterface::isVarExisted(grpid, varname); 
    571540      } 
    572541 
    573542      void CONetCDF4::sync(void) 
    574543      { 
    575          (CNetCdfInterface::sync(this->ncidp)) ; 
     544         CNetCdfInterface::sync(this->ncidp); 
    576545      } 
    577546      ///-------------------------------------------------------------- 
  • XIOS/trunk/src/io/onetcdf4.hpp

    r685 r686  
    113113                                   const std::vector<StdSize> * count); 
    114114 
    115             /// Vérification des erreurs NetCDF /// 
    116             void CheckError(int status); 
    117  
    118115            /// Propriétés privées /// 
    119116            CONetCDF4Path path; 
Note: See TracChangeset for help on using the changeset viewer.