gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master b5bd97c1 1/3: Library: minor edits in comments


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master b5bd97c1 1/3: Library: minor edits in comments of Convolve, Fits and threads
Date: Thu, 20 Apr 2023 06:50:07 -0400 (EDT)

branch: master
commit b5bd97c1b88914772c95f00ea97f49ff1a84b050
Author: Faezeh Bidjarchian <fbidjarchian@gmail.com>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Library: minor edits in comments of Convolve, Fits and threads
    
    Until now, there were several typos and grammatical errors in some
    functions of Gnuastro's library and the Arithmetic program. As well as a
    case of extra (unused) structure element and a non-freed allocation.
    
    With this commit, they have been fixed.
---
 bin/arithmetic/arithmetic.c | 12 ++++-------
 lib/convolve.c              | 50 ++++++++++++++++++++++-----------------------
 lib/dimension.c             |  8 ++++----
 lib/fits.c                  | 19 ++++++++++-------
 lib/interpolate.c           |  2 +-
 lib/threads.c               | 17 ++++++++-------
 6 files changed, 56 insertions(+), 52 deletions(-)

diff --git a/bin/arithmetic/arithmetic.c b/bin/arithmetic/arithmetic.c
index 76ab80e1..2e88412b 100644
--- a/bin/arithmetic/arithmetic.c
+++ b/bin/arithmetic/arithmetic.c
@@ -190,8 +190,6 @@ struct arithmetic_filter_p
   float      sclip_param;       /* Termination critera in sigma-cliping. */
   gal_data_t      *input;       /* Input dataset.                        */
   gal_data_t        *out;       /* Output dataset.                       */
-
-  int           hasblank;       /* If the dataset has blank values.      */
 };
 
 
@@ -481,9 +479,6 @@ wrapper_for_filter(struct arithmeticparams *p, char *token, 
int operator)
       printf("hpfsize: %zu, %zu\n", hpfsize[0], hpfsize[1]);
       */
 
-      /* See if the input has blank pixels. */
-      afp.hasblank=gal_blank_present(afp.input, 1);
-
 
       /* Set the type of the output dataset. */
       switch(operator)
@@ -523,7 +518,7 @@ wrapper_for_filter(struct arithmeticparams *p, char *token, 
int operator)
   /* Add the output to the top of the stack. */
   operands_add(p, NULL, afp.out);
 
-  /* Clean up and add the output on top of the stack */
+  /* Clean up and add the output on top of the stack. */
   gal_data_free(zero);
   gal_data_free(afp.input);
   gal_list_data_free(params_list);
@@ -686,7 +681,7 @@ arithmetic_fill_holes(struct arithmeticparams *p, char 
*token)
   /* Basic sanity checks. */
   conn_int=arithmetic_binary_sanity_checks(in, conn, token);
 
-  /* Fill the holes */
+  /* Fill the holes. */
   gal_binary_holes_fill(in, conn_int, -1);
 
   /* Push the result onto the stack. */
@@ -852,6 +847,7 @@ arithmetic_interpolate_region(struct arithmeticparams *p,
   */
 
   /* Clean up. */
+  free(dinc);
   gal_data_free(lab);
   gal_data_free(minmax);
   gal_data_free(connectivity);
@@ -870,7 +866,7 @@ arithmetic_interpolate(struct arithmeticparams *p, int 
operator, char *token)
   gal_data_t *interpolated;
   int num_int, interpop=GAL_ARITHMETIC_OP_INVALID;
 
-  /* First pop the number of nearby neighbors.*/
+  /* First pop the number of nearby neighbors. */
   gal_data_t *num = operands_pop(p, token);
 
   /* Then pop the actual dataset to interpolate. */
diff --git a/lib/convolve.c b/lib/convolve.c
index 4c4422b6..02074f8d 100644
--- a/lib/convolve.c
+++ b/lib/convolve.c
@@ -92,18 +92,18 @@ convolve_tile_is_on_edge(size_t *h, size_t 
*start_end_coord, size_t *k,
 struct per_thread_spatial_prm
 {
   /* Internally stored/used values. */
-  size_t             id;     /* ID of tile being operatred on.           */
-  gal_data_t      *tile;     /* Tile this thread is working on.          */
-  gal_data_t *i_overlap;     /* Overlap tile over input dataset.         */
-  gal_data_t *k_overlap;     /* Overlap tile over kernel dataset.        */
-  size_t *overlap_start;     /* Starting coordinate of kernel overlap.   */
-  size_t  *kernel_start;     /* Kernel starting point.                   */
-  size_t    *host_start;     /* Starting coordinate of host.             */
+  size_t             id;     /* ID of tile being operatred on.            */
+  gal_data_t      *tile;     /* Tile this thread is working on.           */
+  gal_data_t *i_overlap;     /* Overlap tile over input dataset.          */
+  gal_data_t *k_overlap;     /* Overlap tile over kernel dataset.         */
+  size_t *overlap_start;     /* Starting coordinate of kernel overlap.    */
+  size_t  *kernel_start;     /* Kernel starting point.                    */
+  size_t    *host_start;     /* Starting coordinate of host.              */
   size_t           *pix;     /* 2*ndim: starting and ending of tile,
-                                Later, just the pixel being convolved.   */
-  int           on_edge;     /* If the tile is on the edge or not.       */
-  gal_data_t      *host;     /* Size of host (channel or block).         */
-  struct spatial_params *cprm; /* Link to main structure for all threads.*/
+                                Later, just the pixel being convolved.    */
+  int           on_edge;     /* If the tile is on the edge or not.        */
+  gal_data_t      *host;     /* Size of host (channel or block).          */
+  struct spatial_params *cprm; /* Link to main structure for all threads. */
 };
 
 
@@ -113,14 +113,14 @@ struct per_thread_spatial_prm
 struct spatial_params
 {
   /* Main input/output parameters. */
-  gal_data_t       *out;     /* Output data structure.                   */
-  gal_data_t     *tiles;     /* Tiles over the input image.              */
-  gal_data_t     *block;     /* Pointer to block for this tile.          */
-  gal_data_t    *kernel;     /* Kernel to convolve with input.           */
-  gal_data_t *tocorrect;     /* (possible) convolved image to correct.   */
-  int        convoverch;     /* Ignore channel edges in convolution.     */
-  int    edgecorrection;     /* Correct convolution's edge effects.      */
-  struct per_thread_spatial_prm *pprm; /* Array of per-thread parameters.*/
+  gal_data_t       *out;     /* Output data structure.                    */
+  gal_data_t     *tiles;     /* Tiles over the input image.               */
+  gal_data_t     *block;     /* Pointer to block for this tile.           */
+  gal_data_t    *kernel;     /* Kernel to convolve with input.            */
+  gal_data_t *tocorrect;     /* (possible) convolved image to correct.    */
+  int        convoverch;     /* Ignore channel edges in convolution.      */
+  int    edgecorrection;     /* Correct convolution's edge effects.       */
+  struct per_thread_spatial_prm *pprm; /* Array of per-thread parameters. */
 };
 
 
@@ -129,7 +129,7 @@ struct spatial_params
 
 /* Define the overlap of the kernel and image over this part of the image,
    the necessary input image parameters are stored in 'overlap' (its
-   'array' and 'dsize' elements).  */
+   'array' and 'dsize' elements). */
 static int
 convolve_spatial_overlap(struct per_thread_spatial_prm *pprm, int tocorrect)
 {
@@ -226,7 +226,7 @@ convolve_spatial_overlap(struct per_thread_spatial_prm 
*pprm, int tocorrect)
         }
 
       /* There is full overlap for this pixel or tile over this
-         dimension.  */
+         dimension. */
       if(dim_full_overlap)
         {
           /* Set the values. */
@@ -483,7 +483,7 @@ convolve_spatial_on_thread(void *inparam)
 
 
 /* General spatial convolve function. This function is called by both
-   'gal_convolve_spatial' and */
+   'gal_convolve_spatial' and 'gal_convolve_spatial_correct_ch_edge'. */
 static gal_data_t *
 gal_convolve_spatial_general(gal_data_t *tiles, gal_data_t *kernel,
                              size_t numthreads, int edgecorrection,
@@ -504,7 +504,7 @@ gal_convolve_spatial_general(gal_data_t *tiles, gal_data_t 
*kernel,
   /* It may happen that an input dataset is part of a linked list, but it
      is not actually a tile structure (the user wants to convolve the whole
      dataset without using tiles)! In that case, this function should break
-     beacuse a linked list is interpretted as a tile structure here.*/
+     beacuse a linked list is interpretted as a tile structure here. */
   if( tiles->block==NULL && tiles->next && tiles->next->block==NULL )
     error(EXIT_FAILURE, 0, "%s: the input is a linked list but not a "
           "tessellation (a list of tiles). This function is optimized to "
@@ -513,7 +513,7 @@ gal_convolve_spatial_general(gal_data_t *tiles, gal_data_t 
*kernel,
           __func__);
 
 
-  /* Set the output datastructure.  */
+  /* Set the output datastructure. */
   if(tocorrect) out=tocorrect;
   else
     {
@@ -566,7 +566,7 @@ gal_convolve_spatial_general(gal_data_t *tiles, gal_data_t 
*kernel,
    convolution can be greatly sped up if it is done on separate tiles over
    the image (on multiple threads). So as input, you can either give tile
    values or one full array. Just note that if you give a single array as
-   input, the 'next' element has to be 'NULL'.*/
+   input, the 'next' element has to be 'NULL'. */
 gal_data_t *
 gal_convolve_spatial(gal_data_t *tiles, gal_data_t *kernel,
                      size_t numthreads, int edgecorrection, int convoverch)
diff --git a/lib/dimension.c b/lib/dimension.c
index 035aa7a7..e3a347c6 100644
--- a/lib/dimension.c
+++ b/lib/dimension.c
@@ -401,7 +401,7 @@ dimension_collapse_sanity_check(gal_data_t *in, gal_data_t 
*weight,
   if(hasblank==0)
     *cnum=in->dsize[c_dim];
 
-  /* Weight sanity checks */
+  /* Weight sanity checks. */
   if(weight)
     {
       if( weight->ndim!=1 )
@@ -583,7 +583,7 @@ gal_dimension_collapse_sum(gal_data_t *in, size_t c_dim, 
gal_data_t *weight)
   sum=gal_data_alloc(NULL, GAL_TYPE_FLOAT64, outndim, outdsize, in->wcs,
                      1, in->minmapsize, in->quietmmap, NULL, NULL, NULL);
 
-  /* The number dataset (when there are blank values).*/
+  /* The number dataset (when there are blank values). */
   if(hasblank)
     num=gal_data_alloc(NULL, GAL_TYPE_INT8, outndim, outdsize, NULL,
                        1, in->minmapsize, in->quietmmap, NULL, NULL, NULL);
@@ -663,7 +663,7 @@ gal_dimension_collapse_mean(gal_data_t *in, size_t c_dim,
   if( weight )
     {
       /* There are blank values, so we'll need to keep the sums of the
-         weights for each collapsed dimension */
+         weights for each collapsed dimension. */
       if( hasblank )
         wsumarr=gal_pointer_allocate(GAL_TYPE_FLOAT64, sum->size, 1,
                                      __func__, "wsumarr");
@@ -994,7 +994,7 @@ dimension_collapse_sortbased_worker(void *in_prm)
       }
       */
 
-      /* Do the necessary satistical operation. */
+      /* Do the necessary statistical operation. */
       switch(p->operator)
         {
         case DIMENSION_COLLAPSE_MEDIAN:
diff --git a/lib/fits.c b/lib/fits.c
index a84ef921..58e0aff8 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -3564,6 +3564,11 @@ struct fits_tab_read_onecol_params
   gal_data_t       **colarray;  /* Array of pointers to all columns. */
   gal_list_sizet_t   *indexll;  /* Index of columns to read.         */
 };
+
+
+
+
+
 void *
 fits_tab_read_onecol(void *in_prm)
 {
@@ -3583,7 +3588,7 @@ fits_tab_read_onecol(void *in_prm)
   int isfloat, hdutype, anynul=0, status=0;
   size_t i, j, c, ndim, strw, repeat, indout, indin=GAL_BLANK_SIZE_T;
 
-  /* Open the FITS file */
+  /* Open the FITS file. */
   fptr=gal_fits_hdu_open_format(p->filename, p->hdu, 1);
 
   /* See if its a Binary or ASCII table (necessary for floating point
@@ -3660,7 +3665,7 @@ fits_tab_read_onecol(void *in_prm)
                defines blanks as NaN (same as almost any other software
                like Gnuastro). However if a blank value is specified,
                CFITSIO will convert other special numbers like 'inf' to NaN
-               also. We want to be able to distringuish 'inf' and NaN here,
+               also. We want to be able to distinguish 'inf' and NaN here,
                so for floating point types in binary tables, we won't
                define any blank value. In ASCII tables, CFITSIO doesn't
                read the 'NAN' values (that it has written itself) unless we
@@ -3713,7 +3718,7 @@ fits_tab_read_onecol(void *in_prm)
       p->colarray[indout]=col;
     }
 
-  /* Close the FITS file */
+  /* Close the FITS file. */
   status=0;
   fits_close_file(fptr, &status);
   gal_fits_io_error(status, NULL);
@@ -3836,7 +3841,7 @@ fits_string_fixed_alloc_size(gal_data_t *data)
     {
       /* Allocate (and clear) the space for the new string. We want it to
          be cleared, so when the strings are smaller, the rest of the space
-         is filled with '\0' (ASCII for 0) values.*/
+         is filled with '\0' (ASCII for 0) values. */
       errno=0;
       tmp=calloc(maxlen+1, sizeof *strarr[i]);
       if(tmp==NULL)
@@ -3845,7 +3850,7 @@ fits_string_fixed_alloc_size(gal_data_t *data)
 
       /* Put the old array into the newly allocated space. 'tmp' was
          cleared (all values set to '\0', so we don't need to set the final
-         one explicity after the copy.*/
+         one explicity after the copy. */
       for(j=0;strarr[i][j]!='\0';++j)
         tmp[j]=strarr[i][j];
 
@@ -3928,7 +3933,7 @@ fits_table_prepare_arrays(gal_data_t *cols, size_t 
numcols,
                 free(blank);
               }
 
-            /* Print the value to be used as TFORMn:  */
+            /* Print the value to be used as TFORMn: */
             switch(col->type)
               {
               case GAL_TYPE_STRING:
@@ -4282,7 +4287,7 @@ gal_fits_tab_write(gal_data_t *cols, gal_list_str_t 
*comments,
   size_t i, numrows=-1, thisnrows;
   int tbltype, numcols=0, status=0;
 
-  /* Make sure all the input columns have the same number of elements */
+  /* Make sure all the input columns have the same number of elements. */
   for(col=cols; col!=NULL; col=col->next)
     {
       thisnrows = col->dsize ? col->dsize[0] : 0;
diff --git a/lib/interpolate.c b/lib/interpolate.c
index 6223e60c..7fdbaae1 100644
--- a/lib/interpolate.c
+++ b/lib/interpolate.c
@@ -471,7 +471,7 @@ gal_interpolate_neighbors(gal_data_t *input,
                                         "prm.thread_flags");
 
 
-  /* Spin off the threads. */
+  /* Spin-off the threads. */
   gal_threads_spin_off(interpolate_neighbors_on_thread, &prm,
                        input->size, numthreads, input->minmapsize,
                        input->quietmmap);
diff --git a/lib/threads.c b/lib/threads.c
index 68deb2f7..a74fc97c 100644
--- a/lib/threads.c
+++ b/lib/threads.c
@@ -91,7 +91,7 @@ pthread_barrier_init(pthread_barrier_t *b, 
pthread_barrierattr_t *attr,
    announced by another thread that succeeds the 'if'. After the thread no
    longer needs the condition variable, we increment 'b->condfinished' so
    'pthread_barrier_destroy' can know if it should wait (sleep) or
-   continue.*/
+   continue. */
 int
 pthread_barrier_wait(pthread_barrier_t *b)
 {
@@ -139,7 +139,7 @@ pthread_barrier_destroy(pthread_barrier_t *b)
   while( b->condfinished < b->limit )
     nanosleep(&request, &remaining);
 
-  /* Destroy the condition variable and mutex */
+  /* Destroy the condition variable and mutex. */
   pthread_cond_destroy(&b->cond);
   pthread_mutex_destroy(&b->mutex);
   return 0;
@@ -296,7 +296,7 @@ gal_threads_attr_barrier_init(pthread_attr_t *attr, 
pthread_barrier_t *b,
        {
 
            THE INDEX OF THE TARGET IS NOW AVAILABLE AS
-           'tprm->indexs[i]'. YOU CAN USE IT IN WHAT EVER MANNER YOU LIKE
+           'tprm->indexs[i]'. YOU CAN USE IT IN WHATEVER MANNER YOU LIKE
            ALONG WITH THE SET OF VARIABLES/ARRAYS in 'prm'.
 
        }
@@ -314,12 +314,15 @@ gal_threads_attr_barrier_init(pthread_attr_t *attr, 
pthread_barrier_t *b,
         struct my_params;
         size_t numthreads;
 
+        int quietmmap=1;
+        size_t minmapsize=-1;
+
         my_params.value1=value1;
         my_params.value2=value2;
         my_params.arary=array;
 
         gal_threads_spin_off(run_on_thread, &my_params, num_in_array,
-                             numthreads);
+                             numthreads, minmapsize, quietmmap);
 
         return 1;
      }
@@ -367,7 +370,7 @@ gal_threads_spin_off(void *(*worker)(void *), void 
*caller_params,
                                        quietmmap, &indexs, &thrdcols);
 
   /* Do the job: when only one thread is necessary, there is no need to
-     spin off one thread, just call the workerfunction directly (spinning
+     spin-off one thread, just call the workerfunction directly (spinning
      off threads is expensive). This is for the generic thread spinner
      function, not this simple function where 'numthreads' is a
      constant. */
@@ -382,13 +385,13 @@ gal_threads_spin_off(void *(*worker)(void *), void 
*caller_params,
   else
     {
       /* Initialize the attributes. Note that this running thread
-         (that spinns off the nt threads) is also a thread, so the
+         (that spins-off the nt threads) is also a thread, so the
          number the barriers should be one more than the number of
          threads spinned off. */
       numbarriers = (numactions<numthreads ? numactions : numthreads) + 1;
       gal_threads_attr_barrier_init(&attr, &b, numbarriers);
 
-      /* Spin off the threads: */
+      /* Spin-off the threads: */
       for(i=0;i<numthreads;++i)
         if(indexs[i*thrdcols]!=GAL_BLANK_SIZE_T)
           {



reply via email to

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