From: David Wells Date: Tue, 7 Jul 2015 01:39:16 +0000 (-0400) Subject: Fix strange VTK timestamps with refactoring. X-Git-Tag: v8.3.0-rc1~50^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d515038493dfac8a8381e6c6c524707280dd45b5;p=dealii.git Fix strange VTK timestamps with refactoring. VTK files, based on when they are written, may save output with text like This file was generated by the deal.II library on 2015/7/6 at 17: 3:49 which, while correct, is a bit strange to read. This behavior may occur in other output file formats. I fixed this by calling utility functions with the correct behavior. --- diff --git a/include/deal.II/base/utilities.h b/include/deal.II/base/utilities.h index f73a4566ef..43ca9c6bac 100644 --- a/include/deal.II/base/utilities.h +++ b/include/deal.II/base/utilities.h @@ -377,6 +377,12 @@ namespace Utilities */ std::string get_time (); + /** + * Return the present date as YYYY/MM/DD. MM and DD may be either one or two + * digits. + */ + std::string get_date (); + /** * Call the system function posix_memalign, or a replacement function if not * available, to allocate memory with a certain minimal alignment. The diff --git a/source/base/data_out_base.cc b/source/base/data_out_base.cc index 57e3ca85d0..adc1b3b2f5 100644 --- a/source/base/data_out_base.cc +++ b/source/base/data_out_base.cc @@ -2526,17 +2526,9 @@ namespace DataOutBase // preamble if (flags.write_preamble) { - std::time_t time1= std::time (0); - std::tm *time = std::localtime(&time1); out << "# This file was generated by the deal.II library." << '\n' - << "# Date = " - << time->tm_year+1900 << "/" - << time->tm_mon+1 << "/" - << time->tm_mday << '\n' - << "# Time = " - << time->tm_hour << ":" - << std::setw(2) << time->tm_min << ":" - << std::setw(2) << time->tm_sec << '\n' + << "# Date = " << Utilities::System::get_date() << "\n" + << "# Time = " << Utilities::System::get_time() << "\n" << "#" << '\n' << "# For a description of the UCD format see the AVS Developer's guide." << '\n' @@ -2850,16 +2842,10 @@ namespace DataOutBase if (true) { - std::time_t time1= std::time (0); - std::tm *time = std::localtime(&time1); out << "attribute \"created\" string \"" - << time->tm_year+1900 << "/" - << time->tm_mon+1 << "/" - << time->tm_mday + << Utilities::System::get_date() << ' ' - << time->tm_hour << ":" - << std::setw(2) << time->tm_min << ":" - << std::setw(2) << time->tm_sec << '"' << '\n'; + << Utilities::System::get_time() << '"' << '\n'; } out << "end" << '\n'; @@ -2918,17 +2904,9 @@ namespace DataOutBase // block this to have local // variables destroyed after // use - const std::time_t time1= std::time (0); - const std::tm *time = std::localtime(&time1); out << "# This file was generated by the deal.II library." << '\n' - << "# Date = " - << time->tm_year+1900 << "/" - << time->tm_mon+1 << "/" - << time->tm_mday << '\n' - << "# Time = " - << time->tm_hour << ":" - << std::setw(2) << time->tm_min << ":" - << std::setw(2) << time->tm_sec << '\n' + << "# Date = " << Utilities::System::get_date() << '\n' + << "# Time = " << Utilities::System::get_time() << '\n' << "#" << '\n' << "# For a description of the GNUPLOT format see the GNUPLOT manual." << '\n' @@ -3155,17 +3133,9 @@ namespace DataOutBase { // block this to have local // variables destroyed after use - const std::time_t time1= std::time (0); - const std::tm *time = std::localtime(&time1); out << "/* This file was generated by the deal.II library." << '\n' - << " Date = " - << time->tm_year+1900 << "/" - << time->tm_mon+1 << "/" - << time->tm_mday << '\n' - << " Time = " - << time->tm_hour << ":" - << std::setw(2) << time->tm_min << ":" - << std::setw(2) << time->tm_sec << '\n' + << " Date = " << Utilities::System::get_date() << '\n' + << " Time = " << Utilities::System::get_time() << '\n' << '\n' << " For a description of the POVRAY format see the POVRAY manual." << '\n' @@ -3754,18 +3724,13 @@ namespace DataOutBase // block this to have local // variables destroyed after // use - std::time_t time1= std::time (0); - std::tm *time = std::localtime(&time1); out << "%!PS-Adobe-2.0 EPSF-1.2" << '\n' << "%%Title: deal.II Output" << '\n' << "%%Creator: the deal.II library" << '\n' << "%%Creation Date: " - << time->tm_year+1900 << "/" - << time->tm_mon+1 << "/" - << time->tm_mday << " - " - << time->tm_hour << ":" - << std::setw(2) << time->tm_min << ":" - << std::setw(2) << time->tm_sec << '\n' + << Utilities::System::get_date() + << " - " + << Utilities::System::get_time() << '\n' << "%%BoundingBox: " // lower left corner << "0 0 " @@ -4083,17 +4048,9 @@ namespace DataOutBase /////////// // preamble { - std::time_t time1= std::time (0); - std::tm *time = std::localtime(&time1); out << "# This file was generated by the deal.II library." << '\n' - << "# Date = " - << time->tm_year+1900 << "/" - << time->tm_mon+1 << "/" - << time->tm_mday << '\n' - << "# Time = " - << time->tm_hour << ":" - << std::setw(2) << time->tm_min << ":" - << std::setw(2) << time->tm_sec << '\n' + << "# Date = " << Utilities::System::get_date() << '\n' + << "# Time = " << Utilities::System::get_time() << '\n' << "#" << '\n' << "# For a description of the Tecplot format see the Tecplot documentation." << '\n' @@ -4671,19 +4628,14 @@ namespace DataOutBase /////////////////////// // preamble { - std::time_t time1= std::time (0); - std::tm *time = std::localtime(&time1); out << "# vtk DataFile Version 3.0" << '\n' << "#This file was generated by the deal.II library"; if (flags.print_date_and_time) - out << " on " - << time->tm_year+1900 << "/" - << time->tm_mon+1 << "/" - << time->tm_mday << " at " - << time->tm_hour << ":" - << std::setw(2) << time->tm_min << ":" - << std::setw(2) << time->tm_sec; + { + out << " on " << Utilities::System::get_date() + << " at " << Utilities::System::get_time(); + } else out << "."; out << '\n' @@ -4900,21 +4852,16 @@ namespace DataOutBase const VtkFlags &flags) { AssertThrow (out, ExcIO()); - std::time_t time1= std::time (0); - std::tm *time = std::localtime(&time1); out << " \n"; out << "\n"; @@ -6233,16 +6180,10 @@ write_pvd_record (std::ostream &out, out << "\n"; - std::time_t time1= std::time (0); - std::tm *time = std::localtime(&time1); out << "\n"; out << "\n"; @@ -6277,16 +6218,10 @@ DataOutInterface::write_pvtu_record (std::ostream &out, out << "\n"; - std::time_t time1= std::time (0); - std::tm *time = std::localtime(&time1); out << "\n"; out << "\n"; diff --git a/source/base/utilities.cc b/source/base/utilities.cc index c8bd42a2c5..5859972be3 100644 --- a/source/base/utilities.cc +++ b/source/base/utilities.cc @@ -607,6 +607,22 @@ namespace Utilities } + + std::string get_date () + { + std::time_t time1= std::time (0); + std::tm *time = std::localtime(&time1); + + std::ostringstream o; + o << time->tm_year + 1900 << "/" + << time->tm_mon + 1 << "/" + << time->tm_mday; + + return o.str(); + } + + + void posix_memalign (void **memptr, size_t alignment, size_t size) { #ifndef DEAL_II_MSVC