gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 00bb26e 1/2: Library: new gal_blank_initialize


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 00bb26e 1/2: Library: new gal_blank_initialize_array function
Date: Sun, 9 Jun 2019 01:47:38 -0400 (EDT)

branch: master
commit 00bb26e676f83227bed853865d85e20b330b5c4c
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    Library: new gal_blank_initialize_array function
    
    This function will allow initializing all elements in an array (not within
    a `gal_data_t') to blank values corresponding to its type. Recall that for
    initializing a `gal_data_t' we already have `gal_blank_initialize'.
---
 NEWS                 |  1 +
 doc/gnuastro.texi    |  6 ++++++
 lib/blank.c          | 19 +++++++++++++++++++
 lib/gnuastro/blank.h |  3 +++
 4 files changed, 29 insertions(+)

diff --git a/NEWS b/NEWS
index d14635a..f7f0b8f 100644
--- a/NEWS
+++ b/NEWS
@@ -53,6 +53,7 @@ See the end of the file for license conditions.
    - list.h: Functions to return the last element in linked lists. For
      example `gal_list_sizet_last' or `gal_list_data_last'.
    - gal_list_data_to_array_ptr: Make an array of pointers from the list.
+   - gal_blank_initialize_array: Initialize an array with blank values.
    - GAL_BLANK_INT: Blank value for `int' (can be 16-bit or 32-bit).
    - GAL_BLANK_UINT: Blank value for unsigned `int' (can be 16-bit or 32-bit).
    - gal_arithmetic_operator_string: Return operator string from code.
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index c0cd5fc..6463a55 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -24800,6 +24800,12 @@ that corresponds to its type. If @code{input} is a 
tile over a larger
 dataset, only the region that the tile covers will be set to blank.
 @end deftypefun
 
+@deftypefun void gal_blank_initialize_array (void @code{*array}, size_t 
@code{size}, uint8_t @code{type})
+Initialize all the elements in the @code{array} to the blank value that
+corresponds to its type (identified with @code{type}), assuming the array
+has @code{size} elements.
+@end deftypefun
+
 @deftypefun {char *} gal_blank_as_string (uint8_t @code{type}, int 
@code{width})
 Write the blank value for the given data type @code{type} into a string and
 return it. The space for the string is dynamically allocated so it must be
diff --git a/lib/blank.c b/lib/blank.c
index 4445d5d..a195018 100644
--- a/lib/blank.c
+++ b/lib/blank.c
@@ -114,6 +114,25 @@ gal_blank_initialize(gal_data_t *input)
 
 
 
+/* Initialize an array to the given type's blank values.*/
+void
+gal_blank_initialize_array(void *array, size_t size, uint8_t type)
+{
+  size_t i, w=gal_type_sizeof(type);
+  void *b=gal_blank_alloc_write(type);
+
+  /* Set all the elements to blank. */
+  for(i=0;i<size;++i)
+    memcpy(gal_pointer_increment(array, i, type), b, w);
+
+  /* Clean up. */
+  free(b);
+}
+
+
+
+
+
 /* Print the blank value as a string. For the integer types, we'll use the
    PRIxNN keywords of `inttypes.h' (which is imported into Gnuastro from
    Gnulib, so we don't necessarily rely on the host system having it). */
diff --git a/lib/gnuastro/blank.h b/lib/gnuastro/blank.h
index 0bb67da..0c52522 100644
--- a/lib/gnuastro/blank.h
+++ b/lib/gnuastro/blank.h
@@ -108,6 +108,9 @@ gal_blank_alloc_write(uint8_t type);
 void
 gal_blank_initialize(gal_data_t *input);
 
+void
+gal_blank_initialize_array(void *array, size_t size, uint8_t type);
+
 char *
 gal_blank_as_string(uint8_t type, int width);
 



reply via email to

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