gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 3551402 1/3: No blank lines in MakeCatalogs te


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 3551402 1/3: No blank lines in MakeCatalogs text table outputs
Date: Tue, 23 May 2017 20:04:58 -0400 (EDT)

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

    No blank lines in MakeCatalogs text table outputs
    
    Until now, when the output was a text file, empty lines were present in the
    middle of the comments. This is inconvenient for table readers like AWK,
    you have to check for both comments and empty lines (and ignore
    them). Without any empty lines, you can just ignore the commented ones. The
    main problem was with the usage of `ctime' which prints a new-line
    character in the end of its output. This new-line character is now manually
    removed. Also the other comments don't add any new-line characters either.
    
    Some other corrections in this commit:
    
     - The WCS structure is now read unconditionally in MakeCatalog. Until now,
       it would only be read when there was a WCS-related column. But it is
       also necessary to report the pixel area in the comments of the
       catalog. So that condition was removed.
    
     - When the user specifies a text file as output, the input value of
       `p->cp.tableformat' is now ignored and it is set to
       `GAL_TABLE_FORMAT_TXT'. This is done to help decide which comments
       should be added to the catalog in the end.
    
     - In `ui_check_options_and_arguments', `one' was not initialized! It is
       now set to `1' as it should have been. This caused a crash in one of our
       tests because the compiler had given it a value of zero.
    
     - In the option management system, the `set' flag should not be set for
       the `--config' option (which is unique). This has been corrected.
---
 bin/mkcatalog/mkcatalog.c |  8 ++++----
 bin/mkcatalog/ui.c        | 41 ++++++++++++++++-------------------------
 lib/options.c             | 12 +++++++-----
 3 files changed, 27 insertions(+), 34 deletions(-)

diff --git a/bin/mkcatalog/mkcatalog.c b/bin/mkcatalog/mkcatalog.c
index 926079d..b8d1978 100644
--- a/bin/mkcatalog/mkcatalog.c
+++ b/bin/mkcatalog/mkcatalog.c
@@ -665,11 +665,14 @@ mkcatalog_outputs_same_start(struct mkcatalogparams *p, 
int o0c1,
      FITS, this will be automatically included). */
   if(p->cp.tableformat==GAL_TABLE_FORMAT_TXT && gal_git_describe())
     {
-      asprintf(&str, "# Directory commit %s\n", gal_git_describe());
+      asprintf(&str, "Working directory commit %s", gal_git_describe());
       gal_list_str_add(&comments, str, 0);
     }
 
+  /* Write the date. However, `ctime' is going to put a new-line character
+     in the end of its string, so we are going to remove it manually. */
   asprintf(&str, "%s started on %s", PROGRAM_NAME, ctime(&p->rawtime));
+  str[strlen(str)-1]='\0';
   gal_list_str_add(&comments, str, 0);
 
 
@@ -797,9 +800,6 @@ mkcatalog_outputs_same_start(struct mkcatalogparams *p, int 
o0c1,
 
   if(p->cp.tableformat==GAL_TABLE_FORMAT_TXT)
     {
-      asprintf(&str, "-------------------------------------------\n");
-      gal_list_str_add(&comments, str, 0);
-
       asprintf(&str, "--------- Table columns ---------");
       gal_list_str_add(&comments, str, 0);
     }
diff --git a/bin/mkcatalog/ui.c b/bin/mkcatalog/ui.c
index fac76a3..a8855c1 100644
--- a/bin/mkcatalog/ui.c
+++ b/bin/mkcatalog/ui.c
@@ -327,9 +327,8 @@ ui_check_options_and_arguments(struct mkcatalogparams *p)
 static void
 ui_preparations_read_inputs(struct mkcatalogparams *p)
 {
-  size_t one;
-  gal_list_i32_t *tmp;
-  int readclumps=0, readwcs=0;
+  size_t one=1;
+  int readclumps=0;
   char *namestypes, **strarr=NULL;
   gal_data_t *zero, *key=gal_data_array_calloc(1);
   char *skyfile=p->skyfile ? p->skyfile : p->inputname;
@@ -481,25 +480,10 @@ ui_preparations_read_inputs(struct mkcatalogparams *p)
     p->clumps=gal_data_copy_to_new_type_free(p->clumps, GAL_TYPE_INT32);
 
 
-  /* If any WCS related parameter is requested then read the input's WCS
-     structure. */
-  for(tmp=p->columnids; tmp!=NULL; tmp=tmp->next)
-    if(readwcs==0)
-      switch(tmp->v)
-        {
-        case UI_KEY_RA:
-        case UI_KEY_DEC:
-        case UI_KEY_GEORA:
-        case UI_KEY_GEODEC:
-        case UI_KEY_CLUMPSRA:
-        case UI_KEY_CLUMPSDEC:
-        case UI_KEY_CLUMPSGEORA:
-        case UI_KEY_CLUMPSGEODEC:
-          readwcs=1;
-          break;
-        }
-  if(readwcs)
-    p->input->wcs=gal_wcs_read(p->inputname, p->cp.hdu, 0, 0, &p->input->nwcs);
+  /* Read the WCS structure of the input dataset. Even if no WCS-related
+     columns are requested, we still need it to report the pixel area of
+     the input dataset. */
+  p->input->wcs=gal_wcs_read(p->inputname, p->cp.hdu, 0, 0, &p->input->nwcs);
 
 
   /* Clean up. */
@@ -738,9 +722,16 @@ ui_preparations_outnames(struct mkcatalogparams *p)
   /* Set the output filename */
   if(p->cp.output)
     {
-      /* Make sure the given output filename corresponds to the
-         `tableformat' option. */
-      gal_tableintern_check_fits_format(p->cp.output, p->cp.tableformat);
+      /* If the output name is a FITS file, then
+         `gal_tableintern_check_fits_format' will see if the tableformat
+         corresponds to a FITS table or not. If the output name isn't a
+         FITS file then the current value of `p->cp.tableformat' is
+         irrelevant and it must be set to text. We use this value in the
+         end to determine specific features. */
+      if( gal_fits_name_is_fits(p->cp.output) )
+        gal_tableintern_check_fits_format(p->cp.output, p->cp.tableformat);
+      else
+        p->cp.tableformat=GAL_TABLE_FORMAT_TXT;
 
       /* If a clumps image has been read, then we have two outputs. */
       if(p->clumps) ui_preparations_both_names(p);
diff --git a/lib/options.c b/lib/options.c
index 1ab94ca..bc57997 100644
--- a/lib/options.c
+++ b/lib/options.c
@@ -442,7 +442,8 @@ gal_options_read_searchin(struct argp_option *option, char 
*arg,
       /* Note that `gal_data_type_as_string' returns a static string. But
          the output must be an allocated string so we can free it. */
       gal_checkset_allocate_copy(
-        gal_tableintern_searchin_as_string( *(uint8_t *)(option->value)), 
&str);
+        gal_tableintern_searchin_as_string( *(uint8_t *)(option->value)),
+        &str);
       return str;
     }
   else
@@ -451,7 +452,7 @@ gal_options_read_searchin(struct argp_option *option, char 
*arg,
       if(option->set) return NULL;
 
       /* Read the value. */
-      if(( *(uint8_t *)(option->value)=gal_tableintern_string_to_searchin(arg))
+      if((*(uint8_t *)(option->value)=gal_tableintern_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 "
@@ -491,7 +492,7 @@ gal_options_read_tableformat(struct argp_option *option, 
char *arg,
       if(option->set) return NULL;
 
       /* Read the value. */
-      if( (*(uint8_t *)(option->value) = gal_tableintern_string_to_format(arg) 
)
+      if( (*(uint8_t *)(option->value)=gal_tableintern_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 "
@@ -897,9 +898,10 @@ gal_options_read_check(struct argp_option *option, char 
*arg, char *filename,
         }
 
       /* Call the function to parse the value, flag the option as set and
-         return. */
+         return (except for the `--config' option, which must always be
+         unset). */
       option->func(option, arg, filename, lineno, topass);
-      option->set=GAL_OPTIONS_SET;
+      if(option->key!=GAL_OPTIONS_KEY_CONFIG) option->set=GAL_OPTIONS_SET;
       return;
     }
 



reply via email to

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