1 | #ifndef __XMLIO_INETCDF4__ |
---|
2 | #define __XMLIO_INETCDF4__ |
---|
3 | |
---|
4 | /// xmlioserver headers /// |
---|
5 | #include "xmlioserver_spl.hpp" |
---|
6 | #include "exception.hpp" |
---|
7 | #include "array.hpp" |
---|
8 | |
---|
9 | #include <mpi.h> |
---|
10 | #include <netcdf.h> |
---|
11 | |
---|
12 | #ifndef UNLIMITED_DIM |
---|
13 | #define UNLIMITED_DIM (size_t)(-1) |
---|
14 | #endif //UNLIMITED_DIM |
---|
15 | |
---|
16 | namespace xmlioserver |
---|
17 | { |
---|
18 | namespace io |
---|
19 | { |
---|
20 | /// ////////////////////// Déclarations ////////////////////// /// |
---|
21 | typedef std::vector<StdString> CVarPath; |
---|
22 | |
---|
23 | class CINetCDF4 |
---|
24 | { |
---|
25 | public : |
---|
26 | |
---|
27 | /// Constructeurs /// |
---|
28 | CINetCDF4(void); // Not implemented. |
---|
29 | CINetCDF4(const StdString & filename); |
---|
30 | CINetCDF4(const CINetCDF4 & inetcdf4); // Not implemented. |
---|
31 | CINetCDF4(const CINetCDF4 * const inetcdf4); // Not implemented. |
---|
32 | |
---|
33 | //------------------------------------------------------------- |
---|
34 | |
---|
35 | /// Accesseurs /// |
---|
36 | StdSize getNbOfTimestep(const CVarPath * const path = NULL); |
---|
37 | |
---|
38 | StdString getUnlimitedDimensionName(const CVarPath * const path = NULL); |
---|
39 | |
---|
40 | StdString getCoordinatesId(const StdString & name, |
---|
41 | const CVarPath * const path = NULL); |
---|
42 | |
---|
43 | StdString getBoundsId(const StdString & name, |
---|
44 | const CVarPath * const path = NULL); |
---|
45 | |
---|
46 | StdString getLonCoordName(const StdString & varname, |
---|
47 | const CVarPath * const path = NULL); |
---|
48 | StdString getLatCoordName(const StdString & varname, |
---|
49 | const CVarPath * const path = NULL); |
---|
50 | StdString getVertCoordName(const StdString & varname, |
---|
51 | const CVarPath * const path = NULL); |
---|
52 | |
---|
53 | std::set<StdString> getCoordVariables(const CVarPath * const path = NULL); |
---|
54 | std::set<StdString> getBoundVariables(const CVarPath * const path = NULL); |
---|
55 | |
---|
56 | std::list<StdString> getGroups (const CVarPath * const path = NULL); |
---|
57 | std::list<StdString> getVariables(const CVarPath * const path = NULL); |
---|
58 | |
---|
59 | std::list<StdString> getDataVariables(bool _is3D = true, |
---|
60 | bool _isRecti = true, |
---|
61 | bool _isCurvi = true, |
---|
62 | bool _isUnstr = true, |
---|
63 | bool _isCellData = true, |
---|
64 | bool _isTemporal = true, |
---|
65 | const CVarPath * const path = NULL); |
---|
66 | |
---|
67 | std::list<StdString> getAttributes |
---|
68 | (const StdString * const var = NULL, |
---|
69 | const CVarPath * const path = NULL); |
---|
70 | |
---|
71 | std::list<StdString> getDimensionsList |
---|
72 | (const StdString * const var = NULL, |
---|
73 | const CVarPath * const path = NULL); |
---|
74 | |
---|
75 | std::list<StdString> getCoordinatesIdList(const StdString & name, |
---|
76 | const CVarPath * const path = NULL); |
---|
77 | |
---|
78 | std::map<StdString, StdSize> getDimensions (const StdString * const var = NULL, |
---|
79 | const CVarPath * const path = NULL); |
---|
80 | |
---|
81 | StdSize getNbVertex(const StdString & name, |
---|
82 | const CVarPath * const path = NULL); |
---|
83 | //------------------------------------------------------------- |
---|
84 | |
---|
85 | template <class T> |
---|
86 | T getMissingValue(const StdString & name, |
---|
87 | const CVarPath * const path = NULL); |
---|
88 | |
---|
89 | template <class T> |
---|
90 | T getAttributeValue(const StdString & name, |
---|
91 | const StdString * const var = NULL, |
---|
92 | const CVarPath * const path = NULL); |
---|
93 | |
---|
94 | template <class T> |
---|
95 | void getData(ARRAY(T, 1) data, |
---|
96 | const StdString & var, |
---|
97 | const CVarPath * const path = NULL, |
---|
98 | StdSize record = UNLIMITED_DIM); |
---|
99 | |
---|
100 | //------------------------------------------------------------- |
---|
101 | |
---|
102 | /// Tests /// |
---|
103 | bool hasMissingValue(const StdString & name, |
---|
104 | const CVarPath * const path = NULL); |
---|
105 | |
---|
106 | bool hasAttribute(const StdString & name, |
---|
107 | const StdString * const var = NULL, |
---|
108 | const CVarPath * const path = NULL); |
---|
109 | |
---|
110 | bool hasVariable(const StdString & name, |
---|
111 | const CVarPath * const path = NULL); |
---|
112 | |
---|
113 | bool hasCoordinates(const StdString & name, |
---|
114 | const CVarPath * const path = NULL); |
---|
115 | |
---|
116 | bool hasTemporalDim(const CVarPath * const path = NULL); |
---|
117 | |
---|
118 | bool hasBounds(const StdString & name, |
---|
119 | const CVarPath * const path = NULL); |
---|
120 | |
---|
121 | //------------------------------------------------------------- |
---|
122 | |
---|
123 | bool isBound(const StdString & name, |
---|
124 | const CVarPath * const path = NULL); |
---|
125 | bool isCoordinate(const StdString & name, |
---|
126 | const CVarPath * const path = NULL); |
---|
127 | bool isRectilinear(const StdString & name, |
---|
128 | const CVarPath * const path = NULL); |
---|
129 | bool isCurvilinear(const StdString & name, |
---|
130 | const CVarPath * const path = NULL); |
---|
131 | bool isUnknown(const StdString & name, |
---|
132 | const CVarPath * const path = NULL); |
---|
133 | bool isUnstructured(const StdString & name, |
---|
134 | const CVarPath * const path = NULL); |
---|
135 | |
---|
136 | bool isTemporal(const StdString & name, |
---|
137 | const CVarPath * const path = NULL); |
---|
138 | bool is3Dim(const StdString & name, |
---|
139 | const CVarPath * const path = NULL); |
---|
140 | bool isCellGrid(const StdString & name, |
---|
141 | const CVarPath * const path = NULL); |
---|
142 | |
---|
143 | //------------------------------------------------------------- |
---|
144 | |
---|
145 | /// Destructeur /// |
---|
146 | virtual ~CINetCDF4(void); |
---|
147 | |
---|
148 | protected : |
---|
149 | |
---|
150 | //------------------------------------------------------------- |
---|
151 | |
---|
152 | /// Accesseurs /// |
---|
153 | int getGroup (const CVarPath * const path = NULL); |
---|
154 | int getVariable(const StdString & varname, |
---|
155 | const CVarPath * const path = NULL); |
---|
156 | int getDimension(const StdString & dimname, |
---|
157 | const CVarPath * const path = NULL); |
---|
158 | int getUnlimitedDimension(const CVarPath * const path = NULL); |
---|
159 | int getAttributeId(const StdString & name, |
---|
160 | const StdString * const var = NULL, |
---|
161 | const CVarPath * const path = NULL); |
---|
162 | |
---|
163 | std::pair<nc_type , StdSize> getAttribute(const StdString & attname, |
---|
164 | const StdString * const var = NULL, |
---|
165 | const CVarPath * const path = NULL); |
---|
166 | |
---|
167 | //------------------------------------------------------------- |
---|
168 | |
---|
169 | void getDataInfo(const StdString & var, const CVarPath * const path, StdSize record, |
---|
170 | std::vector<StdSize> & start, std::vector<StdSize> & count, |
---|
171 | StdSize & array_size); |
---|
172 | |
---|
173 | private : |
---|
174 | |
---|
175 | /// Vérification des erreurs NetCDF /// |
---|
176 | static void CheckError(int status); |
---|
177 | |
---|
178 | int ncidp; // Identifiant de fichier netcdf. |
---|
179 | |
---|
180 | }; // class CINetCDF4 |
---|
181 | |
---|
182 | ///-------------------------------------------------------------- |
---|
183 | template <> |
---|
184 | StdString CINetCDF4::getAttributeValue |
---|
185 | (const StdString & name, const StdString * const var, |
---|
186 | const CVarPath * const path); |
---|
187 | |
---|
188 | template <> |
---|
189 | std::vector<double> CINetCDF4::getAttributeValue |
---|
190 | (const StdString & name, const StdString * const var, |
---|
191 | const CVarPath * const path); |
---|
192 | |
---|
193 | template <> |
---|
194 | std::vector<float> CINetCDF4::getAttributeValue |
---|
195 | (const StdString & name, const StdString * const var, |
---|
196 | const CVarPath * const path); |
---|
197 | |
---|
198 | template <> |
---|
199 | std::vector<int> CINetCDF4::getAttributeValue |
---|
200 | (const StdString & name, const StdString * const var, |
---|
201 | const CVarPath * const path); |
---|
202 | |
---|
203 | template <> |
---|
204 | std::vector<char> CINetCDF4::getAttributeValue |
---|
205 | (const StdString & name, const StdString * const var, |
---|
206 | const CVarPath * const path); |
---|
207 | |
---|
208 | //--------------------------------------------------------------- |
---|
209 | template <> |
---|
210 | int CINetCDF4::getMissingValue |
---|
211 | (const StdString & name, const CVarPath * const path); |
---|
212 | |
---|
213 | template <> |
---|
214 | double CINetCDF4::getMissingValue |
---|
215 | (const StdString & name, const CVarPath * const path); |
---|
216 | |
---|
217 | template <> |
---|
218 | float CINetCDF4::getMissingValue |
---|
219 | (const StdString & name, const CVarPath * const path); |
---|
220 | |
---|
221 | //--------------------------------------------------------------- |
---|
222 | template <> |
---|
223 | void CINetCDF4::getData(ARRAY(int, 1) data, const StdString & var, |
---|
224 | const CVarPath * const path, StdSize record); |
---|
225 | |
---|
226 | template <> |
---|
227 | void CINetCDF4::getData(ARRAY(double, 1) data, const StdString & var, |
---|
228 | const CVarPath * const path, StdSize record); |
---|
229 | |
---|
230 | template <> |
---|
231 | void CINetCDF4::getData(ARRAY(float, 1) data, const StdString & var, |
---|
232 | const CVarPath * const path, StdSize record); |
---|
233 | ///-------------------------------------------------------------- |
---|
234 | |
---|
235 | } // namespace io |
---|
236 | } // namespace xmlioserver |
---|
237 | |
---|
238 | #endif //__XMLIO_INETCDF4__ |
---|