diff -Nru wcstools-3.9.5/addpix.c wcstools-3.9.6/addpix.c --- wcstools-3.9.5/addpix.c 2017-03-30 15:21:51.000000000 +0000 +++ wcstools-3.9.6/addpix.c 2020-05-14 18:03:53.000000000 +0000 @@ -34,7 +34,7 @@ static void usage(); static int newimage = 0; static int verbose = 0; /* verbose flag */ -static char *RevMsg = "ADDPIX WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "ADDPIX WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static void AddPix(); static int version = 0; /* If 1, print only program name and version */ diff -Nru wcstools-3.9.5/bincat.c wcstools-3.9.6/bincat.c --- wcstools-3.9.5/bincat.c 2017-03-30 15:21:51.000000000 +0000 +++ wcstools-3.9.6/bincat.c 2020-05-14 18:03:53.000000000 +0000 @@ -48,7 +48,7 @@ extern void setcdelt(); extern struct WorldCoor *GetFITSWCS(); -static char *RevMsg = "BINCAT WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "BINCAT WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static int verbose = 0; /* verbose flag */ static int debug = 0; /* debugging flag */ static int bitpix = 0; /* number of bits per pixel (FITS code, 0=no image) */ diff -Nru wcstools-3.9.5/catrot.c wcstools-3.9.6/catrot.c --- wcstools-3.9.5/catrot.c 2017-03-30 15:21:51.000000000 +0000 +++ wcstools-3.9.6/catrot.c 2020-05-14 18:03:53.000000000 +0000 @@ -46,7 +46,7 @@ static int fitsout = 0; /* Output FITS file from IRAF input if 1 */ static int nsplit = 0; /* Output multiple FITS files from n-extension file */ static int overwrite = 0; /* allow overwriting of input image file */ -static char *RevMsg = "IMROT WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "IMROT WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static int version = 0; /* If 1, print only program name and version */ static int xshift = 0; static int yshift = 0; diff -Nru wcstools-3.9.5/char2sp.c wcstools-3.9.6/char2sp.c --- wcstools-3.9.5/char2sp.c 2017-03-30 15:21:51.000000000 +0000 +++ wcstools-3.9.6/char2sp.c 2020-05-14 18:03:53.000000000 +0000 @@ -39,7 +39,7 @@ static int version = 0; /* If 1, print only program name and version */ static char spchar = '_'; -static char *RevMsg = "CHAR2SP WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "CHAR2SP WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; int main (ac, av) diff -Nru wcstools-3.9.5/conpix.c wcstools-3.9.6/conpix.c --- wcstools-3.9.5/conpix.c 2017-03-30 15:21:51.000000000 +0000 +++ wcstools-3.9.6/conpix.c 2020-05-14 18:03:53.000000000 +0000 @@ -52,7 +52,7 @@ static int setgnoise = 0; /* If 1, pixels have been set to random noise */ static int addgnoise = 0; /* If 1, pixels have random noise added */ -static char *RevMsg = "CONPIX WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "CONPIX WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; int main (ac, av) diff -Nru wcstools-3.9.5/cphead.c wcstools-3.9.6/cphead.c --- wcstools-3.9.5/cphead.c 2017-03-30 15:21:51.000000000 +0000 +++ wcstools-3.9.6/cphead.c 2020-05-14 18:03:53.000000000 +0000 @@ -41,7 +41,7 @@ extern char *GetFITShead(); static int verbose = 0; /* verbose/debugging flag */ -static char *RevMsg = "CPHEAD WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "CPHEAD WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static int copyall = 0; /* Copy entire header, overwriting old one */ static int nfile = 0; static int ndec0 = -9; diff -Nru wcstools-3.9.5/debian/changelog wcstools-3.9.6/debian/changelog --- wcstools-3.9.5/debian/changelog 2018-05-18 19:22:48.000000000 +0000 +++ wcstools-3.9.6/debian/changelog 2020-06-25 13:43:46.000000000 +0000 @@ -1,3 +1,19 @@ +wcstools (3.9.6-1) unstable; urgency=low + + * Fix defdir in helpdb.mip + * Use http download URL (https does not work yet) + * Add gitlab-ci file to trigger automated CI test + * New upstream version 3.9.6. Rediff patches + * Push Standards-Version to 4.5.0. No changes needed. + * Push dh-compat to 13 + * Fix getpix output + * Fix axes order in getpix test + * Update symbols file + * Add Rules-Requires-Root: no to d/control + * Replace ADTTMP with AUTOPKG_TMP + + -- Ole Streicher Thu, 25 Jun 2020 15:43:46 +0200 + wcstools (3.9.5-3) unstable; urgency=medium [ Ole Streicher ] diff -Nru wcstools-3.9.5/debian/compat wcstools-3.9.6/debian/compat --- wcstools-3.9.5/debian/compat 2018-05-18 19:22:26.000000000 +0000 +++ wcstools-3.9.6/debian/compat 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -11 diff -Nru wcstools-3.9.5/debian/control wcstools-3.9.6/debian/control --- wcstools-3.9.5/debian/control 2018-05-18 19:22:30.000000000 +0000 +++ wcstools-3.9.6/debian/control 2020-06-25 13:43:46.000000000 +0000 @@ -3,14 +3,15 @@ Uploaders: Ole Streicher Section: science Priority: optional -Build-Depends: debhelper (>= 11), +Build-Depends: debhelper-compat (= 13), dh-exec, help2man Build-Depends-Indep: iraf-dev -Standards-Version: 4.1.4 +Standards-Version: 4.5.0 Vcs-Browser: https://salsa.debian.org/debian-astro-team/wcstools Vcs-Git: https://salsa.debian.org/debian-astro-team/wcstools.git Homepage: http://tdc-www.harvard.edu/software/wcstools/ +Rules-Requires-Root: no Package: wcstools Architecture: any diff -Nru wcstools-3.9.5/debian/gitlab-ci.yml wcstools-3.9.6/debian/gitlab-ci.yml --- wcstools-3.9.5/debian/gitlab-ci.yml 1970-01-01 00:00:00.000000000 +0000 +++ wcstools-3.9.6/debian/gitlab-ci.yml 2020-06-25 13:37:17.000000000 +0000 @@ -0,0 +1,8 @@ + +include: + - https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/salsa-ci.yml + - https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/pipeline-jobs.yml + +variables: + RELEASE: 'unstable' + \ No newline at end of file diff -Nru wcstools-3.9.5/debian/libwcstools1.lintian-overrides wcstools-3.9.6/debian/libwcstools1.lintian-overrides --- wcstools-3.9.5/debian/libwcstools1.lintian-overrides 2017-02-03 15:46:33.000000000 +0000 +++ wcstools-3.9.6/debian/libwcstools1.lintian-overrides 2020-06-25 13:43:46.000000000 +0000 @@ -1,4 +1,4 @@ # calling exit() is part of the wcstools API. -shlib-calls-exit usr/lib/*/libwcstools.so* +exit-in-shared-library usr/lib/*/libwcstools.so* # False positive spelling-error-in-binary usr/lib/*/libwcstools.so* lengH length diff -Nru wcstools-3.9.5/debian/libwcstools1.symbols wcstools-3.9.6/debian/libwcstools1.symbols --- wcstools-3.9.5/debian/libwcstools1.symbols 2017-02-03 15:46:33.000000000 +0000 +++ wcstools-3.9.6/debian/libwcstools1.symbols 2020-06-25 13:43:46.000000000 +0000 @@ -1,4 +1,5 @@ libwcstools.so.1 libwcstools1 #MINVER# +* Build-Depends-Package: libwcstools-dev AIR@Base 3.8.4 AIT@Base 3.8.4 ARC@Base 3.8.4 @@ -111,6 +112,7 @@ amoeba@Base 3.8.4 ang2deg@Base 3.8.4 ang2hr@Base 3.8.4 + ang2sec@Base 3.9.6 arcfwd@Base 3.8.4 arcrev@Base 3.8.4 arcset@Base 3.8.4 @@ -184,6 +186,7 @@ daoread@Base 3.8.4 dec2str@Base 3.8.4 deg2ang@Base 3.8.4 + deg2sec@Base 3.9.6 deg2str@Base 3.8.4 distortinit@Base 3.8.4 doy2dt@Base 3.8.4 @@ -398,6 +401,7 @@ hputra@Base 3.8.4 hputs@Base 3.8.4 hr2ang@Base 3.8.4 + hr2sec@Base 3.9.6 idg@Base 3.8.4 igetc@Base 3.8.4 igeti2@Base 3.8.4 @@ -778,6 +782,7 @@ ucac1path@Base 3.8.4 ucac2path@Base 3.8.4 ucac3path@Base 3.8.4 + ucac4hpmpath@Base 3.9.6 ucac4path@Base 3.9.0 ucacbin@Base 3.8.4 ucacclose@Base 3.8.4 diff -Nru wcstools-3.9.5/debian/mkhelpdb.cl wcstools-3.9.6/debian/mkhelpdb.cl --- wcstools-3.9.5/debian/mkhelpdb.cl 2018-01-23 20:22:29.000000000 +0000 +++ wcstools-3.9.6/debian/mkhelpdb.cl 2020-06-25 13:37:17.000000000 +0000 @@ -1,5 +1,5 @@ #!/usr/bin/irafcl -f softools -cd debian/iraf/lib -mkhelpdb root.hd helpdb.mip +set wcslib = "wcstools$lib/" +mkhelpdb wcslib$root.hd wcslib$helpdb.mip logout diff -Nru wcstools-3.9.5/debian/patches/Fix-getpix-output.patch wcstools-3.9.6/debian/patches/Fix-getpix-output.patch --- wcstools-3.9.5/debian/patches/Fix-getpix-output.patch 1970-01-01 00:00:00.000000000 +0000 +++ wcstools-3.9.6/debian/patches/Fix-getpix-output.patch 2020-06-25 13:43:46.000000000 +0000 @@ -0,0 +1,26 @@ +From: Ole Streicher +Date: Thu, 25 Jun 2020 16:14:57 +0200 +Subject: Fix getpix output + +--- + getpix.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/getpix.c b/getpix.c +index 3748199..1ac423f 100644 +--- a/getpix.c ++++ b/getpix.c +@@ -643,11 +643,11 @@ int *xpix, *ypix; /* Vectors of x,y coordinate pairs */ + intout = 0; + } + else if (bitpix > 0) { +- strcpy (pform, "%%d"); ++ sprintf (pform, "%%d"); + intout = 1; + } + else { +- strcpy (pform, "%%.2f"); ++ sprintf (pform, "%%.2f"); + intout = 0; + } + diff -Nru wcstools-3.9.5/debian/patches/Fix-several-bugs-that-appear-in-during-the-mayhem-tests.patch wcstools-3.9.6/debian/patches/Fix-several-bugs-that-appear-in-during-the-mayhem-tests.patch --- wcstools-3.9.5/debian/patches/Fix-several-bugs-that-appear-in-during-the-mayhem-tests.patch 2017-04-14 18:59:37.000000000 +0000 +++ wcstools-3.9.6/debian/patches/Fix-several-bugs-that-appear-in-during-the-mayhem-tests.patch 2020-06-25 13:43:46.000000000 +0000 @@ -8,7 +8,7 @@ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cphead.c b/cphead.c -index 9956e00..034e013 100644 +index e3dc09d..63fe2fb 100644 --- a/cphead.c +++ b/cphead.c @@ -148,7 +148,7 @@ char **av; @@ -21,11 +21,11 @@ } strcpy (kwd[nkwd], "RA"); diff --git a/getpix.c b/getpix.c -index 5a42f24..e49e328 100644 +index 05bd4bd..3748199 100644 --- a/getpix.c +++ b/getpix.c -@@ -83,6 +83,7 @@ char **av; - char *crange; /* Column range string */ +@@ -85,6 +85,7 @@ char **av; + char *yrange; /* Vertical(y) range string */ char *rstr; char *dstr = NULL; + char rastr[32], decstr[32]; diff -Nru wcstools-3.9.5/debian/patches/Fix-some-compiler-warnings.patch wcstools-3.9.6/debian/patches/Fix-some-compiler-warnings.patch --- wcstools-3.9.5/debian/patches/Fix-some-compiler-warnings.patch 2017-04-14 18:59:37.000000000 +0000 +++ wcstools-3.9.6/debian/patches/Fix-some-compiler-warnings.patch 2020-06-25 13:43:46.000000000 +0000 @@ -21,7 +21,7 @@ /* Pixel file has same name as header file, but with .pix extension */ diff --git a/libwcs/webread.c b/libwcs/webread.c -index 1f5c518..cd9cba9 100644 +index b317cad..da6f50c 100644 --- a/libwcs/webread.c +++ b/libwcs/webread.c @@ -32,6 +32,7 @@ diff -Nru wcstools-3.9.5/debian/patches/Rename-libwcs-to-libwcstools-to-avoid-conflicts-with-Mark.patch wcstools-3.9.6/debian/patches/Rename-libwcs-to-libwcstools-to-avoid-conflicts-with-Mark.patch --- wcstools-3.9.5/debian/patches/Rename-libwcs-to-libwcstools-to-avoid-conflicts-with-Mark.patch 2017-04-14 18:59:37.000000000 +0000 +++ wcstools-3.9.6/debian/patches/Rename-libwcs-to-libwcstools-to-avoid-conflicts-with-Mark.patch 2020-06-25 13:43:46.000000000 +0000 @@ -1,17 +1,18 @@ From: Ole Streicher Date: Fri, 5 Aug 2016 16:17:42 +0200 -Subject: Rename libwcs to libwcstools to avoid conflicts with Mark - Calabretta's wcslib package. +Subject: Rename libwcs to libwcstools + +Avoid conflicts with Mark Calabretta's wcslib package. Also, build a dynamic library and forward CFLAGS, CPPFLAGS and LDFLAGS for fortification. --- - Makefile | 134 ++++++++++++++++++++++++++++---------------------------- + Makefile | 136 ++++++++++++++++++++++++++++---------------------------- libwcs/Makefile | 14 ++++-- - 2 files changed, 76 insertions(+), 72 deletions(-) + 2 files changed, 77 insertions(+), 73 deletions(-) diff --git a/Makefile b/Makefile -index 38a0337..296219c 100644 +index 3c4a850..3d036f1 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,11 @@ @@ -31,7 +32,7 @@ all: cphead delwcs delhead edhead fixpix gethead i2f imcat imhead immatch \ imrot imsize imstar imwcs scat sethead addpix getpix setpix sky2xy \ -@@ -16,187 +15,186 @@ all: cphead delwcs delhead edhead fixpix gethead i2f imcat imhead immatch \ +@@ -16,190 +15,189 @@ all: cphead delwcs delhead edhead fixpix gethead i2f imcat imhead immatch \ isfile simpos bincat addpix: addpix.c $(LIBWCS) libwcs/fitsfile.h @@ -118,6 +119,10 @@ - $(CC) $(CFLAGS) -o $(BIN)/httpget httpget.c $(LIBS) + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $(BIN)/httpget httpget.c $(LIBS) + htmlsp: htmlsp.c +- $(CC) $(CFLAGS) -o $(BIN)/htmlsp htmlsp.c ++ $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $(BIN)/htmlsp htmlsp.c + i2f: i2f.c $(LIBWCS) libwcs/fitsfile.h - $(CC) $(CFLAGS) -o $(BIN)/i2f i2f.c $(LIBS) + $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $(BIN)/i2f i2f.c $(LIBS) diff -Nru wcstools-3.9.5/debian/patches/series wcstools-3.9.6/debian/patches/series --- wcstools-3.9.5/debian/patches/series 2017-04-14 18:59:37.000000000 +0000 +++ wcstools-3.9.6/debian/patches/series 2020-06-25 13:43:46.000000000 +0000 @@ -3,3 +3,4 @@ Fix-some-compiler-warnings.patch Fix-uninitialized-value-for-haspm-in-RASortStars.patch Spellfixes-and-manpage-fixes.patch +Fix-getpix-output.patch diff -Nru wcstools-3.9.5/debian/patches/Spellfixes-and-manpage-fixes.patch wcstools-3.9.6/debian/patches/Spellfixes-and-manpage-fixes.patch --- wcstools-3.9.5/debian/patches/Spellfixes-and-manpage-fixes.patch 2017-04-14 18:59:37.000000000 +0000 +++ wcstools-3.9.6/debian/patches/Spellfixes-and-manpage-fixes.patch 2020-06-25 13:43:46.000000000 +0000 @@ -9,6 +9,8 @@ libwcs/fitsfile.c | 10 +++++----- libwcs/imhfile.c | 4 ++-- man/man1/edhead.1 | 2 +- + man/man1/getcol.1 | 2 +- + man/man1/getpix.1 | 2 +- man/man1/imcat.1 | 2 +- man/man1/imgsc.1 | 4 ++-- man/man1/imua2.1 | 2 +- @@ -16,10 +18,10 @@ man/man1/skycoor.1 | 2 +- man/man1/sua2.1 | 2 +- man/man1/susa2.1 | 2 +- - 13 files changed, 20 insertions(+), 20 deletions(-) + 15 files changed, 22 insertions(+), 22 deletions(-) diff --git a/edhead.c b/edhead.c -index ceb1aef..da106d9 100644 +index 5e2883f..80dba1c 100644 --- a/edhead.c +++ b/edhead.c @@ -109,7 +109,7 @@ usage () @@ -32,7 +34,7 @@ fprintf(stderr," -v: verbose\n"); exit (1); diff --git a/immatch.c b/immatch.c -index 302a252..ed98c10 100644 +index a969663..aecad95 100644 --- a/immatch.c +++ b/immatch.c @@ -383,7 +383,7 @@ char **av; @@ -45,7 +47,7 @@ /* Process image files from list file */ diff --git a/imwcs.c b/imwcs.c -index 65e0bca..1334723 100644 +index ada7f28..4a23b19 100644 --- a/imwcs.c +++ b/imwcs.c @@ -285,7 +285,7 @@ char **av; @@ -67,7 +69,7 @@ if (!writeheader && !verbose) { diff --git a/libwcs/fitsfile.c b/libwcs/fitsfile.c -index 2c3e709..a2f0d0f 100644 +index 41a3797..c26c727 100644 --- a/libwcs/fitsfile.c +++ b/libwcs/fitsfile.c @@ -1583,7 +1583,7 @@ char *image; /* FITS image pixels */ @@ -150,6 +152,32 @@ .TP .B \-n Write a new file with .e before the file type extension. The default is +diff --git a/man/man1/getcol.1 b/man/man1/getcol.1 +index 9f2f2e6..dc630b5 100644 +--- a/man/man1/getcol.1 ++++ b/man/man1/getcol.1 +@@ -77,7 +77,7 @@ Print only sum, mmean, sigma, median, or range, not entries + .B \-r line range + Print columns from the lines specified as either the first nonzero + number on each line of the file listfile or the comma- and hyphen- +-delimitied range; i.e. 1-5,10-12 will print values from lines ++delimited range; i.e. 1-5,10-12 will print values from lines + 1, 2, 3, 4, 5, 10, 11, and 12. + (added in version 2.6.12) + .TP +diff --git a/man/man1/getpix.1 b/man/man1/getpix.1 +index 95d0b5e..bd7569e 100644 +--- a/man/man1/getpix.1 ++++ b/man/man1/getpix.1 +@@ -5,7 +5,7 @@ getpix \-Display FITS or IRAF image values + setpix [\-vn] file.fts [x_range y_range value] [@valuefile] + getpix [\-vp][\-n num][\-g val][\-l val] file.fits x_range y_range + getpix [\-vp][\-n num][\-g val][\-l val] file.fits x1 y1 x2 y2 ... xn yn +-getpix [\-vp][\-n num][\-g val][-\l val] file.fits @file ++getpix [\-vp][\-n num][\-g val][\-l val] file.fits @file + .SH Description + Display the values of list of specified pixels or ranges of pixels in a FITS or + IRAF 2-D image. Pixel values from a file of x y pairs may be displayed diff --git a/man/man1/imcat.1 b/man/man1/imcat.1 index a1cac13..e975af6 100644 --- a/man/man1/imcat.1 diff -Nru wcstools-3.9.5/debian/rules wcstools-3.9.6/debian/rules --- wcstools-3.9.5/debian/rules 2018-05-18 19:22:48.000000000 +0000 +++ wcstools-3.9.6/debian/rules 2020-06-25 13:43:46.000000000 +0000 @@ -15,7 +15,7 @@ mv bin/remap bin/wcsremap override_dh_auto_build-indep: - HOME=/tmp irafcl -f debian/mkhelpdb.cl + HOME=/tmp wcstools=`pwd`/debian/iraf/ irafcl -f debian/mkhelpdb.cl test -e debian/iraf/lib/helpdb.mip override_dh_auto_test-arch: @@ -34,7 +34,7 @@ for i in `ls bin` ; do \ if [ ! -f man/man1/$$i.1 ] ; then \ NAME=`fgrep $$i wcstools | sed "s/:/ \\\\- /"` ; \ - LD_LIBRARY_PATH=$$LD_LIBRARY_PATH:libwcs help2man --no-discard-stderr --version-string="$(shell dpkg-parsechangelog -S Version | cut -d- -f1)" -N -h "" -n "$NAME" bin/$$i | fgrep -v WCSTools > man/man_generated/$$i.1 ; \ + LD_LIBRARY_PATH=$$LD_LIBRARY_PATH:libwcs help2man --no-discard-stderr --version-string="$DEB_SOURCE" -N -h "" -n "$NAME" bin/$$i | fgrep -v WCSTools > man/man_generated/$$i.1 ; \ fi \ done dh_installman @@ -43,4 +43,3 @@ override_dh_fixperms-arch: dh_fixperms chmod 0644 debian/wcstools/usr/share/doc/wcstools/examples/* - diff -Nru wcstools-3.9.5/debian/tests/wcstools-test wcstools-3.9.6/debian/tests/wcstools-test --- wcstools-3.9.5/debian/tests/wcstools-test 2017-02-03 15:46:33.000000000 +0000 +++ wcstools-3.9.6/debian/tests/wcstools-test 2020-06-25 13:43:46.000000000 +0000 @@ -50,7 +50,7 @@ return 0 } -test_dir="$ADTTMP" +test_dir="$AUTOPKGTEST_TMP" if [ -z "$test_dir" ] ; then test_dir="$(mktemp -d)" fi @@ -87,7 +87,7 @@ EOF rm -f log fi - if [ "$test_dir" != "$ADTTMP" ] ; then + if [ "$test_dir" != "$AUTOPKGTEST_TMP" ] ; then rm -rf "$test_dir" fi exit $exitval @@ -126,9 +126,10 @@ EOF testProg getpix $fitsfile 100-102 200-203 <24.555812 + 1051: 2.69641123766753693348775 + 1151: 3149.96146500 + 1201: 12220.0554404 + 1251: 14092125.8383 + 1301: 623.880423.1722122.3471122.006121237667536933486881149.952612459009 + 1651: 20.044095448416625.2240121.7728420.4771919.2192718. + 1901: 55294^ diff -Nru wcstools-3.9.5/fdump.par wcstools-3.9.6/fdump.par --- wcstools-3.9.5/fdump.par 1970-01-01 00:00:00.000000000 +0000 +++ wcstools-3.9.6/fdump.par 2018-11-06 03:06:39.000000000 +0000 @@ -0,0 +1,6 @@ +FILENAME='testhtml' +NSKIP=1000 +NREAD=923 +DATATYPE='A' +END + diff -Nru wcstools-3.9.5/filedir.c wcstools-3.9.6/filedir.c --- wcstools-3.9.5/filedir.c 2017-03-30 15:21:51.000000000 +0000 +++ wcstools-3.9.6/filedir.c 2020-05-14 18:03:53.000000000 +0000 @@ -31,7 +31,7 @@ static int replace = 0; /* character replacement flag */ static char c1, c2; static void usage(); -static char *RevMsg = "FILEDIR WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "FILEDIR WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; int main (ac, av) diff -Nru wcstools-3.9.5/fileroot.c wcstools-3.9.6/fileroot.c --- wcstools-3.9.5/fileroot.c 2017-03-30 15:21:51.000000000 +0000 +++ wcstools-3.9.6/fileroot.c 2020-05-14 18:03:53.000000000 +0000 @@ -1,9 +1,9 @@ /* File fileroot.c - * January 10, 2007 + * August 17, 2018 * By Jessica Mink, Harvard-Smithsonian Center for Astrophysics * Send bug reports to jmink@cfa.harvard.edu - Copyright (C) 2000-2007 + Copyright (C) 2000-2018 Smithsonian Astrophysical Observatory, Cambridge, MA USA This program is free software; you can redistribute it and/or @@ -29,6 +29,7 @@ static int verbose = 0; /* verbose/debugging flag */ static int replace = 0; /* character replacement flag */ +static int twoext = 0; /* double extension flag */ static char c1, c2; static void usage(); @@ -39,7 +40,7 @@ { char *fn; char *str; - char *ext; + char *ext, *ext2; int i, lroot; /* crack arguments */ @@ -64,6 +65,10 @@ replace++; break; + case '2': /* remove double extension */ + twoext++; + break; + default: usage(); break; @@ -80,11 +85,19 @@ printf ("%s -> ", fn); ext = strrchr (fn, ','); if (ext != NULL) - *ext = 0; + *ext = (char) 0; else { ext = strrchr (fn, '.'); - if (ext != NULL) - *ext = 0; + if (ext != NULL) { + *ext = (char) 0; + if (twoext) { + ext2 = strrchr (fn, '.'); + if (ext2 != NULL) { + *ext = '.'; + *ext2 = (char) 0; + } + } + } } if (replace) { lroot= strlen (fn); @@ -101,9 +114,10 @@ usage () { fprintf (stderr,"FILEROOT: Drop file name extension\n"); - fprintf(stderr,"Usage: fileroot file1 file2 file3 ...\n"); - fprintf(stderr," fileroot -r c1 c2 file1 file2 file3 ...\n"); - fprintf(stderr," -r replaces c1 with c2 in file name\n"); + fprintf (stderr,"Usage: fileroot file1 file2 file3 ...\n"); + fprintf (stderr," fileroot -r c1 c2 file1 file2 file3 ...\n"); + fprintf (stderr," -r replaces c1 with c2 in file name\n"); + fprintf (stderr," -2 drops two extensions at once\n"); exit (1); } /* May 3 2000 New program @@ -114,4 +128,6 @@ * Jun 21 2006 Clean up code * * Jan 10 2007 Add second parentheses around character check + * + * Aug 17 2018 Add -2 to drop two-par extensions such as ".ms.fits" */ diff -Nru wcstools-3.9.5/fixpix.c wcstools-3.9.6/fixpix.c --- wcstools-3.9.5/fixpix.c 2017-03-30 15:21:51.000000000 +0000 +++ wcstools-3.9.6/fixpix.c 2020-05-14 18:03:53.000000000 +0000 @@ -47,7 +47,7 @@ static int version = 0; /* If 1, print only program name and version */ static int xl[MAXFIX],yl[MAXFIX]; /* Lower left corners of regions (1 based) */ static int xr[MAXFIX],yr[MAXFIX]; /* Upper right corners of regions (1 based) */ -static char *RevMsg = "FIXPIX WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "FIXPIX WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; int main (ac, av) diff -Nru wcstools-3.9.5/getcol.c wcstools-3.9.6/getcol.c --- wcstools-3.9.5/getcol.c 2017-03-30 21:31:22.000000000 +0000 +++ wcstools-3.9.6/getcol.c 2020-05-14 18:03:53.000000000 +0000 @@ -1,9 +1,9 @@ /* File getcol.c - * March 30, 2017 + * January 22, 2020 * By Jessica Mink, Harvard-Smithsonian Center for Astrophysics * Send bug reports to jmink@cfa.harvard.edu - Copyright (C) 1999-2017 + Copyright (C) 1999-2020 Smithsonian Astrophysical Observatory, Cambridge, MA USA This program is free software; you can redistribute it and/or @@ -37,13 +37,14 @@ #define MAXFILES 2000 #define MAXLINES 500000 -static char *RevMsg = "GETCOL WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "GETCOL WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static void usage(); static int ListFile(); static char *iscolop(); static int iscol(); static double median(); +static double stdev(); static int maxnfile = MAXFILES; static int maxq = MAXFILES; @@ -58,6 +59,8 @@ static int sumcol = 0; /* True to sum column values */ static int ameancol = 0; /* True for absolute mean of column values */ static int meancol = 0; /* True to compute mean of column values */ +static int adevcol = 0; /* True for stdev of absolute mean of column values */ +static int devcol = 0; /* True for stdev of mean of column values */ static int amedcol = 0; /* True for absolute median of column values */ static int medcol = 0; /* True to compute median of column values */ static int countcol = 0; /* True to count entries in columns */ @@ -409,6 +412,14 @@ ac--; break; + case 'y': /* Compute standard deviation of means of selected columns */ + devcol++; + break; + + case 'z': /* Compute standard deviation of absolute means of selected columns */ + adevcol++; + break; + default: usage (); break; @@ -510,6 +521,8 @@ fprintf(stderr," -v: Verbose\n"); fprintf(stderr," -w: Print file pathnames\n"); fprintf(stderr," -x num: Set value to ignore\n"); + fprintf(stderr," -y: Print stdev of means of selected numeric column(s)\n"); + fprintf(stderr," -z: Print stdev of means of absolute values of selected column(s)\n"); exit (1); } @@ -561,7 +574,7 @@ char tcond, *cstr, *cval, top; char colstr[16]; char numstr[32], numstr1[32]; - double dcond, dval; + double dcond, dval, dmean; int pass; int nchar, k; int iapp; @@ -588,8 +601,8 @@ if (verbose) printf ("\n%s\n", RevMsg); - if (listpath) - printf ("%s ", filename); + /* if (listpath) + printf ("%s ", filename); */ if (nread < 1) nread = MAXLINES; @@ -867,11 +880,19 @@ if (condand && !pass) break; } - if (pass) - printf ("%s\n", line); + if (pass) { + printf ("%s", line); + if (listpath) + printf ("%s", filename); + printf ("\n"); + } + } + else { + printf ("%s", line); + if (listpath) + printf ("%s", filename); + printf ("\n"); } - else - printf ("%s\n", line); } } @@ -1203,7 +1224,7 @@ token[j] = (char) 0; } strfix (token, 0, 1); - if (isnum (token) > 0 && isnum (token) < 2) { + if (isnum (token) > 0 && isnum (token) < 3) { dval = atof (token); hms[i] = 0; idnum = 1; @@ -1376,8 +1397,18 @@ qsum = qsum + sqrt (qsum1); } } - if (nt > 0 && printcol) + if (nt > 0 && printcol) { + if (listpath) { + if (tabout) + printf (" "); + else if (linout) + printf ("\n"); + else + printf (" "); + printf ("%s", filename); + } printf ("\n"); + } } } @@ -1439,6 +1470,46 @@ printf ("\n"); } + /* Standard deviation of mean absolute value */ + if (adevcol) { + for (i = 0; i < ncol; i++) { + if (nsum[i] > 0) { + dmean = asum[i] / (double)nsum[i]; + dval = stdev (amed[i], nsum[i], dmean); + if (hms[i]) { + if (ndec > -1) + dec2str (numstr, 32, dval, ndec); + else + dec2str (numstr, 32, dval, 3); + } + else if (ndec > -1) + num2str (numstr, dval, 0, ndec); + else { + sprintf (numstr, "%f", dval); + strfix (numstr, 0, 1); + } + if (i < ncol-1) + printf ("%s ", numstr); + else + printf ("%s", numstr); + } + else if (i < ncol-1) + printf ("___ "); + else + printf ("___"); + } + if (countcol) { + for (i = 0; i < ncol; i++) { + if (nent[i] > 0) + printf (" %d", nent[i]); + } + } + if (lranges != NULL) + printf (" %s", lranges); + if (ncol > 0) + printf ("\n"); + } + /* Print means of values in numeric columns */ if (meancol) { for (i = 0; i < ncol; i++) { @@ -1478,6 +1549,46 @@ printf ("\n"); } + /* Standard deviation of mean values */ + if (devcol) { + for (i = 0; i < ncol; i++) { + if (nsum[i] > 0) { + dmean = sum[i] / (double)nsum[i]; + dval = stdev (med[i], nsum[i], dmean); + if (hms[i]) { + if (ndec > -1) + dec2str (numstr, 32, dval, ndec); + else + dec2str (numstr, 32, dval, 3); + } + else if (ndec > -1) + num2str (numstr, dval, 0, ndec); + else { + sprintf (numstr, "%f", dval); + strfix (numstr, 0, 1); + } + if (i < ncol-1) + printf ("%s ", numstr); + else + printf ("%s", numstr); + } + else if (i < ncol-1) + printf ("___ "); + else + printf ("___"); + } + if (countcol) { + for (i = 0; i < ncol; i++) { + if (nent[i] > 0) + printf (" %d", nent[i]); + } + } + if (lranges != NULL) + printf (" %s", lranges); + if (ncol > 0) + printf ("\n"); + } + /* Print medians of absolute values in numeric columns */ if (amedcol) { for (i = 0; i < ncol; i++) { @@ -1702,6 +1813,32 @@ return ((x[lhs] + x[rhs]) / 2.0); } +static double +stdev (x, n, dmean) + +double *x; +int n; +double dmean; +{ + double diff, sqdiff; + double sumsq = 0.0; + double dn = (double) n; + int i; + + if (n < 2) { + return (0.0); + } + + for (i = 0; i < n; i++) { + diff = (x[i] - dmean); + sqdiff = diff * diff; + sumsq = sumsq + sqdiff; + } + + return (sqrt (sumsq / dn)); +} + + static int iscol (string) @@ -1846,4 +1983,9 @@ * Aug 10 2016 Add -u argument to print each field on a new line * * Mar 30 2017 Increase default maximum number of lines to process to 500000 + * + * Jul 25 2019 Fix bug so stats on floating point numbers are computed + * Jul 25 2019 Add standard deviations of means of selected columns + * + * Jan 22 2020 Change path option to append path at end of each line */ diff -Nru wcstools-3.9.5/getdate.c wcstools-3.9.6/getdate.c --- wcstools-3.9.5/getdate.c 2017-03-30 15:21:51.000000000 +0000 +++ wcstools-3.9.6/getdate.c 2020-05-14 18:03:53.000000000 +0000 @@ -1,9 +1,9 @@ /* File getdate.c - * August 2, 1016 + * September 24, 2019 * By Jessica Mink, Harvard-Smithsonian Center for Astrophysics * Send bug reports to jmink@cfa.harvard.edu - Copyright (C) 1999-2016 + Copyright (C) 1999-2019 Smithsonian Astrophysical Observatory, Cambridge, MA USA This program is free software; you can redistribute it and/or @@ -59,6 +59,7 @@ #define DTANG 25 /* Angle in fractional degrees */ #define DTHR 26 /* Angle in sexigesimal hours (hh:mm:ss.ss) */ #define DTDEG 27 /* Angle in sexigesimal degrees (dd:mm:ss.ss) */ +#define DTSEC 28 /* Angle in fractional arcseconds */ #define UT 0 #define ET 1 @@ -66,7 +67,7 @@ #define MST 3 #define LST 4 -static char *RevMsg = "GETDATE WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "GETDATE WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static void usage(); static void ConvertDate(); @@ -132,6 +133,8 @@ intype = DTVIG; else if (!strncmp (*av, "ang2", 4)) intype = DTANG; + else if (!strncmp (*av, "sec2", 4)) + intype = DTSEC; else if (!strncmp (*av, "deg2", 4)) intype = DTDEG; else if (!strncmp (*av, "hr2", 3)) @@ -198,6 +201,8 @@ /* Set output date format */ if (strsrch (*av, "2dt")) outtype = DTVIG; + else if (strsrch (*av, "2sec")) + outtype = DTSEC; else if (strsrch (*av, "2ang")) outtype = DTANG; else if (strsrch (*av, "2deg")) @@ -440,6 +445,7 @@ fprintf(stderr," ep=epoch, epj=Julian epoch, epb=Besselian epoch\n"); fprintf(stderr," ts=seconds since 1950-01-01, tsu=Unix sec, tsi=IRAF sec\n"); fprintf(stderr," gst=Greenwich Sidereal Time, lst=Local Sidereal Time\n"); + fprintf(stderr," sec=fractional arcseconds\n"); fprintf(stderr," @file: First one or two columns are in itype format\n"); fprintf(stderr," ra dec sys: Need for Heliocentric conversions\n"); fprintf(stderr," -a: Append date to input file, if there is one\n"); @@ -547,6 +553,10 @@ ang2deg (vtime, 64, temp); printf ("%s\n", temp); break; + case DTSEC: + vtime = ang2sec (atof (datestring)); + printf (outform, vtime); + break; default: printf ("*** Unknown output type %d\n", outtype); } @@ -566,6 +576,10 @@ ang2hr (vtime, 64, temp); printf ("%s\n", temp); break; + case DTSEC: + vtime = deg2sec (datestring); + printf (outform, vtime); + break; default: printf ("*** Unknown output type %d\n", outtype); } @@ -585,6 +599,10 @@ ang2deg (vtime, 64, temp); printf ("%s\n", temp); break; + case DTSEC: + vtime = hr2sec (datestring); + printf (outform, vtime); + break; default: printf ("*** Unknown output type %d\n", outtype); } @@ -2376,4 +2394,6 @@ * Aug 24 2015 Fix bug with FITS date conversion * * Aug 2 2016 Fix bug handling input files + * + * Sep 24 2019 Add DTSEC=28 and ang2sec, hr2sec, and dec2sec conversions */ diff -Nru wcstools-3.9.5/getfits.c wcstools-3.9.6/getfits.c --- wcstools-3.9.5/getfits.c 2017-03-30 15:21:51.000000000 +0000 +++ wcstools-3.9.6/getfits.c 2020-05-14 18:03:53.000000000 +0000 @@ -1,9 +1,9 @@ /* File getfits.c - * June 24, 2016 + * July 26, 2018 * By Jessica Mink, Harvard-Smithsonian Center for Astrophysics * Send bug reports to jmink@cfa.harvard.edu - Copyright (C) 2002-2016 + Copyright (C) 2002-2018 Smithsonian Astrophysical Observatory, Cambridge, MA USA This program is free software; you can redistribute it and/or @@ -43,7 +43,7 @@ static int ExtractFITS(); static int verbose = 0; /* verbose/debugging flag */ -static char *RevMsg = "GETFITS WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "GETFITS WCSTools 3.9.6, 28 July 2018, Jessica Mink (jmink@cfa.harvard.edu)"; static int version = 0; /* If 1, print only program name and version */ static char outname[128]; /* Name for output image */ static char outdir[256]; /* Output directory pathname */ @@ -74,11 +74,12 @@ FILE *flist; char *nextarg; char rastr[32], decstr[32]; + int lstr; int nkwd = 0; /* Number of keywords to delete */ int nkwd1 = 0; /* Number of keywords in delete file */ + int ikwd; char **kwd = NULL; /* List of keywords to be deleted */ char **kwdnew; - int ikwd; FILE *fdk; char *klistfile; @@ -102,16 +103,39 @@ /* crack arguments */ for (av++; --ac > 0; av++) { + /* Set range of pixels to extract */ + if (isrange (*av)) { + if (crange == NULL) { + lstr = strlen (*av); + crange = (char *) calloc (lstr+1, sizeof (char) ); + strcpy (crange, *av); + } + else { + lstr = strlen (*av); + rrange = (char *) calloc (lstr+1, sizeof (char)); + strcpy (rrange, *av); + if (verbose) { + printf ("GETFITS: rows %s, columns %s\n",rrange,crange); + } + } + } + /* Set center RA, Dec, and equinox if colon in argument */ - if (strsrch (*av,":") != NULL) { + else if (isnum (*av) == 3) { if (ac < 2) usage ("Right ascension given but no declination"); else { strcpy (rastr, *av); ac--; - strcpy (decstr, *++av); - ra0 = str2ra (rastr); - dec0 = str2dec (decstr); + av++; + if (isnum (*av) == 3) { + strcpy (decstr, *av); + ra0 = str2ra (rastr); + dec0 = str2dec (decstr); + } + else { + usage ("Declination not in sexigesimal"); + } ac--; if (ac < 1) { syscoor = WCS_J2000; @@ -177,7 +201,7 @@ } else { for (ikwd = nkwd; ikwd < nkwd+nkwd1; ikwd++) { - kwd[ikwd] = (char *) calloc (32, 1); + kwd[ikwd] = (char *) calloc (32, sizeof (char)); first_token (fdk, 31, kwd[ikwd]); } fclose (fdk); @@ -253,14 +277,6 @@ } } - /* Range of pixels to extract */ - else if (isrange (*av)) { - if (crange == NULL) - crange = str; - else - rrange = str; - } - /* File with list of image files */ else if (*av[0] == '@') { listfile = *av + 1; @@ -286,6 +302,11 @@ ydpix = xdpix; } + /* If column range is set, but not row range, set them to be the same */ + else if (!rrange && ydpix == 0) { + rrange = crange; + } + /* If one side is set, set the other */ if (xdpix && !ydpix) ydpix = xdpix; @@ -480,6 +501,7 @@ return (1); } + /* Keep extracted region within image height (nrows) */ if (ifrow1 < 1) ifrow1 = 1; if (ifrow2 < 1) @@ -514,6 +536,7 @@ return (1); } + /* Keep extracted region within image width (ncols) */ if (ifcol1 < 1) ifcol1 = 1; if (ifcol2 < 1) @@ -524,6 +547,11 @@ ifcol2 = ncols; wp = ifcol2 - ifcol1 + 1; + if (verbose) { + printf ("GETFITS: Extracting %d rows %d - %d, %d columns %d - %d\n", + hp, ifrow1, ifrow2, wp, ifcol1, ifcol2); + } + /* Extract image */ newimage = fitsrsect (name, header, nbhead, ifcol1, ifrow1, wp, hp, nlog); @@ -754,4 +782,6 @@ * * Jun 9 2016 Fix isnum() tests for added coloned times and dashed dates * Jun 24 2016 Decrement argument counter after reading center RA + + * Jul 26 2018 Add statement of limits in verbose mode */ Binary files /tmp/tmpAU7Qas/lxsO8C14BK/wcstools-3.9.5/getfits.zip and /tmp/tmpAU7Qas/kkdBNQZs62/wcstools-3.9.6/getfits.zip differ diff -Nru wcstools-3.9.5/getftab.c wcstools-3.9.6/getftab.c --- wcstools-3.9.5/getftab.c 2017-03-30 15:21:51.000000000 +0000 +++ wcstools-3.9.6/getftab.c 2020-05-14 18:03:53.000000000 +0000 @@ -40,7 +40,7 @@ static void PrintValues(); static int maxncond = 100; -static char *RevMsg = "GETFTAB WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "GETFTAB WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static int verbose = 0; /* verbose/debugging flag */ static int nfile = 0; diff -Nru wcstools-3.9.5/gethead.c wcstools-3.9.6/gethead.c --- wcstools-3.9.5/gethead.c 2017-03-30 15:21:51.000000000 +0000 +++ wcstools-3.9.6/gethead.c 2020-05-14 18:03:53.000000000 +0000 @@ -47,7 +47,7 @@ static char nextnsp(); static int PrintValues(); -static char *RevMsg = "GETHEAD WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "GETHEAD WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static int verbose = 0; /* verbose/debugging flag */ static int nfile = 0; @@ -762,6 +762,7 @@ fprintf(stderr," -n num: Number of decimal places in numeric output\n"); fprintf(stderr," -o: OR conditions instead of ANDing them\n"); fprintf(stderr," -p: Print full pathnames of files\n"); + fprintf(stderr," -r: Precede each value by first keyword character\n"); fprintf(stderr," -s: Do not pad tab-separated table with spaces\n"); fprintf(stderr," -t: Output in tab-separated table format\n"); fprintf(stderr," -u: Always print ___ if keyword not found or null value\n"); @@ -1135,6 +1136,13 @@ } nfound++; } + else if (tabchar) { + if (keyword[0] == 'B') + sprintf (temp, "%c_", keyword[0], str); + else + sprintf (temp, "%c___", keyword[0], str); + strcat (outline, temp); + } } } @@ -1285,6 +1293,13 @@ strcat (outline, str); nfound++; } + else if (tabchar) { + if (keyword[0] == 'B') + sprintf (temp, "%c_", keyword[0], str); + else + sprintf (temp, "%c___", keyword[0], str); + strcat (outline, temp); + } /* Read IRAF-style multiple-line keyword value */ else if (hgetm (header, keyword, maxml, mstring)) { @@ -1524,4 +1539,6 @@ * Dec 19 2014 Add option to separate values by first character of keyword * * Jan 20 2015 Add quotes to string values with spaces in -e option + * + * Mar 12 2019 Fill in single-character null returns */ diff -Nru wcstools-3.9.5/getpix.c wcstools-3.9.6/getpix.c --- wcstools-3.9.5/getpix.c 2017-03-30 15:21:51.000000000 +0000 +++ wcstools-3.9.6/getpix.c 2020-05-14 18:03:54.000000000 +0000 @@ -1,9 +1,9 @@ /* File getpix.c - * June 9, 2016 + * May 14, 2020 * By Jessica Mink, Harvard-Smithsonian Center for Astrophysics) * Send bug reports to jmink@cfa.harvard.edu - Copyright (C) 1996-2016 + Copyright (C) 1996-2020 Smithsonian Astrophysical Observatory, Cambridge, MA USA This program is free software; you can redistribute it and/or @@ -41,12 +41,12 @@ static void PrintPix(); static void procpix(); -static char *RevMsg = "GETPIX WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "GETPIX WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static int verbose = 0; /* verbose/debugging flag */ static int version = 0; /* If 1, print only program name and version */ -static int nline = 10; /* Number of pixels printer per line */ -static char *pform = NULL; /* Format in which to print pixels */ +static int nline = 10; /* Number of pixels displayed per line */ +static int ndec = -1; /* Format in which to print pixels */ static int pixlabel = 0; /* If 1, label pixels in output */ static int gtcheck = 0; /* If 1, list pixels greater than gtval */ static int ltcheck = 0; /* If 1, list pixels less than ltval */ @@ -54,6 +54,7 @@ static int printrange = 0; /* If 1, print range of values, not values */ static int printmean = 0; /* If 1, print mean of values, not values */ static int printname = 0; /* If 1, print file name */ +static int bycol = 0; /* If 1, display column as line */ static double gtval = 0.0; static double ltval = 0.0; static double ra0 = -99.0; /* Initial center RA in degrees */ @@ -66,6 +67,7 @@ static int identifier = 0; /* If 1, identifier precedes x y in file */ static int printtab = 0; /* If 1, separate number with tabs */ static int procinit = 1; /* If 1, start mean and limits */ +static char pformat[8]; /* If not null, format for pixels without leading % */ int main (ac, av) @@ -79,8 +81,8 @@ char filename[256]; int ifile, nbytes; FILE *flist; - char *rrange; /* Row range string */ - char *crange; /* Column range string */ + char *xrange; /* Horizontal(x) range string */ + char *yrange; /* Vertical(y) range string */ char *rstr; char *dstr = NULL; char *cstr; @@ -88,6 +90,8 @@ int i; int npix = 0; int nfile; + int ixnum, iynum; + int ixrange, iyrange; char linebuff[1024]; char listname[256]; char *line; @@ -103,6 +107,7 @@ fn = (char **)calloc (maxnfile, sizeof(char *)); xpix = (int *)calloc (maxnpix, sizeof (int)); ypix = (int *)calloc (maxnpix, sizeof (int)); + pformat[0] = (char) 0; /* Check for help or version command first */ str = *(av+1); @@ -113,24 +118,27 @@ usage(); } - crange = NULL; - rrange = NULL; + xrange = NULL; + yrange = NULL; /* crack arguments */ for (av++; --ac > 0; av++) { str = *av; - if (ac > 0) + ixnum = isnum (str); + ixrange = isrange (str); + if (ac > 0) { str1 = *(av+1); - else + iynum = isnum (str1); + iyrange = isrange (str1); + } + else { str1 = NULL; - - /* Output format */ - if (str[0] == '%') { - pform = *av; + iynum = 0; + iyrange = 0; } - /* Other command */ - else if (str[0] == '-') { + /* Command */ + if (str[0] == '-') { char c; while ((c = *++str)) switch (c) { @@ -139,7 +147,14 @@ verbose++; break; - case 'd': /* Print range of values */ + case 'd': /* Display this number of decimal places */ + if (ac < 2) + usage(); + ndec = atoi (*++av); + ac--; + break; + + case 'e': /* Print range of values */ printrange=1; break; @@ -178,6 +193,13 @@ ac--; break; + case 'o': /* Output pixel format without leading % */ + if (ac < 2) + usage(); + strncpy (pformat, *++av, 8); + ac--; + break; + case 'p': /* label pixels */ pixlabel++; break; @@ -216,6 +238,10 @@ printtab++; break; + case 'y': /* Display by column instead of line */ + bycol++; + break; + default: usage(); break; @@ -223,9 +249,10 @@ } /* Set search RA, Dec, and equinox if colon in argument */ - else if (isnum (str) == 3 && isnum (str1) == 3) { - if (ac < 2) + else if (ixnum == 3 && iynum == 3) { + if (ac < 2) { usage (); + } else { strcpy (rstr, str); ac--; @@ -248,7 +275,7 @@ } /* Search coordinates in degrees if coordinate system specified */ - else if (isnum (str) == 2 && isnum (str) == 2) { + else if (ixnum == 2 && iynum == 2) { rstr = str; dstr = str1; ac--; @@ -297,8 +324,24 @@ } } + /* Ranges of x and y pixels to print (only one pair allowed) */ + else if (ixrange && iynum || ixnum && iyrange || ixrange && iyrange) { + xrange = str; + yrange = str1; + ac--; + av++; + } + + /* Two zeroes indicates that the entire image should be printed */ + else if (!strcmp (str, "0") && !strcmp (str, "0")) { + xrange = str; + yrange = str1; + ac--; + av++; + } + /* Coordinate pairs for pixels to print */ - else if (isnum (str) == 1 && isnum (str1) == 1) { + else if (ixnum == 1 && iynum == 1) { if (npix+1 > maxnpix) { maxnpix = 2 * maxnpix; xp1 = calloc (maxnpix, sizeof (int)); @@ -315,8 +358,8 @@ ix = atoi (str); iy = atoi (str1); if (ix == 0 || iy == 0) { - crange = str1; - rrange = str; + xrange = str1; + yrange = str; } else { xpix[npix] = ix; @@ -327,14 +370,6 @@ ac--; } - /* Range of pixels to print (only one allowed) */ - else if (isrange (str) && isrange (str1)) { - rrange = str; - crange = str1; - ac--; - av++; - } - /* File containing a list of files or image coordinates */ else if (str[0] == '@') { strcpy (listname, str+1); @@ -392,12 +427,12 @@ } } - if ((crange && rrange) || npix > 0) { + if ((xrange && yrange) || npix > 0) { /* Process files already read from the command line */ - if (fn) { + if (nfile) { for (ifile = 0; ifile < nfile; ifile++) { - PrintPix (fn[ifile], crange, rrange, npix, xpix, ypix); + PrintPix (fn[ifile], xrange, yrange, npix, xpix, ypix); } } @@ -411,7 +446,7 @@ } for (ifile = 0; ifile < nfile; ifile++) { first_token (flist, 254, filename); - PrintPix (filename, crange, rrange, npix, xpix, ypix); + PrintPix (filename, xrange, yrange, npix, xpix, ypix); } fclose (flist); } @@ -430,12 +465,12 @@ if (version) exit (-1); fprintf (stderr,"Print FITS or IRAF pixel values\n"); - fprintf(stderr,"Usage: getpix [-vp][-n num][-g val][-l val][format] file.fit x_range y_range\n"); - fprintf(stderr," or getpix [-vp][-n num][-g val][-l val][format] file.fit x1 y1 x2 y2 ... xn yn\n"); - fprintf(stderr," or getpix [-vp][-n num][-g val][-l val][format] file.fit @file\n"); - fprintf(stderr," format: C-style (%%f, %%d, ...) format for pixel values\n"); + fprintf(stderr,"Usage: getpix [-vp][-n num][-g val][-l val] file.fits x_range y_range\n"); + fprintf(stderr," or getpix [-vp][-n num][-g val][-l val] file.fits x1 y1 x2 y2 ... xn yn\n"); + fprintf(stderr," or getpix [-vp][-n num][-g val][-l val] file.fits @file\n"); fprintf(stderr," file: File with x y coordinates as first two tokens on lines\n"); - fprintf(stderr," -d: Print range of pixel values in specified image region\n"); + fprintf(stderr," -d: Number of decimal places in displayed pixel values\n"); + fprintf(stderr," -e: Print range of pixel values in specified image region\n"); fprintf(stderr," -f name: Write specified region to a FITS file\n"); fprintf(stderr," -g num: keep pixels with values greater than this\n"); fprintf(stderr," -h: print file name on line above pixel values\n"); @@ -443,26 +478,30 @@ fprintf(stderr," -l num: keep pixels with values less than this\n"); fprintf(stderr," -m: Print mean of pixel values in specified image region\n"); fprintf(stderr," -n num: number of pixel values printed per line\n"); + fprintf(stderr," -o format: Output format in C style without leading %%\n"); fprintf(stderr," -p: label pixels\n"); fprintf(stderr," -r num: radius (<0=box) to extract in degrees/arcsec\n"); fprintf(stderr," -s: print x y value with no punctuation\n"); + fprintf(stderr," -t: separate columns in table with tabs not spaces \n"); fprintf(stderr," -v: verbose\n"); - fprintf(stderr," %%: C format for each pixel value\n"); + fprintf(stderr," -y: display by column instead of by row\n"); exit (1); } static void -PrintPix (name, crange, rrange, npix, xpix, ypix) +PrintPix (name, xrange, yrange, npix, xpix, ypix) char *name; -char *crange; /* Column range string */ -char *rrange; /* Row range string */ +char *xrange; /* Horizontal(x) range string */ +char *yrange; /* Vertical(y) range string */ int npix; /* Number of coordinate pairs */ int *xpix, *ypix; /* Vectors of x,y coordinate pairs */ { char *header; /* FITS image header */ + char pform[8]; /* Pixel display format */ + char testval[32]; /* Test value string for column header formatting */ int lhead; /* Maximum number of bytes in FITS header */ int nbhead; /* Actual number of bytes in FITS header */ char *irafheader; /* IRAF image header */ @@ -470,15 +509,17 @@ double bzero; /* Zero point for pixel scaling */ double bscale; /* Scale factor for pixel scaling */ int iraffile; + int lf; + int intout = 0; /* Display output pixel values as integer if =1 */ double dpix, dsum, dmean, dmin, dmax, dnpix; char *c; - int *yi; - int bitpix,xdim,ydim, i, nx, ny, ix, iy, x, y, pixperline; + int *yi, *xi; + int bitpix, xdim, ydim, i, nx, ny, ix, iy, x, y, x1, y1, pixperline, ndig; int ipix = 0; char pixname[255]; - char nform[8]; - struct Range *xrange; /* X range structure */ - struct Range *yrange; /* Y range structure */ + char cform[8], rform[8]; + struct Range *crange; /* Column (nominally x) range structure */ + struct Range *rrange; /* Row (nominally y) range structure */ /* Open IRAF image if .imh extension is present */ if (isiraf (name)) { @@ -529,16 +570,35 @@ else fprintf (stderr,"%s:\n", name); } + + /* Get size of image and scaling factors */ + bitpix = 32; + hgeti4 (header,"BITPIX",&bitpix); + xdim = 1; + hgeti4 (header,"NAXIS1",&xdim); + ydim = 1; + hgeti4 (header,"NAXIS2",&ydim); + bzero = 0.0; + hgetr8 (header,"BZERO",&bzero); + bscale = 1.0; + hgetr8 (header,"BSCALE",&bscale); + if (verbose) { fprintf (stderr,"%s\n",RevMsg); if (npix > 0) - fprintf (stderr,"Print pixels in "); - else if (!strcmp (crange, "0")) - fprintf (stderr,"Print rows %s in ", rrange); - else if (!strcmp (rrange, "0")) - fprintf (stderr,"Print columns %s in ", crange); + fprintf (stderr,"Print pixels of "); + else if (!strcmp (xrange, "0") && !strcmp (yrange, "0")) + fprintf (stderr,"Print x 1-%d columns, y 1-%d rows of ", xdim, ydim); + else if (!strcmp (xrange, "0")) + fprintf (stderr,"Print x 1-%d columns, y %s rows of ", xdim, yrange); + else if (bycol && !strcmp (yrange, "0")) + fprintf (stderr,"Print y 1-%d columns, x %s rows of ", ydim, xrange); + else if (!strcmp (yrange, "0")) + fprintf (stderr,"Print x %s columns, y 1-%d rows of ", xrange, ydim); + else if (bycol) + fprintf (stderr,"Print y %s columns , x %s rows of ", yrange, xrange); else - fprintf (stderr,"Print rows %s, columns %s in ", rrange, crange); + fprintf (stderr,"Print x %s rows, y %s columns of ", xrange, yrange); if (iraffile) fprintf (stderr,"IRAF image file %s\n", name); else @@ -555,18 +615,7 @@ else pixperline = 0; -/* Get value of specified pixel */ - - /* Get size of image and scaling factors */ - hgeti4 (header,"BITPIX",&bitpix); - xdim = 1; - hgeti4 (header,"NAXIS1",&xdim); - ydim = 1; - hgeti4 (header,"NAXIS2",&ydim); - bzero = 0.0; - hgetr8 (header,"BZERO",&bzero); - bscale = 1.0; - hgetr8 (header,"BSCALE",&bscale); +/* Set up pixel access and display */ /* Set initial values */ dsum = 0.0; @@ -576,12 +625,29 @@ procinit = 1; /* Set format if not already set */ - if (pform == NULL) { - pform = (char *) calloc (8,1); - if (bitpix > 0) - strcpy (pform, "%d"); - else - strcpy (pform, "%.2f"); + for (i = 0; i < 8; i++) + pform[i] = (char) 0; + if (pformat[0] != (char) 0) { + sprintf (pform, "%%%s", pformat); + lf = strlen (pformat); + if (pformat[lf-1] == 'd') + intout = 1; + } + else if (ndec == 0) { + sprintf (pform, "%%d"); + intout = 1; + } + else if (ndec > 0) { + sprintf (pform, "%%.%df", ndec); + intout = 0; + } + else if (bitpix > 0) { + strcpy (pform, "%%d"); + intout = 1; + } + else { + strcpy (pform, "%%.2f"); + intout = 0; } /* Print values at specified coordinates in an image */ @@ -594,20 +660,32 @@ if ((gtcheck && dpix > gtval) || (ltcheck && dpix < ltval)) { procpix (&dsum, &dnpix, &dmin, &dmax, dpix); + if (intout) { + if (dpix > 0) + ipix = (int) (dpix + 0.5); + else if (dpix < 0) + ipix = (int) (dpix - 0.5); + else + ipix = 0; + } if (nopunct) - printf ("%d %d %f\n", xpix[i], ypix[i], dpix); + printf ("%d %d \n", xpix[i], ypix[i]); else - printf ("[%d,%d] = %f\n", xpix[i], ypix[i], dpix); + printf ("[%d,%d] = \n", xpix[i], ypix[i]); + if (intout) + printf (pform, ipix); + else + printf (pform, dpix); + printf ("\n"); } continue; } + else procpix (&dsum, &dnpix, &dmin, &dmax, dpix); if (printrange || printmean) continue; - if (bitpix > 0) { - if ((c = strchr (pform,'f')) != NULL) - *c = 'd'; + if (intout) { if (dpix > 0) ipix = (int) (dpix + 0.5); else if (dpix < 0) @@ -615,20 +693,16 @@ else ipix = 0; } - else { - if ((c = strchr (pform,'d')) != NULL) - *c = 'f'; - } if (pixperline) { printf ("%s[%d,%d] = ",name,xpix[i],ypix[i]); - if (bitpix > 0) + if (intout) printf (pform, ipix); else printf (pform, dpix); printf ("\n"); } else { - if (bitpix > 0) + if (intout) printf (pform, ipix); else printf (pform, dpix); @@ -645,7 +719,7 @@ } /* Print entire image */ - else if (!strcmp (rrange, "0") && !strcmp (crange, "0")) { + else if (!strcmp (xrange, "0") && !strcmp (yrange, "0")) { if (printmean || printrange) { nx = xdim; ny = ydim; @@ -668,22 +742,24 @@ nx = xdim; ny = ydim; for (y = 0; y < ny; y++) { + y1 = y + 1; for (x = 0; x < nx; x++) { + x1 = x + 1; dpix = getpix (image,bitpix,xdim,ydim,bzero,bscale,x,y); if (gtcheck && ltcheck) { if (dpix > gtval && dpix < ltval) { if (nopunct) - printf ("%d %d %f\n", x+1, y+1, dpix); + printf ("%d %d %f\n", x1, y1, dpix); else - printf ("[%d,%d] = %f\n", x+1, y+1, dpix); + printf ("[%d,%d] = %f\n", x1, y1, dpix); } } else if ((gtcheck && dpix > gtval) || (ltcheck && dpix < ltval)) { if (nopunct) - printf ("%d %d %f\n", x+1, y+1, dpix); + printf ("%d %d %f\n", x1, y1, dpix); else - printf ("[%d,%d] = %f\n", x+1, y+1, dpix); + printf ("[%d,%d] = %f\n", x1, y1, dpix); } } } @@ -694,29 +770,37 @@ } /* Print entire columns */ - else if (!strcmp (rrange, "0")) { - xrange = RangeInit (crange, xdim); - nx = rgetn (xrange); + else if (!strcmp (yrange, "0")) { + + /* Make list of x coordinates */ + crange = RangeInit (xrange, xdim); + nx = rgetn (crange); + xi = (int *) calloc (nx, sizeof (int)); + for (i = 0; i < nx; i++) { + xi[i] = rgeti4 (crange); + } + ny = ydim; - for (ix = 0; ix < nx; ix++) { - rstart (xrange); - x = rgeti4 (xrange) - 1; - for (y = 0; y < ny; y++) { + for (y = 0; y < ny; y++) { + y1 = y + 1; + for (ix = 0; ix < nx; ix++) { + x = xi[ix]; + x1 = x + 1; dpix = getpix (image,bitpix,xdim,ydim,bzero,bscale,x,y); if (gtcheck || ltcheck) { if ((gtcheck && dpix > gtval) || (ltcheck && dpix < ltval)) { procpix (&dsum, &dnpix, &dmin, &dmax, dpix); if (nopunct) - printf ("%d %d %f\n", x+1, y+1, dpix); + printf ("%d %d %f\n", x1, y1, dpix); else - printf ("[%d,%d] = %f\n", x+1, y+1, dpix); + printf ("[%d,%d] = %f\n", x1, y1, dpix); } continue; } else procpix (&dsum, &dnpix, &dmin, &dmax, dpix); - if (bitpix > 0) { + if (intout) { if (dpix > 0) ipix = (int) (dpix + 0.5); else if (dpix < 0) @@ -726,18 +810,18 @@ } if (pixperline) { printf ("%s[%d,%d] = ",name,x,y); - if (bitpix > 0) + if (intout) printf (pform, ipix); else printf (pform, dpix); printf ("\n"); } else { - if (bitpix > 0) + if (intout) printf (pform, ipix); else printf (pform, dpix); - if ((y+1) % nline == 0) + if ((y1) % nline == 0) printf ("\n"); else if (printtab) printf ("\t"); @@ -750,17 +834,24 @@ if (nx > 1 && !gtcheck && !ltcheck) printf ("\n"); } - free (xrange); + free (crange); } /* Print entire rows */ - else if (!strcmp (crange, "0")) { - yrange = RangeInit (rrange, xdim); - ny = rgetn (yrange); + else if (!strcmp (xrange, "0")) { + + /* Make list of y coordinates */ + rrange = RangeInit (yrange, ydim); + ny = rgetn (rrange); + yi = (int *) calloc (ny, sizeof (int)); + for (i = 0; i < ny; i++) { + yi[i] = rgeti4 (rrange); + } + nx = xdim; - for (iy = 0; iy < ny; iy++) { - y = rgeti4 (yrange) - 1; - for (x = 0; x < nx; x++) { + for (x = 0; x < nx; x++) { + for (iy = 0; iy < ny; iy++) { + y = yi[iy]; dpix = getpix (image,bitpix,xdim,ydim,bzero,bscale,x,y); if (gtcheck || ltcheck) { if ((gtcheck && dpix > gtval) || @@ -775,7 +866,7 @@ } else procpix (&dsum, &dnpix, &dmin, &dmax, dpix); - if (bitpix > 0) { + if (intout) { if (dpix > 0) ipix = (int) (dpix + 0.5); else if (dpix < 0) @@ -785,14 +876,14 @@ } if (pixperline) { printf ("%s[%d,%d] = ",name,x,y); - if (bitpix > 0) + if (intout) printf (pform, ipix); else printf (pform, dpix); printf ("\n"); } else { - if (bitpix > 0) + if (intout) printf (pform, ipix); else printf (pform, dpix); @@ -809,86 +900,229 @@ if (ny > 1 && !gtcheck && !ltcheck) printf ("\n"); } - free (yrange); + free (rrange); + } + +/* Print a region of a two-dimensional image sideways */ + else if (bycol) { + + /* Make list of x coordinates */ + rrange = RangeInit (xrange, xdim); + nx = rgetn (rrange); + xi = (int *) calloc (nx, sizeof (int)); + for (i = 0; i < nx; i++) { + xi[i] = rgeti4 (rrange); + } + + /* Make list of x coordinates */ + crange = RangeInit (yrange, xdim); + ny = rgetn (crange); + yi = (int *) calloc (ny, sizeof (int)); + for (i = 0; i < ny; i++) { + yi[i] = rgeti4 (crange); + } + + /* Set pixel label formats */ + if (pixlabel) { + + /* Format for row pixel labels */ + x = xi[nx-1]; + sprintf (testval, "%d", x); + ndig = strlen (testval); + if (printtab) { + sprintf (rform, "%%%dd:\t", ndig); + } + else{ + sprintf (rform, "%%%dd: ", ndig); + } + + /* Format for column pixel labels */ + sprintf (testval, pform, 1.12345678); + ndig = strlen (testval); + y = yi[ny-1]; + sprintf (testval, "%d", y); + ndig = ndig + strlen (testval); + if (printtab) { + sprintf (cform, "%%%dd\t", ndig); + } + else{ + sprintf (cform, "%%%dd ", ndig); + } + + /* Label column pixels */ + printf ("Coord"); + for (iy = 0; iy < ny; iy++) { + y = yi[iy]; + printf (cform, y); + } + printf ("\n"); + } + + /* Loop through rows */ + for (ix = 0; ix < nx; ix++) { + x1 = xi[ix]; + x = x1 - 1; + if (pixlabel) { + printf (rform, x1); + } + + /* Loop through columns */ + for (iy = 0; iy < ny; iy++) { + y1 = yi[iy]; + y = y1 - 1; + dpix = getpix (image,bitpix,xdim,ydim,bzero,bscale,x,y); + if (gtcheck || ltcheck) { + if ((gtcheck && dpix > gtval) || + (ltcheck && dpix < ltval)) { + procpix (&dsum, &dnpix, &dmin, &dmax, dpix); + if (nopunct) { + printf ("%d %d %f\n", x1, y1, dpix); + } + else { + printf ("[%d,%d] = %f\n", x1, y1, dpix); + } + } + continue; + } + else { + procpix (&dsum, &dnpix, &dmin, &dmax, dpix); + } + if (printrange || printmean) { + continue; + } + if (intout) { + if (dpix > 0) + ipix = (int) (dpix + 0.5); + else if (dpix < 0) + ipix = (int) (dpix - 0.5); + else + ipix = 0; + } + if (pixperline) { + printf ("%s[%d,%d] = ", name, x1, y1); + if (intout) + printf (pform, ipix); + else + printf (pform, dpix); + printf ("\n"); + } + else { + if (intout) + printf (pform, ipix); + else + printf (pform, dpix); + if ((iy+1) % nline == 0) + printf ("\n"); + else if (printtab) + printf ("\t"); + else + printf (" "); + } + } + if (!pixperline && !ltcheck && !gtcheck) { + if (!printrange && !printmean && iy % nline != 0) + printf ("\n"); + } + } + free (rrange); + free (crange); } /* Print a region of a two-dimensional image */ else { - xrange = RangeInit (crange, xdim); - nx = rgetn (xrange); + + /* Make list of x coordinates */ + crange = RangeInit (xrange, xdim); + nx = rgetn (crange); + xi = (int *) calloc (nx, sizeof (int)); + for (i = 0; i < nx; i++) { + xi[i] = rgeti4 (crange); + } /* Make list of y coordinates */ - yrange = RangeInit (rrange, ydim); - ny = rgetn (yrange); + rrange = RangeInit (yrange, ydim); + ny = rgetn (rrange); yi = (int *) calloc (ny, sizeof (int)); for (i = 0; i < ny; i++) { - yi[i] = rgeti4 (yrange) - 1; + yi[i] = rgeti4 (rrange); } - /* Label horizontal pixels */ + /* Set pixel label formats */ if (pixlabel) { - printf ("Coord"); - rstart (xrange); - strcpy (nform, pform); - if ((c = strchr (nform,'.')) != NULL) { - *c = 'd'; - c[1] = (char) 0; + + /* Format for row pixel labels */ + x = xi[nx-1]; + sprintf (testval, "%d", x); + ndig = strlen (testval); + sprintf (rform, "%%%dd:", ndig); + if (printtab) { + sprintf (rform, "%%%dd:\t", ndig); + } + else{ + sprintf (rform, "%%%dd: ", ndig); + } + + /* Format for column pixel labels */ + sprintf (testval, pform, 1.12345678); + ndig = strlen (testval); + y = yi[ny-1]; + sprintf (testval, "%d", y); + ndig = ndig + strlen (testval); + if (printtab) { + sprintf (cform, "%%%dd\t", ndig); } - else if ((c = strchr (nform,'f')) != NULL) { - *c = 'd'; + else{ + sprintf (cform, "%%%dd ", ndig); } + + /* Label column pixels */ + printf ("Coord"); for (ix = 0; ix < nx; ix++) { - x = rgeti4 (xrange); - if (printtab) - printf ("\t"); - else - printf (" "); - printf (nform, x); + x = xi[ix]; + printf (cform, x); } printf ("\n"); } - if (verbose) + + if (pixperline) iy = -1; else iy = ny; /* Loop through rows starting with the last one */ for (i = 0; i < ny; i++) { - if (verbose) + if (pixperline) iy++; else iy--; - rstart (xrange); + y1 = yi[iy]; + y = y1 - 1; if (pixlabel) { - printf ("%4d:",yi[iy]+1); - if (printtab) - printf ("\t"); - else - printf (" "); + printf (rform, y1); } /* Loop through columns */ for (ix = 0; ix < nx; ix++) { - x = rgeti4 (xrange) - 1; - dpix = getpix (image,bitpix,xdim,ydim,bzero,bscale,x,yi[iy]); + x1 = xi[ix]; + x = x1 - 1; + dpix = getpix (image,bitpix,xdim,ydim,bzero,bscale,x,y); if (gtcheck || ltcheck) { if ((gtcheck && dpix > gtval) || (ltcheck && dpix < ltval)) { procpix (&dsum, &dnpix, &dmin, &dmax, dpix); if (nopunct) - printf ("%d %d %f\n", x+1, yi[iy]+1, dpix); + printf ("%d %d %f\n", x1, y1, dpix); else - printf ("[%d,%d] = %f\n", x+1, yi[iy]+1, dpix); + printf ("[%d,%d] = %f\n", x1, y1, dpix); } continue; } - else + else { procpix (&dsum, &dnpix, &dmin, &dmax, dpix); + } if (printrange || printmean) continue; - if (bitpix > 0) { - if ((c = strchr (pform,'f')) != NULL) - *c = 'd'; + if (intout) { if (dpix > 0) ipix = (int) (dpix + 0.5); else if (dpix < 0) @@ -896,20 +1130,16 @@ else ipix = 0; } - else { - if ((c = strchr (pform,'d')) != NULL) - *c = 'f'; - } if (pixperline) { - printf ("%s[%d,%d] = ",name,x+1,yi[i]+1); - if (bitpix > 0) + printf ("%s[%d,%d] = ", name, x1, y1); + if (intout) printf (pform, ipix); else printf (pform, dpix); printf ("\n"); } else { - if (bitpix > 0) + if (intout) printf (pform, ipix); else printf (pform, dpix); @@ -926,8 +1156,8 @@ printf ("\n"); } } - free (xrange); - free (yrange); + free (rrange); + free (crange); } if (printmean) { @@ -1038,4 +1268,10 @@ * Jan 10 2014 Add command line option @listfile as list of files * * Jun 9 2016 Fix isnum() tests for added coloned times and dashed dates + * + * May 12 2020 Reverse column and row assignment in range interpretation (Steve Willner) + * May 12 2020 Change range of values to -e and add -d for decimal places + * May 12 2020 Add -y to print columns as rows + * May 14 2020 Clean up distinctions between image x and y and output columns and rows + * May 14 2020 Add -o [format] to allow any legal C format for pixel display */ Binary files /tmp/tmpAU7Qas/lxsO8C14BK/wcstools-3.9.5/getpix.o and /tmp/tmpAU7Qas/kkdBNQZs62/wcstools-3.9.6/getpix.o differ diff -Nru wcstools-3.9.5/getpixx.c wcstools-3.9.6/getpixx.c --- wcstools-3.9.5/getpixx.c 1970-01-01 00:00:00.000000000 +0000 +++ wcstools-3.9.6/getpixx.c 2020-05-14 18:03:54.000000000 +0000 @@ -0,0 +1,1041 @@ +/* File getpix.c + * June 9, 2016 + * By Jessica Mink, Harvard-Smithsonian Center for Astrophysics) + * Send bug reports to jmink@cfa.harvard.edu + + Copyright (C) 1996-2016 + Smithsonian Astrophysical Observatory, Cambridge, MA USA + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include "libwcs/wcs.h" +#include "libwcs/fitsfile.h" +#include "libwcs/wcscat.h" + +#define MAXFILES 2000 +static int maxnfile = MAXFILES; +#define MAXNPIX 100; +static int maxnpix = MAXNPIX; + +static void usage(); +static void PrintPix(); +static void procpix(); + +static char *RevMsg = "GETPIX WCSTools 3.9.5a, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; + +static int verbose = 0; /* verbose/debugging flag */ +static int version = 0; /* If 1, print only program name and version */ +static int nline = 10; /* Number of pixels printer per line */ +static char *pform = NULL; /* Format in which to print pixels */ +static int pixlabel = 0; /* If 1, label pixels in output */ +static int gtcheck = 0; /* If 1, list pixels greater than gtval */ +static int ltcheck = 0; /* If 1, list pixels less than ltval */ +static int nopunct=0; /* If 1, print output with no punctuation */ +static int printrange = 0; /* If 1, print range of values, not values */ +static int printmean = 0; /* If 1, print mean of values, not values */ +static int printname = 0; /* If 1, print file name */ +static double gtval = 0.0; +static double ltval = 0.0; +static double ra0 = -99.0; /* Initial center RA in degrees */ +static double dec0 = -99.0; /* Initial center Dec in degrees */ +static double rad0 = 0.0; /* Search box radius */ +static double dra0 = 0.0; /* Search box width */ +static double ddec0 = 0.0; /* Search box height */ +static double eqcoor = 2000.0; /* Equinox of search center */ +static int syscoor = 0; /* Input search coordinate system */ +static int identifier = 0; /* If 1, identifier precedes x y in file */ +static int printtab = 0; /* If 1, separate number with tabs */ +static int procinit = 1; /* If 1, start mean and limits */ + +int +main (ac, av) + +int ac; +char **av; +{ + char *str, *str1; + char listfile[256]; + char **fn; + char filename[256]; + int ifile, nbytes; + FILE *flist; + char *rrange; /* Row range string */ + char *crange; /* Column range string */ + char *rstr; + char *dstr = NULL; + char *cstr; + int systemp; + int i; + int npix = 0; + int nfile; + char linebuff[1024]; + char listname[256]; + char *line; + char xstr[16], ystr[16], temp[64]; + int ix, iy; + int *xpix, *ypix; + int iline, nlines; + FILE *fd; + int *xp1, *yp1; + double x, y; + + nfile = 0; + fn = (char **)calloc (maxnfile, sizeof(char *)); + xpix = (int *)calloc (maxnpix, sizeof (int)); + ypix = (int *)calloc (maxnpix, sizeof (int)); + + /* Check for help or version command first */ + str = *(av+1); + if (!str || !strcmp (str, "help") || !strcmp (str, "-help")) + usage(); + if (!strcmp (str, "version") || !strcmp (str, "-version")) { + version = 1; + usage(); + } + + crange = NULL; + rrange = NULL; + + /* crack arguments */ + for (av++; --ac > 0; av++) { + str = *av; + if (ac > 0) + str1 = *(av+1); + else + str1 = NULL; + + /* Output format */ + if (str[0] == '%') { + pform = *av; + } + + /* Other command */ + else if (str[0] == '-') { + char c; + while ((c = *++str)) + switch (c) { + + case 'v': /* more verbosity */ + verbose++; + break; + + case 'd': /* Print range of values */ + printrange=1; + break; + + case 'g': /* Keep pixels greater than this */ + if (ac < 2) + usage(); + gtval = atof (*++av); + gtcheck++; + ac--; + break; + + case 'h': /* Print file name above pixel values */ + printname++; + break; + + case 'i': /* Identifier precedes x y in file */ + identifier++; + break; + + case 'l': /* Keep pixels less than this */ + if (ac < 2) + usage(); + ltval = atof (*++av); + ltcheck++; + ac--; + break; + + case 'm': /* Print mean, sigma of values */ + printmean = 1; + break; + + case 'n': /* Number of pixels per line */ + if (ac < 2) + usage(); + nline = atoi (*++av); + ac--; + break; + + case 'p': /* label pixels */ + pixlabel++; + break; + + case 'r': /* Box radius in arcseconds */ + if (ac < 2) + usage (); + av++; + if ((dstr = strchr (*av, ',')) != NULL) { + *dstr = (char) 0; + dstr++; + } + if (strchr (*av,':')) + rad0 = 3600.0 * str2dec (*av); + else + rad0 = atof (*av); + if (dstr != NULL) { + dra0 = rad0; + rad0 = 0.0; + if (strchr (dstr, ':')) + ddec0 = 3600.0 * str2dec (dstr); + else + ddec0 = atof (dstr); + if (ddec0 <= 0.0) + ddec0 = dra0; + /* rad0 = sqrt (dra0*dra0 + ddec0*ddec0); */ + } + ac--; + break; + + case 's': /* Print x y value without punctuation */ + nopunct++; + break; + + case 't': /* Separate pixels with tabs */ + printtab++; + break; + + default: + usage(); + break; + } + } + + /* Set search RA, Dec, and equinox if colon in argument */ + else if (isnum (str) == 3 && isnum (str1) == 3) { + if (ac < 2) + usage (); + else { + strcpy (rstr, str); + ac--; + av++; + strcpy (dstr, str1); + ra0 = str2ra (rstr); + dec0 = str2dec (dstr); + ac--; + if (ac < 1) { + syscoor = WCS_J2000; + eqcoor = 2000.0; + } + else if ((syscoor = wcscsys (*(av+1))) >= 0) + eqcoor = wcsceq (*++av); + else { + syscoor = WCS_J2000; + eqcoor = 2000.0; + } + } + } + + /* Search coordinates in degrees if coordinate system specified */ + else if (isnum (str) == 2 && isnum (str) == 2) { + rstr = str; + dstr = str1; + ac--; + av++; + av++; + if (ac > 0 && (systemp = wcscsys (*av)) > 0) { + ra0 = atof (rstr); + dec0 = atof (dstr); + cstr = *av++; + syscoor = systemp; + eqcoor = wcsceq (cstr); + } + + /* Fractional coordinate pair if no coordinate system */ + else { + if (npix+1 > maxnpix) { + maxnpix = 2 * maxnpix; + xp1 = calloc (maxnpix, sizeof (int)); + yp1 = calloc (maxnpix, sizeof (int)); + for (i = 0; i < maxnpix; i++) { + xp1[i] = xpix[i]; + yp1[i] = ypix[i]; + } + free (xpix); + free (ypix); + xpix = xp1; + ypix = yp1; + } + x = atof (rstr); + if (x > 0.0) + ix = (int) (x + 0.5); + else if (x < 0.0) + ix = (int) (x - 0.5); + else + ix = 0; + y = atof (dstr); + if (y > 0.0) + iy = (int) (y + 0.5); + else if (y < 0.0) + iy = (int) (y - 0.5); + else + iy = 0; + xpix[npix] = ix; + ypix[npix] = iy; + npix++; + } + } + + /* Coordinate pairs for pixels to print */ + else if (isnum (str) == 1 && isnum (str1) == 1) { + if (npix+1 > maxnpix) { + maxnpix = 2 * maxnpix; + xp1 = calloc (maxnpix, sizeof (int)); + yp1 = calloc (maxnpix, sizeof (int)); + for (i = 0; i < maxnpix; i++) { + xp1[i] = xpix[i]; + yp1[i] = ypix[i]; + } + free (xpix); + free (ypix); + xpix = xp1; + ypix = yp1; + } + ix = atoi (str); + iy = atoi (str1); + if (ix == 0 || iy == 0) { + crange = str1; + rrange = str; + } + else { + xpix[npix] = ix; + ypix[npix] = iy; + npix++; + } + av++; + ac--; + } + + /* Range of pixels to print (only one allowed) */ + else if (isrange (str) && isrange (str1)) { + crange = str; + rrange = str1; + ac--; + av++; + } + + /* File containing a list of files or image coordinates */ + else if (str[0] == '@') { + strcpy (listname, str+1); + if (isimlist (listname)) { + strcpy (listfile, listname); + listname[0] = (char) 0; + } + else { + nlines = getfilelines (listname); + fd = fopen (listname, "r"); + if (fd == NULL) { + fprintf (stderr, "GETPIX: Cannot read file %s\n", listname); + nlines = 0; + } + for (iline = 0; iline < nlines; iline++) { + if (!fgets (linebuff, 1023, fd)) + break; + line = linebuff; + if (line[0] == '#') + continue; + if (identifier) + sscanf (line,"%s %s %s", temp, xstr, ystr); + else + sscanf (line,"%s %s", xstr, ystr); + if (npix+1 > maxnpix) { + maxnpix = 2 * maxnpix; + xp1 = calloc (maxnpix, sizeof (int)); + yp1 = calloc (maxnpix, sizeof (int)); + for (i = 0; i < maxnpix; i++) { + xp1[i] = xpix[i]; + yp1[i] = ypix[i]; + } + free (xpix); + free (ypix); + xpix = xp1; + ypix = yp1; + } + xpix[npix] = atoi (xstr); + ypix[npix] = atoi (ystr); + npix++; + } + } + ac--; + } + + /* Image file name */ + else if (isfits (str) || isiraf (str)) { + if (nfile >= maxnfile) { + maxnfile = maxnfile * 2; + nbytes = maxnfile * sizeof (char *); + fn = (char **) realloc ((void *)fn, nbytes); + } + fn[nfile] = str; + nfile++; + } + } + + if ((crange && rrange) || npix > 0) { + + /* Process files already read from the command line */ + if (fn) { + for (ifile = 0; ifile < nfile; ifile++) { + PrintPix (fn[ifile], crange, rrange, npix, xpix, ypix); + } + } + + /* Process files from listfile one at a time */ + else if (isimlist (listfile)) { + nfile = getfilelines (listfile); + if ((flist = fopen (listfile, "r")) == NULL) { + fprintf (stderr,"GETPIX: Image list file %s cannot be read\n", + listfile); + usage (); + } + for (ifile = 0; ifile < nfile; ifile++) { + first_token (flist, 254, filename); + PrintPix (filename, crange, rrange, npix, xpix, ypix); + } + fclose (flist); + } + } + + free (xpix); + free (ypix); + free (fn); + return (0); +} + +static void +usage () +{ + fprintf (stderr,"%s\n",RevMsg); + if (version) + exit (-1); + fprintf (stderr,"Print FITS or IRAF pixel values\n"); + fprintf(stderr,"Usage: getpix [-vp][-n num][-g val][-l val][format] file.fit x_range y_range\n"); + fprintf(stderr," or getpix [-vp][-n num][-g val][-l val][format] file.fit x1 y1 x2 y2 ... xn yn\n"); + fprintf(stderr," or getpix [-vp][-n num][-g val][-l val][format] file.fit @file\n"); + fprintf(stderr," format: C-style (%%f, %%d, ...) format for pixel values\n"); + fprintf(stderr," file: File with x y coordinates as first two tokens on lines\n"); + fprintf(stderr," -d: Print range of pixel values in specified image region\n"); + fprintf(stderr," -f name: Write specified region to a FITS file\n"); + fprintf(stderr," -g num: keep pixels with values greater than this\n"); + fprintf(stderr," -h: print file name on line above pixel values\n"); + fprintf(stderr," -i: Ignore first token per line of coordinate file\n"); + fprintf(stderr," -l num: keep pixels with values less than this\n"); + fprintf(stderr," -m: Print mean of pixel values in specified image region\n"); + fprintf(stderr," -n num: number of pixel values printed per line\n"); + fprintf(stderr," -p: label pixels\n"); + fprintf(stderr," -r num: radius (<0=box) to extract in degrees/arcsec\n"); + fprintf(stderr," -s: print x y value with no punctuation\n"); + fprintf(stderr," -v: verbose\n"); + fprintf(stderr," %%: C format for each pixel value\n"); + exit (1); +} + + +static void +PrintPix (name, crange, rrange, npix, xpix, ypix) + +char *name; +char *crange; /* Column range string */ +char *rrange; /* Row range string */ +int npix; /* Number of coordinate pairs */ +int *xpix, *ypix; /* Vectors of x,y coordinate pairs */ + +{ + char *header; /* FITS image header */ + int lhead; /* Maximum number of bytes in FITS header */ + int nbhead; /* Actual number of bytes in FITS header */ + char *irafheader; /* IRAF image header */ + char *image; /* FITS or IRAF image */ + double bzero; /* Zero point for pixel scaling */ + double bscale; /* Scale factor for pixel scaling */ + int iraffile; + double dpix, dsum, dmean, dmin, dmax, dnpix; + char *c; + int *yi; + int bitpix,xdim,ydim, i, nx, ny, ix, iy, x, y, pixperline; + int ipix = 0; + char pixname[255]; + char nform[8]; + struct Range *xrange; /* X range structure */ + struct Range *yrange; /* Y range structure */ + + /* Open IRAF image if .imh extension is present */ + if (isiraf (name)) { + iraffile = 1; + if ((irafheader = irafrhead (name, &lhead)) != NULL) { + header = iraf2fits (name, irafheader, lhead, &nbhead); + free (irafheader); + if (header == NULL) { + fprintf (stderr, "Cannot translate IRAF header %s/n",name); + return; + } + if ((image = irafrimage (header)) == NULL) { + hgetm (header,"PIXFIL", 255, pixname); + fprintf (stderr, "Cannot read IRAF pixel file %s\n", pixname); + free (irafheader); + free (header); + return; + } + } + else { + fprintf (stderr, "Cannot read IRAF file %s\n", name); + return; + } + } + + /* Open FITS file if .imh extension is not present */ + else { + iraffile = 0; + if ((header = fitsrhead (name, &lhead, &nbhead)) != NULL) { + if ((image = fitsrimage (name, nbhead, header)) == NULL) { + fprintf (stderr, "Cannot read FITS image %s\n", name); + free (header); + return; + } + } + else { + fprintf (stderr, "Cannot read FITS file %s\n", name); + return; + } + } + if (printname) { + if (ltcheck & gtcheck) + fprintf (stderr, "%s: %f < pixel values < %f\n", name, gtval, ltval); + else if (ltcheck) + fprintf (stderr, "%s: pixel values < %f\n", name, ltval); + else if (gtcheck) + fprintf (stderr, "%s: pixel values > %f\n", name, gtval); + else + fprintf (stderr,"%s:\n", name); + } + if (verbose) { + fprintf (stderr,"%s\n",RevMsg); + if (npix > 0) + fprintf (stderr,"Print pixels in "); + else if (!strcmp (crange, "0")) + fprintf (stderr,"Print rows %s in ", rrange); + else if (!strcmp (rrange, "0")) + fprintf (stderr,"Print columns %s in ", crange); + else + fprintf (stderr,"Print rows %s, columns %s in ", rrange, crange); + if (iraffile) + fprintf (stderr,"IRAF image file %s\n", name); + else + fprintf (stderr,"FITS image file %s\n", name); + if (ltcheck & gtcheck) + fprintf (stderr, "%f < pixel values < %f\n", gtval, ltval); + else if (ltcheck) + fprintf (stderr, "pixel values < %f\n", ltval); + else if (gtcheck) + fprintf (stderr, "pixel values > %f\n", gtval); + } + if (verbose && !pixlabel) + pixperline = 1; + else + pixperline = 0; + +/* Get value of specified pixel */ + + /* Get size of image and scaling factors */ + hgeti4 (header,"BITPIX",&bitpix); + xdim = 1; + hgeti4 (header,"NAXIS1",&xdim); + ydim = 1; + hgeti4 (header,"NAXIS2",&ydim); + bzero = 0.0; + hgetr8 (header,"BZERO",&bzero); + bscale = 1.0; + hgetr8 (header,"BSCALE",&bscale); + + /* Set initial values */ + dsum = 0.0; + dnpix = 0.0; + dmin = 0.0; + dmax = 0.0; + procinit = 1; + + /* Set format if not already set */ + if (pform == NULL) { + pform = (char *) calloc (8,1); + if (bitpix > 0) + strcpy (pform, "%d"); + else + strcpy (pform, "%.2f"); + } + +/* Print values at specified coordinates in an image */ + if (npix > 0) { + + /* Loop through rows starting with the last one */ + for (i = 0; i < npix; i++) { + dpix = getpix1(image,bitpix,xdim,ydim,bzero,bscale,xpix[i],ypix[i]); + if (gtcheck || ltcheck) { + if ((gtcheck && dpix > gtval) || + (ltcheck && dpix < ltval)) { + procpix (&dsum, &dnpix, &dmin, &dmax, dpix); + if (nopunct) + printf ("%d %d %f\n", xpix[i], ypix[i], dpix); + else + printf ("[%d,%d] = %f\n", xpix[i], ypix[i], dpix); + } + continue; + } + else + procpix (&dsum, &dnpix, &dmin, &dmax, dpix); + if (printrange || printmean) + continue; + if (bitpix > 0) { + if ((c = strchr (pform,'f')) != NULL) + *c = 'd'; + if (dpix > 0) + ipix = (int) (dpix + 0.5); + else if (dpix < 0) + ipix = (int) (dpix - 0.5); + else + ipix = 0; + } + else { + if ((c = strchr (pform,'d')) != NULL) + *c = 'f'; + } + if (pixperline) { + printf ("%s[%d,%d] = ",name,xpix[i],ypix[i]); + if (bitpix > 0) + printf (pform, ipix); + else + printf (pform, dpix); + printf ("\n"); + } + else { + if (bitpix > 0) + printf (pform, ipix); + else + printf (pform, dpix); + if ((i+1) % nline == 0) + printf ("\n"); + else if (printtab) + printf ("\t"); + else + printf (" "); + } + } + if (!pixperline && !ltcheck && !gtcheck) + printf ("\n"); + } + +/* Print entire image */ + else if (!strcmp (rrange, "0") && !strcmp (crange, "0")) { + if (printmean || printrange) { + nx = xdim; + ny = ydim; + for (y = 0; y < ny; y++) { + for (x = 0; x < nx; x++) { + dpix = getpix (image,bitpix,xdim,ydim,bzero,bscale,x,y); + if (!gtcheck && !ltcheck) + procpix (&dsum, &dnpix, &dmin, &dmax, dpix); + else if (gtcheck && ltcheck) { + if (dpix > gtval && dpix < ltval) + procpix (&dsum, &dnpix, &dmin, &dmax, dpix); + } + else if ((gtcheck && dpix > gtval) || + (ltcheck && dpix < ltval)) + procpix (&dsum, &dnpix, &dmin, &dmax, dpix); + } + } + } + else if (gtcheck || ltcheck) { + nx = xdim; + ny = ydim; + for (y = 0; y < ny; y++) { + for (x = 0; x < nx; x++) { + dpix = getpix (image,bitpix,xdim,ydim,bzero,bscale,x,y); + if (gtcheck && ltcheck) { + if (dpix > gtval && dpix < ltval) { + if (nopunct) + printf ("%d %d %f\n", x+1, y+1, dpix); + else + printf ("[%d,%d] = %f\n", x+1, y+1, dpix); + } + } + else if ((gtcheck && dpix > gtval) || + (ltcheck && dpix < ltval)) { + if (nopunct) + printf ("%d %d %f\n", x+1, y+1, dpix); + else + printf ("[%d,%d] = %f\n", x+1, y+1, dpix); + } + } + } + } + else + printf ("GETPIX will not print this %d x %d image; use ranges\n", + xdim, ydim); + } + +/* Print entire columns */ + else if (!strcmp (rrange, "0")) { + xrange = RangeInit (crange, xdim); + nx = rgetn (xrange); + ny = ydim; + for (ix = 0; ix < nx; ix++) { + rstart (xrange); + x = rgeti4 (xrange) - 1; + for (y = 0; y < ny; y++) { + dpix = getpix (image,bitpix,xdim,ydim,bzero,bscale,x,y); + if (gtcheck || ltcheck) { + if ((gtcheck && dpix > gtval) || + (ltcheck && dpix < ltval)) { + procpix (&dsum, &dnpix, &dmin, &dmax, dpix); + if (nopunct) + printf ("%d %d %f\n", x+1, y+1, dpix); + else + printf ("[%d,%d] = %f\n", x+1, y+1, dpix); + } + continue; + } + else + procpix (&dsum, &dnpix, &dmin, &dmax, dpix); + if (bitpix > 0) { + if (dpix > 0) + ipix = (int) (dpix + 0.5); + else if (dpix < 0) + ipix = (int) (dpix - 0.5); + else + ipix = 0; + } + if (pixperline) { + printf ("%s[%d,%d] = ",name,x,y); + if (bitpix > 0) + printf (pform, ipix); + else + printf (pform, dpix); + printf ("\n"); + } + else { + if (bitpix > 0) + printf (pform, ipix); + else + printf (pform, dpix); + if ((y+1) % nline == 0) + printf ("\n"); + else if (printtab) + printf ("\t"); + else + printf (" "); + } + } + if (y % nline != 0 && !gtcheck && !ltcheck) + printf ("\n"); + if (nx > 1 && !gtcheck && !ltcheck) + printf ("\n"); + } + free (xrange); + } + +/* Print entire rows */ + else if (!strcmp (crange, "0")) { + yrange = RangeInit (rrange, xdim); + ny = rgetn (yrange); + nx = xdim; + for (iy = 0; iy < ny; iy++) { + y = rgeti4 (yrange) - 1; + for (x = 0; x < nx; x++) { + dpix = getpix (image,bitpix,xdim,ydim,bzero,bscale,x,y); + if (gtcheck || ltcheck) { + if ((gtcheck && dpix > gtval) || + (ltcheck && dpix < ltval)) { + procpix (&dsum, &dnpix, &dmin, &dmax, dpix); + if (nopunct) + printf ("%d %d %f\n", x+1, y+1, dpix); + else + printf ("[%d,%d] = %f\n", x+1, y+1, dpix); + } + continue; + } + else + procpix (&dsum, &dnpix, &dmin, &dmax, dpix); + if (bitpix > 0) { + if (dpix > 0) + ipix = (int) (dpix + 0.5); + else if (dpix < 0) + ipix = (int) (dpix - 0.5); + else + ipix = 0; + } + if (pixperline) { + printf ("%s[%d,%d] = ",name,x,y); + if (bitpix > 0) + printf (pform, ipix); + else + printf (pform, dpix); + printf ("\n"); + } + else { + if (bitpix > 0) + printf (pform, ipix); + else + printf (pform, dpix); + if ((x+1) % nline == 0) + printf ("\n"); + else if (printtab) + printf ("\t"); + else + printf (" "); + } + } + if (x % nline != 0 && !gtcheck && !ltcheck) + printf ("\n"); + if (ny > 1 && !gtcheck && !ltcheck) + printf ("\n"); + } + free (yrange); + } + +/* Print a region of a two-dimensional image */ + else { + xrange = RangeInit (crange, xdim); + nx = rgetn (xrange); + + /* Make list of y coordinates */ + yrange = RangeInit (rrange, ydim); + ny = rgetn (yrange); + yi = (int *) calloc (ny, sizeof (int)); + for (i = 0; i < ny; i++) { + yi[i] = rgeti4 (yrange) - 1; + } + + /* Label horizontal pixels */ + if (pixlabel) { + printf ("Coord"); + rstart (xrange); + strcpy (nform, pform); + if ((c = strchr (nform,'.')) != NULL) { + *c = 'd'; + c[1] = (char) 0; + } + else if ((c = strchr (nform,'f')) != NULL) { + *c = 'd'; + } + for (ix = 0; ix < nx; ix++) { + x = rgeti4 (xrange); + if (printtab) + printf ("\t"); + else + printf (" "); + printf (nform, x); + } + printf ("\n"); + } + if (verbose) + iy = -1; + else + iy = ny; + + /* Loop through rows starting with the last one */ + for (i = 0; i < ny; i++) { + if (verbose) + iy++; + else + iy--; + rstart (xrange); + if (pixlabel) { + printf ("%4d:",yi[iy]+1); + if (printtab) + printf ("\t"); + else + printf (" "); + } + + /* Loop through columns */ + for (ix = 0; ix < nx; ix++) { + x = rgeti4 (xrange) - 1; + dpix = getpix (image,bitpix,xdim,ydim,bzero,bscale,x,yi[iy]); + if (gtcheck || ltcheck) { + if ((gtcheck && dpix > gtval) || + (ltcheck && dpix < ltval)) { + procpix (&dsum, &dnpix, &dmin, &dmax, dpix); + if (nopunct) + printf ("%d %d %f\n", x+1, yi[iy]+1, dpix); + else + printf ("[%d,%d] = %f\n", x+1, yi[iy]+1, dpix); + } + continue; + } + else + procpix (&dsum, &dnpix, &dmin, &dmax, dpix); + if (printrange || printmean) + continue; + if (bitpix > 0) { + if ((c = strchr (pform,'f')) != NULL) + *c = 'd'; + if (dpix > 0) + ipix = (int) (dpix + 0.5); + else if (dpix < 0) + ipix = (int) (dpix - 0.5); + else + ipix = 0; + } + else { + if ((c = strchr (pform,'d')) != NULL) + *c = 'f'; + } + if (pixperline) { + printf ("%s[%d,%d] = ",name,x+1,yi[i]+1); + if (bitpix > 0) + printf (pform, ipix); + else + printf (pform, dpix); + printf ("\n"); + } + else { + if (bitpix > 0) + printf (pform, ipix); + else + printf (pform, dpix); + if ((ix+1) % nline == 0) + printf ("\n"); + else if (printtab) + printf ("\t"); + else + printf (" "); + } + } + if (!pixperline && !ltcheck && !gtcheck) { + if (!printrange && !printmean && ix % nline != 0) + printf ("\n"); + } + } + free (xrange); + free (yrange); + } + + if (printmean) { + dmean = dsum / dnpix; + if (verbose) + printf ("Mean= %.4f ", dmean); + else + printf ("%.4f", dmean); + } + if (printrange) { + if (printmean) + printf (" "); + if (verbose) + printf ("Range = %.4f - %.4f ", dmin, dmax); + else + printf ("%.4f %.4f", dmin, dmax); + } + if (printmean || printrange) { + if (verbose) + printf ("for %d pixels\n", (int) dnpix); + else + printf ("\n"); + } + + free (header); + free (image); + return; +} + + +static void +procpix (dsum, dnpix, dmin, dmax, dpix) + +double *dsum; /* Sum of pixel values */ +double *dnpix; /* Number of pixels so far */ +double *dmin; /* Minimum pixel value */ +double *dmax; /* Maximum pixel value */ +double dpix; /* Current pixel value */ +{ + if (procinit) { + *dsum = dpix; + *dnpix = 1.0; + *dmin = dpix; + *dmax = dpix; + } + else { + *dsum = *dsum + dpix; + *dnpix = *dnpix + 1.0; + if (dpix < *dmin) + *dmin = dpix; + else if (dpix > *dmax) + *dmax = dpix; + } + procinit = 0; +} +/* Dec 6 1996 New program + * + * Feb 21 1997 Check pointers against NULL explicitly for Linux + * Dec 15 1997 Add capability of reading and writing IRAF 2.11 images + * + * May 27 1998 Include fitsio.h instead of fitshead.h + * Jul 24 1998 Make irafheader char instead of int + * Aug 6 1998 Change fitsio.h to fitsfile.h + * Oct 14 1998 Use isiraf() to determine file type + * Nov 30 1998 Add version and help commands for consistency + * + * Feb 12 1999 Initialize dxisn to 1 so it works for 1-D images + * Apr 29 1999 Add BZERO and BSCALE + * Jun 29 1999 Fix typo in BSCALE setting + * Jul 2 1999 Use ranges instead of individual pixels + * Oct 15 1999 Fix format statement + * Oct 22 1999 Drop unused variables after lint + * Dec 9 1999 Add -g -l limits + * Dec 13 1999 Fix bug so that -g and -l limits can be ANDed + * + * Mar 23 2000 Use hgetm() to get the IRAF pixel file name, not hgets() + * + * Jan 30 2001 Fix format specification in help message + * + * Jun 3 2002 Add -s option to print x y value with no punctuation + * Oct 30 2002 Add code to count lines when printing a region + * + * Feb 20 2003 Add option to enter multiple pixel (x,y) as well as ranges + * Mar 26 2003 Fix pixel counter bug in individual pixel printing + * Sep 17 2003 Fix bug which broke use of 0 as substitute for 1-naxisn range + * + * Apr 26 2004 Fix handling of 0 0 for entire image + * Aug 30 2004 Fix declarations + * Sep 21 2004 Fix bug which used x instead of ix for number of elements printed + * + * Jul 29 2005 Add mean and range computation + * + * Jun 21 2006 Clean up code + * + * Jan 10 2007 Declare RevMsg static, not const + * Dec 20 2007 Add option to read x y coordinates from a file + * Dec 21 2007 Fix bug reallocating coordinate list when current size exceeded + * + * Aug 14 2009 If coordinates are floating point round to appropriate pixel + * + * Sep 21 2010 Add option -t to separate numbers by tabs + * Sep 21 2010 Fix bug in computing means and limits + * + * Feb 22 2012 Print descriptors for mean and limits only in verbose mode + * Feb 22 2012 Fix bug to avoid printing all pixels if printing mean and/or limits + * + * Jan 10 2014 Get same pixels from multiple files + * Jan 10 2014 Add command line option @listfile as list of files + * + * Jun 9 2016 Fix isnum() tests for added coloned times and dashed dates + */ diff -Nru wcstools-3.9.5/gettab.c wcstools-3.9.6/gettab.c --- wcstools-3.9.5/gettab.c 2017-03-30 15:21:51.000000000 +0000 +++ wcstools-3.9.6/gettab.c 2020-05-14 18:03:54.000000000 +0000 @@ -40,7 +40,7 @@ static void PrintValues(); static int maxncond = 100; -static char *RevMsg = "GETTAB WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "GETTAB WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static int verbose = 0; /* verbose/debugging flag */ static int nfile = 0; diff -Nru wcstools-3.9.5/gsc2cat.c wcstools-3.9.6/gsc2cat.c --- wcstools-3.9.5/gsc2cat.c 2017-03-30 15:21:51.000000000 +0000 +++ wcstools-3.9.6/gsc2cat.c 2020-05-14 18:03:54.000000000 +0000 @@ -37,7 +37,7 @@ static void usage(); void SaveGSC2(); -static char *RevMsg = "GSC2CAT WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "GSC2CAT WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; main (ac, av) int ac; diff -Nru wcstools-3.9.5/htmlsp.c wcstools-3.9.6/htmlsp.c --- wcstools-3.9.5/htmlsp.c 1970-01-01 00:00:00.000000000 +0000 +++ wcstools-3.9.6/htmlsp.c 2020-05-14 18:03:54.000000000 +0000 @@ -0,0 +1,218 @@ +/* File crlf.c + * June 20, 2006 + * By Jessica Mink, Harvard-Smithsonian Center for Astrophysics + * Send bug reports to jmink@cfa.harvard.edu + + Copyright (C) 2006 + Smithsonian Astrophysical Observatory, Cambridge, MA USA + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include +#include +#include +#include +#include + +static int verbose = 0; /* verbose/debugging flag */ +static void usage(); +static void HTMLFix(); +int StripHTMLTags(); +static char *RevMsg = "HTMLSP WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; + +int +main (ac, av) +int ac; +char **av; +{ + char *fn; + char *str; + + /* crack arguments */ + for (av++; --ac > 0 && *(str = *av) == '-'; av++) { + char c; + while ((c = *++str)) + switch (c) { + + case 'v': /* more verbosity */ + verbose++; + break; + + default: + usage(); + break; + } + } + + /* There are ac remaining file names starting at av[0] */ + if (ac == 0) + usage (); + + while (ac-- > 0) { + fn = *av++; + if (verbose) + printf ("%s:\n", fn); + HTMLFix (fn); + if (verbose) + printf ("\n"); + } + + return (0); +} + +static void +usage () +{ + fprintf (stderr,"HTMLSP: Remove HTML tags from input file\n"); + fprintf(stderr,"Usage: htmlsp [-v] file1 file2 ... filen\n"); + fprintf(stderr," -v: verbose\n"); + exit (1); +} + +static int flag; /* 0: searching for < or &, + 1: searching for >, + 2: searching for ; after &, + 3: searching for ,, --> */ +static int k=0; +static char tempbuf[1024] = ""; + +static void +HTMLFix (name) + +char *name; + +{ + char buffer[1000]; + int fd; + int nbr, nnbr, i; + + flag = 0; + + fd = open (name, O_RDONLY); + nbr = 1000; + while (nbr > 0) { + nbr = read (fd, buffer, 1000); + if (nbr > 0) { + nnbr = StripHTMLTags (buffer, nbr); + (void) write (1, buffer, nnbr); + } + } + return; +} + + +int +StripHTMLTags (instring, size) + +char *instring; +int size; + +{ +int i=0, j=0; +char searchbuf[1024] = ""; + +while (i < size) { + + if (flag == 0) { + if (instring[i] == '<') { + flag = 1; + tempbuf[0] = '\0'; + k=0; /* track for "); + tempbuf[0] = '\0'; + k = 0; + } + else if ((0 == strcmp(tempbuf,"style"))) { + flag = 3; + strcpy (searchbuf,""); + tempbuf[0] = '\0'; + k = 0; + } + else if ((0 == strcmp(tempbuf,"!--"))) { + flag = 3; + strcpy (searchbuf,"-->"); + tempbuf[0] = '\0'; + k = 0; + } + + if (instring[i] == '>') { + if ((0 == strcmp (tempbuf, "/tr"))) { + fprintf (stderr, "encountered end of table line\n"); + instring[j] = (char) 10; + } + else if ((0 == strcmp (tempbuf, "br"))) { + instring[j] = (char) 10; + } + else if ((0 == strcmp (tempbuf, "p"))) { + instring[j] = (char) 10; + } + else { + instring[j] = ' '; + } + j++; + flag = 0; + } + + } + + else if (flag == 2) { + if(instring[i] == ';') { + instring[j] = ' '; + j++; + flag = 0; + } + } + + else if(flag == 3) { + tempbuf[k] = instring[i]; + k++; + tempbuf[k] = '\0'; + + if (0 == strcmp(&tempbuf[0] + k - strlen(searchbuf),searchbuf)) { + flag = 0; + searchbuf[0] = '\0'; + tempbuf[0] = '\0'; + k = 0; + } + } + + i++; + } + +instring[j] = '\0'; + +return j; +} + +/* Nov 5 2018 New program based on CRLF + */ diff -Nru wcstools-3.9.5/i2f.c wcstools-3.9.6/i2f.c --- wcstools-3.9.5/i2f.c 2017-03-30 15:21:51.000000000 +0000 +++ wcstools-3.9.6/i2f.c 2020-05-14 18:03:54.000000000 +0000 @@ -34,7 +34,7 @@ static void IRAFtoFITS (); static int verbose = 0; /* verbose/debugging flag */ -static char *RevMsg = "I2F WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "I2F WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static int version = 0; /* If 1, print only program name and version */ static int delirafkey = 0; /* If 1, delete IRAF .imh keywords */ static int deliraffile = 0; /* If 1, delete IRAF .imh files */ diff -Nru wcstools-3.9.5/imcat0.c wcstools-3.9.6/imcat0.c --- wcstools-3.9.5/imcat0.c 2017-03-30 15:21:51.000000000 +0000 +++ wcstools-3.9.6/imcat0.c 2020-05-14 18:03:54.000000000 +0000 @@ -64,7 +64,7 @@ extern void setparm(); extern void setnpix(); -static char *RevMsg = "WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static int verbose = 0; /* verbose/debugging flag */ static int wfile = 0; /* True to print output file */ diff -Nru wcstools-3.9.5/imcat.c wcstools-3.9.6/imcat.c --- wcstools-3.9.5/imcat.c 2017-03-30 15:21:51.000000000 +0000 +++ wcstools-3.9.6/imcat.c 2020-05-14 18:03:54.000000000 +0000 @@ -64,7 +64,7 @@ extern void setparm(); extern void setnpix(); -static char *RevMsg = "IMCAT WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "IMCAT WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static int verbose = 0; /* verbose/debugging flag */ static int wfile = 0; /* True to print output file */ diff -Nru wcstools-3.9.5/imextract.c wcstools-3.9.6/imextract.c --- wcstools-3.9.5/imextract.c 2017-03-30 15:21:51.000000000 +0000 +++ wcstools-3.9.6/imextract.c 2020-05-14 18:03:54.000000000 +0000 @@ -37,7 +37,7 @@ static void usage(); static int ExtractImage(); -static char *RevMsg = "IMEXTRACT WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "IMEXTRACT WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static int verbose = 0; /* verbose flag */ static int krename = 0; diff -Nru wcstools-3.9.5/imfill.c wcstools-3.9.6/imfill.c --- wcstools-3.9.5/imfill.c 2017-03-30 15:21:51.000000000 +0000 +++ wcstools-3.9.6/imfill.c 2020-05-14 18:03:54.000000000 +0000 @@ -63,7 +63,7 @@ static double minpixval = -9999.0; /* Minimum good pixel value */ static double maxpixval = -9999.0; /* Maximum good pixel value */ -static char *RevMsg = "IMFILL WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "IMFILL WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; int main (ac, av) diff -Nru wcstools-3.9.5/imhead.c wcstools-3.9.6/imhead.c --- wcstools-3.9.5/imhead.c 2017-03-30 15:21:51.000000000 +0000 +++ wcstools-3.9.6/imhead.c 2020-05-14 18:03:54.000000000 +0000 @@ -39,7 +39,7 @@ static int verbose = 0; /* verbose/debugging flag */ static int fitsout = 0; /* If 1, write exact FITS header */ static int zbitpix = 0; /* If 1, set BITPIX to 0 for dataless header */ -static char *RevMsg = "IMHEAD WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "IMHEAD WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static int version = 0; /* If 1, print only program name and version */ int diff -Nru wcstools-3.9.5/immatch.c wcstools-3.9.6/immatch.c --- wcstools-3.9.5/immatch.c 2017-03-30 15:21:51.000000000 +0000 +++ wcstools-3.9.6/immatch.c 2020-05-14 18:03:54.000000000 +0000 @@ -41,7 +41,7 @@ #define MAXFILES 1000 static int maxnfile = MAXFILES; -static char *RevMsg = "WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static int verbose = 0; /* verbose/debugging flag */ static int rot = 0; diff -Nru wcstools-3.9.5/imresize.c wcstools-3.9.6/imresize.c --- wcstools-3.9.5/imresize.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/imresize.c 2020-05-14 18:03:54.000000000 +0000 @@ -62,7 +62,7 @@ static int mean = 0; /* 1 if mean for regrouped pixels */ static int northup = 0; /* 1 to rotate to north up, east left */ -static char *RevMsg = "IMRESIZE WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "IMRESIZE WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; int main (ac, av) diff -Nru wcstools-3.9.5/imrot.c wcstools-3.9.6/imrot.c --- wcstools-3.9.5/imrot.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/imrot.c 2020-05-14 18:03:54.000000000 +0000 @@ -38,7 +38,7 @@ static int deletewcs = 0; /* If 1, delete FITS WCS keywords in image */ static int rotatewcs = 1; /* If 1, rotate FITS WCS keywords in image */ static int extnum = 0; /* Use extension number instead of EXTNAME for output */ -static char *RevMsg = "IMROT WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "IMROT WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; int main (ac, av) diff -Nru wcstools-3.9.5/imsize.c wcstools-3.9.6/imsize.c --- wcstools-3.9.5/imsize.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/imsize.c 2020-05-14 18:03:54.000000000 +0000 @@ -44,7 +44,7 @@ static double size = 0.0; static double frac = 0.0; -static char *RevMsg = "IMSIZE WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "IMSIZE WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static int verbose = 0; /* verbose/debugging flag */ static int dss = 0; /* Flag to drop extra stuff for DSS */ diff -Nru wcstools-3.9.5/imsmooth.c wcstools-3.9.6/imsmooth.c --- wcstools-3.9.5/imsmooth.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/imsmooth.c 2020-05-14 18:03:54.000000000 +0000 @@ -55,7 +55,7 @@ static int filter = 0; /* Filter code */ static int nlog = 100; /* Number of lines between log messages */ -static char *RevMsg = "IMSMOOTH WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "IMSMOOTH WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; int main (ac, av) diff -Nru wcstools-3.9.5/imstack.c wcstools-3.9.6/imstack.c --- wcstools-3.9.5/imstack.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/imstack.c 2020-05-14 18:03:54.000000000 +0000 @@ -37,7 +37,7 @@ static int verbose = 0; /* verbose flag */ static int wfits = 1; /* if 1, write FITS header before data */ static char *newname = NULL; -static char *RevMsg = "IMSTACK WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "IMSTACK WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static int nfiles = 0; static int nbstack = 0; static int extend = 0; /* If 1, output multi-extension FITS file */ diff -Nru wcstools-3.9.5/imstar.c wcstools-3.9.6/imstar.c --- wcstools-3.9.5/imstar.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/imstar.c 2020-05-14 18:03:54.000000000 +0000 @@ -41,7 +41,7 @@ #define MAXFILES 1000 static int maxnfile = MAXFILES; -static char *RevMsg = "IMSTAR WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "IMSTAR WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static int verbose = 0; /* verbose flag */ static int debug = 0; /* debugging flag */ diff -Nru wcstools-3.9.5/imwcs.c wcstools-3.9.6/imwcs.c --- wcstools-3.9.5/imwcs.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/imwcs.c 2020-05-14 18:03:54.000000000 +0000 @@ -40,7 +40,7 @@ static void PrintUsage(); static void FitWCS(); -static char *RevMsg = "IMWCS WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "IMWCS WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static int verbose = 0; /* verbose/debugging flag */ static int writeheader = 0; /* write header fields; else read-only */ diff -Nru wcstools-3.9.5/isfile.c wcstools-3.9.6/isfile.c --- wcstools-3.9.5/isfile.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/isfile.c 2020-05-14 18:03:54.000000000 +0000 @@ -28,7 +28,7 @@ #include #include "libwcs/fitsfile.h" -static char *RevMsg = "ISFILE WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "ISFILE WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; int main (ac, av) diff -Nru wcstools-3.9.5/isfits.c wcstools-3.9.6/isfits.c --- wcstools-3.9.5/isfits.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/isfits.c 2020-05-14 18:03:54.000000000 +0000 @@ -28,7 +28,7 @@ #include #include "libwcs/fitsfile.h" -static char *RevMsg = "ISFITS WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "ISFITS WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; int main (ac, av) diff -Nru wcstools-3.9.5/isimlist.c wcstools-3.9.6/isimlist.c --- wcstools-3.9.5/isimlist.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/isimlist.c 2020-05-14 18:03:54.000000000 +0000 @@ -28,7 +28,7 @@ #include #include "libwcs/fitsfile.h" -static char *RevMsg = "ISIMLIST WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "ISIMLIST WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; int main (ac, av) diff -Nru wcstools-3.9.5/isnum.c wcstools-3.9.6/isnum.c --- wcstools-3.9.5/isnum.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/isnum.c 2020-05-14 18:03:54.000000000 +0000 @@ -28,7 +28,7 @@ #include #include "libwcs/fitshead.h" -static char *RevMsg = "ISNUM WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "ISNUM WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; int main (ac, av) diff -Nru wcstools-3.9.5/isrange.c wcstools-3.9.6/isrange.c --- wcstools-3.9.5/isrange.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/isrange.c 2020-05-14 18:03:54.000000000 +0000 @@ -27,7 +27,7 @@ #include #include -static char *RevMsg = "ISRANGE WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "ISRANGE WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static int isrange(); diff -Nru wcstools-3.9.5/keyhead.c wcstools-3.9.6/keyhead.c --- wcstools-3.9.5/keyhead.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/keyhead.c 2020-05-14 18:03:54.000000000 +0000 @@ -50,7 +50,7 @@ static int nproc = 0; static int first_file = 1; -static char *RevMsg = "KEYHEAD WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "KEYHEAD WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; int main (ac, av) diff -Nru wcstools-3.9.5/libwcs/catutil.c wcstools-3.9.6/libwcs/catutil.c --- wcstools-3.9.5/libwcs/catutil.c 2017-03-23 21:10:11.000000000 +0000 +++ wcstools-3.9.6/libwcs/catutil.c 2019-10-29 18:24:09.000000000 +0000 @@ -1,8 +1,8 @@ /*** File libwcs/catutil.c - *** November 25, 2015 + *** October 29, 2019 *** By Jessica Mink, jmink@cfa.harvard.edu *** Harvard-Smithsonian Center for Astrophysics - *** Copyright (C) 1998-2015 + *** Copyright (C) 1998-2019 *** Smithsonian Astrophysical Observatory, Cambridge, MA, USA This library is free software; you can redistribute it and/or @@ -2099,7 +2099,6 @@ return; } - /* REFLIM-- Set limits in reference catalog coordinates given search coords */ void RefLim (cra, cdec, dra, ddec, sysc, sysr, eqc, eqr, epc, epr, secmarg, @@ -2177,6 +2176,10 @@ else if (adec == 90.0) dra1 = 180.0; + /* Deal with images containing a pole */ + if (dra1 > 180.0) + dra1 = 180.0; + /* Set right ascension limits for search */ ra1 = cra - dra1; ra2 = cra + dra1; @@ -2774,13 +2777,16 @@ *lastval = 0; } - /* Drop trailing spaces/underscores */ + /* Drop trailing spaces/underscores/commas */ if (!fillblank) { lval = strlen (value); for (ival = value+lval-1; ival > value; ival--) { if (*ival == '_') { *ival = (char) 0; } + else if (*ival == ',') { + *ival = (char) 0; + } else if (*ival == ' ') { *ival = (char) 0; } @@ -3571,4 +3577,8 @@ * Sep 23 2013 Finish adding UCAC4 catalog * * Nov 25 2015 Add tab as an assignment character in agets() + * + * Jul 31 2018 Keep RA limits to +- 180 (suggested by Ed Los, Harvard) + * + * Oct 29 2019 Drop trailing commas as well as underscores and spaces */ diff -Nru wcstools-3.9.5/libwcs/dateutil.c wcstools-3.9.6/libwcs/dateutil.c --- wcstools-3.9.5/libwcs/dateutil.c 2012-10-19 21:26:05.000000000 +0000 +++ wcstools-3.9.6/libwcs/dateutil.c 2019-09-24 21:37:29.000000000 +0000 @@ -1,8 +1,8 @@ /*** File libwcs/dateutil.c - *** October 19, 2012 + *** September 24, 2019 *** By Jessica Mink, jmink@cfa.harvard.edu *** Harvard-Smithsonian Center for Astrophysics - *** Copyright (C) 1999-2012 + *** Copyright (C) 1999-2019 *** Smithsonian Astrophysical Observatory, Cambridge, MA, USA This library is free software; you can redistribute it and/or @@ -61,6 +61,7 @@ lst = Local Sidereal Time (includes nutation) (longitude must be set) hjd = Heliocentric Julian Date mhjd = modified Heliocentric Julian Date = HJD - 2400000.5 + sec = seconds of angle * ang2hr (angle) * Convert angle in decimal floating point degrees to hours as hh:mm:ss.ss @@ -390,6 +391,48 @@ } +/* HR2SEC -- Convert angle in hours as hh:mm:ss.ss to fractional arcseconds */ + +double +hr2sec (angle) + +char *angle; /* Angle as dd:mm:ss.ss */ +{ + double sec; + + sec = 15.0 * (str2dec (angle) * 3600.0); + return (sec); +} + + +/* DEG2SEC -- Convert angle in degrees as dd:mm:ss.ss to fractional arcseconds */ + +double +deg2sec (angle) + +char *angle; /* Angle as dd:mm:ss.ss */ +{ + double sec; + + sec = str2dec (angle) * 3600.0; + return (sec); +} + + +/* ANG2SEC -- Convert angle in fractional degrees to fractional arcseconds */ + +double +ang2sec (angle) + +double angle; /* Angle in degrees */ +{ + double sec; + + sec = angle * 3600.0; + return (sec); +} + + /* DT2FD-- convert vigesimal date and time to FITS date, yyyy-mm-ddThh:mm:ss.ss */ char * @@ -2333,7 +2376,7 @@ } -/* FD2OFD-- convert any FITS standard date to old FITS standard date */ +/* FD2OFD-- convert any FITS standard datetime string to old FITS standard date */ char * fd2ofd (string) @@ -2347,20 +2390,21 @@ { int iyr,imon,iday,ihr,imn; double sec; + char *dstr; fd2i (string,&iyr,&imon,&iday,&ihr,&imn,&sec, 3); /* Convert to old FITS date format */ - string = (char *) calloc (32, sizeof (char)); + dstr = (char *) calloc (32, sizeof (char)); if (iyr < 1900) - sprintf (string, "*** date out of range ***"); + sprintf (dstr, "*** date out of range ***"); else if (iyr < 2000) - sprintf (string, "%02d/%02d/%02d", iday, imon, iyr-1900); + sprintf (dstr, "%02d/%02d/%02d", iday, imon, iyr-1900); else if (iyr < 2900.0) - sprintf (string, "%02d/%02d/%3d", iday, imon, iyr-1900); + sprintf (dstr, "%02d/%02d/%3d", iday, imon, iyr-1900); else - sprintf (string, "*** date out of range ***"); - return (string); + sprintf (dstr, "*** date out of range ***"); + return (dstr); } @@ -2378,13 +2422,14 @@ { int iyr,imon,iday,ihr,imn; double sec; + char *tstr; fd2i (string,&iyr,&imon,&iday,&ihr,&imn,&sec, 3); /* Convert to old FITS date format */ - string = (char *) calloc (32, sizeof (char)); - sprintf (string, "%02d:%02d:%06.3f", ihr, imn, sec); - return (string); + tstr = (char *) calloc (32, sizeof (char)); + sprintf (tstr, "%02d:%02d:%06.3f", ihr, imn, sec); + return (tstr); } @@ -4551,4 +4596,8 @@ * * Jan 11 2012 Add TAI, TT, GPS time * Oct 19 2012 Unused l0 dropped from jd2lst(); ts2ss from jd2mst() + * + * May 2 2017 Allocate new output string for fd2ofd() and fd2oft() + * + * Sep 24 2019 Add ang2sec() and deg2sec() to convert to arcseconds */ diff -Nru wcstools-3.9.5/libwcs/fitsfile.c wcstools-3.9.6/libwcs/fitsfile.c --- wcstools-3.9.5/libwcs/fitsfile.c 2016-06-24 18:39:05.000000000 +0000 +++ wcstools-3.9.6/libwcs/fitsfile.c 2019-09-23 16:14:06.000000000 +0000 @@ -1,8 +1,8 @@ /*** File libwcs/fitsfile.c - *** June 24, 2016 + *** September 23, 2019 *** By Jessica Mink, jmink@cfa.harvard.edu *** Harvard-Smithsonian Center for Astrophysics - *** Copyright (C) 1996-2016 + *** Copyright (C) 1996-2019 *** Smithsonian Astrophysical Observatory, Cambridge, MA, USA This library is free software; you can redistribute it and/or @@ -200,7 +200,7 @@ nbytes = FITSBLOCK; *nbhead = 0; headend = NULL; - nbh = FITSBLOCK * 20 + 4; + nbh = FITSBLOCK * 100 + 4; header = (char *) calloc ((unsigned int) nbh, 1); (void) hlength (header, nbh); headnext = header; @@ -2325,4 +2325,6 @@ * * Jun 9 2016 Fix isnum() tests for added coloned times and dashed dates * Jun 24 2016 Add 1 to allocation of pheader for trailing null, fix by Ole Streicher + * + * Sep 23 2019 Increase header length default to 288000 = 100 blocks */ diff -Nru wcstools-3.9.5/libwcs/fitsfile.h wcstools-3.9.6/libwcs/fitsfile.h --- wcstools-3.9.5/libwcs/fitsfile.h 2014-06-20 20:41:59.000000000 +0000 +++ wcstools-3.9.6/libwcs/fitsfile.h 2019-09-24 21:26:50.000000000 +0000 @@ -1,8 +1,8 @@ /*** File fitsfile.h FITS and IRAF file access subroutines - *** June 20, 2014 + *** September 24, 2019 *** By Jessica Mink, jmink@cfa.harvard.edu *** Harvard-Smithsonian Center for Astrophysics - *** Copyright (C) 1996-2014 + *** Copyright (C) 1996-2019 *** Smithsonian Astrophysical Observatory, Cambridge, MA, USA This library is free software; you can redistribute it and/or @@ -461,6 +461,12 @@ char *angle); /* Angle as dd:mm:ss.ss */ double hr2ang ( /* Hours as hh:mm:ss.ss to fractional degrees */ char *angle); /* Angle in sexigesimal hours (hh:mm:ss.sss) */ + double ang2sec ( /* Angle in fractional arcseconds */ + double angle); /* Angle in fractional degrees */ + double hr2sec ( /* Angle in fractional arcseconds */ + char *angle); /* Angle in sexigesimal hours (hh:mm:ss.sss) */ + double deg2sec ( /* Angle in fractional arcseconds */ + char *angle); /* Angle in sexigesimal degrees (dd:mm:ss.sss) */ /* Subroutines to convert from year and day of year */ @@ -1046,6 +1052,9 @@ void ang2deg(); /* Fractional degrees to degrees as dd:mm:ss.ss */ double deg2ang(); /* Degrees as dd:mm:ss.ss to fractional degrees */ double hr2ang(); /* Hours as hh:mm:ss.ss to fractional degrees */ +double ang2sec(); /* Angle as fractional degrees to fractional arcsec */ +double deg2sec(); /* Angle as dd:mm:ss.ss to fractional arcsec */ +double hr2sec(); /* Angle as hh:mm:ss.ss to fractional arcsec */ void doy2dt(); /* year and day of year to yyyy.mmdd hh.mmss */ double doy2ep(); /* year and day of year to fractional year (epoch) */ @@ -1290,4 +1299,6 @@ * Sep 25 2009 Add moveb() * * Jun 20 2014 Add next_line() + * + * Sep 24 2019 Add hr2sec(), deg2sec(), ang2sec() to convert to arcseconds */ diff -Nru wcstools-3.9.5/libwcs/gsc2read.c wcstools-3.9.6/libwcs/gsc2read.c --- wcstools-3.9.5/libwcs/gsc2read.c 2015-03-24 19:20:16.000000000 +0000 +++ wcstools-3.9.6/libwcs/gsc2read.c 2018-08-07 16:14:51.000000000 +0000 @@ -1,8 +1,8 @@ /*** File libwcs/gsc2read.c - *** March 24, 2015 + *** August 7, 2018 *** By Jessica Mink, jmink@cfa.harvard.edu *** Harvard-Smithsonian Center for Astrophysics - *** Copyright (C) 2001-2015 + *** Copyright (C) 2001-2018 *** Smithsonian Astrophysical Observatory, Cambridge, MA, USA This library is free software; you can redistribute it and/or @@ -158,6 +158,7 @@ starcat->equinox = 2000.0; /* Extract desired sources from catalog and return them */ + settabkey ("gsc2ID"); nstar = tabread (gsc2url,distsort,cra,cdec,dra,ddec,drad,dradi, sysout,eqout,epout,mag1,mag2,sortmag,nstarmax,&starcat, gnum,gra,gdec,gpra,gpdec,gmag,gtype,gobj,nlog); @@ -390,4 +391,6 @@ * Aug 29 2014 Add line of dashes after header to returned table * * Mar 24 2015 Drop concatenation of "empty" string to search URL + * + * Aug 7 2018 Set extra table keyword to objID */ diff -Nru wcstools-3.9.5/libwcs/healpix.diff wcstools-3.9.6/libwcs/healpix.diff --- wcstools-3.9.5/libwcs/healpix.diff 1970-01-01 00:00:00.000000000 +0000 +++ wcstools-3.9.6/libwcs/healpix.diff 2017-07-31 21:55:25.000000000 +0000 @@ -0,0 +1,1547 @@ +--- + libwcs/proj.c | 1365 +++++++++++++++++++++++++++++++++++++++++++++++++++++- + libwcs/wcs.c | 17 +- + libwcs/wcs.h | 19 +- + libwcs/wcsinit.c | 8 + + libwcs/wcslib.h | 11 +- + 5 files changed, 1401 insertions(+), 19 deletions(-) + +diff --git a/libwcs/proj.c b/libwcs/proj.c +index 8460329..87d7c53 100644 +--- a/libwcs/proj.c ++++ b/libwcs/proj.c +@@ -1,3 +1,5 @@ ++#include ++ + /*============================================================================ + * + * WCSLIB - an implementation of the FITS WCS proposal. +@@ -67,6 +69,9 @@ + * tscset tscfwd tscrev TSC: tangential spherical cube + * cscset cscfwd cscrev CSC: COBE quadrilateralized spherical cube + * qscset qscfwd qscrev QSC: quadrilateralized spherical cube ++* hpxset hpxfwd hpxrev HPX: HEALPix projection ++* xpfset xpffwd xpfrev XPH: HEALPix polar, aka "butterfly" ++* toaset toafwd toarev TOA: TOAST projection + * + * + * Driver routines; prjset(), prjfwd() & prjrev() +@@ -237,11 +242,11 @@ + #include + #include "wcslib.h" + +-int npcode = 26; +-char pcodes[26][4] = ++int npcode = 29; ++char pcodes[29][4] = + {"AZP", "SZP", "TAN", "STG", "SIN", "ARC", "ZPN", "ZEA", "AIR", "CYP", + "CEA", "CAR", "MER", "COP", "COE", "COD", "COO", "SFL", "PAR", "MOL", +- "AIT", "BON", "PCO", "TSC", "CSC", "QSC"}; ++ "AIT", "BON", "PCO", "TSC", "CSC", "QSC", "HPX", "XPH", "TOA"}; + + const int AZP = 101; + const int SZP = 102; +@@ -269,6 +274,9 @@ const int PCO = 602; + const int TSC = 701; + const int CSC = 702; + const int QSC = 703; ++const int HPX = 801; ++const int XPH = 802; ++const int TOA = 803; + + /* Map error number to error message for each function. */ + const char *prjset_errmsg[] = { +@@ -288,6 +296,31 @@ const char *prjrev_errmsg[] = { + #define copysgn(X, Y) ((Y) < 0.0 ? -fabs(X) : fabs(X)) + #define copysgni(X, Y) ((Y) < 0 ? -abs(X) : abs(X)) + ++ ++/* Vector functions for TOAST partitioning */ ++ ++const double deg2rad = PI / 180.0; ++ ++typedef struct vec ++{ ++ double lon, lat; ++ double x, y, z; ++} ++Vec; ++ ++void vCopy (Vec *v, Vec *c); ++void vCalcRADec(Vec *v); ++void vCalcXYZ (Vec *v); ++void vMidpoint (Vec *a, Vec *b, Vec *c); ++void vPixCenter(Vec *a, Vec *b, Vec *c, Vec *d, Vec *v); ++int vCross (Vec *a, Vec *b, Vec *c); ++double vDot (Vec *a, Vec *b); ++double vNormalize(Vec *a); ++double vPrint (Vec *v, char *lbl); ++ ++void splitIndex(unsigned long index, int level, int *x, int *y); ++ ++ + /*==========================================================================*/ + + int prjset(pcode, prj) +@@ -349,6 +382,12 @@ struct prjprm *prj; + cscset(prj); + } else if (strcmp(pcode, "QSC") == 0) { + qscset(prj); ++ } else if (strcmp(pcode, "HPX") == 0) { ++ hpxset(prj); ++ } else if (strcmp(pcode, "XPH") == 0) { ++ xphset(prj); ++ } else if (strcmp(pcode, "TOA") == 0) { ++ toaset(prj); + } else { + /* Unrecognized projection code. */ + return 1; +@@ -4364,6 +4403,1100 @@ double *phi, *theta; + return 0; + } + ++/*============================================================================ ++* HPX: HEALPix projection. ++* ++* Given: ++* prj->p[1] H - the number of facets in longitude. ++* prj->p[2] K - the number of facets in latitude ++* ++* Given and/or returned: ++* prj->r0 Reset to 180/pi if 0. ++* prj->phi0 Reset to 0.0 ++* prj->theta0 Reset to 0.0 ++* ++* Returned: ++* prj->flag HPX ++* prj->code "HPX" ++* prj->n True if K is odd. ++* prj->w[0] r0*(pi/180) ++* prj->w[1] (180/pi)/r0 ++* prj->w[2] (K-1)/K ++* prj->w[3] 90*K/H ++* prj->w[4] (K+1)/2 ++* prj->w[5] 90*(K-1)/H ++* prj->w[6] 180/H ++* prj->w[7] H/360 ++* prj->w[8] (90*K/H)*r0*(pi/180) ++* prj->w[9] (180/H)*r0*(pi/180) ++* prj->prjfwd Pointer to hpxfwd(). ++* prj->prjrev Pointer to hpxrev(). ++ ++ ++*===========================================================================*/ ++ ++int hpxset(prj) ++ ++struct prjprm *prj; ++ ++{ ++ strcpy(prj->code, "HPX"); ++ prj->flag = HPX; ++ prj->phi0 = 0.0; ++ prj->theta0 = 0.0; ++ ++ prj->n = ((int)prj->p[2])%2; ++ ++ if (prj->r0 == 0.0) { ++ prj->r0 = R2D; ++ prj->w[0] = 1.0; ++ prj->w[1] = 1.0; ++ } else { ++ prj->w[0] = prj->r0*D2R; ++ prj->w[1] = R2D/prj->r0; ++ } ++ ++ prj->w[2] = (prj->p[2] - 1.0) / prj->p[2]; ++ prj->w[3] = 90.0 * prj->p[2] / prj->p[1]; ++ prj->w[4] = (prj->p[2] + 1.0) / 2.0; ++ prj->w[5] = 90.0 * (prj->p[2] - 1.0) / prj->p[1]; ++ prj->w[6] = 180.0 / prj->p[1]; ++ prj->w[7] = prj->p[1] / 360.0; ++ prj->w[8] = prj->w[3] * prj->w[0]; ++ prj->w[9] = prj->w[6] * prj->w[0]; ++ ++ prj->prjfwd = hpxfwd; ++ prj->prjrev = hpxrev; ++ ++ return 0; ++} ++ ++/*--------------------------------------------------------------------------*/ ++ ++int hpxfwd(phi, theta, prj, x, y) ++ ++const double phi, theta; ++struct prjprm *prj; ++double *x, *y; ++ ++{ ++ double abssin, sigma, sinthe, phic; ++ int hodd; ++ ++ if( prj->flag != HPX ) { ++ if( hpxset( prj ) ) return 1; ++ } ++ ++ sinthe = sindeg( theta ); ++ abssin = fabs( sinthe ); ++ ++/* Equatorial zone */ ++ if( abssin <= prj->w[2] ) { ++ *x = prj->w[0] * phi; ++ *y = prj->w[8] * sinthe; ++ ++/* Polar zone */ ++ } else { ++ ++/* DSB - The expression for phic is conditioned differently to the ++ WCSLIB code in order to improve accuracy of the floor function for ++ arguments very slightly below an integer value. */ ++ hodd = ((int)prj->p[1]) % 2; ++ if( !prj->n && theta <= 0.0 ) hodd = 1 - hodd; ++ if( hodd ) { ++ phic = -180.0 + (2.0*floor( prj->w[7] * phi + 1/2 ) + prj->p[1] ) * prj->w[6]; ++ } else { ++ phic = -180.0 + (2.0*floor( prj->w[7] * phi ) + prj->p[1] + 1 ) * prj->w[6]; ++ } ++ ++ sigma = sqrt( prj->p[2]*( 1.0 - abssin )); ++ ++ *x = prj->w[0] *( phic + ( phi - phic )*sigma ); ++ ++ *y = prj->w[9] * ( prj->w[4] - sigma ); ++ if( theta < 0 ) *y = -*y; ++ ++ } ++ ++ return 0; ++} ++ ++/*--------------------------------------------------------------------------*/ ++ ++int hpxrev(x, y, prj, phi, theta) ++ ++const double x, y; ++struct prjprm *prj; ++double *phi, *theta; ++ ++{ ++ double absy, sigma, t, yr, xc; ++ int hodd; ++ ++ if (prj->flag != HPX) { ++ if (hpxset(prj)) return 1; ++ } ++ ++ yr = prj->w[1]*y; ++ absy = fabs( yr ); ++ ++/* Equatorial zone */ ++ if( absy <= prj->w[5] ) { ++ *phi = prj->w[1] * x; ++ t = yr/prj->w[3]; ++ if( t < -1.0 || t > 1.0 ) { ++ return 2; ++ } else { ++ *theta = asindeg( t ); ++ } ++ ++/* Polar zone */ ++ } else if( absy <= 90 ){ ++ ++ hodd = ((int)prj->p[1]) % 2; ++ if( !prj->n && yr <= 0.0 ) hodd = 1 - hodd; ++ if( hodd ) { ++ xc = -180.0 + (2.0*floor( prj->w[7] * x + 1/2 ) + prj->p[1] ) * prj->w[6]; ++ } else { ++ xc = -180.0 + (2.0*floor( prj->w[7] * x ) + prj->p[1] + 1 ) * prj->w[6]; ++ } ++ ++ sigma = prj->w[4] - absy / prj->w[6]; ++ ++ if( sigma == 0.0 ) { ++ return 2; ++ } else { ++ ++ t = ( x - xc )/sigma; ++ if( fabs( t ) <= prj->w[6] ) { ++ *phi = prj->w[1] *( xc + t ); ++ } else { ++ return 2; ++ } ++ } ++ ++ t = 1.0 - sigma*sigma/prj->p[2]; ++ if( t < -1.0 || t > 1.0 ) { ++ return 2; ++ } else { ++ *theta = asindeg ( t ); ++ if( y < 0 ) *theta = -*theta; ++ } ++ ++ } else { ++ return 2; ++ } ++ ++ return 0; ++} ++ ++/*============================================================================ ++* XPH: HEALPix polar, aka "butterfly" projection. ++* ++* Given and/or returned: ++* prj->r0 Reset to 180/pi if 0. ++* prj->phi0 Reset to 0.0 if undefined. ++* prj->theta0 Reset to 0.0 if undefined. ++* ++* Returned: ++* prj->flag XPH ++* prj->code "XPH" ++* prj->w[0] r0*(pi/180)/sqrt(2) ++* prj->w[1] (180/pi)/r0/sqrt(2) ++* prj->w[2] 2/3 ++* prj->w[3] tol (= 1e-4) ++* prj->w[4] sqrt(2/3)*(180/pi) ++* prj->w[5] 90 - tol*sqrt(2/3)*(180/pi) ++* prj->w[6] sqrt(3/2)*(pi/180) ++* prj->prjfwd Pointer to xphfwd(). ++* prj->prjrev Pointer to xphrev(). ++*===========================================================================*/ ++ ++int xphset(prj) ++ ++struct prjprm *prj; ++ ++{ ++ strcpy(prj->code, "XPH"); ++ prj->flag = XPH; ++ ++ if (prj->r0 == 0.0) { ++ prj->r0 = R2D; ++ prj->w[0] = 1.0; ++ prj->w[1] = 1.0; ++ } else { ++ prj->w[0] = prj->r0*D2R; ++ prj->w[1] = R2D/prj->r0; ++ } ++ ++ prj->w[0] /= sqrt(2.0); ++ prj->w[1] /= sqrt(2.0); ++ prj->w[2] = 2.0/3.0; ++ prj->w[3] = 1e-4; ++ prj->w[4] = sqrt(prj->w[2])*R2D; ++ prj->w[5] = 90.0 - prj->w[3]*prj->w[4]; ++ prj->w[6] = sqrt(1.5)*D2R; ++ ++ prj->prjfwd = xphfwd; ++ prj->prjrev = xphrev; ++ ++ return 0; ++} ++ ++/*--------------------------------------------------------------------------*/ ++ ++int xphfwd(phi, theta, prj, x, y) ++ ++const double phi, theta; ++struct prjprm *prj; ++double *x, *y; ++ ++{ ++ double abssin, chi, eta, psi, sigma, sinthe, xi; ++ ++ if (prj->flag != XPH) { ++ if (xphset(prj)) return 1; ++ } ++ ++ /* Do phi dependence. */ ++ chi = phi; ++ if (180.0 <= fabs(chi)) { ++ chi = fmod(chi, 360.0); ++ if (chi < -180.0) { ++ chi += 360.0; ++ } else if (180.0 <= chi) { ++ chi -= 360.0; ++ } ++ } ++ ++ /* phi is also recomputed from chi to avoid rounding problems. */ ++ chi += 180.0; ++ psi = fmod(chi, 90.0); ++ ++ /* y is used to hold phi (rounded). */ ++ *x = psi; ++ *y = chi - 180.0; ++ ++ /* Do theta dependence. */ ++ sinthe = sindeg(theta); ++ abssin = fabs(sinthe); ++ ++ if (abssin <= prj->w[2]) { ++ /* Equatorial regime. */ ++ xi = *x; ++ eta = 67.5 * sinthe; ++ ++ } else { ++ /* Polar regime. */ ++ if (theta < prj->w[5]) { ++ sigma = sqrt(3.0*(1.0 - abssin)); ++ } else { ++ sigma = (90.0 - theta)*prj->w[6]; ++ } ++ ++ xi = 45.0 + (*x - 45.0)*sigma; ++ eta = 45.0 * (2.0 - sigma); ++ if (theta < 0.0) eta = -eta; ++ } ++ ++ xi -= 45.0; ++ eta -= 90.0; ++ ++ /* Recall that y holds phi. */ ++ if (*y < -90.0) { ++ *x = prj->w[0]*(-xi + eta); ++ *y = prj->w[0]*(-xi - eta); ++ ++ } else if (*y < 0.0) { ++ *x = prj->w[0]*(+xi + eta); ++ *y = prj->w[0]*(-xi + eta); ++ ++ } else if (*y < 90.0) { ++ *x = prj->w[0]*( xi - eta); ++ *y = prj->w[0]*( xi + eta); ++ ++ } else { ++ *x = prj->w[0]*(-xi - eta); ++ *y = prj->w[0]*( xi - eta); ++ } ++ ++ return 0; ++ ++} ++ ++/*--------------------------------------------------------------------------*/ ++ ++int xphrev(x, y, prj, phi, theta) ++ ++const double x, y; ++struct prjprm *prj; ++double *phi, *theta; ++ ++{ ++ double abseta, eta, eta1, sigma, xi, xi1, xr, yr; ++ const double tol = 1.0e-12; ++ ++ if (prj->flag != XPH) { ++ if (xphset(prj)) return 1; ++ } ++ ++ ++ xr = x*prj->w[1]; ++ yr = y*prj->w[1]; ++ if (xr <= 0.0 && 0.0 < yr) { ++ xi1 = -xr - yr; ++ eta1 = xr - yr; ++ *phi = -180.0; ++ } else if (xr < 0.0 && yr <= 0.0) { ++ xi1 = xr - yr; ++ eta1 = xr + yr; ++ *phi = -90.0; ++ } else if (0.0 <= xr && yr < 0.0) { ++ xi1 = xr + yr; ++ eta1 = -xr + yr; ++ *phi = 0.0; ++ } else { ++ xi1 = -xr + yr; ++ eta1 = -xr - yr; ++ *phi = 90.0; ++ } ++ ++ xi = xi1 + 45.0; ++ eta = eta1 + 90.0; ++ abseta = fabs(eta); ++ ++ if (abseta <= 90.0) { ++ if (abseta <= 45.0) { ++ /* Equatorial regime. */ ++ *phi += xi; ++ *theta = asindeg (eta/67.5); ++ ++ /* Bounds checking. */ ++ if (45.0+tol < fabs(xi1)) return 2; ++ ++ } else { ++ /* Polar regime. */ ++ sigma = (90.0 - abseta) / 45.0; ++ ++ /* Ensure an exact result for points on the boundary. */ ++ if (xr == 0.0) { ++ if (yr <= 0.0) { ++ *phi = 0.0; ++ } else { ++ *phi = 180.0; ++ } ++ } else if (yr == 0.0) { ++ if (xr < 0.0) { ++ *phi = -90.0; ++ } else { ++ *phi = 90.0; ++ } ++ } else { ++ *phi += 45.0 + xi1/sigma; ++ } ++ ++ if (sigma < prj->w[3]) { ++ *theta = 90.0 - sigma*prj->w[4]; ++ } else { ++ *theta = asindeg (1.0 - sigma*sigma/3.0); ++ } ++ if (eta < 0.0) *theta = -(*theta); ++ ++ /* Bounds checking. */ ++ if (eta < -45.0 && eta+90.0+tol < fabs(xi1)) return 2; ++ } ++ ++ } else { ++ /* Beyond latitude range. */ ++ *phi = 0.0; ++ *theta = 0.0; ++ return 2; ++ } ++ ++ return 0; ++} ++ ++ ++/*============================================================================ ++* TOA: TOAST projection. ++* ++* Given: ++* prj->p[1] The HTM level (number of iterative subdivisions of space) ++* ++* Returned: ++* prj->flag TOA ++* prj->code "TOA" ++* prj->prjfwd Pointer to toafwd(). ++* prj->prjrev Pointer to toarev(). ++ ++ ++*===========================================================================*/ ++ ++int toaset(prj) ++ ++struct prjprm *prj; ++ ++{ ++ strcpy(prj->code, "TOA"); ++ prj->flag = TOA; ++ ++ prj->prjfwd = toafwd; ++ prj->prjrev = toarev; ++ ++ return 0; ++} ++ ++/*--------------------------------------------------------------------------*/ ++ ++int toafwd(phi, theta, prj, x, y) ++ ++const double phi, theta; ++struct prjprm *prj; ++double *x, *y; ++{ ++ Vec ref; ++ Vec center; ++ Vec corner [4]; ++ Vec midpoint[4]; ++ Vec normal [4]; ++ ++ unsigned long index, maxindex; ++ ++ int debug = 0; ++ ++ int i, level, maxlevel, npix; ++ int xindex, yindex; ++ int prime, opposite; ++ ++ double direction[4]; ++ double size; ++ ++ ++ if(debug > 1) ++ printf("\nTOAFWD> LON = %10.6f LAT = %10.6f\n\n", phi, theta); ++ ++ ++ if( prj->flag != TOA ) ++ if( toaset( prj ) ) ++ return 1; ++ ++ ++ // We calculate down to level 27 to allow ++ // for fraction pixel coordinates ++ ++ maxlevel = 27; ++ ++ maxindex = 0b1 << maxlevel; ++ ++ ++ // Get location of interest from command line ++ ++ ref.lon = phi; ++ ref.lat = theta; ++ ++ while(ref.lon < 0.) ref.lon += 360.; ++ while(ref.lon >= 360.) ref.lon -= 360.; ++ ++ if(ref.lat > 90.) ref.lat = 90.; ++ if(ref.lat < -90.) ref.lat = -90.; ++ ++ vCalcXYZ(&ref); ++ ++ ++ // Get the level of the map ++ // This determines how many pixels there are in the map ++ ++ level = (int)prj->p[1]; ++ ++ npix = 0b1 << (level+8); ++ ++ ++ // The first level has to be done by hand ++ ++ if(ref.lon < 90.) // quadrant 11 [3] ++ { ++ if(debug > 1) ++ printf("TOAFWD> Quadrant 11\n\n"); ++ ++ index = 0b11; ++ ++ corner[0].lon = 0.; ++ corner[0].lat = 90.; ++ ++ corner[1].lon = 0.; ++ corner[1].lat = 0.; ++ ++ corner[2].lon = 0.; ++ corner[2].lat = -90.; ++ ++ corner[3].lon = 90.; ++ corner[3].lat = 0.; ++ ++ prime = 1; ++ } ++ ++ else if(ref.lon < 180.) // quadrant 10 [2] ++ { ++ if(debug > 1) ++ printf("TOAFWD> Quadrant 10\n\n"); ++ ++ index = 0b10; ++ ++ corner[0].lon = 180.; ++ corner[0].lat = 0.; ++ ++ corner[1].lon = 0.; ++ corner[1].lat = 90.; ++ ++ corner[2].lon = 90.; ++ corner[2].lat = 0.; ++ ++ corner[3].lon = 0.; ++ corner[3].lat = -90.; ++ ++ prime = 0; ++ } ++ ++ else if(ref.lon < 270.) // quadrant 00 [0] ++ { ++ if(debug >1) ++ printf("TOAFWD> Quadrant 00\n\n"); ++ ++ index = 0b00; ++ ++ corner[0].lon = 0.; ++ corner[0].lat = -90.; ++ ++ corner[1].lon = 270.; ++ corner[1].lat = 0.; ++ ++ corner[2].lon = 0.; ++ corner[2].lat = 90.; ++ ++ corner[3].lon = 180.; ++ corner[3].lat = 0.; ++ ++ prime = 1; ++ } ++ ++ else // quadrant 01 [1] ++ { ++ if(debug > 1) ++ printf("TOAFWD> Quadrant 01\n\n"); ++ ++ index = 0b01; ++ ++ corner[0].lon = 270.; ++ corner[0].lat = 0.; ++ ++ corner[1].lon = 0.; ++ corner[1].lat = -90.; ++ ++ corner[2].lon = 0.; ++ corner[2].lat = 0.; ++ ++ corner[3].lon = 0.; ++ corner[3].lat = 90.; ++ ++ prime = 0; ++ } ++ ++ level = 1; ++ ++ vCalcXYZ(&corner[0]); ++ vCalcXYZ(&corner[1]); ++ vCalcXYZ(&corner[2]); ++ vCalcXYZ(&corner[3]); ++ ++ if(debug > 1) ++ { ++ vPrint(&corner[0], "corner[0]"); ++ vPrint(&corner[1], "corner[1]"); ++ vPrint(&corner[2], "corner[2]"); ++ vPrint(&corner[3], "corner[3]"); ++ } ++ ++ ++ // Drill down level by level ++ ++ while(level < maxlevel) ++ { ++ // Find cell edge midpoints ++ ++ vMidpoint(&corner[1], &corner[0], &midpoint[0]); ++ vMidpoint(&corner[2], &corner[1], &midpoint[1]); ++ vMidpoint(&corner[3], &corner[2], &midpoint[2]); ++ vMidpoint(&corner[0], &corner[3], &midpoint[3]); ++ ++ if(debug > 1) ++ { ++ vPrint(&midpoint[0], "midpoint[0]"); ++ vPrint(&midpoint[1], "midpoint[1]"); ++ vPrint(&midpoint[2], "midpoint[2]"); ++ vPrint(&midpoint[3], "midpoint[3]"); ++ } ++ ++ ++ // We also need the center point (midpoint of the HTM diagonal) ++ ++ opposite = (prime + 2) % 4; ++ ++ vMidpoint(&corner[prime], &corner[opposite], ¢er); ++ ++ if(debug > 1) ++ { ++ vPrint(&corner[prime], "Prime"); ++ vPrint(&corner[opposite], "Opposite"); ++ vPrint(¢er, "center"); ++ } ++ ++ ++ // Find the lines connecting the center and the edge midpoints ++ // (actually the normal vectors to those planes) ++ ++ vCross(&midpoint[0], ¢er, &normal[0]); ++ vNormalize(&normal[0]); ++ ++ vCross(¢er, &midpoint[2], &normal[2]); ++ vNormalize(&normal[0]); ++ ++ vCross(&midpoint[1], ¢er, &normal[1]); ++ vNormalize(&normal[0]); ++ ++ vCross(¢er, &midpoint[3], &normal[3]); ++ vNormalize(&normal[0]); ++ ++ ++ // The dot product of these with the point of interest vector ++ // tells us which half of the cell that point is in ++ ++ if(debug > 1) ++ { ++ vPrint(&ref, "ref"); ++ vPrint(&normal[0], "normal[0]"); ++ vPrint(&normal[1], "normal[1]"); ++ vPrint(&normal[2], "normal[2]"); ++ vPrint(&normal[3], "normal[3]"); ++ } ++ ++ direction[0] = vDot(&normal[0], &ref); ++ direction[1] = vDot(&normal[1], &ref); ++ direction[2] = vDot(&normal[2], &ref); ++ direction[3] = vDot(&normal[3], &ref); ++ ++ if(debug > 1) ++ printf("DIRECTIONS> %.4f %.4f %.4d %.4f\n", direction[0], direction[1], direction[2], direction[3]); ++ ++ ++ // Use this to define the next level down ++ ++ if(direction[0] >= 0. && direction[3] >= 0.) // Upper left (00) ++ { ++ if(debug > 1) ++ printf("TOAFWD> Level %2d, Subquadrant 00\n", level); ++ ++ index = (index << 2) + 0b00; ++ ++ if(prime == 0) prime = 0; ++ else if(opposite == 0) prime = 0; ++ else prime = 1; ++ ++ //-- ++ vCopy(&midpoint[0], &corner[1]); ++ vCopy( ¢er, &corner[2]); ++ vCopy(&midpoint[3], &corner[3]); ++ } ++ ++ if(direction[0] < 0. && direction[1] >= 0.) // Upper right (01) ++ { ++ if(debug > 1) ++ printf("TOAFWD> Level %2d, Subquadrant 01\n", level); ++ ++ index = (index << 2) + 0b01; ++ ++ if(prime == 1) prime = 1; ++ else if(opposite == 1) prime = 1; ++ else prime = 0; ++ ++ vCopy(&midpoint[0], &corner[0]); ++ //-- ++ vCopy(&midpoint[1], &corner[2]); ++ vCopy( ¢er, &corner[3]); ++ } ++ ++ if(direction[2] >= 0. && direction[3] < 0.) // Lower left (10) ++ { ++ if(debug > 1) ++ printf("TOAFWD> Level %2d, Subquadrant 10\n", level); ++ ++ index = (index << 2) + 0b10; ++ ++ if(prime == 3) prime = 3; ++ else if(opposite == 3) prime = 3; ++ else prime = 0; ++ ++ vCopy(&midpoint[3], &corner[0]); ++ vCopy( ¢er, &corner[1]); ++ vCopy(&midpoint[2], &corner[2]); ++ //-- ++ } ++ ++ if(direction[2] < 0. && direction[1] < 0.) // Lower right (11) ++ { ++ if(debug > 1) ++ printf("TOAFWD> Level %2d: Subquadrant 11\n", level); ++ ++ index = (index << 2) + 0b11; ++ ++ if(prime == 2) prime = 2; ++ else if(opposite == 2) prime = 2; ++ else prime = 1; ++ ++ vCopy( ¢er, &corner[0]); ++ vCopy(&midpoint[1], &corner[1]); ++ //-- ++ vCopy(&midpoint[2], &corner[3]); ++ } ++ ++ if(debug > 1) ++ { ++ vPrint(&corner[0], "corner[0]"); ++ vPrint(&corner[1], "corner[1]"); ++ vPrint(&corner[2], "corner[2]"); ++ vPrint(&corner[3], "corner[3]"); ++ ++ printf("prime = %d\n", prime); ++ } ++ ++ ++level; ++ } ++ ++ ++ splitIndex(index, level, &xindex, &yindex); ++ ++ *x = (double)xindex * (double)npix / (double)maxindex; ++ *y = (double)yindex * (double)npix / (double)maxindex; ++ ++ if(debug) ++ { ++ printf("TOAFWD> (lon, lat):(%10.6f, %10.6f) -> (xpix, ypix):(%9.4f, %9.4f) fraction of image:[%.3f,%.3f]\n", ++ ref.lon, ref.lat, *x+0.5, *y+0.5, *x/npix, *y/npix); ++ fflush(stdout); ++ } ++ ++ ++ // FITS pixel coordinates start at 0.5 ++ // (so the center of the first pixel is at 1.0) ++ ++ *x += 1.0; ++ *y += 1.0; ++ ++ return(0); ++} ++ ++/*--------------------------------------------------------------------------*/ ++ ++int toarev(x, y, prj, phi, theta) ++ ++const double x, y; ++struct prjprm *prj; ++double *phi, *theta; ++{ ++ Vec ref; ++ Vec center; ++ Vec corner [4]; ++ Vec midpoint[4]; ++ ++ unsigned long index, maxindex, currindex; ++ ++ int debug = 0; ++ ++ int i, npix, level, maxlevel; ++ int xindex, yindex; ++ int xsplit, ysplit; ++ int prime, opposite; ++ ++ double size; ++ ++ if(debug > 1) ++ printf("\nTOAREV> X = %9.4f Y = %9.4f\n\n", x, y); ++ ++ if( prj->flag != TOA ) ++ if( toaset( prj ) ) ++ return 1; ++ ++ ++ // We calculate down to level 27 to allow ++ // for fraction pixel coordinates ++ ++ maxlevel = 27; ++ ++ maxindex = 0b1 << maxlevel; ++ ++ ++ // Get the level of the map ++ // This determines how many pixels there are in the map ++ ++ level = (int)prj->p[1]; ++ ++ npix = 0b1 << (level + 8); ++ ++ if(x < 0) return 2; ++ if(x > npix+1) return 2; ++ if(y < 0) return 2; ++ if(y > npix+1) return 2; ++ ++ xindex = (x-1.0) / npix * maxindex + 0.5; ++ yindex = (y-1.0) / npix * maxindex + 0.5; ++ ++ if(debug > 1) ++ { ++ printf("TOAREV> xindex = %o\n", xindex); ++ printf("TOAREV> yindex = %o\n\n", yindex); ++ } ++ ++ ++ currindex = maxlevel; ++ ++ xsplit = xindex >> (currindex-1) & 0b1; ++ ysplit = yindex >> (currindex-1) & 0b1; ++ ++ ++ // The first level has to be done by hand ++ ++ if(xsplit == 0 && ysplit == 0) // quadrant 00 [0] ++ { ++ if(debug > 1) ++ printf("TOAREV> Quadrant 00\n\n"); ++ ++ corner[0].lon = 0.; ++ corner[0].lat = -90.; ++ ++ corner[1].lon = 270.; ++ corner[1].lat = 0.; ++ ++ corner[2].lon = 0.; ++ corner[2].lat = 90.; ++ ++ corner[3].lon = 180.; ++ corner[3].lat = 0.; ++ ++ prime = 1; ++ } ++ ++ else if(xsplit == 1 && ysplit == 0) // quadrant 01 [1] ++ { ++ if(debug > 1) ++ printf("TOAREV> Quadrant 01\n\n"); ++ ++ corner[0].lon = 270.; ++ corner[0].lat = 0.; ++ ++ corner[1].lon = 0.; ++ corner[1].lat = -90.; ++ ++ corner[2].lon = 0.; ++ corner[2].lat = 0.; ++ ++ corner[3].lon = 0.; ++ corner[3].lat = 90.; ++ ++ prime = 0; ++ } ++ ++ else if(xsplit == 0 && ysplit == 1) // quadrant 10 [2] ++ { ++ if(debug > 1) ++ printf("TOAREV> Quadrant 10\n\n"); ++ ++ corner[0].lon = 180.; ++ corner[0].lat = 0.; ++ ++ corner[1].lon = 0.; ++ corner[1].lat = 90.; ++ ++ corner[2].lon = 90.; ++ corner[2].lat = 0.; ++ ++ corner[3].lon = 0.; ++ corner[3].lat = -90.; ++ ++ prime = 0; ++ } ++ ++ else // quadrant 11 [3] ++ { ++ if(debug > 1) ++ printf("TOAREV> Quadrant 11\n\n"); ++ ++ corner[0].lon = 0.; ++ corner[0].lat = 90.; ++ ++ corner[1].lon = 0.; ++ corner[1].lat = 0.; ++ ++ corner[2].lon = 0.; ++ corner[2].lat = -90.; ++ ++ corner[3].lon = 90.; ++ corner[3].lat = 0.; ++ ++ prime = 1; ++ } ++ ++ level = 1; ++ ++ vCalcXYZ(&corner[0]); ++ vCalcXYZ(&corner[1]); ++ vCalcXYZ(&corner[2]); ++ vCalcXYZ(&corner[3]); ++ ++ if(debug > 1) ++ { ++ vPrint(&corner[0], "corner[0]"); ++ vPrint(&corner[1], "corner[1]"); ++ vPrint(&corner[2], "corner[2]"); ++ vPrint(&corner[3], "corner[3]"); ++ } ++ ++ // Drill down level by level ++ ++ while(level < maxlevel) ++ { ++ // Find cell edge midpoints ++ ++ vMidpoint(&corner[1], &corner[0], &midpoint[0]); ++ vMidpoint(&corner[2], &corner[1], &midpoint[1]); ++ vMidpoint(&corner[3], &corner[2], &midpoint[2]); ++ vMidpoint(&corner[0], &corner[3], &midpoint[3]); ++ ++ if(debug > 1) ++ { ++ vPrint(&midpoint[0], "midpoint[0]"); ++ vPrint(&midpoint[1], "midpoint[1]"); ++ vPrint(&midpoint[2], "midpoint[2]"); ++ vPrint(&midpoint[3], "midpoint[3]"); ++ } ++ ++ ++ // We also need the center point (midpoint of the HTM diagonal) ++ ++ opposite = (prime + 2) % 4; ++ ++ vMidpoint(&corner[prime], &corner[opposite], ¢er); ++ ++ if(debug > 1) ++ { ++ vPrint(&corner[prime], "Prime"); ++ vPrint(&corner[opposite], "Opposite"); ++ vPrint(¢er, "center"); ++ } ++ ++ ++ // The next level up in xindex and yindex tells ++ // us which half of the cell that point is in ++ ++ currindex -= 1; ++ ++ xsplit = xindex >> (currindex-1) & 0b1; ++ ysplit = yindex >> (currindex-1) & 0b1; ++ ++ ++ // Use this to define the next level down ++ ++ if(ysplit == 0 && xsplit == 0) // Upper left (00) ++ { ++ if(debug > 1) ++ printf("TOAREV> Level %2d, Subquadrant 00\n", level); ++ ++ if(prime == 0) prime = 0; ++ else if(opposite == 0) prime = 0; ++ else prime = 1; ++ ++ //-- ++ vCopy(&midpoint[0], &corner[1]); ++ vCopy( ¢er, &corner[2]); ++ vCopy(&midpoint[3], &corner[3]); ++ } ++ ++ else if(ysplit == 0 && xsplit == 1) // Upper right (01) ++ { ++ if(debug > 1) ++ printf("TOAREV> Level %2d, Subquadrant 01\n", level); ++ ++ if(prime == 1) prime = 1; ++ else if(opposite == 1) prime = 1; ++ else prime = 0; ++ ++ vCopy(&midpoint[0], &corner[0]); ++ //-- ++ vCopy(&midpoint[1], &corner[2]); ++ vCopy( ¢er, &corner[3]); ++ } ++ ++ else if(ysplit == 1 && xsplit == 0) // Lower left (10) ++ { ++ if(debug > 1) ++ printf("TOAREV> Level %2d, Subquadrant 10\n", level); ++ ++ if(prime == 3) prime = 3; ++ else if(opposite == 3) prime = 3; ++ else prime = 0; ++ ++ vCopy(&midpoint[3], &corner[0]); ++ vCopy( ¢er, &corner[1]); ++ vCopy(&midpoint[2], &corner[2]); ++ //-- ++ } ++ ++ else // Lower right (11) ++ { ++ if(debug > 1) ++ printf("TOAREV> Level %2d, Subquadrant 11\n", level); ++ ++ if(prime == 2) prime = 2; ++ else if(opposite == 2) prime = 2; ++ else prime = 1; ++ ++ vCopy( ¢er, &corner[0]); ++ vCopy(&midpoint[1], &corner[1]); ++ //-- ++ vCopy(&midpoint[2], &corner[3]); ++ } ++ ++ if(debug > 1) ++ { ++ vPrint(&corner[0], "corner[0]"); ++ vPrint(&corner[1], "corner[1]"); ++ vPrint(&corner[2], "corner[2]"); ++ vPrint(&corner[3], "corner[3]"); ++ ++ printf("prime = %d\n", prime); ++ } ++ ++ ++level; ++ } ++ ++ ++ vPixCenter(&corner[0], &corner[1], &corner[2], &corner[3], &ref); ++ ++ vCalcRADec(&ref); ++ ++ *phi = ref.lon; ++ *theta = ref.lat; ++ ++ if(debug) ++ { ++ printf("TOAREV> (lon, lat):(%10.6f, %10.6f) <- (xpix, ypix):(%9.4f, %9.4f)\n", ++ *phi, *theta, x, y); ++ fflush(stdout); ++ } ++ ++ return(0); ++} ++ ++ ++ + /* This routine comes from E. Bertin sextractor-2.8.6 */ + + int +@@ -4506,6 +5639,230 @@ poly_end: + return 0; + } + ++/***************************************************/ ++/* */ ++/* vCopy() */ ++/* */ ++/* Copy the contents of one vector to another */ ++/* */ ++/***************************************************/ ++ ++void vCopy(Vec *v, Vec *c) ++{ ++ c->lon = v->lon; ++ c->lat = v->lat; ++ ++ c->x = v->x; ++ c->y = v->y; ++ c->z = v->z; ++ ++ return; ++} ++ ++ ++ ++/***************************************************/ ++/* */ ++/* vCalcRADec() */ ++/* */ ++/* Update vector with RA and Dec based on x,y,z */ ++/* */ ++/***************************************************/ ++ ++void vCalcRADec(Vec *v) ++{ ++ v->lon = atan2(v->y, v->x)/deg2rad; ++ v->lat = asin(v->z)/deg2rad; ++ ++ while(v->lon >= 360.) v->lon -= 360.; ++ while(v->lon < 0.) v->lon += 360.; ++ ++ return; ++} ++ ++ ++ ++/***************************************************/ ++/* */ ++/* vCalcXYZ() */ ++/* */ ++/* Update vector with x,y,z based on RA,Dec */ ++/* */ ++/***************************************************/ ++ ++void vCalcXYZ(Vec *v) ++{ ++ v->x = cos(v->lat * deg2rad) * cos(v->lon * deg2rad); ++ v->y = cos(v->lat * deg2rad) * sin(v->lon * deg2rad); ++ v->z = sin(v->lat * deg2rad); ++ ++ return; ++} ++ ++ ++ ++/***************************************************/ ++/* */ ++/* vMidpoint() */ ++/* */ ++/* Finds the midpoint between two points on the */ ++/* sky. */ ++/* */ ++/***************************************************/ ++ ++void vMidpoint(Vec *a, Vec *b, Vec *c) ++{ ++ c->x = a->x + b->x; ++ c->y = a->y + b->y; ++ c->z = a->z + b->z; ++ ++ vNormalize(c); ++ ++ return; ++} ++ ++ ++ ++/***************************************************/ ++/* */ ++/* vPixCenter() */ ++/* */ ++/* Finds the center of a a pixel (four corners) */ ++/* on the sky. */ ++/* */ ++/***************************************************/ ++ ++void vPixCenter(Vec *a, Vec *b, Vec *c, Vec *d, Vec *v) ++{ ++ v->x = a->x + b->x + c->x + d->x; ++ v->y = a->y + b->y + c->y + d->y; ++ v->z = a->z + b->z + c->z + d->z; ++ ++ vNormalize(v); ++ ++ return; ++} ++ ++ ++ ++/***************************************************/ ++/* */ ++/* vCross() */ ++/* */ ++/* Vector cross product. */ ++/* */ ++/***************************************************/ ++ ++int vCross(Vec *v1, Vec *v2, Vec *v3) ++{ ++ v3->x = v1->y*v2->z - v2->y*v1->z; ++ v3->y = -v1->x*v2->z + v2->x*v1->z; ++ v3->z = v1->x*v2->y - v2->x*v1->y; ++ ++ if(v3->x == 0. ++ && v3->y == 0. ++ && v3->z == 0.) ++ return 0; ++ ++ return 1; ++} ++ ++ ++/***************************************************/ ++/* */ ++/* vDot() */ ++/* */ ++/* Vector dot product. */ ++/* */ ++/***************************************************/ ++ ++double vDot(Vec *a, Vec *b) ++{ ++ double sum; ++ ++ sum = a->x * b->x ++ + a->y * b->y ++ + a->z * b->z; ++ ++ return sum; ++} ++ ++ ++/***************************************************/ ++/* */ ++/* vNormalize() */ ++/* */ ++/* Normalize the vector */ ++/* */ ++/***************************************************/ ++ ++double vNormalize(Vec *v) ++{ ++ double len; ++ ++ len = 0.; ++ ++ len = sqrt(v->x * v->x + v->y * v->y + v->z * v->z); ++ ++ if(len == 0.) ++ len = 1.; ++ ++ v->x = v->x / len; ++ v->y = v->y / len; ++ v->z = v->z / len; ++ ++ return len; ++} ++ ++ ++/***************************************************/ ++/* */ ++/* vPrint() */ ++/* */ ++/* Print out vector (for debugging) */ ++/* */ ++/***************************************************/ ++ ++double vPrint(Vec *v, char *label) ++{ ++ vCalcRADec(v); ++ ++ printf("VECTOR> %9.6f %9.6f %9.6f -> %10.6f %10.6f (%s)\n", ++ v->x, v->y, v->z, v->lon, v->lat, label); ++ fflush(stdout); ++} ++ ++ ++/***************************************************/ ++/* */ ++/* splitIndex() */ ++/* */ ++/* Cell indices are Z-order binary constructs. */ ++/* The x and y pixel offsets are constructed by */ ++/* extracting the pattern made by every other bit */ ++/* to make new binary numbers. */ ++/* */ ++/***************************************************/ ++ ++void splitIndex(unsigned long index, int level, int *x, int *y) ++{ ++ int i; ++ unsigned long val; ++ ++ val = index; ++ ++ *x = 0; ++ *y = 0; ++ ++ for(i=0; i> (2*i)) & 0b1) << i); ++ *y = *y + (((val >> (2*i+1)) & 0b1) << i); ++ } ++ ++ return; ++} ++ + /* Dec 20 1999 Doug Mink - Change cosd() and sind() to cosdeg() and sindeg() + * Dec 20 1999 Doug Mink - Include wcslib.h, which includes proj.h, wcsmath.h + * Dec 20 1999 Doug Mink - Define copysign only if it is not defined +@@ -4524,4 +5881,6 @@ poly_end: + * + * Mar 14 2011 Doug Mink - If no coefficients in ZPN, make ARC + * Mar 14 2011 Doug Mink - Add Emmanuel Bertin's TAN polynomial from Ed Los ++ * Dec 22 2016 John Good - Support for HEALPix and TOAST + */ ++ +diff --git a/libwcs/wcs.c b/libwcs/wcs.c +index 84cfb16..2d43d69 100644 +--- a/libwcs/wcs.c ++++ b/libwcs/wcs.c +@@ -375,13 +375,16 @@ char *ctype2; /* FITS WCS projection for axis 2 */ + strcpy (ctypes[24], "CSC"); + strcpy (ctypes[25], "QSC"); + strcpy (ctypes[26], "TSC"); +- strcpy (ctypes[27], "NCP"); +- strcpy (ctypes[28], "GLS"); +- strcpy (ctypes[29], "DSS"); +- strcpy (ctypes[30], "PLT"); +- strcpy (ctypes[31], "TNX"); +- strcpy (ctypes[32], "ZPX"); +- strcpy (ctypes[33], "TPV"); ++ strcpy (ctypes[27], "HPX"); ++ strcpy (ctypes[28], "XPH"); ++ strcpy (ctypes[29], "NCP"); ++ strcpy (ctypes[30], "GLS"); ++ strcpy (ctypes[31], "DSS"); ++ strcpy (ctypes[32], "PLT"); ++ strcpy (ctypes[33], "TNX"); ++ strcpy (ctypes[34], "ZPX"); ++ strcpy (ctypes[35], "TPV"); ++ strcpy (ctypes[36], "TOA"); + + /* Initialize distortion types */ + strcpy (dtypes[1], "SIP"); +diff --git a/libwcs/wcs.h b/libwcs/wcs.h +index 0d69049..3ef1695 100644 +--- a/libwcs/wcs.h ++++ b/libwcs/wcs.h +@@ -192,14 +192,17 @@ struct WorldCoor { + #define WCS_CSC 24 /* COBE quadrilateralized Spherical Cube */ + #define WCS_QSC 25 /* Quadrilateralized Spherical Cube */ + #define WCS_TSC 26 /* Tangential Spherical Cube */ +-#define WCS_NCP 27 /* Special case of SIN from AIPS*/ +-#define WCS_GLS 28 /* Same as SFL from AIPS*/ +-#define WCS_DSS 29 /* Digitized Sky Survey plate solution */ +-#define WCS_PLT 30 /* Plate fit polynomials (SAO) */ +-#define WCS_TNX 31 /* Tangent Plane (NOAO corrections) */ +-#define WCS_ZPX 32 /* Zenithal Azimuthal Polynomial (NOAO corrections) */ +-#define WCS_TPV 33 /* Tangent Plane (SCAMP corrections) */ +-#define NWCSTYPE 34 /* Number of WCS types (-1 really means no WCS) */ ++#define WCS_HPX 27 /* Tangential Spherical Cube */ ++#define WCS_XPH 28 /* Tangential Spherical Cube */ ++#define WCS_NCP 29 /* Special case of SIN from AIPS*/ ++#define WCS_GLS 30 /* Same as SFL from AIPS*/ ++#define WCS_DSS 31 /* Digitized Sky Survey plate solution */ ++#define WCS_PLT 32 /* Plate fit polynomials (SAO) */ ++#define WCS_TNX 33 /* Tangent Plane (NOAO corrections) */ ++#define WCS_ZPX 34 /* Zenithal Azimuthal Polynomial (NOAO corrections) */ ++#define WCS_TPV 35 /* Tangent Plane (SCAMP corrections) */ ++#define WCS_TOA 36 /* TOAST */ ++#define NWCSTYPE 37 /* Number of WCS types (-1 really means no WCS) */ + + /* Coordinate systems */ + #define WCS_J2000 1 /* J2000(FK5) right ascension and declination */ +diff --git a/libwcs/wcsinit.c b/libwcs/wcsinit.c +index c184ca0..e8d40db 100644 +--- a/libwcs/wcsinit.c ++++ b/libwcs/wcsinit.c +@@ -536,6 +536,14 @@ char *wchar; /* Suffix character for one of multiple WCS */ + hgetr8c (hstring, keyword, &mchar, &wcs->prj.p[i]); + } + } ++ else if (wcs->prjcode == WCS_HPX) { ++ hgetr8c (hstring, "PV2_1", &mchar, &wcs->prj.p[1]); ++ hgetr8c (hstring, "PV2_2", &mchar, &wcs->prj.p[2]); ++ } ++ ++ else if (wcs->prjcode == WCS_TOA) { ++ hgetr8c (hstring, "PV2_1", &mchar, &wcs->prj.p[1]); ++ } + + /* Initialize TNX, defaulting to TAN if there is a problem */ + if (wcs->prjcode == WCS_TNX) { +diff --git a/libwcs/wcslib.h b/libwcs/wcslib.h +index 7b10f9a..0603da8 100644 +--- a/libwcs/wcslib.h ++++ b/libwcs/wcslib.h +@@ -109,7 +109,7 @@ extern void poly_addcste(polystruct *poly, double *cste), + #endif + + extern int npcode; +-extern char pcodes[26][4]; ++extern char pcodes[29][4]; + + struct prjprm { + char code[4]; +@@ -219,6 +219,15 @@ struct prjprm { + int qscset(struct prjprm *); + int qscfwd(const double, const double, struct prjprm *, double *, double *); + int qscrev(const double, const double, struct prjprm *, double *, double *); ++ int hpxset(struct prjprm *); ++ int hpxfwd(const double, const double, struct prjprm *, double *, double *); ++ int hpxrev(const double, const double, struct prjprm *, double *, double *); ++ int xphset(struct prjprm *); ++ int xphfwd(const double, const double, struct prjprm *, double *, double *); ++ int xphrev(const double, const double, struct prjprm *, double *, double *); ++ int toaset(struct prjprm *); ++ int toafwd(const double, const double, struct prjprm *, double *, double *); ++ int toarev(const double, const double, struct prjprm *, double *, double *); + int raw_to_pv(struct prjprm *prj, double x, double y, double *xo, double *yo); + #else + int prjset(), prjfwd(), prjrev(); +-- +2.11.0 + + diff -Nru wcstools-3.9.5/libwcs/healpix.doc wcstools-3.9.6/libwcs/healpix.doc --- wcstools-3.9.5/libwcs/healpix.doc 1970-01-01 00:00:00.000000000 +0000 +++ wcstools-3.9.6/libwcs/healpix.doc 2017-07-31 21:55:18.000000000 +0000 @@ -0,0 +1,43 @@ +Dear Jessica, + +when I upgraded the "Montage" Debian package to the new version 5.0, I +discovered that it uses a slightly modified version of wcstools. +Specifically it contains support for HEALPix and TOAST. + +To me, this extension looks quite straightforward, and it would enable +to use HEALPix in the wcstools executable and also in other tools that +link to wcstools, like DS9. For Debian, this patch would be important +since it enables the Debian version of Montage to support Healpix and +Toast -- we are dynamically linking the original version of the wcstools +lib instead of the patched copy in Montage. + +Would you consider adding to the next version of wcstools? Or could I +initiate a discussion about what would need to be changed to get it +there? The author of wcstools is John Good (in Cc), and the github web +page is + +https://github.com/Caltech-IPAC/Montage + +The patch (rebased to the current version 3.9.4 of wcstools) is attached. + +Thank you very much +Best regards + +Ole + +P.S. There is still the issue with the amoeba from Numerical Recipes... + + +wcstools-Support-for-HEALPix-and-TOAST.patch + +>From d6522fd9f08a96d247a3f4c23b6ed0d444d50b7a Mon Sep 17 00:00:00 2001 +From: Ole Streicher +Date: Mon, 30 Jan 2017 17:52:38 +0100 +Subject: [PATCH] Support for HEALPix and TOAST + +Montage treats HEALPix and TOAST as if they were spherical projections +that can processed with the existing reprojection routines. + +These are the changes made by John C Good +(probably) for the Montage release 5.0. They are rebased here to +wcstools 3.9.4. diff -Nru wcstools-3.9.5/libwcs/hget1.c wcstools-3.9.6/libwcs/hget1.c --- wcstools-3.9.5/libwcs/hget1.c 1970-01-01 00:00:00.000000000 +0000 +++ wcstools-3.9.6/libwcs/hget1.c 2018-11-23 18:04:12.000000000 +0000 @@ -0,0 +1,1991 @@ +/*** File libwcs/hget.c + *** August 27, 2018 + *** By Jessica Mink, jmink@cfa.harvard.edu + *** Harvard-Smithsonian Center for Astrophysics + *** Copyright (C) 1994-2018 + *** Smithsonian Astrophysical Observatory, Cambridge, MA, USA + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Correspondence concerning WCSTools should be addressed as follows: + Internet email: jmink@cfa.harvard.edu + Postal address: Jessica Mink + Smithsonian Astrophysical Observatory + 60 Garden St. + Cambridge, MA 02138 USA + + * Module: hget.c (Get FITS Header parameter values) + * Purpose: Extract values for variables from FITS header string + * Subroutine: hgeti2 (hstring,keyword,ival) returns short integer + * Subroutine: hgeti4c (hstring,keyword,wchar,ival) returns long integer + * Subroutine: hgeti4 (hstring,keyword,ival) returns long integer + * Subroutine: hgetr4 (hstring,keyword,rval) returns real + * Subroutine: hgetra (hstring,keyword,ra) returns double RA in degrees + * Subroutine: hgetdec (hstring,keyword,dec) returns double Dec in degrees + * Subroutine: hgetr8c (hstring,keyword,wchar,dval) returns double + * Subroutine: hgetr8 (hstring,keyword,dval) returns double + * Subroutine: hgetl (hstring,keyword,lval) returns logical int (0=F, 1=T) + * Subroutine: hgetsc (hstring,keyword,wchar,lstr,str) returns character string + * Subroutine: hgets (hstring,keyword, lstr, str) returns character string + * Subroutine: hgetm (hstring,keyword, lstr, str) returns multi-keyword string + * Subroutine: hgetdate (hstring,keyword,date) returns date as fractional year + * Subroutine: hgetndec (hstring, keyword, ndec) returns number of dec. places + * Subroutine: hgetc (hstring,keyword) returns character string + * Subroutine: blsearch (hstring,keyword) returns pointer to blank lines + before keyword + * Subroutine: ksearch (hstring,keyword) returns pointer to header string entry + * Subroutine: str2ra (in) converts string to right ascension in degrees + * Subroutine: str2dec (in) converts string to declination in degrees + * Subroutine: strsrch (s1, s2) finds string s2 in null-terminated string s1 + * Subroutine: strnsrch (s1, s2, ls1) finds string s2 in ls1-byte string s1 + * Subroutine: hlength (header,lhead) sets length of FITS header for searching + * Subroutine: isnum (string) returns 1 if integer, 2 if fp number, + * 3 if hh:mm:dd.ss time, 4 if yyyy-mm-dd date, else 0 + * Subroutine: notnum (string) returns 0 if number, else 1 + * Subroutine: numdec (string) returns number of decimal places in numeric string + * Subroutine: strfix (string,blankfill,zerodrop) removes extraneous characters + */ + +#include /* NULL, strlen, strstr, strcpy */ +#include +#include "fitshead.h" /* FITS header extraction subroutines */ +#include +#ifndef VMS +#include +#else +#define INT_MAX 2147483647 /* Biggest number that can fit in long */ +#define SHRT_MAX 32767 +#endif +#define VLENGTH 81 + +#ifdef USE_SAOLIB +static int use_saolib=0; +#endif + +char *hgetc (); + +static char val[VLENGTH+1]; +static int multiline = 0; + +static int lhead0 = 0; /* Length of header string */ + +/* Set the length of the header string, if not terminated by NULL */ +int +hlength (header, lhead) +const char *header; /* FITS header */ +int lhead; /* Maximum length of FITS header */ +{ + char *hend; + if (lhead > 0) + lhead0 = lhead; + else { + lhead0 = 0; + hend = ksearch (header,"END"); + lhead0 = hend + 80 - header; + } + return (lhead0); +} + +/* Return the length of the header string, computing it if lhead0 not set */ +int +gethlength (header) +char *header; /* FITS header */ +{ + if (lhead0 > 0) + return (lhead0); + else + return (hlength (header, 0)); +} + + +/* Extract Integer*4 value for variable from FITS header string */ + +int +hgeti4c (hstring,keyword,wchar,ival) + +const char *hstring; /* character string containing FITS header information + in the format = {/ } */ +const char *keyword; /* character string containing the name of the keyword + the value of which is returned. hget searches for + a line beginning with this string. if "[n]" is + present, the n'th token in the value is returned. + (the first 8 characters must be unique) */ +const char *wchar; /* Character of multiple WCS header; =0 if unused */ +int *ival; /* Keyword value returned */ +{ + char keyword1[64]; + int lkey; + + if (wchar[0] < (char) 64) + return (hgeti4 (hstring, keyword, ival)); + else { + strcpy (keyword1, keyword); + lkey = strlen (keyword); + keyword1[lkey] = wchar[0]; + keyword1[lkey+1] = (char) 0; + return (hgeti4 (hstring, keyword1, ival)); + } +} + + +/* Extract long value for variable from FITS header string */ + +int +hgeti4 (hstring,keyword,ival) + +const char *hstring; /* character string containing FITS header information + in the format = {/ } */ +const char *keyword; /* character string containing the name of the keyword + the value of which is returned. hget searches for a + line beginning with this string. if "[n]" is present, + the n'th token in the value is returned. + (the first 8 characters must be unique) */ +int *ival; +{ + char *value; + double dval; + int minint; + int lval; + char *dchar; + + /* Get value and comment from header string */ + value = hgetc (hstring,keyword); + + /* Translate value from ASCII to binary */ + if (value != NULL) { + if (value[0] == '#') value++; + minint = -INT_MAX - 1; + lval = strlen (value); + if (lval > VLENGTH) { + strncpy (val, value, VLENGTH); + val[VLENGTH] = (char) 0; + } + else + strcpy (val, value); + if (isnum (val) == 2) { + if ((dchar = strchr (val, 'D'))) + *dchar = 'e'; + if ((dchar = strchr (val, 'd'))) + *dchar = 'e'; + if ((dchar = strchr (val, 'E'))) + *dchar = 'e'; + } + dval = atof (val); + if (dval+0.001 > INT_MAX) + *ival = INT_MAX; + else if (dval >= 0) + *ival = (int) (dval + 0.001); + else if (dval-0.001 < minint) + *ival = minint; + else + *ival = (int) (dval - 0.001); + return (1); + } + else { + return (0); + } +} + + +/* Extract integer*2 value for variable from fits header string */ + +int +hgeti2 (hstring,keyword,ival) + +const char *hstring; /* character string containing FITS header information + in the format = {/ } */ +const char *keyword; /* character string containing the name of the keyword + the value of which is returned. hget searches for a + line beginning with this string. if "[n]" is present, + the n'th token in the value is returned. + (the first 8 characters must be unique) */ +short *ival; +{ + char *value; + double dval; + int minshort; + int lval; + char *dchar; + + /* Get value and comment from header string */ + value = hgetc (hstring,keyword); + + /* Translate value from ASCII to binary */ + if (value != NULL) { + if (value[0] == '#') value++; + lval = strlen (value); + if (lval > VLENGTH) { + strncpy (val, value, VLENGTH); + val[VLENGTH] = (char) 0; + } + else + strcpy (val, value); + if (isnum (val) == 2) { + if ((dchar = strchr (val, 'D'))) + *dchar = 'e'; + if ((dchar = strchr (val, 'd'))) + *dchar = 'e'; + if ((dchar = strchr (val, 'E'))) + *dchar = 'e'; + } + dval = atof (val); + minshort = -SHRT_MAX - 1; + if (dval+0.001 > SHRT_MAX) + *ival = SHRT_MAX; + else if (dval >= 0) + *ival = (short) (dval + 0.001); + else if (dval-0.001 < minshort) + *ival = minshort; + else + *ival = (short) (dval - 0.001); + return (1); + } + else { + return (0); + } +} + +/* Extract real value for variable from FITS header string */ + +int +hgetr4 (hstring,keyword,rval) + +const char *hstring; /* character string containing FITS header information + in the format = {/ } */ +const char *keyword; /* character string containing the name of the keyword + the value of which is returned. hget searches for a + line beginning with this string. if "[n]" is present, + the n'th token in the value is returned. + (the first 8 characters must be unique) */ +float *rval; +{ + char *value; + int lval; + char *dchar; + + /* Get value and comment from header string */ + value = hgetc (hstring,keyword); + + /* translate value from ASCII to binary */ + if (value != NULL) { + if (value[0] == '#') value++; + lval = strlen (value); + if (lval > VLENGTH) { + strncpy (val, value, VLENGTH); + val[VLENGTH] = (char) 0; + } + else + strcpy (val, value); + if (isnum (val) == 2) { + if ((dchar = strchr (val, 'D'))) + *dchar = 'e'; + if ((dchar = strchr (val, 'd'))) + *dchar = 'e'; + if ((dchar = strchr (val, 'E'))) + *dchar = 'e'; + } + *rval = (float) atof (val); + return (1); + } + else { + return (0); + } +} + + +/* Extract real*8 right ascension in degrees from FITS header string */ + +int +hgetra (hstring,keyword,dval) + +const char *hstring; /* character string containing FITS header information + in the format = {/ } */ +const char *keyword; /* character string containing the name of the keyword + the value of which is returned. hget searches for a + line beginning with this string. if "[n]" is present, + the n'th token in the value is returned. + (the first 8 characters must be unique) */ +double *dval; /* Right ascension in degrees (returned) */ +{ + char *value; + + /* Get value from header string */ + value = hgetc (hstring,keyword); + + /* Translate value from ASCII colon-delimited string to binary */ + if (value != NULL) { + *dval = str2ra (value); + return (1); + } + else + return (0); +} + + +/* Extract real*8 declination in degrees from FITS header string */ + +int +hgetdec (hstring,keyword,dval) + +const char *hstring; /* character string containing FITS header information + in the format = {/ } */ +const char *keyword; /* character string containing the name of the keyword + the value of which is returned. hget searches for a + line beginning with this string. if "[n]" is present, + the n'th token in the value is returned. + (the first 8 characters must be unique) */ +double *dval; /* Right ascension in degrees (returned) */ +{ + char *value; + + /* Get value from header string */ + value = hgetc (hstring,keyword); + + /* Translate value from ASCII colon-delimited string to binary */ + if (value != NULL) { + *dval = str2dec (value); + return (1); + } + else + return (0); +} + + +/* Extract real*8 value for variable from FITS header string */ + +int +hgetr8c (hstring,keyword,wchar,dval) + +const char *hstring; /* character string containing FITS header information + in the format = {/ } */ +const char *keyword; /* character string containing the name of the keyword + the value of which is returned. hget searches for + a line beginning with this string. if "[n]" is + present, the n'th token in the value is returned. + (the first 8 characters must be unique) */ +const char *wchar; /* Character of multiple WCS header; =0 if unused */ +double *dval; /* Keyword value returned */ +{ + char keyword1[64]; + int lkey; + + if (wchar[0] < (char) 64) + return (hgetr8 (hstring, keyword, dval)); + else { + strcpy (keyword1, keyword); + lkey = strlen (keyword); + keyword1[lkey] = wchar[0]; + keyword1[lkey+1] = (char) 0; + return (hgetr8 (hstring, keyword1, dval)); + } +} + + + +/* Extract real*8 value for variable from FITS header string */ + +int +hgetr8 (hstring,keyword,dval) + +const char *hstring; /* character string containing FITS header information + in the format = {/ } */ +const char *keyword; /* character string containing the name of the keyword + the value of which is returned. hget searches for a + line beginning with this string. if "[n]" is present, + the n'th token in the value is returned. + (the first 8 characters must be unique) */ +double *dval; +{ + char *value; + int lval; + char *dchar; + + /* Get value and comment from header string */ + value = hgetc (hstring,keyword); + + /* Translate value from ASCII to binary */ + if (value != NULL) { + if (value[0] == '#') value++; + lval = strlen (value); + if (lval > VLENGTH) { + strncpy (val, value, VLENGTH); + val[VLENGTH] = (char) 0; + } + else + strcpy (val, value); + if (isnum (val) == 2) { + if ((dchar = strchr (val, 'D'))) + *dchar = 'e'; + if ((dchar = strchr (val, 'd'))) + *dchar = 'e'; + if ((dchar = strchr (val, 'E'))) + *dchar = 'e'; + } + *dval = atof (val); + return (1); + } + else { + return (0); + } +} + + +/* Extract logical value for variable from FITS header string */ + +int +hgetl (hstring,keyword,ival) + +const char *hstring; /* character string containing FITS header information + in the format = {/ } */ +const char *keyword; /* character string containing the name of the keyword + the value of which is returned. hget searches for a + line beginning with this string. if "[n]" is present, + the n'th token in the value is returned. + (the first 8 characters must be unique) */ +int *ival; +{ + char *value; + char newval; + int lval; + + /* Get value and comment from header string */ + value = hgetc (hstring,keyword); + + /* Translate value from ASCII to binary */ + if (value != NULL) { + lval = strlen (value); + if (lval > VLENGTH) { + strncpy (val, value, VLENGTH); + val[VLENGTH] = (char) 0; + } + else + strcpy (val, value); + newval = val[0]; + if (newval == 't' || newval == 'T') + *ival = 1; + else + *ival = 0; + return (1); + } + else { + return (0); + } +} + + +/* Extract real*8 date from FITS header string (dd/mm/yy or dd-mm-yy) */ + +int +hgetdate (hstring,keyword,dval) + +const char *hstring; /* character string containing FITS header information + in the format = {/ } */ +const char *keyword; /* character string containing the name of the keyword + the value of which is returned. hget searches for a + line beginning with this string. if "[n]" is present, + the n'th token in the value is returned. + (the first 8 characters must be unique) */ +double *dval; +{ + double yeardays, seconds, fday; + char *value,*sstr, *dstr, *tstr, *cstr, *nval; + int year, month, day, yday, i, hours, minutes; + static int mday[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; + + /* Get value and comment from header string */ + value = hgetc (hstring,keyword); + + /* Translate value from ASCII to binary */ + if (value != NULL) { + sstr = strchr (value,'/'); + dstr = strchr (value,'-'); + + /* Original FITS date format: dd/mm/yy */ + if (sstr > value) { + *sstr = '\0'; + day = (int) atof (value); + *sstr = '/'; + nval = sstr + 1; + sstr = strchr (nval,'/'); + if (sstr == NULL) + sstr = strchr (nval,'-'); + if (sstr > value) { + *sstr = '\0'; + month = (int) atof (nval); + *sstr = '/'; + nval = sstr + 1; + year = (int) atof (nval); + if (day > 31) { + yday = year; + year = day; + day = yday; + } + if (year >= 0 && year <= 49) + year = year + 2000; + else if (year < 100) + year = year + 1900; + if ((year % 4) == 0) + mday[1] = 29; + else + mday[1] = 28; + if ((year % 100) == 0 && (year % 400) != 0) + mday[1] = 28; + if (day > mday[month-1]) + day = mday[month-1]; + else if (day < 1) + day = 1; + if (mday[1] == 28) + yeardays = 365.0; + else + yeardays = 366.0; + yday = day - 1; + for (i = 0; i < month-1; i++) + yday = yday + mday[i]; + *dval = (double) year + ((double)yday / yeardays); + return (1); + } + else + return (0); + } + + /* New FITS date format: yyyy-mm-ddThh:mm:ss[.sss] */ + else if (dstr > value) { + *dstr = '\0'; + year = (int) atof (value); + *dstr = '-'; + nval = dstr + 1; + dstr = strchr (nval,'-'); + month = 1; + day = 1; + tstr = NULL; + if (dstr > value) { + *dstr = '\0'; + month = (int) atof (nval); + *dstr = '-'; + nval = dstr + 1; + tstr = strchr (nval,'T'); + if (tstr > value) + *tstr = '\0'; + day = (int) atof (nval); + if (tstr > value) + *tstr = 'T'; + } + + /* If year is < 32, it is really day of month in old format */ + if (year < 32) { + i = year; + year = day + 1900; + day = i; + } + + if ((year % 4) == 0) + mday[1] = 29; + else + mday[1] = 28; + if ((year % 100) == 0 && (year % 400) != 0) + mday[1] = 28; + if (day > mday[month-1]) + day = mday[month-1]; + else if (day < 1) + day = 1; + if (mday[1] == 28) + yeardays = 365.0; + else + yeardays = 366.0; + yday = day - 1; + for (i = 0; i < month-1; i++) + yday = yday + mday[i]; + *dval = (double) year + ((double)yday / yeardays); + + /* Extract time, if it is present */ + if (tstr > value) { + nval = tstr + 1; + hours = 0.0; + minutes = 0.0; + seconds = 0.0; + cstr = strchr (nval,':'); + if (cstr > value) { + *cstr = '\0'; + hours = (int) atof (nval); + *cstr = ':'; + nval = cstr + 1; + cstr = strchr (nval,':'); + if (cstr > value) { + *cstr = '\0'; + minutes = (int) atof (nval); + *cstr = ':'; + nval = cstr + 1; + seconds = atof (nval); + } + else { + minutes = (int) atof (nval); + seconds = 0.0; + } + } + fday = ((3.6e3 * (double)hours) + (6.e1 * (double)minutes) + + seconds) / 8.64e4; + *dval = *dval + (fday / yeardays); + } + return (1); + } + else + return (0); + } + else + return (0); +} + + +/* Extract IRAF multiple-keyword string value from FITS header string */ + +int +hgetm (hstring, keyword, lstr, str) + +const char *hstring; /* character string containing FITS header information + in the format = {/ } */ +const char *keyword; /* character string containing the root name of the keyword + the value of which is returned. hget searches for a + line beginning with this string. if "[n]" is present, + the n'th token in the value is returned. + (the first 8 characters must be unique) */ +const int lstr; /* Size of str in characters */ +char *str; /* String (returned) */ +{ + char *value; + char *stri; + char keywordi[16]; + int lval, lstri, ikey; + char keyform[8]; + + stri = str; + lstri = lstr; + + sprintf (keywordi, "%s_1", keyword); + if (ksearch (hstring, keywordi)) + strcpy (keyform, "%s_%d"); + else { + sprintf (keywordi, "%s_01", keyword); + if (ksearch (hstring, keywordi)) + strcpy (keyform, "%s_%02d"); + else { + sprintf (keywordi, "%s_001", keyword); + if (ksearch (hstring, keywordi)) + strcpy (keyform, "%s_%03d"); + else if (ksearch (hstring, keywordi)) + strcpy (keyform, "%s_%03d"); + else + return (0); + } + } + + /* Loop through sequentially-named keywords */ + multiline = 1; + for (ikey = 1; ikey < 500; ikey++) { + sprintf (keywordi, keyform, keyword, ikey); + + /* Get value for this keyword */ + value = hgetc (hstring, keywordi); + if (value != NULL) { + lval = strlen (value); + if (lval < lstri) + strcpy (stri, value); + else if (lstri > 1) { + strncpy (stri, value, lstri-1); + stri[lstri] = (char) 0; + break; + } + else { + str[0] = value[0]; + break; + } + } + else + break; + stri = stri + lval; + lstri = lstri - lval; + } + multiline = 0; + + /* Return 1 if any keyword found, else 0 */ + if (ikey > 1) + return (1); + else + return (0); +} + + +/* Extract string value for variable from FITS header string */ + +int +hgetsc (hstring,keyword,wchar,lstr,str) + +const char *hstring; /* character string containing FITS header information + in the format = {/ } */ +const char *keyword; /* character string containing the name of the keyword + the value of which is returned. hget searches for + a line beginning with this string. if "[n]" is + present, the n'th token in the value is returned. + (the first 8 characters must be unique) */ +const char *wchar; /* Character of multiple WCS header; =0 if unused */ +const int lstr; /* Size of str in characters */ +char *str; /* String (returned) */ +{ + char keyword1[64]; + int lkey; + + if (wchar[0] < (char) 64) + return (hgets (hstring, keyword, lstr, str)); + else { + lkey = strlen (keyword); + if (lkey < 8) { + strncpy (keyword1, keyword, lkey); + keyword1[lkey] = wchar[0]; + keyword1[lkey+1] = (char) 0; + } + else { + strncpy (keyword1, keyword, 7); + keyword1[7] = wchar[0]; + keyword1[8] = (char) 0; + } + return (hgets (hstring, keyword1, lstr, str)); + } +} + + +/* Extract string value for variable from FITS header string */ + +int +hgets (hstring, keyword, lstr, str) + +const char *hstring; /* character string containing FITS header information + in the format = {/ } */ +const char *keyword; /* character string containing the name of the keyword + the value of which is returned. hget searches for a + line beginning with this string. if "[n]" is present, + the n'th token in the value is returned. + (the first 8 characters must be unique) */ +const int lstr; /* Size of str in characters */ +char *str; /* String (returned) */ +{ + char *value; + int lval; + + /* Get value and comment from header string */ + value = hgetc (hstring,keyword); + + if (value != NULL) { + lval = strlen (value); + if (lval < lstr) + strcpy (str, value); + else if (lstr > 1) + strncpy (str, value, lstr-1); + else + str[0] = value[0]; + return (1); + } + else + return (0); +} + + +/* Extract number of decimal places for value in FITS header string */ + +int +hgetndec (hstring, keyword, ndec) + +const char *hstring; /* character string containing FITS header information + in the format = {/ } */ +const char *keyword; /* character string containing the name of the keyword + the value of which is returned. hget searches for a + line beginning with this string. if "[n]" is present, + the n'th token in the value is returned. + (the first 8 characters must be unique) */ +int *ndec; /* Number of decimal places in keyword value */ +{ + char *value; + int i, nchar; + + /* Get value and comment from header string */ + value = hgetc (hstring,keyword); + + /* Find end of string and count backward to decimal point */ + *ndec = 0; + if (value != NULL) { + nchar = strlen (value); + for (i = nchar-1; i >= 0; i--) { + if (value[i] == '.') + return (1); + *ndec = *ndec + 1; + } + return (1); + } + else + return (0); +} + + +/* Extract character value for variable from FITS header string */ + +char * +hgetc (hstring,keyword0) + +const char *hstring; /* character string containing FITS header information + in the format = {/ } */ +const char *keyword0; /* character string containing the name of the keyword + the value of which is returned. hget searches for a + line beginning with this string. if "[n]" is present, + the n'th token in the value is returned. + (the first 8 characters must be unique) */ +{ + static char cval[80]; + char *value; + char cwhite[2]; + char squot[2], dquot[2], lbracket[2], rbracket[2], slash[2], comma[2]; + char space; + char keyword[81]; /* large for ESO hierarchical keywords */ + char line[100]; + char *vpos, *cpar; + char *q1, *q2, *v1, *v2, *c1, *brack1, *brack2; + int ipar, i, lkey; + +#ifdef USE_SAOLIB + int iel=1, ip=1, nel, np, ier; + char *get_fits_head_str(); + + if( !use_saolib ){ +#endif + + squot[0] = (char) 39; + squot[1] = (char) 0; + dquot[0] = (char) 34; + dquot[1] = (char) 0; + lbracket[0] = (char) 91; + lbracket[1] = (char) 0; + comma[0] = (char) 44; + comma[1] = (char) 0; + rbracket[0] = (char) 93; + rbracket[1] = (char) 0; + slash[0] = (char) 47; + slash[1] = (char) 0; + space = (char) 32; + + /* Find length of variable name */ + strncpy (keyword,keyword0, sizeof(keyword)-1); + brack1 = strsrch (keyword,lbracket); + if (brack1 == NULL) + brack1 = strsrch (keyword,comma); + if (brack1 != NULL) { + *brack1 = '\0'; + brack1++; + } + + /* Search header string for variable name */ + vpos = ksearch (hstring,keyword); + + /* Exit if not found */ + if (vpos == NULL) + return (NULL); + + /* Initialize line to nulls */ + for (i = 0; i < 100; i++) + line[i] = 0; + +/* In standard FITS, data lasts until 80th character */ + + /* Extract entry for this variable from the header */ + strncpy (line,vpos,80); + + /* Check for quoted value */ + q1 = strsrch (line,squot); + c1 = strsrch (line,slash); + if (q1 != NULL) { + if (c1 != NULL && q1 < c1) { + q2 = strsrch (q1+1,squot); + if (q2 == NULL) { + q2 = c1 - 1; + while (*q2 == space) + q2--; + q2++; + } + else if (c1 < q2) + c1 = strsrch (q2,slash); + } + else if (c1 == NULL) { + q2 = strsrch (q1+1,squot); + if (q2 == NULL) { + q2 = line + 79; + while (*q2 == space) + q2--; + q2++; + } + } + else + q1 = NULL; + } + else { + q1 = strsrch (line,dquot); + if (q1 != NULL) { + if (c1 != NULL && q1 < c1) { + q2 = strsrch (q1+1,dquot); + if (q2 == NULL) { + q2 = c1 - 1; + while (*q2 == space) + q2--; + q2++; + } + else if (c1 < q2) + c1 = strsrch (q2,slash); + } + else if (c1 == NULL) { + q2 = strsrch (q1+1,dquot); + if (q2 == NULL) { + q2 = line + 79; + while (*q2 == space) + q2--; + q2++; + } + } + else + q1 = NULL; + } + else { + q1 = NULL; + q2 = line + 10; + } + } + + /* Extract value and remove excess spaces */ + if (q1 != NULL) { + v1 = q1 + 1; + v2 = q2; + } + else { + v1 = strsrch (line,"="); + if (v1 == NULL) + v1 = line + 9; + else + v1 = v1 + 1; + c1 = strsrch (line,"/"); + if (c1 != NULL) + v2 = c1; + else + v2 = line + 79; + } + + /* Ignore leading spaces if not multiline */ + if (!multiline) { + while (*v1 == ' ' && v1 < v2) { + v1++; + } + } + + /* Drop trailing spaces */ + *v2 = '\0'; + if (!multiline) { + v2--; + while ((*v2 == ' ' || *v2 == (char) 13) && v2 > v1) { + *v2 = '\0'; + v2--; + } + } + + /* Convert -zero to just plain 0 */ + if (!strcmp (v1, "-0")) + v1++; + strcpy (cval,v1); + value = cval; + + /* If keyword has brackets, extract appropriate token from value */ + if (brack1 != NULL) { + brack2 = strsrch (brack1,rbracket); + if (brack2 != NULL) + *brack2 = '\0'; + if (isnum (brack1) == 1) { + ipar = atoi (brack1); + cwhite[0] = ' '; + cwhite[1] = '\0'; + if (ipar > 0) { + for (i = 1; i <= ipar; i++) { + cpar = strtok (v1,cwhite); + v1 = NULL; + } + if (cpar != NULL) { + strcpy (cval,cpar); + value = cval; + } + else + value = NULL; + } + + /* If token counter is negative, include rest of value */ + else if (ipar < 0) { + for (i = 1; i < -ipar; i++) { + v1 = strchr (v1, ' '); + if (v1 == NULL) + break; + else + v1 = v1 + 1; + } + if (v1 != NULL) { + strcpy (cval, v1); + value = cval; + } + else + value = NULL; + } + } + else { + lkey = strlen (brack1); + for (i = 0; i < lkey; i++) { + if (brack1[i] > 64 && brack1[i] < 91) + brack1[i] = brack1[i] + 32; + } + v1 = igetc (cval, brack1); + if (v1) { + strcpy (cval,v1); + value = cval; + } + else + value = NULL; + } + } + + return (value); +#ifdef USE_SAOLIB + } else { + return(get_fits_head_str(keyword0, iel, ip, &nel, &np, &ier, hstring)); + } +#endif +} + + +/* Find beginning of fillable blank line before FITS header keyword line */ + +char * +blsearch (hstring,keyword) + +/* Find entry for keyword keyword in FITS header string hstring. + (the keyword may have a maximum of eight letters) + NULL is returned if the keyword is not found */ + +const char *hstring; /* character string containing fits-style header + information in the format = {/ } + the default is that each entry is 80 characters long; + however, lines may be of arbitrary length terminated by + nulls, carriage returns or linefeeds, if packed is true. */ +const char *keyword; /* character string containing the name of the variable + to be returned. ksearch searches for a line beginning + with this string. The string may be a character + literal or a character variable terminated by a null + or '$'. it is truncated to 8 characters. */ +{ + const char *headlast; + char *loc, *headnext, *pval, *lc, *line, *loc1; + char *bval; + int icol, nextchar, lkey, nleft, lhstr; + char keywordh[80]; + + pval = 0; + strcpy (keywordh,"HIERARCH "); + + /* Search header string for variable name */ + if (lhead0) + lhstr = lhead0; + else { + lhstr = 0; + while (lhstr < 256000 && hstring[lhstr] != 0) + lhstr++; + } + headlast = hstring + lhstr; + headnext = (char *) hstring; + pval = NULL; + while (headnext < headlast) { + nleft = headlast - headnext; + loc = strncsrch (headnext, keyword, nleft); + + /* Exit if keyword is not found */ + if (loc == NULL) { + break; + } + + icol = (loc - hstring) % 80; + lkey = strlen (keyword); + nextchar = (int) *(loc + lkey); + + /* If string match is not in the first 8 characters of a line */ + if (icol > 7) { + + /* Check for ESO HIERARCH preceding keyword */ + strcat (keywordh, keyword); + loc1 = strncsrch (headnext, keywordh, nleft); + + /* If HIERARCH string is found, get value */ + if (loc1 != NULL) { + icol = (loc1 - hstring) % 80; + lkey = strlen (keywordh); + nextchar = (int) *(loc1 + lkey); + line = loc - icol; + pval = line; + } + + /* Otherwise keep searching */ + else { + headnext = loc + 1; + } + + keywordh[9] = (char) 0; + } + + /* If parameter name in header is longer, keep searching */ + else if (nextchar != 61 && nextchar > 32 && nextchar < 127) + headnext = loc + 1; + + /* If preceeding characters in line are not blanks, keep searching */ + else { + line = loc - icol; + for (lc = line; lc < loc; lc++) { + if (*lc != ' ') + headnext = loc + 1; + } + + /* Return pointer to start of line if match */ + if (loc >= headnext) { + pval = line; + break; + } + } + } + + /* Return NULL to calling program if keyword is not found */ + if (pval == NULL) + return (pval); + + /* Return NULL if keyword is found at start of FITS header string */ + if (pval == hstring) + return (NULL); + + /* Find last nonblank in FITS header string line before requested keyword */ + bval = pval - 80; + while (!strncmp (bval," ",8) && bval >= hstring) + bval = bval - 80; + bval = bval + 80; + + /* Return pointer to calling program if blank lines found */ + if (bval < pval && bval >= hstring) + return (bval); + else + return (NULL); +} + + +/* Find FITS header line containing specified keyword */ + +char * +ksearch (hstring,keyword) + +/* Find entry for keyword keyword in FITS header string hstring. + (the keyword may have a maximum of eight letters) + NULL is returned if the keyword is not found */ + +const char *hstring; /* character string containing fits-style header + information in the format = {/ } + the default is that each entry is 80 characters long; + however, lines may be of arbitrary length terminated by + nulls, carriage returns or linefeeds, if packed is true. */ +const char *keyword; /* character string containing the name of the variable + to be returned. ksearch searches for a line beginning + with this string. The string may be a character + literal or a character variable terminated by a null + or '$'. it is truncated to 8 characters. */ +{ + const char *headlast; + char *loc, *loc1, *headnext, *pval, *lc, *line, nextchar, nextchar1; + char keywordh[80]; + int icol, lkey, nleft, lhead, lmax; + +#ifdef USE_SAOLIB + int iel=1, ip=1, nel, np, ier; + char *get_fits_head_str(); + + if( !use_saolib ){ +#endif + + pval = 0; + strcpy (keywordh,"HIERARCH "); + +/* Find current length of header string */ + if (lhead0) + lmax = lhead0; + else + lmax = 256000; + for (lhead = 0; lhead < lmax; lhead++) { + if (hstring[lhead] <= (char) 0) + break; + } + +/* Search header string for variable name */ + headlast = hstring + lhead; + headnext = (char *) hstring; + pval = NULL; + while (headnext < headlast) { + nleft = headlast - headnext; + loc = strncsrch (headnext, keyword, nleft); + + /* Exit if keyword is not found */ + if (loc == NULL) { + break; + } + + icol = (loc - hstring) % 80; + lkey = strlen (keyword); + nextchar = *(loc + lkey); + + /* If string match is not in the first 8 characters of a line */ + if (icol > 7) { + + /* Check for ESO HIERARCH preceding keyword */ + strcat (keywordh, keyword); + loc1 = strncsrch (headnext, keywordh, nleft); + + /* If HIERARCH string is found, get value */ + if (loc1 != NULL) { + icol = (loc1 - hstring) % 80; + lkey = strlen (keywordh); + nextchar = *(loc1 + lkey); + nextchar1 = *(loc1 + lkey + 1); + if (nextchar == '=' || + (nextchar == ' ' && nextchar1 == '=') || + (nextchar == ' ' && nextchar1 == ' ') ) { + line = loc - icol; + pval = line; + } + + /* Otherwise keep searching */ + else { + headnext = loc + 1; + } + } + + /* Otherwise keep searching */ + else { + headnext = loc + 1; + } + + keywordh[9] = (char) 0; + } + + /* If parameter name in header is longer, keep searching */ + else if (nextchar != (char)61 && + nextchar > (char)32 && + nextchar < (char)127 ) { + headnext = loc + 1; + } + + /* If preceeding characters in line are not blanks, keep searching */ + else { + line = loc - icol; + for (lc = line; lc < loc; lc++) { + if (*lc != ' ') + headnext = loc + 1; + } + + /* Return pointer to start of line if match */ + if (loc >= headnext) { + pval = line; + break; + } + } + } + +/* Return pointer to calling program */ + return (pval); + +#ifdef USE_SAOLIB + } + else { + if (get_fits_head_str(keyword,iel,ip,&nel,&np,&ier,hstring) != NULL) + return(hstring); + else + return(NULL); + } +#endif +} + + +/* Return the right ascension in degrees from sexagesimal hours or decimal degrees */ + +double +str2ra (in) + +const char *in; /* Character string of sexigesimal hours or decimal degrees */ + +{ + double ra; /* Right ascension in degrees (returned) */ + + ra = str2dec (in); + if (strsrch (in,":")) + ra = ra * 15.0; + + return (ra); +} + + +/* Return the declination in degrees from sexagesimal or decimal degrees */ + +double +str2dec (in) + +const char *in; /* Character string of sexigesimal or decimal degrees */ + +{ + double dec; /* Declination in degrees (returned) */ + double deg, min, sec, sign; + char *value, *c1, *c2; + int lval; + char *dchar; + + dec = 0.0; + + /* Return 0.0 if string is null */ + if (in == NULL) + return (dec); + + /* Translate value from ASCII colon-delimited string to binary */ + if (in[0]) { + value = (char *) in; + + /* Remove leading spaces */ + while (*value == ' ') + value++; + + /* Save sign */ + if (*value == '-') { + sign = -1.0; + value++; + } + else if (*value == '+') { + sign = 1.0; + value++; + } + else + sign = 1.0; + + /* Turn comma into space */ + if ((c1 = strsrch (value,",")) != NULL) + *c1 = ' '; + + /* Remove trailing spaces */ + lval = strlen (value); + while (value[lval-1] == ' ') + lval--; + + if ((c1 = strsrch (value,":")) == NULL) + c1 = strnsrch (value," ",lval); + if (c1 != NULL) { + *c1 = 0; + deg = (double) atoi (value); + *c1 = ':'; + value = c1 + 1; + if ((c2 = strsrch (value,":")) == NULL) + c2 = strsrch (value," "); + if (c2 != NULL) { + *c2 = 0; + min = (double) atoi (value); + *c2 = ':'; + value = c2 + 1; + sec = atof (value); + } + else { + sec = 0.0; + if ((c1 = strsrch (value,".")) != NULL) + min = atof (value); + if (strlen (value) > 0) + min = (double) atoi (value); + } + dec = sign * (deg + (min / 60.0) + (sec / 3600.0)); + } + else if (isnum (value) == 2) { + if ((dchar = strchr (value, 'D'))) + *dchar = 'e'; + if ((dchar = strchr (value, 'd'))) + *dchar = 'e'; + if ((dchar = strchr (value, 'E'))) + *dchar = 'e'; + dec = sign * atof (value); + } + else + dec = sign * (double) atoi (value); + } + return (dec); +} + + +/* Find string s2 within null-terminated string s1 */ + +char * +strsrch (s1, s2) + +const char *s1; /* String to search */ +const char *s2; /* String to look for */ + +{ + int ls1; + ls1 = strlen (s1); + return (strnsrch (s1, s2, ls1)); +} + + +/* Find string s2 within string s1 */ + +char * +strnsrch (s1, s2, ls1) + +const char *s1; /* String to search */ +const char *s2; /* String to look for */ +const int ls1; /* Length of string being searched */ + +{ + char *s,*s1e; + char cfirst,clast; + int i,ls2; + + /* Return null string if either pointer is NULL */ + if (s1 == NULL || s2 == NULL) + return (NULL); + + /* A zero-length pattern is found in any string */ + ls2 = strlen (s2); + if (ls2 ==0) + return ((char *) s1); + + /* Only a zero-length string can be found in a zero-length string */ + if (ls1 ==0) + return (NULL); + + cfirst = (char) s2[0]; + clast = (char) s2[ls2-1]; + s1e = (char *) s1 + (int) ls1 - ls2 + 1; + s = (char *) s1; + while (s < s1e) { + + /* Search for first character in pattern string */ + if (*s == cfirst) { + + /* If single character search, return */ + if (ls2 == 1) + return (s); + + /* Search for last character in pattern string if first found */ + if (s[ls2-1] == clast) { + + /* If two-character search, return */ + if (ls2 == 2) + return (s); + + /* If 3 or more characters, check for rest of search string */ + i = 1; + while (i < ls2 && s[i] == s2[i]) + i++; + + /* If entire string matches, return */ + if (i >= ls2) + return (s); + } + } + s++; + } + return (NULL); +} + + +/* Find string s2 within null-terminated string s1 (case-free search) */ + +char * +strcsrch (s1, s2) + +const char *s1; /* String to search */ +const char *s2; /* String to look for */ + +{ + int ls1; + ls1 = strlen ((char *) s1); + return (strncsrch (s1, s2, ls1)); +} + + +/* Find string s2 within string s1 (case-free search) */ + +char * +strncsrch (s1, s2, ls1) + +const char *s1; /* String to search */ +const char *s2; /* String to look for */ +const int ls1; /* Length of string being searched */ + +{ + char *s,*s1e, sl, *os2; + char cfirst,ocfirst; + char clast = ' '; + char oclast = ' '; + int i,ls2; + + /* Return null string if either pointer is NULL */ + if (s1 == NULL || s2 == NULL) + return (NULL); + + /* A zero-length pattern is found in any string */ + ls2 = strlen (s2); + if (ls2 ==0) + return ((char *) s1); + + /* Only a zero-length string can be found in a zero-length string */ + os2 = NULL; + if (ls1 ==0) + return (NULL); + + /* For one or two characters, set opposite case first and last letters */ + if (ls2 < 3) { + cfirst = (char) s2[0]; + if (cfirst > 96 && cfirst < 123) + ocfirst = cfirst - 32; + else if (cfirst > 64 && cfirst < 91) + ocfirst = cfirst + 32; + else + ocfirst = cfirst; + if (ls2 > 1) { + clast = s2[1]; + if (clast > 96 && clast < 123) + oclast = clast - 32; + else if (clast > 64 && clast < 91) + oclast = clast + 32; + else + oclast = clast; + } + } + + /* Else duplicate string with opposite case letters for comparison */ + else { + os2 = (char *) calloc (ls2, 1); + for (i = 0; i < ls2; i++) { + if (s2[i] > 96 && s2[i] < 123) + os2[i] = s2[i] - 32; + else if (s2[i] > 64 && s2[i] < 91) + os2[i] = s2[i] + 32; + else + os2[i] = s2[i]; + } + cfirst = s2[0]; + ocfirst = os2[0]; + clast = s2[ls2-1]; + oclast = os2[ls2-1]; + } + + /* Loop through input string, character by character */ + s = (char *) s1; + s1e = s + (int) ls1 - ls2 + 1; + while (s < s1e) { + + /* Search for first character in pattern string */ + if (*s == cfirst || *s == ocfirst) { + + /* If single character search, return */ + if (ls2 == 1) { + if (os2 != NULL) + free (os2); + return (s); + } + + /* Search for last character in pattern string if first found */ + sl = s[ls2-1]; + if (sl == clast || sl == oclast) { + + /* If two-character search, return */ + if (ls2 == 2) { + if (os2 != NULL) + free (os2); + return (s); + } + + /* If 3 or more characters, check for rest of search string */ + i = 1; + while (i < ls2 && (s[i] == (char) s2[i] || s[i] == os2[i])) + i++; + + /* If entire string matches, return */ + if (i >= ls2) { + if (os2 != NULL) + free (os2); + return (s); + } + } + } + s++; + } + if (os2 != NULL) + free (os2); + return (NULL); +} + + +int +notnum (string) + +const char *string; /* Character string */ +{ + if (isnum (string)) + return (0); + else + return (1); +} + + +/* ISNUM-- Return 1 if string is an integer number, + 2 if floating point, + 3 if sexigesimal, with or without decimal point + 4 if yyyy-mm-dd date + else 0 + */ + +int +isnum (string) + +const char *string; /* Character string */ +{ + int lstr, i, nd, cl; + char cstr, cstr1, cstr2; + int fpcode; + + /* Return 0 if string is NULL */ + if (string == NULL) + return (0); + + lstr = strlen (string); + nd = 0; + cl = 0; + fpcode = 1; + + /* Return 0 if string starts with a D or E */ + cstr = string[0]; + if (cstr == 'D' || cstr == 'd' || + cstr == 'E' || cstr == 'e') { + return (0); + } + + /* Remove trailing spaces */ + while (string[lstr-1] == ' ') + lstr--; + + /* Numeric strings contain 0123456789-+ and d or e for exponents */ + for (i = 0; i < lstr; i++) { + cstr = string[i]; + if (cstr == '\n') + break; + + /* Ignore leading spaces */ + if (cstr == ' ' && nd == 0) + continue; + + if ((cstr < 48 || cstr > 57) && + cstr != '+' && cstr != '-' && + cstr != 'D' && cstr != 'd' && + cstr != 'E' && cstr != 'e' && + cstr != ':' && cstr != '.') + return (0); + else if (cstr == '+' || cstr == '-') { + if (string[i+1] == '-' || string[i+1] == '+') + return (0); + else if (i > 0) { + cstr1 = string[i-1]; + cstr2 = string[i+1]; + if (cstr == '-' && cstr1 > 47 && cstr1 < 58 && + cstr2 > 47 && cstr2 < 58) + return (4); + else if (cstr1 != 'D' && cstr1 != 'd' && + cstr1 != 'E' && cstr1 != 'e' && + cstr1 != ':' && cstr1 != ' ') + return (0); + } + } + else if (cstr >= 47 && cstr <= 57) + nd++; + + /* Check for colon */ + else if (cstr == 58) + cl++; + if (cstr=='.' || cstr=='d' || cstr=='e' || cstr=='d' || cstr=='e') + fpcode = 2; + } + if (nd > 0) { + if (cl) + fpcode = 3; + return (fpcode); + } + else + return (0); +} + + +/* NUMDEC -- Return number of decimal places in numeric string (-1 if not number) */ + +int +numdec (string) + +const char *string; /* Numeric string */ +{ + char *cdot; + int lstr; + + if (notnum (string) && !strchr (string, ':')) + return (-1); + else { + lstr = strlen (string); + if ((cdot = strchr (string, '.')) == NULL) + return (0); + else + return (lstr - (cdot - string) - 1); + } +} + + +#ifdef USE_SAOLIB +int set_saolib(hstring) + void *hstring; +{ + if( *((int *)hstring) == 142857 ) + use_saolib = 1; + else + use_saolib = 0; +} + +#endif + + +/* Remove exponent, leading #, surrounding parentheses, + and/or trailing zeroes, if reasonable */ +void +strfix (string, fillblank, dropzero) + +char *string; /* String to modify */ +int fillblank; /* If nonzero, fill blanks with underscores */ +int dropzero; /* If nonzero, drop trailing zeroes */ +{ + char *sdot, *s, *strend, *str, ctemp, *slast; + int ndek, lstr, i; + + /* If number, ignore leading # and remove trailing non-numeric character */ + if (string[0] == '#') { + strend = string + strlen (string); + str = string + 1; + strend = str + strlen (str) - 1; + ctemp = *strend; + if (!isnum (strend)) + *strend = (char) 0; + if (isnum (str)) { + strend = string + strlen (string); + for (str = string; str < strend; str++) + *str = *(str + 1); + } + else + *strend = ctemp; + } + + /* Remove parentheses if they enclose the string */ + if (string[0] == '(') { + lstr = strlen (string); + if (string[lstr-1] == ')') { + string[lstr-1] = (char) 0; + strend = string + lstr - 1; + for (str = string; str < strend; str++) + *str = *(str+1); + string[lstr-2] = (char) 0; + } + } + + /* Remove positive exponent if there are enough digits given */ + if (isnum (string) > 1 && strsrch (string, "E+") != NULL) { + lstr = strlen (string); + ndek = (int) (string[lstr-1] - 48); + ndek = ndek + (10 * ((int) (string[lstr-2] - 48))); + if (ndek < lstr - 7) { + lstr = lstr - 4; + string[lstr] = (char) 0; + string[lstr+1] = (char) 0; + string[lstr+2] = (char) 0; + string[lstr+3] = (char) 0; + sdot = strchr (string, '.'); + if (ndek > 0 && sdot != NULL) { + for (i = 1; i <= ndek; i++) { + *sdot = *(sdot+1); + sdot++; + *sdot = '.'; + } + } + } + } + + /* Remove trailing zeroes if they are not significant */ + if (dropzero) { + if (isnum (string) > 1 && strchr (string, '.') != NULL && + strsrch (string, "E-") == NULL && + strsrch (string, "E+") == NULL && + strsrch (string, "e-") == NULL && + strsrch (string, "e+") == NULL) { + lstr = strlen (string); + s = string + lstr - 1; + while (*s == '0' && lstr > 1) { + if (*(s - 1) != '.') { + *s = (char) 0; + lstr --; + } + s--; + } + } + } + + /* Remove trailing decimal point */ + lstr = strlen (string); + s = string + lstr - 1; + if (*s == '.') + *s = (char) 0; + + /* Replace embedded blanks with underscores, if requested to */ + if (fillblank) { + lstr = strlen (string); + slast = string + lstr; + for (s = string; s < slast; s++) { + if (*s == ' ') *s = '_'; + } + } + + return; + +} + +/* Oct 28 1994 New program + * + * Mar 1 1995 Search for / after second quote, not first one + * May 2 1995 Initialize line in HGETC; deal with logicals in HGETL better + * May 4 1995 Declare STRSRCH in KSEARCH + * Aug 7 1995 Fix line initialization in HGETC + * Dec 22 1995 Add HGETRA and HGETDEC to get degrees from xx:xx:xx.xxx string + * + * Jan 26 1996 Fix HGETL to not crash when parameter is not present + * Feb 1 1996 Fix HGETC to deal with quotes correctly + * Feb 1 1996 Fix HGETDEG to deal with sign correctly + * Feb 6 1996 Add HGETS to update character strings + * Feb 8 1996 Fix STRSRCH to find final characters in string + * Feb 23 1996 Add string to degree conversions + * Apr 26 1996 Add HGETDATE to get fractional year from date string + * May 22 1996 Fix documentation; return double from STR2RA and STR2DEC + * May 28 1996 Fix string translation of RA and Dec when no seconds + * Jun 10 1996 Remove unused variables after running lint + * Jun 17 1996 Fix bug which failed to return single character strings + * Jul 1 1996 Skip sign when reading declination after testing for it + * Jul 19 1996 Do not divide by 15 if RA header value is already in degrees + * Aug 5 1996 Add STRNSRCH to search strings which are not null-terminated + * Aug 6 1996 Make minor changes after lint + * Aug 8 1996 Fix ksearch bug which finds wrong keywords + * Aug 13 1996 Fix sign bug in STR2DEC for degrees + * Aug 26 1996 Drop unused variables ICOL0, NLINE, PREVCHAR from KSEARCH + * Sep 10 1996 Fix header length setting code + * Oct 15 1996 Clean up loops and fix ICOL assignment + * Nov 13 1996 Handle integer degrees correctly in STR2DEC + * Nov 21 1996 Make changes for Linux thanks to Sidik Isani + * Dec 12 1996 Add ISNUM to check to see whether strings are numbers + * + * Jan 22 1997 Add ifdefs for Eric Mandel (SAOtng) + * Jan 27 1997 Convert to integer through ATOF so exponents are recognized + * Jul 25 1997 Implement FITS version of ISO date format + * + * Feb 24 1998 Implement code to return IRAF multiple-keyword strings + * Mar 12 1998 Add subroutine NOTNUM + * Mar 27 1998 Add changes to match SKYCAT version + * Apr 30 1998 Add BLSEARCH() to find blank lines before END + * May 27 1998 Add HGETNDEC() to get number of decimal places in entry + * Jun 1 1998 Add VMS patch from Harry Payne at StSci + * Jun 18 1998 Fix code which extracts tokens from string values + * Jul 21 1998 Drop minus sign for values of -0 + * Sep 29 1998 Treat hyphen-separated date as old format if 2-digit year + * Oct 7 1998 Clean up search for last blank line + * + * Apr 5 1999 Check lengths of strings before copying them + * May 5 1999 values.h -> POSIX limits.h: MAXINT->INT_MAX, MAXSHORT->SHRT_MAX + * Jul 15 1999 Add hgetm() options of 1- or 2-digit keyword extensions + * Oct 6 1999 Add gethlength() to return header length + * Oct 14 1999 In ksearch(), search only to null not to end of buffer + * Oct 15 1999 Return 1 from hgetndec() if successful + * Oct 20 1999 Drop unused variable after lint (val in hgetndec) + * Dec 3 1999 Fix isnum() to reject strings starting with a d or e + * Dec 20 1999 Update hgetdate() to get minutes and seconds right + * + * Feb 10 2000 Parse RA and Dec with spaces as well as colons as separators + * Feb 11 2000 Add null at end of multi-line keyword value character string + * Feb 25 2000 Change max search string length from 57600 to 256000 + * Mar 15 2000 Deal with missing second quotes in string values + * Mar 17 2000 Return 2 from isnum() if number is floating point (.de) + * Mar 17 2000 Ignore leading # for numeric values in header + * Mar 21 2000 Implement -n to get string value starting with nth token + * Apr 5 2000 Reject +- in isnum() + * Jun 9 2000 Read keyword values even if no equal sign is present + * Sep 20 2000 Ignore linefeed at end of number in isnum() + * Oct 23 2000 Fix handling of embedded + or - in isnum() + * + * Jan 19 2000 Return 0 from isnum(), str2ra(), and str2dec() if string is null + * Mar 30 2001 Fix header length finding algorithm in ksearch() + * Jul 13 2001 Make val[] static int instead of int; drop unused variables + * Sep 12 2001 Read yyyy/mm/dd dates as well as dd/mm/yyyy + * Sep 20 2001 Ignore leading spaces in str2dec() + * Sep 20 2001 Ignore trailing spaces in isnum() + * + * Apr 3 2002 Add hgetr8c(), hgeti4c(), and hgetsc() for multiple WCS handling + * Apr 26 2002 Fix bug in hgetsc(), hgeti4c(), and hgetr8c() found by Bill Joye + * Jun 26 2002 Do not drop leading or trailing spaces in multi-line values + * Aug 6 2002 Add strcsrch() and strncsrch() for case-insensitive searches + * Aug 30 2002 Fix bug so strcsrch() really is case-insensitive + * Oct 20 2003 Add numdec() to return number of decimal places in a string + * Dec 9 2003 Fix numdec() to return 0 if no digits after decimal point + * + * Feb 26 2004 Extract value from keyword=value strings within a keyword value + * Apr 9 2004 Use strncsrch() in ksearch() to find differently-cased keywords + * Apr 28 2004 Free os2 in strncsrch() only if it is allocated + * Jul 13 2004 Accept D, d, E, or e as exponent delimiter in floating points + * Aug 30 2004 Change numdec() to accept sexigesimal numbers (:'s) + * + * Jun 27 2005 Drop unused variables + * Aug 30 2005 Adjust code in hlength() + * + * Jun 20 2006 Initialize uninitialized variables in strnsrch() + * Jun 29 2006 Add new subroutine strfix() to clean strings for other uses + * Jul 13 2006 Increase maximum number of multiline keywords from 20 to 500 + * + * Jan 4 2007 Declare header, keyword to be const + * Jan 4 2007 Change WCS letter from char to char* + * Feb 28 2007 If header length is not set in hlength, set it to 0 + * May 31 2007 Add return value of 3 to isnum() if string has colon(s) + * Aug 22 2007 If closing quote not found, make one up + * + * Nov 12 2009 In strfix(), if drop enclosing parantheses + * + * Apr 19 2011 In str2dec(), change comma to space + * May 19 2011 In strncsrch() always free allocated memory before returning + * + * Nov 6 2015 In isnum(), add return of 4 for yyyy-mm-dd dates + * + * Jun 9 2016 Fix isnum() tests for added coloned times and dashed dates + * + * Dec 12 2017 Compare source and destination string sizes before strcpy() + * + * Aug 27 2018 Finish implementing long keywords, with or without HIERARCH + */ diff -Nru wcstools-3.9.5/libwcs/hget.c wcstools-3.9.6/libwcs/hget.c --- wcstools-3.9.5/libwcs/hget.c 2016-06-09 18:58:10.000000000 +0000 +++ wcstools-3.9.6/libwcs/hget.c 2019-09-23 16:29:37.000000000 +0000 @@ -1,8 +1,8 @@ /*** File libwcs/hget.c - *** November 6, 2015 + *** September 23, 2019 *** By Jessica Mink, jmink@cfa.harvard.edu *** Harvard-Smithsonian Center for Astrophysics - *** Copyright (C) 1994-2015 + *** Copyright (C) 1994-2019 *** Smithsonian Astrophysical Observatory, Cambridge, MA, USA This library is free software; you can redistribute it and/or @@ -58,7 +58,7 @@ * Subroutine: strfix (string,blankfill,zerodrop) removes extraneous characters */ -#include /* NULL, strlen, strstr, strcpy */ +#include /* NULL, strlen, strstr, strcpy */ #include #include "fitshead.h" /* FITS header extraction subroutines */ #include @@ -69,6 +69,7 @@ #define SHRT_MAX 32767 #endif #define VLENGTH 81 +#define LHEAD0 288000 /* Maximum number of characters to search in header */ #ifdef USE_SAOLIB static int use_saolib=0; @@ -90,11 +91,15 @@ char *hend; if (lhead > 0) lhead0 = lhead; - else { + + else if (lhead == 0) { lhead0 = 0; hend = ksearch (header,"END"); lhead0 = hend + 80 - header; } + else { + lhead0 = 0; + } return (lhead0); } @@ -1096,7 +1101,7 @@ lhstr = lhead0; else { lhstr = 0; - while (lhstr < 256000 && hstring[lhstr] != 0) + while (lhstr < LHEAD0 && hstring[lhstr] != 0) lhstr++; } headlast = hstring + lhstr; @@ -1195,10 +1200,10 @@ pval = 0; /* Find current length of header string */ - if (lhead0) + if (lhead0 > 0) lmax = lhead0; else - lmax = 256000; + lmax = LHEAD0; for (lhead = 0; lhead < lmax; lhead++) { if (hstring[lhead] <= (char) 0) break; @@ -1920,4 +1925,6 @@ * Nov 6 2015 In isnum(), add return of 4 for yyyy-mm-dd dates * * Jun 9 2016 Fix isnum() tests for added coloned times and dashed dates + * + * Sep 23 2019 Add -1 argument to hlen() */ diff -Nru wcstools-3.9.5/libwcs/hput.c wcstools-3.9.6/libwcs/hput.c --- wcstools-3.9.5/libwcs/hput.c 2012-05-01 22:18:35.000000000 +0000 +++ wcstools-3.9.6/libwcs/hput.c 2018-08-28 18:49:24.000000000 +0000 @@ -1,8 +1,8 @@ /*** File libwcs/hput.c - *** September 9, 2011 + *** August 28, 2018 *** By Jessica Mink, jmink@cfa.harvard.edu *** Harvard-Smithsonian Center for Astrophysics - *** Copyright (C) 1995-2011 + *** Copyright (C) 1995-2018 *** Smithsonian Astrophysical Observatory, Cambridge, MA, USA This library is free software; you can redistribute it and/or @@ -544,9 +544,14 @@ strncpy (v1, keyword, lkeyword); /* Add parameter value in the appropriate place */ - vp = v1 + 8; + if (lkeyword < 9) + vp = v1 + 8; + else if (lkeyword < 28) + vp = v1 + 28; + else + vp = v1 + lkeyword; *vp = '='; - vp = v1 + 9; + vp = vp + 1; *vp = ' '; vp = vp + 1; if (*value == squot) { @@ -1313,4 +1318,6 @@ * Aug 22 2007 If closing quote not found, make one up * * Sep 9 2011 Always initialize q2 and lroot - */ + * + * Aug 28 2018 Allow arbitrary length keywords up to 64 characters +*/ diff -Nru wcstools-3.9.5/libwcs/html2sp.c wcstools-3.9.6/libwcs/html2sp.c --- wcstools-3.9.5/libwcs/html2sp.c 1970-01-01 00:00:00.000000000 +0000 +++ wcstools-3.9.6/libwcs/html2sp.c 2018-11-06 02:41:56.000000000 +0000 @@ -0,0 +1,244 @@ +/* File html2sp.c + * November 5, 2018 + * By Jessica Mink Harvard-Smithsonian Center for Astrophysics) + * Send bug reports to jmink@cfa.harvard.edu + + Copyright (C) 2018 + Smithsonian Astrophysical Observatory, Cambridge, MA USA + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include "libwcs/fitsfile.h" + +#define MAXKWD 50 +static int maxnkwd = MAXKWD; + +static void usage(); + +static int verbose = 0; /* verbose/debugging flag */ +static int version = 0; /* If 1, print only program name and version */ +static char spchar = '_'; + +static char *RevMsg = "CHAR2SP WCSTools 3.9.6, 28 August 2018, Jessica Mink (jmink@cfa.harvard.edu)"; + +int +main (ac, av) +int ac; +char **av; +{ + char *str; + char **kwd; + int nkwd = 0; + int lstr; + int ikwd, i; + + nkwd = 0; + kwd = (char **)calloc (maxnkwd, sizeof(char *)); + for (ikwd = 0; ikwd < maxnkwd; ikwd++) { + kwd[ikwd] = NULL; + } + + /* Check for help or version command first */ + str = *(av+1); + if (!str || !strcmp (str, "help") || !strcmp (str, "-help")) + usage(); + if (!strcmp (str, "version") || !strcmp (str, "-version")) { + version = 1; + usage(); + } + + /* crack arguments */ + for (av++; --ac > 0; av++) { + if (*(str = *av) == '-') { + char c; + while ((c = *++str)) + switch (c) { + + case 's': /* Replace this character with spaces in string arguments */ + if (ac > 1) { + spchar= *++av[0]; + ac--; + } + break; + + case 'v': /* more verbosity */ + verbose++; + break; + + default: + usage(); + break; + } + } + + /* String component */ + else { + if (nkwd >= maxnkwd) { + maxnkwd = maxnkwd * 2; + kwd = (char **) realloc ((void *)kwd, maxnkwd); + } + kwd[nkwd] = *av; + nkwd++; + } + } + + if (nkwd <= 0 ) + usage (); + else if (nkwd <= 0) { + fprintf (stderr, "HTML2SP: no string components specified\n"); + exit (1); + } + else stripHTMLTags ( + + +int +stripHTMLTags (char *instring, size_t size) +{ +int i=0,j=0,k=0; +int flag = 0; // 0: searching for < or & (& as in &bspn; etc), 1: searching for >, 2: searching for ; after &, 3: searching for ,, --> +char tempbuf[1024*1024] = ""; +char searchbuf[1024] = ""; + +while(i,"); + //printf("DEBUG: Detected %s\n",tempbuf); + tempbuf[0] = '\0'; + k = 0; + } + else if((0 == strcmp(tempbuf,"!--"))) { + flag = 3; + strcpy(searchbuf,"-->"); + //printf("DEBUG: Detected %s\n",tempbuf); + tempbuf[0] = '\0'; + k = 0; + } + + if (instring[i] == '>') { + instring[j] = ' '; + j++; + flag = 0; + } + + } + + else if (flag == 2) { + if(instring[i] == ';') { + sToClean[j] = ' '; + j++; + flag = 0; + } + } + + else if(flag == 3) { + tempbuf[k] = sToClean[i]; + k++; + tempbuf[k] = '\0'; + + //printf("DEBUG: %s\n",tempbuf); + //printf("DEBUG: Searching for %s\n",searchbuf); + + if (0 == strcmp(&tempbuf[0] + k - strlen(searchbuf),searchbuf)) { + flag = 0; + //printf("DEBUG: Detected END OF %s\n",searchbuf); + + searchbuf[0] = '\0'; + tempbuf[0] = '\0'; + k = 0; + } + } + + i++; + } + +instring[j] = '\0'; + +return j; +} +s + lstr = strlen (kwd[ikwd]); + for (i = 0; i < lstr; i++) { + if (kwd[ikwd][i] == spchar) + kwd[ikwd][i] = ' '; + } + printf ("%s", kwd[ikwd]); + if (ikwd < nkwd - 1) + printf (" "); + else + printf ("\n"); + } + + free (kwd); + + return (0); +} + +static void +usage () +{ + fprintf (stderr,"%s\n",RevMsg); + if (version) + exit (-1); + fprintf (stderr,"Removes HTML code from a string with spaces (def=_)\n"); + fprintf(stderr,"Usage: [-v][-s char] string [string2][...][string n]\n"); + fprintf(stderr," -s [char]: Replace this character with spaces in output\n"); + fprintf(stderr," -v: Verbose\n"); + exit (1); +} + +/* Jan 8 2002 New program + * + * Apr 3 2006 Declare main to be int + * Jun 20 2006 Drop unused variables + */ diff -Nru wcstools-3.9.5/libwcs/NEWS wcstools-3.9.6/libwcs/NEWS --- wcstools-3.9.5/libwcs/NEWS 2017-04-13 16:01:07.000000000 +0000 +++ wcstools-3.9.6/libwcs/NEWS 2019-10-29 18:37:14.000000000 +0000 @@ -1,6 +1,13 @@ WCSTools WCS subroutine library release history -Version 3.9.5 (March 30, 2017) +Version 3.9.5 (October 29, 2019) +datutil.c: In agets(), drop trailing commas, underscores, spaces (2019-10-29) +dateutil.c: Add ang2sec() and deg2sec() to convert to arcseconds (2019-09-24) +dateutil.c: Allocate new output string for fd2ofd() and fd2oft() (2017-05-02) +fitsfile.c: Increase header length default to 288000 = 100 blocks (2019-09-23) +hput.c: Allow arbitrary length keywords up to 64 characters (2018-08-28) +wcs.c: Change strcpy() to strncpy() where destination shorter than origin (2017-12-12) +wcsinit.c: Read up to 16 characters for ctype[2] and ctype[3] (2018-05-21) Version 3.9.4 (August 2, 2016) (after Ole Streicher) wcs.c: Clean up use of ptype so it is always 3 characters long diff -Nru wcstools-3.9.5/libwcs/Readme wcstools-3.9.6/libwcs/Readme --- wcstools-3.9.5/libwcs/Readme 1999-12-03 16:04:23.000000000 +0000 +++ wcstools-3.9.6/libwcs/Readme 2018-07-31 21:19:02.000000000 +0000 @@ -2,11 +2,14 @@ These subroutines support the programs in the WCSTools package and include catalog search engines, image manipulation software, and fitting software. -There use is documented on the World Wide Web at +Their use is documented on the World Wide Web at http://tdc-www.harvard.edu/software/wcstools/ -Information about the individual files is in the Subroutines file. +Information about the individual files is here: + + http://tdc-www.harvard.edu/software/wcstools/subroutines/ + A self-contained subset of these programs which deal with image world coordinate systems is separately available and is used by the SAOimage, SAOtng, Skycat, and DS9 image display programs: diff -Nru wcstools-3.9.5/libwcs/sdsssql.c wcstools-3.9.6/libwcs/sdsssql.c --- wcstools-3.9.5/libwcs/sdsssql.c 1970-01-01 00:00:00.000000000 +0000 +++ wcstools-3.9.6/libwcs/sdsssql.c 2018-11-06 02:27:23.000000000 +0000 @@ -0,0 +1,252 @@ +/*** File libwcs/sdsssql.c + *** September 16, 2013 + *** By Jessica Mink, jmink@cfa.harvard.edu + *** Harvard-Smithsonian Center for Astrophysics + *** Copyright (C) 2004-2013 + *** Smithsonian Astrophysical Observatory, Cambridge, MA, USA + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Correspondence concerning WCSTools should be addressed as follows: + Internet email: jmink@cfa.harvard.edu + Postal address: Jessica Mink + Smithsonian Astrophysical Observatory + 60 Garden St. + Cambridge, MA 02138 USA + */ + +#include +#include +#include +#include +#include +#include +#include "fitsfile.h" +#include "wcs.h" +#include "wcscat.h" + +#define ABS(a) ((a) < 0 ? (-(a)) : (a)) +#define LINE 1024 + +/* SDSS DR14 search engine former main server URL */ +char sdssrurl[64]="http://skyserver.sdss.org/dr14/en/tools/search/X_Results.aspx"; + +/* SDSS magnitudes */ +char sdssmag[6]="ugriz"; + +/* SDSSREAD -- Read Sloan Digital Sky Survey catalog stars over the web */ + +int +sdssread (cra,cdec,dra,ddec,drad,dradi,distsort,sysout,eqout,epout, + mag1,mag2,sortmag,nstarmax,gnum,gobj,gra,gdec,gmag,gtype,nlog) + +double cra; /* Search center J2000 right ascension in degrees */ +double cdec; /* Search center J2000 declination in degrees */ +double dra; /* Search half width in right ascension in degrees */ +double ddec; /* Search half-width in declination in degrees */ +double drad; /* Limiting separation in degrees (ignore if 0) */ +double dradi; /* Inner edge of annulus in degrees (ignore if 0) */ +int distsort; /* 1 to sort stars by distance from center */ +int sysout; /* Search coordinate system */ +double eqout; /* Search coordinate equinox */ +double epout; /* Proper motion epoch (0.0 for no proper motion) */ +double mag1,mag2; /* Limiting magnitudes (none if equal) */ +int sortmag; /* Magnitude by which to sort (1 to nmag) */ +int nstarmax; /* Maximum number of stars to be returned */ +double *gnum; /* Array of catalog numbers (returned) */ +char **gobj; /* Array of object IDs (too long for integer*4) */ +double *gra; /* Array of right ascensions (returned) */ +double *gdec; /* Array of declinations (returned) */ +double **gmag; /* 2-D array of magnitudes (returned) */ +int *gtype; /* Array of object classes (returned) */ +int nlog; /* 1 for diagnostics */ +{ + char srchurl[LINE]; + char temp[64]; + char cmag; + struct TabTable *tabtable; + double dtemp; + double *gpra, *gpdec; + struct StarCat *starcat; + int nstar, nlog0; + double ra, dec, mag; + char rastr[32], decstr[32]; + char *sdssurl; + + gpra = NULL; + gpdec = NULL; + + nlog0 = nlog; + if (nstarmax < 1) + nlog = -1; + + /* make mag1 always the smallest magnitude */ + if (mag2 < mag1) { + mag = mag2; + mag2 = mag1; + mag1 = mag; + } + if (mag1 < 0) + mag1 = 0.0; + + /* Set up SQL query for SDSS SQL server */ + ra = cra; + dec = cdec; + if (sysout != WCS_J2000) + wcscon (sysout, WCS_J2000, eqout, 2000.0, &ra, &dec, epout); + + nstar = 50000; + sdssurl = sdssrurl; + deg2str (rastr, 32, ra, 5); + deg2str (decstr, 32, dec, 5); + sprintf (srchurl, "?searchtool=SQL&TaskName=Skyserver.Search.SearchForm&format=csv"); + sprintf (temp, "select top %d p.objid, p.ra, p.dec, p.u, p.g, p.r, p.i, p.z from star p, ", nstar); + strcat (srchurl, temp); + + /* Radius or box size */ + if (drad != 0.0) { + dtemp = drad * 60.0; + } + else { + dtemp = sqrt (dra*dra + ddec*ddec) * 60.0; + } + sprintf (temp, "dbo.fgetNearByObjEq(%.5f,%.5f,%.3f) n", ra, dec, dtemp); + strcat (srchurl, temp); + sprintf (temp, "where p.objid=n.objid"); + strcat (srchurl, temp); + + /* Magnitude limit, if any */ + if (sortmag < 1) + cmag = 'g'; + else + cmag = sdssmag[sortmag - 1]; + if (mag1 < mag2) { + sprintf (temp, " and (p.%c BETWEEN %.2f AND %.2f)", cmag, mag1, mag2); + strcat (srchurl, temp); + } + + if (nlog0 > 0) + fprintf (stderr,"%s%s\n", sdssurl, srchurl); + + /* Run search across the web */ + if ((tabtable = webopen (sdssurl, srchurl, nlog)) == NULL) { + if (nlog > 0) + fprintf (stderr, "WEBREAD: %s failed\n", srchurl); + return (0); + } + + /* Return if no data */ + if (tabtable->tabdata == NULL || strlen (tabtable->tabdata) == 0 || + !strncasecmp (tabtable->tabdata, "[EOD]", 5)) { + if (nlog > 0) + fprintf (stderr, "WEBRNUM: No data returned\n"); + return (0); + } + + /* Dump returned file and stop */ + if (nlog < 0) { + (void) fwrite (tabtable->tabbuff, tabtable->lbuff, 1, stdout); + exit (0); + } + + /* Open returned Starbase table as a catalog */ + if ((starcat = tabcatopen (sdssurl, tabtable,0)) == NULL) { + if (nlog > 0) + fprintf (stderr, "WEBREAD: Could not open Starbase table as catalog\n"); + return (0); + } + + /* Set reference frame, epoch, and equinox of catalog */ + starcat->coorsys = WCS_J2000; + starcat->epoch = 2000.0; + starcat->equinox = 2000.0; + starcat->nmag = 5; + + /* Extract desired sources from catalog and return them */ + nstar = tabread (sdssurl,distsort,cra,cdec,dra,ddec,drad,dradi, + sysout,eqout,epout,mag1,mag2,sortmag,nstarmax,&starcat, + gnum,gra,gdec,gpra,gpdec,gmag,gtype,gobj,nlog); + + tabcatclose (starcat); + + starcat = NULL; + + return (nstar); +} + +char * +sdssc2t (csvbuff) + + char *csvbuff; /* Input comma-separated table */ + +{ + char colhead[180]="objID run rerun camcol field obj type ra dec umag gmag rmag imag zmag uerr gerr rerr ierr zerr \n"; + char colsep[180]="------------------ --- ----- ------ ----- --- ---- ---------- --------- ------ ------ ------ ------ ------ -------- ------ -------- -------- -------\n"; + char *tabbuff; /* Output tab-separated table */ + char *databuff; + char *lastbuff; + int lbuff, i; + char ctab = (char) 9; + char ccom = ','; + + /* Skip first line of returned header */ + databuff = strchr (csvbuff, '\n') + 1; + + /* Drop extraneous data after last linefeed */ + lbuff = strlen (databuff); + lastbuff = strrchr (databuff, '\n'); + if (lastbuff - databuff < lbuff) + *(lastbuff+1) = (char) 0; + + /* Convert commas in table to tabs */ + lbuff = strlen (databuff); + for (i = 0; i < lbuff; i++) { + if (databuff[i] == ccom) + databuff[i] = ctab; + } + + /* Allocate buffer for tab-separated table with header */ + lbuff = strlen (databuff) + strlen (colhead) + strlen (colsep); + tabbuff = (char *) calloc (lbuff, 1); + + /* Copy column headings, separator, and data to output buffer */ + strcpy (tabbuff, colhead); + strcat (tabbuff, colsep); + strcat (tabbuff, databuff); + + return (tabbuff); +} + +/* Jan 5 2004 New program + * + * Apr 6 2006 Use different server to get DR4 data + * Jun 20 2006 Drop unused variables + * Jul 11 2006 Change path to Data Release 5 + * Oct 30 2006 Print URL in verbose mode when printing web-returned sources + * Oct 30 2006 Fix bug in buffer length when setting up tab table + * Nov 3 2006 Drop extra characters from end of data returned from SDSS + * Nov 6 2006 Pass SDSS ID as character string because it is too long integer + * + * Jan 8 2007 Drop unused variables + * Jan 9 2007 Drop refcatname from argument list; it is not used + * Jan 10 2007 Drop gnum argument from sdssread(); gobj replaced it + * Oct 22 2007 Change path to Data Release 6 + * + * May 01 2012 Change path to Data Release 7 + * + * Sep 16 2013 Add alternate servers for SDSS + * + * Jan 13 2015 Add new main server for SDSS DR7 + */ diff -Nru wcstools-3.9.5/libwcs/ucacread.c wcstools-3.9.6/libwcs/ucacread.c --- wcstools-3.9.5/libwcs/ucacread.c 2016-06-23 15:13:48.000000000 +0000 +++ wcstools-3.9.6/libwcs/ucacread.c 2018-08-03 21:54:45.000000000 +0000 @@ -1,1933 +1,1962 @@ -/*** File libwcs/ucacread.c - *** June 22, 2016 - *** By Jessica Mink, jmink@cfa.harvard.edu - *** Harvard-Smithsonian Center for Astrophysics - *** Copyright (C) 2003-2016 - *** Smithsonian Astrophysical Observatory, Cambridge, MA, USA - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Correspondence concerning WCSTools should be addressed as follows: - Internet email: jmink@cfa.harvard.edu - Postal address: Jessica Mink - Smithsonian Astrophysical Observatory - 60 Garden St. - Cambridge, MA 02138 USA - - * ucacread() Read UCAC Star Catalog stars in a rectangle on the sky - * ucacrnum() Read UCAC Star Catalog stars by number - * ucacbin() Fill a FITS WECS image with UCAC Star Catalog stars - * ucaczones() Make list of zones covered by a range of declinations - * ucacsra (sc,st,zone,rax0) Find UCAC star closest to specified right ascension - * ucacopen(zone, nstars) Open UCAC catalog file, returning number of entries - * ucacclose (sc) Close UCAC catalog file - * ucacstar (sc,st,zone,istar) Get UCAC catalog entry for one star - */ - -#include -#include -#include -#include -#include -#include -#include "fitsfile.h" -#include "wcs.h" -#include "wcscat.h" - -#define MAXZONE 900 -#define ABS(a) ((a) < 0 ? (-(a)) : (a)) - -/* #define UCAC_DEBUG 1 */ -typedef struct { - int rasec, decsec; - short cmag; - unsigned char era, edec, nobs, rflg, ncat, cflg; - short epra, epdec; - int rapm, decpm; - unsigned char erapm, edecpm, qrapm, qdecpm; - int id2m; - short jmag, hmag, kmag, qm, cc; -} UCAC2star; - -typedef struct { - int rasec, decsec; - short mmag, amag, sigmag; - char objt, dsf; - short sigra, sigdec; - char na1, nu1, us1, cn1; - short cepra, cepdec; - int rapm, decpm; - short sigpmr, sigpmd; - int id2m; - short jmag, hmag, kmag; - char jq, hq, kq; - char e2mpho[3]; - short bmag, rmag, imag; - char clbl; - char bq, rq, iq; - char catflg[10]; - char g1, c1, leda, x2m; - int rn; -} UCAC3star; -/* The following is from ucac4.h */ -#pragma pack( 1) -typedef struct { - int32_t ra, spd; /* RA/dec at J2000.0, ICRS, in milliarcsec */ - uint16_t magm, maga; /* UCAC fit model & aperture mags, .001 mag */ - uint8_t mag_sigma; - uint8_t obj_type, double_star_flag; - int8_t ra_sigma, dec_sigma; /* sigmas in RA and dec at central epoch */ - uint8_t n_ucac_total; /* Number of UCAC observations of this star */ - uint8_t n_ucac_used; /* # UCAC observations _used_ for this star */ - uint8_t n_cats_used; /* # catalogs (epochs) used for prop motion */ - uint16_t epoch_ra; /* Central epoch for mean RA, minus 1900, .01y */ - uint16_t epoch_dec; /* Central epoch for mean DE, minus 1900, .01y */ - int16_t pm_ra; /* prop motion, .1 mas/yr = .01 arcsec/cy */ - int16_t pm_dec; /* prop motion, .1 mas/yr = .01 arcsec/cy */ - int8_t pm_ra_sigma; /* sigma in same units */ - int8_t pm_dec_sigma; - uint32_t twomass_id; /* 2MASS pts_key star identifier */ - uint16_t mag_j, mag_h, mag_k; /* 2MASS J, H, K_s mags, in millimags */ - uint8_t icq_flag[3]; - uint8_t e2mpho[3]; /* 2MASS error photometry (in centimags) */ - uint16_t apass_mag[5]; /* in millimags */ - uint8_t apass_mag_sigma[5]; /* also in millimags */ - uint8_t yale_gc_flags; /* Yale SPM g-flag * 10 + c-flag */ - uint32_t catalog_flags; - uint8_t leda_flag; /* LEDA galaxy match flag */ - uint8_t twomass_ext_flag; /* 2MASS extended source flag */ - uint32_t id_number; - uint16_t ucac2_zone; - uint32_t ucac2_number; -} UCAC4star; -#pragma pack( ) -/* Fields in the u4hpm.dat file */ -#define MAX_U4HPM_RECORDS 50 -#define MAX_U4HPM_LINE 512 -typedef struct u4hpm { - int rnm; /* unique star identifier (col. 51 main data) */ - int zn; /* UCAC4 zone number for this star */ - int rnz; /* unning record number along that zone for this star */ - int pmrc; /* actual proper motion in RA*cos(dec) [0.1 mas/yr] */ - int pmd; /* actual proper motion in Dec [0.1 mas/yr] */ - int ra; /* col. 1 of main data file (redundant) */ - int dec; /* col. 2 of main data file (redundant) */ - int maga; /* col. 4 of main data file (redundant) */ -} U4HPM,*PU4HPM; - - -int hpmLines = 0; -U4HPM u4hpm_table[MAX_U4HPM_RECORDS]; - - -/* pathname of UCAC1 decompressed data files or search engine URL */ -char ucac1path[64]="/data/astrocat/ucac1"; - -/* pathname of UCAC2 decompressed data files or search engine URL */ -char ucac2path[64]="/data/astrocat/ucac2"; - -/* pathname of UCAC3 decompressed data files or search engine URL */ -char ucac3path[64]="/data/astrocat/ucac3"; - -/* pathname of UCAC4 decompressed data files or search engine URL */ -char ucac4path[64]="/data/astrocat/ucac4/u4b"; - -/* Path name of UCAC4 proper motion catalog */ -char hpmpath[] = "/data/astrocat/ucac4/u4i/u4hpm.dat"; - -char *ucacpath; -static int ucat = 0; - -static double *gdist; /* Array of distances to stars */ -static int ndist = 0; -static int cswap = 0; /* Byte reverse catalog to Mac/Sun/network order if 1 */ - -static int ucaczones(); -struct StarCat *ucacopen(); -void ucacclose(); -static int ucacsra(); -static int ucacstar(); -static void ucacswap4(); -static void ucacswap2(); - - -/* UCACREAD -- Read UCAC Star Catalog stars */ - -int -ucacread (refcatname,cra,cdec,dra,ddec,drad,dradi,distsort,sysout,eqout,epout, - mag1,mag2,sortmag,nstarmax,gnum,gra,gdec,gpra,gpdec,gmag,gtype,nlog) - -char *refcatname; /* Name of catalog (UAC, USAC, UAC2, USAC2) */ -double cra; /* Search center J2000 right ascension in degrees */ -double cdec; /* Search center J2000 declination in degrees */ -double dra; /* Search half width in right ascension in degrees */ -double ddec; /* Search half-width in declination in degrees */ -double drad; /* Limiting separation in degrees (ignore if 0) */ -double dradi; /* Inner edge of annulus in degrees (ignore if 0) */ -int distsort; /* 1 to sort stars by distance from center */ -int sysout; /* Search coordinate system */ -double eqout; /* Search coordinate equinox */ -double epout; /* Proper motion epoch (0.0 for no proper motion) */ -double mag1,mag2; /* Limiting magnitudes (none if equal) */ -int sortmag; /* Magnitude by which to sort (1-8) */ -int nstarmax; /* Maximum number of stars to be returned */ -double *gnum; /* Array of Guide Star numbers (returned) */ -double *gra; /* Array of right ascensions (returned) */ -double *gdec; /* Array of declinations (returned) */ -double *gpra; /* Array of right ascension proper motions (returned) */ -double *gpdec; /* Array of declination proper motions (returned) */ -double **gmag; /* Array of magnitudes (returned) */ -int *gtype; /* Array of object types (returned) */ -int nlog; /* 1 for diagnostics */ -{ - double ra1,ra2; /* Limiting right ascensions of region in degrees */ - double dec1,dec2; /* Limiting declinations of region in degrees */ - double dist = 0.0; /* Distance from search center in degrees */ - double faintmag=0.0; /* Faintest magnitude */ - double maxdist=0.0; /* Largest distance */ - int faintstar=0; /* Faintest star */ - int farstar=0; /* Most distant star */ - int nz; /* Number of UCAC regions in search */ - int zlist[MAXZONE]; /* List of region numbers */ - int sysref = WCS_J2000; /* Catalog coordinate system */ - double eqref = 2000.0; /* Catalog equinox */ - double epref = 2000.0; /* Catalog epoch */ - double secmarg = 60.0; /* Arcsec/century margin for proper motion */ - struct StarCat *starcat; /* Star catalog data structure */ - struct Star *star; /* Single star data structure */ - double errra, errdec, errpmr, errpmd; - int nim, ncat; - int verbose; - int wrap; - int iz; - int magsort; - int jstar; - int nrmax = MAXZONE; - int nstar,i, ntot, imag; - int istar, istar1, istar2; - int jtable,iwrap, nread; - int pass; - int zone; - int nmag; - double num, ra, dec, rapm, decpm, mag; - double rra1, rra2, rdec1, rdec2; - double rdist, ddist; - char cstr[32], rastr[32], decstr[32]; - char ucacenv[16]; - char *str; - - ntot = 0; - if (nlog > 0) - verbose = 1; - else - verbose = 0; - - /* Set catalog code and path to catalog */ - if (strncmp (refcatname,"ucac2",5)==0 || - strncmp (refcatname,"UCAC2",5)==0) { - ucat = UCAC2; - ucacpath = ucac2path; - strcpy (ucacenv, "UCAC2_PATH"); - nmag = 4; - } - else if (strncmp (refcatname,"ucac3",5)==0 || - strncmp (refcatname,"UCAC3",5)==0) { - ucat = UCAC3; - ucacpath = ucac3path; - strcpy (ucacenv, "UCAC3_PATH"); - nmag = 8; - } - else if (strncmp (refcatname,"ucac4",5)==0 || - strncmp (refcatname,"UCAC4",5)==0) { - ucat = UCAC4; - ucacpath = ucac4path; - strcpy (ucacenv, "UCAC4_PATH"); - nmag = 10; - } - else { - ucat = UCAC1; - ucacpath = ucac1path; - strcpy (ucacenv, "UCAC1_PATH"); - nmag = 1; - } - - /* If pathname is set in environment, override local value */ - if ((str = getenv (ucacenv)) != NULL ) - ucacpath = str; - - /* If pathname is a URL, search and return */ - if (!strncmp (ucacpath, "http:",5)) { - return (webread (ucacpath,refcatname,distsort,cra,cdec,dra,ddec,drad, - dradi,sysout,eqout,epout,mag1,mag2,sortmag,nstarmax, - gnum,gra,gdec,gpra,gpdec,gmag,gtype,nlog)); - } - - wcscstr (cstr, sysout, eqout, epout); - - SearchLim (cra,cdec,dra,ddec,sysout,&ra1,&ra2,&dec1,&dec2,verbose); - - /* Make mag1 always the smallest magnitude */ - if (mag2 < mag1) { - mag = mag2; - mag2 = mag1; - mag1 = mag; - } - - if (sortmag < 1) - magsort = 0; - else if (sortmag > nmag) - magsort = nmag - 1; - else - magsort = sortmag - 1; - - /* Allocate table for distances of stars from search center */ - if (nstarmax > ndist) { - if (ndist > 0) - free ((void *)gdist); - gdist = (double *) malloc (nstarmax * sizeof (double)); - if (gdist == NULL) { - fprintf (stderr,"UCACREAD: cannot allocate separation array\n"); - return (0); - } - ndist = nstarmax; - } - - /* Allocate catalog entry buffer */ - star = (struct Star *) calloc (1, sizeof (struct Star)); - star->num = 0.0; - - nstar = 0; - jstar = 0; - - /* Get RA and Dec limits in catalog (J2000) coordinates */ - rra1 = ra1; - rra2 = ra2; - rdec1 = dec1; - rdec2 = dec2; - RefLim (cra,cdec,dra,ddec,sysout,sysref,eqout,eqref,epout,epref,secmarg, - &rra1, &rra2, &rdec1, &rdec2, &wrap, verbose); - - /* Find UCAC Star Catalog zones in which to search */ - nz = ucaczones (rdec1,rdec2,nrmax,zlist,verbose); - if (nz <= 0) { - fprintf (stderr,"UCACREAD: no UCAC zone for %.2f-%.2f %.2f %.2f\n", - rra1, rra2, rdec1, rdec2); - return (0); - } - - /* Write header if printing star entries as found */ - if (nstarmax < 1) { - char *revmessage; - revmessage = getrevmsg(); - printf ("catalog UCAC1\n"); - ra2str (rastr, 31, cra, 3); - printf ("ra %s\n", rastr); - dec2str (decstr, 31, cdec, 2); - printf ("dec %s\n", decstr); - printf ("rpmunit mas/year\n"); - printf ("dpmunit mas/year\n"); - if (drad != 0.0) { - printf ("radmin %.1f\n", drad*60.0); - if (dradi > 0) - printf ("radimin %.1f\n", dradi*60.0); - } - else { - printf ("dramin %.1f\n", dra*60.0* cosdeg (cdec)); - printf ("ddecmin %.1f\n", ddec*60.0); - } - printf ("radecsys %s\n", cstr); - printf ("equinox %.3f\n", eqout); - printf ("epoch %.3f\n", epout); - printf ("program scat %s\n", revmessage); - printf ("ucac_id ra dec "); - if (ucat == UCAC1) { - printf ("mag ura udec arcmin\n"); - printf ("---------- ------------ ------------ "); - printf ("----- ------ ------ ------\n"); - } - else if (ucat == UCAC2) { - printf ("raerr decerr magc "); - printf ("magj magh magk mag "); - printf ("pmra pmdec pmrerr pmderr "); - printf ("ni nc arcsec\n"); - printf ("---------- ------------ ------------ "); - printf ("------ ------ ----- ----- ----- "); - printf ("----- ----- ------ ------ ----- ----- "); - printf ("-- -- ------\n"); - } - else if (ucat == UCAC3) { - printf ("raerr decerr magb magr magi "); - printf ("magj magh magk maga magm "); - printf ("mag pmra pmdec pmrerr pmderr "); - printf ("ni nc arcsec\n"); - printf ("---------- ------------ ------------ "); - printf ("------ ------ ----- ------ ----- "); - printf ("----- ----- ----- ----- ----- "); - printf ("----- ----- ----- ------ ------ "); - printf ("-- -- ------\n"); - } - else if (ucat == UCAC4) { - printf ("raerr decerr magb magv magg "); - printf ("magr magi magj magj magk "); - printf ("pmra pmdec pmrerr pmderr "); - printf ("ni nc arcsec\n"); - printf ("---------- ------------ ------------ "); - printf ("------ ------ ----- ------ ----- "); - printf ("----- ----- ----- ----- ----- "); - printf ("----- ----- ------ ------ "); - printf ("-- -- ------\n"); - } - } - - /* Loop through zone list */ - nstar = 0; - for (iz = 0; iz < nz; iz++) { - - /* Get path to zone catalog */ - zone = zlist[iz]; - -#ifdef UCAC_DEBUG - if (zone == 183) { - fprintf(stderr,"at zone %d\n",zone); - } -#endif /* UCAC_DEBUG */ - - if ((starcat = ucacopen (zone)) != 0) { - - jstar = 0; - jtable = 0; - for (iwrap = 0; iwrap <= wrap; iwrap++) { - - /* Find first star based on RA */ - if (iwrap == 0 || wrap == 0) { - istar1 = ucacsra (starcat, star, zone, rra1); - if (istar1 > 5) - istar1 = istar1 - 5; - else - istar1 = 1; - } - else - istar1 = 1; - - /* Find last star based on RA */ - if (iwrap == 1 || wrap == 0) { - istar2 = ucacsra (starcat, star, zone, rra2); - if (istar2 < starcat->nstars - 5) - istar2 = istar2 + 5; - else - istar2 = starcat->nstars; - } - else - istar2 = starcat->nstars; - - if (istar1 == 0 || istar2 == 0) - break; - - nread = istar2 - istar1 + 1; - - /* Loop through zone catalog for this region */ - for (istar = istar1; istar <= istar2; istar++) { - jtable ++; - - if (ucacstar (starcat, star, zone, istar)) { - fprintf(stderr,"UCACREAD: Cannot read star %d\n",istar); - break; - } - - /* ID number */ - num = star->num; - - /* Magnitude */ - mag = star->xmag[magsort]; - - /* Check magnitude limits */ - pass = 1; - if (mag1 != mag2 && (mag < mag1 || mag > mag2)) - pass = 0; - - /* Check position limits */ - if (pass) { - - /* Get position in output coordinate system */ - ra = star->ra; - dec = star->dec; - rapm = star->rapm; - decpm = star->decpm; - errra = star->errra; - errdec = star->errdec; - errpmr = star->errpmr; - errpmd = star->errpmd; - nim = star->nimage; - ncat = star->ncat; - wcsconp (sysref, sysout, eqref, eqout, epref, epout, - &ra, &dec, &rapm, &decpm); - - /* Compute distance from search center */ - if (drad > 0 || distsort) - dist = wcsdist (cra,cdec,ra,dec); - else - dist = 0.0; - - /* Check radial distance to search center */ - if (drad > 0) { - if (dist > drad) - pass = 0; - if (dradi > 0.0 && dist < dradi) - pass = 0; - } - - /* Check distance along RA and Dec axes */ - else { - ddist = wcsdist (cra,cdec,cra,dec); - if (ddist > ddec) - pass = 0; - rdist = wcsdist (cra,dec,ra,dec); - if (rdist > dra) - pass = 0; - } - } - - if (pass) { - - /* Write star position and magnitude to stdout */ - if (nstarmax < 1) { - ra2str (rastr, 31, ra, 3); - dec2str (decstr, 31, dec, 2); - dist = wcsdist (cra,cdec,ra,dec) * 3600.0; - printf ("%010.6f %s %s", num,rastr,decstr); - if (ucat == UCAC2 || ucat == UCAC3 || ucat == UCAC4) - printf (" %5.3f %5.3f", - errra * 3600.0 * cosdeg (dec), errdec * 3600.0); - if (ucat == UCAC1) - printf (" %5.2f", mag); - else - printf (" %5.2f %5.2f %5.2f %5.2f", - star->xmag[0], star->xmag[1], - star->xmag[2], star->xmag[3]); - if (ucat == UCAC3 || ucat == UCAC4) - printf (" %5.2f %5.2f %5.2f %5.2f", - star->xmag[4], star->xmag[5], - star->xmag[6], star->xmag[7]); - printf (" %5.2f %6.1f %6.1f", - mag, rapm*3600000.0*cosdeg (dec), - decpm*3600000.0); - printf (" %6.1f %6.1f", - errpmr*3600000.0, errpmd*3600000.0); - printf (" %2d %2d %.3f\n", nim, ncat, dist); - } - - /* Save star position and magnitude in table */ - else if (nstar < nstarmax) { - gnum[nstar] = num; - gra[nstar] = ra; - gdec[nstar] = dec; - gpra[nstar] = rapm; - gpdec[nstar] = decpm; - if (ucat == UCAC1) - gmag[0][nstar] = mag; - else { - for (imag = 0; imag < nmag; imag++) - gmag[imag][nstar] = star->xmag[imag]; - gmag[nmag][nstar] = star->errra; - gmag[nmag+1][nstar] = star->errdec; - gmag[nmag+2][nstar] = star->errpmr; - gmag[nmag+3][nstar] = star->errpmd; - gtype[nstar] = (1000 * nim) + ncat; - } - gdist[nstar] = dist; - if (dist > maxdist) { - maxdist = dist; - farstar = nstar; - } - if (mag > faintmag) { - faintmag = mag; - faintstar = nstar; - } - } - - /* If too many stars and distance sorting, - replace farthest star */ - else if (distsort) { - if (dist < maxdist) { - gnum[farstar] = num; - gra[farstar] = ra; - gdec[farstar] = dec; - gpra[farstar] = rapm; - gpdec[farstar] = decpm; - if (ucat == UCAC1) - gmag[0][farstar] = mag; - else { - for (imag = 0; imag < nmag; imag++) - gmag[imag][farstar] = star->xmag[imag]; - gmag[nmag][farstar] = star->errra; - gmag[nmag+1][farstar] = star->errdec; - gmag[nmag+2][farstar] = star->errpmr; - gmag[nmag+3][farstar] = star->errpmd; - gtype[farstar] = (1000 * nim) + ncat; - } - gdist[farstar] = dist; - - /* Find new farthest star */ - maxdist = 0.0; - for (i = 0; i < nstarmax; i++) { - if (gdist[i] > maxdist) { - maxdist = gdist[i]; - farstar = i; - } - } - } - } - - /* Else if too many stars, replace faintest star */ - else if (mag < faintmag) { - gnum[faintstar] = num; - gra[faintstar] = ra; - gdec[faintstar] = dec; - gpra[faintstar] = rapm; - gpdec[faintstar] = decpm; - if (ucat == UCAC1) - gmag[0][faintstar] = mag; - else { - for (imag = 0; imag < nmag; imag++) - gmag[imag][faintstar] = star->xmag[imag]; - gmag[nmag][faintstar] = star->errra; - gmag[nmag+1][faintstar] = star->errdec; - gmag[nmag+2][faintstar] = star->errpmr; - gmag[nmag+3][faintstar] = star->errpmd; - gtype[faintstar] = (1000 * nim) + ncat; - } - gdist[faintstar] = dist; - - /* Find new faintest star */ - faintmag = 0.0; - for (i = 0; i < nstarmax; i++) { - if (gmag[magsort][i] > faintmag) { - faintmag = gmag[magsort][i]; - faintstar = i; - } - } - } - - nstar++; - if (nlog == 1) - fprintf (stderr,"UCACREAD: %11.6f: %9.5f %9.5f %5.2f\n", - num,ra,dec,mag); - - /* End of accepted star processing */ - } - - /* Log operation */ - jstar++; - if (nlog > 0 && istar%nlog == 0) - fprintf (stderr,"UCACREAD: %5d / %5d / %5d sources\r", - nstar,jstar,starcat->nstars); - - /* End of star loop */ - } - - /* End of 0:00 RA wrap loop */ - } - - /* End of successful zone file loop */ - ntot = ntot + starcat->nstars; - if (nlog > 0) - fprintf (stderr,"UCACREAD: %4d / %4d: %5d / %5d / %5d sources from zone %4d \n", - iz+1,nz,nstar,jstar,starcat->nstars,zlist[iz]); - - /* Close region input file */ - ucacclose (starcat); - } - - /* End of zone loop */ - } - - /* Summarize transfer */ - if (nlog > 0) { - if (nz > 1) - fprintf (stderr,"UCACREAD: %d zones: %d / %d found\n",nz,nstar,ntot); - else - fprintf (stderr,"UCACREAD: 1 region: %d / %d found\n",nstar,ntot); - if (nstar > nstarmax) - fprintf (stderr,"UCACREAD: %d stars found; only %d returned\n", - nstar,nstarmax); - } - return (nstar); -} - -/* UCACRNUM -- Read HST Guide Star Catalog stars from CDROM */ - -int -ucacrnum (refcatname,nstars,sysout,eqout,epout, - gnum,gra,gdec,gpra,gpdec,gmag,gtype,nlog) - - char *refcatname; /* Name of catalog (UAC, USAC, UAC2, USAC2) */ - int nstars; /* Number of stars to find */ - int sysout; /* Search coordinate system */ - double eqout; /* Search coordinate equinox */ - double epout; /* Proper motion epoch (0.0 for no proper motion) */ - double *gnum; /* Array of Guide Star numbers (returned) */ - double *gra; /* Array of right ascensions (returned) */ - double *gdec; /* Array of declinations (returned) */ - double *gpra; /* Array of right ascension proper motions (returned) */ - double *gpdec; /* Array of declination proper motions (returned) */ - double **gmag; /* Array of B and V magnitudes (returned) */ - int *gtype; /* Array of object types (returned) */ - int nlog; /* 1 for diagnostics */ -{ - int sysref=WCS_J2000; /* Catalog coordinate system */ - double eqref=2000.0; /* Catalog equinox */ - double epref=2000.0; /* Catalog epoch */ - struct StarCat *starcat; - struct Star *star; - char *str; - char ucacenv[16]; - - int verbose; - int zone, zone0; - int jstar, imag, nmag; - int istar, nstar; - double num, ra, dec, rapm, decpm, mag; - - if (nlog == 1) - verbose = 1; - else - verbose = 0; - - /* Set catalog code and path to catalog */ - if (strncmp (refcatname,"ucac4",5)==0 || - strncmp (refcatname,"UCAC4",5)==0) { - ucat = UCAC4; - ucacpath = ucac4path; - strcpy (ucacenv, "UCAC4_PATH"); - nmag = 8; - } - if (strncmp (refcatname,"ucac3",5)==0 || - strncmp (refcatname,"UCAC3",5)==0) { - ucat = UCAC3; - ucacpath = ucac3path; - strcpy (ucacenv, "UCAC3_PATH"); - nmag = 8; - } - else if (strncmp (refcatname,"ucac2",5)==0 || - strncmp (refcatname,"UCAC2",5)==0) { - ucat = UCAC2; - ucacpath = ucac2path; - strcpy (ucacenv, "UCAC2_PATH"); - nmag = 4; - } - else { - ucat = UCAC1; - ucacpath = ucac1path; - strcpy (ucacenv, "UCAC1_PATH"); - nmag = 1; - } - - /* If pathname is set in environment, override local value */ - if ((str = getenv(ucacenv)) != NULL ) - ucacpath = str; - - /* If pathname is a URL, search and return */ - if (!strncmp (ucacpath, "http:",5)) - return (webrnum (ucacpath,refcatname,nstars,sysout,eqout,epout,1, - gnum,gra,gdec,gpra,gpdec,gmag,gtype,nlog)); - - /* Allocate catalog entry buffer */ - star = (struct Star *) calloc (1, sizeof (struct Star)); - star->num = 0.0; - nstar = 0; - zone0 = 0; - starcat = NULL; - - /* Loop through star list */ - for (jstar = 0; jstar < nstars; jstar++) { - zone = (int) (gnum[jstar] + 0.0000001); - - /* Find numbered stars (rrr.nnnnnn) */ - istar = (int) ((gnum[jstar] - (double) zone + 0.0000001) * 1000000.0); - if (istar > 0) { - if (zone != zone0) { - if (starcat != NULL) - ucacclose (starcat); - starcat = ucacopen (zone); - } - if (starcat == NULL) { - fprintf (stderr,"UCACRNUM: Zone %d file not found\n", zone); - return (0); - } - if (ucacstar (starcat, star, zone, istar)) { - fprintf (stderr,"UCACRNUM: Cannot read star %d.%06d\n", zone, istar); - gra[jstar] = 0.0; - gdec[jstar] = 0.0; - if (ucat == UCAC1) - gmag[0][jstar] = 0.0; - else { - for (imag = 0; imag < nmag; imag++) - gmag[imag][jstar] = 0.0; - } - gtype[jstar] = 0; - continue; - } - - /* If star has been found in catalog */ - - /* ID number */ - num = star->num; - - /* Position in degrees at designated epoch */ - ra = star->ra; - dec = star->dec; - rapm = star->rapm; - decpm = star->decpm; - wcsconp (sysref, sysout, eqref, eqout, epref, epout, - &ra, &dec, &rapm, &decpm); - - /* Magnitude */ - mag = star->xmag[0]; - - /* Save star position and magnitude in table */ - gnum[jstar] = num; - gra[jstar] = ra; - gdec[jstar] = dec; - gpra[jstar] = rapm; - gpdec[jstar] = decpm; - gmag[0][jstar] = mag; - gtype[jstar] = (1000 * star->nimage) + star->ncat; - if (ucat == UCAC1) - gmag[0][jstar] = star->xmag[0]; - else { - for (imag = 0; imag < nmag; imag++) - gmag[imag][jstar] = star->xmag[imag]; - gmag[nmag][jstar] = star->errra; - gmag[nmag+1][jstar] = star->errdec; - gmag[nmag+2][jstar] = star->errpmr; - gmag[nmag+3][jstar] = star->errpmd; - gtype[jstar] = (1000 * star->nimage) + star->ncat; - } - if (nlog == 1) { - if (ucat == UCAC1) - fprintf (stderr,"UCACRNUM: %11.6f: %9.5f %9.5f %5.2f %s \n", - num, ra, dec, mag, star->isp); - else if (ucat == UCAC2) { - fprintf (stderr,"UCACRNUM: %11.6f: %9.5f %9.5f %5.2f", - num, ra, dec, star->xmag[0]); - fprintf (stderr," %5.2f %5.2f %5.2f", - star->xmag[1],star->xmag[2],star->xmag[3]); - fprintf (stderr," %d %d\n",star->nimage,star->ncat); - } - else if (ucat == UCAC3) { - fprintf (stderr,"UCACRNUM: %11.6f: %9.5f %9.5f %5.2f %5.2f", - num, ra, dec, star->xmag[0],star->xmag[1]); - fprintf (stderr," %5.2f %5.2f %5.2f", - star->xmag[2], star->xmag[3], star->xmag[4]); - fprintf (stderr," %5.2f %5.2f %5.2f", - star->xmag[5], star->xmag[6], star->xmag[7]); - fprintf (stderr," %d %d\n",star->nimage,star->ncat); - } - else if (ucat == UCAC4) { - fprintf (stderr,"UCACRNUM: %11.6f: %9.5f %9.5f %5.2f %5.2f", - num, ra, dec, star->xmag[0],star->xmag[1]); - fprintf (stderr," %5.2f %5.2f %5.2f", - star->xmag[2], star->xmag[3], star->xmag[4]); - fprintf (stderr," %5.2f %5.2f %5.2f", - star->xmag[5], star->xmag[6], star->xmag[7]); - fprintf (stderr," %d %d\n",star->nimage,star->ncat); - } else { - fprintf(stderr,"ucacread CATALOG NUMBER ERROR %d in line %d\n",ucat,__LINE__); - exit(-1); - } - } - } - - /* End of star loop */ - } - - /* Summarize search */ - ucacclose (starcat); - if (nlog > 0) - fprintf (stderr,"UCACRNUM: %d / %d found\n",nstar,starcat->nstars); - - return (nstars); -} - - -/* UCACBIN -- Fill a FITS WCS image with UCAC Star Catalog stars */ - -int -ucacbin (refcatname, wcs, header, image, mag1, mag2, sortmag, magscale, nlog) - - char *refcatname; /* Name of catalog (UAC, USAC, UAC2, USAC2) */ - struct WorldCoor *wcs; /* World coordinate system for image */ - char *header; /* FITS header for output image */ - char *image; /* Output FITS image */ - double mag1,mag2; /* Limiting magnitudes (none if equal) */ - int sortmag; /* Magnitude by which to sort (1 or 2) */ - double magscale; /* Scaling factor for magnitude to pixel flux - * (number of catalog objects per bin if 0) */ - int nlog; /* 1 for diagnostics */ -{ - double cra; /* Search center J2000 right ascension in degrees */ - double cdec; /* Search center J2000 declination in degrees */ - double dra; /* Search half width in right ascension in degrees */ - double ddec; /* Search half-width in declination in degrees */ - int sysout; /* Search coordinate system */ - double eqout; /* Search coordinate equinox */ - double epout; /* Proper motion epoch (0.0 for no proper motion) */ - double ra1,ra2; /* Limiting right ascensions of region in degrees */ - double dec1,dec2; /* Limiting declinations of region in degrees */ - int nz; /* Number of UCAC regions in search */ - int zlist[MAXZONE]; /* List of region numbers */ - int sysref = WCS_J2000; /* Catalog coordinate system */ - double eqref = 2000.0; /* Catalog equinox */ - double epref = 2000.0; /* Catalog epoch */ - double secmarg = 60.0; /* Arcsec/century margin for proper motion */ - struct StarCat *starcat; /* Star catalog data structure */ - struct Star *star; /* Single star cata structure */ - int verbose; - int wrap; - int ix, iy, iz; - int magsort; - int jstar; - int nrmax = MAXZONE; - int nstar, ntot; - int istar, istar1, istar2; - int jtable,iwrap, nread; - int pass; - int zone; - double num, ra, dec, rapm, decpm, mag; - double rra1, rra2, rdec1, rdec2; - double rdist, ddist; - char cstr[32]; - char ucacenv[16]; - char *str; - double xpix, ypix, flux; - int offscl; - int bitpix, w, h; /* Image bits/pixel and pixel width and height */ - double logt = log(10.0); - - ntot = 0; - if (nlog > 0) - verbose = 1; - else - verbose = 0; - - /* Set catalog code and path to catalog */ - if (strncmp (refcatname,"ucac4",5)==0 || - strncmp (refcatname,"UCAC4",5)==0) { - ucat = UCAC4; - ucacpath = ucac4path; - strcpy (ucacenv, "UCAC4_PATH"); - } - if (strncmp (refcatname,"ucac3",5)==0 || - strncmp (refcatname,"UCAC3",5)==0) { - ucat = UCAC3; - ucacpath = ucac3path; - strcpy (ucacenv, "UCAC3_PATH"); - } - else if (strncmp (refcatname,"ucac2",5)==0 || - strncmp (refcatname,"UCAC2",5)==0) { - ucat = UCAC2; - ucacpath = ucac2path; - strcpy (ucacenv, "UCAC2_PATH"); - } - else { - ucat = UCAC1; - ucacpath = ucac1path; - strcpy (ucacenv, "UCAC1_PATH"); - } - - /* If pathname is set in environment, override local value */ - if ((str = getenv (ucacenv)) != NULL ) - ucacpath = str; - - /* Set image parameters */ - bitpix = 0; - (void)hgeti4 (header, "BITPIX", &bitpix); - w = 0; - (void)hgeti4 (header, "NAXIS1", &w); - h = 0; - (void)hgeti4 (header, "NAXIS2", &h); - - /* Set catalog search limits from image WCS information */ - sysout = wcs->syswcs; - eqout = wcs->equinox; - epout = wcs->epoch; - wcscstr (cstr, sysout, eqout, epout); - wcssize (wcs, &cra, &cdec, &dra, &ddec); - SearchLim (cra,cdec,dra,ddec,sysout,&ra1,&ra2,&dec1,&dec2,verbose); - - /* Make mag1 always the smallest magnitude */ - if (mag2 < mag1) { - mag = mag2; - mag2 = mag1; - mag1 = mag; - } - - if (sortmag < 1) - magsort = 0; - else if (sortmag > 4) - magsort = 3; - else - magsort = sortmag - 1; - - /* Allocate catalog entry buffer */ - star = (struct Star *) calloc (1, sizeof (struct Star)); - star->num = 0.0; - - nstar = 0; - jstar = 0; - - /* Get RA and Dec limits in catalog (J2000) coordinates */ - rra1 = ra1; - rra2 = ra2; - rdec1 = dec1; - rdec2 = dec2; - RefLim (cra,cdec,dra,ddec,sysout,sysref,eqout,eqref,epout,epref,secmarg, - &rra1, &rra2, &rdec1, &rdec2, &wrap, verbose); - - /* Find UCAC Star Catalog zones in which to search */ - nz = ucaczones (rdec1,rdec2,nrmax,zlist,verbose); - if (nz <= 0) { - fprintf (stderr,"UCACBIN: no UCAC zone for %.2f-%.2f %.2f %.2f\n", - rra1, rra2, rdec1, rdec2); - return (0); - } - - /* Loop through zone list */ - nstar = 0; - for (iz = 0; iz < nz; iz++) { - - /* Get path to zone catalog */ - zone = zlist[iz]; - if ((starcat = ucacopen (zone)) != 0) { - - jstar = 0; - jtable = 0; - for (iwrap = 0; iwrap <= wrap; iwrap++) { - - /* Find first star based on RA */ - if (iwrap == 0 || wrap == 0) - istar1 = ucacsra (starcat, star, zone, rra1); - else - istar1 = 1; - - /* Find last star based on RA */ - if (iwrap == 1 || wrap == 0) - istar2 = ucacsra (starcat, star, zone, rra2); - else - istar2 = starcat->nstars; - - if (istar1 == 0 || istar2 == 0) - break; - - nread = istar2 - istar1 + 1; - - /* Loop through zone catalog for this region */ - for (istar = istar1; istar <= istar2; istar++) { - jtable ++; - - if (ucacstar (starcat, star, zone, istar)) { - fprintf(stderr,"UCACBIN: Cannot read star %d\n",istar); - break; - } - - /* ID number */ - num = star->num; - - /* Magnitude */ - mag = star->xmag[magsort]; - - /* Check magnitude limits */ - pass = 1; - if (mag1 != mag2 && (mag < mag1 || mag > mag2)) - pass = 0; - - /* Check position limits */ - if (pass) { - - /* Get position in output coordinate system */ - rapm = star->rapm; - decpm = star->decpm; - ra = star->ra; - dec = star->dec; - wcsconp (sysref, sysout, eqref, eqout, epref, epout, - &ra, &dec, &rapm, &decpm); - - /* Check distance along RA and Dec axes */ - ddist = wcsdist (cra,cdec,cra,dec); - if (ddist > ddec) - pass = 0; - rdist = wcsdist (cra,dec,ra,dec); - if (rdist > dra) - pass = 0; - } - - /* Save star in FITS image */ - if (pass) { - wcs2pix (wcs, ra, dec, &xpix, &ypix, &offscl); - if (!offscl) { - if (magscale > 0.0) - flux = magscale * exp (logt * (-mag / 2.5)); - else - flux = 1.0; - ix = (int) (xpix + 0.5); - iy = (int) (ypix + 0.5); - addpix1 (image, bitpix, w,h, 0.0,1.0, xpix,ypix, flux); - nstar++; - jstar++; - } - else { - ix = 0; - iy = 0; - } - if (nlog == 1) { - fprintf (stderr,"UCACBIN: %11.6f: %9.5f %9.5f %s", - num,ra,dec,cstr); - if (magscale > 0.0) - fprintf (stderr, " %5.2f", mag); - if (!offscl) - flux = getpix1 (image, bitpix, w, h, 0.0, 1.0, ix, iy); - else - flux = 0.0; - fprintf (stderr," (%d,%d): %f\n", ix, iy, flux); - } - - /* End of accepted star processing */ - } - - /* Log operation */ - jstar++; - if (nlog > 0 && istar%nlog == 0) - fprintf (stderr,"UCACBIN: %5d / %5d / %5d sources\r", - nstar,jstar,starcat->nstars); - - /* End of star loop */ - } - - /* End of 0:00 RA wrap loop */ - } - - /* End of successful zone file loop */ - ntot = ntot + starcat->nstars; - if (nlog > 0) - fprintf (stderr,"UCACBIN: %4d / %4d: %5d / %5d / %5d sources from zone %4d \n", - iz+1,nz,nstar,jstar,starcat->nstars,zlist[iz]); - - /* Close region input file */ - ucacclose (starcat); - } - - /* End of zone loop */ - } - - /* Summarize transfer */ - if (nlog > 0) { - if (nz > 1) - fprintf (stderr,"UCACBIN: %d zones: %d / %d found\n",nz,nstar,ntot); - else - fprintf (stderr,"UCACBIN: 1 region: %d / %d found\n",nstar,ntot); - } - return (nstar); -} - - -/* UCACZONE -- Compute the zones over which to search - * in the specified range of coordinates. - * Build lists containing the first star and number of stars for each range. - */ - -static int -ucaczones (dec1, dec2, nzmax, zones, verbose) - - double dec1, dec2; /* Declination limits in degrees */ - int nzmax; /* Maximum number of zones to find */ - int *zones; /* Zone numbers (returned)*/ - int verbose; /* 1 for diagnostics */ - -{ - int nz; /* Number of declination zones found (returned) */ - int iz, iz1, iz2; - int i; - double spd1, spd2; - - for (i = 0; i < nzmax; i++) - zones[i] = 0; - - /* Find first and last declination zone to search */ - spd1 = 90.0 + dec1; - iz1 = (int) ((spd1 * 2.0) + 0.99999); - if (iz1 < 1) iz1 = 1; - spd2 = 90.0 + dec2; - iz2 = (int) ((spd2 * 2.0) + 0.99999); - if (ucat == UCAC1 && iz2 > 169) iz2 = 169; - if (ucat == UCAC2 && iz2 > 288) iz2 = 288; - if (ucat == UCAC3 && iz2 > 360) iz2 = 360; - if (ucat == UCAC4) { - iz1 = (int) ((spd1 * 5.0) + 0.99999); - if (iz1 < 1) iz1 = 1; - spd2 = 90.0 + dec2; - iz2 = (int) ((spd2 * 5.0) + 0.99999); - if (iz2 > 900) { - iz2 = 900; - } - } - - if (iz1 > iz2) - return (0); - - nz = iz2 - iz1 + 1; - if (verbose) { - fprintf (stderr,"UCACZONES: searching %d zones: %d - %d\n",nz,iz1,iz2); - fprintf(stderr,"UCACZONES: Dec: %.5f - %.5f\n", dec1,dec2); - } - - i = 0; - for (iz = iz1; iz <= iz2; iz++) { - zones[i] = iz; - i++; - } - - return (nz); -} - - -/* UCACSRA -- Find UCAC star closest to specified right ascension */ - -static int -ucacsra (sc, st, zone, rax0) - - struct StarCat *sc; /* Star catalog descriptor */ - struct Star *st; /* Current star entry */ - int zone; /* Declination zone */ - double rax0; /* Right ascension in degrees for which to search */ -{ - int istar, istar1, istar2, nrep; - double rax, ra1, ra2, ra, rdiff, rdiff1, rdiff2, sdiff; - char rastrx[32]; - int debug = 0; - int maxnrep; -#ifdef UCAC_DEBUG - if (zone == 183) { - debug = 1; - fprintf(stderr,"Entering UCACSRA, zone %d\n",zone); - } else { - debug = 0; - } -#endif /* UCAC_DEBUG */ - - rax = rax0; - if (debug) - ra2str (rastrx, 31, rax, 3); - istar1 = 1; - ucacstar (sc, st, zone, istar1); - ra1 = st->ra; - istar2 = sc->nstars; - maxnrep = sc->nstars; - istar = (istar1+istar2)/2; - nrep = 0; - while (istar != istar1 && nrep < maxnrep) { - if (ucacstar (sc, st, zone, istar)) { - break; - } else { - ra = st->ra; - if (ra == ra1) - break; - if (debug) { - char rastr[32]; - ra2str (rastr, 31, ra, 3); - fprintf (stderr,"UCACSRA %d %d: %s (%s)\n", - nrep,istar,rastr,rastrx); - } - nrep++; - if (ra > rax) { - istar2 = istar; - ra2 = ra; - } else { - istar1 = istar; - ra1 = ra; - } - istar = (istar1+istar2)/2; - if (debug) { - fprintf (stderr," ra1= %.5f ra2= %.5f rax= %.5f\n", - ra1,ra2,rax); - fprintf (stderr," istar1= %d istar= %d istar2= %d\n", - istar1,istar,istar2); - } - if (istar < 1) - istar = 1; - if (istar > sc->nstars) - istar = sc->nstars; - if (istar == istar1) - break; - } - } - return (istar); -} - - -/* UCACOPEN -- Open UCAC catalog file, returning number of entries */ - -struct StarCat * -ucacopen (zone) - - int zone; /* Number of catalog zone to read */ - -{ - FILE *fcat; - struct StarCat *sc; - int lfile, lpath; - char *zonefile; - char *zonepath; /* Full pathname for catalog file */ - - /* Set pathname for catalog file */ - lpath = strlen (ucacpath) + 16; - zonepath = (char *) malloc (lpath); - if (ucat == UCAC1) - sprintf (zonepath, "%s/u1/z%03d", ucacpath, zone); - else if (ucat == UCAC2) - sprintf (zonepath, "%s/u2/z%03d", ucacpath, zone); - else if (ucat == UCAC3) - sprintf (zonepath, "%s/z%03d", ucacpath, zone); - else if (ucat == UCAC4) - sprintf (zonepath, "%s/z%03d", ucacpath, zone); - else { - fprintf(stderr,"ucacread CATALOG NUMBER ERROR %d in line %d\n",ucat,__LINE__); - exit(-1); - } - /* Set UCAC catalog header information */ - sc = (struct StarCat *) calloc (1, sizeof (struct StarCat)); - sc->byteswapped = 0; - - /* Set number of stars in this zone catalog */ - if (ucat == UCAC1) - sc->nbent = 67; - else if (ucat == UCAC2) - sc->nbent = 44; - else if (ucat == UCAC3) - sc->nbent = 84; - else if (ucat == UCAC4) - sc->nbent = sizeof(UCAC4star); - else { - fprintf(stderr,"ucacread CATALOG NUMBER ERROR %d in line %d\n",ucat,__LINE__); - exit(-1); - } - lfile = getfilesize (zonepath); - if (lfile < 2) { - fprintf (stderr,"UCAC zone catalog %s has no entries\n",zonepath); - free (sc); - sc = NULL; - return (NULL); - } - else - sc->nstars = lfile / sc->nbent; - - /* Open UCAC file */ - if (!(fcat = fopen (zonepath, "r"))) { - fprintf (stderr,"UCACOPEN: UCAC file %s cannot be read\n",zonepath); - free (sc); - return (NULL); - } - - /* Separate filename from pathname and save in structure */ - zonefile = strrchr (zonepath,'/'); - if (zonefile) - zonefile = zonefile + 1; - else - zonefile = zonepath; - if (strlen (zonefile) < 24) - strcpy (sc->isfil, zonefile); - else - strncpy (sc->isfil, zonefile, 23); - - /* Set other catalog information in structure */ - sc->inform = 'J'; - sc->coorsys = WCS_J2000; - sc->epoch = 2000.0; - sc->equinox = 2000.0; - sc->ifcat = fcat; - sc->sptype = 0; - if (ucat == UCAC1) - sc->nmag = 1; - else if (ucat == UCAC2) - sc->nmag = 4; - else if (ucat == UCAC3) - sc->nmag = 8; - else if (ucat == UCAC4) - sc->nmag = 8; - else { - fprintf(stderr,"ucacread CATALOG NUMBER ERROR %d in line %d\n",ucat,__LINE__); - exit(-1); - } - - - /* UCAC stars are RA-sorted within declination zones */ - sc->rasorted = 1; - - /* Check to see if byte-swapping is necessary */ - cswap = 0; - if (ucat == UCAC2) { - UCAC2star us2; /* UCAC2 catalog entry for one star */ - int nbr; - - nbr = fread (&us2, 1, sc->nbent, sc->ifcat); - if (nbr < 1) { - fprintf (stderr, - "UCACOPEN: cannot read star 1 from UCAC2 zone catalog %s\n", - zonepath); - return (0); - } - - /* RA should be between 0 and 360 degrees in milliarcseconds */ - if (us2.rasec > 360 * 3600000 || us2.rasec < 0) - cswap = 1; - - /* Dec should be between -90 and +90 degrees in milliarcseconds */ - else if (us2.decsec > 90 * 3600000 || us2.decsec < -90 * 3600000) - cswap = 1; - - /* J H K magnitudes should be near-positive */ - else if (us2.jmag < -1000 || us2.hmag < -1000 || us2.kmag < -1000) - cswap = 1; - else - cswap = 0; - - /* if (cswap) - fprintf (stderr, - "UCACOPEN: swapping bytes in UCAC2 zone catalog %s\n", - zonepath); */ - } - else if (ucat == UCAC3) { - UCAC3star us3; /* UCAC3 catalog entry for one star */ - int nbr; - - nbr = fread (&us3, 1, sc->nbent, sc->ifcat); - if (nbr < 1) { - fprintf (stderr, - "UCACOPEN: cannot read star 1 from UCAC3 zone catalog %s\n", - zonepath); - return (0); - } - - /* RA should be between 0 and 360 degrees in milliarcseconds */ - if (us3.rasec > 360 * 3600000 || us3.rasec < 0) - cswap = 1; - - /* Dec should be between -90 and +90 degrees in milliarcseconds */ - else if (us3.decsec > 180 * 3600000 || us3.decsec < -180 * 3600000) - cswap = 1; - - /* J H K magnitudes should be near-positive */ - else if (us3.jmag < -1000 || us3.hmag < -1000 || us3.kmag < -1000) - cswap = 1; - else - cswap = 0; - - /* if (cswap) - fprintf (stderr, - "UCACOPEN: swapping bytes in UCAC2 zone catalog %s\n",zomepath); */ - } - else if (ucat == UCAC4) { - UCAC4star us4; /* UCAC4 catalog entry for one star */ - int nbr; - - nbr = fread (&us4, 1, sc->nbent, sc->ifcat); - if (nbr < 1) { - fprintf (stderr, - "UCACOPEN: cannot read star 1 from UCAC4 zone catalog %s\n", - zonepath); - return (0); - } - - /* RA should be between 0 and 360 degrees in milliarcseconds */ - if (us4.ra > 360 * 3600000 || us4.ra < 0) - cswap = 1; - - /* Dec should be between -90 and +90 degrees in milliarcseconds */ - else if (us4.spd > 180 * 3600000 || us4.spd < 0) - cswap = 1; - - /* J H K magnitudes should be near-positive */ - else if (us4.mag_j < -1000 || us4.mag_h < -1000 || us4.mag_k < -1000) - cswap = 1; - else - cswap = 0; - - if (cswap) - fprintf (stderr, - "UCACOPEN: swapping bytes in UCAC4 zone catalog %s\n",zonepath); - } - else { - fprintf(stderr,"ucacread CATALOG NUMBER ERROR %d in line %d\n",ucat,__LINE__); - exit(-1); - } - - sc->istar = 0; - free (zonepath); - return (sc); -} - - -void -ucacclose (sc) - struct StarCat *sc; /* Star catalog descriptor */ -{ - fclose (sc->ifcat); - free (sc); - return; -} - - -/* UCACSTAR -- Get UCAC catalog entry for one star; - return 0 if successful */ - -static int -ucacstar (sc, st, zone, istar) - - struct StarCat *sc; /* Star catalog descriptor */ - struct Star *st; /* Current star entry */ - int zone; /* Declination zone */ - int istar; /* Star sequence number in UCAC catalog region file */ -{ - - - char line[256]; - int nbr, nbskip; - UCAC2star us2; /* UCAC2 catalog entry for one star */ - UCAC3star us3; /* UCAC3 catalog entry for one star */ - UCAC4star us4; /* UCAC4 catalog entry for one star */ - - int hpmIndex; - int lineLen; - int nvals; - FILE *hpmHandle; - char inLine[MAX_U4HPM_LINE]; - char *inBuffer; - PU4HPM pU4hpm = NULL; - - - /* Drop out if catalog pointer is not set */ - if (sc == NULL) - return (1); - - /* Drop out if catalog is not open */ - if (sc->ifcat == NULL) - return (2); - - /* Drop out if star number is too small or too large */ - if (istar < 1 || istar > sc->nstars) { - fprintf (stderr, "UCAC star %d is not in catalog\n",istar); - return (-1); - } - - /* Move file pointer to start of correct star entry */ - nbskip = sc->nbent * (istar - 1); - if (fseek (sc->ifcat,nbskip,SEEK_SET)) - return (-1); - - if (ucat == UCAC1) - nbr = fread (line, 1, sc->nbent, sc->ifcat); - else if (ucat == UCAC2) - nbr = fread (&us2, 1, sc->nbent, sc->ifcat); - else if (ucat == UCAC3) - nbr = fread (&us3, 1, sc->nbent, sc->ifcat); - else if (ucat == UCAC4) - nbr = fread (&us4, 1, sc->nbent, sc->ifcat); - else { - fprintf(stderr,"ucacread CATALOG NUMBER ERROR %d in line %d\n",ucat,__LINE__); - exit(-1); - } - if (nbr < sc->nbent) { - fprintf (stderr, "UCACSTAR %d / %d bytes read\n",nbr, sc->nbent); - return (-2); - } -#if 0 - if ((zone == 552) && (istar == 43247)) { - printf("At zone %d and istar %d\n",zone,istar); - } -#endif - - - /* Star ID number = region.sequence */ - st->num = (double) zone + (0.000001 * (double) istar); - - /* Read UCAC1 position and proper motion from ASCII file */ - if (ucat == UCAC1) { - - /* Read position in degrees */ - st->ra = atof (line) / 3600000.0; - st->dec = (atof (line+10) / 3600000.0) - 90.0; - - /* Read proper motion and convert it to to degrees/year */ - st->rapm = (atof (line+41) / 3600000.0) / cosdeg (st->dec); - st->decpm = atof (line+48) / 3600000.0; - - /* Set V magnitude */ - st->xmag[0] = atof (line+20) * 0.01; - } - - /* Read UCAC2 position, proper motion, and magnitudes from binary file */ - else if (ucat == UCAC2) { - if (cswap) { - ucacswap4 (&us2.rasec); - ucacswap4 (&us2.decsec); - ucacswap4 (&us2.rapm); - ucacswap4 (&us2.decpm); - ucacswap2 (&us2.cmag); - ucacswap2 (&us2.jmag); - ucacswap2 (&us2.hmag); - ucacswap2 (&us2.kmag); - } - st->ra = (double) us2.rasec / 3600000.0; - st->dec = (double) us2.decsec / 3600000.0; - st->errra = (double) us2.era / 3600000.0; /* mas */ - st->errra = st->errra / cosdeg (st->dec); /* to RA deg */ - st->errdec = (double) us2.edec / 3600000.0; /* mas */ - st->rapm = (double) us2.rapm / 36000000.0; /* 0.1mas/yr */ - st->decpm = (double) us2.decpm / 36000000.0; /* 0.1mas/yr */ - st->errpmr = (double) us2.erapm / 36000000.0; /* 0.1mas/yr */ - st->errpmr = st->errpmr / cosdeg (st->dec); /* to RA deg */ - st->errpmd = (double) us2.edecpm / 36000000.0; /* 0.1mas/yr */ - st->xmag[0] = ((double) us2.jmag) / 1000.0; - st->xmag[1] = ((double) us2.hmag) / 1000.0; - st->xmag[2] = ((double) us2.kmag) / 1000.0; - st->xmag[3] = ((double) us2.cmag) / 100.0; - st->nimage = (int) us2.nobs; - st->ncat = (int) us2.ncat; - } - - /* Read UCAC3 position, proper motion, and magnitudes from binary file */ - else if (ucat == UCAC3) { - if (cswap) { - ucacswap4 (&us3.rasec); - ucacswap4 (&us3.decsec); - ucacswap4 (&us3.rapm); - ucacswap4 (&us3.decpm); - ucacswap2 (&us3.sigra); - ucacswap2 (&us3.sigdec); - ucacswap2 (&us3.sigpmr); - ucacswap2 (&us3.sigpmd); - ucacswap2 (&us3.mmag); - ucacswap2 (&us3.amag); - ucacswap2 (&us3.jmag); - ucacswap2 (&us3.hmag); - ucacswap2 (&us3.kmag); - ucacswap2 (&us3.bmag); - ucacswap2 (&us3.rmag); - ucacswap2 (&us3.imag); - } - st->ra = (double) us3.rasec / 3600000.0; /* mas */ - st->dec = (double) us3.decsec / 3600000.0; /* mas */ - st->dec = st->dec - 90.0; - st->errra = (double) us3.sigra / 3600000.0; /* mas */ - st->errra = st->errra / cosdeg (st->dec); /* to RA deg */ - st->errdec = (double) us3.sigdec / 3600000.0; /* mas */ - st->rapm = (double) us3.rapm / 36000000.0; /* 0.1mas/yr */ - st->rapm = st->rapm / cosdeg (st->dec); /* to RA deg */ - st->decpm = (double) us3.decpm / 36000000.0; /* 0.1mas/yr */ - st->errpmr = (double) us3.sigpmr / 36000000.0; /* 0.1mas/yr */ - st->errpmr = st->errpmr / cosdeg (st->dec); /* to RA deg */ - st->errpmd = (double) us3.sigpmd / 36000000.0; /* 0.1mas/yr */ - st->nimage = (int) us3.nu1; - st->ncat = (int) us3.us1; - if (us3.bmag == 0) - st->xmag[0] = 99.990; - else - st->xmag[0] = ((double) us3.bmag) / 1000.0; - if (us3.rmag == 0) - st->xmag[1] = 99.990; - else - st->xmag[1] = ((double) us3.rmag) / 1000.0; - if (us3.imag == 0) - st->xmag[2] = 99.990; - else - st->xmag[2] = ((double) us3.imag) / 1000.0; - if (us3.jmag == 0) - st->xmag[3] = 99.990; - else - st->xmag[3] = ((double) us3.jmag) / 1000.0; - if (us3.hmag == 0) - st->xmag[4] = 99.990; - else - st->xmag[4] = ((double) us3.hmag) / 1000.0; - if (us3.kmag == 0) - st->xmag[5] = 99.990; - else - st->xmag[5] = ((double) us3.kmag) / 1000.0; - if (us3.mmag == 0) - st->xmag[6] = 99.990; - else - st->xmag[6] = ((double) us3.mmag) / 1000.0; - if (us3.amag == 0) - st->xmag[7] = 99.990; - else - st->xmag[7] = ((double) us3.amag) / 1000.0; - } - else if (ucat == UCAC4) { - if (cswap) { - ucacswap4 (&us4.ra); - ucacswap4 (&us4.spd); - ucacswap4 (&us4.pm_ra); - ucacswap4 (&us4.pm_dec); - ucacswap4 (&us4.id_number); - ucacswap2 (&us4.ra_sigma); - ucacswap2 (&us4.dec_sigma); - ucacswap2 (&us4.pm_ra_sigma); - ucacswap2 (&us4.pm_dec_sigma); - ucacswap2 (&us4.magm); - ucacswap2 (&us4.maga); - ucacswap2 (&us4.mag_j); - ucacswap2 (&us4.mag_h); - ucacswap2 (&us4.mag_k); - ucacswap2 (&us4.apass_mag[0]); - ucacswap2 (&us4.apass_mag[1]); - ucacswap2 (&us4.apass_mag[2]); - ucacswap2 (&us4.apass_mag[3]); - ucacswap2 (&us4.apass_mag[4]); - } - st->ra = (double) us4.ra / 3600000.0; /* mas */ - st->dec = (double) us4.spd / 3600000.0; /* mas */ - st->dec = st->dec - 90.0; - st->errra = (double) us4.ra_sigma / 3600000.0; /* mas */ - st->errra = st->errra / cosdeg (st->dec); /* to RA deg */ - st->errdec = (double) us4.dec_sigma / 3600000.0; /* mas */ - - /* Must get proper motions from a different catalog */ - if ((us4.pm_ra == 32767) || (us4.pm_dec == 32767)) { - if (hpmLines == 0) { - /* Read in the high proper motion catalog */ - hpmHandle = fopen(hpmpath,"rt"); - if (hpmHandle == NULL) { - printf("ERROR: failed to open %s\n",hpmpath); - exit(-1); - } - hpmLines = 0; - while(1) { - if (hpmLines >= MAX_U4HPM_RECORDS) { - printf("ERROR: MAX_U4HPM_RECORDS exceeded\n"); - exit(-1); - } - pU4hpm = &u4hpm_table[hpmLines]; - memset(pU4hpm,0,sizeof(U4HPM)); - inBuffer = fgets(inLine,MAX_U4HPM_LINE,hpmHandle); - if (inBuffer == NULL) { - break; - } - lineLen = strlen(inBuffer); - /* Trim off the carriage return */ - if (inBuffer[lineLen-1] == 10) { - inBuffer[lineLen-1] = 0; - lineLen--; - } - /* Trim off the line feed */ - if (inBuffer[lineLen-1] == 13) { - inBuffer[lineLen-1] = 0; - lineLen--; - } - nvals = sscanf(inBuffer,"%d %d %d %d %d %d %d %d", - &pU4hpm->rnm, - &pU4hpm->zn, - &pU4hpm->rnz, - &pU4hpm->pmrc, - &pU4hpm->pmd, - &pU4hpm->ra, - &pU4hpm->dec, - &pU4hpm->maga); - if (nvals != 8) { - fprintf(stderr,"Error reading line %d of u4hpm %s\n",hpmLines,inLine); - } else { - hpmLines++; - } - } - fclose(hpmHandle); - } - for (hpmIndex = 0; hpmIndex < hpmLines; hpmIndex++) { - pU4hpm = &u4hpm_table[hpmIndex]; - if ((zone == pU4hpm->zn) && - (us4.id_number == pU4hpm->rnm) && - (us4.ra == pU4hpm->ra) && - (us4.spd == pU4hpm->dec) && - (us4.maga == pU4hpm->maga)) { - /* We have a match */ - st->rapm = (1.0 * pU4hpm->pmrc) / 36000000.0; /* 0.1 mas/yr */ - st->rapm = st->rapm / cosdeg (st->dec); /* to RA deg */ - st->decpm = (1.0 * pU4hpm->pmd) / 36000000.0; /* 0.1 mas/yr */ - break; - } - } - if (hpmIndex == hpmLines) { - fprintf(stderr,"ERROR: no proper motion found for zone %d entry %d\n",zone,us4.id_number); - } - - } else { - - st->rapm = (double) us4.pm_ra / 36000000.0; /* 0.1mas/yr */ - st->rapm = st->rapm / cosdeg (st->dec); /* to RA deg */ - st->decpm = (double) us4.pm_dec / 36000000.0; /* 0.1mas/yr */ - } - st->errpmr = (double) (us4.pm_ra_sigma+128) / 36000000.0; /* 0.1mas/yr */ - st->errpmr = st->errpmr / cosdeg (st->dec); /* to RA deg */ - st->errpmd = (double) (us4.pm_dec_sigma+128) / 36000000.0; /* 0.1mas/yr */ - st->nimage = (int) us4.n_ucac_used; - st->ncat = (int) us4.n_cats_used; - if (us4.apass_mag[0] == 20000) - st->xmag[0] = 99.990; - else - st->xmag[0] = ((double) us4.apass_mag[0]) / 1000.0; - if (us4.apass_mag[1] == 20000) - st->xmag[1] = 99.990; - else - st->xmag[1] = ((double) us4.apass_mag[1]) / 1000.0; - if (us4.apass_mag[2] == 20000) - st->xmag[2] = 99.990; - else - st->xmag[2] = ((double) us4.apass_mag[2]) / 1000.0; - if (us4.apass_mag[3] == 20000) - st->xmag[3] = 99.990; - else - st->xmag[3] = ((double) us4.apass_mag[3]) / 1000.0; - if (us4.apass_mag[4] == 20000) - st->xmag[4] = 99.990; - else - st->xmag[4] = ((double) us4.apass_mag[4]) / 1000.0; - if (us4.mag_j == 0) - st->xmag[5] = 99.990; - else - st->xmag[5] = ((double) us4.mag_j) / 1000.0; - if (us4.mag_h == 0) - st->xmag[6] = 99.990; - else - st->xmag[6] = ((double) us4.mag_h) / 1000.0; - if (us4.mag_k == 0) - st->xmag[7] = 99.990; - else - st->xmag[7] = ((double) us4.mag_k) / 1000.0; - if (us4.magm == 20000) - st->xmag[8] = 99.990; - else - st->xmag[8] = ((double) us4.magm) / 1000.0; - if (us4.maga == 20000) - st->xmag[9] = 99.990; - else - st->xmag[9] = ((double) us4.maga) / 1000.0; - - /* DASCH specific. Since we are sorting on mag[8], try using APASS B or mag[9] first */ - if (st->xmag[9] < 90.0) { - st->xmag[8] = st->xmag[9]; - } - if (st->xmag[0] < 90.0) { - st->xmag[8] = st->xmag[0]; - } - - } - else { - fprintf(stderr,"ucacread CATALOG NUMBER ERROR %d in line %d\n",ucat,__LINE__); - exit(-1); - } - - -#if 0 - if ((zone == 256) && (istar == 149200)) { - printf("At zone %d and istar %d\n",zone,istar); - } -#endif - -#ifdef UCAC_DEBUG - if (zone == 183) { - fprintf(stderr,"istar %6d, ra %.3f dec %.3f\n",istar,st->ra,st->dec); - - } -#endif /* UCAC_DEBUG */ - - return (0); -} - - -/* UCACSWAP2 -- Swap bytes in Integer*2 number in place */ - -static void -ucacswap2 (string) - - - char *string; /* Address of starting point of bytes to swap */ - -{ - char *sbyte, temp; - - sbyte = string; - temp = sbyte[0]; - sbyte[0] = sbyte[1]; - sbyte[1] = temp; - return; -} - - -/* UCACSWAP4 -- Reverse bytes of Integer*4 or Real*4 number in place */ - -static void -ucacswap4 (string) - - char *string; /* Address of Integer*4 or Real*4 vector */ - -{ - char temp0, temp1, temp2, temp3; - - temp3 = string[0]; - temp2 = string[1]; - temp1 = string[2]; - temp0 = string[3]; - string[0] = temp0; - string[1] = temp1; - string[2] = temp2; - string[3] = temp3; - - return; -} - -/* Apr 24 2003 New subroutines, based on ty2read.c and uacread.c - * May 30 2003 Add UCAC2, compute file size rather than reading it from file - * Jun 2 2003 Print proper motions as mas/year - * Aug 22 2003 Add radi argument for inner edge of search annulus - * Sep 25 2003 Add ucacbin() to fill an image with sources - * Oct 6 2003 Update ubcread() and ubcbin() for improved RefLim() - * Nov 10 2003 Fix byte-swapping test in ucacopen() found by Ed Beshore - * Nov 18 2003 Initialize image size and bits/pixel from header in ucacbin() - * Dec 1 2003 Add missing tab to n=-1 header - * Dec 12 2003 Fix bug in wcs2pix() call in ucacbin() - * - * Jan 4 2005 Fix bug in if statement on line 626 found by Dan Katz at JPL - * - * Jun 20 2006 Drop unused variables - * Sep 26 2006 Increase length of rastr and destr from 16 to 32 - * Nov 16 2006 Fix binning - * - * Jan 8 2007 Drop unused variable in ucacbin() - * Jan 10 2007 Add match=1 argument to webrnum() - * Jul 11 2007 Add magnitude byte-swap check - * - * Oct 5 2009 Add UCAC3 - * Oct 15 2009 Read extra stars in RA - * Oct 22 2009 Set UCAC3 magnitudes to 99.99 if zero - * Oct 30 2009 Add position and proper motion error to Star structure - * Nov 2 2009 Print UCAC3 errors if n = -1 - * Nov 5 2009 Return number of images and catalogs in gtype - * Nov 5 2009 Return errors in position and proper motion as magnitudes - * Nov 5 2009 Return UCAC2 and UCAC3 RA proper motion and error as RA degrees - * Dec 14 2009 Drop nmag1 from ucacread() and ucacrnum(); it wasn't being used - * - * Jan 29 2013 Add UCAC4 support see "DASCH" tag for DASCH-specific changes - * - * Jun 12 2015 Fix UCAC4 support to include BVgriJHK magnitudes correctly - * - * Jun 22 2016 Remove extra variables from format string (via Ole Streicher) - */ +/*** File libwcs/ucacread.c + *** August 3, 2018 + *** By Jessica Mink, jmink@cfa.harvard.edu + *** Harvard-Smithsonian Center for Astrophysics + *** Copyright (C) 2003-2018 + *** Smithsonian Astrophysical Observatory, Cambridge, MA, USA + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Correspondence concerning WCSTools should be addressed as follows: + Internet email: jmink@cfa.harvard.edu + Postal address: Jessica Mink + Smithsonian Astrophysical Observatory + 60 Garden St. + Cambridge, MA 02138 USA + + * ucacread() Read UCAC Star Catalog stars in a rectangle on the sky + * ucacrnum() Read UCAC Star Catalog stars by number + * ucacbin() Fill a FITS WECS image with UCAC Star Catalog stars + * ucaczones() Make list of zones covered by a range of declinations + * ucacsra (sc,st,zone,rax0) Find UCAC star closest to specified right ascension + * ucacopen(zone, nstars) Open UCAC catalog file, returning number of entries + * ucacclose (sc) Close UCAC catalog file + * ucacstar (sc,st,zone,istar) Get UCAC catalog entry for one star + */ + +#include +#include +#include +#include +#include +#include +#include "fitsfile.h" +#include "wcs.h" +#include "wcscat.h" + +#define MAXZONE 900 +#define ABS(a) ((a) < 0 ? (-(a)) : (a)) + +/* #define UCAC_DEBUG 1 */ +typedef struct { + int rasec, decsec; + short cmag; + unsigned char era, edec, nobs, rflg, ncat, cflg; + short epra, epdec; + int rapm, decpm; + unsigned char erapm, edecpm, qrapm, qdecpm; + int id2m; + short jmag, hmag, kmag, qm, cc; +} UCAC2star; + +typedef struct { + int rasec, decsec; + short mmag, amag, sigmag; + char objt, dsf; + short sigra, sigdec; + char na1, nu1, us1, cn1; + short cepra, cepdec; + int rapm, decpm; + short sigpmr, sigpmd; + int id2m; + short jmag, hmag, kmag; + char jq, hq, kq; + char e2mpho[3]; + short bmag, rmag, imag; + char clbl; + char bq, rq, iq; + char catflg[10]; + char g1, c1, leda, x2m; + int rn; +} UCAC3star; +/* The following is from ucac4.h */ +#pragma pack( 1) +typedef struct { + int32_t ra, spd; /* RA/dec at J2000.0, ICRS, in milliarcsec */ + uint16_t magm, maga; /* UCAC fit model & aperture mags, .001 mag */ + uint8_t mag_sigma; + uint8_t obj_type, double_star_flag; + int8_t ra_sigma, dec_sigma; /* sigmas in RA and dec at central epoch */ + uint8_t n_ucac_total; /* Number of UCAC observations of this star */ + uint8_t n_ucac_used; /* # UCAC observations _used_ for this star */ + uint8_t n_cats_used; /* # catalogs (epochs) used for prop motion */ + uint16_t epoch_ra; /* Central epoch for mean RA, minus 1900, .01y */ + uint16_t epoch_dec; /* Central epoch for mean DE, minus 1900, .01y */ + int16_t pm_ra; /* prop motion, .1 mas/yr = .01 arcsec/cy */ + int16_t pm_dec; /* prop motion, .1 mas/yr = .01 arcsec/cy */ + int8_t pm_ra_sigma; /* sigma in same units */ + int8_t pm_dec_sigma; + uint32_t twomass_id; /* 2MASS pts_key star identifier */ + uint16_t mag_j, mag_h, mag_k; /* 2MASS J, H, K_s mags, in millimags */ + uint8_t icq_flag[3]; + uint8_t e2mpho[3]; /* 2MASS error photometry (in centimags) */ + uint16_t apass_mag[5]; /* in millimags */ + uint8_t apass_mag_sigma[5]; /* also in millimags */ + uint8_t yale_gc_flags; /* Yale SPM g-flag * 10 + c-flag */ + uint32_t catalog_flags; + uint8_t leda_flag; /* LEDA galaxy match flag */ + uint8_t twomass_ext_flag; /* 2MASS extended source flag */ + uint32_t id_number; + uint16_t ucac2_zone; + uint32_t ucac2_number; +} UCAC4star; +#pragma pack( ) +/* Fields in the u4hpm.dat file */ +#define MAX_U4HPM_RECORDS 50 +#define MAX_U4HPM_LINE 512 +typedef struct u4hpm { + int rnm; /* unique star identifier (col. 51 main data) */ + int zn; /* UCAC4 zone number for this star */ + int rnz; /* unning record number along that zone for this star */ + int pmrc; /* actual proper motion in RA*cos(dec) [0.1 mas/yr] */ + int pmd; /* actual proper motion in Dec [0.1 mas/yr] */ + int ra; /* col. 1 of main data file (redundant) */ + int dec; /* col. 2 of main data file (redundant) */ + int maga; /* col. 4 of main data file (redundant) */ +} U4HPM,*PU4HPM; + + +int hpmLines = 0; +U4HPM u4hpm_table[MAX_U4HPM_RECORDS]; + + +/* pathname of UCAC1 decompressed data files or search engine URL */ +char ucac1path[64]="/data/astrocat/ucac1"; + +/* pathname of UCAC2 decompressed data files or search engine URL */ +char ucac2path[64]="/data/astrocat/ucac2"; + +/* pathname of UCAC3 decompressed data files or search engine URL */ +char ucac3path[64]="/data/astrocat/ucac3"; + +/* pathname of UCAC4 decompressed data files or search engine URL */ +char ucac4path[64]="/data/astrocat/ucac4/u4b"; + +/* Path name of UCAC4 proper motion catalog */ +char ucac4hpmpath[] = "/data/astrocat/ucac4/u4i/u4hpm.dat"; + +char *ucacpath; +char *hpmpath; +static int ucat = 0; + +static double *gdist; /* Array of distances to stars */ +static int ndist = 0; +static int cswap = 0; /* Byte reverse catalog to Mac/Sun/network order if 1 */ + +static int ucaczones(); +struct StarCat *ucacopen(); +void ucacclose(); +static int ucacsra(); +static int ucacstar(); +static void ucacswap4(); +static void ucacswap2(); + + +/* UCACREAD -- Read UCAC Star Catalog stars */ + +int +ucacread (refcatname,cra,cdec,dra,ddec,drad,dradi,distsort,sysout,eqout,epout, + mag1,mag2,sortmag,nstarmax,gnum,gra,gdec,gpra,gpdec,gmag,gtype,nlog) + +char *refcatname; /* Name of catalog (UAC, USAC, UAC2, USAC2) */ +double cra; /* Search center J2000 right ascension in degrees */ +double cdec; /* Search center J2000 declination in degrees */ +double dra; /* Search half width in right ascension in degrees */ +double ddec; /* Search half-width in declination in degrees */ +double drad; /* Limiting separation in degrees (ignore if 0) */ +double dradi; /* Inner edge of annulus in degrees (ignore if 0) */ +int distsort; /* 1 to sort stars by distance from center */ +int sysout; /* Search coordinate system */ +double eqout; /* Search coordinate equinox */ +double epout; /* Proper motion epoch (0.0 for no proper motion) */ +double mag1,mag2; /* Limiting magnitudes (none if equal) */ +int sortmag; /* Magnitude by which to sort (1-8) */ +int nstarmax; /* Maximum number of stars to be returned */ +double *gnum; /* Array of Guide Star numbers (returned) */ +double *gra; /* Array of right ascensions (returned) */ +double *gdec; /* Array of declinations (returned) */ +double *gpra; /* Array of right ascension proper motions (returned) */ +double *gpdec; /* Array of declination proper motions (returned) */ +double **gmag; /* Array of magnitudes (returned) */ +int *gtype; /* Array of object types (returned) */ +int nlog; /* 1 for diagnostics */ +{ + double ra1,ra2; /* Limiting right ascensions of region in degrees */ + double dec1,dec2; /* Limiting declinations of region in degrees */ + double dist = 0.0; /* Distance from search center in degrees */ + double faintmag=0.0; /* Faintest magnitude */ + double maxdist=0.0; /* Largest distance */ + int faintstar=0; /* Faintest star */ + int farstar=0; /* Most distant star */ + int nz; /* Number of UCAC regions in search */ + int zlist[MAXZONE]; /* List of region numbers */ + int sysref = WCS_J2000; /* Catalog coordinate system */ + double eqref = 2000.0; /* Catalog equinox */ + double epref = 2000.0; /* Catalog epoch */ + double secmarg = 60.0; /* Arcsec/century margin for proper motion */ + struct StarCat *starcat; /* Star catalog data structure */ + struct Star *star; /* Single star data structure */ + double errra, errdec, errpmr, errpmd; + int nim, ncat; + int verbose; + int wrap; + int iz; + int magsort; + int jstar; + int nrmax = MAXZONE; + int nstar,i, ntot, imag; + int istar, istar1, istar2; + int jtable,iwrap, nread; + int pass; + int zone; + int nmag; + int lstr; + double num, ra, dec, rapm, decpm, mag; + double rra1, rra2, rdec1, rdec2; + double rdist, ddist; + char cstr[32], rastr[32], decstr[32]; + char ucacenv[16]; + char *str, *str1; + char *hpmfile; + + hpmpath = 0; + str1 = 0; + ntot = 0; + if (nlog > 0) + verbose = 1; + else + verbose = 0; + + /* Set catalog code and path to catalog */ + if (strncmp (refcatname,"ucac2",5)==0 || + strncmp (refcatname,"UCAC2",5)==0) { + ucat = UCAC2; + ucacpath = ucac2path; + strcpy (ucacenv, "UCAC2_PATH"); + nmag = 4; + } + else if (strncmp (refcatname,"ucac3",5)==0 || + strncmp (refcatname,"UCAC3",5)==0) { + ucat = UCAC3; + ucacpath = ucac3path; + strcpy (ucacenv, "UCAC3_PATH"); + nmag = 8; + } + else if (strncmp (refcatname,"ucac4",5)==0 || + strncmp (refcatname,"UCAC4",5)==0) { + ucat = UCAC4; + ucacpath = ucac4path; + strcpy (ucacenv, "UCAC4_PATH"); + nmag = 10; + /* UCAC4 high proper motion catalog */ + hpmpath = ucac4hpmpath; + } + else { + ucat = UCAC1; + ucacpath = ucac1path; + strcpy (ucacenv, "UCAC1_PATH"); + nmag = 1; + } + + /* If pathname is set in environment, override local value */ + if ((str = getenv (ucacenv)) != NULL ) { + ucacpath = str; + if (hpmpath) { + lstr = strlen (ucacpath) + 16; + str1 = (char *) calloc (lstr, sizeof (char)); + strcpy (str1, str); + hpmfile = strrchr (str1, '/') + 1; + strcpy (hpmfile, "u4i/u4hpm.dat"); + } + } + + /* If pathname is a URL, search and return */ + if (!strncmp (ucacpath, "http:",5)) { + if (str1) { + free ((void *)str1); + } + return (webread (ucacpath,refcatname,distsort,cra,cdec,dra,ddec,drad, + dradi,sysout,eqout,epout,mag1,mag2,sortmag,nstarmax, + gnum,gra,gdec,gpra,gpdec,gmag,gtype,nlog)); + } + + wcscstr (cstr, sysout, eqout, epout); + + SearchLim (cra,cdec,dra,ddec,sysout,&ra1,&ra2,&dec1,&dec2,verbose); + + /* Make mag1 always the smallest magnitude */ + if (mag2 < mag1) { + mag = mag2; + mag2 = mag1; + mag1 = mag; + } + + if (sortmag < 1) + magsort = 0; + else if (sortmag > nmag) + magsort = nmag - 1; + else + magsort = sortmag - 1; + + /* Allocate table for distances of stars from search center */ + if (nstarmax > ndist) { + if (ndist > 0) + free ((void *)gdist); + gdist = (double *) malloc (nstarmax * sizeof (double)); + if (gdist == NULL) { + if (str1) { + free ((void *)str1); + } + fprintf (stderr,"UCACREAD: cannot allocate separation array\n"); + return (0); + } + ndist = nstarmax; + } + + /* Allocate catalog entry buffer */ + star = (struct Star *) calloc (1, sizeof (struct Star)); + star->num = 0.0; + + nstar = 0; + jstar = 0; + + /* Get RA and Dec limits in catalog (J2000) coordinates */ + rra1 = ra1; + rra2 = ra2; + rdec1 = dec1; + rdec2 = dec2; + RefLim (cra,cdec,dra,ddec,sysout,sysref,eqout,eqref,epout,epref,secmarg, + &rra1, &rra2, &rdec1, &rdec2, &wrap, verbose); + + /* Find UCAC Star Catalog zones in which to search */ + nz = ucaczones (rdec1,rdec2,nrmax,zlist,verbose); + if (nz <= 0) { + if (str1) { + free ((void *)str1); + } + fprintf (stderr,"UCACREAD: no UCAC zone for %.2f-%.2f %.2f %.2f\n", + rra1, rra2, rdec1, rdec2); + return (0); + } + + /* Write header if printing star entries as found */ + if (nstarmax < 1) { + char *revmessage; + revmessage = getrevmsg(); + printf ("catalog UCAC1\n"); + ra2str (rastr, 31, cra, 3); + printf ("ra %s\n", rastr); + dec2str (decstr, 31, cdec, 2); + printf ("dec %s\n", decstr); + printf ("rpmunit mas/year\n"); + printf ("dpmunit mas/year\n"); + if (drad != 0.0) { + printf ("radmin %.1f\n", drad*60.0); + if (dradi > 0) + printf ("radimin %.1f\n", dradi*60.0); + } + else { + printf ("dramin %.1f\n", dra*60.0* cosdeg (cdec)); + printf ("ddecmin %.1f\n", ddec*60.0); + } + printf ("radecsys %s\n", cstr); + printf ("equinox %.3f\n", eqout); + printf ("epoch %.3f\n", epout); + printf ("program scat %s\n", revmessage); + printf ("ucac_id ra dec "); + if (ucat == UCAC1) { + printf ("mag ura udec arcmin\n"); + printf ("---------- ------------ ------------ "); + printf ("----- ------ ------ ------\n"); + } + else if (ucat == UCAC2) { + printf ("raerr decerr magc "); + printf ("magj magh magk mag "); + printf ("pmra pmdec pmrerr pmderr "); + printf ("ni nc arcsec\n"); + printf ("---------- ------------ ------------ "); + printf ("------ ------ ----- ----- ----- "); + printf ("----- ----- ------ ------ ----- ----- "); + printf ("-- -- ------\n"); + } + else if (ucat == UCAC3) { + printf ("raerr decerr magb magr magi "); + printf ("magj magh magk maga magm "); + printf ("mag pmra pmdec pmrerr pmderr "); + printf ("ni nc arcsec\n"); + printf ("---------- ------------ ------------ "); + printf ("------ ------ ----- ------ ----- "); + printf ("----- ----- ----- ----- ----- "); + printf ("----- ----- ----- ------ ------ "); + printf ("-- -- ------\n"); + } + else if (ucat == UCAC4) { + printf ("raerr decerr magb magv magg "); + printf ("magr magi magj magj magk "); + printf ("pmra pmdec pmrerr pmderr "); + printf ("ni nc arcsec\n"); + printf ("---------- ------------ ------------ "); + printf ("------ ------ ----- ------ ----- "); + printf ("----- ----- ----- ----- ----- "); + printf ("----- ----- ------ ------ "); + printf ("-- -- ------\n"); + } + } + + /* Loop through zone list */ + nstar = 0; + for (iz = 0; iz < nz; iz++) { + + /* Get path to zone catalog */ + zone = zlist[iz]; + +#ifdef UCAC_DEBUG + if (zone == 183) { + fprintf(stderr,"at zone %d\n",zone); + } +#endif /* UCAC_DEBUG */ + + if ((starcat = ucacopen (zone)) != 0) { + + jstar = 0; + jtable = 0; + for (iwrap = 0; iwrap <= wrap; iwrap++) { + + /* Find first star based on RA */ + if (iwrap == 0 || wrap == 0) { + istar1 = ucacsra (starcat, star, zone, rra1); + if (istar1 > 5) + istar1 = istar1 - 5; + else + istar1 = 1; + } + else + istar1 = 1; + + /* Find last star based on RA */ + if (iwrap == 1 || wrap == 0) { + istar2 = ucacsra (starcat, star, zone, rra2); + if (istar2 < starcat->nstars - 5) + istar2 = istar2 + 5; + else + istar2 = starcat->nstars; + } + else + istar2 = starcat->nstars; + + if (istar1 == 0 || istar2 == 0) + break; + + nread = istar2 - istar1 + 1; + + /* Loop through zone catalog for this region */ + for (istar = istar1; istar <= istar2; istar++) { + jtable ++; + + if (ucacstar (starcat, star, zone, istar)) { + fprintf(stderr,"UCACREAD: Cannot read star %d\n",istar); + break; + } + + /* ID number */ + num = star->num; + + /* Magnitude */ + mag = star->xmag[magsort]; + + /* Check magnitude limits */ + pass = 1; + if (mag1 != mag2 && (mag < mag1 || mag > mag2)) + pass = 0; + + /* Check position limits */ + if (pass) { + + /* Get position in output coordinate system */ + ra = star->ra; + dec = star->dec; + rapm = star->rapm; + decpm = star->decpm; + errra = star->errra; + errdec = star->errdec; + errpmr = star->errpmr; + errpmd = star->errpmd; + nim = star->nimage; + ncat = star->ncat; + wcsconp (sysref, sysout, eqref, eqout, epref, epout, + &ra, &dec, &rapm, &decpm); + + /* Compute distance from search center */ + if (drad > 0 || distsort) + dist = wcsdist (cra,cdec,ra,dec); + else + dist = 0.0; + + /* Check radial distance to search center */ + if (drad > 0) { + if (dist > drad) + pass = 0; + if (dradi > 0.0 && dist < dradi) + pass = 0; + } + + /* Check distance along RA and Dec axes */ + else { + ddist = wcsdist (cra,cdec,cra,dec); + if (ddist > ddec) + pass = 0; + rdist = wcsdist (cra,dec,ra,dec); + if (rdist > dra) + pass = 0; + } + } + + if (pass) { + + /* Write star position and magnitude to stdout */ + if (nstarmax < 1) { + ra2str (rastr, 31, ra, 3); + dec2str (decstr, 31, dec, 2); + dist = wcsdist (cra,cdec,ra,dec) * 3600.0; + printf ("%010.6f %s %s", num,rastr,decstr); + if (ucat == UCAC2 || ucat == UCAC3 || ucat == UCAC4) + printf (" %5.3f %5.3f", + errra * 3600.0 * cosdeg (dec), errdec * 3600.0); + if (ucat == UCAC1) + printf (" %5.2f", mag); + else + printf (" %5.2f %5.2f %5.2f %5.2f", + star->xmag[0], star->xmag[1], + star->xmag[2], star->xmag[3]); + if (ucat == UCAC3 || ucat == UCAC4) + printf (" %5.2f %5.2f %5.2f %5.2f", + star->xmag[4], star->xmag[5], + star->xmag[6], star->xmag[7]); + printf (" %5.2f %6.1f %6.1f", + mag, rapm*3600000.0*cosdeg (dec), + decpm*3600000.0); + printf (" %6.1f %6.1f", + errpmr*3600000.0, errpmd*3600000.0); + printf (" %2d %2d %.3f\n", nim, ncat, dist); + } + + /* Save star position and magnitude in table */ + else if (nstar < nstarmax) { + gnum[nstar] = num; + gra[nstar] = ra; + gdec[nstar] = dec; + gpra[nstar] = rapm; + gpdec[nstar] = decpm; + if (ucat == UCAC1) + gmag[0][nstar] = mag; + else { + for (imag = 0; imag < nmag; imag++) + gmag[imag][nstar] = star->xmag[imag]; + gmag[nmag][nstar] = star->errra; + gmag[nmag+1][nstar] = star->errdec; + gmag[nmag+2][nstar] = star->errpmr; + gmag[nmag+3][nstar] = star->errpmd; + gtype[nstar] = (1000 * nim) + ncat; + } + gdist[nstar] = dist; + if (dist > maxdist) { + maxdist = dist; + farstar = nstar; + } + if (mag > faintmag) { + faintmag = mag; + faintstar = nstar; + } + } + + /* If too many stars and distance sorting, + replace farthest star */ + else if (distsort) { + if (dist < maxdist) { + gnum[farstar] = num; + gra[farstar] = ra; + gdec[farstar] = dec; + gpra[farstar] = rapm; + gpdec[farstar] = decpm; + if (ucat == UCAC1) + gmag[0][farstar] = mag; + else { + for (imag = 0; imag < nmag; imag++) + gmag[imag][farstar] = star->xmag[imag]; + gmag[nmag][farstar] = star->errra; + gmag[nmag+1][farstar] = star->errdec; + gmag[nmag+2][farstar] = star->errpmr; + gmag[nmag+3][farstar] = star->errpmd; + gtype[farstar] = (1000 * nim) + ncat; + } + gdist[farstar] = dist; + + /* Find new farthest star */ + maxdist = 0.0; + for (i = 0; i < nstarmax; i++) { + if (gdist[i] > maxdist) { + maxdist = gdist[i]; + farstar = i; + } + } + } + } + + /* Else if too many stars, replace faintest star */ + else if (mag < faintmag) { + gnum[faintstar] = num; + gra[faintstar] = ra; + gdec[faintstar] = dec; + gpra[faintstar] = rapm; + gpdec[faintstar] = decpm; + if (ucat == UCAC1) + gmag[0][faintstar] = mag; + else { + for (imag = 0; imag < nmag; imag++) + gmag[imag][faintstar] = star->xmag[imag]; + gmag[nmag][faintstar] = star->errra; + gmag[nmag+1][faintstar] = star->errdec; + gmag[nmag+2][faintstar] = star->errpmr; + gmag[nmag+3][faintstar] = star->errpmd; + gtype[faintstar] = (1000 * nim) + ncat; + } + gdist[faintstar] = dist; + + /* Find new faintest star */ + faintmag = 0.0; + for (i = 0; i < nstarmax; i++) { + if (gmag[magsort][i] > faintmag) { + faintmag = gmag[magsort][i]; + faintstar = i; + } + } + } + + nstar++; + if (nlog == 1) + fprintf (stderr,"UCACREAD: %11.6f: %9.5f %9.5f %5.2f\n", + num,ra,dec,mag); + + /* End of accepted star processing */ + } + + /* Log operation */ + jstar++; + if (nlog > 0 && istar%nlog == 0) + fprintf (stderr,"UCACREAD: %5d / %5d / %5d sources\r", + nstar,jstar,starcat->nstars); + + /* End of star loop */ + } + + /* End of 0:00 RA wrap loop */ + } + + /* End of successful zone file loop */ + ntot = ntot + starcat->nstars; + if (nlog > 0) + fprintf (stderr,"UCACREAD: %4d / %4d: %5d / %5d / %5d sources from zone %4d \n", + iz+1,nz,nstar,jstar,starcat->nstars,zlist[iz]); + + /* Close region input file */ + ucacclose (starcat); + } + + /* End of zone loop */ + } + + /* Summarize transfer */ + if (nlog > 0) { + if (nz > 1) + fprintf (stderr,"UCACREAD: %d zones: %d / %d found\n",nz,nstar,ntot); + else + fprintf (stderr,"UCACREAD: 1 region: %d / %d found\n",nstar,ntot); + if (nstar > nstarmax) + fprintf (stderr,"UCACREAD: %d stars found; only %d returned\n", + nstar,nstarmax); + } + if (str1) { + free ((void *)str1); + } + return (nstar); +} + +/* UCACRNUM -- Read HST Guide Star Catalog stars from CDROM */ + +int +ucacrnum (refcatname,nstars,sysout,eqout,epout, + gnum,gra,gdec,gpra,gpdec,gmag,gtype,nlog) + + char *refcatname; /* Name of catalog (UAC, USAC, UAC2, USAC2) */ + int nstars; /* Number of stars to find */ + int sysout; /* Search coordinate system */ + double eqout; /* Search coordinate equinox */ + double epout; /* Proper motion epoch (0.0 for no proper motion) */ + double *gnum; /* Array of Guide Star numbers (returned) */ + double *gra; /* Array of right ascensions (returned) */ + double *gdec; /* Array of declinations (returned) */ + double *gpra; /* Array of right ascension proper motions (returned) */ + double *gpdec; /* Array of declination proper motions (returned) */ + double **gmag; /* Array of B and V magnitudes (returned) */ + int *gtype; /* Array of object types (returned) */ + int nlog; /* 1 for diagnostics */ +{ + int sysref=WCS_J2000; /* Catalog coordinate system */ + double eqref=2000.0; /* Catalog equinox */ + double epref=2000.0; /* Catalog epoch */ + struct StarCat *starcat; + struct Star *star; + char *str; + char ucacenv[16]; + + int verbose; + int zone, zone0; + int jstar, imag, nmag; + int istar, nstar; + double num, ra, dec, rapm, decpm, mag; + + if (nlog == 1) + verbose = 1; + else + verbose = 0; + + /* Set catalog code and path to catalog */ + if (strncmp (refcatname,"ucac4",5)==0 || + strncmp (refcatname,"UCAC4",5)==0) { + ucat = UCAC4; + ucacpath = ucac4path; + strcpy (ucacenv, "UCAC4_PATH"); + nmag = 8; + } + if (strncmp (refcatname,"ucac3",5)==0 || + strncmp (refcatname,"UCAC3",5)==0) { + ucat = UCAC3; + ucacpath = ucac3path; + strcpy (ucacenv, "UCAC3_PATH"); + nmag = 8; + } + else if (strncmp (refcatname,"ucac2",5)==0 || + strncmp (refcatname,"UCAC2",5)==0) { + ucat = UCAC2; + ucacpath = ucac2path; + strcpy (ucacenv, "UCAC2_PATH"); + nmag = 4; + } + else { + ucat = UCAC1; + ucacpath = ucac1path; + strcpy (ucacenv, "UCAC1_PATH"); + nmag = 1; + } + + /* If pathname is set in environment, override local value */ + if ((str = getenv(ucacenv)) != NULL ) + ucacpath = str; + + /* If pathname is a URL, search and return */ + if (!strncmp (ucacpath, "http:",5)) + return (webrnum (ucacpath,refcatname,nstars,sysout,eqout,epout,1, + gnum,gra,gdec,gpra,gpdec,gmag,gtype,nlog)); + + /* Allocate catalog entry buffer */ + star = (struct Star *) calloc (1, sizeof (struct Star)); + star->num = 0.0; + nstar = 0; + zone0 = 0; + starcat = NULL; + + /* Loop through star list */ + for (jstar = 0; jstar < nstars; jstar++) { + zone = (int) (gnum[jstar] + 0.0000001); + + /* Find numbered stars (rrr.nnnnnn) */ + istar = (int) ((gnum[jstar] - (double) zone + 0.0000001) * 1000000.0); + if (istar > 0) { + if (zone != zone0) { + if (starcat != NULL) + ucacclose (starcat); + starcat = ucacopen (zone); + } + if (starcat == NULL) { + fprintf (stderr,"UCACRNUM: Zone %d file not found\n", zone); + return (0); + } + if (ucacstar (starcat, star, zone, istar)) { + fprintf (stderr,"UCACRNUM: Cannot read star %d.%06d\n", zone, istar); + gra[jstar] = 0.0; + gdec[jstar] = 0.0; + if (ucat == UCAC1) + gmag[0][jstar] = 0.0; + else { + for (imag = 0; imag < nmag; imag++) + gmag[imag][jstar] = 0.0; + } + gtype[jstar] = 0; + continue; + } + + /* If star has been found in catalog */ + + /* ID number */ + num = star->num; + + /* Position in degrees at designated epoch */ + ra = star->ra; + dec = star->dec; + rapm = star->rapm; + decpm = star->decpm; + wcsconp (sysref, sysout, eqref, eqout, epref, epout, + &ra, &dec, &rapm, &decpm); + + /* Magnitude */ + mag = star->xmag[0]; + + /* Save star position and magnitude in table */ + gnum[jstar] = num; + gra[jstar] = ra; + gdec[jstar] = dec; + gpra[jstar] = rapm; + gpdec[jstar] = decpm; + gmag[0][jstar] = mag; + gtype[jstar] = (1000 * star->nimage) + star->ncat; + if (ucat == UCAC1) + gmag[0][jstar] = star->xmag[0]; + else { + for (imag = 0; imag < nmag; imag++) + gmag[imag][jstar] = star->xmag[imag]; + gmag[nmag][jstar] = star->errra; + gmag[nmag+1][jstar] = star->errdec; + gmag[nmag+2][jstar] = star->errpmr; + gmag[nmag+3][jstar] = star->errpmd; + gtype[jstar] = (1000 * star->nimage) + star->ncat; + } + if (nlog == 1) { + if (ucat == UCAC1) + fprintf (stderr,"UCACRNUM: %11.6f: %9.5f %9.5f %5.2f %s \n", + num, ra, dec, mag, star->isp); + else if (ucat == UCAC2) { + fprintf (stderr,"UCACRNUM: %11.6f: %9.5f %9.5f %5.2f", + num, ra, dec, star->xmag[0]); + fprintf (stderr," %5.2f %5.2f %5.2f", + star->xmag[1],star->xmag[2],star->xmag[3]); + fprintf (stderr," %d %d\n",star->nimage,star->ncat); + } + else if (ucat == UCAC3) { + fprintf (stderr,"UCACRNUM: %11.6f: %9.5f %9.5f %5.2f %5.2f", + num, ra, dec, star->xmag[0],star->xmag[1]); + fprintf (stderr," %5.2f %5.2f %5.2f", + star->xmag[2], star->xmag[3], star->xmag[4]); + fprintf (stderr," %5.2f %5.2f %5.2f", + star->xmag[5], star->xmag[6], star->xmag[7]); + fprintf (stderr," %d %d\n",star->nimage,star->ncat); + } + else if (ucat == UCAC4) { + fprintf (stderr,"UCACRNUM: %11.6f: %9.5f %9.5f %5.2f %5.2f", + num, ra, dec, star->xmag[0],star->xmag[1]); + fprintf (stderr," %5.2f %5.2f %5.2f", + star->xmag[2], star->xmag[3], star->xmag[4]); + fprintf (stderr," %5.2f %5.2f %5.2f", + star->xmag[5], star->xmag[6], star->xmag[7]); + fprintf (stderr," %d %d\n",star->nimage,star->ncat); + } else { + fprintf(stderr,"ucacread CATALOG NUMBER ERROR %d in line %d\n",ucat,__LINE__); + exit(-1); + } + } + } + + /* End of star loop */ + } + + /* Summarize search */ + ucacclose (starcat); + if (nlog > 0) + fprintf (stderr,"UCACRNUM: %d / %d found\n",nstar,starcat->nstars); + + return (nstars); +} + + +/* UCACBIN -- Fill a FITS WCS image with UCAC Star Catalog stars */ + +int +ucacbin (refcatname, wcs, header, image, mag1, mag2, sortmag, magscale, nlog) + + char *refcatname; /* Name of catalog (UAC, USAC, UAC2, USAC2) */ + struct WorldCoor *wcs; /* World coordinate system for image */ + char *header; /* FITS header for output image */ + char *image; /* Output FITS image */ + double mag1,mag2; /* Limiting magnitudes (none if equal) */ + int sortmag; /* Magnitude by which to sort (1 or 2) */ + double magscale; /* Scaling factor for magnitude to pixel flux + * (number of catalog objects per bin if 0) */ + int nlog; /* 1 for diagnostics */ +{ + double cra; /* Search center J2000 right ascension in degrees */ + double cdec; /* Search center J2000 declination in degrees */ + double dra; /* Search half width in right ascension in degrees */ + double ddec; /* Search half-width in declination in degrees */ + int sysout; /* Search coordinate system */ + double eqout; /* Search coordinate equinox */ + double epout; /* Proper motion epoch (0.0 for no proper motion) */ + double ra1,ra2; /* Limiting right ascensions of region in degrees */ + double dec1,dec2; /* Limiting declinations of region in degrees */ + int nz; /* Number of UCAC regions in search */ + int zlist[MAXZONE]; /* List of region numbers */ + int sysref = WCS_J2000; /* Catalog coordinate system */ + double eqref = 2000.0; /* Catalog equinox */ + double epref = 2000.0; /* Catalog epoch */ + double secmarg = 60.0; /* Arcsec/century margin for proper motion */ + struct StarCat *starcat; /* Star catalog data structure */ + struct Star *star; /* Single star cata structure */ + int verbose; + int wrap; + int ix, iy, iz; + int magsort; + int jstar; + int nrmax = MAXZONE; + int nstar, ntot; + int istar, istar1, istar2; + int jtable,iwrap, nread; + int pass; + int zone; + double num, ra, dec, rapm, decpm, mag; + double rra1, rra2, rdec1, rdec2; + double rdist, ddist; + char cstr[32]; + char ucacenv[16]; + char *str; + double xpix, ypix, flux; + int offscl; + int bitpix, w, h; /* Image bits/pixel and pixel width and height */ + double logt = log(10.0); + + ntot = 0; + if (nlog > 0) + verbose = 1; + else + verbose = 0; + + /* Set catalog code and path to catalog */ + if (strncmp (refcatname,"ucac4",5)==0 || + strncmp (refcatname,"UCAC4",5)==0) { + ucat = UCAC4; + ucacpath = ucac4path; + strcpy (ucacenv, "UCAC4_PATH"); + } + if (strncmp (refcatname,"ucac3",5)==0 || + strncmp (refcatname,"UCAC3",5)==0) { + ucat = UCAC3; + ucacpath = ucac3path; + strcpy (ucacenv, "UCAC3_PATH"); + } + else if (strncmp (refcatname,"ucac2",5)==0 || + strncmp (refcatname,"UCAC2",5)==0) { + ucat = UCAC2; + ucacpath = ucac2path; + strcpy (ucacenv, "UCAC2_PATH"); + } + else { + ucat = UCAC1; + ucacpath = ucac1path; + strcpy (ucacenv, "UCAC1_PATH"); + } + + /* If pathname is set in environment, override local value */ + if ((str = getenv (ucacenv)) != NULL ) + ucacpath = str; + + /* Set image parameters */ + bitpix = 0; + (void)hgeti4 (header, "BITPIX", &bitpix); + w = 0; + (void)hgeti4 (header, "NAXIS1", &w); + h = 0; + (void)hgeti4 (header, "NAXIS2", &h); + + /* Set catalog search limits from image WCS information */ + sysout = wcs->syswcs; + eqout = wcs->equinox; + epout = wcs->epoch; + wcscstr (cstr, sysout, eqout, epout); + wcssize (wcs, &cra, &cdec, &dra, &ddec); + SearchLim (cra,cdec,dra,ddec,sysout,&ra1,&ra2,&dec1,&dec2,verbose); + + /* Make mag1 always the smallest magnitude */ + if (mag2 < mag1) { + mag = mag2; + mag2 = mag1; + mag1 = mag; + } + + if (sortmag < 1) + magsort = 0; + else if (sortmag > 4) + magsort = 3; + else + magsort = sortmag - 1; + + /* Allocate catalog entry buffer */ + star = (struct Star *) calloc (1, sizeof (struct Star)); + star->num = 0.0; + + nstar = 0; + jstar = 0; + + /* Get RA and Dec limits in catalog (J2000) coordinates */ + rra1 = ra1; + rra2 = ra2; + rdec1 = dec1; + rdec2 = dec2; + RefLim (cra,cdec,dra,ddec,sysout,sysref,eqout,eqref,epout,epref,secmarg, + &rra1, &rra2, &rdec1, &rdec2, &wrap, verbose); + + /* Find UCAC Star Catalog zones in which to search */ + nz = ucaczones (rdec1,rdec2,nrmax,zlist,verbose); + if (nz <= 0) { + fprintf (stderr,"UCACBIN: no UCAC zone for %.2f-%.2f %.2f %.2f\n", + rra1, rra2, rdec1, rdec2); + return (0); + } + + /* Loop through zone list */ + nstar = 0; + for (iz = 0; iz < nz; iz++) { + + /* Get path to zone catalog */ + zone = zlist[iz]; + if ((starcat = ucacopen (zone)) != 0) { + + jstar = 0; + jtable = 0; + for (iwrap = 0; iwrap <= wrap; iwrap++) { + + /* Find first star based on RA */ + if (iwrap == 0 || wrap == 0) + istar1 = ucacsra (starcat, star, zone, rra1); + else + istar1 = 1; + + /* Find last star based on RA */ + if (iwrap == 1 || wrap == 0) + istar2 = ucacsra (starcat, star, zone, rra2); + else + istar2 = starcat->nstars; + + if (istar1 == 0 || istar2 == 0) + break; + + nread = istar2 - istar1 + 1; + + /* Loop through zone catalog for this region */ + for (istar = istar1; istar <= istar2; istar++) { + jtable ++; + + if (ucacstar (starcat, star, zone, istar)) { + fprintf(stderr,"UCACBIN: Cannot read star %d\n",istar); + break; + } + + /* ID number */ + num = star->num; + + /* Magnitude */ + mag = star->xmag[magsort]; + + /* Check magnitude limits */ + pass = 1; + if (mag1 != mag2 && (mag < mag1 || mag > mag2)) + pass = 0; + + /* Check position limits */ + if (pass) { + + /* Get position in output coordinate system */ + rapm = star->rapm; + decpm = star->decpm; + ra = star->ra; + dec = star->dec; + wcsconp (sysref, sysout, eqref, eqout, epref, epout, + &ra, &dec, &rapm, &decpm); + + /* Check distance along RA and Dec axes */ + ddist = wcsdist (cra,cdec,cra,dec); + if (ddist > ddec) + pass = 0; + rdist = wcsdist (cra,dec,ra,dec); + if (rdist > dra) + pass = 0; + } + + /* Save star in FITS image */ + if (pass) { + wcs2pix (wcs, ra, dec, &xpix, &ypix, &offscl); + if (!offscl) { + if (magscale > 0.0) + flux = magscale * exp (logt * (-mag / 2.5)); + else + flux = 1.0; + ix = (int) (xpix + 0.5); + iy = (int) (ypix + 0.5); + addpix1 (image, bitpix, w,h, 0.0,1.0, xpix,ypix, flux); + nstar++; + jstar++; + } + else { + ix = 0; + iy = 0; + } + if (nlog == 1) { + fprintf (stderr,"UCACBIN: %11.6f: %9.5f %9.5f %s", + num,ra,dec,cstr); + if (magscale > 0.0) + fprintf (stderr, " %5.2f", mag); + if (!offscl) + flux = getpix1 (image, bitpix, w, h, 0.0, 1.0, ix, iy); + else + flux = 0.0; + fprintf (stderr," (%d,%d): %f\n", ix, iy, flux); + } + + /* End of accepted star processing */ + } + + /* Log operation */ + jstar++; + if (nlog > 0 && istar%nlog == 0) + fprintf (stderr,"UCACBIN: %5d / %5d / %5d sources\r", + nstar,jstar,starcat->nstars); + + /* End of star loop */ + } + + /* End of 0:00 RA wrap loop */ + } + + /* End of successful zone file loop */ + ntot = ntot + starcat->nstars; + if (nlog > 0) + fprintf (stderr,"UCACBIN: %4d / %4d: %5d / %5d / %5d sources from zone %4d \n", + iz+1,nz,nstar,jstar,starcat->nstars,zlist[iz]); + + /* Close region input file */ + ucacclose (starcat); + } + + /* End of zone loop */ + } + + /* Summarize transfer */ + if (nlog > 0) { + if (nz > 1) + fprintf (stderr,"UCACBIN: %d zones: %d / %d found\n",nz,nstar,ntot); + else + fprintf (stderr,"UCACBIN: 1 region: %d / %d found\n",nstar,ntot); + } + return (nstar); +} + + +/* UCACZONE -- Compute the zones over which to search + * in the specified range of coordinates. + * Build lists containing the first star and number of stars for each range. + */ + +static int +ucaczones (dec1, dec2, nzmax, zones, verbose) + + double dec1, dec2; /* Declination limits in degrees */ + int nzmax; /* Maximum number of zones to find */ + int *zones; /* Zone numbers (returned)*/ + int verbose; /* 1 for diagnostics */ + +{ + int nz; /* Number of declination zones found (returned) */ + int iz, iz1, iz2; + int i; + double spd1, spd2; + + for (i = 0; i < nzmax; i++) + zones[i] = 0; + + /* Find first and last declination zone to search */ + spd1 = 90.0 + dec1; + iz1 = (int) ((spd1 * 2.0) + 0.99999); + if (iz1 < 1) iz1 = 1; + spd2 = 90.0 + dec2; + iz2 = (int) ((spd2 * 2.0) + 0.99999); + if (ucat == UCAC1 && iz2 > 169) iz2 = 169; + if (ucat == UCAC2 && iz2 > 288) iz2 = 288; + if (ucat == UCAC3 && iz2 > 360) iz2 = 360; + if (ucat == UCAC4) { + iz1 = (int) ((spd1 * 5.0) + 0.99999); + if (iz1 < 1) iz1 = 1; + spd2 = 90.0 + dec2; + iz2 = (int) ((spd2 * 5.0) + 0.99999); + if (iz2 > 900) { + iz2 = 900; + } + } + + if (iz1 > iz2) + return (0); + + nz = iz2 - iz1 + 1; + if (verbose) { + fprintf (stderr,"UCACZONES: searching %d zones: %d - %d\n",nz,iz1,iz2); + fprintf(stderr,"UCACZONES: Dec: %.5f - %.5f\n", dec1,dec2); + } + + i = 0; + for (iz = iz1; iz <= iz2; iz++) { + zones[i] = iz; + i++; + } + + return (nz); +} + + +/* UCACSRA -- Find UCAC star closest to specified right ascension */ + +static int +ucacsra (sc, st, zone, rax0) + + struct StarCat *sc; /* Star catalog descriptor */ + struct Star *st; /* Current star entry */ + int zone; /* Declination zone */ + double rax0; /* Right ascension in degrees for which to search */ +{ + int istar, istar1, istar2, nrep; + double rax, ra1, ra2, ra, rdiff, rdiff1, rdiff2, sdiff; + char rastrx[32]; + int debug = 0; + int maxnrep; +#ifdef UCAC_DEBUG + if (zone == 183) { + debug = 1; + fprintf(stderr,"Entering UCACSRA, zone %d\n",zone); + } else { + debug = 0; + } +#endif /* UCAC_DEBUG */ + + rax = rax0; + if (debug) + ra2str (rastrx, 31, rax, 3); + istar1 = 1; + ucacstar (sc, st, zone, istar1); + ra1 = st->ra; + istar2 = sc->nstars; + maxnrep = sc->nstars; + istar = (istar1+istar2)/2; + nrep = 0; + while (istar != istar1 && nrep < maxnrep) { + if (ucacstar (sc, st, zone, istar)) { + break; + } else { + ra = st->ra; + if (ra == ra1) + break; + if (debug) { + char rastr[32]; + ra2str (rastr, 31, ra, 3); + fprintf (stderr,"UCACSRA %d %d: %s (%s)\n", + nrep,istar,rastr,rastrx); + } + nrep++; + if (ra > rax) { + istar2 = istar; + ra2 = ra; + } else { + istar1 = istar; + ra1 = ra; + } + istar = (istar1+istar2)/2; + if (debug) { + fprintf (stderr," ra1= %.5f ra2= %.5f rax= %.5f\n", + ra1,ra2,rax); + fprintf (stderr," istar1= %d istar= %d istar2= %d\n", + istar1,istar,istar2); + } + if (istar < 1) + istar = 1; + if (istar > sc->nstars) + istar = sc->nstars; + if (istar == istar1) + break; + } + } + return (istar); +} + + +/* UCACOPEN -- Open UCAC catalog file, returning number of entries */ + +struct StarCat * +ucacopen (zone) + + int zone; /* Number of catalog zone to read */ + +{ + FILE *fcat; + struct StarCat *sc; + int lfile, lpath; + char *zonefile; + char *zonepath; /* Full pathname for catalog file */ + + /* Set pathname for catalog file */ + lpath = strlen (ucacpath) + 16; + zonepath = (char *) malloc (lpath); + if (ucat == UCAC1) + sprintf (zonepath, "%s/u1/z%03d", ucacpath, zone); + else if (ucat == UCAC2) + sprintf (zonepath, "%s/u2/z%03d", ucacpath, zone); + else if (ucat == UCAC3) + sprintf (zonepath, "%s/z%03d", ucacpath, zone); + else if (ucat == UCAC4) + sprintf (zonepath, "%s/z%03d", ucacpath, zone); + else { + fprintf(stderr,"ucacread CATALOG NUMBER ERROR %d in line %d\n",ucat,__LINE__); + exit(-1); + } + /* Set UCAC catalog header information */ + sc = (struct StarCat *) calloc (1, sizeof (struct StarCat)); + sc->byteswapped = 0; + + /* Set number of stars in this zone catalog */ + if (ucat == UCAC1) + sc->nbent = 67; + else if (ucat == UCAC2) + sc->nbent = 44; + else if (ucat == UCAC3) + sc->nbent = 84; + else if (ucat == UCAC4) + sc->nbent = sizeof(UCAC4star); + else { + fprintf(stderr,"ucacread CATALOG NUMBER ERROR %d in line %d\n",ucat,__LINE__); + exit(-1); + } + lfile = getfilesize (zonepath); + if (lfile < 2) { + fprintf (stderr,"UCAC zone catalog %s has no entries\n",zonepath); + free (sc); + sc = NULL; + return (NULL); + } + else + sc->nstars = lfile / sc->nbent; + + /* Open UCAC file */ + if (!(fcat = fopen (zonepath, "r"))) { + fprintf (stderr,"UCACOPEN: UCAC file %s cannot be read\n",zonepath); + free (sc); + return (NULL); + } + + /* Separate filename from pathname and save in structure */ + zonefile = strrchr (zonepath,'/'); + if (zonefile) + zonefile = zonefile + 1; + else + zonefile = zonepath; + if (strlen (zonefile) < 24) + strcpy (sc->isfil, zonefile); + else + strncpy (sc->isfil, zonefile, 23); + + /* Set other catalog information in structure */ + sc->inform = 'J'; + sc->coorsys = WCS_J2000; + sc->epoch = 2000.0; + sc->equinox = 2000.0; + sc->ifcat = fcat; + sc->sptype = 0; + if (ucat == UCAC1) + sc->nmag = 1; + else if (ucat == UCAC2) + sc->nmag = 4; + else if (ucat == UCAC3) + sc->nmag = 8; + else if (ucat == UCAC4) + sc->nmag = 8; + else { + fprintf(stderr,"ucacread CATALOG NUMBER ERROR %d in line %d\n",ucat,__LINE__); + exit(-1); + } + + + /* UCAC stars are RA-sorted within declination zones */ + sc->rasorted = 1; + + /* Check to see if byte-swapping is necessary */ + cswap = 0; + if (ucat == UCAC2) { + UCAC2star us2; /* UCAC2 catalog entry for one star */ + int nbr; + + nbr = fread (&us2, 1, sc->nbent, sc->ifcat); + if (nbr < 1) { + fprintf (stderr, + "UCACOPEN: cannot read star 1 from UCAC2 zone catalog %s\n", + zonepath); + return (0); + } + + /* RA should be between 0 and 360 degrees in milliarcseconds */ + if (us2.rasec > 360 * 3600000 || us2.rasec < 0) + cswap = 1; + + /* Dec should be between -90 and +90 degrees in milliarcseconds */ + else if (us2.decsec > 90 * 3600000 || us2.decsec < -90 * 3600000) + cswap = 1; + + /* J H K magnitudes should be near-positive */ + else if (us2.jmag < -1000 || us2.hmag < -1000 || us2.kmag < -1000) + cswap = 1; + else + cswap = 0; + + /* if (cswap) + fprintf (stderr, + "UCACOPEN: swapping bytes in UCAC2 zone catalog %s\n", + zonepath); */ + } + else if (ucat == UCAC3) { + UCAC3star us3; /* UCAC3 catalog entry for one star */ + int nbr; + + nbr = fread (&us3, 1, sc->nbent, sc->ifcat); + if (nbr < 1) { + fprintf (stderr, + "UCACOPEN: cannot read star 1 from UCAC3 zone catalog %s\n", + zonepath); + return (0); + } + + /* RA should be between 0 and 360 degrees in milliarcseconds */ + if (us3.rasec > 360 * 3600000 || us3.rasec < 0) + cswap = 1; + + /* Dec should be between -90 and +90 degrees in milliarcseconds */ + else if (us3.decsec > 180 * 3600000 || us3.decsec < -180 * 3600000) + cswap = 1; + + /* J H K magnitudes should be near-positive */ + else if (us3.jmag < -1000 || us3.hmag < -1000 || us3.kmag < -1000) + cswap = 1; + else + cswap = 0; + + /* if (cswap) + fprintf (stderr, + "UCACOPEN: swapping bytes in UCAC2 zone catalog %s\n",zomepath); */ + } + else if (ucat == UCAC4) { + UCAC4star us4; /* UCAC4 catalog entry for one star */ + int nbr; + + nbr = fread (&us4, 1, sc->nbent, sc->ifcat); + if (nbr < 1) { + fprintf (stderr, + "UCACOPEN: cannot read star 1 from UCAC4 zone catalog %s\n", + zonepath); + return (0); + } + + /* RA should be between 0 and 360 degrees in milliarcseconds */ + if (us4.ra > 360 * 3600000 || us4.ra < 0) + cswap = 1; + + /* Dec should be between -90 and +90 degrees in milliarcseconds */ + else if (us4.spd > 180 * 3600000 || us4.spd < 0) + cswap = 1; + + /* J H K magnitudes should be near-positive */ + else if (us4.mag_j < -1000 || us4.mag_h < -1000 || us4.mag_k < -1000) + cswap = 1; + else + cswap = 0; + + if (cswap) + fprintf (stderr, + "UCACOPEN: swapping bytes in UCAC4 zone catalog %s\n",zonepath); + } + else { + fprintf(stderr,"ucacread CATALOG NUMBER ERROR %d in line %d\n",ucat,__LINE__); + exit(-1); + } + + sc->istar = 0; + free (zonepath); + return (sc); +} + + +void +ucacclose (sc) + struct StarCat *sc; /* Star catalog descriptor */ +{ + fclose (sc->ifcat); + free (sc); + return; +} + + +/* UCACSTAR -- Get UCAC catalog entry for one star; + return 0 if successful */ + +static int +ucacstar (sc, st, zone, istar) + + struct StarCat *sc; /* Star catalog descriptor */ + struct Star *st; /* Current star entry */ + int zone; /* Declination zone */ + int istar; /* Star sequence number in UCAC catalog region file */ +{ + + + char line[256]; + int nbr, nbskip; + UCAC2star us2; /* UCAC2 catalog entry for one star */ + UCAC3star us3; /* UCAC3 catalog entry for one star */ + UCAC4star us4; /* UCAC4 catalog entry for one star */ + + int hpmIndex; + int lineLen; + int nvals; + FILE *hpmHandle; + char inLine[MAX_U4HPM_LINE]; + char *inBuffer; + PU4HPM pU4hpm = NULL; + + + /* Drop out if catalog pointer is not set */ + if (sc == NULL) + return (1); + + /* Drop out if catalog is not open */ + if (sc->ifcat == NULL) + return (2); + + /* Drop out if star number is too small or too large */ + if (istar < 1 || istar > sc->nstars) { + fprintf (stderr, "UCAC star %d is not in catalog\n",istar); + return (-1); + } + + /* Move file pointer to start of correct star entry */ + nbskip = sc->nbent * (istar - 1); + if (fseek (sc->ifcat,nbskip,SEEK_SET)) + return (-1); + + if (ucat == UCAC1) + nbr = fread (line, 1, sc->nbent, sc->ifcat); + else if (ucat == UCAC2) + nbr = fread (&us2, 1, sc->nbent, sc->ifcat); + else if (ucat == UCAC3) + nbr = fread (&us3, 1, sc->nbent, sc->ifcat); + else if (ucat == UCAC4) + nbr = fread (&us4, 1, sc->nbent, sc->ifcat); + else { + fprintf(stderr,"ucacread CATALOG NUMBER ERROR %d in line %d\n",ucat,__LINE__); + exit(-1); + } + if (nbr < sc->nbent) { + fprintf (stderr, "UCACSTAR %d / %d bytes read\n",nbr, sc->nbent); + return (-2); + } +#if 0 + if ((zone == 552) && (istar == 43247)) { + printf("At zone %d and istar %d\n",zone,istar); + } +#endif + + + /* Star ID number = region.sequence */ + st->num = (double) zone + (0.000001 * (double) istar); + + /* Read UCAC1 position and proper motion from ASCII file */ + if (ucat == UCAC1) { + + /* Read position in degrees */ + st->ra = atof (line) / 3600000.0; + st->dec = (atof (line+10) / 3600000.0) - 90.0; + + /* Read proper motion and convert it to to degrees/year */ + st->rapm = (atof (line+41) / 3600000.0) / cosdeg (st->dec); + st->decpm = atof (line+48) / 3600000.0; + + /* Set V magnitude */ + st->xmag[0] = atof (line+20) * 0.01; + } + + /* Read UCAC2 position, proper motion, and magnitudes from binary file */ + else if (ucat == UCAC2) { + if (cswap) { + ucacswap4 (&us2.rasec); + ucacswap4 (&us2.decsec); + ucacswap4 (&us2.rapm); + ucacswap4 (&us2.decpm); + ucacswap2 (&us2.cmag); + ucacswap2 (&us2.jmag); + ucacswap2 (&us2.hmag); + ucacswap2 (&us2.kmag); + } + st->ra = (double) us2.rasec / 3600000.0; + st->dec = (double) us2.decsec / 3600000.0; + st->errra = (double) us2.era / 3600000.0; /* mas */ + st->errra = st->errra / cosdeg (st->dec); /* to RA deg */ + st->errdec = (double) us2.edec / 3600000.0; /* mas */ + st->rapm = (double) us2.rapm / 36000000.0; /* 0.1mas/yr */ + st->decpm = (double) us2.decpm / 36000000.0; /* 0.1mas/yr */ + st->errpmr = (double) us2.erapm / 36000000.0; /* 0.1mas/yr */ + st->errpmr = st->errpmr / cosdeg (st->dec); /* to RA deg */ + st->errpmd = (double) us2.edecpm / 36000000.0; /* 0.1mas/yr */ + st->xmag[0] = ((double) us2.jmag) / 1000.0; + st->xmag[1] = ((double) us2.hmag) / 1000.0; + st->xmag[2] = ((double) us2.kmag) / 1000.0; + st->xmag[3] = ((double) us2.cmag) / 100.0; + st->nimage = (int) us2.nobs; + st->ncat = (int) us2.ncat; + } + + /* Read UCAC3 position, proper motion, and magnitudes from binary file */ + else if (ucat == UCAC3) { + if (cswap) { + ucacswap4 (&us3.rasec); + ucacswap4 (&us3.decsec); + ucacswap4 (&us3.rapm); + ucacswap4 (&us3.decpm); + ucacswap2 (&us3.sigra); + ucacswap2 (&us3.sigdec); + ucacswap2 (&us3.sigpmr); + ucacswap2 (&us3.sigpmd); + ucacswap2 (&us3.mmag); + ucacswap2 (&us3.amag); + ucacswap2 (&us3.jmag); + ucacswap2 (&us3.hmag); + ucacswap2 (&us3.kmag); + ucacswap2 (&us3.bmag); + ucacswap2 (&us3.rmag); + ucacswap2 (&us3.imag); + } + st->ra = (double) us3.rasec / 3600000.0; /* mas */ + st->dec = (double) us3.decsec / 3600000.0; /* mas */ + st->dec = st->dec - 90.0; + st->errra = (double) us3.sigra / 3600000.0; /* mas */ + st->errra = st->errra / cosdeg (st->dec); /* to RA deg */ + st->errdec = (double) us3.sigdec / 3600000.0; /* mas */ + st->rapm = (double) us3.rapm / 36000000.0; /* 0.1mas/yr */ + st->rapm = st->rapm / cosdeg (st->dec); /* to RA deg */ + st->decpm = (double) us3.decpm / 36000000.0; /* 0.1mas/yr */ + st->errpmr = (double) us3.sigpmr / 36000000.0; /* 0.1mas/yr */ + st->errpmr = st->errpmr / cosdeg (st->dec); /* to RA deg */ + st->errpmd = (double) us3.sigpmd / 36000000.0; /* 0.1mas/yr */ + st->nimage = (int) us3.nu1; + st->ncat = (int) us3.us1; + if (us3.bmag == 0) + st->xmag[0] = 99.990; + else + st->xmag[0] = ((double) us3.bmag) / 1000.0; + if (us3.rmag == 0) + st->xmag[1] = 99.990; + else + st->xmag[1] = ((double) us3.rmag) / 1000.0; + if (us3.imag == 0) + st->xmag[2] = 99.990; + else + st->xmag[2] = ((double) us3.imag) / 1000.0; + if (us3.jmag == 0) + st->xmag[3] = 99.990; + else + st->xmag[3] = ((double) us3.jmag) / 1000.0; + if (us3.hmag == 0) + st->xmag[4] = 99.990; + else + st->xmag[4] = ((double) us3.hmag) / 1000.0; + if (us3.kmag == 0) + st->xmag[5] = 99.990; + else + st->xmag[5] = ((double) us3.kmag) / 1000.0; + if (us3.mmag == 0) + st->xmag[6] = 99.990; + else + st->xmag[6] = ((double) us3.mmag) / 1000.0; + if (us3.amag == 0) + st->xmag[7] = 99.990; + else + st->xmag[7] = ((double) us3.amag) / 1000.0; + } + else if (ucat == UCAC4) { + if (cswap) { + ucacswap4 (&us4.ra); + ucacswap4 (&us4.spd); + ucacswap4 (&us4.pm_ra); + ucacswap4 (&us4.pm_dec); + ucacswap4 (&us4.id_number); + ucacswap2 (&us4.ra_sigma); + ucacswap2 (&us4.dec_sigma); + ucacswap2 (&us4.pm_ra_sigma); + ucacswap2 (&us4.pm_dec_sigma); + ucacswap2 (&us4.magm); + ucacswap2 (&us4.maga); + ucacswap2 (&us4.mag_j); + ucacswap2 (&us4.mag_h); + ucacswap2 (&us4.mag_k); + ucacswap2 (&us4.apass_mag[0]); + ucacswap2 (&us4.apass_mag[1]); + ucacswap2 (&us4.apass_mag[2]); + ucacswap2 (&us4.apass_mag[3]); + ucacswap2 (&us4.apass_mag[4]); + } + st->ra = (double) us4.ra / 3600000.0; /* mas */ + st->dec = (double) us4.spd / 3600000.0; /* mas */ + st->dec = st->dec - 90.0; + st->errra = (double) us4.ra_sigma / 3600000.0; /* mas */ + st->errra = st->errra / cosdeg (st->dec); /* to RA deg */ + st->errdec = (double) us4.dec_sigma / 3600000.0; /* mas */ + + /* Must get proper motions from a different catalog */ + if ((us4.pm_ra == 32767) || (us4.pm_dec == 32767)) { + if (hpmLines == 0) { + /* Read in the high proper motion catalog */ + hpmHandle = fopen(hpmpath,"rt"); + if (hpmHandle == NULL) { + printf("ERROR: failed to open %s\n",hpmpath); + exit(-1); + } + hpmLines = 0; + while(1) { + if (hpmLines >= MAX_U4HPM_RECORDS) { + printf("ERROR: MAX_U4HPM_RECORDS exceeded\n"); + exit(-1); + } + pU4hpm = &u4hpm_table[hpmLines]; + memset(pU4hpm,0,sizeof(U4HPM)); + inBuffer = fgets(inLine,MAX_U4HPM_LINE,hpmHandle); + if (inBuffer == NULL) { + break; + } + lineLen = strlen(inBuffer); + /* Trim off the carriage return */ + if (inBuffer[lineLen-1] == 10) { + inBuffer[lineLen-1] = 0; + lineLen--; + } + /* Trim off the line feed */ + if (inBuffer[lineLen-1] == 13) { + inBuffer[lineLen-1] = 0; + lineLen--; + } + nvals = sscanf(inBuffer,"%d %d %d %d %d %d %d %d", + &pU4hpm->rnm, + &pU4hpm->zn, + &pU4hpm->rnz, + &pU4hpm->pmrc, + &pU4hpm->pmd, + &pU4hpm->ra, + &pU4hpm->dec, + &pU4hpm->maga); + if (nvals != 8) { + fprintf(stderr,"Error reading line %d of u4hpm %s\n",hpmLines,inLine); + } else { + hpmLines++; + } + } + fclose(hpmHandle); + } + for (hpmIndex = 0; hpmIndex < hpmLines; hpmIndex++) { + pU4hpm = &u4hpm_table[hpmIndex]; + if ((zone == pU4hpm->zn) && + (us4.id_number == pU4hpm->rnm) && + (us4.ra == pU4hpm->ra) && + (us4.spd == pU4hpm->dec) && + (us4.maga == pU4hpm->maga)) { + /* We have a match */ + st->rapm = (1.0 * pU4hpm->pmrc) / 36000000.0; /* 0.1 mas/yr */ + st->rapm = st->rapm / cosdeg (st->dec); /* to RA deg */ + st->decpm = (1.0 * pU4hpm->pmd) / 36000000.0; /* 0.1 mas/yr */ + break; + } + } + if (hpmIndex == hpmLines) { + fprintf(stderr,"ERROR: no proper motion found for zone %d entry %d\n",zone,us4.id_number); + } + + } else { + + st->rapm = (double) us4.pm_ra / 36000000.0; /* 0.1mas/yr */ + st->rapm = st->rapm / cosdeg (st->dec); /* to RA deg */ + st->decpm = (double) us4.pm_dec / 36000000.0; /* 0.1mas/yr */ + } + st->errpmr = (double) (us4.pm_ra_sigma+128) / 36000000.0; /* 0.1mas/yr */ + st->errpmr = st->errpmr / cosdeg (st->dec); /* to RA deg */ + st->errpmd = (double) (us4.pm_dec_sigma+128) / 36000000.0; /* 0.1mas/yr */ + st->nimage = (int) us4.n_ucac_used; + st->ncat = (int) us4.n_cats_used; + if (us4.apass_mag[0] == 20000) + st->xmag[0] = 99.990; + else + st->xmag[0] = ((double) us4.apass_mag[0]) / 1000.0; + if (us4.apass_mag[1] == 20000) + st->xmag[1] = 99.990; + else + st->xmag[1] = ((double) us4.apass_mag[1]) / 1000.0; + if (us4.apass_mag[2] == 20000) + st->xmag[2] = 99.990; + else + st->xmag[2] = ((double) us4.apass_mag[2]) / 1000.0; + if (us4.apass_mag[3] == 20000) + st->xmag[3] = 99.990; + else + st->xmag[3] = ((double) us4.apass_mag[3]) / 1000.0; + if (us4.apass_mag[4] == 20000) + st->xmag[4] = 99.990; + else + st->xmag[4] = ((double) us4.apass_mag[4]) / 1000.0; + if (us4.mag_j == 0) + st->xmag[5] = 99.990; + else + st->xmag[5] = ((double) us4.mag_j) / 1000.0; + if (us4.mag_h == 0) + st->xmag[6] = 99.990; + else + st->xmag[6] = ((double) us4.mag_h) / 1000.0; + if (us4.mag_k == 0) + st->xmag[7] = 99.990; + else + st->xmag[7] = ((double) us4.mag_k) / 1000.0; + if (us4.magm == 20000) + st->xmag[8] = 99.990; + else + st->xmag[8] = ((double) us4.magm) / 1000.0; + if (us4.maga == 20000) + st->xmag[9] = 99.990; + else + st->xmag[9] = ((double) us4.maga) / 1000.0; + + /* DASCH specific. Since we are sorting on mag[8], try using APASS B or mag[9] first */ + if (st->xmag[9] < 90.0) { + st->xmag[8] = st->xmag[9]; + } + if (st->xmag[0] < 90.0) { + st->xmag[8] = st->xmag[0]; + } + + } + else { + fprintf(stderr,"ucacread CATALOG NUMBER ERROR %d in line %d\n",ucat,__LINE__); + exit(-1); + } + + +#if 0 + if ((zone == 256) && (istar == 149200)) { + printf("At zone %d and istar %d\n",zone,istar); + } +#endif + +#ifdef UCAC_DEBUG + if (zone == 183) { + fprintf(stderr,"istar %6d, ra %.3f dec %.3f\n",istar,st->ra,st->dec); + + } +#endif /* UCAC_DEBUG */ + + return (0); +} + + +/* UCACSWAP2 -- Swap bytes in Integer*2 number in place */ + +static void +ucacswap2 (string) + + + char *string; /* Address of starting point of bytes to swap */ + +{ + char *sbyte, temp; + + sbyte = string; + temp = sbyte[0]; + sbyte[0] = sbyte[1]; + sbyte[1] = temp; + return; +} + + +/* UCACSWAP4 -- Reverse bytes of Integer*4 or Real*4 number in place */ + +static void +ucacswap4 (string) + + char *string; /* Address of Integer*4 or Real*4 vector */ + +{ + char temp0, temp1, temp2, temp3; + + temp3 = string[0]; + temp2 = string[1]; + temp1 = string[2]; + temp0 = string[3]; + string[0] = temp0; + string[1] = temp1; + string[2] = temp2; + string[3] = temp3; + + return; +} + +/* Apr 24 2003 New subroutines, based on ty2read.c and uacread.c + * May 30 2003 Add UCAC2, compute file size rather than reading it from file + * Jun 2 2003 Print proper motions as mas/year + * Aug 22 2003 Add radi argument for inner edge of search annulus + * Sep 25 2003 Add ucacbin() to fill an image with sources + * Oct 6 2003 Update ubcread() and ubcbin() for improved RefLim() + * Nov 10 2003 Fix byte-swapping test in ucacopen() found by Ed Beshore + * Nov 18 2003 Initialize image size and bits/pixel from header in ucacbin() + * Dec 1 2003 Add missing tab to n=-1 header + * Dec 12 2003 Fix bug in wcs2pix() call in ucacbin() + * + * Jan 4 2005 Fix bug in if statement on line 626 found by Dan Katz at JPL + * + * Jun 20 2006 Drop unused variables + * Sep 26 2006 Increase length of rastr and destr from 16 to 32 + * Nov 16 2006 Fix binning + * + * Jan 8 2007 Drop unused variable in ucacbin() + * Jan 10 2007 Add match=1 argument to webrnum() + * Jul 11 2007 Add magnitude byte-swap check + * + * Oct 5 2009 Add UCAC3 + * Oct 15 2009 Read extra stars in RA + * Oct 22 2009 Set UCAC3 magnitudes to 99.99 if zero + * Oct 30 2009 Add position and proper motion error to Star structure + * Nov 2 2009 Print UCAC3 errors if n = -1 + * Nov 5 2009 Return number of images and catalogs in gtype + * Nov 5 2009 Return errors in position and proper motion as magnitudes + * Nov 5 2009 Return UCAC2 and UCAC3 RA proper motion and error as RA degrees + * Dec 14 2009 Drop nmag1 from ucacread() and ucacrnum(); it wasn't being used + * + * Jan 29 2013 Add UCAC4 support see "DASCH" tag for DASCH-specific changes + * + * Jun 12 2015 Fix UCAC4 support to include BVgriJHK magnitudes correctly + * + * Jun 22 2016 Remove extra variables from format string (via Ole Streicher) + * + * Aug 3 2018 Fix bug to set up UCAC4 hpm file path if environment UCAC4_PATH used + */ diff -Nru wcstools-3.9.5/libwcs/wcs.c wcstools-3.9.6/libwcs/wcs.c --- wcstools-3.9.5/libwcs/wcs.c 2016-06-24 21:51:37.000000000 +0000 +++ wcstools-3.9.6/libwcs/wcs.c 2017-12-13 00:55:08.000000000 +0000 @@ -1,8 +1,8 @@ /*** File libwcs/wcs.c - *** June 24, 2016 + *** December 12, 2017 *** By Jessica Mink, jmink@cfa.harvard.edu *** Harvard-Smithsonian Center for Astrophysics - *** Copyright (C) 1994-2016 + *** Copyright (C) 1994-2017 *** Smithsonian Astrophysical Observatory, Cambridge, MA, USA This library is free software; you can redistribute it and/or @@ -150,6 +150,7 @@ { struct WorldCoor *wcs; double cdelt1, cdelt2; + int lproj; wcs = (struct WorldCoor *) calloc (1, sizeof(struct WorldCoor)); @@ -191,8 +192,11 @@ wcs->ptype[3] = (char) 0; strcpy (wcs->ctype[0],"RA---"); strcpy (wcs->ctype[1],"DEC--"); - strcat (wcs->ctype[0],proj); - strcat (wcs->ctype[1],proj); + lproj = strlen (proj); + if (lproj > 15) + lproj = 15; + strncat (wcs->ctype[0],proj, lproj); + strncat (wcs->ctype[1],proj, lproj); if (wcstype (wcs, wcs->ctype[0], wcs->ctype[1])) { wcsfree (wcs); @@ -346,6 +350,7 @@ int nctype = NWCSTYPE; char ctypes[NWCSTYPE][4]; char dtypes[10][4]; + int lctype1; /* Initialize projection types */ strcpy (ctypes[0], "LIN"); @@ -389,7 +394,8 @@ if (!strncmp (ctype1, "LONG",4)) strncpy (ctype1, "XLON",4); - strcpy (wcs->ctype[0], ctype1); + lctype1 = strlen (ctype1) + 1; + strncpy (wcs->ctype[0], ctype1, lctype1); /* This is only to catch special non-standard projections */ strncpy (wcs->ptype, ctype1, 3); @@ -2468,10 +2474,14 @@ void setwcsfile (filename) char *filename; /* FITS or IRAF file with WCS */ -{ if (strlen (filename) < 256) - strcpy (wcsfile, filename); - else +{ + int lfn = strlen (filename) + 1; + if (lfn < 257) + strncpy (wcsfile, filename, lfn); + else { strncpy (wcsfile, filename, 255); + wcsfile[255] = (char) 0; + } return; } /* Set error message */ @@ -3015,4 +3025,6 @@ * Jun 8 2016 Increase ctype, ctype1, and ctype2 to 16 characters for distortion * Jun 23 2016 Set initial allocation of keyword arrays to MAXNKWD instead of 100 in cpwcs() * Jun 24 2016 wcs->ptype contains only 3-letter projection code + * + * Dec 12 2017 Change strcpy() to strncpy() where destination variable shorter than origin */ diff -Nru wcstools-3.9.5/libwcs/wcsinit.c wcstools-3.9.6/libwcs/wcsinit.c --- wcstools-3.9.5/libwcs/wcsinit.c 2016-06-24 19:19:05.000000000 +0000 +++ wcstools-3.9.6/libwcs/wcsinit.c 2018-05-21 14:37:05.000000000 +0000 @@ -1,8 +1,8 @@ /*** File libwcs/wcsinit.c - *** July 24, 2016 + *** May 21, 2018 *** By Jessica Mink, jmink@cfa.harvard.edu *** Harvard-Smithsonian Center for Astrophysics - *** Copyright (C) 1998-2016 + *** Copyright (C) 1998-2018 *** Smithsonian Astrophysical Observatory, Cambridge, MA, USA This library is free software; you can redistribute it and/or @@ -416,9 +416,9 @@ /* Read third and fourth coordinate types, if present */ strcpy (wcs->ctype[2], ""); - hgetsc (hstring, "CTYPE3", &mchar, 9, wcs->ctype[2]); + hgetsc (hstring, "CTYPE3", &mchar, 16, wcs->ctype[2]); strcpy (wcs->ctype[3], ""); - hgetsc (hstring, "CTYPE4", &mchar, 9, wcs->ctype[3]); + hgetsc (hstring, "CTYPE4", &mchar, 16, wcs->ctype[3]); /* Set projection type in WCS data structure */ if (wcstype (wcs, ctype1, ctype2)) { @@ -1613,5 +1613,8 @@ * Feb 07 2013 Avoid SWARP distortion if SIRTF distortion is present * Jul 25 2013 Initialize n=0 when checking for SCAMP distortion terms (fix from Martin Kuemmel) * + * Jun 8 2016 Read up tpo 16 characters for ctype[0] and ctype[1] for SIP distortion * Jun 24 2016 wcs->ptype contains only 3-letter projection code + * + * May 21 2018 Read up to 16 characters for ctype[2] and ctype[3], too. */ diff -Nru wcstools-3.9.5/libwcs/webread.c wcstools-3.9.6/libwcs/webread.c --- wcstools-3.9.5/libwcs/webread.c 2015-02-06 23:15:46.000000000 +0000 +++ wcstools-3.9.6/libwcs/webread.c 2018-11-05 18:14:44.000000000 +0000 @@ -1,9 +1,9 @@ /*** File webread.c - *** February 6, 2015 + *** November 5, 2018 *** By Jessica Mink, jmink@cfa.harvard.edu *** Harvard-Smithsonian Center for Astrophysics - *** (http code from John Roll) - *** Copyright (C) 2000-2015 + *** (http code originally from John Roll) + *** Copyright (C) 2000-2018 *** Smithsonian Astrophysical Observatory, Cambridge, MA, USA This library is free software; you can redistribute it and/or @@ -411,7 +411,7 @@ char *srchurl; int lsrch; char *tabbuff; - int lbuff = 0; + int lbuff = 0, lbuff0 = 0; char *tabnew, *tabline, *lastline, *tempbuff, *tabold; int formfeed = (char) 12; struct TabTable *tabtable; @@ -489,10 +489,14 @@ } if (tempbuff == NULL) { tempbuff = tabbuff; + lbuff0 = strlen (tabbuff); tabbuff = space2tab (tempbuff); lbuff = strlen (tabbuff); free (tempbuff); } + else { + lbuff = strlen (tabbuff); + } } /* Allocate tab table structure */ @@ -539,7 +543,7 @@ tabline = strchr (tabline,newline) + 1; } if (*tabline != '-') { - fprintf (stderr,"WEBOPEN: No - line in tab table %s",srchurl); + fprintf (stderr,"WEBOPEN: No - line in %d tab table %s",lbuff,srchurl); tabclose (tabtable); free (srchurl); return (NULL); @@ -662,7 +666,7 @@ newpath = urlpath; /* Send HTTP GET command */ - fprintf (sok, "GET %s HTTP/1.1\r\nHost: %s\n\n", newpath, server); + fprintf (sok, "GET %s HTTP/1.1\r\nHost: %s\r\n\r\n", newpath, server); fflush (sok); free (server); if (newpath != urlpath) { @@ -715,7 +719,7 @@ newpath = urlpath; /* Send HTTP GET command (simbad forward fails if HTTP/1.1 included) */ - fprintf(sok, "GET %s HTTP/1.1\r\nHost: %s\n\n", newpath, server); + fprintf(sok, "GET %s HTTP/1.1\r\nHost: %s\r\n\r\n", newpath, server); fflush (sok); free (server); if (newpath != urlpath) { @@ -728,7 +732,7 @@ /* Skip continue lines if (status == 100) { while (status == 100) - fscanf(sok, "%*s %d %*s\n", &status); + fscanf(sok, "%*s %d %*s\r\n", &status); } */ /* If status is not 200 return without data */ @@ -1124,4 +1128,7 @@ * http://geekhideout.com/urlcode.shtml * * Feb 6 2015 Drop URL encoding because GSC2 search fails when used. + * + * Jan 19 2018 Always use "\r\n" instead of "\n" when writing to socket (from Robert Wiegand) + * Nov 5 2018 Fix bug that failed to set lbuff when tab table returned by scat */ diff -Nru wcstools-3.9.5/Makefile wcstools-3.9.6/Makefile --- wcstools-3.9.5/Makefile 2016-03-30 17:10:25.000000000 +0000 +++ wcstools-3.9.6/Makefile 2018-11-06 02:55:26.000000000 +0000 @@ -12,7 +12,7 @@ imrot imsize imstar imwcs scat sethead addpix getpix setpix sky2xy \ keyhead skycoor subpix xy2sky wcshead conpix gettab newfits getfits \ imstack imextract sumpix remap getcol getdate imfill imsmooth imresize \ - fileroot filename filext char2sp sp2char crlf isnum isrange isfits \ + fileroot filename filext char2sp sp2char crlf htmlsp isnum isrange isfits \ isfile simpos bincat addpix: addpix.c $(LIBWCS) libwcs/fitsfile.h @@ -78,6 +78,9 @@ httpget: httpget.c $(LIBWCS) libwcs/wcscat.h $(CC) $(CFLAGS) -o $(BIN)/httpget httpget.c $(LIBS) +htmlsp: htmlsp.c + $(CC) $(CFLAGS) -o $(BIN)/htmlsp htmlsp.c + i2f: i2f.c $(LIBWCS) libwcs/fitsfile.h $(CC) $(CFLAGS) -o $(BIN)/i2f i2f.c $(LIBS) diff -Nru wcstools-3.9.5/Makefile.static wcstools-3.9.6/Makefile.static --- wcstools-3.9.5/Makefile.static 1970-01-01 00:00:00.000000000 +0000 +++ wcstools-3.9.6/Makefile.static 2018-11-03 01:20:53.000000000 +0000 @@ -0,0 +1,202 @@ +CFLAGS= -g -D_FILE_OFFSET_BITS=64 -static +CC= cc +LIBWCS = libwcs/libwcs.a +LIBS = $(LIBWCS) -lm +#LIBS = $(LIBWCS) -lm -lnsl -lsocket +BIN = bin +.PRECIOUS: ${LIBWCS} ${LIBNED} +.c.o: + $(CC) -c $(CFLAGS) $(DEFS) $< + +all: cphead delwcs delhead edhead fixpix gethead i2f imcat imhead immatch \ + imrot imsize imstar imwcs scat sethead addpix getpix setpix sky2xy \ + keyhead skycoor subpix xy2sky wcshead conpix gettab newfits getfits \ + imstack imextract sumpix remap getcol getdate imfill imsmooth imresize \ + fileroot filename filext char2sp sp2char crlf isnum isrange isfits \ + isfile simpos bincat + +addpix: addpix.c $(LIBWCS) libwcs/fitsfile.h + $(CC) $(CFLAGS) -o $(BIN)/addpix addpix.c $(LIBS) + +bincat: bincat.c $(LIBWCS) libwcs/fitsfile.h libwcs/wcs.h + $(CC) $(CFLAGS) -o $(BIN)/bincat bincat.c $(LIBS) + +char2sp: char2sp.c $(LIBWCS) libwcs/fitsfile.h + $(CC) $(CFLAGS) -o $(BIN)/char2sp char2sp.c $(LIBWCS) + +conpix: conpix.c $(LIBWCS) libwcs/fitsfile.h + $(CC) $(CFLAGS) -o $(BIN)/conpix conpix.c $(LIBS) + +cphead: cphead.c $(LIBWCS) libwcs/fitsfile.h + $(CC) $(CFLAGS) -o $(BIN)/cphead cphead.c $(LIBS) + +crlf: crlf.c + $(CC) $(CFLAGS) -o $(BIN)/crlf crlf.c + +delwcs: delwcs.c $(LIBWCS) libwcs/fitsfile.h + $(CC) $(CFLAGS) -o $(BIN)/delwcs delwcs.c $(LIBS) + +delhead: delhead.c $(LIBWCS) libwcs/fitsfile.h + $(CC) $(CFLAGS) -o $(BIN)/delhead delhead.c $(LIBS) + +edhead: edhead.c $(LIBWCS) libwcs/fitsfile.h + $(CC) $(CFLAGS) -o $(BIN)/edhead edhead.c $(LIBS) + +filename: filename.c + $(CC) $(CFLAGS) -o $(BIN)/filename filename.c + +filedir: filedir.c + $(CC) $(CFLAGS) -o $(BIN)/filedir filedir.c + +fileroot: fileroot.c + $(CC) $(CFLAGS) -o $(BIN)/fileroot fileroot.c + +filext: filext.c + $(CC) $(CFLAGS) -o $(BIN)/filext filext.c + +fixpix: fixpix.c $(LIBWCS) libwcs/fitsfile.h + $(CC) $(CFLAGS) -o $(BIN)/fixpix fixpix.c $(LIBS) + +getcol: getcol.c $(LIBWCS) libwcs/wcscat.h + $(CC) $(CFLAGS) -o $(BIN)/getcol getcol.c $(LIBS) + +getdate: getdate.c $(LIBWCS) libwcs/wcscat.h + $(CC) $(CFLAGS) -o $(BIN)/getdate getdate.c $(LIBS) + +gethead: gethead.c $(LIBWCS) libwcs/wcs.h libwcs/fitsfile.h libwcs/wcscat.h + $(CC) $(CFLAGS) -o $(BIN)/gethead gethead.c $(LIBS) + +getfits: getfits.c $(LIBWCS) libwcs/fitsfile.h libwcs/wcs.h libwcs/wcscat.h + $(CC) $(CFLAGS) -o $(BIN)/getfits getfits.c $(LIBS) + +getpix: getpix.c $(LIBWCS) libwcs/wcs.h libwcs/fitsfile.h libwcs/wcscat.h + $(CC) $(CFLAGS) -o $(BIN)/getpix getpix.c $(LIBS) + +gettab: gettab.c $(LIBWCS) libwcs/wcscat.h + $(CC) $(CFLAGS) -o $(BIN)/gettab gettab.c $(LIBS) + +httpget: httpget.c $(LIBWCS) libwcs/wcscat.h + $(CC) $(CFLAGS) -o $(BIN)/httpget httpget.c $(LIBS) + +i2f: i2f.c $(LIBWCS) libwcs/fitsfile.h + $(CC) $(CFLAGS) -o $(BIN)/i2f i2f.c $(LIBS) + +imcat: imcat.c $(LIBWCS) libwcs/fitsfile.h libwcs/wcs.h + $(CC) $(CFLAGS) -o $(BIN)/imcat imcat.c $(LIBS) + +imfill: imfill.c $(LIBWCS) libwcs/fitsfile.h + $(CC) $(CFLAGS) -o $(BIN)/imfill imfill.c $(LIBS) + +imresize: imresize.c $(LIBWCS) libwcs/fitsfile.h + $(CC) $(CFLAGS) -o $(BIN)/imresize imresize.c $(LIBS) + +imsmooth: imsmooth.c $(LIBWCS) libwcs/fitsfile.h + $(CC) $(CFLAGS) -o $(BIN)/imsmooth imsmooth.c $(LIBS) + +imhead: imhead.c $(LIBWCS) libwcs/fitsfile.h libwcs/wcs.h + $(CC) $(CFLAGS) -o $(BIN)/imhead imhead.c $(LIBS) + +imrot: imrot.c $(LIBWCS) libwcs/fitsfile.h + $(CC) $(CFLAGS) -o $(BIN)/imrot imrot.c $(LIBS) + +imsize: imsize.c $(LIBWCS) libwcs/fitsfile.h libwcs/wcs.h + $(CC) $(CFLAGS) -o $(BIN)/imsize imsize.c $(LIBS) + +imstack: imstack.c $(LIBWCS) libwcs/fitsfile.h + $(CC) $(CFLAGS) -o $(BIN)/imstack imstack.c $(LIBS) + +imextract: imextract.c $(LIBWCS) libwcs/fitsfile.h libwcs/wcscat.h + $(CC) $(CFLAGS) -o $(BIN)/imextract imextract.c $(LIBS) + +imstar: imstar.c $(LIBWCS) libwcs/fitsfile.h libwcs/wcs.h libwcs/lwcs.h libwcs/wcscat.h + $(CC) $(CFLAGS) -o $(BIN)/imstar imstar.c $(LIBS) + +isfile: isfile.c $(LIBWCS) libwcs/fitshead.h + $(CC) $(CFLAGS) -o $(BIN)/isfile isfile.c $(LIBS) + +isfits: isfits.c $(LIBWCS) libwcs/fitshead.h + $(CC) $(CFLAGS) -o $(BIN)/isfits isfits.c $(LIBS) + +isnum: isnum.c $(LIBWCS) libwcs/fitshead.h + $(CC) $(CFLAGS) -o $(BIN)/isnum isnum.c $(LIBS) + +isimlist: isimlist.c $(LIBWCS) libwcs/fitsfile.h + $(CC) $(CFLAGS) -o $(BIN)/isimlist isimlist.c $(LIBS) + +isrange: isrange.c + $(CC) $(CFLAGS) -o $(BIN)/isrange isrange.c + +imwcs: imwcs.c $(LIBWCS) libwcs/fitsfile.h libwcs/lwcs.h + $(CC) $(CFLAGS) -o $(BIN)/imwcs imwcs.c $(LIBS) + +immatch: immatch.c $(LIBWCS) libwcs/fitsfile.h libwcs/lwcs.h + $(CC) $(CFLAGS) -o $(BIN)/immatch immatch.c $(LIBS) + +immwcs: immwcs.c $(LIBWCS) libwcs/fitsfile.h libwcs/lwcs.h + $(CC) $(CFLAGS) -o $(BIN)/immwcs immwcs.c $(LIBS) + +keyhead: keyhead.c $(LIBWCS) libwcs/fitsfile.h libwcs/wcs.h + $(CC) $(CFLAGS) -o $(BIN)/keyhead keyhead.c $(LIBS) + +matchcat: matchcat.c $(LIBWCS) libwcs/wcscat.h libwcs/wcs.h + $(CC) $(CFLAGS) -o $(BIN)/matchcat matchcat.c $(LIBS) + +newfits: newfits.c $(LIBWCS) libwcs/fitshead.h libwcs/wcs.h + $(CC) $(CFLAGS) -o $(BIN)/newfits newfits.c $(LIBS) + +remap: remap.c $(LIBWCS) libwcs/fitsfile.h libwcs/wcs.h + $(CC) $(CFLAGS) -o $(BIN)/remap remap.c $(LIBS) + +scat: scat.c $(LIBWCS) libwcs/wcscat.h libwcs/wcs.h + $(CC) $(CFLAGS) -o $(BIN)/scat scat.c $(LIBS) + +sethead: sethead.c $(LIBWCS) libwcs/fitsfile.h libwcs/wcs.h + $(CC) $(CFLAGS) -o $(BIN)/sethead sethead.c $(LIBS) + +setpix: setpix.c $(LIBWCS) libwcs/fitsfile.h libwcs/wcscat.h + $(CC) $(CFLAGS) -o $(BIN)/setpix setpix.c $(LIBS) + +sky2xy: sky2xy.c $(LIBWCS) libwcs/wcs.h libwcs/fitsfile.h + $(CC) $(CFLAGS) -o $(BIN)/sky2xy sky2xy.c $(LIBS) + +skycoor: skycoor.c $(LIBWCS) libwcs/wcs.h libwcs/wcscat.h + $(CC) $(CFLAGS) -o $(BIN)/skycoor skycoor.c $(LIBS) + +sp2char: sp2char.c $(LIBWCS) libwcs/fitsfile.h + $(CC) $(CFLAGS) -o $(BIN)/sp2char sp2char.c $(LIBWCS) + +subpix: subpix.c $(LIBWCS) libwcs/fitsfile.h + $(CC) $(CFLAGS) -o $(BIN)/subpix subpix.c $(LIBS) + +sumpix: sumpix.c $(LIBWCS) libwcs/fitsfile.h libwcs/wcscat.h + $(CC) $(CFLAGS) -o $(BIN)/sumpix sumpix.c $(LIBS) + +wcshead: wcshead.c $(LIBWCS) libwcs/fitsfile.h + $(CC) $(CFLAGS) -o $(BIN)/wcshead wcshead.c $(LIBS) + +xy2sky: xy2sky.c $(LIBWCS) libwcs/wcs.h libwcs/wcscat.h + $(CC) $(CFLAGS) -o $(BIN)/xy2sky xy2sky.c $(LIBS) + +simpos: simpos.c libwcs/libwcs.a + $(CC) $(CFLAGS) -o $(BIN)/simpos simpos.c $(LIBS) + +gsc2cat: gsc2cat.c $(LIBWCS) + $(CC) $(CFLAGS) -o $(BIN)/gsc2cat gsc2cat.c $(LIBS) + +tmcat: tmcat.c + $(CC) $(CFLAGS) -o $(BIN)/tmcat tmcat.c + +tmcate: tmcate.c + $(CC) $(CFLAGS) -o $(BIN)/tmcate tmcate.c + +$(LIBWCS): libwcs/*.c libwcs/*.h + cd libwcs; make + +objclean: + cd libwcs; make clean + +binclean: + rm -f ./bin/* + +clean: + make objclean; make binclean diff -Nru wcstools-3.9.5/man/man1/getpix.1 wcstools-3.9.6/man/man1/getpix.1 --- wcstools-3.9.5/man/man1/getpix.1 1970-01-01 00:00:00.000000000 +0000 +++ wcstools-3.9.6/man/man1/getpix.1 2020-05-14 18:50:41.000000000 +0000 @@ -0,0 +1,74 @@ +.TH getpix 1 WCSTools "14 May 2020" +.SH Name +getpix \-Display FITS or IRAF image values +.SH Synopsis +setpix [\-vn] file.fts [x_range y_range value] [@valuefile] +getpix [\-vp][\-n num][\-g val][\-l val] file.fits x_range y_range +getpix [\-vp][\-n num][\-g val][\-l val] file.fits x1 y1 x2 y2 ... xn yn +getpix [\-vp][\-n num][\-g val][-\l val] file.fits @file +.SH Description +Display the values of list of specified pixels or ranges of pixels in a FITS or +IRAF 2-D image. Pixel values from a file of x y pairs may be displayed +.SH Options +.TP +.B filename +Name of IRAF image header file or FITS file. This must be present. +.TP +.B @coordfile +File with x y coordinates as first two tokens on lines +.TP +.B xrange yrange +Image coordinate x and y ranges as x1-x2 y1-y2 or lists of x and y +coordinates, where x is the horizontal and y is along the vertical axis +starting at 1,1 in the lower left corner of the image. If either range is "0", +all of the coordinate values along that axis are displayed. +.TP +.B \-d number +Set the number of decimal places in displayed pixel values +.TP +.B \-e pixel value range +Print range of pixel values in specified image region +.TP +.B \-f name +Write specified region to a FITS file +.TP +.B \-g num +Keep pixels with values greater than this +.TP +.B \-h +Print file name on line above pixel values +.TP +.B \-i +Ignore first token per line of coordinate file +.TP +.B \-l num +Keep pixels with values less than this +.TP +.B \-m +Print mean of pixel values in specified image region +.TP +.B \-n num +Number of pixel values printed per line +.TP +.B \-o format: Output format in C style without leading % +.TP +.B \-p +Label pixel rows and columns +.TP +.B \-r num +Radius (<0=box) to extract in degrees/arcsec +.TP +.B \-s +Print x y value with no punctuation +.TP +.B \-t +Separate columns in table with tabs instead of spaces +.TP +.B \-v +Verbose header with more about the image and label pixel coordinates from input list +.TP +.B \-y +Display x as rows (vertically) and y as columns (horizontally) + +.SH Author +Jessica Mink, SAO (jmink@cfa.harvard.edu) Binary files /tmp/tmpAU7Qas/lxsO8C14BK/wcstools-3.9.5/man/man1/.nfs00000000b2cb4ec3000306f8 and /tmp/tmpAU7Qas/kkdBNQZs62/wcstools-3.9.6/man/man1/.nfs00000000b2cb4ec3000306f8 differ diff -Nru wcstools-3.9.5/matchcat.c wcstools-3.9.6/matchcat.c --- wcstools-3.9.5/matchcat.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/matchcat.c 2020-05-14 18:03:54.000000000 +0000 @@ -36,7 +36,7 @@ int version = 0; /* If 1, print only program name and version */ static void usage(); -static char *RevMsg = "MATCHCAT WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "MATCHCAT WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; main (ac, av) int ac; diff -Nru wcstools-3.9.5/newfits.c wcstools-3.9.6/newfits.c --- wcstools-3.9.5/newfits.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/newfits.c 2020-05-14 18:03:54.000000000 +0000 @@ -47,7 +47,7 @@ extern void setproj(); extern struct WorldCoor *GetFITSWCS(); -static char *RevMsg = "NEWFITS WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "NEWFITS WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static int verbose = 0; /* verbose/debugging flag */ static int bitpix = 0; /* number of bits per pixel (FITS code, 0=no image) */ static int version = 0; /* If 1, print only program name and version */ diff -Nru wcstools-3.9.5/NEWS wcstools-3.9.6/NEWS --- wcstools-3.9.5/NEWS 2017-04-13 15:54:59.000000000 +0000 +++ wcstools-3.9.6/NEWS 2020-05-12 21:39:53.000000000 +0000 @@ -1,5 +1,14 @@ WCSTools Package updates +Version 3.9.6 (May 12, 2020) +getcol: Fix bug so stats on floating point numbers are computed (2019-07-25) +getfits: Fix command line parsing so ranges work (2018-07-26) +getpix: Fix a variety of bugs; add -d option for decimal places; add -y +option to print columns as lines (2020-05-12) +webread.c: Always use "\r\n" instead of \n" when writing to or reading from socket (2018-01-19) +ucacread.c: Correct bug to read UCAC 4 high proper motion stars correctly using local path (2018-08-03) +gsc2read.c: Read GSC2 ID as extra tab-separated-table keyword (2018-08-07) + Version 3.9.5 (March 30, 2017) sethead: Fix bug so that coordinates with : and dates with - are strings getcol: Set default maximum number of lines to process from 100000 to 500000 diff -Nru wcstools-3.9.5/Readme wcstools-3.9.6/Readme --- wcstools-3.9.5/Readme 2017-04-13 13:42:07.000000000 +0000 +++ wcstools-3.9.6/Readme 2020-05-12 21:40:36.000000000 +0000 @@ -1,4 +1,4 @@ -WCSTools 3.9.5 +WCSTools 3.9.6 WCSTools is a set of software utilities, written in C, which create, display and manipulate the world coordinate system of a FITS or IRAF @@ -10,11 +10,7 @@ make all -in the main directory or, on Solaris machines - -make -f Makefile.solaris - -This is version 3.9.5 of the WCSTools package developed by Jessica Mink +This is version 3.9.6 of the WCSTools package developed by Jessica Mink (jmink@cfa.harvard.edu) at the Smithsonian Astrophysical Observatory, with significant code or algorithms from @@ -39,47 +35,16 @@ The update history is in the NEWS file, but here is what is new: -Version 3.9.5 (March 30, 2017) -sethead: Fix bug so that coordinates with : and dates with - are strings -getcol: Set default maximum number of lines to process from 100000 to 500000 -ty2read: Add fifth digit to star numbers because 256 are over 9999 - -Version 3.9.4 (August 2, 2016) (after Ole Streicher) -getdate: Fix input list so it works correctly (2016-08-02 for Armin Rest) -imstar: Append to output line rather than overwriting it -bincatc: Fix mis-reading of coordinates from command line -cphead: Increase number of keywords to handle distortion polynomials -filext: If no file extension, print null string, avoiding seg fault -getfits: Decrement argument counter after reading center RA -imcat: Fix typo in UCAC output format -imstar: Fix sprintf of headline -findstar.c: Fix but in trim section parsing -fitsfile.c: Add one to header string length for trailing NULL -wcs.c: Clean up use of ptype so it is always 3 characters long -sortstar.c: Initialize haspm flag if zero -Update all man pages - -Version 3.9.3 (June 23, 2016) -wcs.h, wcs.c: Increase ctype string length to 15 (+null=16) for distortion -wcslib.h, wcslib.c: Increase ctype string length to 15 (+null=16) for distortion -scat.c, ucacread.c: Typos in code fixed -matchstar.c, hget.c, fitsfile.c: Fix isnum() tests for added coloned times and dashed date - -Version 3.9.2 (December 10, 2015) -isnum: Add return of 4 for yyyy-mm-dd dates (2015-11-06) -isnum: Add -n option to output number without linefeed -imcat, imstar: Print two decimal places on PROS region file coordinates -remap: Declare GetFITSWCS() -simpos: Switch to CfA Vizier server as default (2015-05-05) -simpos: Use NED name resolver if called as nedpos or using -n argument -simpos: Look up in VIZIER catalogs if called as vizpos or using -z argument -simpos: Use CDS server if called as cdspos or using -c argument -sky2xy: Add xy option to -o to print only computed x and y coordinates -nedpos,nedname: Drop tasks because IPAC has dropped interface; use simpos -n -getdate: Fix bug with FITS date conversion (2015-08-24) -filedir: Add option to read file pathnames from stdin -catutil.c: Add tab as an assignment character in agets() -hget.c: Add return of 4 for yyyy-mm-dd dates to isnum() (2015-11-06) +Version 3.9.6 (May 12, 2020) +getcol: Fix bug so stats on floating point numbers are computed (2019-07-25) +getfits: Fix command line parsing so ranges work (2018-07-26) +getpix: Fix a variety of bugs; add -d option for decimal places; add -y +option to print columns as lines (2020-05-12) +webread.c: Always use "\r\n" instead of \n" when writing to or reading +from socket (2018-01-19) +ucacread.c: Correct bug to read UCAC 4 high proper motion stars +correctly using local path (2018-08-03) +gsc2read.c: Read GSC2 ID as extra tab-separated-table keyword (2018-08-07) Documentation, with examples and installation directions, is on the World Wide Web at @@ -197,5 +162,5 @@ xy2sky Print sky coordinates for given image pixel coordinates on the command line or in a list file. --Jessica Mink, SAO, 2017-04-13 +-Jessica Mink, SAO, 2020-05-12 http://tdc-www.harvard.edu/mink/ diff -Nru wcstools-3.9.5/remap.c wcstools-3.9.6/remap.c --- wcstools-3.9.5/remap.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/remap.c 2020-05-14 18:03:54.000000000 +0000 @@ -49,7 +49,7 @@ static char *outname; static char *wcsproj; /* WCS projection name */ -static char *RevMsg = "REMAP WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "REMAP WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static int nfiles = 0; static int fitsout = 1; static double secpix = 0; diff -Nru wcstools-3.9.5/revup.sed wcstools-3.9.6/revup.sed --- wcstools-3.9.5/revup.sed 2017-03-30 15:21:42.000000000 +0000 +++ wcstools-3.9.6/revup.sed 2020-05-14 18:03:46.000000000 +0000 @@ -1 +1 @@ -1,$s/3\.9\.5, 22 March 2017/3\.9\.5, 30 March 2017/ +1,$s/3\.9\.6, 12 May 2020/3\.9\.6, 14 May 2020/ diff -Nru wcstools-3.9.5/scat.c wcstools-3.9.6/scat.c --- wcstools-3.9.5/scat.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/scat.c 2020-05-14 18:03:54.000000000 +0000 @@ -33,7 +33,7 @@ #include "libwcs/fitsfile.h" #include "libwcs/wcscat.h" -static char *RevMsg = "SCAT WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "SCAT WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static void PrintUsage(); static int scatparm(); diff -Nru wcstools-3.9.5/sethead.c wcstools-3.9.6/sethead.c --- wcstools-3.9.5/sethead.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/sethead.c 2020-05-14 18:03:54.000000000 +0000 @@ -66,7 +66,7 @@ static int errflag = 0; /* Error return from program */ static char *rootdir=NULL; /* Root directory for input files */ -static char *RevMsg = "SETHEAD WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "SETHEAD WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; int main (ac, av) diff -Nru wcstools-3.9.5/setpix.c wcstools-3.9.6/setpix.c --- wcstools-3.9.5/setpix.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/setpix.c 2020-05-14 18:03:54.000000000 +0000 @@ -48,7 +48,7 @@ static int logrange = 1; /* Log pixel change in image header */ static char *pform = NULL; /* Format in which to print pixels */ -static char *RevMsg = "SETPIX WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "SETPIX WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; int main (ac, av) diff -Nru wcstools-3.9.5/simpos.c wcstools-3.9.6/simpos.c --- wcstools-3.9.5/simpos.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/simpos.c 2020-05-14 18:03:54.000000000 +0000 @@ -14,7 +14,7 @@ static char searchorder[4]; static int printall = 0; static void PrintUsage(); -static char *RevMsg = "SIMPOS 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "SIMPOS 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; int main (ac, av) diff -Nru wcstools-3.9.5/simposx.c wcstools-3.9.6/simposx.c --- wcstools-3.9.5/simposx.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/simposx.c 2020-05-14 18:03:54.000000000 +0000 @@ -12,7 +12,7 @@ extern int ned_errno; static void PrintUsage(); -static char *RevMsg = "SIMPOS 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "SIMPOS 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; int main (ac, av) diff -Nru wcstools-3.9.5/sky2xy.c wcstools-3.9.6/sky2xy.c --- wcstools-3.9.5/sky2xy.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/sky2xy.c 2020-05-14 18:03:54.000000000 +0000 @@ -36,7 +36,7 @@ extern struct WorldCoor *GetFITSWCS (); /* Read WCS from FITS or IRAF header */ static int version = 0; /* If 1, print only program name and version */ -static char *RevMsg = "SKY2XY WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "SKY2XY WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; int main (ac, av) diff -Nru wcstools-3.9.5/skycoor.c wcstools-3.9.6/skycoor.c --- wcstools-3.9.5/skycoor.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/skycoor.c 2020-05-14 18:03:54.000000000 +0000 @@ -1,9 +1,9 @@ /* File skycoor.c - * August 17, 2011 + * September 27, 2019 * By Jessica Mink, Harvard-Smithsonian Center for Astrophysics * Send bug reports to jmink@cfa.harvard.edu - Copyright (C) 1996-2011 + Copyright (C) 1996-2019 Smithsonian Astrophysical Observatory, Cambridge, MA USA This program is free software; you can redistribute it and/or @@ -51,7 +51,7 @@ static int epset = 0; static int inhours = 0; -static char *RevMsg = "SKYCOOR WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "SKYCOOR WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; int main (ac, av) @@ -74,7 +74,7 @@ char *ic; int sys0; int sys1 = -1; - double ra, dec, r, ra1, dec1, ra2, dec2, dra, ddec, a; + double ra, dec, r, ra1, dec1, ra2, dec2, dra, ddec, mra, mdec, a; double offra = 0.0; double offdec = 0.0; double t1, t2, tdiff; @@ -200,6 +200,63 @@ sys1 = WCS_J2000; break; + case 'k': /* RA and Dec angular separation between two RA Dec pairs */ + if (ac < 5) + usage("Missing coordinates for -k"); + ra = str2ra (*++av); + ac--; + dec = str2dec (*++av); + ac--; + ra1 = str2ra (*++av); + ac--; + dec1 = str2dec (*++av); + ac--; + ra2str (rastr0, lstr, ra, 3); + dec2str (decstr0, lstr, dec, 2); + if (verbose) { + fprintf (stderr,"%s\n",RevMsg); + printf ("ra1, dec1: %s %s\n", rastr0, decstr0); + } + ra2str (rastr0, lstr, ra1, 3); + dec2str (decstr0, lstr, dec1, 2); + if (verbose) + printf ("ra2, dec2: %s %s\n", rastr0, decstr0); + mdec = 0.5 * (dec + dec1); + dra = wcsdist (ra, mdec, ra1, mdec); + mra = 0.5 * (ra + ra1); + ddec = wcsdist (mra, dec, mra, dec1); + if (degout) { + if (verbose) { + printf ("dRA = %.5f deg, dDec = %.5f deg\n", + dra, ddec); + } + else if (ndecset) { + sprintf (sform,"%%.%df ", ndec); + printf (sform, dra); + sprintf (sform,"%%.%df\n", ndec); + printf (sform, ddec); + } + else + printf ("%.7f %.7f\n", dra, ddec); + } + else { + dra = dra * 3600.0; + ddec = ddec * 3600.0; + if (verbose) { + printf ("dRA = %.5f arcsec, dDec = %.5f arcsec\n", + dra, ddec); + } + else if (ndecset) { + sprintf (sform,"%%.%df ", ndec); + printf (sform, dra); + sprintf (sform,"%%.%df\n", ndec); + printf (sform, ddec); + } + else + printf ("%.3f %.3f\n", dra, ddec); + } + break; + case 'n': /* Number of decimal places in output */ if (ac < 2) usage("Missing number of decimal places for -n"); @@ -713,6 +770,7 @@ fprintf (stderr," -h: Input RA in fractional hours instead of degrees\n"); fprintf (stderr," -i code: Input units (r=radians, d=degrees, ...\n"); fprintf (stderr," -j: J2000 (FK5) output\n"); + fprintf (stderr," -k ra dec ra dec: Return separate RA and DEC angular differences\n"); fprintf (stderr," -n num: Number of decimal places in output RA seconds\n"); fprintf (stderr," -o num1[,num2] : Add arcseconds to position (both same if 1 arg)\n"); fprintf (stderr," -p rapm decpm: RA and Dec proper motion in milliarcseconds/year\n"); @@ -789,4 +847,6 @@ * * Apr 19 2011 Take care of comma in coordinate input * Aug 17 2011 Allow 99 in input list file for longitudes and RA + * + * Sep 27 2011 Add -k to return separate RA and DEC differences */ diff -Nru wcstools-3.9.5/sp2char.c wcstools-3.9.6/sp2char.c --- wcstools-3.9.5/sp2char.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/sp2char.c 2020-05-14 18:03:55.000000000 +0000 @@ -40,7 +40,7 @@ static int version = 0; /* If 1, print only program name and version */ static char spchar = '_'; -static char *RevMsg = "SP2CHAR WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "SP2CHAR WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; int main (ac, av) diff -Nru wcstools-3.9.5/subpix.c wcstools-3.9.6/subpix.c --- wcstools-3.9.5/subpix.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/subpix.c 2020-05-14 18:03:55.000000000 +0000 @@ -38,7 +38,7 @@ static int verbose = 0; /* verbose flag */ static int version = 0; /* If 1, print only program name and version */ -static char *RevMsg = "SUBPIX WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "SUBPIX WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; int main (ac, av) diff -Nru wcstools-3.9.5/sumpix.c wcstools-3.9.6/sumpix.c --- wcstools-3.9.5/sumpix.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/sumpix.c 2020-05-14 18:03:55.000000000 +0000 @@ -39,7 +39,7 @@ static void SumPix(); extern double PhotPix(); -static char *RevMsg = "SUMPIX WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "SUMPIX WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; static int verbose = 0; /* verbose/debugging flag */ static int version = 0; /* If 1, print only program name and version */ diff -Nru wcstools-3.9.5/temp wcstools-3.9.6/temp --- wcstools-3.9.5/temp 1970-01-01 00:00:00.000000000 +0000 +++ wcstools-3.9.6/temp 2020-05-14 16:47:50.000000000 +0000 @@ -0,0 +1,31 @@ + + /* Make list of x coordinates */ + crange = RangeInit (yrange, xdim); + ny = rgetn (crange); + yi = (int *) calloc (ny, sizeof (int)); + for (i = 0; i < ny; i++) { + yi[i] = rgeti4 (crange); + } + + /* Label vertical pixels */ + if (pixlabel) { + + /* Format for row pixel labels */ + x = ix[nx-1]; + sprintf (testval, "%d", x); + ndig = strlen (testval); + sprintf (rform, "%%%dd:", ndig); + + /* Format for column pixel labels */ + printf ("Coord"); + sprintf (testval, pform, 1.12345678); + ndig = strlen (testval); + y = iy[ny-1]; + sprintf (testval, "%d", y); + ndig = ndig + strlen (testval) + 1; + if (printtab) { + sprintf (cform, "%%%dd", ndig); + } + else{ + sprintf (cform, "%%%dd", ndig); + } diff -Nru wcstools-3.9.5/temp1.html wcstools-3.9.6/temp1.html --- wcstools-3.9.5/temp1.html 1970-01-01 00:00:00.000000000 +0000 +++ wcstools-3.9.6/temp1.html 2018-11-06 02:00:52.000000000 +0000 @@ -0,0 +1,8 @@ + +SDSS Query Results + +

Your SQL command was:
select top 300 p.objid, p.ra, p.dec, p.u, p.g, p.r, p.i, p.z
+from star p, dbo.fgetNearByObjEq(150,20,5) n
+where p.objid=n.objid and (p.g BETWEEN 0 AND 25)
+

Your query output (max 500,000 rows):

+
objidradecugriz
1237667536933486968149.96642605419320.056251644430322.4260324.9085724.190524.5558122.69641
1237667536933487753149.9614650012220.055440414092125.8383623.880423.1722122.3471122.00612
1237667536933486881149.95261245900920.044095448416625.2240121.7728420.4771919.2192718.55294
1237667536933486882149.95244595149520.042471500526624.5123223.0123421.5386920.0700719.29092
1237667536933487364149.96727617707520.049482103079425.8824424.6494522.5370621.870421.80008
1237667536933487359149.96720220775920.044655564043423.3055522.9408222.1323622.1209722.37773
1237667536933487332149.95911516897920.040366682649826.0284223.5137525.4055725.143523.52424
1237667536933487365149.9667528662320.049914281637723.1731922.3518122.2238322.3008821.91514
1237667540679786659149.94776037599420.026157012552320.5666219.2153518.5999118.3481818.21479
1237667540679852150149.96243035588120.028918841188120.0199519.0683218.7903818.6680418.62234
1237667540679853361149.96938481499320.029735226362724.4801823.3987823.5132422.3997921.64503
1237667540679852992149.96164471196320.01713213620824.4646824.6434123.1483723.3712822.6344
1237667540679852578149.96883062740920.024835783496224.9079222.9751422.1523322.0860421.11423
1237667536933487330149.96037282313420.034718624479424.1256622.9678122.1090721.6305121.61654
1237667536933486877149.95474524264620.033259169870524.7799921.3211219.960618.8546418.21878
1237667540679786535149.92699675923919.971507364030716.0220814.8069514.3904814.2259214.17986
1237667540679786536149.92858781796719.973879637031624.2831923.2812122.2447120.8787720.10825
1237667540679786539149.92455307457319.973382387114723.7687923.2694424.7463823.2361522.87075
1237667540679786551149.92394026190220.011846697836623.8713724.8083824.8020224.361820.64042
1237667540679786556149.92827685128120.01096393451522.9642222.2570121.8824822.3965521.62824
1237667540679786545149.92214572891820.009200650053915.9737111.8533710.7198910.405812.7499
1237667540679786557149.9281538290920.010350023170322.009722.3995223.2078922.1527621.37527
1237667540679786567149.92508401822720.01027940091622.936124.9859324.8020224.361821.31667
1237667540679786640149.91608627145819.995635421880320.7563719.8484919.5864819.5050919.45461
1237667540679786558149.92283273616420.001626820544124.1997624.7527122.5745521.4866321.10661
1237667540679787202149.9285901273719.988510262208724.4119323.9815723.0653522.9338521.70112
1237667540679787200149.92794928928919.990097926996324.3109422.7774821.1280619.5309418.56912
1237667540679787201149.9286325275219.991193011959223.9903124.5830624.1295322.5530121.65226
1237667540679787678149.92145907540919.987665986608524.4039823.9172723.5741322.4250821.63087
1237667540679852289149.97170654467519.979594379721423.930221.913420.5070319.5395419.00142
1237667540679787532149.9436794716919.975259671043225.7083323.4245821.8596320.6171119.85274
1237667540679787550149.95671871067819.985255413057323.2803823.5137423.0235322.939921.8307
1237667540679786878149.95796738853219.991053088549522.8574221.6526121.3113521.2013721.36971
1237667540679786892149.9681615886919.97968836897622.3731324.7856624.2085224.4830923.30006
1237667540679852292149.9688007529819.986290277473123.5028320.5778219.4510318.9617218.71946
1237667540679786886149.960591177320.00360792373221.5622420.6241120.2392520.1012820.13819
1237667540679786857149.93499815275120.00199569216522.6276624.7298525.0121825.1854522.59937
1237667540679787536149.93614356172220.010814074383823.1868123.3572722.9684123.2005222.32876
1237667540679786713149.94360809613720.005201833980222.2785220.1122818.9412618.4780918.19592
1237667540679787552149.95218598663920.006820406529324.5471224.151822.2051521.9380521.82258
1237667540679787528149.93774339262819.99411463612623.475323.4454521.8180320.7465120.05929
1237667540679787236149.96593160384219.94308305913424.3669724.2239824.7354122.371622.25604
1237667540679787691149.96004142802419.92977638605725.3224824.3797323.9696622.5700722.29247
1237667540679787266149.98369733859219.924318150853424.1988421.6808920.2061719.1708118.59343
1237667540679852152149.99068318202319.933654281718920.8205219.6418819.1808218.924418.7516
1237667540679852419149.98377220249819.941093796054625.1887324.8900824.9373622.2812822.48594
1237667540679852420149.98274144129819.940818404378124.3326724.6768924.6863322.6503722.63358
1237667540679786598149.96999873656819.944837220732424.9309223.2456224.3732824.4915422.56615
1237667540679786597149.97331052671419.944355283148624.367424.1857923.2319122.2747621.50764
1237667540679787554149.97094771076219.939910192742824.2601223.5414722.0313321.5975421.53224
1237667540679786596149.97125018728519.944632906900519.0730218.1491917.7951117.6647417.60424
1237667540679786884149.97638083062419.937570325492222.0116921.2808921.0419920.89320.96118
1237667540679787557149.96670541700619.965497258944123.893524.1976423.152322.6853421.59781
1237667540679787244149.9666866145419.949342212037223.0375922.7143721.9784921.9149621.9044
1237667540679787523149.94645288124119.954287497209725.4341524.7108923.0367823.1953121.76982
1237667540679787688149.94783287373319.965011865422324.2085623.5998123.5172722.5799922.61911
1237667540679787692149.95910350724619.941270221823425.7385224.5516724.9722522.446222.79988
1237667540679787526149.95044088165219.945492952678523.7407323.6115322.9130422.7554621.49961
1237667540679787520149.94894903446719.936712298547925.1496123.3032622.8683923.3497522.28565
1237667540679786856149.94822830459419.947380771683521.6904120.6379820.2541920.0924720.03105
1237667540679786867149.9617171436419.954537374609921.7689520.9268720.6472120.5140120.64172
1237667540679787735149.95747073355319.94836467944925.4823124.6080625.0009324.9621721.25213
1237667540679786849149.93356802368719.966775322470922.6365824.323924.6382524.6623222.89179
1237667540679786538149.92961487306219.969175671837824.586224.5183923.5272422.5226622.9873
1237667540679787206149.94092158991619.949268195110724.3435624.0089223.2326522.7021521.93315
1237667540679787204149.93943395781619.9486388209625.4692822.8656521.2605820.0718419.36119
1237667540679787753149.93665291161519.953473716740425.4471823.7298923.9593123.4255723.23993
1237667540679786542149.93390437119.94695388250318.0933216.2712615.583715.3138415.19024
1237667540679786643149.9311267058219.956413832659320.9342119.2061418.4844518.1946718.07238
1237667536933486796149.97514380698620.048827567863221.8208218.9069617.3916516.2380115.62426
1237667536933486799149.98309229753220.041879145522223.8761919.6157817.9201815.5605614.19144
1237667536933487376149.97097411978720.045018443556625.5503323.5409721.8580920.7617420.03244
1237667536933487403149.97521296608220.07076391126523.7975623.197822.62522.383722.37665
1237667536933487406149.98522701831820.039783345617425.6069323.5543224.5904324.4466722.89272
1237667536933487440149.99773259569220.06460877101624.2883422.0812621.8164621.4808821.45144
1237667536933487782150.00088020693420.047111284310525.4562924.5097523.007422.3214922.41913
1237667536933487820149.97859934240420.040590447541624.4909824.922724.8875323.172619.28066
1237667536933487823149.97902613494420.059190259470324.566224.6218125.433324.1238121.21616
1237667536933552169150.03315288527320.0606518427315.7195414.6408313.8686213.7451413.77949
1237667536933552170150.03600955159720.055407479949218.3274817.1398716.6622416.4741716.41367
1237667536933552171150.03016984382520.06090357774522.8775220.1591118.7934817.5949416.97581
1237667536933552268150.02577112223620.072950015047320.4646717.9536816.6931916.1501215.86218
1237667536933552274150.02937176997820.071065965919622.1244424.0432624.8377424.1261923.57829
1237667536933552281150.0459501165120.069757449746823.5093723.9186923.1970322.7273323.00898
1237667536933552370150.00692595178520.0667631268323.5165620.4083418.9737818.0576617.57124
1237667536933552668150.02682347611920.056967787588125.5745923.0422622.0270721.6677221.38085
1237667536933552714150.04625275995720.054069104001124.9475123.2292925.5200425.4939522.93958
1237667536933553164150.01264925756420.067511282635725.4472323.4119822.9989222.6213621.47634
1237667536933553171150.01999992728520.065655606796725.8863423.7940222.8298723.2499422.39665
1237667536933553447150.05326937062920.065711300569924.00523.4413823.2564922.3900321.60314
1237667540679852070149.98081878075820.017276490933415.9986413.6180512.5055712.1883613.00015
1237667540679852073149.98447487291520.022640969923924.6928524.986424.5429622.4960922.76906
1237667540679852074149.97815053237920.021079834181323.8676624.3370823.9656522.6083222.84336
1237667540679852075149.98648423195620.017187319415223.6037823.0855723.3973622.9843722.75075
1237667540679852076149.97555456155820.020218395450922.741724.4548225.2186923.8397222.92216
1237667540679852078149.98987873634920.013357374190715.6664514.5100614.254414.2722113.96794
1237667540679852094150.02525892001820.044745863814318.8836816.5050215.5060615.1491814.96568
1237667540679852095150.02700296140620.044452161781723.934223.1695422.8234123.1869922.73956
1237667540679852102150.05197060372719.97887678693317.7583115.6536214.7865714.46514.30313
1237667540679852103150.05384316986219.97851535516822.6829124.9320824.4550824.3065623.14767
1237667540679852111150.06027386478519.96648763027215.3599113.9057113.2571113.188313.62227
1237667540679852113150.06328772449319.963222451136425.1199623.7876423.0690422.396421.80136
1237667540679852114150.05740084644919.967405389144222.6066624.2251124.4547522.8112823.03099
1237667540679852125150.06291839107820.055743195098316.6823415.4897815.0741614.9006314.83469
1237667540679852158149.98871462699919.952736041570125.7160924.2584523.1921822.2666422.33821
1237667540679852165149.99423909820819.946184182218420.4041118.1141817.1705616.8506416.65546
1237667540679852170149.9818683321520.005777954466721.5578819.3930418.2399617.7696617.47716
1237667540679852171149.981345339420.005917974439224.1941222.953321.9819521.4573920.65025
1237667540679852185150.00083213113919.967724688567824.2852924.9788724.6896324.2875721.17146
1237667540679852189149.99264981398320.003123603151921.7668519.5049118.3875417.9605417.7053
1237667540679852196150.01583851862419.947330752405820.6909819.8400519.5716319.4684119.41268
1237667540679852197150.01666812819219.948477786232525.0511523.9942122.7841922.3724122.29454
1237667540679852199150.00761499549520.039265552094722.086419.7123918.5564317.9936417.66514
1237667540679852207150.0287171022920.031916421419524.5951824.9497623.0326321.8467621.02443
1237667540679852217150.05040091335319.966549172156721.5454119.2844318.2438117.7849217.5203
1237667540679852218150.05149805873819.965174027607925.1383123.6552823.0848423.8135821.96425
1237667540679852225150.03742223716120.040606830892822.1869720.0571218.8809718.4075118.11821
1237667540679852245150.06939766378619.998453650890920.2322919.0274718.4847918.2717618.17243
1237667540679852307150.04573830279519.929539820990723.900321.1303319.7166319.0779218.75595
1237667540679852349150.07397775464220.022102730804824.5214624.1915322.037321.7214121.05154
1237667540679852395150.05365996665719.97544016335823.3250721.3362419.7831618.6771618.07425
1237667540679852399150.0628460242219.984078515212825.0075524.6993923.2261822.5469722.7804
1237667540679852433149.99538901679619.965941668950524.5824923.8253623.1067523.0486421.88751
1237667540679852438149.98920428864320.031338762760922.0661424.7616724.0736222.9535323.95202
1237667540679852442149.9967147614820.016571774685924.1291922.8199521.2988520.7149320.21899
1237667540679852445150.02438813970519.921140706414821.6934220.490220.1716220.1335220.14277
1237667540679852448150.00053277265720.034009849814422.5121924.7950525.0943125.1098922.84663
1237667540679852449149.9995545763120.039372032398722.4901721.8674921.3140521.2424521.06739
1237667540679852472150.04786939294119.950883246378522.0383920.8719220.5555220.443220.35356
1237667540679852478150.05006885919419.973475751179922.3429822.2835121.629721.244621.22821
1237667540679852494150.05228220676520.044519806229322.3276423.0358321.9197321.7292721.14098
1237667540679852595150.00728113460519.929643189735623.5619323.1124622.094621.8556221.31284
1237667540679852598149.99069287596220.001375558180626.0040322.9604522.9134623.3112821.57102
1237667540679852602150.0029027972219.962680989760424.6385220.9463319.998119.6392419.42664
1237667540679852607150.00576081244919.968346641892523.2464321.6125920.7939920.5407420.3294
1237667540679852614150.00206667690619.990897606850923.64122.725622.0655221.9788621.39964
1237667540679852621150.0015731117720.001910549869724.3856523.8267923.2543922.414722.24143
1237667540679852623150.00050454647220.015576417192124.7551923.4131124.1089223.2704222.04775
1237667540679852626149.99607542163520.030545571105924.0530224.4570622.7007521.1111220.20724
1237667540679852631150.01725692507619.962659008113324.3950922.7211222.422122.4642121.4403
1237667540679852636150.02044439458919.957536035905723.125822.711522.2100221.8323421.41492
1237667540679852638150.00302246362920.031524211800523.7075222.3372621.9135721.7489621.6074
1237667540679852672150.03478211869719.946574533686523.7209722.4914922.0640921.9971321.87659
1237667540679852673150.03562640873619.945735527384523.327923.4335623.9000223.7706422.81033
1237667540679852694150.02359500686820.016285186854723.6376923.7103722.9933923.6055322.86188
1237667540679852698150.04297206287219.957156811686424.5051521.8590520.5401720.011519.77749
1237667540679852707150.04310565313519.968197240790925.9538624.5092823.1713923.2372822.47069
1237667540679852714150.04692522846419.955920804852224.2387324.4553624.6054122.6376623.12794
1237667540679852747150.03714146739620.034821218002924.0088522.2173120.6223119.5787118.91265
1237667540679852789150.04523227758720.050275867859324.0666621.9738521.2293120.9229520.83462
1237667540679852801150.07196695490419.978526378483524.7514523.0150521.4264320.2077419.47961
1237667540679852803150.07421159170719.972121825169225.6969523.1554524.9570724.9724523.61905
1237667540679852840150.08588610495619.98451016377124.1417422.1177521.0112220.5810420.29366
1237667540679852878150.08419618061520.024208389811722.812621.6518321.2443221.2045220.73042
1237667540679853000149.98972100000319.955821616583925.3461824.2868922.4525322.1979722.34164
1237667540679853006150.00140301783819.920037674875323.8030823.4690622.6392222.3505322.23955
1237667540679853010149.97676844387120.025156779231925.3330124.3191123.0668722.161622.2377
1237667540679853014150.00694063338419.923368060833323.3073323.5228322.7186522.7801221.31966
1237667540679853016149.99073105316219.988284113019623.6482523.9384422.903524.8719223.05344
1237667540679853018150.00754791052519.932282850702724.925824.0234922.5323322.0754221.96423
1237667540679853033149.99508841633120.009998826436224.5981224.7300122.8618521.3584820.30837
1237667540679853034149.99416920502320.016040581182324.482423.2540423.0556422.8877322.54831
1237667540679853037149.99797060644820.005908326782624.7833923.9629322.5078722.3770121.59072
1237667540679853043149.99501448982220.021637692916923.0682723.4283722.5027522.4800922.06647
1237667540679853047150.01926280225819.938294648165325.486223.8161821.9393121.3738220.65718
1237667540679853058150.03007284974119.925264140795224.3002923.7740322.525721.4056321.17029
1237667540679853060150.00855009795720.007574550497823.7688824.9020723.1104824.1391823.37637
1237667540679853079150.01764691645120.027889993815624.9025623.5094222.3010820.9526520.09003
1237667540679853086150.04333478850319.941036974404924.3120823.7745822.3394320.7655719.84065
1237667540679853088150.03750442497619.965824025786425.1767723.4130422.6250422.1828922.00393
1237667540679853154150.04490321174320.038332475988623.627124.9540422.3544921.6590920.94472
1237667540679853170150.06533523249519.994501996295724.656123.527622.4731121.7649821.61342
1237667540679853173150.06520072220719.99877368215623.8425924.4912922.6230821.5560221.18183
1237667540679853195150.08086263647319.978785180914625.8706423.2277123.3129522.1157421.81063
1237667540679853196150.07987038220819.978095106886223.1903123.3967422.9666522.9172622.90016
1237667540679853216150.07139665268720.035525535551723.5032323.3478422.9762822.6242721.97483
1237667540679853221150.08477806100819.993657084257623.5944324.245722.9631623.2503421.44757
1237667540679853362149.99271995752119.943158589598325.5129923.4864625.2125622.4720422.71149
1237667540679853367149.98881931125519.973209861913824.1908323.3612822.9875322.4125922.15463
1237667540679853371150.01226701010819.934997964369623.173823.4265423.202222.2705421.41897
1237667540679853374149.99882046343619.994676552983823.2342923.7149223.1250422.2380222.14328
1237667540679853396150.03021605542920.016085839321624.0865224.0029523.8139422.4312722.49623
1237667540679853397150.04979188986219.943548411447724.8512824.3749923.1733222.3312521.34988
1237667540679853408150.03258655046820.043462686390825.3599124.0018323.1936822.1010621.08349
1237667540679853409150.05429546850219.963663341736825.596524.0069725.278222.4760122.52358
1237667540679853412150.05214517966819.985802086770624.8203624.3715324.1246522.4276222.94733
1237667540679853423150.08239225427619.97076112068825.5736624.3674625.1223622.4699423.20025
1237667540679853476149.99566859605119.953108240964623.7842924.2408924.1207624.6115521.26306
1237667536933486638149.93262594152920.031190289006114.4493611.518211.101711.0039813.29102
1237667536933486639149.93210641672920.032660833933824.6346520.6832121.0656924.361822.8269
1237667536933486640149.93108701830820.030895475953624.6346520.5712121.3465121.6751722.8269
1237667536933486643149.93344592217220.028191806192124.6346523.403723.0860922.4490422.82689
1237667536933486648149.93733013883820.035582122209524.5013424.6621925.1495322.7182623.38941
1237667536933486649149.92648928545320.032657388200424.3988323.52725.308322.909923.43207
1237667536933486782149.94847502860320.059598593145320.1926319.093818.6007318.4212918.34959
1237667536933486860149.97948379551820.080689464802123.8758920.8170319.4378318.5808418.08092
1237667536933486949149.94189899499220.049046022485824.3877422.3950120.8375819.7160219.04477
1237667536933486950149.94373222042920.050261557179524.5475424.2000722.9105522.606823.03515
1237667536933487327149.95342371371520.060400519860123.8664622.7164821.4925120.8606520.69391
1237667536933487340149.95548822390320.069728051865324.3955322.8852822.5476121.4850122.65967
1237667536933487345149.95791878899620.066075955195324.3726222.5404522.0800422.0397222.19501
1237667536933487575149.940265308520.039060544451125.6928723.8691822.5320521.9344120.92043
1237667536933487769149.9769018134920.07815963434323.9497523.5597423.3122722.3710622.29713
1237667540679786560149.92736389381220.017044263859125.1638424.2885222.8408522.1122421.09951
1237667540679786562149.92042200383620.015885168025724.7928624.1855424.7253723.1948123.39883
1237667540679786564149.91414756398420.014084736004424.0052724.6823622.7203122.7102921.96593
1237667540679786566149.91577865889720.010620847022724.5458924.2706623.3014222.8888322.37614
1237667540679787501149.91752903930220.015424162889123.1750423.4985922.6403621.901221.50328
1237667540679787514149.92350680573120.019368933932325.2243524.4197622.7144624.3247622.17584
1237667540679787683149.92190195298620.017459001191725.0648424.6303424.3242322.511222.11053
1237667540679852182149.99972261670519.970150525461320.5670617.7146716.2113914.6250313.75668
1237667540679852184149.99798842906119.971848637246325.4984223.8860223.7038322.2969522.87161
1237667540679852239150.06382235887620.0050104449122.2417919.63418.3741317.8911317.64459
1237667540679852310150.03789999782619.992128675460923.133420.7497119.7290119.3448519.08041
1237667540679852346150.06895580462520.024193212310624.4603223.2739721.525221.009220.50312
1237667540679852347150.06955277203420.019071459710724.1517222.7908122.5933522.4619222.56883
1237667540679852348150.06965590148920.02292611723423.697923.2458422.1522221.7278622.1195
1237667540679852351150.06729982842520.019970254104524.0043424.8486322.7632722.1494322.06081
1237667540679852459150.02166241630620.005445816256822.5237124.7417424.882824.244522.64661
1237667540679852596149.99473607948719.977615134081322.5200123.2909523.3282722.8595623.2657
1237667540679852676150.02936568982919.97893013768722.9049122.6913522.7203722.2637221.73992
1237667540679852690150.03395531717919.982383656796624.6718222.6216421.2532620.0043419.31323
1237667540679852693150.024344297520.014130329475524.2276524.1671723.0217422.8899522.11329
1237667540679852733150.04302574075619.995585167647424.0671423.1909222.7864422.2108721.7388
1237667540679852745150.06243057944719.941617394492825.0004723.6850422.7807222.2900722.00552
1237667540679852774150.04623915537220.024121526558824.2866122.3833321.0128919.7047618.90362
1237667540679852802150.06062639891520.022074501779324.5625322.1251520.756219.9948619.51831
1237667540679853118150.04356299155519.985497597189423.8829923.8015122.9973422.2083521.57158
1237667540679853125150.04211617153820.009942777982325.5064524.5227823.2460322.7274921.68442
1237667540679853127150.04510840048120.001414590522724.4516823.4764322.2599520.6891319.61595
1237667540679853143150.05305613981419.998968790265824.3869923.7872623.1542222.4587122.05472
1237667540679853163150.05366474117220.02490562898124.4982223.2814722.5092722.5785521.93493
1237667540679853164150.06062537125920.004848458174824.1243924.0756923.104722.6854122.40507
1237667540679853174150.06082737113320.015994052094125.1541923.5766822.635722.0877121.72324
1237667540679853175150.05540879205120.037248724994724.8484424.6688422.9820921.6048520.63416
1237667540679853386150.02963951595719.991829168429524.631524.5428323.3794622.030121.20406
1237667540679853421150.06149382863420.024876402094724.6807324.226523.6155322.4308722.56933

diff -Nru wcstools-3.9.5/temp.c wcstools-3.9.6/temp.c --- wcstools-3.9.5/temp.c 1970-01-01 00:00:00.000000000 +0000 +++ wcstools-3.9.6/temp.c 2020-05-14 18:03:55.000000000 +0000 @@ -0,0 +1,115 @@ + +/* Print a region of a two-dimensional image */ + else if (bycol) { + yrange = RangeInit (rrange, xdim); + nx = rgetn (xrange); + + /* Make list of x coordinates */ + xrange = RangeInit (crange, ydim); + nx = rgetn (xrange); + xi = (int *) calloc (nx, sizeof (int)); + for (i = 0; i < nx; i++) { + xi[i] = rgeti4 (xrange) - 1; + } + + /* Label vertical pixels */ + if (pixlabel) { + printf ("Coord"); + rstart (yrange); + strcpy (nform, pform); + if ((c = strchr (nform,'.')) != NULL) { + *c = 'd'; + c[1] = (char) 0; + } + else if ((c = strchr (nform,'f')) != NULL) { + *c = 'd'; + } + for (iy = 0; iy < ny; ix++) { + y = rgeti4 (yrange); + if (printtab) + printf ("\t"); + else + printf (" "); + printf (nform, y); + } + printf ("\n"); + } + if (verbose) + ix = -1; + else + ix = nx; + + /* Loop through columns */ + for (iy = 0; i < ny; i++) { + rstart (yrange); + y = rgeti4 (yrange) - 1; + if (pixlabel) { + printf ("%4d:",y); + if (printtab) + printf ("\t"); + else + printf (" "); + } + + /* Loop through rows */ + for (ix = 0; ix < nx; ix++) { + x = rgeti4 (xrange) - 1; + dpix = getpix (image,bitpix,xdim,ydim,bzero,bscale,x,y); + if (gtcheck || ltcheck) { + if ((gtcheck && dpix > gtval) || + (ltcheck && dpix < ltval)) { + procpix (&dsum, &dnpix, &dmin, &dmax, dpix); + if (nopunct) + printf ("%d %d %f\n", x+1, y+1, dpix); + else + printf ("[%d,%d] = %f\n", x+1, y+1, dpix); + } + continue; + } + else + procpix (&dsum, &dnpix, &dmin, &dmax, dpix); + if (printrange || printmean) + continue; + if (bitpix > 0) { + if ((c = strchr (pform,'f')) != NULL) + *c = 'd'; + if (dpix > 0) + ipix = (int) (dpix + 0.5); + else if (dpix < 0) + ipix = (int) (dpix - 0.5); + else + ipix = 0; + } + else { + if ((c = strchr (pform,'d')) != NULL) + *c = 'f'; + } + if (pixperline) { + printf ("%s[%d,%d] = ",name,x+1,yi[i]+1); + if (bitpix > 0) + printf (pform, ipix); + else + printf (pform, dpix); + printf ("\n"); + } + else { + if (bitpix > 0) + printf (pform, ipix); + else + printf (pform, dpix); + if ((ix+1) % nline == 0) + printf ("\n"); + else if (printtab) + printf ("\t"); + else + printf (" "); + } + } + if (!pixperline && !ltcheck && !gtcheck) { + if (!printrange && !printmean && ix % nline != 0) + printf ("\n"); + } + } + free (xrange); + free (yrange); + } diff -Nru wcstools-3.9.5/temp.csv wcstools-3.9.6/temp.csv --- wcstools-3.9.5/temp.csv 1970-01-01 00:00:00.000000000 +0000 +++ wcstools-3.9.6/temp.csv 2018-11-06 02:01:52.000000000 +0000 @@ -0,0 +1,239 @@ +#Table1 +objid,ra,dec,u,g,r,i,z +1237667536933486968,149.966426054193,20.0562516444303,22.42603,24.90857,24.1905,24.55581,22.69641 +1237667536933487753,149.96146500122,20.0554404140921,25.83836,23.8804,23.17221,22.34711,22.00612 +1237667536933486881,149.952612459009,20.0440954484166,25.22401,21.77284,20.47719,19.21927,18.55294 +1237667536933486882,149.952445951495,20.0424715005266,24.51232,23.01234,21.53869,20.07007,19.29092 +1237667536933487364,149.967276177075,20.0494821030794,25.88244,24.64945,22.53706,21.8704,21.80008 +1237667536933487359,149.967202207759,20.0446555640434,23.30555,22.94082,22.13236,22.12097,22.37773 +1237667536933487332,149.959115168979,20.0403666826498,26.02842,23.51375,25.40557,25.1435,23.52424 +1237667536933487365,149.96675286623,20.0499142816377,23.17319,22.35181,22.22383,22.30088,21.91514 +1237667540679786659,149.947760375994,20.0261570125523,20.56662,19.21535,18.59991,18.34818,18.21479 +1237667540679852150,149.962430355881,20.0289188411881,20.01995,19.06832,18.79038,18.66804,18.62234 +1237667540679853361,149.969384814993,20.0297352263627,24.48018,23.39878,23.51324,22.39979,21.64503 +1237667540679852992,149.961644711963,20.017132136208,24.46468,24.64341,23.14837,23.37128,22.6344 +1237667540679852578,149.968830627409,20.0248357834962,24.90792,22.97514,22.15233,22.08604,21.11423 +1237667536933487330,149.960372823134,20.0347186244794,24.12566,22.96781,22.10907,21.63051,21.61654 +1237667536933486877,149.954745242646,20.0332591698705,24.77999,21.32112,19.9606,18.85464,18.21878 +1237667540679786535,149.926996759239,19.9715073640307,16.02208,14.80695,14.39048,14.22592,14.17986 +1237667540679786536,149.928587817967,19.9738796370316,24.28319,23.28121,22.24471,20.87877,20.10825 +1237667540679786539,149.924553074573,19.9733823871147,23.76879,23.26944,24.74638,23.23615,22.87075 +1237667540679786551,149.923940261902,20.0118466978366,23.87137,24.80838,24.80202,24.3618,20.64042 +1237667540679786556,149.928276851281,20.010963934515,22.96422,22.25701,21.88248,22.39655,21.62824 +1237667540679786545,149.922145728918,20.0092006500539,15.97371,11.85337,10.71989,10.4058,12.7499 +1237667540679786557,149.92815382909,20.0103500231703,22.0097,22.39952,23.20789,22.15276,21.37527 +1237667540679786567,149.925084018227,20.010279400916,22.9361,24.98593,24.80202,24.3618,21.31667 +1237667540679786640,149.916086271458,19.9956354218803,20.75637,19.84849,19.58648,19.50509,19.45461 +1237667540679786558,149.922832736164,20.0016268205441,24.19976,24.75271,22.57455,21.48663,21.10661 +1237667540679787202,149.92859012737,19.9885102622087,24.41193,23.98157,23.06535,22.93385,21.70112 +1237667540679787200,149.927949289289,19.9900979269963,24.31094,22.77748,21.12806,19.53094,18.56912 +1237667540679787201,149.92863252752,19.9911930119592,23.99031,24.58306,24.12953,22.55301,21.65226 +1237667540679787678,149.921459075409,19.9876659866085,24.40398,23.91727,23.57413,22.42508,21.63087 +1237667540679852289,149.971706544675,19.9795943797214,23.9302,21.9134,20.50703,19.53954,19.00142 +1237667540679787532,149.94367947169,19.9752596710432,25.70833,23.42458,21.85963,20.61711,19.85274 +1237667540679787550,149.956718710678,19.9852554130573,23.28038,23.51374,23.02353,22.9399,21.8307 +1237667540679786878,149.957967388532,19.9910530885495,22.85742,21.65261,21.31135,21.20137,21.36971 +1237667540679786892,149.96816158869,19.979688368976,22.37313,24.78566,24.20852,24.48309,23.30006 +1237667540679852292,149.96880075298,19.9862902774731,23.50283,20.57782,19.45103,18.96172,18.71946 +1237667540679786886,149.9605911773,20.003607923732,21.56224,20.62411,20.23925,20.10128,20.13819 +1237667540679786857,149.934998152751,20.001995692165,22.62766,24.72985,25.01218,25.18545,22.59937 +1237667540679787536,149.936143561722,20.0108140743838,23.18681,23.35727,22.96841,23.20052,22.32876 +1237667540679786713,149.943608096137,20.0052018339802,22.27852,20.11228,18.94126,18.47809,18.19592 +1237667540679787552,149.952185986639,20.0068204065293,24.54712,24.1518,22.20515,21.93805,21.82258 +1237667540679787528,149.937743392628,19.994114636126,23.4753,23.44545,21.81803,20.74651,20.05929 +1237667540679787236,149.965931603842,19.943083059134,24.36697,24.22398,24.73541,22.3716,22.25604 +1237667540679787691,149.960041428024,19.929776386057,25.32248,24.37973,23.96966,22.57007,22.29247 +1237667540679787266,149.983697338592,19.9243181508534,24.19884,21.68089,20.20617,19.17081,18.59343 +1237667540679852152,149.990683182023,19.9336542817189,20.82052,19.64188,19.18082,18.9244,18.7516 +1237667540679852419,149.983772202498,19.9410937960546,25.18873,24.89008,24.93736,22.28128,22.48594 +1237667540679852420,149.982741441298,19.9408184043781,24.33267,24.67689,24.68633,22.65037,22.63358 +1237667540679786598,149.969998736568,19.9448372207324,24.93092,23.24562,24.37328,24.49154,22.56615 +1237667540679786597,149.973310526714,19.9443552831486,24.3674,24.18579,23.23191,22.27476,21.50764 +1237667540679787554,149.970947710762,19.9399101927428,24.26012,23.54147,22.03133,21.59754,21.53224 +1237667540679786596,149.971250187285,19.9446329069005,19.07302,18.14919,17.79511,17.66474,17.60424 +1237667540679786884,149.976380830624,19.9375703254922,22.01169,21.28089,21.04199,20.893,20.96118 +1237667540679787557,149.966705417006,19.9654972589441,23.8935,24.19764,23.1523,22.68534,21.59781 +1237667540679787244,149.96668661454,19.9493422120372,23.03759,22.71437,21.97849,21.91496,21.9044 +1237667540679787523,149.946452881241,19.9542874972097,25.43415,24.71089,23.03678,23.19531,21.76982 +1237667540679787688,149.947832873733,19.9650118654223,24.20856,23.59981,23.51727,22.57999,22.61911 +1237667540679787692,149.959103507246,19.9412702218234,25.73852,24.55167,24.97225,22.4462,22.79988 +1237667540679787526,149.950440881652,19.9454929526785,23.74073,23.61153,22.91304,22.75546,21.49961 +1237667540679787520,149.948949034467,19.9367122985479,25.14961,23.30326,22.86839,23.34975,22.28565 +1237667540679786856,149.948228304594,19.9473807716835,21.69041,20.63798,20.25419,20.09247,20.03105 +1237667540679786867,149.96171714364,19.9545373746099,21.76895,20.92687,20.64721,20.51401,20.64172 +1237667540679787735,149.957470733553,19.948364679449,25.48231,24.60806,25.00093,24.96217,21.25213 +1237667540679786849,149.933568023687,19.9667753224709,22.63658,24.3239,24.63825,24.66232,22.89179 +1237667540679786538,149.929614873062,19.9691756718378,24.5862,24.51839,23.52724,22.52266,22.9873 +1237667540679787206,149.940921589916,19.9492681951107,24.34356,24.00892,23.23265,22.70215,21.93315 +1237667540679787204,149.939433957816,19.94863882096,25.46928,22.86565,21.26058,20.07184,19.36119 +1237667540679787753,149.936652911615,19.9534737167404,25.44718,23.72989,23.95931,23.42557,23.23993 +1237667540679786542,149.933904371,19.946953882503,18.09332,16.27126,15.5837,15.31384,15.19024 +1237667540679786643,149.93112670582,19.9564138326593,20.93421,19.20614,18.48445,18.19467,18.07238 +1237667536933486796,149.975143806986,20.0488275678632,21.82082,18.90696,17.39165,16.23801,15.62426 +1237667536933486799,149.983092297532,20.0418791455222,23.87619,19.61578,17.92018,15.56056,14.19144 +1237667536933487376,149.970974119787,20.0450184435566,25.55033,23.54097,21.85809,20.76174,20.03244 +1237667536933487403,149.975212966082,20.070763911265,23.79756,23.1978,22.625,22.3837,22.37665 +1237667536933487406,149.985227018318,20.0397833456174,25.60693,23.55432,24.59043,24.44667,22.89272 +1237667536933487440,149.997732595692,20.064608771016,24.28834,22.08126,21.81646,21.48088,21.45144 +1237667536933487782,150.000880206934,20.0471112843105,25.45629,24.50975,23.0074,22.32149,22.41913 +1237667536933487820,149.978599342404,20.0405904475416,24.49098,24.9227,24.88753,23.1726,19.28066 +1237667536933487823,149.979026134944,20.0591902594703,24.5662,24.62181,25.4333,24.12381,21.21616 +1237667536933552169,150.033152885273,20.06065184273,15.71954,14.64083,13.86862,13.74514,13.77949 +1237667536933552170,150.036009551597,20.0554074799492,18.32748,17.13987,16.66224,16.47417,16.41367 +1237667536933552171,150.030169843825,20.060903577745,22.87752,20.15911,18.79348,17.59494,16.97581 +1237667536933552268,150.025771122236,20.0729500150473,20.46467,17.95368,16.69319,16.15012,15.86218 +1237667536933552274,150.029371769978,20.0710659659196,22.12444,24.04326,24.83774,24.12619,23.57829 +1237667536933552281,150.04595011651,20.0697574497468,23.50937,23.91869,23.19703,22.72733,23.00898 +1237667536933552370,150.006925951785,20.06676312683,23.51656,20.40834,18.97378,18.05766,17.57124 +1237667536933552668,150.026823476119,20.0569677875881,25.57459,23.04226,22.02707,21.66772,21.38085 +1237667536933552714,150.046252759957,20.0540691040011,24.94751,23.22929,25.52004,25.49395,22.93958 +1237667536933553164,150.012649257564,20.0675112826357,25.44723,23.41198,22.99892,22.62136,21.47634 +1237667536933553171,150.019999927285,20.0656556067967,25.88634,23.79402,22.82987,23.24994,22.39665 +1237667536933553447,150.053269370629,20.0657113005699,24.005,23.44138,23.25649,22.39003,21.60314 +1237667540679852070,149.980818780758,20.0172764909334,15.99864,13.61805,12.50557,12.18836,13.00015 +1237667540679852073,149.984474872915,20.0226409699239,24.69285,24.9864,24.54296,22.49609,22.76906 +1237667540679852074,149.978150532379,20.0210798341813,23.86766,24.33708,23.96565,22.60832,22.84336 +1237667540679852075,149.986484231956,20.0171873194152,23.60378,23.08557,23.39736,22.98437,22.75075 +1237667540679852076,149.975554561558,20.0202183954509,22.7417,24.45482,25.21869,23.83972,22.92216 +1237667540679852078,149.989878736349,20.0133573741907,15.66645,14.51006,14.2544,14.27221,13.96794 +1237667540679852094,150.025258920018,20.0447458638143,18.88368,16.50502,15.50606,15.14918,14.96568 +1237667540679852095,150.027002961406,20.0444521617817,23.9342,23.16954,22.82341,23.18699,22.73956 +1237667540679852102,150.051970603727,19.978876786933,17.75831,15.65362,14.78657,14.465,14.30313 +1237667540679852103,150.053843169862,19.978515355168,22.68291,24.93208,24.45508,24.30656,23.14767 +1237667540679852111,150.060273864785,19.966487630272,15.35991,13.90571,13.25711,13.1883,13.62227 +1237667540679852113,150.063287724493,19.9632224511364,25.11996,23.78764,23.06904,22.3964,21.80136 +1237667540679852114,150.057400846449,19.9674053891442,22.60666,24.22511,24.45475,22.81128,23.03099 +1237667540679852125,150.062918391078,20.0557431950983,16.68234,15.48978,15.07416,14.90063,14.83469 +1237667540679852158,149.988714626999,19.9527360415701,25.71609,24.25845,23.19218,22.26664,22.33821 +1237667540679852165,149.994239098208,19.9461841822184,20.40411,18.11418,17.17056,16.85064,16.65546 +1237667540679852170,149.98186833215,20.0057779544667,21.55788,19.39304,18.23996,17.76966,17.47716 +1237667540679852171,149.9813453394,20.0059179744392,24.19412,22.9533,21.98195,21.45739,20.65025 +1237667540679852185,150.000832131139,19.9677246885678,24.28529,24.97887,24.68963,24.28757,21.17146 +1237667540679852189,149.992649813983,20.0031236031519,21.76685,19.50491,18.38754,17.96054,17.7053 +1237667540679852196,150.015838518624,19.9473307524058,20.69098,19.84005,19.57163,19.46841,19.41268 +1237667540679852197,150.016668128192,19.9484777862325,25.05115,23.99421,22.78419,22.37241,22.29454 +1237667540679852199,150.007614995495,20.0392655520947,22.0864,19.71239,18.55643,17.99364,17.66514 +1237667540679852207,150.02871710229,20.0319164214195,24.59518,24.94976,23.03263,21.84676,21.02443 +1237667540679852217,150.050400913353,19.9665491721567,21.54541,19.28443,18.24381,17.78492,17.5203 +1237667540679852218,150.051498058738,19.9651740276079,25.13831,23.65528,23.08484,23.81358,21.96425 +1237667540679852225,150.037422237161,20.0406068308928,22.18697,20.05712,18.88097,18.40751,18.11821 +1237667540679852245,150.069397663786,19.9984536508909,20.23229,19.02747,18.48479,18.27176,18.17243 +1237667540679852307,150.045738302795,19.9295398209907,23.9003,21.13033,19.71663,19.07792,18.75595 +1237667540679852349,150.073977754642,20.0221027308048,24.52146,24.19153,22.0373,21.72141,21.05154 +1237667540679852395,150.053659966657,19.975440163358,23.32507,21.33624,19.78316,18.67716,18.07425 +1237667540679852399,150.06284602422,19.9840785152128,25.00755,24.69939,23.22618,22.54697,22.7804 +1237667540679852433,149.995389016796,19.9659416689505,24.58249,23.82536,23.10675,23.04864,21.88751 +1237667540679852438,149.989204288643,20.0313387627609,22.06614,24.76167,24.07362,22.95353,23.95202 +1237667540679852442,149.99671476148,20.0165717746859,24.12919,22.81995,21.29885,20.71493,20.21899 +1237667540679852445,150.024388139705,19.9211407064148,21.69342,20.4902,20.17162,20.13352,20.14277 +1237667540679852448,150.000532772657,20.0340098498144,22.51219,24.79505,25.09431,25.10989,22.84663 +1237667540679852449,149.99955457631,20.0393720323987,22.49017,21.86749,21.31405,21.24245,21.06739 +1237667540679852472,150.047869392941,19.9508832463785,22.03839,20.87192,20.55552,20.4432,20.35356 +1237667540679852478,150.050068859194,19.9734757511799,22.34298,22.28351,21.6297,21.2446,21.22821 +1237667540679852494,150.052282206765,20.0445198062293,22.32764,23.03583,21.91973,21.72927,21.14098 +1237667540679852595,150.007281134605,19.9296431897356,23.56193,23.11246,22.0946,21.85562,21.31284 +1237667540679852598,149.990692875962,20.0013755581806,26.00403,22.96045,22.91346,23.31128,21.57102 +1237667540679852602,150.00290279722,19.9626809897604,24.63852,20.94633,19.9981,19.63924,19.42664 +1237667540679852607,150.005760812449,19.9683466418925,23.24643,21.61259,20.79399,20.54074,20.3294 +1237667540679852614,150.002066676906,19.9908976068509,23.641,22.7256,22.06552,21.97886,21.39964 +1237667540679852621,150.00157311177,20.0019105498697,24.38565,23.82679,23.25439,22.4147,22.24143 +1237667540679852623,150.000504546472,20.0155764171921,24.75519,23.41311,24.10892,23.27042,22.04775 +1237667540679852626,149.996075421635,20.0305455711059,24.05302,24.45706,22.70075,21.11112,20.20724 +1237667540679852631,150.017256925076,19.9626590081133,24.39509,22.72112,22.4221,22.46421,21.4403 +1237667540679852636,150.020444394589,19.9575360359057,23.1258,22.7115,22.21002,21.83234,21.41492 +1237667540679852638,150.003022463629,20.0315242118005,23.70752,22.33726,21.91357,21.74896,21.6074 +1237667540679852672,150.034782118697,19.9465745336865,23.72097,22.49149,22.06409,21.99713,21.87659 +1237667540679852673,150.035626408736,19.9457355273845,23.3279,23.43356,23.90002,23.77064,22.81033 +1237667540679852694,150.023595006868,20.0162851868547,23.63769,23.71037,22.99339,23.60553,22.86188 +1237667540679852698,150.042972062872,19.9571568116864,24.50515,21.85905,20.54017,20.0115,19.77749 +1237667540679852707,150.043105653135,19.9681972407909,25.95386,24.50928,23.17139,23.23728,22.47069 +1237667540679852714,150.046925228464,19.9559208048522,24.23873,24.45536,24.60541,22.63766,23.12794 +1237667540679852747,150.037141467396,20.0348212180029,24.00885,22.21731,20.62231,19.57871,18.91265 +1237667540679852789,150.045232277587,20.0502758678593,24.06666,21.97385,21.22931,20.92295,20.83462 +1237667540679852801,150.071966954904,19.9785263784835,24.75145,23.01505,21.42643,20.20774,19.47961 +1237667540679852803,150.074211591707,19.9721218251692,25.69695,23.15545,24.95707,24.97245,23.61905 +1237667540679852840,150.085886104956,19.984510163771,24.14174,22.11775,21.01122,20.58104,20.29366 +1237667540679852878,150.084196180615,20.0242083898117,22.8126,21.65183,21.24432,21.20452,20.73042 +1237667540679853000,149.989721000003,19.9558216165839,25.34618,24.28689,22.45253,22.19797,22.34164 +1237667540679853006,150.001403017838,19.9200376748753,23.80308,23.46906,22.63922,22.35053,22.23955 +1237667540679853010,149.976768443871,20.0251567792319,25.33301,24.31911,23.06687,22.1616,22.2377 +1237667540679853014,150.006940633384,19.9233680608333,23.30733,23.52283,22.71865,22.78012,21.31966 +1237667540679853016,149.990731053162,19.9882841130196,23.64825,23.93844,22.9035,24.87192,23.05344 +1237667540679853018,150.007547910525,19.9322828507027,24.9258,24.02349,22.53233,22.07542,21.96423 +1237667540679853033,149.995088416331,20.0099988264362,24.59812,24.73001,22.86185,21.35848,20.30837 +1237667540679853034,149.994169205023,20.0160405811823,24.4824,23.25404,23.05564,22.88773,22.54831 +1237667540679853037,149.997970606448,20.0059083267826,24.78339,23.96293,22.50787,22.37701,21.59072 +1237667540679853043,149.995014489822,20.0216376929169,23.06827,23.42837,22.50275,22.48009,22.06647 +1237667540679853047,150.019262802258,19.9382946481653,25.4862,23.81618,21.93931,21.37382,20.65718 +1237667540679853058,150.030072849741,19.9252641407952,24.30029,23.77403,22.5257,21.40563,21.17029 +1237667540679853060,150.008550097957,20.0075745504978,23.76888,24.90207,23.11048,24.13918,23.37637 +1237667540679853079,150.017646916451,20.0278899938156,24.90256,23.50942,22.30108,20.95265,20.09003 +1237667540679853086,150.043334788503,19.9410369744049,24.31208,23.77458,22.33943,20.76557,19.84065 +1237667540679853088,150.037504424976,19.9658240257864,25.17677,23.41304,22.62504,22.18289,22.00393 +1237667540679853154,150.044903211743,20.0383324759886,23.6271,24.95404,22.35449,21.65909,20.94472 +1237667540679853170,150.065335232495,19.9945019962957,24.6561,23.5276,22.47311,21.76498,21.61342 +1237667540679853173,150.065200722207,19.998773682156,23.84259,24.49129,22.62308,21.55602,21.18183 +1237667540679853195,150.080862636473,19.9787851809146,25.87064,23.22771,23.31295,22.11574,21.81063 +1237667540679853196,150.079870382208,19.9780951068862,23.19031,23.39674,22.96665,22.91726,22.90016 +1237667540679853216,150.071396652687,20.0355255355517,23.50323,23.34784,22.97628,22.62427,21.97483 +1237667540679853221,150.084778061008,19.9936570842576,23.59443,24.2457,22.96316,23.25034,21.44757 +1237667540679853362,149.992719957521,19.9431585895983,25.51299,23.48646,25.21256,22.47204,22.71149 +1237667540679853367,149.988819311255,19.9732098619138,24.19083,23.36128,22.98753,22.41259,22.15463 +1237667540679853371,150.012267010108,19.9349979643696,23.1738,23.42654,23.2022,22.27054,21.41897 +1237667540679853374,149.998820463436,19.9946765529838,23.23429,23.71492,23.12504,22.23802,22.14328 +1237667540679853396,150.030216055429,20.0160858393216,24.08652,24.00295,23.81394,22.43127,22.49623 +1237667540679853397,150.049791889862,19.9435484114477,24.85128,24.37499,23.17332,22.33125,21.34988 +1237667540679853408,150.032586550468,20.0434626863908,25.35991,24.00183,23.19368,22.10106,21.08349 +1237667540679853409,150.054295468502,19.9636633417368,25.5965,24.00697,25.2782,22.47601,22.52358 +1237667540679853412,150.052145179668,19.9858020867706,24.82036,24.37153,24.12465,22.42762,22.94733 +1237667540679853423,150.082392254276,19.970761120688,25.57366,24.36746,25.12236,22.46994,23.20025 +1237667540679853476,149.995668596051,19.9531082409646,23.78429,24.24089,24.12076,24.61155,21.26306 +1237667536933486638,149.932625941529,20.0311902890061,14.44936,11.5182,11.1017,11.00398,13.29102 +1237667536933486639,149.932106416729,20.0326608339338,24.63465,20.68321,21.06569,24.3618,22.8269 +1237667536933486640,149.931087018308,20.0308954759536,24.63465,20.57121,21.34651,21.67517,22.8269 +1237667536933486643,149.933445922172,20.0281918061921,24.63465,23.4037,23.08609,22.44904,22.82689 +1237667536933486648,149.937330138838,20.0355821222095,24.50134,24.66219,25.14953,22.71826,23.38941 +1237667536933486649,149.926489285453,20.0326573882004,24.39883,23.527,25.3083,22.9099,23.43207 +1237667536933486782,149.948475028603,20.0595985931453,20.19263,19.0938,18.60073,18.42129,18.34959 +1237667536933486860,149.979483795518,20.0806894648021,23.87589,20.81703,19.43783,18.58084,18.08092 +1237667536933486949,149.941898994992,20.0490460224858,24.38774,22.39501,20.83758,19.71602,19.04477 +1237667536933486950,149.943732220429,20.0502615571795,24.54754,24.20007,22.91055,22.6068,23.03515 +1237667536933487327,149.953423713715,20.0604005198601,23.86646,22.71648,21.49251,20.86065,20.69391 +1237667536933487340,149.955488223903,20.0697280518653,24.39553,22.88528,22.54761,21.48501,22.65967 +1237667536933487345,149.957918788996,20.0660759551953,24.37262,22.54045,22.08004,22.03972,22.19501 +1237667536933487575,149.9402653085,20.0390605444511,25.69287,23.86918,22.53205,21.93441,20.92043 +1237667536933487769,149.97690181349,20.078159634343,23.94975,23.55974,23.31227,22.37106,22.29713 +1237667540679786560,149.927363893812,20.0170442638591,25.16384,24.28852,22.84085,22.11224,21.09951 +1237667540679786562,149.920422003836,20.0158851680257,24.79286,24.18554,24.72537,23.19481,23.39883 +1237667540679786564,149.914147563984,20.0140847360044,24.00527,24.68236,22.72031,22.71029,21.96593 +1237667540679786566,149.915778658897,20.0106208470227,24.54589,24.27066,23.30142,22.88883,22.37614 +1237667540679787501,149.917529039302,20.0154241628891,23.17504,23.49859,22.64036,21.9012,21.50328 +1237667540679787514,149.923506805731,20.0193689339323,25.22435,24.41976,22.71446,24.32476,22.17584 +1237667540679787683,149.921901952986,20.0174590011917,25.06484,24.63034,24.32423,22.5112,22.11053 +1237667540679852182,149.999722616705,19.9701505254613,20.56706,17.71467,16.21139,14.62503,13.75668 +1237667540679852184,149.997988429061,19.9718486372463,25.49842,23.88602,23.70383,22.29695,22.87161 +1237667540679852239,150.063822358876,20.00501044491,22.24179,19.634,18.37413,17.89113,17.64459 +1237667540679852310,150.037899997826,19.9921286754609,23.1334,20.74971,19.72901,19.34485,19.08041 +1237667540679852346,150.068955804625,20.0241932123106,24.46032,23.27397,21.5252,21.0092,20.50312 +1237667540679852347,150.069552772034,20.0190714597107,24.15172,22.79081,22.59335,22.46192,22.56883 +1237667540679852348,150.069655901489,20.022926117234,23.6979,23.24584,22.15222,21.72786,22.1195 +1237667540679852351,150.067299828425,20.0199702541045,24.00434,24.84863,22.76327,22.14943,22.06081 +1237667540679852459,150.021662416306,20.0054458162568,22.52371,24.74174,24.8828,24.2445,22.64661 +1237667540679852596,149.994736079487,19.9776151340813,22.52001,23.29095,23.32827,22.85956,23.2657 +1237667540679852676,150.029365689829,19.978930137687,22.90491,22.69135,22.72037,22.26372,21.73992 +1237667540679852690,150.033955317179,19.9823836567966,24.67182,22.62164,21.25326,20.00434,19.31323 +1237667540679852693,150.0243442975,20.0141303294755,24.22765,24.16717,23.02174,22.88995,22.11329 +1237667540679852733,150.043025740756,19.9955851676474,24.06714,23.19092,22.78644,22.21087,21.7388 +1237667540679852745,150.062430579447,19.9416173944928,25.00047,23.68504,22.78072,22.29007,22.00552 +1237667540679852774,150.046239155372,20.0241215265588,24.28661,22.38333,21.01289,19.70476,18.90362 +1237667540679852802,150.060626398915,20.0220745017793,24.56253,22.12515,20.7562,19.99486,19.51831 +1237667540679853118,150.043562991555,19.9854975971894,23.88299,23.80151,22.99734,22.20835,21.57158 +1237667540679853125,150.042116171538,20.0099427779823,25.50645,24.52278,23.24603,22.72749,21.68442 +1237667540679853127,150.045108400481,20.0014145905227,24.45168,23.47643,22.25995,20.68913,19.61595 +1237667540679853143,150.053056139814,19.9989687902658,24.38699,23.78726,23.15422,22.45871,22.05472 +1237667540679853163,150.053664741172,20.024905628981,24.49822,23.28147,22.50927,22.57855,21.93493 +1237667540679853164,150.060625371259,20.0048484581748,24.12439,24.07569,23.1047,22.68541,22.40507 +1237667540679853174,150.060827371133,20.0159940520941,25.15419,23.57668,22.6357,22.08771,21.72324 +1237667540679853175,150.055408792051,20.0372487249947,24.84844,24.66884,22.98209,21.60485,20.63416 +1237667540679853386,150.029639515957,19.9918291684295,24.6315,24.54283,23.37946,22.0301,21.20406 +1237667540679853421,150.061493828634,20.0248764020947,24.68073,24.2265,23.61553,22.43087,22.56933 diff -Nru wcstools-3.9.5/testhtml wcstools-3.9.6/testhtml --- wcstools-3.9.5/testhtml 1970-01-01 00:00:00.000000000 +0000 +++ wcstools-3.9.6/testhtml 2018-11-06 02:14:15.000000000 +0000 @@ -0,0 +1,8 @@ + +SDSS Query Results + +

Your SQL command was:
select top 1000 p.objid, p.ra, p.dec, p.u, p.g, p.r, p.i, p.z
+from star p, dbo.fgetNearByObjEq(150,20,5) n
+where p.objid=n.objid and (p.g BETWEEN 0 AND 25)
+

Your query output (max 500,000 rows):

+ diff -Nru wcstools-3.9.5/testrot.c wcstools-3.9.6/testrot.c --- wcstools-3.9.5/testrot.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/testrot.c 2020-05-14 18:03:55.000000000 +0000 @@ -24,7 +24,7 @@ static int nf = 0; static int version = 0; /* If 1, print only program name and version */ -static char *RevMsg = "TESTROT WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "TESTROT WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; main (ac, av) int ac; diff -Nru wcstools-3.9.5/wcshead.c wcstools-3.9.6/wcshead.c --- wcstools-3.9.5/wcshead.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/wcshead.c 2020-05-14 18:03:55.000000000 +0000 @@ -47,7 +47,7 @@ static int printhead = 1; /* 1 until header has been printed */ static char *rootdir=NULL; /* Root directory for input files */ -static char *RevMsg = "WCSHEAD WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "WCSHEAD WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; int main (ac, av) diff -Nru wcstools-3.9.5/wcstools wcstools-3.9.6/wcstools --- wcstools-3.9.5/wcstools 2016-06-24 23:10:19.000000000 +0000 +++ wcstools-3.9.6/wcstools 2018-11-08 18:49:27.000000000 +0000 @@ -1,6 +1,5 @@ #!/bin/sh -echo "WCSTools 3.9.4 Programs -http://tdc-www.harvard.edu/software/wcstools/ +echo "WCSTools 3.9.5 Programs addpix: Add a constant value(s) to specified pixel(s) bincat: Bin a catalog into a FITS image in flux or number diff -Nru wcstools-3.9.5/xy2sky1.c wcstools-3.9.6/xy2sky1.c --- wcstools-3.9.5/xy2sky1.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/xy2sky1.c 2020-05-14 18:03:55.000000000 +0000 @@ -51,7 +51,7 @@ static int scaleset = 0; static int version = 0; /* If 1, print only program name and version */ -static char *RevMsg = "XY2SKY WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "XY2SKY WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; int main (ac, av) diff -Nru wcstools-3.9.5/xy2sky.c wcstools-3.9.6/xy2sky.c --- wcstools-3.9.5/xy2sky.c 2017-03-30 15:21:52.000000000 +0000 +++ wcstools-3.9.6/xy2sky.c 2020-05-14 18:03:55.000000000 +0000 @@ -49,7 +49,7 @@ static char printonly = 'n'; static int version = 0; /* If 1, print only program name and version */ -static char *RevMsg = "XY2SKY WCSTools 3.9.5, 30 March 2017, Jessica Mink (jmink@cfa.harvard.edu)"; +static char *RevMsg = "XY2SKY WCSTools 3.9.6, 14 May 2020, Jessica Mink (jmink@cfa.harvard.edu)"; int main (ac, av)
objidradecugriz
1237667536933486968149.96642605419320.056251644430322.4260324.9085724.190524.5558122.69641
1237667536933487753149.9614650012220.055440414092125.8383623.880423.1722122.3471122.00612
1237667536933486881149.95261245900920.044095448416625.2240121.7728420.4771919.2192718.55294