source: XIOS/dev/branch_yushan_merged/src/io/onetcdf4_impl.hpp @ 1138

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

test_remap back to work. No thread for now

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