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

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

branch merged with trunk @1155

  • 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
RevLine 
[352]1#ifndef __ONETCDF4_IMPL_HPP__
2#define __ONETCDF4_IMPL_HPP__
3
4#include "onetcdf4.hpp"
[498]5#include "netCdfInterface.hpp"
[352]6
[1138]7// mpi_std.hpp
8
[352]9namespace xios
10{
[369]11  template <class T, int ndim>
12  void CONetCDF4::writeData(const CArray<T, ndim>& data, const StdString & name,
[352]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)
[498]23    CNetCdfInterface::varParAccess(grpid, varid, NC_COLLECTIVE);
[352]24    if (this->wmpi && !collective)
[498]25    CNetCdfInterface::varParAccess(grpid, varid, NC_INDEPENDENT);
[352]26
[1156]27    CTimer::get("Files : get data infos").resume();
[352]28    this->getWriteDataInfos
29    (name, record, array_size,  sstart, scount, start, count);
[1156]30    CTimer::get("Files : get data infos").suspend();
31
[369]32    if (data.numElements() != array_size)
[352]33    {
34      ERROR("CONetCDF4::writeData(...)",
[369]35      << "[ input array size = "  << data.numElements()
[352]36      << ", intern array size = " << array_size
37      << " ] Invalid input data !" );
38    }
[498]39
[369]40    this->writeData_(grpid, varid, sstart, scount, data.dataFirst());
[352]41  }
[498]42
[1050]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
[1156]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 
[1050]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    }
[1156]79    CTimer::get("CONetCDF4::writeData writeData_").resume();
[1050]80    this->writeData_(grpid, varid, sstart, scount, ArrayStr);
[1156]81    CTimer::get("CONetCDF4::writeData writeData_").suspend();
[1050]82    delete [] ArrayStr ;
83  }
84
[352]85//----------------------------------------------------------------
[498]86
[352]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);
[498]92
[352]93    if (value != NULL)
94    {
[517]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);
[352]101      this->addAttribute(StdString("missing_value"), *value, &varname);
102    }
[517]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    }
[352]108  }
[498]109
[352]110  ///---------------------------------------------------------------
111
112}
113
114
115
116#endif
Note: See TracBrowser for help on using the repository browser.