fitsTcl-2.5/Makefile.in0000644000220700000360000002433313133202233013626 0ustar birbylhea# FITS TCL makefile.in # $Id$ #---------------------------------------------------------------------------- # Definitions: #---------------------------------------------------------------------------- LIBRARY = fitstcl CFILES = fitsInit.c fitsUtils.c fitsTcl.c fitsCmds.c fitsIO.c fvTcl.c SHARED_CFILE = tclShared.c OBJECTS = ${CFILES:.c=.o} LOCAL_OBJ = ${OBJECTS} ${SHARED_CFILE:.c=.o} CFITSIO_OBJ_TMP = ${shell if [ -f ${CFITSIO_DIR}/Makefile ]; then ${MAKE} -f ${CFITSIO_DIR}/Makefile cfitsioLibObjs; fi | grep buffers} CFITSIO_OBJ = ${shell if [ "x${CFITSIO_OBJ_TMP}" != "x" ]; then echo ${CFITSIO_OBJ_TMP}; fi | sed "s: : ${CFITSIO_DIR}/:g" | sed "s:^:${CFITSIO_DIR}/:"} SHARED_OBJ = ${LOCAL_OBJ} ${CFITSIO_OBJ} STATIC_LIB = lib${LIBRARY}.a SHARED_LIB = lib${LIBRARY}${SHLIB_SUFFIX} IFLAGS = -I${CFITSIO_DIR} -I${TCL_INC_PATH} -I./ #---------------------------------------------------------------------------- # Configurable macros: #---------------------------------------------------------------------------- INSTALLDIR = @prefix@ CC = @CC@ RANLIB = @RANLIB@ CFLAGS = @CFLAGS@ DEFS = @DEFS@ C_LIB_OPTION = @C_LIB_OPTION@ SHLIB_SUFFIX = @SHLIB_SUFFIX@ SHLIB_LD = @SHLIB_LD@ LD_FLAGS = @LD_FLAGS@ TCL_INC_PATH = @TCL_INC_PATH@ TCL_LIB_PATH = @TCL_PATH@ TCL_LIB = @TCL_LIB@ CFITSIO_DIR = @CFITSIODIR@ SHLIB_LD_LIBS = @LIBS@ @SHLIB_LD_LIBS@ #---------------------------------------------------------------------------- # Targets: #---------------------------------------------------------------------------- all: ${C_LIB_OPTION} static: ${STATIC_LIB} shared: ${SHARED_LIB} ${STATIC_LIB}: ${OBJECTS} rm -f ${STATIC_LIB} ar cr ${STATIC_LIB} ${OBJECTS} ${RANLIB} ${STATIC_LIB} ${SHARED_LIB}: build-cfitsio ${LOCAL_OBJ} @if [ "x${TCL_LIB_PATH}" = x -o "x${TCL_LIB}" = x ]; then \ echo "${SHLIB_LD} ${LD_FLAGS} ${SHARED_OBJ} ${SHLIB_LD_LIBS} -o ${SHARED_LIB}"; \ ${SHLIB_LD} ${LD_FLAGS} ${SHARED_OBJ} ${SHLIB_LD_LIBS} \ -o ${SHARED_LIB}; \ else \ echo "${SHLIB_LD} ${LD_FLAGS} ${SHARED_OBJ} ${SHLIB_LD_LIBS} -L${TCL_LIB_PATH} -l${TCL_LIB} -o ${SHARED_LIB}"; \ ${SHLIB_LD} ${LD_FLAGS} ${SHARED_OBJ} ${SHLIB_LD_LIBS} \ -L${TCL_LIB_PATH} -l${TCL_LIB} -o ${SHARED_LIB}; \ fi build-cfitsio: @if [ "x${CFITSIO_DIR}" != x ]; then \ if [ -d "${CFITSIO_DIR}" ]; then \ if [ ! -f ${CFITSIO_DIR}/buffers.o ]; then \ echo "Configuring and building in ${CFITSIO_DIR}"; \ cd ${CFITSIO_DIR}; ./configure; \ ${MAKE} stand_alone "CC=${CC}" "CFLAGS=${CFLAGS}" \ "FITSIO_OBJ=" "FITSIO_SRC="; \ fi; \ else \ echo "CFITSIO_DIR='${CFITSIO_DIR}' does not exist!"; \ exit 1; \ fi; \ else \ echo "CFITSIO_DIR was not set!"; \ exit 1; \ fi install: all @if [ "x${C_LIB_OPTION}" = xstatic ]; then \ echo "cp ${STATIC_LIB} ${INSTALLDIR}/lib/"; \ cp ${STATIC_LIB} ${INSTALLDIR}/lib/; \ else \ echo "cp ${SHARED_LIB} ${INSTALLDIR}/lib/"; \ cp ${SHARED_LIB} ${INSTALLDIR}/lib/; \ fi clean: -rm -rf ${LOCAL_OBJ} ${STATIC_LIB} ${SHARED_LIB} distclean: clean -rm -f config.cache config.status config.log Makefile so_locations #---------------------------------------------------------------------------- # Make target which outputs the list of the .o contained in the fitsTcl lib # useful to build a single big shared library containing Tcl/Tk and other # extensions. used for the Tcl Plugin. #---------------------------------------------------------------------------- fitstclLibObjs: @echo ${OBJECTS} .c.o: ${CC} -c -o ${ call cfitsio's make clean # makefile.bc5-> suppress many many warnings # # Revision 1.32 1998/09/30 14:20:21 peachey # Set FTOOLS using configure's prefix; this will still be overridden if # fitsTcl is built from within the ftools/tcltk2 Makefile # # Revision 1.31 1998/09/21 16:36:43 pwilson # Make build more portable for new tcl/tk versions # # Revision 1.30 1998/09/16 16:08:14 jxu # point to tcl8.0.3 # # Revision 1.29 1998/08/27 21:40:30 peachey # Umm... remove wcssub.o, but don't fall down if you can't # # Revision 1.28 1998/08/07 17:32:29 elwin # Hack to remove wcssub.o from cfitsio before making shared lib. # # Revision 1.27 1998/08/05 20:34:31 elwin # Quick temporary fixes on the road to itcl3.0 integration. # # Revision 1.26 1998/06/04 12:38:55 peachey # Fix libcfitsio make so it doesn't delete object files, and it excludes the # Fortran wrappers, which are not necessary for this copy of libcfitsio.a # # Revision 1.25 1998/06/03 14:13:41 peachey # Fixed typos from last commit # # Revision 1.24 1998/06/02 19:38:09 peachey # Use cfitsio's native configure and Makefile rather than compile objects # here explicitly. # # Revision 1.23 1997/11/24 20:46:32 elwin # Added compress.c to the cfitsio build stuff # # Revision 1.22 1997/08/27 17:01:08 oneel # cfitsio 1.26b5 # # Revision 1.21 1997/07/11 15:26:03 jxu # add in the new file. # # Revision 1.20 1997/04/04 18:31:13 jxu # add command # get imgwcs # to calculate the world coordinate system parameter for image # # Revision 1.19 1997/03/28 20:14:01 oneel # cfitsio 1.21 update # # Revision 1.18 1997/01/24 19:32:50 oneel # itcl 2.2 changes # # Revision 1.17 1996/12/05 21:45:03 oneel # More fixes to make the new regime work # # Revision 1.16 1996/12/05 21:15:05 oneel # More fixes to make the new regime work # # Revision 1.15 1996/12/05 20:24:54 oneel # More fixes to make the new regiem work # # Revision 1.14 1996/11/04 19:13:59 oneel # AUTHORIZED CHANGES: Opps, screwed up my list of files to build. # # Revision 1.13 1996/11/01 20:26:59 oneel # cfitsio beta update # # Revision 1.12 1996/08/22 17:40:46 oneel # Put back in the shared cflags so that shared libraries build on SunOS # and Solaris # # Revision 1.11 1996/08/22 12:14:24 oneel # Don't require an install on itcl2.1 to build fitsTcl # # Revision 1.10 1996/08/19 21:01:08 jxu # On the ALPHAs, if cfitsio functions are compiled with "gcc -O", then # some column in bin table will give floating exception error. Take "-O" out # for now. # # Revision 1.9 1996/08/19 20:58:08 jxu # On the ALPHAS, long != int. VISU can not hadle long type image, while # most of the images in fits are long type. Simply convert the long to # int in fitstcl. VISU is happy # # Revision 1.8 1996/08/07 16:30:00 oneel # build fixes # # Revision 1.5 1996/07/19 14:41:40 oneel # fitstcl Shared libraries # # Revision 1.4 1996/07/19 13:58:51 oneel # fitstcl Shared libraries # # Revision 1.3 1996/07/18 18:43:36 oneel # itcl 2.1 updates # # Revision 1.2 1996/06/14 14:41:07 oneel # itcl2 updates, both for SunOS 4 and to resync with orig tcltk # # Revision 1.1 1996/06/13 14:00:17 oneel # itcl2 additions # # Revision 3.6 1996/04/23 18:22:52 oneel # Converting to /ftools/vc cvs root # # Revision 1.2 1996/04/04 16:22:14 oneel # Fitstcl Updates, newewst from Jianjun, plus makefile changes to let # irix buildok. # # ftools_query fixes. # # Revision 1.1.1.1 1996/02/20 20:22:10 oneel # tcltk directory import # # Revision 1.5 1996/02/12 18:04:49 oneel # Added CFLAGS to cfitsio compile # # Revision 1.4 1995/10/20 16:18:35 oneel # Changed to not set CFLAGS # # Revision 1.3 1995/08/24 21:52:31 oneel # Changed to use passed in FORTRANLIB # # Revision 1.2 1995/08/18 18:54:29 oneel # Some include and library fixes # # Revision 1.1 1995/08/16 19:30:44 oneel # Initial revision # # fitsTcl-2.5/README0000644000220700000360000000534113133202233012437 0ustar birbylhea fitsTcl Installation Guide fitsTcl is a TCL interface to the CFITSIO astronomical library which provides access to FITS data files. It can be used either by itself within the standard Tcl/Tk applications tclsh and wish, or within the fv software package also distributed by the HEASARC at NASA Goddard. The fitsTcl User's Guide is located in the fitsTcl.html file distributed with fitsTcl and located on the web at: http://heasarc.gsfc.nasa.gov/ftools/fv/fitsTcl.html fitsTcl can be built under PC Linux or Mac OS X, and requires the CFITSIO and Tcl packages. Instructions for building the software are below. Please send any questions or problem reports to the FTOOLS help desk: ftoolshelp@bigbang.gsfc.nasa.gov. Before building fitsTcl, make sure you have Tcl installed on your machine and can locate the tcl.h header file. To build the fitsTcl library: 1. Download the latest version of the cfitsio source code from: http://heasarc.gsfc.nasa.gov/docs/software/fitsio/fitsio.html and unpack the tar file. 2. Unpack the compressed fitsTcl tar file and enter the fitsTcl-2.4 directory. 3. Configure fitsTcl for your system with the command ./configure [optional arguments] where the optional arguments are: --prefix=DIR1 --with-cfitsio=DIR2 --with-tcl-includes=DIR3 DIR1 is the installation path (default is /usr/local) DIR2 is the path to the cfitsio source directory (default is ./cfitsio) DIR3 is the path to the location of the tcl.h header file (default is $prefix/include or /usr/include). These may be considered optional only if the defaults are valid for your system/setup. Under the Cygwin environment, an additional argument is required: --with-tcl=DIR4 DIR4 is the path to the location of the Tcl library (libtcl8.x.dll). The final library will be installed in the directory DIR1/lib which must exist. Note that the library itself does not depend on the value of DIR1, only the installation step in the Makefile. 4. Build fitsTcl with the command make 5. Install fitsTcl either with the command make install which will place it in the DIR1/lib directory, or move the library (libfitstcl.so, or libfitstcl.dylib under Mac OS X) manually to where you want it. To use fitsTcl, startup tclsh or wish and type the command load libfitstcl.so (libfitstcl.dylib on Mac OS X) You may need to specify an explicit path to the library or set the LD_LIBRARY_PATH (DYLD_LIBRARY_PATH on Mac OS X) to its location. fitsTcl-2.5/ReleaseNotes0000644000220700000360000002034614346644255014122 0ustar birbylheaDecember, 2022: Release of fitsTcl v2.5 * Updated for new interface to CFITSIO calculator * Updated configuration ===================================================================== June, 2015: Release of fitsTcl v2.4 * Fix compatibility issues with Tcl 8.5. * Remove dependency on wcslib and repair issues with 'get wcs'. * Fix memory faults when trying to open a FITS file that has a binary table with non-zero variable length array columns but has no rows. * Fix WCS projection for vector image column. * Fix several issues with ASCII output and increase precision in output ASCII file values. ===================================================================== July, 2009: Release of fitsTcl v2.3 (part of fv5.3) * Fix large FITS file crashing and displaying summary/header issue. * Fix opening FITS files in read-only mode issue. ===================================================================== September, 2007: Release of fitsTcl v2.2 (part of fv5.0) * Allow Long Long type (64 bits integer) in Windows. * Allow the switching of different set of WCS (WCSn, where n is a, b, c..) information. * Add routines to extract WCS header information. ===================================================================== July, 2006: Release of fitsTcl v2.1.5 (part of fv4.4) * Fix incorrect calculation of Table array size of a FITS file. ===================================================================== March, 2006: Release of fitsTcl v.2.1.4 (part of fv4.3) * Add region statistical calculation ===================================================================== April 5th, 2005: Release of fitsTcl v.2.1.3 (part of fv4.2) * Change calling routine parameters to cfitsio * Fix TSTRING column length calculation (previous set to 80) ===================================================================== August 9, 2004: Release of fitsTcl v.2.1.2 (part of fv4.1.4) * Fix CAR projection ===================================================================== April 19, 2004: Release of fitsTcl v.2.1.1 (part of fv4.1.2) * Seperate cfitsio package from fitsTcl package. ===================================================================== November 9, 2000: Release of fitsTcl v2.1 (part of fv3.0) * Added smooth command. Currently only supports a boxcar filter. * Added range command. Currently only has a "count" option which takes a range string (eg, 1-4,7,9-) and counts how many rows are included. * Added -rows parameter to "load expr". This allows calculations to be performed on a subset of rows. * Replace fitsTcl's histogramming code with call to CFITSIO's better implementation. Add new command 'histogram' which replaces the 'create 1dhisto' and 'create 2dhisto' and deprecate the latter. New command supports up to 4D histograms and inverse weighting. * Convert fitsObjn entry point to use Tcl_Objs instead of strings. Was able to get full precision data, but lost it when putting it. About half of file commands converted, rest have all parameters converted to strings in fitsDispatch. * Dropped/Ignore numElem parameter to 'put image'. Can get number of elements from data list. * When "put"ting data to a complex column, single numbers will be interpretted as real only... imaginary part is zero * Added an optional rowList parameter to "get vtable" * Added -noformat option to "load tblock", "get table", and "get vtable" so that one can obtain raw values, not formatted strings. * Modified "get image" and "load iblock" routines so that they use native Tcl_Obj's instead of DString's for return values... allows full precision instead of truncated formats in real values->string conversion. * Revised wcs code to support CD matrix keywords and be more general. "-m" flag to 'get wcs' command will return WCS information as... {refVals} {refPix} {matrix} {types} {projections} Old-style keywords will be converted to this. New-style will be converted to old-style in absence of "-m". New-style not limited to 2D images or only 2 columns... can be 1 thru N-dimensions. ======================================================================== February 7, 2000: Release of fitsTcl v2.002 (part of fv2.6 and FTOOLS 5.0) * Modified histogram code so that it writes the column names into the CTYPEn keywords if the columns did not have TCTYPn keywords. * Add optional wcsSwap to return list of 'get wcs' command to flag whether the RA and Dec WCS keywords are swapped with regard to X and Y. Use 'fits option wcsSwap 1|0' to toggle this parameter on or off. (Default: off... old behavior) * Add new 'fits option' command which allows one to alter fitsTcl's default behaviors. * Cast all argv's to "char *const[]" to protect them from accidental modification. * Modify 'load image' to conform to vtable/column's default NULL handling... NULLS are converted to datatype_MAX. Formerly converted to -1. * Modify 'load vtable' to accept a default Null parameter. This breaks backwards compatibility (it used to take a vector column width at the same position, but ignored in v2.0). * Modify 'get wcs' defaults to match CFITSIO's new implementation of them: 1.0 for xinc/yinc and 0.0 for all others. Keep ctype='none', although CFITSIO uses a null string. ======================================================================== July 28, 1999: Release of fitsTcl v2.0 * Major rewrite of internal code, while keeping as backwards compatible as possible with last fv release. Update documentation and create this Release Notes document. * Change method of passing address pointers... Instead of using %ld to read and write addresses to/from strings, use the much more appropriate %p format. NOTE: This is *NOT* compatible with %ld formats. You must change any code dependent on fitsTcl in this regard! (Or change all '%p' strings in fitsTcl back to '%ld'.) * Drop 'get imageblock' which was actually identical to 'load iblock'. 'get' commands should return lists of data, which 'get imageblock' did not. (Still exists for backwards compatibility, but removed from docs.) * Add new 'get image' command which returns list of data from an image array. * Rename 'put ihd/ahd/bhd' to 'insert image/table' which makes more sense. New version drops the numCols parameter and allows some parameters to be empty. (Again, old commands still exist but undocumented.) * Make many more trailing parameters optional * Convert some series of parameters to lists (eg, 'get keyword keyName ...' becomes 'get keyword keyList') * Add/improve support for long keywords using new HIERARCH notation. * Eliminate (ignore if present) the object type parameter from the 'free' command and accept a list of addresses to free. * Add general 'fits free addList' command to replace the fitsObj-dependent free command. * Add 'fits version' command to get fitsTcl and cfitsio version numbers. * Replace 'get imgwcs' and 'get colwcs' with a single 'get wcs' command which behaves appropriately based on the CHDU type. Error-handling behavior (ie, use of default values) is consistent, unlike the separate versions. (Old commands exist, but undocumntd.) * Add 2 new commands for creating/reading 'load'ed data: lst2ptr and ptr2lst. The former takes a TCL list and creates a pointer able to be passed to C code (eg, POW). The latter reverses the conversion, taking a pointer and producing a TCL list. * Add new vector math command: vexpr. It takes a C-style arithmetic expression and evaluates it in the context of TCL lists (or fitsTcl pointers). Returns results as either a TCL list or fitsTcl pointer. ======================================================================== Apr 30, 1999: Release of fv v2.5 (unnumbered fitsTcl included) ======================================================================== NovDec, 1998: Release of FTOOLS v4.2 and fv v2.4 (unnumbered fitsTcl included) ======================================================================== ??? ??, 1997: Release of fitsTcl v1.0 fitsTcl-2.5/config.guess0000755000220700000360000014044614214134036014113 0ustar birbylhea#! /bin/sh # Attempt to guess a canonical system name. # Copyright 1992-2021 Free Software Foundation, Inc. timestamp='2021-01-25' # This file 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 3 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, see . # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that # program. This Exception is an additional permission under section 7 # of the GNU General Public License, version 3 ("GPLv3"). # # Originally written by Per Bothner; maintained since 2000 by Ben Elliston. # # You can get the latest version of this script from: # https://git.savannah.gnu.org/cgit/config.git/plain/config.guess # # Please send patches to . me=$(echo "$0" | sed -e 's,.*/,,') usage="\ Usage: $0 [OPTION] Output the configuration name of the system \`$me' is run on. Options: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit Report bugs and patches to ." version="\ GNU config.guess ($timestamp) Originally written by Per Bothner. Copyright 1992-2021 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." help=" Try \`$me --help' for more information." # Parse command line while test $# -gt 0 ; do case $1 in --time-stamp | --time* | -t ) echo "$timestamp" ; exit ;; --version | -v ) echo "$version" ; exit ;; --help | --h* | -h ) echo "$usage"; exit ;; -- ) # Stop option processing shift; break ;; - ) # Use stdin as input. break ;; -* ) echo "$me: invalid option $1$help" >&2 exit 1 ;; * ) break ;; esac done if test $# != 0; then echo "$me: too many arguments$help" >&2 exit 1 fi # CC_FOR_BUILD -- compiler used by this script. Note that the use of a # compiler to aid in system detection is discouraged as it requires # temporary files to be created and, as you can see below, it is a # headache to deal with in a portable fashion. # Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still # use `HOST_CC' if defined, but it is deprecated. # Portable tmp directory creation inspired by the Autoconf team. tmp= # shellcheck disable=SC2172 trap 'test -z "$tmp" || rm -fr "$tmp"' 0 1 2 13 15 set_cc_for_build() { # prevent multiple calls if $tmp is already set test "$tmp" && return 0 : "${TMPDIR=/tmp}" # shellcheck disable=SC2039 { tmp=$( (umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null) && test -n "$tmp" && test -d "$tmp" ; } || { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir "$tmp" 2>/dev/null) ; } || { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir "$tmp" 2>/dev/null) && echo "Warning: creating insecure temp directory" >&2 ; } || { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } dummy=$tmp/dummy case ${CC_FOR_BUILD-},${HOST_CC-},${CC-} in ,,) echo "int x;" > "$dummy.c" for driver in cc gcc c89 c99 ; do if ($driver -c -o "$dummy.o" "$dummy.c") >/dev/null 2>&1 ; then CC_FOR_BUILD="$driver" break fi done if test x"$CC_FOR_BUILD" = x ; then CC_FOR_BUILD=no_compiler_found fi ;; ,,*) CC_FOR_BUILD=$CC ;; ,*,*) CC_FOR_BUILD=$HOST_CC ;; esac } # This is needed to find uname on a Pyramid OSx when run in the BSD universe. # (ghazi@noc.rutgers.edu 1994-08-24) if test -f /.attbin/uname ; then PATH=$PATH:/.attbin ; export PATH fi UNAME_MACHINE=$( (uname -m) 2>/dev/null) || UNAME_MACHINE=unknown UNAME_RELEASE=$( (uname -r) 2>/dev/null) || UNAME_RELEASE=unknown UNAME_SYSTEM=$( (uname -s) 2>/dev/null) || UNAME_SYSTEM=unknown UNAME_VERSION=$( (uname -v) 2>/dev/null) || UNAME_VERSION=unknown case "$UNAME_SYSTEM" in Linux|GNU|GNU/*) LIBC=unknown set_cc_for_build cat <<-EOF > "$dummy.c" #include #if defined(__UCLIBC__) LIBC=uclibc #elif defined(__dietlibc__) LIBC=dietlibc #elif defined(__GLIBC__) LIBC=gnu #else #include /* First heuristic to detect musl libc. */ #ifdef __DEFINED_va_list LIBC=musl #endif #endif EOF eval "$($CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g')" # Second heuristic to detect musl libc. if [ "$LIBC" = unknown ] && command -v ldd >/dev/null && ldd --version 2>&1 | grep -q ^musl; then LIBC=musl fi # If the system lacks a compiler, then just pick glibc. # We could probably try harder. if [ "$LIBC" = unknown ]; then LIBC=gnu fi ;; esac # Note: order is significant - the case branches are not exclusive. case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in *:NetBSD:*:*) # NetBSD (nbsd) targets should (where applicable) match one or # more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*, # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently # switched to ELF, *-*-netbsd* would select the old # object file format. This provides both forward # compatibility and a consistent mechanism for selecting the # object file format. # # Note: NetBSD doesn't particularly care about the vendor # portion of the name. We always set it to "unknown". UNAME_MACHINE_ARCH=$( (uname -p 2>/dev/null || \ /sbin/sysctl -n hw.machine_arch 2>/dev/null || \ /usr/sbin/sysctl -n hw.machine_arch 2>/dev/null || \ echo unknown)) case "$UNAME_MACHINE_ARCH" in aarch64eb) machine=aarch64_be-unknown ;; armeb) machine=armeb-unknown ;; arm*) machine=arm-unknown ;; sh3el) machine=shl-unknown ;; sh3eb) machine=sh-unknown ;; sh5el) machine=sh5le-unknown ;; earmv*) arch=$(echo "$UNAME_MACHINE_ARCH" | sed -e 's,^e\(armv[0-9]\).*$,\1,') endian=$(echo "$UNAME_MACHINE_ARCH" | sed -ne 's,^.*\(eb\)$,\1,p') machine="${arch}${endian}"-unknown ;; *) machine="$UNAME_MACHINE_ARCH"-unknown ;; esac # The Operating System including object format, if it has switched # to ELF recently (or will in the future) and ABI. case "$UNAME_MACHINE_ARCH" in earm*) os=netbsdelf ;; arm*|i386|m68k|ns32k|sh3*|sparc|vax) set_cc_for_build if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ELF__ then # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). # Return netbsd for either. FIX? os=netbsd else os=netbsdelf fi ;; *) os=netbsd ;; esac # Determine ABI tags. case "$UNAME_MACHINE_ARCH" in earm*) expr='s/^earmv[0-9]/-eabi/;s/eb$//' abi=$(echo "$UNAME_MACHINE_ARCH" | sed -e "$expr") ;; esac # The OS release # Debian GNU/NetBSD machines have a different userland, and # thus, need a distinct triplet. However, they do not need # kernel version information, so it can be replaced with a # suitable tag, in the style of linux-gnu. case "$UNAME_VERSION" in Debian*) release='-gnu' ;; *) release=$(echo "$UNAME_RELEASE" | sed -e 's/[-_].*//' | cut -d. -f1,2) ;; esac # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: # contains redundant information, the shorter form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. echo "$machine-${os}${release}${abi-}" exit ;; *:Bitrig:*:*) UNAME_MACHINE_ARCH=$(arch | sed 's/Bitrig.//') echo "$UNAME_MACHINE_ARCH"-unknown-bitrig"$UNAME_RELEASE" exit ;; *:OpenBSD:*:*) UNAME_MACHINE_ARCH=$(arch | sed 's/OpenBSD.//') echo "$UNAME_MACHINE_ARCH"-unknown-openbsd"$UNAME_RELEASE" exit ;; *:LibertyBSD:*:*) UNAME_MACHINE_ARCH=$(arch | sed 's/^.*BSD\.//') echo "$UNAME_MACHINE_ARCH"-unknown-libertybsd"$UNAME_RELEASE" exit ;; *:MidnightBSD:*:*) echo "$UNAME_MACHINE"-unknown-midnightbsd"$UNAME_RELEASE" exit ;; *:ekkoBSD:*:*) echo "$UNAME_MACHINE"-unknown-ekkobsd"$UNAME_RELEASE" exit ;; *:SolidBSD:*:*) echo "$UNAME_MACHINE"-unknown-solidbsd"$UNAME_RELEASE" exit ;; *:OS108:*:*) echo "$UNAME_MACHINE"-unknown-os108_"$UNAME_RELEASE" exit ;; macppc:MirBSD:*:*) echo powerpc-unknown-mirbsd"$UNAME_RELEASE" exit ;; *:MirBSD:*:*) echo "$UNAME_MACHINE"-unknown-mirbsd"$UNAME_RELEASE" exit ;; *:Sortix:*:*) echo "$UNAME_MACHINE"-unknown-sortix exit ;; *:Twizzler:*:*) echo "$UNAME_MACHINE"-unknown-twizzler exit ;; *:Redox:*:*) echo "$UNAME_MACHINE"-unknown-redox exit ;; mips:OSF1:*.*) echo mips-dec-osf1 exit ;; alpha:OSF1:*:*) case $UNAME_RELEASE in *4.0) UNAME_RELEASE=$(/usr/sbin/sizer -v | awk '{print $3}') ;; *5.*) UNAME_RELEASE=$(/usr/sbin/sizer -v | awk '{print $4}') ;; esac # According to Compaq, /usr/sbin/psrinfo has been available on # OSF/1 and Tru64 systems produced since 1995. I hope that # covers most systems running today. This code pipes the CPU # types through head -n 1, so we only detect the type of CPU 0. ALPHA_CPU_TYPE=$(/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1) case "$ALPHA_CPU_TYPE" in "EV4 (21064)") UNAME_MACHINE=alpha ;; "EV4.5 (21064)") UNAME_MACHINE=alpha ;; "LCA4 (21066/21068)") UNAME_MACHINE=alpha ;; "EV5 (21164)") UNAME_MACHINE=alphaev5 ;; "EV5.6 (21164A)") UNAME_MACHINE=alphaev56 ;; "EV5.6 (21164PC)") UNAME_MACHINE=alphapca56 ;; "EV5.7 (21164PC)") UNAME_MACHINE=alphapca57 ;; "EV6 (21264)") UNAME_MACHINE=alphaev6 ;; "EV6.7 (21264A)") UNAME_MACHINE=alphaev67 ;; "EV6.8CB (21264C)") UNAME_MACHINE=alphaev68 ;; "EV6.8AL (21264B)") UNAME_MACHINE=alphaev68 ;; "EV6.8CX (21264D)") UNAME_MACHINE=alphaev68 ;; "EV6.9A (21264/EV69A)") UNAME_MACHINE=alphaev69 ;; "EV7 (21364)") UNAME_MACHINE=alphaev7 ;; "EV7.9 (21364A)") UNAME_MACHINE=alphaev79 ;; esac # A Pn.n version is a patched version. # A Vn.n version is a released version. # A Tn.n version is a released field test version. # A Xn.n version is an unreleased experimental baselevel. # 1.2 uses "1.2" for uname -r. echo "$UNAME_MACHINE"-dec-osf"$(echo "$UNAME_RELEASE" | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz)" # Reset EXIT trap before exiting to avoid spurious non-zero exit code. exitcode=$? trap '' 0 exit $exitcode ;; Amiga*:UNIX_System_V:4.0:*) echo m68k-unknown-sysv4 exit ;; *:[Aa]miga[Oo][Ss]:*:*) echo "$UNAME_MACHINE"-unknown-amigaos exit ;; *:[Mm]orph[Oo][Ss]:*:*) echo "$UNAME_MACHINE"-unknown-morphos exit ;; *:OS/390:*:*) echo i370-ibm-openedition exit ;; *:z/VM:*:*) echo s390-ibm-zvmoe exit ;; *:OS400:*:*) echo powerpc-ibm-os400 exit ;; arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) echo arm-acorn-riscix"$UNAME_RELEASE" exit ;; arm*:riscos:*:*|arm*:RISCOS:*:*) echo arm-unknown-riscos exit ;; SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) echo hppa1.1-hitachi-hiuxmpp exit ;; Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. if test "$( (/bin/universe) 2>/dev/null)" = att ; then echo pyramid-pyramid-sysv3 else echo pyramid-pyramid-bsd fi exit ;; NILE*:*:*:dcosx) echo pyramid-pyramid-svr4 exit ;; DRS?6000:unix:4.0:6*) echo sparc-icl-nx6 exit ;; DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) case $(/usr/bin/uname -p) in sparc) echo sparc-icl-nx7; exit ;; esac ;; s390x:SunOS:*:*) echo "$UNAME_MACHINE"-ibm-solaris2"$(echo "$UNAME_RELEASE" | sed -e 's/[^.]*//')" exit ;; sun4H:SunOS:5.*:*) echo sparc-hal-solaris2"$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*//')" exit ;; sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) echo sparc-sun-solaris2"$(echo "$UNAME_RELEASE" | sed -e 's/[^.]*//')" exit ;; i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*) echo i386-pc-auroraux"$UNAME_RELEASE" exit ;; i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) set_cc_for_build SUN_ARCH=i386 # If there is a compiler, see if it is configured for 64-bit objects. # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. # This test works for both compilers. if test "$CC_FOR_BUILD" != no_compiler_found; then if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \ (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ grep IS_64BIT_ARCH >/dev/null then SUN_ARCH=x86_64 fi fi echo "$SUN_ARCH"-pc-solaris2"$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*//')" exit ;; sun4*:SunOS:6*:*) # According to config.sub, this is the proper way to canonicalize # SunOS6. Hard to guess exactly what SunOS6 will be like, but # it's likely to be more like Solaris than SunOS4. echo sparc-sun-solaris3"$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*//')" exit ;; sun4*:SunOS:*:*) case "$(/usr/bin/arch -k)" in Series*|S4*) UNAME_RELEASE=$(uname -v) ;; esac # Japanese Language versions have a version number like `4.1.3-JL'. echo sparc-sun-sunos"$(echo "$UNAME_RELEASE"|sed -e 's/-/_/')" exit ;; sun3*:SunOS:*:*) echo m68k-sun-sunos"$UNAME_RELEASE" exit ;; sun*:*:4.2BSD:*) UNAME_RELEASE=$( (sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null) test "x$UNAME_RELEASE" = x && UNAME_RELEASE=3 case "$(/bin/arch)" in sun3) echo m68k-sun-sunos"$UNAME_RELEASE" ;; sun4) echo sparc-sun-sunos"$UNAME_RELEASE" ;; esac exit ;; aushp:SunOS:*:*) echo sparc-auspex-sunos"$UNAME_RELEASE" exit ;; # The situation for MiNT is a little confusing. The machine name # can be virtually everything (everything which is not # "atarist" or "atariste" at least should have a processor # > m68000). The system name ranges from "MiNT" over "FreeMiNT" # to the lowercase version "mint" (or "freemint"). Finally # the system name "TOS" denotes a system which is actually not # MiNT. But MiNT is downward compatible to TOS, so this should # be no problem. atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) echo m68k-atari-mint"$UNAME_RELEASE" exit ;; atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) echo m68k-atari-mint"$UNAME_RELEASE" exit ;; *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) echo m68k-atari-mint"$UNAME_RELEASE" exit ;; milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) echo m68k-milan-mint"$UNAME_RELEASE" exit ;; hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) echo m68k-hades-mint"$UNAME_RELEASE" exit ;; *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) echo m68k-unknown-mint"$UNAME_RELEASE" exit ;; m68k:machten:*:*) echo m68k-apple-machten"$UNAME_RELEASE" exit ;; powerpc:machten:*:*) echo powerpc-apple-machten"$UNAME_RELEASE" exit ;; RISC*:Mach:*:*) echo mips-dec-mach_bsd4.3 exit ;; RISC*:ULTRIX:*:*) echo mips-dec-ultrix"$UNAME_RELEASE" exit ;; VAX*:ULTRIX*:*:*) echo vax-dec-ultrix"$UNAME_RELEASE" exit ;; 2020:CLIX:*:* | 2430:CLIX:*:*) echo clipper-intergraph-clix"$UNAME_RELEASE" exit ;; mips:*:*:UMIPS | mips:*:*:RISCos) set_cc_for_build sed 's/^ //' << EOF > "$dummy.c" #ifdef __cplusplus #include /* for printf() prototype */ int main (int argc, char *argv[]) { #else int main (argc, argv) int argc; char *argv[]; { #endif #if defined (host_mips) && defined (MIPSEB) #if defined (SYSTYPE_SYSV) printf ("mips-mips-riscos%ssysv\\n", argv[1]); exit (0); #endif #if defined (SYSTYPE_SVR4) printf ("mips-mips-riscos%ssvr4\\n", argv[1]); exit (0); #endif #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) printf ("mips-mips-riscos%sbsd\\n", argv[1]); exit (0); #endif #endif exit (-1); } EOF $CC_FOR_BUILD -o "$dummy" "$dummy.c" && dummyarg=$(echo "$UNAME_RELEASE" | sed -n 's/\([0-9]*\).*/\1/p') && SYSTEM_NAME=$("$dummy" "$dummyarg") && { echo "$SYSTEM_NAME"; exit; } echo mips-mips-riscos"$UNAME_RELEASE" exit ;; Motorola:PowerMAX_OS:*:*) echo powerpc-motorola-powermax exit ;; Motorola:*:4.3:PL8-*) echo powerpc-harris-powermax exit ;; Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) echo powerpc-harris-powermax exit ;; Night_Hawk:Power_UNIX:*:*) echo powerpc-harris-powerunix exit ;; m88k:CX/UX:7*:*) echo m88k-harris-cxux7 exit ;; m88k:*:4*:R4*) echo m88k-motorola-sysv4 exit ;; m88k:*:3*:R3*) echo m88k-motorola-sysv3 exit ;; AViiON:dgux:*:*) # DG/UX returns AViiON for all architectures UNAME_PROCESSOR=$(/usr/bin/uname -p) if test "$UNAME_PROCESSOR" = mc88100 || test "$UNAME_PROCESSOR" = mc88110 then if test "$TARGET_BINARY_INTERFACE"x = m88kdguxelfx || \ test "$TARGET_BINARY_INTERFACE"x = x then echo m88k-dg-dgux"$UNAME_RELEASE" else echo m88k-dg-dguxbcs"$UNAME_RELEASE" fi else echo i586-dg-dgux"$UNAME_RELEASE" fi exit ;; M88*:DolphinOS:*:*) # DolphinOS (SVR3) echo m88k-dolphin-sysv3 exit ;; M88*:*:R3*:*) # Delta 88k system running SVR3 echo m88k-motorola-sysv3 exit ;; XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) echo m88k-tektronix-sysv3 exit ;; Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) echo m68k-tektronix-bsd exit ;; *:IRIX*:*:*) echo mips-sgi-irix"$(echo "$UNAME_RELEASE"|sed -e 's/-/_/g')" exit ;; ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id exit ;; # Note that: echo "'$(uname -s)'" gives 'AIX ' i*86:AIX:*:*) echo i386-ibm-aix exit ;; ia64:AIX:*:*) if test -x /usr/bin/oslevel ; then IBM_REV=$(/usr/bin/oslevel) else IBM_REV="$UNAME_VERSION.$UNAME_RELEASE" fi echo "$UNAME_MACHINE"-ibm-aix"$IBM_REV" exit ;; *:AIX:2:3) if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then set_cc_for_build sed 's/^ //' << EOF > "$dummy.c" #include main() { if (!__power_pc()) exit(1); puts("powerpc-ibm-aix3.2.5"); exit(0); } EOF if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=$("$dummy") then echo "$SYSTEM_NAME" else echo rs6000-ibm-aix3.2.5 fi elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then echo rs6000-ibm-aix3.2.4 else echo rs6000-ibm-aix3.2 fi exit ;; *:AIX:*:[4567]) IBM_CPU_ID=$(/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }') if /usr/sbin/lsattr -El "$IBM_CPU_ID" | grep ' POWER' >/dev/null 2>&1; then IBM_ARCH=rs6000 else IBM_ARCH=powerpc fi if test -x /usr/bin/lslpp ; then IBM_REV=$(/usr/bin/lslpp -Lqc bos.rte.libc | awk -F: '{ print $3 }' | sed s/[0-9]*$/0/) else IBM_REV="$UNAME_VERSION.$UNAME_RELEASE" fi echo "$IBM_ARCH"-ibm-aix"$IBM_REV" exit ;; *:AIX:*:*) echo rs6000-ibm-aix exit ;; ibmrt:4.4BSD:*|romp-ibm:4.4BSD:*) echo romp-ibm-bsd4.4 exit ;; ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and echo romp-ibm-bsd"$UNAME_RELEASE" # 4.3 with uname added to exit ;; # report: romp-ibm BSD 4.3 *:BOSX:*:*) echo rs6000-bull-bosx exit ;; DPX/2?00:B.O.S.:*:*) echo m68k-bull-sysv3 exit ;; 9000/[34]??:4.3bsd:1.*:*) echo m68k-hp-bsd exit ;; hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) echo m68k-hp-bsd4.4 exit ;; 9000/[34678]??:HP-UX:*:*) HPUX_REV=$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*.[0B]*//') case "$UNAME_MACHINE" in 9000/31?) HP_ARCH=m68000 ;; 9000/[34]??) HP_ARCH=m68k ;; 9000/[678][0-9][0-9]) if test -x /usr/bin/getconf; then sc_cpu_version=$(/usr/bin/getconf SC_CPU_VERSION 2>/dev/null) sc_kernel_bits=$(/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null) case "$sc_cpu_version" in 523) HP_ARCH=hppa1.0 ;; # CPU_PA_RISC1_0 528) HP_ARCH=hppa1.1 ;; # CPU_PA_RISC1_1 532) # CPU_PA_RISC2_0 case "$sc_kernel_bits" in 32) HP_ARCH=hppa2.0n ;; 64) HP_ARCH=hppa2.0w ;; '') HP_ARCH=hppa2.0 ;; # HP-UX 10.20 esac ;; esac fi if test "$HP_ARCH" = ""; then set_cc_for_build sed 's/^ //' << EOF > "$dummy.c" #define _HPUX_SOURCE #include #include int main () { #if defined(_SC_KERNEL_BITS) long bits = sysconf(_SC_KERNEL_BITS); #endif long cpu = sysconf (_SC_CPU_VERSION); switch (cpu) { case CPU_PA_RISC1_0: puts ("hppa1.0"); break; case CPU_PA_RISC1_1: puts ("hppa1.1"); break; case CPU_PA_RISC2_0: #if defined(_SC_KERNEL_BITS) switch (bits) { case 64: puts ("hppa2.0w"); break; case 32: puts ("hppa2.0n"); break; default: puts ("hppa2.0"); break; } break; #else /* !defined(_SC_KERNEL_BITS) */ puts ("hppa2.0"); break; #endif default: puts ("hppa1.0"); break; } exit (0); } EOF (CCOPTS="" $CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null) && HP_ARCH=$("$dummy") test -z "$HP_ARCH" && HP_ARCH=hppa fi ;; esac if test "$HP_ARCH" = hppa2.0w then set_cc_for_build # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler # generating 64-bit code. GNU and HP use different nomenclature: # # $ CC_FOR_BUILD=cc ./config.guess # => hppa2.0w-hp-hpux11.23 # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess # => hppa64-hp-hpux11.23 if echo __LP64__ | (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | grep -q __LP64__ then HP_ARCH=hppa2.0w else HP_ARCH=hppa64 fi fi echo "$HP_ARCH"-hp-hpux"$HPUX_REV" exit ;; ia64:HP-UX:*:*) HPUX_REV=$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*.[0B]*//') echo ia64-hp-hpux"$HPUX_REV" exit ;; 3050*:HI-UX:*:*) set_cc_for_build sed 's/^ //' << EOF > "$dummy.c" #include int main () { long cpu = sysconf (_SC_CPU_VERSION); /* The order matters, because CPU_IS_HP_MC68K erroneously returns true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct results, however. */ if (CPU_IS_PA_RISC (cpu)) { switch (cpu) { case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; default: puts ("hppa-hitachi-hiuxwe2"); break; } } else if (CPU_IS_HP_MC68K (cpu)) puts ("m68k-hitachi-hiuxwe2"); else puts ("unknown-hitachi-hiuxwe2"); exit (0); } EOF $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=$("$dummy") && { echo "$SYSTEM_NAME"; exit; } echo unknown-hitachi-hiuxwe2 exit ;; 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:*) echo hppa1.1-hp-bsd exit ;; 9000/8??:4.3bsd:*:*) echo hppa1.0-hp-bsd exit ;; *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) echo hppa1.0-hp-mpeix exit ;; hp7??:OSF1:*:* | hp8?[79]:OSF1:*:*) echo hppa1.1-hp-osf exit ;; hp8??:OSF1:*:*) echo hppa1.0-hp-osf exit ;; i*86:OSF1:*:*) if test -x /usr/sbin/sysversion ; then echo "$UNAME_MACHINE"-unknown-osf1mk else echo "$UNAME_MACHINE"-unknown-osf1 fi exit ;; parisc*:Lites*:*:*) echo hppa1.1-hp-lites exit ;; C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) echo c1-convex-bsd exit ;; C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) if getsysinfo -f scalar_acc then echo c32-convex-bsd else echo c2-convex-bsd fi exit ;; C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) echo c34-convex-bsd exit ;; C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) echo c38-convex-bsd exit ;; C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) echo c4-convex-bsd exit ;; CRAY*Y-MP:*:*:*) echo ymp-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*[A-Z]90:*:*:*) echo "$UNAME_MACHINE"-cray-unicos"$UNAME_RELEASE" \ | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ -e 's/\.[^.]*$/.X/' exit ;; CRAY*TS:*:*:*) echo t90-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*T3E:*:*:*) echo alphaev5-cray-unicosmk"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*SV1:*:*:*) echo sv1-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' exit ;; *:UNICOS/mp:*:*) echo craynv-cray-unicosmp"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' exit ;; F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) FUJITSU_PROC=$(uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz) FUJITSU_SYS=$(uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///') FUJITSU_REL=$(echo "$UNAME_RELEASE" | sed -e 's/ /_/') echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit ;; 5000:UNIX_System_V:4.*:*) FUJITSU_SYS=$(uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///') FUJITSU_REL=$(echo "$UNAME_RELEASE" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/') echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit ;; i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) echo "$UNAME_MACHINE"-pc-bsdi"$UNAME_RELEASE" exit ;; sparc*:BSD/OS:*:*) echo sparc-unknown-bsdi"$UNAME_RELEASE" exit ;; *:BSD/OS:*:*) echo "$UNAME_MACHINE"-unknown-bsdi"$UNAME_RELEASE" exit ;; arm:FreeBSD:*:*) UNAME_PROCESSOR=$(uname -p) set_cc_for_build if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_PCS_VFP then echo "${UNAME_PROCESSOR}"-unknown-freebsd"$(echo ${UNAME_RELEASE}|sed -e 's/[-(].*//')"-gnueabi else echo "${UNAME_PROCESSOR}"-unknown-freebsd"$(echo ${UNAME_RELEASE}|sed -e 's/[-(].*//')"-gnueabihf fi exit ;; *:FreeBSD:*:*) UNAME_PROCESSOR=$(/usr/bin/uname -p) case "$UNAME_PROCESSOR" in amd64) UNAME_PROCESSOR=x86_64 ;; i386) UNAME_PROCESSOR=i586 ;; esac echo "$UNAME_PROCESSOR"-unknown-freebsd"$(echo "$UNAME_RELEASE"|sed -e 's/[-(].*//')" exit ;; i*:CYGWIN*:*) echo "$UNAME_MACHINE"-pc-cygwin exit ;; *:MINGW64*:*) echo "$UNAME_MACHINE"-pc-mingw64 exit ;; *:MINGW*:*) echo "$UNAME_MACHINE"-pc-mingw32 exit ;; *:MSYS*:*) echo "$UNAME_MACHINE"-pc-msys exit ;; i*:PW*:*) echo "$UNAME_MACHINE"-pc-pw32 exit ;; *:Interix*:*) case "$UNAME_MACHINE" in x86) echo i586-pc-interix"$UNAME_RELEASE" exit ;; authenticamd | genuineintel | EM64T) echo x86_64-unknown-interix"$UNAME_RELEASE" exit ;; IA64) echo ia64-unknown-interix"$UNAME_RELEASE" exit ;; esac ;; i*:UWIN*:*) echo "$UNAME_MACHINE"-pc-uwin exit ;; amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) echo x86_64-pc-cygwin exit ;; prep*:SunOS:5.*:*) echo powerpcle-unknown-solaris2"$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*//')" exit ;; *:GNU:*:*) # the GNU system echo "$(echo "$UNAME_MACHINE"|sed -e 's,[-/].*$,,')-unknown-$LIBC$(echo "$UNAME_RELEASE"|sed -e 's,/.*$,,')" exit ;; *:GNU/*:*:*) # other systems with GNU libc and userland echo "$UNAME_MACHINE-unknown-$(echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]")$(echo "$UNAME_RELEASE"|sed -e 's/[-(].*//')-$LIBC" exit ;; *:Minix:*:*) echo "$UNAME_MACHINE"-unknown-minix exit ;; aarch64:Linux:*:*) echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; aarch64_be:Linux:*:*) UNAME_MACHINE=aarch64_be echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; alpha:Linux:*:*) case $(sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' /proc/cpuinfo 2>/dev/null) in EV5) UNAME_MACHINE=alphaev5 ;; EV56) UNAME_MACHINE=alphaev56 ;; PCA56) UNAME_MACHINE=alphapca56 ;; PCA57) UNAME_MACHINE=alphapca56 ;; EV6) UNAME_MACHINE=alphaev6 ;; EV67) UNAME_MACHINE=alphaev67 ;; EV68*) UNAME_MACHINE=alphaev68 ;; esac objdump --private-headers /bin/sh | grep -q ld.so.1 if test "$?" = 0 ; then LIBC=gnulibc1 ; fi echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; arc:Linux:*:* | arceb:Linux:*:*) echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; arm*:Linux:*:*) set_cc_for_build if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_EABI__ then echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" else if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_PCS_VFP then echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"eabi else echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"eabihf fi fi exit ;; avr32*:Linux:*:*) echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; cris:Linux:*:*) echo "$UNAME_MACHINE"-axis-linux-"$LIBC" exit ;; crisv32:Linux:*:*) echo "$UNAME_MACHINE"-axis-linux-"$LIBC" exit ;; e2k:Linux:*:*) echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; frv:Linux:*:*) echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; hexagon:Linux:*:*) echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; i*86:Linux:*:*) echo "$UNAME_MACHINE"-pc-linux-"$LIBC" exit ;; ia64:Linux:*:*) echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; k1om:Linux:*:*) echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; loongarch32:Linux:*:* | loongarch64:Linux:*:* | loongarchx32:Linux:*:*) echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; m32r*:Linux:*:*) echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; m68*:Linux:*:*) echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; mips:Linux:*:* | mips64:Linux:*:*) set_cc_for_build IS_GLIBC=0 test x"${LIBC}" = xgnu && IS_GLIBC=1 sed 's/^ //' << EOF > "$dummy.c" #undef CPU #undef mips #undef mipsel #undef mips64 #undef mips64el #if ${IS_GLIBC} && defined(_ABI64) LIBCABI=gnuabi64 #else #if ${IS_GLIBC} && defined(_ABIN32) LIBCABI=gnuabin32 #else LIBCABI=${LIBC} #endif #endif #if ${IS_GLIBC} && defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 CPU=mipsisa64r6 #else #if ${IS_GLIBC} && !defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 CPU=mipsisa32r6 #else #if defined(__mips64) CPU=mips64 #else CPU=mips #endif #endif #endif #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) MIPS_ENDIAN=el #else #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) MIPS_ENDIAN= #else MIPS_ENDIAN= #endif #endif EOF eval "$($CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU\|^MIPS_ENDIAN\|^LIBCABI')" test "x$CPU" != x && { echo "$CPU${MIPS_ENDIAN}-unknown-linux-$LIBCABI"; exit; } ;; mips64el:Linux:*:*) echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; openrisc*:Linux:*:*) echo or1k-unknown-linux-"$LIBC" exit ;; or32:Linux:*:* | or1k*:Linux:*:*) echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; padre:Linux:*:*) echo sparc-unknown-linux-"$LIBC" exit ;; parisc64:Linux:*:* | hppa64:Linux:*:*) echo hppa64-unknown-linux-"$LIBC" exit ;; parisc:Linux:*:* | hppa:Linux:*:*) # Look for CPU level case $(grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2) in PA7*) echo hppa1.1-unknown-linux-"$LIBC" ;; PA8*) echo hppa2.0-unknown-linux-"$LIBC" ;; *) echo hppa-unknown-linux-"$LIBC" ;; esac exit ;; ppc64:Linux:*:*) echo powerpc64-unknown-linux-"$LIBC" exit ;; ppc:Linux:*:*) echo powerpc-unknown-linux-"$LIBC" exit ;; ppc64le:Linux:*:*) echo powerpc64le-unknown-linux-"$LIBC" exit ;; ppcle:Linux:*:*) echo powerpcle-unknown-linux-"$LIBC" exit ;; riscv32:Linux:*:* | riscv32be:Linux:*:* | riscv64:Linux:*:* | riscv64be:Linux:*:*) echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; s390:Linux:*:* | s390x:Linux:*:*) echo "$UNAME_MACHINE"-ibm-linux-"$LIBC" exit ;; sh64*:Linux:*:*) echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; sh*:Linux:*:*) echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; sparc:Linux:*:* | sparc64:Linux:*:*) echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; tile*:Linux:*:*) echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; vax:Linux:*:*) echo "$UNAME_MACHINE"-dec-linux-"$LIBC" exit ;; x86_64:Linux:*:*) set_cc_for_build LIBCABI=$LIBC if test "$CC_FOR_BUILD" != no_compiler_found; then if (echo '#ifdef __ILP32__'; echo IS_X32; echo '#endif') | \ (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ grep IS_X32 >/dev/null then LIBCABI="$LIBC"x32 fi fi echo "$UNAME_MACHINE"-pc-linux-"$LIBCABI" exit ;; xtensa*:Linux:*:*) echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; i*86:DYNIX/ptx:4*:*) # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. # earlier versions are messed up and put the nodename in both # sysname and nodename. echo i386-sequent-sysv4 exit ;; i*86:UNIX_SV:4.2MP:2.*) # Unixware is an offshoot of SVR4, but it has its own version # number series starting with 2... # I am not positive that other SVR4 systems won't match this, # I just have to hope. -- rms. # Use sysv4.2uw... so that sysv4* matches it. echo "$UNAME_MACHINE"-pc-sysv4.2uw"$UNAME_VERSION" exit ;; i*86:OS/2:*:*) # If we were able to find `uname', then EMX Unix compatibility # is probably installed. echo "$UNAME_MACHINE"-pc-os2-emx exit ;; i*86:XTS-300:*:STOP) echo "$UNAME_MACHINE"-unknown-stop exit ;; i*86:atheos:*:*) echo "$UNAME_MACHINE"-unknown-atheos exit ;; i*86:syllable:*:*) echo "$UNAME_MACHINE"-pc-syllable exit ;; i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*) echo i386-unknown-lynxos"$UNAME_RELEASE" exit ;; i*86:*DOS:*:*) echo "$UNAME_MACHINE"-pc-msdosdjgpp exit ;; i*86:*:4.*:*) UNAME_REL=$(echo "$UNAME_RELEASE" | sed 's/\/MP$//') if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then echo "$UNAME_MACHINE"-univel-sysv"$UNAME_REL" else echo "$UNAME_MACHINE"-pc-sysv"$UNAME_REL" fi exit ;; i*86:*:5:[678]*) # UnixWare 7.x, OpenUNIX and OpenServer 6. case $(/bin/uname -X | grep "^Machine") in *486*) UNAME_MACHINE=i486 ;; *Pentium) UNAME_MACHINE=i586 ;; *Pent*|*Celeron) UNAME_MACHINE=i686 ;; esac echo "$UNAME_MACHINE-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}" exit ;; i*86:*:3.2:*) if test -f /usr/options/cb.name; then UNAME_REL=$(sed -n 's/.*Version //p' /dev/null >/dev/null ; then UNAME_REL=$( (/bin/uname -X|grep Release|sed -e 's/.*= //')) (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ && UNAME_MACHINE=i586 (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ && UNAME_MACHINE=i686 (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ && UNAME_MACHINE=i686 echo "$UNAME_MACHINE"-pc-sco"$UNAME_REL" else echo "$UNAME_MACHINE"-pc-sysv32 fi exit ;; pc:*:*:*) # Left here for compatibility: # uname -m prints for DJGPP always 'pc', but it prints nothing about # the processor, so we play safe by assuming i586. # Note: whatever this is, it MUST be the same as what config.sub # prints for the "djgpp" host, or else GDB configure will decide that # this is a cross-build. echo i586-pc-msdosdjgpp exit ;; Intel:Mach:3*:*) echo i386-pc-mach3 exit ;; paragon:*:*:*) echo i860-intel-osf1 exit ;; i860:*:4.*:*) # i860-SVR4 if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then echo i860-stardent-sysv"$UNAME_RELEASE" # Stardent Vistra i860-SVR4 else # Add other i860-SVR4 vendors below as they are discovered. echo i860-unknown-sysv"$UNAME_RELEASE" # Unknown i860-SVR4 fi exit ;; mini*:CTIX:SYS*5:*) # "miniframe" echo m68010-convergent-sysv exit ;; mc68k:UNIX:SYSTEM5:3.51m) echo m68k-convergent-sysv exit ;; M680?0:D-NIX:5.3:*) echo m68k-diab-dnix exit ;; M68*:*:R3V[5678]*:*) test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) OS_REL='' test -r /etc/.relid \ && OS_REL=.$(sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid) /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4.3"$OS_REL"; exit; } /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;; 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4; exit; } ;; NCR*:*:4.2:* | MPRAS*:*:4.2:*) OS_REL='.3' test -r /etc/.relid \ && OS_REL=.$(sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid) /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4.3"$OS_REL"; exit; } /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \ && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;; m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) echo m68k-unknown-lynxos"$UNAME_RELEASE" exit ;; mc68030:UNIX_System_V:4.*:*) echo m68k-atari-sysv4 exit ;; TSUNAMI:LynxOS:2.*:*) echo sparc-unknown-lynxos"$UNAME_RELEASE" exit ;; rs6000:LynxOS:2.*:*) echo rs6000-unknown-lynxos"$UNAME_RELEASE" exit ;; PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*) echo powerpc-unknown-lynxos"$UNAME_RELEASE" exit ;; SM[BE]S:UNIX_SV:*:*) echo mips-dde-sysv"$UNAME_RELEASE" exit ;; RM*:ReliantUNIX-*:*:*) echo mips-sni-sysv4 exit ;; RM*:SINIX-*:*:*) echo mips-sni-sysv4 exit ;; *:SINIX-*:*:*) if uname -p 2>/dev/null >/dev/null ; then UNAME_MACHINE=$( (uname -p) 2>/dev/null) echo "$UNAME_MACHINE"-sni-sysv4 else echo ns32k-sni-sysv fi exit ;; PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort # says echo i586-unisys-sysv4 exit ;; *:UNIX_System_V:4*:FTX*) # From Gerald Hewes . # How about differentiating between stratus architectures? -djm echo hppa1.1-stratus-sysv4 exit ;; *:*:*:FTX*) # From seanf@swdc.stratus.com. echo i860-stratus-sysv4 exit ;; i*86:VOS:*:*) # From Paul.Green@stratus.com. echo "$UNAME_MACHINE"-stratus-vos exit ;; *:VOS:*:*) # From Paul.Green@stratus.com. echo hppa1.1-stratus-vos exit ;; mc68*:A/UX:*:*) echo m68k-apple-aux"$UNAME_RELEASE" exit ;; news*:NEWS-OS:6*:*) echo mips-sony-newsos6 exit ;; R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) if test -d /usr/nec; then echo mips-nec-sysv"$UNAME_RELEASE" else echo mips-unknown-sysv"$UNAME_RELEASE" fi exit ;; BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. echo powerpc-be-beos exit ;; BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. echo powerpc-apple-beos exit ;; BePC:BeOS:*:*) # BeOS running on Intel PC compatible. echo i586-pc-beos exit ;; BePC:Haiku:*:*) # Haiku running on Intel PC compatible. echo i586-pc-haiku exit ;; x86_64:Haiku:*:*) echo x86_64-unknown-haiku exit ;; SX-4:SUPER-UX:*:*) echo sx4-nec-superux"$UNAME_RELEASE" exit ;; SX-5:SUPER-UX:*:*) echo sx5-nec-superux"$UNAME_RELEASE" exit ;; SX-6:SUPER-UX:*:*) echo sx6-nec-superux"$UNAME_RELEASE" exit ;; SX-7:SUPER-UX:*:*) echo sx7-nec-superux"$UNAME_RELEASE" exit ;; SX-8:SUPER-UX:*:*) echo sx8-nec-superux"$UNAME_RELEASE" exit ;; SX-8R:SUPER-UX:*:*) echo sx8r-nec-superux"$UNAME_RELEASE" exit ;; SX-ACE:SUPER-UX:*:*) echo sxace-nec-superux"$UNAME_RELEASE" exit ;; Power*:Rhapsody:*:*) echo powerpc-apple-rhapsody"$UNAME_RELEASE" exit ;; *:Rhapsody:*:*) echo "$UNAME_MACHINE"-apple-rhapsody"$UNAME_RELEASE" exit ;; arm64:Darwin:*:*) echo aarch64-apple-darwin"$UNAME_RELEASE" exit ;; *:Darwin:*:*) UNAME_PROCESSOR=$(uname -p) case $UNAME_PROCESSOR in unknown) UNAME_PROCESSOR=powerpc ;; esac if command -v xcode-select > /dev/null 2> /dev/null && \ ! xcode-select --print-path > /dev/null 2> /dev/null ; then # Avoid executing cc if there is no toolchain installed as # cc will be a stub that puts up a graphical alert # prompting the user to install developer tools. CC_FOR_BUILD=no_compiler_found else set_cc_for_build fi if test "$CC_FOR_BUILD" != no_compiler_found; then if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ grep IS_64BIT_ARCH >/dev/null then case $UNAME_PROCESSOR in i386) UNAME_PROCESSOR=x86_64 ;; powerpc) UNAME_PROCESSOR=powerpc64 ;; esac fi # On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \ (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ grep IS_PPC >/dev/null then UNAME_PROCESSOR=powerpc fi elif test "$UNAME_PROCESSOR" = i386 ; then # uname -m returns i386 or x86_64 UNAME_PROCESSOR=$UNAME_MACHINE fi echo "$UNAME_PROCESSOR"-apple-darwin"$UNAME_RELEASE" exit ;; *:procnto*:*:* | *:QNX:[0123456789]*:*) UNAME_PROCESSOR=$(uname -p) if test "$UNAME_PROCESSOR" = x86; then UNAME_PROCESSOR=i386 UNAME_MACHINE=pc fi echo "$UNAME_PROCESSOR"-"$UNAME_MACHINE"-nto-qnx"$UNAME_RELEASE" exit ;; *:QNX:*:4*) echo i386-pc-qnx exit ;; NEO-*:NONSTOP_KERNEL:*:*) echo neo-tandem-nsk"$UNAME_RELEASE" exit ;; NSE-*:NONSTOP_KERNEL:*:*) echo nse-tandem-nsk"$UNAME_RELEASE" exit ;; NSR-*:NONSTOP_KERNEL:*:*) echo nsr-tandem-nsk"$UNAME_RELEASE" exit ;; NSV-*:NONSTOP_KERNEL:*:*) echo nsv-tandem-nsk"$UNAME_RELEASE" exit ;; NSX-*:NONSTOP_KERNEL:*:*) echo nsx-tandem-nsk"$UNAME_RELEASE" exit ;; *:NonStop-UX:*:*) echo mips-compaq-nonstopux exit ;; BS2000:POSIX*:*:*) echo bs2000-siemens-sysv exit ;; DS/*:UNIX_System_V:*:*) echo "$UNAME_MACHINE"-"$UNAME_SYSTEM"-"$UNAME_RELEASE" exit ;; *:Plan9:*:*) # "uname -m" is not consistent, so use $cputype instead. 386 # is converted to i386 for consistency with other x86 # operating systems. # shellcheck disable=SC2154 if test "$cputype" = 386; then UNAME_MACHINE=i386 else UNAME_MACHINE="$cputype" fi echo "$UNAME_MACHINE"-unknown-plan9 exit ;; *:TOPS-10:*:*) echo pdp10-unknown-tops10 exit ;; *:TENEX:*:*) echo pdp10-unknown-tenex exit ;; KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) echo pdp10-dec-tops20 exit ;; XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) echo pdp10-xkl-tops20 exit ;; *:TOPS-20:*:*) echo pdp10-unknown-tops20 exit ;; *:ITS:*:*) echo pdp10-unknown-its exit ;; SEI:*:*:SEIUX) echo mips-sei-seiux"$UNAME_RELEASE" exit ;; *:DragonFly:*:*) echo "$UNAME_MACHINE"-unknown-dragonfly"$(echo "$UNAME_RELEASE"|sed -e 's/[-(].*//')" exit ;; *:*VMS:*:*) UNAME_MACHINE=$( (uname -p) 2>/dev/null) case "$UNAME_MACHINE" in A*) echo alpha-dec-vms ; exit ;; I*) echo ia64-dec-vms ; exit ;; V*) echo vax-dec-vms ; exit ;; esac ;; *:XENIX:*:SysV) echo i386-pc-xenix exit ;; i*86:skyos:*:*) echo "$UNAME_MACHINE"-pc-skyos"$(echo "$UNAME_RELEASE" | sed -e 's/ .*$//')" exit ;; i*86:rdos:*:*) echo "$UNAME_MACHINE"-pc-rdos exit ;; *:AROS:*:*) echo "$UNAME_MACHINE"-unknown-aros exit ;; x86_64:VMkernel:*:*) echo "$UNAME_MACHINE"-unknown-esx exit ;; amd64:Isilon\ OneFS:*:*) echo x86_64-unknown-onefs exit ;; *:Unleashed:*:*) echo "$UNAME_MACHINE"-unknown-unleashed"$UNAME_RELEASE" exit ;; esac # No uname command or uname output not recognized. set_cc_for_build cat > "$dummy.c" < #include #endif #if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) #if defined (vax) || defined (__vax) || defined (__vax__) || defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) #include #if defined(_SIZE_T_) || defined(SIGLOST) #include #endif #endif #endif main () { #if defined (sony) #if defined (MIPSEB) /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, I don't know.... */ printf ("mips-sony-bsd\n"); exit (0); #else #include printf ("m68k-sony-newsos%s\n", #ifdef NEWSOS4 "4" #else "" #endif ); exit (0); #endif #endif #if defined (NeXT) #if !defined (__ARCHITECTURE__) #define __ARCHITECTURE__ "m68k" #endif int version; version=$( (hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null); if (version < 4) printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); else printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); exit (0); #endif #if defined (MULTIMAX) || defined (n16) #if defined (UMAXV) printf ("ns32k-encore-sysv\n"); exit (0); #else #if defined (CMU) printf ("ns32k-encore-mach\n"); exit (0); #else printf ("ns32k-encore-bsd\n"); exit (0); #endif #endif #endif #if defined (__386BSD__) printf ("i386-pc-bsd\n"); exit (0); #endif #if defined (sequent) #if defined (i386) printf ("i386-sequent-dynix\n"); exit (0); #endif #if defined (ns32000) printf ("ns32k-sequent-dynix\n"); exit (0); #endif #endif #if defined (_SEQUENT_) struct utsname un; uname(&un); if (strncmp(un.version, "V2", 2) == 0) { printf ("i386-sequent-ptx2\n"); exit (0); } if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ printf ("i386-sequent-ptx1\n"); exit (0); } printf ("i386-sequent-ptx\n"); exit (0); #endif #if defined (vax) #if !defined (ultrix) #include #if defined (BSD) #if BSD == 43 printf ("vax-dec-bsd4.3\n"); exit (0); #else #if BSD == 199006 printf ("vax-dec-bsd4.3reno\n"); exit (0); #else printf ("vax-dec-bsd\n"); exit (0); #endif #endif #else printf ("vax-dec-bsd\n"); exit (0); #endif #else #if defined(_SIZE_T_) || defined(SIGLOST) struct utsname un; uname (&un); printf ("vax-dec-ultrix%s\n", un.release); exit (0); #else printf ("vax-dec-ultrix\n"); exit (0); #endif #endif #endif #if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) #if defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) #if defined(_SIZE_T_) || defined(SIGLOST) struct utsname *un; uname (&un); printf ("mips-dec-ultrix%s\n", un.release); exit (0); #else printf ("mips-dec-ultrix\n"); exit (0); #endif #endif #endif #if defined (alliant) && defined (i860) printf ("i860-alliant-bsd\n"); exit (0); #endif exit (1); } EOF $CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null && SYSTEM_NAME=$($dummy) && { echo "$SYSTEM_NAME"; exit; } # Apollos put the system type in the environment. test -d /usr/apollo && { echo "$ISP-apollo-$SYSTYPE"; exit; } echo "$0: unable to guess system type" >&2 case "$UNAME_MACHINE:$UNAME_SYSTEM" in mips:Linux | mips64:Linux) # If we got here on MIPS GNU/Linux, output extra information. cat >&2 <&2 <&2 </dev/null || echo unknown) uname -r = $( (uname -r) 2>/dev/null || echo unknown) uname -s = $( (uname -s) 2>/dev/null || echo unknown) uname -v = $( (uname -v) 2>/dev/null || echo unknown) /usr/bin/uname -p = $( (/usr/bin/uname -p) 2>/dev/null) /bin/uname -X = $( (/bin/uname -X) 2>/dev/null) hostinfo = $( (hostinfo) 2>/dev/null) /bin/universe = $( (/bin/universe) 2>/dev/null) /usr/bin/arch -k = $( (/usr/bin/arch -k) 2>/dev/null) /bin/arch = $( (/bin/arch) 2>/dev/null) /usr/bin/oslevel = $( (/usr/bin/oslevel) 2>/dev/null) /usr/convex/getsysinfo = $( (/usr/convex/getsysinfo) 2>/dev/null) UNAME_MACHINE = "$UNAME_MACHINE" UNAME_RELEASE = "$UNAME_RELEASE" UNAME_SYSTEM = "$UNAME_SYSTEM" UNAME_VERSION = "$UNAME_VERSION" EOF fi exit 1 # Local variables: # eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" # End: fitsTcl-2.5/config.sub0000755000220700000360000010315414214134036013551 0ustar birbylhea#! /bin/sh # Configuration validation subroutine script. # Copyright 1992-2021 Free Software Foundation, Inc. timestamp='2021-01-08' # This file 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 3 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, see . # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that # program. This Exception is an additional permission under section 7 # of the GNU General Public License, version 3 ("GPLv3"). # Please send patches to . # # Configuration subroutine to validate and canonicalize a configuration type. # Supply the specified configuration type as an argument. # If it is invalid, we print an error message on stderr and exit with code 1. # Otherwise, we print the canonical config type on stdout and succeed. # You can get the latest version of this script from: # https://git.savannah.gnu.org/cgit/config.git/plain/config.sub # This file is supposed to be the same for all GNU packages # and recognize all the CPU types, system types and aliases # that are meaningful with *any* GNU software. # Each package is responsible for reporting which valid configurations # it does not support. The user should be able to distinguish # a failure to support a valid configuration from a meaningless # configuration. # The goal of this file is to map all the various variations of a given # machine specification into a single specification in the form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM # or in some cases, the newer four-part form: # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM # It is wrong to echo any other type of specification. me=$(echo "$0" | sed -e 's,.*/,,') usage="\ Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS Canonicalize a configuration name. Options: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit Report bugs and patches to ." version="\ GNU config.sub ($timestamp) Copyright 1992-2021 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." help=" Try \`$me --help' for more information." # Parse command line while test $# -gt 0 ; do case $1 in --time-stamp | --time* | -t ) echo "$timestamp" ; exit ;; --version | -v ) echo "$version" ; exit ;; --help | --h* | -h ) echo "$usage"; exit ;; -- ) # Stop option processing shift; break ;; - ) # Use stdin as input. break ;; -* ) echo "$me: invalid option $1$help" >&2 exit 1 ;; *local*) # First pass through any local machine types. echo "$1" exit ;; * ) break ;; esac done case $# in 0) echo "$me: missing argument$help" >&2 exit 1;; 1) ;; *) echo "$me: too many arguments$help" >&2 exit 1;; esac # Split fields of configuration type # shellcheck disable=SC2162 IFS="-" read field1 field2 field3 field4 <&2 exit 1 ;; *-*-*-*) basic_machine=$field1-$field2 basic_os=$field3-$field4 ;; *-*-*) # Ambiguous whether COMPANY is present, or skipped and KERNEL-OS is two # parts maybe_os=$field2-$field3 case $maybe_os in nto-qnx* | linux-* | uclinux-uclibc* \ | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* \ | netbsd*-eabi* | kopensolaris*-gnu* | cloudabi*-eabi* \ | storm-chaos* | os2-emx* | rtmk-nova*) basic_machine=$field1 basic_os=$maybe_os ;; android-linux) basic_machine=$field1-unknown basic_os=linux-android ;; *) basic_machine=$field1-$field2 basic_os=$field3 ;; esac ;; *-*) # A lone config we happen to match not fitting any pattern case $field1-$field2 in decstation-3100) basic_machine=mips-dec basic_os= ;; *-*) # Second component is usually, but not always the OS case $field2 in # Prevent following clause from handling this valid os sun*os*) basic_machine=$field1 basic_os=$field2 ;; # Manufacturers dec* | mips* | sequent* | encore* | pc533* | sgi* | sony* \ | att* | 7300* | 3300* | delta* | motorola* | sun[234]* \ | unicom* | ibm* | next | hp | isi* | apollo | altos* \ | convergent* | ncr* | news | 32* | 3600* | 3100* \ | hitachi* | c[123]* | convex* | sun | crds | omron* | dg \ | ultra | tti* | harris | dolphin | highlevel | gould \ | cbm | ns | masscomp | apple | axis | knuth | cray \ | microblaze* | sim | cisco \ | oki | wec | wrs | winbond) basic_machine=$field1-$field2 basic_os= ;; *) basic_machine=$field1 basic_os=$field2 ;; esac ;; esac ;; *) # Convert single-component short-hands not valid as part of # multi-component configurations. case $field1 in 386bsd) basic_machine=i386-pc basic_os=bsd ;; a29khif) basic_machine=a29k-amd basic_os=udi ;; adobe68k) basic_machine=m68010-adobe basic_os=scout ;; alliant) basic_machine=fx80-alliant basic_os= ;; altos | altos3068) basic_machine=m68k-altos basic_os= ;; am29k) basic_machine=a29k-none basic_os=bsd ;; amdahl) basic_machine=580-amdahl basic_os=sysv ;; amiga) basic_machine=m68k-unknown basic_os= ;; amigaos | amigados) basic_machine=m68k-unknown basic_os=amigaos ;; amigaunix | amix) basic_machine=m68k-unknown basic_os=sysv4 ;; apollo68) basic_machine=m68k-apollo basic_os=sysv ;; apollo68bsd) basic_machine=m68k-apollo basic_os=bsd ;; aros) basic_machine=i386-pc basic_os=aros ;; aux) basic_machine=m68k-apple basic_os=aux ;; balance) basic_machine=ns32k-sequent basic_os=dynix ;; blackfin) basic_machine=bfin-unknown basic_os=linux ;; cegcc) basic_machine=arm-unknown basic_os=cegcc ;; convex-c1) basic_machine=c1-convex basic_os=bsd ;; convex-c2) basic_machine=c2-convex basic_os=bsd ;; convex-c32) basic_machine=c32-convex basic_os=bsd ;; convex-c34) basic_machine=c34-convex basic_os=bsd ;; convex-c38) basic_machine=c38-convex basic_os=bsd ;; cray) basic_machine=j90-cray basic_os=unicos ;; crds | unos) basic_machine=m68k-crds basic_os= ;; da30) basic_machine=m68k-da30 basic_os= ;; decstation | pmax | pmin | dec3100 | decstatn) basic_machine=mips-dec basic_os= ;; delta88) basic_machine=m88k-motorola basic_os=sysv3 ;; dicos) basic_machine=i686-pc basic_os=dicos ;; djgpp) basic_machine=i586-pc basic_os=msdosdjgpp ;; ebmon29k) basic_machine=a29k-amd basic_os=ebmon ;; es1800 | OSE68k | ose68k | ose | OSE) basic_machine=m68k-ericsson basic_os=ose ;; gmicro) basic_machine=tron-gmicro basic_os=sysv ;; go32) basic_machine=i386-pc basic_os=go32 ;; h8300hms) basic_machine=h8300-hitachi basic_os=hms ;; h8300xray) basic_machine=h8300-hitachi basic_os=xray ;; h8500hms) basic_machine=h8500-hitachi basic_os=hms ;; harris) basic_machine=m88k-harris basic_os=sysv3 ;; hp300 | hp300hpux) basic_machine=m68k-hp basic_os=hpux ;; hp300bsd) basic_machine=m68k-hp basic_os=bsd ;; hppaosf) basic_machine=hppa1.1-hp basic_os=osf ;; hppro) basic_machine=hppa1.1-hp basic_os=proelf ;; i386mach) basic_machine=i386-mach basic_os=mach ;; isi68 | isi) basic_machine=m68k-isi basic_os=sysv ;; m68knommu) basic_machine=m68k-unknown basic_os=linux ;; magnum | m3230) basic_machine=mips-mips basic_os=sysv ;; merlin) basic_machine=ns32k-utek basic_os=sysv ;; mingw64) basic_machine=x86_64-pc basic_os=mingw64 ;; mingw32) basic_machine=i686-pc basic_os=mingw32 ;; mingw32ce) basic_machine=arm-unknown basic_os=mingw32ce ;; monitor) basic_machine=m68k-rom68k basic_os=coff ;; morphos) basic_machine=powerpc-unknown basic_os=morphos ;; moxiebox) basic_machine=moxie-unknown basic_os=moxiebox ;; msdos) basic_machine=i386-pc basic_os=msdos ;; msys) basic_machine=i686-pc basic_os=msys ;; mvs) basic_machine=i370-ibm basic_os=mvs ;; nacl) basic_machine=le32-unknown basic_os=nacl ;; ncr3000) basic_machine=i486-ncr basic_os=sysv4 ;; netbsd386) basic_machine=i386-pc basic_os=netbsd ;; netwinder) basic_machine=armv4l-rebel basic_os=linux ;; news | news700 | news800 | news900) basic_machine=m68k-sony basic_os=newsos ;; news1000) basic_machine=m68030-sony basic_os=newsos ;; necv70) basic_machine=v70-nec basic_os=sysv ;; nh3000) basic_machine=m68k-harris basic_os=cxux ;; nh[45]000) basic_machine=m88k-harris basic_os=cxux ;; nindy960) basic_machine=i960-intel basic_os=nindy ;; mon960) basic_machine=i960-intel basic_os=mon960 ;; nonstopux) basic_machine=mips-compaq basic_os=nonstopux ;; os400) basic_machine=powerpc-ibm basic_os=os400 ;; OSE68000 | ose68000) basic_machine=m68000-ericsson basic_os=ose ;; os68k) basic_machine=m68k-none basic_os=os68k ;; paragon) basic_machine=i860-intel basic_os=osf ;; parisc) basic_machine=hppa-unknown basic_os=linux ;; psp) basic_machine=mipsallegrexel-sony basic_os=psp ;; pw32) basic_machine=i586-unknown basic_os=pw32 ;; rdos | rdos64) basic_machine=x86_64-pc basic_os=rdos ;; rdos32) basic_machine=i386-pc basic_os=rdos ;; rom68k) basic_machine=m68k-rom68k basic_os=coff ;; sa29200) basic_machine=a29k-amd basic_os=udi ;; sei) basic_machine=mips-sei basic_os=seiux ;; sequent) basic_machine=i386-sequent basic_os= ;; sps7) basic_machine=m68k-bull basic_os=sysv2 ;; st2000) basic_machine=m68k-tandem basic_os= ;; stratus) basic_machine=i860-stratus basic_os=sysv4 ;; sun2) basic_machine=m68000-sun basic_os= ;; sun2os3) basic_machine=m68000-sun basic_os=sunos3 ;; sun2os4) basic_machine=m68000-sun basic_os=sunos4 ;; sun3) basic_machine=m68k-sun basic_os= ;; sun3os3) basic_machine=m68k-sun basic_os=sunos3 ;; sun3os4) basic_machine=m68k-sun basic_os=sunos4 ;; sun4) basic_machine=sparc-sun basic_os= ;; sun4os3) basic_machine=sparc-sun basic_os=sunos3 ;; sun4os4) basic_machine=sparc-sun basic_os=sunos4 ;; sun4sol2) basic_machine=sparc-sun basic_os=solaris2 ;; sun386 | sun386i | roadrunner) basic_machine=i386-sun basic_os= ;; sv1) basic_machine=sv1-cray basic_os=unicos ;; symmetry) basic_machine=i386-sequent basic_os=dynix ;; t3e) basic_machine=alphaev5-cray basic_os=unicos ;; t90) basic_machine=t90-cray basic_os=unicos ;; toad1) basic_machine=pdp10-xkl basic_os=tops20 ;; tpf) basic_machine=s390x-ibm basic_os=tpf ;; udi29k) basic_machine=a29k-amd basic_os=udi ;; ultra3) basic_machine=a29k-nyu basic_os=sym1 ;; v810 | necv810) basic_machine=v810-nec basic_os=none ;; vaxv) basic_machine=vax-dec basic_os=sysv ;; vms) basic_machine=vax-dec basic_os=vms ;; vsta) basic_machine=i386-pc basic_os=vsta ;; vxworks960) basic_machine=i960-wrs basic_os=vxworks ;; vxworks68) basic_machine=m68k-wrs basic_os=vxworks ;; vxworks29k) basic_machine=a29k-wrs basic_os=vxworks ;; xbox) basic_machine=i686-pc basic_os=mingw32 ;; ymp) basic_machine=ymp-cray basic_os=unicos ;; *) basic_machine=$1 basic_os= ;; esac ;; esac # Decode 1-component or ad-hoc basic machines case $basic_machine in # Here we handle the default manufacturer of certain CPU types. It is in # some cases the only manufacturer, in others, it is the most popular. w89k) cpu=hppa1.1 vendor=winbond ;; op50n) cpu=hppa1.1 vendor=oki ;; op60c) cpu=hppa1.1 vendor=oki ;; ibm*) cpu=i370 vendor=ibm ;; orion105) cpu=clipper vendor=highlevel ;; mac | mpw | mac-mpw) cpu=m68k vendor=apple ;; pmac | pmac-mpw) cpu=powerpc vendor=apple ;; # Recognize the various machine names and aliases which stand # for a CPU type and a company and sometimes even an OS. 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) cpu=m68000 vendor=att ;; 3b*) cpu=we32k vendor=att ;; bluegene*) cpu=powerpc vendor=ibm basic_os=cnk ;; decsystem10* | dec10*) cpu=pdp10 vendor=dec basic_os=tops10 ;; decsystem20* | dec20*) cpu=pdp10 vendor=dec basic_os=tops20 ;; delta | 3300 | motorola-3300 | motorola-delta \ | 3300-motorola | delta-motorola) cpu=m68k vendor=motorola ;; dpx2*) cpu=m68k vendor=bull basic_os=sysv3 ;; encore | umax | mmax) cpu=ns32k vendor=encore ;; elxsi) cpu=elxsi vendor=elxsi basic_os=${basic_os:-bsd} ;; fx2800) cpu=i860 vendor=alliant ;; genix) cpu=ns32k vendor=ns ;; h3050r* | hiux*) cpu=hppa1.1 vendor=hitachi basic_os=hiuxwe2 ;; hp3k9[0-9][0-9] | hp9[0-9][0-9]) cpu=hppa1.0 vendor=hp ;; hp9k2[0-9][0-9] | hp9k31[0-9]) cpu=m68000 vendor=hp ;; hp9k3[2-9][0-9]) cpu=m68k vendor=hp ;; hp9k6[0-9][0-9] | hp6[0-9][0-9]) cpu=hppa1.0 vendor=hp ;; hp9k7[0-79][0-9] | hp7[0-79][0-9]) cpu=hppa1.1 vendor=hp ;; hp9k78[0-9] | hp78[0-9]) # FIXME: really hppa2.0-hp cpu=hppa1.1 vendor=hp ;; hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) # FIXME: really hppa2.0-hp cpu=hppa1.1 vendor=hp ;; hp9k8[0-9][13679] | hp8[0-9][13679]) cpu=hppa1.1 vendor=hp ;; hp9k8[0-9][0-9] | hp8[0-9][0-9]) cpu=hppa1.0 vendor=hp ;; i*86v32) cpu=$(echo "$1" | sed -e 's/86.*/86/') vendor=pc basic_os=sysv32 ;; i*86v4*) cpu=$(echo "$1" | sed -e 's/86.*/86/') vendor=pc basic_os=sysv4 ;; i*86v) cpu=$(echo "$1" | sed -e 's/86.*/86/') vendor=pc basic_os=sysv ;; i*86sol2) cpu=$(echo "$1" | sed -e 's/86.*/86/') vendor=pc basic_os=solaris2 ;; j90 | j90-cray) cpu=j90 vendor=cray basic_os=${basic_os:-unicos} ;; iris | iris4d) cpu=mips vendor=sgi case $basic_os in irix*) ;; *) basic_os=irix4 ;; esac ;; miniframe) cpu=m68000 vendor=convergent ;; *mint | mint[0-9]* | *MiNT | *MiNT[0-9]*) cpu=m68k vendor=atari basic_os=mint ;; news-3600 | risc-news) cpu=mips vendor=sony basic_os=newsos ;; next | m*-next) cpu=m68k vendor=next case $basic_os in openstep*) ;; nextstep*) ;; ns2*) basic_os=nextstep2 ;; *) basic_os=nextstep3 ;; esac ;; np1) cpu=np1 vendor=gould ;; op50n-* | op60c-*) cpu=hppa1.1 vendor=oki basic_os=proelf ;; pa-hitachi) cpu=hppa1.1 vendor=hitachi basic_os=hiuxwe2 ;; pbd) cpu=sparc vendor=tti ;; pbb) cpu=m68k vendor=tti ;; pc532) cpu=ns32k vendor=pc532 ;; pn) cpu=pn vendor=gould ;; power) cpu=power vendor=ibm ;; ps2) cpu=i386 vendor=ibm ;; rm[46]00) cpu=mips vendor=siemens ;; rtpc | rtpc-*) cpu=romp vendor=ibm ;; sde) cpu=mipsisa32 vendor=sde basic_os=${basic_os:-elf} ;; simso-wrs) cpu=sparclite vendor=wrs basic_os=vxworks ;; tower | tower-32) cpu=m68k vendor=ncr ;; vpp*|vx|vx-*) cpu=f301 vendor=fujitsu ;; w65) cpu=w65 vendor=wdc ;; w89k-*) cpu=hppa1.1 vendor=winbond basic_os=proelf ;; none) cpu=none vendor=none ;; leon|leon[3-9]) cpu=sparc vendor=$basic_machine ;; leon-*|leon[3-9]-*) cpu=sparc vendor=$(echo "$basic_machine" | sed 's/-.*//') ;; *-*) # shellcheck disable=SC2162 IFS="-" read cpu vendor <&2 exit 1 ;; esac ;; esac # Here we canonicalize certain aliases for manufacturers. case $vendor in digital*) vendor=dec ;; commodore*) vendor=cbm ;; *) ;; esac # Decode manufacturer-specific aliases for certain operating systems. if test x$basic_os != x then # First recognize some ad-hoc caes, or perhaps split kernel-os, or else just # set os. case $basic_os in gnu/linux*) kernel=linux os=$(echo $basic_os | sed -e 's|gnu/linux|gnu|') ;; os2-emx) kernel=os2 os=$(echo $basic_os | sed -e 's|os2-emx|emx|') ;; nto-qnx*) kernel=nto os=$(echo $basic_os | sed -e 's|nto-qnx|qnx|') ;; *-*) # shellcheck disable=SC2162 IFS="-" read kernel os <&2 exit 1 ;; esac # As a final step for OS-related things, validate the OS-kernel combination # (given a valid OS), if there is a kernel. case $kernel-$os in linux-gnu* | linux-dietlibc* | linux-android* | linux-newlib* | linux-musl* | linux-uclibc* ) ;; uclinux-uclibc* ) ;; -dietlibc* | -newlib* | -musl* | -uclibc* ) # These are just libc implementations, not actual OSes, and thus # require a kernel. echo "Invalid configuration \`$1': libc \`$os' needs explicit kernel." 1>&2 exit 1 ;; kfreebsd*-gnu* | kopensolaris*-gnu*) ;; vxworks-simlinux | vxworks-simwindows | vxworks-spe) ;; nto-qnx*) ;; os2-emx) ;; *-eabi* | *-gnueabi*) ;; -*) # Blank kernel with real OS is always fine. ;; *-*) echo "Invalid configuration \`$1': Kernel \`$kernel' not known to work with OS \`$os'." 1>&2 exit 1 ;; esac # Here we handle the case where we know the os, and the CPU type, but not the # manufacturer. We pick the logical manufacturer. case $vendor in unknown) case $cpu-$os in *-riscix*) vendor=acorn ;; *-sunos*) vendor=sun ;; *-cnk* | *-aix*) vendor=ibm ;; *-beos*) vendor=be ;; *-hpux*) vendor=hp ;; *-mpeix*) vendor=hp ;; *-hiux*) vendor=hitachi ;; *-unos*) vendor=crds ;; *-dgux*) vendor=dg ;; *-luna*) vendor=omron ;; *-genix*) vendor=ns ;; *-clix*) vendor=intergraph ;; *-mvs* | *-opened*) vendor=ibm ;; *-os400*) vendor=ibm ;; s390-* | s390x-*) vendor=ibm ;; *-ptx*) vendor=sequent ;; *-tpf*) vendor=ibm ;; *-vxsim* | *-vxworks* | *-windiss*) vendor=wrs ;; *-aux*) vendor=apple ;; *-hms*) vendor=hitachi ;; *-mpw* | *-macos*) vendor=apple ;; *-*mint | *-mint[0-9]* | *-*MiNT | *-MiNT[0-9]*) vendor=atari ;; *-vos*) vendor=stratus ;; esac ;; esac echo "$cpu-$vendor-${kernel:+$kernel-}$os" exit # Local variables: # eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" # End: fitsTcl-2.5/configure0000755000220700000360000052037313357670752013524 0ustar birbylhea#! /bin/sh # From configure.in Revision. # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.69. # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. # # # This configure script is free software; the Free Software Foundation # gives unlimited permission to copy, distribute and modify it. ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi as_nl=' ' export as_nl # Printing a long string crashes Solaris 7 /usr/bin/printf. as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo # Prefer a ksh shell builtin over an external printf program on Solaris, # but without wasting forks for bash or zsh. if test -z "$BASH_VERSION$ZSH_VERSION" \ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='print -r --' as_echo_n='print -rn --' elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='printf %s\n' as_echo_n='printf %s' else if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' as_echo_n='/usr/ucb/echo -n' else as_echo_body='eval expr "X$1" : "X\\(.*\\)"' as_echo_n_body='eval arg=$1; case $arg in #( *"$as_nl"*) expr "X$arg" : "X\\(.*\\)$as_nl"; arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' export as_echo_n_body as_echo_n='sh -c $as_echo_n_body as_echo' fi export as_echo_body as_echo='sh -c $as_echo_body as_echo' fi # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # IFS # We need space, tab and new line, in precisely that order. Quoting is # there to prevent editors from complaining about space-tab. # (If _AS_PATH_WALK were called with IFS unset, it would disable word # splitting by setting IFS to empty value.) IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as `sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Unset variables that we do not need and which cause bugs (e.g. in # pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" # suppresses any "Segmentation fault" message there. '((' could # trigger a bug in pdksh 5.2.14. for as_var in BASH_ENV ENV MAIL MAILPATH do eval test x\${$as_var+set} = xset \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done PS1='$ ' PS2='> ' PS4='+ ' # NLS nuisances. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH # Use a proper internal environment variable to ensure we don't fall # into an infinite loop, continuously re-executing ourselves. if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then _as_can_reexec=no; export _as_can_reexec; # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV case $- in # (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. $as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 as_fn_exit 255 fi # We don't want this to propagate to other subprocesses. { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which # is contrary to our usage. Disable this feature. alias -g '\${1+\"\$@\"}'='\"\$@\"' setopt NO_GLOB_SUBST else case \`(set -o) 2>/dev/null\` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi " as_required="as_fn_return () { (exit \$1); } as_fn_success () { as_fn_return 0; } as_fn_failure () { as_fn_return 1; } as_fn_ret_success () { return 0; } as_fn_ret_failure () { return 1; } exitcode=0 as_fn_success || { exitcode=1; echo as_fn_success failed.; } as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : else exitcode=1; echo positional parameters were not saved. fi test x\$exitcode = x0 || exit 1 test -x / || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1 test \$(( 1 + 1 )) = 2 || exit 1" if (eval "$as_required") 2>/dev/null; then : as_have_required=yes else as_have_required=no fi if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR as_found=false for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. as_found=: case $as_dir in #( /*) for as_base in sh bash ksh sh5; do # Try only shells that exist, to save several forks. as_shell=$as_dir/$as_base if { test -f "$as_shell" || test -f "$as_shell.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : CONFIG_SHELL=$as_shell as_have_required=yes if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : break 2 fi fi done;; esac as_found=false done $as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : CONFIG_SHELL=$SHELL as_have_required=yes fi; } IFS=$as_save_IFS if test "x$CONFIG_SHELL" != x; then : export CONFIG_SHELL # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV case $- in # (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. $as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 exit 255 fi if test x$as_have_required = xno; then : $as_echo "$0: This script requires a shell more modern than all" $as_echo "$0: the shells that I found on your system." if test x${ZSH_VERSION+set} = xset ; then $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" $as_echo "$0: be upgraded to zsh 4.3.4 or later." else $as_echo "$0: Please tell bug-autoconf@gnu.org about your system, $0: including any error possibly output before this $0: message. Then install a modern shell, or manually run $0: the script under such a shell if you do have one." fi exit 1 fi fi fi SHELL=${CONFIG_SHELL-/bin/sh} export SHELL # Unset more variables known to interfere with behavior of common tools. CLICOLOR_FORCE= GREP_OPTIONS= unset CLICOLOR_FORCE GREP_OPTIONS ## --------------------- ## ## M4sh Shell Functions. ## ## --------------------- ## # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p # as_fn_executable_p FILE # ----------------------- # Test if FILE is an executable regular file. as_fn_executable_p () { test -f "$1" && test -x "$1" } # as_fn_executable_p # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' else as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits as_lineno_1=$LINENO as_lineno_1a=$LINENO as_lineno_2=$LINENO as_lineno_2a=$LINENO eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-) sed -n ' p /[$]LINENO/= ' <$as_myself | sed ' s/[$]LINENO.*/&-/ t lineno b :lineno N :loop s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ t loop s/-\n.*// ' >$as_me.lineno && chmod +x "$as_me.lineno" || { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } # If we had to re-execute with $CONFIG_SHELL, we're ensured to have # already done that, so ensure we don't try to do so again and fall # in an infinite loop. This has already happened in practice. _as_can_reexec=no; export _as_can_reexec # Don't try to exec as it changes $[0], causing all sort of problems # (the dirname of $[0] is not the place where we might find the # original and so on. Autoconf is especially sensitive to this). . "./$as_me.lineno" # Exit status is that of the last command. exit } ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. # In both cases, we have to default to `cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -pR' fi else as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi as_test_x='test -x' as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" # Sed expression to map a string onto a valid variable name. as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" test -n "$DJDIR" || exec 7<&0 &1 # Name of the host. # hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status, # so uname gets run too. ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` # # Initializations. # ac_default_prefix=/usr/local ac_clean_files= ac_config_libobj_dir=. LIBOBJS= cross_compiling=no subdirs= MFLAGS= MAKEFLAGS= # Identity of this package. PACKAGE_NAME= PACKAGE_TARNAME= PACKAGE_VERSION= PACKAGE_STRING= PACKAGE_BUGREPORT= PACKAGE_URL= ac_unique_file="Makefile.in" # Factoring default headers for most tests. ac_includes_default="\ #include #ifdef HAVE_SYS_TYPES_H # include #endif #ifdef HAVE_SYS_STAT_H # include #endif #ifdef STDC_HEADERS # include # include #else # ifdef HAVE_STDLIB_H # include # endif #endif #ifdef HAVE_STRING_H # if !defined STDC_HEADERS && defined HAVE_MEMORY_H # include # endif # include #endif #ifdef HAVE_STRINGS_H # include #endif #ifdef HAVE_INTTYPES_H # include #endif #ifdef HAVE_STDINT_H # include #endif #ifdef HAVE_UNISTD_H # include #endif" ac_subst_vars='LTLIBOBJS TCL_LIB LIBOBJS SHLIB_SUFFIX SHLIB_LD_LIBS SHLIB_LD LD_FLAGS ALLOCA EGREP GREP CURLCONFIG XLIBS XLIBPTH XINCLUDES USE_X CPP XMKMF RANLIB OBJEXT EXEEXT ac_ct_CC CPPFLAGS LDFLAGS CFLAGS CC EXT BIN_EXT BINDIR UNAME C_LIB_OPTION CFITSIODIR TCL_INC_PATH TCL_PATH target_alias host_alias build_alias LIBS ECHO_T ECHO_N ECHO_C DEFS mandir localedir libdir psdir pdfdir dvidir htmldir infodir docdir oldincludedir includedir localstatedir sharedstatedir sysconfdir datadir datarootdir libexecdir sbindir bindir program_transform_name prefix exec_prefix PACKAGE_URL PACKAGE_BUGREPORT PACKAGE_STRING PACKAGE_VERSION PACKAGE_TARNAME PACKAGE_NAME PATH_SEPARATOR SHELL' ac_subst_files='' ac_user_opts=' enable_option_checking with_tcl with_tcl_includes with_cfitsio enable_shared enable_static with_x ' ac_precious_vars='build_alias host_alias target_alias CC CFLAGS LDFLAGS LIBS CPPFLAGS XMKMF CPP' # Initialize some variables set by options. ac_init_help= ac_init_version=false ac_unrecognized_opts= ac_unrecognized_sep= # The variables have the same names as the options, with # dashes changed to underlines. cache_file=/dev/null exec_prefix=NONE no_create= no_recursion= prefix=NONE program_prefix=NONE program_suffix=NONE program_transform_name=s,x,x, silent= site= srcdir= verbose= x_includes=NONE x_libraries=NONE # Installation directory options. # These are left unexpanded so users can "make install exec_prefix=/foo" # and all the variables that are supposed to be based on exec_prefix # by default will actually change. # Use braces instead of parens because sh, perl, etc. also accept them. # (The list follows the same order as the GNU Coding Standards.) bindir='${exec_prefix}/bin' sbindir='${exec_prefix}/sbin' libexecdir='${exec_prefix}/libexec' datarootdir='${prefix}/share' datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE}' infodir='${datarootdir}/info' htmldir='${docdir}' dvidir='${docdir}' pdfdir='${docdir}' psdir='${docdir}' libdir='${exec_prefix}/lib' localedir='${datarootdir}/locale' mandir='${datarootdir}/man' ac_prev= ac_dashdash= for ac_option do # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then eval $ac_prev=\$ac_option ac_prev= continue fi case $ac_option in *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; *=) ac_optarg= ;; *) ac_optarg=yes ;; esac # Accept the important Cygnus configure options, so we can diagnose typos. case $ac_dashdash$ac_option in --) ac_dashdash=yes ;; -bindir | --bindir | --bindi | --bind | --bin | --bi) ac_prev=bindir ;; -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) bindir=$ac_optarg ;; -build | --build | --buil | --bui | --bu) ac_prev=build_alias ;; -build=* | --build=* | --buil=* | --bui=* | --bu=*) build_alias=$ac_optarg ;; -cache-file | --cache-file | --cache-fil | --cache-fi \ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) ac_prev=cache_file ;; -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) cache_file=$ac_optarg ;; --config-cache | -C) cache_file=config.cache ;; -datadir | --datadir | --datadi | --datad) ac_prev=datadir ;; -datadir=* | --datadir=* | --datadi=* | --datad=*) datadir=$ac_optarg ;; -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ | --dataroo | --dataro | --datar) ac_prev=datarootdir ;; -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) datarootdir=$ac_optarg ;; -disable-* | --disable-*) ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=no ;; -docdir | --docdir | --docdi | --doc | --do) ac_prev=docdir ;; -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) docdir=$ac_optarg ;; -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) ac_prev=dvidir ;; -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) dvidir=$ac_optarg ;; -enable-* | --enable-*) ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=\$ac_optarg ;; -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ | --exec | --exe | --ex) ac_prev=exec_prefix ;; -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ | --exec=* | --exe=* | --ex=*) exec_prefix=$ac_optarg ;; -gas | --gas | --ga | --g) # Obsolete; use --with-gas. with_gas=yes ;; -help | --help | --hel | --he | -h) ac_init_help=long ;; -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) ac_init_help=recursive ;; -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) ac_init_help=short ;; -host | --host | --hos | --ho) ac_prev=host_alias ;; -host=* | --host=* | --hos=* | --ho=*) host_alias=$ac_optarg ;; -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) ac_prev=htmldir ;; -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ | --ht=*) htmldir=$ac_optarg ;; -includedir | --includedir | --includedi | --included | --include \ | --includ | --inclu | --incl | --inc) ac_prev=includedir ;; -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ | --includ=* | --inclu=* | --incl=* | --inc=*) includedir=$ac_optarg ;; -infodir | --infodir | --infodi | --infod | --info | --inf) ac_prev=infodir ;; -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) infodir=$ac_optarg ;; -libdir | --libdir | --libdi | --libd) ac_prev=libdir ;; -libdir=* | --libdir=* | --libdi=* | --libd=*) libdir=$ac_optarg ;; -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ | --libexe | --libex | --libe) ac_prev=libexecdir ;; -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ | --libexe=* | --libex=* | --libe=*) libexecdir=$ac_optarg ;; -localedir | --localedir | --localedi | --localed | --locale) ac_prev=localedir ;; -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) localedir=$ac_optarg ;; -localstatedir | --localstatedir | --localstatedi | --localstated \ | --localstate | --localstat | --localsta | --localst | --locals) ac_prev=localstatedir ;; -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) localstatedir=$ac_optarg ;; -mandir | --mandir | --mandi | --mand | --man | --ma | --m) ac_prev=mandir ;; -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) mandir=$ac_optarg ;; -nfp | --nfp | --nf) # Obsolete; use --without-fp. with_fp=no ;; -no-create | --no-create | --no-creat | --no-crea | --no-cre \ | --no-cr | --no-c | -n) no_create=yes ;; -no-recursion | --no-recursion | --no-recursio | --no-recursi \ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) no_recursion=yes ;; -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ | --oldin | --oldi | --old | --ol | --o) ac_prev=oldincludedir ;; -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) oldincludedir=$ac_optarg ;; -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) ac_prev=prefix ;; -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) prefix=$ac_optarg ;; -program-prefix | --program-prefix | --program-prefi | --program-pref \ | --program-pre | --program-pr | --program-p) ac_prev=program_prefix ;; -program-prefix=* | --program-prefix=* | --program-prefi=* \ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) program_prefix=$ac_optarg ;; -program-suffix | --program-suffix | --program-suffi | --program-suff \ | --program-suf | --program-su | --program-s) ac_prev=program_suffix ;; -program-suffix=* | --program-suffix=* | --program-suffi=* \ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) program_suffix=$ac_optarg ;; -program-transform-name | --program-transform-name \ | --program-transform-nam | --program-transform-na \ | --program-transform-n | --program-transform- \ | --program-transform | --program-transfor \ | --program-transfo | --program-transf \ | --program-trans | --program-tran \ | --progr-tra | --program-tr | --program-t) ac_prev=program_transform_name ;; -program-transform-name=* | --program-transform-name=* \ | --program-transform-nam=* | --program-transform-na=* \ | --program-transform-n=* | --program-transform-=* \ | --program-transform=* | --program-transfor=* \ | --program-transfo=* | --program-transf=* \ | --program-trans=* | --program-tran=* \ | --progr-tra=* | --program-tr=* | --program-t=*) program_transform_name=$ac_optarg ;; -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) ac_prev=pdfdir ;; -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) pdfdir=$ac_optarg ;; -psdir | --psdir | --psdi | --psd | --ps) ac_prev=psdir ;; -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) psdir=$ac_optarg ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) silent=yes ;; -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ | --sbi=* | --sb=*) sbindir=$ac_optarg ;; -sharedstatedir | --sharedstatedir | --sharedstatedi \ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ | --sharedst | --shareds | --shared | --share | --shar \ | --sha | --sh) ac_prev=sharedstatedir ;; -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ | --sha=* | --sh=*) sharedstatedir=$ac_optarg ;; -site | --site | --sit) ac_prev=site ;; -site=* | --site=* | --sit=*) site=$ac_optarg ;; -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) ac_prev=srcdir ;; -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) srcdir=$ac_optarg ;; -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ | --syscon | --sysco | --sysc | --sys | --sy) ac_prev=sysconfdir ;; -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) sysconfdir=$ac_optarg ;; -target | --target | --targe | --targ | --tar | --ta | --t) ac_prev=target_alias ;; -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) target_alias=$ac_optarg ;; -v | -verbose | --verbose | --verbos | --verbo | --verb) verbose=yes ;; -version | --version | --versio | --versi | --vers | -V) ac_init_version=: ;; -with-* | --with-*) ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=\$ac_optarg ;; -without-* | --without-*) ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=no ;; --x) # Obsolete; use --with-x. with_x=yes ;; -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ | --x-incl | --x-inc | --x-in | --x-i) ac_prev=x_includes ;; -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) x_includes=$ac_optarg ;; -x-libraries | --x-libraries | --x-librarie | --x-librari \ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) ac_prev=x_libraries ;; -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) x_libraries=$ac_optarg ;; -*) as_fn_error $? "unrecognized option: \`$ac_option' Try \`$0 --help' for more information" ;; *=*) ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` # Reject names that are not valid shell variable names. case $ac_envvar in #( '' | [0-9]* | *[!_$as_cr_alnum]* ) as_fn_error $? "invalid variable name: \`$ac_envvar'" ;; esac eval $ac_envvar=\$ac_optarg export $ac_envvar ;; *) # FIXME: should be removed in autoconf 3.0. $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" ;; esac done if test -n "$ac_prev"; then ac_option=--`echo $ac_prev | sed 's/_/-/g'` as_fn_error $? "missing argument to $ac_option" fi if test -n "$ac_unrecognized_opts"; then case $enable_option_checking in no) ;; fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; esac fi # Check all directory arguments for consistency. for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ libdir localedir mandir do eval ac_val=\$$ac_var # Remove trailing slashes. case $ac_val in */ ) ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` eval $ac_var=\$ac_val;; esac # Be sure to have absolute directory names. case $ac_val in [\\/$]* | ?:[\\/]* ) continue;; NONE | '' ) case $ac_var in *prefix ) continue;; esac;; esac as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" done # There might be people who depend on the old broken behavior: `$host' # used to hold the argument of --host etc. # FIXME: To remove some day. build=$build_alias host=$host_alias target=$target_alias # FIXME: To remove some day. if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe elif test "x$build_alias" != "x$host_alias"; then cross_compiling=yes fi fi ac_tool_prefix= test -n "$host_alias" && ac_tool_prefix=$host_alias- test "$silent" = yes && exec 6>/dev/null ac_pwd=`pwd` && test -n "$ac_pwd" && ac_ls_di=`ls -di .` && ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || as_fn_error $? "working directory cannot be determined" test "X$ac_ls_di" = "X$ac_pwd_ls_di" || as_fn_error $? "pwd does not report name of working directory" # Find the source files, if location was not specified. if test -z "$srcdir"; then ac_srcdir_defaulted=yes # Try the directory containing this script, then the parent directory. ac_confdir=`$as_dirname -- "$as_myself" || $as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_myself" : 'X\(//\)[^/]' \| \ X"$as_myself" : 'X\(//\)$' \| \ X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_myself" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` srcdir=$ac_confdir if test ! -r "$srcdir/$ac_unique_file"; then srcdir=.. fi else ac_srcdir_defaulted=no fi if test ! -r "$srcdir/$ac_unique_file"; then test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" fi ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" ac_abs_confdir=`( cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" pwd)` # When building in place, set srcdir=. if test "$ac_abs_confdir" = "$ac_pwd"; then srcdir=. fi # Remove unnecessary trailing slashes from srcdir. # Double slashes in file names in object file debugging info # mess up M-x gdb in Emacs. case $srcdir in */) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; esac for ac_var in $ac_precious_vars; do eval ac_env_${ac_var}_set=\${${ac_var}+set} eval ac_env_${ac_var}_value=\$${ac_var} eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} eval ac_cv_env_${ac_var}_value=\$${ac_var} done # # Report the --help message. # if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF \`configure' configures this package to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. Configuration: -h, --help display this help and exit --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit -q, --quiet, --silent do not print \`checking ...' messages --cache-file=FILE cache test results in FILE [disabled] -C, --config-cache alias for \`--cache-file=config.cache' -n, --no-create do not create output files --srcdir=DIR find the sources in DIR [configure dir or \`..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX [$ac_default_prefix] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] By default, \`make install' will install all the files in \`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify an installation prefix other than \`$ac_default_prefix' using \`--prefix', for instance \`--prefix=\$HOME'. For better control, use the options below. Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root [DATAROOTDIR/doc/PACKAGE] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] --psdir=DIR ps documentation [DOCDIR] _ACEOF cat <<\_ACEOF X features: --x-includes=DIR X include files are in DIR --x-libraries=DIR X library files are in DIR _ACEOF fi if test -n "$ac_init_help"; then cat <<\_ACEOF Optional Features: --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --disable-shared Produce static binaries --enable-static Produce static binaries Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-tcl Path to tcl library --with-tcl-includes Path to tcl include files --with-cfitsio Path to cfitsio source --with-x use the X Window System Some influential environment variables: CC C compiler command CFLAGS C compiler flags LDFLAGS linker flags, e.g. -L if you have libraries in a nonstandard directory LIBS libraries to pass to the linker, e.g. -l CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if you have headers in a nonstandard directory XMKMF Path to xmkmf, Makefile generator for X Window System CPP C preprocessor Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. Report bugs to the package provider. _ACEOF ac_status=$? fi if test "$ac_init_help" = "recursive"; then # If there are subdirs, report their specific --help. for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue test -d "$ac_dir" || { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || continue ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; esac ;; esac ac_abs_top_builddir=$ac_pwd ac_abs_builddir=$ac_pwd$ac_dir_suffix # for backward compatibility: ac_top_builddir=$ac_top_build_prefix case $srcdir in .) # We are building in place. ac_srcdir=. ac_top_srcdir=$ac_top_builddir_sub ac_abs_top_srcdir=$ac_pwd ;; [\\/]* | ?:[\\/]* ) # Absolute name. ac_srcdir=$srcdir$ac_dir_suffix; ac_top_srcdir=$srcdir ac_abs_top_srcdir=$srcdir ;; *) # Relative name. ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix ac_top_srcdir=$ac_top_build_prefix$srcdir ac_abs_top_srcdir=$ac_pwd/$srcdir ;; esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix cd "$ac_dir" || { ac_status=$?; continue; } # Check for guested configure. if test -f "$ac_srcdir/configure.gnu"; then echo && $SHELL "$ac_srcdir/configure.gnu" --help=recursive elif test -f "$ac_srcdir/configure"; then echo && $SHELL "$ac_srcdir/configure" --help=recursive else $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 fi || ac_status=$? cd "$ac_pwd" || { ac_status=$?; break; } done fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF configure generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF exit fi ## ------------------------ ## ## Autoconf initialization. ## ## ------------------------ ## # ac_fn_c_try_compile LINENO # -------------------------- # Try to compile conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack rm -f conftest.$ac_objext if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_c_werror_flag" || test ! -s conftest.err } && test -s conftest.$ac_objext; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_compile # ac_fn_c_try_link LINENO # ----------------------- # Try to link conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_link () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack rm -f conftest.$ac_objext conftest$ac_exeext if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_c_werror_flag" || test ! -s conftest.err } && test -s conftest$ac_exeext && { test "$cross_compiling" = yes || test -x conftest$ac_exeext }; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would # interfere with the next link command; also delete a directory that is # left behind by Apple's compiler. We do this before executing the actions. rm -rf conftest.dSYM conftest_ipa8_conftest.oo eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_link # ac_fn_c_check_func LINENO FUNC VAR # ---------------------------------- # Tests whether FUNC exists, setting the cache variable VAR accordingly ac_fn_c_check_func () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Define $2 to an innocuous variant, in case declares $2. For example, HP-UX 11i declares gettimeofday. */ #define $2 innocuous_$2 /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $2 (); below. Prefer to if __STDC__ is defined, since exists even on freestanding compilers. */ #ifdef __STDC__ # include #else # include #endif #undef $2 /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char $2 (); /* The GNU C library defines this for functions which it implements to always fail with ENOSYS. Some functions are actually named something starting with __ and the normal name is an alias. */ #if defined __stub_$2 || defined __stub___$2 choke me #endif int main () { return $2 (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : eval "$3=yes" else eval "$3=no" fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_func # ac_fn_c_try_cpp LINENO # ---------------------- # Try to preprocess conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_cpp () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if { { ac_try="$ac_cpp conftest.$ac_ext" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } > conftest.i && { test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || test ! -s conftest.err }; then : ac_retval=0 else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_cpp # ac_fn_c_try_run LINENO # ---------------------- # Try to link conftest.$ac_ext, and return whether this succeeded. Assumes # that executables *can* be run. ac_fn_c_try_run () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then : ac_retval=0 else $as_echo "$as_me: program exited with status $ac_status" >&5 $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=$ac_status fi rm -rf conftest.dSYM conftest_ipa8_conftest.oo eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_run # ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES # ------------------------------------------------------- # Tests whether HEADER exists, giving a warning if it cannot be compiled using # the include files in INCLUDES and setting the cache variable VAR # accordingly. ac_fn_c_check_header_mongrel () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if eval \${$3+:} false; then : { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } else # Is the header compilable? { $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5 $as_echo_n "checking $2 usability... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 #include <$2> _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_header_compiler=yes else ac_header_compiler=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5 $as_echo "$ac_header_compiler" >&6; } # Is the header present? { $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5 $as_echo_n "checking $2 presence... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include <$2> _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : ac_header_preproc=yes else ac_header_preproc=no fi rm -f conftest.err conftest.i conftest.$ac_ext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5 $as_echo "$ac_header_preproc" >&6; } # So? What about this header? case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #(( yes:no: ) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5 $as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 $as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} ;; no:yes:* ) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5 $as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: check for missing prerequisite headers?" >&5 $as_echo "$as_me: WARNING: $2: check for missing prerequisite headers?" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5 $as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&5 $as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 $as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} ;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else eval "$3=\$ac_header_compiler" fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_header_mongrel # ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES # ------------------------------------------------------- # Tests whether HEADER exists and can be compiled using the include files in # INCLUDES, setting the cache variable VAR accordingly. ac_fn_c_check_header_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 #include <$2> _ACEOF if ac_fn_c_try_compile "$LINENO"; then : eval "$3=yes" else eval "$3=no" fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_header_compile # ac_fn_c_check_type LINENO TYPE VAR INCLUDES # ------------------------------------------- # Tests whether TYPE exists after having included INCLUDES, setting cache # variable VAR accordingly. ac_fn_c_check_type () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else eval "$3=no" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { if (sizeof ($2)) return 0; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int main () { if (sizeof (($2))) return 0; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : else eval "$3=yes" fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_type cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by $as_me, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ _ACEOF exec 5>>config.log { cat <<_ASUNAME ## --------- ## ## Platform. ## ## --------- ## hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` uname -m = `(uname -m) 2>/dev/null || echo unknown` uname -r = `(uname -r) 2>/dev/null || echo unknown` uname -s = `(uname -s) 2>/dev/null || echo unknown` uname -v = `(uname -v) 2>/dev/null || echo unknown` /usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` /bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` /bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` /usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` /usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` /bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` /bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` _ASUNAME as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. $as_echo "PATH: $as_dir" done IFS=$as_save_IFS } >&5 cat >&5 <<_ACEOF ## ----------- ## ## Core tests. ## ## ----------- ## _ACEOF # Keep a trace of the command line. # Strip out --no-create and --no-recursion so they do not pile up. # Strip out --silent because we don't want to record it for future runs. # Also quote any args containing shell meta-characters. # Make two passes to allow for proper duplicate-argument suppression. ac_configure_args= ac_configure_args0= ac_configure_args1= ac_must_keep_next=false for ac_pass in 1 2 do for ac_arg do case $ac_arg in -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) continue ;; *\'*) ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; esac case $ac_pass in 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; 2) as_fn_append ac_configure_args1 " '$ac_arg'" if test $ac_must_keep_next = true; then ac_must_keep_next=false # Got value, back to normal. else case $ac_arg in *=* | --config-cache | -C | -disable-* | --disable-* \ | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ | -with-* | --with-* | -without-* | --without-* | --x) case "$ac_configure_args0 " in "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; esac ;; -* ) ac_must_keep_next=true ;; esac fi as_fn_append ac_configure_args " '$ac_arg'" ;; esac done done { ac_configure_args0=; unset ac_configure_args0;} { ac_configure_args1=; unset ac_configure_args1;} # When interrupted or exit'd, cleanup temporary files, and complete # config.log. We remove comments because anyway the quotes in there # would cause problems or look ugly. # WARNING: Use '\'' to represent an apostrophe within the trap. # WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. trap 'exit_status=$? # Save into config.log some information that might help in debugging. { echo $as_echo "## ---------------- ## ## Cache variables. ## ## ---------------- ##" echo # The following way of writing the cache mishandles newlines in values, ( for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( *${as_nl}ac_space=\ *) sed -n \ "s/'\''/'\''\\\\'\'''\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" ;; #( *) sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) echo $as_echo "## ----------------- ## ## Output variables. ## ## ----------------- ##" echo for ac_var in $ac_subst_vars do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo if test -n "$ac_subst_files"; then $as_echo "## ------------------- ## ## File substitutions. ## ## ------------------- ##" echo for ac_var in $ac_subst_files do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac $as_echo "$ac_var='\''$ac_val'\''" done | sort echo fi if test -s confdefs.h; then $as_echo "## ----------- ## ## confdefs.h. ## ## ----------- ##" echo cat confdefs.h echo fi test "$ac_signal" != 0 && $as_echo "$as_me: caught signal $ac_signal" $as_echo "$as_me: exit $exit_status" } >&5 rm -f core *.core core.conftest.* && rm -f -r conftest* confdefs* conf$$* $ac_clean_files && exit $exit_status ' 0 for ac_signal in 1 2 13 15; do trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal done ac_signal=0 # confdefs.h avoids OS command line length limits that DEFS can exceed. rm -f -r conftest* confdefs.h $as_echo "/* confdefs.h */" > confdefs.h # Predefined preprocessor variables. cat >>confdefs.h <<_ACEOF #define PACKAGE_NAME "$PACKAGE_NAME" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_TARNAME "$PACKAGE_TARNAME" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_VERSION "$PACKAGE_VERSION" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_STRING "$PACKAGE_STRING" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" _ACEOF cat >>confdefs.h <<_ACEOF #define PACKAGE_URL "$PACKAGE_URL" _ACEOF # Let the site file select an alternate cache file if it wants to. # Prefer an explicitly selected file to automatically selected ones. ac_site_file1=NONE ac_site_file2=NONE if test -n "$CONFIG_SITE"; then # We do not want a PATH search for config.site. case $CONFIG_SITE in #(( -*) ac_site_file1=./$CONFIG_SITE;; */*) ac_site_file1=$CONFIG_SITE;; *) ac_site_file1=./$CONFIG_SITE;; esac elif test "x$prefix" != xNONE; then ac_site_file1=$prefix/share/config.site ac_site_file2=$prefix/etc/config.site else ac_site_file1=$ac_default_prefix/share/config.site ac_site_file2=$ac_default_prefix/etc/config.site fi for ac_site_file in "$ac_site_file1" "$ac_site_file2" do test "x$ac_site_file" = xNONE && continue if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 $as_echo "$as_me: loading site script $ac_site_file" >&6;} sed 's/^/| /' "$ac_site_file" >&5 . "$ac_site_file" \ || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "failed to load site script $ac_site_file See \`config.log' for more details" "$LINENO" 5; } fi done if test -r "$cache_file"; then # Some versions of bash will fail to source /dev/null (special files # actually), so we avoid doing that. DJGPP emulates it as a regular file. if test /dev/null != "$cache_file" && test -f "$cache_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 $as_echo "$as_me: loading cache $cache_file" >&6;} case $cache_file in [\\/]* | ?:[\\/]* ) . "$cache_file";; *) . "./$cache_file";; esac fi else { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 $as_echo "$as_me: creating cache $cache_file" >&6;} >$cache_file fi # Check that the precious variables saved in the cache have kept the same # value. ac_cache_corrupted=false for ac_var in $ac_precious_vars; do eval ac_old_set=\$ac_cv_env_${ac_var}_set eval ac_new_set=\$ac_env_${ac_var}_set eval ac_old_val=\$ac_cv_env_${ac_var}_value eval ac_new_val=\$ac_env_${ac_var}_value case $ac_old_set,$ac_new_set in set,) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} ac_cache_corrupted=: ;; ,set) { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 $as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} ac_cache_corrupted=: ;; ,);; *) if test "x$ac_old_val" != "x$ac_new_val"; then # differences in whitespace do not lead to failure. ac_old_val_w=`echo x $ac_old_val` ac_new_val_w=`echo x $ac_new_val` if test "$ac_old_val_w" != "$ac_new_val_w"; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 $as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} ac_cache_corrupted=: else { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 $as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} eval $ac_var=\$ac_old_val fi { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 $as_echo "$as_me: former value: \`$ac_old_val'" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 $as_echo "$as_me: current value: \`$ac_new_val'" >&2;} fi;; esac # Pass precious variables to config.status. if test "$ac_new_set" = set; then case $ac_new_val in *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; *) ac_arg=$ac_var=$ac_new_val ;; esac case " $ac_configure_args " in *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. *) as_fn_append ac_configure_args " '$ac_arg'" ;; esac fi done if $ac_cache_corrupted; then { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 $as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 fi ## -------------------- ## ## Main body of script. ## ## -------------------- ## ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu if test $cache_file = ./config.cache; then cache_file=`pwd`/config.cache fi # Tcl: #------------------------------------------- # Check whether --with-tcl was given. if test "${with_tcl+set}" = set; then : withval=$with_tcl; TCL_PATH=$withval fi # Check whether --with-tcl-includes was given. if test "${with_tcl_includes+set}" = set; then : withval=$with_tcl_includes; TCL_INCLUDES=$withval fi # Make sure we have tcl.h before proceeding: #------------------------------------------- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for tcl header file" >&5 $as_echo_n "checking for tcl header file... " >&6; } TCL_INC_PATH= for dir in $TCL_INCLUDES $prefix/include /usr/include ; do if test -r $dir/tcl.h; then TCL_INC_PATH=$dir { $as_echo "$as_me:${as_lineno-$LINENO}: result: $dir" >&5 $as_echo "$dir" >&6; } break fi done if test -z "$TCL_INC_PATH"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } as_fn_error $? "Cannot find Tcl header. Use --with-tcl-includes to specify the location of tcl.h on your system." "$LINENO" 5 fi # CFITSIO: #------------------------------------------- # Check whether --with-cfitsio was given. if test "${with_cfitsio+set}" = set; then : withval=$with_cfitsio; CFITSIO=$withval fi # Make sure we have cfitsio before proceeding: #------------------------------------------- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for cfitsio source directory" >&5 $as_echo_n "checking for cfitsio source directory... " >&6; } CFITSIODIR= for dir in $CFITSIO ./cfitsio ; do if test -r $dir/eval_defs.h; then CFITSIODIR=$dir { $as_echo "$as_me:${as_lineno-$LINENO}: result: $dir" >&5 $as_echo "$dir" >&6; } break fi done if test -z "$CFITSIODIR"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } as_fn_error $? "Cannot find cfitsio. Use --with-cfitsio to specify the location of the cfitsio source code." "$LINENO" 5 fi #------------------------------------------- # Check whether --enable-shared was given. if test "${enable_shared+set}" = set; then : enableval=$enable_shared; lhea_shared=$enableval else lhea_shared=yes fi # Check whether --enable-static was given. if test "${enable_static+set}" = set; then : enableval=$enable_static; if test $enableval = yes; then lhea_shared=no; fi fi if test $lhea_shared = yes; then C_LIB_OPTION=shared else C_LIB_OPTION=static fi #------------------------------------------------------------------------------- # Determine system type #------------------------------------------------------------------------------- BIN_EXT= if test "x$EXT" = x; then EXT=lnx; fi if test "x$BINDIR" = x; then # Extract the first word of "uname", so it can be a program name with args. set dummy uname; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_UNAME+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$UNAME"; then ac_cv_prog_UNAME="$UNAME" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_UNAME="uname" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS test -z "$ac_cv_prog_UNAME" && ac_cv_prog_UNAME="nouname" fi fi UNAME=$ac_cv_prog_UNAME if test -n "$UNAME"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $UNAME" >&5 $as_echo "$UNAME" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test $UNAME = nouname; then as_fn_error $? "HEAsoft: Unable to guess system type. Please set it using --with-bindir option" "$LINENO" 5 fi BINDIR=`$UNAME -s 2> /dev/null`_`$UNAME -r 2> /dev/null | sed 's:[^0-9]*\([0-9][0-9]*\.[0-9]*\).*:\1:'` lhea_machine=`$UNAME -m 2> /dev/null` BIN_EXT= case $BINDIR in CYGWIN*) BINDIR=CYGWIN32_`$UNAME -a 2> /dev/null | awk '{ print $4 }'` lhea_machine= BIN_EXT=".exe" EXT=win ;; Linux*) EXT=lnx ;; Darwin*) EXT=darwin lhea_machine=`$UNAME -p` ;; SunOS_5*) EXT=sol lhea_machine=`$UNAME -p` ;; *) as_fn_error $? "Unable to recognize your system. Please make sure this platform is supported." "$LINENO" 5 ;; esac if test x$lhea_machine != x; then BINDIR=$BINDIR"_"$lhea_machine fi fi #------------------------------------------------------------------------------- # Checks for programs. #------------------------------------------------------------------------------- # Try first to find a proprietary C compiler, then gcc if test "x$CC" = x; then for ac_prog in cc do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$CC" && break done fi # Set up flags to use the selected compiler # ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. set dummy ${ac_tool_prefix}gcc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="${ac_tool_prefix}gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_CC"; then ac_ct_CC=$CC # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CC="gcc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 $as_echo "$ac_ct_CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi else CC="$ac_cv_prog_CC" fi if test -z "$CC"; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. set dummy ${ac_tool_prefix}cc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="${ac_tool_prefix}cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi fi if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else ac_prog_rejected=no as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then ac_prog_rejected=yes continue fi ac_cv_prog_CC="cc" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS if test $ac_prog_rejected = yes; then # We found a bogon in the path, so make sure we never use it. set dummy $ac_cv_prog_CC shift if test $# != 0; then # We chose a different compiler from the bogus one. # However, it has the same basename, so the bogon will be chosen # first if we set CC to just the basename; use the full file name. shift ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" fi fi fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$CC"; then if test -n "$ac_tool_prefix"; then for ac_prog in cl.exe do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CC="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 $as_echo "$CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$CC" && break done fi if test -z "$CC"; then ac_ct_CC=$CC for ac_prog in cl.exe do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_CC+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CC="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 $as_echo "$ac_ct_CC" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi test -n "$ac_ct_CC" && break done if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi fi fi test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "no acceptable C compiler found in \$PATH See \`config.log' for more details" "$LINENO" 5; } # Provide some information about the compiler. $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 set X $ac_compile ac_compiler=$2 for ac_option in --version -v -V -qversion; do { { ac_try="$ac_compiler $ac_option >&5" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compiler $ac_option >&5") 2>conftest.err ac_status=$? if test -s conftest.err; then sed '10a\ ... rest of stderr output deleted ... 10q' conftest.err >conftest.er1 cat conftest.er1 >&5 fi rm -f conftest.er1 conftest.err $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } done cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" # Try to create an executable without -o first, disregard a.out. # It will help us diagnose broken compilers, and finding out an intuition # of exeext. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 $as_echo_n "checking whether the C compiler works... " >&6; } ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` # The possible output files: ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" ac_rmfiles= for ac_file in $ac_files do case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; * ) ac_rmfiles="$ac_rmfiles $ac_file";; esac done rm -f $ac_rmfiles if { { ac_try="$ac_link_default" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link_default") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. # So ignore a value of `no', otherwise this would lead to `EXEEXT = no' # in a Makefile. We should not override ac_cv_exeext if it was cached, # so that the user can short-circuit this test for compilers unknown to # Autoconf. for ac_file in $ac_files '' do test -f "$ac_file" || continue case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; [ab].out ) # We found the default executable, but exeext='' is most # certainly right. break;; *.* ) if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; then :; else ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` fi # We set ac_cv_exeext here because the later test for it is not # safe: cross compilers may not add the suffix if given an `-o' # argument, so we may need to know it at that point already. # Even if this section looks crufty: it has the advantage of # actually working. break;; * ) break;; esac done test "$ac_cv_exeext" = no && ac_cv_exeext= else ac_file='' fi if test -z "$ac_file"; then : { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "C compiler cannot create executables See \`config.log' for more details" "$LINENO" 5; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 $as_echo_n "checking for C compiler default output file name... " >&6; } { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 $as_echo "$ac_file" >&6; } ac_exeext=$ac_cv_exeext rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out ac_clean_files=$ac_clean_files_save { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 $as_echo_n "checking for suffix of executables... " >&6; } if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : # If both `conftest.exe' and `conftest' are `present' (well, observable) # catch `conftest.exe'. For instance with Cygwin, `ls conftest' will # work properly (i.e., refer to `conftest.exe'), while it won't with # `rm'. for ac_file in conftest.exe conftest conftest.*; do test -f "$ac_file" || continue case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` break;; * ) break;; esac done else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of executables: cannot compile and link See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest conftest$ac_cv_exeext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 $as_echo "$ac_cv_exeext" >&6; } rm -f conftest.$ac_ext EXEEXT=$ac_cv_exeext ac_exeext=$EXEEXT cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { FILE *f = fopen ("conftest.out", "w"); return ferror (f) || fclose (f) != 0; ; return 0; } _ACEOF ac_clean_files="$ac_clean_files conftest.out" # Check that the compiler produces executables we can run. If not, either # the compiler is broken, or we cross compile. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 $as_echo_n "checking whether we are cross compiling... " >&6; } if test "$cross_compiling" != yes; then { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if { ac_try='./conftest$ac_cv_exeext' { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then cross_compiling=no else if test "$cross_compiling" = maybe; then cross_compiling=yes else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot run C compiled programs. If you meant to cross compile, use \`--host'. See \`config.log' for more details" "$LINENO" 5; } fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 $as_echo "$cross_compiling" >&6; } rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out ac_clean_files=$ac_clean_files_save { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 $as_echo_n "checking for suffix of object files... " >&6; } if ${ac_cv_objext+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF rm -f conftest.o conftest.obj if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" $as_echo "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>&5 ac_status=$? $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then : for ac_file in conftest.o conftest.obj conftest.*; do test -f "$ac_file" || continue; case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;; *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` break;; esac done else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of object files: cannot compile See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest.$ac_cv_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 $as_echo "$ac_cv_objext" >&6; } OBJEXT=$ac_cv_objext ac_objext=$OBJEXT { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 $as_echo_n "checking whether we are using the GNU C compiler... " >&6; } if ${ac_cv_c_compiler_gnu+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { #ifndef __GNUC__ choke me #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_compiler_gnu=yes else ac_compiler_gnu=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_cv_c_compiler_gnu=$ac_compiler_gnu fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 $as_echo "$ac_cv_c_compiler_gnu" >&6; } if test $ac_compiler_gnu = yes; then GCC=yes else GCC= fi ac_test_CFLAGS=${CFLAGS+set} ac_save_CFLAGS=$CFLAGS { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 $as_echo_n "checking whether $CC accepts -g... " >&6; } if ${ac_cv_prog_cc_g+:} false; then : $as_echo_n "(cached) " >&6 else ac_save_c_werror_flag=$ac_c_werror_flag ac_c_werror_flag=yes ac_cv_prog_cc_g=no CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_g=yes else CFLAGS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : else ac_c_werror_flag=$ac_save_c_werror_flag CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_g=yes fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_c_werror_flag=$ac_save_c_werror_flag fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 $as_echo "$ac_cv_prog_cc_g" >&6; } if test "$ac_test_CFLAGS" = set; then CFLAGS=$ac_save_CFLAGS elif test $ac_cv_prog_cc_g = yes; then if test "$GCC" = yes; then CFLAGS="-g -O2" else CFLAGS="-g" fi else if test "$GCC" = yes; then CFLAGS="-O2" else CFLAGS= fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 $as_echo_n "checking for $CC option to accept ISO C89... " >&6; } if ${ac_cv_prog_cc_c89+:} false; then : $as_echo_n "(cached) " >&6 else ac_cv_prog_cc_c89=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include struct stat; /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ struct buf { int x; }; FILE * (*rcsopen) (struct buf *, struct stat *, int); static char *e (p, i) char **p; int i; { return p[i]; } static char *f (char * (*g) (char **, int), char **p, ...) { char *s; va_list v; va_start (v,p); s = g (p, va_arg (v,int)); va_end (v); return s; } /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has function prototypes and stuff, but not '\xHH' hex character constants. These don't provoke an error unfortunately, instead are silently treated as 'x'. The following induces an error, until -std is added to get proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an array size at least. It's necessary to write '\x00'==0 to get something that's true only with -std. */ int osf4_cc_array ['\x00' == 0 ? 1 : -1]; /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters inside strings and character constants. */ #define FOO(x) 'x' int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; int test (int i, double x); struct s1 {int (*f) (int a);}; struct s2 {int (*f) (double a);}; int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); int argc; char **argv; int main () { return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; ; return 0; } _ACEOF for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" do CC="$ac_save_CC $ac_arg" if ac_fn_c_try_compile "$LINENO"; then : ac_cv_prog_cc_c89=$ac_arg fi rm -f core conftest.err conftest.$ac_objext test "x$ac_cv_prog_cc_c89" != "xno" && break done rm -f conftest.$ac_ext CC=$ac_save_CC fi # AC_CACHE_VAL case "x$ac_cv_prog_cc_c89" in x) { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 $as_echo "none needed" >&6; } ;; xno) { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 $as_echo "unsupported" >&6; } ;; *) CC="$CC $ac_cv_prog_cc_c89" { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 $as_echo "$ac_cv_prog_cc_c89" >&6; } ;; esac if test "x$ac_cv_prog_cc_c89" != xno; then : fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu if test "$cross_compiling" = yes; then { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Cannot run a simple C executable on your system:" >&5 $as_echo "$as_me: WARNING: Cannot run a simple C executable on your system:" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: There may be something wrong with your compiler" >&5 $as_echo "$as_me: WARNING: There may be something wrong with your compiler" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: or perhaps you are trying to cross-compile?" >&5 $as_echo "$as_me: WARNING: or perhaps you are trying to cross-compile?" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Cross-compiling is not supported within HEAsoft." >&5 $as_echo "$as_me: WARNING: Cross-compiling is not supported within HEAsoft." >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Please make sure your compiler is working." >&5 $as_echo "$as_me: WARNING: Please make sure your compiler is working." >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Contact the FTOOLS help desk for further assistance." >&5 $as_echo "$as_me: WARNING: Contact the FTOOLS help desk for further assistance." >&2;} as_fn_error $? "Cross-compiling is not allowed." "$LINENO" 5 fi if test "x$GCC" = x; then GCC=no fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. set dummy ${ac_tool_prefix}ranlib; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_RANLIB+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$RANLIB"; then ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi RANLIB=$ac_cv_prog_RANLIB if test -n "$RANLIB"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5 $as_echo "$RANLIB" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test -z "$ac_cv_prog_RANLIB"; then ac_ct_RANLIB=$RANLIB # Extract the first word of "ranlib", so it can be a program name with args. set dummy ranlib; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_ac_ct_RANLIB+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_RANLIB"; then ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_RANLIB="ranlib" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi fi ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB if test -n "$ac_ct_RANLIB"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5 $as_echo "$ac_ct_RANLIB" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi if test "x$ac_ct_RANLIB" = x; then RANLIB=":" else case $cross_compiling:$ac_tool_warned in yes:) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac RANLIB=$ac_ct_RANLIB fi else RANLIB="$ac_cv_prog_RANLIB" fi if test $EXT = darwin; then RANLIB="$RANLIB -cs" fi #------------------------------------------------------------------------------- # Checks for libraries. #------------------------------------------------------------------------------- # X XLIBS= XLIBPTH= XINCLUDES= # socket and nsl libraries -- only if needed ac_fn_c_check_func "$LINENO" "gethostbyname" "ac_cv_func_gethostbyname" if test "x$ac_cv_func_gethostbyname" = xyes; then : else { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gethostbyname in -lnsl" >&5 $as_echo_n "checking for gethostbyname in -lnsl... " >&6; } if ${ac_cv_lib_nsl_gethostbyname+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-lnsl $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char gethostbyname (); int main () { return gethostbyname (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_nsl_gethostbyname=yes else ac_cv_lib_nsl_gethostbyname=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_nsl_gethostbyname" >&5 $as_echo "$ac_cv_lib_nsl_gethostbyname" >&6; } if test "x$ac_cv_lib_nsl_gethostbyname" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBNSL 1 _ACEOF LIBS="-lnsl $LIBS" fi fi for ac_func in connect accept do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" if eval test \"x\$"$as_ac_var"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF else { $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -lsocket" >&5 $as_echo_n "checking for main in -lsocket... " >&6; } if ${ac_cv_lib_socket_main+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-lsocket $XLIBS $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { return main (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_socket_main=yes else ac_cv_lib_socket_main=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_socket_main" >&5 $as_echo "$ac_cv_lib_socket_main" >&6; } if test "x$ac_cv_lib_socket_main" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBSOCKET 1 _ACEOF LIBS="-lsocket $LIBS" fi fi done # Prepend the standard location X11 bin directory (if it exists) to PATH # to assist AC_PATH_X in finding headers & libraries: if test -d /usr/X11R6/bin; then if test "x$PATH" != x; then PATH=$PATH:/usr/X11R6/bin else PATH=/usr/X11R6/bin fi export PATH fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 $as_echo_n "checking how to run the C preprocessor... " >&6; } # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= fi if test -z "$CPP"; then if ${ac_cv_prog_CPP+:} false; then : $as_echo_n "(cached) " >&6 else # Double quotes because CPP needs to be expanded for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" do ac_preproc_ok=false for ac_c_preproc_warn_flag in '' yes do # Use a header file that comes with gcc, so configuring glibc # with a fresh cross-compiler works. # Prefer to if __STDC__ is defined, since # exists even on freestanding compilers. # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. "Syntax error" is here to catch this case. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef __STDC__ # include #else # include #endif Syntax error _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : else # Broken: fails on valid input. continue fi rm -f conftest.err conftest.i conftest.$ac_ext # OK, works on sane cases. Now check whether nonexistent headers # can be detected and how. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : # Broken: success on invalid input. continue else # Passes both tests. ac_preproc_ok=: break fi rm -f conftest.err conftest.i conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. rm -f conftest.i conftest.err conftest.$ac_ext if $ac_preproc_ok; then : break fi done ac_cv_prog_CPP=$CPP fi CPP=$ac_cv_prog_CPP else ac_cv_prog_CPP=$CPP fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 $as_echo "$CPP" >&6; } ac_preproc_ok=false for ac_c_preproc_warn_flag in '' yes do # Use a header file that comes with gcc, so configuring glibc # with a fresh cross-compiler works. # Prefer to if __STDC__ is defined, since # exists even on freestanding compilers. # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. "Syntax error" is here to catch this case. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef __STDC__ # include #else # include #endif Syntax error _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : else # Broken: fails on valid input. continue fi rm -f conftest.err conftest.i conftest.$ac_ext # OK, works on sane cases. Now check whether nonexistent headers # can be detected and how. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : # Broken: success on invalid input. continue else # Passes both tests. ac_preproc_ok=: break fi rm -f conftest.err conftest.i conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. rm -f conftest.i conftest.err conftest.$ac_ext if $ac_preproc_ok; then : else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "C preprocessor \"$CPP\" fails sanity check See \`config.log' for more details" "$LINENO" 5; } fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu { $as_echo "$as_me:${as_lineno-$LINENO}: checking for X" >&5 $as_echo_n "checking for X... " >&6; } # Check whether --with-x was given. if test "${with_x+set}" = set; then : withval=$with_x; fi # $have_x is `yes', `no', `disabled', or empty when we do not yet know. if test "x$with_x" = xno; then # The user explicitly disabled X. have_x=disabled else case $x_includes,$x_libraries in #( *\'*) as_fn_error $? "cannot use X directory names containing '" "$LINENO" 5;; #( *,NONE | NONE,*) if ${ac_cv_have_x+:} false; then : $as_echo_n "(cached) " >&6 else # One or both of the vars are not set, and there is no cached value. ac_x_includes=no ac_x_libraries=no rm -f -r conftest.dir if mkdir conftest.dir; then cd conftest.dir cat >Imakefile <<'_ACEOF' incroot: @echo incroot='${INCROOT}' usrlibdir: @echo usrlibdir='${USRLIBDIR}' libdir: @echo libdir='${LIBDIR}' _ACEOF if (export CC; ${XMKMF-xmkmf}) >/dev/null 2>/dev/null && test -f Makefile; then # GNU make sometimes prints "make[1]: Entering ...", which would confuse us. for ac_var in incroot usrlibdir libdir; do eval "ac_im_$ac_var=\`\${MAKE-make} $ac_var 2>/dev/null | sed -n 's/^$ac_var=//p'\`" done # Open Windows xmkmf reportedly sets LIBDIR instead of USRLIBDIR. for ac_extension in a so sl dylib la dll; do if test ! -f "$ac_im_usrlibdir/libX11.$ac_extension" && test -f "$ac_im_libdir/libX11.$ac_extension"; then ac_im_usrlibdir=$ac_im_libdir; break fi done # Screen out bogus values from the imake configuration. They are # bogus both because they are the default anyway, and because # using them would break gcc on systems where it needs fixed includes. case $ac_im_incroot in /usr/include) ac_x_includes= ;; *) test -f "$ac_im_incroot/X11/Xos.h" && ac_x_includes=$ac_im_incroot;; esac case $ac_im_usrlibdir in /usr/lib | /usr/lib64 | /lib | /lib64) ;; *) test -d "$ac_im_usrlibdir" && ac_x_libraries=$ac_im_usrlibdir ;; esac fi cd .. rm -f -r conftest.dir fi # Standard set of common directories for X headers. # Check X11 before X11Rn because it is often a symlink to the current release. ac_x_header_dirs=' /usr/X11/include /usr/X11R7/include /usr/X11R6/include /usr/X11R5/include /usr/X11R4/include /usr/include/X11 /usr/include/X11R7 /usr/include/X11R6 /usr/include/X11R5 /usr/include/X11R4 /usr/local/X11/include /usr/local/X11R7/include /usr/local/X11R6/include /usr/local/X11R5/include /usr/local/X11R4/include /usr/local/include/X11 /usr/local/include/X11R7 /usr/local/include/X11R6 /usr/local/include/X11R5 /usr/local/include/X11R4 /usr/X386/include /usr/x386/include /usr/XFree86/include/X11 /usr/include /usr/local/include /usr/unsupported/include /usr/athena/include /usr/local/x11r5/include /usr/lpp/Xamples/include /usr/openwin/include /usr/openwin/share/include' if test "$ac_x_includes" = no; then # Guess where to find include files, by looking for Xlib.h. # First, try using that file with no special directory specified. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if ac_fn_c_try_cpp "$LINENO"; then : # We can compile using X headers with no special include directory. ac_x_includes= else for ac_dir in $ac_x_header_dirs; do if test -r "$ac_dir/X11/Xlib.h"; then ac_x_includes=$ac_dir break fi done fi rm -f conftest.err conftest.i conftest.$ac_ext fi # $ac_x_includes = no if test "$ac_x_libraries" = no; then # Check for the libraries. # See if we find them without any special options. # Don't add to $LIBS permanently. ac_save_LIBS=$LIBS LIBS="-lX11 $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { XrmInitialize () ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : LIBS=$ac_save_LIBS # We can link X programs with no special library path. ac_x_libraries= else LIBS=$ac_save_LIBS for ac_dir in `$as_echo "$ac_x_includes $ac_x_header_dirs" | sed s/include/lib/g` do # Don't even attempt the hair of trying to link an X program! for ac_extension in a so sl dylib la dll; do if test -r "$ac_dir/libX11.$ac_extension"; then ac_x_libraries=$ac_dir break 2 fi done done fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi # $ac_x_libraries = no case $ac_x_includes,$ac_x_libraries in #( no,* | *,no | *\'*) # Didn't find X, or a directory has "'" in its name. ac_cv_have_x="have_x=no";; #( *) # Record where we found X for the cache. ac_cv_have_x="have_x=yes\ ac_x_includes='$ac_x_includes'\ ac_x_libraries='$ac_x_libraries'" esac fi ;; #( *) have_x=yes;; esac eval "$ac_cv_have_x" fi # $with_x != no if test "$have_x" != yes; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_x" >&5 $as_echo "$have_x" >&6; } no_x=yes else # If each of the values was on the command line, it overrides each guess. test "x$x_includes" = xNONE && x_includes=$ac_x_includes test "x$x_libraries" = xNONE && x_libraries=$ac_x_libraries # Update the cache value to reflect the command line values. ac_cv_have_x="have_x=yes\ ac_x_includes='$x_includes'\ ac_x_libraries='$x_libraries'" { $as_echo "$as_me:${as_lineno-$LINENO}: result: libraries $x_libraries, headers $x_includes" >&5 $as_echo "libraries $x_libraries, headers $x_includes" >&6; } fi if test "x$no_x" != xyes; then USE_X=yes no_x=no if test `echo $x_includes | grep -c /` -ne 0; then XINCLUDES="-I$x_includes" fi if test `echo $x_libraries | grep -c /` -ne 0; then XLIBPTH="-L$x_libraries " fi XLIBS="$XLIBPTH-lX11" if test -f $x_libraries/libXt.a; then XLIBS="$XLIBS -lXt" fi # dnet_stub { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getnodebyname in -ldnet_stub" >&5 $as_echo_n "checking for getnodebyname in -ldnet_stub... " >&6; } if ${ac_cv_lib_dnet_stub_getnodebyname+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-ldnet_stub $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char getnodebyname (); int main () { return getnodebyname (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_dnet_stub_getnodebyname=yes else ac_cv_lib_dnet_stub_getnodebyname=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dnet_stub_getnodebyname" >&5 $as_echo "$ac_cv_lib_dnet_stub_getnodebyname" >&6; } if test "x$ac_cv_lib_dnet_stub_getnodebyname" = xyes; then : XLIBS="$XLIBS -ldnet_stub" fi else USE_X=no fi # dl { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 $as_echo_n "checking for dlopen in -ldl... " >&6; } if ${ac_cv_lib_dl_dlopen+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-ldl $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char dlopen (); int main () { return dlopen (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_dl_dlopen=yes else ac_cv_lib_dl_dlopen=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 $as_echo "$ac_cv_lib_dl_dlopen" >&6; } if test "x$ac_cv_lib_dl_dlopen" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBDL 1 _ACEOF LIBS="-ldl $LIBS" fi if test `echo $LIBS | grep -c '\-ldl'` -eq 0; then { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldld" >&5 $as_echo_n "checking for dlopen in -ldld... " >&6; } if ${ac_cv_lib_dld_dlopen+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-ldld $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char dlopen (); int main () { return dlopen (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_dld_dlopen=yes else ac_cv_lib_dld_dlopen=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_dlopen" >&5 $as_echo "$ac_cv_lib_dld_dlopen" >&6; } if test "x$ac_cv_lib_dld_dlopen" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_LIBDLD 1 _ACEOF LIBS="-ldld $LIBS" fi fi # If available, use curl-config to get linker flags for Curl library, # which may be pulled in to the shared CFITSIO library for HTTPS support. # On Macs, prefer XCode curl-config, and reject MacPorts version until # further notice to prevent build errors: CURL_LIB="" if test "x$EXT" = xdarwin -a -x /usr/bin/curl-config; then CURLCONFIG="/usr/bin/curl-config" { $as_echo "$as_me:${as_lineno-$LINENO}: result: checking for curl-config... choosing /usr/bin/curl-config on Mac" >&5 $as_echo "checking for curl-config... choosing /usr/bin/curl-config on Mac" >&6; } else # Extract the first word of "curl-config", so it can be a program name with args. set dummy curl-config; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } if ${ac_cv_prog_CURLCONFIG+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CURLCONFIG"; then ac_cv_prog_CURLCONFIG="$CURLCONFIG" # Let the user override the test. else ac_prog_rejected=no as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then if test "$as_dir/$ac_word$ac_exec_ext" = "/opt/local/bin/curl-config"; then ac_prog_rejected=yes continue fi ac_cv_prog_CURLCONFIG="curl-config" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS if test $ac_prog_rejected = yes; then # We found a bogon in the path, so make sure we never use it. set dummy $ac_cv_prog_CURLCONFIG shift if test $# != 0; then # We chose a different compiler from the bogus one. # However, it has the same basename, so the bogon will be chosen # first if we set CURLCONFIG to just the basename; use the full file name. shift ac_cv_prog_CURLCONFIG="$as_dir/$ac_word${1+' '}$@" fi fi fi fi CURLCONFIG=$ac_cv_prog_CURLCONFIG if test -n "$CURLCONFIG"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CURLCONFIG" >&5 $as_echo "$CURLCONFIG" >&6; } else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi fi if test "x$CURLCONFIG" != x; then CURL_LIB=`$CURLCONFIG --libs` # Also reject anaconda curl on Macs until further notice: if test "x$EXT" = xdarwin -a `echo $CURL_LIB | grep -ci anaconda` -gt 0; then LIBS="$LIBS $CURL_LIB" fi fi #------------------------------------------------------------------------------- # Checks for header files. #------------------------------------------------------------------------------- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 $as_echo_n "checking for grep that handles long lines and -e... " >&6; } if ${ac_cv_path_GREP+:} false; then : $as_echo_n "(cached) " >&6 else if test -z "$GREP"; then ac_path_GREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_prog in grep ggrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_GREP" || continue # Check for GNU ac_path_GREP and select it if it is found. # Check for GNU $ac_path_GREP case `"$ac_path_GREP" --version 2>&1` in *GNU*) ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; *) ac_count=0 $as_echo_n 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" $as_echo 'GREP' >> "conftest.nl" "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_GREP_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_GREP_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_GREP"; then as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 fi else ac_cv_path_GREP=$GREP fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 $as_echo "$ac_cv_path_GREP" >&6; } GREP="$ac_cv_path_GREP" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 $as_echo_n "checking for egrep... " >&6; } if ${ac_cv_path_EGREP+:} false; then : $as_echo_n "(cached) " >&6 else if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 then ac_cv_path_EGREP="$GREP -E" else if test -z "$EGREP"; then ac_path_EGREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_prog in egrep; do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_EGREP" || continue # Check for GNU ac_path_EGREP and select it if it is found. # Check for GNU $ac_path_EGREP case `"$ac_path_EGREP" --version 2>&1` in *GNU*) ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; *) ac_count=0 $as_echo_n 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" $as_echo 'EGREP' >> "conftest.nl" "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_EGREP_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_EGREP_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_EGREP"; then as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 fi else ac_cv_path_EGREP=$EGREP fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 $as_echo "$ac_cv_path_EGREP" >&6; } EGREP="$ac_cv_path_EGREP" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 $as_echo_n "checking for ANSI C header files... " >&6; } if ${ac_cv_header_stdc+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #include #include int main () { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_header_stdc=yes else ac_cv_header_stdc=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "memchr" >/dev/null 2>&1; then : else ac_cv_header_stdc=no fi rm -f conftest* fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "free" >/dev/null 2>&1; then : else ac_cv_header_stdc=no fi rm -f conftest* fi if test $ac_cv_header_stdc = yes; then # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. if test "$cross_compiling" = yes; then : : else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #if ((' ' & 0x0FF) == 0x020) # define ISLOWER(c) ('a' <= (c) && (c) <= 'z') # define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) #else # define ISLOWER(c) \ (('a' <= (c) && (c) <= 'i') \ || ('j' <= (c) && (c) <= 'r') \ || ('s' <= (c) && (c) <= 'z')) # define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) #endif #define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) int main () { int i; for (i = 0; i < 256; i++) if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) return 2; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : else ac_cv_header_stdc=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 $as_echo "$ac_cv_header_stdc" >&6; } if test $ac_cv_header_stdc = yes; then $as_echo "#define STDC_HEADERS 1" >>confdefs.h fi # On IRIX 5.3, sys/types and inttypes.h are conflicting. for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ inttypes.h stdint.h unistd.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default " if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 _ACEOF fi done for ac_header in dirent.h fcntl.h limits.h malloc.h string.h sys/time.h unistd.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 _ACEOF fi done { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether time.h and sys/time.h may both be included" >&5 $as_echo_n "checking whether time.h and sys/time.h may both be included... " >&6; } if ${ac_cv_header_time+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #include int main () { if ((struct tm *) 0) return 0; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_header_time=yes else ac_cv_header_time=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_time" >&5 $as_echo "$ac_cv_header_time" >&6; } if test $ac_cv_header_time = yes; then $as_echo "#define TIME_WITH_SYS_TIME 1" >>confdefs.h fi ac_fn_c_check_type "$LINENO" "size_t" "ac_cv_type_size_t" "$ac_includes_default" if test "x$ac_cv_type_size_t" = xyes; then : else cat >>confdefs.h <<_ACEOF #define size_t unsigned int _ACEOF fi # The Ultrix 4.2 mips builtin alloca declared by alloca.h only works # for constant arguments. Useless! { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working alloca.h" >&5 $as_echo_n "checking for working alloca.h... " >&6; } if ${ac_cv_working_alloca_h+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main () { char *p = (char *) alloca (2 * sizeof (int)); if (p) return 0; ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_working_alloca_h=yes else ac_cv_working_alloca_h=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_working_alloca_h" >&5 $as_echo "$ac_cv_working_alloca_h" >&6; } if test $ac_cv_working_alloca_h = yes; then $as_echo "#define HAVE_ALLOCA_H 1" >>confdefs.h fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for alloca" >&5 $as_echo_n "checking for alloca... " >&6; } if ${ac_cv_func_alloca_works+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #ifdef __GNUC__ # define alloca __builtin_alloca #else # ifdef _MSC_VER # include # define alloca _alloca # else # ifdef HAVE_ALLOCA_H # include # else # ifdef _AIX #pragma alloca # else # ifndef alloca /* predefined by HP cc +Olibcalls */ void *alloca (size_t); # endif # endif # endif # endif #endif int main () { char *p = (char *) alloca (1); if (p) return 0; ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_func_alloca_works=yes else ac_cv_func_alloca_works=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_alloca_works" >&5 $as_echo "$ac_cv_func_alloca_works" >&6; } if test $ac_cv_func_alloca_works = yes; then $as_echo "#define HAVE_ALLOCA 1" >>confdefs.h else # The SVR3 libPW and SVR4 libucb both contain incompatible functions # that cause trouble. Some versions do not even contain alloca or # contain a buggy version. If you still want to use their alloca, # use ar to extract alloca.o from them instead of compiling alloca.c. ALLOCA=\${LIBOBJDIR}alloca.$ac_objext $as_echo "#define C_ALLOCA 1" >>confdefs.h { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether \`alloca.c' needs Cray hooks" >&5 $as_echo_n "checking whether \`alloca.c' needs Cray hooks... " >&6; } if ${ac_cv_os_cray+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #if defined CRAY && ! defined CRAY2 webecray #else wenotbecray #endif _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "webecray" >/dev/null 2>&1; then : ac_cv_os_cray=yes else ac_cv_os_cray=no fi rm -f conftest* fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_os_cray" >&5 $as_echo "$ac_cv_os_cray" >&6; } if test $ac_cv_os_cray = yes; then for ac_func in _getb67 GETB67 getb67; do as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" if eval test \"x\$"$as_ac_var"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define CRAY_STACKSEG_END $ac_func _ACEOF break fi done fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking stack direction for C alloca" >&5 $as_echo_n "checking stack direction for C alloca... " >&6; } if ${ac_cv_c_stack_direction+:} false; then : $as_echo_n "(cached) " >&6 else if test "$cross_compiling" = yes; then : ac_cv_c_stack_direction=0 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default int find_stack_direction (int *addr, int depth) { int dir, dummy = 0; if (! addr) addr = &dummy; *addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1; dir = depth ? find_stack_direction (addr, depth - 1) : 0; return dir + dummy; } int main (int argc, char **argv) { return find_stack_direction (0, argc + !argv + 20) < 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : ac_cv_c_stack_direction=1 else ac_cv_c_stack_direction=-1 fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_stack_direction" >&5 $as_echo "$ac_cv_c_stack_direction" >&6; } cat >>confdefs.h <<_ACEOF #define STACK_DIRECTION $ac_cv_c_stack_direction _ACEOF fi #------------------------------------------------------------------------------- # Checks for typedefs, structures, and compiler characteristics. #------------------------------------------------------------------------------- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for an ANSI C-conforming const" >&5 $as_echo_n "checking for an ANSI C-conforming const... " >&6; } if ${ac_cv_c_const+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main () { #ifndef __cplusplus /* Ultrix mips cc rejects this sort of thing. */ typedef int charset[2]; const charset cs = { 0, 0 }; /* SunOS 4.1.1 cc rejects this. */ char const *const *pcpcc; char **ppc; /* NEC SVR4.0.2 mips cc rejects this. */ struct point {int x, y;}; static struct point const zero = {0,0}; /* AIX XL C 1.02.0.0 rejects this. It does not let you subtract one const X* pointer from another in an arm of an if-expression whose if-part is not a constant expression */ const char *g = "string"; pcpcc = &g + (g ? g-g : 0); /* HPUX 7.0 cc rejects these. */ ++pcpcc; ppc = (char**) pcpcc; pcpcc = (char const *const *) ppc; { /* SCO 3.2v4 cc rejects this sort of thing. */ char tx; char *t = &tx; char const *s = 0 ? (char *) 0 : (char const *) 0; *t++ = 0; if (s) return 0; } { /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */ int x[] = {25, 17}; const int *foo = &x[0]; ++foo; } { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */ typedef const int *iptr; iptr p = 0; ++p; } { /* AIX XL C 1.02.0.0 rejects this sort of thing, saying "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */ struct s { int j; const int *ap[3]; } bx; struct s *b = &bx; b->j = 5; } { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */ const int foo = 10; if (!foo) return 0; } return !cs[0] && !zero.x; #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_c_const=yes else ac_cv_c_const=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_const" >&5 $as_echo "$ac_cv_c_const" >&6; } if test $ac_cv_c_const = no; then $as_echo "#define const /**/" >>confdefs.h fi ac_fn_c_check_type "$LINENO" "mode_t" "ac_cv_type_mode_t" "$ac_includes_default" if test "x$ac_cv_type_mode_t" = xyes; then : else cat >>confdefs.h <<_ACEOF #define mode_t int _ACEOF fi ac_fn_c_check_type "$LINENO" "size_t" "ac_cv_type_size_t" "$ac_includes_default" if test "x$ac_cv_type_size_t" = xyes; then : else cat >>confdefs.h <<_ACEOF #define size_t unsigned int _ACEOF fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether struct tm is in sys/time.h or time.h" >&5 $as_echo_n "checking whether struct tm is in sys/time.h or time.h... " >&6; } if ${ac_cv_struct_tm+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include int main () { struct tm tm; int *p = &tm.tm_sec; return !p; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_struct_tm=time.h else ac_cv_struct_tm=sys/time.h fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_struct_tm" >&5 $as_echo "$ac_cv_struct_tm" >&6; } if test $ac_cv_struct_tm = sys/time.h; then $as_echo "#define TM_IN_SYS_TIME 1" >>confdefs.h fi #------------------------------------------------------------------------------- # Tweak compiler flags as needed #------------------------------------------------------------------------------- case $EXT in darwin) CFLAGS="$CFLAGS -Dunix" ;; lnx) ;; sol) $as_echo "#define HAVE_POSIX_SIGNALS 1" >>confdefs.h ;; *) ;; esac #------------------------------------------------------------------------------- # Shared library section #------------------------------------------------------------------------------- LD_FLAGS= SHLIB_SUFFIX=".so" SHLIB_LD_LIBS="" lhea_shlib_cflags= lhea_shlib_fflags= if test $lhea_shared = yes; then case $EXT in darwin) SHLIB_LD="$CC -dynamiclib -flat_namespace -undefined suppress" SHLIB_SUFFIX=".dylib" lhea_shlib_cflags='-fPIC -fno-common' lhea_shlib_fflags='-fPIC -fno-common' ;; lnx) SHLIB_LD=":" ;; sol) SHLIB_LD="/usr/ccs/bin/ld -G" SHLIB_LD_LIBS='${LIBS}' lhea_shlib_cflags="-KPIC" lhea_shlib_fflags="-KPIC" ;; win) SHLIB_LD="$CC -shared" SHLIB_SUFFIX=".dll" ;; *) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Unable to determine how to make a shared library" >&5 $as_echo "$as_me: WARNING: Unable to determine how to make a shared library" >&2;} ;; esac # Darwin uses gcc, but uses -dynamiclib flag if test $GCC = yes -a $EXT != darwin; then SHLIB_LD="$CC -shared" lhea_shlib_cflags='-fPIC' fi if test "x$lhea_shlib_cflags" != x; then CFLAGS="$CFLAGS $lhea_shlib_cflags" fi else SHLIB_LD=: fi #------------------------------------------------------------------------------- # Checks for library functions. #------------------------------------------------------------------------------- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working memcmp" >&5 $as_echo_n "checking for working memcmp... " >&6; } if ${ac_cv_func_memcmp_working+:} false; then : $as_echo_n "(cached) " >&6 else if test "$cross_compiling" = yes; then : ac_cv_func_memcmp_working=no else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default int main () { /* Some versions of memcmp are not 8-bit clean. */ char c0 = '\100', c1 = '\200', c2 = '\201'; if (memcmp(&c0, &c2, 1) >= 0 || memcmp(&c1, &c2, 1) >= 0) return 1; /* The Next x86 OpenStep bug shows up only when comparing 16 bytes or more and with at least one buffer not starting on a 4-byte boundary. William Lewis provided this test program. */ { char foo[21]; char bar[21]; int i; for (i = 0; i < 4; i++) { char *a = foo + i; char *b = bar + i; strcpy (a, "--------01111111"); strcpy (b, "--------10000000"); if (memcmp (a, b, 16) >= 0) return 1; } return 0; } ; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO"; then : ac_cv_func_memcmp_working=yes else ac_cv_func_memcmp_working=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_memcmp_working" >&5 $as_echo "$ac_cv_func_memcmp_working" >&6; } test $ac_cv_func_memcmp_working = no && case " $LIBOBJS " in *" memcmp.$ac_objext "* ) ;; *) LIBOBJS="$LIBOBJS memcmp.$ac_objext" ;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking return type of signal handlers" >&5 $as_echo_n "checking return type of signal handlers... " >&6; } if ${ac_cv_type_signal+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include int main () { return *(signal (0, 0)) (0) == 1; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : ac_cv_type_signal=int else ac_cv_type_signal=void fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_signal" >&5 $as_echo "$ac_cv_type_signal" >&6; } cat >>confdefs.h <<_ACEOF #define RETSIGTYPE $ac_cv_type_signal _ACEOF for ac_func in strftime do : ac_fn_c_check_func "$LINENO" "strftime" "ac_cv_func_strftime" if test "x$ac_cv_func_strftime" = xyes; then : cat >>confdefs.h <<_ACEOF #define HAVE_STRFTIME 1 _ACEOF else # strftime is in -lintl on SCO UNIX. { $as_echo "$as_me:${as_lineno-$LINENO}: checking for strftime in -lintl" >&5 $as_echo_n "checking for strftime in -lintl... " >&6; } if ${ac_cv_lib_intl_strftime+:} false; then : $as_echo_n "(cached) " >&6 else ac_check_lib_save_LIBS=$LIBS LIBS="-lintl $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char strftime (); int main () { return strftime (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO"; then : ac_cv_lib_intl_strftime=yes else ac_cv_lib_intl_strftime=no fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_intl_strftime" >&5 $as_echo "$ac_cv_lib_intl_strftime" >&6; } if test "x$ac_cv_lib_intl_strftime" = xyes; then : $as_echo "#define HAVE_STRFTIME 1" >>confdefs.h LIBS="-lintl $LIBS" fi fi done for ac_func in getcwd socket strcspn strspn strstr strtod strtol do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" if eval test \"x\$"$as_ac_var"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF fi done #------------------------------------------------------------------------------- # Construct TCL_LIB: #------------------------------------------------------------------------------- for tclversion in 8 8.6 8.5 8.4; do if test -e "$TCL_PATH/libtcl${tclversion}${SHLIB_SUFFIX}"; then TCL_LIB="tcl${tclversion}" fi done ac_config_files="$ac_config_files Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure # scripts and configure runs, see configure's option --config-cache. # It is not useful on other systems. If it contains results you don't # want to keep, you may remove or edit it. # # config.status only pays attention to the cache file if you give it # the --recheck option to rerun configure. # # `ac_cv_env_foo' variables (set or unset) will be overridden when # loading this file, other *unset* `ac_cv_foo' will be assigned the # following values. _ACEOF # The following way of writing the cache mishandles newlines in values, # but we know of no workaround that is simple, portable, and efficient. # So, we kill variables containing newlines. # Ultrix sh set writes to stderr and can't be redirected directly, # and sets the high bit in the cache file unless we assign to the vars. ( for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space=' '; set) 2>&1` in #( *${as_nl}ac_space=\ *) # `set' does not quote correctly, so add quotes: double-quote # substitution turns \\\\ into \\, and sed turns \\ into \. sed -n \ "s/'/'\\\\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" ;; #( *) # `set' quotes correctly as required by POSIX, so do not add quotes. sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) | sed ' /^ac_cv_env_/b end t clear :clear s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ t end s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ :end' >>confcache if diff "$cache_file" confcache >/dev/null 2>&1; then :; else if test -w "$cache_file"; then if test "x$cache_file" != "x/dev/null"; then { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 $as_echo "$as_me: updating cache $cache_file" >&6;} if test ! -f "$cache_file" || test -h "$cache_file"; then cat confcache >"$cache_file" else case $cache_file in #( */* | ?:*) mv -f confcache "$cache_file"$$ && mv -f "$cache_file"$$ "$cache_file" ;; #( *) mv -f confcache "$cache_file" ;; esac fi fi else { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 $as_echo "$as_me: not updating unwritable cache $cache_file" >&6;} fi fi rm -f confcache test "x$prefix" = xNONE && prefix=$ac_default_prefix # Let make expand exec_prefix. test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' # Transform confdefs.h into DEFS. # Protect against shell expansion while executing Makefile rules. # Protect against Makefile macro expansion. # # If the first sed substitution is executed (which looks for macros that # take arguments), then branch to the quote section. Otherwise, # look for a macro that doesn't take arguments. ac_script=' :mline /\\$/{ N s,\\\n,, b mline } t clear :clear s/^[ ]*#[ ]*define[ ][ ]*\([^ (][^ (]*([^)]*)\)[ ]*\(.*\)/-D\1=\2/g t quote s/^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\)/-D\1=\2/g t quote b any :quote s/[ `~#$^&*(){}\\|;'\''"<>?]/\\&/g s/\[/\\&/g s/\]/\\&/g s/\$/$$/g H :any ${ g s/^\n// s/\n/ /g p } ' DEFS=`sed -n "$ac_script" confdefs.h` ac_libobjs= ac_ltlibobjs= U= for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue # 1. Remove the extension, and $U if already installed. ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' ac_i=`$as_echo "$ac_i" | sed "$ac_script"` # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR # will be set to the directory where LIBOBJS objects are built. as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext" as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo' done LIBOBJS=$ac_libobjs LTLIBOBJS=$ac_ltlibobjs : "${CONFIG_STATUS=./config.status}" ac_write_fail=0 ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files $CONFIG_STATUS" { $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 $as_echo "$as_me: creating $CONFIG_STATUS" >&6;} as_write_fail=0 cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 #! $SHELL # Generated by $as_me. # Run this file to recreate the current configuration. # Compiler output produced by configure, useful for debugging # configure, is in config.log if it exists. debug=false ac_cs_recheck=false ac_cs_silent=false SHELL=\${CONFIG_SHELL-$SHELL} export SHELL _ASEOF cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac fi as_nl=' ' export as_nl # Printing a long string crashes Solaris 7 /usr/bin/printf. as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo # Prefer a ksh shell builtin over an external printf program on Solaris, # but without wasting forks for bash or zsh. if test -z "$BASH_VERSION$ZSH_VERSION" \ && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='print -r --' as_echo_n='print -rn --' elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then as_echo='printf %s\n' as_echo_n='printf %s' else if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' as_echo_n='/usr/ucb/echo -n' else as_echo_body='eval expr "X$1" : "X\\(.*\\)"' as_echo_n_body='eval arg=$1; case $arg in #( *"$as_nl"*) expr "X$arg" : "X\\(.*\\)$as_nl"; arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; esac; expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" ' export as_echo_n_body as_echo_n='sh -c $as_echo_n_body as_echo' fi export as_echo_body as_echo='sh -c $as_echo_body as_echo' fi # The user is always right. if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # IFS # We need space, tab and new line, in precisely that order. Quoting is # there to prevent editors from complaining about space-tab. # (If _AS_PATH_WALK were called with IFS unset, it would disable word # splitting by setting IFS to empty value.) IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as `sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Unset variables that we do not need and which cause bugs (e.g. in # pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" # suppresses any "Segmentation fault" message there. '((' could # trigger a bug in pdksh 5.2.14. for as_var in BASH_ENV ENV MAIL MAILPATH do eval test x\${$as_var+set} = xset \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done PS1='$ ' PS2='> ' PS4='+ ' # NLS nuisances. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : eval 'as_fn_append () { eval $1+=\$2 }' else as_fn_append () { eval $1=\$$1\$2 } fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : eval 'as_fn_arith () { as_val=$(( $* )) }' else as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || $as_echo X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. # In both cases, we have to default to `cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -pR' fi else as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi # as_fn_executable_p FILE # ----------------------- # Test if FILE is an executable regular file. as_fn_executable_p () { test -f "$1" && test -x "$1" } # as_fn_executable_p as_test_x='test -x' as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" # Sed expression to map a string onto a valid variable name. as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" exec 6>&1 ## ----------------------------------- ## ## Main body of $CONFIG_STATUS script. ## ## ----------------------------------- ## _ASEOF test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Save the log message, to keep $0 and so on meaningful, and to # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" This file was extended by $as_me, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS CONFIG_LINKS = $CONFIG_LINKS CONFIG_COMMANDS = $CONFIG_COMMANDS $ $0 $@ on `(hostname || uname -n) 2>/dev/null | sed 1q` " _ACEOF case $ac_config_files in *" "*) set x $ac_config_files; shift; ac_config_files=$*;; esac cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 # Files that config.status was made for. config_files="$ac_config_files" _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 ac_cs_usage="\ \`$as_me' instantiates files and other configuration actions from templates according to the current configuration. Unless the files and actions are specified as TAGs, all are instantiated by default. Usage: $0 [OPTION]... [TAG]... -h, --help print this help, then exit -V, --version print version number and configuration settings, then exit --config print configuration, then exit -q, --quiet, --silent do not print progress messages -d, --debug don't remove temporary files --recheck update $as_me by reconfiguring in the same conditions --file=FILE[:TEMPLATE] instantiate the configuration file FILE Configuration files: $config_files Report bugs to the package provider." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ config.status configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" Copyright (C) 2012 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." ac_pwd='$ac_pwd' srcdir='$srcdir' test -n "\$AWK" || AWK=awk _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # The default lists apply if the user does not specify any file. ac_need_defaults=: while test $# != 0 do case $1 in --*=?*) ac_option=`expr "X$1" : 'X\([^=]*\)='` ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` ac_shift=: ;; --*=) ac_option=`expr "X$1" : 'X\([^=]*\)='` ac_optarg= ac_shift=: ;; *) ac_option=$1 ac_optarg=$2 ac_shift=shift ;; esac case $ac_option in # Handling of the options. -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) ac_cs_recheck=: ;; --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) $as_echo "$ac_cs_version"; exit ;; --config | --confi | --conf | --con | --co | --c ) $as_echo "$ac_cs_config"; exit ;; --debug | --debu | --deb | --de | --d | -d ) debug=: ;; --file | --fil | --fi | --f ) $ac_shift case $ac_optarg in *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; '') as_fn_error $? "missing file argument" ;; esac as_fn_append CONFIG_FILES " '$ac_optarg'" ac_need_defaults=false;; --he | --h | --help | --hel | -h ) $as_echo "$ac_cs_usage"; exit ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil | --si | --s) ac_cs_silent=: ;; # This is an error. -*) as_fn_error $? "unrecognized option: \`$1' Try \`$0 --help' for more information." ;; *) as_fn_append ac_config_targets " $1" ac_need_defaults=false ;; esac shift done ac_configure_extra_args= if $ac_cs_silent; then exec 6>/dev/null ac_configure_extra_args="$ac_configure_extra_args --silent" fi _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 if \$ac_cs_recheck; then set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion shift \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' export CONFIG_SHELL exec "\$@" fi _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 exec 5>>config.log { echo sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX ## Running $as_me. ## _ASBOX $as_echo "$ac_log" } >&5 _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Handling of arguments. for ac_config_target in $ac_config_targets do case $ac_config_target in "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; esac done # If the user did not use the arguments to specify the items to instantiate, # then the envvar interface is used. Set only those that are not. # We use the long form for the default assignment because of an extremely # bizarre bug on SunOS 4.1.3. if $ac_need_defaults; then test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files fi # Have a temporary directory for convenience. Make it in the build tree # simply because there is no reason against having it here, and in addition, # creating and moving files from /tmp can sometimes cause problems. # Hook for its removal unless debugging. # Note that there is a small window in which the directory will not be cleaned: # after its creation but before its name has been assigned to `$tmp'. $debug || { tmp= ac_tmp= trap 'exit_status=$? : "${ac_tmp:=$tmp}" { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status ' 0 trap 'as_fn_exit 1' 1 2 13 15 } # Create a (secure) tmp directory for tmp files. { tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && test -d "$tmp" } || { tmp=./conf$$-$RANDOM (umask 077 && mkdir "$tmp") } || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5 ac_tmp=$tmp # Set up the scripts for CONFIG_FILES section. # No need to generate them if there are no CONFIG_FILES. # This happens for instance with `./config.status config.h'. if test -n "$CONFIG_FILES"; then ac_cr=`echo X | tr X '\015'` # On cygwin, bash can eat \r inside `` if the user requested igncr. # But we know of no other shell where ac_cr would be empty at this # point, so we can use a bashism as a fallback. if test "x$ac_cr" = x; then eval ac_cr=\$\'\\r\' fi ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null` if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then ac_cs_awk_cr='\\r' else ac_cs_awk_cr=$ac_cr fi echo 'BEGIN {' >"$ac_tmp/subs1.awk" && _ACEOF { echo "cat >conf$$subs.awk <<_ACEOF" && echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' && echo "_ACEOF" } >conf$$subs.sh || as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'` ac_delim='%!_!# ' for ac_last_try in false false false false false :; do . ./conf$$subs.sh || as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X` if test $ac_delim_n = $ac_delim_num; then break elif $ac_last_try; then as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 else ac_delim="$ac_delim!$ac_delim _$ac_delim!! " fi done rm -f conf$$subs.sh cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK && _ACEOF sed -n ' h s/^/S["/; s/!.*/"]=/ p g s/^[^!]*!// :repl t repl s/'"$ac_delim"'$// t delim :nl h s/\(.\{148\}\)..*/\1/ t more1 s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/ p n b repl :more1 s/["\\]/\\&/g; s/^/"/; s/$/"\\/ p g s/.\{148\}// t nl :delim h s/\(.\{148\}\)..*/\1/ t more2 s/["\\]/\\&/g; s/^/"/; s/$/"/ p b :more2 s/["\\]/\\&/g; s/^/"/; s/$/"\\/ p g s/.\{148\}// t delim ' >$CONFIG_STATUS || ac_write_fail=1 rm -f conf$$subs.awk cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 _ACAWK cat >>"\$ac_tmp/subs1.awk" <<_ACAWK && for (key in S) S_is_set[key] = 1 FS = "" } { line = $ 0 nfields = split(line, field, "@") substed = 0 len = length(field[1]) for (i = 2; i < nfields; i++) { key = field[i] keylen = length(key) if (S_is_set[key]) { value = S[key] line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3) len += length(value) + length(field[++i]) substed = 1 } else len += 1 + keylen } print line } _ACAWK _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g" else cat fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \ || as_fn_error $? "could not setup config files machinery" "$LINENO" 5 _ACEOF # VPATH may cause trouble with some makes, so we remove sole $(srcdir), # ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and # trailing colons and then remove the whole line if VPATH becomes empty # (actually we leave an empty line to preserve line numbers). if test "x$srcdir" = x.; then ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{ h s/// s/^/:/ s/[ ]*$/:/ s/:\$(srcdir):/:/g s/:\${srcdir}:/:/g s/:@srcdir@:/:/g s/^:*// s/:*$// x s/\(=[ ]*\).*/\1/ G s/\n// s/^[^=]*=[ ]*$// }' fi cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 fi # test -n "$CONFIG_FILES" eval set X " :F $CONFIG_FILES " shift for ac_tag do case $ac_tag in :[FHLC]) ac_mode=$ac_tag; continue;; esac case $ac_mode$ac_tag in :[FHL]*:*);; :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;; :[FH]-) ac_tag=-:-;; :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; esac ac_save_IFS=$IFS IFS=: set x $ac_tag IFS=$ac_save_IFS shift ac_file=$1 shift case $ac_mode in :L) ac_source=$1;; :[FH]) ac_file_inputs= for ac_f do case $ac_f in -) ac_f="$ac_tmp/stdin";; *) # Look for the file first in the build tree, then in the source tree # (if the path is not absolute). The absolute path cannot be DOS-style, # because $ac_f cannot contain `:'. test -f "$ac_f" || case $ac_f in [\\/$]*) false;; *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; esac || as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;; esac case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac as_fn_append ac_file_inputs " '$ac_f'" done # Let's still pretend it is `configure' which instantiates (i.e., don't # use $as_me), people would be surprised to read: # /* config.h. Generated by config.status. */ configure_input='Generated from '` $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' `' by configure.' if test x"$ac_file" != x-; then configure_input="$ac_file. $configure_input" { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 $as_echo "$as_me: creating $ac_file" >&6;} fi # Neutralize special characters interpreted by sed in replacement strings. case $configure_input in #( *\&* | *\|* | *\\* ) ac_sed_conf_input=`$as_echo "$configure_input" | sed 's/[\\\\&|]/\\\\&/g'`;; #( *) ac_sed_conf_input=$configure_input;; esac case $ac_tag in *:-:* | *:-) cat >"$ac_tmp/stdin" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; esac ;; esac ac_dir=`$as_dirname -- "$ac_file" || $as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$ac_file" : 'X\(//\)[^/]' \| \ X"$ac_file" : 'X\(//\)$' \| \ X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || $as_echo X"$ac_file" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` as_dir="$ac_dir"; as_fn_mkdir_p ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; esac ;; esac ac_abs_top_builddir=$ac_pwd ac_abs_builddir=$ac_pwd$ac_dir_suffix # for backward compatibility: ac_top_builddir=$ac_top_build_prefix case $srcdir in .) # We are building in place. ac_srcdir=. ac_top_srcdir=$ac_top_builddir_sub ac_abs_top_srcdir=$ac_pwd ;; [\\/]* | ?:[\\/]* ) # Absolute name. ac_srcdir=$srcdir$ac_dir_suffix; ac_top_srcdir=$srcdir ac_abs_top_srcdir=$srcdir ;; *) # Relative name. ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix ac_top_srcdir=$ac_top_build_prefix$srcdir ac_abs_top_srcdir=$ac_pwd/$srcdir ;; esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix case $ac_mode in :F) # # CONFIG_FILE # _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # If the template does not know about datarootdir, expand it. # FIXME: This hack should be removed a few years after 2.60. ac_datarootdir_hack=; ac_datarootdir_seen= ac_sed_dataroot=' /datarootdir/ { p q } /@datadir@/p /@docdir@/p /@infodir@/p /@localedir@/p /@mandir@/p' case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in *datarootdir*) ac_datarootdir_seen=yes;; *@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 $as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_datarootdir_hack=' s&@datadir@&$datadir&g s&@docdir@&$docdir&g s&@infodir@&$infodir&g s&@localedir@&$localedir&g s&@mandir@&$mandir&g s&\\\${datarootdir}&$datarootdir&g' ;; esac _ACEOF # Neutralize VPATH when `$srcdir' = `.'. # Shell code in configure.ac might set extrasub. # FIXME: do we really want to maintain this feature? cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_sed_extra="$ac_vpsub $extrasub _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 :t /@[a-zA-Z_][a-zA-Z_0-9]*@/!b s|@configure_input@|$ac_sed_conf_input|;t t s&@top_builddir@&$ac_top_builddir_sub&;t t s&@top_build_prefix@&$ac_top_build_prefix&;t t s&@srcdir@&$ac_srcdir&;t t s&@abs_srcdir@&$ac_abs_srcdir&;t t s&@top_srcdir@&$ac_top_srcdir&;t t s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t s&@builddir@&$ac_builddir&;t t s&@abs_builddir@&$ac_abs_builddir&;t t s&@abs_top_builddir@&$ac_abs_top_builddir&;t t $ac_datarootdir_hack " eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \ >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5 test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } && { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \ "$ac_tmp/out"`; test -z "$ac_out"; } && { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&5 $as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&2;} rm -f "$ac_tmp/stdin" case $ac_file in -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";; *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";; esac \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; esac done # for ac_tag as_fn_exit 0 _ACEOF ac_clean_files=$ac_clean_files_save test $ac_write_fail = 0 || as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5 # configure is writing to config.log, and then calls config.status. # config.status does its own redirection, appending to config.log. # Unfortunately, on DOS this fails, as config.log is still kept open # by configure, so config.status won't be able to write to it; its # output is simply discarded. So we exec the FD to /dev/null, # effectively closing config.log, so it can be properly (re)opened and # appended to by config.status. When coming back to configure, we # need to make the FD available again. if test "$no_create" != yes; then ac_cs_success=: ac_config_status_args= test "$silent" = yes && ac_config_status_args="$ac_config_status_args --quiet" exec 5>/dev/null $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false exec 5>>config.log # Use ||, not &&, to avoid exiting from the if with $? = 1, which # would make configure fail if this is the last instruction. $ac_cs_success || as_fn_exit 1 fi if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} fi fitsTcl-2.5/configure.in0000644000220700000360000002251313357670752014117 0ustar birbylheadnl Process this file with autoconf to produce a configure script. dnl disable caching to avoid sticky mistakes dnl ---------------------------------------------------------------------------- dnl define([AC_CACHE_LOAD], ) dnl define([AC_CACHE_SAVE], ) dnl ---------------------------------------------------------------------------- AC_INIT AC_CONFIG_SRCDIR([Makefile.in]) AC_REVISION($Revision$) AC_PREREQ(2.59) if test $cache_file = ./config.cache; then cache_file=`pwd`/config.cache fi # Tcl: #------------------------------------------- AC_ARG_WITH( tcl, [ --with-tcl Path to tcl library ], TCL_PATH=$withval ) AC_ARG_WITH( tcl-includes, [ --with-tcl-includes Path to tcl include files ], TCL_INCLUDES=$withval ) AC_SUBST(TCL_PATH) # Make sure we have tcl.h before proceeding: #------------------------------------------- AC_MSG_CHECKING([for tcl header file]) TCL_INC_PATH= for dir in $TCL_INCLUDES $prefix/include /usr/include ; do if test -r $dir/tcl.h; then TCL_INC_PATH=$dir AC_MSG_RESULT($dir) break fi done if test -z "$TCL_INC_PATH"; then AC_MSG_RESULT([no]) AC_MSG_ERROR(Cannot find Tcl header. Use --with-tcl-includes to specify the location of tcl.h on your system.) fi AC_SUBST(TCL_INC_PATH) # CFITSIO: #------------------------------------------- AC_ARG_WITH( cfitsio, [ --with-cfitsio Path to cfitsio source ], CFITSIO=$withval ) # Make sure we have cfitsio before proceeding: #------------------------------------------- AC_MSG_CHECKING([for cfitsio source directory]) CFITSIODIR= for dir in $CFITSIO ./cfitsio ; do if test -r $dir/eval_defs.h; then CFITSIODIR=$dir AC_MSG_RESULT($dir) break fi done if test -z "$CFITSIODIR"; then AC_MSG_RESULT([no]) AC_MSG_ERROR(Cannot find cfitsio. Use --with-cfitsio to specify the location of the cfitsio source code.) fi AC_SUBST(CFITSIODIR) #------------------------------------------- AC_ARG_ENABLE( shared, [ --disable-shared Produce static binaries ], lhea_shared=$enableval, lhea_shared=yes, lhea_shared=no ) AC_ARG_ENABLE( static, [ --enable-static Produce static binaries ], [ if test $enableval = yes; then lhea_shared=no; fi ] ) if test $lhea_shared = yes; then C_LIB_OPTION=shared else C_LIB_OPTION=static fi AC_SUBST(C_LIB_OPTION) #------------------------------------------------------------------------------- # Determine system type #------------------------------------------------------------------------------- BIN_EXT= if test "x$EXT" = x; then EXT=lnx; fi if test "x$BINDIR" = x; then AC_CHECK_PROG(UNAME, uname, uname, nouname) if test $UNAME = nouname; then AC_MSG_ERROR(HEAsoft: Unable to guess system type. Please set it using --with-bindir option) fi changequote(,) BINDIR=`$UNAME -s 2> /dev/null`_`$UNAME -r 2> /dev/null | sed 's:[^0-9]*\([0-9][0-9]*\.[0-9]*\).*:\1:'` changequote([,]) lhea_machine=`$UNAME -m 2> /dev/null` BIN_EXT= case $BINDIR in CYGWIN*) BINDIR=CYGWIN32_`$UNAME -a 2> /dev/null | awk '{ print $4 }'` lhea_machine= BIN_EXT=".exe" EXT=win ;; Linux*) EXT=lnx ;; Darwin*) EXT=darwin lhea_machine=`$UNAME -p` ;; SunOS_5*) EXT=sol lhea_machine=`$UNAME -p` ;; *) AC_MSG_ERROR(Unable to recognize your system. Please make sure this platform is supported.) ;; esac if test x$lhea_machine != x; then BINDIR=$BINDIR"_"$lhea_machine fi fi AC_SUBST(BINDIR) AC_SUBST(BIN_EXT) AC_SUBST(EXT) #------------------------------------------------------------------------------- # Checks for programs. #------------------------------------------------------------------------------- # Try first to find a proprietary C compiler, then gcc if test "x$CC" = x; then AC_CHECK_PROGS(CC, cc) fi # Set up flags to use the selected compiler # AC_PROG_CC if test "$cross_compiling" = yes; then AC_MSG_WARN(Cannot run a simple C executable on your system:) AC_MSG_WARN(There may be something wrong with your compiler,) AC_MSG_WARN(or perhaps you are trying to cross-compile?) AC_MSG_WARN(Cross-compiling is not supported within HEAsoft.) AC_MSG_WARN(Please make sure your compiler is working.) AC_MSG_WARN(Contact the FTOOLS help desk for further assistance.) AC_MSG_ERROR(Cross-compiling is not allowed.) fi if test "x$GCC" = x; then GCC=no fi AC_PROG_RANLIB if test $EXT = darwin; then RANLIB="$RANLIB -cs" fi #------------------------------------------------------------------------------- # Checks for libraries. #------------------------------------------------------------------------------- # X XLIBS= XLIBPTH= XINCLUDES= # socket and nsl libraries -- only if needed AC_CHECK_FUNC(gethostbyname, [], [AC_CHECK_LIB(nsl, gethostbyname)]) AC_CHECK_FUNCS(connect accept, [], [AC_CHECK_LIB(socket, main, , , [ $XLIBS ])]) # Prepend the standard location X11 bin directory (if it exists) to PATH # to assist AC_PATH_X in finding headers & libraries: if test -d /usr/X11R6/bin; then if test "x$PATH" != x; then PATH=$PATH:/usr/X11R6/bin else PATH=/usr/X11R6/bin fi export PATH fi AC_PATH_X if test "x$no_x" != xyes; then USE_X=yes no_x=no if test `echo $x_includes | grep -c /` -ne 0; then XINCLUDES="-I$x_includes" fi if test `echo $x_libraries | grep -c /` -ne 0; then XLIBPTH="-L$x_libraries " fi XLIBS="$XLIBPTH-lX11" dnl xpa sometimes needs Xt dnl this doesn't work at the moment: dnl AC_CHECK_LIB(Xt, main, XLIBS="$XLIBS -lXt") if test -f $x_libraries/libXt.a; then XLIBS="$XLIBS -lXt" fi # dnet_stub AC_CHECK_LIB(dnet_stub, getnodebyname, XLIBS="$XLIBS -ldnet_stub") else USE_X=no fi AC_SUBST(USE_X) AC_SUBST(XINCLUDES) AC_SUBST(XLIBPTH) AC_SUBST(XLIBS) # dl AC_CHECK_LIB(dl, dlopen) if test `echo $LIBS | grep -c '\-ldl'` -eq 0; then AC_CHECK_LIB(dld, dlopen) fi # If available, use curl-config to get linker flags for Curl library, # which may be pulled in to the shared CFITSIO library for HTTPS support. # On Macs, prefer XCode curl-config, and reject MacPorts version until # further notice to prevent build errors: CURL_LIB="" if test "x$EXT" = xdarwin -a -x /usr/bin/curl-config; then CURLCONFIG="/usr/bin/curl-config" AC_MSG_RESULT(checking for curl-config... choosing /usr/bin/curl-config on Mac) else AC_CHECK_PROG([CURLCONFIG], [curl-config], [curl-config], [], [], [/opt/local/bin/curl-config]) fi if test "x$CURLCONFIG" != x; then CURL_LIB=`$CURLCONFIG --libs` # Also reject anaconda curl on Macs until further notice: if test "x$EXT" = xdarwin -a `echo $CURL_LIB | grep -ci anaconda` -gt 0; then LIBS="$LIBS $CURL_LIB" fi fi #------------------------------------------------------------------------------- # Checks for header files. #------------------------------------------------------------------------------- AC_HEADER_STDC AC_CHECK_HEADERS( dirent.h fcntl.h limits.h malloc.h string.h sys/time.h unistd.h ) AC_HEADER_TIME AC_FUNC_ALLOCA #------------------------------------------------------------------------------- # Checks for typedefs, structures, and compiler characteristics. #------------------------------------------------------------------------------- AC_C_CONST AC_TYPE_MODE_T AC_TYPE_SIZE_T AC_STRUCT_TM #------------------------------------------------------------------------------- # Tweak compiler flags as needed #------------------------------------------------------------------------------- case $EXT in darwin) CFLAGS="$CFLAGS -Dunix" ;; lnx) ;; sol) AC_DEFINE(HAVE_POSIX_SIGNALS) ;; *) ;; esac #------------------------------------------------------------------------------- # Shared library section #------------------------------------------------------------------------------- LD_FLAGS= SHLIB_SUFFIX=".so" SHLIB_LD_LIBS="" lhea_shlib_cflags= lhea_shlib_fflags= if test $lhea_shared = yes; then case $EXT in darwin) SHLIB_LD="$CC -dynamiclib -flat_namespace -undefined suppress" SHLIB_SUFFIX=".dylib" lhea_shlib_cflags='-fPIC -fno-common' lhea_shlib_fflags='-fPIC -fno-common' ;; lnx) SHLIB_LD=":" ;; sol) SHLIB_LD="/usr/ccs/bin/ld -G" SHLIB_LD_LIBS='${LIBS}' lhea_shlib_cflags="-KPIC" lhea_shlib_fflags="-KPIC" ;; win) SHLIB_LD="$CC -shared" SHLIB_SUFFIX=".dll" ;; *) AC_MSG_WARN(Unable to determine how to make a shared library) ;; esac # Darwin uses gcc, but uses -dynamiclib flag if test $GCC = yes -a $EXT != darwin; then SHLIB_LD="$CC -shared" lhea_shlib_cflags='-fPIC' fi if test "x$lhea_shlib_cflags" != x; then CFLAGS="$CFLAGS $lhea_shlib_cflags" fi else SHLIB_LD=: fi AC_SUBST(LD_FLAGS) AC_SUBST(SHLIB_LD) AC_SUBST(SHLIB_LD_LIBS) AC_SUBST(SHLIB_SUFFIX) #------------------------------------------------------------------------------- # Checks for library functions. #------------------------------------------------------------------------------- AC_FUNC_MEMCMP AC_TYPE_SIGNAL AC_FUNC_STRFTIME AC_CHECK_FUNCS(getcwd socket strcspn strspn strstr strtod strtol) #------------------------------------------------------------------------------- # Construct TCL_LIB: #------------------------------------------------------------------------------- for tclversion in 8 8.6 8.5 8.4; do if test -e "$TCL_PATH/libtcl${tclversion}${SHLIB_SUFFIX}"; then TCL_LIB="tcl${tclversion}" fi done AC_SUBST(TCL_LIB) AC_CONFIG_FILES([Makefile]) AC_OUTPUT fitsTcl-2.5/fitsCmds.c0000644000220700000360000034474713133202233013517 0ustar birbylhea/* * fitsCmds.c -- * * This holds the handlers for all of the fitsObj commands * */ /* * ------------------------------------------------------------ * MODIFICATION HISTORY: * 2004-02-05 Ziqin Pan: * Add the following commands: * 1. delete row -rowrange rangelist * 2. add column colName colForm ?expr? ?rowrange? * 3. select rows -expr expression firstrow nrow * * */ #include "fitsTclInt.h" #define ARGV_STR(x) Tcl_GetStringFromObj(argv[x],NULL) /* * ------------------------------------------------------------ * * fitsDispatch -- * * This is the dispatch routine for the Fits objects * * Results: * Depends on argv[1]. * * Side Effects: * Depends on argv[1]. * * ------------------------------------------------------------ * */ int fitsDispatch( ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *const argv[] ) { static char *commandList = "Available commands:\n" "close - close the file and delete this object\n" "move ?+/-?n - move to HDU #n or forward/backward +/-n HDUs\n" "dump ?-s/-e/-l? - return contents of the CHDU's header in various formats\n" "info - get information about the CHDU \n" "get - get various data from CHDU\n" "put - change contents of CHDU: keywords or extension data\n" "insert- insert KEYWORDs, COLUMNs, ROWs, or HDUs \n" "delete- delete KEYWORDs, COLUMNs, ROWs, or HDUs \n" "select- select ROWs \n" "load - load image and table data into variables or pointers \n" "free - free loaded data. **If the address is not the right one\n" " returned from \"load xxx\", a core dump will occur** \n" "flush ?clear? - flush dirty buffers to disk (also clear buffer contents?) \n" "copy filename - copy the CHDU to a new file\n" "sascii- save extension contents to an ascii file \n" "sort - sort the CHDU according to supplied parameters \n" "add - Append new columns and rows to table. Column may be filled\n" " with the results of a supplied arithmetic expression\n" "append filename - Append current HDU to indicated fits file\n" "histogram - Create N-D histogram from table columns\n" "smooth - Create a smoothed image from the original image.\n" "checksum update|verify - Update or verify checksum keywords of the\n" " current HDU. Verify: 1=good, -1=bad, 0=none\n" ; int i, j, status; FitsFD *curFile = (FitsFD *) clientData; struct { char *cmd; int tclObjs; int (*fct)(FitsFD*,int,Tcl_Obj*const[]); } cmdLookup[] = { { "close", 1, fitsTcl_close }, { "move", 1, fitsTcl_move }, { "dump", 1, fitsTcl_dump }, { "info", 0, fitsTcl_info }, { "get", 0, fitsTcl_get }, { "put", 1, fitsTcl_put }, { "insert", 0, fitsTcl_insert }, { "delete", 0, fitsTcl_delete }, { "select", 0, fitsTcl_select }, { "load", 0, fitsTcl_load }, { "free", 1, fitsTcl_free }, { "flush", 1, fitsTcl_flush }, { "copy", 1, fitsTcl_copy }, { "sascii", 0, fitsTcl_sascii }, { "sort", 0, fitsTcl_sort }, { "add", 0, fitsTcl_add }, { "append", 1, fitsTcl_append }, { "histogram",1, fitsTcl_histo }, { "create", 1, fitsTcl_create }, { "smooth", 1, fitsTcl_smooth }, { "checksum", 1, fitsTcl_checksum }, { "", 0, NULL } }; char *cmd, **args; /* * If there are no arguments, return the help string */ if( argc==1 ) { Tcl_SetResult(interp,commandList,TCL_STATIC); return TCL_OK; } /* * Search for the command and call its handler */ cmd = Tcl_GetStringFromObj( argv[1], NULL ); for( i=0; cmdLookup[i].cmd[0]; i++ ) { if( !strcmp( cmdLookup[i].cmd, cmd ) ) { if( cmdLookup[i].tclObjs ) { status = (*cmdLookup[i].fct)(curFile, argc, argv); } else { /* * Convert TCL_OBJs to strings */ args = (char **) ckalloc( argc * sizeof(char *) ); for( j=0; jinterp, "Wrong number of args: expected fits close",TCL_STATIC); return TCL_ERROR; } if( Tcl_DeleteCommand( curFile->interp, curFile->handleName ) != TCL_OK ) { return TCL_ERROR; } curFile->fptr = NULL; curFile->handleName = NULL; return TCL_OK; } /****************************************************************** * Move ******************************************************************/ int fitsTcl_move( FitsFD *curFile, int argc, Tcl_Obj *const argv[] ) { static char *moveList = "\n" "move nmove - moves the CHDU: \n" " nmove = +- -> relative move, otherwise absolute\n" " returns hdutype\n"; char *pStr; int nmove; int mSilent=0; int status=0; if ( 3 > argc ) { Tcl_SetResult(curFile->interp, moveList, TCL_STATIC); return TCL_OK; } /* Convert the nmove argument */ if( Tcl_GetIntFromObj(curFile->interp,argv[2],&nmove) != TCL_OK ) { Tcl_SetResult(curFile->interp,"Wrong type for nmove",TCL_STATIC); return TCL_ERROR; } if( argc == 4 ) { pStr = Tcl_GetStringFromObj( argv[3], NULL ); if( !strcmp(pStr, "-s") ) { mSilent = 1; } else { Tcl_SetResult(curFile->interp, "fitsTcl Error: " "unknown option: -s for load without read header", TCL_STATIC); return TCL_ERROR; } } pStr = Tcl_GetStringFromObj( argv[2], NULL ); if( mSilent ) { if ( strchr(pStr,'+') ) { status = fitsJustMoveHDU(curFile, nmove, 1); } else if ( strchr(pStr,'-') ) { status = fitsJustMoveHDU(curFile, nmove,-1); } else { status = fitsJustMoveHDU(curFile, nmove, 0); } } else { if ( strchr(pStr,'+') ) { status = fitsMoveHDU(curFile, nmove, 1); } else if ( strchr(pStr,'-') ) { status = fitsMoveHDU(curFile, nmove,-1); } else { status = fitsMoveHDU(curFile, nmove, 0); } } if ( status ) { return TCL_ERROR; } /* Return the hdutype */ Tcl_SetObjResult(curFile->interp, Tcl_NewIntObj( curFile->hduType ) ); return TCL_OK; } /****************************************************************** * Dump ******************************************************************/ int fitsTcl_dump( FitsFD *curFile, int argc, Tcl_Obj *const argv[] ) { int status; char *option; if( argc == 2 ) { status = fitsDumpHeader(curFile); } else { option = Tcl_GetStringFromObj( argv[2], NULL ); if( !strcmp("-l",option) ) { status = fitsDumpKwdsToList(curFile); } else if( !strcmp("-s",option) ) { status = fitsDumpHeaderToKV(curFile); } else if( !strcmp("-e",option) ) { status = fitsDumpHeaderToCard(curFile); } else { Tcl_SetResult(curFile->interp, "Usage: fitsFile dump ?-s/-e/-l?", TCL_STATIC); return TCL_ERROR; } } return status; } /****************************************************************** * Info ******************************************************************/ int fitsTcl_info( FitsFD *curFile, int argc, char *const argv[] ) { static char *infoList = "\n" "Available Commands:\n" "\n" "info chdu - returns the CHDU\n" "info nhdu - returns the total number of hdu in the file\n" "info filesize- returns the size of the file(in unit of 2880 byte)\n" "info hdutype - returns the type of the CHDU\n" "info imgType - returns the image type of the CHDU \n" "info imgdim - returns the image dimension of the CHDU \n" "info ncols - returns the number of columns in the CHDU\n" "info nrows - returns the number of rows in the CHDU\n" "info nkwds - returns the number of keywords in the CHDU\n" "info column ?-exact? ?colNames? \n" " with no argument, lists the columns,\n" " otherwise gives more info about columns in colName\n" " ?-minmax? colName firstElement ?rowRange? \n" " min and max\n" " ?-stat? colName firstElement ?rowRange? \n" " statistics about the indicated column\n" "\n"; int i, j, felem, numRange, *range=NULL; int numCols, colTypes[FITS_COLMAX], colNums[FITS_COLMAX], strSize[FITS_COLMAX]; int status = 0; char result[32]; char tmpStr[3][FLEN_VALUE]; /* Some general purpose string buffers */ char *mrgList[9], *pattern, *tmpStrPtr; char errMsg[256], **colList; Tcl_DString concatList; if( argc < 3 ) { Tcl_SetResult(curFile->interp, infoList, TCL_STATIC); return TCL_OK; } /* check if the chdu has been loaded or not */ if( curFile->CHDUInfo.table.loadStatus != 1 ) { Tcl_SetResult(curFile->interp, "You need to load the CHDU first", TCL_STATIC); return TCL_ERROR; } if( !strcmp("chdu",argv[2] ) ) { sprintf(result,"%d",curFile->chdu); Tcl_SetResult(curFile->interp, result, TCL_VOLATILE); } else if( !strcmp("imgType",argv[2]) ) { int bitpix = 0; int naxis = 0; long naxes[9]; fits_get_img_dim(curFile->fptr, &naxis, &status); status = 0; fits_get_img_size(curFile->fptr, naxis, naxes, &status); status = 0; fits_get_img_type(curFile->fptr, &bitpix, &status); sprintf(result,"%d", bitpix); Tcl_SetResult(curFile->interp, result, TCL_VOLATILE); } else if( !strcmp("filesize",argv[2]) ) { sprintf(result,"%lld",curFile->fptr->Fptr->filesize/2880); Tcl_SetResult(curFile->interp, result, TCL_VOLATILE); } else if( !strcmp("hdutype",argv[2]) ) { switch ( curFile->hduType ) { case IMAGE_HDU: if( curFile->chdu ) tmpStrPtr = "Image extension"; else tmpStrPtr = "Primary array"; break; case ASCII_TBL: tmpStrPtr = "ASCII Table"; break; case BINARY_TBL: tmpStrPtr = "Binary Table"; break; default: Tcl_SetResult(curFile->interp, "Unsupported hdu type", TCL_STATIC); return TCL_ERROR; } Tcl_SetResult(curFile->interp, tmpStrPtr, TCL_STATIC); } else if( !strcmp("nhdu", argv[2]) ) { int nhdu; ffthdu(curFile->fptr, &nhdu, &status); if( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } sprintf(result, "%d", nhdu); Tcl_SetResult( curFile->interp, result, TCL_VOLATILE ); } else if( !strcmp("nkwds",argv[2] ) ) { sprintf(result, "%-d", curFile->numKwds); Tcl_SetResult( curFile->interp, result, TCL_VOLATILE ); } else if( !strcmp("ncols",argv[2] ) ) { if (curFile->hduType == IMAGE_HDU ) { Tcl_SetResult( curFile->interp, "No columns for an Image extension", TCL_STATIC); return TCL_ERROR; } sprintf(result, "%d", curFile->CHDUInfo.table.numCols); Tcl_SetResult( curFile->interp, result, TCL_VOLATILE ); } else if( !strcmp("nrows",argv[2] ) ) { if (curFile->hduType == IMAGE_HDU ) { Tcl_SetResult( curFile->interp, "No rows for an Image extension", TCL_STATIC ); return TCL_ERROR; } sprintf(result,"%lld",curFile->CHDUInfo.table.numRows); Tcl_SetResult( curFile->interp, result, TCL_VOLATILE ); } else if( !strcmp("column",argv[2] ) ) { if( curFile->hduType == IMAGE_HDU ) { Tcl_SetResult( curFile->interp, "No Columns in an image extension", TCL_STATIC ); return TCL_ERROR; } if( argc == 3 ) { /*********************************** * Return a list of column names * ***********************************/ for ( i = 0; i < curFile->CHDUInfo.table.numCols; i++ ) { Tcl_AppendElement(curFile->interp, curFile->CHDUInfo.table.colName[i]); } } else { /******************************************* * Return info about one or more columns * *******************************************/ if( !strcmp(argv[3], "-stat") ) { if ( argc < 5 ) { Tcl_SetResult(curFile->interp, "Usage: info column -stat columnName ?felem? ?rows?", TCL_STATIC); return TCL_ERROR; } if( argc == 5 ) { felem = 1; } else if( Tcl_GetInt(curFile->interp, argv[5], &felem) != TCL_OK ) { return TCL_ERROR; } if( argc >= 7 ) { numRange = fitsParseRangeNum(argv[6])+1; range = (int*) malloc(numRange*2*sizeof(int)); if( fitsParseRange(argv[6],&numRange,range,numRange, 1, curFile->CHDUInfo.table.numRows,errMsg) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Error parsing row range:\n", TCL_STATIC); Tcl_AppendResult(curFile->interp, errMsg, (char*)NULL); return TCL_ERROR; } } else { numRange = 1; range = (int*) malloc(numRange*2*sizeof(int)); range[0] = 1; range[1] = curFile->CHDUInfo.table.numRows ; } if( fitsTransColList( curFile, argv[4], &numCols, colNums, colTypes, strSize) != TCL_OK ) return TCL_ERROR; if( fitsColumnStatistics(curFile,colNums[0],felem, numRange,range) != TCL_OK ) { return TCL_ERROR; } } else if( !strcmp(argv[3], "-minmax") ) { if ( argc < 5 ) { Tcl_SetResult(curFile->interp, "Usage: info column -minmax " "columnName ?felem? ?rows?", TCL_STATIC); return TCL_ERROR; } if( argc == 5 ) { felem = 1; } else if( Tcl_GetInt(curFile->interp, argv[5], &felem) != TCL_OK ) { return TCL_ERROR; } if( argc >= 7 ) { numRange = fitsParseRangeNum(argv[6])+1; range = (int*) malloc(numRange*2*sizeof(int)); if( fitsParseRange(argv[6],&numRange,range,numRange, 1, curFile->CHDUInfo.table.numRows,errMsg) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Error parsing row range:\n", TCL_STATIC); Tcl_AppendResult(curFile->interp, errMsg, (char*)NULL); return TCL_ERROR; } } else { numRange = 1; range = (int*) malloc(numRange*2*sizeof(int)); range[0] = 1; range[1] = curFile->CHDUInfo.table.numRows ; } for ( i = 0; i < curFile->CHDUInfo.table.numCols; i++) { if( !strcasecmp(argv[4],curFile->CHDUInfo.table.colName[i]) ) { if( fitsColumnMinMax(curFile, i+1, felem, numRange, range) != TCL_OK ) { return TCL_ERROR; } break; } } } else if( !strcmp(argv[3], "-exact") ) { /************************************************************* * Return Info about Columns matching an exact column name * *************************************************************/ if( argc != 5 ) { Tcl_SetResult(curFile->interp, "Usage: info column -exact columnNames", TCL_STATIC); return TCL_ERROR; } if( fitsTransColList( curFile, argv[4], &numCols, colNums, colTypes, strSize) != TCL_OK ) return TCL_ERROR; for ( i = 0; i < numCols; i++ ) { j = colNums[i]-1; mrgList[0] = curFile->CHDUInfo.table.colName[j]; mrgList[1] = curFile->CHDUInfo.table.colType[j]; mrgList[2] = curFile->CHDUInfo.table.colUnit[j]; mrgList[3] = curFile->CHDUInfo.table.colDisp[j]; mrgList[4] = curFile->CHDUInfo.table.colFormat[j]; sprintf(tmpStr[0], "%d", curFile->CHDUInfo.table.colWidth[j]); mrgList[5] = tmpStr[0]; sprintf(tmpStr[1], "%d", curFile->CHDUInfo.table.colTzflag[j]); mrgList[6] = tmpStr[1]; sprintf(tmpStr[2], "%d", curFile->CHDUInfo.table.colTsflag[j]); mrgList[7] = tmpStr[2]; mrgList[8] = curFile->CHDUInfo.table.colNull[j]; Tcl_AppendElement(curFile->interp,Tcl_Merge(9,mrgList)); } } else if( argc==4 ) { /*********************************************************** * Return Info about Columns matching regular expression * ***********************************************************/ Tcl_DStringInit(&concatList); if( Tcl_SplitList(curFile->interp, argv[3], &numCols, &colList) != TCL_OK ) { return TCL_ERROR; } if( fitsMakeRegExp(curFile->interp, numCols, colList, &concatList, 1) == TCL_ERROR ) { Tcl_SetResult(curFile->interp, "Error making up reg expr", TCL_STATIC); Tcl_DStringFree(&concatList); ckfree((char*)colList); return TCL_ERROR; } ckfree((char*)colList); pattern = Tcl_DStringValue(&concatList); for ( i = 0; i < curFile->CHDUInfo.table.numCols; i++) { strToUpper(curFile->CHDUInfo.table.colName[i], &tmpStrPtr); status = Tcl_RegExpMatch(curFile->interp, tmpStrPtr, pattern); ckfree( (char*)tmpStrPtr ); if( status == 1 ) { mrgList[0] = curFile->CHDUInfo.table.colName[i]; mrgList[1] = curFile->CHDUInfo.table.colType[i]; mrgList[2] = curFile->CHDUInfo.table.colUnit[i]; mrgList[3] = curFile->CHDUInfo.table.colDisp[i]; mrgList[4] = curFile->CHDUInfo.table.colFormat[i]; sprintf(tmpStr[0], "%d", curFile->CHDUInfo.table.colWidth[i]); mrgList[5] = tmpStr[0]; sprintf(tmpStr[1], "%d", curFile->CHDUInfo.table.colTzflag[i]); mrgList[6] = tmpStr[1]; sprintf(tmpStr[2], "%d", curFile->CHDUInfo.table.colTsflag[i]); mrgList[7] = tmpStr[2]; mrgList[8] = curFile->CHDUInfo.table.colNull[i]; Tcl_AppendElement(curFile->interp,Tcl_Merge(9,mrgList)); } else if( status == -1 ) { Tcl_AppendResult(curFile->interp,"Error, ", pattern, " not a Regular Expression.", (char *) NULL); Tcl_DStringFree(&concatList); return TCL_ERROR; } } Tcl_DStringFree(&concatList); } else { Tcl_SetResult(curFile->interp, "Usage:\n" " info column ?-exact? colNames \n" " -minmax colName firstElement ?rowRange? \n" " -stat colName firstElement ?rowRange? \n", TCL_STATIC); return TCL_ERROR; } } /* End of 'info column' */ } else if( !strcmp("expr", argv[2]) ) { if( curFile->hduType == IMAGE_HDU ) { Tcl_SetResult(curFile->interp,"Not a table extension", TCL_STATIC); return TCL_ERROR; } if( argc != 4 ) { Tcl_SetResult(curFile->interp, "Usage: info expr exprStr", TCL_STATIC); return TCL_ERROR; } if( exprGetInfo( curFile, argv[3] ) ) { return TCL_ERROR; } } else if( !strcmp("imgdim", argv[2]) ) { if ( curFile->hduType != IMAGE_HDU ) { Tcl_SetResult(curFile->interp, "Current extension is not an image", TCL_STATIC); return TCL_ERROR; } Tcl_ResetResult(curFile->interp); for (i=0; i < curFile->CHDUInfo.image.naxes; i++) { sprintf(tmpStr[0], "%lld", curFile->CHDUInfo.image.naxisn[i]); Tcl_AppendElement(curFile->interp, tmpStr[0]); } } else { Tcl_SetResult(curFile->interp, "Unrecognized option to info", TCL_STATIC); return TCL_ERROR; } if (range) free(range); return TCL_OK; } /****************************************************************** * Get ******************************************************************/ int fitsTcl_get( FitsFD *curFile, int argc, char *const argv[] ) { static char *getList = "\n" "Available Commands:\n" "get keyword ?keyName? - displays the keyword(s) keyname\n" " - keywords are specified by reg. expression\n" "get keyword -num keyNum - displays the num th keyword in the CHDU\n" "get wcs ?RAcol DECcol?\n" " - return a list of the WCS parameters for either a table or image:\n" " {xrval yrval xrpix yrpix xinc yinc rot ctype}\n" " For a table, supply RAcol and DECcol which are column names or \n" " numbers of the RA column and DEC column\n" "get header2str - get header and construct it into a string\n" "get translatedKeywords - translated header keyword to normal one.\n" "get dummy2str - create dummy fits image file and get header and construct it into a string\n" "get image ?firstElem? ?numElem?\n" " - return elements of an image\n" "get table ?-c? ?-noformat? ?colList? ?rowList?\n" " - return the elements rowList from list colList\n" " - if no rowList is provided, give all rows\n" " - if no colList is provided, give all columns\n" " - use colList = * for all columns\n" " - -c means return each column as a separate list.\n" "get vtable ?-noformat? colname firstelement ?rowList?\n" " - get the firstelement-th vector element\n" "\n"; char Comment[FLEN_COMMENT], Name[FLEN_KEYWORD], Value[FLEN_VALUE]; int numCols,colNums[FITS_COLMAX],colTypes[FITS_COLMAX],strSize[FITS_COLMAX]; int numRange, *range=NULL; Tcl_HashEntry *newEntry; Tcl_HashSearch search; Tcl_DString concatList, regExpList; FitsCardList *curCard; Keyword *newKwd; char errMsg[256]; int nmove,i,k,l,n; int bycol,niters,fRow; int ntodo,felem; char *pattern; int status = 0; char *header; int nkeys; Tcl_Obj *resObj, **valArray, *listObj, **listArray; listObj = Tcl_NewObj(); if ( argc == 2 ) { Tcl_SetResult(curFile->interp, getList, TCL_STATIC); return TCL_OK; } if( !strcmp("keyword", argv[2]) ) { /* GET KEYWORD */ if( argc == 3 ) { Tcl_DStringInit(&concatList); newEntry = Tcl_FirstHashEntry(curFile->kwds,&search); while ( newEntry ) { newKwd = (Keyword *) Tcl_GetHashValue(newEntry); Tcl_DStringStartSublist(&concatList); Tcl_DStringAppendElement(&concatList,newKwd->name); Tcl_DStringAppendElement(&concatList,newKwd->value); Tcl_DStringAppendElement(&concatList,newKwd->comment); Tcl_DStringEndSublist(&concatList); newEntry = Tcl_NextHashEntry(&search); } Tcl_DStringResult(curFile->interp,&concatList); } else if( !strcmp(argv[3],"-num") ) { if ( 5 != argc ) { Tcl_SetResult(curFile->interp, "Wrong number of args, expected get keyword " "-num number", TCL_STATIC); return TCL_ERROR; } if( Tcl_GetInt(curFile->interp,argv[4],&nmove) != TCL_OK ) { Tcl_AppendResult(curFile->interp, "\nWrong type for nmove",(char *) NULL); return TCL_ERROR; } /* * First look through the comments and the history cards: * remember the first card is always a dummy... */ curCard = (curFile->hisHead)->next; while( curCard ) { if ( curCard->pos == nmove ) { Tcl_AppendElement(curFile->interp,"HISTORY"); Tcl_AppendElement(curFile->interp," "); Tcl_AppendElement(curFile->interp,curCard->value); return TCL_OK; } curCard = curCard->next; } curCard = (curFile->comHead)->next; while( curCard ) { if ( curCard->pos == nmove ) { Tcl_AppendElement(curFile->interp,"COMMENT"); Tcl_AppendElement(curFile->interp," "); Tcl_AppendElement(curFile->interp,curCard->value); return TCL_OK; } curCard = curCard->next; } newEntry = Tcl_FirstHashEntry(curFile->kwds,&search); while( newEntry ) { newKwd = (Keyword *) Tcl_GetHashValue(newEntry); if ( newKwd->pos == nmove ) { Tcl_AppendElement(curFile->interp,newKwd->name); Tcl_AppendElement(curFile->interp,newKwd->value); Tcl_AppendElement(curFile->interp,newKwd->comment); return TCL_OK; } newEntry = Tcl_NextHashEntry(&search); } /* The Hashes all failed (maybe duplicate keys in header. */ /* Go directly to file. */ ffgkyn( curFile->fptr, nmove, Name, Value, Comment, &status); if( status ) { dumpFitsErrStack(curFile->interp,status); return TCL_ERROR; } Tcl_AppendElement(curFile->interp,Name); Tcl_AppendElement(curFile->interp,Value); Tcl_AppendElement(curFile->interp,Comment); } else { Tcl_DStringInit(®ExpList); if( fitsMakeRegExp(curFile->interp, argc-3, argv+3, ®ExpList, 1) == TCL_ERROR ) { Tcl_SetResult(curFile->interp, "Error building regular expression", TCL_STATIC); Tcl_DStringFree(®ExpList); return TCL_ERROR; } pattern = Tcl_DStringValue(®ExpList); Tcl_DStringInit(&concatList); niters = 0; newEntry = Tcl_FirstHashEntry(curFile->kwds,&search); while ( NULL != newEntry ) { newKwd = (Keyword *) Tcl_GetHashValue(newEntry); status = Tcl_RegExpMatch(curFile->interp,newKwd->name,pattern); if ( status == 1 ) { niters = 1; Tcl_DStringStartSublist(&concatList); Tcl_DStringAppendElement(&concatList,newKwd->name); Tcl_DStringAppendElement(&concatList,newKwd->value); Tcl_DStringAppendElement(&concatList,newKwd->comment); Tcl_DStringEndSublist(&concatList); newEntry = Tcl_NextHashEntry(&search); } else if ( status == -1 ) { Tcl_AppendResult(curFile->interp,"The Pattern: ",pattern, " is not a regular expression." ,(char *) NULL); Tcl_DStringFree(&concatList); Tcl_DStringFree(®ExpList); return TCL_ERROR; } else { newEntry = Tcl_NextHashEntry(&search); } } if( !niters ) { Tcl_SetResult(curFile->interp, "No matching keywords found/or keyword not loaded", TCL_STATIC); Tcl_DStringFree(&concatList); return TCL_ERROR; } Tcl_DStringResult(curFile->interp,&concatList); } } else if( !strcmp("wcs", argv[2]) ) { /* Get WCS */ if ( curFile->hduType == IMAGE_HDU ) { /* Get WCS from Image extension */ if( argc < 3 || argc > 5 ) { Tcl_SetResult(curFile->interp, "For image extension use, get wcs", TCL_STATIC); return TCL_ERROR; } if ( (argc == 4 || argc == 5) && !strcmp("-m", argv[3]) ) { if (argc == 4) { if( fitsGetWcsMatrix(curFile, 0, NULL, '\0') != TCL_OK ) { return TCL_ERROR; } } else { /* this tells which wcs to use.. wcsA, wcsB.. etcc*/ if( fitsGetWcsMatrix(curFile, 0, NULL, argv[4][0]) != TCL_OK ) { return TCL_ERROR; } } } else { if( fitsGetWcsPair(curFile,0,0, '\0') != TCL_OK ) { return TCL_ERROR; } } } else { /* Get WCS from Table extension */ int i,j; int nCols = 0; int getMatrix = 0; int columns[FITS_MAXDIMS]; if( argc>4 && !strcmp("-m", argv[3]) ) { getMatrix = 1; nCols = argc - 5; if( nCols<1 ) { Tcl_SetResult(curFile->interp, "For table extension use, " "get wcs -m dest Col1 ?Col2 ...?", TCL_STATIC); return TCL_ERROR; } else if( nCols > FITS_MAXDIMS ) { Tcl_SetResult(curFile->interp, "Too many columns to obtain WCS information", TCL_STATIC); return TCL_ERROR; } } else { nCols = 2; if( argc != 7 ) { Tcl_SetResult(curFile->interp, "For table extension use, get wcs -m dest RAcol DecCol", TCL_STATIC); return TCL_ERROR; } } for( j=0, i=argc-nCols; iinterp, argv[i], columns+j) != TCL_OK ) { Tcl_ResetResult(curFile->interp); if( fitsTransColList( curFile, argv[i], &numCols, colNums, colTypes, strSize) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Unable to read column specifier", TCL_STATIC); return TCL_ERROR; } if( numCols != 1 ) { Tcl_SetResult(curFile->interp, "Can only have column value", TCL_STATIC); return TCL_ERROR; } columns[j] = colNums[0]; } } if( getMatrix ) { if( fitsGetWcsMatrix(curFile, nCols, columns, argv[4][0]) != TCL_OK ) { return TCL_ERROR; } } else { if( fitsGetWcsPair(curFile, columns[0], columns[1], argv[4][0]) != TCL_OK ) { return TCL_ERROR; } } } } else if( !strcmp("dummy2str", argv[2]) ) { fitsfile *dummyptr; int status = 0; int bitpix = 8; int naxis = 2; long naxes[2]; int columns[FITS_MAXDIMS]; int nkeys; char *header; int i,j; /* Pan Chai: there is only 2 columns */ int nCols = 2; Tcl_Obj *data[5]; naxes[0] = 10; naxes[1] = 10; for( j=0, i=argc-nCols; iinterp, argv[i], columns+j) != TCL_OK ) { Tcl_ResetResult(curFile->interp); if( fitsTransColList( curFile, argv[i], &numCols, colNums, colTypes, strSize) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Unable to read column specifier", TCL_STATIC); return TCL_ERROR; } if( numCols != 1 ) { Tcl_SetResult(curFile->interp, "Can only have column value", TCL_STATIC); return TCL_ERROR; } columns[j] = colNums[0]; } } /* size of histogram is now known, so create temp output file */ if (ffinit(&dummyptr, "mem://", &status) > 0) { ffpmsg("failed to create temp output file for dummy fits file"); return(status); } status = 0; /* create output FITS image HDU */ if (ffcrim(dummyptr, bitpix, naxis, naxes, &status) > 0) { ffpmsg("failed to create output dummy FITS image"); return(status); } status = 0; /* copy header keywords, converting pixel list WCS keywords to image WCS form */ if (fits_copy_pixlist2image(curFile->fptr, dummyptr, 9, naxis, columns, &status) > 0) { ffpmsg("failed to copy pixel list keywords to new dummy header"); return(status); } status = 0; if ( ffhdr2str(dummyptr, 1, (char **)NULL, 0, &header, &nkeys, &status) > 0 ) { Tcl_SetResult(curFile->interp, "Failed to collect all the headers.", TCL_STATIC); return TCL_ERROR; } /* since this is a dummy header, all relative reference starts with 1 */ for (i = 0; i < naxis; i++) { columns[i] = i + 1; } fitsFileGetWcsMatrix( curFile, dummyptr, naxis, columns, argv[3][0], data); Tcl_ListObjAppendElement( curFile->interp, listObj, Tcl_NewStringObj(header, -1)); Tcl_ListObjAppendElement( curFile->interp, listObj, Tcl_NewIntObj( nkeys ) ); Tcl_ListObjAppendElement( curFile->interp, listObj, Tcl_NewListObj(5,data) ); Tcl_SetObjResult(curFile->interp, listObj); /* Use fits_free_memory here instead of ckfree since header was opened */ /* (by cfitsio) using malloc, not ckalloc. */ if (fits_free_memory((char*)header, &status) > 0) { ffpmsg("Failed to free header memory"); return(status); } else return TCL_OK; } else if( !strcmp("translatedKeywords", argv[2]) ) { char outfile[FLEN_FILENAME]; char dest[8]; int status = 0; int status2 = 0; long rownum; fitsfile *newptr; if (argc != 7) { Tcl_SetResult(curFile->interp,"get translatedKeywords rownum colname", TCL_STATIC); return TCL_ERROR; } if (strcmp(argv[6], "NONE") == 0 ) { /* call by fv, use memory to store the data */ strcpy(outfile, "mem://_1"); } else { /* call by ds9, argv[6] is a temporary file name exists in fvtemp */ status = CREATE_DISK_FILE; strcpy(outfile, argv[6]); } /* Copy the image into new primary array and open it as the current */ /* fptr. This will close the table that contains the original image. */ /* create new empty file to hold copy of the image */ if (ffinit(&newptr, outfile, &status) > 0) { ffpmsg("failed to create file for copy of image in table cell:"); ffpmsg(outfile); return(status); } rownum = atol(argv[4]); status = 0; status2 = 0; if (fits_copy_cell2image(curFile->fptr, newptr, argv[3], rownum, &status) > 0) { ffpmsg("Failed to copy table cell to new primary array:"); ffclos(curFile->fptr, &status2); curFile->fptr = 0; /* return null file pointer */ return(status); } if ( ffhdr2str(newptr, 1, (char **)NULL, 0, &header, &nkeys, &status) > 0 ) { Tcl_SetResult(curFile->interp, "Failed to collect all the headers.", TCL_STATIC); return TCL_ERROR; } Tcl_ListObjAppendElement( curFile->interp, listObj, Tcl_NewStringObj(header, -1)); Tcl_ListObjAppendElement( curFile->interp, listObj, Tcl_NewIntObj( nkeys ) ); strcpy(dest, argv[5]); if (strcmp(dest, "DEFAULT") == 0) { /* set destion to '\0' */ dest[0] = '\0'; } else { /* else keep the first character and set rest to '\0' */ dest[1] = '\0'; } if ( fitsGetWcsMatrixAlt(curFile, newptr, listObj, 0, NULL, dest[0]) > 0 ) { Tcl_SetResult(curFile->interp, "Failed to collect all the headers.", TCL_STATIC); return TCL_ERROR; } /* if ( fitsGetWcsPairAlt(curFile, newptr, listObj, 0, 0, '\0') > 0 ) { Tcl_SetResult(curFile->interp, "Failed to collect all the headers.", TCL_STATIC); return TCL_ERROR; } Tcl_SetObjResult(curFile->interp, listObj); */ if (strcmp(argv[6], "NONE") != 0 ) { /* called by ds9, close out the temporary file */ fits_close_file(newptr, &status); } /* Use fits_free_memory here instead of ckfree since header was opened */ /* (by cfitsio) using malloc, not ckalloc. */ if (fits_free_memory((char*)header, &status) > 0) { ffpmsg("Failed to free header memory"); return(status); } else return TCL_OK; } else if( !strcmp("header2str", argv[2]) ) { /* int ffhdr2str( fitsfile *fptr, I - FITS file pointer */ /* int exclude_comm, I - if TRUE, exclude commentary keywords */ /* char **exclist, I - list of excluded keyword names */ /* int nexc, I - number of names in exclist */ /* char **header, O - returned header string */ /* int *nkeys, O - returned number of 80-char keywords */ /* int *status) IO - error status */ if ( ffhdr2str(curFile->fptr, 1, (char **)NULL, 0, &header, &nkeys, &status) > 0 ) { Tcl_SetResult(curFile->interp, "Failed to collect all the headers.", TCL_STATIC); return TCL_ERROR; } Tcl_ListObjAppendElement( curFile->interp, listObj, Tcl_NewStringObj(header, -1)); Tcl_ListObjAppendElement( curFile->interp, listObj, Tcl_NewIntObj( nkeys ) ); Tcl_SetObjResult(curFile->interp, listObj); /* Use fits_free_memory here instead of ckfree since header was opened */ /* (by cfitsio) using malloc, not ckalloc. */ if (fits_free_memory((char*)header, &status) > 0) { ffpmsg("Failed to free header memory"); return(status); } else return TCL_OK; } else if( !strcmp("imgwcs", argv[2]) ) { /* Get IMGWCS */ if ( curFile->hduType != IMAGE_HDU ) { Tcl_SetResult(curFile->interp, "Current extension is not an image", TCL_STATIC); return TCL_ERROR; } if( fitsGetWcsPair(curFile,0,0,'\0') != TCL_OK ) { return TCL_ERROR; } } else if( !strcmp("colwcs", argv[2]) ) { /* Get COLWCS */ int ranum = 0; int decnum = 0; if( curFile->hduType == IMAGE_HDU ) { Tcl_SetResult(curFile->interp, "Current extension is not a table", TCL_STATIC); return TCL_ERROR; } if( argc != 5 ) { Tcl_SetResult(curFile->interp, "get colwcs RAcol DECcol", TCL_STATIC); return TCL_ERROR; } if( Tcl_GetInt(curFile->interp, argv[3], &ranum) != TCL_OK ) { Tcl_ResetResult(curFile->interp); if( fitsTransColList( curFile, argv[3], &numCols, colNums, colTypes, strSize) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Unable to read RAcol", TCL_STATIC); return TCL_ERROR; } if( numCols != 1 ) { Tcl_SetResult(curFile->interp, "Can only have 1 RAcol value", TCL_STATIC); return TCL_ERROR; } ranum = colNums[0]; } if( Tcl_GetInt(curFile->interp, argv[4], &decnum) != TCL_OK ) { Tcl_ResetResult(curFile->interp); if( fitsTransColList( curFile, argv[4], &numCols, colNums, colTypes, strSize) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Unable to read DecCol", TCL_STATIC); return TCL_ERROR; } if( numCols != 1 ) { Tcl_SetResult(curFile->interp, "Can only have 1 DecCol value", TCL_STATIC); return TCL_ERROR; } decnum = colNums[0]; } if( fitsTableGetWcsOld(curFile, ranum, decnum) != TCL_OK ) { return TCL_ERROR; } } else if( !strcmp("image", argv[2]) ) { long fElem, nElem; if( argc < 3 || argc > 5 ) { Tcl_SetResult(curFile->interp, "get image firstElem numElem", TCL_STATIC); return TCL_ERROR; } if( curFile->hduType != IMAGE_HDU ) { Tcl_SetResult(curFile->interp, "Current extension is not a table", TCL_STATIC); return TCL_ERROR; } if( argc>3 ) { fElem = atol( argv[3] ); if( argc>4 ) { nElem = atol( argv[4] ); } else { nElem = 1; } } else { fElem = 1; nElem = 1; i = curFile->CHDUInfo.image.naxes; while( i-- ) nElem *= curFile->CHDUInfo.image.naxisn[i]; } if( imageBlockLoad_1D(curFile, fElem, nElem) != TCL_OK ) { return TCL_ERROR; } } else if ( !strcmp("imageblock", argv[2]) ) { /* GET IMAGE in blocks */ long slice = 1; long cslice = 1; if( argc < 8 || argc > 10 ) { Tcl_SetResult(curFile->interp, "FitsHandle get imageblock arrayName firstRow " "numRows firstCol numCols ?2D image slice? ?cube slice?", TCL_STATIC); return TCL_ERROR; } if( curFile->hduType != IMAGE_HDU ) { Tcl_SetResult(curFile->interp, "Current extension is not an image.", TCL_STATIC); return TCL_ERROR; } if( argc > 8 ) slice = atol(argv[8]); if( argc > 9 ) cslice = atol(argv[9]); if( imageBlockLoad(curFile, argv[3], fitsTcl_atoll(argv[4]), fitsTcl_atoll(argv[5]), fitsTcl_atoll(argv[6]), fitsTcl_atoll(argv[7]), slice, cslice ) != TCL_OK ) { return TCL_ERROR; /* Sets own error message */ } } else if( !strcmp("table",argv[2] ) ) { int idx, format; /* GET TABLE */ if ( curFile->hduType == IMAGE_HDU ) { Tcl_SetResult(curFile->interp, "Current extension is not a table", TCL_STATIC); return TCL_ERROR; } if( curFile->CHDUInfo.table.loadStatus != 1 ) { Tcl_SetResult(curFile->interp, "Need to load the hdu first", TCL_STATIC); return TCL_ERROR; } /* * Strip off the "-c" flag if present... */ bycol = 0; format = 1; idx = 3; while( idx < argc && argv[idx][0]=='-' ) { if( !strcmp(argv[idx],"-c") ) { bycol = 1; } else if( !strcmp(argv[idx],"-noformat") ) { format = 0; } else { break; } idx++; } if( argc-idx > 2 ) { Tcl_SetResult(curFile->interp, "Wrong number of arguments, need " "'get table ?-c? ?-noformat? ?columns? ?rows?'", TCL_STATIC); return TCL_ERROR; } /* If no colList is given, or it is "*", use all the columns... */ if( TCL_OK != fitsTransColList( curFile, ( argc==idx ? "*" : argv[idx] ), &numCols, colNums, colTypes, strSize) ) return TCL_ERROR; /* * Get the Row range parameter */ idx++; if( argc <= idx ) { numRange = 1; range = (int*) malloc(numRange*2*sizeof(int)); range[0] = 1; range[1] = curFile->CHDUInfo.table.numRows; } else { numRange =fitsParseRangeNum(argv[idx])+1; range = (int*) malloc(numRange*2*sizeof(int)); if( fitsParseRange( argv[idx], &numRange, range, numRange, 1, curFile->CHDUInfo.table.numRows, errMsg ) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Error parsing row range:\n", TCL_STATIC); Tcl_AppendResult(curFile->interp, errMsg, (char*)NULL); return TCL_ERROR; } } /* Now get the rows... */ if ( bycol ) { listArray = (Tcl_Obj**) ckalloc( numCols * sizeof(Tcl_Obj*) ); for( k=0; kFITS_CHUNKSIZE ) ntodo = FITS_CHUNKSIZE; status = tableBlockLoad( curFile, "", 1, fRow, ntodo, -99, numCols, colNums, format ); if( status != TCL_OK ) break; fRow += ntodo; resObj = Tcl_GetObjResult( curFile->interp ); if ( bycol ) { for( k = 0; k < numCols; k++) { Tcl_ListObjIndex( curFile->interp, resObj, k, &listObj ); Tcl_ListObjAppendList( curFile->interp, listArray[k], listObj ); } } else { Tcl_ListObjGetElements( curFile->interp, resObj, &n, &listArray ); for ( l = 0; l < ntodo; l++) { for( k = 0; k < numCols; k++) { Tcl_ListObjIndex( curFile->interp, listArray[k], l, valArray+k ); } Tcl_ListObjAppendElement( curFile->interp, listObj, Tcl_NewListObj(numCols, valArray) ); } } } } if( status ) { if ( bycol ) { ckfree( (char*) listArray ); } else { ckfree( (char*) valArray ); } } else { if ( bycol ) { Tcl_SetObjResult( curFile->interp, Tcl_NewListObj( numCols, listArray ) ); } else { Tcl_SetObjResult( curFile->interp, listObj ); } } if( status ) return TCL_ERROR; } else if( !strcmp("vtable",argv[2]) ) { int idx, format; /* GET vector from the TABLE */ if( curFile->hduType == IMAGE_HDU ) { Tcl_SetResult(curFile->interp, "Current extension is not a table", TCL_STATIC); return TCL_ERROR; } if( curFile->CHDUInfo.table.loadStatus != 1 ){ Tcl_SetResult(curFile->interp, "Need to load the hdu first", TCL_STATIC); return TCL_ERROR; } idx = 3; format = 1; if( idxinterp, "Wrong number of arguments, need " "'get vtable ?-noformat? column felem ?rowList?'", TCL_STATIC); return TCL_ERROR; } if( fitsTransColList( curFile, argv[idx++], &numCols, colNums, colTypes, strSize ) != TCL_OK ) return TCL_ERROR; if( numCols != 1 ) { Tcl_SetResult(curFile->interp, "Can only read one vector column of a table at a time", TCL_STATIC); return TCL_ERROR; } felem = atoi(argv[idx++]); /* * Get the Row range parameter */ if( argc <= idx ) { numRange = 1; range = (int*) malloc(numRange*2*sizeof(int)); range[0] = 1; range[1] = curFile->CHDUInfo.table.numRows; } else { numRange = fitsParseRangeNum(argv[idx])+1; range = (int*) malloc(numRange*2*sizeof(int)); if( fitsParseRange( argv[idx++], &numRange, range, numRange, 1, curFile->CHDUInfo.table.numRows, errMsg ) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Error parsing row range:\n", TCL_STATIC); Tcl_AppendResult(curFile->interp, errMsg, (char*)NULL); return TCL_ERROR; } } /* Now get the rows... */ listObj = Tcl_NewListObj( 0, NULL ); for (i = 0; i < numRange; i++ ) { fRow = range[i*2]; while( fRow <= range[i*2+1] ) { ntodo = range[i*2+1] - fRow + 1; if( ntodo>FITS_CHUNKSIZE ) ntodo = FITS_CHUNKSIZE; if( tableBlockLoad( curFile, "", felem, fRow, ntodo, -99, numCols, colNums, format ) != TCL_OK ) return TCL_ERROR; fRow += ntodo; if( Tcl_ListObjIndex( curFile->interp, Tcl_GetObjResult( curFile->interp ), 0, &resObj ) != TCL_OK ) return TCL_ERROR; if( Tcl_ListObjAppendList( curFile->interp, listObj, resObj ) != TCL_OK ) return TCL_ERROR; } } Tcl_SetObjResult( curFile->interp, listObj ); } else { Tcl_SetResult(curFile->interp, "ERROR: unrecognized command to get", TCL_STATIC); return TCL_ERROR; } if (range) free(range); return TCL_OK; } /****************************************************************** * Put ******************************************************************/ int fitsTcl_put( FitsFD *curFile, int argc, Tcl_Obj *const argv[] ) { static char *putKeyList = "put keyword ?-num n? card ?formatFlag?"; static char *putHisList = "put history string"; static char *putTabList = "put table colName firstElem rowSpan listOfData\n"; static char *putImgList = "put image firstElem listOfData\n"; static char *putIhdList = "put ihd ?-p? ?bitpix naxis naxesList? \n" " - -p primary extension \n"; static char *putAhdList = "put ahd numRows numCols {colName} {colType} {colUnit} {tbCol}\n" " extname rowLength\n" " - colType: L(logical), X(bit), I(16 bit integer), " "J(32 bit integer)\n" " An(n Character), En(Single with n format), \n" " Dn(Double with n format), B(Unsigned) \n" " C(Complex), M(Double complex) "; static char *putBhdList = "put bhd numRows numCols {colName} {colType} {colUnit} extname \n" " - colType: nL(logical),nX(bit), nI(16 bit integer), " "nJ(32 bit integer)\n" " nA(Character), nE(Single), nD(Double), nB(Unsigned) \n" " nC(Complex), M(Double complex) "; int numCols,colNums[FITS_COLMAX],colTypes[FITS_COLMAX],strSize[FITS_COLMAX]; int numRange, *range=NULL; char errMsg[256], *argStr, *cmd, **args; int i; if ( argc == 2 ) { Tcl_SetResult(curFile->interp,"Available Commands:\n",TCL_STATIC); Tcl_AppendResult(curFile->interp, putKeyList,"\n", (char *)NULL); Tcl_AppendResult(curFile->interp, putTabList,"\n", (char *)NULL); Tcl_AppendResult(curFile->interp, putIhdList,"\n", (char *)NULL); Tcl_AppendResult(curFile->interp, putAhdList,"\n", (char *)NULL); Tcl_AppendResult(curFile->interp, putBhdList,"\n", (char *)NULL); return TCL_OK; } cmd = Tcl_GetStringFromObj( argv[2], NULL ); if( !strcmp( "keyword", cmd ) ) { /* Write Keyword */ int format, cardNum=0, recLoc=3; if( argc < 4 || argc > 7 ) { Tcl_SetResult(curFile->interp, putKeyList, TCL_STATIC); return TCL_ERROR; } if( !strcmp(Tcl_GetStringFromObj(argv[3],NULL), "-num") ) { if( argc < 6 ) { Tcl_SetResult(curFile->interp, putKeyList, TCL_STATIC); return TCL_ERROR; } if( Tcl_GetIntFromObj(curFile->interp, argv[4], &cardNum) != TCL_OK ) { return TCL_ERROR; } recLoc += 2; } if( recLoc+1 < argc ) { if( Tcl_GetIntFromObj(curFile->interp, argv[recLoc+1], &format) != TCL_OK ) { return TCL_ERROR; } } else { format = 1; } if( fitsPutKwds(curFile, cardNum, Tcl_GetStringFromObj(argv[recLoc],NULL), format) != TCL_OK ) { return TCL_ERROR; } } else if( !strcmp( "history", cmd ) ) { /* Write History */ if( argc != 4 ) { Tcl_SetResult(curFile->interp, putHisList, TCL_STATIC); return TCL_ERROR; } if( fitsPutHisKwd(curFile, Tcl_GetStringFromObj(argv[3],NULL) ) != TCL_OK ) { return TCL_ERROR; } } else if( !strcmp ( "image", cmd ) ) { /* Write Image */ int nElem; long fElem; Tcl_Obj **dataList; if( curFile->hduType != IMAGE_HDU ) { Tcl_SetResult(curFile->interp, "Current extension is not an image", TCL_STATIC); return TCL_ERROR; } if( argc < 5 || argc > 6 ) { Tcl_SetResult(curFile->interp, putImgList, TCL_STATIC); return TCL_ERROR; } if( Tcl_GetLongFromObj(curFile->interp, argv[3], &fElem) != TCL_OK ) { return TCL_ERROR; } /* Skip to last argument... can get nElem directly from data list */ if( Tcl_ListObjGetElements( curFile->interp, argv[argc-1], &nElem, &dataList ) != TCL_OK ) { return TCL_ERROR; } if( varSaveToImage( curFile, fElem, (long)nElem, dataList ) != TCL_OK ) { return TCL_ERROR; } } else if( !strcmp( "table", cmd ) ) { /* Write Table */ int nElem; long fElem; Tcl_Obj **dataElems; if ( curFile->hduType == IMAGE_HDU ) { Tcl_SetResult(curFile->interp, "Current extension is not a table", TCL_STATIC); return TCL_ERROR; } if ( argc != 7 ) { Tcl_SetResult(curFile->interp, putTabList, TCL_STATIC); return TCL_ERROR; } /* parse the column name */ if( fitsTransColList(curFile, Tcl_GetStringFromObj(argv[3],NULL), &numCols,colNums,colTypes,strSize) != TCL_OK ) { return TCL_ERROR; } if( numCols != 1 ) { Tcl_SetResult(curFile->interp, "Can only write one column at a time", TCL_STATIC); return TCL_ERROR; } /* * Get the Row range parameter */ argStr = Tcl_GetStringFromObj( argv[5], NULL ); numRange =fitsParseRangeNum(argStr)+1; range =(int*) malloc(numRange*2*sizeof(int)); if( fitsParseRange(argStr,&numRange,range,numRange, 1, curFile->CHDUInfo.table.numRows,errMsg) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Error parsing row range:\n", TCL_STATIC); Tcl_AppendResult(curFile->interp, errMsg, (char*)NULL); return TCL_ERROR; } if( numRange != 1 ) { Tcl_SetResult(curFile->interp, "Can only write one row range at a time", TCL_STATIC); return TCL_ERROR; } if( Tcl_GetLongFromObj(curFile->interp,argv[4],&fElem) != TCL_OK ) { return TCL_ERROR; } if ( Tcl_ListObjGetElements( curFile->interp, argv[6], &nElem, &dataElems ) != TCL_OK ) { return TCL_ERROR; } if( varSaveToTable(curFile, colNums[0], range[0], fElem, range[1]-range[0]+1, (long)nElem, dataElems ) != TCL_OK ) { return TCL_ERROR; } } else if( !strcmp( "ihd", cmd ) ) { /* Write Image Header */ int isPrimary; if ( argc < 4 || argc > 7 ) { Tcl_SetResult(curFile->interp, putIhdList, TCL_STATIC); return TCL_ERROR; } if( !strcmp( ARGV_STR(3), "-p" ) ) { isPrimary = 1; } else { isPrimary = 0; } args = (char **) ckalloc( argc * sizeof(char *) ); for( i=0; iinterp, putAhdList, TCL_STATIC); return TCL_ERROR; } /* Strip out the numCols[4] parameter... use colNames length instead */ for( j=0,i=3; i<11; i++ ) { if( i!=4 ) newArg[j++] = ARGV_STR(i); } if( fitsPutReqKwds(curFile, 0, ASCII_TBL, 7, (char **)newArg) != TCL_OK ) { return TCL_ERROR; } } else if( !strcmp( "bhd", cmd ) ) { /* Write Binary Table Header */ char const *newArg[5]; int j; if( argc != 9 ) { Tcl_SetResult(curFile->interp, putBhdList, TCL_STATIC); return TCL_ERROR; } /* Strip out the numCols[4] parameter... use colNames length instead */ for( j=0,i=3; i<9; i++ ) { if( i!=4 ) newArg[j++] = ARGV_STR(i); } if( fitsPutReqKwds(curFile, 0, BINARY_TBL, 5, (char **)newArg) != TCL_OK ) { return TCL_ERROR; } } else { Tcl_SetResult(curFile->interp, "Unknown put function", TCL_STATIC); return TCL_ERROR; } if (range) free(range); return TCL_OK; } /****************************************************************** * Insert ******************************************************************/ int fitsTcl_insert( FitsFD *curFile, int argc, char *const argv[] ) { static char *insertList[] = { "insert keyword index record ?formatflag?", "insert column index colName colForm", "insert row index numRows", "insert image ?-p? ?bitpix naxis naxesList? \n" " - -p primary extension, keywords optional if empty array", "insert table numRows {colNames} {colForms} ?{colUnits} extname?\n" " - colForm: nL(logical),nX(bit), nI(16 bit integer), " "nJ(32 bit integer)\n" " nA(Character), nE(Single), nD(Double), nB(Unsigned) \n" " nC(Complex), M(Double complex) \n" "insert table -ascii numRows {colNames} {colForms} ?{colUnits}\n" " {tbCols} extname rowWidth?\n" " - colForm: L(logical), X(bit), I(16 bit integer), " "J(32 bit integer)\n" " An(n Character), En(Single with n format), \n" " Dn(Double with n format), B(Unsigned) \n" " C(Complex), M(Double complex) " }; int index, format, numRows; if( argc == 2 ) { Tcl_AppendResult(curFile->interp, "Available commands:\n", insertList[0], "\n", insertList[1], "\n", insertList[2], "\n", insertList[3], "\n", insertList[4], "\n", (char *)NULL); return TCL_ERROR; } if( !strcmp( "keyword", argv[2] ) ) { if( argc < 5 || argc > 6 ) { Tcl_SetResult(curFile->interp, insertList[0], TCL_STATIC); return TCL_OK; } if( Tcl_GetInt(curFile->interp, argv[3], &index) != TCL_OK) { Tcl_SetResult(curFile->interp, "Failed to get integer index", TCL_STATIC); return TCL_ERROR; } if( argc==6 ) { if ( Tcl_GetInt(curFile->interp, argv[5], &format) != TCL_OK) { Tcl_SetResult(curFile->interp, "Failed to get integer format flag", TCL_STATIC); return TCL_ERROR; } } else { format = 1; } if( fitsInsertKwds(curFile, index, argv[4], format) != TCL_OK ) { return TCL_ERROR; } } else if( !strcmp( "column", argv[2] ) ) { if (argc != 6 ) { Tcl_SetResult(curFile->interp, insertList[1], TCL_STATIC); return TCL_ERROR; } if( Tcl_GetInt(curFile->interp, argv[3], &index) != TCL_OK) { Tcl_SetResult(curFile->interp, "Failed to get integer index", TCL_STATIC); return TCL_ERROR; } if( addColToTable(curFile,index,argv[4],argv[5]) != TCL_OK ) { return TCL_ERROR; } } else if( !strcmp( "row", argv[2] ) ) { if( argc != 5 ) { Tcl_SetResult(curFile->interp, insertList[2], TCL_STATIC); return TCL_ERROR; } if( Tcl_GetInt(curFile->interp, argv[3], &index) != TCL_OK) { Tcl_SetResult(curFile->interp, "Failed to get integer index", TCL_STATIC); return TCL_ERROR; } if( Tcl_GetInt(curFile->interp, argv[4], &numRows) != TCL_OK) { Tcl_SetResult(curFile->interp, "Failed to get integer numRows", TCL_STATIC); return TCL_ERROR; } if( addRowToTable(curFile,index-1,numRows) != TCL_OK ) { return TCL_ERROR; } } else if( !strcmp( "image", argv[2] ) ) { /* Write Image Header */ int isPrimary; if ( argc < 4 || argc > 7 ) { Tcl_SetResult(curFile->interp, insertList[3], TCL_STATIC); return TCL_ERROR; } /* * Strip off the "-p" flag if present... */ if( !strcmp(argv[3],"-p") ) { isPrimary = 1; } else { isPrimary = 0; } if( fitsPutReqKwds(curFile, isPrimary, IMAGE_HDU, argc-3-isPrimary, argv+3+isPrimary) !=TCL_OK ) { return TCL_ERROR; } } else if( !strcmp( "table", argv[2] ) ) { /* Write Table Header */ int tabType; if( argc>3 && !strcmp( "-ascii", argv[3] ) ) { tabType = ASCII_TBL; if( argc < 7 || argc > 11 ) { Tcl_SetResult(curFile->interp, insertList[4], TCL_STATIC); return TCL_ERROR; } } else { tabType = BINARY_TBL; if( argc < 6 || argc > 8 ) { Tcl_SetResult(curFile->interp, insertList[4], TCL_STATIC); return TCL_ERROR; } } if( fitsPutReqKwds(curFile, 0, tabType, argc-3-(tabType==ASCII_TBL?1:0), argv+3+(tabType==ASCII_TBL?1:0)) != TCL_OK ) { return TCL_ERROR; } } else { Tcl_SetResult(curFile->interp, "No such insert command", TCL_STATIC); return TCL_ERROR; } return TCL_OK; } /****************************************************************** * Select ******************************************************************/ int fitsTcl_select( FitsFD *curFile, int argc, char *const argv[] ) { static char *selRowList = "select rows -expr expression firstrow nrow\n "; int fRow, nRows; char * row_status; long n_good_rows; int i; Tcl_Obj *valObj, *listObj; if( argc == 2 ) { Tcl_AppendResult(curFile->interp, selRowList,(char *) NULL); return TCL_OK; } if( !strcmp("rows", argv[2]) ) { if( argc != 7 ) { Tcl_SetResult(curFile->interp, selRowList, TCL_STATIC); return TCL_ERROR; } if( !strcmp("-expr", argv[3]) ) { if( Tcl_GetInt(curFile->interp, argv[5], &fRow) != TCL_OK ) { return TCL_ERROR; } if( Tcl_GetInt(curFile->interp, argv[6], &nRows) != TCL_OK ) { return TCL_ERROR; } row_status = (char*) malloc((nRows+1)*sizeof(char)); listObj = Tcl_NewObj(); if( fitsSelectRowsExpr(curFile, argv[4], fRow,nRows, &n_good_rows,row_status) == TCL_OK ) { /* for ( i=0 ; i< nRows; i++ ) { # if ( row_status[i] == 1 ) { # sprintf(result,"%d",i+fRow); # Tcl_AppendElement(curFile->interp,result); # } # }*/ if (n_good_rows ) { for (i=0; i < nRows; i++) { if ( row_status[i] == 1 ) { valObj = Tcl_NewLongObj( i+fRow ); Tcl_ListObjAppendElement( curFile->interp, listObj, valObj); } } Tcl_SetObjResult( curFile->interp, listObj); } } else { if(row_status) free(row_status); return TCL_ERROR; } } else { Tcl_SetResult(curFile->interp, selRowList, TCL_STATIC); return TCL_ERROR; } } else { Tcl_SetResult(curFile->interp, "Unrecognized option to select", TCL_STATIC); return TCL_ERROR; } if(row_status) free(row_status); return TCL_OK; } /****************************************************************** * Delete ******************************************************************/ int fitsTcl_delete( FitsFD *curFile, int argc, char *const argv[] ) { static char *delKeyList = "delete keyword KeyList\n" " (KeyList can be a mix of keyword names and keyword numbers\n"; static char *delHduList = "delete chdu\n"; static char *delTabList = "delete cols colList\n "; static char *delRowList = "delete rows -expr expression\n " "delete rows -range rangelist\n " "delete rows firstRow numRows\n "; int numCols,colNums[FITS_COLMAX],colTypes[FITS_COLMAX],strSize[FITS_COLMAX]; int fRow, nRows; if( argc == 2 ) { Tcl_AppendResult(curFile->interp, delKeyList, delHduList, delTabList, delRowList, (char *) NULL); return TCL_OK; } if( !strcmp("keyword", argv[2]) ) { if( argc != 4 ) { Tcl_SetResult(curFile->interp, delKeyList, TCL_STATIC); return TCL_ERROR; } if( fitsDeleteKwds(curFile, argv[3] ) != TCL_OK ) { return TCL_ERROR; } } else if( !strcmp("cols", argv[2]) ) { if( argc != 4 ) { Tcl_SetResult(curFile->interp, delTabList, TCL_STATIC); return TCL_ERROR; } if( fitsTransColList( curFile,argv[3], &numCols,colNums,colTypes,strSize) != TCL_OK ) return TCL_ERROR; if( fitsDeleteCols(curFile, colNums, numCols) != TCL_OK ) { return TCL_ERROR; } } else if( !strcmp("rows", argv[2]) ) { if( argc != 5 ) { Tcl_SetResult(curFile->interp, delRowList, TCL_STATIC); return TCL_ERROR; } if( !strcmp("-expr", argv[3]) ) { if( fitsDeleteRowsExpr(curFile, argv[4]) != TCL_OK ) { return TCL_ERROR; } } else if (!strcmp("-range", argv[3]) ) { if( fitsDeleteRowsRange(curFile, argv[4]) != TCL_OK ) { return TCL_ERROR; } } else { if( Tcl_GetInt(curFile->interp, argv[3], &fRow) != TCL_OK ) { return TCL_ERROR; } if( Tcl_GetInt(curFile->interp, argv[4], &nRows) != TCL_OK ) { return TCL_ERROR; } if( fitsDeleteRows(curFile, fRow, nRows) != TCL_OK ) { return TCL_ERROR; } } } else if( !strcmp("chdu", argv[2]) ) { if( argc != 3 ) { Tcl_SetResult(curFile->interp, delHduList, TCL_STATIC); return TCL_ERROR; } if( fitsDeleteCHdu(curFile) != TCL_OK ) { return TCL_ERROR; } } else { Tcl_SetResult(curFile->interp, "Unrecognized option to delete", TCL_STATIC); return TCL_ERROR; } return TCL_OK; } /****************************************************************** * Load ******************************************************************/ int fitsTcl_load( FitsFD *curFile, int argc, char *const argv[] ) { static char *loadList = "\n" "load arrayRow colName ?defaultNull? ?firstElement? - Load a row\n" "load column colName ?defaultNull? ?firstElement? - Load a column\n" "load vtable colName - Load all elements of a vector column into memory\n" "load tblock arrayName colList firstRow numRows colIndex ?felem?\n" " - load a chunk of table and set up an array \"arrayName\"\n" " with indices of (colIndex-1,firstRow-1), etc \n" "load copyto filename taget\n" "load image ?slice? ?rotate? - Load a 2D slice of an image into memory\n" " (rotate: number of 90deg ccw rotations to perform)\n" "load irows firstRow lastRow ?slice? - load mean value of rows\n" "load icols firstCol lastCol ?slice? - load mean value of columns\n" "load iblock arrayName firstRow numRows fitsCol numCols ?slice?\n" " - load 2d image slice into an array or memory\n" " if arrayName is --, then a pointer is returned\n" "load expr expression ?defaultNull?\n" "load keyword - load the header of CHDU into a hash table \n" "load chdu - load the CHDU (useful if you move to the CHDU with -s,\n" " which does't load the HDUInfo) \n"; int numCols,colNums[FITS_COLMAX],colTypes[FITS_COLMAX],strSize[FITS_COLMAX]; int fRow, nRows; int fCol, felem=1; fitsfile *infptr, *outfptr; /* FITS file pointers defined in fitsio.h */ int status = 0, ii = 1, iteration = 0, single = 0, hdupos; int hdutype, bitpix, bytepix, naxis = 0, nkeys, datatype = 0, anynul; long naxes[9] = {1, 1, 1, 1, 1, 1, 1, 1, 1}; long first, totpix = 0, npix; double *array, bscale = 1.0, bzero = 0.0, nulval = 0.; char card[81]; if( argc == 2 ) { Tcl_SetResult(curFile->interp, loadList, TCL_STATIC); return TCL_OK; } if( !strcmp("keyword", argv[2]) ) { /* Now LOAD the kwds hash table... */ if( fitsLoadKwds(curFile) != TCL_OK ) { fitsCloseFile((ClientData) curFile); return TCL_ERROR; } } else if( !strcmp("irows", argv[2]) ) { long slice; if( curFile->hduType != IMAGE_HDU ) { Tcl_SetResult(curFile->interp, "Current extension is not an image", TCL_STATIC); return TCL_ERROR; } if( argc < 5 ) { Tcl_SetResult(curFile->interp, "FitsHandle load irows firstRow lastRows ?slice?", TCL_STATIC); return TCL_ERROR; } if( argc == 5 ) { slice = 1; } else { slice = atol(argv[5]); } if( imageRowsMeanToPtr(curFile, atol(argv[3]), /* first row */ atol(argv[4]), /* last row*/ slice ) != TCL_OK ) { Tcl_AppendResult(curFile->interp, "fitsTcl Error: cannot load irows", NULL); return TCL_ERROR; } } else if( !strcmp("icols", argv[2]) ) { long slice; if( curFile->hduType != IMAGE_HDU ) { Tcl_SetResult(curFile->interp, "Current extension is not an image", TCL_STATIC); return TCL_ERROR; } if( argc < 5 ) { Tcl_SetResult(curFile->interp, "FitsHandle load icols firstCol lastCols ?slice?", TCL_STATIC); return TCL_ERROR; } if( argc == 5 ) { slice = 1; } else { slice = atol(argv[5]); } if( imageColsMeanToPtr(curFile, atol(argv[3]), atol(argv[4]), slice) != TCL_OK ) { Tcl_AppendResult(curFile->interp, "\nfitsTcl Error: cannot load icols", NULL); return TCL_ERROR; } } else if( !strcmp("iblock", argv[2]) ) { char *varName="\0"; LONGLONG slice = 1; LONGLONG cslice = 1; if ( curFile->hduType != IMAGE_HDU ) { Tcl_SetResult(curFile->interp, "Current extension is not an image", TCL_STATIC); return TCL_ERROR; } if( argc < 8 || argc > 10 ) { Tcl_SetResult(curFile->interp, "FitsHandle load iblock varName firstRow numRows " "firstCol numCols ?slice?", TCL_STATIC); return TCL_ERROR; } if( argc > 8 ) slice = fitsTcl_atoll(argv[8]); if( argc > 9 ) cslice = fitsTcl_atoll(argv[9]); if( strcmp( argv[3], "--" ) ) varName = argv[3]; if( imageBlockLoad(curFile, varName, fitsTcl_atoll(argv[4]), fitsTcl_atoll(argv[5]), fitsTcl_atoll(argv[6]), fitsTcl_atoll(argv[7]), slice, cslice ) != TCL_OK ) { return TCL_ERROR; } } else if( !strcmp("tblock", argv[2]) ) { int format=1; int idx; int varIdx; if ( curFile->hduType == IMAGE_HDU ) { Tcl_SetResult(curFile->interp, "Current extension is not a table", TCL_STATIC); return TCL_ERROR; } if (argc < 8 || argc > 11) { Tcl_SetResult(curFile->interp, "Usage: load tblock ?-noformat? arrayName colList " "firstRow numRows firstCol ?felem?", TCL_STATIC); return TCL_ERROR; } idx = 3; if( !strcmp("-noformat", argv[idx]) ) { idx++; format=0; } varIdx = idx++; /* parse column list */ if( fitsTransColList( curFile,argv[idx++], &numCols,colNums,colTypes,strSize) != TCL_OK ) return TCL_ERROR; /* get the firstRow and numRows */ if( Tcl_GetInt(curFile->interp, argv[idx++], &fRow) != TCL_OK ) return TCL_ERROR; if( Tcl_GetInt(curFile->interp, argv[idx++], &nRows) != TCL_OK ) return TCL_ERROR; if( Tcl_GetInt(curFile->interp, argv[idx++], &fCol) != TCL_OK ) return TCL_ERROR; /* Skip a possible obsolete value between fCol and last argument */ if( argc>idx ) { /* Read felem from very last argument */ if( Tcl_GetInt(curFile->interp, argv[argc-1], &felem) != TCL_OK ) return TCL_ERROR; } if( tableBlockLoad(curFile, argv[varIdx], felem, fRow, nRows, fCol, numCols, colNums, format) != TCL_OK ) return TCL_ERROR; } else if( !strcmp("image", argv[2]) ) { long slice = 1; int rotate = 0; if ( curFile->hduType != IMAGE_HDU ) { Tcl_SetResult(curFile->interp, "Current extension is not an image", TCL_STATIC); return TCL_ERROR; } /* starting element, increment of naxisn[0] x naxisn[1] to get different frames of a 3d image */ if( argc == 3 ) { ; /* default to the first frame to allow backward compatible */ } else if( curFile->CHDUInfo.image.naxes <= 2 ) { ; /* two-d image */ } else { slice = atol(argv[3]); if( slice < 1 ) { Tcl_SetResult(curFile->interp, "fitsTcl Error: slice starts at 1", TCL_STATIC); return TCL_ERROR; } /* if( slice > curFile->CHDUInfo.image.naxisn[2] ) { Tcl_SetResult(curFile->interp, "fitsTcl Error: slice exceeds the 3rd dim", TCL_STATIC); return TCL_ERROR; } */ if( argc == 5 ) { rotate = atoi(argv[4]); if( rotate<0 || rotate>3 ) { Tcl_SetResult(curFile->interp, "fitsTcl Error: Illegal rotate value", TCL_STATIC); return TCL_ERROR; } } } if( imageGetToPtr(curFile, slice, rotate) != TCL_OK ) { return TCL_ERROR; } } else if( !strcmp("copyto", argv[2]) ) { /* Open the input file and create output file */ fits_open_file(&infptr, argv[3], READONLY, &status); fits_create_file(&outfptr, argv[4], &status); if (status != 0) { fits_report_error(stderr, status); return(status); } fits_get_hdu_num(infptr, &hdupos); /* Get the current HDU position */ /* Copy only a single HDU if a specific extension was given */ if (hdupos != 1 || strchr(argv[3], '[')) single = 1; for (; !status; hdupos++) /* Main loop through each extension */ { fits_get_hdu_type(infptr, &hdutype, &status); if (hdutype == IMAGE_HDU) { /* get image dimensions and total number of pixels in image */ for (ii = 0; ii < 9; ii++) naxes[ii] = 1; fits_get_img_param(infptr, 9, &bitpix, &naxis, naxes, &status); totpix = naxes[0] * naxes[1] * naxes[2] * naxes[3] * naxes[4] * naxes[5] * naxes[6] * naxes[7] * naxes[8]; } if (hdutype != IMAGE_HDU || naxis == 0 || totpix == 0) { /* just copy tables and null images */ fits_copy_hdu(infptr, outfptr, 0, &status); } else { /* Explicitly create new image, to support compression */ fits_create_img(outfptr, bitpix, naxis, naxes, &status); /* copy all the user keywords (not the structural keywords) */ fits_get_hdrspace(infptr, &nkeys, NULL, &status); for (ii = 1; ii <= nkeys; ii++) { fits_read_record(infptr, ii, card, &status); if (fits_get_keyclass(card) > TYP_CMPRS_KEY) fits_write_record(outfptr, card, &status); } switch(bitpix) { case BYTE_IMG: datatype = TBYTE; break; case SHORT_IMG: datatype = TSHORT; break; case LONG_IMG: datatype = TLONG; break; case FLOAT_IMG: datatype = TFLOAT; break; case DOUBLE_IMG: datatype = TDOUBLE; break; case LONGLONG_IMG: datatype = TLONGLONG; break; } bytepix = abs(bitpix) / 8; npix = totpix; iteration = 0; /* try to allocate memory for the entire image */ /* use double type to force memory alignment */ array = (double *) calloc(npix, bytepix); /* if allocation failed, divide size by 2 and try again */ while (!array && iteration < 10) { iteration++; npix = npix / 2; array = (double *) calloc(npix, bytepix); } if (!array) { fprintf(stdout,"Memory allocation error\n"); return(0); } /* turn off any scaling so that we copy the raw pixel values */ fits_set_bscale(infptr, bscale, bzero, &status); fits_set_bscale(outfptr, bscale, bzero, &status); first = 1; while (totpix > 0 && !status) { /* read all or part of image then write it back to the output file */ fits_read_img(infptr, datatype, first, npix, &nulval, array, &anynul, &status); fits_write_img(outfptr, datatype, first, npix, array, &status); totpix = totpix - npix; first = first + npix; } free(array); } if (single) break; /* quit if only copying a single HDU */ fits_movrel_hdu(infptr, 1, NULL, &status); /* try to move to next HDU */ } if (status == END_OF_FILE) status = 0; /* Reset after normal error */ fits_close_file(outfptr, &status); fits_close_file(infptr, &status); } else if( !strcmp("arrayRow", argv[2]) ) { char *nullPtr = "NULL"; long rowNum; long nelem; if( curFile->hduType == IMAGE_HDU ) { Tcl_SetResult(curFile->interp, "Current extension is not a table", TCL_STATIC); return TCL_ERROR; } if( argc < 4 || argc > 8 ) { Tcl_SetResult(curFile->interp, "fitsObj load arrayRow colName rowNumber numElement ?nulValue? ?firstelem?", TCL_STATIC); return TCL_ERROR; } if( fitsTransColList( curFile, argv[3], &numCols, colNums, colTypes, strSize ) != TCL_OK ) return TCL_ERROR; if( numCols != 1 ) { Tcl_SetResult(curFile->interp, "Can only load one column at a time", TCL_STATIC); return TCL_ERROR; } rowNum = atol(argv[4]); nelem = atol(argv[5]); if( argc>6 ) nullPtr = argv[6]; if( argc>7 ) felem = atol(argv[7]); if( tableRowGetToPtr(curFile, rowNum, colNums[0], nelem, nullPtr, felem) ) { return TCL_ERROR; } } else if( !strcmp("column", argv[2]) ) { char *nullPtr = "NULL"; if( curFile->hduType == IMAGE_HDU ) { Tcl_SetResult(curFile->interp, "Current extension is not a table", TCL_STATIC); return TCL_ERROR; } if( argc < 4 || argc > 6 ) { Tcl_SetResult(curFile->interp, "load column colName ?nulValue? ?firstelem?", TCL_STATIC); return TCL_ERROR; } if( fitsTransColList( curFile, argv[3], &numCols, colNums, colTypes, strSize ) != TCL_OK ) return TCL_ERROR; if( numCols != 1 ) { Tcl_SetResult(curFile->interp, "Can only load one column at a time", TCL_STATIC); return TCL_ERROR; } if( argc>4 ) nullPtr = argv[4]; if( argc>5 ) felem = atol(argv[5]); if( tableGetToPtr(curFile, colNums[0], nullPtr, felem) ) { return TCL_ERROR; } } else if( !strcmp("vtable", argv[2]) ) { char *nullPtr = "NULL"; if ( curFile->hduType == IMAGE_HDU ) { Tcl_SetResult(curFile->interp, "Current extension is not a table", TCL_STATIC); return TCL_ERROR; } if( argc < 4 || argc > 5 ) { /* For backwards compatibility, allow for one extra parameter */ /* ... formerly the vector size of column */ /* PDW 12/06/99: Sacrifice backwards compat for adding defNull*/ Tcl_SetResult(curFile->interp, "load vtable colName ?nulValue?", TCL_STATIC); return TCL_ERROR; } if( fitsTransColList( curFile,argv[3], &numCols,colNums,colTypes,strSize) != TCL_OK ) return TCL_ERROR; if( numCols != 1 ) { Tcl_SetResult( curFile->interp, "Can only load one column at a time", TCL_STATIC ); return TCL_ERROR; } if( argc>4 ) nullPtr = argv[4]; if( vtableGetToPtr(curFile, colNums[0], nullPtr) ) { return TCL_ERROR; } } else if( !strcmp("expr", argv[2]) ) { char *nullPtr = "NULL", errMsg[256]; int numRange, *range=NULL; int argOff=0; if( curFile->hduType == IMAGE_HDU ) { Tcl_SetResult(curFile->interp, "Current extension is not a table", TCL_STATIC); return TCL_ERROR; } if( !strcmp("-rows", argv[3]) && argc>4 ) { numRange = fitsParseRangeNum(argv[4])+1; range = (int*) malloc(numRange*2*sizeof(int)); if( fitsParseRange(argv[4],&numRange,range,numRange, 1, curFile->CHDUInfo.table.numRows,errMsg) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Error parsing row range:\n", TCL_STATIC); Tcl_AppendResult(curFile->interp, errMsg, (char*)NULL); return TCL_ERROR; } argOff = 2; } else { numRange = 1; range = (int*) malloc(numRange*2*sizeof(int)); range[0] = 1; range[1] = curFile->CHDUInfo.table.numRows; } if( argc < 4+argOff || argc-argOff > 5+argOff ) { Tcl_SetResult(curFile->interp, "Usage: load expr ?-rows range? exprStr ?nullVal?", TCL_STATIC); return TCL_ERROR; } if( argc > 4+argOff ) nullPtr = argv[4+argOff]; if( exprGetToPtr( curFile, argv[3+argOff], nullPtr, numRange, range ) ) { return TCL_ERROR; } } else if( !strcmp("all", argv[2]) || !strcmp("chdu", argv[2]) ) { /* load the current hdu */ if( fitsUpdateCHDU(curFile, curFile->hduType) != TCL_OK ) { Tcl_SetResult(curFile->interp, "fitsTcl Error: Cannot update current HDU", TCL_STATIC); return TCL_ERROR; } if( fitsLoadHDU(curFile) != TCL_OK ) { return TCL_ERROR; } } else { Tcl_SetResult(curFile->interp, "Error in fitsTcl: unknown load function", TCL_STATIC); return TCL_ERROR; } return TCL_OK; } /****************************************************************** * Free ******************************************************************/ int fitsTcl_free( FitsFD *curFile, int argc, Tcl_Obj *const argv[] ) { void *databuff; Tcl_Obj **addList; char *addStr; int nAdd; if( argc == 2 ) { Tcl_SetResult(curFile->interp, "free addressList", TCL_STATIC); return TCL_OK; } if( argc>4 ) { Tcl_SetResult(curFile->interp, "Too many arguments to free", TCL_STATIC); return TCL_ERROR; } if( Tcl_ListObjGetElements(curFile->interp, argv[argc-1], &nAdd, &addList) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot parse the address list", TCL_STATIC); return TCL_ERROR; } while( nAdd-- ) { databuff = NULL; addStr = Tcl_GetStringFromObj( addList[nAdd], NULL ); sscanf(addStr,PTRFORMAT,&databuff); if ( databuff == NULL) { Tcl_SetResult(curFile->interp, "Error interpretting pointer address", TCL_STATIC); return TCL_ERROR; } ckfree( (char *) databuff); } return TCL_OK; } /****************************************************************** * Flush ******************************************************************/ int fitsTcl_flush( FitsFD *curFile, int argc, Tcl_Obj *const argv[] ) { int status = 0; if ( argc == 2 ) { ffflsh(curFile->fptr, 0, &status); } else if( argc == 3 ) { char *opt; opt = Tcl_GetStringFromObj( argv[2], NULL ); if( !strcmp(opt, "clear") ) { ffflsh(curFile->fptr, 1, &status); } else { Tcl_SetResult(curFile->interp, "fitsFile flush ?clear?", TCL_STATIC); return TCL_ERROR; } } else { Tcl_SetResult(curFile->interp, "fitsFile flush ?clear?", TCL_STATIC); return TCL_ERROR; } if( status ) { Tcl_SetResult(curFile->interp, "fitsTcl Error: cannot flush file\n", TCL_STATIC); dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } return TCL_OK; } /****************************************************************** * Copy ******************************************************************/ int fitsTcl_copy( FitsFD *curFile, int argc, Tcl_Obj *const argv[] ) { static char *copyList = "\n" "copy filename\n"; if( argc == 2 ) { Tcl_SetResult(curFile->interp, copyList, TCL_STATIC); return TCL_OK; } if( fitsCopyCHduToFile(curFile, Tcl_GetStringFromObj( argv[2], NULL ) ) != TCL_OK ) { return TCL_ERROR; } return TCL_OK; } /****************************************************************** * Sascii ******************************************************************/ int fitsTcl_sascii( FitsFD *curFile, int argc, char *const argv[] ) { static char *sasciiList = "sascii table filename fileMode firstRow numRows colList widthList\n" " ifFixedFormat ifCSV ifPrintRow sepString\n" "sascii image filename fileMode firstRow numRows firstCol\n" " numCols cellSize ifCSV ifPrintRow sepString ?slice?\n"; int numCols,colNums[FITS_COLMAX],colTypes[FITS_COLMAX],strSize[FITS_COLMAX]; int fRow, nRows; int fCol, nCols, nWdths; int cellSize, i, baseColNum, ifVariableVec; int ifCSV, ifPrintRow, ifFixedFormat; char **listWid; if( argc == 2 ) { Tcl_SetResult(curFile->interp, sasciiList, TCL_STATIC); return TCL_OK; } if( !strcmp("table", argv[2]) ){ if( argc < 13 || argc > 14 ) { Tcl_SetResult(curFile->interp, "Wrong # of args to 'sascii table'", TCL_STATIC); return TCL_ERROR; } if( Tcl_GetInt(curFile->interp, argv[5], &fRow) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot get first row", TCL_STATIC); return TCL_ERROR; } if( Tcl_GetInt(curFile->interp, argv[6], &nRows) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot get number of rows", TCL_STATIC); return TCL_ERROR; } if( fitsTransColList( curFile,argv[7], &numCols,colNums,colTypes,strSize) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot parse the column list", TCL_STATIC); return TCL_ERROR; } if( Tcl_SplitList(curFile->interp, argv[8], &nWdths, &listWid) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot parse the width list", TCL_STATIC); ckfree( (char*)listWid ); return TCL_ERROR; } if( nWdths != numCols ) { Tcl_SetResult(curFile->interp, "Cell width array and Column list have different sizes", TCL_STATIC); ckfree( (char*)listWid ); return TCL_ERROR; } for( i=0; i< numCols; i++ ) { if( Tcl_GetInt(curFile->interp, listWid[i], strSize+i) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Unable to parse the width list", TCL_STATIC); ckfree( (char*)listWid ); return TCL_ERROR; } } ckfree( (char*)listWid ); if( Tcl_GetInt(curFile->interp, argv[9], &ifFixedFormat) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot get ifFixedFormat", TCL_STATIC); return TCL_ERROR; } if( Tcl_GetInt(curFile->interp, argv[10], &ifCSV) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot get ifCSV", TCL_STATIC); return TCL_ERROR; } if( Tcl_GetInt(curFile->interp, argv[11], &ifPrintRow) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot get ifPrintRow", TCL_STATIC); return TCL_ERROR; } if( saveTableToAscii( curFile, argv[3], argv[4], 1, fRow, nRows, numCols, colTypes, colNums, strSize, ifFixedFormat, ifCSV, ifPrintRow, argv[12]) ) return TCL_ERROR; } else if( !strcmp("image", argv[2]) ) { long slice = 1; if( argc < 13 || argc > 14 ) { Tcl_SetResult(curFile->interp, "Wrong # of args to 'sascii image'", TCL_STATIC); return TCL_ERROR; } if( argc == 14 ) slice = atol(argv[13]); if( Tcl_GetInt(curFile->interp, argv[5], &fRow) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot get first row", TCL_STATIC); return TCL_ERROR; } if( Tcl_GetInt(curFile->interp, argv[6], &nRows) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot get number of rows", TCL_STATIC); return TCL_ERROR; } if( Tcl_GetInt(curFile->interp, argv[7], &fCol) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot get first column", TCL_STATIC); return TCL_ERROR; } if( Tcl_GetInt(curFile->interp, argv[8], &nCols) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot get number of columns", TCL_STATIC); return TCL_ERROR; } if( Tcl_GetInt(curFile->interp, argv[9], &cellSize) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot get cellSize", TCL_STATIC); return TCL_ERROR; } if( Tcl_GetInt(curFile->interp, argv[10], &ifCSV) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot get ifCSV", TCL_STATIC); return TCL_ERROR; } if( Tcl_GetInt(curFile->interp, argv[11], &ifPrintRow) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot get ifPrintRow", TCL_STATIC); return TCL_ERROR; } /* do error checking later sepString = argv[12]; */ if( saveImageToAscii( curFile, argv[3], argv[4], fRow, nRows, fCol, nCols, cellSize, ifCSV, ifPrintRow, argv[12], slice ) ) return TCL_ERROR; } else if( !strcmp("vector", argv[2]) ) { ifVariableVec = atol(argv[13]); if( Tcl_GetInt(curFile->interp, argv[5], &fRow) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot get first row", TCL_STATIC); return TCL_ERROR; } if( Tcl_GetInt(curFile->interp, argv[6], &nRows) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot get number of rows", TCL_STATIC); return TCL_ERROR; } if( Tcl_GetInt(curFile->interp, argv[7], &fCol) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot get first column", TCL_STATIC); return TCL_ERROR; } if( Tcl_GetInt(curFile->interp, argv[8], &nCols) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot get number of columns", TCL_STATIC); return TCL_ERROR; } if( fitsTransColList( curFile,argv[9], &numCols,colNums,colTypes,strSize) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot parse the column list", TCL_STATIC); return TCL_ERROR; } /* 1-based */ baseColNum = colNums[0]; if( Tcl_GetInt(curFile->interp, argv[10], &ifCSV) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot get ifCSV", TCL_STATIC); return TCL_ERROR; } if( Tcl_GetInt(curFile->interp, argv[11], &ifPrintRow) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot get ifPrintRow", TCL_STATIC); return TCL_ERROR; } /* do error checking later sepString = argv[12]; */ if( saveVectorTableToAscii( curFile, argv[3], argv[4], fRow, nRows, fCol, nCols, baseColNum, ifCSV, ifPrintRow, argv[12], ifVariableVec ) ) return TCL_ERROR; } else { Tcl_SetResult(curFile->interp, "Unknown sascii command", TCL_STATIC); return TCL_ERROR; } return TCL_OK; } /****************************************************************** * Sort ******************************************************************/ int fitsTcl_sort( FitsFD *curFile, int argc, char *const argv[] ) { static char *sortList = "sort ?-merge? colNameList ?isAscendFlagList? \n"; int numCols,colNums[FITS_COLMAX],colTypes[FITS_COLMAX],strSize[FITS_COLMAX]; int i; int *isAscend; char *const *argPtr; char **listPtr; int listNum; int isMerge = 0; if( argc == 2 ) { Tcl_SetResult(curFile->interp, sortList, TCL_STATIC); return TCL_OK; } if( curFile->hduType == IMAGE_HDU ) { Tcl_SetResult(curFile->interp, "Cannot sort an image", TCL_STATIC); return TCL_ERROR; } argc -= 2; argPtr = argv + 2; if( !strcmp(argPtr[0], "-merge") ) { isMerge = 1; argc --; argPtr ++; } if( fitsTransColList( curFile,argPtr[0], &numCols,colNums,colTypes,strSize) != TCL_OK ) { return TCL_ERROR; } isAscend = (int *) ckalloc(numCols*sizeof(int)); /* if no isAscend specified, set as default ascend */ if (argc == 1) { for (i=0; i < numCols; i++) isAscend[i] = 1; } else { if( Tcl_SplitList(curFile->interp, argPtr[1], &listNum, &listPtr) != TCL_OK ) { ckfree((char *) isAscend); return TCL_ERROR; } if( listNum != numCols ) { Tcl_SetResult(curFile->interp, "fitsTcl Error: number of flags and columns don't match", TCL_STATIC); ckfree((char *) isAscend); ckfree((char *) listPtr); return TCL_ERROR; } for (i=0; i< listNum; i++) { if( Tcl_GetInt(curFile->interp, listPtr[i], &isAscend[i]) != TCL_OK ) { ckfree((char*) isAscend); ckfree((char*) listPtr); Tcl_SetResult(curFile->interp, "fitsTcl Error: cannot parse sort flag", TCL_STATIC); return TCL_ERROR; } } ckfree((char *) listPtr); } if( fitsSortTable(curFile, numCols, colNums, strSize, isAscend, isMerge) != TCL_OK ) { ckfree ((char *) isAscend); return TCL_ERROR; } ckfree ((char *) isAscend); return TCL_OK; } /****************************************************************** * Add ******************************************************************/ int fitsTcl_add( FitsFD *curFile, int argc, char *const argv[] ) { static char *addColList = "add column colName colForm ?expr?\n" "add column colName colForm ?expr? ?rowrange?\n" " colForm: e.g.\n" " ASCII Table: A15, I10, E12.5, D20.10, F14.6 ... \n" " BINARY Table: 15A, 1I, 1J, 1E, 1D, 1L, 1X, 1B, 1C, 1M\n"; static char *addRowList = "add row numRows\n"; char result[16]; int numCols,colNums[FITS_COLMAX],colTypes[FITS_COLMAX],strSize[FITS_COLMAX]; int numRange, *range=NULL; char errMsg[256]; /* range = (int*) malloc(FITS_MAXRANGE*2*sizeof(int)); */ if( argc == 2 ) { Tcl_AppendResult(curFile->interp, addColList, addRowList, (char*)NULL); return TCL_OK; } if( !strcmp(argv[2], "column") ) { if( argc == 5 ) { if( addColToTable(curFile, FITS_COLMAX, argv[3], argv[4]) != TCL_OK ) { return TCL_ERROR; } } else if( argc >= 6 ) { char *tmpColName; int isNew; strToUpper(argv[3], &tmpColName); if( fitsTransColList(curFile,tmpColName, &numCols,colNums,colTypes,strSize) != TCL_OK ) { /* column name doesn't exist, add a new column*/ isNew = 1; } else if( numCols == 1 ) { isNew = 0; } else { Tcl_SetResult(curFile->interp, "Can only add one column at a time", TCL_STATIC); ckfree((char *) tmpColName); return TCL_ERROR; } ckfree((char *) tmpColName); /* Feb 2004, Ziqin Pan add */ if( argc >= 7 ) { numRange = fitsParseRangeNum(argv[6])+1; range = (int*) malloc(numRange*2*sizeof(int)); if ( fitsParseRange(argv[6],&numRange,range,numRange, 1, curFile->CHDUInfo.table.numRows,errMsg) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Error parsing row range:\n", TCL_STATIC); Tcl_AppendResult(curFile->interp, errMsg, (char*)NULL); return TCL_ERROR; } if ( fitsCalculaterngColumn(curFile, argv[3], ( strcmp(argv[4],"default") ? argv[4] : NULL ), argv[5],numRange,range) != TCL_OK ) { return TCL_ERROR; } } else { if ( fitsCalculateColumn(curFile, argv[3], ( strcmp(argv[4],"default") ? argv[4] : NULL ), argv[5]) != TCL_OK ) { return TCL_ERROR; } } sprintf(result,"%d",isNew); Tcl_SetResult(curFile->interp, result, TCL_VOLATILE); } else { Tcl_SetResult(curFile->interp, addColList, TCL_STATIC); return TCL_ERROR; } } else if( !strcmp(argv[2], "row") ) { int numRows; if( argc != 4 ) { Tcl_SetResult(curFile->interp, addRowList, TCL_STATIC); return TCL_ERROR; } if( Tcl_GetInt(curFile->interp, argv[3], &numRows) != TCL_OK) { Tcl_SetResult(curFile->interp, "Failed to get numRows parameter", TCL_STATIC); return TCL_ERROR; } if( addRowToTable(curFile, curFile->CHDUInfo.table.numRows, numRows) != TCL_OK ) { return TCL_ERROR; } } else { Tcl_SetResult(curFile->interp, "Unknown add command", TCL_STATIC); return TCL_ERROR; } if (range) free(range); return TCL_OK; } /****************************************************************** * Append ******************************************************************/ int fitsTcl_append( FitsFD *curFile, int argc, Tcl_Obj *const argv[] ) { static char *appendList = "\n" "append filename \n" " -- append the chdu to another file\n"; if( argc < 3 ) { Tcl_SetResult(curFile->interp, appendList, TCL_STATIC); return TCL_OK; } if( fitsAppendCHduToFile(curFile, Tcl_GetStringFromObj( argv[2], NULL ) ) != TCL_OK ) { return TCL_ERROR; } return TCL_OK; } /****************************************************************** * Histogram ******************************************************************/ int fitsTcl_histo( FitsFD *curFile, int argc, Tcl_Obj *const argv[] ) { static char *histoList = "\n" "histogram ?-weight w? ?-rows rowSpan? filename {col min max bin} ... \n"; int i, j, argNum, nRows; char *opt; int numRange, *range=NULL; char errMsg[256]; Tcl_Obj **binList; /* Args to ffhist */ fitsfile *fptr; char *outfile; int imagetype = TINT; int naxis; char colname[4][FLEN_VALUE]; double minin[4]; double maxin[4]; double binsizein[4]; char minname[4][FLEN_VALUE]; char maxname[4][FLEN_VALUE]; char binname[4][FLEN_VALUE]; double weightin; char wtcol[FLEN_VALUE]; int recip=0; char *selectrow=NULL; int status=0; if( argc == 2 ) { Tcl_SetResult(curFile->interp, histoList, TCL_STATIC); return TCL_OK; } if( curFile->hduType == IMAGE_HDU ) { Tcl_SetResult(curFile->interp, "Cannot histogram an image", TCL_STATIC); return TCL_ERROR; } /* Zero out all the parameters */ for( i=0; i<4; i++ ) { colname[i][0] = '\0'; minname[i][0] = '\0'; minin[i] = DOUBLENULLVALUE; maxname[i][0] = '\0'; maxin[i] = DOUBLENULLVALUE; binname[i][0] = '\0'; binsizein[i] = DOUBLENULLVALUE; } wtcol[0] = '\0'; /* Search for histogram options */ weightin = 1.0; nRows = curFile->CHDUInfo.table.numRows; argNum = 2; do { /* argc guaranteed to be at least 3 */ opt = Tcl_GetStringFromObj( argv[argNum++], NULL ); if( opt[0]!='-' ) break; if( !strcmp(opt,"-weight") ) { if( argNum == argc ) { Tcl_SetResult(curFile->interp, histoList, TCL_STATIC); if( selectrow ) ckfree( (char*)selectrow ); return TCL_ERROR; } if( Tcl_GetDoubleFromObj( curFile->interp, argv[argNum], &weightin ) != TCL_OK ) { strcpy( wtcol, Tcl_GetStringFromObj( argv[argNum], NULL ) ); } imagetype = TFLOAT; argNum++; } else if( !strcmp(opt,"-inverse") ) { recip = 1; } else if( !strcmp(opt,"-rows") ) { if( argNum == argc ) { Tcl_SetResult(curFile->interp, histoList, TCL_STATIC); if( selectrow ) ckfree( (char*)selectrow ); return TCL_ERROR; } opt = Tcl_GetStringFromObj( argv[argNum++], NULL ); numRange = fitsParseRangeNum(opt)+1; range = (int*) malloc(numRange*2*sizeof(int)); if( fitsParseRange( opt, &numRange, range, numRange, 1, nRows, errMsg) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Error parsing row range:\n", TCL_STATIC); Tcl_AppendResult(curFile->interp, errMsg, (char*)NULL); if( selectrow ) ckfree( (char*)selectrow ); return TCL_ERROR; } if( numRange>1 || range[0]!=1 || range[1]!=nRows ) { if( selectrow==NULL ) { selectrow = (char *)ckalloc( nRows * sizeof(char) ); if( !selectrow ) { Tcl_SetResult( curFile->interp, "Unable to allocate row-selection array", TCL_STATIC ); return TCL_ERROR; } for( i=0; i= argc ) { /* Need at least a filename parameter */ Tcl_SetResult( curFile->interp, histoList, TCL_STATIC ); if( selectrow ) ckfree( (char*)selectrow ); return TCL_ERROR; } } while( 1 ); /* Exit by one of breaks... found non option */ /* opt should be pointing to the file name */ outfile = opt; naxis = argc - argNum; if( naxis < 1 ) { if( selectrow ) ckfree( (char*)selectrow ); Tcl_SetResult( curFile->interp, "Missing binning arguments", TCL_STATIC ); return TCL_ERROR; } if( naxis > 4 ) { if( selectrow ) ckfree( (char*)selectrow ); Tcl_SetResult( curFile->interp, "Histograms are limited to 4 dimensions", TCL_STATIC ); return TCL_ERROR; } /* Parse each of the binning lists */ for( i=0; iinterp, argv[argNum], &j, &binList) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot parse the column binning parameters", TCL_STATIC); return TCL_ERROR; } if( j!=4 ) { if( selectrow ) ckfree( (char*)selectrow ); Tcl_SetResult( curFile->interp, "Binning list should be {colName min max binsize}", TCL_STATIC ); return TCL_ERROR; } /* Get column name */ opt = Tcl_GetStringFromObj( binList[0], &j ); if( jinterp, binList[1], minin+i ) != TCL_OK ) { opt = Tcl_GetStringFromObj( binList[1], &j ); if( strcmp(opt,"-") ) { /* Use supplied keyword name */ if( jinterp, binList[2], maxin+i ) != TCL_OK ) { opt = Tcl_GetStringFromObj( binList[2], &j ); if( strcmp(opt,"-") ) { /* Use supplied keyword name */ if( jinterp, binList[3], binsizein+i ) != TCL_OK ) { opt = Tcl_GetStringFromObj( binList[3], &j ); if( strcmp(opt,"-") ) { /* Use supplied keyword name */ if( jfptr, &fptr, &status ); ffmahd( fptr, curFile->chdu, &j, &status ); ffhist2( &fptr, outfile, imagetype, naxis, colname, minin, maxin, binsizein, minname, maxname, binname, weightin, wtcol, recip, selectrow, &status ); ffclos( fptr, &status ); if (range) free(range); if( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } Tcl_ResetResult(curFile->interp); return TCL_OK; } /****************************************************************** * Create ******************************************************************/ int fitsTcl_create( FitsFD *curFile, int argc, Tcl_Obj *const argv[] ) { static char *createList= "\n" "create 2dhisto filename {colList} {xmin xmax xbin} {ymin ymax ybin} ?rows?\n" " 1dhisto filename {colList} {xmin xmax xbin} ?row?\n" " (DEPRECATED) Use 'objName histogram' command instead\n"; Tcl_Obj *newCmd[10]; int newArgc, nelem, naxes, i; char *opt; if( argc == 2 ) { Tcl_SetResult(curFile->interp, createList, TCL_STATIC); return TCL_OK; } opt = Tcl_GetStringFromObj( argv[2], NULL ); if( !strcmp("dhisto", opt+1) ) { naxes = *opt - '0'; if( argc < 5 + naxes ) { Tcl_SetResult(curFile->interp, "Wrong # of args to 'create ndhisto'", TCL_STATIC); return TCL_ERROR; } newArgc=0; newCmd[newArgc++] = argv[0]; newCmd[newArgc++] = Tcl_NewStringObj("histogram",-1); /* Look for a row span */ if ( argc > 5 + naxes) { newCmd[newArgc++] = Tcl_NewStringObj("-rows",-1); newCmd[newArgc++] = argv[argc-1]; } /* Look for a weight argument */ Tcl_ListObjLength( curFile->interp, argv[4], &nelem ); if( nelemnaxes+1 ) { Tcl_SetResult(curFile->interp, "Need 2-3 columns to produce histogram", TCL_STATIC); return TCL_ERROR; } if( nelem==naxes+1 ) { newCmd[newArgc++] = Tcl_NewStringObj("-weight",-1); Tcl_ListObjIndex( curFile->interp, argv[4], naxes, newCmd+newArgc ); newArgc++; } /* Grab filename argument */ newCmd[newArgc++] = argv[3]; /* Build axes bin parameter */ for( i=0; iinterp, argv[5+i], &nelem ); if( nelem != 3 ) { Tcl_SetResult(curFile->interp, "Incorrect axis binning parameters", TCL_STATIC); return TCL_ERROR; } Tcl_ListObjIndex( curFile->interp, argv[4], i, newCmd+newArgc ); newCmd[newArgc] = Tcl_NewListObj(1,newCmd+newArgc); Tcl_ListObjAppendList( curFile->interp, newCmd[newArgc], argv[5+i] ); newArgc++; } if( fitsTcl_histo( curFile, newArgc, newCmd ) != TCL_OK ) { return TCL_ERROR; } } else { Tcl_SetResult(curFile->interp, "Unknown 'create' command", TCL_STATIC); return TCL_ERROR; } return TCL_OK; } /****************************************************************** * Checksum ******************************************************************/ int fitsTcl_checksum( FitsFD *curFile, int argc, Tcl_Obj *const argv[] ) { static char *checksumList="\n" "checksum verify\n" "checksum update\n"; char *opt; int datastatus = 0; int hdustatus = 0; int status = 0; if( argc < 3 ) { Tcl_SetResult(curFile->interp, checksumList, TCL_STATIC); return TCL_OK; } opt = Tcl_GetStringFromObj( argv[2], NULL ); if( !strcmp("verify", opt) ) { /* verify the checksum keyword. */ /* return 1 OK, 0 checksum keyword not present, -1 wrong */ if( ffvcks(curFile->fptr, &datastatus, &hdustatus, &status) ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } /* Return "minimum" checksum status */ Tcl_SetObjResult(curFile->interp, Tcl_NewIntObj( hdustatusfptr, &status) ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } if( fitsUpdateFile(curFile) != TCL_OK ) { return TCL_ERROR; } } else { Tcl_SetResult(curFile->interp, "Unknown checksum option", TCL_STATIC); return TCL_ERROR; } return TCL_OK; } /****************************************************************** * Smooth ******************************************************************/ int fitsTcl_smooth( FitsFD *curFile, int argc, Tcl_Obj *const argv[] ) { static char *smoothList= "\n" "smooth {width height} filename ?inPrimary? \n"; char *opt; int status = 0; int i,j,k,l; int xwin, ywin; Tcl_Obj **winList; int nwin,len; fitsfile *infptr; fitsfile *outfptr; int xd,yd; int xl,yl,xh,yh; char outfile[FLEN_FILENAME]; float *data; /* original data */ float *sdata; /* smoothed data */ int ndim; float nullval = -999; /* null value */ int anynul = 0 ; int id; float sum; int npix; int bitpix, naxis; int maxaxis = 4; long naxes[999]; int canprimary = 0; int hdunum; char strtemp[FLEN_FILENAME]; /* help */ if( argc == 2 ) { Tcl_SetResult(curFile->interp, smoothList, TCL_STATIC); return TCL_OK; } if( argc < 4 ) { Tcl_SetResult(curFile->interp, "Wrong # of args to 'smooth'", TCL_STATIC); return TCL_ERROR; } if( curFile->hduType != IMAGE_HDU ) { Tcl_SetResult(curFile->interp, "Cannot smooth a table", TCL_STATIC); return TCL_ERROR; } /* Get the width and height parameters */ if( Tcl_ListObjGetElements(curFile->interp, argv[2], &nwin, &winList) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot parse the window parameters", TCL_STATIC); return TCL_ERROR; } if( nwin!=2 ) { Tcl_SetResult( curFile->interp, "Window list should be {xwin ywin}", TCL_STATIC ); return TCL_ERROR; } /* Get the width/height parameters */ if( Tcl_GetIntFromObj( curFile->interp, winList[0], &xwin) != TCL_OK ) { Tcl_SetResult( curFile->interp, "Error reading the width parameter", TCL_STATIC ); return TCL_ERROR; } if (xwin%2 == 0) { Tcl_SetResult( curFile->interp, "The width must be a odd number", TCL_STATIC ); return TCL_ERROR; } if( Tcl_GetIntFromObj( curFile->interp, winList[1], &ywin) != TCL_OK ) { Tcl_SetResult( curFile->interp, "Error reading the height parameter", TCL_STATIC ); return TCL_ERROR; } if (ywin%2 == 0) { Tcl_SetResult( curFile->interp, "The height must be a odd number", TCL_STATIC ); return TCL_ERROR; } /* Get the image output file name */ opt = Tcl_GetStringFromObj( argv[3], NULL ); len = strlen(opt); if( len < FLEN_FILENAME ) { strcpy(outfile, opt ); } else { Tcl_SetResult( curFile->interp, "The length of filename is too long. ", TCL_STATIC ); return TCL_ERROR; } if( argc == 5 ) { if ( Tcl_GetBooleanFromObj( curFile->interp, argv[4], &canprimary ) != TCL_OK ) return TCL_ERROR; } /* open the input file */ ffreopen( curFile->fptr, &infptr, &status ); ffmahd( infptr, curFile->chdu, &j, &status ); /*get the image parameter */ ffgipr(infptr, maxaxis, &bitpix, &naxis, naxes, &status); if (naxis < 2 ) { Tcl_SetResult( curFile->interp, "The smooth algorithm only supports 2-d images.", TCL_STATIC ); return TCL_ERROR; } for (i = 2; i < naxis; i++) { if (naxes[i] > 1 ) { Tcl_SetResult( curFile->interp, "The smooth algorithm only supports 2-d images.", TCL_STATIC ); return TCL_ERROR; } } ndim = (int)(naxes[0]*naxes[1]); data = (float *) ckalloc(ndim*sizeof(float )); sdata = (float *) ckalloc(ndim*sizeof(float )); ffgpv(infptr,TFLOAT,1, naxes[0]*naxes[1],&nullval, data, &anynul, &status); xd = xwin / 2; yd = ywin / 2; /* iterate over y */ yl = 0; yh = yd; for (i=0; i < naxes[1]; i++) { /* initialize the kernal for this row */ sum = 0; npix = 0; xl = 0; xh = xd; for (k = yl; k <= yh; k++) { for ( l = xl; l <= xh; l++) { id = k * naxes[0] + l; if(data[id]!=nullval) { npix++; sum += data[id]; } } } /* iterate over x */ for (j = 0; j < naxes[0]; j++) { id = i*naxes[0]+j; if(npix == 0) { sdata[id] = nullval; } else { sdata[id] = sum/(float )npix; } /* increase the x by 1 */ if(j - xl == xd ) { for ( k = yl; k <= yh; k++) { id = k*naxes[0]+xl; if(data[id]!=nullval) { npix--; sum -= data[id]; } } xl++; } if(xh + 1< naxes[0] ) { xh++; for ( k = yl; k <= yh; k++) { id = k*naxes[0]+xh; if(data[id]!=nullval) { npix++; sum += data[id]; } } } } /* increase the y by 1 */ if (i - yl == yd ) yl++; if (yh + 1 < naxes[1]) yh++; } /* open the output file */ ffopen(&outfptr, outfile,READWRITE, &status); if(status == FILE_NOT_OPENED) { status = 0; ffinit(&outfptr,outfile,&status); if(!canprimary) ffcrim(outfptr,FLOAT_IMG,0,NULL,&status); } else if (status) { strcpy(strtemp,"Error opening output file: "); strcat(strtemp,curFile->fileName); Tcl_SetResult( curFile->interp, strtemp, TCL_STATIC ); return TCL_ERROR; } /* ffcrim(outfptr,FLOAT_IMG, naxis, naxes, &status); */ ffcphd(infptr,outfptr,&status); /* Update keywords */ ffghdn(outfptr, &hdunum); i = FLOAT_IMG; ffuky(outfptr,TINT, "BITPIX",&i, NULL, &status); ffpky(outfptr,TINT, "XWIN",&xwin,"x-width of the smoothing window", &status); ffpky(outfptr,TINT, "YWIN",&ywin,"y-width of the smoothing window", &status); strcpy(strtemp,"Smoothed output of the image file: "); strcat(strtemp,curFile->fileName); ffpcom(outfptr,strtemp, &status); /* write data*/ ffppn(outfptr,TFLOAT,1,naxes[0]*naxes[1],sdata,&nullval,&status); ckfree(data); ckfree(sdata); /* close file */ ffclos(infptr,&status); ffclos(outfptr,&status); return TCL_OK; } fitsTcl-2.5/fitsIO.c0000644000220700000360000063023413133202233013125 0ustar birbylhea/* * fitsIO.c -- * * This is the file-handling routines which use CFITSIO * */ /* *------------------------------------------------------------ * * MODIFICATION HISTORY: * 2004-02-06 Ziqin Pan: * Added the following routines: * 1. fitsSelectRowsExpr * 2. fitsCalculaterngColumn * 3. fitsDeleteRowsRange * 4. fitsDeleteRowlist * Updated the following routines: * 1. fitsSortTable: * return a list of row index which represents * pre-sorted table row * * */ #include "fitsTclInt.h" #include /* on some systems, e.g. linux, SUNs DBL_MAX is in float.h */ #ifndef DBL_MAX # include #endif #ifndef DBL_MIN # include #endif /* ------------------------------------------------------------ * * fitsMoveHDU -- * * Given a FitsHD, move nmove. * If direction = 1, move forward * = -1, move backwards * = 0, move absolute * If there is an error, then exit with status != 0 * (>0 => FITSIO err stat...) * * Results: * Alters the CHDU * * Side Effects: * None * * ------------------------------------------------------------ */ int fitsMoveHDU( FitsFD *curFile, int nmove, int direction ) { if( fitsJustMoveHDU(curFile, nmove, direction) != TCL_OK ) { return TCL_ERROR; } if( fitsLoadHDU(curFile) != TCL_OK ) { return TCL_ERROR; } return TCL_OK; } /************************************************************** * load the table and the rest **************************************************************/ int fitsLoadHDU( FitsFD *curFile ) { int i,status=0; int simple,extend; long pcount, gcount, rowlen; LONGLONG tbcol[FITS_COLMAX], varidat; char tmpStr[80]; char tmpKey[FLEN_KEYWORD]; Tcl_HashEntry *thisEntry; Keyword *tmpKwd; char testChar[1024]; char numChar[1024]; char *p, *n; long len; /* Now get the Header info for the CHDU */ switch( curFile->hduType ) { case IMAGE_HDU: ffghprll(curFile->fptr, FITS_MAXDIMS, &simple, &curFile->CHDUInfo.image.bitpix, &curFile->CHDUInfo.image.naxes, curFile->CHDUInfo.image.naxisn, &pcount, &gcount, &extend, &status); strcpy(curFile->extname ,"Image"); break; case ASCII_TBL: ffghtbll(curFile->fptr, FITS_COLMAX, &curFile->CHDUInfo.table.rowLen, &curFile->CHDUInfo.table.numRows, &curFile->CHDUInfo.table.numCols, curFile->CHDUInfo.table.colName, tbcol, curFile->CHDUInfo.table.colType, curFile->CHDUInfo.table.colUnit, curFile->extname, &status); break; case BINARY_TBL: ffghbnll(curFile->fptr, FITS_COLMAX, &curFile->CHDUInfo.table.numRows, &curFile->CHDUInfo.table.numCols, curFile->CHDUInfo.table.colName, curFile->CHDUInfo.table.colType, curFile->CHDUInfo.table.colUnit, curFile->extname, &varidat, &status); ffgkyj(curFile->fptr,"NAXIS1",&rowlen, NULL,&status); curFile->CHDUInfo.table.rowLen = rowlen; break; default: sprintf(tmpStr, "Unrecognized Extension type: %d", curFile->hduType); Tcl_SetResult(curFile->interp, tmpStr, TCL_VOLATILE); return TCL_ERROR; } /* Now LOAD the kwds hash table... */ if( TCL_OK != fitsLoadKwds(curFile) ) { fitsCloseFile((ClientData) curFile); return TCL_ERROR; } /* * Also, search BZERO and BSCALE from keyword hash table for speed */ if ( IMAGE_HDU == curFile->hduType ) { thisEntry = Tcl_FindHashEntry(curFile->kwds, "BZERO"); if ( NULL == thisEntry ) { curFile->CHDUInfo.image.bzero = 0.0; curFile->CHDUInfo.image.bzflag = 0; } else { tmpKwd = (Keyword *) Tcl_GetHashValue(thisEntry); curFile->CHDUInfo.image.bzero = atof( tmpKwd->value ); curFile->CHDUInfo.image.bzflag = 1; } thisEntry = Tcl_FindHashEntry(curFile->kwds, "BSCALE"); if ( NULL == thisEntry ) { curFile->CHDUInfo.image.bscale = 1.0; curFile->CHDUInfo.image.bsflag = 0; } else if (status == 0) { tmpKwd = (Keyword *) Tcl_GetHashValue(thisEntry); curFile->CHDUInfo.image.bscale = atof( tmpKwd->value ); curFile->CHDUInfo.image.bsflag = 1; } thisEntry = Tcl_FindHashEntry(curFile->kwds, "BLANK"); if ( NULL == thisEntry ) { strcpy(curFile->CHDUInfo.image.blank, " "); } else if (status == 0) { tmpKwd = (Keyword *) Tcl_GetHashValue(thisEntry); strcpy(curFile->CHDUInfo.image.blank, tmpKwd->value); } } else { /* Table */ for (i=0; i < curFile->CHDUInfo.table.numCols; i++) { sprintf(tmpKey,"TZERO%d",i+1); thisEntry = Tcl_FindHashEntry(curFile->kwds, tmpKey); if ( thisEntry == NULL ) { curFile->CHDUInfo.table.colTzero[i] = 0.0; curFile->CHDUInfo.table.colTzflag[i] = 0; } else { tmpKwd = (Keyword *) Tcl_GetHashValue(thisEntry); curFile->CHDUInfo.table.colTzero[i] = atof(tmpKwd->value); curFile->CHDUInfo.table.colTzflag[i] = 1; } sprintf(tmpKey,"TSCAL%d",i+1); thisEntry = Tcl_FindHashEntry(curFile->kwds, tmpKey); if ( thisEntry == NULL ) { curFile->CHDUInfo.table.colTscale[i] = 1.0; curFile->CHDUInfo.table.colTsflag[i] = 0; } else { tmpKwd = (Keyword *) Tcl_GetHashValue(thisEntry); curFile->CHDUInfo.table.colTscale[i] = atof(tmpKwd->value ); curFile->CHDUInfo.table.colTsflag[i] = 1; } sprintf(tmpKey,"TDISP%d",i+1); thisEntry = Tcl_FindHashEntry(curFile->kwds, tmpKey); if ( thisEntry == NULL ) { strcpy(curFile->CHDUInfo.table.colDisp[i], " "); } else { tmpKwd = (Keyword *) Tcl_GetHashValue(thisEntry); strcpy(curFile->CHDUInfo.table.colDisp[i], tmpKwd->value); } sprintf(tmpKey,"TNULL%d",i+1); thisEntry = Tcl_FindHashEntry(curFile->kwds, tmpKey); if ( thisEntry == NULL ) { strcpy(curFile->CHDUInfo.table.colNull[i], "NULL"); } else { tmpKwd = (Keyword *) Tcl_GetHashValue(thisEntry); strcpy(curFile->CHDUInfo.table.colNull[i], tmpKwd->value); } } } /* Finally fill the dataType with the translation of the TTYPE keywords... * and set the variable traces on the columns... */ if( IMAGE_HDU == curFile->hduType ) { switch ( curFile->CHDUInfo.image.bitpix ) { case 8: curFile->CHDUInfo.image.dataType = TBYTE; break; case 16: curFile->CHDUInfo.image.dataType = TSHORT; break; case 32: curFile->CHDUInfo.image.dataType = TINT; break; case 64: /* 11/01/2006: added to handle 64 bits fits file */ curFile->CHDUInfo.image.dataType = TLONGLONG; break; case -32: curFile->CHDUInfo.image.dataType = TFLOAT; break; case -64: curFile->CHDUInfo.image.dataType = TDOUBLE; break; default: Tcl_SetResult(curFile->interp, "fitsTcl Error: unknown image type", TCL_STATIC); return TCL_ERROR; break; } /* if BSCALE or BZERO exists, set type to double */ if( curFile->CHDUInfo.image.bzflag || curFile->CHDUInfo.image.bsflag ) { curFile->CHDUInfo.image.dataType = TDOUBLE; } } else { /* Table */ for (i = 0; i < curFile->CHDUInfo.table.numCols; i++ ) { /* judging for TDISP or TTYPE, load the column width and display format */ if ( TCL_ERROR == tdispGetFormat(curFile, i) ) { return TCL_ERROR; } /* See if it's a vector column */ if (BINARY_TBL == curFile->hduType) { if (strchr(curFile->CHDUInfo.table.colType[i],'P')) { /* need to find the vector size */ curFile->CHDUInfo.table.vecSize[i] = -1; p = strchr(curFile->CHDUInfo.table.colType[i],'P'); strcpy(testChar, p); /* find the number after xPA(nnnnnnn) */ n = strpbrk(testChar, "0123456789"); if ( n != (char *)NULL ) { len = strspn(n, "0123456789"); memset (numChar, '\0', 1024); strncpy(numChar, n, len); sscanf (numChar, "%ld", &(curFile->CHDUInfo.table.vecSize[i])); } else { curFile->CHDUInfo.table.vecSize[i] = -1; } } else { int status = 0; int typecode = 0; long repeat = 0; long width = 0; /* use CFITSIO to get column dimension */ fits_get_coltype(curFile->fptr, i+1, &typecode, &repeat, &width, &status); curFile->CHDUInfo.table.vecSize[i] = 1; if (repeat > 1) { if (typecode == TSTRING) { curFile->CHDUInfo.table.vecSize[i] = repeat / width; } else { curFile->CHDUInfo.table.vecSize[i] = repeat; } } } } else { curFile->CHDUInfo.table.vecSize[i] = 1; } /* init colMin and colMax */ curFile->CHDUInfo.table.colMin[i] = DBL_MIN; curFile->CHDUInfo.table.colMax[i] = DBL_MAX; /* * Now ascertain the colDataType */ if ( strchr(curFile->CHDUInfo.table.colType[i],'A')) { curFile->CHDUInfo.table.colDataType[i] = TSTRING; } else if (strchr(curFile->CHDUInfo.table.colType[i],'I')) { if( curFile->CHDUInfo.table.colTzflag[i] || curFile->CHDUInfo.table.colTsflag[i] ) { curFile->CHDUInfo.table.colDataType[i] = TDOUBLE; } else { /* in an ASCII table, an integer could be a long int */ if ( curFile->hduType == ASCII_TBL ) { curFile->CHDUInfo.table.colDataType[i] = TLONG; } else { curFile->CHDUInfo.table.colDataType[i] = TSHORT; } } } else if ( strchr(curFile->CHDUInfo.table.colType[i],'K')) { if( curFile->CHDUInfo.table.colTzflag[i] || curFile->CHDUInfo.table.colTsflag[i] ) { curFile->CHDUInfo.table.colDataType[i] = TDOUBLE; } else { curFile->CHDUInfo.table.colDataType[i] = TLONGLONG; } } else if ( strchr(curFile->CHDUInfo.table.colType[i],'J')) { if( curFile->CHDUInfo.table.colTzflag[i] || curFile->CHDUInfo.table.colTsflag[i] ) { curFile->CHDUInfo.table.colDataType[i] = TDOUBLE; } else { curFile->CHDUInfo.table.colDataType[i] = TLONG; } } else if ( strchr(curFile->CHDUInfo.table.colType[i],'X')) { curFile->CHDUInfo.table.colDataType[i] = TBIT; } else if ( strchr(curFile->CHDUInfo.table.colType[i],'L')) { curFile->CHDUInfo.table.colDataType[i] = TLOGICAL; } else if ( strchr(curFile->CHDUInfo.table.colType[i],'B')){ if( curFile->CHDUInfo.table.colTzflag[i] || curFile->CHDUInfo.table.colTsflag[i] ) { curFile->CHDUInfo.table.colDataType[i] = TDOUBLE; } else { curFile->CHDUInfo.table.colDataType[i] = TBYTE; } } else if ( strchr(curFile->CHDUInfo.table.colType[i],'E') || strchr(curFile->CHDUInfo.table.colType[i],'F') ) { /* in an ASCII table , a float could be a double */ if ( curFile->hduType == ASCII_TBL ) { curFile->CHDUInfo.table.colDataType[i] = TDOUBLE; } else { curFile->CHDUInfo.table.colDataType[i] = TFLOAT; } } else if ( strchr(curFile->CHDUInfo.table.colType[i],'D')){ curFile->CHDUInfo.table.colDataType[i] = TDOUBLE; } else if ( strchr(curFile->CHDUInfo.table.colType[i],'C')){ curFile->CHDUInfo.table.colDataType[i] = TCOMPLEX; } else if ( strchr(curFile->CHDUInfo.table.colType[i],'M')){ curFile->CHDUInfo.table.colDataType[i] = TDBLCOMPLEX; } else { Tcl_ResetResult(curFile->interp); Tcl_AppendResult(curFile->interp, "Unknown or unsupported TFORM: ", curFile->CHDUInfo.table.colType[i], " for column ", curFile->CHDUInfo.table.colName[i], (char*)NULL); return TCL_ERROR; } /* * Now ascertain the default strSize's of the column * (Use minimum of 4 to handle "NULL" values) */ if( curFile->hduType == BINARY_TBL ) { switch( curFile->CHDUInfo.table.colDataType[i] ) { case TSTRING: /* If it's a variable size vector, it's format could be 1PA, but it takes more than 1 */ if( strchr(curFile->CHDUInfo.table.colType[i],'P') ) { p = strchr(curFile->CHDUInfo.table.colType[i],'P'); strcpy(testChar, p); /* find the number after xPA(nnnnnnn) */ n = strpbrk(testChar, "0123456789"); if ( n != (char *)NULL ) { len = strspn(n, "0123456789"); memset (numChar, '\0', 1024); strncpy(numChar, n, len); sscanf (numChar, "%d", &(curFile->CHDUInfo.table.strSize[i])); } else { curFile->CHDUInfo.table.strSize[i] = 80; } } else { sscanf(curFile->CHDUInfo.table.colType[i], "%dA",&(curFile->CHDUInfo.table.strSize[i])); if( curFile->CHDUInfo.table.strSize[i] < 4 ) curFile->CHDUInfo.table.strSize[i] = 4; } break; case TLOGICAL: curFile->CHDUInfo.table.strSize[i] = 4; break; case TBIT: curFile->CHDUInfo.table.strSize[i] = 4; break; case TBYTE: curFile->CHDUInfo.table.strSize[i] = 4; break; case TSHORT: curFile->CHDUInfo.table.strSize[i] = 8; break; case TINT: curFile->CHDUInfo.table.strSize[i] = 12; break; case TLONG: curFile->CHDUInfo.table.strSize[i] = 16; break; case TFLOAT: curFile->CHDUInfo.table.strSize[i] = 16; break; case TLONGLONG: curFile->CHDUInfo.table.strSize[i] = 24; break; case TDOUBLE: curFile->CHDUInfo.table.strSize[i] = 24; break; case TCOMPLEX: curFile->CHDUInfo.table.strSize[i] = 36; break; case TDBLCOMPLEX: curFile->CHDUInfo.table.strSize[i] = 52; break; default: curFile->CHDUInfo.table.strSize[i] = 24; break; } } else { /* ASCII Table... Use actual column width */ if( i+1 < curFile->CHDUInfo.table.numCols ) curFile->CHDUInfo.table.strSize[i] = tbcol[i+1] - tbcol[i]; else curFile->CHDUInfo.table.strSize[i] = curFile->CHDUInfo.table.rowLen - tbcol[i] + 1; if( curFile->CHDUInfo.table.strSize[i] < 4 ) curFile->CHDUInfo.table.strSize[i] = 4; } } } /* now set the hdu status */ curFile->CHDUInfo.table.loadStatus = 1; return TCL_OK; } /* just move the keyword and clean up all the data struct */ int fitsJustMoveHDU( FitsFD *curFile, int nmove, int direction ) { int status=0; int newHduType; char errMsg[80]; /* move to the right hdu */ if ( 1 == direction || -1 == direction ) { ffmrhd(curFile->fptr,nmove,&newHduType,&status); } else { ffmahd(curFile->fptr,nmove,&newHduType,&status); } if ( curFile->CHDUInfo.table.loadStatus > 0 ) { /* clean up the old keywords hash table in the old header */ if ( fitsFlushKeywords(curFile) ) { Tcl_SetResult(curFile->interp, "Error dumping altered keywords, proceed with caution", TCL_STATIC); } } if( status ) { dumpFitsErrStack(curFile->interp,status); return TCL_ERROR; } /* Should check here to see if you need to expand the column info blocks... */ if( newHduType != IMAGE_HDU ) { if( curFile->CHDUInfo.table.numCols > FITS_COLMAX ) { sprintf(errMsg,"Too many columns in Fits file, MAX is %d", FITS_COLMAX); Tcl_SetResult(curFile->interp, errMsg, TCL_VOLATILE); return TCL_ERROR; } } if( fitsUpdateCHDU(curFile, newHduType) != TCL_OK ) { Tcl_SetResult(curFile->interp, "fitsTcl Error: Cannot update CHDU", TCL_STATIC); return TCL_ERROR; } return TCL_OK; } /* * Update the CHDU */ int fitsUpdateCHDU( FitsFD *curFile, int newHduType) { /* * Allocate space for the new CHDUInfo */ if(makeNewCHDUInfo(curFile,newHduType) != TCL_OK ) { return TCL_ERROR; } /* reset the load status */ curFile->CHDUInfo.table.loadStatus = 0; /* Reset the CHDU field */ ffghdn(curFile->fptr,&curFile->chdu); return TCL_OK; } /* * ------------------------------------------------------------ * * fitsLoadKwds -- * * Loads the keywords from a FitsFD struct. * * Results: * Creates the Hash Table... curFile->kwds * * Side Effects: * None * * ------------------------------------------------------------ * */ int fitsLoadKwds( FitsFD *curFile ) { int status=0,i,new,nkwds; Keyword *newKwd; Tcl_HashEntry *newEntry; Tcl_HashSearch search; FitsCardList *comCard,*hisCard; char Comment[FLEN_COMMENT], Name[FLEN_KEYWORD], Value[FLEN_VALUE]; /* Delete the previous hash Table */ newEntry = Tcl_FirstHashEntry(curFile->kwds,&search); while ( NULL != newEntry ) { ckfree((char *) Tcl_GetHashValue(newEntry)); Tcl_DeleteHashEntry(newEntry); newEntry = Tcl_NextHashEntry(&search); } /* Now load the Current one */ if( curFile->CHDUInfo.table.loadStatus != 1 ) curFile->CHDUInfo.table.loadStatus = 2; curFile->numCom = 0; curFile->numHis = 0; hisCard = curFile->hisHead; comCard = curFile->comHead; ffghsp(curFile->fptr,&nkwds,&i,&status); if ( status ) { dumpFitsErrStack(curFile->interp,status); return TCL_ERROR; } for (i = 1;i <= nkwds; i++ ) { ffgkyn( curFile->fptr, i, Name, Value, Comment, &status); if( status ) { dumpFitsErrStack(curFile->interp,status); return TCL_ERROR; } if( !strcmp(Name,"HISTORY") ) { if (hisCard->next == NULL ) { hisCard->next = (FitsCardList *) ckalloc( sizeof (FitsCardList)); if ( hisCard->next == NULL ) { Tcl_SetResult(curFile->interp, "Error mallocing space for history card\n", TCL_STATIC); fitsCloseFile((ClientData)curFile); return TCL_ERROR; } hisCard = hisCard->next; hisCard->next = (FitsCardList *) NULL; hisCard->pos = i; strcpy(hisCard->value,Comment); } else { hisCard = hisCard->next; hisCard->pos = i; strcpy(hisCard->value,Comment); } curFile->numHis++; } else if( !strcmp(Name,"COMMENT") ) { if (comCard->next == NULL ) { comCard->next = (FitsCardList *) ckalloc( sizeof (FitsCardList)); if ( comCard->next == NULL ) { Tcl_SetResult(curFile->interp, "Error mallocing space for comment card\n", TCL_STATIC); fitsCloseFile((ClientData)curFile); return TCL_ERROR; } comCard = comCard->next; comCard->next = (FitsCardList *) NULL; comCard->pos = i; strcpy(comCard->value,Comment); } else { comCard = comCard->next; comCard->pos = i; strcpy(comCard->value,Comment); } curFile->numCom++; } else if( !strcmp(Name, "CONTINUE" ) ) { } else if( !strcmp(Name, "REFERENC" ) ) { } else if( !strcmp(Name,"") ) { } else { newEntry = Tcl_CreateHashEntry(curFile->kwds,Name,&new); newKwd = (Keyword *) ckalloc(sizeof(Keyword)); strcpy(newKwd->name,Name); strcpy(newKwd->value,Value); strcpy(newKwd->comment,Comment); newKwd->pos = i; Tcl_SetHashValue(newEntry,(ClientData) newKwd); } } curFile->numKwds = i; /* * Now clean up the remaining comment and history records... */ deleteFitsCardList(comCard); deleteFitsCardList(hisCard); return TCL_OK; } /* * ------------------------------------------------------------ * * deleteFitsCardList -- * * Takes an element in a Fits Card list, and deletes the rest of the list * From this element on. * * Results: * Kills the rest of the string, and sets the next of comCard to NULL. * * Side Effects: * None * * ------------------------------------------------------------ * */ void deleteFitsCardList( FitsCardList *comCard ) { FitsCardList *tmpCard1,*tmpCard2; tmpCard1 = comCard->next; comCard->next = (FitsCardList *) NULL; while ( tmpCard1 ) { tmpCard2 = tmpCard1->next; ckfree( (char*)tmpCard1 ); tmpCard1 = tmpCard2; } return; } /* * ------------------------------------------------------------ * * fitsDumpHeader -- * * Dump the header into a list of strings * * Results: * Returns the result * * Side Effects: * None * * ------------------------------------------------------------ * */ int fitsDumpHeader( FitsFD *curFile ) { int status,i,nkwds; char record[FLEN_CARD]; status = 0; ffghsp(curFile->fptr,&nkwds,&i,&status); for ( i = 1; i <= nkwds ; i++) { if( ffgrec(curFile->fptr,i,record,&status) ) { sprintf(record,"Error dumping header: card #%d\n",i); Tcl_SetResult(curFile->interp,record,TCL_VOLATILE); dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } Tcl_AppendElement(curFile->interp,record); } return TCL_OK; } /* * ------------------------------------------------------------ * * fitsDumpHeaderToKV -- * * Dump the header into a list of keyword and a list to value * * Results: * Returns the result * * Side Effects: * None * * ------------------------------------------------------------ * */ int fitsDumpHeaderToKV( FitsFD *curFile ) { int status,i,nkwds; char key[FLEN_KEYWORD]; char val[FLEN_VALUE]; char com[FLEN_COMMENT]; Tcl_DString kList; Tcl_DString vList; Tcl_DString cList; Tcl_DString theList; Tcl_DStringInit(&theList); Tcl_DStringInit(&kList); Tcl_DStringInit(&vList); Tcl_DStringInit(&cList); status = 0; ffghsp(curFile->fptr, &nkwds, &i, &status); for ( i = 1; i <= nkwds ; i++) { if( ffgkyn( curFile->fptr, i, key, val, com, &status) ) { sprintf(key,"Error dumping header: card #%d\n",i); Tcl_SetResult(curFile->interp, key, TCL_VOLATILE); dumpFitsErrStack(curFile->interp, status); Tcl_DStringFree(&kList); Tcl_DStringFree(&vList); Tcl_DStringFree(&cList); return TCL_ERROR; } Tcl_DStringAppendElement(&kList, key); Tcl_DStringAppendElement(&vList, val); Tcl_DStringAppendElement(&cList, com); } Tcl_DStringAppendElement(&theList, Tcl_DStringValue(&kList)); Tcl_DStringAppendElement(&theList, Tcl_DStringValue(&vList)); Tcl_DStringAppendElement(&theList, Tcl_DStringValue(&cList)); Tcl_DStringFree(&kList); Tcl_DStringFree(&vList); Tcl_DStringFree(&cList); Tcl_DStringResult(curFile->interp, &theList); return TCL_OK; } /* * Just dump the keywords to a TCL list */ int fitsDumpKwdsToList( FitsFD *curFile ) { int status; int i,nkwds; char key[FLEN_KEYWORD]; char val[FLEN_VALUE]; Tcl_DString kList; Tcl_DStringInit(&kList); status = 0; ffghsp(curFile->fptr,&nkwds,&i,&status); for ( i = 1; i <= nkwds ; i++) { if( ffgkyn( curFile->fptr, i, key, val, NULL, &status) ) { sprintf(val,"Error dumping header: card #%d\n",i); Tcl_SetResult(curFile->interp, val, TCL_VOLATILE); dumpFitsErrStack(curFile->interp, status); Tcl_DStringFree(&kList); return TCL_ERROR; } Tcl_DStringAppendElement(&kList, key); } Tcl_DStringResult(curFile->interp, &kList); return TCL_OK; } /* * ------------------------------------------------------------ * * fitsDumpHeaderToCard -- * * Dump the header into a list of keyword ended with a new line * * Results: * Returns the result * * Side Effects: * None * * ------------------------------------------------------------ * */ int fitsDumpHeaderToCard( FitsFD *curFile ) { int status,i,nkwds; char record[FLEN_CARD+1]; Tcl_DString theList; Tcl_DStringInit(&theList); status = 0; ffghsp(curFile->fptr,&nkwds,&i,&status); for ( i = 1; i <= nkwds ; i++ ) { if( ffgrec(curFile->fptr, i, record, &status) ) { sprintf(record,"Error dumping header: card #%d\n",i); Tcl_SetResult(curFile->interp, record, TCL_VOLATILE); dumpFitsErrStack(curFile->interp, status); Tcl_DStringFree(&theList); return TCL_ERROR; } strcat(record, "\n"); Tcl_DStringAppend(&theList, record, -1); } Tcl_DStringResult(curFile->interp, &theList); return TCL_OK; } /* * ------------------------------------------------------------ * * makeNewCHDUInfo-- * * This removes the current CHDU structure and replaces it with one * suitable for an extension of type newHduType. Returns TCL_OK for * success. If the old CHDUInfo is of the same type as newHduType, * just return. * * Results: * Deallocates the memory for the previous header type, allocates memory * for the new type. * * Side Effects: * None * * ------------------------------------------------------------ */ int makeNewCHDUInfo( FitsFD *curFile, int newHduType ) { /* * If the new and old files have the same HDUTYPE, no need to do anything */ if(curFile->hduType == newHduType ) { return TCL_OK; /* * If going from IMAGE to anything, wipe all the space, and start over: * If going from nothing to BINARY or ASCII, skip the freeing: */ } else if ( curFile->hduType == IMAGE_HDU || (curFile->hduType == NOHDU && newHduType != IMAGE_HDU)) { /* * First release the space from the previous header... */ if( curFile->hduType != NOHDU ) { freeCHDUInfo(curFile); } curFile->CHDUInfo.table.colName = (char **) makeContigArray(FITS_COLMAX,FLEN_VALUE,'c'); if( NULL == curFile->CHDUInfo.table.colName ) { Tcl_SetResult(curFile->interp, "Error malloc'ing space for colName", TCL_STATIC); return TCL_ERROR; } curFile->CHDUInfo.table.colType = (char **) makeContigArray(FITS_COLMAX,FLEN_VALUE,'c'); if( NULL == curFile->CHDUInfo.table.colType ) { Tcl_SetResult(curFile->interp, "Error malloc'ing space for colType", TCL_STATIC); return TCL_ERROR; } curFile->CHDUInfo.table.colDataType = (int *) makeContigArray(FITS_COLMAX,1,'i'); if( NULL == curFile->CHDUInfo.table.colDataType ) { Tcl_SetResult(curFile->interp, "Error malloc'ing space for colDataType", TCL_STATIC); return TCL_ERROR; } curFile->CHDUInfo.table.colWidth = (int *) makeContigArray(FITS_COLMAX,1,'i'); if( NULL == curFile->CHDUInfo.table.colWidth ) { Tcl_SetResult(curFile->interp, "Error malloc'ing space for colWidth", TCL_STATIC); return TCL_ERROR; } curFile->CHDUInfo.table.colUnit = (char **) makeContigArray(FITS_COLMAX,FLEN_VALUE,'c'); if( NULL == curFile->CHDUInfo.table.colUnit ) { Tcl_SetResult(curFile->interp, "Error malloc'ing space for colUnit", TCL_STATIC); return TCL_ERROR; } curFile->CHDUInfo.table.colFormat = (char **) makeContigArray(FITS_COLMAX,FLEN_VALUE,'c'); if( NULL == curFile->CHDUInfo.table.colFormat ) { Tcl_SetResult(curFile->interp, "Error malloc'ing space for colFormat", TCL_STATIC); return TCL_ERROR; } curFile->CHDUInfo.table.colDisp = (char **) makeContigArray(FITS_COLMAX,FLEN_VALUE,'c'); if( NULL == curFile->CHDUInfo.table.colDisp ) { Tcl_SetResult(curFile->interp, "Error malloc'ing space for colDisp", TCL_STATIC); return TCL_ERROR; } curFile->CHDUInfo.table.colNull = (char **) makeContigArray(FITS_COLMAX,FLEN_VALUE,'c'); if( NULL == curFile->CHDUInfo.table.colNull ) { Tcl_SetResult(curFile->interp, "Error malloc'ing space for colNull", TCL_STATIC); return TCL_ERROR; } curFile->CHDUInfo.table.vecSize = (long *) makeContigArray(FITS_COLMAX,1,'l'); if( NULL == curFile->CHDUInfo.table.vecSize ) { Tcl_SetResult(curFile->interp, "Error malloc'ing space for vecSize", TCL_STATIC); return TCL_ERROR; } curFile->CHDUInfo.table.vecDim = (long *) makeContigArray(FITS_COLMAX,1,'l'); if( NULL == curFile->CHDUInfo.table.vecDim) { Tcl_SetResult(curFile->interp, "Error malloc'ing space for vecDim", TCL_STATIC); return TCL_ERROR; } curFile->CHDUInfo.table.colTscale = (double *) makeContigArray(FITS_COLMAX,1,'d'); if( NULL == curFile->CHDUInfo.table.colTscale ) { Tcl_SetResult(curFile->interp, "Error malloc'ing space for colTscale", TCL_STATIC); return TCL_ERROR; } curFile->CHDUInfo.table.colTzero = (double *) makeContigArray(FITS_COLMAX,1,'d'); if( NULL == curFile->CHDUInfo.table.colTzero ) { Tcl_SetResult(curFile->interp, "Error malloc'ing space for colTzero", TCL_STATIC); return TCL_ERROR; } curFile->CHDUInfo.table.colTzflag = (int *) makeContigArray(FITS_COLMAX,1,'i'); if( NULL == curFile->CHDUInfo.table.colTzflag ) { Tcl_SetResult(curFile->interp, "Error malloc'ing space for colTzflag", TCL_STATIC); return TCL_ERROR; } curFile->CHDUInfo.table.colTsflag = (int *) makeContigArray(FITS_COLMAX,1,'i'); if( NULL == curFile->CHDUInfo.table.colTsflag ) { Tcl_SetResult(curFile->interp, "Error malloc'ing space for colTsflag", TCL_STATIC); return TCL_ERROR; } curFile->CHDUInfo.table.colMin = (double *) makeContigArray(FITS_COLMAX,1,'d'); if( NULL == curFile->CHDUInfo.table.colMin ) { Tcl_SetResult(curFile->interp, "Error malloc'ing space for colMin", TCL_STATIC); return TCL_ERROR; } curFile->CHDUInfo.table.colMax = (double *) makeContigArray(FITS_COLMAX,1,'d'); if( NULL == curFile->CHDUInfo.table.colMax ) { Tcl_SetResult(curFile->interp, "Error malloc'ing space for colMax", TCL_STATIC); return TCL_ERROR; } curFile->CHDUInfo.table.strSize = (int *) makeContigArray(FITS_COLMAX,1,'i'); if( NULL == curFile->CHDUInfo.table.strSize ) { Tcl_SetResult(curFile->interp, "Error malloc'ing space for strSize", TCL_STATIC); return TCL_ERROR; } /* * If you are going to Image HDU, then also wipe everything, * and start over: */ } else if ( newHduType == IMAGE_HDU ) { if (curFile->hduType != NOHDU ) { freeCHDUInfo(curFile); } curFile->CHDUInfo.image.naxisn = (long long *) makeContigArray(FITS_MAXDIMS,1,'l'); if( NULL == curFile->CHDUInfo.image.naxisn ) { Tcl_SetResult(curFile->interp, "Error malloc'ing space for naxisn", TCL_STATIC); return TCL_ERROR; } curFile->CHDUInfo.image.axisUnit = (char **) makeContigArray(FITS_MAXDIMS,FLEN_VALUE,'c'); if( NULL == curFile->CHDUInfo.image.axisUnit ) { Tcl_SetResult(curFile->interp, "Error malloc'ing space for axisUnit", TCL_STATIC); return TCL_ERROR; } } else if ( newHduType == ASCII_TBL || newHduType == BINARY_TBL ) { /* Do Nothing */ } else { Tcl_SetResult(curFile->interp, "In makeNewCHDUInfo - You should not get here...", TCL_STATIC); return TCL_ERROR; } curFile->hduType = newHduType; return TCL_OK; } /* * ------------------------------------------------------------ * * freeCHDUInfo -- * * This removes the current CHDU structure * * Results: * Deallocates the memory for the previous header type. * * Side Effects: * None * * ------------------------------------------------------------ */ int freeCHDUInfo( FitsFD * curFile ) { if (curFile->hduType == IMAGE_HDU ) { ckfree((char *) curFile->CHDUInfo.image.naxisn); ckfree((char *) curFile->CHDUInfo.image.axisUnit[0]); ckfree((char *) curFile->CHDUInfo.image.axisUnit); } else if (curFile->hduType == ASCII_TBL || curFile->hduType == BINARY_TBL) { ckfree((char *) curFile->CHDUInfo.table.colName[0]); ckfree((char *) curFile->CHDUInfo.table.colType[0]); ckfree((char *) curFile->CHDUInfo.table.colUnit[0]); ckfree((char *) curFile->CHDUInfo.table.colDisp[0]); ckfree((char *) curFile->CHDUInfo.table.colNull[0]); ckfree((char *) curFile->CHDUInfo.table.colFormat[0]); ckfree((char *) curFile->CHDUInfo.table.colDataType); ckfree((char *) curFile->CHDUInfo.table.colWidth); ckfree((char *) curFile->CHDUInfo.table.colName); ckfree((char *) curFile->CHDUInfo.table.colUnit); ckfree((char *) curFile->CHDUInfo.table.colType); ckfree((char *) curFile->CHDUInfo.table.colDisp); ckfree((char *) curFile->CHDUInfo.table.colNull); ckfree((char *) curFile->CHDUInfo.table.vecSize); ckfree((char *) curFile->CHDUInfo.table.vecDim); ckfree((char *) curFile->CHDUInfo.table.colFormat); ckfree((char *) curFile->CHDUInfo.table.colMin); ckfree((char *) curFile->CHDUInfo.table.colMax); ckfree((char *) curFile->CHDUInfo.table.colTzero); ckfree((char *) curFile->CHDUInfo.table.colTscale); ckfree((char *) curFile->CHDUInfo.table.colTzflag); ckfree((char *) curFile->CHDUInfo.table.colTsflag); ckfree((char *) curFile->CHDUInfo.table.strSize); } else { char errMsg[80]; sprintf(errMsg,"Unknown HDU Type: %d\n",curFile->hduType); Tcl_SetResult(curFile->interp,errMsg,TCL_VOLATILE); return TCL_ERROR; } return TCL_OK; } int imageRowsMeanToPtr( FitsFD *curFile, long fRow, long lRow, long slice ) { long fCol = 1; long nRows; long nCols; void *databuffer; int dataType; int dataLength; long tmpL; int i,j, offset; unsigned char *byteData; short *shortData; int *intData; float *floatData; float *floatBack; double *dblData; double *dblBack; LONGLONG *longlongData; LONGLONG *longlongBack; void *backPtr; char result[80]; nCols = curFile->CHDUInfo.image.naxisn[0]; if ( fRow > lRow) { tmpL = lRow; lRow = fRow; fRow = tmpL; } if( fRow < 1 ) fRow = 1; if( lRow < 1 ) lRow = 1; if( curFile->CHDUInfo.image.naxes == 1 ) { nRows = 1; } else { nRows = curFile->CHDUInfo.image.naxisn[1]; } if( lRow > nRows ) lRow = nRows; if( fRow > nRows ) fRow = nRows; nRows = lRow - fRow + 1; if ( TCL_OK != imageBlockLoad(curFile,"",fRow,nRows,fCol,nCols,slice,1) ) { return TCL_ERROR; } sscanf( Tcl_GetStringResult(curFile->interp), PTRFORMAT " %d %d", &databuffer, &dataType, &dataLength); Tcl_ResetResult(curFile->interp); if ( dataLength != nRows*nCols ) { ckfree( (char*)databuffer ); Tcl_SetResult(curFile->interp, "fitsTcl Error: data lengths don't match", TCL_STATIC); return TCL_ERROR; } switch( dataType ) { case BYTE_DATA: byteData = (unsigned char *) databuffer; floatBack = (float *) ckalloc( nCols * sizeof(float) ); for (i=0; i< nCols; i++ ) { floatBack[i] = 0.0; for ( j=0; j < nRows; j++) { offset = i + j*nCols; floatBack[i] += byteData[offset]; } floatBack[i] /= nRows; } backPtr = floatBack; sprintf(result, PTRFORMAT " %d %ld", backPtr, FLOAT_DATA, nCols); break; case SHORTINT_DATA: shortData = (short *) databuffer; floatBack = (float *) ckalloc( nCols * sizeof(float) ); for (i=0; i< nCols; i++ ) { floatBack[i] = 0.0; for ( j=0; j < nRows; j++) { offset = i + j*nCols; floatBack[i] += shortData[offset]; } floatBack[i] /= nRows; } backPtr = floatBack; sprintf(result, PTRFORMAT " %d %ld", backPtr, FLOAT_DATA, nCols); break; case INT_DATA: intData = (int *) databuffer; floatBack = (float *) ckalloc( nCols * sizeof(float) ); for (i=0; i< nCols; i++ ) { floatBack[i] = 0.0; for ( j=0; j < nRows; j++) { offset = i + j*nCols; floatBack[i] += intData[offset]; } floatBack[i] /= nRows; } backPtr = floatBack; sprintf(result, PTRFORMAT " %d %ld", backPtr, FLOAT_DATA, nCols); break; case FLOAT_DATA: floatData = (float *) databuffer; floatBack = (float *) ckalloc( nCols * sizeof(float) ); for (i=0; i< nCols; i++ ) { floatBack[i] = 0.0; for ( j=0; j < nRows; j++) { offset = i + j*nCols; floatBack[i] += floatData[offset]; } floatBack[i] /= nRows; } backPtr = floatBack; sprintf(result, PTRFORMAT " %d %ld", backPtr, FLOAT_DATA, nCols); break; case DOUBLE_DATA: dblData = (double *) databuffer; dblBack = (double *) ckalloc( nCols * sizeof(double) ); for (i=0; i< nCols; i++ ) { dblBack[i] = 0.0; for ( j=0; j < nRows; j++) { offset = i + j*nCols; dblBack[i] += dblData[offset]; } dblBack[i] /= nRows; } backPtr = dblBack; sprintf(result, PTRFORMAT " %d %ld", backPtr, DOUBLE_DATA, nCols); break; case LONGLONG_DATA: longlongData = (LONGLONG *) databuffer; longlongBack = (LONGLONG *) ckalloc( nCols * sizeof(LONGLONG) ); for (i=0; i< nCols; i++ ) { longlongBack[i] = 0; for ( j=0; j < nRows; j++) { offset = i + j*nCols; longlongBack[i] += longlongData[offset]; } longlongBack[i] /= nRows; } backPtr = longlongBack; sprintf(result, PTRFORMAT " %d %ld", backPtr, LONGLONG_DATA, nCols); break; default: ckfree((char *) databuffer); Tcl_SetResult(curFile->interp, "fitsTcl Error:unknown data type in irows", TCL_STATIC); return TCL_ERROR; } ckfree((char *) databuffer); Tcl_SetResult(curFile->interp,result,TCL_VOLATILE); return TCL_OK; } int imageColsMeanToPtr( FitsFD *curFile, long fCol, long lCol, long slice ) { long fRow = 1; long nRows; long nCols; void *databuffer; int dataType; int dataLength; long tmpL; int i,j, offset; unsigned char *byteData; short *shortData; int *intData; float *floatData; float *floatBack; double *dblData; double *dblBack; LONGLONG *longlongData; LONGLONG *longlongBack; void *backPtr; char result[80]; if( curFile->CHDUInfo.image.naxes == 1 ) nRows = 1; else nRows = curFile->CHDUInfo.image.naxisn[1]; if ( fCol > lCol) { tmpL = lCol; lCol = fCol; fCol = tmpL; } if (fCol < 1) fCol = 1; if ( lCol > curFile->CHDUInfo.image.naxisn[0]) lCol = curFile->CHDUInfo.image.naxisn[0]; nCols = lCol-fCol + 1; if ( TCL_OK != imageBlockLoad(curFile,"",fRow,nRows,fCol,nCols,slice,1) ) { return TCL_ERROR; } sscanf( Tcl_GetStringResult(curFile->interp), PTRFORMAT " %d %d", &databuffer, &dataType, &dataLength); Tcl_ResetResult(curFile->interp); if ( dataLength != nRows*nCols ) { ckfree( (char*) databuffer ); Tcl_SetResult(curFile->interp, "fitsTcl Error: data lengths don't match", TCL_STATIC); return TCL_ERROR; } switch (dataType) { case BYTE_DATA: byteData = (unsigned char *) databuffer; floatBack = (float *) ckalloc( nRows * sizeof(float)); for (i=0; i< nRows; i++ ) { floatBack[i] = 0.0; for ( j=0; j < nCols; j++) { offset = j + i*nCols; floatBack[i] += byteData[offset]; } floatBack[i] /= nCols; } backPtr = floatBack; sprintf(result, PTRFORMAT " %d %ld", backPtr, FLOAT_DATA, nRows); break; case SHORTINT_DATA: shortData = (short *) databuffer; floatBack = (float *) ckalloc( nRows * sizeof(float) ); for (i=0; i< nRows; i++ ) { floatBack[i] = 0.0; for ( j=0; j < nCols; j++) { offset = j + i*nCols; floatBack[i] += shortData[offset]; } floatBack[i] /= nCols; } backPtr = floatBack; sprintf(result, PTRFORMAT " %d %ld", backPtr, FLOAT_DATA, nRows); break; case INT_DATA: intData = (int *) databuffer; floatBack = (float *) ckalloc( nRows * sizeof(float) ); for (i=0; i< nRows; i++ ) { floatBack[i] = 0.0; for ( j=0; j < nCols; j++) { offset = j + i*nCols; floatBack[i] += intData[offset]; } floatBack[i] /= nCols; } backPtr = floatBack; sprintf(result, PTRFORMAT " %d %ld", backPtr, FLOAT_DATA, nRows); break; case FLOAT_DATA: floatData = (float *) databuffer; floatBack = (float *) ckalloc( nRows * sizeof(float) ); for (i=0; i< nRows; i++ ) { floatBack[i] = 0.0; for ( j=0; j < nCols; j++) { offset = j + i*nCols; floatBack[i] += floatData[offset]; } floatBack[i] /= nCols; } backPtr = floatBack; sprintf(result, PTRFORMAT " %d %ld", backPtr, FLOAT_DATA, nRows); break; case DOUBLE_DATA: dblData = (double *) databuffer; dblBack = (double *) ckalloc( nRows * sizeof(double) ); for (i=0; i< nRows; i++ ) { dblBack[i] = 0.0; for ( j=0; j < nCols; j++) { offset = j + i*nCols; dblBack[i] += dblData[offset]; } dblBack[i] /= nCols; } backPtr = dblBack; sprintf(result, PTRFORMAT " %d %ld", backPtr, DOUBLE_DATA, nRows); break; case LONGLONG_DATA: longlongData = (LONGLONG *) databuffer; longlongBack = (LONGLONG *) ckalloc( nRows * sizeof(LONGLONG) ); for (i=0; i< nRows; i++ ) { longlongBack[i] = 0; for ( j=0; j < nCols; j++) { offset = j + i*nCols; longlongBack[i] += longlongData[offset]; } longlongBack[i] /= nCols; } backPtr = longlongBack; sprintf(result, PTRFORMAT " %d %ld", backPtr, LONGLONG_DATA, nCols); break; default: ckfree((char *) databuffer); Tcl_SetResult(curFile->interp, "fitsTcl Error: unknown data type in irows", TCL_STATIC); return TCL_ERROR; } ckfree((char *) databuffer); Tcl_SetResult(curFile->interp,result,TCL_VOLATILE); return TCL_OK; } /* * imageBlockLoad_1D * assign a block of the image data to varName variable or return a pointer */ int imageBlockLoad_1D( FitsFD *curFile, long fElem, long nElem ) { long i; int anyNul, status; char *nullArray, tmpStr[80]; void *imgData; Tcl_Obj *valObj, *nullObj, *listObj; listObj = Tcl_NewObj(); nullObj = Tcl_NewStringObj( "NULL", -1 ); status = 0; nullArray = (char *) ckalloc(nElem*sizeof(char)); switch ( curFile->CHDUInfo.image.dataType ) { case TDOUBLE: case TFLOAT: imgData = (double *) ckalloc(nElem*sizeof(double)); ffgpfd(curFile->fptr, 1, fElem, nElem, imgData, nullArray, &anyNul, &status); if ( status > 0 ) { Tcl_SetResult(curFile->interp,"Error reading image\n",TCL_VOLATILE); dumpFitsErrStack(curFile->interp,status); ckfree( (char *) imgData ); ckfree( (char *) nullArray ); return TCL_ERROR; } for ( i=0; i< nElem; i++ ) { if ( nullArray[i] ) { valObj = nullObj; } else { valObj = Tcl_NewDoubleObj( ((double*)imgData)[i] ); } Tcl_ListObjAppendElement( curFile->interp, listObj, valObj ); } break; case TLONGLONG: imgData = (LONGLONG *) ckalloc(nElem*sizeof(LONGLONG)); ffgpfjj(curFile->fptr, 1, fElem, nElem, imgData, nullArray, &anyNul, &status); if ( status > 0 ) { Tcl_SetResult(curFile->interp,"Error reading image\n",TCL_VOLATILE); dumpFitsErrStack(curFile->interp,status); ckfree( (char *) imgData ); ckfree( (char *) nullArray ); return TCL_ERROR; } for ( i=0; i< nElem; i++ ) { if ( nullArray[i] ) { valObj = nullObj; } else { #ifdef __WIN32__ sprintf(tmpStr, "%I64d", ((LONGLONG *)imgData)[i]); #else sprintf(tmpStr, "%lld", ((LONGLONG *)imgData)[i]); #endif valObj = Tcl_NewStringObj( tmpStr, -1 ); } Tcl_ListObjAppendElement( curFile->interp, listObj, valObj ); } break; case TLONG: case TINT: case TSHORT: case TBYTE: imgData = (long *) ckalloc(nElem*sizeof(long)); ffgpfj(curFile->fptr, 1, fElem, nElem, imgData, nullArray, &anyNul, &status); if ( status > 0 ) { Tcl_SetResult(curFile->interp,"Error reading image\n",TCL_VOLATILE); dumpFitsErrStack(curFile->interp,status); ckfree( (char *) imgData ); ckfree( (char *) nullArray ); return TCL_ERROR; } for ( i=0; i< nElem; i++ ) { if ( nullArray[i] ) { valObj = nullObj; } else { valObj = Tcl_NewLongObj( ((long*)imgData)[i] ); } Tcl_ListObjAppendElement( curFile->interp, listObj, valObj ); } break; default: Tcl_SetResult(curFile->interp, "Unknown image type", TCL_STATIC); ckfree( (char *) nullArray ); return TCL_ERROR; } ckfree( (char *) imgData ); ckfree( (char *) nullArray); Tcl_SetObjResult(curFile->interp,listObj); return TCL_OK; } /* * imageBlockLoad * assign a block of the image data to varName variable or return a pointer */ int imageBlockLoad( FitsFD *curFile, char *varName, LONGLONG fRow, LONGLONG nRow, LONGLONG fCol, LONGLONG nCol, long slice, long cslice) { unsigned char *byteData; short *shortData; int *intData; float *floatData; double *dblData; LONGLONG *longlongData; char *nullArray; int ptrFlag, status; LONGLONG tmpIndex; int i,j; char tmpStr[80]; char varIndex[80]; int anyNul; LONGLONG blc[FITS_MAXDIMS], trc[FITS_MAXDIMS]; long blc_l[FITS_MAXDIMS], trc_l[FITS_MAXDIMS]; long incrc[FITS_MAXDIMS]; int naxes, flip=0; LONGLONG xDim, yDim; char result[80]; Tcl_Obj *valObj; long naxisn[9]; naxes = curFile->CHDUInfo.image.naxes; for (i=0; i< curFile->CHDUInfo.image.naxes; i++) { naxisn[i] = (long) curFile->CHDUInfo.image.naxisn[i]; } /* if( naxes > 3 ) { for (i = 3; i < naxes; i++) { if (curFile->CHDUInfo.image.naxisn[i] != 1) { Tcl_SetResult(curFile->interp, "Can only read L X M X N X 1 ... images", TCL_STATIC); return TCL_ERROR; } } } */ if( naxes > FITS_MAXDIMS ) { sprintf(result,"Image exceeds %d dimensions", FITS_MAXDIMS); Tcl_SetResult(curFile->interp, result, TCL_VOLATILE); return TCL_ERROR; } xDim = naxisn[0]; if( naxes>1 ) { yDim = naxisn[1]; } else { yDim = 1; if( (fCol>1 && fRow>1) || (nRow>1 && nCol>1) ) { Tcl_SetResult(curFile->interp, "Cannot read 2D block from a 1D image", TCL_STATIC); return TCL_ERROR; } if( fRow>2 || nRow>2 ) { /* Interpret 1D image as a column */ flip = 1; yDim = xDim; xDim = 1; } } if ( fRow+nRow-1 > yDim ) { nRow = yDim - fRow +1; } if ( fCol+nCol-1 > xDim ) { nCol = xDim - fCol +1; } for (i=0; i < naxes; i++) { blc[i] = 1; trc[i] = 1; incrc[i] = 1; blc_l[i] = (long) blc[i]; trc_l[i] = (long) trc[i]; } if( flip ) { blc[0] = fRow; trc[0] = fRow+nRow-1; incrc[0] = 1; } else { blc[0] = fCol; trc[0] = fCol+nCol-1; incrc[0] = 1; } blc_l[0] = (long) blc[0]; trc_l[0] = (long) trc[0]; if( naxes>1 ) { if( flip ) { blc[1] = fCol; trc[1] = fCol+nCol-1; incrc[1] = 1; } else { blc[1] = fRow; trc[1] = fRow+nRow-1; incrc[1] = 1; } /* blc[1] = fRow; trc[1] = fRow+nRow-1; incrc[1] = 1; */ blc_l[1] = (long) blc[1]; trc_l[1] = (long) trc[1]; if( naxes>2 ) { blc[2] = slice; trc[2] = slice; incrc[2] = 1; blc_l[2] = (long) blc[2]; trc_l[2] = (long) trc[2]; if ( cslice > 1 ) { blc[3] = cslice; trc[3] = cslice; incrc[i] = 1; blc_l[3] = (long) blc[2]; trc_l[3] = (long) trc[2]; } } } if( varName[0] == '\0' ) { ptrFlag=1; } else { ptrFlag=0; } status = 0; nullArray = (char *) ckalloc(nCol*nRow*sizeof(char)); switch ( curFile->CHDUInfo.image.dataType ) { case TDOUBLE: dblData = (double *) ckalloc(nCol*nRow*sizeof(double)); memset (dblData, 0, nCol*nRow*sizeof(double)); ffgsfd(curFile->fptr, 1, curFile->CHDUInfo.image.naxes, naxisn, blc_l, trc_l, incrc, dblData, nullArray, &anyNul, &status); if ( status > 0 ) { Tcl_SetResult(curFile->interp,"Error reading image\n",TCL_VOLATILE); dumpFitsErrStack(curFile->interp,status); ckfree( (char *) dblData ); ckfree( (char *) nullArray ); return TCL_ERROR; } if( ptrFlag ) { #ifdef __WIN32__ sprintf(result, PTRFORMAT " %d %I64d", dblData, 4, nCol*nRow); #else sprintf(result, PTRFORMAT " %d %lld", dblData, 4, nCol*nRow); #endif Tcl_SetResult(curFile->interp,result,TCL_VOLATILE); } else { for ( i=0; i< nCol; i++ ) { for ( j=0; j< nRow; j++ ) { tmpIndex = j*nCol + i; #ifdef __WIN32__ sprintf(varIndex,"%I64d,%I64d", fCol+i-1, fRow+j-1); #else sprintf(varIndex,"%lld,%lld", fCol+i-1, fRow+j-1); #endif if ( nullArray[tmpIndex] ) { valObj = Tcl_NewStringObj("NULL",-1); } else { valObj = Tcl_NewDoubleObj( dblData[tmpIndex] ); } Tcl_SetVar2Ex(curFile->interp, varName, varIndex, valObj, 0); } } ckfree( (char *) dblData); } break; case TLONGLONG: longlongData = (LONGLONG *) ckalloc(nCol*nRow*sizeof(LONGLONG)); memset (longlongData, 0, nCol*nRow*sizeof(LONGLONG)); ffgsfjj(curFile->fptr, 1, curFile->CHDUInfo.image.naxes, naxisn, blc_l, trc_l, incrc, longlongData, nullArray, &anyNul, &status); if ( status > 0 ) { Tcl_SetResult(curFile->interp,"Error reading image\n",TCL_VOLATILE); dumpFitsErrStack(curFile->interp,status); ckfree( (char *) longlongData ); ckfree( (char *) nullArray ); return TCL_ERROR; } if( ptrFlag ) { #ifdef __WIN32__ sprintf(result, PTRFORMAT " %d %I64d", longlongData, 4, nCol*nRow); #else sprintf(result, PTRFORMAT " %d %lld", longlongData, 4, nCol*nRow); #endif Tcl_SetResult(curFile->interp,result,TCL_VOLATILE); } else { for ( i=0; i< nCol; i++ ) { for ( j=0; j< nRow; j++ ) { tmpIndex = j*nCol + i; #ifdef __WIN32__ sprintf(varIndex,"%I64d,%I64d", fCol+i-1, fRow+j-1); #else sprintf(varIndex,"%lld,%lld", fCol+i-1, fRow+j-1); #endif if ( nullArray[tmpIndex] ) { valObj = Tcl_NewStringObj("NULL",-1); } else { #ifdef __WIN32__ sprintf(tmpStr, "%I64d", longlongData[tmpIndex]); #else sprintf(tmpStr, "%lld", longlongData[tmpIndex]); #endif valObj = Tcl_NewStringObj( tmpStr, -1 ); } Tcl_SetVar2Ex(curFile->interp, varName, varIndex, valObj, 0); } } ckfree( (char *) longlongData); } break; case TFLOAT: floatData = (float *) ckalloc(nCol*nRow*sizeof(float)); memset (floatData, 0, nCol*nRow*sizeof(float)); ffgsfe(curFile->fptr, 1, curFile->CHDUInfo.image.naxes, naxisn, blc_l, trc_l, incrc, floatData, nullArray, &anyNul, &status); if ( status > 0 ) { Tcl_SetResult(curFile->interp,"Error reading image\n",TCL_VOLATILE); dumpFitsErrStack(curFile->interp,status); ckfree( (char *) floatData ); ckfree( (char *) nullArray ); return TCL_ERROR; } if( ptrFlag ) { #ifdef __WIN32__ sprintf(result, PTRFORMAT " %d %I64d", floatData, 3, nCol*nRow); #else sprintf(result, PTRFORMAT " %d %lld", floatData, 3, nCol*nRow); #endif Tcl_SetResult(curFile->interp,result,TCL_VOLATILE); } else { for ( i=0; i< nCol; i++ ) { for ( j=0; j< nRow; j++ ) { tmpIndex = j*nCol + i; #ifdef __WIN32__ sprintf(varIndex,"%I64d,%I64d", fCol+i-1, fRow+j-1); #else sprintf(varIndex,"%lld,%lld", fCol+i-1, fRow+j-1); #endif if ( nullArray[tmpIndex] ) { valObj = Tcl_NewStringObj("NULL",-1); } else { valObj = Tcl_NewDoubleObj( (double)floatData[tmpIndex] ); /* sprintf(tmpStr,"%#.5f", floatData[tmpIndex]); */ } Tcl_SetVar2Ex(curFile->interp, varName, varIndex, valObj, 0); } } ckfree( (char *) floatData); } break; case TLONG: case TINT: intData = (int *) ckalloc(nRow*nCol*sizeof(int)); memset (intData, 0, nCol*nRow*sizeof(int)); ffgsfk(curFile->fptr, 1, curFile->CHDUInfo.image.naxes, naxisn, blc_l, trc_l, incrc, intData, nullArray, &anyNul, &status); if ( status > 0 ) { Tcl_SetResult(curFile->interp,"Error reading image\n",TCL_VOLATILE); dumpFitsErrStack(curFile->interp,status); ckfree( (char *) intData ); ckfree( (char *) nullArray ); return TCL_ERROR; } if( ptrFlag ) { #ifdef __WIN32__ sprintf(result, PTRFORMAT " %d %I64d", intData, 2, nCol*nRow); #else sprintf(result, PTRFORMAT " %d %lld", intData, 2, nCol*nRow); #endif Tcl_SetResult(curFile->interp,result,TCL_VOLATILE); } else { for ( i=0; i< nCol; i++ ) { for ( j=0; j< nRow; j++ ) { tmpIndex = j*nCol + i; #ifdef __WIN32__ sprintf(varIndex,"%I64d,%I64d", fCol+i-1, fRow+j-1); #else sprintf(varIndex,"%lld,%lld", fCol+i-1, fRow+j-1); #endif if ( nullArray[tmpIndex] ) { valObj = Tcl_NewStringObj("NULL",-1); } else { valObj = Tcl_NewLongObj( (long)intData[tmpIndex] ); /* sprintf(tmpStr,"%d", intData[tmpIndex]); */ } Tcl_SetVar2Ex(curFile->interp, varName, varIndex, valObj, 0); } } ckfree( (char *) intData); } break; case TSHORT: shortData = (short *) ckalloc(nCol*nRow*sizeof(short)); memset (shortData, 0, nCol*nRow*sizeof(short)); ffgsfi(curFile->fptr, 1, curFile->CHDUInfo.image.naxes, naxisn, blc_l, trc_l, incrc, shortData, nullArray, &anyNul, &status); if ( status > 0 ) { Tcl_SetResult(curFile->interp,"Error reading image\n",TCL_VOLATILE); dumpFitsErrStack(curFile->interp,status); ckfree( (char *) shortData ); ckfree( (char *) nullArray ); return TCL_ERROR; } if( ptrFlag ) { #ifdef __WIN32__ sprintf(result, PTRFORMAT " %d %I64d", shortData, 1, nCol*nRow); #else sprintf(result, PTRFORMAT " %d %lld", shortData, 1, nCol*nRow); #endif Tcl_SetResult(curFile->interp,result,TCL_VOLATILE); } else { for ( i=0; i< nCol; i++ ) { for ( j=0; j< nRow; j++ ) { tmpIndex = j*nCol + i; #ifdef __WIN32__ sprintf(varIndex,"%I64d,%I64d", fCol+i-1, fRow+j-1); #else sprintf(varIndex,"%lld,%lld", fCol+i-1, fRow+j-1); #endif if ( nullArray[tmpIndex] ) { valObj = Tcl_NewStringObj("NULL",-1); } else { valObj = Tcl_NewLongObj( (long)shortData[tmpIndex] ); /* sprintf(tmpStr,"%d", shortData[tmpIndex]); */ } Tcl_SetVar2Ex(curFile->interp, varName, varIndex, valObj, 0); } } ckfree( (char *) shortData); } break; case TBYTE: byteData = (unsigned char *) ckalloc(nCol*nRow*sizeof(unsigned char)); memset (byteData, 0, nCol*nRow*sizeof(unsigned char)); ffgsfb(curFile->fptr, 1, curFile->CHDUInfo.image.naxes, naxisn, blc_l, trc_l, incrc, byteData, nullArray, &anyNul, &status); if ( status > 0 ) { Tcl_SetResult(curFile->interp,"Error reading image\n",TCL_VOLATILE); dumpFitsErrStack(curFile->interp,status); ckfree( (char *) byteData ); ckfree( (char *) nullArray ); return TCL_ERROR; } if( ptrFlag ) { #ifdef __WIN32__ sprintf(result, PTRFORMAT " %d %I64d", byteData, 0, nCol*nRow); #else sprintf(result, PTRFORMAT " %d %lld", byteData, 0, nCol*nRow); #endif Tcl_SetResult(curFile->interp,result,TCL_VOLATILE); } else { for ( i=0; i< nCol; i++ ) { for ( j=0; j< nRow; j++ ) { tmpIndex = j*nCol + i; #ifdef __WIN32__ sprintf(varIndex,"%I64d,%I64d", fCol+i-1, fRow+j-1); #else sprintf(varIndex,"%lld,%lld", fCol+i-1, fRow+j-1); #endif if ( nullArray[tmpIndex] ) { valObj = Tcl_NewStringObj("NULL",-1); } else { valObj = Tcl_NewLongObj( (long)byteData[tmpIndex] ); /* sprintf(tmpStr,"%u", byteData[tmpIndex]); */ } Tcl_SetVar2Ex(curFile->interp, varName, varIndex, valObj, 0); } } ckfree( (char *) byteData); } break; default: Tcl_SetResult(curFile->interp, "Unknown image type", TCL_STATIC); ckfree( (char *) nullArray ); return TCL_ERROR; } ckfree( (char *) nullArray ); return TCL_OK; } /* * imageGetToPtr */ int imageGetToPtr( FitsFD *curFile, long slice, int rotate ) { void *backPtr; long i, j; int anynul, status=0; double *dblValArray; double *dblTmpArray; LONGLONG *longlongValArray; LONGLONG *longlongTmpArray; float *floatValArray; float *floatTmpArray; short *shortValArray; short *shortTmpArray; int *intValArray; int *intTmpArray; unsigned char *byteValArray; unsigned char *byteTmpArray; char result[80]; long tmpIndex; long offset; long naxis1, naxis2, felem, nelem; naxis1 = curFile->CHDUInfo.image.naxisn[0]; naxis2 = curFile->CHDUInfo.image.naxisn[1]; if( curFile->CHDUInfo.image.naxes==1 || naxis2 < 1 ) naxis2 = 1; nelem = naxis1 * naxis2; felem = (slice-1) * nelem + 1; switch ( curFile->CHDUInfo.image.dataType ) { case TDOUBLE: dblValArray = (double *) ckalloc( nelem*sizeof(double) ); ffgpvd(curFile->fptr, 1L, felem, nelem, DBL_MAX, dblValArray, &anynul, &status); if( status ) { Tcl_SetResult(curFile->interp, "fitsTcl Error: Cannot get image", TCL_STATIC); dumpFitsErrStack( curFile->interp, status ); ckfree((char *) dblValArray); return TCL_ERROR; } if (rotate == 0) { backPtr = dblValArray; } else { dblTmpArray = (double *) ckalloc( nelem*sizeof(double) ); for (i=0; i < naxis1; i ++) { for (j=0; j < naxis2; j ++) { tmpIndex = j*naxis1 + i; switch (rotate) { case 1: /* 90 degree */ offset = (i+1)*naxis2 -j-1; break; case 2: offset = (naxis2-j-1)*naxis1 +(naxis1-i-1); break; case 3: offset = (naxis1-i-1)*naxis2 + j; break; default: offset = tmpIndex; break; } dblTmpArray[offset] = dblValArray[tmpIndex]; } } ckfree ((char *) dblValArray); backPtr = dblTmpArray; } break; case TLONGLONG: longlongValArray = (LONGLONG *) ckalloc( nelem*sizeof(LONGLONG) ); ffgpvjj(curFile->fptr, 1L, felem, nelem, (LONGLONG)NULL, longlongValArray, &anynul, &status); if( status ) { Tcl_SetResult(curFile->interp, "fitsTcl Error: Cannot get image", TCL_STATIC); dumpFitsErrStack( curFile->interp, status ); ckfree((char *) longlongValArray); return TCL_ERROR; } if (rotate == 0) { backPtr = longlongValArray; } else { longlongTmpArray = (LONGLONG *) ckalloc( nelem*sizeof(LONGLONG) ); for (i=0; i < naxis1; i ++) { for (j=0; j < naxis2; j ++) { tmpIndex = j*naxis1 + i; switch (rotate) { case 1: /* 90 degree */ offset = (i+1)*naxis2 -j-1; break; case 2: offset = (naxis2-j-1)*naxis1 +(naxis1-i-1); break; case 3: offset = (naxis1-i-1)*naxis2 + j; break; default: offset = tmpIndex; break; } longlongTmpArray[offset] = longlongValArray[tmpIndex]; } } ckfree ((char *) longlongValArray); backPtr = longlongTmpArray; } break; case TFLOAT: floatValArray = (float *) ckalloc( nelem*sizeof(float) ); ffgpve(curFile->fptr, 1L, felem, nelem, FLT_MAX, floatValArray, &anynul, &status); if ( status ) { Tcl_SetResult(curFile->interp, "fitsTcl Error: Cannot get image", TCL_STATIC); dumpFitsErrStack(curFile->interp, status); ckfree((char *) floatValArray); return TCL_ERROR; } if (rotate == 0) { backPtr = floatValArray; } else { floatTmpArray = (float *) ckalloc( nelem*sizeof(float) ); for (i=0; i < naxis1; i ++) { for (j=0; j < naxis2; j ++) { tmpIndex = j*naxis1 + i; switch (rotate) { case 1: /* 90 degree */ offset = (i+1)*naxis2 -j-1; break; case 2: offset = (naxis2-j-1)*naxis1 +(naxis1-i-1); break; case 3: offset = (naxis1-i-1)*naxis2 + j; break; default: offset = tmpIndex; break; } floatTmpArray[offset] = floatValArray[tmpIndex]; } } ckfree ((char *) floatValArray); backPtr = floatTmpArray; } break; case TINT: intValArray = (int *) ckalloc( nelem*sizeof(int) ); ffgpvk(curFile->fptr, 1L, felem, nelem, INT_MAX, intValArray, &anynul, &status); if ( status ) { Tcl_SetResult(curFile->interp, "fitsTcl Error: Cannot get image", TCL_STATIC); dumpFitsErrStack(curFile->interp, status); ckfree((char *) intValArray); return TCL_ERROR; } if (rotate == 0) { backPtr = intValArray; } else { intTmpArray = (int *) ckalloc(nelem*sizeof(int) ); for (i=0; i < naxis1; i ++) { for (j=0; j < naxis2; j ++) { tmpIndex = j*naxis1 + i; switch (rotate) { case 1: /* 90 degree */ offset = (i+1)*naxis2 -j-1; break; case 2: offset = (naxis2-j-1)*naxis1 +(naxis1-i-1); break; case 3: offset = (naxis1-i-1)*naxis2 + j; break; default: offset = tmpIndex; break; } intTmpArray[offset] = intValArray[tmpIndex]; } } ckfree ((char *) intValArray); backPtr = intTmpArray; } break; case TSHORT: shortValArray = (short *) ckalloc( nelem*sizeof(short) ); ffgpvi(curFile->fptr, 1L, felem, nelem, SHRT_MAX, shortValArray, &anynul, &status); if ( status ) { Tcl_SetResult(curFile->interp, "fitsTcl Error: Cannot get image", TCL_STATIC); dumpFitsErrStack(curFile->interp, status); ckfree((char *) shortValArray); return TCL_ERROR; } if (rotate == 0) { backPtr = shortValArray; } else { shortTmpArray = (short *) ckalloc( nelem*sizeof(short) ); for (i=0; i < naxis1; i ++) { for (j=0; j < naxis2; j ++) { tmpIndex = j*naxis1 + i; switch (rotate) { case 1: /* 90 degree */ offset = (i+1)*naxis2 -j-1; break; case 2: offset = (naxis2-j-1)*naxis1 +(naxis1-i-1); break; case 3: offset = (naxis1-i-1)*naxis2 + j; break; default: offset = tmpIndex; break; } shortTmpArray[offset] = shortValArray[tmpIndex]; } } ckfree ((char *) shortValArray); backPtr = shortTmpArray; } break; case TBYTE: byteValArray = (unsigned char *) ckalloc( nelem*sizeof(unsigned char) ); ffgpvb(curFile->fptr, 1L, felem, nelem, UCHAR_MAX, byteValArray, &anynul, &status); if ( status ) { Tcl_SetResult(curFile->interp, "fitsTcl Error: Cannot get image", TCL_STATIC); dumpFitsErrStack(curFile->interp, status); ckfree((char *) byteValArray); return TCL_ERROR; } if (rotate == 0) { backPtr = byteValArray; } else { byteTmpArray = (unsigned char *) ckalloc(nelem*sizeof(unsigned char) ); for (i=0; i < naxis1; i ++) { for (j=0; j < naxis2; j ++) { tmpIndex = j*naxis1 + i; switch (rotate) { case 1: /* 90 degree */ offset = (i+1)*naxis2 -j-1; break; case 2: offset = (naxis2-j-1)*naxis1 +(naxis1-i-1); break; case 3: offset = (naxis1-i-1)*naxis2 + j; break; default: offset = tmpIndex; break; } byteTmpArray[offset] = byteValArray[tmpIndex]; } } ckfree ((char *) byteValArray); backPtr = byteTmpArray; } break; default: Tcl_SetResult(curFile->interp, "Unknown image type", TCL_STATIC); return TCL_ERROR; } sprintf(result, PTRFORMAT, backPtr); Tcl_SetResult(curFile->interp,result,TCL_VOLATILE); return TCL_OK; } /* * vtableGetToPtr * return "address dataType numberElements" * */ int vtableGetToPtr( FitsFD *curFile, long colNum, char *nulStr) { void *backPtr; int retnType; int dataType; long numRows; int anynul; long dataSize, vecSize; char result[80]; int status = 0; int useDefNull; double dblNul; LONGLONG longlongNul; float fltNul; int intNul; short shtNul; unsigned char bytNul; void *defNul; vecSize = curFile->CHDUInfo.table.vecSize[ colNum-1 ]; numRows = curFile->CHDUInfo.table.numRows; dataSize = numRows * vecSize; dataType = curFile->CHDUInfo.table.colDataType[ colNum-1 ]; useDefNull = !strcmp(nulStr,"NULL"); switch ( dataType ) { case TBYTE: case TBIT: retnType = BYTE_DATA; backPtr = (void *) ckalloc (dataSize * sizeof(unsigned char)); if( useDefNull ) { bytNul = UCHAR_MAX; } else { bytNul = atoi(nulStr); } defNul = &bytNul; break; case TSHORT: retnType = SHORTINT_DATA; backPtr = (void *) ckalloc (dataSize * sizeof(short)); if( useDefNull ) { shtNul = SHRT_MAX; } else { shtNul = atoi(nulStr); } defNul = &shtNul; break; case TINT: case TLONG: dataType = TINT; /* Cast TLONG to TINT */ retnType = INT_DATA; backPtr = (void *) ckalloc (dataSize * sizeof(int)); if( useDefNull ) { intNul = INT_MAX; } else { intNul = atoi(nulStr); } defNul = &intNul; break; case TFLOAT: retnType = FLOAT_DATA; backPtr = (void *) ckalloc (dataSize * sizeof(float)); if( useDefNull ) { fltNul = FLT_MAX; } else { fltNul = atof(nulStr); } defNul = &fltNul; break; case TDOUBLE: retnType = DOUBLE_DATA; backPtr = (void *) ckalloc (dataSize * sizeof(double)); if( useDefNull ) { dblNul = DBL_MAX; } else { dblNul = atof(nulStr); } defNul = &dblNul; break; case TLONGLONG: retnType = LONGLONG_DATA; backPtr = (void *) ckalloc (dataSize * sizeof(LONGLONG)); if( useDefNull ) { longlongNul = (LONGLONG)NULL; } else { longlongNul = atof(nulStr); } defNul = &longlongNul; break; default: Tcl_SetResult(curFile->interp, "The data type is not suitable for making an image", TCL_STATIC); return TCL_ERROR; break; } ffgcv( curFile->fptr, dataType, colNum, 1, 1, dataSize, defNul, backPtr, &anynul, &status); if ( status ) { dumpFitsErrStack(curFile->interp, status); ckfree( (char *) backPtr); return TCL_ERROR; } sprintf(result, PTRFORMAT " %d %ld", backPtr, retnType, dataSize); Tcl_SetResult(curFile->interp,result,TCL_VOLATILE); return TCL_OK; } /* * tableGetToPtr * return : "address dataType numberElements" * address can be recovered using sscanf(address, PTRFORMAT, &dataArray) * where void *dataArray * dataType : 0 byte(unsigned char) , 1 short int, 2 int , 3 float , 4 double * numberElements : dimension of the array * */ int tableGetToPtr( FitsFD *curFile, long colNum, char *nulStr, long firstelem ) { void *backPtr; LONGLONG *longlongArray; double *dblArray; float *fltArray; short *shtArray; int *intArray; unsigned char *bytArray; LONGLONG longlongNul; double dblNul; float fltNul; int intNul; short shtNul; unsigned char bytNul; char result[80]; long numRows, vecSize; int anynul, dataType, colDataType; int status=0; numRows = curFile->CHDUInfo.table.numRows; vecSize = curFile->CHDUInfo.table.vecSize[colNum-1]; colDataType = curFile->CHDUInfo.table.colDataType[colNum-1]; switch ( colDataType ) { case TSTRING: Tcl_SetResult(curFile->interp, "Cannot load string array", TCL_STATIC); return TCL_ERROR; case TBYTE: if( !strcmp(nulStr, "NULL") ) { bytNul = UCHAR_MAX; } else { bytNul = atoi(nulStr); } bytArray = (unsigned char *) ckalloc(numRows*sizeof(unsigned char)); ffgclb(curFile->fptr, colNum, 1, firstelem, numRows, vecSize, 1, bytNul, bytArray, (char*) NULL, &anynul, &status); if ( status ) { ckfree((char *) bytArray); dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } dataType = BYTE_DATA; backPtr = bytArray; break; case TSHORT: if( !strcmp(nulStr, "NULL") ) { shtNul = SHRT_MAX; } else { shtNul = atoi(nulStr); } shtArray = (short *) ckalloc(numRows*sizeof(short)); ffgcli(curFile->fptr, colNum, 1, firstelem, numRows, vecSize, 1, shtNul, shtArray, (char*) NULL, &anynul, &status); if ( status ) { ckfree((char *) shtArray); dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } dataType = SHORTINT_DATA; backPtr = shtArray; break; case TINT: case TLONG: if( !strcmp(nulStr, "NULL") ) { intNul = INT_MAX; } else { intNul = atoi(nulStr); } intArray = (int *) ckalloc(numRows*sizeof(int)); ffgclk(curFile->fptr, colNum, 1, firstelem, numRows, vecSize, 1, intNul, intArray, (char*) NULL, &anynul, &status); if ( status ) { ckfree((char *) intArray); dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } dataType = INT_DATA; backPtr = intArray; break; case TFLOAT: if( !strcmp(nulStr, "NULL") ) { fltNul = FLT_MAX; } else { fltNul = atof(nulStr); } fltArray = (float *) ckalloc(numRows*sizeof(float)); ffgcle(curFile->fptr, colNum, 1, firstelem, numRows, vecSize, 1, fltNul, fltArray, (char*) NULL, &anynul, &status); if ( status ) { ckfree((char *) fltArray); dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } dataType = FLOAT_DATA; backPtr = fltArray; break; case TDOUBLE: if( !strcmp(nulStr, "NULL") ) { dblNul = DBL_MAX; } else { dblNul = atof(nulStr); } dblArray = (double *) ckalloc(numRows*sizeof(double)); ffgcld(curFile->fptr, colNum, 1, firstelem, numRows, vecSize, 1, dblNul, dblArray, (char*) NULL, &anynul, &status); if ( status ) { ckfree((char *) dblArray); dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } dataType = DOUBLE_DATA; backPtr = dblArray; break; case TLONGLONG: if( !strcmp(nulStr, "NULL") ) { longlongNul = (LONGLONG)NULL; } else { longlongNul = atof(nulStr); } longlongArray = (LONGLONG *) ckalloc(numRows*sizeof(LONGLONG)); ffgcljj(curFile->fptr, colNum, 1, firstelem, numRows, vecSize, 1, longlongNul, longlongArray, (char*) NULL, &anynul, &status); if ( status ) { ckfree((char *) longlongArray); dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } dataType = LONGLONG_DATA; backPtr = longlongArray; break; default: Tcl_SetResult(curFile->interp, "fitsTcl Error: cannot load this type of column", TCL_STATIC); return TCL_ERROR; } sprintf(result, PTRFORMAT " %d %ld", backPtr, dataType, numRows); Tcl_SetResult(curFile->interp, result, TCL_VOLATILE); return TCL_OK; } /* * tableRowGetToPtr * return : "address dataType numberElements" * address can be recovered using sscanf(address, PTRFORMAT, &dataArray) * where void *dataArray * dataType : 0 byte(unsigned char) , 1 short int, 2 int , 3 float , 4 double * numberElements : dimension of the array * */ int tableRowGetToPtr( FitsFD *curFile, long rowNum, long colNum, long vecSize, char *nulStr, long firstelem ) { void *backPtr; LONGLONG *longlongArray; double *dblArray; float *fltArray; short *shtArray; int *intArray; unsigned char *bytArray; LONGLONG longlongNul; double dblNul; float fltNul; int intNul; short shtNul; unsigned char bytNul; char result[80]; long numRows; int anynul, dataType, colDataType; int status=0; numRows = curFile->CHDUInfo.table.numRows; /* vecSize = curFile->CHDUInfo.table.vecSize[colNum-1]; */ colDataType = curFile->CHDUInfo.table.colDataType[colNum-1]; switch ( colDataType ) { case TSTRING: Tcl_SetResult(curFile->interp, "Cannot load string array", TCL_STATIC); return TCL_ERROR; case TBYTE: if( !strcmp(nulStr, "NULL") ) { bytNul = UCHAR_MAX; } else { bytNul = atoi(nulStr); } bytArray = (unsigned char *) ckalloc(vecSize*sizeof(unsigned char)); ffgclb(curFile->fptr, colNum, rowNum, firstelem, vecSize, 1, 1, bytNul, bytArray, (char*) NULL, &anynul, &status); if ( status ) { ckfree((char *) bytArray); dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } dataType = BYTE_DATA; backPtr = bytArray; break; case TSHORT: if( !strcmp(nulStr, "NULL") ) { shtNul = SHRT_MAX; } else { shtNul = atoi(nulStr); } /* fprintf(stdout, "shtArray size: %ld\n", vecSize*sizeof(short)); */ /* fprintf(stdout, "vecSize size: %ld\n", vecSize); */ /* fprintf(stdout, "short size: %ld\n", sizeof(short)); */ shtArray = (short *) ckalloc(vecSize*sizeof(short)); ffgcli(curFile->fptr, colNum, rowNum, firstelem, vecSize, 1, 1, shtNul, shtArray, (char*) NULL, &anynul, &status); if ( status ) { ckfree((char *) shtArray); dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } dataType = SHORTINT_DATA; backPtr = shtArray; break; case TINT: case TLONG: if( !strcmp(nulStr, "NULL") ) { intNul = INT_MAX; } else { intNul = atoi(nulStr); } intArray = (int *) ckalloc(vecSize*sizeof(int)); ffgclk(curFile->fptr, colNum, rowNum, firstelem, vecSize, 1, 1, intNul, intArray, (char*) NULL, &anynul, &status); if ( status ) { ckfree((char *) intArray); dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } dataType = INT_DATA; backPtr = intArray; break; case TFLOAT: if( !strcmp(nulStr, "NULL") ) { fltNul = FLT_MAX; } else { fltNul = atof(nulStr); } fltArray = (float *) ckalloc(vecSize*sizeof(float)); ffgcle(curFile->fptr, colNum, rowNum, firstelem, vecSize, 1, 1, fltNul, fltArray, (char*) NULL, &anynul, &status); if ( status ) { ckfree((char *) fltArray); dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } dataType = FLOAT_DATA; backPtr = fltArray; break; case TDOUBLE: if( !strcmp(nulStr, "NULL") ) { dblNul = DBL_MAX; } else { dblNul = atof(nulStr); } dblArray = (double *) ckalloc(vecSize*sizeof(double)); ffgcld(curFile->fptr, colNum, rowNum, firstelem, vecSize, 1, 1, dblNul, dblArray, (char*) NULL, &anynul, &status); if ( status ) { ckfree((char *) dblArray); dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } dataType = DOUBLE_DATA; backPtr = dblArray; break; case TLONGLONG: if( !strcmp(nulStr, "NULL") ) { longlongNul = (LONGLONG)NULL; } else { longlongNul = atof(nulStr); } longlongArray = (LONGLONG *) ckalloc(vecSize*sizeof(LONGLONG)); ffgcljj(curFile->fptr, colNum, rowNum, firstelem, vecSize, 1, 1, longlongNul, longlongArray, (char*) NULL, &anynul, &status); if ( status ) { ckfree((char *) longlongArray); dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } dataType = LONGLONG_DATA; backPtr = longlongArray; break; default: Tcl_SetResult(curFile->interp, "fitsTcl Error: cannot load this type of column", TCL_STATIC); return TCL_ERROR; } sprintf(result, PTRFORMAT " %d %ld", backPtr, dataType, numRows); Tcl_SetResult(curFile->interp, result, TCL_VOLATILE); return TCL_OK; } /* * ------------------------------------------------------------ * * tableBlockLoad -- * a block of table is either set to an 2-D array varName(i_j) * or placed within a TCL list and returned * * ------------------------------------------------------------ */ int tableBlockLoad( FitsFD *curFile, char *varName, int felem, int fRow, int nRows, int fCol, int nCols, int colNums[], int format ) { int k,m; int anyf; char **cValue; long longValue[1]; double dblValue[2]; char xValue[1]; double dblComplex[2]; char nullArray[1]; char strNullVal[]="NULL"; char lValue[1]; char colFormat[80]; char cplxFormat[80]; char tmpStr[80]; int tmpInt; char varIndex[80]; int dataType; int status=0; char errMsg[160]; int listFlag=0; Tcl_Obj *valObj, **colData, *valObj2[2]; Tcl_Obj *cnstObj[5]; LONGLONG longlongValue[1]; enum { cnstNullObj=0, cnstTrueObj, cnstFalseObj, cnstUndefObj, cnstBlnkObj }; if( varName[0] == '\0' ) { listFlag = 1; colData = (Tcl_Obj**) ckalloc( nCols * sizeof( Tcl_Obj* ) ); } cnstObj[cnstNullObj] = Tcl_NewStringObj( "NULL", -1 ); cnstObj[cnstTrueObj] = Tcl_NewStringObj( "T", -1 ); cnstObj[cnstFalseObj] = Tcl_NewStringObj( "F", -1 ); cnstObj[cnstUndefObj] = Tcl_NewStringObj( "U", -1 ); cnstObj[cnstBlnkObj] = Tcl_NewStringObj( " ", -1 ); for ( k = 0; k < nCols; k++ ) { if( listFlag ) colData[k] = Tcl_NewObj(); strcpy(colFormat, curFile->CHDUInfo.table.colFormat[colNums[k]-1]); dataType = curFile->CHDUInfo.table.colDataType[colNums[k]-1]; if( curFile->CHDUInfo.table.vecSize[ colNums[k]-1 ]==0 ) { valObj = cnstObj[ cnstBlnkObj ]; for (m=fRow; m < (fRow+nRows); m++ ) { if( listFlag ) { Tcl_ListObjAppendElement(curFile->interp, colData[k], valObj); } else { sprintf(varIndex,"%d,%d", fCol-1+k, m-1); Tcl_SetVar2Ex(curFile->interp, varName, varIndex, valObj, 0); } } continue; } switch ( dataType ) { case TSTRING: tmpInt = curFile->CHDUInfo.table.strSize[ colNums[k]-1 ]+1; cValue = (char **) makeContigArray(2, tmpInt, 'c'); for (m=fRow; m < (fRow+nRows); m++ ) { ffgcls(curFile->fptr, colNums[k], m, felem, 1, 1, strNullVal, cValue, nullArray, &anyf, &status); if ( status > 0 ) { valObj = cnstObj[ cnstBlnkObj ]; status = 0; ffcmsg(); } else if( format ) { sprintf(cValue[1], colFormat, cValue[0]); valObj = Tcl_NewStringObj(cValue[1], -1); } else { valObj = Tcl_NewStringObj(cValue[0], -1); } if( listFlag ) { Tcl_ListObjAppendElement(curFile->interp, colData[k], valObj); } else { sprintf(varIndex,"%d,%d", fCol-1+k, m-1); Tcl_SetVar2Ex(curFile->interp, varName, varIndex, valObj, 0); } } ckfree( (char *) cValue[0]); ckfree( (char *) cValue); break; case TLOGICAL: for (m=fRow; m < (fRow+nRows); m++ ) { ffgcfl(curFile->fptr, colNums[k], m, felem, 1, lValue, nullArray, &anyf, &status); if ( status > 0 ) { valObj = cnstObj[ cnstBlnkObj ]; status = 0; ffcmsg(); } else if( anyf ) { valObj = cnstObj[ cnstUndefObj ]; } else { if (lValue[0] == 1) { valObj = cnstObj[ cnstTrueObj ]; } else if (lValue[0] == 0) { valObj = cnstObj[ cnstFalseObj ]; } else { valObj = cnstObj[ cnstUndefObj ]; } } if( listFlag ) { Tcl_ListObjAppendElement(curFile->interp, colData[k], valObj); } else { sprintf(varIndex,"%d,%d", fCol-1+k, m-1); Tcl_SetVar2Ex(curFile->interp, varName, varIndex, valObj, 0); } } break; case TBIT: for (m=fRow; m < (fRow+nRows); m++ ) { ffgcx(curFile->fptr, colNums[k], m, felem, 1, xValue, &status); if ( status > 0 ) { valObj = cnstObj[ cnstBlnkObj ]; status = 0; ffcmsg(); } else if( format ) { sprintf(tmpStr,colFormat,xValue[0]); valObj = Tcl_NewStringObj( tmpStr, -1 ); } else { valObj = Tcl_NewLongObj( (long)xValue[0] ); } if( listFlag ) { Tcl_ListObjAppendElement(curFile->interp, colData[k], valObj); } else { sprintf(varIndex,"%d,%d", fCol-1+k, m-1); Tcl_SetVar2Ex(curFile->interp, varName, varIndex, valObj, 0); } } break; case TBYTE: case TSHORT: case TINT: case TLONG: for (m=fRow; m < (fRow+nRows); m++ ) { ffgcfj(curFile->fptr, colNums[k], m, felem, 1, longValue, nullArray, &anyf, &status); if ( status > 0 ) { valObj = cnstObj[ cnstBlnkObj ]; status = 0; ffcmsg(); } else if( anyf ) { valObj = cnstObj[ cnstNullObj ]; } else if( format ) { sprintf(tmpStr,colFormat,longValue[0]); valObj = Tcl_NewStringObj( tmpStr, -1 ); } else { valObj = Tcl_NewLongObj( longValue[0] ); } if( listFlag ) { Tcl_ListObjAppendElement(curFile->interp, colData[k], valObj); } else { sprintf(varIndex,"%d,%d", fCol-1+k, m-1); Tcl_SetVar2Ex(curFile->interp, varName, varIndex, valObj, 0); } } break; case TFLOAT: case TDOUBLE: for (m=fRow; m < (fRow+nRows); m++ ) { ffgcfd(curFile->fptr, colNums[k], m, felem, 1, dblValue, nullArray, &anyf, &status); if ( status > 0 ) { valObj = cnstObj[ cnstBlnkObj ]; status = 0; ffcmsg(); } else if( anyf ) { valObj = cnstObj[ cnstNullObj ]; } else if( format ) { if( strchr(colFormat,'d') ) { sprintf(tmpStr, "%.0f", dblValue[0]); tmpInt = atoi(tmpStr); sprintf(tmpStr,colFormat,tmpInt); } else if( strchr(colFormat,'s') ) { sprintf(tmpStr, "%f", dblValue[0]); sprintf(tmpStr,colFormat,tmpStr); } else { sprintf(tmpStr,colFormat,dblValue[0]); } valObj = Tcl_NewStringObj( tmpStr, -1 ); } else { valObj = Tcl_NewDoubleObj( dblValue[0] ); } if( listFlag ) { Tcl_ListObjAppendElement(curFile->interp, colData[k], valObj); } else { sprintf(varIndex,"%d,%d", fCol-1+k, m-1); Tcl_SetVar2Ex(curFile->interp, varName, varIndex, valObj, 0); } } break; case TLONGLONG: for (m=fRow; m < (fRow+nRows); m++ ) { ffgcfjj(curFile->fptr, colNums[k], m, felem, 1, longlongValue, nullArray, &anyf, &status); if ( status > 0 ) { valObj = cnstObj[ cnstBlnkObj ]; status = 0; ffcmsg(); } else if( anyf ) { valObj = cnstObj[ cnstNullObj ]; } else { #ifdef __WIN32__ sprintf(tmpStr, "%I64d", longlongValue[0]); #else sprintf(tmpStr, "%lld", longlongValue[0]); #endif valObj = Tcl_NewStringObj( tmpStr, -1 ); } if( listFlag ) { Tcl_ListObjAppendElement(curFile->interp, colData[k], valObj); } else { sprintf(varIndex,"%d,%d", fCol-1+k, m-1); Tcl_SetVar2Ex(curFile->interp, varName, varIndex, valObj, 0); } } break; case TCOMPLEX: case TDBLCOMPLEX: if( format ) { sprintf(cplxFormat,"%s, %s",colFormat,colFormat); } for (m=fRow; m < (fRow+nRows); m++ ) { ffgcfm(curFile->fptr, colNums[k], m, felem, 1, dblComplex, nullArray, &anyf, &status); if ( status > 0 ) { valObj = cnstObj[ cnstBlnkObj ]; status = 0; ffcmsg(); } else if( anyf ) { if( format ) { valObj = Tcl_NewStringObj( "NULL, NULL", -1 ); } else { valObj = cnstObj[ cnstNullObj ]; } } else if( format ) { sprintf(tmpStr,cplxFormat,dblComplex[0],dblComplex[1]); valObj = Tcl_NewStringObj( tmpStr, -1 ); } else { valObj2[0] = Tcl_NewDoubleObj( dblComplex[0] ); valObj2[1] = Tcl_NewDoubleObj( dblComplex[1] ); valObj = Tcl_NewListObj(2, valObj2); } if( listFlag ) { Tcl_ListObjAppendElement(curFile->interp, colData[k], valObj); } else { sprintf(varIndex,"%d,%d", fCol-1+k, m-1); Tcl_SetVar2Ex(curFile->interp, varName, varIndex, valObj, 0); } } break; default: sprintf(errMsg,"Unrecognized colType: %d for column %d", dataType,colNums[k]); Tcl_SetResult(curFile->interp,errMsg,TCL_VOLATILE); if( listFlag ) { ckfree( (char*)colData ); } return TCL_ERROR; } } if( listFlag ) { Tcl_SetObjResult(curFile->interp, Tcl_NewListObj(nCols, colData) ); ckfree( (char *)colData ); } return TCL_OK; } /* * ------------------------------------------------------------ * * fitsFlushKeywords -- * * Flushes the header of the CHDU to the output file. * * Results: * * Side Effects: * None * * ------------------------------------------------------------ */ int fitsFlushKeywords( FitsFD *curFile ) { Tcl_HashEntry *newEntry; Tcl_HashSearch search; /* clean up the keyword hash table */ newEntry = Tcl_FirstHashEntry(curFile->kwds,&search); while ( NULL != newEntry ) { ckfree((char *) Tcl_GetHashValue(newEntry)); Tcl_DeleteHashEntry(newEntry); newEntry = Tcl_NextHashEntry(&search); } return TCL_OK; } /* * ------------------------------------------------------------ * * fitsPutReqKwds * * * ERROR Returns through elem: * * Results: * Side Effects: * * ------------------------------------------------------------ */ int fitsPutReqKwds( FitsFD *curFile, int isPrImg, int hduType, int argc, char *const argv[] ) { int nRows, nCols; int nElement, tmpInt, rowLen; char **cName, **cType, **cUnit, **cDims; char **cPost, *extname; long *tbcol; int status = 0; long *naxes; int i; int dataType, naxe; if ( hduType != IMAGE_HDU ) { /* parse the arg */ if ( Tcl_GetInt(curFile->interp, argv[0], &nRows) != TCL_OK) { Tcl_SetResult(curFile->interp, "Error getting nRows", TCL_STATIC); return TCL_ERROR; } /* col Name */ if (TCL_OK != Tcl_SplitList(curFile->interp, argv[1], &nCols, &cName) ){ Tcl_SetResult(curFile->interp, "cannot split colName list", TCL_STATIC); return TCL_ERROR; } /* col Type */ if (TCL_OK != Tcl_SplitList(curFile->interp, argv[2], &nElement, &cType) ){ Tcl_SetResult(curFile->interp, "cannot split colType list", TCL_STATIC); return TCL_ERROR; } if ( nElement != nCols ) { Tcl_SetResult(curFile->interp, "colType list doesn't match nCols", TCL_STATIC); return TCL_ERROR; } /* col Unit */ if( argc>3 ) { if (TCL_OK != Tcl_SplitList(curFile->interp, argv[3], &nElement, &cUnit)) { Tcl_SetResult(curFile->interp, "cannot split colUnit list", TCL_STATIC); return TCL_ERROR; } if( nElement>0 && nElement != nCols ) { Tcl_SetResult(curFile->interp, "colUnit list doesn't match nCols", TCL_STATIC); return TCL_ERROR; } /* Pan Chai (02/10/2015) add to check to see if input is empty. if so, set cUnit to NULL */ if (nElement <= 0) { cUnit = NULL; } } else { cUnit = NULL; } } switch ( hduType ) { case IMAGE_HDU: if( isPrImg && argc == 0 ) { /* Write an empty primary array */ ffphpr(curFile->fptr, 1, 16, 0, NULL, 0, 1, 1, &status); } else { char *const *argvPtr; /* Use this preserve argv's const status */ if( argc == 1 ) { if ( Tcl_SplitList(curFile->interp, argv[0], &nElement, &cPost ) != TCL_OK ) { Tcl_SetResult(curFile->interp, "Cannot split image parameter list", TCL_STATIC); return TCL_ERROR; } if ( nElement != 3 ) { ckfree( (char*)cPost ); Tcl_SetResult(curFile->interp, "Wrong number of parameter list", TCL_STATIC); return TCL_ERROR; } argvPtr = cPost; } else if( argc == 3 ) { argvPtr = argv; } else { Tcl_SetResult(curFile->interp, "Wrong number of parameter list", TCL_STATIC); return TCL_ERROR; } if ( TCL_OK != Tcl_GetInt(curFile->interp, argvPtr[0], &dataType)) { if( argc==1 ) ckfree( (char*)cPost ); Tcl_SetResult(curFile->interp, "The image data type is not an integer", TCL_STATIC); return TCL_ERROR; } if ( TCL_OK != Tcl_GetInt(curFile->interp, argvPtr[1], &naxe)) { if( argc==1 ) ckfree( (char*)cPost ); Tcl_SetResult(curFile->interp, "The image dimension is not an integer", TCL_STATIC); return TCL_ERROR; } if ( Tcl_SplitList(curFile->interp, argvPtr[2], &nElement, &cDims ) != TCL_OK ) { if( argc==1 ) ckfree( (char*)cPost ); Tcl_SetResult(curFile->interp, "Cannot split image dimension list", TCL_STATIC); return TCL_ERROR; } if( argc==1 ) ckfree( (char*)cPost ); if ( nElement != naxe ) { ckfree( (char*)cDims ); Tcl_SetResult(curFile->interp, "The number of elements in the list " "does not match naxes", TCL_STATIC); return TCL_ERROR; } naxes = (long *)ckalloc(naxe * sizeof(long)); for ( i =0; i < nElement; i++) { naxes[i] = atol(cDims[i]); } if( isPrImg ) ffphpr(curFile->fptr, 1, dataType, naxe, naxes, 0, 1, 1, &status); else ffiimg(curFile->fptr, dataType, naxe, naxes, &status); ckfree( (char *)naxes); ckfree( (char *)cDims ); } break; case ASCII_TBL: /* get tbcol */ if( argc>4 ) { if ( Tcl_SplitList(curFile->interp, argv[4], &nElement, &cPost ) != TCL_OK ) { Tcl_SetResult(curFile->interp, "cannot split tbcol list\n", TCL_STATIC); return TCL_ERROR; } if( nElement>0 && nElement != nCols ) { ckfree( (char *) cPost); ckfree( (char *) cName); ckfree( (char *) cType); if( cUnit ) ckfree( (char *) cUnit); Tcl_SetResult(curFile->interp, "tbcol list doesn't match nCols", TCL_STATIC); return TCL_ERROR; } if( nElement ) { tbcol = (long *) ckalloc( nCols*sizeof(long) ); for (i=0; i < nCols; i++) { if( Tcl_GetInt(curFile->interp, cPost[i], &tmpInt) != TCL_OK ) { ckfree( (char *) cPost); ckfree( (char *) cName); ckfree( (char *) cType); if( cUnit ) ckfree( (char *) cUnit); Tcl_SetResult(curFile->interp, "Cannot get colPosition", TCL_STATIC); return TCL_ERROR; } tbcol[i] = tmpInt; } } else { tbcol = NULL; } ckfree( (char *) cPost ); } else { tbcol = NULL; } if( argc>5 ) extname = argv[5]; else extname = ""; if( argc>6 ) Tcl_GetInt(curFile->interp, argv[6], &rowLen ); else rowLen = 0; ffitab(curFile->fptr, rowLen, nRows, nCols, cName, tbcol, cType, cUnit, extname, &status); ckfree( (char *) cName); ckfree( (char *) cType); if( cUnit ) ckfree( (char *) cUnit); if( tbcol ) ckfree( (char *) tbcol); break; case BINARY_TBL: if( argc>4 ) extname = argv[4]; else extname = ""; ffibin(curFile->fptr, nRows, nCols, cName, cType, cUnit, extname, 0, &status); ckfree( (char *) cName); ckfree( (char *) cType); if( cUnit ) ckfree( (char *) cUnit); break; default: Tcl_SetResult(curFile->interp, "Unknown Type", TCL_STATIC); return TCL_ERROR; } if ( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } /* now update */ if ( TCL_OK != fitsUpdateCHDU(curFile, hduType) ) return TCL_ERROR; if ( TCL_OK != fitsLoadHDU(curFile) ) return TCL_ERROR; return TCL_OK; } /* * Function for deleting keywords * */ int fitsDeleteKwds( FitsFD *curFile, char *keyList ) { char *tokptr; int status = 0; char *keyName; int tmpInt; /* get the keywords from the list */ tokptr = strtok(keyList, " "); while ( tokptr ) { if (TCL_OK == Tcl_GetInt(curFile->interp, tokptr, &tmpInt) ) { ffdrec(curFile->fptr, tmpInt, &status); } else { Tcl_ResetResult(curFile->interp); strToUpper(tokptr, &keyName); ffdkey(curFile->fptr, keyName, &status); ckfree((char *) keyName); } if ( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } tokptr = strtok(NULL, " "); } return fitsUpdateFile(curFile); } int fitsPutKwds( FitsFD *curFile, int nkey, char *inCard, int ifFormat ) { char card[FLEN_CARD],orig[FLEN_CARD]; char keyName[FLEN_KEYWORD]; char keyword[FLEN_KEYWORD]; char val[FLEN_VALUE]; char comm[FLEN_COMMENT]; int i, hdtype; int status = 0; if ( ifFormat == 1 ) { if( !strncmp(inCard,"HIERARCH ",9) ) inCard+=9; ffgthd(inCard, card, &hdtype, &status); if( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } } else { strncpy(keyword, inCard, 8); keyword[8] = '\0'; fftkey(keyword, &status); strncpy(card, inCard, 80); card[80] = '\0'; ffpsvc(card, val, comm, &status); if( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } } if ( nkey ) { ffgrec(curFile->fptr, nkey, orig, &status); ffmrec(curFile->fptr, nkey, card, &status); } else { for (i=0; i<8; i++) { if ( card[i] == ' ' ) break; keyName[i] = card[i]; } keyName[i] = '\0'; ffgcrd(curFile->fptr, keyName, orig, &status); if( status==KEY_NO_EXIST ) { orig[0]='\0'; status=0; ffcmsg(); } ffucrd(curFile->fptr, keyName, card, &status); } if ( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } Tcl_SetResult(curFile->interp, card, TCL_VOLATILE); if( fitsUpdateFile(curFile)==TCL_ERROR ) { if( nkey ) ffmrec(curFile->fptr, nkey, orig, &status); else { /* Reset location to start of header */ ffgrec(curFile->fptr, 0, card, &status); if( *orig ) ffucrd(curFile->fptr, keyName, orig, &status); else ffdkey(curFile->fptr, keyName, &status); } ffrhdu(curFile->fptr, &hdtype, &status); fitsUpdateFile(curFile); return TCL_ERROR; } return TCL_OK; } int fitsInsertKwds( FitsFD *curFile, int index, char *inCard, int ifFormat ) { char card[FLEN_CARD]; char keyword[FLEN_KEYWORD]; char val[FLEN_VALUE]; char comm[FLEN_COMMENT]; long headend; int hdtype; int status = 0; if ( ifFormat == 1 ) { /* from the templet, get the card */ if( strncmp(inCard,"HIERARCH ",9)==0 ) inCard+=9; ffgthd(inCard, card, &hdtype, &status); if( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } } else { strncpy(keyword, inCard, 8); keyword[8] = '\0'; fftkey(keyword, &status); ffpsvc(inCard, val, comm, &status); if( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } strcpy(card, inCard); } Tcl_SetResult(curFile->interp, card, TCL_VOLATILE); /* insert */ ffirec(curFile->fptr, index, card, &status); if ( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } headend = curFile->fptr->Fptr->headend; if( fitsUpdateFile(curFile)==TCL_ERROR ) { /* Error recovery */ curFile->fptr->Fptr->headend = headend; ffdrec(curFile->fptr, index, &status); ffrhdu(curFile->fptr, &hdtype, &status); fitsUpdateFile(curFile); return TCL_ERROR; } return TCL_OK; } /**********/ int fitsDeleteCols( FitsFD *curFile, int *colList, int numCols ) { int status = 0; int i,j,tmp; /* Need to make sure colList is sorted, then delete in reverse */ for ( i = 1; i tmp ) { colList[j] = colList[j-1]; j--; } colList[j] = tmp; } while( numCols-- ) { ffdcol(curFile->fptr, colList[numCols], &status); if ( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } } return fitsUpdateFile(curFile); } /**********/ int fitsDeleteRowlist ( FitsFD *curFile, long* rowlist, int numRows ) { int status = 0; ffdrws(curFile->fptr, rowlist, numRows, &status); if ( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } return fitsUpdateFile(curFile); } /**********/ int fitsDeleteRowsRange( FitsFD *curFile, char * rangelist) { int status = 0; ffdrrg(curFile->fptr, rangelist, &status); if ( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } return fitsUpdateFile(curFile); } /**********/ int fitsDeleteRows( FitsFD *curFile, int firstRow, int numRows ) { int status = 0; ffdrow(curFile->fptr, firstRow, numRows, &status); if ( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } return fitsUpdateFile(curFile); } /***************/ int fitsDeleteCHdu( FitsFD *curFile ) { int status = 0; int newHduType; char result[80]; ffdhdu(curFile->fptr, &newHduType, &status); if ( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } sprintf(result, "%d", newHduType); Tcl_SetResult(curFile->interp, result, TCL_VOLATILE); return fitsUpdateFile(curFile); } /* all numbers are 1-based, including baseColNum */ int saveVectorTableToAscii( FitsFD *curFile, char *filename, char *fileStatus, int fRow, int nRows, int fCol, int nCols, int baseColNum, int ifCSV, int ifPrintRow, char *sepString, int ifVariableVec) { FILE *fPtr; LONGLONG m; char colFormat[80]; char outputStr[80]; int dataType; if ( ifCSV == 1) { sepString = (char *) ckalloc(4); strcpy(sepString,"\",\""); } if( !strcmp(fileStatus,"0") ) { /* Create new file */ if ( ( fPtr = fopen(filename, "w")) == NULL ) { Tcl_ResetResult(curFile->interp); Tcl_AppendResult(curFile->interp,"Cannot open file ", filename, (char*)NULL); return TCL_ERROR; } } else { /* Append data only to file */ if ( ( fPtr = fopen(filename, "a")) == NULL ) { Tcl_ResetResult(curFile->interp); Tcl_AppendResult(curFile->interp,"Cannot open file ", filename, (char*)NULL); return TCL_ERROR; } } strcpy(colFormat, curFile->CHDUInfo.table.colFormat[baseColNum-1]); dataType = curFile->CHDUInfo.table.colDataType[baseColNum-1]; for (m=fRow; m < (fRow+nRows); m++ ) { if ( ifCSV == 1 ) fprintf(fPtr, "\""); if ( ifPrintRow == 1 ) { sprintf(outputStr, "%lld", m); fprintf(fPtr,"%s", outputStr); fprintf(fPtr,"%s", sepString); } saveVectorTableRowToAscii(curFile, filename, fileStatus, m, 1, fCol, nCols, baseColNum, ifCSV, ifPrintRow, sepString, ifVariableVec, colFormat, dataType, fPtr, 0); if ( ifCSV == 1) fprintf(fPtr, "\""); fprintf(fPtr,"\n"); } fclose(fPtr); return TCL_OK; } int saveVectorTableRowToAscii( FitsFD *curFile, char *filename, char *fileStatus, int fRow, int nRows, int fCol, int nCols, int baseColNum, int ifCSV, int ifPrintRow, char *sepString, int ifVariableVec, char *colFormat, int dataType, FILE *fPtr, int ifFixedFormat) { LONGLONG k; int anyf; char **cValue; long longValue[1]; LONGLONG longlongValue[1]; double dblValue[1]; char xValue[1]; char nullArray[1]; char strNullVal[]="NULL"; char lValue[1]; char outputStr[80]; int tmpInt; int status=0; char errMsg[160]; for ( k = fCol; k <= (fCol+nCols-1); k++ ) { switch ( dataType ) { case TSTRING: tmpInt = curFile->CHDUInfo.table.strSize[ baseColNum-1 ]+1; cValue = (char **) makeContigArray(2, tmpInt, 'c'); ffgcls(curFile->fptr, baseColNum, fRow, k, 1, 1, strNullVal, cValue, nullArray, &anyf, &status); if ( status > 0 ) { strcpy(outputStr," "); status = 0; ffcmsg(); } else if ( anyf ) { strcpy(outputStr,"NULL"); } else { sprintf(outputStr, colFormat, cValue[0]); } ckfree( (char *) cValue[0]); ckfree( (char *) cValue); break; /* not implemented yet */ case TLOGICAL: ffgcfl(curFile->fptr, baseColNum, fRow, k, 1, lValue, nullArray, &anyf, &status); if ( status > 0 ) { strcpy(outputStr," "); status = 0; ffcmsg(); } else if( anyf ) { strcpy(outputStr,"NULL"); /* valObj = cnstObj[ cnstUndefObj ]; */ } else { if (lValue[0] == 1) { /* valObj = cnstObj[ cnstTrueObj ]; */ } else { /* valObj = cnstObj[ cnstFalseObj ]; */ } } break; case TBIT: ffgcx(curFile->fptr, baseColNum, fRow, k, 1, xValue, &status); if ( status > 0 ) { status = 0; ffcmsg(); } else { sprintf(outputStr,colFormat,xValue[0]); } break; case TBYTE: case TSHORT: case TINT: case TLONG: ffgcfj(curFile->fptr, baseColNum, fRow, k, 1, longValue, nullArray, &anyf, &status); if ( status > 0 ) { strcpy(outputStr," "); status = 0; ffcmsg(); } else if ( anyf ) { strcpy(outputStr,"NULL"); } else { sprintf(outputStr,colFormat,longValue[0]); } break; case TFLOAT: case TDOUBLE: ffgcfd(curFile->fptr, baseColNum, fRow, k, 1, dblValue, nullArray, &anyf, &status); if ( status > 0 ) { strcpy(outputStr," "); status = 0; ffcmsg(); } else if( anyf ) { /* */ strcpy(outputStr,"NULL"); } else { if( strchr(colFormat,'d') ) { sprintf(outputStr, "%.0f", dblValue[0]); tmpInt = atoi(outputStr); sprintf(outputStr,colFormat,tmpInt); } else if( strchr(colFormat,'s') ) { sprintf(outputStr, "%f", dblValue[0]); sprintf(outputStr,colFormat,outputStr); } else { sprintf(outputStr,colFormat,dblValue[0]); } } break; case TLONGLONG: ffgcfjj(curFile->fptr, baseColNum, fRow, k, 1, longlongValue, nullArray, &anyf, &status); if ( status > 0 ) { strcpy(outputStr," "); status = 0; ffcmsg(); } else if( anyf ) { strcpy(outputStr,"NULL"); } else { strcpy(outputStr,longlongValue[0]); } break; default: sprintf(errMsg,"ERROR"); Tcl_SetResult(curFile->interp,errMsg,TCL_VOLATILE); return TCL_ERROR; } fprintf(fPtr, "%s", outputStr); if ( k != (fCol+nCols-1) ) fprintf(fPtr, "%s", sepString); } return TCL_OK; } /***************/ /* * save current table to an ascii file */ int saveTableToAscii( FitsFD *curFile, char *filename, char *fileStatus, int felem, int fRow, int nRows, int nCols, int colTypes[], int colNums[], int strSize[], int ifFixedFormat, int ifCSV, int ifPrintRow, char *sepString) { FILE *fPtr; int m, j, k; char rowFormatStr[10]; char **outFStr; char **tmpFStr; char **colFStr; char **cValue; short shtValue[1]; int intValue[1]; long longValue[1]; LONGLONG longlongValue[1]; double dblValue[1]; float fValue[1]; double dblComplex[2]; float fltComplex[2]; char nullArray[1]; char strNullVal[]="NULL"; unsigned char binValue[1]; char lValue[1]; char *outputStr; char errMsg[80]; int tmpInt; int anyf; int status=0; /* create a minimum large enough to encompass the row string */ int maxWidth = 99999; int dataType; int ifVariableVec; if ( ifCSV == 1) { sepString = (char *) ckalloc(4); strcpy(sepString,"\",\""); } /* outFStr pads columns with extra spaces in Fixed Format */ outFStr = (char **) makeContigArray(nCols, 80, 'c'); tmpFStr = (char **) makeContigArray(nCols, 80, 'c'); colFStr = (char **) makeContigArray(nCols, 80, 'c'); for (k=0; k< nCols; k++) { if ( ifFixedFormat == 1) { sprintf(outFStr[k]," %%%ds", strSize[k]); sprintf(rowFormatStr," %%%ds", 8); } else { strcpy(outFStr[k],"%s"); strcpy(rowFormatStr,"%s"); } strcpy(colFStr[k], curFile->CHDUInfo.table.colFormat[colNums[k]-1]); if( strSize[k] > maxWidth ) maxWidth = strSize[k]; } outputStr = (char *) ckalloc( (maxWidth+1) * sizeof(char) ); if( !strcmp(fileStatus,"0") ) { /* Create new file */ if ( ( fPtr = fopen(filename, "w")) == NULL ) { Tcl_ResetResult(curFile->interp); Tcl_AppendResult(curFile->interp,"Cannot open file ", filename, (char*)NULL); return TCL_ERROR; } /* Don't print column names until we decide format */ if ( ifFixedFormat == 1 ) { if ( ifPrintRow == 1 ) { strcpy(outputStr,"Row"); fprintf(fPtr,rowFormatStr,outputStr); } for (k=0; k< nCols; k++) { tmpInt = curFile->CHDUInfo.table.vecSize[ colNums[k]-1 ]; if ( tmpInt != 1 ) { if ( ifFixedFormat == 1 ) { sprintf(outFStr[k]," %%%ds", strSize[k] * tmpInt - (tmpInt - 1)); } } fprintf(fPtr,outFStr[k],curFile->CHDUInfo.table.colName[colNums[k]-1]); } fprintf(fPtr,"\n"); if ( ifPrintRow == 1 ) { strcpy(outputStr," "); fprintf(fPtr,rowFormatStr,outputStr); } for (k=0; k< nCols; k++) { tmpInt = curFile->CHDUInfo.table.vecSize[ colNums[k]-1 ]; if ( tmpInt != 1 ) { if ( ifFixedFormat == 1 ) { sprintf(outFStr[k]," %%%ds", strSize[k] * tmpInt - (tmpInt - 1)); } } fprintf(fPtr,outFStr[k],curFile->CHDUInfo.table.colType[colNums[k]-1]); } fprintf(fPtr,"\n"); if ( ifPrintRow == 1 ) { strcpy(outputStr," "); fprintf(fPtr,rowFormatStr,outputStr); } for (k=0; k< nCols; k++) { tmpInt = curFile->CHDUInfo.table.vecSize[ colNums[k]-1 ]; if ( tmpInt != 1 ) { if ( ifFixedFormat == 1 ) { sprintf(outFStr[k]," %%%ds", strSize[k] * tmpInt - (tmpInt - 1)); } } fprintf(fPtr,outFStr[k],curFile->CHDUInfo.table.colUnit[colNums[k]-1]); } fprintf(fPtr,"\n"); } } else if( !strcmp(fileStatus,"1") ) { /* Append to file with header */ if ( ( fPtr = fopen(filename, "a")) == NULL ) { Tcl_ResetResult(curFile->interp); Tcl_AppendResult(curFile->interp,"Cannot open file ", filename, (char*)NULL); return TCL_ERROR; } fprintf(fPtr,"\n"); for (k=0; k< nCols; k++) { tmpInt = curFile->CHDUInfo.table.vecSize[ colNums[k]-1 ]; if ( tmpInt != 1 ) { if ( ifFixedFormat == 1 ) { sprintf(outFStr[k]," %%%ds", strSize[k] * tmpInt - (tmpInt - 1)); } } fprintf(fPtr,outFStr[k],curFile->CHDUInfo.table.colName[colNums[k]-1]); } fprintf(fPtr,"\n"); for (k=0; k< nCols; k++) { tmpInt = curFile->CHDUInfo.table.vecSize[ colNums[k]-1 ]; if ( tmpInt != 1 ) { if ( ifFixedFormat == 1 ) { sprintf(outFStr[k]," %%%ds", strSize[k] * tmpInt - (tmpInt - 1)); } } fprintf(fPtr,outFStr[k],curFile->CHDUInfo.table.colType[colNums[k]-1]); } fprintf(fPtr,"\n"); for (k=0; k< nCols; k++) { tmpInt = curFile->CHDUInfo.table.vecSize[ colNums[k]-1 ]; if ( tmpInt != 1 ) { if ( ifFixedFormat == 1 ) { sprintf(outFStr[k]," %%%ds", strSize[k] * tmpInt - (tmpInt - 1)); } } fprintf(fPtr,outFStr[k],curFile->CHDUInfo.table.colUnit[colNums[k]-1]); } fprintf(fPtr,"\n"); } else { /* Append data only to file */ if ( ( fPtr = fopen(filename, "a")) == NULL ) { Tcl_ResetResult(curFile->interp); Tcl_AppendResult(curFile->interp,"Cannot open file ", filename, (char*)NULL); return TCL_ERROR; } } for (m= 0; m < nRows; m++ ) { if ( ifCSV == 1 ) fprintf(fPtr, "\""); if ( ifPrintRow == 1 ) { int rowNum = fRow + m; sprintf(outputStr, "%d", rowNum); if ( ifFixedFormat == 1 ) { /* pad the row number with blank spaces */ fprintf(fPtr, rowFormatStr, outputStr); } else { /* don't pad */ fprintf(fPtr, "%s", outputStr); } fprintf(fPtr, "%s", sepString); } for (j=0; j< nCols; j++) { tmpInt = (int) curFile->CHDUInfo.table.vecSize[ colNums[j]-1 ]; if ( tmpInt != 1 ) { dataType = curFile->CHDUInfo.table.colDataType[colNums[j]-1]; ifVariableVec = 0; if ( ifFixedFormat == 1 ) { fprintf(fPtr,"%3s"," "); } saveVectorTableRowToAscii(curFile, filename, fileStatus, fRow+m, 1, 1, tmpInt, colNums[j], ifCSV, 0, sepString, ifVariableVec, colFStr[j], dataType, fPtr, ifFixedFormat); if ( ifFixedFormat == 0 ) { if ( j < nCols-1 ) { fprintf(fPtr,"%s",sepString); } } } else { switch (curFile->CHDUInfo.table.colDataType[colNums[j]-1]) { case TSTRING: cValue = (char **) makeContigArray(1, maxWidth+1, 'c'); ffgcls(curFile->fptr, colNums[j], m+fRow, felem, 1, 1, strNullVal, cValue, nullArray, &anyf, &status); if ( status > 0 ) { strcpy(outputStr," "); status = 0; ffcmsg(); } else { sprintf(outputStr,colFStr[j],cValue[0]); } ckfree( (char *) cValue[0]); ckfree( (char *) cValue); break; case TLOGICAL: ffgcfl(curFile->fptr, colNums[j], m+fRow, felem, 1, lValue, nullArray, &anyf, &status); if ( status > 0 ) { strcpy(outputStr," "); status = 0; ffcmsg(); } else if( anyf ) { sprintf(outputStr,colFStr[j],"U"); } else { if( lValue[0] ) { sprintf(outputStr,colFStr[j],"T"); } else { sprintf(outputStr,colFStr[j],"F"); } } break; case TBIT: ffgcfb(curFile->fptr, colNums[j], m+fRow, felem, 1, binValue, nullArray, &anyf, &status); if ( status > 0 ) { strcpy(outputStr," "); status = 0; ffcmsg(); } else if( anyf ) { strcpy(outputStr,"NULL"); } else { sprintf(outputStr,colFStr[j],binValue[0]); } break; case TBYTE: ffgcfb(curFile->fptr, colNums[j], m+fRow, felem, 1, binValue, nullArray, &anyf, &status); if ( status > 0 ) { strcpy(outputStr," "); status = 0; ffcmsg(); } else if( anyf ) { strcpy(outputStr,"NULL"); } else { sprintf(outputStr,colFStr[j],binValue[0]); } break; case TSHORT: ffgcfi(curFile->fptr, colNums[j], m+fRow, 1, 1, shtValue, nullArray, &anyf, &status); if ( status > 0 ) { strcpy(outputStr," "); status = 0; ffcmsg(); } else if( anyf ) { strcpy(outputStr,"NULL"); } else { sprintf(outputStr,colFStr[j],shtValue[0]); } break; case TINT: ffgcfk(curFile->fptr, colNums[j], m+fRow, 1, 1, intValue, nullArray, &anyf, &status); if ( status > 0 ) { strcpy(outputStr," "); status = 0; ffcmsg(); } else if( anyf ) { strcpy(outputStr,"NULL"); } else { sprintf(outputStr,colFStr[j],intValue[0]); } break; case TLONG: ffgcfj(curFile->fptr, colNums[j], m+fRow, felem, 1, longValue, nullArray, &anyf, &status); if ( status > 0 ) { strcpy(outputStr," "); status = 0; ffcmsg(); } else if( anyf ) { strcpy(outputStr,"NULL"); } else { sprintf(outputStr,colFStr[j],longValue[0]); } break; case TFLOAT: ffgcfe(curFile->fptr, colNums[j], m+fRow, felem, 1, fValue, nullArray, &anyf, &status); if ( status > 0 ) { strcpy(outputStr," "); status = 0; ffcmsg(); } else if( anyf ) { strcpy(outputStr,"NULL"); } else { sprintf(outputStr,colFStr[j],fValue[0]); } break; case TDOUBLE: ffgcfd(curFile->fptr, colNums[j], m+fRow, felem, 1, dblValue, nullArray, &anyf, &status); if ( status > 0 ) { strcpy(outputStr," "); status = 0; ffcmsg(); } else if( anyf ) { strcpy(outputStr,"NULL"); } else { if (strchr(colFStr[j],'d') !=NULL) { sprintf(outputStr, "%.0f", dblValue[0]); tmpInt = atoi(outputStr); sprintf(outputStr,colFStr[j],tmpInt); } else { sprintf(outputStr,colFStr[j],dblValue[0]); } } break; case TLONGLONG: ffgcfjj(curFile->fptr, colNums[j], m+fRow, felem, 1, longlongValue, nullArray, &anyf, &status); if ( status > 0 ) { strcpy(outputStr," "); status = 0; ffcmsg(); } else if( anyf ) { strcpy(outputStr,"NULL"); } else { #ifdef __WIN32__ sprintf(outputStr,"%I64d",longlongValue[0]); #else sprintf(outputStr,"%lld",longlongValue[0]); #endif /* strcpy(outputStr,longlongValue[0]); */ } break; case TCOMPLEX: ffgcfc(curFile->fptr, colNums[j], m+fRow, felem, 1, fltComplex, nullArray, &anyf, &status); if ( status > 0 ) { strcpy(outputStr," "); status = 0; ffcmsg(); } else if( anyf ) { strcpy(outputStr,"NULL, NULL"); } else { sprintf(outputStr,"%.5f, %.5f",fltComplex[0],fltComplex[1]); } break; case TDBLCOMPLEX: ffgcfm(curFile->fptr, colNums[j], m+fRow, felem, 1, dblComplex, nullArray, &anyf, &status); if ( status > 0 ) { strcpy(outputStr," "); status = 0; ffcmsg(); } else if( anyf ) { strcpy(outputStr,"NULL, NULL"); } else { sprintf(outputStr,"%.8f, %.8f",dblComplex[0], dblComplex[1]); } break; default: sprintf(errMsg,"Unrecognized colType: %d for column %d\n", colTypes[j],colNums[j]); Tcl_SetResult(curFile->interp,errMsg,TCL_VOLATILE); ckfree( (char *) outFStr[0]); ckfree( (char *) colFStr[0]); ckfree( (char *) outFStr); ckfree( (char *) colFStr); ckfree( (char *) outputStr ); fclose(fPtr); return TCL_ERROR; } fprintf(fPtr, outFStr[j], outputStr); if ( ifFixedFormat == 0 ) { if ( j != nCols-1 ) /* print sepString if we're not on last column */ fprintf(fPtr, "%s", sepString); } } } if (ifCSV == 1) { fprintf(fPtr,"\""); } fprintf(fPtr,"\n"); } fclose(fPtr); ckfree( (char *) outFStr[0]); ckfree( (char *) outFStr); ckfree( (char *) colFStr[0]); ckfree( (char *) colFStr); ckfree( (char *) outputStr ); return TCL_OK; } /* save image table to an ascii file */ int saveImageToAscii( FitsFD *curFile, char *filename, char *fileStatus, int fRow, int nRows, int fCol, int nCols, int cellSize, int ifCSV, int ifPrintRow, char *sepString, long slice ) { FILE *fPtr; char outFStr[80]; int i,j; unsigned char *byteData; short *shortData; int *intData; float *floatData; double *dblData; LONGLONG *longlongData; char *nullArray; long tmpIndex; char outputStr[1024]; long blc[FITS_MAXDIMS], trc[FITS_MAXDIMS], incrc[FITS_MAXDIMS]; int anyNul; int naxes, flip=0; int xDim, yDim; char result[80]; int status=0; long naxisn[9]; naxes = curFile->CHDUInfo.image.naxes; if( naxes > 3 ) { for (i = 3; i < naxes; i++) { if (curFile->CHDUInfo.image.naxisn[i] != 1) { Tcl_SetResult(curFile->interp, "Can only read L X M X N X 1 ... images", TCL_STATIC); return TCL_ERROR; } } } if( naxes > FITS_MAXDIMS ) { sprintf(result,"Image exceeds %d dimensions", FITS_MAXDIMS); Tcl_SetResult(curFile->interp, result, TCL_VOLATILE); return TCL_ERROR; } for (i=0; i< curFile->CHDUInfo.image.naxes; i++) { naxisn[i] = (long) curFile->CHDUInfo.image.naxisn[i]; } xDim = naxisn[0]; if( naxes>1 ) { yDim = naxisn[1]; } else { yDim = 1; if( (fCol>1 && fRow>1) || (nRows>1 && nCols>1) ) { Tcl_SetResult(curFile->interp, "Cannot read 2D block from a 1D image", TCL_STATIC); return TCL_ERROR; } if( fRow>2 || nRows>2 ) { /* Interpret 1D image as a column */ flip = 1; yDim = xDim; xDim = 1; } } if ( fRow+nRows > yDim ) { nRows = yDim - fRow +1; } if ( fCol+nCols > xDim ) { nCols = xDim - fCol +1; } if( flip ) { blc[0] = fRow; trc[0] = fRow+nRows-1; incrc[0] = 1; } else { blc[0] = fCol; trc[0] = fCol+nCols-1; incrc[0] = 1; } if( naxes>1 ) { blc[1] = fRow; trc[1] = fRow+nRows-1; incrc[1] = 1; if( naxes>2 ) { blc[2] = slice; trc[2] = slice; incrc[2] = 1; for (i=3; i < naxes; i++) { blc[i] = 1; trc[i] = 1; incrc[i] = 1; } } } if( !strcmp(fileStatus,"0") ) { if ( ( fPtr = fopen(filename, "w")) == NULL ) { Tcl_SetResult(curFile->interp, "Cannot open file ", TCL_STATIC); Tcl_AppendResult(curFile->interp, filename, (char*)NULL); return TCL_ERROR; } } else { if ( ( fPtr = fopen(filename, "a")) == NULL ) { Tcl_SetResult(curFile->interp, "Cannot open file ", TCL_STATIC); Tcl_AppendResult(curFile->interp, filename, (char*)NULL); return TCL_ERROR; } } /* not used, we aren't using fixed format that uses padded spaces */ sprintf(outFStr, "%%%ds", cellSize); nullArray = (char *) ckalloc(nCols*nRows*sizeof(char)); if ( ifCSV == 1) { sepString = (char *) ckalloc(4); strcpy(sepString,"\",\""); } if( !strcmp(fileStatus,"0") ) { /* print columns, appropriately formatted */ } switch( curFile->CHDUInfo.image.dataType ) { case TDOUBLE: dblData = (double *) ckalloc(nCols*nRows*sizeof(double)); memset (dblData, 0, nCols*nRows*sizeof(double)); ffgsfd(curFile->fptr, 0, curFile->CHDUInfo.image.naxes, naxisn, blc, trc, incrc, dblData, nullArray, &anyNul, &status); if ( status > 0 ) { Tcl_SetResult(curFile->interp, "Error reading image\n", TCL_STATIC); dumpFitsErrStack( curFile->interp, status ); ckfree( (char *) dblData); return TCL_ERROR; } for (j=0; j < nRows; j++ ) { /* for (j=nRows-1; j>=0; j-- ) { */ if ( ifCSV == 1 ) fprintf(fPtr, "\""); if ( ifPrintRow == 1 ) { int rowNum = fRow + j; sprintf(outputStr, "%d", rowNum); fprintf(fPtr, "%s", outputStr); fprintf(fPtr, "%s", sepString); } for (i=0; ifptr, 0, curFile->CHDUInfo.image.naxes, naxisn, blc, trc, incrc, longlongData, nullArray, &anyNul, &status); if ( status > 0 ) { Tcl_SetResult(curFile->interp, "Error reading image\n", TCL_STATIC); dumpFitsErrStack( curFile->interp, status ); ckfree( (char *) longlongData); return TCL_ERROR; } for (j=0; j < nRows; j++ ) { /* for (j=nRows-1; j>=0; j-- ) { */ if ( ifCSV == 1 ) fprintf(fPtr, "\""); if ( ifPrintRow == 1 ) { int rowNum = fRow + j; sprintf(outputStr, "%d", rowNum); fprintf(fPtr, "%s", outputStr); fprintf(fPtr, "%s", sepString); } for (i=0; ifptr, 0, curFile->CHDUInfo.image.naxes, naxisn, blc, trc, incrc, floatData, nullArray, &anyNul, &status); if ( status > 0 ) { Tcl_SetResult(curFile->interp, "Error reading image\n", TCL_STATIC); dumpFitsErrStack( curFile->interp, status ); ckfree( (char *) floatData); return TCL_ERROR; } for (j=0; j < nRows; j++ ) { /* for (j=nRows-1; j>=0; j-- ) { */ if ( ifCSV == 1) fprintf(fPtr, "\""); if ( ifPrintRow == 1) { int rowNum = fRow + j; sprintf(outputStr, "%d", rowNum); fprintf(fPtr, "%s", outputStr); fprintf(fPtr, "%s", sepString); } for (i=0; ifptr, 0, curFile->CHDUInfo.image.naxes, naxisn, blc, trc, incrc, intData, nullArray, &anyNul, &status); if ( status > 0 ) { Tcl_SetResult(curFile->interp, "Error reading image\n", TCL_STATIC); dumpFitsErrStack( curFile->interp, status ); ckfree( (char *) intData); return TCL_ERROR; } for (j=0; j < nRows; j++ ) { /* for (j=nRows-1; j>=0; j-- ) { */ if ( ifCSV == 1) fprintf(fPtr, "\""); if ( ifPrintRow == 1) { int rowNum = fRow + j; sprintf(outputStr, "%d", rowNum); fprintf(fPtr, "%s", outputStr); fprintf(fPtr, "%s", sepString); } for (i=0; ifptr, 0, curFile->CHDUInfo.image.naxes, naxisn, blc, trc, incrc, shortData, nullArray, &anyNul, &status); if ( status > 0 ) { Tcl_SetResult(curFile->interp, "Error reading image\n", TCL_STATIC); dumpFitsErrStack( curFile->interp, status ); ckfree( (char *) shortData); return TCL_ERROR; } for (j=0; j < nRows; j++ ) { /* for (j=nRows-1; j>=0; j-- ) { */ if ( ifCSV == 1) fprintf(fPtr, "\""); if ( ifPrintRow == 1) { int rowNum = fRow + j; sprintf(outputStr, "%d", rowNum); fprintf(fPtr, "%s", outputStr); fprintf(fPtr, "%s", sepString); } for (i=0; ifptr, 0, curFile->CHDUInfo.image.naxes, naxisn, blc, trc, incrc, byteData, nullArray, &anyNul, &status); if ( status > 0 ) { Tcl_SetResult(curFile->interp, "Error reading image\n", TCL_STATIC); dumpFitsErrStack( curFile->interp, status ); ckfree( (char *) byteData); return TCL_ERROR; } for (j=0; j < nRows; j++ ) { /* for (j=nRows-1; j>=0; j-- ) { */ if ( ifCSV == 1) fprintf(fPtr, "\""); if ( ifPrintRow == 1) { int rowNum = fRow + j; sprintf(outputStr, "%d", rowNum); fprintf(fPtr, "%s", outputStr); fprintf(fPtr, "%s", sepString); } for (i=0; iinterp, "Unknown image type", TCL_STATIC); fclose(fPtr); return TCL_ERROR; } ckfree((char *)nullArray); fclose(fPtr); return TCL_OK; } /* save a column in memory to a table */ int varSaveToTable( FitsFD *curFile, int colNum, long firstRow, long firstElem, long numRows, long numElem, Tcl_Obj **dataElems ) { int status = 0; int colDataType, colVecSize; int i; void *dataArray; char **strArray; char *bitArray; long *lngArray; double *dblArray; LONGLONG *longlongArray; char *strPtr; char *nulFlag; int iVal; long lVal; double dVal; Tcl_Obj **cpxList; int nCpx; /* check the number of the input array and the number specified */ colDataType = curFile->CHDUInfo.table.colDataType[colNum-1]; colVecSize = curFile->CHDUInfo.table.vecSize[colNum-1]; if( colVecSize == 0 ) return TCL_OK; if( colVecSize == 1 || colDataType == TSTRING ) { /* this is not a vector column, do as usual */ if ( numRows != numElem ) { Tcl_SetResult(curFile->interp, "fitsTcl Error: " "the number of the elements in the input " "array does not match the specified row range.", TCL_STATIC); return TCL_ERROR; } } else { /* this is a vector column, write to the vector element */ numRows = numElem; } nulFlag = (char *) ckalloc(numRows*sizeof(char)); switch ( colDataType ) { case TSTRING: strArray = (char **) ckalloc(numRows * sizeof(char*)); dataArray = strArray; for ( i = 0; i < numRows; i++ ) { strArray[i] = Tcl_GetStringFromObj( dataElems[i], NULL ); if( !strcmp("NULL",strArray[i]) ) { nulFlag[i] = 1; } else { nulFlag[i] = 0; } } break; case TLOGICAL: bitArray = (char *) ckalloc(numRows * sizeof(char)); dataArray = bitArray; for ( i= 0; i < numRows; i++ ) { if( Tcl_GetBooleanFromObj( curFile->interp, dataElems[i], &iVal ) != TCL_OK ) { bitArray[i] = 0; nulFlag[i] = 1; } else { bitArray[i] = iVal; nulFlag[i] = 0; } } break; case TBIT: bitArray = (char *) ckalloc(numRows * sizeof(char)); dataArray = bitArray; for ( i= 0; i < numRows; i++ ) { if( Tcl_GetLongFromObj( curFile->interp, dataElems[i], &lVal ) != TCL_OK ) { strPtr = Tcl_GetStringFromObj( dataElems[i], NULL ); if( !strcmp(strPtr,"NULL") ) { bitArray[i] = 0; nulFlag[i] = 1; } else { ckfree( (char*)nulFlag ); ckfree( (char*)dataArray ); return TCL_ERROR; } } else { bitArray[i] = lVal; nulFlag[i] = 0; } } break; case TBYTE: case TSHORT: case TINT: colDataType = TLONG; /* Fallthrough */ case TLONG: lngArray = (long *) ckalloc(numRows * sizeof(long)); dataArray = lngArray; for ( i= 0; i < numRows; i++ ) { if( Tcl_GetLongFromObj( curFile->interp, dataElems[i], &lVal ) != TCL_OK ) { if( Tcl_GetDoubleFromObj( curFile->interp, dataElems[i], &dVal ) != TCL_OK ) { strPtr = Tcl_GetStringFromObj( dataElems[i], NULL ); if( !strcmp(strPtr,"NULL") ) { lngArray[i] = 0; nulFlag[i] = 1; } else { ckfree( (char*)nulFlag ); ckfree( (char*)dataArray ); return TCL_ERROR; } } else { lngArray[i] = dVal; nulFlag[i] = 0; } } else { lngArray[i] = lVal; nulFlag[i] = 0; } } break; case TFLOAT: colDataType = TDOUBLE; /* Fallthrough */ case TDOUBLE: dblArray = (double *) ckalloc(numRows * sizeof(double)); dataArray = dblArray; for ( i= 0; i < numRows; i++ ) { if( Tcl_GetDoubleFromObj( curFile->interp, dataElems[i], &dVal ) != TCL_OK ) { strPtr = Tcl_GetStringFromObj( dataElems[i], NULL ); if( !strcmp(strPtr,"NULL") ) { dblArray[i] = 0.0; nulFlag[i] = 1; } else { ckfree( (char*)nulFlag ); ckfree( (char*)dataArray ); return TCL_ERROR; } } else { dblArray[i] = dVal; nulFlag[i] = 0; } } break; case TLONGLONG: longlongArray = (LONGLONG *) ckalloc(numRows * sizeof(LONGLONG)); dataArray = longlongArray; for ( i= 0; i < numRows; i++ ) { strPtr = Tcl_GetStringFromObj( dataElems[i], NULL ); if ( !strcmp(strPtr,"NULL") ) { nulFlag[i] = 1; } else { nulFlag[i] = 0; } longlongArray[i] = fitsTcl_atoll(strPtr); } break; case TCOMPLEX: colDataType = TDBLCOMPLEX; /* Fallthrough */ case TDBLCOMPLEX: dblArray = (double *) ckalloc(2 * numRows * sizeof(double)); dataArray = dblArray; for ( i= 0; i < numRows; i++ ) { if( Tcl_ListObjGetElements( curFile->interp, dataElems[i], &nCpx, &cpxList ) != TCL_OK ) { ckfree( (char*)nulFlag ); ckfree( (char*)dataArray ); return TCL_ERROR; } if( nCpx < 0 || nCpx > 2 ) { Tcl_SetResult( curFile->interp, "Complex element did not contain " "1 or 2 values", TCL_STATIC ); ckfree( (char*)nulFlag ); ckfree( (char*)dataArray ); return TCL_ERROR; } if( Tcl_GetDoubleFromObj( curFile->interp, cpxList[0], &dVal ) != TCL_OK ) { strPtr = Tcl_GetStringFromObj( cpxList[0], NULL ); if( !strncmp(strPtr,"NULL",4) ) { dblArray[i+i] = 0.0; nulFlag[i] = 1; nCpx = 1; } else if( strchr(strPtr, ',') ) { dblArray[i+i] = atof(strPtr); if( nCpx==1 ) { strPtr = strchr(strPtr, ',') + 1; dblArray[i+i+1] = atof(strPtr); nCpx = 0; } nulFlag[i] = 0; } else { ckfree( (char*)nulFlag ); ckfree( (char*)dataArray ); return TCL_ERROR; } } else { dblArray[i+i] = dVal; nulFlag[i] = 0; } if( nCpx == 2 ) { if( Tcl_GetDoubleFromObj( curFile->interp, cpxList[1], &dVal ) != TCL_OK ) { ckfree( (char*)nulFlag ); ckfree( (char*)dataArray ); return TCL_ERROR; } else { dblArray[i+i+1] = dVal; } } else if( nCpx == 1 ) { /* Make explicit to allow fallthrough */ dblArray[i+i+1] = 0.0; } } break; default: Tcl_SetResult(curFile->interp, "fitsTcl Error: unknown column type", TCL_STATIC); ckfree( (char*)nulFlag ); return TCL_ERROR; } /* Write Data */ ffpcl(curFile->fptr, colDataType, colNum, firstRow, firstElem, numRows, dataArray, &status); ckfree( (char*)dataArray ); if ( status ) { dumpFitsErrStack(curFile->interp, status); ckfree( (char*)nulFlag ); return TCL_ERROR; } /* Flag Nulls */ if ( colVecSize == 1 || colDataType == TSTRING ) { for (i=0; i< numRows; i++) { if ( nulFlag[i] ) { ffpclu(curFile->fptr, colNum, firstRow+i, firstElem, 1, &status); if( status ) { dumpFitsErrStack(curFile->interp, status); ckfree( (char*)nulFlag ); return TCL_ERROR; } } } } else { for (i=0; i< numRows; i++) { if ( nulFlag[i] ) { ffpclu(curFile->fptr, colNum, firstRow, firstElem+i, 1, &status); if( status ) { dumpFitsErrStack(curFile->interp, status); ckfree( (char*)nulFlag ); return TCL_ERROR; } } } } ckfree((char *) nulFlag); return fitsUpdateFile(curFile); } int addColToTable( FitsFD *curFile, int colNum, char *ttype, char *tform ) { int status = 0; fficol(curFile->fptr, colNum, ttype, tform, &status); if( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } return fitsUpdateFile(curFile); } int addRowToTable( FitsFD *curFile, int rowNum, int nRows ) { int status = 0; ffirow(curFile->fptr, rowNum, nRows, &status); if( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } return fitsUpdateFile(curFile); } /* save to an image */ int varSaveToImage( FitsFD *curFile, long firstElem, long numElem, Tcl_Obj **listArray ) { int status = 0, i; void *dataArray; unsigned char *bytArray; short *shtArray; int *intArray; long *lngArray; float *fltArray; double *dblArray; LONGLONG *longlongArray; char *nulFlag; char *objStr; long longVal; double dblVal; nulFlag = (char *) ckalloc(numElem*sizeof(char)); switch ( curFile->CHDUInfo.image.dataType ) { case TBYTE: bytArray = (unsigned char *) ckalloc(numElem * sizeof(unsigned char)); for ( i= 0; i < numElem; i++, listArray++ ) { if( Tcl_GetLongFromObj( curFile->interp, *listArray, &longVal ) != TCL_OK ) { objStr = Tcl_GetStringFromObj( *listArray, NULL ); if( !strcmp(objStr, "NULL") ) { bytArray[i] = 0; nulFlag[i] = 1; } else { ckfree( (char*)bytArray ); ckfree( (char*)nulFlag ); return TCL_ERROR; } } else { bytArray[i] = longVal; nulFlag[i] = 0; } } dataArray = bytArray; break; case TSHORT: shtArray = (short *) ckalloc(numElem * sizeof(short)); for ( i= 0; i < numElem; i++, listArray++ ) { if( Tcl_GetLongFromObj( curFile->interp, *listArray, &longVal ) != TCL_OK ) { objStr = Tcl_GetStringFromObj( *listArray, NULL ); if( !strcmp(objStr, "NULL") ) { shtArray[i] = 0; nulFlag[i] = 1; } else { ckfree( (char*)shtArray ); ckfree( (char*)nulFlag ); return TCL_ERROR; } } else { shtArray[i] = longVal; nulFlag[i] = 0; } } dataArray = shtArray; break; case TINT: intArray = (int *) ckalloc(numElem* sizeof(int)); for ( i= 0; i < numElem; i++, listArray++ ) { if( Tcl_GetLongFromObj( curFile->interp, *listArray, &longVal ) != TCL_OK ) { objStr = Tcl_GetStringFromObj( *listArray, NULL ); if( !strcmp(objStr, "NULL") ) { intArray[i] = 0; nulFlag[i] = 1; } else { ckfree( (char*)intArray ); ckfree( (char*)nulFlag ); return TCL_ERROR; } } else { intArray[i] = longVal; nulFlag[i] = 0; } } dataArray = intArray; break; case TLONG: lngArray = (long *) ckalloc(numElem* sizeof(long)); for ( i= 0; i < numElem; i++, listArray++ ) { if( Tcl_GetLongFromObj( curFile->interp, *listArray, &longVal ) != TCL_OK ) { objStr = Tcl_GetStringFromObj( *listArray, NULL ); if( !strcmp(objStr, "NULL") ) { lngArray[i] = 0; nulFlag[i] = 1; } else { ckfree( (char*)lngArray ); ckfree( (char*)nulFlag ); return TCL_ERROR; } } else { lngArray[i] = longVal; nulFlag[i] = 0; } } dataArray = lngArray; break; case TFLOAT: fltArray = (float *) ckalloc(numElem* sizeof(float)); for ( i= 0; i < numElem; i++, listArray++ ) { if( Tcl_GetDoubleFromObj( curFile->interp, *listArray, &dblVal ) != TCL_OK ) { objStr = Tcl_GetStringFromObj( *listArray, NULL ); if( !strcmp(objStr, "NULL") ) { fltArray[i] = 0.0; nulFlag[i] = 1; } else { ckfree( (char*)fltArray ); ckfree( (char*)nulFlag ); return TCL_ERROR; } } else { fltArray[i] = dblVal; nulFlag[i] = 0; } } dataArray = fltArray; break; case TDOUBLE: dblArray = (double *) ckalloc(numElem* sizeof(double)); for ( i= 0; i < numElem; i++, listArray++ ) { if( Tcl_GetDoubleFromObj( curFile->interp, *listArray, &dblVal ) != TCL_OK ) { objStr = Tcl_GetStringFromObj( *listArray, NULL ); if( !strcmp(objStr, "NULL") ) { dblArray[i] = 0.0; nulFlag[i] = 1; } else { ckfree( (char*)dblArray ); ckfree( (char*)nulFlag ); return TCL_ERROR; } } else { dblArray[i] = dblVal; nulFlag[i] = 0; } } dataArray = dblArray; break; case TLONGLONG: longlongArray = (LONGLONG *) ckalloc(numElem* sizeof(LONGLONG)); for ( i= 0; i < numElem; i++, listArray++ ) { objStr = Tcl_GetStringFromObj( *listArray, NULL ); if ( !strcmp(objStr, "NULL") ) { nulFlag[i] = 1; } else { nulFlag[i] = 0; } longlongArray[i] = fitsTcl_atoll(objStr); } dataArray = longlongArray; break; default: Tcl_SetResult(curFile->interp, "fitsTcl Error: unknown image type", TCL_STATIC); ckfree( (char*)nulFlag ); return TCL_ERROR; } /* Write Data */ ffppr(curFile->fptr, curFile->CHDUInfo.image.dataType, firstElem, numElem, dataArray, &status); ckfree((char *) dataArray); if ( status ) { dumpFitsErrStack(curFile->interp, status); ckfree((char *) nulFlag); return TCL_ERROR; } /* Flag Nulls */ for (i=0;ifptr, 1, firstElem+i, 1, &status); if( status ) { dumpFitsErrStack(curFile->interp, status); ckfree((char *) nulFlag); return TCL_ERROR; } } } ckfree((char *) nulFlag); return fitsUpdateFile(curFile); } int fitsCopyCHduToFile( FitsFD *curFile, char *newfilename ) { fitsfile *newFptr; int status = 0; remove(newfilename); ffinit(&newFptr, newfilename, &status); if( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } if ( curFile->hduType != IMAGE_HDU ) { ffphpr(newFptr, 1, 32, 0, NULL, 0, 1, 1, &status); ffcrhd(newFptr, &status); if( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } } ffcopy(curFile->fptr, newFptr, 0, &status); ffclos(newFptr, &status) ; if ( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } return TCL_OK; } int fitsAppendCHduToFile( FitsFD *curFile, char *targetfilename ) { fitsfile *targFptr; int status = 0; int nhdu, hdutype; /* Do everything... then check status */ ffopen(&targFptr, targetfilename, 1, &status); ffthdu(targFptr, &nhdu, &status); ffmahd(targFptr, nhdu, &hdutype, &status); ffcrhd(targFptr, &status); ffcopy(curFile->fptr, targFptr, 0, &status); ffclos(targFptr, &status) ; if ( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } return TCL_OK; } int fitsPutHisKwd( FitsFD *curFile, char *his ) { int status = 0; ffphis(curFile->fptr, his, &status); if ( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } return fitsUpdateFile(curFile); } /*********************************************************************/ /* W C S */ /* */ /* extract the world coordinate from a header, return in Matrix form */ /* */ /*********************************************************************/ int fitsFileGetWcsMatrix( FitsFD *curFile, fitsfile *dummyFile, int naxis, int axes[], char dest, Tcl_Obj *data[]) { int status = 0; int foundCD= 0; int foundTp= 0; int foundBK= 0; int endBK= 0; int i = 0; double refVal[FITS_MAXDIMS], refPix[FITS_MAXDIMS]; double delt[FITS_MAXDIMS], rot; double matrix[FITS_MAXDIMS][FITS_MAXDIMS]; int row, col, axisNum[FITS_MAXDIMS]; char keyword[FLEN_VALUE]; char axisType[FITS_MAXDIMS][FLEN_VALUE]; int isImage; static char *Keys[2][7] = { { "TCTYP", "TCUNI", "TCRVL", "TCRPX", "TCD", "TCDLT", "TCROT" }, { "CTYPE", "CUNIT", "CRVAL", "CRPIX", "CD", "CDELT", "CROTA" } }; enum { cType=0, cUnit, cRefVal, cRefPix, cMatrix, cDelta, cRota }; /* Init Variables */ if( naxis ) { isImage = 1; for( row=0; row1 ) { sprintf(keyword,"%s%d%c", Keys[isImage][cRota], axisNum[1], dest); ffgkyd(dummyFile, keyword, &rot, NULL, &status); if( status==KEY_NO_EXIST ) { /* Try other column */ status = 0; if( !isImage ) { sprintf(keyword,"%s%d%c", Keys[isImage][cRota], axisNum[0], dest); ffgkyd(dummyFile, keyword, &rot,NULL, &status); if( status==KEY_NO_EXIST ) status=0; else rot = -rot; } } rot *= 1.745329252e-2; } for( col=0; colinterp, data[0], Tcl_NewDoubleObj(refVal[row]) ); Tcl_ListObjAppendElement(curFile->interp, data[1], Tcl_NewDoubleObj(refPix[row]) ); for( col=0; colinterp, data[2], Tcl_NewDoubleObj(matrix[row][col]) ); /* if( foundTp == naxis ) { */ if( foundTp > 0 ) { /* Pan: find out where the break point "-" is */ foundBK = 0; endBK = -1; for ( i=0; i< strlen(axisType[row]); i++) { if (foundBK == 0 && axisType[row][i] == '-') { foundBK = 1; } if ( foundBK == 1 && axisType[row][i] != '-' ) { endBK = i - 1; break; } } if ( endBK >= 0 ) { Tcl_ListObjAppendElement(curFile->interp, data[4], Tcl_NewStringObj(axisType[row]+endBK,-1) ); } else { Tcl_ListObjAppendElement(curFile->interp, data[4], Tcl_NewListObj(0,NULL)); } for( col=endBK; col>0 && axisType[row][col]=='-'; ) axisType[row][col--] = '\0'; } Tcl_ListObjAppendElement(curFile->interp, data[3], Tcl_NewStringObj(axisType[row],-1) ); } Tcl_SetObjResult(curFile->interp, Tcl_NewListObj(5,data) ); return TCL_OK; } int fitsGetWcsMatrix( FitsFD *curFile, int naxis, int axes[], char dest ) { int status = 0; int foundCD= 0; int foundTp= 0; int foundBK= 0; int endBK= 0; int i = 0; double refVal[FITS_MAXDIMS], refPix[FITS_MAXDIMS]; double delt[FITS_MAXDIMS], rot; double matrix[FITS_MAXDIMS][FITS_MAXDIMS]; int row, col, axisNum[FITS_MAXDIMS]; char keyword[FLEN_VALUE]; char axisType[FITS_MAXDIMS][FLEN_VALUE]; Tcl_Obj *data[5]; int isImage; static char *Keys[2][7] = { { "TCTYP", "TCUNI", "TCRVL", "TCRPX", "TCD", "TCDLT", "TCROT" }, { "CTYPE", "CUNIT", "CRVAL", "CRPIX", "CD", "CDELT", "CROTA" } }; enum { cType=0, cUnit, cRefVal, cRefPix, cMatrix, cDelta, cRota }; /* Init Variables */ if( naxis ) { isImage = 0; for( row=0; rowCHDUInfo.image.naxes; for( row=0; rowfptr, keyword, refVal+row, NULL, &status); if( status==KEY_NO_EXIST ) status = 0; sprintf(keyword, "%s%d%c", Keys[isImage][cRefPix], axisNum[row], dest); ffgkyd(curFile->fptr, keyword, refPix+row, NULL, &status); if( status==KEY_NO_EXIST ) status = 0; sprintf(keyword, "%s%d%c", Keys[isImage][cType], axisNum[row], dest); axisType[row][0] = '\0'; ffgkys(curFile->fptr, keyword, axisType[row], NULL, &status); if( status==KEY_NO_EXIST ) { status = 0; memset(axisType[row], '\0', FITS_MAXDIMS * FITS_MAXDIMS ); foundTp++; } else if( !status ) { /* Pan: find out if a break point "-" exist */ foundBK = 0; for ( i=0; i< strlen(axisType[row]); i++) { if (axisType[row][i] == '-') { foundBK = 1; break; } } /* Pan: if( strlen(axisType[row])==8 && axisType[row][4]=='-' ) */ /* if( strlen(axisType[row])==8 && foundBK == 1) */ if( foundBK == 1) foundTp++; } for( col=0; colfptr, keyword, &matrix[row][col], NULL, &status); if( status==0 ) foundCD = 1; else if( status==KEY_NO_EXIST ) status = 0; } } if( !foundCD ) { rot = 0.0; if( naxis>1 ) { sprintf(keyword,"%s%d%c", Keys[isImage][cRota], axisNum[1], dest); ffgkyd(curFile->fptr, keyword, &rot, NULL, &status); if( status==KEY_NO_EXIST ) { /* Try other column */ status = 0; if( !isImage ) { sprintf(keyword,"%s%d%c", Keys[isImage][cRota], axisNum[0], dest); ffgkyd(curFile->fptr, keyword, &rot,NULL, &status); if( status==KEY_NO_EXIST ) status=0; else rot = -rot; } } rot *= 1.745329252e-2; } for( col=0; colfptr, keyword, delt+col, NULL, &status); if( status==KEY_NO_EXIST ) status = 0; if( col<2 ) { for( row=0; rowinterp, data[0], Tcl_NewDoubleObj(refVal[row]) ); Tcl_ListObjAppendElement(curFile->interp, data[1], Tcl_NewDoubleObj(refPix[row]) ); for( col=0; colinterp, data[2], Tcl_NewDoubleObj(matrix[row][col]) ); /* if( foundTp == naxis ) { */ if( foundTp > 0 ) { /* Pan: find out where the break point "-" is */ foundBK = 0; endBK = -1; for ( i=0; i< strlen(axisType[row]); i++) { if (foundBK == 0 && axisType[row][i] == '-') { foundBK = 1; } if ( foundBK == 1 && axisType[row][i] != '-' ) { endBK = i - 1; break; } } /* Tcl_ListObjAppendElement(curFile->interp, data[4], Tcl_NewStringObj(axisType[row]+endBK,-1) ); */ if ( endBK >= 0 ) { Tcl_ListObjAppendElement(curFile->interp, data[4], Tcl_NewStringObj(axisType[row]+endBK,-1) ); } else { Tcl_ListObjAppendElement(curFile->interp, data[4], Tcl_NewListObj(0,NULL)); } for( col=endBK; col>0 && axisType[row][col]=='-'; ) axisType[row][col--] = '\0'; } Tcl_ListObjAppendElement(curFile->interp, data[3], Tcl_NewStringObj(axisType[row],-1) ); } Tcl_SetObjResult(curFile->interp, Tcl_NewListObj(5,data) ); ffcmsg(); return TCL_OK; } int fitsGetWcsMatrixAlt( FitsFD *curFile, fitsfile *fptr, Tcl_Obj *listObj, int naxis, int axes[], char dest ) { int status = 0; int foundCD= 0; int foundTp= 0; int foundBK= 0; int endBK= 0; int i = 0; double refVal[FITS_MAXDIMS], refPix[FITS_MAXDIMS]; double delt[FITS_MAXDIMS], rot; double matrix[FITS_MAXDIMS][FITS_MAXDIMS]; int row, col, axisNum[FITS_MAXDIMS]; char keyword[FLEN_VALUE]; char axisType[FITS_MAXDIMS][FLEN_VALUE]; Tcl_Obj *data[5]; int isImage; static char *Keys[2][7] = { { "TCTYP", "TCUNI", "TCRVL", "TCRPX", "TCD", "TCDLT", "TCROT" }, { "CTYPE", "CUNIT", "CRVAL", "CRPIX", "CD", "CDELT", "CROTA" } }; enum { cType=0, cUnit, cRefVal, cRefPix, cMatrix, cDelta, cRota }; /* Init Variables */ if( naxis ) { isImage = 0; for( row=0; row1 ) { sprintf(keyword,"%s%d%c", Keys[isImage][cRota], axisNum[1], dest); ffgkyd(fptr, keyword, &rot, NULL, &status); if( status==KEY_NO_EXIST ) { /* Try other column */ status = 0; if( !isImage ) { sprintf(keyword,"%s%d%c", Keys[isImage][cRota], axisNum[0], dest); ffgkyd(fptr, keyword, &rot,NULL, &status); if( status==KEY_NO_EXIST ) status=0; else rot = -rot; } } rot *= 1.745329252e-2; } for( col=0; colinterp, data[0], Tcl_NewDoubleObj(refVal[row]) ); Tcl_ListObjAppendElement(curFile->interp, data[1], Tcl_NewDoubleObj(refPix[row]) ); for( col=0; colinterp, data[2], Tcl_NewDoubleObj(matrix[row][col]) ); /* if( foundTp == naxis ) { */ if( foundTp > 0 ) { /* Pan: find out where the break point "-" is */ foundBK = 0; endBK = -1; for ( i=0; i< strlen(axisType[row]); i++) { if (foundBK == 0 && axisType[row][i] == '-') { foundBK = 1; } if ( foundBK == 1 && axisType[row][i] != '-' ) { endBK = i - 1; break; } } /* Tcl_ListObjAppendElement(curFile->interp, data[4], Tcl_NewStringObj(axisType[row]+endBK,-1) ); */ if ( endBK >= 0 ) { Tcl_ListObjAppendElement(curFile->interp, data[4], Tcl_NewStringObj(axisType[row]+endBK,-1) ); } else { Tcl_ListObjAppendElement(curFile->interp, data[4], Tcl_NewListObj(0,NULL)); } for( col=endBK; col>0 && axisType[row][col]=='-'; ) axisType[row][col--] = '\0'; } Tcl_ListObjAppendElement(curFile->interp, data[3], Tcl_NewStringObj(axisType[row],-1) ); } Tcl_ListObjAppendElement( curFile->interp, listObj, Tcl_NewListObj(5,data) ); Tcl_SetObjResult(curFile->interp, listObj); ffcmsg(); return TCL_OK; } int fitsGetWcsPairAlt( FitsFD *curFile, fitsfile *fptr, Tcl_Obj *listObj, int Col1, int Col2, char dest ) { int status = 0; int swap = 0; double xrval = 0.0, yrval = 0.0, xrpix = 0.0, yrpix = 0.0, xinc = 1.0, yinc = 1.0, rot = 0.0; char ctype[FLEN_VALUE], ctemp[FLEN_VALUE]; char keyword[FLEN_VALUE]; double matrix[FITS_MAXDIMS][FITS_MAXDIMS],temp; int anyKeysFnd; Tcl_Obj *data[9]; int isImage; static char *Keys[2][7] = { { "TCTYP", "TCUNI", "TCRVL", "TCRPX", "TCD", "TCDLT", "TCROT" }, { "CTYPE", "CUNIT", "CRVAL", "CRPIX", "CD", "CDELT", "CROTA" } }; enum { cType=0, cUnit, cRefVal, cRefPix, cMatrix, cDelta, cRota }; if( Col1 && Col2 ) { isImage = 0; } else { isImage = 1; Col1 = 1; Col2 = 2; } /* Grab any existing WCS keywords. Use defaults for missing values */ sprintf(keyword, "%s%d%c", Keys[isImage][cRefVal], Col1, dest); ffgkyd(fptr, keyword, &xrval, NULL, &status); if( status==KEY_NO_EXIST ) status = 0; sprintf(keyword, "%s%d%c", Keys[isImage][cRefVal], Col2, dest); ffgkyd(fptr, keyword, &yrval, NULL, &status); if( status==KEY_NO_EXIST ) status = 0; sprintf(keyword, "%s%d%c", Keys[isImage][cRefPix], Col1, dest); ffgkyd(fptr, keyword, &xrpix, NULL, &status); if( status==KEY_NO_EXIST ) status = 0; sprintf(keyword, "%s%d%c", Keys[isImage][cRefPix], Col2, dest); ffgkyd(fptr, keyword, &yrpix, NULL, &status); if( status==KEY_NO_EXIST ) status = 0; anyKeysFnd = 0; sprintf(keyword, "%s%d%c", Keys[isImage][cDelta], Col1, dest); ffgkyd(fptr, keyword, &xinc, NULL, &status); if( status==KEY_NO_EXIST ) status = 0; else anyKeysFnd++; sprintf(keyword, "%s%d%c", Keys[isImage][cDelta], Col2, dest); ffgkyd(fptr, keyword, &yinc, NULL, &status); if( status==KEY_NO_EXIST ) status = 0; else anyKeysFnd++; sprintf(keyword, "%s%d%c", Keys[isImage][cRota], Col2, dest); ffgkyd(fptr, keyword, &rot, NULL, &status); if( status==KEY_NO_EXIST ) { /* Try other column */ status = 0; if( !isImage ) { sprintf(keyword, "%s%d%c", Keys[isImage][cRota], Col1, dest); ffgkyd(fptr, keyword, &rot, NULL, &status); if( status==KEY_NO_EXIST ) { status=0; } else { rot = -rot; anyKeysFnd++; } } } else anyKeysFnd++; if( ! anyKeysFnd ) { /* Couldn't find old-style keys; look for new-style */ anyKeysFnd = 0; matrix[0][0] = 1.0; sprintf(keyword, "%s%d_%d%c", Keys[isImage][cMatrix], Col1, Col1, dest); ffgkyd(fptr, keyword, &matrix[0][0], NULL, &status); if( status==KEY_NO_EXIST ) status = 0; else anyKeysFnd++; matrix[1][1] = 1.0; sprintf(keyword, "%s%d_%d%c", Keys[isImage][cMatrix], Col2, Col2, dest); ffgkyd(fptr, keyword, &matrix[1][1], NULL, &status); if( status==KEY_NO_EXIST ) status = 0; else anyKeysFnd++; matrix[0][1] = 0.0; sprintf(keyword, "%s%d_%d%c", Keys[isImage][cMatrix], Col1, Col2, dest); ffgkyd(fptr, keyword, &matrix[0][1], NULL, &status); if( status==KEY_NO_EXIST ) status = 0; else anyKeysFnd++; matrix[1][0] = 0.0; sprintf(keyword, "%s%d_%d%c", Keys[isImage][cMatrix], Col2, Col1, dest); ffgkyd(fptr, keyword, &matrix[1][0], NULL, &status); if( status==KEY_NO_EXIST ) status = 0; else anyKeysFnd++; if( anyKeysFnd ) { /* Modified from CFITSIO... compute old-style from new-style */ double phia, phib; double pi = 3.1415926535897932; /* there are 2 ways to compute the angle: */ phia = atan2( matrix[1][0], matrix[0][0]); phib = atan2(-matrix[0][1], matrix[1][1]); /* ensure that phia <= phib */ temp = minvalue(phia, phib); phib = maxvalue(phia, phib); phia = temp; /* there is a possible 180 degree ambiguity in the angles */ /* so add 180 degress to the smaller value if the values */ /* differ by more than 90 degrees = pi/2 radians. */ /* (Later, we may decide to take the other solution by */ /* subtracting 180 degrees from the larger value). */ if( (phib - phia) > (pi * 0.5) ) phia += pi; if( fabs(phia - phib) > 0.0002 ) { /* angles don't agree, so looks like there is some skewness */ /* between the axes. Return with an error to be safe. */ /* PDW: Lets just ignore this and give the best estimate we can. status = APPROX_WCS_KEY; */ } phia = (phia + phib) * 0.5; /* use the average of the 2 values */ temp = cos(phia); if( fabs(temp)<0.1 ) { temp = sin(phia); xinc = matrix[1][0] / temp; yinc =-matrix[0][1] / temp; } else { xinc = matrix[0][0] / temp; yinc = matrix[1][1] / temp; } rot = phia * 180. / pi; /* common usage is to have a positive yinc value. If it is */ /* negative, then subtract 180 degrees from rot and negate */ /* both xinc and yinc. */ if( yinc < 0 ) { xinc = -xinc; yinc = -yinc; rot -= 180.0; } } /* else keep default delt/rot = 1/0 */ } /* Read both RA and DEC CTYPs to check that they both exist and agree */ sprintf(keyword, "%s%d%c", Keys[isImage][cType], Col1, dest); ffgkys(fptr, keyword, ctype, NULL, &status); sprintf(keyword, "%s%d%c", Keys[isImage][cType], Col2, dest); ffgkys(fptr, keyword, ctemp, NULL, &status); if( status || strlen(ctype)<5 || strlen(ctemp)<5 || strcmp(ctype+4,ctemp+4) ) { strcpy(ctype,"none"); status = 0; } else { if( !strncmp(ctype, "DEC-", 4) || !strncmp(ctype+1, "LAT", 3) ) { /* RA/Dec are swapped!!! */ swap = 1; } /* copy the projection type string */ strncpy(ctype, &ctype[4], 4); ctype[4] = '\0'; } data[0] = Tcl_NewDoubleObj(xrval); data[1] = Tcl_NewDoubleObj(yrval); data[2] = Tcl_NewDoubleObj(xrpix); data[3] = Tcl_NewDoubleObj(yrpix); data[4] = Tcl_NewDoubleObj(xinc); data[5] = Tcl_NewDoubleObj(yinc); data[6] = Tcl_NewDoubleObj(rot); data[7] = Tcl_NewStringObj(ctype,-1); if( userOptions.wcsSwap ) { data[8] = Tcl_NewBooleanObj( swap ); Tcl_ListObjAppendElement(curFile->interp, listObj, Tcl_NewListObj(9,data) ); } else { Tcl_ListObjAppendElement(curFile->interp, listObj, Tcl_NewListObj(8,data) ); } ffcmsg(); Tcl_SetObjResult(curFile->interp, listObj); return TCL_OK; } /* extract the world coordinate from a table */ /* (Old behavior... deprecated) */ /* extract the world coordinate from an image header */ int fitsGetWcsPair( FitsFD *curFile, int Col1, int Col2, char dest ) { int status = 0; int swap = 0; double xrval = 0.0, yrval = 0.0, xrpix = 0.0, yrpix = 0.0, xinc = 1.0, yinc = 1.0, rot = 0.0; char ctype[FLEN_VALUE], ctemp[FLEN_VALUE]; char keyword[FLEN_VALUE]; double matrix[FITS_MAXDIMS][FITS_MAXDIMS],temp; int anyKeysFnd; Tcl_Obj *data[9]; int isImage; static char *Keys[2][7] = { { "TCTYP", "TCUNI", "TCRVL", "TCRPX", "TCD", "TCDLT", "TCROT" }, { "CTYPE", "CUNIT", "CRVAL", "CRPIX", "CD", "CDELT", "CROTA" } }; enum { cType=0, cUnit, cRefVal, cRefPix, cMatrix, cDelta, cRota }; if( Col1 && Col2 ) { isImage = 0; } else { isImage = 1; Col1 = 1; Col2 = 2; } /* Grab any existing WCS keywords. Use defaults for missing values */ sprintf(keyword, "%s%d%c", Keys[isImage][cRefVal], Col1, dest); ffgkyd(curFile->fptr, keyword, &xrval, NULL, &status); if( status==KEY_NO_EXIST ) status = 0; sprintf(keyword, "%s%d%c", Keys[isImage][cRefVal], Col2, dest); ffgkyd(curFile->fptr, keyword, &yrval, NULL, &status); if( status==KEY_NO_EXIST ) status = 0; sprintf(keyword, "%s%d%c", Keys[isImage][cRefPix], Col1, dest); ffgkyd(curFile->fptr, keyword, &xrpix, NULL, &status); if( status==KEY_NO_EXIST ) status = 0; sprintf(keyword, "%s%d%c", Keys[isImage][cRefPix], Col2, dest); ffgkyd(curFile->fptr, keyword, &yrpix, NULL, &status); if( status==KEY_NO_EXIST ) status = 0; anyKeysFnd = 0; sprintf(keyword, "%s%d%c", Keys[isImage][cDelta], Col1, dest); ffgkyd(curFile->fptr, keyword, &xinc, NULL, &status); if( status==KEY_NO_EXIST ) status = 0; else anyKeysFnd++; sprintf(keyword, "%s%d%c", Keys[isImage][cDelta], Col2, dest); ffgkyd(curFile->fptr, keyword, &yinc, NULL, &status); if( status==KEY_NO_EXIST ) status = 0; else anyKeysFnd++; sprintf(keyword, "%s%d%c", Keys[isImage][cRota], Col2, dest); ffgkyd(curFile->fptr, keyword, &rot, NULL, &status); if( status==KEY_NO_EXIST ) { /* Try other column */ status = 0; if( !isImage ) { sprintf(keyword, "%s%d%c", Keys[isImage][cRota], Col1, dest); ffgkyd(curFile->fptr, keyword, &rot, NULL, &status); if( status==KEY_NO_EXIST ) { status=0; } else { rot = -rot; anyKeysFnd++; } } } else anyKeysFnd++; if( ! anyKeysFnd ) { /* Couldn't find old-style keys; look for new-style */ anyKeysFnd = 0; matrix[0][0] = 1.0; sprintf(keyword, "%s%d_%d%c", Keys[isImage][cMatrix], Col1, Col1, dest); ffgkyd(curFile->fptr, keyword, &matrix[0][0], NULL, &status); if( status==KEY_NO_EXIST ) status = 0; else anyKeysFnd++; matrix[1][1] = 1.0; sprintf(keyword, "%s%d_%d%c", Keys[isImage][cMatrix], Col2, Col2, dest); ffgkyd(curFile->fptr, keyword, &matrix[1][1], NULL, &status); if( status==KEY_NO_EXIST ) status = 0; else anyKeysFnd++; matrix[0][1] = 0.0; sprintf(keyword, "%s%d_%d%c", Keys[isImage][cMatrix], Col1, Col2, dest); ffgkyd(curFile->fptr, keyword, &matrix[0][1], NULL, &status); if( status==KEY_NO_EXIST ) status = 0; else anyKeysFnd++; matrix[1][0] = 0.0; sprintf(keyword, "%s%d_%d%c", Keys[isImage][cMatrix], Col2, Col1, dest); ffgkyd(curFile->fptr, keyword, &matrix[1][0], NULL, &status); if( status==KEY_NO_EXIST ) status = 0; else anyKeysFnd++; if( anyKeysFnd ) { /* Modified from CFITSIO... compute old-style from new-style */ double phia, phib; double pi = 3.1415926535897932; /* there are 2 ways to compute the angle: */ phia = atan2( matrix[1][0], matrix[0][0]); phib = atan2(-matrix[0][1], matrix[1][1]); /* ensure that phia <= phib */ temp = minvalue(phia, phib); phib = maxvalue(phia, phib); phia = temp; /* there is a possible 180 degree ambiguity in the angles */ /* so add 180 degress to the smaller value if the values */ /* differ by more than 90 degrees = pi/2 radians. */ /* (Later, we may decide to take the other solution by */ /* subtracting 180 degrees from the larger value). */ if( (phib - phia) > (pi * 0.5) ) phia += pi; if( fabs(phia - phib) > 0.0002 ) { /* angles don't agree, so looks like there is some skewness */ /* between the axes. Return with an error to be safe. */ /* PDW: Lets just ignore this and give the best estimate we can. status = APPROX_WCS_KEY; */ } phia = (phia + phib) * 0.5; /* use the average of the 2 values */ temp = cos(phia); if( fabs(temp)<0.1 ) { temp = sin(phia); xinc = matrix[1][0] / temp; yinc =-matrix[0][1] / temp; } else { xinc = matrix[0][0] / temp; yinc = matrix[1][1] / temp; } rot = phia * 180. / pi; /* common usage is to have a positive yinc value. If it is */ /* negative, then subtract 180 degrees from rot and negate */ /* both xinc and yinc. */ if( yinc < 0 ) { xinc = -xinc; yinc = -yinc; rot -= 180.0; } } /* else keep default delt/rot = 1/0 */ } /* Read both RA and DEC CTYPs to check that they both exist and agree */ sprintf(keyword, "%s%d%c", Keys[isImage][cType], Col1, dest); ffgkys(curFile->fptr, keyword, ctype, NULL, &status); sprintf(keyword, "%s%d%c", Keys[isImage][cType], Col2, dest); ffgkys(curFile->fptr, keyword, ctemp, NULL, &status); if( status || strlen(ctype)<5 || strlen(ctemp)<5 || strcmp(ctype+4,ctemp+4) ) { strcpy(ctype,"none"); status = 0; } else { if( !strncmp(ctype, "DEC-", 4) || !strncmp(ctype+1, "LAT", 3) ) { /* RA/Dec are swapped!!! */ swap = 1; } /* copy the projection type string */ strncpy(ctype, &ctype[4], 4); ctype[4] = '\0'; } data[0] = Tcl_NewDoubleObj(xrval); data[1] = Tcl_NewDoubleObj(yrval); data[2] = Tcl_NewDoubleObj(xrpix); data[3] = Tcl_NewDoubleObj(yrpix); data[4] = Tcl_NewDoubleObj(xinc); data[5] = Tcl_NewDoubleObj(yinc); data[6] = Tcl_NewDoubleObj(rot); data[7] = Tcl_NewStringObj(ctype,-1); if( userOptions.wcsSwap ) { data[8] = Tcl_NewBooleanObj( swap ); Tcl_SetObjResult(curFile->interp, Tcl_NewListObj(9,data) ); } else { Tcl_SetObjResult(curFile->interp, Tcl_NewListObj(8,data) ); } ffcmsg(); return TCL_OK; } /* extract the world coordinate from a table */ /* (Old behavior... deprecated) */ int fitsTableGetWcsOld( FitsFD *curFile, int RAColNum, int DecColNum ) { int status = 0; double xrval, yrval, xrpix, yrpix, xinc, yinc, rot; char ctype[5]; Tcl_Obj *data[8]; ffgtcs(curFile->fptr, RAColNum, DecColNum, &xrval, &yrval, &xrpix, &yrpix, &xinc, &yinc, &rot, ctype, &status); if ( status ) { /* if there is no wcs info , keep silent */ Tcl_SetResult(curFile->interp, "", TCL_STATIC); ffcmsg(); return TCL_OK; } data[0] = Tcl_NewDoubleObj(xrval); data[1] = Tcl_NewDoubleObj(yrval); data[2] = Tcl_NewDoubleObj(xrpix); data[3] = Tcl_NewDoubleObj(yrpix); data[4] = Tcl_NewDoubleObj(xinc); data[5] = Tcl_NewDoubleObj(yinc); data[6] = Tcl_NewDoubleObj(rot); data[7] = Tcl_NewStringObj(ctype,-1); Tcl_SetObjResult(curFile->interp, Tcl_NewListObj(8,data) ); return TCL_OK; } /***********************************************************************/ /* */ /* End of WCS Routines */ /***********************************************************************/ int fitsReadColData( FitsFD *curFile, int colNum, int strSize, colData columndata[], int *dataType ) { long numRows, i, vecSize; int status = 0; char **tmpPtr; char *nullArray=NULL; int anyf; int colType; double *tmpDbl; LONGLONG *tmpLonglong; long *tmpLong; char *tmpChar; char *cPtr; colType = curFile->CHDUInfo.table.colDataType[colNum-1]; vecSize = curFile->CHDUInfo.table.vecSize[colNum-1]; numRows = curFile->CHDUInfo.table.numRows; nullArray = (char *) ckalloc(numRows*sizeof(char)); switch ( colType ) { case TSTRING: tmpPtr = (char **) makeContigArray(1, strSize+1, 'c'); for (i=0;ifptr, colNum, i+1, 1, 1, 1, "NULL", tmpPtr, nullArray, &anyf, &status); if ( status ) { status = 0; strcpy(tmpPtr[0], ""); ffcmsg(); } columndata[i].strData = (char *)ckalloc( (strSize+1)*sizeof(char) ); cPtr = tmpPtr[0]; while ( *cPtr == ' ') cPtr++; strcpy(columndata[i].strData, cPtr); } ckfree((char *) tmpPtr[0]); ckfree((char *) tmpPtr); *dataType = 0; break; case TSHORT: case TINT: case TBYTE: case TLONG: tmpLong = (long *) ckalloc(numRows*sizeof(long)); ffgclj(curFile->fptr, colNum, 1, 1, numRows, vecSize, 1, LONG_MAX, tmpLong, nullArray, &anyf, &status); for (i=0; i< numRows; i++) columndata[i].intData = tmpLong[i]; *dataType = 1; ckfree((char *)tmpLong); break; case TBIT: tmpChar = (char *) ckalloc(1*sizeof(char)); for (i=0;ifptr, colNum, i+1, 1, 1, tmpChar, &status); columndata[i].intData = tmpChar[0]; } *dataType = 1; ckfree((char *)tmpChar); break; case TLOGICAL: tmpChar = (char *) ckalloc(numRows*sizeof(char)); ffgcfl(curFile->fptr, colNum, 1, 1, numRows, tmpChar, nullArray, &anyf, &status); for (i=0; i< numRows; i++) { if ( nullArray[i] ) { columndata[i].intData = 2; } else { columndata[i].intData = tmpChar[i]; } } *dataType = 1; ckfree((char *)tmpChar ); break; case TFLOAT: case TDOUBLE: tmpDbl = (double *) ckalloc(numRows*sizeof(double)); ffgcld(curFile->fptr, colNum, 1, 1, numRows, vecSize, 1, DBL_MAX, tmpDbl, nullArray, &anyf, &status); for (i = 0; i < numRows; i++ ) columndata[i].dblData = tmpDbl[i]; *dataType = 2; ckfree((char *) tmpDbl); break; case TLONGLONG: tmpLonglong = (LONGLONG *) ckalloc(numRows*sizeof(LONGLONG)); ffgcljj(curFile->fptr, colNum, 1, 1, numRows, vecSize, 1, (LONGLONG)NULL, tmpLonglong, nullArray, &anyf, &status); for (i = 0; i < numRows; i++ ) columndata[i].longlongData = tmpLonglong[i]; *dataType = 3; ckfree((char *) tmpLonglong); break; default: Tcl_SetResult(curFile->interp, "fitsTcl ERROR: unknown column type", TCL_STATIC); return TCL_ERROR; } ckfree((char *)nullArray); return TCL_OK; } int fitsReadRawColData( FitsFD *curFile, colData columndata[], LONGLONG *rowSize ) { long numRows, i; int status = 0; long *tbcol; numRows = curFile->CHDUInfo.table.numRows; if ( ASCII_TBL == curFile->hduType ) { /* tbcol = (long *) ckalloc(curFile->CHDUInfo.table.numCols*sizeof(long)); ffgabc(curFile->CHDUInfo.table.numCols, curFile->CHDUInfo.table.colType, 1, rowSize, tbcol, &status); */ *rowSize =curFile->CHDUInfo.table.rowLen; } else if ( BINARY_TBL == curFile->hduType) { /* ffgtbc(curFile->fptr, rowSize, &status); */ *rowSize =curFile->CHDUInfo.table.rowLen; } else { Tcl_SetResult(curFile->interp, "fitsTcl ERROR:unknown table type", TCL_STATIC); return TCL_ERROR; } if ( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } for (i = 0; i < numRows; i++ ) { columndata[i].rowindex = i+1; columndata[i].colBuffer = (unsigned char *) ckalloc( *rowSize * sizeof(unsigned char) ); ffgtbb(curFile->fptr, i+1, 1, *rowSize, columndata[i].colBuffer, &status); if ( status ) { status = 0; ffcmsg(); } columndata[i].flag = 0; /* Init flag values */ } return TCL_OK; } int fitsSortTable( FitsFD *curFile, int numCols, int *colNum, int *strSize, int *isAscend, int isMerge ) { int result, i, j, k; colData *columndata; int dataType; long *bottom; long *top; long nrange=0, numRows, uniqueNum; LONGLONG rowSize; char ** rowlist; numRows = curFile->CHDUInfo.table.numRows; columndata = (colData *) ckalloc(numRows*sizeof(colData)); /* read in raw table data in rows */ result = fitsReadRawColData(curFile, columndata, &rowSize); if (result != TCL_OK) { ckfree((char *) columndata); return TCL_ERROR; } rowlist = (char **) ckalloc(numRows*sizeof(char*)); for (i=0; i0 ; i++ ) { result = fitsReadColData(curFile, colNum[i], strSize[i], columndata, &dataType); if (result != TCL_OK) { fitsFreeRawColData( columndata, numRows ); ckfree((char *) columndata); return TCL_ERROR; } /* allocate top and bottom */ top = (long *)ckalloc(nrange*sizeof(long)); bottom = (long *)ckalloc(nrange*sizeof(long)); if( i ) { fitsGetSortRange(columndata, numRows, top, bottom); } else { fitsRandomizeColData( columndata, numRows ); top[0] = numRows-1; bottom[0] = 0; } /* do sorting when there are identical keys */ for ( j=0; j < nrange; j++ ) { for ( k=bottom[j]; k<=top[j]; k++ ) { if (dataType == 0 && (strcmp(columndata[k].strData,"NULL") == 0)) { strcpy(columndata[k].strData, "\0"); } else { columndata[k].flag = 0; } } fitsQuickSort(columndata, dataType, strSize[i], bottom[j], top[j], isAscend[i]); fitsQSsetFlag(columndata, dataType, strSize[i], bottom[j], top[j]); } ckfree((char *) top); ckfree((char *) bottom); if (dataType == 0) for ( j=0; j< numRows; j++) ckfree((char *) columndata[j].strData); /* before read more keys, write the sorted buffer to file */ result = fitsWriteRowsToFile(curFile, rowSize, columndata, ( i+1 == numCols ? isMerge : 0 ) ); if (result != TCL_OK) { fitsFreeRawColData( columndata, numRows ); ckfree((char *) columndata); return TCL_ERROR; } /* prepare for the next key */ fitsGetSortRangeNum(columndata, numRows, &nrange); } /* numRows = curFile->CHDUInfo.table.numRows; */ uniqueNum = 0; if (isMerge == 0 ) { for (i=0; iinterp,Tcl_Merge(uniqueNum,rowlist)); } else { Tcl_AppendElement(curFile->interp,Tcl_Merge(numRows,rowlist)); } for ( i=0; iCHDUInfo.table.numRows ; long uniqNum = 0; /* write the buffer to file */ if( isMerge ) { for (i=0; i< numRows; i++) { if ( columndata[i].flag == 0) { uniqNum++; ffptbb(curFile->fptr, uniqNum, 1, rowSize, columndata[i].colBuffer, &status); if ( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } } } if ( uniqNum != numRows) { ffdrow(curFile->fptr, uniqNum+1, numRows-uniqNum, &status); } } else { for (i=0; i< numRows; i++) { ffptbb(curFile->fptr, i+1, 1, rowSize, columndata[i].colBuffer, &status); if( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } } } return fitsUpdateFile(curFile); } void fitsGetSortRangeNum( colData a[], long n, long *nr ) { long i, count = 0; unsigned char flag = 0; /* an identical key start with sequence of "0 1 1 1 ... 1" */ for (i=0; ifptr, 0, &status); ffchdu(curFile->fptr, &status); ffrdef(curFile->fptr, &status); if ( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } /* reload info */ if ( TCL_OK != fitsUpdateCHDU(curFile, curFile->hduType) ) { Tcl_SetResult(curFile->interp, "Cannot update current HDU", TCL_STATIC); return TCL_ERROR; } /* reload the hdu */ return fitsLoadHDU(curFile); } int fitsColumnStatistics( FitsFD *curFile, int colNum, int felem, int numrange, int range[][2] ) { colStat colstat; char tmpStr[80]; int statFlag = 1; if ( TCL_OK != fitsColumnStatToPtr(curFile, colNum, felem, numrange, range, &colstat, statFlag) ) return TCL_ERROR; Tcl_ResetResult(curFile->interp); if (colstat.min < 0.000000100 || colstat.min > 999999999) { sprintf(tmpStr, "%16.8g", colstat.min); } else { sprintf(tmpStr, "%.10f", colstat.min); } Tcl_AppendElement(curFile->interp, tmpStr); sprintf(tmpStr, "%ld", colstat.fmin); Tcl_AppendElement(curFile->interp, tmpStr); if (colstat.max < 0.000000100 || colstat.max > 999999999) { sprintf(tmpStr, "%16.8g", colstat.max); } else { sprintf(tmpStr, "%.10f", colstat.max); } Tcl_AppendElement(curFile->interp, tmpStr); sprintf(tmpStr, "%ld", colstat.fmax); Tcl_AppendElement(curFile->interp, tmpStr); if (colstat.mean < 0.000000100 || colstat.mean > 999999999) { sprintf(tmpStr, "%16.8g", colstat.mean); } else { sprintf(tmpStr, "%.10f", colstat.mean); } Tcl_AppendElement(curFile->interp, tmpStr); if (colstat.stdiv < 0.000000100 || colstat.stdiv > 999999999) { sprintf(tmpStr, "%16.8g", colstat.stdiv); } else { sprintf(tmpStr, "%.10f", colstat.stdiv); } Tcl_AppendElement(curFile->interp, tmpStr); sprintf(tmpStr, "%ld", colstat.numData); Tcl_AppendElement(curFile->interp, tmpStr); return TCL_OK; } int fitsColumnMinMax( FitsFD *curFile, int colNum, int felem, int numrange, int range[][2] ) { colStat colstat; char tmpStr[80]; int statFlag = 0; if ( TCL_OK != fitsColumnStatToPtr(curFile, colNum, felem, numrange, range, &colstat, statFlag) ) return TCL_ERROR; sprintf(tmpStr, "%.10f", colstat.min); Tcl_SetResult(curFile->interp, tmpStr, TCL_VOLATILE); sprintf(tmpStr, "%.10f", colstat.max); Tcl_AppendElement(curFile->interp, tmpStr); return TCL_OK; } int fitsColumnMinMaxToPtr( FitsFD *curFile, int colNum, int felem, int fRow, int lRow, double *min, double *max ) { colStat colstat; int statFlag = 0; int range[1][2]; range[0][0] = fRow; range[0][1] = lRow; if ( TCL_OK != fitsColumnStatToPtr(curFile, colNum, felem, 1, range, &colstat, statFlag) ) return TCL_ERROR; *min = colstat.min; *max = colstat.max; return TCL_OK; } int fitsColumnStatToPtr( FitsFD *curFile, int colNum, int felem, int numrange, int range[][2], colStat *colstat, int statFlag ) { int m; int nRows, numRows; double *array; char *flagArray; int colType; int n; long fRow, lRow; double min = DBL_MAX; double max = -DBL_MAX; double d_total = 0.0; double s_total = 0.0; long l_count = 0; colType = curFile->CHDUInfo.table.colDataType[colNum-1]; if ( colType == TSTRING || colType == TLOGICAL || colType == TCOMPLEX || colType == TDBLCOMPLEX || (colType == TBIT && statFlag) ) { Tcl_SetResult(curFile->interp, "fitsTcl Error: cannot work on this type of column", TCL_STATIC); return TCL_ERROR; } nRows = curFile->CHDUInfo.table.numRows; /* check if is a vector column */ if ( felem > curFile->CHDUInfo.table.vecSize[colNum-1] ) { Tcl_SetResult(curFile->interp, "fitsTcl Error: vector out of bound", TCL_STATIC); return TCL_ERROR; } /* if not a vector and colMin and colMax are loaded then skip calculation */ if ( !statFlag ) { if ( curFile->CHDUInfo.table.vecSize[colNum-1] <= 1 && (curFile->CHDUInfo.table.colMin[colNum-1] != DBL_MIN || curFile->CHDUInfo.table.colMax[colNum-1] != DBL_MAX )) { if ( range[0][0] == 1L && (range[0][1] == nRows) ) { min = curFile->CHDUInfo.table.colMin[colNum-1] ; max = curFile->CHDUInfo.table.colMax[colNum-1] ; colstat->min = min; colstat->max = max; return TCL_OK; } } } for (n=0; n < numrange; n++) { fRow = range[n][0]; lRow = range[n][1]; numRows = lRow - fRow + 1; array = (double *) ckalloc(numRows*sizeof(double)); flagArray = (char *) ckalloc(numRows*sizeof(char)); if ( fitsColumnGetToArray(curFile, colNum, felem, fRow, lRow, array, flagArray) != TCL_OK) { ckfree((char *) array); ckfree((char *) flagArray); return TCL_ERROR; } if ( statFlag ) { for (m=0; m < numRows; m++ ) { if ( !flagArray[m] ) { d_total += array[m]; s_total += array[m] * array[m]; l_count ++; if (max < array[m]) { max = array[m]; colstat->fmax = fRow + m; } if (min > array[m]) { min = array[m]; colstat->fmin = fRow + m; } } } } else { for (m=0; m < numRows; m++ ) { if ( !flagArray[m] ) { if (max < array[m]) max = array[m]; if (min > array[m]) min = array[m]; } } } if ( fRow == 1 && lRow == nRows ) { /* update curFile info */ curFile->CHDUInfo.table.colMin[colNum-1] = min; curFile->CHDUInfo.table.colMax[colNum-1] = max; } ckfree((char *)array); ckfree((char *)flagArray); } colstat->min = min; colstat->max = max; if ( statFlag ) { colstat->mean = d_total/l_count; colstat->numData = l_count; if ( l_count-1 <= 0 ) { colstat->stdiv = 0; } else { s_total -= l_count * colstat->mean * colstat->mean; colstat->stdiv = sqrt(s_total/(l_count-1)); } } return TCL_OK; } int fitsColumnGetToArray( FitsFD *curFile, int colNum, int felem, long fRow, long lRow, double *array, char *flagArray ) { int status = 0; long nRows, m; char cValue[1]; double dblValue[1]; LONGLONG longlongValue[1]; int dataType; char nullArray[1]; int anyf = 0; /* check the row range */ if ( lRow > curFile->CHDUInfo.table.numRows) lRow = curFile->CHDUInfo.table.numRows; if ( fRow < 1) fRow = 1; if ( lRow < 1) lRow = 1; nRows = lRow - fRow +1; dataType = curFile->CHDUInfo.table.colDataType[colNum-1]; switch ( dataType ) { case TBIT: for (m=0; m < nRows; m++ ) { ffgcfl(curFile->fptr, colNum, fRow+m, felem, 1, cValue, nullArray, &anyf, &status); if ( status > 0 ) { flagArray[m] = 2; array[m] = 0; status = 0; ffcmsg(); } else if ( nullArray[0] ) { flagArray[m] = 1; array[m] = 0; } else { flagArray[m] = 0; array[m] = cValue[0]; } } break; case TBYTE: /* CFITSIO does automatic type conversion for columns */ case TSHORT: /* Don't know about the TBIT -> TDOUBLE conversion? */ case TINT: case TLONG: case TFLOAT: case TDOUBLE: for (m=0; m < nRows; m++ ) { ffgcfd(curFile->fptr, colNum, fRow+m, felem, 1, dblValue, nullArray, &anyf, &status); if ( status > 0 ) { flagArray[m] = 2; array[m] = 0; status = 0; ffcmsg(); } else if ( nullArray[0] ) { flagArray[m] = 1; array[m] = 0; } else { flagArray[m] = 0; array[m] = dblValue[0]; } } break; case TLONGLONG: for (m=0; m < nRows; m++ ) { ffgcfjj(curFile->fptr, colNum, fRow+m, felem, 1, longlongValue, nullArray, &anyf, &status); if ( status > 0 ) { flagArray[m] = 2; array[m] = 0; status = 0; ffcmsg(); } else if ( nullArray[0] ) { flagArray[m] = 1; array[m] = 0; } else { flagArray[m] = 0; array[m] = longlongValue[0]; } } break; default: Tcl_SetResult(curFile->interp, "fitsTcl Error: Not a numerical column", TCL_STATIC); ckfree ((char *) flagArray); return TCL_ERROR; } return TCL_OK; } int fitsCalculaterngColumn( FitsFD *curFile, char *colName, char *colForm, char *expr , int numrange, int range[][2] ) { int status=0; int i; long * firstrow; long * lastrow; firstrow = (long *) malloc(numrange*sizeof(long)); lastrow = (long *) malloc(numrange*sizeof(long)); for (i=0; ifptr, expr, curFile->fptr, colName, colForm, numrange, firstrow,lastrow, &status ); free(firstrow); free(lastrow); if( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } return fitsUpdateFile(curFile); } int fitsCalculateColumn( FitsFD *curFile, char *colName, char *colForm, char *expr ) { int status=0; ffcalc( curFile->fptr, expr, curFile->fptr, colName, colForm, &status ); if( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } return fitsUpdateFile(curFile); } int fitsSelectRowsExpr (FitsFD *curFile, char *expr, long firstrow, long nrows, long * n_good_rows, char * row_status) { int status=0; fffrow( curFile->fptr, expr, firstrow, nrows, n_good_rows, row_status,&status ); if( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } return TCL_OK; } int fitsDeleteRowsExpr( FitsFD *curFile, char *expr ) { int status=0; char *negExpr; negExpr = (char*)ckalloc((strlen(expr)+15)*sizeof(char)); sprintf(negExpr,"DEFNULL(!(%s),T)",expr); ffsrow( curFile->fptr, curFile->fptr, negExpr, &status ); ckfree( negExpr ); if( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } return fitsUpdateFile(curFile); } /* * ------------------------------------------------------------ * * exprGetToPtr * * return : "address dataType numberElements" * address can be recovered using sscanf(address, PTRFORMAT, &dataArray) * where void *dataArray * dataType : 0 uchar, 2 int, 4 double (No others allowed) * numberElements : dimension of the array * * ------------------------------------------------------------ */ int exprGetToPtr( FitsFD *curFile, char *expr, char *nulStr, int numrange, int range[][2] ) { void *backPtr; LONGLONG *longlongArray; double *dblArray; int *intArray; unsigned char *bytArray; LONGLONG longlongNul; double dblNul; int intNul; unsigned char bytNul; long numRows; int anynul=0; int dataType, naxis; long nelem, naxes[5], offset=0, ntodo; char result[80]; int status = 0; int rngCnt; fftexp( curFile->fptr, expr, 5, &dataType, &nelem, &naxis, naxes, &status ); if ( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } if( nelem < 0 ) nelem = -nelem; /* Flags a constant result */ /* Count the number of rows */ numRows = 0; for( rngCnt=0; rngCntfptr, TLOGICAL, expr, (long)range[rngCnt][0], (long)nelem*ntodo, &intNul, bytArray+offset, &anynul, &status ); offset += nelem*ntodo; } dataType = BYTE_DATA; backPtr = bytArray; break; case TLONG: if( !strcmp(nulStr, "NULL") ) { intNul = INT_MAX; } else { intNul = atol(nulStr); } /* pow/visu donot like long type array. convert to int */ intArray = (int *) ckalloc(numRows*nelem*sizeof(int)); for( rngCnt=0; rngCntfptr, TINT, expr, (long)range[rngCnt][0], (long)nelem*ntodo, &intNul, intArray+offset, &anynul, &status ); offset += nelem*ntodo; } dataType = INT_DATA; backPtr = intArray; break; case TDOUBLE: if( !strcmp(nulStr, "NULL") ) { dblNul = DBL_MAX; } else { dblNul = atof(nulStr); } dblArray = (double *) ckalloc(numRows*nelem*sizeof(double)); for( rngCnt=0; rngCntfptr, TDOUBLE, expr, (long)range[rngCnt][0], (long)nelem*ntodo, &dblNul, dblArray+offset, &anynul, &status ); offset += nelem*ntodo; } dataType = DOUBLE_DATA; backPtr = dblArray; break; case TLONGLONG: if( !strcmp(nulStr, "NULL") ) { longlongNul = (LONGLONG)NULL; } else { longlongNul = atof(nulStr); } longlongArray = (LONGLONG *) ckalloc(numRows*nelem*sizeof(LONGLONG)); for( rngCnt=0; rngCntfptr, TLONGLONG, expr, (long)range[rngCnt][0], (long)nelem*ntodo, &longlongNul, longlongArray+offset, &anynul, &status ); offset += nelem*ntodo; } dataType = LONGLONG_DATA; backPtr = longlongArray; break; default: Tcl_SetResult(curFile->interp, "fitsTcl Error: cannot load this type of expression", TCL_STATIC); return TCL_ERROR; } if ( status ) { ckfree( (char *)backPtr ); dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } sprintf( result, PTRFORMAT " %d %ld", backPtr, dataType, numRows*nelem ); Tcl_SetResult(curFile->interp, result, TCL_VOLATILE); return TCL_OK; } /* * ------------------------------------------------------------ * * exprGetInfo * * return : "dataType numberElements naxes" * address can be recovered using sscanf(address, PTRFORMAT, &dataArray) * where void *dataArray * dataType : CFITSIO datatype... TDOUBLE, TSTRING, etc * * ------------------------------------------------------------ */ int exprGetInfo( FitsFD *curFile, char *expr ) { long i; char tmpStr[32]; int dataType, naxis; long nelem, naxes[5]; int status = 0; Tcl_ResetResult(curFile->interp); fftexp( curFile->fptr, expr, 5, &dataType, &nelem, &naxis, naxes, &status ); if ( status ) { dumpFitsErrStack(curFile->interp, status); return TCL_ERROR; } sprintf( tmpStr, "%d %ld {", dataType, nelem ); Tcl_AppendResult( curFile->interp, tmpStr, (char*)NULL ); for( i=0; iinterp, tmpStr, (char *)NULL ); } Tcl_AppendResult( curFile->interp, "}", (char *)NULL ); return TCL_OK; } fitsTcl-2.5/fitsInit.c0000644000220700000360000001427413133202233013521 0ustar birbylhea/* * fits_Init.c -- * * This is the setup routine for the Fits extended Tcl. * */ #include "fitsTclInt.h" static Tcl_HashTable interpTokenMap; static int interpTokenMapInitialised = 0; FitsFD FitsOpenFiles[FITS_MAX_OPEN_FILES]; Tcl_HashTable *FitsDataStore; int FitsDS_numElems = 0; int FitsDS_curAccess = 0; fitsTclOptions userOptions; Tcl_Command * FitsTclInterpToTokens( Tcl_Interp *interp) { int newEntry; Tcl_Command *cmdTokens; Tcl_HashEntry *entryPtr = Tcl_CreateHashEntry(&interpTokenMap, (char *) interp, &newEntry); if (newEntry) { cmdTokens = (Tcl_Command *) Tcl_Alloc(sizeof(Tcl_Command) * (MAX_REGISTERED_COMMANDS+1)); for (newEntry=0 ; newEntrynext = (FitsCardList *) NULL; FitsOpenFiles[i].hisHead->pos = -1; FitsOpenFiles[i].comHead = comCardList + i; FitsOpenFiles[i].comHead->next = (FitsCardList *) NULL; FitsOpenFiles[i].comHead->pos = -1; FitsOpenFiles[i].handleName = NULL; } userOptions.wcsSwap = 0; FitsDataStore = (Tcl_HashTable *) ckalloc(sizeof(Tcl_HashTable)); Tcl_InitHashTable(FitsDataStore,3); Tcl_CreateObjCommand(interp, "fits", Fits_MainCommand,( ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "lst2ptr", fitsLst2Ptr, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "ptr2lst", fitsPtr2Lst, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand(interp, "vexpr", fitsExpr, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand( interp, "range", fitsRange, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); /* * Remaining commands are special commands used by fv. * They are all located in fvTcl.c. */ Tcl_CreateCommand(interp,"isFits",(Tcl_CmdProc*)isFitsCmd, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateCommand(interp,"getmax",(Tcl_CmdProc*)getMaxCmd, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateCommand(interp,"getmin",(Tcl_CmdProc*)getMinCmd, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateCommand(interp,"setarray",(Tcl_CmdProc*)setArray, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateCommand(interp,"sarray",(Tcl_CmdProc*)searchArray, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateCommand(interp,"updateFirst",(Tcl_CmdProc*)updateFirst, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateCommand(interp,"calAbsXPos",(Tcl_CmdProc*)Table_calAbsXPos, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); Tcl_CreateObjCommand( interp, "updateCell", (Tcl_ObjCmdProc*)Table_updateCell, (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL); return TCL_OK; } fitsTcl-2.5/fitsTcl.c0000644000220700000360000010617014334765652013364 0ustar birbylhea/* * fitsTcl.c -- * * This is the main file for defining the Fits objects in fitsTcl... * > fits open, close, info * */ #include "fitsTclInt.h" #include /* on some systems, e.g. linux, SUNs DBL_MAX is in float.h */ #ifndef DBL_MAX # include #endif #ifndef DBL_MIN # include #endif #define LONGLONGDATA 257 /* * ------------------------------------------------------------ * * Fits_MainCommand -- * * This dispatches all the fits ... commands * * Results: * Depends on command line arguments * * Side Effects: * Ditto * * ------------------------------------------------------------ * */ ParseData gParse; int Fits_MainCommand( ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *const argv[] ) { static char *infoString = "\n" "open - opens a Fits file\n" "close - closes ALL open Fits files\n" "info - reports on open Fits files: {Handle Filename RWmode CHDU Hdutype}\n" "option - manipulate behavior of fitsTcl\n" "version - reports the fitsTcl and cfitsio version numbers\n" "free - free one or more pointers allocated (via load) by fitsTcl\n" ; int i; char *cmdStr; if ( argc == 1 ) { Tcl_SetResult(interp,infoString,TCL_STATIC); return TCL_OK; } cmdStr = Tcl_GetStringFromObj( argv[1], NULL ); if( !strcmp(cmdStr,"info") ) { /* * ******************* INFO ******************* */ return FitsInfo(interp,argc,argv); } else if( !strcmp(cmdStr,"open") ) { /* * ******************* OPEN ******************** */ return FitsCreateObject(interp,argc,argv); } else if( !strcmp(cmdStr,"close") ) { /* * ******************* CLOSE ******************** */ for ( i = 0; i < FITS_MAX_OPEN_FILES ; i++ ) { if( FitsOpenFiles[i].fptr ) { if( TCL_OK != Tcl_DeleteCommand(interp,FitsOpenFiles[i].handleName) ) { return TCL_ERROR; } FitsOpenFiles[i].fptr = NULL; FitsOpenFiles[i].handleName = NULL; } } } else if( !strcmp(cmdStr,"option") ) { /* * ******************* OPTION ***************** */ char *optStr; Tcl_Obj *opt[2],*res; if( argc > 4 ) { Tcl_SetResult(interp, "option ?opt? ?value?", TCL_STATIC); return TCL_ERROR; } if( argc == 2 ) { /* Return a list of all current options and values */ res = Tcl_NewListObj(0,NULL); /* Repeat these 3 lines for each new option added */ opt[0] = Tcl_NewStringObj("wcsSwap", -1); opt[1] = Tcl_NewBooleanObj( userOptions.wcsSwap ); Tcl_ListObjAppendElement(interp, res, Tcl_NewListObj(2,opt)); Tcl_SetObjResult(interp, res); } else if( argc==3 ) { /* Return single option value */ optStr = Tcl_GetStringFromObj( argv[2], NULL ); if( !strcmp(optStr,"wcsSwap") ) { res = Tcl_NewBooleanObj( userOptions.wcsSwap ); } else { Tcl_SetResult(interp,"Unknown fits option",TCL_STATIC); return TCL_ERROR; } Tcl_SetObjResult(interp, res); } else { /* Set an option */ optStr = Tcl_GetStringFromObj( argv[2], NULL ); if( !strcmp(optStr,"wcsSwap") ) { Tcl_GetBooleanFromObj(interp, argv[3], &userOptions.wcsSwap); } else { Tcl_SetResult(interp,"Unknown fits option",TCL_STATIC); return TCL_ERROR; } } } else if( !strcmp(cmdStr,"version") ) { /* * ******************* VERSION ***************** */ float cfitsioVersion; char buffer[32]; ffvers(&cfitsioVersion); sprintf(buffer,"%s %5.3f", FITSTCL_VERSION, cfitsioVersion); Tcl_SetResult(interp, buffer, TCL_VOLATILE); } else if( !strcmp(cmdStr,"free") ) { /* * ******************* FREE ***************** */ Tcl_Obj **addList; void *databuff; int nAdd; if( argc == 2 ) { Tcl_SetResult(interp, "free addressList", TCL_STATIC); return TCL_OK; } if( argc>3 ) { Tcl_SetResult(interp, "Too many arguments to free", TCL_STATIC); return TCL_ERROR; } if( Tcl_ListObjGetElements(interp, argv[2], &nAdd, &addList) != TCL_OK ) { Tcl_SetResult(interp, "Cannot parse the address list", TCL_STATIC); return TCL_ERROR; } while( nAdd-- ) { databuff = fitsTcl_ReadPtrStr( addList[nAdd] ); if( !databuff ) { Tcl_SetResult(interp, "Error interpretting pointer address", TCL_STATIC); return TCL_ERROR; } ckfree( (char *) databuff); } } else { Tcl_SetResult(interp, "Unknown argument to fits command", TCL_STATIC); return TCL_ERROR; } return TCL_OK; } /* * ------------------------------------------------------------ * * FitsCreateObject -- * * This opens a new Fits file, and creates the associated command * * Results: * A Fits file argv[2] is opened with rwmode argv[3]. If argv[4] * is provided, then an associated object is created named argv[4] * otherwise the object is called fitsFile#, where # is incremented. * * Side effects: * Creates a new command, allocates the FPTR, opens the file * * ------------------------------------------------------------ */ int FitsCreateObject( Tcl_Interp *interp, int argc, Tcl_Obj *const argv[] ) { FitsFD *newFile; int status,rwmode,i; int isConflict; char *objName,tmpStr[16], *filename; fitsfile *fptr; static char *argList = "fits open filename ?rwmode? ?objName? "; static int objCounter=0; /* Deal with wrong # of arguments */ if( argc==2 ) { Tcl_SetResult(interp, argList, TCL_STATIC); return TCL_OK; } else if( argc > 5 ) { Tcl_AppendResult(interp,"Wrong number of Arguments: expected ", argList, (char *) NULL); return TCL_ERROR; } filename = Tcl_GetStringFromObj( argv[2], NULL ); /* Convert the rwmode, or set to default */ if ( 3 == argc ) { rwmode = READWRITE; /* 1 */ } else if ( 4 <= argc ) { if( Tcl_GetIntFromObj(interp,argv[3],&rwmode) != TCL_OK ) { Tcl_AppendResult(interp,"\nWrong type for rwmode",(char *) NULL); return TCL_ERROR; } } /* * Generate an automatic name if one was not given. * Check for conflicts... */ do { if( argc == 5 ) { objName = Tcl_GetStringFromObj(argv[4],NULL); } else { sprintf(tmpStr,"fitsObj%d",objCounter++); objName = tmpStr; } isConflict = 0; for( i = 0; i < FITS_MAX_OPEN_FILES; i++ ) { if( FitsOpenFiles[i].handleName && !strcmp(FitsOpenFiles[i].handleName,objName) ) { isConflict = 1; break; } } if( isConflict && argc==5 ) { Tcl_AppendResult(interp, "Error: Fits Handle: ", Tcl_GetStringFromObj(argv[4],NULL), " already used.", (char*)NULL); return TCL_ERROR; } } while( isConflict ); /* Get a file pointer, and try to FFOPEN the file: */ status = 0; if( rwmode==2 ) { /* if file exists, remove it */ remove( filename ); /* Get a file pointer for an empty fits file */ ffinit(&fptr, filename, &status); if ( status ) { dumpFitsErrStack(interp, status); return TCL_ERROR; } } else { /* Get a file pointer, if the fits file exists */ ffopen(&fptr, filename, rwmode, &status); if ( status ) { dumpFitsErrStack(interp, status); return TCL_ERROR; } } /* If we succeeded, then write the new FitsFD structure */ i = 0; while( i= FITS_MAX_OPEN_FILES ) { Tcl_SetResult(interp, "Too many open files. Max is ", TCL_STATIC); sprintf(tmpStr,"%d", FITS_MAX_OPEN_FILES); Tcl_AppendResult(interp, tmpStr, (char*)NULL); ffclos(fptr,&status); return TCL_ERROR; } newFile = &FitsOpenFiles[i] ; newFile->fileNum = i; newFile->fileName = (char *) ckalloc(strlen(filename)+1); if( NULL == newFile->fileName ) { Tcl_SetResult(interp,"Error malloc'ing space for fileName",TCL_STATIC); return TCL_ERROR; } strcpy(newFile->fileName, filename); newFile->handleName = (char *) ckalloc( strlen(objName) + 1 ); if ( NULL == newFile->handleName ) { Tcl_SetResult(interp, "Error Malloc'ing space for Handle Name", TCL_STATIC); ckfree( (char*)newFile->fileName ); return TCL_ERROR; } strcpy(newFile->handleName,objName); newFile->interp = interp; newFile->fptr = fptr; newFile->rwmode = rwmode; newFile->chdu = 1; newFile->hduType = NOHDU; newFile->CHDUInfo.table.loadStatus = 0; /* * Initialize the hash table for the keywords */ Tcl_InitHashTable(newFile->kwds,TCL_STRING_KEYS); /* * Load the current extension by moving relative 0 HDUs */ if( rwmode != 2 ) { if( fitsMoveHDU(newFile,0,1) != TCL_OK ) { fitsCloseFile((ClientData) newFile); return TCL_ERROR; } } /* Now create the new Tcl command for this object */ Tcl_CreateObjCommand( interp, newFile->handleName, (Tcl_ObjCmdProc*)fitsDispatch, (ClientData) newFile, fitsCloseFile ); Tcl_SetResult(interp, newFile->handleName, TCL_STATIC); return TCL_OK; } /* * ------------------------------------------------------------ * * fitsCloseFile -- * * This is the delete procedure for a Fits file object. * * Results: * It closes the file, unallocates the FPTR, and frees the FitsFD struc * * Side Effects: * The whole file is removed from Tcl. * * ------------------------------------------------------------ * */ void fitsCloseFile(ClientData clientData) { int status; FitsFD *curFile = (FitsFD *) clientData; char result[256]; /* Pan Chai, we already free this.. no need to do it again */ if (curFile->fptr == NULL && curFile->handleName == NULL) return; status = 0; /* Flush the altered keywords */ fitsFlushKeywords(curFile); /* now close the File */ ffclos(curFile->fptr,&status); if ( status ) { sprintf(result, "Error closing Fits file %s\n", curFile->fileName); Tcl_SetResult(curFile->interp, result, TCL_VOLATILE); } ckfree((char *) curFile->fileName); ckfree((char *) curFile->handleName); curFile->fptr = NULL; curFile->handleName = NULL; deleteFitsCardList(curFile->comHead); deleteFitsCardList(curFile->hisHead); freeCHDUInfo(curFile); } /* * ------------------------------------------------------------ * * FitsInfo -- * * This gives info on the open FITS files - the command fits info... * * Results: * For each file - HANDLE FILENAME RWMODE CHDU HDUTYPE * * Side Effects: * Ditto * * ------------------------------------------------------------ * */ int FitsInfo( Tcl_Interp *interp, int argc, Tcl_Obj *const argv[] ) { int i, gotit = 0; int argc2; char **argv2; char strBuff[16]; Tcl_DString resultStr,regExpStr; Tcl_DStringInit(®ExpStr); if( argc != 2 ) { argc2 = argc-2; argv2 = (char **) ckalloc( argc2 * sizeof( char *) ); for( i=0; i 4 ) { Tcl_SetResult(interp, "lst2ptr dataList ?dataType? ?naxes?", TCL_STATIC); return TCL_ERROR; } if( argc>2 ) Tcl_GetIntFromObj( interp, argv[2], &dataType ); else dataType = DOUBLE_DATA; dataPtr = fitsTcl_Lst2Ptr( interp, argv[1], dataType, &ntodo, NULL ); if( argc>3 ) { fitsTcl_GetDims( interp, argv[3], &nelem, &naxis, naxes ); if( ntodo != nelem ) { Tcl_SetResult(interp, "List dimensions not same size as list", TCL_STATIC); ckfree( (char *)dataPtr ); return TCL_ERROR; } } else { nelem = ntodo; naxis = 1; naxes[0] = ntodo; } sprintf(ptrStr, PTRFORMAT, dataPtr); resElem[0] = Tcl_NewStringObj( ptrStr, -1 ); resElem[1] = Tcl_NewIntObj( dataType ); fitsTcl_SetDims( interp, resElem+2, naxis, naxes ); res = Tcl_NewListObj( 3, resElem ); Tcl_SetObjResult(interp, res); return TCL_OK; } /*********************************************************************** * Implement some utility routines ***********************************************************************/ int fitsRange( ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *const argv[] ) { char *rangeStr, errMsg[256], *opt; int numInt, *range, maxInt, i; long numElem; if( argc==2 ) { Tcl_SetResult( interp, "Usage: range count ranges maxValue", TCL_STATIC ); return TCL_OK; } opt = Tcl_GetStringFromObj( argv[1], NULL ); if( !strcmp( "count", opt ) ) { if( argc!=4 ) { Tcl_SetResult( interp, "Usage: range count ranges maxValue", TCL_STATIC ); return TCL_ERROR; } rangeStr = Tcl_GetStringFromObj( argv[2], NULL ); if( Tcl_GetIntFromObj( interp, argv[3], &maxInt ) != TCL_OK ) { Tcl_AppendResult( interp, "Unable to read maxValue parameter", (char *)NULL ); return TCL_ERROR; } numInt = fitsParseRangeNum(rangeStr)+1; range = (int *) malloc (numInt*2*sizeof(int)); if( fitsParseRange( rangeStr, &numInt, range, numInt, 1, maxInt, errMsg ) != TCL_OK ) { Tcl_SetResult(interp, "Error parsing range:\n", TCL_STATIC); Tcl_AppendResult(interp, errMsg, (char*)NULL); return TCL_ERROR; } numElem = 0; for( i=0; i argc ) { Tcl_SetResult(interp,"usage: vexpr ?-ptr? ?-use dataFctn? expression", TCL_STATIC); return TCL_ERROR; } /*******************************/ /* Read-in the expression */ /*******************************/ Tcl_DStringInit ( &expr ); Tcl_DStringAppend( &expr, strArg, -1 ); while( argPosoperation==CONST_OP ) { constant = 1; ntodo = 1; dims = Tcl_NewIntObj( 1 ); } else { constant = 0; ntodo = result->value.nelem * vexprInfo.nrows; fitsTcl_SetDims( interp, &dims, result->value.naxis, result->value.naxes ); if( vexprInfo.nrows>1 ) Tcl_ListObjAppendElement( interp, dims, Tcl_NewIntObj( vexprInfo.nrows ) ); } /* Identify the fitsTcl DataType of result */ switch( result->type ) { case LONGLONGDATA: dataType = LONGLONG_DATA; break; case DOUBLE: dataType = DOUBLE_DATA; break; case LONG: dataType = INT_DATA; if( !constant && sizeof(int) != sizeof(long) ) { /* Demote long array to int */ long *lPtr; lPtr = (long *)result->value.data.ptr; ptr.Int = (int *)result->value.data.ptr; for( i=0; ivalue.data.str, -1) ); break; case DOUBLE_DATA: Tcl_ListObjAppendElement( interp, answer, Tcl_NewDoubleObj( result->value.data.dbl ) ); break; case INT_DATA: Tcl_ListObjAppendElement( interp, answer, Tcl_NewIntObj( (int)result->value.data.lng ) ); break; case BYTE_DATA: Tcl_ListObjAppendElement( interp, answer, Tcl_NewIntObj( (int)result->value.data.log ) ); break; } } else { answer = fitsTcl_Ptr2Lst( interp, result->value.data.ptr, result->value.undef, dataType, ntodo ); } } else { undef = result->value.undef; ptr.Dbl = result->value.data.dblptr; switch( dataType ) { case LONGLONG_DATA: ptr2.Llong = (LONGLONG *) ckalloc( ntodo * sizeof(LONGLONG) ); if( constant ) ptr2.Llong[0] = fitsTcl_atoll(result->value.data.str); else for( i=0; ivalue.data.dbl; else for( i=0; ivalue.data.lng; else for( i=0; ivalue.data.log; else for( i=0; ioperation>0 ) { free( result->value.data.ptr ); } fitsExprCleanup(); if( vexprInfo.callback || !returnList ) { res = Tcl_NewListObj( 0, NULL ); Tcl_ListObjAppendElement( interp, res, answer ); Tcl_ListObjAppendElement( interp, res, type ); Tcl_ListObjAppendElement( interp, res, dims ); } else { res = answer; } Tcl_SetObjResult(interp,res); return TCL_OK; } static void fitsExprCleanup( void ) { int i; for( i=0; istr, "%I64d", ptrs.llong[0]); #else sprintf(thelval->str, "%lld", ptrs.llong[0]); #endif type = LONGLONGDATA; break; case DOUBLE_DATA: thelval->dbl = ptrs.dbl[0]; type = DOUBLE; break; case FLOAT_DATA: thelval->dbl = ptrs.flt[0]; type = DOUBLE; break; case INT_DATA: thelval->lng = ptrs.iptr[0]; type = LONG; break; case SHORTINT_DATA: thelval->lng = ptrs.shrt[0]; type = LONG; break; case BYTE_DATA: thelval->lng = ptrs.byte[0]; type = LONG; break; } if( !isPtr ) ckfree( (char *)ptrs.ptr ); ckfree( (char *)undef ); } else { /* Received a VECTOR */ if( vexprInfo.nrows==0 ) { vexprInfo.nrows = nrows; } else if( nrows != vexprInfo.nrows ) { Tcl_SetResult( interp, "Vectors of incompatible lengths", TCL_STATIC); gParse.status = PARSE_SYNTAX_ERR; return pERROR; } /* Allocate an entry for this variable */ nCol = ++gParse.nCols; if( gParse.varData ) { gParse.varData = (DataInfo *) ckrealloc( (char *)gParse.varData, nCol*sizeof(DataInfo) ); } else { gParse.varData = (DataInfo *) ckalloc ( nCol*sizeof(DataInfo) ); } /* Initialize Data Array for this variable */ variable = gParse.varData+(nCol-1); strncpy( variable->name, dataName, MAXVARNAME ); variable->name[MAXVARNAME] = '\0'; variable->nelem = nelem; variable->naxis = naxis; for( i=0; inaxes[i] = naxes[i]; variable->undef = undef; variable->data = ptrs.ptr; thelval->lng = nCol - 1; switch( datatype ) { case LONGLONG_DATA: variable->type = LONGLONGDATA; type = COLUMN; if( isPtr ) { /* Must make copy and define undef */ LONGLONG *llong = ptrs.llong; ptrs.llong = (LONGLONG *)ckalloc( ntodo * sizeof(LONGLONG) ); for( i=0; idata = ptrs.ptr; } break; case DOUBLE_DATA: variable->type = DOUBLE; type = COLUMN; if( isPtr ) { /* Must make copy and define undef */ double *dbl = ptrs.dbl; ptrs.dbl = (double *)ckalloc( ntodo * sizeof(double) ); for( i=0; idata = ptrs.ptr; } break; case FLOAT_DATA: variable->type = DOUBLE; type = COLUMN; do { /* Promote array to double */ float *flt = (float *)ptrs.ptr; ptrs.dbl = (double *)ckalloc( ntodo * sizeof(double) ); if( isPtr ) { for( i=0; idata ); } variable->data = ptrs.ptr; } while( 0 ); break; case INT_DATA: variable->type = LONG; type = COLUMN; if( sizeof(int)!=sizeof(long) || isPtr ) { /* Promote array to long */ int *iPtr = (int *)ptrs.ptr; ptrs.lng = (long *)ckalloc( ntodo * sizeof(long) ); if( isPtr ) { for( i=0; idata ); } variable->data = ptrs.ptr; } break; case SHORTINT_DATA: variable->type = LONG; type = COLUMN; do { /* Promote array to long */ short *sPtr = (short*)ptrs.ptr; ptrs.lng = (long *)ckalloc( ntodo * sizeof(long) ); if( isPtr ) { for( i=0; idata ); } variable->data = ptrs.ptr; } while( 0 ); break; case BYTE_DATA: variable->type = LONG; type = COLUMN; do { /* Promote array to long */ unsigned char *bPtr; bPtr = (unsigned char *)ptrs.ptr; ptrs.lng = (long *)ckalloc( ntodo * sizeof(long) ); if( isPtr ) { for( i=0; idata ); } variable->data = ptrs.ptr; } while( 0 ); break; } } Tcl_ResetResult( interp ); return type; } static int fitsGetDataCallback( char *dataName, int *argc, Tcl_Obj ***argv) { Tcl_Obj *res, *cmd; res = NULL; if( vexprInfo.callback ) { cmd = Tcl_NewStringObj(vexprInfo.callback, -1); Tcl_AppendToObj( cmd, " ", -1 ); Tcl_AppendToObj( cmd, dataName, -1 ); if( Tcl_EvalObj( vexprInfo.interp, cmd ) != TCL_OK ) { gParse.status = PARSE_SYNTAX_ERR; return TCL_ERROR; } res = Tcl_GetObjResult( vexprInfo.interp ); Tcl_ListObjGetElements( vexprInfo.interp, res, argc, argv ); if( *argc==0 ) res=NULL; } if( res==NULL ) { res = fitsGetTclData( dataName ); if( res==NULL ) return TCL_ERROR; Tcl_ListObjGetElements( vexprInfo.interp, res, argc, argv ); } if( (*argc < 3 || *argc > 4) || (*argc == 4 && strcmp(Tcl_GetStringFromObj((*argv)[0],NULL),"-ptr") ) ) { gParse.status = PARSE_SYNTAX_ERR; Tcl_SetResult( vexprInfo.interp, "Bad callback function results", TCL_STATIC ); return TCL_ERROR; } return TCL_OK; } static Tcl_Obj *fitsGetTclData( char *dataName ) { /* Locates TCL variable and returns "data dType dims" */ /* ... dims is just the length of the list, though */ Tcl_Interp *interp; Tcl_Obj *var, *name, *res; int nelem; interp = vexprInfo.interp; name = Tcl_NewStringObj( dataName, -1 ); var = Tcl_ObjGetVar2( interp, name, NULL, 0 ); if( var==NULL ) { Tcl_SetResult( interp, "Unable to locate variable: ", TCL_STATIC); Tcl_AppendResult(interp, dataName, "\n", NULL); gParse.status = PARSE_SYNTAX_ERR; return NULL; } res = Tcl_NewListObj(1,&var); Tcl_ListObjLength(interp, var, &nelem); Tcl_ListObjAppendElement(interp, res, Tcl_NewIntObj(DOUBLE_DATA)); Tcl_ListObjAppendElement(interp, res, Tcl_NewIntObj(nelem)); return res; } fitsTcl-2.5/fitsTcl.h0000644000220700000360000000516213133202233013341 0ustar birbylhea/* * fitsTcl.h -- * * This header file describes the externally visible * calls in the Tcl wrapping for Fitsio. * */ #ifndef FITSTCL #define FITSTCL #define FITSTCL_VERSION "2.4" #define MAX_REGISTERED_COMMANDS 2 #define FITSTCL_MAJOR_VERSION 2 #define FITSTCL_MINOR_VERSION 4 #define FITSTCL_SERIAL 0 #include /* Sun4s do not support %p, so switch to %lx */ #ifdef HEX_PTRFORMAT #define PTRFORMAT "%lx" #else #define PTRFORMAT "%p" #endif EXTERN void FitsTclDeleteTokens(Tcl_Interp *interp); EXTERN void FitsTclFreeTokensHashTable(void); EXTERN Tcl_Command * FitsTclInterpToTokens( Tcl_Interp *interp); EXTERN int Fits_Init (Tcl_Interp *interp); EXTERN int Fits_SafeInit (Tcl_Interp *interp); EXTERN int FitsTcl_SafeUnload(Tcl_Interp *interp, int flags); EXTERN int FitsTcl_Unload(Tcl_Interp *interp, int flags); EXTERN int Fits_MainCommand (ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *const argv[]); EXTERN int fitsDispatch (ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *const argv[]); EXTERN int fitsLst2Ptr (ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *const argv[]); EXTERN int fitsPtr2Lst (ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *const argv[]); EXTERN int fitsExpr (ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *const argv[]); EXTERN int fitsRange(ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *const argv[]); EXTERN int getMaxCmd (ClientData clientData, Tcl_Interp *interp, int argc, char *const argv[]); EXTERN int getMinCmd (ClientData clientData, Tcl_Interp *interp, int argc, char *const argv[]); EXTERN int isFitsCmd (ClientData clientData, Tcl_Interp *interp, int argc, char *const argv[]); EXTERN int updateFirst (ClientData clientData, Tcl_Interp *interp, int argc, char *const argv[]); EXTERN int dataBlockToVar (ClientData clientData, Tcl_Interp *interp, int argc, char *const argv[]); EXTERN int setArray (ClientData clientData, Tcl_Interp *interp, int argc, char *const argv[]); EXTERN int searchArray (ClientData clientData, Tcl_Interp *interp, int argc, char *const argv[]); EXTERN int Table_calAbsXPos (ClientData clientData, Tcl_Interp *interp, int argc, char *const argv[]); EXTERN int Table_updateCell ( ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *const argv[] ); #endif fitsTcl-2.5/fitsTcl.html0000644000220700000360000010254213133202233014056 0ustar birbylhea fitsTcl User's Guide

fitsTcl User's Guide

FITS (Flexible Image Transport System) file format is widely used in the astronomical community. But its complexity makes it very difficult for general users to interact with data in FITS format.

Current FORTRAN and C interfaces to FITS -- FITSIO/CFITSIO, developed by the HEASARC (High Energy Astrophysics Science Archive Research Center) at the NASA Goddard Space Flight Center -- provide very powerful and robust functions to interact with FITS files. However, utilizing FITSIO/CFITSIO requires some basic FORTRAN/C programming skills, and this low level library often is more powerful, and hence more complex, than the general user needs.

To provide general users with a simple interface to read/write FITS file, we developed fitsTcl, an extension to the simple but powerful script language TCL/TK, which uses the CFITSIO library. fitsTcl was developed for the fv project and is distributed as part of fv, which can be obtained by visiting the fv website. fitsTcl can also be downloaded separately from the fitsTcl web page. fitsTcl runs under Unix, Windows, and Mac OS.

fitsTcl is compiled as a dynamic library which can be loaded as a TCL extension. To load fitsTcl, type the following command in a Tcl shell (i.e. tclsh):

% load libfitstcl.so       (Linux)

% load libfitstcl.dylib    (Mac OS X)

% load libfitstcl          (Cygwin)
If the library is not found you may need to set the environment variable LD_LIBRARY_PATH (Unix only) to the directory containing libfitstcl.so or include an explicit path to the file.

In fitsTcl, every FITS file is treated as a FitsFile object. The following sections describe how to create FitsFile objects and all the methods in a FitsFile object.


Handling FitsFile objects


fits open fileName mode ?objName?
Create a FitsFile object, open the file and read the header of the current HDU. (Read the CFITSIO web pages or documentation to learn about its "Extended File Name Syntax".) mode can be 0 (read only) or 1 (read and write). If no objName is given, a name will be automatically assigned. A new empty FITS file can be created by setting mode to 2. In this case, if the named file exists, then it will be overwritten. Returns objName which will be used in most of the methods as the handle to the object.
fits info ?objName ...?
Return a list of all the existing objects, or the named objects (supports regular expressions), with the following information:

{objName fileName mode CHDU hduType}

where CHDU is the current HDU (1-primary array, 2-the first extension ...) and hduType is the type of the HDU (0-image, 1-ASCII table, 2-Binary table).
objName move ?+/-?n
If n has ``+/-'' sign, then move n units relative to the CHDU, otherwise move to the nth HDU. Return the extension type of the new HDU: 0-image, 1-ASCII table, 2-Binary Table.
objName close
Delete object objName.
fits close
Delete all the existing objects.

Getting information about the CHDU


objName info chdu
Return the CHDU. 1=primary, 2=first extension, etc.
objName info filesize
Return the size of the file (in units of 2880 bytes).
objName info hdutype
Return ``Primary array'', ``Image extension'', ``Binary Table'', or ``ASCII Table''.
objName info imgdim
Return the dimensions of the image if the CHDU is an image extension.
objName info ncols
Return the number of columns in the table if the CHDU is a table extension.
objName info nrows
Return the number of rows in the table if the CHDU is a table extension.
objName info nkwds
Return the number of keywords in the header of the CHDU.
objName info column ?-exact? ?colList?
Without any arguments, return a list of all the column names in the table if the CHDU is a table extension. If colList is present, detailed information about the listed columns, using regular expression name comparisons, is returned in the form of:

{Name Type Unit DisplayFormat DefaultFormat ColumnWidth isOffset isScaled defaultNull}

where
  Name name of the column (TTYPE keyword)
Type type of the column (TFORM keyword)
Unit unit of the column (TUNIT keyword)
DisplayFormat format for display (TDISP keyword)
DefaultFormat default format for display (if TDISP keyword is absent)
ColumnWidth the width of the column (in units of characters).
isOffset 0 = no offset (no TZERO keyword), 1 = offset.
isScaled 0 = not scaled (no TSCALE keyword), 1 = scaled.
defaultNull default NULL value (TNULL keyword)
The -exact option turns off the regular expression matching.

Reading data from a FITS file


objName dump ?-s/-e/-l?
Return all the keyword records in the current header. The following options control how the information is formatted:
  none return list of all cards in header
-s return three lists: {keywords} {values} {comments}
-e return a single string containing a newline-separated list of all header records
-l return all the keyword names
objName get keyword ?keyList?
Return a list of {keyword value comment} for all the keywords in keyList (supports regular expressions). If no keyList is given, return a list of entries for all the keywords in the CHDU. The order in which keywords are listed is undefined. (HISTORY and COMMENT keywords are never returned.)
objName get keyword -num n
Return a list of {keyword value comment} of the nth keyword.
objName get wcs ?RAcol DecCol?
Return a list of the WCS parameters -- {xrval yrval xrpix yrpix xinc yinc rot ctype} -- for the CHDU. If the current HDU is a table, supply the RAcol and DecCol parameters specifying the two columns (as names or column numbers) containing WCS data. Use defaults for any missing WCS keywords: 1.0 for xinc/yinc; ``none'' for ctype; and 0.0 or all others. If the RA/Dec identity of the columns (or image axes) are not known, an extra WCS parameter -- wcsSwap -- can be obtained which, when on, indicates that the X parameters are for Dec instead of RA. Turn this option on with fits option wcsSwap 1.
objName get wcs -m ?Col1 ...?
Similar to above, but information is returned in new-style format, allowing arbitrary matrix transforms. Return value is {refVals refPix matrix types projections} where each item (except matrix) contains a list of the given information for each image dimension or table column; matrix is the rotation, scale, skew, NxN transformation matrix given as {cd11 .. cd1N cd21 .. cd2N .. cdNN}. The wcsSwap option has no effect on this command; one must check the types values to see if the RA and Dec transforms are associated with the first and second axes, respectively, of the image (as is usually the case) or are reversed.
objName get image ?firstElem? ?numElem?
Read data elements from the current IMAGE extension and return them in a list. Without any parameters, the entire image will be returned. If only firstElem is given, return just one element.
objName get table ?-c? ?-noformat? ?colList? ?rows?
Read a block of a table and return list(s) of data. The block range is set in
  colList a list of all the columns one wants to read. Read all columns if missing or is ``*''.
rows a comma-separated list of row ranges of the form start-end (eg, ``3-5,7,9-'')
-c return data from each column as a separate list
-noformat do not format results according to a TDISPn, or default, format
objName get vtable ?-noformat? colName n ?rows?
Return a list of data in the nth vector element in column colName of the given rows. The -noformat option turns off any TDISPn formatting.

Loading data into memory or to a TCL array


When loading data into memory, fitsTcl will normally return address dataType numElements where these are:
  address Memory address of the data. Can be recovered in C by
  sscanf(address, "%p", &databuff);
with void *databuff
dataType
0 - BYTE_DATA 1 byte data
1 - SHORTINT_DATA 2 byte integer
2 - INT_DATA 4 byte integer
3 - FLOAT_DATA 4 byte floating point
4 - DOUBLE_DATA 8 byte floating point
numElement Number of data elements in the array

objName load image ?slice? ?rotate?
Load a full 2D image in the CHDU into memory and return the address address (see above). slice indicates which frame to use if image is 3D. rotate indicates how many 90-degree counter-clockwise rotations to perform on the image (0-3).
objName load iblock arrayName firstRow numRows firstCol numCols ?slice?
Load a block (start from firstCol, firstRow with size numCols x numRows) of image data to a 2-D TCL array arrayName or to memory if arrayName is ``--''. The indices of the array variable are (firstCol-1 ... firstCol+numCols-1, firstRow-1 ... firstRow+numRows-1). A 1D image will be treated as either a single row or column, depending on the row/column parameters supplied. For a 3D image, slice indicates which frame to use. If arrayName is ``--'', read the data block into memory and return the pointer information: address dataType numElements.
objName load irows firstRow lastRow ?slice?
objName load icols firstCol lastCol ?slice?
Read and average together a range of rows or columns of an image. Returns address dataType numElements. dataType will be 3 for all image data types except for double for which dataType is 4.
objName load column colName ?defaultNull? ?firstElement?
Load a column of a table into memory and return address dataType numElements. Use the value of defaultNull for NULL values, or internal defaults (normally the data type's maximum value) if ``NULL'' or absent. If colName is a vector column, read the firstElement-th element. One can only load numerical columns.
objName load vtable colName
Load all elements of the vector column colName and return address dataType numElements.
objName load tblock ?-noformat? arrayName colList firstRow numRows colIndex ?firstElem?
Load a block of table data to a 2-D TCL array arrayName. colIndex is (almost) the column index of the array to use for the first column read. The first data index is actually (as for images) (colIndex-1,firstRow-1). For scaler columns, firstElem = 1. Without the -noformat flag, values will be returned as strings formatted according to a TDISP keyword or default format based on data type.
objName load expr ?-rows rows? expression ?defaultNull?
Evaluate the arithmetic expression on each row (or a subset of rows given by rows) of the CHDU's table and return address dataType numElements, using defaultNull as the null value of any NULL results.
objName load keyword
Load keywords into fitsTcl's internal hash table. One usually will not need to call this routine.
objName load chdu
Reload the information about the current HDU. One usually will not need to call this routine.

Writing to a FITS file


objName insert image bitpix naxis naxesList
objName insert image -p ?bitpix naxis naxesList?
Insert an empty image HDU (primary header with -p) after the current HDU (or, at start of file for primary array). The image parameters -- bitpix naxis naxesList -- can be left off if creating a zero-length primary array.
objName insert table numRows {colNames} {colFormats} ?{colUnits} extensionName?
objName insert table -ascii numRows {colNames} {colFormats} ?{colUnits} {colPosition} extensionName rowWidth?
Insert an empty BINARY (default) or ASCII (with -ascii flag) table HDU after the current HDU. The colNames and colFormats lists must be of equal length (possibly both empty). The optional parameters can each be empty if one wants to use default/empty values.
objName insert keyword index record ?formatFlag?
Insert a new record at the index-th keyword. If formatFlag is 0, write the record exactly as passed, otherwise parse it as a free form keyname value comment and reformat it into a standardized KEYNAME = VALUE / COMMENT (default).
objName put keyword ?-num index? record ?formatFlag?
Write a keyword record either at position index; the position of a pre-existing keyword with the same name; or append it if no such keyword exists. See above for format/meaning of record and formatFlag.
objName put history historyStr
Write a HISTORY keyword with content historyStr
objName insert column index colName colFormat
Insert an empty column with format colFormat before the index-th column. colFormat specifies the column format as, for example:
  ASCII Table: A15, I10, E12.5, D20.10, F14.6 ...
  BINARY Table: 15A, 1I, 1J, 1E, 1D, 1L, 1X, 1B, 1C, 1M
objName add column colName colFormat ?expression?
Without an expression, append an empty column to the CHDU table; return nothing. Given an arithmetic expression, though, the indicated column (new or old) will be filled in with the results of the expression evaluated for each row of the table. If colName does not exist in the current table extension, a new one will be created with format colFormat (see above). If colFormat is ``default'', the column will be created based on the data type of the result. Return 1 or 0 to indicate whether a new column was created (1) or not (0). expression can be in either C or Fortran format with table columns and keywords referenced by their names. Here are some expression samples:
  Expression Result  
17.2 17.2 for every row
17 + 4*(PHI > 32) 17 or 21, depending on whether that row of the PHI column is greater than 32
sqrt( (X-X0)^2 + (Y-Y0)^2 ) Distance of the (X,Y) column coordinates from the (X0,Y0) keyword values
See the CFITSIO web pages and documentation for more details.
objName insert row index numRows
Insert number of numRows rows after the index-th row.
objName add row numRows
Add numRows rows at the end of the CHDU table.
objName put image firstElem listOfData
Write a block of data to the CHDU image. The first pixel of an image has firstElem = 1, not zero.
objName put table colName firstElem rowSpan listOfData
Write a list of data to the firstElem-th element of column colName in the CHDU table. (For scalar columns firstElem is 1.) rowSpan is a single row range of form start-end with ``-'' indicating all rows.

Deleting data from a FITS file


objName delete keyword keyList
Delete listed keywords, where the keyList can be the mix of keyword names and index numbers. Keywords are deleted individually in sequence, causing keyword positions to change after each deletion, so be careful when deleting multiple keywords by index.
objName delete cols colList
Delete listed columns in a table extension.
objName delete rows firstRow numRows
Delete a block of rows.
objName delete rows -expr expression
Delete rows using expression which must evaluate to a boolean value. Rows for which expression evaluates to TRUE get deleted.
objName delete chdu
Delete the current HDU. The HDU immediately following the one deleted (or the preceeding one if the current HDU is the last one of the file) will become the new current HDU. Returns extension type of new HDU: 0-image, 1-ASCII table, 2-Binary Table.

Analyzing FITS data


objName sort ?-merge? colList ?ascendFlags?
Sort table rows using columns in colList. When -merge is present, if multiple rows have identical sort keys all but one of the rows will be deleted. If present, ascendFlags contains a list of 1s and 0s indicating whether that column will be sorted in ascending (1, the default) or descending (0) order.
objName column -stat colName ?firstElem? ?rows?
Return statistics on the firstElem-th element (1 for scalar columns) of column colName in the order min firstMinRow max firstMaxRow mean stdDev numData.
objName column -minmax colName ?firstElem? ?rows?
Returns minimum and maximum values of the firstElem-th element (1 for scalar columns) of column colName.
objName histogram ?-weight colName|value? ?-inverse? ?-rows rows? filename {binAxis1} ?{binAxis2} ...?
Create a 1D - 4D histogram from columns in the current table. The binning parameters are given by the binAxisN parameters which are lists of the form colName min max binSize where the last 3 elements can each be ``-'', indicating default values. If TLMINn, TLMAXn, and/or TDBINn exist, those values will be used for defaults. Otherwise, for min and max the defaults are the actual min/max values of the data; for binSize the smaller of one-tenth the data span or 1.0 will be selected. A weighting value can be indicated with the -weight option. This can be either another column or a numerical constant. The -inverse option indicates the weight should be 1.0/weight instead of the weighting value itself. The histogram can be restricted to certain row ranges using the -rows option.
objName smooth {width height} outfile ?inPrimary?
Smooth the current image extension with a boxcar function of dimensions width by height pixels. The dimensions must be odd integers. The resulting image will be placed in a new extension appended to the file outfile. If outfile does not exist, the image will be placed either in the primary or in the first extension, depending on the value of the inPrimary flag; the default is to place it in an extension.

List/Pointer Manipulation


lst2ptr dataList ?dataType? ?naxesList?
Convert a TCL list into a memory-resident array. Returns address dataType naxesList (see the load commands above). The TCL list will be cast as double values in the absence of the dataType paramter. The parameter naxesList gives the vector dimensions of the list. It can be a single number indicating the length of the list (the default value when absent) or a list of numbers which must multiply together to be the list length. If a list entry contains the string "NULL", the maximum value of the given dataType will be inserted.
ptr2lst address dataType naxesList
Convert a memory pointer into a TCL list. Returns dataList dataType naxesList (see lst2ptr). If an array element contains the maximum value for the given dataType, the string "NULL" will be inserted into the list.
vexpr ?-ptr? ?-use getDataCallback? expression
Perform a vector calculation using lists or arrays where expression is a C-style arithmetic expression. (Ie, do not use $var notation unless you explicitly want variable substitution before passing expression to vexpr.) Without any of the options, variable references within expression will be interpretted as local TCL lists (or scalars) containing double data and the result will itself be a simple TCL list. With the -ptr option set, the answer instead will be returned as a pointer to a memory-resident array. With either option set, two additional parameters will be returned in a list of the form dataList dataType naxesList or address dataType naxesList. The -use option provides a "callback" routine which is to be used for supplying the variable data. It gets called when a variable is encountered in the expression and will be passed a single argument containing the name of the variable. The callback routine should return either "dataList dataType naxesList" or "-ptr address dataType naxesList". If the callback routine doesn't recognize the variable, it should return an empty string. The parser will then try to find the variable in the local namespace, as when no callback is supplied. If this fallback behavior is not desired, raise an error instead. The callback function can itself check for local variables using the TCL command upvar 1 $varName localName. The following code snippet provides a sample callback function which assumes the expression contains variables storing the results of a load or lst2ptr command (ie, address dataType naxesList): proc getPtrData { varName } { upvar $varName myName if [info exists myName] { return [eval list -ptr $myName] } else { error "Variable doesn't exist" } } then the following code would calculate the average value of a table column: set myCol [objName load column X] vexpr -use getPtrData "sum( (double)myCol ) / nelem( myCol )" By default, a vector with a single-valued naxesList is interpretted as a single vector containing n elements such that the above "sum" function sums all of the elements. In the context of loading a column, though, one actually has an array of n rows with each row containing 1 (or perhaps more) elements. To handle this case, one must use the callback function to provide an naxisList of "1 n" (or "2 m", etc) instead of merely "n". In that case each row will be calculated separately and have its own result. When naxesList has multiple elements, the final element specifies the number of rows.

See the CFITSIO web pages and documentation for details on expression syntax. One can also read the fv online help file on expression syntax, noting that vexpr can only handle numerical input and output.

fits free addressList
Free the memory occupied by the data generated by one of the load, lst2ptr, and vexpr commands.

Other commands


objName copy filename
Copy the CHDU to a new FITS file. If the CHDU is not an image array, then an empty primary array is inserted.
objName sascii table filename fileMode firstRow numRows colList widthList
Write the listed columns into an ASCII file. In the output file, each column has the width listed in widthList. fileMode indicates how to write the data to filename: 0-create new file and write column headings; 1-append to old file and write column headings; 2-append to old file, but don't write any headings.
objName sascii image filename fileMode firstRow numRows firstCol numCols cellSize ?slice?
Write a block of the image data to an ASCII file. In the output file, the data has width of cellSize. Use frame slice for 3D image data.
objName flush ?clear?
Flush any dirty buffers to the disk. With clear, free the buffers, too.
objName append filename
Append current HDU to another FITS file.
objName checksum update|verify
Update or Verify the checksum keywords in the current HDU. If none exist, update will create them. For verify, the return values are 1 for valid values, 0 if either keyword (CHECKSUM or DATASUM) is missing, and -1 for invalid values.
objName info expr expression
Get information on the result of the supplied arithmetic expression. Return value is cDataType numElements {naxesList} where cDataType is the CFITSIO datatype (not fitsTcl's): TDOUBLE, TSTRING, etc; numElements is the number of elements in the result; and naxesList contains the vector dimensions of the result ({1} for scalar result). An expression which evaluates to a constant (no dependency on the contents of the table) will be indicated by a negative number of elements.
range count rangeStr maxElem
Count the number of elements (esp. rows) contained within the comma-separated list of ranges in rangeStr (eg, 1-4,5,7-). To support ranges of the form "7-" which specifies a range from element 7 through the final element, maxElem is passed with the maximum element number.
fits option ?option? ?value?
Modify fitsTcl's default behavior. With no options, this returns a list of all the current fitsTcl options and their values. With the option parameter, return the value of that parameter. When both option and value are supplied, set the parameter to the given value. Current options: wcsSwap (0).
fits version
Get version numbers for fitsTcl and underlying cfitsio.
fitsTcl-2.5/fitsTclInt.h0000644000220700000360000003651513133202233014022 0ustar birbylhea/* * fitsTclInt.h - * * This header file contains the definitions, structures, and * function prototypes for fitsTcl's internal use. */ /* *----------------------------------------------------------------- * MODIFICATION HISTORY * 2004-02-06 Ziqin Pan * 1. Add long rowindex to colData structure * *---------------------------------------------------------------- */ #ifndef FITSTCLINT #define FITSTCLINT #ifndef macintosh #include #endif #include #include #include #include #include #include #ifdef HAVE_ALLOCA_H #include #endif #include "fitsTcl.h" #include "fitsio2.h" #define FITS_COLMAX 999 #define FITS_MAXDIMS 15 #define FITS_MAXRANGE 30 #define FITS_CHUNKSIZE 100 #define BYTE_DATA 0 #define SHORTINT_DATA 1 #define INT_DATA 2 #define FLOAT_DATA 3 #define DOUBLE_DATA 4 #define LONGLONG_DATA 5 #define NOHDU -1 typedef struct { int numCols; LONGLONG numRows; LONGLONG rowLen; char **colName; char **colType; int *colDataType; char **colUnit; char **colDisp; char **colNull; long *vecSize; long *vecDim; double *colTzero; double *colTscale; int *colTzflag; int *colTsflag; int *strSize; int loadStatus; int *colWidth; char **colFormat; double *colMin; double *colMax; } TableHDUInfo; typedef struct { int bitpix; int naxes; LONGLONG *naxisn; char **axisUnit; double bscale; double bzero; long bsflag; long bzflag; char blank[80]; int dataType; } ImageHDUInfo; typedef union { TableHDUInfo table; ImageHDUInfo image; } HDUInfo; typedef struct { char name[FLEN_KEYWORD]; char value[FLEN_VALUE]; char comment[FLEN_COMMENT]; int pos; } Keyword; typedef struct FitsCardStruct{ int pos; char value[FLEN_CARD]; struct FitsCardStruct * next; } FitsCardList; typedef struct { Tcl_Interp *interp; fitsfile *fptr; int fileNum; char* fileName; char* handleName; int rwmode; int chdu; int hduType; char extname[FLEN_VALUE]; int numKwds; int numHis; int numCom; Tcl_HashTable *kwds; FitsCardList *hisHead; FitsCardList *comHead; HDUInfo CHDUInfo; } FitsFD; typedef struct { LONGLONG longlongData; double dblData; long intData; char *strData; char flag; long rowindex; unsigned char *colBuffer; } colData; typedef struct { double min; double max; double mean; long fmin; long fmax; double stdiv; long numData; } colStat; /* * These are the function Prototypes: */ EXTERN void fitsCloseFile (ClientData clientData); EXTERN void dumpFitsErrStackToDString( Tcl_DString *stack, int status ); EXTERN void dumpFitsErrStack ( Tcl_Interp *interp, int status ); EXTERN int fitsMoveHDU (FitsFD *curFile, int nmove, int direction); EXTERN int FitsCreateObject (Tcl_Interp *interp, int argc, Tcl_Obj *const argv[]); EXTERN int FitsInfo (Tcl_Interp *interp, int argc, Tcl_Obj *const argv[]); EXTERN int fitsLoadKwds (FitsFD *curFile); EXTERN int fitsLoadHDU (FitsFD *curFile); EXTERN int fitsMakeRegExp (Tcl_Interp *interp, int argc, char *const argv[], Tcl_DString *concatList, int caseSen ); EXTERN int fitsDumpHeader (FitsFD *curFile); EXTERN int fitsParseRangeNum (char* rangeStr); EXTERN int fitsParseRange (char* rangeStr, int *numInt, int *range, int maxInt, int minval, int maxval, char *errMsg); EXTERN void *makeContigArray (int nrows, int ncols, char type); EXTERN int freeCHDUInfo (FitsFD * curFile); EXTERN int makeNewCHDUInfo (FitsFD * curFile, int newHduType); EXTERN int tableBlockLoad ( FitsFD * curFile, char *varName, int felem, int fRow, int nRows, int fCol, int nCols, int colNums[], int format); EXTERN int freeDataPtr (FitsFD * curFile, char ptrAddress[]); EXTERN int tableGetToPtr (FitsFD * curFile, long colNum, char *nulStr, long firstelem); EXTERN int tableRowGetToPtr (FitsFD * curFile, long rowNum, long colNum, long vecSize, char *nulStr, long firstelem); EXTERN int vtableGetToPtr (FitsFD *curFile, long colNum, char *nulStr); EXTERN void deleteFitsCardList ( FitsCardList *comCard); EXTERN int fitsTransColList (FitsFD *curFile, char *colStr, int *numCols, int colNums[], int colTypes[], int strSize[]); EXTERN int fitsFlushKeywords (FitsFD *curFile); EXTERN int strToUpper (char *inStr, char **outStr); EXTERN int fitsInsertKwds (FitsFD *curFile, int index, char *inCard, int ifFormat); EXTERN int fitsPutKwds (FitsFD *curFile, int nkey, char *inCard, int ifFormat); EXTERN int fitsPutHisKwd ( FitsFD *curFile, char *his); EXTERN int fitsDeleteKwds (FitsFD *curFile, char *keyList); EXTERN int fitsDeleteCols (FitsFD *curFile, int *colList, int numCols); EXTERN int fitsDeleteRows (FitsFD *curFile, int firstRow, int numRows); EXTERN int fitsDeleteCHdu (FitsFD *curFile); EXTERN int tdispGetFormat (FitsFD *curFile, int colnum); EXTERN int saveTableToAscii (FitsFD *curFile, char *filename, char *fileStatus, int felem, int fRow, int nRows, int nCols, int colTypes[], int colNums[], int strSize[], int ifFixedFormat, int ifCSV, int ifPrintRow, char *sepString); EXTERN int saveImageToAscii( FitsFD *curFile, char *filename, char *fileStatus, int fRow, int nRows, int fCol, int nCols, int cellSize, int ifCSV, int ifPrintRow, char *sepString, long slice ); EXTERN int saveVectorTableToAscii( FitsFD *curFile, char *filename, char *fileStatus, int fRow, int nRows, int fCol, int nCols, int baseColNum, int ifCSV, int ifPrintRow, char *sepString, int ifVariableVec); EXTERN int saveVectorTableRowToAscii( FitsFD *curFile, char *filename, char *fileStatus, int fRow, int nRows, int fCol, int nCols, int baseColNum, int ifCSV, int ifPrintRow, char *sepString, int ifVariableVec, char *colFormat, int dataType, FILE *fPtr, int ifFixedFormat); EXTERN int varSaveToTable (FitsFD *curFile, int colNum, long firstRow, long firstElem, long numRows, long numElem, Tcl_Obj **listArray); EXTERN int varSaveToImage (FitsFD *curFile, long firstElem, long numElem, Tcl_Obj **listArray); EXTERN int addColToTable (FitsFD *curFile, int colNum, char *ttype, char *tform); EXTERN int addRowToTable (FitsFD *curFile, int rowNum, int nRows); EXTERN int fitsCopyCHduToFile (FitsFD *curFile, char *newfilename); EXTERN void fitsQSsetFlag (colData a[], int dataType, int strSize, int fst, int lst); EXTERN void fitsQuickSort (colData a[], int dataType, int strSize, int fst, int lst, int isAscend); /* EXTERN int fitsSplit (colData a[], int dataType, int strSize, int f, int l, int isAscend); */ EXTERN int fitsSplit (colData a[], int dataType, int strSize, int f, int l, int isAscend, int * sp1, int * sp2); EXTERN void fitsSwap (colData *p, colData *q); EXTERN int fitsUpdateFile (FitsFD *curFile); EXTERN void fitsGetSortRange (colData a[], long n, long *t, long *b); EXTERN void fitsGetSortRangeNum (colData a[], long n, long *nr); EXTERN int fitsWriteRowsToFile (FitsFD *curFile, long rowSize, colData columndata[], int isMerge); EXTERN int fitsCalculateColumn (FitsFD *curFile, char *colName, char *colForm, char *expr); EXTERN int fitsCalculaterngColumn ( FitsFD *curFile, char *colName, char *colForm, char *expr, int numrange, int range[][2]); EXTERN int fitsDeleteRowsExpr (FitsFD *curFile, char *expr); EXTERN int exprGetInfo ( FitsFD *curFile, char *expr ); EXTERN int exprGetToPtr ( FitsFD *curFile, char *expr, char *nulStr, int numrange, int range[][2]); EXTERN int fitsColumnGetToArray ( FitsFD *curFile, int colNum, int felem, long fRow, long lRow, double *array, char *flagArray); EXTERN int fitsJustMoveHDU ( FitsFD *curFile, int nmove, int direction); EXTERN int fitsUpdateCHDU( FitsFD *curFile, int newHduType); EXTERN int fitsDumpHeaderToKV ( FitsFD *curFile ); EXTERN int fitsDumpHeaderToCard( FitsFD *curFile ); EXTERN int fitsDumpKwdsToList ( FitsFD *curFile ); EXTERN int imageRowsMeanToPtr( FitsFD *curFile, long fRow, long lRow, long slice ); EXTERN int imageColsMeanToPtr( FitsFD *curFile, long fCol, long lCol, long slice ); EXTERN int imageBlockLoad_1D( FitsFD *curFile, long fElem, long nElem ); EXTERN int imageBlockLoad( FitsFD *curFile, char *varName, LONGLONG fRow, LONGLONG nRow, LONGLONG fCol, LONGLONG nCol, long slice, long cslice); EXTERN int imageGetToPtr( FitsFD *curFile, long slice, int rotate ); EXTERN int fitsPutReqKwds( FitsFD *curFile, int isPrImg, int hduType, int argc, char *const argv[] ); EXTERN int fitsAppendCHduToFile( FitsFD *curFile, char *targetfilename ); EXTERN int fitsGetWcsMatrix( FitsFD *curFile, int nDims, int cols[], char dest ); EXTERN int fitsGetWcsMatrixAlt( FitsFD *curFile, fitsfile *fptr, Tcl_Obj *listObj, int nDims, int cols[], char dest ); EXTERN int fitsFileGetWcsMatrix( FitsFD *curFile, fitsfile *dummyFile, int nDims, int cols[], char dest, Tcl_Obj *data[]); EXTERN int fitsGetWcsPair( FitsFD *curFile, int Col1, int Col2, char dest ); EXTERN int fitsGetWcsPairAlt( FitsFD *curFile, fitsfile *fptr, Tcl_Obj *listObj, int Col1, int Col2, char dest ); EXTERN int fitsTableGetWcsOld( FitsFD *curFile, int RAColNum, int DecColNum ); EXTERN int fitsReadColData( FitsFD *curFile, int colNum, int strSize, colData columndata[], int *dataType ); EXTERN int fitsReadRawColData( FitsFD *curFile, colData columndata[], LONGLONG *rowSize ); EXTERN int fitsSortTable( FitsFD *curFile, int numCols, int *colNum, int *strSize, int *isAscend, int isMerge ); EXTERN int fitsColumnStatistics( FitsFD *curFile, int colNum, int felem, int numrange, int range[][2] ); EXTERN int fitsColumnMinMax( FitsFD *curFile, int colNum, int felem, int numrange, int range[][2] ); EXTERN int fitsColumnMinMaxToPtr( FitsFD *curFile, int colNum, int felem, int fRow, int lRow, double *min, double *max ); EXTERN int fitsColumnStatToPtr( FitsFD *curFile, int colNum, int felem, int numrange, int range[][2], colStat *colstat, int statFlag ); EXTERN void fitsRandomizeColData( colData columndata[], long numRows ); EXTERN void fitsFreeRawColData ( colData columndata[], long numRows ); EXTERN Tcl_Obj *fitsTcl_Ptr2Lst( Tcl_Interp *interp, void *thePtr, char *undef, int dataType, long nelem ); EXTERN void *fitsTcl_Lst2Ptr( Tcl_Interp *interp, Tcl_Obj *dataLst, int dataType, long *nelem, char **undef ); EXTERN int fitsTcl_SetDims( Tcl_Interp *interp, Tcl_Obj **dimObj, int naxis, long naxes[] ); EXTERN int fitsTcl_GetDims( Tcl_Interp *interp, Tcl_Obj *dimObj, long *nelem, int *naxis, long naxes[] ); EXTERN void *fitsTcl_ReadPtrStr( Tcl_Obj *ptrObj ); /* Feb 18, 2004, Ziqin Pan add to support row selection */ EXTERN int fitsDeleteRowlist(FitsFD *curFile,long* rowlist,int numRows ); EXTERN int fitsDeleteRowsRange( FitsFD *curFile,char * rangelist); EXTERN int fitsCalculaterngColumn( FitsFD *curFile,char *colName,char *colForm, char *expr, int numrange, int range[][2] ); EXTERN int fitsSelectRowsExpr (FitsFD *curFile,char *expr,long firstrow,long nrows, long * n_good_rows,char * row_status); EXTERN LONGLONG fitsTcl_atoll (char *inputStr); /********************************** * fitsTcl command handlers * **********************************/ int fitsTcl_close ( FitsFD *curFile, int argc, Tcl_Obj *const argv[] ); int fitsTcl_move ( FitsFD *curFile, int argc, Tcl_Obj *const argv[] ); int fitsTcl_dump ( FitsFD *curFile, int argc, Tcl_Obj *const argv[] ); int fitsTcl_info ( FitsFD *curFile, int argc, char *const argv[] ); int fitsTcl_get ( FitsFD *curFile, int argc, char *const argv[] ); int fitsTcl_put ( FitsFD *curFile, int argc, Tcl_Obj *const argv[] ); int fitsTcl_insert ( FitsFD *curFile, int argc, char *const argv[] ); int fitsTcl_delete ( FitsFD *curFile, int argc, char *const argv[] ); int fitsTcl_select ( FitsFD *curFile, int argc, char *const argv[] ); int fitsTcl_load ( FitsFD *curFile, int argc, char *const argv[] ); int fitsTcl_free ( FitsFD *curFile, int argc, Tcl_Obj *const argv[] ); int fitsTcl_flush ( FitsFD *curFile, int argc, Tcl_Obj *const argv[] ); int fitsTcl_copy ( FitsFD *curFile, int argc, Tcl_Obj *const argv[] ); int fitsTcl_sascii ( FitsFD *curFile, int argc, char *const argv[] ); int fitsTcl_sort ( FitsFD *curFile, int argc, char *const argv[] ); int fitsTcl_add ( FitsFD *curFile, int argc, char *const argv[] ); int fitsTcl_append ( FitsFD *curFile, int argc, Tcl_Obj *const argv[] ); int fitsTcl_histo ( FitsFD *curFile, int argc, Tcl_Obj *const argv[] ); int fitsTcl_create ( FitsFD *curFile, int argc, Tcl_Obj *const argv[] ); int fitsTcl_smooth ( FitsFD *curFile, int argc, Tcl_Obj *const argv[] ); int fitsTcl_checksum( FitsFD *curFile, int argc, Tcl_Obj *const argv[] ); #define FITS_MAX_OPEN_FILES NIOBUF /* Set by CFITSIO */ /* * This is the list of open Fits Files... */ EXTERN FitsFD FitsOpenFiles[FITS_MAX_OPEN_FILES]; typedef struct { int wcsSwap; } fitsTclOptions; EXTERN fitsTclOptions userOptions; #endif fitsTcl-2.5/fitsUtils.c0000644000220700000360000012773513133202233013725 0ustar birbylhea/* * fitsUtils.c -- * * This is a collection of utility routines for fitsTcl. * */ /* *------------------------------------------------------------ * * MODIFICATION HISTORY: * 2007-01-24 Pan Chai * rewrite sort routine - use standard qsort routine * 2004-02-06 Ziqin Pan * Add the following routines: * 1. fitsParseRangeNum * *------------------------------------------------------------ */ #include "fitsTclInt.h" #include /* on some systems, e.g. linux, SUNs DBL_MAX is in float.h */ #ifndef DBL_MAX # include #endif #ifndef DBL_MIN # include #endif /* * ------------------------------------------------------------ * * dumpFitsErrStack -- * * Dumps the FITSIO internal error stack onto the interp result * * ------------------------------------------------------------ */ void dumpFitsErrStack( Tcl_Interp *interp, int status ) { Tcl_DString stack; char *res; long len; res = Tcl_GetStringResult( interp ); len = strlen( res ); if( len>0 && res[len-1]!='\n' ) Tcl_AppendResult( interp, "\n", (char*)NULL ); dumpFitsErrStackToDString( &stack, status ); Tcl_AppendResult( interp, Tcl_DStringValue(&stack), (char*)NULL ); Tcl_DStringFree(&stack); } /* * ------------------------------------------------------------ * * dumpFitsErrStackToDString -- * * Dumps the FITSIO internal error stack to a Tcl_DString * * ------------------------------------------------------------ */ void dumpFitsErrStackToDString( Tcl_DString *stack, int status ) { char buffer[100]; Tcl_DStringInit(stack); ffgerr(status, buffer); Tcl_DStringAppend(stack, buffer, -1); sprintf(buffer, ". (CFITSIO error status was %d)\n", status); Tcl_DStringAppend(stack, buffer, -1); /* get error stack messages */ while( ffgmsg(buffer) ) { strcat(buffer, "\n"); Tcl_DStringAppend(stack, buffer, -1); } return; } /* * ------------------------------------------------------------ * * fitsMakeRegExp -- * * Takes the argc - argv pair, and a pointer to a DString, and * gobbles them into a regexp. If caseSen = 0, expression is case * sensitive, if = 1 UC, if = -1 LC... * * Results: * Fills the DString * * Side Effects: * None * * ------------------------------------------------------------ * */ int fitsMakeRegExp( Tcl_Interp *interp, int argc, char *const argv[], Tcl_DString *regExp, int caseSen ) { char **list; int numElem,i; char *p,*pattern; Tcl_DStringInit(regExp); while ( argc-- ) { if( Tcl_SplitList(interp,*argv,&numElem,&list) != TCL_OK ) { Tcl_AppendResult(interp,"Error parsing argument: ",argv, " as a Tcl list.",(char *) NULL); ckfree((char *) list); return TCL_ERROR; } for ( i = 0; i < numElem; i++ ) { Tcl_DStringAppend(regExp,list[i],-1); Tcl_DStringAppend(regExp,"|",-1); } ckfree((char *) list); argv++; } /* Strip off final "|" */ Tcl_DStringTrunc(regExp,Tcl_DStringLength(regExp) - 1); /* Make the match CASE INSENSITIVE -- All Keywds are UPPER CASE: */ if( caseSen == 1 ) { pattern = Tcl_DStringValue(regExp); for (p = pattern; *p ; p++ ) { if( islower((unsigned char) *p) ) { *p = toupper(*p); } } } else if ( caseSen == -1 ) { pattern = Tcl_DStringValue(regExp); for (p = pattern; *p ; p++ ) { if( isupper((unsigned char) *p) ) { *p = tolower(*p); } } } return TCL_OK; } /* * ------------------------------------------------------------ * * fitsParseRange -- * * This parses a list, and passes back a 2-d array of the ranges. * Returns TCL_OK for success. * * Results: * Sets numInt to the number of intervals found. * Fills range with the ranges... * * Side effects: * None * * ------------------------------------------------------------ */ int fitsParseRangeNum(char *rangeStr) { char *delim = ","; int count=0; char* strtmp=NULL; strtmp=strdup(rangeStr); if (strtok(strtmp,delim) !=NULL) { count++; while ( strtok(NULL,delim) !=NULL ) { count++; } } if(strtmp) free(strtmp); return count; } int fitsParseRange( char *rangeStr, int *numInt, int *range, int maxInt, int minval, int maxval, char *errMsg ) { char *delim = ","; char *tok,*strptr,*tokstore; int result,count,tmpVal[2],**tmpArray,i,j; char *rangeCpy; if( *rangeStr=='\0' || !strcmp(rangeStr,"-") || !strcmp(rangeStr,"*") ) { *numInt = 1; range[0] = minval; range[1] = maxval; return TCL_OK; } rangeCpy = (char *)ckalloc( (strlen(rangeStr)+1) * sizeof(char) ); strcpy(rangeCpy,rangeStr); tok = (char *) strtok(rangeCpy,delim); if ( ! tok ) { sprintf(errMsg,"No tokens found"); return TCL_ERROR; } tmpArray = (int **) ckalloc( (maxInt+1) * sizeof(int *) ); tmpArray[0] = (int *) ckalloc( 2 * (maxInt+1) * sizeof(int) ); for(i = 1; i <= maxInt; i++ ) { tmpArray[i] = tmpArray[i-1] + 2; } /* * This will be the sentinal... */ tmpArray[0][0] = minval - 1; count = 1; do { while ( *tok == ' ') tok++; if ( *tok == '\0' ) { sprintf(errMsg,"Null token in range"); ckfree( (char*)rangeCpy ); return TCL_ERROR; } tokstore = tok; strptr = (char *) strchr(tok,'-'); /* This translates the first token */ if ( NULL == strptr ) { result = sscanf( tok, "%d", &(tmpArray[count][0]) ); if ( 1 != result ) { sprintf(errMsg,"Error converting token %s in element %s", tok,tokstore); ckfree( (char*)rangeCpy ); return TCL_ERROR; } if ( tmpArray[count][0] > maxval ) { tmpArray[count][0] = maxval; } if ( tmpArray[count][0] < minval ) { tmpArray[count][0] = minval; } tmpArray[count][1] = tmpArray[count][0]; (count)++; continue; } else if (tok == strptr) { tmpArray[count][0] = minval; } else { result = sscanf(tok,"%d",&(tmpArray[count][0])); if ( result != 1 ) { sprintf(errMsg,"Error converting token %s in element %s", tok,tokstore); ckfree( (char*)rangeCpy ); return TCL_ERROR; } } /* This translates the second token */ while (' ' == *(++strptr) ) ; if ( '\0' == *strptr ) { tmpArray[count][1] = maxval; } else { result = sscanf(strptr,"%d",&(tmpArray[count][1])); if ( result != 1 ) { sprintf(errMsg,"Error converting token %s in element %s", strptr,tokstore); ckfree( (char*)rangeCpy ); return TCL_ERROR; } } /* Test for the sanity of the range... */ if ( tmpArray[count][0] > tmpArray[count][1] ) { sprintf(errMsg,"Range out of order in element %s",tokstore); ckfree( (char*)rangeCpy ); return TCL_ERROR; } if ( tmpArray[count][0] < minval ) { tmpArray[count][0] = minval; } if ( tmpArray[count][0] > maxval ) { tmpArray[count][0] = maxval; } if ( tmpArray[count][1] < minval ) { tmpArray[count][1] = minval; } if ( tmpArray[count][1] > maxval ) { tmpArray[count][1] = maxval; } (count)++; } while((tok = (char *) strtok(NULL,delim)) && count <= maxInt) ; if ( tok != NULL ) { sprintf(errMsg,"Too many ranges, maximum is %d",maxInt); ckfree( (char*)rangeCpy ); return TCL_ERROR; } if ( count == 2 ) { *numInt = 1; range[0] = tmpArray[1][0]; range[1] = tmpArray[1][1]; ckfree( (char*)rangeCpy ); return TCL_OK; } /* * Now sort: an insert sort is fine, there will never be that many, * and they should be almost in order... */ for ( i = 1; i< count; i++ ) { tmpVal[0] = tmpArray[i][0]; tmpVal[1] = tmpArray[i][1]; j = i; while(tmpArray[j-1][0] > tmpVal[0]) { tmpArray[j][0] = tmpArray[j-1][0]; tmpArray[j][1] = tmpArray[j-1][1]; j--; } tmpArray[j][0] = tmpVal[0]; tmpArray[j][1] = tmpVal[1]; } /* * Now merge the ranges, and shift down to remove the sentinal... */ *numInt = 0; range[0] = tmpArray[1][0]; range[1] = tmpArray[1][1]; for ( i = 2; i < count; i++) { if ( tmpArray[i][0] <= range[(*numInt)*2+1] ) { if ( range[(*numInt)*2+1] < tmpArray[i][1] ) range[(*numInt)*2+1] = tmpArray[i][1]; } else { (*numInt)++; range[(*numInt)*2] = tmpArray[i][0]; range[(*numInt)*2+1] = tmpArray[i][1]; } } /* * Remember to return number of elements, not index of the last element... */ (*numInt)++; ckfree((char*)tmpArray[0]); ckfree((char*)tmpArray); ckfree((char*)rangeCpy); return TCL_OK; } /* * ------------------------------------------------------------ * * makeContigArray -- * * Allocates a contiguous array of type type {c,i,l,f,d}. * * For 'c' type, returns a char ** pointing to 1-D string array of * nrows strings of length ncols. * * For 'i' returns an int ** pointing to the 2-d array, or an int* * pointing to 1-d array if ncols == 1. The same holds for f & d. * * Results: * Allocates Memory for the array * * Side effects: * None * * ------------------------------------------------------------ */ void *makeContigArray( int nrows, int ncols, char type ) { int i; char *ctmpPtr, **ctmpHandle; int *itmpPtr, **itmpHandle; long *ltmpPtr, **ltmpHandle; float *ftmpPtr, **ftmpHandle; double *dtmpPtr, **dtmpHandle; if ( type == 'c' ) { ctmpHandle = (char **) ckalloc(nrows*sizeof(char *)); if (ctmpHandle == NULL ) { return (void *) NULL; } ctmpHandle[0] = (char *) ckalloc(nrows * ncols * sizeof(char)); if (ctmpHandle[0] == NULL ) { ckfree((char *)ctmpHandle); return (void *) NULL; } ctmpPtr = ctmpHandle[0]; for ( i = 1; iCHDUInfo.table.numCols;i++) colTotSize += strlen(curFile->CHDUInfo.table.colName[i])+1; colArray = (char **) ckalloc( (unsigned)curFile->CHDUInfo.table.numCols * sizeof(char *) + colTotSize ); colArray[0] = (char*)(colArray+curFile->CHDUInfo.table.numCols); for ( i = 0; i < curFile->CHDUInfo.table.numCols ; i++ ) { colNums[i] = i; if( i ) colArray[i] = colArray[i-1] + strlen(colArray[i-1]) + 1; strToUpper( curFile->CHDUInfo.table.colName[i], &tmpstr); strcpy( colArray[i], tmpstr ); ckfree((char *) tmpstr); } *numCols = curFile->CHDUInfo.table.numCols; } else { /* Get the column list, -> UPC, match & translate to column number */ strToUpper( colStr, &pattern ); if( Tcl_SplitList(curFile->interp,pattern,numCols,&colArray) != TCL_OK ) { Tcl_SetResult(curFile->interp,"Error parsing column list",TCL_STATIC); ckfree(pattern); return TCL_ERROR; } ckfree(pattern); if( *numCols >= FITS_COLMAX ) { Tcl_SetResult(curFile->interp,"Too many columns in list",TCL_STATIC); ckfree((char*)colArray); return TCL_ERROR; } } for ( i = 0; i < *numCols; i++ ) { foundIt = 0; for ( j = 0; j < curFile->CHDUInfo.table.numCols; j++) { if( !strcasecmp(colArray[i], curFile->CHDUInfo.table.colName[j]) ) { colNums[i] = j+1; colTypes[i] = curFile->CHDUInfo.table.colDataType[j]; strSize[i] = curFile->CHDUInfo.table.strSize[j]; foundIt = 1; break; } } if ( ! foundIt ) { if( i==0 ) { /* See if original colStr matches anything */ for ( j = 0; j < curFile->CHDUInfo.table.numCols; j++) { if( !strcasecmp(colStr, curFile->CHDUInfo.table.colName[j]) ) { colNums[0] = j+1; colTypes[0] = curFile->CHDUInfo.table.colDataType[j]; strSize[0] = curFile->CHDUInfo.table.strSize[j]; foundIt = 1; break; } } if( foundIt ) { *numCols = 1; break; } } Tcl_ResetResult(curFile->interp); Tcl_AppendResult(curFile->interp, "Column name was not found: ",colArray[i], (char*)NULL); ckfree((char*)colArray); return TCL_ERROR; } } ckfree((char*)colArray); return TCL_OK; } int strToUpper( char *inStr, char **outStr ) { char *ptr; *outStr = (char *) ckalloc ( strlen(inStr) +1 ); strcpy( *outStr, inStr); for ( ptr=*outStr; *ptr; ptr++ ) { if ( islower((unsigned char) *ptr) ) { *ptr = toupper(*ptr); } } return TCL_OK; } int tdispGetFormat( FitsFD *curFile, int colnum ) { int w; char *tokenPtr; char *TDispKey; char tmp[80]; char rtFormat[80]; int isDisp; int i, idx; /* make a copy of the display format */ if ( strcmp(curFile->CHDUInfo.table.colDisp[colnum]," ") != 0 ) { strcpy(tmp, curFile->CHDUInfo.table.colDisp[colnum]); isDisp = 1; /* TDISP exists, use for format */ } else { strcpy(tmp, curFile->CHDUInfo.table.colType[colnum]); if( curFile->hduType == ASCII_TBL ) { isDisp = 1; /* Treat TFORM as TDISP for ASCII Tables */ } else { isDisp = 0; /* TDISP does not exist, use default format */ } } /* take out the 's and spaces */ if((TDispKey = strtok(tmp,"' "))==NULL) TDispKey = curFile->CHDUInfo.table.colType[colnum]; if ( strpbrk(TDispKey, "Aa") ) { /* ASCII column , consider wA and Aw type */ tokenPtr = strtok(TDispKey, "PApa"); sprintf(rtFormat,"%%s"); if( tokenPtr ) curFile->CHDUInfo.table.colWidth[colnum] = atoi(tokenPtr); else curFile->CHDUInfo.table.colWidth[colnum] = 8; if (curFile->CHDUInfo.table.colWidth[colnum] == 1) { curFile->CHDUInfo.table.colWidth[colnum] = 8; } } else if ( strpbrk(TDispKey, "Ll") ) { /* Logic type */ sprintf(rtFormat,"%%s"); if ( !isDisp || atoi(TDispKey) != 0 ) { curFile->CHDUInfo.table.colWidth[colnum] = 6; } else { tokenPtr = strtok(TDispKey, "PLpl"); if ( tokenPtr == NULL ) { curFile->CHDUInfo.table.colWidth[colnum] = 6; } else { curFile->CHDUInfo.table.colWidth[colnum] = atoi(tokenPtr); } } } else if ( strpbrk(TDispKey, "Bb") ) { /* Byte */ if ( (strcmp(curFile->CHDUInfo.table.colDisp[colnum], " ") ==0 ) && ( (curFile->CHDUInfo.table.colTzflag[colnum]==1) || (curFile->CHDUInfo.table.colTsflag[colnum]==1)) ) { curFile->CHDUInfo.table.colWidth[colnum] = 13; sprintf(rtFormat,"%%.8G"); } else { if ( !isDisp || atoi(TDispKey) != 0 ) { sprintf(rtFormat,"%%u"); curFile->CHDUInfo.table.colWidth[colnum] = 6; } else { tokenPtr = strtok(TDispKey, "PBpb"); if ( tokenPtr == NULL ) { sprintf(rtFormat,"%%u"); curFile->CHDUInfo.table.colWidth[colnum] = 6; } else { w = atoi(tokenPtr); sprintf(rtFormat,"%%%su", tokenPtr); curFile->CHDUInfo.table.colWidth[colnum] = w; } } } } else if ( strpbrk(TDispKey, "Kk") ) { /* Short Integer */ if ( (strcmp(curFile->CHDUInfo.table.colDisp[colnum], " ") ==0 ) && ( (curFile->CHDUInfo.table.colTzflag[colnum]==1) || (curFile->CHDUInfo.table.colTsflag[colnum]==1)) ) { curFile->CHDUInfo.table.colWidth[colnum] = 13; sprintf(rtFormat,"%%.8G"); } else { if ( !isDisp || atoi(TDispKey) != 0 ) { sprintf(rtFormat,"%%d"); curFile->CHDUInfo.table.colWidth[colnum] = 6; } else { tokenPtr = strtok(TDispKey, "PKpk"); if ( tokenPtr == NULL ) { sprintf(rtFormat,"%%d"); curFile->CHDUInfo.table.colWidth[colnum] = 6; } else { w = atoi (tokenPtr); sprintf(rtFormat,"%%%sd", tokenPtr); curFile->CHDUInfo.table.colWidth[colnum] = w; } } } } else if ( strpbrk(TDispKey, "Ii") ) { /* Integer type */ if ( (strcmp(curFile->CHDUInfo.table.colDisp[colnum], " ") ==0 ) && ( (curFile->CHDUInfo.table.colTzflag[colnum]==1) || (curFile->CHDUInfo.table.colTsflag[colnum]==1)) ) { curFile->CHDUInfo.table.colWidth[colnum] = 13; sprintf(rtFormat,"%%.8G"); } else { if ( !isDisp || atoi(TDispKey) != 0 ) { sprintf(rtFormat,"%%d"); curFile->CHDUInfo.table.colWidth[colnum] = 6; } else { tokenPtr = strtok(TDispKey, "PIpi"); if ( tokenPtr == NULL ) { sprintf(rtFormat,"%%d"); curFile->CHDUInfo.table.colWidth[colnum] = 6; } else { w = atoi (tokenPtr); sprintf(rtFormat,"%%%sd", tokenPtr); curFile->CHDUInfo.table.colWidth[colnum] = w; } } } } else if ( strpbrk(TDispKey, "Jj") ) { /* Long Integer */ if ( (strcmp(curFile->CHDUInfo.table.colDisp[colnum], " ") ==0 ) && ( (curFile->CHDUInfo.table.colTzflag[colnum]==1) || (curFile->CHDUInfo.table.colTsflag[colnum]==1)) ) { curFile->CHDUInfo.table.colWidth[colnum] = 13; sprintf(rtFormat,"%%.8G"); } else { sprintf(rtFormat,"%%ld"); curFile->CHDUInfo.table.colWidth[colnum] = 11; } } else if ( strpbrk(TDispKey, "E") ) { /* Real */ if ( !isDisp || atoi(TDispKey) != 0 ) { sprintf(rtFormat,"%%#.6E"); curFile->CHDUInfo.table.colWidth[colnum] = 13; } else { tokenPtr = strtok(TDispKey, "PENSpens"); if (tokenPtr == NULL ) { sprintf(rtFormat,"%%#.6E"); curFile->CHDUInfo.table.colWidth[colnum] = 13; } else { sprintf(rtFormat,"%%%sE", tokenPtr); w = atoi(tokenPtr); if ( w == 0 ) { curFile->CHDUInfo.table.colWidth[colnum] = 13; } else { curFile->CHDUInfo.table.colWidth[colnum] = w; } } } } else if ( strpbrk(TDispKey, "Ff") ) { /* 4-byte real */ if ( !isDisp || atoi(TDispKey) != 0 ) { sprintf(rtFormat,"%%#.6f"); curFile->CHDUInfo.table.colWidth[colnum] = 13; } else { tokenPtr = strtok(TDispKey, "PFpf"); if ( tokenPtr == NULL ) { sprintf(rtFormat,"%%#.6f"); curFile->CHDUInfo.table.colWidth[colnum] = 13; } else { w = atoi(tokenPtr); sprintf(rtFormat,"%%%sf", tokenPtr); if ( w == 0 ) { curFile->CHDUInfo.table.colWidth[colnum] = 13; } else { curFile->CHDUInfo.table.colWidth[colnum] = w; } } } } else if ( strpbrk(TDispKey, "Dd") ) { /* 8-byte Real */ if ( !isDisp || atoi(TDispKey) != 0 ) { sprintf(rtFormat,"%%.12E"); curFile->CHDUInfo.table.colWidth[colnum] = 19; } else { tokenPtr = strtok(TDispKey, "PDEpde"); if (tokenPtr == NULL ) { sprintf(rtFormat, "%%.12E"); curFile->CHDUInfo.table.colWidth[colnum] = 19; } else { sprintf(rtFormat,"%%%sf", tokenPtr); w = atoi(tokenPtr); if ( w == 0 ) { curFile->CHDUInfo.table.colWidth[colnum] = 19; } else { curFile->CHDUInfo.table.colWidth[colnum] = w; } } } } else if ( strpbrk(TDispKey, "Gg") ) { /* Real */ if ( !isDisp || atoi(TDispKey) != 0 ) { sprintf(rtFormat,"%%.6G"); curFile->CHDUInfo.table.colWidth[colnum] = 13; } else { tokenPtr = strtok(TDispKey, "PGEpge"); if ( tokenPtr == NULL ) { sprintf(rtFormat,"%%.6G"); curFile->CHDUInfo.table.colWidth[colnum] = 13; } else { sprintf(rtFormat,"%%%sG", tokenPtr); w = atoi(tokenPtr); if ( w == 0 ) { curFile->CHDUInfo.table.colWidth[colnum] = 13; } else { curFile->CHDUInfo.table.colWidth[colnum] = w; } } } } else if ( strpbrk(TDispKey, "Cc") ) { /* 4-byte Complex */ sprintf(rtFormat,"%%#.6G"); curFile->CHDUInfo.table.colWidth[colnum] = 30; } else if ( strpbrk(TDispKey, "Mm") ) { /* 8-byte Complex */ sprintf(rtFormat,"%%#.12G"); curFile->CHDUInfo.table.colWidth[colnum] = 36; } else if ( strpbrk(TDispKey, "Oo") ) { /* Octal? */ if ( !isDisp || atoi(TDispKey) != 0 ) { sprintf(rtFormat,"%%#o"); curFile->CHDUInfo.table.colWidth[colnum] = 8; } else { tokenPtr = strtok(TDispKey, "POpo"); if ( tokenPtr == NULL ) { sprintf(rtFormat,"%%#o"); curFile->CHDUInfo.table.colWidth[colnum] = 8; } else { w = atoi(tokenPtr); sprintf(rtFormat,"%%%so", tokenPtr); curFile->CHDUInfo.table.colWidth[colnum] = w; } } } else if ( strpbrk(TDispKey, "Zz") ) { /* ? */ if ( !isDisp || atoi(TDispKey) != 0 ) { sprintf(rtFormat,"%%#x"); curFile->CHDUInfo.table.colWidth[colnum] = 8; } else { tokenPtr = strtok(TDispKey, "PZpz"); if ( tokenPtr == NULL ) { sprintf(rtFormat,"%%#x"); curFile->CHDUInfo.table.colWidth[colnum] = 8; } else { w = atoi(tokenPtr); sprintf(rtFormat,"%%%sx", tokenPtr); curFile->CHDUInfo.table.colWidth[colnum] = w; } } } else if ( strpbrk(TDispKey, "Xx") ) { /* ? */ if ( !isDisp || atoi(TDispKey) != 0 ) { sprintf(rtFormat,"%%#u"); curFile->CHDUInfo.table.colWidth[colnum] = 8; } else { tokenPtr = strtok(TDispKey, "PXpx"); if (tokenPtr == NULL ) { sprintf(rtFormat,"%%#u"); curFile->CHDUInfo.table.colWidth[colnum] = 8; } else { sprintf(rtFormat,"%%#u"); curFile->CHDUInfo.table.colWidth[colnum] = atoi(tokenPtr); } } } else { /* ERROR */ if (strlen(TDispKey) == 0) { return TCL_OK; } for (i=0; i= '0' && TDispKey[i] <= '9') || (TDispKey[i] >= 'A' && TDispKey[i] <= 'Z') || (TDispKey[i] >= 'a' && TDispKey[i] <= 'z')) { /* check No.1 the TDIM keyword is a string */ continue; } else { /* illegal TDISP keyword, ignored */ return TCL_OK; } } /* check No.2 the TDISP keyword starts with A, L, I, B, O, Z, E, EN, ES, G or D */ if ((TDispKey[0] == 'A') || (TDispKey[0] == 'L') || (TDispKey[0] == 'I') || (TDispKey[0] == 'B') || (TDispKey[0] == 'O') || (TDispKey[0] == 'Z') || (TDispKey[0] == 'F') || (TDispKey[0] == 'E') || (TDispKey[0] == 'G') || (TDispKey[0] == 'D')) { /* check No.3 follow by a decimal digit */ idx = 1; if ((TDispKey[0] == 'E' && TDispKey[1] == 'N') || (TDispKey[0] == 'E' && TDispKey[1] == 'S')) { idx = 2; } if (TDispKey[idx] >= '0' && TDispKey[idx] <= '9') { /* legal TDISP keyword */ strcpy(curFile->CHDUInfo.table.colFormat[colnum], rtFormat); return TCL_OK; } } /* illegal TDISP keyword, ignored */ return TCL_OK; } strcpy(curFile->CHDUInfo.table.colFormat[colnum], rtFormat); return TCL_OK; } void fitsSwap(colData *p, colData *q) { colData temp; temp = *p; *p = *q; *q = temp; } void fitsQSsetFlag(colData a[], int dataType, int strSize, int left, int right) { /* dataType: 0: TSTRING */ /* 1: TSHORT, TINT, TBYTE, TLONG, TBIT, TLOGICAL */ /* 2: TFLOAT, TDOUBLE */ /* 3: TLONGLONG */ LONGLONG checkLongLong; long checkInt; double checkDbl; char *checkStr; int i; checkStr = (char *) ckalloc (strSize *sizeof(char ) + 1); for (i=left; i<=right; i++) { switch (dataType) { case 0 : if (i == left) { strcpy(checkStr, a[i].strData); a[i].flag = 0; } else { if (strcmp(checkStr, a[i].strData) == 0) { a[i].flag = 1; } else { strcpy(checkStr, a[i].strData); a[i].flag = 0; } } break; case 1 : if (i == left) { checkInt = a[i].intData; } else { if (checkInt == a[i].intData) { a[i].flag = 1; } else { checkInt = a[i].intData; a[i].flag = 0; } } break; case 2 : if (i == left) { checkDbl = a[i].dblData; } else { if (checkDbl == a[i].dblData) { a[i].flag = 1; } else { checkDbl = a[i].dblData; a[i].flag = 0; } } break; case 3 : if (i == left) { checkLongLong = a[i].longlongData; } else { if (checkLongLong == a[i].longlongData) { a[i].flag = 1; } else { checkLongLong = a[i].longlongData; a[i].flag = 0; } } break; default : break; } } ckfree((char *)checkStr); } void fitsQuickSort(colData a[], int dataType, int strSize, int left, int right, int isAscend) { int pivot; pivot = fitsSplit(a, dataType, strSize, left, right, isAscend, &left, &right); if (left < pivot) fitsQuickSort(a, dataType, strSize, left, pivot - 1, isAscend); if (right > pivot) fitsQuickSort(a, dataType, strSize, pivot + 1, right, isAscend); } /* * Split array in the following fashion: * the left subarray has all the values less than the divider * the right subarray has all the values greater than the divider */ int fitsSplit(colData a[], int dataType, int strSize, int left, int right, int isAscend,int *r_left, int *r_right) { colData tmpData; int l_hold = left; int r_hold = right; if ( isAscend == 1) { /* push all the smaller values to the left */ switch (dataType) { case 0: /* 0: TSTRING */ tmpData = a[left]; while ( left < right ) { while ((strcmp(a[right].strData,tmpData.strData) >= 0) && (left < right)) right--; if (left != right) { a[left] = a[right]; left++; } while ((strcmp(a[left].strData,tmpData.strData) <= 0) && (left < right)) left++; if (left != right) { a[right] = a[left]; right--; } } a[left] = tmpData; break; case 1: /* 1: TSHORT, TINT, TBYTE, TLONG, TBIT, TLOGICAL */ tmpData = a[left]; while ( left < right ) { while ((a[right].intData >= tmpData.intData) && (left < right)) right--; if (left != right) { a[left] = a[right]; left++; } while ((a[left].intData <= tmpData.intData) && (left < right)) left++; if (left != right) { a[right] = a[left]; right--; } } a[left] = tmpData; break; case 2: /* 2: TFLOAT, TDOUBLE */ tmpData = a[left]; while ( left < right ) { while ((a[right].dblData >= tmpData.dblData) && (left < right)) right--; if (left != right) { a[left] = a[right]; left++; } while ((a[left].dblData <= tmpData.dblData) && (left < right)) left++; if (left != right) { a[right] = a[left]; right--; } } a[left] = tmpData; break; case 3: /* 3: TLONGLONG */ tmpData = a[left]; while ( left < right ) { while ((a[right].longlongData >= tmpData.longlongData) && (left < right)) right--; if (left != right) { a[left] = a[right]; left++; } while ((a[left].longlongData <= tmpData.longlongData) && (left < right)) left++; if (left != right) { a[right] = a[left]; right--; } } a[left] = tmpData; break; } } else { /* push all the smaller values to the RIGHT */ switch (dataType) { case 0: /* 0: TSTRING */ tmpData = a[left]; while ( left < right ) { while ((strcmp(a[right].strData,tmpData.strData) >= 0) && (left < right)) right--; if (left != right) { a[left] = a[right]; left++; } while ((strcmp(a[left].strData,tmpData.strData) <= 0) && (left < right)) left++; if (left != right) { a[right] = a[left]; right--; } } a[left] = tmpData; break; case 1: /* 1: TSHORT, TINT, TBYTE, TLONG, TBIT, TLOGICAL */ tmpData = a[left]; while ( left < right ) { while ((a[right].intData <= tmpData.intData) && (left < right)) right--; if (left != right) { a[left] = a[right]; left++; } while ((a[left].intData >= tmpData.intData) && (left < right)) left++; if (left != right) { a[right] = a[left]; right--; } } a[left] = tmpData; break; case 2: /* 2: TFLOAT, TDOUBLE */ tmpData = a[left]; while ( left < right ) { while ((a[right].dblData <= tmpData.dblData) && (left < right)) right--; if (left != right) { a[left] = a[right]; left++; } while ((a[left].dblData >= tmpData.dblData) && (left < right)) left++; if (left != right) { a[right] = a[left]; right--; } } a[left] = tmpData; break; case 3: /* 3: TLONGLONG */ tmpData = a[left]; while ( left < right ) { while ((a[right].longlongData <= tmpData.longlongData) && (left < right)) right--; if (left != right) { a[left] = a[right]; left++; } while ((a[left].longlongData >= tmpData.longlongData) && (left < right)) left++; if (left != right) { a[right] = a[left]; right--; } } a[left] = tmpData; break; } } *r_left = l_hold; *r_right = r_hold; return(left); } void fitsFreeRawColData( colData columndata[], long numRows ) { long i; for(i=0; i= '0' && *inputStr <= '9') #ifdef __WIN32__ ig = ig * 10I64 + *inputStr++ - '0'; #else ig = ig * 10LL + *inputStr++ - '0'; #endif else inputStr++; return (ig * (LONGLONG)sign); } fitsTcl-2.5/fvTcl.c0000644000220700000360000003332213133202233013001 0ustar birbylhea/************************************************************ * * fvTcl.c * * This holds all the fv-specific Tcl commands * ***********************************************************/ #include "fitsTclInt.h" /* * ------------------------------------------------------------ * * isFitsCmd * check for fits file * usage : isFits filename (1 is, 0 no) * * ------------------------------------------------------------ */ int isFitsCmd( ClientData clientData, Tcl_Interp *interp, int argc, char *const argv[]) { char simple[10]; int i; FILE *fitsPtr; if( argc != 2 ) { Tcl_SetResult(interp, "Usage: isFits filename", TCL_STATIC); return TCL_ERROR; } /* check if it's a remote file */ if ( !strncmp(argv[1], "ftp://", 6) || !strncmp(argv[1], "http://", 7) ) { Tcl_SetResult(interp, "2", TCL_STATIC); return TCL_OK; } /* also pass if it's a fv script file */ if( strstr(argv[1], ".fv") ) { Tcl_SetResult(interp, "3", TCL_STATIC); return TCL_OK; } /* skip IRAF files end with .imh */ if( strstr(argv[1], ".imh") ) { Tcl_SetResult(interp, "4", TCL_STATIC); return TCL_OK; } if( (fitsPtr = fopen(argv[1], "r")) == NULL ) { Tcl_AppendResult(interp, "File not found: ", argv[1], (char*)NULL ); return TCL_ERROR; } fgets(simple, 7, fitsPtr); /* to catch a zero length file */ /* if( strlen(simple) < 6 ) { */ if( strlen(simple) <= 0 ) { Tcl_SetResult(interp, "0", TCL_STATIC); /* real FITS file */ } else if( !strcmp(simple, "SIMPLE") ) { for ( i = 0; i< 100; i++) { if ( (fgetc(fitsPtr) == '\n') || (fgetc(fitsPtr) == '\r') ) { Tcl_SetResult(interp, "0", TCL_STATIC); break; } Tcl_SetResult(interp, "1", TCL_STATIC); } /* compressed file. should check if its FITS */ } else if( strncmp(simple, "\037\036", 2) == 0 || strncmp(simple, "\037\213", 2) == 0 || strncmp(simple, "\037\240", 2) == 0 || strncmp(simple, "\037\235", 2) == 0 || strncmp(simple, "\120\113", 2) == 0 ) { /* return 2 if the file is compressed files */ Tcl_SetResult(interp, "2", TCL_STATIC); } else { Tcl_SetResult(interp, "0", TCL_STATIC); } fclose(fitsPtr); return TCL_OK; } /* * ------------------------------------------------------------ * * getMaxCmd * pick out the maximum * * ------------------------------------------------------------ */ int getMaxCmd( ClientData clientData, Tcl_Interp *interp, int argc, char *const argv[] ) { int i, numCount, j; char **arrayPtr; double theMax, tmp; char theMaxStr[40]; if( argc == 1 ) { Tcl_SetResult(interp, "getmax list ?list? ...", TCL_STATIC); return TCL_OK; } theMaxStr[39]='\0'; for (i=1; i theMax ) { theMax = tmp; strncpy(theMaxStr, arrayPtr[j], 39); } } ckfree((char *) arrayPtr); } Tcl_SetResult(interp, theMaxStr, TCL_VOLATILE); return TCL_OK; } /* * ------------------------------------------------------------ * * getMinCmd * pick out the minimum * * ------------------------------------------------------------ */ int getMinCmd( ClientData clientData, Tcl_Interp *interp, int argc, char *const argv[] ) { int i, numCount, j; char **arrayPtr; double theMin, tmp; char theMinStr[40]; if( argc == 1 ) { Tcl_SetResult(interp, "getmin list", TCL_STATIC); return TCL_OK; } theMinStr[39] = '\0'; for (i=1; i tmpWidth ) { Tcl_SetVar2Ex(interp, "_numEntry", index1, overflowObj, TCL_NAMESPACE_ONLY); } else { Tcl_SetVar2Ex(interp, "_numEntry", index1, valObj, TCL_NAMESPACE_ONLY); } } } return TCL_OK; } fitsTcl-2.5/install-sh0000755000220700000360000003471713363675130013613 0ustar birbylhea#!/bin/sh # install - install a program, script, or datafile scriptversion=2017-09-23.17; # UTC # This originates from X11R5 (mit/util/scripts/install.sh), which was # later released in X11R6 (xc/config/util/install.sh) with the # following copyright and license. # # Copyright (C) 1994 X Consortium # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to # deal in the Software without restriction, including without limitation the # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or # sell copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # # Except as contained in this notice, the name of the X Consortium shall not # be used in advertising or otherwise to promote the sale, use or other deal- # ings in this Software without prior written authorization from the X Consor- # tium. # # # FSF changes to this file are in the public domain. # # Calling this script install-sh is preferred over install.sh, to prevent # 'make' implicit rules from creating a file called install from it # when there is no Makefile. # # This script is compatible with the BSD install script, but was written # from scratch. tab=' ' nl=' ' IFS=" $tab$nl" # Set DOITPROG to "echo" to test this script. doit=${DOITPROG-} doit_exec=${doit:-exec} # Put in absolute file names if you don't have them in your path; # or use environment vars. chgrpprog=${CHGRPPROG-chgrp} chmodprog=${CHMODPROG-chmod} chownprog=${CHOWNPROG-chown} cmpprog=${CMPPROG-cmp} cpprog=${CPPROG-cp} mkdirprog=${MKDIRPROG-mkdir} mvprog=${MVPROG-mv} rmprog=${RMPROG-rm} stripprog=${STRIPPROG-strip} posix_mkdir= # Desired mode of installed file. mode=0755 chgrpcmd= chmodcmd=$chmodprog chowncmd= mvcmd=$mvprog rmcmd="$rmprog -f" stripcmd= src= dst= dir_arg= dst_arg= copy_on_change=false is_target_a_directory=possibly usage="\ Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE or: $0 [OPTION]... SRCFILES... DIRECTORY or: $0 [OPTION]... -t DIRECTORY SRCFILES... or: $0 [OPTION]... -d DIRECTORIES... In the 1st form, copy SRCFILE to DSTFILE. In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. In the 4th, create DIRECTORIES. Options: --help display this help and exit. --version display version info and exit. -c (ignored) -C install only if different (preserve the last data modification time) -d create directories instead of installing files. -g GROUP $chgrpprog installed files to GROUP. -m MODE $chmodprog installed files to MODE. -o USER $chownprog installed files to USER. -s $stripprog installed files. -t DIRECTORY install into DIRECTORY. -T report an error if DSTFILE is a directory. Environment variables override the default commands: CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG " while test $# -ne 0; do case $1 in -c) ;; -C) copy_on_change=true;; -d) dir_arg=true;; -g) chgrpcmd="$chgrpprog $2" shift;; --help) echo "$usage"; exit $?;; -m) mode=$2 case $mode in *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) echo "$0: invalid mode: $mode" >&2 exit 1;; esac shift;; -o) chowncmd="$chownprog $2" shift;; -s) stripcmd=$stripprog;; -t) is_target_a_directory=always dst_arg=$2 # Protect names problematic for 'test' and other utilities. case $dst_arg in -* | [=\(\)!]) dst_arg=./$dst_arg;; esac shift;; -T) is_target_a_directory=never;; --version) echo "$0 $scriptversion"; exit $?;; --) shift break;; -*) echo "$0: invalid option: $1" >&2 exit 1;; *) break;; esac shift done # We allow the use of options -d and -T together, by making -d # take the precedence; this is for compatibility with GNU install. if test -n "$dir_arg"; then if test -n "$dst_arg"; then echo "$0: target directory not allowed when installing a directory." >&2 exit 1 fi fi if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then # When -d is used, all remaining arguments are directories to create. # When -t is used, the destination is already specified. # Otherwise, the last argument is the destination. Remove it from $@. for arg do if test -n "$dst_arg"; then # $@ is not empty: it contains at least $arg. set fnord "$@" "$dst_arg" shift # fnord fi shift # arg dst_arg=$arg # Protect names problematic for 'test' and other utilities. case $dst_arg in -* | [=\(\)!]) dst_arg=./$dst_arg;; esac done fi if test $# -eq 0; then if test -z "$dir_arg"; then echo "$0: no input file specified." >&2 exit 1 fi # It's OK to call 'install-sh -d' without argument. # This can happen when creating conditional directories. exit 0 fi if test -z "$dir_arg"; then if test $# -gt 1 || test "$is_target_a_directory" = always; then if test ! -d "$dst_arg"; then echo "$0: $dst_arg: Is not a directory." >&2 exit 1 fi fi fi if test -z "$dir_arg"; then do_exit='(exit $ret); exit $ret' trap "ret=129; $do_exit" 1 trap "ret=130; $do_exit" 2 trap "ret=141; $do_exit" 13 trap "ret=143; $do_exit" 15 # Set umask so as not to create temps with too-generous modes. # However, 'strip' requires both read and write access to temps. case $mode in # Optimize common cases. *644) cp_umask=133;; *755) cp_umask=22;; *[0-7]) if test -z "$stripcmd"; then u_plus_rw= else u_plus_rw='% 200' fi cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; *) if test -z "$stripcmd"; then u_plus_rw= else u_plus_rw=,u+rw fi cp_umask=$mode$u_plus_rw;; esac fi for src do # Protect names problematic for 'test' and other utilities. case $src in -* | [=\(\)!]) src=./$src;; esac if test -n "$dir_arg"; then dst=$src dstdir=$dst test -d "$dstdir" dstdir_status=$? else # Waiting for this to be detected by the "$cpprog $src $dsttmp" command # might cause directories to be created, which would be especially bad # if $src (and thus $dsttmp) contains '*'. if test ! -f "$src" && test ! -d "$src"; then echo "$0: $src does not exist." >&2 exit 1 fi if test -z "$dst_arg"; then echo "$0: no destination specified." >&2 exit 1 fi dst=$dst_arg # If destination is a directory, append the input filename. if test -d "$dst"; then if test "$is_target_a_directory" = never; then echo "$0: $dst_arg: Is a directory" >&2 exit 1 fi dstdir=$dst dstbase=`basename "$src"` case $dst in */) dst=$dst$dstbase;; *) dst=$dst/$dstbase;; esac dstdir_status=0 else dstdir=`dirname "$dst"` test -d "$dstdir" dstdir_status=$? fi fi case $dstdir in */) dstdirslash=$dstdir;; *) dstdirslash=$dstdir/;; esac obsolete_mkdir_used=false if test $dstdir_status != 0; then case $posix_mkdir in '') # Create intermediate dirs using mode 755 as modified by the umask. # This is like FreeBSD 'install' as of 1997-10-28. umask=`umask` case $stripcmd.$umask in # Optimize common cases. *[2367][2367]) mkdir_umask=$umask;; .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; *[0-7]) mkdir_umask=`expr $umask + 22 \ - $umask % 100 % 40 + $umask % 20 \ - $umask % 10 % 4 + $umask % 2 `;; *) mkdir_umask=$umask,go-w;; esac # With -d, create the new directory with the user-specified mode. # Otherwise, rely on $mkdir_umask. if test -n "$dir_arg"; then mkdir_mode=-m$mode else mkdir_mode= fi posix_mkdir=false case $umask in *[123567][0-7][0-7]) # POSIX mkdir -p sets u+wx bits regardless of umask, which # is incompatible with FreeBSD 'install' when (umask & 300) != 0. ;; *) tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 if (umask $mkdir_umask && exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 then if test -z "$dir_arg" || { # Check for POSIX incompatibilities with -m. # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or # other-writable bit of parent directory when it shouldn't. # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. ls_ld_tmpdir=`ls -ld "$tmpdir"` case $ls_ld_tmpdir in d????-?r-*) different_mode=700;; d????-?--*) different_mode=755;; *) false;; esac && $mkdirprog -m$different_mode -p -- "$tmpdir" && { ls_ld_tmpdir_1=`ls -ld "$tmpdir"` test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" } } then posix_mkdir=: fi rmdir "$tmpdir/d" "$tmpdir" else # Remove any dirs left behind by ancient mkdir implementations. rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null fi trap '' 0;; esac;; esac if $posix_mkdir && ( umask $mkdir_umask && $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" ) then : else # The umask is ridiculous, or mkdir does not conform to POSIX, # or it failed possibly due to a race condition. Create the # directory the slow way, step by step, checking for races as we go. case $dstdir in /*) prefix='/';; [-=\(\)!]*) prefix='./';; *) prefix='';; esac oIFS=$IFS IFS=/ set -f set fnord $dstdir shift set +f IFS=$oIFS prefixes= for d do test X"$d" = X && continue prefix=$prefix$d if test -d "$prefix"; then prefixes= else if $posix_mkdir; then (umask=$mkdir_umask && $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break # Don't fail if two instances are running concurrently. test -d "$prefix" || exit 1 else case $prefix in *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; *) qprefix=$prefix;; esac prefixes="$prefixes '$qprefix'" fi fi prefix=$prefix/ done if test -n "$prefixes"; then # Don't fail if two instances are running concurrently. (umask $mkdir_umask && eval "\$doit_exec \$mkdirprog $prefixes") || test -d "$dstdir" || exit 1 obsolete_mkdir_used=true fi fi fi if test -n "$dir_arg"; then { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 else # Make a couple of temp file names in the proper directory. dsttmp=${dstdirslash}_inst.$$_ rmtmp=${dstdirslash}_rm.$$_ # Trap to clean up those temp files at exit. trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 # Copy the file name to the temp name. (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && # and set any options; do chmod last to preserve setuid bits. # # If any of these fail, we abort the whole thing. If we want to # ignore errors from any of these, just make sure not to ignore # errors from the above "$doit $cpprog $src $dsttmp" command. # { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && # If -C, don't bother to copy if it wouldn't change the file. if $copy_on_change && old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && set -f && set X $old && old=:$2:$4:$5:$6 && set X $new && new=:$2:$4:$5:$6 && set +f && test "$old" = "$new" && $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 then rm -f "$dsttmp" else # Rename the file to the real destination. $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || # The rename failed, perhaps because mv can't rename something else # to itself, or perhaps because mv is so ancient that it does not # support -f. { # Now remove or move aside any old file at destination location. # We try this two ways since rm can't unlink itself on some # systems and the destination file might be busy for other # reasons. In this case, the final cleanup might fail but the new # file should still install successfully. { test ! -f "$dst" || $doit $rmcmd -f "$dst" 2>/dev/null || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } } || { echo "$0: cannot unlink or rename $dst" >&2 (exit 1); exit 1 } } && # Now rename the file to the real destination. $doit $mvcmd "$dsttmp" "$dst" } fi || exit 1 trap '' 0 fi done # Local variables: # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC0" # time-stamp-end: "; # UTC" # End: fitsTcl-2.5/tclShared.c0000644000220700000360000000125013357670753013657 0ustar birbylhea#include #ifdef macintosh #pragma export on #endif #ifdef __WIN32__ int _export Fitstcl_Init (Tcl_Interp *interp); #else int Fitstcl_Init (Tcl_Interp *interp); #endif #ifdef macintosh #pragma export reset #endif int Fitstcl_Init (interp) Tcl_Interp *interp; /* Interpreter for application. */ { return Fits_Init(interp); } int Fitstcl_SafeInit (interp) Tcl_Interp *interp; /* Interpreter for application. */ { return Fits_SafeInit(interp); } int Fitstcl_SafeUnload(Tcl_Interp *interp, int flags) { return FitsTcl_SafeUnload(interp, flags); } int Fitstcl_Unload(Tcl_Interp *interp, int flags) { return FitsTcl_Unload(interp, flags); }