OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
HE2CF.h
Go to the documentation of this file.
1 // This file is part of the hdf4 data handler for the OPeNDAP data server.
3 // Copyright (c) 2010-2012 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 "debug.h"
35 #include "DAS.h"
36 #include "HDFCFUtil.h"
37 
38 
39 using namespace std;
40 using namespace libdap;
41 
42 
57 class HE2CF
58 {
59 
60  private:
61 
62  DAS* das;
63 
64  // SDStart ID
65  int32 sd_id;
66 
67  // Hopen ID
68  int32 file_id;
69 
70  // Number of global attributes
71  int32 num_global_attributes;
72 
73  // ECS metadata
74  string metadata;
75 
76  // group name
77  string gname;
78 
79  // Store all metadata names.
80  // Not an ideal approach, need to re-visit later. KY 2012-6-11
81  vector<string> eosmetadata_namelist;
82 
83  // SDS name to SDS id
84  map < string, int32 > vg_sd_map;
85 
86  // vdata name to vdata id
87  map < string, int32 > vg_vd_map;
88 
89  // Add metadata_name to the metadata name list.
90  void set_eosmetadata_namelist(const string &metadata_name)
91  {
92  eosmetadata_namelist.push_back(metadata_name);
93  }
94 
95  // Is this EOS metadata
96  bool is_eosmetadata(const string& metadata_name) {
97  return (find(eosmetadata_namelist.begin(),eosmetadata_namelist.end(),metadata_name) !=eosmetadata_namelist.end());
98  }
99 
100  // Get HDF-EOS2 "Data Fields" and "Geolocation Fields" group object tag and object reference numbers.
101  bool get_vgroup_field_refids(const string& _gname, int32* _ref_df, int32* _ref_gf);
102 
103  // Open SD
104  bool open_sd(const string& filename,const int sd_id);
105 
106  // Open vgroup
107  bool open_vgroup(const string& filename,const int fileid);
108 
109  // Combine ECS metadata coremetadata.0, coremetadata.1 etc. into one string.
110  bool set_metadata(const string& metadataname,vector<string>&non_num_names, vector<string>&non_num_data);
111 
112  // This routine will generate three ECS metadata lists. Note in theory list sl1 and sl2 should be sorted.
113  // Since the ECS metadata is always written(sorted) in increasing numeric order, we don't perform this now.
114  // Should watch if there are any outliers.
115  void arrange_list(list<string> & sl1, list<string>&sl2,vector<string>&v1,string name,int& flag);
116 
117  // Obtain SD attribute value
118  void obtain_SD_attr_value(const string &,string&);
119 
120  // Create SDS name to SDS ID and Vdata name to vdata ID maps.
121  bool set_vgroup_map(int32 refid);
122 
123  // Write the long_name attribute.
124  bool write_attr_long_name(const string& long_name,
125  const string& varname,
126  int fieldtype);
127  bool write_attr_long_name(const string& group_name,
128  const string& long_name,
129  const string& varname,
130  int fieldtype);
131 
132  // Write the SD attribute.
133  bool write_attr_sd(int32 sds_id, const string& newfname);
134 
135  // Write the Vdata attribute.
136  bool write_attr_vdata(int32 vd_id, const string& newfname);
137  void throw_error(string _error);
138 
139  public:
140  HE2CF();
141  virtual ~HE2CF();
142 
144  bool close();
145 
147  string get_metadata(const string& metadataname,bool&suffix_is_num,vector<string>&non_num_names, vector<string>&non_num_data);
148  bool set_non_ecsmetadata_attrs();
149 
151  bool open(const string& filename,const int sd_id, const int file_id);
152 
154  void set_DAS(DAS* das);
155 
158  bool write_attribute(const string& gname,
159  const string& fname,
160  const string& newfname,
161  int n_groups,
162  int fieldtype);
163 
168  bool write_attribute_FillValue(const string& varname, int type, float val);
169 
174  bool write_attribute_coordinates(const string& varname, string coord);
175 
179  bool write_attribute_units(const string& varname, string units);
180 
181 };
182 
183 
184 #endif
A class for writing attributes from an HDF-EOS2 file.
Definition: HE2CF.h:57
STL namespace.
static class NCMLUtil overview