IODA Bundle
RegionCache.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 1996-2012 ECMWF.
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 /// \file RegionCache.h
12 /// ECMWF July 2010
13 
14 #ifndef RegionCache_H
15 #define RegionCache_H
16 
17 #include <vector>
18 
19 #include "eckit/memory/NonCopyable.h"
21 
22 namespace odc {
23 namespace sql {
24 namespace function {
25 
26 static const int dim=2;
27 static const double min_resol = 0.1e0;
28 static const double sphere_area = piconst::four_pi; /* Actually: 4 * pi * R^2 */
29 
30 #define NINT(x) F90nint(x)
31 
32 /* Fortran90 compatible NINT-function */
33 #define F90nint(x) ( ((x) > 0) ? (int)((x) + 0.5) : (int)((x) - 0.5) )
34 
35 #define R2D(x) ( (180/piconst::pi) * ( ((x) > piconst::pi) ? ((x) - 2*piconst::pi) : (x) ) )
36 
37 typedef enum { eq_cache_kind = 1, rgg_cache_kind = 2 } RegionCacheKind;
38 
39 class RegionCache;
40 typedef std::vector<RegionCache *> VectorRegionCache;
41 
42 // To store results from the last find_latband, find_lonbox
43  class Last {
44  public:
45  int jb;
46  int lonbox;
47  int boxid;
48  double left, mid, right;
49  };
50 
51 class RegionCache : private eckit::NonCopyable {
52 public:
53 
54  RegionCache();
55  virtual ~RegionCache();
56 
57  static VectorRegionCache & instance();
58 
59  double get_midlat(const double &, const double &);
60  double get_midlon(const double &, const double &, const double &);
61 
62 private: // members
63  RegionCacheKind *kind_; // type of cache (rgg, eq_boxes)
64  int *nboxes_; // Actual number of boxes
65  double *resol_; // Approximate resolution in degrees at Equator
66  int *nbands_; // number of latitude bands
67  double *latband_; // starting latitudes for each latitude band : size nbands+1
68  double *midlat_; // mid latitudes for each latitude band : size nbands
69  int *loncnt_; // # of longitude boxes for each latitude band : size nbands
70  int *sum_loncnt_; // Sum of (longitude) boxes BEFORE this latitude band : size nbands
71  double *stlon_; // starting longitudes for each latitude band : size nb
72  double *deltalon_; // longitudinal delta for each latitude band : size nb
74 
75 private: // methods
76  virtual double get_resol(const double & val);
77  virtual void create_cache(const double &, const int &);
78  void get_cache(const double &);
79  void put_cache(const RegionCacheKind & kind,const double &,const int &,double [],double [],double [],
80  double [],int []);
81  int find_latband(const double &);
82  int find_lonbox(const int &, const double &, double *, double *, double *);
83  int interval_bsearch(const double &, const int &, const double [], const double *, const double &, const double &);
84 
85  friend class EqRegionCache;
86  friend class RggRegionCache;
87  //friend std::ostream& operator<<(std::ostream& s,const RegionCache& p)
88  // { p.print(s); return s; }
89 
90 };
91 
92 } // namespace function
93 } // namespace sql
94 } // namespace odc
95 
96 #endif
double get_midlon(const double &, const double &, const double &)
Definition: RegionCache.cc:184
static VectorRegionCache & instance()
Definition: RegionCache.cc:34
virtual double get_resol(const double &val)
Definition: RegionCache.cc:39
int interval_bsearch(const double &, const int &, const double[], const double *, const double &, const double &)
Definition: RegionCache.cc:43
void get_cache(const double &)
Definition: RegionCache.cc:195
void put_cache(const RegionCacheKind &kind, const double &, const int &, double[], double[], double[], double[], int[])
Definition: RegionCache.cc:231
virtual void create_cache(const double &, const int &)
Definition: RegionCache.cc:226
int find_latband(const double &)
Definition: RegionCache.cc:146
double get_midlat(const double &, const double &)
Definition: RegionCache.cc:173
int find_lonbox(const int &, const double &, double *, double *, double *)
Definition: RegionCache.cc:83
constexpr double four_pi
Definition: piconst.h:28
static const int dim
Definition: RegionCache.h:26
static const double min_resol
Definition: RegionCache.h:27
std::vector< RegionCache * > VectorRegionCache
Definition: RegionCache.h:39
static const double sphere_area
Definition: RegionCache.h:28
Definition: ColumnInfo.h:23