MI - Fimex
ToVLevelConverter.h
Go to the documentation of this file.
1 /*
2  * Fimex, ToVLevelConverter.h
3  *
4  * (C) Copyright 2011, met.no
5  *
6  * Project Info: https://wiki.met.no/fimex/start
7  *
8  * This library is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 2.1 of the License, or
11  * (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16  * License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21  * USA.
22  *
23  * Created on: Aug 9, 2011
24  * Author: Heiko Klein
25  */
26 
27 #ifndef TO_VLEVEL_CONVERTER_H_
28 #define TO_VLEVEL_CONVERTER_H_
29 
30 #include <vector>
31 #include <boost/shared_ptr.hpp>
32 #include <boost/shared_array.hpp>
33 #include <boost/noncopyable.hpp>
35 #include "fimex/mifi_constants.h"
36 #include "fimex/IndexedData.h"
37 #include "fimex/deprecated.h"
38 
39 namespace MetNoFimex
40 {
41 // forward decl.
42 class CDMReader;
43 
44 using namespace std;
45 
53 class ToVLevelConverter : boost::noncopyable {
54 public:
55  virtual ~ToVLevelConverter() {}
64  virtual vector<double> operator()(size_t x, size_t y, size_t t) = 0;
65 
67  inline vector<double> values(size_t x, size_t y, size_t t)
68  { return operator()(x, y, t); }
69 
79  virtual bool isValid(double val, size_t x, size_t y, size_t t);
80 };
81 
86  const vector<double> vlevel_;
87 public:
91  IdentityToVLevelConverter(const vector<double>& vlevel) : vlevel_(vlevel) {}
92  virtual vector<double> operator()(size_t x, size_t y, size_t t);
93 };
94 
99  const boost::shared_array<float> pressure_;
100  size_t nx_;
101  size_t ny_;
102  size_t nz_;
103  size_t nt_;
104 public:
105  Identity4DToVLevelConverter(const boost::shared_array<float> pressure, size_t nx, size_t ny, size_t nk, size_t nt)
106  : pressure_(pressure), nx_(nx), ny_(ny), nz_(nk), nt_(nt) {}
107  virtual vector<double> operator()(size_t x, size_t y, size_t t);
108 };
109 
114  vector<double> pres_;
115 public:
120  LnPressureToPressureConverter(double p0, const vector<double>& lnP);
121  virtual vector<double> operator()(size_t x, size_t y, size_t t);
122 };
123 
128  vector<double> pres_;
129 public:
134  virtual vector<double> operator()(size_t x, size_t y, size_t t);
135 };
136 
142  const vector<double> sigma_;
143  double ptop_;
144  const boost::shared_array<double> ps_;
145  size_t nx_;
146  size_t ny_;
147  size_t nt_;
148 public:
157  SigmaToPressureConverter(const vector<double>& sigma, double ptop, const boost::shared_array<double> ps, size_t nx, size_t ny, size_t nt)
158  : sigma_(sigma), ptop_(ptop), ps_(ps), nx_(nx), ny_(ny), nt_(nt) {}
159  virtual vector<double> operator()(size_t x, size_t y, size_t t);
160 };
161 
162 
168  const vector<double> ap_;
169  const vector<double> b_;
170  const boost::shared_array<double> ps_;
171  size_t nx_;
172  size_t ny_;
173  size_t nt_;
174 public:
183  HybridSigmaApToPressureConverter(const vector<double>& ap, const vector<double>& b, const boost::shared_array<double> ps, size_t nx, size_t ny, size_t nt)
184  : ap_(ap), b_(b), ps_(ps), nx_(nx), ny_(ny), nt_(nt) {}
185  virtual vector<double> operator()(size_t x, size_t y, size_t t);
186 };
187 
193  const vector<double> a_;
194  const vector<double> b_;
195  double p0_;
196  const boost::shared_array<double> ps_;
197  size_t nx_;
198  size_t ny_;
199  size_t nt_;
200 public:
210  HybridSigmaToPressureConverter(const vector<double>& a, const vector<double>& b, double p0, const boost::shared_array<double> ps, size_t nx, size_t ny, size_t nt)
211  : a_(a), b_(b), p0_(p0), ps_(ps), nx_(nx), ny_(ny), nt_(nt) {}
212  virtual vector<double> operator()(size_t x, size_t y, size_t t);
213 };
214 
220  const boost::shared_ptr<ToVLevelConverter> presConv_;
221 public:
225  PressureToStandardAltitudeConverter(boost::shared_ptr<ToVLevelConverter> presConv) : presConv_(presConv) {}
226  virtual vector<double> operator()(size_t x, size_t y, size_t t);
227 };
228 
234  const boost::shared_ptr<ToVLevelConverter> presConv_;
235  typedef const boost::shared_array<float> float_cp;
236  float_cp surface_air_pressure_, surface_geopotential_, air_temperature_, specific_humidity_;
237  size_t nx_, ny_, nt_;
238 
239 public:
243  PressureIntegrationToAltitudeConverter(boost::shared_ptr<ToVLevelConverter> pressure,
244  float_cp sapVal, float_cp sgpVal, float_cp airtVal, float_cp shVal,
245  size_t nx, size_t ny, size_t nt);
246  virtual vector<double> operator()(size_t x, size_t y, size_t t);
247 };
248 
254  const boost::shared_ptr<ToVLevelConverter> conv_;
255  const boost::shared_array<float> topo_;
256  size_t nx_;
257  size_t ny_;
258  size_t nz_;
259  size_t nt_;
260 public:
261  AltitudeConverterToHeightConverter(const boost::shared_ptr<ToVLevelConverter> altiConverter, const boost::shared_array<float> topography, size_t nx, size_t ny, size_t nk, size_t nt)
262  : conv_(altiConverter), topo_(topography), nx_(nx), ny_(ny), nz_(nk), nt_(nt) {}
263  virtual vector<double> operator()(size_t x, size_t y, size_t t);
264 };
265 
271  const boost::shared_ptr<ToVLevelConverter> conv_;
272  const boost::shared_array<float> topo_;
273  size_t nx_;
274  size_t ny_;
275  size_t nz_;
276  size_t nt_;
277 public:
278  HeightConverterToAltitudeConverter(const boost::shared_ptr<ToVLevelConverter> heightConverter, const boost::shared_array<float> topography, size_t nx, size_t ny, size_t nk, size_t nt)
279  : conv_(heightConverter), topo_(topography), nx_(nx), ny_(ny), nz_(nk), nt_(nt) {}
280  virtual vector<double> operator()(size_t x, size_t y, size_t t);
281 };
282 
283 
289  const boost::shared_array<float> geopot_;
290  size_t nx_;
291  size_t ny_;
292  size_t nz_;
293  size_t nt_;
294 public:
295  GeopotentialToAltitudeConverter(const boost::shared_array<float> geopot_height, size_t nx, size_t ny, size_t nk, size_t nt)
296  : geopot_(geopot_height), nx_(nx), ny_(ny), nz_(nk), nt_(nt) {}
297  virtual vector<double> operator()(size_t x, size_t y, size_t t);
298 };
299 
300 
305  vector<double> s_;
306  vector<double> C_;
307  double depth_c_;
308  const IndexedData eta_;
309  const IndexedData depth_;
310  /* eta might be 0 */
311  size_t nx_;
312  size_t ny_;
313  size_t nz_;
314  size_t nt_;
315  bool timeDependentDepth_;
316  int (*func_)(size_t, double, double, double, const double*, const double*, double*);
317 
318 public:
329  IndexedData eta, IndexedData depth,
330  size_t nx, size_t ny, size_t nk, size_t nt,
331  int (*func)(size_t, double, double, double, const double*, const double*, double*))
332  : s_(s), C_(C), depth_c_(depth_c), eta_(eta), depth_(depth),
333  nx_(nx), ny_(ny), nz_(nk), nt_(nt)
334  {
335  timeDependentDepth_ = (depth_.idx().getDims().size() == 3);
336  func_ = func;
337  }
338  virtual vector<double> operator()(size_t x, size_t y, size_t t);
339  virtual bool isValid(double val, size_t x, size_t y, size_t t);
340 };
341 
342 } // namespace
343 
344 #endif /* TO_VLEVEL_CONVERTER_H_ */
const std::vector< std::size_t > & getDims() const
Definition: DataIndex.h:56
IdentityToVLevelConverter(const vector< double > &vlevel)
Definition: ToVLevelConverter.h:91
STL namespace.
virtual ~ToVLevelConverter()
Definition: ToVLevelConverter.h:55
HybridSigmaApToPressureConverter(const vector< double > &ap, const vector< double > &b, const boost::shared_array< double > ps, size_t nx, size_t ny, size_t nt)
Definition: ToVLevelConverter.h:183
vector< double > values(size_t x, size_t y, size_t t)
same as operator()
Definition: ToVLevelConverter.h:67
HybridSigmaToPressureConverter(const vector< double > &a, const vector< double > &b, double p0, const boost::shared_array< double > ps, size_t nx, size_t ny, size_t nt)
Definition: ToVLevelConverter.h:210
Definition: ToVLevelConverter.h:127
HeightConverterToAltitudeConverter(const boost::shared_ptr< ToVLevelConverter > heightConverter, const boost::shared_array< float > topography, size_t nx, size_t ny, size_t nk, size_t nt)
Definition: ToVLevelConverter.h:278
OceanSCoordinateGToDepthConverter(const vector< double > &s, const vector< double > &C, double depth_c, IndexedData eta, IndexedData depth, size_t nx, size_t ny, size_t nk, size_t nt, int(*func)(size_t, double, double, double, const double *, const double *, double *))
Definition: ToVLevelConverter.h:328
AltitudeConverterToHeightConverter(const boost::shared_ptr< ToVLevelConverter > altiConverter, const boost::shared_array< float > topography, size_t nx, size_t ny, size_t nk, size_t nt)
Definition: ToVLevelConverter.h:261
Definition: C_CDMReader.h:35
Identity4DToVLevelConverter(const boost::shared_array< float > pressure, size_t nx, size_t ny, size_t nk, size_t nt)
Definition: ToVLevelConverter.h:105
PressureToStandardAltitudeConverter(boost::shared_ptr< ToVLevelConverter > presConv)
Definition: ToVLevelConverter.h:225
GeopotentialToAltitudeConverter(const boost::shared_array< float > geopot_height, size_t nx, size_t ny, size_t nk, size_t nt)
Definition: ToVLevelConverter.h:295
size_type size() const
Definition: ToVLevelConverter.h:98
const DataIndex & idx() const
get the index belonging to the data
Definition: ToVLevelConverter.h:304
Definition: ToVLevelConverter.h:219
Definition: ToVLevelConverter.h:192
Definition: ToVLevelConverter.h:233
Definition: ToVLevelConverter.h:253
Definition: ToVLevelConverter.h:141
Definition: ToVLevelConverter.h:53
Definition: ToVLevelConverter.h:85
Definition: ToVLevelConverter.h:167
SigmaToPressureConverter(const vector< double > &sigma, double ptop, const boost::shared_array< double > ps, size_t nx, size_t ny, size_t nt)
Definition: ToVLevelConverter.h:157
Definition: IndexedData.h:43
Definition: ToVLevelConverter.h:288
Definition: ToVLevelConverter.h:113
Definition: ToVLevelConverter.h:270