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