gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 327c7d3 6/7: Library (wcs.c): rename array to


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 327c7d3 6/7: Library (wcs.c): rename array to list converter
Date: Mon, 4 Oct 2021 18:51:29 -0400 (EDT)

branch: master
commit 327c7d31b2c5e615067e194340685919b7dd16f2
Author: Pedram Ashofteh Ardakani <pedramardakani@pm.me>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Library (wcs.c): rename array to list converter
    
    Until now, the 'wcs_convert_list_to_array' took a 'listtoarray'
    argument. If one, it would indeed convert a list to an array, and vice
    versa. However, since the function could convert both types to each other,
    the '..._list_to_array' in the function name could lead to confusion.
    
    With this commit, the function is renamed '..._list_to_from_array' to
    indicate the capability to convert both ways.
    
    Also, the parameter is renamed to 'to0from1' to facilitate the
    understanding of which integer should the developer provide for which way
    of conversion. For that matter, I had to swap the procedure inside if to
    cope with this new naming convention.
    
    Think of it this way: wcs_convert_list_to_from_array has 'to' as its first
    use (the '0' as zero-indexed), and 'from' as its second function, hence the
    '1' as its value.
---
 lib/wcs.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/lib/wcs.c b/lib/wcs.c
index b8a120e..32867dc 100644
--- a/lib/wcs.c
+++ b/lib/wcs.c
@@ -2245,8 +2245,8 @@ wcs_convert_sanity_check_alloc(gal_data_t *coords, struct 
wcsprm *wcs,
    list. But in WCSLIB, the input is a single array (with multiple
    columns). This function will convert between the two. */
 static void
-wcs_convert_list_to_array(gal_data_t *list, double *array, int *stat,
-                          size_t ndim, int listtoarray)
+wcs_convert_list_to_from_array(gal_data_t *list, double *array, int *stat,
+                               size_t ndim, int to0from1)
 {
   size_t i, d=0;
   gal_data_t *tmp;
@@ -2257,10 +2257,10 @@ wcs_convert_list_to_array(gal_data_t *list, double 
*array, int *stat,
          input into or output from WCSLIB. */
       for(i=0;i<list->size;++i)
         {
-          if(listtoarray)
-            array[i*ndim+d] = ((double *)(tmp->array))[i];
-          else
+          if(to0from1)
             ((double *)(tmp->array))[i] = stat[i] ? NAN : array[i*ndim+d];
+          else
+            array[i*ndim+d] = ((double *)(tmp->array))[i];
         }
 
       /* Increment the dimension. */
@@ -2313,7 +2313,7 @@ gal_wcs_world_to_img(gal_data_t *coords, struct wcsprm 
*wcs, int inplace)
 
   /* Write the values from the input list of separate columns into a single
      array (WCSLIB input). */
-  wcs_convert_list_to_array(coords, world, stat, wcs->naxis, 1);
+  wcs_convert_list_to_from_array(coords, world, stat, wcs->naxis, 0);
 
 
   /* Use WCSLIB's wcss2p for the conversion. */
@@ -2341,7 +2341,7 @@ gal_wcs_world_to_img(gal_data_t *coords, struct wcsprm 
*wcs, int inplace)
 
   /* Write the output from a single array (WCSLIB output) into the output
      list of this function. */
-  wcs_convert_list_to_array(out, pixcrd, stat, wcs->naxis, 0);
+  wcs_convert_list_to_from_array(out, pixcrd, stat, wcs->naxis, 1);
 
 
   /* Clean up. */
@@ -2376,7 +2376,7 @@ gal_wcs_img_to_world(gal_data_t *coords, struct wcsprm 
*wcs, int inplace)
 
   /* Write the values from the input list of separate columns into a single
      array (WCSLIB input). */
-  wcs_convert_list_to_array(coords, pixcrd, stat, wcs->naxis, 1);
+  wcs_convert_list_to_from_array(coords, pixcrd, stat, wcs->naxis, 0);
 
 
   /* Use WCSLIB's wcsp2s for the conversion. */
@@ -2414,7 +2414,7 @@ gal_wcs_img_to_world(gal_data_t *coords, struct wcsprm 
*wcs, int inplace)
 
   /* Write the output from a single array (WCSLIB output) into the output
      list of this function. */
-  wcs_convert_list_to_array(out, world, stat, wcs->naxis, 0);
+  wcs_convert_list_to_from_array(out, world, stat, wcs->naxis, 1);
 
 
   /* Clean up. */



reply via email to

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