aboutsummaryrefslogtreecommitdiff
path: root/CarpetDev/CarpetIOF5/src/file.cc
diff options
context:
space:
mode:
Diffstat (limited to 'CarpetDev/CarpetIOF5/src/file.cc')
-rw-r--r--CarpetDev/CarpetIOF5/src/file.cc292
1 files changed, 144 insertions, 148 deletions
diff --git a/CarpetDev/CarpetIOF5/src/file.cc b/CarpetDev/CarpetIOF5/src/file.cc
index f200277b5..d78dcb001 100644
--- a/CarpetDev/CarpetIOF5/src/file.cc
+++ b/CarpetDev/CarpetIOF5/src/file.cc
@@ -1,16 +1,19 @@
#include <algorithm>
#include <cassert>
#include <iomanip>
-#include <iostream>
#include <sstream>
#include <string>
+#include <vector>
#include <hdf5.h>
#include "cctk.h"
#include "cctk_Parameters.h"
+#include "defs.hh"
+
#include "file.hh"
+#include "utils.hh"
@@ -22,58 +25,86 @@ namespace CarpetIOF5 {
file_t::
file_t (cGH const * const cctkGH,
+ string const path,
string const basename,
string const extension,
- bool const do_truncate)
+ bool const do_truncate,
+ bool const is_metafile,
+ bool const is_datafile)
: m_cctkGH (cctkGH),
+ m_path (path),
m_basename (basename),
- m_extension (extension)
+ m_extension (extension),
+ m_is_metafile (is_metafile),
+ m_is_datafile (is_datafile)
{
- assert (cctkGH);
-
- int const proc = CCTK_MyProc (cctkGH);
- m_have_metafile = determine_want_metafile (proc);
- m_output_processor = determine_output_processor (proc);
+ DECLARE_CCTK_PARAMETERS;
- m_metafilename = make_metafilename ();
- m_filename = make_filename (proc);
+ assert (cctkGH);
- char const * const metafilenameptr = m_metafilename.c_str();
- char const * const filenameptr = m_filename.c_str();
+ // Create file names, creating subdirectories to avoid placing
+ // too many files into the same directory
+ check (CCTK_CreateDirectory (mode, path.c_str()) >= 0);
+ if (is_metafile)
+ {
+ m_filename = basename + extension;
+ }
+ else
+ {
+ int const myproc = CCTK_MyProc (cctkGH);
+ m_filename = create_filename (myproc, true);
+ }
+ string const filepath = m_path + "/" + m_filename;
htri_t is_hdf5;
H5E_BEGIN_TRY {
- is_hdf5 = H5Fis_hdf5 (filenameptr);
+ is_hdf5 = H5Fis_hdf5 (filepath.c_str());
} H5E_END_TRY;
bool const file_exists = is_hdf5 > 0;
- // Ignore the metafile when determining whether the file already
- // exists
if (do_truncate or not file_exists)
{
- m_hdf5_metafile = -1;
- if (m_have_metafile)
+ if (veryverbose)
{
- m_hdf5_metafile
- = H5Fcreate (metafilenameptr,
- H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ CCTK_VInfo (CCTK_THORNSTRING,
+ "H5Fcreate (name=\"%s\")", filepath.c_str());
}
m_hdf5_file
- = H5Fcreate (filenameptr, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ = H5Fcreate (filepath.c_str(),
+ H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
}
else
{
- m_hdf5_metafile = -1;
- if (m_have_metafile)
+ if (veryverbose)
{
- m_hdf5_metafile
- = H5Fopen (metafilenameptr, H5F_ACC_RDWR, H5P_DEFAULT);
+ CCTK_VInfo (CCTK_THORNSTRING,
+ "H5Fopen (name=\"%s\")", filepath.c_str());
}
- m_hdf5_file = H5Fopen (filenameptr, H5F_ACC_RDWR, H5P_DEFAULT);
+ m_hdf5_file = H5Fopen (filepath.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
}
+ assert (m_hdf5_file >= 0);
- m_filenames.resize (CCTK_nProcs (cctkGH));
- m_filenames.at(proc) = m_filename;
+ m_hdf5_fiber_contents = -1;
+ m_hdf5_fiber_global_charts = -1;
+ m_hdf5_fiber_parameter_space = -1;
+ if (m_is_metafile)
+ {
+ create_or_check_version (m_hdf5_file);
+ m_hdf5_fiber_contents
+ = open_or_create_group (m_hdf5_file, "TableOfContents");
+ assert (m_hdf5_fiber_contents >= 0);
+ m_hdf5_fiber_global_charts
+ = open_or_create_group (m_hdf5_file, "Charts");
+ assert (m_hdf5_fiber_global_charts >= 0);
+ m_hdf5_fiber_parameter_space
+ = open_or_create_group (m_hdf5_fiber_contents, "Parameters");
+ assert (m_hdf5_fiber_parameter_space >= 0);
+
+ hid_t const hdf5_time_group
+ = open_or_create_group (m_hdf5_fiber_parameter_space, "Time");
+ assert (hdf5_time_group >= 0);
+ check (not H5Gclose (hdf5_time_group));
+ }
assert (invariant());
}
@@ -83,102 +114,91 @@ namespace CarpetIOF5 {
file_t::
~ file_t()
{
- if (m_have_metafile)
- {
- herr_t const herr = H5Fclose (m_hdf5_metafile);
- assert (not herr);
- }
- herr_t const herr = H5Fclose (m_hdf5_file);
- assert (not herr);
- }
-
-
-
- bool file_t::
- determine_want_metafile (int const proc)
- const
- {
- DECLARE_CCTK_PARAMETERS;
-
- if (CCTK_EQUALS (out_mode, "proc") or
- CCTK_EQUALS (out_mode, "np"))
- {
- return proc == 0;
- }
- else if (CCTK_EQUALS (out_mode, "onefile"))
- {
- return false;
- }
- else
+ if (m_is_metafile)
{
- assert (0);
+ check (not H5Gclose (m_hdf5_fiber_parameter_space));
+ check (not H5Gclose (m_hdf5_fiber_contents));
+ check (not H5Gclose (m_hdf5_fiber_global_charts));
}
+ check (not H5Fclose (m_hdf5_file));
}
- int file_t::
- determine_output_processor (int const proc)
+ string file_t::
+ create_filename (int const proc, bool const create_directories)
const
{
DECLARE_CCTK_PARAMETERS;
- if (CCTK_EQUALS (out_mode, "proc"))
- {
- return proc;
- }
- else if (CCTK_EQUALS (out_mode, "np"))
- {
- return proc / out_proc_every * out_proc_every;
- }
- else if (CCTK_EQUALS (out_mode, "onefile"))
+ int const nprocs = CCTK_nProcs (m_cctkGH);
+ string extrapath;
+ if (create_subdirs)
{
- return 0;
+ if (nprocs >= 10000)
+ {
+ ostringstream buf;
+ buf << extrapath
+ << m_basename
+ << ".p" << setw (max (0, processor_digits - 4)) << setfill ('0')
+ << proc / 10000
+ << "nnnn/";
+ extrapath = buf.str();
+ if (create_directories)
+ {
+ string const filepath = m_path + "/" + extrapath;
+ check (CCTK_CreateDirectory (mode, filepath.c_str()) >= 0);
+ }
+ }
+ if (nprocs >= 100)
+ {
+ ostringstream buf;
+ buf << extrapath
+ << m_basename
+ << ".p" << setw (max (0, processor_digits - 2)) << setfill ('0')
+ << proc / 100
+ << "nn/";
+ extrapath = buf.str();
+ if (create_directories)
+ {
+ string const filepath = m_path + "/" + extrapath;
+ check (CCTK_CreateDirectory (mode, filepath.c_str()) >= 0);
+ }
+ }
}
- else
+ if (one_dir_per_file and nprocs >= 1)
{
- assert (0);
+ ostringstream buf;
+ buf << extrapath
+ << m_basename
+ << ".p" << setw (processor_digits) << setfill ('0')
+ << proc
+ << "/";
+ extrapath = buf.str();
+ if (create_directories)
+ {
+ string const filepath = m_path + "/" + extrapath;
+ check (CCTK_CreateDirectory (mode, filepath.c_str()) >= 0);
+ }
}
+ ostringstream buf;
+ buf << extrapath
+ << m_basename
+ << ".p" << setw (processor_digits) << setfill ('0') << proc
+ << m_extension;
+ return buf.str();
}
-
-
- string file_t::
- make_metafilename ()
- const
+
+
+ void file_t::
+ create_or_check_version (hid_t const hdf5_file)
{
- return m_basename + m_extension;
- }
-
-
-
- string file_t::
- make_filename (int const proc)
- const
- {
- DECLARE_CCTK_PARAMETERS;
-
- ostringstream filenamebuf;
-
- filenamebuf << m_basename;
-
- if (CCTK_EQUALS (out_mode, "proc") or
- CCTK_EQUALS (out_mode, "np"))
- {
- filenamebuf << ".p" << setw (processor_digits) << setfill ('0') << proc;
- }
- else if (CCTK_EQUALS (out_mode, "onefile"))
- {
- // do nothing
- }
- else
- {
- assert (0);
- }
-
- filenamebuf << m_extension;
-
- return filenamebuf.str();
+ hid_t const hdf5_group = open_or_create_group (hdf5_file, "version");
+ assert (hdf5_group >= 0);
+ string const version ("http://www.zib.de/visual/F5-0.1.2/");
+ write_or_check_attribute (hdf5_group, "version", version.c_str());
+ check (not H5Gclose (hdf5_group));
}
@@ -192,72 +212,50 @@ namespace CarpetIOF5 {
- bool file_t::
- get_have_metafile ()
- const
- {
- return m_have_metafile;
- }
-
-
-
- int file_t::
- get_output_processor ()
+ hid_t file_t::
+ get_hdf5_file ()
const
{
- return m_output_processor;
+ return m_hdf5_file;
}
- string file_t::
- get_filename (int const proc)
+ hid_t file_t::
+ get_hdf5_fiber_parameter_space ()
const
{
- assert (proc >= 0 and proc < CCTK_nProcs (m_cctkGH));
- if (m_filenames.at(proc).empty())
- {
- m_filenames.at(proc) = make_filename (proc);
- }
- return m_filenames.at(proc);
+ return m_hdf5_fiber_parameter_space;
}
- hid_t file_t::
- get_hdf5_metafile()
+ bool file_t::
+ get_is_metafile ()
const
{
- return m_hdf5_metafile;
+ return m_is_metafile;
}
- hid_t file_t::
- get_hdf5_file()
+ bool file_t::
+ get_is_datafile ()
const
{
- return m_hdf5_file;
+ return m_is_datafile;
}
void file_t::
- get_link_destination (string & filename,
+ get_link_destination (int const proc,
+ string & filename,
string & objectname)
const
{
- static bool initialised = false;
- static string l_filename;
- static string l_objectname;
- if (not initialised)
- {
- initialised = true;
- l_filename = m_filename;
- l_objectname = string ("");
- }
- filename = l_filename;
- objectname = l_objectname;
+ filename = create_filename (proc);
+ objectname = "";
}
@@ -266,9 +264,7 @@ namespace CarpetIOF5 {
invariant()
const
{
- return (m_cctkGH != 0
- and (not m_have_metafile or m_hdf5_metafile >= 0)
- and m_hdf5_file >= 0);
+ return m_cctkGH != 0 and m_hdf5_file >= 0;
}
} // namespace F5