bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
FONcArray.h
1// FONcArray.h
2
3// This file is part of BES Netcdf File Out Module
4
5// Copyright (c) 2004,2005 University Corporation for Atmospheric Research
6// Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Lesser General Public
10// License as published by the Free Software Foundation; either
11// version 2.1 of the License, or (at your option) any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16// Lesser General Public 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 USA
21//
22// You can contact University Corporation for Atmospheric Research at
23// 3080 Center Green Drive, Boulder, CO 80301
24
25// (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
26// Please read the full copyright statement in the file COPYRIGHT_UCAR.
27//
28// Authors:
29// pwest Patrick West <pwest@ucar.edu>
30// jgarcia Jose Garcia <jgarcia@ucar.edu>
31
32#ifndef FONcArray_h_
33#define FONcArray_h_ 1
34
35#include <vector>
36#include <string>
37
38#include <netcdf.h>
39
40#include "FONcBaseType.h"
41
42class FONcDim;
43class FONcMap;
44
45namespace libdap {
46class BaseType;
47class Array;
48}
49
56class FONcArray: public FONcBaseType {
57private:
58 // The array being converted
59 libdap::Array *d_a = nullptr;
60 // The type of data stored in the array
61 nc_type d_array_type = NC_NAT;
62 // The number of dimensions to be stored in netcdf (if string, 2)
63 int d_ndims = 0;
64 // The actual number of dimensions of this array (if string, 1)
65 int d_actual_ndims = 0;
66 // The number of elements that will be stored in netcdf
67 size_t d_nelements = 1;
68 // The FONcDim dimensions to be used for this variable
69 std::vector<FONcDim *> d_dims;
70 // The netcdf dimension ids for this array from DAP4
71 std::vector<int> d4_dim_ids{};
72
73 std::vector<bool>use_d4_dim_ids;
74 std::vector<int> d4_rds_nums;
75
76 // The netcdf dimension ids for this array
77 std::vector<int> d_dim_ids{};
78 // The netcdf dimension sizes to be written
79 //size_t * d_dim_sizes; // changed int to size_t. jhrg 12.27.2011
80 std::vector<size_t> d_dim_sizes{};
81 // If string data, we need to do some comparison, so instead of
82 // reading it more than once, read it once and save here
83 // FIXME std::vector<std::string> d_str_data;
84
85 // If the array is already a map in a grid, then we don't want to
86 // define it or write it.
87 bool d_dont_use_it = false;
88
89 // Make this a vector<> jhrg 10/12/15
90 // The netcdf chunk sizes for each dimension of this array.
91 std::vector<size_t> d_chunksizes{};
92
93 // This is vector holds instances of FONcMap* that wrap existing Array
94 // objects that are pushed onto the global FONcGrid::Maps vector. These
95 // are hand made reference counting pointers. I'm not sure we need to
96 // store copies in this object, but it may be the case that without
97 // calling the FONcMap->decref() method they are not deleted. jhrg 8/28/13
98 std::vector<FONcMap*> d_grid_maps{};
99
100 // if DAP4 dim. is defined
101 bool d4_def_dim = false;
102
103#if 0
104 // direct io flag, used in the define mode,the default is false. It should be set to true when direct io is supported.
105 // TODO: This is for the temporary memory usage optimization. Once we can support the define() with or without dio for individual array.
106 // This flag is not necessary and should be removed. KY 11/29/23
107 bool farray_dio_flag = false;
108#endif
109
110
111 FONcDim * find_dim(const std::vector<std::string> &embed, const std::string &name, int64_t size, bool ignore_size = false);
112
113 // Used in write()
114 void write_for_nc4_types(int ncid);
115 void write_for_nc3_types(int ncid);
116 void write_nc_variable(int ncid, nc_type var_type);
117 static bool equal_length(vector<string> &the_strings);
118 void write_string_array(int ncid);
119 void write_equal_length_string_array(int ncid);
120
121 void define_dio_filters(int ncid, int d_varid);
122 void obtain_dio_filters_order(const string&,bool &,bool &, bool &, bool &, bool &) const;
123 void allocate_dio_nc4_def_filters(int, int, bool ,bool , bool , bool , bool, const vector<unsigned int> &) const;
124 void write_direct_io_data(int, int);
125
126 FONcArray() = default; // Used in some unit tests
127 friend class FONcArrayTest;
128
129public:
130 explicit FONcArray(libdap::BaseType *b);
131 FONcArray(libdap::BaseType *b, const std::vector<int>&dim_ids, const std::vector<bool>&use_dim_ids,
132 const std::vector<int>&rds_nums);
133 ~FONcArray() override;
134
135 virtual void convert(std::vector<std::string> embed, bool _dap4=false, bool is_dap4_group=false) override;
136 virtual void define(int ncid) override;
137 virtual void write(int ncid) override;
138
139 std::string name() override;
140
141 virtual libdap::Array *array() { return d_a; }
142
143 virtual void dump(std::ostream &strm) const override;
144
145 // The following code is to calcuate the maximum possible chunk size one can use for array.
146 // It is not used now. But keep it for the potential future use.
147#if 0
148 size_t obtain_max_chunk_size(size_t total_size, int m_num_chunks, int chunk_dim_size, int allowed_chunk_dim_size) {
149
150 int actual_num_chunks = total_size/(chunk_dim_size*chunk_dim_size);
151 if ((actual_num_chunks > m_num_chunks) && (chunk_dim_size < allowed_chunk_dim_size))
152 chunk_dim_size = obtain_max_chunk_size(total_size,m_num_chunks,2*chunk_dim_size,allowed_chunk_dim_size);
153 return chunk_dim_size;
154
155 }
156#endif
157 // The below line is not necessary. Still keep it here for the future use.
158 // KY 2021-05-25
159#if 0
160 virtual libdap::AttrType getAttrType(nc_type nct) override;
161#endif
162
163#if 0
164 // TODO: This is for the temporary memory usage optimization. Once we can support the define() with or without dio for individual array.
165 // The following methods are not necessary and should be removed. KY 11/29/23
166 bool get_dio_flag() const {return farray_dio_flag; }
167 void set_dio_flag(bool dio_flag_value = true) { farray_dio_flag = dio_flag_value; }
168#endif
169
170 static std::vector<FONcDim *> Dimensions;
171};
172
173#endif // FONcArray_h_
174
virtual void dump(std::ostream &strm) const override
dumps information about this object for debugging purposes
virtual void define(int ncid) override
define the DAP Array in the netcdf file
Definition FONcArray.cc:540
~FONcArray() override
Destructor that cleans up the array.
Definition FONcArray.cc:117
virtual void convert(std::vector< std::string > embed, bool _dap4=false, bool is_dap4_group=false) override
Converts the DAP Array to a FONcArray.
Definition FONcArray.cc:141
virtual void write(int ncid) override
Write the array out to the netcdf file.
Definition FONcArray.cc:859
std::string name() override
returns the name of the DAP Array
A class that represents the dimension of an array.
Definition FONcDim.h:45
A map of a DAP Grid with file out netcdf information included.
Definition FONcMap.h:52
STL class.