From 14de1035ad1825dcb9343c779ffbaaddaa281144 Mon Sep 17 00:00:00 2001
From: Norbert Podhorszki <pnorbert@ornl.gov>
Date: Wed, 2 Aug 2017 11:45:13 -0400
Subject: [PATCH] templatize PrintData() so that it can work with all types

---
 examples/heatTransfer/read/CMakeLists.txt |  4 +-
 examples/heatTransfer/read/PrintData.cpp  | 93 -----------------------
 examples/heatTransfer/read/PrintData.h    | 45 ++++++++++-
 3 files changed, 44 insertions(+), 98 deletions(-)
 delete mode 100644 examples/heatTransfer/read/PrintData.cpp

diff --git a/examples/heatTransfer/read/CMakeLists.txt b/examples/heatTransfer/read/CMakeLists.txt
index 5691e81b4..d1b7e2853 100644
--- a/examples/heatTransfer/read/CMakeLists.txt
+++ b/examples/heatTransfer/read/CMakeLists.txt
@@ -10,7 +10,7 @@ if(ADIOS2_HAVE_MPI)
     find_package(MPI COMPONENTS C REQUIRED)
     find_package(ADIOS1 REQUIRED)
     
-    add_executable(heatTransfer_read_adios2 heatRead_adios2.cpp PrintData.cpp)
+    add_executable(heatTransfer_read_adios2 heatRead_adios2.cpp PrintData.h)
     target_include_directories(heatTransfer_read_adios2
       PRIVATE ${MPI_C_INCLUDE_PATH}
     )
@@ -18,7 +18,7 @@ if(ADIOS2_HAVE_MPI)
       adios2 ${MPI_C_LIBRARIES}
     )
 
-    add_executable(heatTransfer_read_adios1 heatRead_adios1.cpp PrintData.cpp)
+    add_executable(heatTransfer_read_adios1 heatRead_adios1.cpp PrintData.h)
     target_include_directories(heatTransfer_read_adios1
       PRIVATE ${MPI_C_INCLUDE_PATH}
     )
diff --git a/examples/heatTransfer/read/PrintData.cpp b/examples/heatTransfer/read/PrintData.cpp
deleted file mode 100644
index edbc6688f..000000000
--- a/examples/heatTransfer/read/PrintData.cpp
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Distributed under the OSI-approved Apache License, Version 2.0.  See
- * accompanying file Copyright.txt for details.
- *
- * PrintData.cpp
- *
- *  Created on: Apr 2017
- *      Author: Norbert Podhorszki
- */
-
-#include <fstream>
-#include <iomanip>
-#include <iostream>
-#include <string>
-
-#include "PrintData.h"
-
-void printData(double *xy, size_t *size, size_t *offset, int rank, int steps)
-{
-    std::ofstream myfile;
-    std::string filename = "data." + std::to_string(rank);
-    myfile.open(filename);
-    double *data = xy;
-    uint64_t nelems = size[0] * size[1];
-    for (int step = 0; step < steps; step++)
-    {
-        myfile << "rank=" << rank << " size=" << size[0] << "x" << size[1]
-               << " offsets=" << offset[0] << ":" << offset[1]
-               << " step=" << step << std::endl;
-
-        myfile << " time   row   columns " << offset[1] << "..."
-               << offset[1] + size[1] - 1 << std::endl;
-        myfile << "        ";
-        for (int j = 0; j < size[1]; j++)
-        {
-            myfile << std::setw(9) << offset[1] + j;
-        }
-        myfile << std::endl;
-        myfile << "------------------------------------------------------------"
-                  "--\n";
-        for (int i = 0; i < size[0]; i++)
-        {
-            myfile << std::setw(5) << step << std::setw(5) << offset[0] + i;
-            for (int j = 0; j < size[1]; j++)
-            {
-                myfile << std::setw(9) << std::setprecision(2)
-                       << data[i * size[1] + j];
-            }
-            myfile << std::endl;
-        }
-        data += nelems;
-    }
-    myfile.close();
-}
-
-void printData(double *xy, uint64_t *size, uint64_t *offset, int rank,
-               int steps)
-{
-    std::ofstream myfile;
-    std::string filename = "data." + std::to_string(rank);
-    myfile.open(filename);
-    double *data = xy;
-    uint64_t nelems = size[0] * size[1];
-    for (int step = 0; step < steps; step++)
-    {
-        myfile << "rank=" << rank << " size=" << size[0] << "x" << size[1]
-               << " offsets=" << offset[0] << ":" << offset[1]
-               << " step=" << step << std::endl;
-
-        myfile << " time   row   columns " << offset[1] << "..."
-               << offset[1] + size[1] - 1 << std::endl;
-        myfile << "        ";
-        for (int j = 0; j < size[1]; j++)
-        {
-            myfile << std::setw(9) << offset[1] + j;
-        }
-        myfile << std::endl;
-        myfile << "------------------------------------------------------------"
-                  "--\n";
-        for (int i = 0; i < size[0]; i++)
-        {
-            myfile << std::setw(5) << step << std::setw(5) << offset[0] + i;
-            for (int j = 0; j < size[1]; j++)
-            {
-                myfile << std::setw(9) << std::setprecision(2)
-                       << data[i * size[1] + j];
-            }
-            myfile << std::endl;
-        }
-        data += nelems;
-    }
-    myfile.close();
-}
diff --git a/examples/heatTransfer/read/PrintData.h b/examples/heatTransfer/read/PrintData.h
index 13e1e527c..f18948af6 100644
--- a/examples/heatTransfer/read/PrintData.h
+++ b/examples/heatTransfer/read/PrintData.h
@@ -12,9 +12,48 @@
 #define PRINTDATA_H_
 
 #include <cstdint>
+#include <fstream>
+#include <iomanip>
+#include <iostream>
+#include <string>
 
-void printData(double *xy, size_t *size, size_t *offset, int rank, int steps);
-void printData(double *xy, uint64_t *size, uint64_t *offset, int rank,
-               int steps);
+template <class T>
+void printData(double *xy, T *size, T *offset, int rank, int steps)
+{
+    std::ofstream myfile;
+    std::string filename = "data." + std::to_string(rank);
+    myfile.open(filename);
+    double *data = xy;
+    uint64_t nelems = size[0] * size[1];
+    for (int step = 0; step < steps; step++)
+    {
+        myfile << "rank=" << rank << " size=" << size[0] << "x" << size[1]
+               << " offsets=" << offset[0] << ":" << offset[1]
+               << " step=" << step << std::endl;
+
+        myfile << " time   row   columns " << offset[1] << "..."
+               << offset[1] + size[1] - 1 << std::endl;
+        myfile << "        ";
+        for (int j = 0; j < size[1]; j++)
+        {
+            myfile << std::setw(9) << offset[1] + j;
+        }
+        myfile << std::endl;
+        myfile << "------------------------------------------------------------"
+                  "--\n";
+        for (int i = 0; i < size[0]; i++)
+        {
+            myfile << std::setw(5) << step << std::setw(5) << offset[0] + i;
+            for (int j = 0; j < size[1]; j++)
+            {
+                myfile << std::setw(9) << std::setprecision(2)
+                       << data[i * size[1] + j];
+            }
+            myfile << std::endl;
+        }
+        data += nelems;
+    }
+    myfile.close();
+}
 
 #endif /* PRINTDATA_H_ */
-- 
GitLab