[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master dc67dc1 2/2: Library (wcs.h): new function to
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master dc67dc1 2/2: Library (wcs.h): new function to return WCS dimension name |
Date: |
Sun, 13 Sep 2020 18:59:27 -0400 (EDT) |
branch: master
commit dc67dc1706e71b2f7f426397bb1e12a8abd43cc9
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Library (wcs.h): new function to return WCS dimension name
In some contexts, it is useful to report the name of given WCS
coordinates. With this commit, the new 'gal_wcs_dimension_name' will do the
job.
---
NEWS | 3 +++
bin/fits/fits.c | 23 ++---------------------
doc/gnuastro.texi | 7 +++++++
lib/gnuastro/wcs.h | 2 ++
lib/wcs.c | 28 ++++++++++++++++++++++++++++
5 files changed, 42 insertions(+), 21 deletions(-)
diff --git a/NEWS b/NEWS
index 5a17b58..c509137 100644
--- a/NEWS
+++ b/NEWS
@@ -37,6 +37,9 @@ See the end of the file for license conditions.
'astquery' option, to easily search the contents of external databases
within the image.
+ Library:
+ - gal_wcs_dimension_name: return the name of the requested WCS dim.
+
** Removed features
** Changed features
diff --git a/bin/fits/fits.c b/bin/fits/fits.c
index eab09c5..ebd000e 100644
--- a/bin/fits/fits.c
+++ b/bin/fits/fits.c
@@ -353,25 +353,6 @@ fits_pixelscale(struct fitsparams *p)
-/* Extract the dimension name from CTYPE. */
-static char *
-fits_wcs_dim_name(char *ctype)
-{
- size_t i;
- char *out;
-
- /* Make a copy of the CTYPE value and set the first occurance of '-' to
- '\0', to avoid the projection type. */
- gal_checkset_allocate_copy(ctype, &out);
- for(i=0;i<strlen(out);++i) if(out[i]=='-') out[i]='\0';
-
- /* Return the output array. */
- return out;
-}
-
-
-
-
static void
fits_skycoverage(struct fitsparams *p)
@@ -531,8 +512,8 @@ fits_skycoverage(struct fitsparams *p)
/* For the range type of coverage. */
printf("\nSky coverage by range along dimensions:\n");
for(i=0;i<ndim;++i)
- printf(" %-8s %-15.10g%-15.10g\n",
- fits_wcs_dim_name(wcs->ctype[i]), min[i], max[i]);
+ printf(" %-8s %-15.10g%-15.10g\n", gal_wcs_dimension_name(wcs, i),
+ min[i], max[i]);
}
/* Clean up. */
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index cb1c4b7..fe4143c 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -23045,6 +23045,13 @@ number of coordinate representations found into the
space that @code{nwcs}
points to. Please see @code{gal_wcs_read_fitsptr} for more.
@end deftypefun
+
+@deftypefun {char *} gal_wcs_dimension_name (struct wcsprm @code{*wcs}, size_t
@code{dimension})
+Return an allocated string array (that should be freed later) containing the
first part of the @code{CTYPEi} FITS keyword (which contains the dimension name
in the FITS standard).
+For example if @code{CTYPE1} is @code{RA---TAN}, the string that function
returns will be @code{RA}.
+Recall that the second component of @code{CTYPEi} contains the type of
projection.
+@end deftypefun
+
@deftypefun void gal_wcs_write (struct wcsprm @code{*wcs}, char
@code{*filename}, char @code{*extname}, gal_fits_list_key_t @code{*headers},
char @code{*program_string})
Write the given WCS structure into the second extension of an empty FITS
header.
The first/primary extension will be empty like the default format of all
Gnuastro outputs.
diff --git a/lib/gnuastro/wcs.h b/lib/gnuastro/wcs.h
index dede089..b4c0aac 100644
--- a/lib/gnuastro/wcs.h
+++ b/lib/gnuastro/wcs.h
@@ -85,6 +85,8 @@ struct wcsprm *
gal_wcs_read(char *filename, char *hdu, size_t hstartwcs,
size_t hendwcs, int *nwcs);
+char *
+gal_wcs_dimension_name(struct wcsprm *wcs, size_t dimension);
diff --git a/lib/wcs.c b/lib/wcs.c
index 93a1233..492eb64 100644
--- a/lib/wcs.c
+++ b/lib/wcs.c
@@ -41,6 +41,8 @@ along with Gnuastro. If not, see
<http://www.gnu.org/licenses/>.
#include <gnuastro/dimension.h>
#include <gnuastro/permutation.h>
+#include <gnuastro-internal/checkset.h>
+
#if GAL_CONFIG_HAVE_WCSLIB_DIS_H
#include <wcslib/dis.h>
#include <gnuastro-internal/wcsdistortion.h>
@@ -298,6 +300,32 @@ gal_wcs_read(char *filename, char *hdu, size_t hstartwcs,
+/* Extract the dimension name from CTYPE. */
+char *
+gal_wcs_dimension_name(struct wcsprm *wcs, size_t dimension)
+{
+ size_t i;
+ char *out;
+
+ /* Make sure a WCS pointer actually exists. */
+ if(wcs==NULL) return NULL;
+
+ /* Make sure the requested dimension is not larger than the number of
+ dimensions in the WCS. */
+ if(dimension >= wcs->naxis) return NULL;
+
+ /* Make a copy of the CTYPE value and set the first occurance of '-' to
+ '\0', to avoid the projection type. */
+ gal_checkset_allocate_copy(wcs->ctype[dimension], &out);
+ for(i=0;i<strlen(out);++i) if(out[i]=='-') out[i]='\0';
+
+ /* Return the output array. */
+ return out;
+}
+
+
+
+