gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 62c3bd2 4/5: Option for Arithmetic's output ty


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 62c3bd2 4/5: Option for Arithmetic's output type
Date: Fri, 26 Aug 2016 17:37:28 +0000 (UTC)

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

    Option for Arithmetic's output type
    
    In commit ffd7f18 (Output type print and checks moved to libraries), the
    functions to check the output image type (FITS BITPIX value) were moved to
    the libraries to be accessible to all utilities. They were initially only
    defined in MakeProfiles. In this commit we have used them in Arithmetic.
    
    The type of Arithmetic's output is no longer an internal default, but a
    configurable parameter by the user (through the `--type'
    option. Internally, the used datatype is 'double', but this only concerns
    the final creation of the output.
---
 src/arithmetic/args.h             |   15 ++++++++++++++-
 src/arithmetic/arithmetic.c       |   30 ++++++++++++++----------------
 src/arithmetic/astarithmetic.conf |    1 +
 src/arithmetic/main.h             |    4 ++--
 src/arithmetic/ui.c               |   12 ++++++++++++
 5 files changed, 43 insertions(+), 19 deletions(-)

diff --git a/src/arithmetic/args.h b/src/arithmetic/args.h
index efd87f1..f34a4eb 100644
--- a/src/arithmetic/args.h
+++ b/src/arithmetic/args.h
@@ -82,7 +82,7 @@ const char doc[] =
 /* Available letters for short options:
 
    a b c d e f g i j k l m n p r s t u v w x y z
-   A B C E F G H I J L O Q R T U W X Y Z
+   A B C E F G H I J L O Q R U W X Y Z
 
    Number keys used: <=500
 
@@ -129,6 +129,14 @@ static struct argp_option options[] =
       "Output:",
       2
     },
+    {
+      "type",
+      'T',
+      "STR",
+      0,
+      "byte, short, long, longlong, float, double.",
+      2
+    },
 
 
     {
@@ -185,6 +193,11 @@ parse_opt(int key, char *arg, struct argp_state *state)
       break;
 
 
+    /* Output */
+    case 'T':
+      gal_checkset_known_types(arg, &p->type, NULL, 0);
+      p->up.typeset=1;
+      break;
 
     /* Operating modes: */
 
diff --git a/src/arithmetic/arithmetic.c b/src/arithmetic/arithmetic.c
index 6e5f589..f0925d1 100644
--- a/src/arithmetic/arithmetic.c
+++ b/src/arithmetic/arithmetic.c
@@ -155,9 +155,6 @@ pop_operand(struct imgarithparams *p, double *number, 
double **array,
       /* Free the HDU string: */
       free(hdu);
 
-      /* Set the bitpix of the output. */
-      if(bitpix==DOUBLE_IMG) p->obitpix=DOUBLE_IMG;
-
       /* Add to the number of popped FITS images: */
       ++p->popcounter;
     }
@@ -923,7 +920,6 @@ reversepolish(struct imgarithparams *p)
   /* Prepare the processing: */
   p->s0=p->s1=0;
   p->operands=NULL;
-  p->obitpix=FLOAT_IMG;
   p->addcounter=p->popcounter=0;
 
   /* Go over each input token and do the work. */
@@ -976,24 +972,26 @@ reversepolish(struct imgarithparams *p)
      FITS image, if not, simply print the floating point number. */
   if(p->operands->array)
     {
-      /* If none of the inputs had a double type, then convert the
-         output array into a float and then save it. Note that the
-         last operand must be an array. */
-      if(p->obitpix==FLOAT_IMG)
+      /* Internally, all arrays were double type. But the user could set
+         the the output type using the type option. So if the user has
+         asked for anything other than a double, we will have to convert
+         the arrays.*/
+      if(p->type==DOUBLE_IMG)
+        gal_fits_array_to_file(p->cp.output, "astimgarith",
+                               DOUBLE_IMG, p->operands->array,
+                               p->s0, p->s1, p->anyblank,
+                               p->wcs, NULL, SPACK_STRING);
+      else
         {
           gal_fits_change_type(p->operands->array, DOUBLE_IMG,
-                                    p->s0*p->s1, p->anyblank,
-                                    (void **)(&farray), FLOAT_IMG);
+                               p->s0*p->s1, p->anyblank,
+                               (void **)(&farray), p->type);
           gal_fits_array_to_file(p->cp.output, "astimgarith",
-                                 FLOAT_IMG, farray, p->s0, p->s1,
+                                 p->type, farray, p->s0, p->s1,
                                  p->anyblank, p->wcs, NULL,
                                  SPACK_STRING);
         }
-      else
-        gal_fits_array_to_file(p->cp.output, "astimgarith",
-                               DOUBLE_IMG, p->operands->array,
-                               p->s0, p->s1, p->anyblank,
-                               p->wcs, NULL, SPACK_STRING);
+
     }
   else
     printf("%g\n", p->operands->number);
diff --git a/src/arithmetic/astarithmetic.conf 
b/src/arithmetic/astarithmetic.conf
index 0a8361e..bdd347f 100644
--- a/src/arithmetic/astarithmetic.conf
+++ b/src/arithmetic/astarithmetic.conf
@@ -27,3 +27,4 @@
  hdu            0
 
 # Output:
+ type       float
diff --git a/src/arithmetic/main.h b/src/arithmetic/main.h
index 3b330d4..30430f4 100644
--- a/src/arithmetic/main.h
+++ b/src/arithmetic/main.h
@@ -71,6 +71,7 @@ struct uiparams
   char        *maskname;  /* Name of mask image.                        */
   char            *mhdu;  /* Mask image HDU.                            */
 
+  int           typeset;
   int       masknameset;
   int masknameallocated;
   int           mhduset;
@@ -93,13 +94,12 @@ struct imgarithparams
   size_t        popcounter;  /* The number of FITS images popped.       */
   size_t                s0;  /* Length of image along first C axis.     */
   size_t                s1;  /* Length of image along second C axis.    */
-  int              obitpix;  /* The type of the output image.           */
   int                 nwcs;  /* The number of WCS coordinates.          */
   struct wcsprm       *wcs;  /* The WCS structure.                      */
   int             anyblank;  /* If there are blank pixels in the image. */
 
   /* Output: */
-
+  int                 type;  /* User's desired output bixpix value.     */
 
   /* Operating mode: */
 
diff --git a/src/arithmetic/ui.c b/src/arithmetic/ui.c
index 54a0f1a..74ab080 100644
--- a/src/arithmetic/ui.c
+++ b/src/arithmetic/ui.c
@@ -122,6 +122,12 @@ readconfig(char *filename, struct imgarithparams *p)
       else if(strcmp(name, "output")==0)
         gal_checkset_allocate_copy_set(value, &cp->output,
                                        &cp->outputset);
+      else if(strcmp(name, "type")==0)
+        {
+          if(p->up.typeset) continue;
+          gal_checkset_known_types(value, &p->type, filename, lineno);
+          p->up.typeset=1;
+        }
 
 
       /* Operating modes: */
@@ -167,6 +173,8 @@ printvalues(FILE *fp, struct imgarithparams *p)
   fprintf(fp, "\n# Output:\n");
   if(cp->outputset)
     fprintf(fp, CONF_SHOWFMT"%s\n", "output", cp->output);
+  if(up->typeset)
+    gal_configfiles_print_type(fp, p->type);
 
 
   /* For the operating mode, first put the macro to print the common
@@ -191,6 +199,10 @@ checkifset(struct imgarithparams *p)
   char comment[100];
   size_t numhdus=gal_linkedlist_num_in_stll(p->hdus);
 
+  /* Output parameters: */
+  if(p->up.typeset==0)
+    GAL_CONFIGFILES_REPORT_NOTSET("type");
+
   /* Make sure the number of HDUs is not less than the total number of
      FITS images. If there are more HDUs than there are FITS images,
      there is no problem (since they can come from the configuration



reply via email to

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