gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master a2fd24c: Table: informative error message for


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master a2fd24c: Table: informative error message for wcstoimg and imgtowcs
Date: Fri, 10 Jul 2020 17:52:45 -0400 (EDT)

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

    Table: informative error message for wcstoimg and imgtowcs
    
    These two column arithmetic operators need the same number of operands as
    the dimensions in the input WCS structure. However, until now, when the
    proper number of columns wasn't given to them, they would just complain
    with "not enough operands" which can be really confusing in practice (it
    happened for myself! I was using these operators in an IFU cube, but since
    I was so focused on the RA and Dec, I forgot about the spectral dimension
    and was so confused by this error message that I had to come to the code to
    find out the real cause!!!).
    
    With this commit, a new optional argument has been given to the
    'arithmetic_stack_pop' function (which is in charge of popping operand) for
    this job! When it isn't NULL, the given string will be printed after the
    main error message. Currently its only active for these two operators (we
    can easily add one for the rest if they need it).
---
 bin/table/arithmetic.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/bin/table/arithmetic.c b/bin/table/arithmetic.c
index a4c6d69..94fadcb 100644
--- a/bin/table/arithmetic.c
+++ b/bin/table/arithmetic.c
@@ -315,7 +315,7 @@ arithmetic_indexs_final(struct tableparams *p, size_t 
*colmatch)
 /********************       Low-level tools      *********************/
 /*********************************************************************/
 static gal_data_t *
-arithmetic_stack_pop(gal_data_t **stack, int operator)
+arithmetic_stack_pop(gal_data_t **stack, int operator, char *errormsg)
 {
   gal_data_t *out=*stack;
 
@@ -323,8 +323,8 @@ arithmetic_stack_pop(gal_data_t **stack, int operator)
   if(*stack)
     *stack=(*stack)->next;
   else
-    error(EXIT_FAILURE, 0, "not enough operands for '%s'",
-          arithmetic_operator_name(operator));
+    error(EXIT_FAILURE, 0, "not enough operands for '%s'%s",
+          arithmetic_operator_name(operator), errormsg?errormsg:"");
 
   /* Remove the 'next' element to break from the stack and return. */
   out->next=NULL;
@@ -377,16 +377,21 @@ static void
 arithmetic_wcs(struct tableparams *p, gal_data_t **stack, int operator)
 {
   gal_data_t *tmp;
+  char errormsg[100];
   struct wcsprm *wcs=p->wcs;
   size_t i, ndim=p->wcs->naxis;
   gal_data_t *coord[3]={NULL, NULL, NULL};
 
+  /* Prepare the (possibly necessaary!) error message for the number of
+     popped operand. */
+  sprintf(errormsg, " (input WCS has %zu dimensions)", ndim);
+
   /* Pop all the necessary datasets and make sure they are
      double-precision. NOTE: the top dataset on the stack is the
      highest-dimensional dataset. */
   for(i=0;i<ndim;++i)
     {
-      tmp=arithmetic_stack_pop(stack, operator);
+      tmp=arithmetic_stack_pop(stack, operator, errormsg);
       tmp=gal_data_copy_to_new_type_free(tmp, GAL_TYPE_FLOAT64);
       coord[ndim-i-1]=tmp;
     }
@@ -457,16 +462,16 @@ arithmetic_distance(struct tableparams *p, gal_data_t 
**stack, int operator)
   double (*distance_func)(double, double, double, double);
 
   /* Pop the columns for point 'b'.*/
-  tmp=arithmetic_stack_pop(stack, operator);
+  tmp=arithmetic_stack_pop(stack, operator, NULL);
   tmp=gal_data_copy_to_new_type_free(tmp, GAL_TYPE_FLOAT64);
-  b=arithmetic_stack_pop(stack, operator);
+  b=arithmetic_stack_pop(stack, operator, NULL);
   b=gal_data_copy_to_new_type_free(b, GAL_TYPE_FLOAT64);
   b->next=tmp;
 
   /* Pop the columns for point 'a'.*/
-  tmp=arithmetic_stack_pop(stack, operator);
+  tmp=arithmetic_stack_pop(stack, operator, NULL);
   tmp=gal_data_copy_to_new_type_free(tmp, GAL_TYPE_FLOAT64);
-  a=arithmetic_stack_pop(stack, operator);
+  a=arithmetic_stack_pop(stack, operator, NULL);
   a=gal_data_copy_to_new_type_free(a, GAL_TYPE_FLOAT64);
   a->next=tmp;
 
@@ -594,18 +599,18 @@ arithmetic_operator_run(struct tableparams *p, gal_data_t 
**stack,
       switch(num_operands)
         {
         case 1:
-          d1=arithmetic_stack_pop(stack, operator);
+          d1=arithmetic_stack_pop(stack, operator, NULL);
           break;
 
         case 2:
-          d2=arithmetic_stack_pop(stack, operator);
-          d1=arithmetic_stack_pop(stack, operator);
+          d2=arithmetic_stack_pop(stack, operator, NULL);
+          d1=arithmetic_stack_pop(stack, operator, NULL);
           break;
 
         case 3:
-          d3=arithmetic_stack_pop(stack, operator);
-          d2=arithmetic_stack_pop(stack, operator);
-          d1=arithmetic_stack_pop(stack, operator);
+          d3=arithmetic_stack_pop(stack, operator, NULL);
+          d2=arithmetic_stack_pop(stack, operator, NULL);
+          d1=arithmetic_stack_pop(stack, operator, NULL);
           break;
 
         case -1:



reply via email to

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