[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 | |
---|
| 8 | namespace 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 | |
---|
| 62 | if (data.numElements()*stringArrayLen != array_size) |
---|
| 63 | { |
---|
| 64 | ERROR("CONetCDF4::writeData(...)", |
---|
| 65 | << "[ input array size = " << data.numElements() |
---|
| 66 | << ", intern array size = " << array_size |
---|
| 67 | << " ] Invalid input data !" ); |
---|
| 68 | } |
---|
| 69 | char* ArrayStr ; |
---|
| 70 | char *PtrArrayStr ; |
---|
| 71 | PtrArrayStr=ArrayStr=new char[data.numElements()*stringArrayLen] ; |
---|
| 72 | Array<StdString,1>::const_iterator it, itb=data.begin(), ite=data.end() ; |
---|
| 73 | for(it=itb;it!=ite;++it,PtrArrayStr+=stringArrayLen) |
---|
| 74 | { |
---|
| 75 | it->copy(PtrArrayStr,it->size()) ; |
---|
| 76 | PtrArrayStr[it->size()]='\0' ; |
---|
| 77 | } |
---|
| 78 | CTimer::get("CONetCDF4::writeData writeData_").resume(); |
---|
| 79 | this->writeData_(grpid, varid, sstart, scount, ArrayStr); |
---|
| 80 | CTimer::get("CONetCDF4::writeData writeData_").suspend(); |
---|
| 81 | delete [] ArrayStr ; |
---|
| 82 | } |
---|
| 83 | |
---|
[352] | 84 | //---------------------------------------------------------------- |
---|
[498] | 85 | |
---|
[352] | 86 | template <class T> |
---|
| 87 | void CONetCDF4::setDefaultValue(const StdString & varname, const T * value) |
---|
| 88 | { |
---|
| 89 | int grpid = this->getCurrentGroup(); |
---|
| 90 | int varid = this->getVariable(varname); |
---|
[498] | 91 | |
---|
[352] | 92 | if (value != NULL) |
---|
| 93 | { |
---|
[517] | 94 | // nc_def_var_fill will automatically set the _FillValue attribute when |
---|
| 95 | // using the NetCDF 4 format but we need to do it manually otherwise |
---|
| 96 | if (useClassicFormat) |
---|
| 97 | this->addAttribute(StdString("_FillValue"), *value, &varname); |
---|
| 98 | else |
---|
| 99 | CNetCdfInterface::defVarFill(grpid, varid, 0, (void*)value); |
---|
[352] | 100 | this->addAttribute(StdString("missing_value"), *value, &varname); |
---|
| 101 | } |
---|
[517] | 102 | else if (!useClassicFormat) |
---|
| 103 | { |
---|
| 104 | // The "no-fill mode" is set globally for the classic NetCDF format |
---|
| 105 | CNetCdfInterface::defVarFill(grpid, varid, 1, NULL); |
---|
| 106 | } |
---|
[352] | 107 | } |
---|
[498] | 108 | |
---|
[352] | 109 | ///--------------------------------------------------------------- |
---|
| 110 | |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | #endif |
---|