source: XIOS/dev/branch_openmp/src/io/onetcdf4_impl.hpp @ 1207

Last change on this file since 1207 was 1205, checked in by yushan, 7 years ago

branch merged with trunk @1200

  • 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: 3.9 KB
Line 
1#ifndef __ONETCDF4_IMPL_HPP__
2#define __ONETCDF4_IMPL_HPP__
3
4#include "onetcdf4.hpp"
5#include "netCdfInterface.hpp"
6#include "timer.hpp"
7// mpi_std.hpp
8
9namespace xios
10{
11  template <class T, int ndim>
12  void CONetCDF4::writeData(const CArray<T, ndim>& data, const StdString & name,
13                            bool collective, StdSize record,
14                            const std::vector<StdSize> * start,
15                            const std::vector<StdSize> * count)
16  {
17    int grpid = this->getCurrentGroup();
18    int varid = this->getVariable(name);
19    StdSize array_size = 1;
20    std::vector<StdSize> sstart, scount;
21
22    if (this->wmpi && collective)
23    CNetCdfInterface::varParAccess(grpid, varid, NC_COLLECTIVE);
24    if (this->wmpi && !collective)
25    CNetCdfInterface::varParAccess(grpid, varid, NC_INDEPENDENT);
26
27    CTimer::get("Files : get data infos").resume();
28    this->getWriteDataInfos
29    (name, record, array_size,  sstart, scount, start, count);
30    CTimer::get("Files : get data infos").suspend();
31
32    if (data.numElements() != array_size)
33    {
34      ERROR("CONetCDF4::writeData(...)",
35      << "[ input array size = "  << data.numElements()
36      << ", intern array size = " << array_size
37      << " ] Invalid input data !" );
38    }
39
40    this->writeData_(grpid, varid, sstart, scount, data.dataFirst());
41  }
42
43  template <>
44  void CONetCDF4::writeData(const CArray<StdString, 1>& data, const StdString & name,
45                            bool collective, StdSize record,
46                            const std::vector<StdSize> * start,
47                            const std::vector<StdSize> * count)
48  {
49    int grpid = this->getCurrentGroup();
50    int varid = this->getVariable(name);
51    StdSize array_size = 1;
52    std::vector<StdSize> sstart, scount;
53
54    if (this->wmpi && collective)
55    CNetCdfInterface::varParAccess(grpid, varid, NC_COLLECTIVE);
56    if (this->wmpi && !collective)
57    CNetCdfInterface::varParAccess(grpid, varid, NC_INDEPENDENT);
58
59    CTimer::get("CONetCDF4::writeData getWriteDataInfos").resume();
60    this->getWriteDataInfos(name, record, array_size,  sstart, scount, start, count);
61    CTimer::get("CONetCDF4::writeData getWriteDataInfos").suspend();
62 
63    if (data.numElements()*stringArrayLen != array_size)
64    {
65      ERROR("CONetCDF4::writeData(...)",
66      << "[ input array size = "  << data.numElements()
67      << ", intern array size = " << array_size
68      << " ] Invalid input data !" );
69    }
70    char* ArrayStr ;
71    char *PtrArrayStr ;
72    PtrArrayStr=ArrayStr=new char[data.numElements()*stringArrayLen] ;
73    Array<StdString,1>::const_iterator it, itb=data.begin(), ite=data.end() ;
74    for(it=itb;it!=ite;++it,PtrArrayStr+=stringArrayLen)
75    {
76      it->copy(PtrArrayStr,it->size()) ;
77      PtrArrayStr[it->size()]='\0' ;
78    }
79    CTimer::get("CONetCDF4::writeData writeData_").resume();
80    this->writeData_(grpid, varid, sstart, scount, ArrayStr);
81    CTimer::get("CONetCDF4::writeData writeData_").suspend();
82    delete [] ArrayStr ;
83  }
84
85//----------------------------------------------------------------
86
87  template <class T>
88  void CONetCDF4::setDefaultValue(const StdString & varname, const T * value)
89  {
90    int grpid = this->getCurrentGroup();
91    int varid = this->getVariable(varname);
92
93    if (value != NULL)
94    {
95      // nc_def_var_fill will automatically set the _FillValue attribute when
96      // using the NetCDF 4 format but we need to do it manually otherwise
97      if (useClassicFormat)
98        this->addAttribute(StdString("_FillValue"), *value, &varname);
99      else
100        CNetCdfInterface::defVarFill(grpid, varid, 0, (void*)value);
101      this->addAttribute(StdString("missing_value"), *value, &varname);
102    }
103    else if (!useClassicFormat)
104    {
105      // The "no-fill mode" is set globally for the classic NetCDF format
106      CNetCdfInterface::defVarFill(grpid, varid, 1, NULL);
107    }
108  }
109
110  ///---------------------------------------------------------------
111
112}
113
114
115
116#endif
Note: See TracBrowser for help on using the repository browser.