gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 1af4ea9 062/113: Correct checks for kernel dim


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 1af4ea9 062/113: Correct checks for kernel dimension in NoiseChisel and Segment
Date: Fri, 16 Apr 2021 10:33:47 -0400 (EDT)

branch: master
commit 1af4ea9d19bd6a3a34ce6a29215e87de95b11ba3
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Correct checks for kernel dimension in NoiseChisel and Segment
    
    Until now, NoiseChisel wasn't checking if the dimensionality of the kernel
    is the same as the input. Also, Segment was checking the dimensionality
    after possibly setting `p->kernel=NULL' (when `--kernel=none' is called,
    which caused a segmentation fault).
    
    With this commit, we now check the dimensionality of the kernel in both
    NoiseChisel and Segment. In both cases, this check is also done only when
    `--kernel' has not been `none'.
---
 bin/noisechisel/ui.c | 14 ++++++++++++--
 bin/segment/ui.c     | 19 +++++++++++--------
 2 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/bin/noisechisel/ui.c b/bin/noisechisel/ui.c
index 156dc7e..4bb3d12 100644
--- a/bin/noisechisel/ui.c
+++ b/bin/noisechisel/ui.c
@@ -420,9 +420,19 @@ ui_prepare_kernel(struct noisechiselparams *p)
      kernel. */
   if(p->kernelname)
     {
+      /* Read the kernel. */
       if( strcmp(p->kernelname, UI_NO_CONV_KERNEL_NAME) )
-        p->kernel=gal_fits_img_read_kernel(p->kernelname, p->khdu,
-                                           p->cp.minmapsize);
+        {
+          /* Read the kernel into memory. */
+          p->kernel=gal_fits_img_read_kernel(p->kernelname, p->khdu,
+                                             p->cp.minmapsize);
+
+          /* Make sure it has the same dimensions as the input. */
+          if( p->kernel->ndim != p->input->ndim )
+            error(EXIT_FAILURE, 0, "%s (hdu %s): is %zuD, however, %s (%s) "
+                  "is a %zuD dataset", p->kernelname, p->khdu,
+                  p->kernel->ndim, p->inputname, p->cp.hdu, p->input->ndim);
+        }
       else
         p->kernel=NULL;
     }
diff --git a/bin/segment/ui.c b/bin/segment/ui.c
index 648aaf4..8231dc3 100644
--- a/bin/segment/ui.c
+++ b/bin/segment/ui.c
@@ -513,16 +513,19 @@ ui_prepare_kernel(struct segmentparams *p)
     {
       /* Read the kernel. */
       if( strcmp(p->kernelname, UI_NO_CONV_KERNEL_NAME) )
-        p->kernel=gal_fits_img_read_kernel(p->kernelname, p->khdu,
-                                           p->cp.minmapsize);
+        {
+          /* Read the kernel into memory. */
+          p->kernel=gal_fits_img_read_kernel(p->kernelname, p->khdu,
+                                             p->cp.minmapsize);
+
+          /* Make sure it has the same dimensions as the input. */
+          if( p->kernel->ndim != p->input->ndim )
+            error(EXIT_FAILURE, 0, "%s (hdu %s): is %zuD, however, %s (%s) "
+                  "is a %zuD dataset", p->kernelname, p->khdu,
+                  p->kernel->ndim, p->inputname, p->cp.hdu, p->input->ndim);
+        }
       else
         p->kernel=NULL;
-
-      /* Make sure it has the same dimensions as the input. */
-      if( p->kernel->ndim != p->input->ndim )
-        error(EXIT_FAILURE, 0, "%s (hdu %s): is %zuD, however, %s (%s) is a"
-              "%zuD dataset", p->kernelname, p->khdu, p->kernel->ndim,
-              p->inputname, p->cp.hdu, p->input->ndim);
     }
   else
     {



reply via email to

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