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