gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master 613e1e8: Library (checkset): add timestamp fun


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 613e1e8: Library (checkset): add timestamp function
Date: Sun, 21 Nov 2021 11:05:05 -0500 (EST)

branch: master
commit 613e1e867e1d02ae3b54166b89bab701ed33c9da
Author: Pedram Ashofteh Ardakani <pedramardakani@pm.me>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Library (checkset): add timestamp function
    
    Until now, when it was necessary to create temporary debugging files during
    the development, there was no generic/easy way to generate their names in a
    systematic way. As a result, developers would be discouraged from making
    such files (that would ultimately slow the development cycle).
    
    With this commit, a new function called 'al_checkset_timestamp' has been
    added to Gnuastro's internal libray. This new function receives a filename
    (or any string), checks current system time, adds a YYYY-MM-DD prefix, a
    HH-MM-SS suffix, and replaces the file extension (if any) with given
    extension.
    
    The date prefix and time suffix are added in this order so that sorting
    same files within a working day will be easier. Same files will be stacked
    on top of each other regardless of their modification time, but based on
    their modification date!
---
 NEWS                             |  1 -
 lib/checkset.c                   | 39 +++++++++++++++++++++++++++++++++++++++
 lib/gnuastro-internal/checkset.h |  3 +++
 3 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index 4cee3f4..bfc2233 100644
--- a/NEWS
+++ b/NEWS
@@ -29,7 +29,6 @@ See the end of the file for license conditions.
      WCS. This was suggested by Jesús Varela.
 
   Fits:
-
    - If a 'CHECKSUM' keyword exists in a HDU and any of the keyword
      modification keywords are called, Fits will automatically update the
      checksum after all the changes are done. This is important to keep the
diff --git a/lib/checkset.c b/lib/checkset.c
index e4ddd04..c8e367a 100644
--- a/lib/checkset.c
+++ b/lib/checkset.c
@@ -5,6 +5,7 @@ This is part of GNU Astronomy Utilities (Gnuastro) package.
 Original author:
      Mohammad Akhlaghi <mohammad@akhlaghi.org>
 Contributing author(s):
+     Pedram Ashofteh Ardakani <pedramardakani@pm.me>
 Copyright (C) 2015-2021, Free Software Foundation, Inc.
 
 Gnuastro is free software: you can redistribute it and/or modify it
@@ -910,6 +911,7 @@ checkset_directory_writable(char *dirname)
 
 
 
+
 /* Check if dirname is actually a real directory and that we can
    actually write inside of it. To insure all conditions an actual
    file will be made */
@@ -984,3 +986,40 @@ gal_checkset_mkdir(char *dirname)
   /* Return the final 'errno'. */
   return errnum;
 }
+
+
+
+
+
+/* Timestamp the file name (or any other string) with a YYYY-MM-DD prefix
+   and a HH-MM-SS suffix. This is useful in making temporary debugging
+   files during a program. The 'filename' is wrapped between the dates so
+   it is easy to sort files by name and easily seperate files by their date
+   and name, where the same files will be stacked regardless of their
+   creation hour. */
+char *
+gal_checkset_timestamp(char *filename, char *newext)
+{
+  time_t t;
+  struct tm *now;
+  char suffix[20], prefix[20], *top, *rawname, *oldext;
+
+  /* Parse time */
+  time( &t );
+  now=localtime( &t );
+  strftime(prefix, 20, "%Y-%m-%d_", now);
+  strftime(suffix, 20, "_%H-%M-%S", now);
+
+  /* If parsing a filename, take care of its parent directory and
+     update the extension */
+  top=gal_checkset_dir_part(filename);
+  rawname=gal_checkset_not_dir_part(filename);
+  filename=gal_checkset_suffix_separate(rawname, &oldext);
+  filename=gal_checkset_malloc_cat(filename, suffix);
+  filename=gal_checkset_malloc_cat(prefix, filename);
+  filename=gal_checkset_malloc_cat(top, filename);
+  if(newext) filename=gal_checkset_malloc_cat(filename, newext);
+  else       filename=gal_checkset_malloc_cat(filename, oldext);
+
+  return filename;
+}
diff --git a/lib/gnuastro-internal/checkset.h b/lib/gnuastro-internal/checkset.h
index ec3810e..482810a 100644
--- a/lib/gnuastro-internal/checkset.h
+++ b/lib/gnuastro-internal/checkset.h
@@ -5,6 +5,7 @@ This is part of GNU Astronomy Utilities (Gnuastro) package.
 Original author:
      Mohammad Akhlaghi <mohammad@akhlaghi.org>
 Contributing author(s):
+     Pedram Ashofteh Ardakani <pedramardakani@pm.me>
 Copyright (C) 2015-2021, Free Software Foundation, Inc.
 
 Gnuastro is free software: you can redistribute it and/or modify it
@@ -93,6 +94,8 @@ gal_checkset_allocate_copy_set(char *arg, char **copy, int 
*set);
 char *
 gal_checkset_dataset_name(char *filename, char *hdu);
 
+char *
+gal_checkset_timestamp(char *filename, char *newext);
 
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]