source: XIOS/dev/dev_ym/XIOS_ONE_SIDED/src/io/onetcdf4_impl.hpp @ 1847

Last change on this file since 1847 was 1755, checked in by ymipsl, 5 years ago

Solve crash with blitz using recent compiler.

YM

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