From e9244e0ee4817e31796acb5d4e28daf6cdee9e8b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Offringa?= <offringa@astron.nl>
Date: Thu, 2 Feb 2023 13:36:18 +0100
Subject: [PATCH] Reduce and correct LOBES warnings

---
 cpp/elementresponsefactory.cc     | 13 +++++++++----
 cpp/lobes/lobeselementresponse.cc |  4 ++--
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/cpp/elementresponsefactory.cc b/cpp/elementresponsefactory.cc
index 374bc825..ec576392 100644
--- a/cpp/elementresponsefactory.cc
+++ b/cpp/elementresponsefactory.cc
@@ -31,10 +31,15 @@ std::shared_ptr<const ElementResponse> ElementResponse::GetInstance(
       try {
         return LOBESElementResponse::GetInstance(name, options);
       } catch (const std::runtime_error& e) {
-        std::cout << "Creating LOBESElementResponse for station " << name
-                  << " failed because: " << std::endl;
-        std::cout << e.what() << std::endl;
-        std::cout << "Switching to HamakerElementResponse instead" << std::endl;
+        static bool first_time = true;
+        if (first_time) {
+          std::cout << "Creating LOBESElementResponse for station " << name
+                    << " failed because: \n"
+                    << e.what() << '\n'
+                    << "Switching to HamakerElementResponse instead. Further "
+                       "warnings of this type will be suppressed.\n";
+          first_time = false;
+        }
         return std::make_shared<HamakerElementResponse>(name);
       }
     default:
diff --git a/cpp/lobes/lobeselementresponse.cc b/cpp/lobes/lobeselementresponse.cc
index 94726135..83468a04 100644
--- a/cpp/lobes/lobeselementresponse.cc
+++ b/cpp/lobes/lobeselementresponse.cc
@@ -152,14 +152,14 @@ LOBESElementResponse::LOBESElementResponse(const std::string& name,
   H5::H5File h5file;
 
   if (!std::filesystem::exists(coeff_file_path)) {
-    throw std::runtime_error("LOBES coeffcients file: " +
+    throw std::runtime_error("LOBES coefficients file: " +
                              coeff_file_path.string() + " does not exists");
   }
 
   try {
     h5file.openFile(coeff_file_path.c_str(), H5F_ACC_RDONLY);
   } catch (const H5::FileIException& e) {
-    throw std::runtime_error("Could not open LOBES coeffcients file: " +
+    throw std::runtime_error("Could not open LOBES coefficients file: " +
                              coeff_file_path.string());
   }
 
-- 
GitLab