gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master dd603fb4: Makefile extensions: two new functio


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master dd603fb4: Makefile extensions: two new functions for upper/lower case
Date: Thu, 28 Dec 2023 06:35:36 -0500 (EST)

branch: master
commit dd603fb4c60a2354832c4f515c10d4ba84baca56
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Makefile extensions: two new functions for upper/lower case
    
    Until now, the basic text functions would just select words within the
    given string. But there are more basic text operations that are missing in
    GNU Make's default functions.
    
    In this commit, two new functions have been added to convert the input
    string to upper or lower case.
---
 NEWS                             |   3 ++
 doc/gnuastro.texi                | 102 ++++++++++++++++++++++++++++++---------
 lib/checkset.c                   |  12 +++++
 lib/gnuastro-internal/checkset.h |   3 ++
 lib/makeplugin.c                 |  77 ++++++++++++++++++++++++++---
 5 files changed, 167 insertions(+), 30 deletions(-)

diff --git a/NEWS b/NEWS
index 747b8f75..65d9995c 100644
--- a/NEWS
+++ b/NEWS
@@ -73,6 +73,9 @@ See the end of the file for license conditions.
                  you want something similar to 3-sigma (the default), you
                  should set the MAD multiple to 5 (the default).
 
+*** Makefile extension
+  - 'ast-text-to-upper': convert input string to upper-case.
+  - 'ast-text-to-lower': convert input string to lower-case.
 *** Library
 **** Functions
   - gal_dimension_collapse_mclip_mad: MAD-clipped MAD.
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 0337ffad..99733163 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -825,6 +825,11 @@ Makefile extensions (for GNU Make)
 * Loading the Gnuastro Make functions::  How to find and load Gnuastro's Make 
library.
 * Makefile functions of Gnuastro::  The available functions.
 
+Makefile functions of Gnuastro
+
+* Text functions for Makefiles::  Basic text operations to supplement Make.
+* Astronomy functions for Makefiles::  Astronomy/FITS related functions.
+
 Library
 
 * Review of library fundamentals::  Guide on libraries and linking.
@@ -35510,7 +35515,9 @@ All Gnuastro Make functions start with the 
@command{ast-} prefix (similar to the
 After you have loaded Gnuastro's shared library for Makefiles within your 
Makefile, you can call these functions just like any Make function.
 For instructions on how to load Gnuastro's Make functions, see @ref{Loading 
the Gnuastro Make functions}.
 
-The Make functions in Gnuastro have been recently added (in August 2022), and 
will be gradually increasing, as we find the need for more specialized 
functions.
+There are two types of Make functions in Gnuastro's Make extensions:
+1) Basic operations on text which more general than astronomy or Gnuastro, see 
@ref{Text functions for Makefiles}).
+2) Operations that are directly related to astronomy (mostly FITS files) and 
Gnuastro, see @ref{Astronomy functions for Makefiles}).
 
 @cartouche
 @noindent
@@ -35523,32 +35530,19 @@ Otherwise, each time the value is used, the function 
will be expanded (possibly
 For more, see the 
@url{https://www.gnu.org/software/make/manual/html_node/Flavors.html, The two 
flavors of variables} in the GNU Make manual.
 @end cartouche
 
-@table @code
-@item $(ast-version-is STRING)
-@cindex Reproducibility
-Returns @code{1} if the version of the used Gnuastro is equal to 
@code{STRING}, and @code{0} otherwise.
-This is useful/critical for obtaining reproducible results on different 
systems.
-It can be used in combination with 
@url{https://www.gnu.org/software/make/manual/html_node/Conditionals.html, 
Conditionals in Make} to ensure the required version of Gnuastro is going to be 
used in your workflow.
-
-For example, in the minimal working Makefile below, we are using it to specify 
if the default (first) target (@code{all}) should have any prerequisites (and 
let the workflow start), or if it should simply print a message (that the 
required version of Gnuastro isn't installed) and abort (without any 
prerequisites).
-
-@example
-load /usr/local/lib/libgnuastro_make.so
-
-gnuastro-version = 0.19
-ifeq ($(ast-version-is $(gnuastro-version)),1)
-all: paper.pdf
-else
-all:; @@echo "Please use Gnuastro $(gnuastro-version)"
-endif
+@menu
+* Text functions for Makefiles::  Basic text operations to supplement Make.
+* Astronomy functions for Makefiles::  Astronomy/FITS related functions.
+@end menu
 
-result.fits: input.fits
-        astnoisechisel $< --output=$@@
+@node Text functions for Makefiles, Astronomy functions for Makefiles, 
Makefile functions of Gnuastro, Makefile functions of Gnuastro
+@subsection Text functions for Makefiles
 
-paper.pdf: result.fits
-        pdflatex --halt-on-error paper.tex
-@end example
+The functions described below are generic (not limited to astronomy/FITS) 
functions that operate on plain text.
+You can see these as functions that should have been implemented in GNU Make 
itself.
+The names of these functions start with @code{ast-text-*} and each has a fully 
working example to demonstrate its usage.
 
+@table @code
 @item $(ast-text-contains STRING, TEXT)
 Returns all white-space-separated words in @code{TEXT} that contain the 
@code{STRING}, removing any words that @emph{do not} match.
 For example, the following minimal Makefile will only print the @code{bAaz 
Aah} word of the list.
@@ -35578,6 +35572,66 @@ all:
      echo $(ast-text-not-contains Aa, $(list))
 @end example
 
+@item $(ast-text-to-upper STRING)
+Returns the input string but with all characters in UPPER-CASE.
+For example, the following minimal Makefile will print @code{FOOO BAAR UGGH} 
word of the list.
+
+@example
+load /usr/local/lib/libgnuastro_make.so
+
+list   = fOOo bAar UggH
+ulist := $(ast-text-to-upper $(list))
+all:; echo $(ulist)
+@end example
+
+@item $(ast-text-to-lower STRING)
+Returns the input string but with all characters in lower-case.
+For example, the following minimal Makefile will print @code{fooo baar uggh} 
word of the list.
+
+@example
+load /usr/local/lib/libgnuastro_make.so
+
+list  = fOOo bAar UggH
+list := $(ast-text-to-lower $(list))
+all:; echo $(ulist)
+@end example
+
+@end table
+
+
+@node Astronomy functions for Makefiles,  , Text functions for Makefiles, 
Makefile functions of Gnuastro
+@subsection Astronomy functions for Makefiles
+
+FITS files (the standard data format in astronomy) have unique features 
(header keywords and HDUs) that can greatly help designing workflows in 
Makefiles.
+The Makefile extension functions of this section allow you to optimally use 
those features within your pipelines.
+Besides FITS, when desinging your workflow/pipeline with Gnuastro, there are 
also special features like version checking that simplify your design.
+
+@table @code
+@item $(ast-version-is STRING)
+@cindex Reproducibility
+Returns @code{1} if the version of the used Gnuastro is equal to 
@code{STRING}, and @code{0} otherwise.
+This is useful/critical for obtaining reproducible results on different 
systems.
+It can be used in combination with 
@url{https://www.gnu.org/software/make/manual/html_node/Conditionals.html, 
Conditionals in Make} to ensure the required version of Gnuastro is going to be 
used in your workflow.
+
+For example, in the minimal working Makefile below, we are using it to specify 
if the default (first) target (@code{all}) should have any prerequisites (and 
let the workflow start), or if it should simply print a message (that the 
required version of Gnuastro isn't installed) and abort (without any 
prerequisites).
+
+@example
+load /usr/local/lib/libgnuastro_make.so
+
+gnuastro-version = 0.19
+ifeq ($(ast-version-is $(gnuastro-version)),1)
+all: paper.pdf
+else
+all:; @@echo "Please use Gnuastro $(gnuastro-version)"
+endif
+
+result.fits: input.fits
+        astnoisechisel $< --output=$@@
+
+paper.pdf: result.fits
+        pdflatex --halt-on-error paper.tex
+@end example
+
 @item $(ast-fits-with-keyvalue KEYNAME, KEYVALUES, HDU, FITS_FILES)
 Will select only the FITS files (from a list of many in @code{FITS_FILES}, 
non-FITS files are ignored), where the @code{KEYNAME} keyword has the value(s) 
given in @code{KEYVALUES}.
 Only the HDU given in the @code{HDU} argument will be checked.
diff --git a/lib/checkset.c b/lib/checkset.c
index 16e99b82..54b3ba09 100644
--- a/lib/checkset.c
+++ b/lib/checkset.c
@@ -352,6 +352,18 @@ gal_checkset_string_has_space(char *in)
 
 
 
+void
+gal_checkset_string_case_change(char *in, int toupper1_tolower0)
+{
+  if(toupper1_tolower0) do *in=toupper(*in); while(*in++!='\0');
+  else                  do *in=tolower(*in); while(*in++!='\0');
+
+}
+
+
+
+
+
 char *
 gal_checkset_malloc_cat(char *inname, char *toappend)
 {
diff --git a/lib/gnuastro-internal/checkset.h b/lib/gnuastro-internal/checkset.h
index ba02e213..882df4be 100644
--- a/lib/gnuastro-internal/checkset.h
+++ b/lib/gnuastro-internal/checkset.h
@@ -82,6 +82,9 @@ gal_checkset_known_types(char *optarg, int *type, char 
*filename,
 int
 gal_checkset_string_has_space(char *in);
 
+void
+gal_checkset_string_case_change(char *in, int toupper1_tolower0);
+
 char *
 gal_checkset_malloc_cat(char *inname, char *toappend);
 
diff --git a/lib/makeplugin.c b/lib/makeplugin.c
index 8b1222b9..f7ef09b0 100644
--- a/lib/makeplugin.c
+++ b/lib/makeplugin.c
@@ -48,9 +48,14 @@ int plugin_is_GPL_compatible=1;
 
 /* Names of the separate functions. */
 #define MAKEPLUGIN_FUNC_PREFIX "ast"
-static char *version_is_name=MAKEPLUGIN_FUNC_PREFIX"-version-is";
+/* Basic text functions */
+static char *text_to_upper=MAKEPLUGIN_FUNC_PREFIX"-text-to-upper";
+static char *text_to_lower=MAKEPLUGIN_FUNC_PREFIX"-text-to-lower";
 static char *text_contains_name=MAKEPLUGIN_FUNC_PREFIX"-text-contains";
 static char *text_not_contains_name=MAKEPLUGIN_FUNC_PREFIX"-text-not-contains";
+
+/* Gnuastro analysis functions */
+static char *version_is_name=MAKEPLUGIN_FUNC_PREFIX"-version-is";
 static char 
*fits_with_keyvalue_name=MAKEPLUGIN_FUNC_PREFIX"-fits-with-keyvalue";
 static char 
*fits_unique_keyvalues_name=MAKEPLUGIN_FUNC_PREFIX"-fits-unique-keyvalues";
 
@@ -168,6 +173,35 @@ makeplugin_text_not_contains(const char *caller, unsigned 
int argc,
 
 
 
+/* Convert input string to upper-case. */
+static char *
+makeplugin_text_to_upper(const char *caller, unsigned int argc,
+                         char **argv)
+{
+  char *out;
+  gal_checkset_allocate_copy(argv[0], &out);
+  gal_checkset_string_case_change(out, 1);
+  return out;
+}
+
+
+
+
+
+/* Convert input string to upper-case. */
+static char *
+makeplugin_text_to_lower(const char *caller, unsigned int argc,
+                         char **argv)
+{
+  char *out;
+  gal_checkset_allocate_copy(argv[0], &out);
+  gal_checkset_string_case_change(out, 0);
+  return out;
+}
+
+
+
+
 
 
 
@@ -291,14 +325,28 @@ makeplugin_fits_unique_keyvalues(const char *caller, 
unsigned int argc,
 
 
 
-/* Top-level function (that should have this name). */
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/**********************************************************************/
+/********          High-level interface with Make             *********/
+/**********************************************************************/
 int
 libgnuastro_make_gmk_setup()
 {
-  /* Return 1 if Gnuastro has the requested version. */
-  gmk_add_function(version_is_name, makeplugin_version_is,
-                   1, 1, GMK_FUNC_DEFAULT);
-
+  /* ------------ Basic useful text functions ------------ */
   /* Return the input strings that contain the given string. */
   gmk_add_function(text_contains_name, makeplugin_text_contains,
                    2, 2, GMK_FUNC_DEFAULT);
@@ -307,6 +355,23 @@ libgnuastro_make_gmk_setup()
   gmk_add_function(text_not_contains_name, makeplugin_text_not_contains,
                    2, 2, GMK_FUNC_DEFAULT);
 
+  /* Convert input sting into upper-case. */
+  gmk_add_function(text_to_upper, makeplugin_text_to_upper,
+                   1, 1, GMK_FUNC_DEFAULT);
+
+  /* Convert input string to lower-case. */
+  gmk_add_function(text_to_lower, makeplugin_text_to_lower,
+                   1, 1, GMK_FUNC_DEFAULT);
+
+
+
+
+
+  /* ------------ Gnuastro related functions ------------ */
+  /* Return 1 if Gnuastro has the requested version. */
+  gmk_add_function(version_is_name, makeplugin_version_is,
+                   1, 1, GMK_FUNC_DEFAULT);
+
   /* Select files, were a certain keyword has a certain value. It takes
      four arguments. */
   gmk_add_function(fits_with_keyvalue_name, makeplugin_fits_with_keyvalue,



reply via email to

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