source: XIOS/trunk/src/output/onetcdf4_impl.hpp @ 499

Last change on this file since 499 was 498, checked in by mhnguyen, 10 years ago

Making a wrapper of NetCdf? C functions

+) Add a wrapper class for NetCdf? functions
+) Add a class to manage exception for NetCdf? functions
+) Replace direct call to netcdf functions by functions of the wrapper

Test
+) On Curie
+) In case of error, exception is thrown and more information is provided

File size: 1.7 KB
Line 
1#ifndef __ONETCDF4_IMPL_HPP__
2#define __ONETCDF4_IMPL_HPP__
3
4#include "onetcdf4.hpp"
5#include "netCdfInterface.hpp"
6
7namespace xios
8{
9  template <class T, int ndim>
10  void CONetCDF4::writeData(const CArray<T, ndim>& data, const StdString & name,
11                            bool collective, StdSize record,
12                            const std::vector<StdSize> * start,
13                            const std::vector<StdSize> * count)
14  {
15    int grpid = this->getCurrentGroup();
16    int varid = this->getVariable(name);
17    StdSize array_size = 1;
18    std::vector<StdSize> sstart, scount;
19
20    if (this->wmpi && collective)
21    CNetCdfInterface::varParAccess(grpid, varid, NC_COLLECTIVE);
22    if (this->wmpi && !collective)
23    CNetCdfInterface::varParAccess(grpid, varid, NC_INDEPENDENT);
24
25    this->getWriteDataInfos
26    (name, record, array_size,  sstart, scount, start, count);
27    if (data.numElements() != array_size)
28    {
29      ERROR("CONetCDF4::writeData(...)",
30      << "[ input array size = "  << data.numElements()
31      << ", intern array size = " << array_size
32      << " ] Invalid input data !" );
33    }
34
35    this->writeData_(grpid, varid, sstart, scount, data.dataFirst());
36  }
37
38//----------------------------------------------------------------
39
40  template <class T>
41  void CONetCDF4::setDefaultValue(const StdString & varname, const T * value)
42  {
43    int grpid = this->getCurrentGroup();
44    int varid = this->getVariable(varname);
45
46    if (value != NULL)
47    {
48      CNetCdfInterface::defVarFill(grpid, varid, 0, (void*)value);
49      this->addAttribute(StdString("missing_value"), *value, &varname);
50    }
51    else CNetCdfInterface::defVarFill(grpid, varid, 1, NULL);
52  }
53
54  ///---------------------------------------------------------------
55
56}
57
58
59
60#endif
Note: See TracBrowser for help on using the repository browser.