From ee8ca0230cc99d721e09f45110a980a7ea71472e Mon Sep 17 00:00:00 2001
From: Giovanni La Mura <giovanni.lamura@inaf.it>
Date: Fri, 26 Jan 2024 12:26:29 +0100
Subject: [PATCH] Implement HDF5 I/O for cluster case Transition Matrix

---
 src/cluster/Makefile    |  4 ++--
 src/cluster/cluster.cpp | 15 ++++++++++++---
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/cluster/Makefile b/src/cluster/Makefile
index 49e2fe59..1193c17e 100644
--- a/src/cluster/Makefile
+++ b/src/cluster/Makefile
@@ -11,8 +11,8 @@ clu: clu.o
 edfb_clu: edfb_clu.o
 	$(FC) $(FCFLAGS) -o $(BUILDDIR)/edfb_clu $(BUILDDIR)/edfb_clu.o $(LDFLAGS)
 
-np_cluster: $(BUILDDIR)/np_cluster.o $(BUILDDIR)/Commons.o $(BUILDDIR)/Configuration.o $(BUILDDIR)/file_io.o $(BUILDDIR)/Parsers.o $(BUILDDIR)/sph_subs.o $(BUILDDIR)/clu_subs.o $(BUILDDIR)/cluster.o
-	$(CXX) $(CXXFLAGS) -o $(BUILDDIR)/np_cluster $(BUILDDIR)/np_cluster.o $(BUILDDIR)/Commons.o $(BUILDDIR)/Configuration.o $(BUILDDIR)/file_io.o $(BUILDDIR)/Parsers.o $(BUILDDIR)/sph_subs.o $(BUILDDIR)/clu_subs.o $(BUILDDIR)/cluster.o $(CXXLDFLAGS) 
+np_cluster: $(BUILDDIR)/np_cluster.o $(BUILDDIR)/Commons.o $(BUILDDIR)/Configuration.o $(BUILDDIR)/file_io.o $(BUILDDIR)/Parsers.o $(BUILDDIR)/sph_subs.o $(BUILDDIR)/clu_subs.o $(BUILDDIR)/cluster.o $(BUILDDIR)/TransitionMatrix.o
+	$(CXX) $(CXXFLAGS) -o $(BUILDDIR)/np_cluster $(BUILDDIR)/np_cluster.o $(BUILDDIR)/Commons.o $(BUILDDIR)/Configuration.o $(BUILDDIR)/file_io.o $(BUILDDIR)/Parsers.o $(BUILDDIR)/sph_subs.o $(BUILDDIR)/clu_subs.o $(BUILDDIR)/cluster.o $(BUILDDIR)/TransitionMatrix.o $(CXXLDFLAGS) 
 
 #$(BUILDDIR)/np_cluster.o:
 #	$(CXX) $(CXXFLAGS) -c np_cluster.cpp -o $(BUILDDIR)/np_cluster.o
diff --git a/src/cluster/cluster.cpp b/src/cluster/cluster.cpp
index 42a0c4c9..c0b4a64c 100644
--- a/src/cluster/cluster.cpp
+++ b/src/cluster/cluster.cpp
@@ -24,6 +24,10 @@
 #include "../include/clu_subs.h"
 #endif
 
+#ifndef INCLUDE_TRANSITIONMATRIX_H_
+#include "../include/TransitionMatrix.h"
+#endif
+
 using namespace std;
 
 /*! \brief C++ implementation of CLU
@@ -331,16 +335,20 @@ void cluster(string config_file, string data_file, string output_path) {
 	ztm(am, c1, c1ao, c4, c6, c9);
 	if (sconf->idfc >= 0) {
 	  if (jxi488 == gconf->jwtm) {
+	    int nlemt = 2 * c4->nlem;
+	    string ttms_name = output_path + "/c_TTMS.hd5";
+	    TransitionMatrix ttms(nlemt, lm, vk, exri, c1ao->am0m);
+	    ttms.write_binary(ttms_name, "HDF5");
+	    ttms_name = output_path + "/c_TTMS";
+	    ttms.write_binary(ttms_name);
+	    /*
 	    int is = 1;
-	    fstream ttms_file;
-	    string ttms_name = output_path + "/c_TTMS";
 	    ttms_file.open(ttms_name.c_str(), ios::out | ios::binary);
 	    if (ttms_file.is_open()) {
 	      ttms_file.write(reinterpret_cast<char *>(&is), sizeof(int));
 	      ttms_file.write(reinterpret_cast<char *>(&lm), sizeof(int));
 	      ttms_file.write(reinterpret_cast<char *>(&vk), sizeof(double));
 	      ttms_file.write(reinterpret_cast<char *>(&exri), sizeof(double));
-	      int nlemt = 2 * c4->nlem;
 	      for (int ami = 0; ami < nlemt; ami++) {
 		for (int amj = 0; amj < nlemt; amj++) {
 		  complex<double> value = c1ao->am0m[ami][amj];
@@ -355,6 +363,7 @@ void cluster(string config_file, string data_file, string output_path) {
 	      printf("\nERROR: failed to open TTMS file.\n");
 	      break;
 	    }
+	    */
 	  }
 	}
 	// label 156: continue from here
-- 
GitLab