OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
dim_mgr.hpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <cstring>
3 using namespace std;
4 #include <vector>
5 #include <valarray>
6 #include <math.h>
7 
8 /* set the structure set - just use the non-OO versions - maybe they'll change
9 */
10 /* define characteristics for each dimension */
12  {
13  int32_t nvals; /* # values in this grid dim */
14  double min; /* min and max of this dim */
15  double max;
16  double delta; // if evenly distributed, type 0, point separation
17  int32_t type; /* type of vals along dim: 0 - evenly distrib, 1 - custom */
18  double *dim_coords; /* if type = 1, an array of the grid point values */
19  };
20 
21 /* data info structure - one for each data group of any # dimensions */
23  {
24  int32_t n_intervals; /* # of bottom intervals pointing to this data */
25  int32_t dat_status; /* status of this data point: -1 - not set yet,
26  0 - no data available, 1 - data is there */
27  int32_t *ix_arr; /* size n_dim array of indicies for this point */
28  void *dat; /* points to the data storage area */
29  };
30 
32  {
33  int32_t access_id; /* A 'last time of reference' index for this interval
34  if it is a bottom interval - identifies old
35  intervals that haven't been used before a certain
36  value */
37  int32_t dat_filled; /* status of the data pointed to: 0 - not filled,
38  1 - filled */
40  };
41 
42 // the hash_entry_struc is the hash table item for a managed intervals
44  {
45  valarray<int> ix_arr;
47  };
48 
49 // Similarly, the grid point hash table item is a convenient way to get
50 // to the individual grid points
52  {
53  valarray<int> ix_arr;
55  };
56 
57  // The pt_info_struc is a convenient collector for the info about a
58  // found point, and it keeps all that together. We'll have the
59  // caller set up the storage for it
61  {
62  int32_t interval_needs_data; // flag saying the interval needs data
63  int32_t *pt_status; // point status for the 2^ndim corner points:
64  // -1 - not set yet, 0 - no data
65  // available, 1 - data is there
66  int32_t *pt_base_loc; // size ndim base location of the found point in
67  // the grid
68  double *wt; // weight for each dimension
69  double *wt_pt; // size 2^ndim weight for that point
70  void **dat_ptrs; // size 2^ndim pointers to the data blobs for that
71  // corner
72  };
73 
74 /* Looks like declaring the classes here is best, with defining in the
75  .cpp of the same name - I don't like separating the implementation from
76  the definition, but it seems the only way if you have multi-file
77  programs
78 */
79 class dim_mgr {
80  public:
81  // 2 different constructors
82  dim_mgr(int32_t);
83  dim_mgr(int32_t, int32_t);
84  // just 1 destructor
85  ~dim_mgr();
86  // for init of dims
87  int32_t init_dim( int32_t, int32_t, double * );
88  int32_t init_dim( int32_t, int32_t, double, double );
89  // for setting the data blob address
90  void set_store( void *, int32_t );
91  void update_new_data( );
92  // for the getting of the point and recording it in the table
93  pt_info_struc * mng_pt( double *, int32_t, int32_t * );
94  // to clear all point entries or selected ones
95  int32_t purge();
96  int32_t prune(int32_t);
97 
98  // info getting
99  void dump_last_interval();
100  void dump_mgr( double * );
101 
102  // manage total # data blobs
103  int32_t get_ndim();
104  int32_t get_hdim();
105  void add_pts( int32_t );
106  int32_t get_tot_blobs();
107 
108  private:
109  // helper for the constructors
110  void const_hlp(int32_t);
111  // other routines
112  // help for mng_pt
113  int32_t sparse_get_loc( dim_info_struc **, int32_t, double *,
114  int32_t *, double *, double * );
115  interval_struc *access( valarray<int>&, int32_t );
116  int32_t gpt_add( valarray<int>, data_info_struc * );
117  int hash_func(valarray<int>, int32_t );
118  int32_t share_gpt( interval_struc *, int32_t * );
119  void dump_interval( interval_struc * );
120 
121  // remember prior state of point sent in to look for and search status
122  double old_pt[10] = { NAN };
123  int32_t old_status = 2;
124  // for hash table
125  int32_t hash_tbl_siz;
126  int32_t hash_h_mult, hash_ifirst = 0;
127 
128  int32_t ndim, n_tot_dat_blobs;
129  pt_info_struc pt_info;
130  interval_struc *prev_int; // remember the previous interval here
131  dim_info_struc **dim_info;
132  vector <hash_entry_struc> *hash_tbl; // array of vectors for each hash
133  // table entry
134  vector <gpt_hash_struc> *gpt_hash_tbl; // Similar to above but for the
135  // grid points
136 
137  };
138 // The non-member function declarations
139  int32_t linear_to_offset( int32_t, int32_t, int32_t * );
void ** dat_ptrs
Definition: dim_mgr.hpp:70
int32_t n_intervals
Definition: dim_mgr.hpp:24
double min
Definition: dim_mgr.hpp:14
double * wt
Definition: dim_mgr.hpp:68
valarray< int > ix_arr
Definition: dim_mgr.hpp:45
data_info_struc ** dat_info
Definition: dim_mgr.hpp:39
int32_t access_id
Definition: dim_mgr.hpp:33
valarray< int > ix_arr
Definition: dim_mgr.hpp:53
double * wt_pt
Definition: dim_mgr.hpp:69
int32_t * pt_status
Definition: dim_mgr.hpp:63
data_info_struc * dat_info
Definition: dim_mgr.hpp:54
int32_t nvals
Definition: dim_mgr.hpp:13
double * dim_coords
Definition: dim_mgr.hpp:18
int32_t type
Definition: dim_mgr.hpp:17
int32_t * ix_arr
Definition: dim_mgr.hpp:27
Definition: dim_mgr.hpp:43
int32_t interval_needs_data
Definition: dim_mgr.hpp:62
int32_t dat_status
Definition: dim_mgr.hpp:25
int32_t linear_to_offset(int32_t, int32_t, int32_t *)
Definition: dim_mgr.cpp:1010
double max
Definition: dim_mgr.hpp:15
int32_t dat_filled
Definition: dim_mgr.hpp:37
int32_t * pt_base_loc
Definition: dim_mgr.hpp:66
interval_struc * int_str
Definition: dim_mgr.hpp:46
double delta
Definition: dim_mgr.hpp:16