Repository: OPENDAP/bes
Pull request #1099: HYRAX-1688,HYRAX-1756, remove the core dump and uncaught c++ exceptio…
Author: login: kyang2014
Created: 2025-05-22T13:45:03Z | Merged: 2025-05-22T20:08:34Z

…n when just typing build_dmrpp_h4. Also make the help description clear and accurate.


Diff:
diff --git a/modules/dmrpp_module/build_dmrpp_h4/build_dmrpp_h4.cc b/modules/dmrpp_module/build_dmrpp_h4/build_dmrpp_h4.cc
index e54bb0778f..a0c03b2dc1 100644
--- a/modules/dmrpp_module/build_dmrpp_h4/build_dmrpp_h4.cc
+++ b/modules/dmrpp_module/build_dmrpp_h4/build_dmrpp_h4.cc
@@ -51,18 +51,22 @@ using namespace build_dmrpp_util_h4;
 
 void usage() {
     const char *help = R"(
-    build_dmrpp -h: Show this help
+    build_dmrpp_h4 -h: Show this help
 
-    build_dmrpp -V: Show build versions for components that make up the program
+    build_dmrpp_h4 -V: Show build versions for components that make up the program
 
-    build_dmrpp -f <data file> -r <dmr file> [-u <href url>]: As above, but uses the DMR
-       read from the given file.
+    build_dmrpp_h4 -f <data file> -r <dmr file> [-u <href url>] [-M] [-D] [-v] [-V] [-d] 
 
-    Other options:
-        -v: Verbose
-        -d: Turn on BES software debugging output
-        -M: Add information about the build_dmrpp software, incl versions, to the built DMR++
-        -D: Disable the generation of HDF-EOS2/HDF4 missing latitude/longitude)";
+    options:
+        -f: HDF4/HDF-EOS2 file to build DMR++ from
+        -r: DMR file to build DMR++ from
+        -u: The href value to use in the DMR++ for the data file
+        -M: Add information about this software, incl versions, to the built DMR++
+        -D: Disable the generation of HDF-EOS2/HDF4 missing latitude/longitude
+        -h: Show this help
+        -v: Verbose information helpful for debugging and understanding the program working flow
+        -V: Show build versions for components that make up the program
+        -d: Turn on BES software debugging output)";
 
     cerr << help << endl;
 }
@@ -82,7 +86,7 @@ int main(int argc, char *argv[]) {
     bool add_production_metadata = false;
     bool disable_missing_data = false;
 
-    int option_char;
+    int option_char = -1;
     while ((option_char = getopt(argc, argv, "c:f:r:u:dhvVMD")) != -1) {
         switch (option_char) {
             case 'V':
@@ -131,50 +135,31 @@ int main(int argc, char *argv[]) {
         }
     }
 
-#if 0
-    try {
-#endif
+    // Check to see if the file is hdf4 compliant
+    if (h4_file_name.empty()) {
+        cerr << endl << "    The HDF4 file name must be provided with -f <h4_file_name> ." << endl;
+        usage();
+        return EXIT_FAILURE; 
 
-        // Check to see if the file is hdf4 compliant
-        qc_input_file(h4_file_name);
-
-        if (dmr_filename.empty()){
-            stringstream msg;
-            msg << "A DMR file for the granule '" << h4_file_name << "' must also be provided." << endl;
-            throw BESInternalFatalError(msg.str(), __FILE__, __LINE__);
-        }
-
-        // Build the dmr++ from an existing DMR file.
-
-        build_dmrpp_from_dmr_file(
-                dmrpp_href_value,
-                dmr_filename,
-                h4_file_name,
-                add_production_metadata,
-                disable_missing_data,
-                bes_conf_file_used_to_create_dmr,
-                argc,  argv);
-
-#if 0
-        string command = "./h4mapwriter/h4mapwriter " + h4_file_name;
-        system(command.c_str());
-#endif
-
-#if 0
     }
-    catch (const BESError &e) {
-        cerr << "BESError: " << e.get_message() << endl;
-        return EXIT_FAILURE;
-    }
-    catch (const std::exception &e) {
-        cerr << "std::exception: " << e.what() << endl;
-        return EXIT_FAILURE;
-    }
-    catch (...) {
-        cerr << "Unknown error." << endl;
+    qc_input_file(h4_file_name);
+
+    if (dmr_filename.empty()){
+        cerr << endl <<"    A DMR file for the granule '" << h4_file_name << "' must also be provided with -r <h4_dmrpp_file_name> ." << endl;
+        usage();
         return EXIT_FAILURE;
     }
-#endif
+
+    // Build the dmr++ from an existing DMR file.
+    build_dmrpp_from_dmr_file(
+            dmrpp_href_value,
+            dmr_filename,
+            h4_file_name,
+            add_production_metadata,
+            disable_missing_data,
+            bes_conf_file_used_to_create_dmr,
+            argc,  argv);
+
 
     return EXIT_SUCCESS;
 }
diff --git a/modules/dmrpp_module/build_dmrpp_h4/build_dmrpp_util_h4.cc b/modules/dmrpp_module/build_dmrpp_h4/build_dmrpp_util_h4.cc
index d550be81e9..6cc430d1fa 100644
--- a/modules/dmrpp_module/build_dmrpp_h4/build_dmrpp_util_h4.cc
+++ b/modules/dmrpp_module/build_dmrpp_h4/build_dmrpp_util_h4.cc
@@ -1534,14 +1534,6 @@ void add_chunk_information(const string &h4_file_name, DMRpp *dmrpp, bool disabl
  */
 void qc_input_file(const string &file_fqn)
 {
-    //Use an ifstream file to run a check on the provided file's signature
-    // to see if it is an HDF4 file. - kln 11/20/23
-
-    if (file_fqn.empty()) {
-        stringstream msg;
-        msg << "HDF4 input file name must be provided (-f <input>) and be a fully qualified path name." << endl;
-        throw BESInternalFatalError(msg.str(), __FILE__, __LINE__);
-    }
 
     std::ifstream file(file_fqn, ios::binary);
     auto errnum = errno;


Reviews:
user: login: jgallagher59701
body: I think these two changes are needed, but it's easy to not see some things in a diff.

Thanks for fixing this info up.
state: APPROVED
author_association: MEMBER
submitted_at: 2025-05-22T19:49:49Z
user: login: kyang2014
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-05-22T20:07:32Z
user: login: kyang2014
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-05-22T20:08:17Z

Review comments:
diff_hunk: @@ -51,18 +51,22 @@ using namespace build_dmrpp_util_h4;
 
 void usage() {
     const char *help = R"(
-    build_dmrpp -h: Show this help
+    build_dmrpp_h4 -h: Show this help
 
-    build_dmrpp -V: Show build versions for components that make up the program
+    build_dmrpp_h4 -V: Show build versions for components that make up the program
 
-    build_dmrpp -f <data file> -r <dmr file> [-u <href url>]: As above, but uses the DMR
-       read from the given file.
+    build_dmrpp_h4 -f <data file> -r <dmr file> [-u <href url>] [-M] [-D] [-v] [-V] [-d] 
 
-    Other options:
-        -v: Verbose
-        -d: Turn on BES software debugging output
-        -M: Add information about the build_dmrpp software, incl versions, to the built DMR++
-        -D: Disable the generation of HDF-EOS2/HDF4 missing latitude/longitude)";
+    options:
+        -f: HDF4/HDF-EOS2 file to build DMR++ from
+        -r: DMR file to build DMR++ from
+        -u: The href value to use in the DMR++ for the data file
+        -M: Add information about this software, incl versions, to the built DMR++
+        -D: Disable the generation of HDF-EOS2/HDF4 missing latitude/longitude
+        -h: Show this help
+        -v: Verbose information helpful for debugging and understanding the program working flow
+        -V: Show build versions for components that make up the program
+        -d: Turn on BES software debugging output)";
path: modules/dmrpp_module/build_dmrpp_h4/build_dmrpp_h4.cc
user: login: jgallagher59701
body: There is an extra ')' at the end of the text on this line.
created_at: 2025-05-22T19:46:41Z
author_association: MEMBER
diff_hunk: @@ -51,18 +51,22 @@ using namespace build_dmrpp_util_h4;
 
 void usage() {
     const char *help = R"(
-    build_dmrpp -h: Show this help
+    build_dmrpp_h4 -h: Show this help
 
-    build_dmrpp -V: Show build versions for components that make up the program
+    build_dmrpp_h4 -V: Show build versions for components that make up the program
 
-    build_dmrpp -f <data file> -r <dmr file> [-u <href url>]: As above, but uses the DMR
-       read from the given file.
+    build_dmrpp_h4 -f <data file> -r <dmr file> [-u <href url>] [-M] [-D] [-v] [-V] [-d] 
path: modules/dmrpp_module/build_dmrpp_h4/build_dmrpp_h4.cc
user: login: jgallagher59701
body: I think there should be a vertical bar between "-f <data file> -r <dmr file>" like "-f <data file> | -r <dmr file>" although I'm not 100% certain.
created_at: 2025-05-22T19:48:41Z
author_association: MEMBER
diff_hunk: @@ -51,18 +51,22 @@ using namespace build_dmrpp_util_h4;
 
 void usage() {
     const char *help = R"(
-    build_dmrpp -h: Show this help
+    build_dmrpp_h4 -h: Show this help
 
-    build_dmrpp -V: Show build versions for components that make up the program
+    build_dmrpp_h4 -V: Show build versions for components that make up the program
 
-    build_dmrpp -f <data file> -r <dmr file> [-u <href url>]: As above, but uses the DMR
-       read from the given file.
+    build_dmrpp_h4 -f <data file> -r <dmr file> [-u <href url>] [-M] [-D] [-v] [-V] [-d] 
 
-    Other options:
-        -v: Verbose
-        -d: Turn on BES software debugging output
-        -M: Add information about the build_dmrpp software, incl versions, to the built DMR++
-        -D: Disable the generation of HDF-EOS2/HDF4 missing latitude/longitude)";
+    options:
+        -f: HDF4/HDF-EOS2 file to build DMR++ from
+        -r: DMR file to build DMR++ from
+        -u: The href value to use in the DMR++ for the data file
+        -M: Add information about this software, incl versions, to the built DMR++
+        -D: Disable the generation of HDF-EOS2/HDF4 missing latitude/longitude
+        -h: Show this help
+        -v: Verbose information helpful for debugging and understanding the program working flow
+        -V: Show build versions for components that make up the program
+        -d: Turn on BES software debugging output)";
path: modules/dmrpp_module/build_dmrpp_h4/build_dmrpp_h4.cc
user: login: kyang2014
body: That ) has to be there for the raw string literal to work.
created_at: 2025-05-22T20:07:32Z
author_association: COLLABORATOR
diff_hunk: @@ -51,18 +51,22 @@ using namespace build_dmrpp_util_h4;
 
 void usage() {
     const char *help = R"(
-    build_dmrpp -h: Show this help
+    build_dmrpp_h4 -h: Show this help
 
-    build_dmrpp -V: Show build versions for components that make up the program
+    build_dmrpp_h4 -V: Show build versions for components that make up the program
 
-    build_dmrpp -f <data file> -r <dmr file> [-u <href url>]: As above, but uses the DMR
-       read from the given file.
+    build_dmrpp_h4 -f <data file> -r <dmr file> [-u <href url>] [-M] [-D] [-v] [-V] [-d] 
path: modules/dmrpp_module/build_dmrpp_h4/build_dmrpp_h4.cc
user: login: kyang2014
body: No, there should be no vertical bar. Just -f -r.
created_at: 2025-05-22T20:08:17Z
author_association: COLLABORATOR

PR comments:
user: login: sonarqubecloud[bot]
created_at: 2025-05-22T15:18:44Z
body: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=opendap-bes-submodules&pullRequest=1099) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=opendap-bes-submodules&pullRequest=1099&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=opendap-bes-submodules&pullRequest=1099&issueStatuses=ACCEPTED)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=opendap-bes-submodules&pullRequest=1099&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=opendap-bes-submodules&pullRequest=1099&metric=new_coverage&view=list)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=opendap-bes-submodules&pullRequest=1099&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=opendap-bes-submodules&pullRequest=1099)


author_association: NONE
user: login: sonarqubecloud[bot]
created_at: 2025-05-22T15:19:04Z
body: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=opendap-bes&pullRequest=1099) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=opendap-bes&pullRequest=1099&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=opendap-bes&pullRequest=1099&issueStatuses=ACCEPTED)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=opendap-bes&pullRequest=1099&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=opendap-bes&pullRequest=1099&metric=new_coverage&view=list)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=opendap-bes&pullRequest=1099&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=opendap-bes&pullRequest=1099)


author_association: NONE
user: login: sonarqubecloud[bot]
created_at: 2025-05-22T15:19:30Z
body: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=opendap-bes-modules&pullRequest=1099) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=opendap-bes-modules&pullRequest=1099&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=opendap-bes-modules&pullRequest=1099&issueStatuses=ACCEPTED)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=opendap-bes-modules&pullRequest=1099&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=opendap-bes-modules&pullRequest=1099&metric=new_coverage&view=list)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=opendap-bes-modules&pullRequest=1099&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=opendap-bes-modules&pullRequest=1099)


author_association: NONE