gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master ffd7f18 3/5: Output type print and checks move


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master ffd7f18 3/5: Output type print and checks moved to libraries
Date: Fri, 26 Aug 2016 17:37:28 +0000 (UTC)

branch: master
commit ffd7f186b7484d2845d2af64843a99ed6ac97188
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    Output type print and checks moved to libraries
    
    Until now only MakeProfiles had an option to determine the output data type
    (BITPIX in FITS terminology). But Arithmetic (and soon probably other
    utilities) can also greatly benefit from this and if it is common enough,
    we can move the `--type' option to the common parameters.
    
    In order to enable the easy usage of this option the following two new
    library functions were defined: `gal_checkset_known_types' and
    `gal_configfiles_print_type'. The first will make sure the given value is a
    standard value and set the FITS macro for the type, the second will print
    the string value for the given integer macro type when the user wants to
    print the options and their values.
    
    Both these functions were already defined in MakeProfiles, but are now
    moved to the respective library and corrected in MakeProfiles.
---
 lib/checkset.c             |   50 ++++++++++++++++++++++++++++++++++++++++++++
 lib/configfiles.c          |   28 +++++++++++++++++++++++++
 lib/gnuastro/checkset.h    |   10 +++++++++
 lib/gnuastro/configfiles.h |    2 ++
 src/mkprof/args.h          |    3 ++-
 src/mkprof/ui.c            |   49 +++----------------------------------------
 6 files changed, 95 insertions(+), 47 deletions(-)

diff --git a/lib/checkset.c b/lib/checkset.c
index 33f725d..2795dfb 100644
--- a/lib/checkset.c
+++ b/lib/checkset.c
@@ -31,6 +31,8 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <unistd.h>
 #include <sys/stat.h>
 
+#include <fitsio.h>
+
 #include <gnuastro/checkset.h>
 
 
@@ -501,6 +503,54 @@ gal_checkset_any_double(char *optarg, double *var, char 
*lo, char so,
 
 
 /**************************************************************/
+/**********          Check fixed strings           ************/
+/**************************************************************/
+/* Check if the value to the `--type' option is recognized, if so set the
+   integer value. */
+void
+gal_checkset_known_types(char *optarg, int *bitpix, char *filename,
+                         size_t lineno)
+{
+  /* First check if the value is one of the accepted types. */
+  if     (strcmp(optarg, "byte")==0)     *bitpix=BYTE_IMG;
+  else if(strcmp(optarg, "short")==0)    *bitpix=SHORT_IMG;
+  else if(strcmp(optarg, "long")==0)     *bitpix=LONG_IMG;
+  else if(strcmp(optarg, "longlong")==0) *bitpix=LONGLONG_IMG;
+  else if(strcmp(optarg, "float")==0)    *bitpix=FLOAT_IMG;
+  else if(strcmp(optarg, "double")==0)   *bitpix=DOUBLE_IMG;
+  else
+    {
+      if(filename)
+        error_at_line(EXIT_FAILURE, 0, filename, lineno, "given value of "
+                      "the `type' option (`%s') is not recognized. It must "
+                      "be `byte', `short', `long', `longlong', `float', or "
+                      "`double'.", optarg);
+      else
+        error(EXIT_FAILURE, 0, "given value of the `--type' (`-T') option "
+              "(`%s') is not recognized. It must be `byte', `short', `long' "
+              "`longlong', `float', or `double'.", optarg);
+    }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/**************************************************************/
 /**********          My String functions:          ************/
 /**************************************************************/
 int
diff --git a/lib/configfiles.c b/lib/configfiles.c
index 3ce15a1..8864ca2 100644
--- a/lib/configfiles.c
+++ b/lib/configfiles.c
@@ -201,3 +201,31 @@ gal_configfiles_write_local_config_stop(char *indir, char 
*filename,
 
   return fp;
 }
+
+
+
+
+
+void
+gal_configfiles_print_type(FILE *fp, int bitpix)
+{
+  switch(bitpix)
+    {
+    case BYTE_IMG:
+      fprintf(fp, CONF_SHOWFMT"%s\n", "type", "byte");
+    case SHORT_IMG:
+      fprintf(fp, CONF_SHOWFMT"%s\n", "type", "short");
+    case LONG_IMG:
+      fprintf(fp, CONF_SHOWFMT"%s\n", "type", "long");
+    case LONGLONG_IMG:
+      fprintf(fp, CONF_SHOWFMT"%s\n", "type", "longlong");
+    case FLOAT_IMG:
+      fprintf(fp, CONF_SHOWFMT"%s\n", "type", "float");
+    case DOUBLE_IMG:
+      fprintf(fp, CONF_SHOWFMT"%s\n", "type", "double");
+    default:
+      error(EXIT_FAILURE, 0, "a bug! the value of bitpix is not recognized "
+            "in `gal_configfiles_print_type'. Please contact us at %s so "
+            "we can address the problem.", PACKAGE_BUGREPORT);
+    }
+}
diff --git a/lib/gnuastro/checkset.h b/lib/gnuastro/checkset.h
index 1de6428..51f2ab0 100644
--- a/lib/gnuastro/checkset.h
+++ b/lib/gnuastro/checkset.h
@@ -172,6 +172,16 @@ gal_checkset_any_double(char *optarg, double *var, char 
*lo, char so,
 
 
 
+/**************************************************************/
+/**********          Check fixed strings           ************/
+/**************************************************************/
+void
+gal_checkset_known_types(char *optarg, int *bitpix, char *filename,
+                         size_t lineno);
+
+
+
+
 
 
 
diff --git a/lib/gnuastro/configfiles.h b/lib/gnuastro/configfiles.h
index 113650d..5c67765 100644
--- a/lib/gnuastro/configfiles.h
+++ b/lib/gnuastro/configfiles.h
@@ -225,5 +225,7 @@ FILE *
 gal_configfiles_write_local_config_stop(char *indir, char *filename,
                                         char *spack, char *spack_name,
                                         char **outfilename);
+void
+gal_configfiles_print_type(FILE *fp, int bitpix);
 
 #endif
diff --git a/src/mkprof/args.h b/src/mkprof/args.h
index 1d97426..119a664 100644
--- a/src/mkprof/args.h
+++ b/src/mkprof/args.h
@@ -503,7 +503,8 @@ parse_opt(int key, char *arg, struct argp_state *state)
       p->up.replaceset=1;
       break;
     case 'T':
-      checksaveouttype(p, arg);
+      gal_checkset_known_types(arg, &p->up.type, NULL, 0);
+      p->up.typeset=1;
       break;
 
     /* Profiles: */
diff --git a/src/mkprof/ui.c b/src/mkprof/ui.c
index daafda0..ac444ca 100644
--- a/src/mkprof/ui.c
+++ b/src/mkprof/ui.c
@@ -66,30 +66,6 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 /**************************************************************/
 /**************       Options and parameters    ***************/
 /**************************************************************/
-/* Check if the value to the `--type' option is recognized,  */
-void
-checksaveouttype(struct mkprofparams *p, char *arg)
-{
-  /* First check if the value is one of the accepted types. */
-  if     (strcmp(arg, "byte")==0)     p->up.type=BYTE_IMG;
-  else if(strcmp(arg, "short")==0)    p->up.type=SHORT_IMG;
-  else if(strcmp(arg, "long")==0)     p->up.type=LONG_IMG;
-  else if(strcmp(arg, "longlong")==0) p->up.type=LONGLONG_IMG;
-  else if(strcmp(arg, "float")==0)    p->up.type=FLOAT_IMG;
-  else if(strcmp(arg, "double")==0)   p->up.type=DOUBLE_IMG;
-  else
-    error(EXIT_FAILURE, 0, "given value of the `--type' (`-T') option "
-          "(`%s') is not recognized. It must be `byte', `short', `long' "
-          "`longlong', `float', or `double'.", arg);
-
-  /* Flag this option as set: */
-  p->up.typeset=1;
-}
-
-
-
-
-
 void
 readconfig(char *filename, struct mkprofparams *p)
 {
@@ -173,7 +149,8 @@ readconfig(char *filename, struct mkprofparams *p)
       else if(strcmp(name, "type")==0)
         {
           if(p->up.typeset) continue;
-          checksaveouttype(p, value);
+          gal_checkset_known_types(value, &p->up.type, filename, lineno);
+          p->up.typeset=1;
         }
 
 
@@ -415,27 +392,7 @@ printvalues(FILE *fp, struct mkprofparams *p)
   if(up->replaceset)
     fprintf(fp, CONF_SHOWFMT"%d\n", "replace", p->replace);
   if(up->typeset)
-    {
-      switch(up->type)
-        {
-        case BYTE_IMG:
-          fprintf(fp, CONF_SHOWFMT"%s\n", "type", "byte");
-        case SHORT_IMG:
-          fprintf(fp, CONF_SHOWFMT"%s\n", "type", "short");
-        case LONG_IMG:
-          fprintf(fp, CONF_SHOWFMT"%s\n", "type", "long");
-        case LONGLONG_IMG:
-          fprintf(fp, CONF_SHOWFMT"%s\n", "type", "longlong");
-        case FLOAT_IMG:
-          fprintf(fp, CONF_SHOWFMT"%s\n", "type", "float");
-        case DOUBLE_IMG:
-          fprintf(fp, CONF_SHOWFMT"%s\n", "type", "double");
-        default:
-          error(EXIT_FAILURE, 0, "a bug! the value of up->type is not "
-                "recognized in `ui.c'. Please contact us at %s so we can "
-                "address the problem.", PACKAGE_BUGREPORT);
-        }
-    }
+    gal_configfiles_print_type(fp, p->up.type);
 
   fprintf(fp, "\n# Profiles:\n");
   if(up->tunitinpset)



reply via email to

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