gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master cfb3be8: Convolve name and dimensionality chec


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master cfb3be8: Convolve name and dimensionality checks
Date: Mon, 7 Aug 2017 09:11:53 -0400 (EDT)

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

    Convolve name and dimensionality checks
    
    The Convolve program wasn't checking the sanity of the input file names and
    the dimensionality of the input. These checks are now implemented in
    `bin/convolve/ui.c'.
    
    Also to help in reading, the spaces in `gal_fits_name_is_fits' were
    adjusted and `gal_fits_suffix_is_fits' was made more simple/efficient by
    avoiding simultaneous checks with and without a dot.
---
 bin/convolve/ui.c | 19 +++++++++++++++++++
 lib/fits.c        | 32 ++++++++++++++++----------------
 2 files changed, 35 insertions(+), 16 deletions(-)

diff --git a/bin/convolve/ui.c b/bin/convolve/ui.c
index 59f472b..0df6486 100644
--- a/bin/convolve/ui.c
+++ b/bin/convolve/ui.c
@@ -220,6 +220,12 @@ ui_read_check_only_options(struct convolveparams *p)
 {
   struct gal_options_common_params *cp=&p->cp;
 
+  /* Make sure the kernel name is a FITS file and a HDU is given. */
+  if( gal_fits_name_is_fits(p->kernelname)==0 )
+    error(EXIT_FAILURE, 0, "`%s' is not a recognized FITS file name",
+          p->kernelname);
+
+
   /* Read the domain from a string into an integer. */
   if( !strcmp("spatial", p->domainstr) )
     p->domain=CONVOLVE_DOMAIN_SPATIAL;
@@ -229,6 +235,7 @@ ui_read_check_only_options(struct convolveparams *p)
     error(EXIT_FAILURE, 0, "domain value `%s' not recognized. Please use "
           "either `spatial' or `frequency'", p->domainstr);
 
+
   /* If we are in the spatial domain, make sure that the necessary
      parameters are set. */
   if( p->domain==CONVOLVE_DOMAIN_SPATIAL )
@@ -259,6 +266,11 @@ ui_check_options_and_arguments(struct convolveparams *p)
      a HDU is also given. */
   if(p->filename==NULL)
     error(EXIT_FAILURE, 0, "no input file is specified");
+
+  /* Make sure the input name is a FITS file name. */
+  if( gal_fits_name_is_fits(p->filename)==0 )
+    error(EXIT_FAILURE, 0, "`%s' is not a recognized FITS file name",
+          p->filename);
 }
 
 
@@ -344,6 +356,13 @@ ui_preparations(struct convolveparams *p)
   p->input->wcs=gal_wcs_read(p->filename, cp->hdu, 0, 0, &p->input->nwcs);
 
 
+  /* Currently Convolve only works on 2D images. */
+  if(p->input->ndim!=2)
+    error(EXIT_FAILURE, 0, "%s (hdu %s) has %zu dimensions. Currently "
+          "Convolve only operates on 2D images", p->filename, cp->hdu,
+          p->input->ndim);
+
+
   /* See if there are any blank values. */
   if(p->domain==CONVOLVE_DOMAIN_FREQUENCY)
     {
diff --git a/lib/fits.c b/lib/fits.c
index 6cf7621..d172a6c 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -92,7 +92,6 @@ gal_fits_io_error(int status, char *message)
 /*************************************************************
  **************           FITS names           ***************
  *************************************************************/
-
 /* IMPORTANT NOTE: if other compression suffixes are add to this function,
    include them in `gal_checkset_automatic_output', so the compression
    suffix can be skipped when the user doesn't specify an output
@@ -102,12 +101,12 @@ gal_fits_name_is_fits(char *name)
 {
   size_t len;
   len=strlen(name);
-  if ( ( len>=3 && strcmp(&name[len-3], "fit") == 0 )
-       || ( len>=4 && strcmp(&name[len-4], "fits") == 0 )
-       || ( len>=7 && strcmp(&name[len-7], "fits.gz") == 0 )
-       || ( len>=6 && strcmp(&name[len-6], "fits.Z") == 0 )
-       || ( len>=3 && strcmp(&name[len-3], "imh") == 0 )
-       || ( len>=7 && strcmp(&name[len-7], "fits.fz") == 0 ) )
+  if ( (    len>=3 && strcmp(&name[len-3], "fit"     ) == 0 )
+       || ( len>=4 && strcmp(&name[len-4], "fits"    ) == 0 )
+       || ( len>=7 && strcmp(&name[len-7], "fits.gz" ) == 0 )
+       || ( len>=6 && strcmp(&name[len-6], "fits.Z"  ) == 0 )
+       || ( len>=3 && strcmp(&name[len-3], "imh"     ) == 0 )
+       || ( len>=7 && strcmp(&name[len-7], "fits.fz" ) == 0 ) )
     return 1;
   else
     return 0;
@@ -124,15 +123,16 @@ gal_fits_name_is_fits(char *name)
 int
 gal_fits_suffix_is_fits(char *suffix)
 {
-  if (strcmp(suffix, "fit") == 0        || strcmp(suffix, ".fit") == 0
-      || strcmp(suffix, "fits") == 0    || strcmp(suffix, ".fits") == 0
-      || strcmp(suffix, "fits.gz") == 0 || strcmp(suffix, ".fits.gz") == 0
-      || strcmp(suffix, "fits.Z") == 0  || strcmp(suffix, ".fits.Z") == 0
-      || strcmp(suffix, "imh") == 0     || strcmp(suffix, ".imh") == 0
-      || strcmp(suffix, "fits.fz") == 0 || strcmp(suffix, ".fits.fz") == 0)
-   return 1;
- else
-   return 0;
+  char *nodot = suffix[0]=='.' ? (suffix+1) : suffix;
+  if ( strcmp(   nodot, "fit"     ) == 0
+       || strcmp(nodot, "fits"    ) == 0
+       || strcmp(nodot, "fits.gz" ) == 0
+       || strcmp(nodot, "fits.Z"  ) == 0
+       || strcmp(nodot, "imh"     ) == 0
+       || strcmp(nodot, "fits.fz" ) == 0 )
+    return 1;
+  else
+    return 0;
 }
 
 



reply via email to

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