Commit 4a2ef887 authored by Mohammad Akhlaghi's avatar Mohammad Akhlaghi

Configure-time checks to see if host's WCSLIB has dis.h

Until now, we always assumed that WCSLIB has the 'dis.h' header for
distortion-related operations. But this is not always the case and older
versions of WCSLIB don't have it. This could cause problems in the build.

With this commit, configure-time checks have been added to see if 'dis.h'
is present on the host or not. If it isn't the respective functions will
print an informative error and abort. Also a warning will be printed at the
end of the configuration step.
parent 09fa5371
......@@ -22,6 +22,8 @@ See the end of the file for license conditions.
file. The inverse conversion is also supported (from SIP to TPV).
Library:
- GAL_CONFIG_HAVE_WCSLIB_DIS_H: if the host's WCSLIB supports distortions.
- GAL_CONFIG_HAVE_WCSLIB_MJDREF: if the host's WCSLIB reads MJDREF keyword.
- GAL_WCS_FLTERROR: Limit to identify a floating point error for WCS.
- gal_wcs_clean_errors: clean major WCS components from errors specified
by the FITS keyword 'CRDER', or floating point errors.
......
......@@ -28,6 +28,7 @@ along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
#include <stdio.h>
#include <string.h>
#include <gnuastro/wcs.h>
#include <gnuastro/fits.h>
#include <gnuastro-internal/options.h>
......
......@@ -444,6 +444,15 @@ AC_DEFINE_UNQUOTED([GAL_CONFIG_HAVE_WCSLIB_VERSION], [$has_wcslib_version],
AC_SUBST(HAVE_WCSLIB_VERSION, [$has_wcslib_version])
# If the WCS library supports distortion
AC_CHECK_HEADER([wcslib/dis.h], [has_wcslib_dis_h=1],
[has_wcslib_dis_h=0; anywarnings=yes])
AC_DEFINE_UNQUOTED([GAL_CONFIG_HAVE_WCSLIB_DIS_H], [$has_wcslib_dis_h],
[WCSLIB has distortion header in dis.h])
AC_SUBST(HAVE_WCSLIB_DIS_H, [$has_wcslib_dis_h])
AM_CONDITIONAL([COND_HASWCSDIS_H], [test "x$has_wcslib_dis_h" = "x1"])
# If the WCS library has the 'mjdref' element.
AC_CHECK_MEMBER([struct wcsprm.mjdref], [has_wcslib_mjdref=1],
[has_wcslib_mjdref=0], [[#include <wcslib/wcs.h>]])
......@@ -986,6 +995,15 @@ AS_IF([test x$enable_guide_message = xyes],
AS_ECHO([" released in October 2015)."])
AS_ECHO([]) ])
AS_IF([test "x$has_wcslib_dis_h" = "x0"],
[dependency_notice=yes
AS_ECHO([" - WCSLIB (https://www.atnf.csiro.au/people/mcalabre/WCS) version"])
AS_ECHO([" on this system doesn't support distortions (i.e., it doesn't"])
AS_ECHO([" have 'dis.h'. This build won't crash but Gnuastro will not be able"])
AS_ECHO([" to do distortion-related operations. If you don't need such"])
AS_ECHO([" operations you can ignore this warning."])
AS_ECHO([]) ])
AS_IF([test "x$has_libjpeg" = "xno"],
[dependency_notice=yes
AS_ECHO([" - libjpeg (http://ijg.org), could not be linked with in your library"])
......
......@@ -18475,6 +18475,14 @@ However, only more recent versions of WCSLIB also provide its version number.
If the WCSLIB that is installed on the system provides its version (through the possibly existing @code{wcslib_version} function), this macro will have a value of one, otherwise it will have a value of zero.
@end deffn
@deffn Macro GAL_CONFIG_HAVE_WCSLIB_DIS_H
This macro has a value of 1 if the host's WCSLIB has the @file{wcslib/dis.h} header for distortion-related operations.
@end deffn
@deffn Macro GAL_CONFIG_HAVE_WCSLIB_MJDREF
This macro has a value of 1 if the host's WCSLIB reads and stores the @file{MJDREF} FITS header keyword as part of its core @code{wcsprm} structure.
@end deffn
@deffn Macro GAL_CONFIG_HAVE_PTHREAD_BARRIER
The POSIX threads standard define barriers as an optional requirement.
Therefore, some operating systems choose to not include it.
......@@ -50,19 +50,27 @@ libgnuastro_la_LIBADD = $(top_builddir)/bootstrapped/lib/libgnu.la
# Conditional compilation
if COND_HASWCSDIS_H
MAYBE_WCSDISTORTION = wcsdistortion.c
endif
# Specify the library .c files
libgnuastro_la_SOURCES = arithmetic.c arithmetic-and.c arithmetic-bitand.c \
arithmetic-bitlsh.c arithmetic-bitor.c arithmetic-bitrsh.c \
arithmetic-bitxor.c arithmetic-divide.c arithmetic-eq.c arithmetic-ge.c \
arithmetic-gt.c arithmetic-le.c arithmetic-lt.c arithmetic-minus.c \
arithmetic-modulo.c arithmetic-multiply.c arithmetic-ne.c \
arithmetic-or.c arithmetic-plus.c array.c binary.c blank.c box.c \
checkset.c convolve.c cosmology.c data.c eps.c fits.c git.c \
interpolate.c jpeg.c label.c list.c match.c options.c pdf.c \
permutation.c pointer.c polygon.c qsort.c dimension.c speclines.c \
statistics.c table.c tableintern.c threads.c tiff.c tile.c \
tile-internal.c timing.c txt.c type.c units.c wcs.c wcsdistortion.c
libgnuastro_la_SOURCES = $(MAYBE_WCSDISTORTION) arithmetic.c \
arithmetic-and.c arithmetic-bitand.c arithmetic-bitlsh.c \
arithmetic-bitor.c arithmetic-bitrsh.c arithmetic-bitxor.c \
arithmetic-divide.c arithmetic-eq.c arithmetic-ge.c arithmetic-gt.c \
arithmetic-le.c arithmetic-lt.c arithmetic-minus.c arithmetic-modulo.c \
arithmetic-multiply.c arithmetic-ne.c arithmetic-or.c arithmetic-plus.c \
array.c binary.c blank.c box.c checkset.c convolve.c cosmology.c data.c \
eps.c fits.c git.c interpolate.c jpeg.c label.c list.c match.c options.c \
pdf.c permutation.c pointer.c polygon.c qsort.c dimension.c speclines.c \
statistics.c table.c tableintern.c threads.c tiff.c tile.c \
tile-internal.c timing.c txt.c type.c units.c wcs.c
......@@ -72,17 +80,17 @@ libgnuastro_la_SOURCES = arithmetic.c arithmetic-and.c arithmetic-bitand.c \
# in the $(headersdir) directory. Some of the header files don't need to be
# installed.
headersdir=$(top_srcdir)/lib/gnuastro
pkginclude_HEADERS = gnuastro/config.h $(headersdir)/arithmetic.h \
$(headersdir)/array.h $(headersdir)/binary.h $(headersdir)/blank.h \
$(headersdir)/box.h $(headersdir)/convolve.h $(headersdir)/cosmology.h \
$(headersdir)/data.h $(headersdir)/dimension.h $(headersdir)/eps.h \
$(headersdir)/fits.h $(headersdir)/git.h $(headersdir)/interpolate.h \
$(headersdir)/jpeg.h $(headersdir)/label.h $(headersdir)/list.h \
$(headersdir)/match.h $(headersdir)/pdf.h $(headersdir)/permutation.h \
$(headersdir)/pointer.h $(headersdir)/polygon.h $(headersdir)/qsort.h \
$(headersdir)/speclines.h $(headersdir)/statistics.h \
$(headersdir)/table.h $(headersdir)/threads.h $(headersdir)/tiff.h \
$(headersdir)/tile.h $(headersdir)/txt.h $(headersdir)/type.h \
pkginclude_HEADERS = gnuastro/config.h $(headersdir)/arithmetic.h \
$(headersdir)/array.h $(headersdir)/binary.h $(headersdir)/blank.h \
$(headersdir)/box.h $(headersdir)/convolve.h $(headersdir)/cosmology.h \
$(headersdir)/data.h $(headersdir)/dimension.h $(headersdir)/eps.h \
$(headersdir)/fits.h $(headersdir)/git.h $(headersdir)/interpolate.h \
$(headersdir)/jpeg.h $(headersdir)/label.h $(headersdir)/list.h \
$(headersdir)/match.h $(headersdir)/pdf.h $(headersdir)/permutation.h \
$(headersdir)/pointer.h $(headersdir)/polygon.h $(headersdir)/qsort.h \
$(headersdir)/speclines.h $(headersdir)/statistics.h \
$(headersdir)/table.h $(headersdir)/threads.h $(headersdir)/tiff.h \
$(headersdir)/tile.h $(headersdir)/txt.h $(headersdir)/type.h \
$(headersdir)/units.h $(headersdir)/wcs.h
......@@ -95,21 +103,21 @@ pkginclude_HEADERS = gnuastro/config.h $(headersdir)/arithmetic.h \
# will not distributed, so we need to explicitly tell Automake to
# distribute them here.
internaldir=$(top_srcdir)/lib/gnuastro-internal
EXTRA_DIST = gnuastro.pc.in $(headersdir)/README $(internaldir)/README \
$(internaldir)/arithmetic-and.h $(internaldir)/arithmetic-binary.h \
EXTRA_DIST = gnuastro.pc.in $(headersdir)/README $(internaldir)/README \
$(internaldir)/arithmetic-and.h $(internaldir)/arithmetic-binary.h \
$(internaldir)/arithmetic-bitand.h $(internaldir)/arithmetic-bitlsh.h \
$(internaldir)/arithmetic-bitor.h $(internaldir)/arithmetic-bitrsh.h \
$(internaldir)/arithmetic-bitor.h $(internaldir)/arithmetic-bitrsh.h \
$(internaldir)/arithmetic-bitxor.h $(internaldir)/arithmetic-divide.h \
$(internaldir)/arithmetic-eq.h $(internaldir)/arithmetic-ge.h \
$(internaldir)/arithmetic-gt.h $(internaldir)/arithmetic-internal.h \
$(internaldir)/arithmetic-le.h $(internaldir)/arithmetic-lt.h \
$(internaldir)/arithmetic-minus.h $(internaldir)/arithmetic-modulo.h \
$(internaldir)/arithmetic-multiply.h $(internaldir)/arithmetic-ne.h \
$(internaldir)/arithmetic-or.h $(internaldir)/arithmetic-plus.h \
$(internaldir)/checkset.h $(internaldir)/commonopts.h \
$(internaldir)/config.h.in $(internaldir)/fixedstringmacros.h \
$(internaldir)/options.h $(internaldir)/tableintern.h \
$(internaldir)/tile-internal.h $(internaldir)/timing.h \
$(internaldir)/arithmetic-eq.h $(internaldir)/arithmetic-ge.h \
$(internaldir)/arithmetic-gt.h $(internaldir)/arithmetic-internal.h \
$(internaldir)/arithmetic-le.h $(internaldir)/arithmetic-lt.h \
$(internaldir)/arithmetic-minus.h $(internaldir)/arithmetic-modulo.h \
$(internaldir)/arithmetic-multiply.h $(internaldir)/arithmetic-ne.h \
$(internaldir)/arithmetic-or.h $(internaldir)/arithmetic-plus.h \
$(internaldir)/checkset.h $(internaldir)/commonopts.h \
$(internaldir)/config.h.in $(internaldir)/fixedstringmacros.h \
$(internaldir)/options.h $(internaldir)/tableintern.h \
$(internaldir)/tile-internal.h $(internaldir)/timing.h \
$(internaldir)/wcsdistortion.h
......@@ -131,14 +139,15 @@ CLEANFILES = gnuastro.pc gnuastro/config.h
gnuastro/config.h: Makefile $(internaldir)/config.h.in
rm -f [email protected] [email protected].tmp
$(MKDIR_P) gnuastro
$(SED) -e 's|@VERSION[@]|$(VERSION)|g' \
-e 's|@HAVE_LIBGIT2[@]|$(HAVE_LIBGIT2)|g' \
-e 's|@HAVE_WCSLIB_VERSION[@]|$(HAVE_WCSLIB_VERSION)|g' \
-e 's|@HAVE_WCSLIB_MJDREF[@]|$(HAVE_WCSLIB_MJDREF)|g' \
-e 's|@HAVE_PTHREAD_BARRIER[@]|$(HAVE_PTHREAD_BARRIER)|g' \
-e 's|@SIZEOF_LONG[@]|$(SIZEOF_LONG)|g' \
-e 's|@SIZEOF_SIZE_T[@]|$(SIZEOF_SIZE_T)|g' \
-e 's|@RESTRICT_REPLACEMENT[@]|$(RESTRICT_REPLACEMENT)|g' \
$(SED) -e 's|@VERSION[@]|$(VERSION)|g' \
-e 's|@HAVE_LIBGIT2[@]|$(HAVE_LIBGIT2)|g' \
-e 's|@HAVE_WCSLIB_VERSION[@]|$(HAVE_WCSLIB_VERSION)|g' \
-e 's|@HAVE_WCSLIB_DIS_H[@]|$(HAVE_WCSLIB_DIS_H)|g' \
-e 's|@HAVE_WCSLIB_MJDREF[@]|$(HAVE_WCSLIB_MJDREF)|g' \
-e 's|@HAVE_PTHREAD_BARRIER[@]|$(HAVE_PTHREAD_BARRIER)|g' \
-e 's|@SIZEOF_LONG[@]|$(SIZEOF_LONG)|g' \
-e 's|@SIZEOF_SIZE_T[@]|$(SIZEOF_SIZE_T)|g' \
-e 's|@RESTRICT_REPLACEMENT[@]|$(RESTRICT_REPLACEMENT)|g' \
$(internaldir)/config.h.in >> [email protected].tmp
chmod a-w [email protected].tmp
mv [email protected].tmp [email protected]
......
......@@ -40,6 +40,7 @@ along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
#define GAL_CONFIG_HAVE_FITS_IS_REENTRANT @[email protected]
#define GAL_CONFIG_HAVE_WCSLIB_VERSION @[email protected]
#define GAL_CONFIG_HAVE_WCSLIB_DIS_H @[email protected]
#define GAL_CONFIG_HAVE_WCSLIB_MJDREF @[email protected]
#define GAL_CONFIG_HAVE_PTHREAD_BARRIER @[email protected]
......
......@@ -31,8 +31,6 @@ along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
#include <unistd.h>
#include <assert.h>
#include <wcslib/dis.h>
#include <gsl/gsl_linalg.h>
#include <wcslib/wcsmath.h>
......@@ -43,10 +41,10 @@ along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
#include <gnuastro/dimension.h>
#include <gnuastro/permutation.h>
#if GAL_CONFIG_HAVE_WCSLIB_DIS_H
#include <wcslib/dis.h>
#include <gnuastro-internal/wcsdistortion.h>
#endif
......@@ -338,6 +336,7 @@ gal_wcs_distortion_to_string(int distortion)
int
gal_wcs_distortion_identify(struct wcsprm *wcs)
{
#if GAL_CONFIG_HAVE_WCSLIB_DIS_H
struct disprm *dispre=NULL;
struct disprm *disseq=NULL;
......@@ -395,6 +394,14 @@ gal_wcs_distortion_identify(struct wcsprm *wcs)
error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at '%s' to fix "
"the problem. Control should not reach the end of this function",
__func__, PACKAGE_BUGREPORT);
#else
/* The 'wcslib/dis.h' isn't present. */
error(EXIT_FAILURE, 0, "%s: the installed version of WCSLIB on this "
"system doesn't have the 'dis.h' header! Thus Gnuastro can't do "
"distortion-related operations on the world coordinate system "
"(WCS). To use these features, please upgrade your version "
"of WCSLIB and re-build Gnuastro", __func__);
#endif
return GAL_WCS_DISTORTION_INVALID;
}
......@@ -421,6 +428,7 @@ struct wcsprm *
gal_wcs_distortion_convert(struct wcsprm *inwcs, int outdisptype,
size_t *fitsize)
{
#if GAL_CONFIG_HAVE_WCSLIB_DIS_H
struct wcsprm *outwcs=NULL;
int indisptype=gal_wcs_distortion_identify(inwcs);
......@@ -487,6 +495,15 @@ gal_wcs_distortion_convert(struct wcsprm *inwcs, int outdisptype,
/* Return the converted WCS. */
return outwcs;
#else
/* The 'wcslib/dis.h' isn't present. */
error(EXIT_FAILURE, 0, "%s: the installed version of WCSLIB on this "
"system doesn't have the 'dis.h' header! Thus Gnuastro can't do "
"distortion-related operations on the world coordinate system "
"(WCS). To use these features, please upgrade your version "
"of WCSLIB and re-build Gnuastro", __func__);
return NULL;
#endif
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment