bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
build_dmrpp.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
27#include <iostream>
28#include <sstream>
29#include <iterator>
30
31#include <unistd.h>
32#include <cstdlib>
33#include <libgen.h>
34
35#include <libdap/util.h>
36
37#include <TheBESKeys.h>
38#include <BESDebug.h>
39#include <BESError.h>
40#include <BESInternalFatalError.h>
41#include "build_dmrpp_util.h"
42
43using namespace std;
44using namespace libdap;
45using namespace dmrpp;
46using namespace build_dmrpp_util;
47
48#define DEBUG_KEY "metadata_store,dmrpp_store,dmrpp"
49
50void usage() {
51 const char *help = R"(
52 build_dmrpp -h: Show this help
53
54 build_dmrpp -V: Show build versions for components that make up the program
55
56 build_dmrpp -f <data file> -r <dmr file> [-u <href url>] [-c <bes conf file>] [-M] [-D] [-v] [-d]
57
58 options:
59 -f: HDF5 file to build DMR++ from
60 -r: DMR file to build DMR++ from
61 -u: The href value to use in the DMR++ for the data file
62 -c: The BES configuration file used to create the DMR file
63 -M: Add production metadata to the built DMR++
64 -D: Disable Direct IO feature
65 -h: Show this help
66 -v: Verbose HDF5 errors
67 -V: Show build versions for components that make up the program
68 -d: Turn on BES software debugging output)";
69
70 cerr << help << endl;
71}
72
79int main(int argc, char *argv[]) {
80 string h5_file_name;
81 string h5_dset_path;
82 string dmr_filename;
83 string dmrpp_href_value;
84 string bes_conf_file_used_to_create_dmr;
85 bool add_production_metadata = false;
86 bool disable_dio = false;
87
88 int option_char;
89 while ((option_char = getopt(argc, argv, "c:f:r:u:dhvVMD")) != -1) {
90 switch (option_char) {
91 case 'V':
92 cerr << basename(argv[0]) << "-" << CVER << " (bes-"<< CVER << ", " << libdap_name() << "-"
93 << libdap_version() << ")" << endl;
94 exit(EXIT_SUCCESS);
95
96 case 'h':
97 usage();
98 exit(EXIT_FAILURE);
99
100 case 'v':
101 build_dmrpp_util::verbose = true; // verbose hdf5 errors
102 break;
103
104 case 'd':
105 BESDebug::SetUp(string("cerr,").append(DEBUG_KEY));
106 break;
107
108 case 'f':
109 h5_file_name = optarg;
110 break;
111
112 case 'r':
113 dmr_filename = optarg;
114 break;
115
116 case 'u':
117 dmrpp_href_value = optarg;
118 break;
119
120 case 'c':
121 bes_conf_file_used_to_create_dmr = optarg;
122 break;
123
124 case 'M':
125 add_production_metadata = true;
126 break;
127
128 case 'D':
129 disable_dio = true;
130 break;
131
132 default:
133 break;
134 }
135 }
136
137 try {
138 // Check to see if the file is hdf5 compliant
139 qc_input_file(h5_file_name);
140
141 if (dmr_filename.empty()) {
142 stringstream msg;
143 msg << "A DMR file for the granule '" << h5_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 build_dmrpp_from_dmr_file(
149 dmrpp_href_value,
150 dmr_filename,
151 h5_file_name,
152 add_production_metadata,
153 bes_conf_file_used_to_create_dmr,
154 disable_dio,
155 argc, argv);
156 }
157 catch (const BESError &e) {
158 cerr << "ERROR Caught BESError. message: " << e.get_message() << endl;
159 return EXIT_FAILURE;
160 }
161 catch (const std::exception &e) {
162 cerr << "ERROR Caught std::exception. what: " << e.what() << endl;
163 return EXIT_FAILURE;
164 }
165 catch (...) {
166 cerr << "ERROR Caught Unknown Error." << endl;
167 return EXIT_FAILURE;
168 }
169
170 return EXIT_SUCCESS;
171}
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