From f6477a1a633eb5f5212da1d808268a1504cd596a Mon Sep 17 00:00:00 2001
From: Chuck Atkins <chuck.atkins@kitware.com>
Date: Thu, 22 Jun 2017 09:02:45 -0400
Subject: [PATCH] Pass a default config file for the experimental XML example

---
 .../runtimeconfig/hello/CMakeLists.txt        |  3 ++
 .../runtimeconfig/hello/helloBPWriterXML.cpp  | 34 +++++++++++++++++--
 .../hello/helloBPWriterXML_nompi.cpp          | 27 ++++++++++++++-
 3 files changed, 61 insertions(+), 3 deletions(-)

diff --git a/examples/experimental/runtimeconfig/hello/CMakeLists.txt b/examples/experimental/runtimeconfig/hello/CMakeLists.txt
index 794404e46..28adedce7 100644
--- a/examples/experimental/runtimeconfig/hello/CMakeLists.txt
+++ b/examples/experimental/runtimeconfig/hello/CMakeLists.txt
@@ -9,3 +9,6 @@ else()
 endif()
 
 target_link_libraries(helloBPWriterXML adios2)
+target_compile_definitions(helloBPWriterXML PRIVATE
+  -DDEFAULT_CONFIG=${CMAKE_CURRENT_SOURCE_DIR}/helloBPWriter.xml
+)
diff --git a/examples/experimental/runtimeconfig/hello/helloBPWriterXML.cpp b/examples/experimental/runtimeconfig/hello/helloBPWriterXML.cpp
index c367ce33d..dc34fa06e 100644
--- a/examples/experimental/runtimeconfig/hello/helloBPWriterXML.cpp
+++ b/examples/experimental/runtimeconfig/hello/helloBPWriterXML.cpp
@@ -17,6 +17,14 @@
 
 #include <adios2.h>
 
+#define str_helper(X) #X
+#define str(X) str_helper(X)
+
+#ifndef DEFAULT_CONFIG
+#define DEFAULT_CONFIG helloBPWriter.xml
+#endif
+#define DEFAULT_CONFIG_STR str(DEFAULT_CONFIG)
+
 int main(int argc, char *argv[])
 {
     MPI_Init(&argc, &argv);
@@ -24,6 +32,29 @@ int main(int argc, char *argv[])
     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
     MPI_Comm_size(MPI_COMM_WORLD, &size);
 
+    std::string configFile;
+    if (argc == 1)
+    {
+        configFile = DEFAULT_CONFIG_STR;
+    }
+    else if (argc == 2)
+    {
+        configFile = argv[1];
+    }
+    else
+    {
+        if (rank == 0)
+        {
+            std::cerr << "Usage: " << argv[0] << " [/path/to/config.xml]"
+                      << std::endl;
+        }
+        return 1;
+    }
+    if (rank == 0)
+    {
+        std::cout << "Using config file: " << configFile << std::endl;
+    }
+
     /** Application variable */
     std::vector<float> myFloats = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
     const std::size_t Nx = myFloats.size();
@@ -31,8 +62,7 @@ int main(int argc, char *argv[])
     try
     {
         /** ADIOS class factory of IO class objects, DebugON is recommended */
-        adios2::ADIOS adios("helloBPWriter.xml", MPI_COMM_WORLD,
-                            adios2::DebugON);
+        adios2::ADIOS adios(configFile, MPI_COMM_WORLD, adios2::DebugON);
 
         /*** IO class object: settings and factory of Settings: Variables,
          * Parameters, Transports, and Execution: Engines */
diff --git a/examples/experimental/runtimeconfig/hello/helloBPWriterXML_nompi.cpp b/examples/experimental/runtimeconfig/hello/helloBPWriterXML_nompi.cpp
index b2bea104f..50cf93e00 100644
--- a/examples/experimental/runtimeconfig/hello/helloBPWriterXML_nompi.cpp
+++ b/examples/experimental/runtimeconfig/hello/helloBPWriterXML_nompi.cpp
@@ -15,8 +15,33 @@
 
 #include <adios2.h>
 
+#define str_helper(X) #X
+#define str(X) str_helper(X)
+
+#ifndef DEFAULT_CONFIG
+#define DEFAULT_CONFIG helloBPWriter.xml
+#endif
+#define DEFAULT_CONFIG_STR str(DEFAULT_CONFIG)
+
 int main(int argc, char *argv[])
 {
+    std::string configFile;
+    if (argc == 1)
+    {
+        configFile = DEFAULT_CONFIG_STR;
+    }
+    else if (argc == 2)
+    {
+        configFile = argv[1];
+    }
+    else
+    {
+        std::cerr << "Usage: " << argv[0] << " [/path/to/config.xml]"
+                  << std::endl;
+        return 1;
+    }
+    std::cout << "Using config file: " << configFile << std::endl;
+
     /** Application variable */
     std::vector<float> myFloats = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
     const std::size_t Nx = myFloats.size();
@@ -24,7 +49,7 @@ int main(int argc, char *argv[])
     try
     {
         /** ADIOS class factory of IO class objects, DebugON is recommended */
-        adios2::ADIOS adios("helloBPWriter.xml", adios2::DebugON);
+        adios2::ADIOS adios(configFile, adios2::DebugON);
 
         /*** IO class object: settings and factory of Settings: Variables,
          * Parameters, Transports, and Execution: Engines */
-- 
GitLab