From b5474c282f193d0137b0b3071077226383d816a6 Mon Sep 17 00:00:00 2001
From: "Mulas, Giacomo" <gmulas@oa-cagliari.inaf.it>
Date: Mon, 18 Mar 2024 18:46:25 +0100
Subject: [PATCH] - add some more freshly defined variables in the scales loop

---
 src/cluster/cluster.cpp | 60 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 58 insertions(+), 2 deletions(-)

diff --git a/src/cluster/cluster.cpp b/src/cluster/cluster.cpp
index db5836a4..d78f4a90 100644
--- a/src/cluster/cluster.cpp
+++ b/src/cluster/cluster.cpp
@@ -351,8 +351,40 @@ void cluster(string config_file, string data_file, string output_path) {
 	C4 *c4_2 = new C4(*c4);
 	C6 *c6_2 = new C6(*c6);
 	C9 *c9_2 = new C9(*c9);
+	// FILE *output_2 = fopen((output_path + "/c_OCLU_" + to_string(jxi488)).c_str(), "w");
+	// fstream tppoan_2;
+	// tppoan_2.open((output_path + "/c_TPPOAN_" + to_string(jxi488)).c_str(), ios::out | ios::binary);
+	double *gaps_2 = new double[nsph]();
+	double **tqse_2 = new double*[2];
+	dcomplex **tqspe_2 = new dcomplex*[2];
+	double **tqss_2 = new double*[2];
+	dcomplex **tqsps_2 = new dcomplex*[2];
+	for (int ti = 0; ti < 2; ti++) {
+	  tqse_2[ti] = new double[nsph]();
+	  tqspe_2[ti] = new dcomplex[nsph]();
+	  tqss_2[ti] = new double[nsph]();
+	  tqsps_2[ti] = new dcomplex[nsph]();
+	  for (int tj=0; tj<nsph; tj++) {
+	    tqse_2[ti][tj] = tqse[ti][tj];
+	    tqspe_2[ti][tj] = tqspe[ti][tj];
+	    tqss_2[ti][tj] = tqss[ti][tj];
+	    tqsps_2[ti][tj] = tqsps[ti][tj];
+	  }
+	}
+	double ****zpv_2 = new double***[c4->lm]; //[gconf->l_max][3][2][2]; // Matrix: dim[LM x 3 x 2 x 2]
+    for (int zi = 0; zi < c4->lm; zi++) {
+      zpv_2[zi] = new double**[3];
+      for (int zj = 0; zj < 3; zj++) {
+	zpv_2[zi][zj] = new double*[2];
+	for (int zk = 0; zk < 2; zk++) {
+	  zpv_2[zi][zj][zk] = new double[2]();
+	  for (int zl = 0; zl < 2; zl++) zpv_2[zi][zj][zk][zl] = zpv[zi][zj][zk][zl];
+	}
+      }
+    }
 
-	jer = cluster_jxi488_cycle(jxi488, sconf_2, gconf_2, c1_2, c1ao_2, c2_2, c3_2, c4_2, c6_2, c9_2, output, output_path, gaps, tqse, tqspe, tqss, tqsps, zpv, gapm, gappm, nth, nths, nph, nphs, nk, nks, nkks, argi, args, gap, gapp, tqce, tqcpe, tqcs, tqcps, duk, tppoan, cextlr, cext, cmullr, cmul, gapv, tqev, tqsv, nxi, nsph, mxndm, inpol, iavm, npnt, npntts, isam, lm, th, thstp, thlst, ths, thsstp, thslst, ph, phstp, phlst, phs, phsstp, phslst, th1, ph1, ths1, phs1, thsca, u, us, un, uns, up, ups, unmp, unsmp, upmp, upsmp, scan, cfmp, sfmp, cfsp, sfsp, sqsfi, exri, lcalc, arg, wn, vk, ndit, am, isq, ibf);
+	
+	jer = cluster_jxi488_cycle(jxi488, sconf_2, gconf_2, c1_2, c1ao_2, c2_2, c3_2, c4_2, c6_2, c9_2, output, output_path, gaps_2, tqse_2, tqspe_2, tqss_2, tqsps_2, zpv, gapm, gappm, nth, nths, nph, nphs, nk, nks, nkks, argi, args, gap, gapp, tqce, tqcpe, tqcs, tqcps, duk, tppoan, cextlr, cext, cmullr, cmul, gapv, tqev, tqsv, nxi, nsph, mxndm, inpol, iavm, npnt, npntts, isam, lm, th, thstp, thlst, ths, thsstp, thslst, ph, phstp, phlst, phs, phsstp, phslst, th1, ph1, ths1, phs1, thsca, u, us, un, uns, up, ups, unmp, unsmp, upmp, upsmp, scan, cfmp, sfmp, cfsp, sfsp, sqsfi, exri, lcalc, arg, wn, vk, ndit, am, isq, ibf);
 
 	delete sconf_2;
 	delete gconf_2;
@@ -363,7 +395,31 @@ void cluster(string config_file, string data_file, string output_path) {
 	delete c4_2;
 	delete c6_2;
 	delete c9_2;
-      } // jxi488 loop
+	// fclose(output_2);
+	// tppoan_2.close();
+	delete[] gaps_2;
+	for (int ti = 0; ti <2 -1; ti++) {
+	  delete[] tqse_2[ti];
+	  delete[] tqspe_2[ti];
+	  delete[] tqss_2[ti];
+	  delete[] tqsps_2[ti];
+	}
+	delete[] tqse_2;
+	delete[] tqspe_2;
+	delete[] tqss_2;
+	delete[] tqsps_2;
+	for (int zi = 0; zi < c4->lm; zi++) {
+	  for (int zj = 0; zj < 3; zj++) {
+	    for (int zk = 0; zk < 2; zk++) {
+	      delete[] zpv_2[zi][zj][zk];
+	    }
+	    delete[] zpv_2[zi][zj];
+	  }
+	  delete[] zpv_2[zi];
+	}
+	delete[] zpv_2;
+	
+      }// jxi488 loop
       tppoan.close();
     } else { // In case TPPOAN could not be opened. Should never happen.
       printf("\nERROR: failed to open TPPOAN file.\n");
-- 
GitLab