aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetIOScalar/src
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@aei.mpg.de>2005-05-09 12:48:00 +0000
committerErik Schnetter <schnetter@aei.mpg.de>2005-05-09 12:48:00 +0000
commita8b7d56f6254f12d4fa46a6bd19f30fbee9827a7 (patch)
tree1ad58d095cfc4802b1996f6e534449c40500c644 /Carpet/CarpetIOScalar/src
parent6202c65e1f4e8be9752c8d93b81797180561611e (diff)
CarpetIOScalar: Make it possible to have only one output file per group
Add a parameter CarpetIOScalar::one_file_per_group that collects the output for all variables of a group into a single file. This reduces the number of files, and should thus speed up output and reduce disk usage. If at least one variable of a group is output, then the whole group is output. darcs-hash:20050509124843-891bb-efaa54abf4d74843a24526f3fd87248cac825513.gz
Diffstat (limited to 'Carpet/CarpetIOScalar/src')
-rw-r--r--Carpet/CarpetIOScalar/src/ioscalar.cc96
1 files changed, 72 insertions, 24 deletions
diff --git a/Carpet/CarpetIOScalar/src/ioscalar.cc b/Carpet/CarpetIOScalar/src/ioscalar.cc
index eea5a5082..af173434b 100644
--- a/Carpet/CarpetIOScalar/src/ioscalar.cc
+++ b/Carpet/CarpetIOScalar/src/ioscalar.cc
@@ -1,5 +1,6 @@
#include <cassert>
#include <cstdlib>
+#include <cctype>
#include <fstream>
#include <iomanip>
#include <list>
@@ -272,6 +273,15 @@ namespace CarpetIOScalar {
file.open (filename, ios::out | ios::trunc);
file << "# " << varname << " (" << alias << ")" << endl;
file << "# iteration time data" << endl;
+ if (one_file_per_group) {
+ file << "# data columns:";
+ int const firstvar = CCTK_FirstVarIndexI(group);
+ int const numvars = CCTK_NumVarsInGroupI(group);
+ for (int n=firstvar; n<firstvar+numvars; ++n) {
+ file << " " << CCTK_VarName(n);
+ }
+ file << endl;
+ }
} else {
file.open (filename, ios::out | ios::app);
}
@@ -287,7 +297,11 @@ namespace CarpetIOScalar {
assert (file.good());
} // if on the root processor
-
+
+ if (CCTK_MyProc(cctkGH)==0) {
+ file << cctk_iteration << " " << cctk_time;
+ }
+
int const handle = ireduction->handle;
union {
@@ -296,29 +310,39 @@ namespace CarpetIOScalar {
#undef TYPECASE
} result;
- int const ierr
- = CCTK_Reduce (cctkGH, 0, handle, 1, vartype, &result, 1, n);
- assert (! ierr);
-
- if (CCTK_MyProc(cctkGH)==0) {
-
- file << cctk_iteration << " " << cctk_time << " ";
-
- switch (vartype) {
+ int const firstvar
+ = one_file_per_group ? CCTK_FirstVarIndexI(group) : n;
+ int const numvars
+ = one_file_per_group ? CCTK_NumVarsInGroupI(group) : 1;
+
+ for (int n=firstvar; n<firstvar+numvars; ++n) {
+
+ int const ierr
+ = CCTK_Reduce (cctkGH, 0, handle, 1, vartype, &result, 1, n);
+ assert (! ierr);
+
+ if (CCTK_MyProc(cctkGH)==0) {
+ file << " ";
+
+ switch (vartype) {
#define TYPECASE(N,T) \
- case N: \
- file << result.var_##T; \
- break;
+ case N: \
+ file << result.var_##T; \
+ break;
#include "carpet_typecase.hh"
#undef TYPECASE
- default:
- UnsupportedVarType (n);
+ default:
+ UnsupportedVarType (n);
+ }
}
-
+
+ } // for n
+
+ if (CCTK_MyProc(cctkGH)==0) {
file << endl;
assert (file.good());
}
-
+
if (CCTK_MyProc(cctkGH)==0) {
file.close();
assert (file.good());
@@ -475,15 +499,39 @@ namespace CarpetIOScalar {
TriggerOutput (const cGH * const cctkGH, int const vindex)
{
DECLARE_CCTK_ARGUMENTS;
+ DECLARE_CCTK_PARAMETERS;
assert (vindex>=0 && vindex<CCTK_NumVars());
-
- char* const varname = CCTK_FullName(vindex);
- const int retval = OutputVarAs (cctkGH, varname, CCTK_VarName(vindex));
- free (varname);
-
- last_output.at(vindex) = cctk_iteration;
-
+
+ int retval;
+
+ if (one_file_per_group) {
+
+ char* fullname = CCTK_FullName(vindex);
+ int const gindex = CCTK_GroupIndexFromVarI(vindex);
+ char* groupname = CCTK_GroupName(gindex);
+ for (char* p=groupname; *p; ++p) *p=tolower(*p);
+ retval = OutputVarAs (cctkGH, fullname, groupname);
+ free (fullname);
+ free (groupname);
+
+ int const firstvar = CCTK_FirstVarIndexI(gindex);
+ int const numvars = CCTK_NumVarsInGroupI(gindex);
+ for (int n=firstvar; n<firstvar+numvars; ++n) {
+ last_output.at(n) = cctk_iteration;
+ }
+
+ } else {
+
+ char* const fullname = CCTK_FullName(vindex);
+ char const* varname = CCTK_FullName(vindex);
+ const int retval = OutputVarAs (cctkGH, fullname, varname);
+ free (fullname);
+
+ last_output.at(vindex) = cctk_iteration;
+
+ }
+
return retval;
}