bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
build_dmrpp_h4.cc
1// -*- mode: c++; c-basic-offset:4 -*-
2
3// This file is part of the Hyrax data server.
4
5// Copyright (c) 2018 OPeNDAP, Inc.
6// Author: James Gallagher <jgallagher@opendap.org>
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 OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
23
24#include "config.h"
25
26#include <iostream>
27#include <sstream>
28#include <iterator>
29
30#include <unistd.h>
31#include <cstdlib>
32#include <libgen.h>
33
34#include <libdap/util.h>
35
36#include <TheBESKeys.h>
37#include <BESDebug.h>
38#include <BESError.h>
39#include <BESInternalFatalError.h>
40
41#include "build_dmrpp_util_h4.h"
42
43using namespace std;
44using namespace libdap;
45
46using namespace dmrpp;
47using namespace build_dmrpp_util_h4;
48
49
50#define DEBUG_KEY "metadata_store,dmrpp_store,dmrpp"
51
52void usage() {
53 const char *help = R"(
54 build_dmrpp -h: Show this help
55
56 build_dmrpp -V: Show build versions for components that make up the program
57
58 build_dmrpp -f <data file> -r <dmr file> [-u <href url>]: As above, but uses the DMR
59 read from the given file.
60
61 Other options:
62 -v: Verbose
63 -d: Turn on BES software debugging output
64 -M: Add information about the build_dmrpp software, incl versions, to the built DMR++
65 -D: Disable the generation of HDF-EOS2/HDF4 missing latitude/longitude)";
66
67 cerr << help << endl;
68}
69
76int main(int argc, char *argv[]) {
77 string h4_file_name;
78 string h4_dset_path;
79 string dmr_filename;
80 string dmrpp_href_value;
81 string bes_conf_file_used_to_create_dmr;
82 bool add_production_metadata = false;
83 bool disable_missing_data = false;
84
85 int option_char;
86 while ((option_char = getopt(argc, argv, "c:f:r:u:dhvVMD")) != -1) {
87 switch (option_char) {
88 case 'V':
89 cerr << basename(argv[0]) << "-" << CVER << " (bes-"<< CVER << ", " << libdap_name() << "-"
90 << libdap_version() << ")" << endl;
91 return 0;
92
93 case 'v':
94 build_dmrpp_util_h4::verbose = true; // verbose hdf5 errors
95 break;
96
97 case 'd':
98 BESDebug::SetUp(string("cerr,").append(DEBUG_KEY));
99 break;
100
101 case 'f':
102 h4_file_name = optarg;
103 break;
104
105 case 'r':
106 dmr_filename = optarg;
107 break;
108
109 case 'u':
110 dmrpp_href_value = optarg;
111 break;
112
113 case 'c':
114 bes_conf_file_used_to_create_dmr = optarg;
115 break;
116
117 case 'M':
118 add_production_metadata = true;
119 break;
120
121 case 'D':
122 disable_missing_data = true;
123 break;
124
125 case 'h':
126 usage();
127 exit(EXIT_FAILURE);
128
129 default:
130 break;
131 }
132 }
133
134#if 0
135 try {
136#endif
137
138 // Check to see if the file is hdf4 compliant
139 qc_input_file(h4_file_name);
140
141 if (dmr_filename.empty()){
142 stringstream msg;
143 msg << "A DMR file for the granule '" << h4_file_name << "' must also be provided." << endl;
144 throw BESInternalFatalError(msg.str(), __FILE__, __LINE__);
145 }
146
147 // Build the dmr++ from an existing DMR file.
148
149 build_dmrpp_from_dmr_file(
150 dmrpp_href_value,
151 dmr_filename,
152 h4_file_name,
153 add_production_metadata,
154 disable_missing_data,
155 bes_conf_file_used_to_create_dmr,
156 argc, argv);
157
158#if 0
159 string command = "./h4mapwriter/h4mapwriter " + h4_file_name;
160 system(command.c_str());
161#endif
162
163#if 0
164 }
165 catch (const BESError &e) {
166 cerr << "BESError: " << e.get_message() << endl;
167 return EXIT_FAILURE;
168 }
169 catch (const std::exception &e) {
170 cerr << "std::exception: " << e.what() << endl;
171 return EXIT_FAILURE;
172 }
173 catch (...) {
174 cerr << "Unknown error." << endl;
175 return EXIT_FAILURE;
176 }
177#endif
178
179 return EXIT_SUCCESS;
180}
static void SetUp(const std::string &values)
Sets up debugging for the bes.
Definition BESDebug.cc:91
Base exception class for the BES with basic string message.
Definition BESError.h:66
std::string get_message() const
get the error message for this exception
Definition BESError.h:132
exception thrown if an internal error is found and is fatal to the BES