gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 581de34 084/125: Option strings directly conve


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 581de34 084/125: Option strings directly converted to internal codes
Date: Sun, 23 Apr 2017 22:36:43 -0400 (EDT)

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

    Option strings directly converted to internal codes
    
    The `searchin' and `tableformat' options (like the `type' option), accept a
    string from the user (on the command-line or in configuration files), but
    then store the value internally as an integer for easy/fast checking and
    further processing. Until now, the input string would be stored in the
    `gal_options_common_params' and would go into the program for conversion to
    the internal code.
    
    Since `argp_option' now has a `func' field, it is now possible to define
    one function that will immediately parse the user's given value and store
    the string into `gal_options_common_params', so there is no more need to
    keep the user's input string. The program authors can also be sure that
    once option parsing is complete, the value is usable/recognized.
---
 bin/imgcrop/ui.c     | 10 +++---
 bin/imgwarp/args.h   | 13 --------
 bin/imgwarp/ui.c     | 14 ++++-----
 bin/table/ui.c       |  2 --
 doc/gnuastro.texi    | 37 ++++++++++++----------
 lib/commonopts.h     | 20 ++++++------
 lib/data.c           | 44 +++++++++++++-------------
 lib/gnuastro/data.h  | 50 ++++++++++++++---------------
 lib/gnuastro/table.h | 14 +++------
 lib/options.c        | 78 +++++++++++++++++++++++++++++++---------------
 lib/options.h        | 38 +++++++++++++----------
 lib/table.c          | 88 +++++++++++++++++++++++-----------------------------
 12 files changed, 207 insertions(+), 201 deletions(-)

diff --git a/bin/imgcrop/ui.c b/bin/imgcrop/ui.c
index c48a671..18d7366 100644
--- a/bin/imgcrop/ui.c
+++ b/bin/imgcrop/ui.c
@@ -352,12 +352,10 @@ ui_read_check_only_options(struct imgcropparams *p)
       if(p->cp.searchin==GAL_TABLE_SEARCH_INVALID)
         error(EXIT_FAILURE, 0, "%s: no field specified to search for "
               "columns. Please use the `--searchin' option to specify "
-              "which column meta-data you would like to search in: `%s', "
-              "`%s' and `%s'. You may also select columns by their number, "
-              "which won't use this option, but for complentess its best "
-              "for this option to have a value", p->catname,
-              GAL_TABLE_STRING_SEARCH_NAME, GAL_TABLE_STRING_SEARCH_UNIT,
-              GAL_TABLE_STRING_SEARCH_COMMENT);
+              "which column meta-data you would like to search in: `name', "
+              "`unit' and `comment'. You may also select columns by their "
+              "number, which won't use this option, but for complentess its "
+              "best for this option to have a value", p->catname);
 
       /* If it is a FITS file, we need the HDU. */
       if( gal_fits_name_is_fits(p->catname) && p->cathdu==NULL )
diff --git a/bin/imgwarp/args.h b/bin/imgwarp/args.h
index 9fc421a..214040a 100644
--- a/bin/imgwarp/args.h
+++ b/bin/imgwarp/args.h
@@ -89,19 +89,6 @@ struct argp_option program_options[] =
       GAL_OPTIONS_NOT_MANDATORY,
       GAL_OPTIONS_NOT_SET
     },
-    {
-      "type",
-      ARGS_OPTION_KEY_TYPE,
-      "STR",
-      0,
-      "uchar, short, long, longlong, float, double."
-      GAL_OPTIONS_GROUP_OUTPUT,
-      &p->typestr,
-      GAL_DATA_TYPE_STRING,
-      GAL_OPTIONS_RANGE_ANY,
-      GAL_OPTIONS_NOT_MANDATORY,
-      GAL_OPTIONS_NOT_SET
-    },
 
 
     {
diff --git a/bin/imgwarp/ui.c b/bin/imgwarp/ui.c
index 20daafe..5baa932 100644
--- a/bin/imgwarp/ui.c
+++ b/bin/imgwarp/ui.c
@@ -130,7 +130,7 @@ enum option_keys_enum
 /*********    Initialize & Parse command-line    **************/
 /**************************************************************/
 static void
-ui_initialize_options(struct tableparams *p,
+ui_initialize_options(struct imgwarpparams *p,
                       struct argp_option *program_options,
                       struct argp_option *gal_commonopts_options)
 {
@@ -167,7 +167,7 @@ ui_initialize_options(struct tableparams *p,
 error_t
 parse_opt(int key, char *arg, struct argp_state *state)
 {
-  struct tableparams *p = state->input;
+  struct imgwarpparams *p = state->input;
 
   /* Pass `gal_options_common_params' into the child parser.  */
   state->child_inputs[0] = &p->cp;
@@ -230,7 +230,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
 /* Read and check ONLY the options. When arguments are involved, do the
    check in `ui_check_options_and_arguments'. */
 static void
-ui_read_check_only_options(struct tableparams *p)
+ui_read_check_only_options(struct imgwarpparams *p)
 {
 
   /* Check if the format of the output table is valid, given the type of
@@ -244,7 +244,7 @@ ui_read_check_only_options(struct tableparams *p)
 
 
 static void
-ui_check_options_and_arguments(struct tableparams *p)
+ui_check_options_and_arguments(struct imgwarpparams *p)
 {
   /* Make sure an input file name was given and if it was a FITS file, that
      a HDU is also given. */
@@ -284,7 +284,7 @@ ui_check_options_and_arguments(struct tableparams *p)
 /***************       Preparations         *******************/
 /**************************************************************/
 void
-ui_preparations(struct tableparams *p)
+ui_preparations(struct imgwarpparams *p)
 {
   char *numstr;
   int tableformat;
@@ -386,7 +386,7 @@ ui_preparations(struct tableparams *p)
 /**************************************************************/
 
 void
-ui_read_check_inputs_setup(int argc, char *argv[], struct tableparams *p)
+ui_read_check_inputs_setup(int argc, char *argv[], struct imgwarpparams *p)
 {
   struct gal_options_common_params *cp=&p->cp;
 
@@ -460,7 +460,7 @@ ui_read_check_inputs_setup(int argc, char *argv[], struct 
tableparams *p)
 /************      Free allocated, report         *************/
 /**************************************************************/
 void
-ui_free_report(struct tableparams *p)
+ui_free_report(struct imgwarpparams *p)
 {
   /* Free the allocated arrays: */
   free(p->cp.hdu);
diff --git a/bin/table/ui.c b/bin/table/ui.c
index 9b0cf4e..9278a63 100644
--- a/bin/table/ui.c
+++ b/bin/table/ui.c
@@ -449,7 +449,5 @@ ui_free_report(struct tableparams *p)
   /* Free the allocated arrays: */
   free(p->cp.hdu);
   free(p->cp.output);
-  free(p->cp.searchinstr);
-  free(p->cp.tableformatstr);
   gal_data_free_ll(p->table);
 }
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index bb17b44..9f1bef2 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -5593,15 +5593,16 @@ convenient and, especially when the tables are large it 
can be very
 frustrating and prone to errors. Hence, table file formats (for example see
 @ref{Recognized table formats}) have ways to store additional information
 about the columns (meta-data). Some of the most common pieces of
-information about each column are its name, the units of data in the it,
-and a comment for longer/informal description of the column's data.
+information about each column are its @emph{name}, the @emph{units} of data
+in the it, and a @emph{comment} for longer/informal description of the
+column's data.
 
-To facilitate research with Gnuastro, besides the low-level column number,
-you can also select columns by matching, or searching, in these three
-fields. To view this meta-data for all the columns in the table, you can
-use @ref{Table} with the command below (replace @file{table-file} with the
-filename of your table, if its FITS, you might also need to specify the
-HDU/extension which contains the table):
+To facilitate research with Gnuastro, you can select columns by matching,
+or searching in these three fields, besides the low-level column number. To
+view the full list of information on the columns in the table, you can use
+the Table program (see @ref{Table}) with the command below (replace
address@hidden with the filename of your table, if its FITS, you might
+also need to specify the HDU/extension which contains the table):
 
 @example
 $ asttable --information table-file
@@ -5614,27 +5615,31 @@ Declination with @option{--deccol}. Thus, there is no 
unified common option
 name to select columns for all programs. However, when the program expects
 the column for a specific context (like the RA and Dec example above), the
 option names end in the @option{col} suffix (for example @option{--racol}
-and @option{--deccol}). These options accept both integer and string
-arguments.
+and @option{--deccol}). These options accept values in integer (column
+number), or string (metadata match/search) format.
 
 If the value can be parsed as a positive integer, it will be seen as the
 low-level column number. Note that column counting starts from 1, so if you
 ask for column 0, the respective program will abort with an error. When the
 value can't be interpretted as an a integer number, it will be seen as a
 string of characters which will be used to match/search in the table's
-meta-data. The field which the value will be compared with can be selected
-through the @option{--searchin} option, see @ref{Input output}. The
-matching will be done following this convention:
+meta-data. The meta-data field which the value will be compared with can be
+selected through the @option{--searchin} option, see @ref{Input
+output}. @option{--searchin} can take three values: @code{name},
address@hidden, @code{comment}. The matching will be done following this
+convention:
 
 @itemize
 @item
 If the value is enclosed in two slashes (for example @command{-r/RA_/}, or
 @option{--racol=/RA_/}), then it is assumed to be a regular expression with
-the same convention as GNU AWK. GNU AWK has a
address@hidden://wwww.gnu.org/s/gawk/manual/html_node/Regexp.html,complete
+the same convention as GNU AWK. GNU AWK has a very well written
address@hidden://www.gnu.org/software/gawk/manual/html_node/Regexp.html,
 chapter} describing regular expressions, so we we will not continue
 discussing it here. Regular expressions are a very powerful tool in
-matching text and useful in many contexts.
+matching text and useful in many contexts. We thus strongly encourage
+reviewing this chapter for greatly improving the quality of your work in
+many cases, not just for searching column meta-data in Gnuastro.
 
 @item
 When the string isn't inclosed between address@hidden/}'s, any column that 
exactly
diff --git a/lib/commonopts.h b/lib/commonopts.h
index 5eedf46..2535659 100644
--- a/lib/commonopts.h
+++ b/lib/commonopts.h
@@ -62,11 +62,12 @@ struct argp_option gal_commonopts_options[] =
       0,
       "Col. selection field: `name', `unit', `comment'.",
       GAL_OPTIONS_GROUP_INPUT,
-      &cp->searchinstr,
-      GAL_DATA_TYPE_STRING,
+      &cp->searchin,
+      GAL_DATA_TYPE_UINT8,
       GAL_OPTIONS_RANGE_ANY,
       GAL_OPTIONS_NOT_MANDATORY,
-      GAL_OPTIONS_NOT_SET
+      GAL_OPTIONS_NOT_SET,
+      gal_options_read_searchin
     },
     {
       "ignorecase",
@@ -106,12 +107,12 @@ struct argp_option gal_commonopts_options[] =
     {
       "type",
       GAL_OPTIONS_KEY_TYPE,
-      "STR",  /* Will be converted to `int' code by `gal_options_read_type'.*/
+      "STR",
       0,
-      "Numerical datatype of output",
+      "Data type of output: e.g., int16, float32, etc...",
       GAL_OPTIONS_GROUP_OUTPUT,
       &cp->type,
-      GAL_DATA_TYPE_INT32,
+      GAL_DATA_TYPE_UINT8,
       GAL_OPTIONS_RANGE_GT_0,
       GAL_OPTIONS_NOT_MANDATORY,
       GAL_OPTIONS_NOT_SET,
@@ -124,11 +125,12 @@ struct argp_option gal_commonopts_options[] =
       0,
       "Output table format: `fits-ascii', `fits-binary'.",
       GAL_OPTIONS_GROUP_OUTPUT,
-      &cp->tableformatstr,
-      GAL_DATA_TYPE_STRING,
+      &cp->tableformat,
+      GAL_DATA_TYPE_UINT8,
       GAL_OPTIONS_RANGE_ANY,
       GAL_OPTIONS_NOT_MANDATORY,
-      GAL_OPTIONS_NOT_SET
+      GAL_OPTIONS_NOT_SET,
+      gal_options_read_tableformat
     },
     {
       "dontdelete",
diff --git a/lib/data.c b/lib/data.c
index b41d169..33e6ebb 100644
--- a/lib/data.c
+++ b/lib/data.c
@@ -53,7 +53,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
  *************************************************************/
 
 char *
-gal_data_type_as_string(int type, int long_name)
+gal_data_type_as_string(uint8_t type, int long_name)
 {
   switch(type)
     {
@@ -120,7 +120,7 @@ gal_data_type_as_string(int type, int long_name)
 
 
 
-int
+uint8_t
 gal_data_string_as_type(char *str)
 {
   if(      !strcmp(str, "b")     || !strcmp(str, "bit") )
@@ -185,7 +185,7 @@ gal_data_string_as_type(char *str)
    type in the space (that must already be allocated before the call to
    this function) pointed to by in.  */
 void
-gal_data_type_min(int type, void *in)
+gal_data_type_min(uint8_t type, void *in)
 {
   switch(type)
     {
@@ -210,7 +210,7 @@ gal_data_type_min(int type, void *in)
 
 
 void
-gal_data_type_max(int type, void *in)
+gal_data_type_max(uint8_t type, void *in)
 {
   switch(type)
     {
@@ -238,7 +238,7 @@ gal_data_type_max(int type, void *in)
    that work on both, it is convenient to simiplify the check with this
    function. */
 int
-gal_data_is_linked_list(int type)
+gal_data_is_linked_list(uint8_t type)
 {
   return type==GAL_DATA_TYPE_STRLL;
 }
@@ -288,7 +288,7 @@ gal_data_dsize_is_different(gal_data_t *first, gal_data_t 
*second)
 
 
 size_t
-gal_data_sizeof(int type)
+gal_data_sizeof(uint8_t type)
 {
   /* Allocate space for the array to keep the image. */
   switch(type)
@@ -398,7 +398,7 @@ gal_data_copy_wcs(gal_data_t *in, gal_data_t *out)
    bytes each element needs will be determined internaly by this function
    using the datatype argument, so you don't have to worry about it. */
 void *
-gal_data_malloc_array(int type, size_t size)
+gal_data_malloc_array(uint8_t type, size_t size)
 {
   void *array;
 
@@ -416,7 +416,7 @@ gal_data_malloc_array(int type, size_t size)
 
 
 void *
-gal_data_calloc_array(int type, size_t size)
+gal_data_calloc_array(uint8_t type, size_t size)
 {
   void *array;
 
@@ -436,7 +436,7 @@ gal_data_calloc_array(int type, size_t size)
 /* Allocate space for one blank value of the given type and put the value
    in it. */
 void *
-gal_data_alloc_number(int type, void *number)
+gal_data_alloc_number(uint8_t type, void *number)
 {
   void *allocated;
 
@@ -591,7 +591,7 @@ gal_data_mmap(gal_data_t *data, int clear)
      structures (and not have to worry about which one to free later).
 */
 void
-gal_data_initialize(gal_data_t *data, void *array, int type,
+gal_data_initialize(gal_data_t *data, void *array, uint8_t type,
                     size_t ndim, size_t *dsize, struct wcsprm *wcs,
                     int clear, size_t minmapsize, char *name,
                     char *unit, char *comment)
@@ -683,7 +683,7 @@ gal_data_initialize(gal_data_t *data, void *array, int type,
    force the array into the hdd/ssd (mmap it), then set minmapsize=-1
    (largest possible size_t value), in this way, no file will be larger. */
 gal_data_t *
-gal_data_alloc(void *array, int type, size_t ndim, size_t *dsize,
+gal_data_alloc(void *array, uint8_t type, size_t ndim, size_t *dsize,
                struct wcsprm *wcs, int clear, size_t minmapsize,
                char *name, char *unit, char *comment)
 {
@@ -919,7 +919,7 @@ gal_data_add_existing_to_ll(gal_data_t **list, gal_data_t 
*newnode)
 
 
 void
-gal_data_add_to_ll(gal_data_t **list, void *array, int type, size_t ndim,
+gal_data_add_to_ll(gal_data_t **list, void *array, uint8_t type, size_t ndim,
                    size_t *dsize, struct wcsprm *wcs, int clear,
                    size_t minmapsize, char *name, char *unit, char *comment)
 {
@@ -1058,7 +1058,7 @@ gal_data_free_ll(gal_data_t *list)
 
    Note that for strings, pointer should actually be `char **'. */
 void
-gal_data_set_blank(void *pointer, int type)
+gal_data_set_blank(void *pointer, uint8_t type)
 {
   switch(type)
     {
@@ -1119,7 +1119,7 @@ gal_data_set_blank(void *pointer, int type)
 /* Allocate some space for the given type and put the blank value into
    it. */
 void *
-gal_data_alloc_blank(int type)
+gal_data_alloc_blank(uint8_t type)
 {
   void *out;
 
@@ -1139,7 +1139,7 @@ gal_data_alloc_blank(int type)
 
 /* Print the blank value as a string. */
 char *
-gal_data_blank_as_string(int type, int width)
+gal_data_blank_as_string(uint8_t type, int width)
 {
   char *blank;
   switch(type)
@@ -1445,7 +1445,7 @@ gal_data_flag_blank(gal_data_t *data)
 
 /* Only to be used in `data_copy_from_string'. */
 static void
-data_copy_to_string_not_parsed(char *string, void *to, int type)
+data_copy_to_string_not_parsed(char *string, void *to, uint8_t type)
 {
   if( strcmp(string, GAL_DATA_BLANK_STRING) )
     gal_data_set_blank(to, type);
@@ -1755,7 +1755,7 @@ data_copy_to_string(gal_data_t *from, gal_data_t *to)
 
 /* Copy a given data structure to a new one (possibly with a new type). */
 gal_data_t *
-gal_data_copy_to_new_type(gal_data_t *in, int newtype)
+gal_data_copy_to_new_type(gal_data_t *in, uint8_t newtype)
 {
   gal_data_t *out;
 
@@ -1807,7 +1807,7 @@ gal_data_copy_to_new_type(gal_data_t *in, int newtype)
 
 
 gal_data_t *
-gal_data_copy_to_new_type_free(gal_data_t *in, int type)
+gal_data_copy_to_new_type_free(gal_data_t *in, uint8_t type)
 {
   gal_data_t *out;
   out=gal_data_copy_to_new_type(in, type);
@@ -1845,7 +1845,7 @@ gal_data_out_type(gal_data_t *first, gal_data_t *second)
 void
 gal_data_to_same_type(gal_data_t *f,   gal_data_t *s,
                       gal_data_t **of, gal_data_t **os,
-                      int type, int freeinputs)
+                      uint8_t type, int freeinputs)
 {
   /* Change first dataset into the new type if necessary. */
   if( f->type != type )
@@ -1893,7 +1893,7 @@ gal_data_to_same_type(gal_data_t *f,   gal_data_t *s,
 #define WRITE_TO_STRING(CTYPE, FMT) asprintf(&str, FMT, *(CTYPE *)ptr);
 
 char *
-gal_data_write_to_string(void *ptr, int type, int quote_if_str_has_space)
+gal_data_write_to_string(void *ptr, uint8_t type, int quote_if_str_has_space)
 {
   char *c, *str;
   switch(type)
@@ -1961,7 +1961,7 @@ gal_data_string_to_number(char *string)
   int fnz=-1, lnz=0;     /* `F'irst (or `L'ast) `N'on-`Z'ero. */
   void *ptr, *numarr;
   char *tailptr, *cp;
-  int type, forcedfloat=0;
+  uint8_t type, forcedfloat=0;
 
   /* Define initial spaces to keep the value. */
   uint8_t   u8;   int8_t   i8;      uint16_t u16;   int16_t i16;
@@ -2058,7 +2058,7 @@ gal_data_string_to_number(char *string)
    If parsing was successful, it will return a 0. If there was a problem,
    it will return 1.  */
 int
-gal_data_string_to_type(void **out, char *string, int type)
+gal_data_string_to_type(void **out, char *string, uint8_t type)
 {
   long l;
   double d;
diff --git a/lib/gnuastro/data.h b/lib/gnuastro/data.h
index e47b59a..c9f16ec 100644
--- a/lib/gnuastro/data.h
+++ b/lib/gnuastro/data.h
@@ -144,7 +144,7 @@ typedef struct gal_data_t
 {
   /* Basic information on array of data. */
   void             *array;  /* Array keeping data elements.                */
-  int                type;  /* Type of data (from `gal_data_alltypes').    */
+  uint8_t            type;  /* Type of data (from `gal_data_alltypes').    */
   size_t             ndim;  /* Number of dimensions in the array.          */
   size_t           *dsize;  /* Size of array along each dimension.         */
   size_t             size;  /* Total number of data-elements.              */
@@ -177,19 +177,19 @@ typedef struct gal_data_t
  **************        Type information        ***************
  *************************************************************/
 char *
-gal_data_type_as_string(int type, int long_name);
+gal_data_type_as_string(uint8_t type, int long_name);
 
-int
+uint8_t
 gal_data_string_as_type(char *str);
 
 void
-gal_data_type_min(int type, void *in);
+gal_data_type_min(uint8_t type, void *in);
 
 void
-gal_data_type_max(int type, void *in);
+gal_data_type_max(uint8_t type, void *in);
 
 int
-gal_data_is_linked_list(int type);
+gal_data_is_linked_list(uint8_t type);
 
 
 
@@ -203,25 +203,24 @@ int
 gal_data_dsize_is_different(gal_data_t *first, gal_data_t *second);
 
 size_t
-gal_data_sizeof(int type);
+gal_data_sizeof(uint8_t type);
 
 void *
-gal_data_malloc_array(int type, size_t size);
+gal_data_malloc_array(uint8_t type, size_t size);
 
 void *
-gal_data_calloc_array(int type, size_t size);
+gal_data_calloc_array(uint8_t type, size_t size);
 
 void *
-gal_data_alloc_number(int type, void *number);
+gal_data_alloc_number(uint8_t type, void *number);
 
 void
-gal_data_initialize(gal_data_t *data, void *array, int type,
-                    size_t ndim, size_t *dsize, struct wcsprm *wcs,
-                    int clear, size_t minmapsize, char *name,
-                    char *unit, char *comment);
+gal_data_initialize(gal_data_t *data, void *array, uint8_t type, size_t ndim,
+                    size_t *dsize, struct wcsprm *wcs, int clear,
+                    size_t minmapsize, char *name, char *unit, char *comment);
 
 gal_data_t *
-gal_data_alloc(void *array, int type, size_t ndim, size_t *dsize,
+gal_data_alloc(void *array, uint8_t type, size_t ndim, size_t *dsize,
                struct wcsprm *wcs, int clear, size_t minmapsize,
                char *name, char *unit, char *comment);
 
@@ -246,7 +245,7 @@ void
 gal_data_add_existing_to_ll(gal_data_t **list, gal_data_t *newnode);
 
 void
-gal_data_add_to_ll(gal_data_t **list, void *array, int type, size_t ndim,
+gal_data_add_to_ll(gal_data_t **list, void *array, uint8_t type, size_t ndim,
                    size_t *dsize, struct wcsprm *wcs, int clear,
                    size_t minmapsize, char *name, char *unit, char *comment);
 
@@ -272,13 +271,13 @@ gal_data_free_ll(gal_data_t *list);
  **************          Blank data            ***************
  *************************************************************/
 void
-gal_data_set_blank(void *pointer, int type);
+gal_data_set_blank(void *pointer, uint8_t type);
 
 void *
-gal_data_alloc_blank(int type);
+gal_data_alloc_blank(uint8_t type);
 
 char *
-gal_data_blank_as_string(int type, int width);
+gal_data_blank_as_string(uint8_t type, int width);
 
 void
 gal_data_apply_mask(gal_data_t *in, gal_data_t *mask);
@@ -300,10 +299,10 @@ gal_data_flag_blank(gal_data_t *data);
  **************            Copying             ***************
  *************************************************************/
 gal_data_t *
-gal_data_copy_to_new_type(gal_data_t *in, int newtype);
+gal_data_copy_to_new_type(gal_data_t *in, uint8_t newtype);
 
 gal_data_t *
-gal_data_copy_to_new_type_free(gal_data_t *in, int type);
+gal_data_copy_to_new_type_free(gal_data_t *in, uint8_t type);
 
 gal_data_t *
 gal_data_copy(gal_data_t *in);
@@ -312,16 +311,15 @@ int
 gal_data_out_type(gal_data_t *first, gal_data_t *second);
 
 void
-gal_data_to_same_type(gal_data_t *f, gal_data_t *s,
-                      gal_data_t **of, gal_data_t **os,
-                      int type, int freeinputs);
+gal_data_to_same_type(gal_data_t *f, gal_data_t *s, gal_data_t **of,
+                      gal_data_t **os, uint8_t type, int freeinputs);
 
 
 /*************************************************************
  **************              Write             ***************
  *************************************************************/
 char *
-gal_data_write_to_string(void *ptr, int type, int quote_if_str_has_space);
+gal_data_write_to_string(void *ptr, uint8_t type, int quote_if_str_has_space);
 
 
 
@@ -332,7 +330,7 @@ gal_data_t *
 gal_data_string_to_number(char *string);
 
 int
-gal_data_string_to_type(void **out, char *string, int type);
+gal_data_string_to_type(void **out, char *string, uint8_t type);
 
 
 
diff --git a/lib/gnuastro/table.h b/lib/gnuastro/table.h
index a5d95d8..fa53d82 100644
--- a/lib/gnuastro/table.h
+++ b/lib/gnuastro/table.h
@@ -70,9 +70,6 @@ __BEGIN_C_DECLS  /* From C++ preparations */
 
 /* Formats of table storage for input or output, as strings and
    integers. */
-#define GAL_TABLE_STRING_FORMAT_TXT   "txt"
-#define GAL_TABLE_STRING_FORMAT_AFITS "fits-ascii"
-#define GAL_TABLE_STRING_FORMAT_BFITS "fits-binary"
 enum gal_table_types
 {
   GAL_TABLE_FORMAT_INVALID,       /* Invalid (=0 by C standard).       */
@@ -89,9 +86,6 @@ enum gal_table_types
 /* When the desired column is not a number, should the string match or
    regular expression search be in the name, units or comments of the
    columns? */
-#define GAL_TABLE_STRING_SEARCH_NAME    "name"
-#define GAL_TABLE_STRING_SEARCH_UNIT    "unit"
-#define GAL_TABLE_STRING_SEARCH_COMMENT "comment"
 enum gal_table_where_to_search
 {
   GAL_TABLE_SEARCH_INVALID,       /* Invalid (=0 by C standard).     */
@@ -128,15 +122,15 @@ enum gal_table_diplay_formats
 
 
 /* Functions */
-int
+uint8_t
 gal_table_string_to_format(char *string);
 
+uint8_t
+gal_table_string_to_searchin(char *string);
+
 void
 gal_table_check_fits_format(char *filename, int tableformat);
 
-int
-gal_table_string_to_searchin(char *string);
-
 void
 gal_table_too_many_columns(char *filename);
 
diff --git a/lib/options.c b/lib/options.c
index 051ed47..8a0b8ea 100644
--- a/lib/options.c
+++ b/lib/options.c
@@ -178,16 +178,63 @@ void
 gal_options_read_type(struct argp_option *option, char *arg,
                       char *filename, size_t lineno)
 {
-  int type=gal_data_string_as_type(arg);
-  if(type==GAL_DATA_TYPE_INVALID)
+  /* If the option is already set, just return. */
+  if(option->set) return;
+
+  /* Read the value. */
+  if ( (*(uint8_t *)(option->value) = gal_data_string_as_type(arg) )
+       == GAL_DATA_TYPE_INVALID )
     error_at_line(EXIT_FAILURE, 0, filename, lineno, "`%s' (value to "
-                  "`%s' option) couldn't be recognized as a known type."
+                  "`%s' option) couldn't be recognized as a known type.\n\n"
                   "For the full list of known types, please run the "
-                  "following command:\n\n"
+                  "following command (press SPACE key to go down, and `q' "
+                  "to return to the command-line):\n\n"
                   "    $ info gnuastro \"Numeric data types\"\n",
                   arg, option->name);
-  else
-    *(int *)(option->value)=type;
+}
+
+
+
+
+
+void
+gal_options_read_searchin(struct argp_option *option, char *arg,
+                          char *filename, size_t lineno)
+{
+  /* If the option is already set, just return. */
+  if(option->set) return;
+
+  /* Read the value. */
+  if( ( *(uint8_t *)(option->value)=gal_table_string_to_searchin(arg) )
+      == GAL_TABLE_SEARCH_INVALID )
+    error_at_line(EXIT_FAILURE, 0, filename, lineno, "`%s' (value to "
+                  "`%s' option) couldn't be recognized as a known table "
+                  "search-in field (`name', `unit', or `comment').\n\n"
+                  "For more explanation, please run the following command "
+                  "(press SPACE key to go down, and `q' to return to the "
+                  "command-line):\n\n"
+                  "    $ info gnuastro \"Selecting table columns\"\n",
+                  arg, option->name);
+}
+
+
+
+
+
+void
+gal_options_read_tableformat(struct argp_option *option, char *arg,
+                             char *filename, size_t lineno)
+{
+  /* If the option is already set, then you don't have to do anything. */
+  if(option->set) return;
+
+  /* Read the value. */
+  if( (*(uint8_t *)(option->value) = gal_table_string_to_format(arg) )
+      ==GAL_TABLE_FORMAT_INVALID )
+    error_at_line(EXIT_FAILURE, 0, filename, lineno, "`%s' (value to "
+                  "`%s' option) couldn't be recognized as a known table "
+                  "format field (`txt', `fits-ascii', or `fits-binary').\n\n",
+                  arg, option->name);
 }
 
 
@@ -522,7 +569,6 @@ gal_options_read_check(struct argp_option *option, char 
*arg, char *filename,
       options_sanity_check(option, arg, filename, lineno);
     }
 
-
   /* Flip the `set' flag to `GAL_OPTIONS_SET'. */
   option->set=GAL_OPTIONS_SET;
 }
@@ -991,9 +1037,6 @@ options_reverse_lists_check_mandatory(struct 
gal_options_common_params *cp,
 void
 gal_options_read_config_set(struct gal_options_common_params *cp)
 {
-  size_t i;
-  struct argp_option *coptions=cp->coptions;
-
   /* Parse all the configuration files. */
   gal_options_parse_config_files(cp);
 
@@ -1003,21 +1046,6 @@ gal_options_read_config_set(struct 
gal_options_common_params *cp)
   options_reverse_lists_check_mandatory(cp, cp->poptions);
   options_reverse_lists_check_mandatory(cp, cp->coptions);
 
-  /* Some of the values that the user gives as strings should be stored
-     internally as integers. For the program-specific options, this is done
-     in the program's `ui.c', here, we do it for the common options. */
-  for(i=0; !gal_options_is_last(&coptions[i]); ++i)
-    if(coptions[i].set)
-      switch(coptions[i].key)
-      {
-      case GAL_OPTIONS_KEY_SEARCHIN:
-        cp->searchin=gal_table_string_to_searchin(cp->searchinstr);
-        break;
-      case GAL_OPTIONS_KEY_TABLEFORMAT:
-        cp->tableformat=gal_table_string_to_format(cp->tableformatstr);
-        break;
-      }
-
   /* Abort if any of the mandatory options are not set. */
   gal_options_abort_if_mandatory_missing(cp);
 }
diff --git a/lib/options.h b/lib/options.h
index 3b376a2..b1ddc9c 100644
--- a/lib/options.h
+++ b/lib/options.h
@@ -153,31 +153,29 @@ struct gal_options_common_params
 {
   /* Input. */
   char                    *hdu; /* Image extension.                      */
-  unsigned char     ignorecase; /* Ignore case when matching col info.   */
-  char            *searchinstr; /* Column info to search (as a string).  */
+  uint8_t             searchin; /* Column meta-data to match/search.     */
+  uint8_t           ignorecase; /* Ignore case when matching col info.   */
 
   /* Output. */
   char                 *output; /* Directory containg output.            */
-  int                     type; /* Data type of output.                  */
-  unsigned char     dontdelete; /* ==1: Don't delete existing file.      */
-  unsigned char   keepinputdir; /* Keep input directory for auto output. */
-  char         *tableformatstr; /* Format of output table (as a string). */
+  uint8_t                 type; /* Data type of output.                  */
+  uint8_t           dontdelete; /* ==1: Don't delete existing file.      */
+  uint8_t         keepinputdir; /* Keep input directory for auto output. */
+  uint8_t          tableformat; /* Internal code for output table format.*/
 
   /* Operating modes. */
-  unsigned char          quiet; /* Only print errors.                    */
+  uint8_t                quiet; /* Only print errors.                    */
   size_t            numthreads; /* Number of threads to use.             */
   size_t            minmapsize; /* Minimum bytes necessary to use mmap.  */
-  unsigned char            log; /* Make a log file.                      */
+  uint8_t                  log; /* Make a log file.                      */
 
   /* Configuration files. */
-  unsigned char    printparams; /* To print the full list of parameters. */
-  unsigned char     setdirconf; /* To write the directory config file.   */
-  unsigned char     setusrconf; /* To write teh user config config file. */
-  unsigned char     lastconfig; /* This is the last configuration file.  */
-
-  /* For internal purposes. */
-  int                 searchin; /* Internal code for user's input.       */
-  int              tableformat; /* Internal code for output table format.*/
+  uint8_t          printparams; /* To print the full list of parameters. */
+  uint8_t           setdirconf; /* To write the directory config file.   */
+  uint8_t           setusrconf; /* To write teh user config config file. */
+  uint8_t           lastconfig; /* This is the last configuration file.  */
+
+  /* For internal (to option processing) purposes. */
   char           *program_name; /* Official name to be used in text.     */
   char           *program_exec; /* Program's executable name.            */
   char         *program_bibtex; /* BibTeX record for this program.       */
@@ -214,6 +212,14 @@ gal_options_read_type(struct argp_option *option, char 
*arg,
                       char *filename, size_t lineno);
 
 void
+gal_options_read_searchin(struct argp_option *option, char *arg,
+                          char *filename, size_t lineno);
+
+void
+gal_options_read_tableformat(struct argp_option *option, char *arg,
+                             char *filename, size_t lineno);
+
+void
 gal_options_free(struct argp_option *options);
 
 
diff --git a/lib/table.c b/lib/table.c
index 79cad70..ae1c8d1 100644
--- a/lib/table.c
+++ b/lib/table.c
@@ -44,30 +44,54 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 /***************               Table types                ***************/
 /************************************************************************/
 /* Return the type of desired table based on a standard string. */
-int
+uint8_t
 gal_table_string_to_format(char *string)
 {
-  if(string)
+  if(string)                    /* Its not NULL. */
     {
-      if( !strcmp(string, GAL_TABLE_STRING_FORMAT_TXT) )
+      if( !strcmp(string, "txt") )
         return GAL_TABLE_FORMAT_TXT;
 
-      else if( !strcmp(string, GAL_TABLE_STRING_FORMAT_AFITS) )
+      else if( !strcmp(string, "fits-ascii") )
         return GAL_TABLE_FORMAT_AFITS;
 
-      else if( !strcmp(string, GAL_TABLE_STRING_FORMAT_BFITS) )
+      else if( !strcmp(string, "fits-binary") )
         return GAL_TABLE_FORMAT_BFITS;
 
       else
-        error(EXIT_FAILURE, 0, "`%s' couldn't be interpretted as a valid "
-              "table format. The known formats are `%s', `%s', and `%s'",
-              string, GAL_TABLE_STRING_FORMAT_TXT,
-              GAL_TABLE_STRING_FORMAT_AFITS,
-              GAL_TABLE_STRING_FORMAT_BFITS);
+        return GAL_TABLE_FORMAT_INVALID;
     }
+  else
+    return GAL_TABLE_FORMAT_INVALID;
+}
+
+
 
-  /* If string was not NULL, this function won't reach here. */
-  return -1;
+
+
+/* In programs, the `searchin' variable is much more easier to format in as
+   a description than an integer (which is what `gal_table_read_cols'
+   needs). This function will check the string value and give the
+   corresponding integer value.*/
+uint8_t
+gal_table_string_to_searchin(char *string)
+{
+  if(string)                    /* Its not NULL. */
+    {
+      if(strcmp(string, "name")==0)
+        return GAL_TABLE_SEARCH_NAME;
+
+      else if(strcmp(string, "unit")==0)
+        return GAL_TABLE_SEARCH_UNIT;
+
+      else if(strcmp(string, "comment")==0)
+        return GAL_TABLE_SEARCH_COMMENT;
+
+      else
+        return GAL_TABLE_SEARCH_INVALID;
+    }
+  else
+    return GAL_TABLE_SEARCH_INVALID;
 }
 
 
@@ -89,17 +113,15 @@ gal_table_check_fits_format(char *filename, int 
tableformat)
         error(EXIT_FAILURE, 0, "`%s' (output file) is a FITS file but the "
               "desired format of the FITS table has not been specified with "
               "the `--tableformat' option. For FITS tables, this option can "
-              "take two values: `%s', or `%s'", filename,
-              GAL_TABLE_STRING_FORMAT_AFITS, GAL_TABLE_STRING_FORMAT_BFITS);
+              "take two values: `fits-ascii', or `fits-binary'", filename);
 
       /* When `--tableformat' didn't have the correct value. */
       if( tableformat != GAL_TABLE_FORMAT_AFITS
           && tableformat != GAL_TABLE_FORMAT_BFITS )
         error(EXIT_FAILURE, 0, "`%s' (output file) is a FITS file but "
               "is not a recognized FITS table format. For FITS tables, "
-              "`--tableformat' can take two values: `%s', or `%s'",
-              filename, GAL_TABLE_STRING_FORMAT_AFITS,
-              GAL_TABLE_STRING_FORMAT_BFITS);
+              "`--tableformat' can take two values: `fits-ascii', or "
+              "`fits-binary'", filename);
     }
 }
 
@@ -107,38 +129,6 @@ gal_table_check_fits_format(char *filename, int 
tableformat)
 
 
 
-/* In programs, the `searchin' variable is much more easier to format in as a
-   description than an integer (which is what `gal_table_read_cols'
-   needs). This function will check the string value and give the
-   corresponding integer value.*/
-int
-gal_table_string_to_searchin(char *string)
-{
-  if(strcmp(string, GAL_TABLE_STRING_SEARCH_NAME)==0)
-    return GAL_TABLE_SEARCH_NAME;
-
-  else if(strcmp(string, GAL_TABLE_STRING_SEARCH_UNIT)==0)
-    return GAL_TABLE_SEARCH_UNIT;
-
-  else if(strcmp(string, GAL_TABLE_STRING_SEARCH_COMMENT)==0)
-    return GAL_TABLE_SEARCH_COMMENT;
-
-  else
-    error(EXIT_FAILURE, 0, "`--searchin' only recognizes the values "
-          "`%s', `%s', and `%s', you have asked for `%s'",
-          GAL_TABLE_STRING_SEARCH_NAME, GAL_TABLE_STRING_SEARCH_UNIT,
-          GAL_TABLE_STRING_SEARCH_COMMENT, string);
-
-  /* Report an error control reaches here. */
-  error(EXIT_FAILURE, 0, "A bug! please contact us at %s so we can address "
-        "the problem. For some reason control has reached the end of "
-        "`gal_table_string_to_searchin'", PACKAGE_BUGREPORT);
-  return -1;
-}
-
-
-
-
 /* Programs that read columns might match more than one column for a given
    property, for example it might happen (due to bad table design) that
    multiple columns have the same name, or the user uses regular



reply via email to

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