[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(); |
---|
[1691] | 27 | this->getWriteDataInfos(name, record, array_size, sstart, scount, start, count); |
---|
[1158] | 28 | CTimer::get("Files : get data infos").suspend(); |
---|
| 29 | |
---|
[369] | 30 | if (data.numElements() != array_size) |
---|
[352] | 31 | { |
---|
| 32 | ERROR("CONetCDF4::writeData(...)", |
---|
[369] | 33 | << "[ input array size = " << data.numElements() |
---|
[352] | 34 | << ", intern array size = " << array_size |
---|
| 35 | << " ] Invalid input data !" ); |
---|
| 36 | } |
---|
[369] | 37 | this->writeData_(grpid, varid, sstart, scount, data.dataFirst()); |
---|
[352] | 38 | } |
---|
[498] | 39 | |
---|
[1158] | 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 | CTimer::get("CONetCDF4::writeData getWriteDataInfos").resume(); |
---|
| 57 | this->getWriteDataInfos(name, record, array_size, sstart, scount, start, count); |
---|
| 58 | CTimer::get("CONetCDF4::writeData getWriteDataInfos").suspend(); |
---|
| 59 | |
---|
[1441] | 60 | int dimArrayLen; |
---|
| 61 | for (int i=0; i<scount.size(); i++) |
---|
| 62 | if (scount[i] == stringArrayLen) |
---|
| 63 | dimArrayLen = i; |
---|
| 64 | |
---|
[1158] | 65 | if (data.numElements()*stringArrayLen != array_size) |
---|
| 66 | { |
---|
| 67 | ERROR("CONetCDF4::writeData(...)", |
---|
[1435] | 68 | << "[ input array size = " << data.numElements()*stringArrayLen |
---|
[1158] | 69 | << ", intern array size = " << array_size |
---|
| 70 | << " ] Invalid input data !" ); |
---|
| 71 | } |
---|
| 72 | char *PtrArrayStr ; |
---|
[1646] | 73 | PtrArrayStr=new char[stringArrayLen*data.numElements()] ; |
---|
| 74 | memset (PtrArrayStr,' ',stringArrayLen*data.numElements()); |
---|
| 75 | size_t offset=0 ; |
---|
[1666] | 76 | /* Array<StdString,1>::const_iterator it, itb=data.begin(), ite=data.end() ; |
---|
[1646] | 77 | for(it=itb;it!=ite;++it, offset+=stringArrayLen) |
---|
[1158] | 78 | { |
---|
[1646] | 79 | it->copy(PtrArrayStr+offset,it->size()) ; |
---|
| 80 | PtrArrayStr[offset+it->size()]='\0' ; |
---|
[1158] | 81 | } |
---|
[1666] | 82 | */ |
---|
| 83 | for(int i=0;i<data.numElements();i++,offset+=stringArrayLen) |
---|
| 84 | { |
---|
| 85 | data(i).copy(PtrArrayStr+offset,data(i).size()) ; |
---|
| 86 | PtrArrayStr[offset+data(i).size()]='\0' ; |
---|
| 87 | } |
---|
[1646] | 88 | |
---|
[1666] | 89 | CTimer::get("CONetCDF4::writeData writeData_").resume(); |
---|
| 90 | this->writeData_(grpid, varid, sstart, scount, PtrArrayStr); |
---|
| 91 | CTimer::get("CONetCDF4::writeData writeData_").suspend(); |
---|
[1646] | 92 | |
---|
[1441] | 93 | delete [] PtrArrayStr; |
---|
[1158] | 94 | } |
---|
| 95 | |
---|
[352] | 96 | //---------------------------------------------------------------- |
---|
[498] | 97 | |
---|
[352] | 98 | template <class T> |
---|
| 99 | void CONetCDF4::setDefaultValue(const StdString & varname, const T * value) |
---|
| 100 | { |
---|
| 101 | int grpid = this->getCurrentGroup(); |
---|
| 102 | int varid = this->getVariable(varname); |
---|
[498] | 103 | |
---|
[352] | 104 | if (value != NULL) |
---|
| 105 | { |
---|
[517] | 106 | // nc_def_var_fill will automatically set the _FillValue attribute when |
---|
| 107 | // using the NetCDF 4 format but we need to do it manually otherwise |
---|
| 108 | if (useClassicFormat) |
---|
| 109 | this->addAttribute(StdString("_FillValue"), *value, &varname); |
---|
| 110 | else |
---|
| 111 | CNetCdfInterface::defVarFill(grpid, varid, 0, (void*)value); |
---|
[352] | 112 | this->addAttribute(StdString("missing_value"), *value, &varname); |
---|
| 113 | } |
---|
[517] | 114 | else if (!useClassicFormat) |
---|
| 115 | { |
---|
| 116 | // The "no-fill mode" is set globally for the classic NetCDF format |
---|
| 117 | CNetCdfInterface::defVarFill(grpid, varid, 1, NULL); |
---|
| 118 | } |
---|
[352] | 119 | } |
---|
[498] | 120 | |
---|
[352] | 121 | ///--------------------------------------------------------------- |
---|
| 122 | |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | #endif |
---|