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