source: XIOS/trunk/src/output/netCdfInterface_impl.hpp @ 501

Last change on this file since 501 was 501, checked in by ymipsl, 10 years ago

Add licence copyright to all file ond directory src using the command :
svn propset -R copyright -F header_licence src

XIOS is now officialy under CeCILL licence

YM

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
File size: 2.7 KB
Line 
1/*!
2   \file netCdfInterface_impl.hpp
3   \author Ha NGUYEN
4   \date 08 Oct 2014
5   \since 06 Oct 2014
6
7   \brief Implemention of some templated functions in netCdfInterface
8 */
9
10#ifndef __NETCDF_INTERFACE_IMPL_HPP__
11#define __NETCDF_INTERFACE_IMPL_HPP__
12
13#include "netCdfInterface.hpp"
14#include "netCdfException.hpp"
15
16namespace xios
17{
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   */
28  template<typename T>
29  int CNetCdfInterface::putAttType(int ncid, int varId, const StdString& attrName,
30                                   StdSize numVal, const T* op)
31  {
32    int status = ncPutAttType(ncid, varId, attrName.c_str(), numVal, op);
33    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     }
44
45     return status;
46  }
47
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   */
57  template<typename T>
58  int CNetCdfInterface::putVaraType(int ncid, int varId, const StdSize* start, const StdSize* count, const T* op)
59  {
60    int status = ncPutVaraType(ncid, varId, start, count, op);
61    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     }
71
72     return status;
73  }
74
75}
76
77#endif // __NETCDF_INTERFACE_IMPL_HPP__
Note: See TracBrowser for help on using the repository browser.