]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix strange VTK timestamps with refactoring.
authorDavid Wells <drwells@vt.edu>
Tue, 7 Jul 2015 01:39:16 +0000 (21:39 -0400)
committerDavid Wells <drwells@vt.edu>
Tue, 7 Jul 2015 12:10:11 +0000 (08:10 -0400)
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.

include/deal.II/base/utilities.h
source/base/data_out_base.cc
source/base/utilities.cc

index f73a4566efaff4d4d659b2ee0cd749e1574722f9..43ca9c6bac2d3c13480def17a6efcbb8c92d0080 100644 (file)
@@ -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
index 57e3ca85d089805b2ea5ea269771c1a8a6778416..adc1b3b2f5083b05ef24f718cd2a94c4ce86410c 100644 (file)
@@ -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 << "<?xml version=\"1.0\" ?> \n";
     out << "<!-- \n";
     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_time()
+            << " at " << Utilities::System::get_date();
+      }
     else
       out << ".";
     out << "\n-->\n";
@@ -6233,16 +6180,10 @@ write_pvd_record (std::ostream &out,
 
   out << "<?xml version=\"1.0\"?>\n";
 
-  std::time_t  time1= std::time (0);
-  std::tm     *time = std::localtime(&time1);
   out << "<!--\n";
-  out << "#This file was generated by the deal.II library 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 << "#This file was generated by the deal.II library"
+      << " on " << Utilities::System::get_date()
+      << " at " << Utilities::System::get_time()
       << "\n-->\n";
 
   out << "<VTKFile type=\"Collection\" version=\"0.1\" ByteOrder=\"LittleEndian\">\n";
@@ -6277,16 +6218,10 @@ DataOutInterface<dim,spacedim>::write_pvtu_record (std::ostream &out,
 
   out << "<?xml version=\"1.0\"?>\n";
 
-  std::time_t  time1= std::time (0);
-  std::tm     *time = std::localtime(&time1);
   out << "<!--\n";
-  out << "#This file was generated by the deal.II library 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 << "#This file was generated by the deal.II library"
+      << " on " << Utilities::System::get_date()
+      << " at " << Utilities::System::get_time()
       << "\n-->\n";
 
   out << "<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
index c8bd42a2c549780d967e887570cd9961d8320e3d..5859972be3a182d17fab924928e89d47c404771c 100644 (file)
@@ -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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.