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 | |
---|
16 | namespace 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__ |
---|