[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 61aec7b 019/113: Convolve name and dimensional
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 61aec7b 019/113: Convolve name and dimensionality checks |
Date: |
Fri, 16 Apr 2021 10:33:34 -0400 (EDT) |
branch: master
commit 61aec7bbb82b686b8ebb2cd4c6ee08a99dad1bd1
Author: Mohammad Akhlaghi <akhlaghi@gnu.org>
Commit: Mohammad Akhlaghi <akhlaghi@gnu.org>
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 | 33 ++++++++++++++++++++++++++++++---
lib/fits.c | 31 ++++++++++++++++---------------
2 files changed, 46 insertions(+), 18 deletions(-)
diff --git a/bin/convolve/ui.c b/bin/convolve/ui.c
index 59f472b..342a045 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,9 +356,16 @@ ui_preparations(struct convolveparams *p)
p->input->wcs=gal_wcs_read(p->filename, cp->hdu, 0, 0, &p->input->nwcs);
- /* See if there are any blank values. */
+ /* Domain specific checks. */
if(p->domain==CONVOLVE_DOMAIN_FREQUENCY)
{
+ /* Check the dimensionality. */
+ if(p->input->ndim!=2)
+ error(EXIT_FAILURE, 0, "%s (hdu %s) has %zu dimensions. Frequency "
+ "domain convolution currently only operates on 2D images",
+ p->filename, cp->hdu, p->input->ndim);
+
+ /* Blank values. */
if( gal_blank_present(p->input, 1) )
fprintf(stderr, "\n----------------------------------------\n"
"######## %s WARNING ########\n"
@@ -361,8 +380,16 @@ ui_preparations(struct convolveparams *p)
PROGRAM_NAME);
}
else
- gal_tile_full_sanity_check(p->filename, cp->hdu, p->input, &cp->tl);
-
+ {
+ /* Check the dimensionality. */
+ if(p->input->ndim!=2 && p->input->ndim!=3)
+ error(EXIT_FAILURE, 0, "%s (hdu %s) has %zu dimensions. Spatial "
+ "domain convolution currently only operates on 2D images or "
+ "3D cubes", p->filename, cp->hdu, p->input->ndim);
+
+ /* Tessellation checks. */
+ gal_tile_full_sanity_check(p->filename, cp->hdu, p->input, &cp->tl);
+ }
/* Read the file specified by --kernel. If makekernel is specified, then
diff --git a/lib/fits.c b/lib/fits.c
index 6cf7621..f970c0b 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -102,12 +102,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 +124,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;
}
- [gnuastro-commits] master fb3660f 037/113: MakeCatalog works in 3D, (continued)
- [gnuastro-commits] master fb3660f 037/113: MakeCatalog works in 3D, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 73fdf0c 006/113: MakeProfiles builds 3D ellipsoids, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 03d73fe 011/113: Some minor corrections in code and comments, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 87ab805 014/113: Identifiers for integer constants in BZERO comparisons, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 1483201 009/113: Noised cube created in make check, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master bdeaba9 012/113: Corrected name of 3D catalog for tarball inclusion, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 6b53c5e 015/113: Bug fixes in master: commits 1ff1c25 and 540af65, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master adeb1c6 016/113: NoiseChisel's convolution step in 3D completed, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master ace4160 017/113: New --mcolisbrightness option for MakeProfiles, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master f06acc5 018/113: Merged recent work from master, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 61aec7b 019/113: Convolve name and dimensionality checks,
Mohammad Akhlaghi <=
- [gnuastro-commits] master 4627ddf 021/113: NoiseChisel segmentation working in 3D, test added, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 1560a54 022/113: Default NoiseChisel kernel in 3D changed to 1.5 pixels, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 4d2508f 028/113: Fixed NoiseChisel opening and dilation and merged with master, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 4223e60 025/113: Suggestions on viewing/inspecting NoiseChisel's output, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 6086579 031/113: Merged recent work in master (corrected conflicts), Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master b0d5fab 034/113: Merged recent work from master, no conflicts, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 06798a5 035/113: Crop's --checkcenter works on 3D dataset, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master fd51c80 050/113: Imported recent work from master, no conflicts, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master a4dbaba 055/113: Recent work in master imported, minor conflict fixed, Mohammad Akhlaghi, 2021/04/16
- [gnuastro-commits] master 0597cea 058/113: Imported work in master, no conflicts, Mohammad Akhlaghi, 2021/04/16