diff options
author | jthorn <jthorn@f88db872-0e4f-0410-b76b-b9085cfa78c5> | 2003-07-29 13:28:18 +0000 |
---|---|---|
committer | jthorn <jthorn@f88db872-0e4f-0410-b76b-b9085cfa78c5> | 2003-07-29 13:28:18 +0000 |
commit | 955d7ea6026d47a2d05457187612649de61efd4e (patch) | |
tree | 230d2d89204c016fd830339f10488ce37b32146e /src | |
parent | 9ff4c59ad241f4dd9a6ae875f503d723a8bc0ddc (diff) |
- inherit from IO
- add new parameters
BH_diagnostics_directory
h_directory
which both default to IO::out_dir
- change code to use these for output directories
- change code to auto-create output directories if they don't already exist
git-svn-id: http://svn.einsteintoolkit.org/cactus/EinsteinAnalysis/AHFinderDirect/trunk@1157 f88db872-0e4f-0410-b76b-b9085cfa78c5
Diffstat (limited to 'src')
-rw-r--r-- | src/driver/BH_diagnostics.cc | 22 | ||||
-rw-r--r-- | src/driver/Newton.cc | 6 | ||||
-rw-r--r-- | src/driver/driver.hh | 31 | ||||
-rw-r--r-- | src/driver/io.cc | 148 | ||||
-rw-r--r-- | src/driver/setup.cc | 18 |
5 files changed, 146 insertions, 79 deletions
diff --git a/src/driver/BH_diagnostics.cc b/src/driver/BH_diagnostics.cc index 0a8b8e1..733d2f3 100644 --- a/src/driver/BH_diagnostics.cc +++ b/src/driver/BH_diagnostics.cc @@ -333,12 +333,24 @@ FILE* BH_diagnostics::setup_output_file(const struct IO_info& IO_info, int N_horizons, int hn) const { -const int N_file_name_buffer = 200; -char file_name_buffer[N_file_name_buffer]; +char file_name_buffer[IO_info::file_name_buffer_size]; -snprintf(file_name_buffer, N_file_name_buffer, - "%s.ah%d.%s", - IO_info.BH_diagnostics_base_file_name, +const char* directory = IO_info.BH_diagnostics_directory; +const int status = CCTK_CreateDirectory(IO_info.default_directory_permission, + directory); +if (status < 0) + then CCTK_VWarn(FATAL_ERROR, __LINE__, __FILE__, CCTK_THORNSTRING, +"\n" +" BH_diagnostics::setup_output_file():\n" +" error %d trying to create output directory\n" +" \"%s\"!" + , + status, + directory); /*NOTREACHED*/ + +snprintf(file_name_buffer, IO_info::file_name_buffer_size, + "%s/%s.ah%d.%s", + directory, IO_info.BH_diagnostics_base_file_name, hn, IO_info.BH_diagnostics_file_name_extension); FILE *fileptr = fopen(file_name_buffer, "w"); if (fileptr == NULL) diff --git a/src/driver/Newton.cc b/src/driver/Newton.cc index 1e7efbc..dd92984 100644 --- a/src/driver/Newton.cc +++ b/src/driver/Newton.cc @@ -376,10 +376,8 @@ if (hs.has_genuine_horizons()) then { // if this is the first time we've output h for this // horizon, maybe output an OpenDX control file? - if (IO_info.output_OpenDX_control_files - && !AH_data_ptr->OpenDX_control_file_written) - then output_OpenDX_control_file(*ps_ptr, - IO_info, hn); + if (!AH_data_ptr->h_files_written) + then setup_h_files(*ps_ptr, IO_info, hn); output_gridfn(*ps_ptr, gfns::gfn__h, IO_info, IO_info.h_base_file_name, hn, verbose_info diff --git a/src/driver/driver.hh b/src/driver/driver.hh index c60d3b6..74fddaa 100644 --- a/src/driver/driver.hh +++ b/src/driver/driver.hh @@ -122,26 +122,40 @@ struct solver_info // struct IO_info { + // buffer size for file names + // ... file names longer than this will be truncated, but + // they will NOT overflow the buffer (we always use snprintf(3)) + enum { file_name_buffer_size = 512 }; + + // default permissions for newly created directories + // = full access to everyone; the user's umask + // should cut this down to something reasonable + enum { default_directory_permission = 0777 }; + enum horizon_file_format horizon_file_format; bool output_initial_guess; int output_h_every, output_Theta_every; // based on the above, do we want to output things now (this time step)? bool output_h, output_Theta; + bool output_BH_diagnostics; + const char* BH_diagnostics_directory; + const char* BH_diagnostics_base_file_name; + const char* BH_diagnostics_file_name_extension; + bool output_ghost_zones_for_h; const char* ASCII_gnuplot_file_name_extension; const char* HDF5_file_name_extension; + const char* h_directory; const char* h_base_file_name; const char* Theta_base_file_name; const char* Delta_h_base_file_name; + const char* Jacobian_base_file_name; + bool output_OpenDX_control_files; const char* OpenDX_control_file_name_extension; - bool output_BH_diagnostics; - const char* BH_diagnostics_base_file_name; - const char* BH_diagnostics_file_name_extension; - // this is used to choose file names int time_iteration; // the Cactus time interation number // (cctk_iteration) @@ -280,9 +294,8 @@ struct AH_data struct initial_guess_info initial_guess_info; bool found_flag; // did we find this horizon (successfully) - bool OpenDX_control_file_written; // have we written an - // OpenDX control file - // (for this horizon) yet? + bool h_files_written; // have we written horizon-shape or similar + // files for this horizon yet? struct BH_diagnostics BH_diagnostics; FILE *BH_diagnostics_fileptr; @@ -389,12 +402,10 @@ void input_gridfn(patch_system& ps, int unknown_gfn, void input_gridfn__explicit_name(patch_system& ps, int unknown_gfn, const struct IO_info& IO_info, const char file_name[], bool print_msg_flag); +void setup_h_files(patch_system& ps, const struct IO_info& IO_info, int hn); void output_gridfn(patch_system& ps, int unknown_gfn, const struct IO_info& IO_info, const char base_file_name[], int hn, bool print_msg_flag, int AHF_iteration = 0); -void output_OpenDX_control_file(const patch_system& ps, - const struct IO_info& IO_info, - int hn); void output_Jacobians(const patch_system& ps, const Jacobian* Jac_NP_ptr, const Jacobian* Jac_SD_FDdr_ptr, diff --git a/src/driver/io.cc b/src/driver/io.cc index e9b737c..5fb8807 100644 --- a/src/driver/io.cc +++ b/src/driver/io.cc @@ -3,8 +3,10 @@ // // input_gridfn - read an angular grid function from an input file // input_gridfn__explicit_name - ... with the input file explicitly named +// +// setup_h_files - set up to write horizon-shape and similar output files +/// output_OpenDX_control_file - write an OpenDX control file for an output file // output_gridfn - write an angular grid function to an output file -// output_OpenDX_control_file - write an OpenDX control file for an output file // output_Jacobians - write a Jacobian matrix or matrices to an output file // /// io_file_name - compute file name for angular-gridfn I/O file @@ -47,18 +49,25 @@ using jtutil::error_exit; #include "driver.hh" //****************************************************************************** +//****************************************************************************** +//****************************************************************************** // // prototypes for functions local to this file // namespace { +void output_OpenDX_control_file(const patch_system& ps, + const struct IO_info& IO_info, + int hn); const char* io_file_name(const struct IO_info& IO_info, const char base_file_name[], int hn, int AHF_iteration = 0); } //****************************************************************************** +//****************************************************************************** +//****************************************************************************** // // This function inputs a gridfn from a data file, with the file name @@ -123,6 +132,81 @@ default: } //****************************************************************************** +//****************************************************************************** +//****************************************************************************** + +// +// This function sets up to output horizon-shape or similar data files: +// - it creates the output directory if this doesn't already exist +// - it writes the OpenDX control files if this is desired +// +void setup_h_files(patch_system& ps, const struct IO_info& IO_info, int hn) +{ +// create the output directory (if it doesn't already exist) +const int status = CCTK_CreateDirectory(IO_info.default_directory_permission, + IO_info.h_directory); +if (status < 0) + then CCTK_VWarn(FATAL_ERROR, __LINE__, __FILE__, CCTK_THORNSTRING, +"\n" +" setup_h_files():\n" +" error %d trying to create output directory\n" +" \"%s\"!" + , + status, + IO_info.h_directory); /*NOTREACHED*/ + +output_OpenDX_control_file(ps, IO_info, hn); +} + +//****************************************************************************** + +// +// This function outputs an OpenDX control file to allow Thomas Radke's +// OpenDX macros to read in a "ASCII (gnuplot)" data file produced by +// output_gridfn() . +// +namespace { +void output_OpenDX_control_file(const patch_system& ps, + const struct IO_info& IO_info, + int hn) +{ +static char file_name_buffer[IO_info::file_name_buffer_size]; +snprintf(file_name_buffer, IO_info::file_name_buffer_size, + "%s/%s.ah%d.%s", + IO_info.h_directory, IO_info.h_base_file_name, hn, + IO_info.OpenDX_control_file_name_extension); + +FILE *fileptr = fopen(file_name_buffer, "w"); +if (fileptr == NULL) + then CCTK_VWarn(FATAL_ERROR, __LINE__, __FILE__, CCTK_THORNSTRING, + "output_OpenDX_control_file(): can't open output file \"%s\"!", + file_name_buffer); /*NOTREACHED*/ + +fprintf(fileptr, "# list the size of each patch (N_rho x N_sigma)\n"); + for (int pn = 0 ; pn < ps.N_patches() ; ++pn) + { + const patch& p = ps.ith_patch(pn); + fprintf(fileptr, "object \"%s patch\" class array ", p.name()); + fprintf(fileptr, "type int rank 1 shape 2 items 1 data follows %d %d\n", + p.effective_N_irho(IO_info.output_ghost_zones_for_h), + p.effective_N_isigma(IO_info.output_ghost_zones_for_h)); + } +fprintf(fileptr, "\n"); + +fprintf(fileptr, "# collect all patch sizes into a single OpenDX group\n"); +fprintf(fileptr, "# for the ImportAHFinderDirectGnuplot macro to read\n"); +fprintf(fileptr, "object \"patchsizes\" class group\n"); + for (int pn = 0 ; pn < ps.N_patches() ; ++pn) + { + const patch& p = ps.ith_patch(pn); + fprintf(fileptr, "member %d value \"%s patch\"\n", pn, p.name()); + } + +fclose(fileptr); +} + } + +//****************************************************************************** // // This function outputs a gridfn from a data file. @@ -194,53 +278,6 @@ default: //****************************************************************************** // -// This function outputs an OpenDX control file to allow Thomas Radke's -// OpenDX macros to read in a "ASCII (gnuplot)" data file produced by -// output_gridfn() . -// -void output_OpenDX_control_file(const patch_system& ps, - const struct IO_info& IO_info, - int hn) -{ -const int N_file_name_buffer = 200; -static char file_name_buffer[N_file_name_buffer]; -snprintf(file_name_buffer, N_file_name_buffer, - "%s.ah%d.%s", - IO_info.h_base_file_name, hn, - IO_info.OpenDX_control_file_name_extension); - -FILE *fileptr = fopen(file_name_buffer, "w"); -if (fileptr == NULL) - then CCTK_VWarn(FATAL_ERROR, __LINE__, __FILE__, CCTK_THORNSTRING, - "output_Jacobians(): can't open output file \"%s\"!", - file_name_buffer); /*NOTREACHED*/ - -fprintf(fileptr, "# list the size of each patch (N_rho x N_sigma)\n"); - for (int pn = 0 ; pn < ps.N_patches() ; ++pn) - { - const patch& p = ps.ith_patch(pn); - fprintf(fileptr, "object \"%s patch\" class array ", p.name()); - fprintf(fileptr, "type int rank 1 shape 2 items 1 data follows %d %d\n", - p.effective_N_irho(IO_info.output_ghost_zones_for_h), - p.effective_N_isigma(IO_info.output_ghost_zones_for_h)); - } -fprintf(fileptr, "\n"); - -fprintf(fileptr, "# collect all patch sizes into a single OpenDX group\n"); -fprintf(fileptr, "# for the ImportAHFinderDirectGnuplot macro to read\n"); -fprintf(fileptr, "object \"patchsizes\" class group\n"); - for (int pn = 0 ; pn < ps.N_patches() ; ++pn) - { - const patch& p = ps.ith_patch(pn); - fprintf(fileptr, "member %d value \"%s patch\"\n", pn, p.name()); - } - -fclose(fileptr); -} - -//****************************************************************************** - -// // This function prints one or two Jacobian matrices (and their difference // in the latter case) to a named output file. // @@ -389,8 +426,7 @@ const char* io_file_name(const struct IO_info& IO_info, const char base_file_name[], int hn, int AHF_iteration /* = 0 */) { -const int N_file_name_buffer = 200; -static char file_name_buffer[N_file_name_buffer]; +static char file_name_buffer[IO_info::file_name_buffer_size]; const char* file_name_extension; switch (IO_info.horizon_file_format) @@ -411,14 +447,14 @@ default: } if (AHF_iteration == 0) - then snprintf(file_name_buffer, N_file_name_buffer, - "%s.t%d.ah%d.%s", - base_file_name, + then snprintf(file_name_buffer, IO_info::file_name_buffer_size, + "%s/%s.t%d.ah%d.%s", + IO_info.h_directory, base_file_name, IO_info.time_iteration, hn, file_name_extension); - else snprintf(file_name_buffer, N_file_name_buffer, - "%s.t%d.ah%d.it%d.%s", - base_file_name, + else snprintf(file_name_buffer, IO_info::file_name_buffer_size, + "%s/%s.t%d.ah%d.it%d.%s", + IO_info.h_directory, base_file_name, IO_info.time_iteration, hn, AHF_iteration, file_name_extension); diff --git a/src/driver/setup.cc b/src/driver/setup.cc index b48faa9..1e4cc9e 100644 --- a/src/driver/setup.cc +++ b/src/driver/setup.cc @@ -247,18 +247,28 @@ IO_info.output_h_every = output_h_every; IO_info.output_Theta_every = output_Theta_every; IO_info.output_h = false; // dummy value IO_info.output_Theta = false; // dummy value + +IO_info.output_BH_diagnostics = (output_BH_diagnostics != 0); +IO_info.BH_diagnostics_directory + = (strlen(BH_diagnostics_directory) == 0) + ? /* IO:: */ out_dir + : BH_diagnostics_directory; +IO_info.BH_diagnostics_base_file_name = BH_diagnostics_base_file_name; +IO_info.BH_diagnostics_file_name_extension = BH_diagnostics_file_name_extension; + IO_info.output_ghost_zones_for_h = (output_ghost_zones_for_h != 0); IO_info.ASCII_gnuplot_file_name_extension = ASCII_gnuplot_file_name_extension; IO_info.HDF5_file_name_extension = HDF5_file_name_extension; +IO_info.h_directory + = (strlen(h_directory) == 0) + ? /* IO:: */ out_dir + : h_directory; IO_info.h_base_file_name = h_base_file_name; IO_info.Theta_base_file_name = Theta_base_file_name; IO_info.Delta_h_base_file_name = Delta_h_base_file_name; IO_info.Jacobian_base_file_name = Jacobian_base_file_name; IO_info.output_OpenDX_control_files = (output_OpenDX_control_files != 0); IO_info.OpenDX_control_file_name_extension = OpenDX_control_file_name_extension; -IO_info.output_BH_diagnostics = (output_BH_diagnostics != 0); -IO_info.BH_diagnostics_base_file_name = BH_diagnostics_base_file_name; -IO_info.BH_diagnostics_file_name_extension = BH_diagnostics_file_name_extension; IO_info.time_iteration = 0; IO_info.time = 0.0; @@ -501,7 +511,7 @@ if (strlen(surface_interpolator_name) > 0) } AH_data.found_flag = false; - AH_data.OpenDX_control_file_written = false; + AH_data.h_files_written = false; AH_data.BH_diagnostics_fileptr = NULL; } } |