bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
HE2CF.h
1
2// This file is part of the hdf4 data handler for the OPeNDAP data server.
3// Copyright (c) The HDF Group
4//
5// Author: Hyo-Kyung Lee <hyoklee@hdfgroup.org>
6//
7// This is free software; you can redistribute it and/or modify it under the
8// terms of the GNU Lesser General Public License as published by the Free
9// Software Foundation; either version 2.1 of the License, or (at your
10// option) any later version.
11//
12// This software is distributed in the hope that it will be useful, but
13// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15// License for more details.
16//
17// You should have received a copy of the GNU Lesser General Public License
18// along with this software; if not, write to the Free Software Foundation,
19// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20//
21// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
23#ifndef _HE2CF_H_
24#define _HE2CF_H_
25
26#include <mfhdf.h>
27#include <hdf.h>
28//#include <HdfEosDef.h>
29#include <iostream>
30#include <sstream>
31#include <vector>
32#include <map>
33#include <algorithm>
34#include <libdap/debug.h>
35#include <libdap/DAS.h>
36#include "HDFCFUtil.h"
37
38
53class HE2CF
54{
55
56 private:
57
58 libdap::DAS* das = nullptr;
59
60 // SDStart ID
61 int32 sd_id = -1;
62
63 // Hopen ID
64 int32 file_id = -1;
65
66 // Number of global attributes
67 int32 num_global_attributes = -1;
68
69 // ECS metadata
70 std::string metadata;
71
72 // group name
73 std::string gname;
74
75 // Store all metadata names.
76 // Not an ideal approach, need to re-visit later. KY 2012-6-11
77 std::vector<std::string> eosmetadata_namelist;
78
79 // Data field SDS name to SDS id
80 std::map < std::string, int32 > vg_dsd_map;
81
82 // Data field vdata name to vdata id
83 std::map < std::string, int32 > vg_dvd_map;
84
85 // Geolocation field SDS name to SDS id
86 std::map < std::string, int32 > vg_gsd_map;
87
88 // Geolocation field vdata name to vdata id
89 std::map < std::string, int32 > vg_gvd_map;
90
91 // Add metadata_name to the metadata name list.
92 void set_eosmetadata_namelist(const std::string &metadata_name)
93 {
94 eosmetadata_namelist.push_back(metadata_name);
95 }
96
97 // Is this EOS metadata
98 bool is_eosmetadata(const std::string& metadata_name) {
99 return (std::find(eosmetadata_namelist.begin(),eosmetadata_namelist.end(),metadata_name) !=eosmetadata_namelist.end());
100 }
101
102 // Get HDF-EOS2 "Data Fields" and "Geolocation Fields" group object tag and object reference numbers.
103 bool get_vgroup_field_refids(const std::string& _gname, int32* _ref_df, int32* _ref_gf);
104
105 // Open SD
106 bool open_sd(const std::string& filename,const int sd_id);
107
108 // Open vgroup
109 bool open_vgroup(const std::string& filename,const int fileid);
110
111 // Combine ECS metadata coremetadata.0, coremetadata.1 etc. into one string.
112 bool set_metadata(const std::string& metadataname,std::vector<std::string>&non_num_names, std::vector<std::string>&non_num_data);
113
114 // This routine will generate three ECS metadata lists. Note in theory list sl1 and sl2 should be sorted.
115 // Since the ECS metadata is always written(sorted) in increasing numeric order, we don't perform this now.
116 // Should watch if there are any outliers.
117 void arrange_list(std::list<std::string> & sl1, std::list<std::string>&sl2,std::vector<std::string>&v1,const std::string & name,int& flag) const;
118
119 // Obtain SD attribute value
120 void obtain_SD_attr_value(const std::string &,std::string&) const;
121
122 // Create SDS name to SDS ID and Vdata name to vdata ID maps.
123 bool set_vgroup_map(int32 refid,bool isgeo);
124
125 // Write the long_name attribute.
126 bool write_attr_long_name(const std::string& long_name,
127 const std::string& varname,
128 int fieldtype);
129 bool write_attr_long_name(const std::string& group_name,
130 const std::string& long_name,
131 const std::string& varname,
132 int fieldtype);
133
134 // Write the SD attribute.
135 bool write_attr_sd(int32 sds_id, const std::string& newfname,int fieldtype);
136
138 short check_scale_offset(int32 sds_id, bool is_scale);
139
140
141 // Write the Vdata attribute.
142 bool write_attr_vdata(int32 vd_id, const std::string& newfname,int fieldtype);
143 void throw_error(const std::string &_error);
144
145 public:
146 HE2CF();
147 virtual ~HE2CF();
148
150 bool close();
151
153 string get_metadata(const std::string& metadataname,bool&suffix_is_num,std::vector<std::string>&non_num_names, std::vector<std::string>&non_num_data);
154 bool set_non_ecsmetadata_attrs();
155
157 bool open(const std::string& filename,const int sd_id, const int file_id);
158
160 void set_DAS(libdap::DAS* das);
161
164 bool write_attribute(const std::string& gname,
165 const std::string& fname,
166 const std::string& newfname,
167 int n_groups,
168 int fieldtype);
169
174 bool write_attribute_FillValue(const std::string& varname, int type, float val);
175
180 bool write_attribute_coordinates(const std::string& varname, const std::string& coord);
181
185 bool write_attribute_units(const std::string& varname, const std::string& units);
186
187
188};
189
190
191#endif
bool open(const std::string &filename, const int sd_id, const int file_id)
openes \afilename HDF4 file.
Definition HE2CF.cc:943
string get_metadata(const std::string &metadataname, bool &suffix_is_num, std::vector< std::string > &non_num_names, std::vector< std::string > &non_num_data)
retrieves the merged metadata.
Definition HE2CF.cc:936
bool write_attribute(const std::string &gname, const std::string &fname, const std::string &newfname, int n_groups, int fieldtype)
Definition HE2CF.cc:973
bool write_attribute_coordinates(const std::string &varname, const std::string &coord)
Definition HE2CF.cc:1134
void set_DAS(libdap::DAS *das)
sets DAS pointer so that we can bulid attribute tables.
Definition HE2CF.cc:181
bool close()
closes the opened file.
Definition HE2CF.cc:920
bool write_attribute_units(const std::string &varname, const std::string &units)
Definition HE2CF.cc:1147
bool write_attribute_FillValue(const std::string &varname, int type, float val)
Definition HE2CF.cc:1040